Skip to content

Commit b2ddf09

Browse files
ef4mansona
authored andcommitted
Never emit Ember global on ember versions that don't support it
For bad historic reasons, if you disable AMD compilation with `compileModules: false`, it opts you into the using the `Ember` global via modulesAPIPolyfill and debug-macros. This is a problem because we absolutely *do* want to disable AMD compilation as we move toward [strict-es-modules](emberjs/rfcs#938), but the Ember global has been gone since 4.0. It's possible to work around the modulesAPIPolyfill issue by explicitly turning the polyfill off. But it's impossible to work around the debug-macros problem, because we don't want to turn them off, we want to keep them on but tell them to use imports instead of globals. In both cases, it's a bad default that emits code that could never possibly work. This PR makes Ember 4.0 the hard cutoff, after which we will never emit globals, because they don't work there anyway.
1 parent f51470d commit b2ddf09

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

lib/babel-options-util.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,9 @@ function _getDebugMacroPlugins(config, project) {
9191

9292
if (_emberVersionRequiresModulesAPIPolyfill(project)) {
9393
useModulesVersion = false;
94-
} else if (addonOptions.compileModules === false) {
94+
} else if (addonOptions.compileModules === false && _emberVersionSupportsEmberGlobal(project)) {
9595
// we have to use the global form when not compiling modules, because it is often used
9696
// in the context of an `app.import` where there is no wrapped in an AMD module
97-
//
98-
// However, you can opt out of this behavior by explicitly specifying `disableDebugTooling`
9997
useModulesVersion = disableDebugTooling === false;
10098
} else {
10199
useModulesVersion = true;
@@ -141,6 +139,16 @@ function _emberVersionRequiresModulesAPIPolyfill(project) {
141139
return result;
142140
}
143141

142+
function _emberVersionSupportsEmberGlobal(project) {
143+
let checker = new VersionChecker(project).for("ember-source", "npm");
144+
if (!checker.exists()) {
145+
return true;
146+
}
147+
let result = checker.lt("4.0.0-alpha.1");
148+
149+
return result;
150+
}
151+
144152
function _emberDataVersionRequiresPackagesPolyfill(project) {
145153
let checker = new VersionChecker(project);
146154
let dep = checker.for("ember-data");
@@ -165,7 +173,7 @@ function _getEmberModulesAPIPolyfill(config, parent, project) {
165173

166174
if (_emberVersionRequiresModulesAPIPolyfill(project)) {
167175
useModulesVersion = false;
168-
} else if (addonOptions.compileModules === false) {
176+
} else if (addonOptions.compileModules === false && _emberVersionSupportsEmberGlobal(project)) {
169177
// we have to use the global form when not compiling modules, because it is often used
170178
// in the context of an `app.import` where there is no wrapped in an AMD module
171179
//

0 commit comments

Comments
 (0)