diff --git a/index.js b/index.js index 8559114c..1c6ec9a0 100644 --- a/index.js +++ b/index.js @@ -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'), + { + // 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()) { diff --git a/node-tests/addon-test.js b/node-tests/addon-test.js index 77d41363..ad67b21f 100644 --- a/node-tests/addon-test.js +++ b/node-tests/addon-test.js @@ -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});`, }); })); });