Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not transform imports to use the Ember global for [email protected] and higher #387

Merged
merged 2 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions lib/babel-options-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,12 @@ function _getDebugMacroPlugins(config) {
];
}

function _emberVersionRequiresModulesAPIPolyfill() {
// once a version of Ember ships with the
// emberjs/rfcs#176 modules natively this will
// be updated to detect that and return false
return true;
function _emberVersionRequiresModulesAPIPolyfill(parent) {
let checker = new VersionChecker(parent).for("ember-source", "npm");
if (!checker.exists()) {
return true;
}
return checker.lt("3.27.0-alpha.1");
}

function _emberDataVersionRequiresPackagesPolyfill(project) {
Expand All @@ -125,7 +126,7 @@ function _getEmberModulesAPIPolyfill(config, parent, project) {
return;
}

if (_emberVersionRequiresModulesAPIPolyfill()) {
if (_emberVersionRequiresModulesAPIPolyfill(parent)) {
const ignore = _getEmberModulesAPIIgnore(parent, project);

return [
Expand Down
17 changes: 10 additions & 7 deletions lib/ember-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,22 @@ function _getDebugMacroPlugins() {
],
];
}
function _emberVersionRequiresModulesAPIPolyfill() {
// once a version of Ember ships with the
// emberjs/rfcs#176 modules natively this will
// be updated to detect that and return false
return true;
function _emberVersionRequiresModulesAPIPolyfill(appRoot) {
rwjblue marked this conversation as resolved.
Show resolved Hide resolved
let packagePath = resolvePackagePath("ember-source", appRoot);
if (packagePath === null) {
return true;
}

let pkg = require(packagePath);
return pkg && semver.lt(pkg.version, "3.27.0-alpha.1");
}

function _getEmberModulesAPIPolyfill(appRoot, config) {
if (config.disableEmberModulesAPIPolyfill) {
return;
}

if (_emberVersionRequiresModulesAPIPolyfill()) {
if (_emberVersionRequiresModulesAPIPolyfill(appRoot)) {
const ignore = _getEmberModulesAPIIgnore(appRoot, config);

return [
Expand Down Expand Up @@ -128,7 +131,7 @@ function _getEmberDataPackagesPolyfill(appRoot, config) {
function _getModuleResolutionPlugins(config) {
if (!config.disableModuleResolution) {
const resolvePath = require("../lib/relative-module-paths")
.resolveRelativeModulePath;
.resolveRelativeModulePath;
return [
[require.resolve("babel-plugin-module-resolver"), { resolvePath }],
[
Expand Down
110 changes: 108 additions & 2 deletions node-tests/addon-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,112 @@ describe('ember-cli-babel', function() {
}));
});

describe("Opting out of the ember modules API polyfill", function () {
let dependencies;

beforeEach(function () {
dependencies = {};
let project = {
root: input.path(),
emberCLIVersion: () => "2.16.2",
dependencies() {
return dependencies;
},
addons: [],
targets: {
browsers: ["ie 11"],
},
};

this.addon = new Addon({
project,
parent: project,
ui: this.ui,
});

project.addons.push(this.addon);
});

function buildEmberSourceFixture(version) {
return {
node_modules: {
"ember-source": {
"package.json": JSON.stringify({ name: "ember-source", version }),
"index.js": "module.exports = {};",
},
},
};
}

it(
"should replace imports with Ember Globals",
co.wrap(function* () {
const PRE_EMBER_MODULE_IMPORTS_VERSION = "3.26.0";
dependencies[
"ember-source"
] = PRE_EMBER_MODULE_IMPORTS_VERSION;
input.write(
buildEmberSourceFixture(PRE_EMBER_MODULE_IMPORTS_VERSION)
);
input.write({
"foo.js": `import Component from '@ember/component'; Component.extend()`,
"app.js": `import Application from '@ember/application'; Application.extend()`,
});

subject = this.addon.transpileTree(input.path());
output = createBuilder(subject);

yield output.build();

expect(output.read()).to.deep.equal({
"foo.js": `define("foo", [], function () {\n "use strict";\n\n Ember.Component.extend();\n});`,
"app.js": `define("app", [], function () {\n "use strict";\n\n Ember.Application.extend();\n});`,
node_modules: {
"ember-source": {
"index.js":
'define("node_modules/ember-source/index", [], function () {\n "use strict";\n\n module.exports = {};\n});',
"package.json": '{"name":"ember-source","version":"3.26.0"}',
},
},
});
})
);

it(
"should not replace the imports with Ember Globals when using an ember-source version that supports it",
co.wrap(function* () {
const POST_GLOBAL_RESOLVER_DEPRECATION_VERSION = "3.27.0";
dependencies[
"ember-source"
] = POST_GLOBAL_RESOLVER_DEPRECATION_VERSION;
input.write(
buildEmberSourceFixture(POST_GLOBAL_RESOLVER_DEPRECATION_VERSION)
);
input.write({
"foo.js": `import Component from '@ember/component'; Component.extend()`,
"app.js": `import Application from '@ember/application'; Application.extend()`,
});

subject = this.addon.transpileTree(input.path());
output = createBuilder(subject);

yield output.build();

expect(output.read()).to.deep.equal({
"foo.js": `define("foo", ["@ember/component"], function (_component) {\n "use strict";\n\n _component.default.extend();\n});`,
"app.js": `define("app", ["@ember/application"], function (_application) {\n "use strict";\n\n _application.default.extend();\n});`,
node_modules: {
"ember-source": {
"index.js":
'define("node_modules/ember-source/index", [], function () {\n "use strict";\n\n module.exports = {};\n});',
"package.json": '{"name":"ember-source","version":"3.27.0"}',
},
},
});
})
);
});

describe('debug macros', function() {
it("can opt-out via ember-cli-babel.disableDebugTooling", co.wrap(function* () {
process.env.EMBER_ENV = 'development';
Expand Down Expand Up @@ -1606,13 +1712,13 @@ describe('babel config file', function() {
let self = this;
setupForVersion = co.wrap(function*(plugins) {
let fixturifyProject = new FixturifyProject('whatever', '0.0.1');

fixturifyProject.addDependency('ember-cli-babel', 'babel/ember-cli-babel#master');
fixturifyProject.addDependency('random-addon', '0.0.1', addon => {
return prepareAddon(addon);
});
let pkg = JSON.parse(fixturifyProject.toJSON('package.json'));
fixturifyProject.files['babel.config.js'] =
fixturifyProject.files['babel.config.js'] =
`module.exports = function (api) {
api.cache(true);
return {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"amd-name-resolver": "^1.3.1",
"babel-plugin-debug-macros": "^0.3.4",
"babel-plugin-ember-data-packages-polyfill": "^0.1.2",
"babel-plugin-ember-modules-api-polyfill": "^3.4.0",
"babel-plugin-ember-modules-api-polyfill": "^3.5.0",
"babel-plugin-module-resolver": "^3.2.0",
"broccoli-babel-transpiler": "^7.8.0",
"broccoli-debug": "^0.6.4",
Expand Down
17 changes: 11 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1784,12 +1784,12 @@ babel-plugin-ember-modules-api-polyfill@^2.12.0, babel-plugin-ember-modules-api-
dependencies:
ember-rfc176-data "^0.3.13"

babel-plugin-ember-modules-api-polyfill@^3.4.0:
version "3.4.0"
resolved "https://registry.yarnpkg.com/babel-plugin-ember-modules-api-polyfill/-/babel-plugin-ember-modules-api-polyfill-3.4.0.tgz#3f5e0457e135f8a29b3a8b6910806bb5b524649e"
integrity sha512-nVu/LqbZBAup1zLij6xGvQwVLWVk4XYu2fl4vIOUR3S6ukdonMLhKAb0d4QXSzH30Pd7OczVTlPffWbiwahdJw==
babel-plugin-ember-modules-api-polyfill@^3.5.0:
version "3.5.0"
resolved "https://registry.yarnpkg.com/babel-plugin-ember-modules-api-polyfill/-/babel-plugin-ember-modules-api-polyfill-3.5.0.tgz#27b6087fac75661f779f32e60f94b14d0e9f6965"
integrity sha512-pJajN/DkQUnStw0Az8c6khVcMQHgzqWr61lLNtVeu0g61LRW0k9jyK7vaedrHDWGe/Qe8sxG5wpiyW9NsMqFzA==
dependencies:
ember-rfc176-data "^0.3.16"
ember-rfc176-data "^0.3.17"

babel-plugin-htmlbars-inline-precompile@^0.2.5:
version "0.2.6"
Expand Down Expand Up @@ -4091,11 +4091,16 @@ ember-resolver@^5.0.1:
ember-cli-version-checker "^3.0.0"
resolve "^1.10.0"

ember-rfc176-data@^0.3.1, ember-rfc176-data@^0.3.13, ember-rfc176-data@^0.3.16, ember-rfc176-data@^0.3.5:
ember-rfc176-data@^0.3.1, ember-rfc176-data@^0.3.13, ember-rfc176-data@^0.3.5:
version "0.3.16"
resolved "https://registry.yarnpkg.com/ember-rfc176-data/-/ember-rfc176-data-0.3.16.tgz#2ace0ac9cf9016d493a74a1d931643a308679803"
integrity sha512-IYAzffS90r2ybAcx8c2qprYfkxa70G+/UPkxMN1hw55DU5S2aLOX6v3umKDZItoRhrvZMCnzwsdfKSrKdC9Wbg==

ember-rfc176-data@^0.3.17:
version "0.3.17"
resolved "https://registry.yarnpkg.com/ember-rfc176-data/-/ember-rfc176-data-0.3.17.tgz#d4fc6c33abd6ef7b3440c107a28e04417b49860a"
integrity sha512-EVzTTKqxv9FZbEh6Ktw56YyWRAA0MijKvl7H8C06wVF+8f/cRRz3dXxa4nkwjzyVwx4rzKGuIGq77hxJAQhWWw==

ember-router-generator@^1.2.3:
version "1.2.3"
resolved "https://registry.yarnpkg.com/ember-router-generator/-/ember-router-generator-1.2.3.tgz#8ed2ca86ff323363120fc14278191e9e8f1315ee"
Expand Down