Skip to content

Commit

Permalink
Merge pull request #393 from babel/do-not-use-globals-for-debug-macros
Browse files Browse the repository at this point in the history
Avoid global deprecation with @ember/debug on Ember 3.27+
  • Loading branch information
rwjblue committed Mar 19, 2021
2 parents d91f754 + 19010a5 commit a968f09
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 115 deletions.
82 changes: 50 additions & 32 deletions lib/babel-options-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function _shouldHighlightCode(parent) {
return checker.gte("2.1.0");
}

function _getDebugMacroPlugins(config) {
function _getDebugMacroPlugins(config, parent) {
let addonOptions = config["ember-cli-babel"] || {};

if (addonOptions.disableDebugTooling) {
Expand All @@ -56,43 +56,59 @@ function _getDebugMacroPlugins(config) {
const isProduction = process.env.EMBER_ENV === "production";
const isDebug = !isProduction;

return [
[
require.resolve("babel-plugin-debug-macros"),
const emberDebugOptions = {
flags: [
{
flags: [
{
source: "@glimmer/env",
flags: { DEBUG: isDebug, CI: !!process.env.CI },
},
],
source: "@glimmer/env",
flags: { DEBUG: isDebug, CI: !!process.env.CI },
},
],

externalizeHelpers: {
global: "Ember",
},
debugTools: {
isDebug,
source: "@ember/debug",
assertPredicateIndex: 1,
},
};

debugTools: {
isDebug,
source: "@ember/debug",
assertPredicateIndex: 1,
},
},
const emberApplicationDeprecationsOptions = {
// deprecated import path https://github.com/emberjs/ember.js/pull/17926#issuecomment-484987305
externalizeHelpers: {
global: "Ember",
},

debugTools: {
isDebug,
source: "@ember/application/deprecations",
assertPredicateIndex: 1,
},
};

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

return [
[
require.resolve("babel-plugin-debug-macros"),
emberDebugOptions,
"@ember/debug stripping",
],
[
require.resolve("babel-plugin-debug-macros"),
{
// deprecated import path https://github.com/emberjs/ember.js/pull/17926#issuecomment-484987305
externalizeHelpers: {
global: "Ember",
},

debugTools: {
isDebug,
source: "@ember/application/deprecations",
assertPredicateIndex: 1,
},
},
emberApplicationDeprecationsOptions,
"@ember/application/deprecations stripping",
],
];
Expand All @@ -103,7 +119,9 @@ function _emberVersionRequiresModulesAPIPolyfill(parent) {
if (!checker.exists()) {
return true;
}
return checker.lt("3.27.0-alpha.1");
let result = checker.lt("3.27.0-alpha.1");

return result;
}

function _emberDataVersionRequiresPackagesPolyfill(project) {
Expand Down
79 changes: 48 additions & 31 deletions lib/ember-plugins.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,68 @@
const semver = require("semver");
const resolvePackagePath = require("resolve-package-path");

function _getDebugMacroPlugins() {
function _getDebugMacroPlugins(appRoot) {
const isProduction = process.env.EMBER_ENV === "production";
const isDebug = !isProduction;

const emberDebugOptions = {
flags: [
{
source: "@glimmer/env",
flags: { DEBUG: isDebug, CI: !!process.env.CI },
},
],

debugTools: {
isDebug,
source: "@ember/debug",
assertPredicateIndex: 1,
},
};

const emberApplicationDeprecationsOptions = {
// deprecated import path https://github.com/emberjs/ember.js/pull/17926#issuecomment-484987305
externalizeHelpers: {
global: "Ember",
},

debugTools: {
isDebug,
source: "@ember/application/deprecations",
assertPredicateIndex: 1,
},
};

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

return [
[
require.resolve("babel-plugin-debug-macros"),
{
flags: [
{
source: "@glimmer/env",
flags: { DEBUG: isDebug, CI: !!process.env.CI },
},
],

externalizeHelpers: {
global: "Ember",
},

debugTools: {
isDebug,
source: "@ember/debug",
assertPredicateIndex: 1,
},
},
emberDebugOptions,
"@ember/debug stripping",
],
[
require.resolve("babel-plugin-debug-macros"),
{
// deprecated import path https://github.com/emberjs/ember.js/pull/17926#issuecomment-484987305
externalizeHelpers: {
global: "Ember",
},

debugTools: {
isDebug,
source: "@ember/application/deprecations",
assertPredicateIndex: 1,
},
},
emberApplicationDeprecationsOptions,
"@ember/application/deprecations stripping",
],
];
}

function _emberVersionRequiresModulesAPIPolyfill(appRoot) {
let packagePath = resolvePackagePath("ember-source", appRoot);
if (packagePath === null) {
Expand Down
2 changes: 1 addition & 1 deletion lib/get-babel-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module.exports = function getBabelOptions(config, appInstance) {
.concat(
shouldIncludeHelpers && _getHelpersPlugin(project),
userPlugins,
_getDebugMacroPlugins(config),
_getDebugMacroPlugins(config, parent),
_getEmberModulesAPIPolyfill(config, parent, project),
_getEmberDataPackagesPolyfill(config, parent),
_shouldCompileModules(config, project) && _getModulesPlugin(),
Expand Down
Loading

0 comments on commit a968f09

Please sign in to comment.