Skip to content

Commit 89245f9

Browse files
rwjblueef4
andcommitted
Fix combination usages of compileModules along with other flags.
The fix that landed in e20c0e4 was not quite correct. Specifically, it did not address the scenario where you explicitly set `compileModules: false` but also set other flags that relate to modules behaviors (e.g. `disableDebugTooling` or `disableEmberModulesAPIPolyfill`). This adds a number of additional tests (which emulate "real world" usage from Embroider) and ensure they pass. Co-authored-by: Edward Faulkner <edward@eaf4.com>
1 parent b704321 commit 89245f9

File tree

2 files changed

+320
-8
lines changed

2 files changed

+320
-8
lines changed

lib/babel-options-util.js

+37-8
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ function _shouldHighlightCode(parent) {
5050
function _getDebugMacroPlugins(config, project) {
5151
let addonOptions = config["ember-cli-babel"] || {};
5252

53-
if (addonOptions.disableDebugTooling) {
53+
let disableDebugTooling = addonOptions.disableDebugTooling;
54+
if (disableDebugTooling) {
5455
return;
5556
}
5657

@@ -85,21 +86,33 @@ function _getDebugMacroPlugins(config, project) {
8586
},
8687
};
8788

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)) {
89+
let useModulesVersion;
90+
91+
if (_emberVersionRequiresModulesAPIPolyfill(project)) {
92+
useModulesVersion = false;
93+
} else if (addonOptions.compileModules === false) {
94+
// we have to use the global form when not compiling modules, because it is often used
95+
// in the context of an `app.import` where there is no wrapped in an AMD module
96+
//
97+
// However, you can opt out of this behavior by explicitly specifying `disableDebugTooling`
98+
useModulesVersion = disableDebugTooling === false;
99+
} else {
100+
useModulesVersion = true;
101+
}
102+
103+
if (useModulesVersion) {
91104
emberDebugOptions.externalizeHelpers = {
92-
global: "Ember",
105+
module: "@ember/debug",
93106
};
94107
emberApplicationDeprecationsOptions.externalizeHelpers = {
95-
global: "Ember",
108+
module: "@ember/application/deprecations",
96109
};
97110
} else {
98111
emberDebugOptions.externalizeHelpers = {
99-
module: "@ember/debug",
112+
global: "Ember",
100113
};
101114
emberApplicationDeprecationsOptions.externalizeHelpers = {
102-
module: "@ember/application/deprecations",
115+
global: "Ember",
103116
};
104117
}
105118

@@ -147,7 +160,23 @@ function _getEmberModulesAPIPolyfill(config, parent, project) {
147160
return;
148161
}
149162

163+
let useModulesVersion;
164+
150165
if (_emberVersionRequiresModulesAPIPolyfill(project)) {
166+
useModulesVersion = false;
167+
} else if (addonOptions.compileModules === false) {
168+
// we have to use the global form when not compiling modules, because it is often used
169+
// in the context of an `app.import` where there is no wrapped in an AMD module
170+
//
171+
// However, you can opt out of this behavior by explicitly specifying `disableEmberModulesAPIPolyfill`
172+
useModulesVersion = addonOptions.disableEmberModulesAPIPolyfill === false;
173+
} else {
174+
useModulesVersion = true;
175+
}
176+
177+
// we have to use the global form when not compiling modules, because it is often used
178+
// in the context of an `app.import` where there is no wrapped in an AMD module
179+
if (!useModulesVersion) {
151180
const ignore = _getEmberModulesAPIIgnore(parent, project);
152181

153182
return [

node-tests/addon-test.js

+283
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,289 @@ describe('ember-cli-babel', function() {
458458
});
459459
}));
460460

