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

Fix combination usages of compileModules along with other flags. #407

Merged
merged 1 commit into from
May 18, 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
45 changes: 37 additions & 8 deletions lib/babel-options-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ function _shouldHighlightCode(parent) {
function _getDebugMacroPlugins(config, project) {
let addonOptions = config["ember-cli-babel"] || {};

if (addonOptions.disableDebugTooling) {
let disableDebugTooling = addonOptions.disableDebugTooling;
if (disableDebugTooling) {
return;
}

Expand Down Expand Up @@ -85,21 +86,33 @@ function _getDebugMacroPlugins(config, project) {
},
};

// we have to use the global form when not compiling modules, because it is often used
// in the context of an `app.import` where there is no wrapped in an AMD module
if (addonOptions.compileModules === false || _emberVersionRequiresModulesAPIPolyfill(project)) {
let useModulesVersion;

if (_emberVersionRequiresModulesAPIPolyfill(project)) {
useModulesVersion = false;
} else if (addonOptions.compileModules === false) {
// we have to use the global form when not compiling modules, because it is often used
// in the context of an `app.import` where there is no wrapped in an AMD module
//
// However, you can opt out of this behavior by explicitly specifying `disableDebugTooling`
useModulesVersion = disableDebugTooling === false;
} else {
useModulesVersion = true;
}

if (useModulesVersion) {
emberDebugOptions.externalizeHelpers = {
global: "Ember",
module: "@ember/debug",
};
emberApplicationDeprecationsOptions.externalizeHelpers = {
global: "Ember",
module: "@ember/application/deprecations",
};
} else {
emberDebugOptions.externalizeHelpers = {
module: "@ember/debug",
global: "Ember",
};
emberApplicationDeprecationsOptions.externalizeHelpers = {
module: "@ember/application/deprecations",
global: "Ember",
};
}

Expand Down Expand Up @@ -147,7 +160,23 @@ function _getEmberModulesAPIPolyfill(config, parent, project) {
return;
}

let useModulesVersion;

if (_emberVersionRequiresModulesAPIPolyfill(project)) {
useModulesVersion = false;
} else if (addonOptions.compileModules === false) {
// we have to use the global form when not compiling modules, because it is often used
// in the context of an `app.import` where there is no wrapped in an AMD module
//
// However, you can opt out of this behavior by explicitly specifying `disableEmberModulesAPIPolyfill`
useModulesVersion = addonOptions.disableEmberModulesAPIPolyfill === false;
} else {
useModulesVersion = true;
}

// we have to use the global form when not compiling modules, because it is often used
// in the context of an `app.import` where there is no wrapped in an AMD module
if (!useModulesVersion) {
const ignore = _getEmberModulesAPIIgnore(parent, project);

return [
Expand Down
283 changes: 283 additions & 0 deletions node-tests/addon-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,289 @@ describe('ember-cli-babel', function() {
});
}));

it("when transpiling with compileModules: false it should use Ember global for previously 'fake' imports even on Ember 3.27+", co.wrap(function* () {
process.env.EMBER_ENV = 'development';

dependencies[
"ember-source"
] = POST_EMBER_MODULE_IMPORTS_VERSION;
input.write(
buildEmberSourceFixture(POST_EMBER_MODULE_IMPORTS_VERSION)
);

input.write({
app: {
"foo.js": stripIndent`
import Component from '@ember/component';

export default class extends Component {}
`,
},
});

this.addon.project.targets = {
browsers: ['last 2 chrome versions']
};

subject = this.addon.transpileTree(input.path('app'), {
'ember-cli-babel': {
compileModules: false,
}
});
output = createBuilder(subject);

yield output.build();

expect(
output.read()
).to.deep.equal({
"foo.js": `export default class extends Ember.Component {}`,
});
}));

it("when transpiling with compileModules: false, disableEmberModulesAPIPolyfill: true it should not use Ember global for previously 'fake' imports", co.wrap(function* () {
process.env.EMBER_ENV = 'development';

dependencies[
"ember-source"
] = POST_EMBER_MODULE_IMPORTS_VERSION;
input.write(
buildEmberSourceFixture(POST_EMBER_MODULE_IMPORTS_VERSION)
);

input.write({
app: {
"foo.js": stripIndent`
import Component from '@ember/component';

export default class extends Component {}
`,
},
});

this.addon.project.targets = {
browsers: ['last 2 chrome versions']
};

subject = this.addon.transpileTree(input.path('app'), {
'ember-cli-babel': {
compileModules: false,
disableEmberModulesAPIPolyfill: true,
}
});
output = createBuilder(subject);

yield output.build();

expect(
output.read()
).to.deep.equal({
"foo.js": `import Component from '@ember/component';\nexport default class extends Component {}`,
});
}));

it("when transpiling with compileModules: false, disableEmberModulesAPIPolyfill: false it should use global for Ember < 3.27", co.wrap(function* () {
process.env.EMBER_ENV = 'development';

dependencies[
"ember-source"
] = PRE_EMBER_MODULE_IMPORTS_VERSION;
input.write(
buildEmberSourceFixture(PRE_EMBER_MODULE_IMPORTS_VERSION)
);

input.write({
app: {
"foo.js": stripIndent`
import Component from '@ember/component';

export default class extends Component {}
`,
},
});

this.addon.project.targets = {
browsers: ['last 2 chrome versions']
};

subject = this.addon.transpileTree(input.path('app'), {
'ember-cli-babel': {
compileModules: false,
disableEmberModulesAPIPolyfill: false,
}
});
output = createBuilder(subject);

yield output.build();

expect(
output.read()
).to.deep.equal({
"foo.js": `export default class extends Ember.Component {}`,
});
}));

it("when transpiling with compileModules: false, disableEmberModulesAPIPolyfill: false it should use global for Ember > 3.27", co.wrap(function* () {
process.env.EMBER_ENV = 'development';

dependencies[
"ember-source"
] = POST_EMBER_MODULE_IMPORTS_VERSION;
input.write(
buildEmberSourceFixture(POST_EMBER_MODULE_IMPORTS_VERSION)
);

input.write({
app: {
"foo.js": stripIndent`
import Component from '@ember/component';

export default class extends Component {}
`,
},
});

this.addon.project.targets = {
browsers: ['last 2 chrome versions']
};

subject = this.addon.transpileTree(input.path('app'), {
'ember-cli-babel': {
compileModules: false,
disableEmberModulesAPIPolyfill: false,
}
});
output = createBuilder(subject);

yield output.build();

expect(
output.read()
).to.deep.equal({
"foo.js": `import Component from '@ember/component';\nexport default class extends Component {}`,
});
}));

it("when transpiling with compileModules: false, disableDebugTooling: false it should use modules for debug tooling", co.wrap(function* () {
process.env.EMBER_ENV = 'development';

dependencies[
"ember-source"
] = POST_EMBER_MODULE_IMPORTS_VERSION;
input.write(
buildEmberSourceFixture(POST_EMBER_MODULE_IMPORTS_VERSION)
);

input.write({
app: {
"foo.js": stripIndent`
import { assert } from '@ember/debug';
assert('stuff here', isNotBad());
`,
"bar.js": stripIndent`
import { deprecate } from '@ember/debug';
deprecate(
'foo bar baz',
false,
{
id: 'some-id',
until: '1.0.0',
}
);
`,
"baz.js": stripIndent`
import { deprecate } from '@ember/application/deprecations';
deprecate(
'foo bar baz',
false,
{
id: 'some-id',
until: '1.0.0',
}
);
`,
},
});

subject = this.addon.transpileTree(input.path('app'), {
'ember-cli-babel': {
compileModules: false,
disableDebugTooling: false,
}
});
output = createBuilder(subject);

yield output.build();

expect(
output.read()
).to.deep.equal({
"bar.js": `import { deprecate } from '@ember/debug';\n(true && !(false) && deprecate('foo bar baz', false, {\n id: 'some-id',\n until: '1.0.0'\n}));`,
"baz.js": `import { deprecate } from '@ember/application/deprecations';\n(true && !(false) && deprecate('foo bar baz', false, {\n id: 'some-id',\n until: '1.0.0'\n}));`,
"foo.js": `import { assert } from '@ember/debug';\n(true && !(isNotBad()) && assert('stuff here', isNotBad()));`,
});
}));

it("when transpiling with compileModules: false, disableDebugTooling: true it should not use Ember global for debug tooling", co.wrap(function* () {
process.env.EMBER_ENV = 'development';

dependencies[
"ember-source"
] = POST_EMBER_MODULE_IMPORTS_VERSION;
input.write(
buildEmberSourceFixture(POST_EMBER_MODULE_IMPORTS_VERSION)
);

input.write({
app: {
"foo.js": stripIndent`
import { assert } from '@ember/debug';
assert('stuff here', isNotBad());
`,
"bar.js": stripIndent`
import { deprecate } from '@ember/debug';
deprecate(
'foo bar baz',
false,
{
id: 'some-id',
until: '1.0.0',
}
);
`,
"baz.js": stripIndent`
import { deprecate } from '@ember/application/deprecations';
deprecate(
'foo bar baz',
false,
{
id: 'some-id',
until: '1.0.0',
}
);
`,
},
});

subject = this.addon.transpileTree(input.path('app'), {
'ember-cli-babel': {
compileModules: false,
disableDebugTooling: true,
}
});
output = createBuilder(subject);

yield output.build();

expect(
output.read()
).to.deep.equal({
"bar.js": `import { deprecate } from '@ember/debug';\ndeprecate('foo bar baz', false, {\n id: 'some-id',\n until: '1.0.0'\n});`,
"baz.js": `import { deprecate } from '@ember/application/deprecations';\ndeprecate('foo bar baz', false, {\n id: 'some-id',\n until: '1.0.0'\n});`,
"foo.js": `import { assert } from '@ember/debug';\nassert('stuff here', isNotBad());`,
});
}));

it("when transpiling with compileModules: false, it should use Ember global even on Ember 3.27+", co.wrap(function* () {
process.env.EMBER_ENV = 'development';

Expand Down