Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 6 commits into from
Jun 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 47 additions & 24 deletions index.js
Original file line number Diff line number Diff line change
@@ -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']
}
@@ -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']
@@ -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']
@@ -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'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

running the same plugin twice seems unfortunate, can the primary plugin simply be taught how to handle this case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already support arbitrary module paths with flags, but not with debugTools. We can definitely update babel-plugin-debug-macros to support that though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

investigating

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue seems to have been a monorepo with a shared lockfile resulted in an incomplete semver drift of relevant dependencies, upgrading all repos contained within the monorepo fixed the issues.

{
// 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) {
@@ -492,6 +514,7 @@ module.exports = {
_getEmberModulesAPIBlacklist() {
const blacklist = {
'@ember/debug': ['assert', 'deprecate', 'warn'],
'@ember/application/deprecations': ['deprecate'],
};

if (this._shouldBlacklistEmberString()) {
53 changes: 51 additions & 2 deletions node-tests/addon-test.js
Original file line number Diff line number Diff line change
@@ -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';`
@@ -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());
@@ -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});`,
});
}));
});