461+
it("when transpiling with compileModules: false it should use Ember global for previously 'fake' imports 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 Component from '@ember/component';
475+
476+
export default class extends Component {}
477+
`,
478+
},
479+
});
480+
481+
this.addon.project.targets = {
482+
browsers: ['last 2 chrome versions']
483+
};
484+
485+
subject = this.addon.transpileTree(input.path('app'), {
486+
'ember-cli-babel': {
487+
compileModules: false,
488+
}
489+
});
490+
output = createBuilder(subject);
491+
492+
yield output.build();
493+
494+
expect(
495+
output.read()
496+
).to.deep.equal({
497+
"foo.js": `export default class extends Ember.Component {}`,
498+
});
499+
}));
500+
501+
it("when transpiling with compileModules: false, disableEmberModulesAPIPolyfill: true it should not use Ember global for previously 'fake' imports", co.wrap(function* () {
502+
process.env.EMBER_ENV = 'development';
503+
504+
dependencies[
505+
"ember-source"
506+
] = POST_EMBER_MODULE_IMPORTS_VERSION;
507+
input.write(
508+
buildEmberSourceFixture(POST_EMBER_MODULE_IMPORTS_VERSION)
509+
);
510+
511+
input.write({
512+
app: {
513+
"foo.js": stripIndent`
514+
import Component from '@ember/component';
515+
516+
export default class extends Component {}
517+
`,
518+
},
519+
});
520+
521+
this.addon.project.targets = {
522+
browsers: ['last 2 chrome versions']
523+
};
524+
525+
subject = this.addon.transpileTree(input.path('app'), {
526+
'ember-cli-babel': {
527+
compileModules: false,
528+
disableEmberModulesAPIPolyfill: true,
529+
}
530+
});
531+
output = createBuilder(subject);
532+
533+
yield output.build();
534+
535+
expect(
536+
output.read()
537+
).to.deep.equal({
538+
"foo.js": `import Component from '@ember/component';\nexport default class extends Component {}`,
539+
});
540+
}));
541+
542+
it("when transpiling with compileModules: false, disableEmberModulesAPIPolyfill: false it should use global for Ember < 3.27", co.wrap(function* () {
543+
process.env.EMBER_ENV = 'development';
544+
545+
dependencies[
546+
"ember-source"
547+
] = PRE_EMBER_MODULE_IMPORTS_VERSION;
548+
input.write(
549+
buildEmberSourceFixture(PRE_EMBER_MODULE_IMPORTS_VERSION)
550+
);
551+
552+
input.write({
553+
app: {
554+
"foo.js": stripIndent`
555+
import Component from '@ember/component';
556+
557+
export default class extends Component {}
558+
`,
559+
},
560+
});
561+
562+
this.addon.project.targets = {
563+
browsers: ['last 2 chrome versions']
564+
};
565+
566+
subject = this.addon.transpileTree(input.path('app'), {
567+
'ember-cli-babel': {
568+
compileModules: false,
569+
disableEmberModulesAPIPolyfill: false,
570+
}
571+
});
572+
output = createBuilder(subject);
573+
574+
yield output.build();
575+
576+
expect(
577+
output.read()
578+
).to.deep.equal({
579+
"foo.js": `export default class extends Ember.Component {}`,
580+
});
581+
}));
582+
583+
it("when transpiling with compileModules: false, disableEmberModulesAPIPolyfill: false it should use global for Ember > 3.27", co.wrap(function* () {
584+
process.env.EMBER_ENV = 'development';
585+
586+
dependencies[
587+
"ember-source"
588+
] = POST_EMBER_MODULE_IMPORTS_VERSION;
589+
input.write(
590+
buildEmberSourceFixture(POST_EMBER_MODULE_IMPORTS_VERSION)
591+
);
592+
593+
input.write({
594+
app: {
595+
"foo.js": stripIndent`
596+
import Component from '@ember/component';
597+
598+
export default class extends Component {}
599+
`,
600+
},
601+
});
602+
603+
this.addon.project.targets = {
604+
browsers: ['last 2 chrome versions']
605+
};
606+
607+
subject = this.addon.transpileTree(input.path('app'), {
608+
'ember-cli-babel': {
609+
compileModules: false,
610+
disableEmberModulesAPIPolyfill: false,
611+
}
612+
});
613+
output = createBuilder(subject);
614+
615+
yield output.build();
616+
617+
expect(
618+
output.read()
619+
).to.deep.equal({
620+
"foo.js": `import Component from '@ember/component';\nexport default class extends Component {}`,
621+
});
622+
}));
623+
624+
it("when transpiling with compileModules: false, disableDebugTooling: false it should use modules for debug tooling", co.wrap(function* () {
625+
process.env.EMBER_ENV = 'development';
626+
627+
dependencies[
628+
"ember-source"
629+
] = POST_EMBER_MODULE_IMPORTS_VERSION;
630+
input.write(
631+
buildEmberSourceFixture(POST_EMBER_MODULE_IMPORTS_VERSION)
632+
);
633+
634+
input.write({
635+
app: {
636+
"foo.js": stripIndent`
637+
import { assert } from '@ember/debug';
638+
assert('stuff here', isNotBad());
639+
`,
640+
"bar.js": stripIndent`
641+
import { deprecate } from '@ember/debug';
642+
deprecate(
643+
'foo bar baz',
644+
false,
645+
{
646+
id: 'some-id',
647+
until: '1.0.0',
648+
}
649+
);
650+
`,
651+
"baz.js": stripIndent`
652+
import { deprecate } from '@ember/application/deprecations';
653+
deprecate(
654+
'foo bar baz',
655+
false,
656+
{
657+
id: 'some-id',
658+
until: '1.0.0',
659+
}
660+
);
661+
`,
662+
},
663+
});
664+
665+
subject = this.addon.transpileTree(input.path('app'), {
666+
'ember-cli-babel': {
667+
compileModules: false,
668+
disableDebugTooling: false,
669+
}
670+
});
671+
output = createBuilder(subject);
672+
673+
yield output.build();
674+
675+
expect(
676+
output.read()
677+
).to.deep.equal({
678+
"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}));`,
679+
"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}));`,
680+
"foo.js": `import { assert } from '@ember/debug';\n(true && !(isNotBad()) && assert('stuff here', isNotBad()));`,
681+
});
682+
}));
683+
684+
it("when transpiling with compileModules: false, disableDebugTooling: true it should not use Ember global for debug tooling", co.wrap(function* () {
685+
process.env.EMBER_ENV = 'development';
686+
687+
dependencies[
688+
"ember-source"
689+
] = POST_EMBER_MODULE_IMPORTS_VERSION;
690+
input.write(
691+
buildEmberSourceFixture(POST_EMBER_MODULE_IMPORTS_VERSION)
692+
);
693+
694+
input.write({
695+
app: {
696+
"foo.js": stripIndent`
697+
import { assert } from '@ember/debug';
698+
assert('stuff here', isNotBad());
699+
`,
700+
"bar.js": stripIndent`
701+
import { deprecate } from '@ember/debug';
702+
deprecate(
703+
'foo bar baz',
704+
false,
705+
{
706+
id: 'some-id',
707+
until: '1.0.0',
708+
}
709+
);
710+
`,
711+
"baz.js": stripIndent`
712+
import { deprecate } from '@ember/application/deprecations';
713+
deprecate(
714+
'foo bar baz',
715+
false,
716+
{
717+
id: 'some-id',
718+
until: '1.0.0',
719+
}
720+
);
721+
`,
722+
},
723+
});
724+
725+
subject = this.addon.transpileTree(input.path('app'), {
726+
'ember-cli-babel': {
727+
compileModules: false,
728+
disableDebugTooling: true,
729+
}
730+
});
731+
output = createBuilder(subject);
732+
733+
yield output.build();
734+
735+
expect(
736+
output.read()
737+
).to.deep.equal({
738+
"bar.js": `import { deprecate } from '@ember/debug';\ndeprecate('foo bar baz', false, {\n id: 'some-id',\n until: '1.0.0'\n});`,
739+
"baz.js": `import { deprecate } from '@ember/application/deprecations';\ndeprecate('foo bar baz', false, {\n id: 'some-id',\n until: '1.0.0'\n});`,
740+
"foo.js": `import { assert } from '@ember/debug';\nassert('stuff here', isNotBad());`,
741+
});
742+
}));
743+
461744
it("when transpiling with compileModules: false, it should use Ember global even on Ember 3.27+", co.wrap(function* () {
462745
process.env.EMBER_ENV = 'development';
463746

0 commit comments

Comments
 (0)