Skip to content

Commit

Permalink
Enable esModuleInterop for all packages.
Browse files Browse the repository at this point in the history
This allows CommonJS to interop with module imports via babel.

It caused some issues in some deprecated code that I was about to remove
anyways, so it's removed as part of this commit:

BREAKING CHANGE: The following deprecated properties are removed:

* require('eyeglass').Eyeglass
* require('eyeglass').decorate

The tests that relied on those deprecations to test our deprecation
warnings have been rewritten to be more generic.
  • Loading branch information
chriseppstein committed Mar 28, 2020
1 parent 0935d09 commit 5b89784
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 153 deletions.
2 changes: 2 additions & 0 deletions packages/broccoli-eyeglass/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"compilerOptions": {
"module": "CommonJS",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"rootDir": "src",
"baseUrl": "src",
Expand Down
2 changes: 2 additions & 0 deletions packages/ember-cli-eyeglass/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"compilerOptions": {
"module": "CommonJS",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"rootDir": "src",
"baseUrl": "src",
Expand Down
3 changes: 3 additions & 0 deletions packages/eyeglass/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
asynchronous sass functions.
* Manually specified modules no longer take precedence over modules discovered
via node package dependencies. [More Information](https://github.com/linkedin/eyeglass/commit/9d9500abd90414ea9bec7c60465f2bdd42e496ef).
* The following deprecated properties have been removed:
* `require('eyeglass').Eyeglass`. Instead you should do: `const Eyeglass = require('eyeglass'); new Eyeglass(sassOptions);`
* `const decorate = require('eyeglass').decorate` - Instead you should do `const decorate = require('eyeglass'); const decoratedOpts = decorate(sassOptions)`.

# 2.5.0

Expand Down
4 changes: 2 additions & 2 deletions packages/eyeglass/src/Eyeglass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import deprecator, { DeprecateFn } from "./util/deprecator";
import semverChecker from "./util/semverChecker";
import * as fs from "fs-extra";
import { IEyeglass } from "./IEyeglass";
import packageJson = require("package-json");
import * as packageJson from "package-json";
import { SassFunction } from "node-sass";
import { SassImplementation, helpers as sassHelpers } from "./util/SassImplementation";
import { AsyncImporter } from "node-sass";
import { UnsafeDict, Dict } from "./util/typescriptUtils";
import heimdall = require("heimdalljs");
import { SimpleCache } from "./util/SimpleCache";
import { resetGlobalCaches as resetGlobalFSCaches } from "./util/perf";
import * as debugGenerator from "debug";
import debugGenerator from "debug";

const debug = debugGenerator("eyeglass:initialization");

Expand Down
4 changes: 2 additions & 2 deletions packages/eyeglass/src/assets/AssetsSource.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as fs from "fs";
import * as glob from "glob";
import * as path from "path";
import merge = require("lodash.merge") ;
import merge from "lodash.merge";
import { URI } from "../util/URI";
import { AssetSourceOptions } from "../util/Options";
import * as stringify from "json-stable-stringify";
import stringify from "json-stable-stringify";

export interface DiscoveredAssets {
namespace: string | undefined;
Expand Down
2 changes: 1 addition & 1 deletion packages/eyeglass/src/functions/fs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as fs from "fs";
import { existsSync } from "fs";
import * as path from "path";
import * as glob from "glob";
import glob from "glob";
import { IEyeglass } from "../IEyeglass";
import { SassImplementation, isSassString, typeError } from "../util/SassImplementation";
import { SassFunctionCallback, FunctionDeclarations } from "node-sass";
Expand Down
2 changes: 1 addition & 1 deletion packages/eyeglass/src/importers/ImportUtilities.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as debug from "../util/debug";
import { URI } from "../util/URI";
import merge = require("lodash.merge");
import merge from "lodash.merge";
import { ImporterReturnType, AsyncImporter, AsyncContext } from "node-sass";
import { IEyeglass } from "../IEyeglass";
import { SassImplementation } from "../util/SassImplementation";
Expand Down
28 changes: 1 addition & 27 deletions packages/eyeglass/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
import { Options as Opts, Config } from "./util/Options";
import { IEyeglass } from "./IEyeglass";
import { SassImplementation } from "./util/SassImplementation";
import EyeglassImpl, { resetGlobalCaches } from "./Eyeglass";
/* eslint-disable @typescript-eslint/no-namespace, no-inner-declarations, no-redeclare */

function deprecateMethodWarning(this: IEyeglass, method: string): void {
this.deprecate("0.8.0", "0.9.0",
"`require('eyeglass')." + method + "` is deprecated. " +
"Instead, use `require('eyeglass')`"
);
}

interface DeprecatedFunctions {
Eyeglass(options: Opts, deprecatedNodeSassArg?: SassImplementation): EyeglassImpl;
decorate(options: Opts, deprecatedNodeSassArg?: SassImplementation): Config;
}

interface AdditionalFunctions {
resetGlobalCaches(): void;
}

type PublicConstructor =
typeof EyeglassImpl
& DeprecatedFunctions
& AdditionalFunctions
& ((options: Opts, deprecatedNodeSassArg?: SassImplementation) => Config);

Expand All @@ -41,19 +27,7 @@ function newOrOptions(): PublicConstructor {
__Eyeglass.prototype = EyeglassImpl.prototype;
__Eyeglass.VERSION = EyeglassImpl.VERSION;
__Eyeglass.helpers = EyeglassImpl.helpers;
Object.assign(__Eyeglass, {
resetGlobalCaches,
Eyeglass(options: Opts, deprecatedNodeSassArg?: SassImplementation): EyeglassImpl {
let eyeglass = new EyeglassImpl(options, deprecatedNodeSassArg);
deprecateMethodWarning.call(eyeglass, "Eyeglass");
return eyeglass;
},
decorate(options: Opts, deprecatedNodeSassArg?: SassImplementation): Config {
let eyeglass = new EyeglassImpl(options, deprecatedNodeSassArg);
deprecateMethodWarning.call(eyeglass, "decorate");
return eyeglass.options;
},
});
__Eyeglass.resetGlobalCaches = resetGlobalCaches;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return __Eyeglass as any; // we have to cast through any otherwise typescript thinks this function doesn't implement the full API of EyeglassImpl.
}
Expand Down
4 changes: 2 additions & 2 deletions packages/eyeglass/src/modules/EyeglassModules.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as archy from "archy";
import archy from "archy";
import * as path from "path";
import * as semver from "semver";
import { SemVer } from "semver";
Expand All @@ -8,7 +8,7 @@ import resolve from "../util/resolve";
import { SimpleCache } from "../util/SimpleCache";
import { URI } from "../util/URI";
import EyeglassModule, { ModuleSpecifier, DiscoverOptions, isModuleReference } from "./EyeglassModule";
import merge = require("lodash.merge");
import merge from "lodash.merge";
import packageJson = require("package-json");
import { IEyeglass } from "../IEyeglass";
import { SassImplementation } from "../util/SassImplementation";
Expand Down
2 changes: 1 addition & 1 deletion packages/eyeglass/src/util/debug.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as debug from "debug";
import debug from "debug";

export const importer = debug("eyeglass:importer");
export const modules = debug("eyeglass:modules");
Expand Down
132 changes: 15 additions & 117 deletions packages/eyeglass/test/test_options.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use strict";

var Eyeglass = require("../lib");
var Deprecator = require("../lib/util/deprecator").Deprecator;
var Eyeglass = require("../");
var VERSION = Eyeglass.VERSION;
var assert = require("assert");
var testutils = require("./testutils");
Expand Down Expand Up @@ -89,153 +90,50 @@ describe("options", function() {
var options = {
root: rootDir,
eyeglass: {
ignoreDeprecations: semver.inc(VERSION, "minor")
ignoreDeprecations: "1.5.0"
}
};
var eyeglass = new Eyeglass.Eyeglass(options);
/* eslint no-unused-vars:0 */
var sassopts = eyeglass.sassOptions();
let deprecator = new Deprecator(options);
deprecator.deprecate("1.4.0", "20.0.0", "testing deprecator");
checkStderr("");
done();
});
});

it("should enable deprecation warnings via an option", function(done) {
it("should still get new deprecation warnings if ignoreDeprecations is set to an older version.", function(done) {
testutils.assertStderr(function(checkStderr) {
var rootDir = testutils.fixtureDirectory("basic_modules");
var options = {
root: rootDir,
assetsHttpPrefix: "foo",
assetsRelativeTo: "/styles/main.css",
eyeglass: {
ignoreDeprecations: "0.7.1"
ignoreDeprecations: "1.5.0"
}
};
var eyeglass = new Eyeglass.Eyeglass(options);
/* eslint no-unused-vars:0 */
var sassopts = eyeglass.sassOptions();
checkStderr([
"[eyeglass:deprecation] (deprecated in 0.8.0, will be removed in 0.9.0) `root` " +
"should be passed into the eyeglass options rather than the sass options:",
" var options = eyeglass({",
" /* sassOptions */",
" ...",
" eyeglass: {",
" root: ...",
" }",
" });",
"[eyeglass:deprecation] (deprecated in 0.8.0, will be removed in 0.9.0) " +
"`assetsHttpPrefix` has been renamed to `httpPrefix` and should be passed into " +
"the eyeglass asset options rather than the sass options:",
" var options = eyeglass({",
" /* sassOptions */",
" ...",
" eyeglass: {",
" assets: {",
" httpPrefix: ...",
" }",
" }",
" });",
"[eyeglass:deprecation] (deprecated in 0.8.0, will be removed in 0.9.0) " +
"`assetsRelativeTo` has been renamed to `relativeTo` and should be passed into " +
"the eyeglass asset options rather than the sass options:",
" var options = eyeglass({",
" /* sassOptions */",
" ...",
" eyeglass: {",
" assets: {",
" relativeTo: ...",
" }",
" }",
" });",
"[eyeglass:deprecation] (deprecated in 0.8.0, will be removed in 0.9.0) " +
"`require('eyeglass').Eyeglass` is deprecated. Instead, use `require('eyeglass')`",
"[eyeglass:deprecation] (deprecated in 0.8.0, will be removed in 0.9.0) " +
"#sassOptions() is deprecated. Instead, you should access the sass options on #options\n"
].join("\n"));
let deprecator = new Deprecator(options);
deprecator.deprecate("2.0.0", "20.0.0", "this deprecation is expected");
checkStderr("[eyeglass:deprecation] (deprecated in 2.0.0, will be removed in 20.0.0) this deprecation is expected\n");
done();
});
});

it("should use default verion of `0.0.0` if `ignoreDeprecations: false`", function(done) {
it("should get all deprecation warnings if ignoreDeprecations is set to false.", function(done) {
testutils.assertStderr(function(checkStderr) {
var rootDir = testutils.fixtureDirectory("basic_modules");
var options = {
root: rootDir,
assetsHttpPrefix: "foo",
assetsRelativeTo: "/styles/main.css",
eyeglass: {
ignoreDeprecations: false
}
};
var eyeglass = new Eyeglass.Eyeglass(options);
/* eslint no-unused-vars:0 */
var sassopts = eyeglass.sassOptions();
checkStderr([
"[eyeglass:deprecation] (deprecated in 0.8.0, will be removed in 0.9.0) `root` " +
"should be passed into the eyeglass options rather than the sass options:",
" var options = eyeglass({",
" /* sassOptions */",
" ...",
" eyeglass: {",
" root: ...",
" }",
" });",
"[eyeglass:deprecation] (deprecated in 0.8.0, will be removed in 0.9.0) " +
"`assetsHttpPrefix` has been renamed to `httpPrefix` and should be passed into " +
"the eyeglass asset options rather than the sass options:",
" var options = eyeglass({",
" /* sassOptions */",
" ...",
" eyeglass: {",
" assets: {",
" httpPrefix: ...",
" }",
" }",
" });",
"[eyeglass:deprecation] (deprecated in 0.8.0, will be removed in 0.9.0) " +
"`assetsRelativeTo` has been renamed to `relativeTo` and should be passed into " +
"the eyeglass asset options rather than the sass options:",
" var options = eyeglass({",
" /* sassOptions */",
" ...",
" eyeglass: {",
" assets: {",
" relativeTo: ...",
" }",
" }",
" });",
"[eyeglass:deprecation] (deprecated in 0.8.0, will be removed in 0.9.0) " +
"`require('eyeglass').Eyeglass` is deprecated. Instead, use `require('eyeglass')`",
"[eyeglass:deprecation] (deprecated in 0.8.0, will be removed in 0.9.0) " +
"#sassOptions() is deprecated. Instead, you should access the sass options on #options\n"
].join("\n"));
let deprecator = new Deprecator(options);
deprecator.deprecate("0.0.1", "20.0.0", "this deprecation is expected");
checkStderr("[eyeglass:deprecation] (deprecated in 0.0.1, will be removed in 20.0.0) this deprecation is expected\n");
done();
});
});

describe("deprecated interface", function() {
it("should support `new Eyeglass.Eyeglass` with warning", function(done) {
testutils.assertStderr(function(checkStderr) {
var eyeglass = new Eyeglass.Eyeglass();
checkStderr(
"[eyeglass:deprecation] (deprecated in 0.8.0, will be removed in 0.9.0) " +
"`require('eyeglass').Eyeglass` is deprecated. Instead, use `require('eyeglass')`\n"
);
done();
});
});

it("should support `Eyeglass.decorate` with warning", function(done) {
testutils.assertStderr(function(checkStderr) {
var eyeglass = Eyeglass.decorate();
checkStderr(
"[eyeglass:deprecation] (deprecated in 0.8.0, will be removed in 0.9.0) " +
"`require('eyeglass').decorate` is deprecated. Instead, use `require('eyeglass')`\n"
);
done();
});
});
describe("deprecated interface", function() {

it("should support `#sassOptions` method with warning", function(done) {
testutils.assertStderr(function(checkStderr) {
Expand Down
2 changes: 2 additions & 0 deletions packages/eyeglass/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"compilerOptions": {
"module": "CommonJS",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"rootDir": "src",
"baseUrl": "src",
Expand Down

0 comments on commit 5b89784

Please sign in to comment.