Skip to content

Commit e20c0e4

Browse files
author
Robert Jackson
committed
Fix compatibility with Ember 3.27+ when using compileModules: false.
When using libraries that leverage `compileModules: false` (commonly used to transpile `vendor` tree's without introducing a wrapping AMD module) on Ember 3.27+ (where we don't transpile away the various `@ember/*` modules any longer) we would leave the debug module imports alone during transpilation. This resulted (in most cases) in there being a bare unwrapped and untranspiled `import` statement in `vendor.js`. This would then fail **everything**. This changes the logic slightly to continue transpiling to globals mode when `compileModules: false` is set. Note: this is really just a stop gap solution (and will still cause deprecations to be emitted, addons that are currently leveraging `compileModules: false` _will_ need to make some changes for Ember 4.0 (where a global `window.Ember` will not be ambiently available).
1 parent 917f86b commit e20c0e4

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

lib/babel-options-util.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ function _getDebugMacroPlugins(config, project) {
8585
},
8686
};
8787

88-
if (_emberVersionRequiresModulesAPIPolyfill(project)) {
88+
// we have to use the global form when not compiling modules, because it is often used
89+
// in the context of an `app.import` where there is no wrapped in an AMD module
90+
if (addonOptions.compileModules === false || _emberVersionRequiresModulesAPIPolyfill(project)) {
8991
emberDebugOptions.externalizeHelpers = {
9092
global: "Ember",
9193
};
@@ -420,7 +422,7 @@ function _shouldIncludeDecoratorPlugins(config) {
420422
* be deduped as part of `ember-engines`. The reason this is important is because
421423
* `ember-engines` dedupe is _stateful_ so it's possible for `ember-cli-typescript`
422424
* to not be part of the addons array when `ember-cli-babel` is running.
423-
*
425+
*
424426
* For more info on `ember-engines` dedupe logic:
425427
* https://github.com/ember-engines/ember-engines/blob/master/packages/ember-engines/lib/utils/deeply-non-duplicated-addon.js#L35
426428
*

node-tests/addon-test.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,65 @@ describe('ember-cli-babel', function() {
457457
"foo.js": `define("foo", ["@ember/debug"], function (_debug) {\n "use strict";\n\n (true && !(isNotBad()) && (0, _debug.assert)('stuff here', isNotBad()));\n});`,
458458
});
459459
}));
460+
461+
it("when transpiling with compileModules: false, it should use Ember global even on Ember 3.27+", co.wrap(function* () {
462+
process.env.EMBER_ENV = 'development';
463+
464+
dependencies[
465+
"ember-source"
466+
] = POST_EMBER_MODULE_IMPORTS_VERSION;
467+
input.write(
468+
buildEmberSourceFixture(POST_EMBER_MODULE_IMPORTS_VERSION)
469+
);
470+
471+
input.write({
472+
app: {
473+
"foo.js": stripIndent`
474+
import { assert } from '@ember/debug';
475+
assert('stuff here', isNotBad());
476+
`,
477+
"bar.js": stripIndent`
478+
import { deprecate } from '@ember/debug';
479+
deprecate(
480+
'foo bar baz',
481+
false,
482+
{
483+
id: 'some-id',
484+
until: '1.0.0',
485+
}
486+
);
487+
`,
488+
"baz.js": stripIndent`
489+
import { deprecate } from '@ember/application/deprecations';
490+
deprecate(
491+
'foo bar baz',
492+
false,
493+
{
494+
id: 'some-id',
495+
until: '1.0.0',
496+
}
497+
);
498+
`,
499+
},
500+
});
501+
502+
subject = this.addon.transpileTree(input.path('app'), {
503+
'ember-cli-babel': {
504+
compileModules: false,
505+
}
506+
});
507+
output = createBuilder(subject);
508+
509+
yield output.build();
510+
511+
expect(
512+
output.read()
513+
).to.deep.equal({
514+
"bar.js": `(true && !(false) && Ember.deprecate('foo bar baz', false, {\n id: 'some-id',\n until: '1.0.0'\n}));`,
515+
"baz.js": `(true && !(false) && Ember.deprecate('foo bar baz', false, {\n id: 'some-id',\n until: '1.0.0'\n}));`,
516+
"foo.js": `(true && !(isNotBad()) && Ember.assert('stuff here', isNotBad()));`,
517+
});
518+
}));
460519
});
461520

462521
describe('in production', function() {

0 commit comments

Comments
 (0)