Skip to content

Commit

Permalink
Ensure @ember/application/deprecations is stripped in addition to `…
Browse files Browse the repository at this point in the history
…@ember/debug`. (#286)

Ensure `@ember/application/deprecations` is stripped in addition to `@ember/debug`.

Co-authored-by: Robert Jackson <[email protected]>
  • Loading branch information
rwjblue authored Jun 17, 2019
2 parents 47a72eb + f74305f commit 61f65e7
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 26 deletions.
71 changes: 47 additions & 24 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,8 @@ module.exports = {
}
} else {
addPlugin(
plugins,
[require.resolve('@babel/plugin-proposal-decorators'), { legacy: true }],
plugins,
[require.resolve('@babel/plugin-proposal-decorators'), { legacy: true }],
{
before: ['@babel/plugin-proposal-class-properties', '@babel/plugin-transform-typescript']
}
Expand All @@ -354,8 +354,8 @@ module.exports = {
}
} else {
addPlugin(
plugins,
[require.resolve('@babel/plugin-proposal-class-properties'), { loose: true }],
plugins,
[require.resolve('@babel/plugin-proposal-class-properties'), { loose: true }],
{
after: ['@babel/plugin-proposal-decorators'],
before: ['@babel/plugin-transform-typescript']
Expand All @@ -368,7 +368,7 @@ module.exports = {

if (checker.lt('3.0.0')) {
addPlugin(
plugins,
plugins,
require.resolve('./lib/dedupe-internal-decorators-plugin'),
{
after: ['babel-plugin-filter-imports']
Expand All @@ -383,31 +383,53 @@ module.exports = {
_getDebugMacroPlugins(config) {
let addonOptions = config['ember-cli-babel'] || {};

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

const isProduction = process.env.EMBER_ENV === 'production';
const isDebug = !isProduction;

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

externalizeHelpers: {
global: 'Ember',
},

debugTools: {
isDebug,
source: '@ember/debug',
assertPredicateIndex: 1,
},
},
'@ember/debug stripping',
],

externalizeHelpers: {
global: 'Ember'
},

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

return [[require.resolve('babel-plugin-debug-macros'), options]];
[
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,
},
},
'@ember/application/deprecations stripping',
],
];
},

_getEmberModulesAPIPolyfill(config) {
Expand Down Expand Up @@ -492,6 +514,7 @@ module.exports = {
_getEmberModulesAPIBlacklist() {
const blacklist = {
'@ember/debug': ['assert', 'deprecate', 'warn'],
'@ember/application/deprecations': ['deprecate'],
};

if (this._shouldBlacklistEmberString()) {
Expand Down
53 changes: 51 additions & 2 deletions node-tests/addon-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,31 @@ describe('ember-cli-babel', function() {
}));

describe('ember modules API polyfill', function() {
it("does not transpile deprecate debug tooling import paths", co.wrap(function* () {
input.write({
"foo.js": `import { deprecate } from '@ember/debug';\ndeprecate('some message', false, {\n id: 'special-thing',\n until: '1.0.0'\n});`,
"bar.js": `import { deprecate } from '@ember/application/deprecations';\ndeprecate('some message', false, {\n id: 'special-thing',\n until: '1.0.0'\n});`,
});

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

output = createBuilder(subject);

yield output.build();

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

it("can opt-out via ember-cli-babel.disableEmberModulesAPIPolyfill", co.wrap(function* () {
input.write({
"foo.js": `import Component from '@ember/component';`
Expand Down Expand Up @@ -229,7 +254,29 @@ describe('ember-cli-babel', function() {
"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());
Expand All @@ -240,7 +287,9 @@ describe('ember-cli-babel', function() {
expect(
output.read()
).to.deep.equal({
"foo.js": `define("foo", [], function () {\n "use strict";\n\n (true && !(isNotBad()) && Ember.assert('stuff here', isNotBad()));\n});`
"bar.js": `define("bar", [], function () {\n "use strict";\n\n (true && !(false) && Ember.deprecate('foo bar baz', false, {\n id: 'some-id',\n until: '1.0.0'\n }));\n});`,
"baz.js": `define("baz", [], function () {\n "use strict";\n\n (true && !(false) && Ember.deprecate('foo bar baz', false, {\n id: 'some-id',\n until: '1.0.0'\n }));\n});`,
"foo.js": `define("foo", [], function () {\n "use strict";\n\n (true && !(isNotBad()) && Ember.assert('stuff here', isNotBad()));\n});`,
});
}));
});
Expand Down

0 comments on commit 61f65e7

Please sign in to comment.