From 02af02546a05cd372bf53033318f65af7b544023 Mon Sep 17 00:00:00 2001 From: Christopher Garrett Date: Wed, 7 Nov 2018 14:58:37 -0800 Subject: [PATCH] [BUGFIX beta][FEAT] Adds a second dist build which targets IE This PR adds a second dist to the build which targets IE. This allows the primary bundles to drop ES5 compilation from babel, and allows us to choose which bundles we want to use based on the consuming application's targets. In the long run, we want to actually enable consuming apps to build the Ember source code themselves. This is a temporary in-between measure to address a bug in native classes, in which users who do _not_ have IE as a build target cannot `.extend` from native classes due to conflicts in transpilation vs actual native class syntax. --- .travis.yml | 4 +- bin/run-tests.js | 13 + broccoli/babel-helpers.js | 11 +- broccoli/bootstrap-modules.js | 26 +- broccoli/debug-macros.js | 43 +++ broccoli/deprecated-features.js | 4 - broccoli/strip-for-prod.js | 11 + broccoli/to-es5.js | 79 +---- broccoli/to-named-amd.js | 16 +- broccoli/transforms/strip-class-call-check.js | 87 ------ ember-cli-build.js | 287 ++++++++---------- lib/index.js | 34 ++- package.json | 13 +- .../lib/external-helpers-prod.js | 42 --- ...nal-helpers-dev.js => external-helpers.js} | 24 +- testem.dist.js | 2 +- tests/index.html | 21 +- yarn.lock | 65 ++-- 18 files changed, 331 insertions(+), 451 deletions(-) create mode 100644 broccoli/debug-macros.js create mode 100644 broccoli/strip-for-prod.js delete mode 100644 broccoli/transforms/strip-class-call-check.js delete mode 100644 packages/external-helpers/lib/external-helpers-prod.js rename packages/external-helpers/lib/{external-helpers-dev.js => external-helpers.js} (72%) diff --git a/.travis.yml b/.travis.yml index 57f3570a6d9..f5b64e46343 100644 --- a/.travis.yml +++ b/.travis.yml @@ -78,7 +78,9 @@ jobs: - stage: additional tests - env: TEST_SUITE=browserstack + env: + - TEST_SUITE=browserstack + - EMBER_ENV=production - env: - TEST_SUITE=built-tests - EMBER_ENV=production diff --git a/bin/run-tests.js b/bin/run-tests.js index abeb6ad3208..74f23337f52 100755 --- a/bin/run-tests.js +++ b/bin/run-tests.js @@ -88,6 +88,7 @@ function generateBuiltTests() { // Container isn't publicly available. // ember-testing and @ember/debug are stripped from prod/min. var common = 'skipPackage=container,ember-testing,@ember/debug'; + testFunctions.push(function() { return run(common + '&nolint=true'); }); @@ -100,6 +101,18 @@ function generateBuiltTests() { testFunctions.push(function() { return run(common + '&enableoptionalfeatures=true&dist=prod&prod=true'); }); + testFunctions.push(function() { + return run(common + '&ie=true&nolint=true'); + }); + testFunctions.push(function() { + return run(common + '&ie=true&dist=min&prod=true'); + }); + testFunctions.push(function() { + return run(common + '&ie=true&dist=prod&prod=true'); + }); + testFunctions.push(function() { + return run(common + '&ie=true&enableoptionalfeatures=true&dist=prod&prod=true'); + }); } function generateOldJQueryTests() { diff --git a/broccoli/babel-helpers.js b/broccoli/babel-helpers.js index 324e979c280..9d4818114f0 100644 --- a/broccoli/babel-helpers.js +++ b/broccoli/babel-helpers.js @@ -2,16 +2,9 @@ const Funnel = require('broccoli-funnel'); -module.exports = function(env) { - let file; - if (env === 'debug') { - file = 'external-helpers-dev.js'; - } else if (env === 'prod') { - file = 'external-helpers-prod.js'; - } - +module.exports = function() { return new Funnel('packages/external-helpers/lib', { - files: [file], + files: ['external-helpers.js'], getDestinationPath() { return 'ember-babel.js'; }, diff --git a/broccoli/bootstrap-modules.js b/broccoli/bootstrap-modules.js index ebc88b2ca9b..5baee1e18cd 100644 --- a/broccoli/bootstrap-modules.js +++ b/broccoli/bootstrap-modules.js @@ -1,10 +1,7 @@ 'use strict'; const WriteFile = require('broccoli-file-creator'); - -function defaultExport(moduleExport) { - return `(function (m) { if (typeof module === "object" && module.exports) { module.exports = m } }(requireModule('${moduleExport}').default));\n`; -} +const { stripIndent } = require('common-tags'); function sideeffects(moduleExport) { return `requireModule('${moduleExport}')`; @@ -14,11 +11,26 @@ function umd(moduleExport) { return `(function (m) { if (typeof module === "object" && module.exports) { module.exports = m } }(requireModule('${moduleExport}')));\n`; } -module.exports = function bootstrapModule(moduleExport, type = 'sideeffects') { +function testing() { + return stripIndent` + var testing = requireModule('ember-testing'); + Ember.Test = testing.Test; + Ember.Test.Adapter = testing.Adapter; + Ember.Test.QUnitAdapter = testing.QUnitAdapter; + Ember.setupForTesting = testing.setupForTesting; + `; +} + +function empty() { + return ''; +} + +module.exports = function bootstrapModule(type, moduleExport) { let moduleType = { - default: defaultExport, - umd, + empty, sideeffects, + testing, + umd, }; return new WriteFile('bootstrap', moduleType[type](moduleExport)); diff --git a/broccoli/debug-macros.js b/broccoli/debug-macros.js new file mode 100644 index 00000000000..6b250d26cdd --- /dev/null +++ b/broccoli/debug-macros.js @@ -0,0 +1,43 @@ +'use strict'; + +const Babel = require('broccoli-babel-transpiler'); +const FEATURES = require('./features'); + +module.exports = function debugMacros(tree, environment) { + let isDebug = environment !== 'production'; + + let plugins = [ + [ + 'debug-macros', + { + debugTools: { + source: '@ember/debug', + assertPredicateIndex: 1, + isDebug, + }, + externalizeHelpers: { + module: true, + }, + flags: [ + { source: '@glimmer/env', flags: { DEBUG: isDebug } }, + { + source: '@ember/canary-features', + flags: Object.assign( + // explicit list of additional exports within @ember/canary-features + // without adding this (with a null value) an error is thrown during + // the feature replacement process (e.g. XYZ is not a supported flag) + { + FEATURES: null, + DEFAULT_FEATURES: null, + isEnabled: null, + }, + FEATURES + ), + }, + ], + }, + ], + ]; + + return new Babel(tree, { plugins }); +}; diff --git a/broccoli/deprecated-features.js b/broccoli/deprecated-features.js index fbadc01d156..0da8a6a7d41 100644 --- a/broccoli/deprecated-features.js +++ b/broccoli/deprecated-features.js @@ -93,10 +93,6 @@ function svelte(infile, outfile) { ], }); - code = babel.transform(code, { - plugins: ['minify-dead-code-elimination'], - }).code; - fs.writeFileSync(outfile, code); } diff --git a/broccoli/strip-for-prod.js b/broccoli/strip-for-prod.js new file mode 100644 index 00000000000..8e5f16214c2 --- /dev/null +++ b/broccoli/strip-for-prod.js @@ -0,0 +1,11 @@ +'use strict'; + +const Babel = require('broccoli-babel-transpiler'); + +module.exports = function stripForProd(tree) { + let options = { + plugins: [['filter-imports', { imports: { 'ember-babel': ['_classCallCheck'] } }]], + }; + + return new Babel(tree, options); +}; diff --git a/broccoli/to-es5.js b/broccoli/to-es5.js index 93c9b574d84..87d5efac4a0 100644 --- a/broccoli/to-es5.js +++ b/broccoli/to-es5.js @@ -2,57 +2,13 @@ const Babel = require('broccoli-babel-transpiler'); const injectBabelHelpers = require('./transforms/inject-babel-helpers'); -const injectNodeGlobals = require('./transforms/inject-node-globals'); -const enifed = require('./transforms/transform-define'); -const FEATURES = require('./features'); -const stripClassCallCheck = require('./transforms/strip-class-call-check'); -const resolveModuleSource = require('amd-name-resolver').moduleResolve; -module.exports = function toES5(tree, _options) { - let options = Object.assign( - { - environment: 'developement', - }, - _options - ); +module.exports = function toES6(tree, _options) { + let options = Object.assign({}, _options); - let isDebug = options.environment !== 'production'; - - options.moduleIds = true; - options.resolveModuleSource = resolveModuleSource; options.sourceMap = true; options.plugins = [ injectBabelHelpers, - [ - 'debug-macros', - { - debugTools: { - source: '@ember/debug', - assertPredicateIndex: 1, - isDebug, - }, - externalizeHelpers: { - module: true, - }, - flags: [ - { source: '@glimmer/env', flags: { DEBUG: isDebug } }, - { - source: '@ember/canary-features', - flags: Object.assign( - // explicit list of additional exports within @ember/canary-features - // without adding this (with a null value) an error is thrown during - // the feature replacement process (e.g. XYZ is not a supported flag) - { - FEATURES: null, - DEFAULT_FEATURES: null, - isEnabled: null, - }, - FEATURES - ), - }, - ], - }, - ], ['transform-es2015-template-literals', { loose: true }], ['transform-es2015-literals'], ['transform-es2015-arrow-functions'], @@ -65,43 +21,12 @@ module.exports = function toES5(tree, _options) { ['check-es2015-constants'], ['transform-es2015-classes', { loose: true }], ['transform-object-assign'], - injectNodeGlobals, - ['transform-es2015-modules-amd', { noInterop: true, strict: true }], - enifed, ]; - if (options.transformDefine) { - options.plugins = [enifed]; - delete options.transformDefine; - } - - if (options.transformModules === false) { - options.plugins.pop(); - options.plugins.pop(); - delete options.moduleIds; - delete options.resolveModuleSource; - delete options.transformModules; - } - if (options.inlineHelpers) { options.plugins.shift(); delete options.inlineHelpers; } - delete options.environment; - return new Babel(tree, options); }; - -function stripForProd(tree) { - let options = { - plugins: [ - [stripClassCallCheck, { source: 'ember-babel' }], - ['minify-dead-code-elimination', { optimizeRawSize: true }], - ], - }; - - return new Babel(tree, options); -} - -module.exports.stripForProd = stripForProd; diff --git a/broccoli/to-named-amd.js b/broccoli/to-named-amd.js index ba11134712d..da58fcb549a 100644 --- a/broccoli/to-named-amd.js +++ b/broccoli/to-named-amd.js @@ -3,18 +3,28 @@ const resolveModuleSource = require('amd-name-resolver').moduleResolve; const enifed = require('./transforms/transform-define'); const injectNodeGlobals = require('./transforms/inject-node-globals'); -module.exports = function processModulesOnly(tree, annotation) { +module.exports = function processModulesOnly(tree, strict = false) { + let transformOptions = { noInterop: true }; + + // These options need to be exclusive for some reason, even the key existing + // on the options hash causes issues. + if (strict) { + transformOptions.strict = true; + } else { + transformOptions.loose = true; + } + let options = { + sourceMap: true, plugins: [ // ensures `@glimmer/compiler` requiring `crypto` works properly // in both browser and node-land injectNodeGlobals, - ['transform-es2015-modules-amd', { loose: true, noInterop: true }], + ['transform-es2015-modules-amd', transformOptions], enifed, ], moduleIds: true, resolveModuleSource, - annotation, }; return new Babel(tree, options); diff --git a/broccoli/transforms/strip-class-call-check.js b/broccoli/transforms/strip-class-call-check.js deleted file mode 100644 index 57810ed278a..00000000000 --- a/broccoli/transforms/strip-class-call-check.js +++ /dev/null @@ -1,87 +0,0 @@ -// TODO there are like 3 things that do this -'use strict'; - -function stripClassCallCheck({ traverse }) { - return { - name: 'remove classCallCheck', - visitor: { - Program: { - enter(path, state) { - let [amd] = path.get('body'); - - if (!amd) { - return; - } - - let [, deps, callBack] = amd.get('expression.arguments'); - let params = callBack.get('params'); - let elements = deps.get('elements'); - - for (let i = 0; i < elements.length; i++) { - let el = elements[i]; - if (el.node.value === state.opts.source) { - this.binding = params[i]; - this.index = i; - break; - } - } - }, - exit(path) { - if (!this.binding) { - return; - } - - traverse.clearCache(); - path.scope.crawl(); - - let [amd] = path.get('body'); - let [, deps, callBack] = amd.get('expression.arguments'); - let binding = callBack.scope.bindings[this.binding.node.name]; - let elements = deps.get('elements'); - if (binding.referencePaths.length === 0) { - this.binding.remove(); - elements[this.index].remove(); - } - }, - }, - - CallExpression(path) { - let callee = path.get('callee'); - - if (!this.binding) { - return; - } - - if (callee.isSequenceExpression()) { - let [, member] = callee.get('expressions'); - - if ( - member.node.object.name === this.binding.node.name && - member.node.property.name.indexOf('classCallCheck') > -1 - ) { - path.remove(); - } - } - - if (callee.isMemberExpression()) { - if ( - callee.node.object.name === this.binding.node.name && - callee.node.property.name.indexOf('classCallCheck') > -1 - ) { - path.remove(); - } - } - }, - }, - }; -} - -stripClassCallCheck.baseDir = function() { - return 'babel-core'; -}; - -stripClassCallCheck.cacheKey = function() { - return stripClassCallCheck.toString(); -}; - -module.exports = stripClassCallCheck; diff --git a/ember-cli-build.js b/ember-cli-build.js index fc23687d102..07110c2ed64 100644 --- a/ember-cli-build.js +++ b/ember-cli-build.js @@ -10,10 +10,10 @@ const concat = require('broccoli-concat'); const testIndexHTML = require('./broccoli/test-index-html'); const toES5 = require('./broccoli/to-es5'); const toNamedAMD = require('./broccoli/to-named-amd'); -const stripForProd = toES5.stripForProd; +const stripForProd = require('./broccoli/strip-for-prod'); +const debugMacros = require('./broccoli/debug-macros'); const minify = require('./broccoli/minify'); const rename = require('./broccoli/rename'); -const { stripIndent } = require('common-tags'); const { routerES, jquery, @@ -38,7 +38,6 @@ const ENV = process.env.EMBER_ENV || 'development'; module.exports = function() { let loader = internalLoader(); let nodeModule = nodeModuleUtils(); - let license = emberLicense(); // generate "loose" ES modules... let dependenciesES = new MergeTrees([ @@ -63,6 +62,9 @@ module.exports = function() { // packages/** (after typescript compilation) getPackagesES(), + + // externalized helpers + babelHelpers(), ]); let es = new MergeTrees([packagesES, dependenciesES, templateCompilerDependenciesES], { @@ -80,12 +82,8 @@ module.exports = function() { } ); - let babelDebugHelpersES5 = toES5(babelHelpers('debug'), { - annotation: 'babel helpers debug', - }); - // Rollup - let packagesESRollup = new MergeTrees([ + let packagesRollupES = new MergeTrees([ new Funnel(packagesES, { exclude: [ '@ember/-internals/browser-environment/index.js', @@ -110,35 +108,51 @@ module.exports = function() { rollupPackage(packagesES, '@ember/-internals/container'), ]); - // ES5 - let packagesES5 = toES5(packagesESRollup); - let dependenciesES5 = toES5(dependenciesES); - let templateCompilerDependenciesES5 = toES5(templateCompilerDependenciesES); - // Bundling - let emberTestsBundle = new MergeTrees([ - new Funnel(packagesES5, { - include: [ - 'internal-test-helpers/**', - '@ember/-internals/*/tests/**' /* internal packages */, - '*/*/tests/**' /* scoped packages */, - '*/tests/**' /* packages */, - 'license.js', - ], - }), - loader, - license, - nodeModule, - babelDebugHelpersES5, - ]); + let bundleTrees = [ + buildBundles(packagesRollupES, dependenciesES, templateCompilerDependenciesES), + ]; + + if (ENV === 'production') { + let bundlesES5 = buildBundles( + toES5(packagesRollupES), + toES5(dependenciesES), + toES5(templateCompilerDependenciesES) + ); - emberTestsBundle = concatBundle(emberTestsBundle, { - outputFile: 'ember-tests.js', - hasBootstrap: false, + bundleTrees.push(new Funnel(bundlesES5, { destDir: 'ie' })); + } + + let emberTestsEmptyTestem = new Funnel('tests', { + files: ['testem.js'], + destDir: '', + annotation: 'tests/testem.js', }); - let emberDebugBundle = new MergeTrees([ - new Funnel(packagesES5, { + return new MergeTrees([ + new Funnel(es, { destDir: 'es' }), + ...bundleTrees, + pkgAndTestESBundleDebug, + emberTestsEmptyTestem, + nodeTests(), + + // test harness + testIndexHTML(), + jquery(), + qunit(), + ]); +}; + +function buildBundles(packagesES, dependenciesES, templateCompilerDependenciesES) { + let packagesDevES = debugMacros(packagesES, 'development'); + let dependenciesDevES = debugMacros(dependenciesES, 'development'); + let templateCompilerDependenciesDevES = debugMacros( + templateCompilerDependenciesES, + 'development' + ); + + let emberDebugFiles = new MergeTrees([ + new Funnel(packagesDevES, { exclude: [ '@ember/-internals/*/tests/**' /* internal packages */, '*/*/tests/**' /* scoped packages */, @@ -147,20 +161,25 @@ module.exports = function() { 'internal-test-helpers/**', ], }), - dependenciesES5, - loader, - license, - nodeModule, - bootstrapModule('ember'), - babelDebugHelpersES5, + dependenciesDevES, + bootstrapModule('sideeffects', 'ember'), ]); - emberDebugBundle = concatBundle(emberDebugBundle, { - outputFile: 'ember.debug.js', - }); + let emberTestsFiles = new MergeTrees([ + new Funnel(packagesDevES, { + include: [ + 'internal-test-helpers/**', + '@ember/-internals/*/tests/**' /* internal packages */, + '*/*/tests/**' /* scoped packages */, + '*/tests/**' /* packages */, + 'license.js', + ], + }), + bootstrapModule('empty'), + ]); - let emberTestingBundle = new MergeTrees([ - new Funnel(packagesES5, { + let emberTestingFiles = new MergeTrees([ + new Funnel(packagesDevES, { include: [ '@ember/debug/lib/**', '@ember/debug/index.js', @@ -169,56 +188,38 @@ module.exports = function() { 'license.js', ], }), - loader, - license, - babelDebugHelpersES5, - nodeModule, + bootstrapModule('testing'), ]); - emberTestingBundle = concatBundle(emberTestingBundle, { - outputFile: 'ember-testing.js', - hasBootstrap: false, - footer: stripIndent` - var testing = requireModule('ember-testing'); - Ember.Test = testing.Test; - Ember.Test.Adapter = testing.Adapter; - Ember.Test.QUnitAdapter = testing.QUnitAdapter; - Ember.setupForTesting = testing.setupForTesting; - `, - }); - - function templateCompiler() { - return new MergeTrees([ - new Funnel(packagesES5, { - include: [ - '@ember/-internals/utils.js', - '@ember/-internals/environment.js', - '@ember/-internals/browser-environment.js', - '@ember/canary-features/**', - '@ember/debug/index.js', - '@ember/debug/lib/**', - '@ember/deprecated-features/**', - '@ember/error/index.js', - '@ember/polyfills/index.js', - '@ember/polyfills/lib/**', - 'ember/version.js', - 'ember-template-compiler/**', - ], - }), - bootstrapModule('ember-template-compiler', 'umd'), - ]); - } + let templateCompilerFiles = new MergeTrees([ + new Funnel(packagesDevES, { + include: [ + '@ember/-internals/utils.js', + '@ember/-internals/environment.js', + '@ember/-internals/browser-environment.js', + '@ember/canary-features/**', + '@ember/debug/index.js', + '@ember/debug/lib/**', + '@ember/deprecated-features/**', + '@ember/error/index.js', + '@ember/polyfills/index.js', + '@ember/polyfills/lib/**', + 'ember/version.js', + 'ember-template-compiler/**', + ], + }), + templateCompilerDependenciesDevES, + bootstrapModule('umd', 'ember-template-compiler'), + ]); - let trees = []; + let emberProdFiles, emberTestsProdFiles; if (ENV === 'production') { - let prodPackagesES5 = stripForProd(toES5(packagesESRollup, { environment: 'production' })); - let babelProdHelpersES5 = toES5(babelHelpers('prod'), { - environment: 'production', - }); + let packagesProdES = stripForProd(debugMacros(packagesES, 'production')); + let dependenciesProdES = stripForProd(debugMacros(dependenciesES, 'production')); - let emberProdBundle = new MergeTrees([ - new Funnel(prodPackagesES5, { + emberProdFiles = new MergeTrees([ + new Funnel(packagesProdES, { exclude: [ '@ember/-internals/*/tests/**' /* internal packages */, '*/*/tests/**' /* scoped packages */, @@ -228,27 +229,12 @@ module.exports = function() { 'internal-test-helpers/**', ], }), - stripForProd(dependenciesES5), - loader, - license, - nodeModule, - bootstrapModule('ember'), - babelProdHelpersES5, + dependenciesProdES, + bootstrapModule('sideeffects', 'ember'), ]); - emberProdBundle = concatBundle(emberProdBundle, { - outputFile: 'ember.prod.js', - }); - trees.push(emberProdBundle); - - let emberProdMinRename = rename(emberProdBundle, { - 'ember.prod.js': 'ember.min.js', - }); - let emberMinBundle = minify(emberProdMinRename); - trees.push(emberMinBundle); - - let emberTestsBundle = new MergeTrees([ - new Funnel(prodPackagesES5, { + emberTestsProdFiles = new MergeTrees([ + new Funnel(packagesProdES, { include: [ 'internal-test-helpers/**', '*/*/tests/**' /* scoped packages */, @@ -256,73 +242,44 @@ module.exports = function() { 'license.js', ], }), - loader, - license, - nodeModule, - babelProdHelpersES5, + bootstrapModule('empty'), ]); - emberTestsBundle = concatBundle(emberTestsBundle, { - outputFile: 'ember-tests.prod.js', - hasBootstrap: false, - }); - trees.push(emberTestsBundle); - // Note: // We have to build custom production template compiler // because we strip babel helpers in the prod build - let emberTemplateCompilerBundle = new MergeTrees([ - stripForProd(templateCompiler()), - stripForProd(templateCompilerDependenciesES5), - loader, - license, - babelProdHelpersES5, - nodeModule, - ]); - - emberTemplateCompilerBundle = concatBundle(emberTemplateCompilerBundle, { - outputFile: 'ember-template-compiler.js', - }); - trees.push(emberTemplateCompilerBundle); - } else { - let emberTemplateCompilerBundle = new MergeTrees([ - templateCompiler(), - templateCompilerDependenciesES5, - loader, - license, - babelDebugHelpersES5, - nodeModule, - ]); - - emberTemplateCompilerBundle = concatBundle(emberTemplateCompilerBundle, { - outputFile: 'ember-template-compiler.js', - }); - - trees.push(emberTemplateCompilerBundle); + templateCompilerFiles = stripForProd(templateCompilerFiles); } - let emberTestsEmptyTestem = new Funnel('tests', { - files: ['testem.js'], - destDir: '', - annotation: 'tests/testem.js', - }); + // Files that are prebuilt and should not be AMD transformed + let vendor = [internalLoader(), nodeModuleUtils(), emberLicense()]; + + let emberProdBundle = emberProdFiles && buildBundle('ember.prod.js', emberProdFiles, vendor); + let emberMinBundle = + emberProdBundle && minify(rename(emberProdBundle, { 'ember.prod.js': 'ember.min.js' })); + let emberProdTestsBundle = + emberTestsProdFiles && buildBundle('ember-tests.prod.js', emberTestsProdFiles, vendor); + + return new MergeTrees( + [ + emberProdBundle, + emberMinBundle, + emberProdTestsBundle, + buildBundle('ember.debug.js', emberDebugFiles, vendor), + buildBundle('ember-tests.js', emberTestsFiles, vendor), + buildBundle('ember-testing.js', emberTestingFiles, vendor), + buildBundle('ember-template-compiler.js', templateCompilerFiles, vendor), + ].filter(Boolean) + ); +} - return new MergeTrees([ - new Funnel(es, { destDir: 'es' }), - pkgAndTestESBundleDebug, - ...trees, - emberTestsBundle, - emberDebugBundle, - emberTestingBundle, - emberTestsEmptyTestem, - nodeTests(), +function buildBundle(name, tree, extras) { + let bundleWithExtras = new MergeTrees([toNamedAMD(tree, true), ...extras]); - // test harness - testIndexHTML(), - jquery(), - qunit(), - ]); -}; + return concatBundle(bundleWithExtras, { + outputFile: name, + }); +} function glimmerDependenciesES() { let glimmerEntries = ['@glimmer/node', '@glimmer/opcode-compiler', '@glimmer/runtime']; diff --git a/lib/index.js b/lib/index.js index 2b446d94434..31d7f7a25c4 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,11 +1,12 @@ 'use strict'; -var fs = require('fs'); -var path = require('path'); -var resolve = require('resolve'); +const fs = require('fs'); +const path = require('path'); +const resolve = require('resolve'); +const browserslist = require('browserslist'); -var paths = {}; -var absolutePaths = {}; +const paths = {}; +const absolutePaths = {}; function add(paths, name, path) { Object.defineProperty(paths, name, { @@ -49,10 +50,10 @@ module.exports = { absolutePaths: absolutePaths, treeForVendor: function() { - var Funnel = require('broccoli-funnel'); - var MergeTrees = require('broccoli-merge-trees'); + let Funnel = require('broccoli-funnel'); + let MergeTrees = require('broccoli-merge-trees'); - var jqueryPath; + let jqueryPath; try { jqueryPath = path.dirname( resolve.sync('jquery/package.json', { basedir: this.project.root }) @@ -61,13 +62,22 @@ module.exports = { jqueryPath = path.dirname(require.resolve('jquery/package.json')); } - var jquery = new Funnel(jqueryPath + '/dist', { + let jquery = new Funnel(jqueryPath + '/dist', { destDir: 'ember/jquery', files: ['jquery.js'], }); let emberSourceDistPath = path.join(__dirname, '..', 'dist'); - var emberFiles = [ + + if (this.project.targets) { + let browsers = browserslist(this.project.targets.browsers); + + if (browsers.find(browser => browser.startsWith('ie'))) { + emberSourceDistPath = path.join(emberSourceDistPath, 'ie'); + } + } + + let emberFiles = [ 'ember-template-compiler.js', 'ember-testing.js', 'ember.debug.js', @@ -81,12 +91,12 @@ module.exports = { return flat.concat(jsAndMap); }, []) .filter(function(file) { - var fullPath = path.join(emberSourceDistPath, file); + let fullPath = path.join(emberSourceDistPath, file); return fs.existsSync(fullPath); }); - var ember = new Funnel(emberSourceDistPath, { + let ember = new Funnel(emberSourceDistPath, { destDir: 'ember', files: emberFiles, }); diff --git a/package.json b/package.json index 9715a062e23..8172d688b45 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,16 @@ "dist/ember.min.map", "dist/ember.prod.js", "dist/ember.prod.map", + "dist/ie/ember-template-compiler.js", + "dist/ie/ember-template-compiler.map", + "dist/ie/ember-testing.js", + "dist/ie/ember-testing.map", + "dist/ie/ember.debug.js", + "dist/ie/ember.debug.map", + "dist/ie/ember.min.js", + "dist/ie/ember.min.map", + "dist/ie/ember.prod.js", + "dist/ie/ember.prod.map", "docs/data.json", "lib/index.js", "vendor/ember" @@ -50,6 +60,7 @@ "dependencies": { "broccoli-funnel": "^2.0.1", "broccoli-merge-trees": "^2.0.0", + "browserslist": "^4.3.4", "chalk": "^2.3.0", "ember-cli-get-component-path-option": "^1.0.0", "ember-cli-is-package-missing": "^1.0.0", @@ -78,7 +89,7 @@ "aws-sdk": "^2.46.0", "babel-plugin-check-es2015-constants": "^6.22.0", "babel-plugin-debug-macros": "^0.2.0-beta.6", - "babel-plugin-minify-dead-code-elimination": "^0.3.0", + "babel-plugin-filter-imports": "1.1.2", "babel-plugin-transform-es2015-arrow-functions": "^6.22.0", "babel-plugin-transform-es2015-block-scoping": "^6.26.0", "babel-plugin-transform-es2015-classes": "^6.24.1", diff --git a/packages/external-helpers/lib/external-helpers-prod.js b/packages/external-helpers/lib/external-helpers-prod.js deleted file mode 100644 index 2fac6d95e3a..00000000000 --- a/packages/external-helpers/lib/external-helpers-prod.js +++ /dev/null @@ -1,42 +0,0 @@ -const create = Object.create; -const setPrototypeOf = Object.setPrototypeOf; -const defineProperty = Object.defineProperty; - -export function classCallCheck() {} - -export function inherits(subClass, superClass) { - subClass.prototype = create(superClass === null ? null : superClass.prototype, { - constructor: { - value: subClass, - enumerable: false, - writable: true, - configurable: true, - }, - }); - if (superClass !== null) setPrototypeOf(subClass, superClass); -} - -export function taggedTemplateLiteralLoose(strings, raw) { - strings.raw = raw; - return strings; -} - -function defineProperties(target, props) { - for (var i = 0; i < props.length; i++) { - var descriptor = props[i]; - descriptor.enumerable = descriptor.enumerable || false; - descriptor.configurable = true; - if ('value' in descriptor) descriptor.writable = true; - defineProperty(target, descriptor.key, descriptor); - } -} - -export function createClass(Constructor, protoProps, staticProps) { - if (protoProps !== undefined) defineProperties(Constructor.prototype, protoProps); - if (staticProps !== undefined) defineProperties(Constructor, staticProps); - return Constructor; -} - -export function possibleConstructorReturn(self, call) { - return (call !== null && typeof call === 'object') || typeof call === 'function' ? call : self; -} diff --git a/packages/external-helpers/lib/external-helpers-dev.js b/packages/external-helpers/lib/external-helpers.js similarity index 72% rename from packages/external-helpers/lib/external-helpers-dev.js rename to packages/external-helpers/lib/external-helpers.js index 99ed71491ac..cff93d7379a 100644 --- a/packages/external-helpers/lib/external-helpers-dev.js +++ b/packages/external-helpers/lib/external-helpers.js @@ -1,18 +1,24 @@ +import { DEBUG } from '@glimmer/env'; + const create = Object.create; const setPrototypeOf = Object.setPrototypeOf; const defineProperty = Object.defineProperty; export function classCallCheck(instance, Constructor) { - if (!(instance instanceof Constructor)) { - throw new TypeError('Cannot call a class as a function'); + if (DEBUG) { + if (!(instance instanceof Constructor)) { + throw new TypeError('Cannot call a class as a function'); + } } } export function inherits(subClass, superClass) { - if (typeof superClass !== 'function' && superClass !== null) { - throw new TypeError( - 'Super expression must either be null or a function, not ' + typeof superClass - ); + if (DEBUG) { + if (typeof superClass !== 'function' && superClass !== null) { + throw new TypeError( + 'Super expression must either be null or a function, not ' + typeof superClass + ); + } } subClass.prototype = create(superClass === null ? null : superClass.prototype, { constructor: { @@ -47,8 +53,10 @@ export function createClass(Constructor, protoProps, staticProps) { } export const possibleConstructorReturn = function(self, call) { - if (!self) { - throw new ReferenceError(`this hasn't been initialized - super() hasn't been called`); + if (DEBUG) { + if (!self) { + throw new ReferenceError(`this hasn't been initialized - super() hasn't been called`); + } } return (call !== null && typeof call === 'object') || typeof call === 'function' ? call : self; }; diff --git a/testem.dist.js b/testem.dist.js index 79d5d0c94df..e3992313a4b 100644 --- a/testem.dist.js +++ b/testem.dist.js @@ -179,7 +179,7 @@ module.exports = { '-t', '1500', '--u', - '', + '&ie=true', ], protocol: 'browser', }, diff --git a/tests/index.html b/tests/index.html index b5d7947335f..6e9a6b9644f 100644 --- a/tests/index.html +++ b/tests/index.html @@ -74,17 +74,20 @@ @@ -96,24 +99,30 @@ diff --git a/yarn.lock b/yarn.lock index 439fc06cd62..debfbd5d238 100644 --- a/yarn.lock +++ b/yarn.lock @@ -666,11 +666,6 @@ babel-helper-define-map@^6.24.1: babel-types "^6.26.0" lodash "^4.17.4" -babel-helper-evaluate-path@^0.3.0: - version "0.3.0" - resolved "https://registry.yarnpkg.com/babel-helper-evaluate-path/-/babel-helper-evaluate-path-0.3.0.tgz#2439545e0b6eae5b7f49b790acbebd6b9a73df20" - integrity sha512-dRFlMTqUJRGzx5a2smKxmptDdNCXKSkPcXWzKLwAV72hvIZumrd/0z9RcewHkr7PmAEq+ETtpD1GK6wZ6ZUXzw== - babel-helper-explode-assignable-expression@^6.24.1: version "6.24.1" resolved "https://registry.yarnpkg.com/babel-helper-explode-assignable-expression/-/babel-helper-explode-assignable-expression-6.24.1.tgz#f25b82cf7dc10433c55f70592d5746400ac22caa" @@ -707,11 +702,6 @@ babel-helper-hoist-variables@^6.24.1: babel-runtime "^6.22.0" babel-types "^6.24.1" -babel-helper-mark-eval-scopes@^0.3.0: - version "0.3.0" - resolved "https://registry.yarnpkg.com/babel-helper-mark-eval-scopes/-/babel-helper-mark-eval-scopes-0.3.0.tgz#b4731314fdd7a89091271a5213b4e12d236e29e8" - integrity sha512-nrho5Dg4vl0VUgURVpGpEGiwbst5JX7efIyDHFxmkCx/ocQFnrPt8ze9Kxl6TKjR29bJ7D/XKY1NMlSxOQJRbQ== - babel-helper-optimise-call-expression@^6.24.1: version "6.24.1" resolved "https://registry.yarnpkg.com/babel-helper-optimise-call-expression/-/babel-helper-optimise-call-expression-6.24.1.tgz#f7a13427ba9f73f8f4fa993c54a97882d1244257" @@ -740,11 +730,6 @@ babel-helper-remap-async-to-generator@^6.24.1: babel-traverse "^6.24.1" babel-types "^6.24.1" -babel-helper-remove-or-void@^0.3.0: - version "0.3.0" - resolved "https://registry.yarnpkg.com/babel-helper-remove-or-void/-/babel-helper-remove-or-void-0.3.0.tgz#f43c86147c8fcc395a9528cbb31e7ff49d7e16e3" - integrity sha512-D68W1M3ibCcbg0ysh3ww4/O0g10X1CXK720oOuR8kpfY7w0yP4tVcpK7zDmI1JecynycTQYAZ1rhLJo9aVtIKQ== - babel-helper-replace-supers@^6.24.1: version "6.24.1" resolved "https://registry.yarnpkg.com/babel-helper-replace-supers/-/babel-helper-replace-supers-6.24.1.tgz#bf6dbfe43938d17369a213ca8a8bf74b6a90ab1a" @@ -800,15 +785,13 @@ babel-plugin-ember-modules-api-polyfill@^2.3.0: dependencies: ember-rfc176-data "^0.3.0" -babel-plugin-minify-dead-code-elimination@^0.3.0: - version "0.3.0" - resolved "https://registry.yarnpkg.com/babel-plugin-minify-dead-code-elimination/-/babel-plugin-minify-dead-code-elimination-0.3.0.tgz#a323f686c404b824186ba5583cf7996cac81719e" - integrity sha512-SjM2Fzg85YZz+q/PNJ/HU4O3W98FKFOiP9K5z3sfonlamGOzvZw3Eup2OTiEBsbbqTeY8yzNCAv3qpJRYCgGmw== +babel-plugin-filter-imports@1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/babel-plugin-filter-imports/-/babel-plugin-filter-imports-1.1.2.tgz#c6e1f2685253bbda91b1dc5a6652ce825f771264" + integrity sha512-BpXJV3fndKEP1D9Yhwpz4NIjM/d1FYpdx4E4KmUPnTIFUxXNj0QEAY18MXVzEyYi2EWEVhoOG2CmclDfdMj5ew== dependencies: - babel-helper-evaluate-path "^0.3.0" - babel-helper-mark-eval-scopes "^0.3.0" - babel-helper-remove-or-void "^0.3.0" - lodash.some "^4.6.0" + babel-types "^6.26.0" + lodash "^4.17.10" babel-plugin-syntax-async-functions@^6.8.0: version "6.13.0" @@ -1822,6 +1805,15 @@ browserslist@^2.1.2: caniuse-lite "^1.0.30000784" electron-to-chromium "^1.3.30" +browserslist@^4.3.4: + version "4.3.4" + resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.3.4.tgz#4477b737db6a1b07077275b24791e680d4300425" + integrity sha512-u5iz+ijIMUlmV8blX82VGFrB9ecnUg5qEt55CMZ/YJEhha+d8qpBfOFuutJ6F/VKRXjZoD33b6uvarpPxcl3RA== + dependencies: + caniuse-lite "^1.0.30000899" + electron-to-chromium "^1.3.82" + node-releases "^1.0.1" + browserstack-local@^1.3.0: version "1.3.0" resolved "https://registry.yarnpkg.com/browserstack-local/-/browserstack-local-1.3.0.tgz#fe80ef05ce8954c4d626e3502eb62d60903b4237" @@ -1954,6 +1946,11 @@ caniuse-lite@^1.0.30000784: resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000789.tgz#2e3d937b267133f63635ef7f441fac66360fc889" integrity sha1-Lj2TeyZxM/Y2Ne9/RB+sZjYPyIk= +caniuse-lite@^1.0.30000899: + version "1.0.30000906" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000906.tgz#7c44e498a2504f7a5db3b4f91285bbc821157a77" + integrity sha512-ME7JFX6h0402om/nC/8Lw+q23QvPe2ust9U0ntLmkX9F2zaGwq47fZkjlyHKirFBuq1EM+T/LXBcDdW4bvkCTA== + capture-exit@^1.1.0: version "1.2.0" resolved "https://registry.yarnpkg.com/capture-exit/-/capture-exit-1.2.0.tgz#1c5fcc489fd0ab00d4f1ac7ae1072e3173fbab6f" @@ -2812,6 +2809,11 @@ electron-to-chromium@^1.3.30: dependencies: electron-releases "^2.1.0" +electron-to-chromium@^1.3.82: + version "1.3.83" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.83.tgz#74584eb0972bb6777811c5d68d988c722f5e6666" + integrity sha512-DqJoDarxq50dcHsOOlMLNoy+qQitlMNbYb6wwbE0oUw2veHdRkpNrhmngiUYKMErdJ8SJ48rpJsZTQgy5SoEAA== + ember-cli-babel@^6.6.0: version "6.11.0" resolved "https://registry.yarnpkg.com/ember-cli-babel/-/ember-cli-babel-6.11.0.tgz#79cb184bac3c05bfe181ddc306bac100ab1f9493" @@ -5661,11 +5663,6 @@ lodash.restparam@^3.0.0: resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805" integrity sha1-k2pOMJ7zMKdkXtQUWYbIWuWyCAU= -lodash.some@^4.6.0: - version "4.6.0" - resolved "https://registry.yarnpkg.com/lodash.some/-/lodash.some-4.6.0.tgz#1bb9f314ef6b8baded13b549169b2a945eb68e4d" - integrity sha1-G7nzFO9ri63tE7VJFpsqlF62jk0= - lodash.support@~2.3.0: version "2.3.0" resolved "https://registry.yarnpkg.com/lodash.support/-/lodash.support-2.3.0.tgz#7eaf038af4f0d6aab776b44aa6dcfc80334c9bfd" @@ -5741,6 +5738,11 @@ lodash@^4.0.0, lodash@^4.14.0, lodash@^4.16.1, lodash@^4.17.2, lodash@^4.17.4, l resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae" integrity sha1-eCA6TRwyiuHYbcpkYONptX9AVa4= +lodash@^4.17.10: + version "4.17.11" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d" + integrity sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg== + log-symbols@^2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-2.2.0.tgz#5740e1c5d6f0dfda4ad9323b5332107ef6b4c40a" @@ -6306,6 +6308,13 @@ node-pre-gyp@^0.6.39: tar "^2.2.1" tar-pack "^3.4.0" +node-releases@^1.0.1: + version "1.0.3" + resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-1.0.3.tgz#3414ed84595096459c251699bfcb47d88324a9e4" + integrity sha512-ZaZWMsbuDcetpHmYeKWPO6e63pSXLb50M7lJgCbcM2nC/nQC3daNifmtp5a2kp7EWwYfhuvH6zLPWkrF8IiDdw== + dependencies: + semver "^5.3.0" + node-uuid@1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/node-uuid/-/node-uuid-1.4.0.tgz#07f9b2337572ff6275c775e1d48513f3a45d7a65"