From 91ce9812626f90198db523927bb53f105f98ad62 Mon Sep 17 00:00:00 2001 From: Keith Cirkel Date: Fri, 1 Mar 2019 10:12:35 +0000 Subject: [PATCH] Add dynamicImportFunction option (#2723) * feat: add dynamicImportFunction option This option allows users of `es` format to rename the `import()` function, which right now has mixed support in browsers. By allowing this function to be renamed we can have polyfills (which cannot use the reserved `import` keyword but could go by a different name like `importModule`). * docs: add dynamicImportFunction docs * feat: warn when using dynamicImportFunction in non-esm format * Add functional tests and align warning messages * Fix merge * Add dynamicImportFunction to two more places and fix sorting --- bin/src/help.md | 1 + docs/01-command-line-reference.md | 1 + docs/02-javascript-api.md | 1 + docs/999-big-list-of-options.md | 7 ++++ src/Chunk.ts | 9 ++++- src/ast/nodes/Import.ts | 19 +++++++---- src/finalisers/iife.ts | 2 +- src/finalisers/umd.ts | 2 +- src/rollup/index.ts | 33 ++++++++++--------- src/rollup/types.d.ts | 1 + src/utils/mergeOptions.ts | 1 + src/utils/renderHelpers.ts | 1 + .../samples/dynamic-import-name/_config.js | 15 +++++++++ .../dynamic-import-name/_expected/amd/main.js | 5 +++ .../dynamic-import-name/_expected/cjs/main.js | 3 ++ .../dynamic-import-name/_expected/es/main.js | 1 + .../_expected/system/main.js | 10 ++++++ .../samples/dynamic-import-name/main.js | 1 + .../dynamic-import-name-warn/_config.js | 32 ++++++++++++++++++ .../_expected/amd/main.js | 5 +++ .../_expected/cjs/main.js | 3 ++ .../_expected/es/main.js | 1 + .../_expected/system/main.js | 10 ++++++ .../samples/dynamic-import-name-warn/main.js | 1 + .../samples/dynamic-import-name/_config.js | 27 +++++++++++++++ .../dynamic-import-name/_expected/amd/main.js | 5 +++ .../dynamic-import-name/_expected/cjs/main.js | 3 ++ .../dynamic-import-name/_expected/es/main.js | 1 + .../_expected/system/main.js | 10 ++++++ .../samples/dynamic-import-name/main.js | 1 + .../inline-imports-with-manual/_config.js | 2 +- .../inline-imports-with-multiple/_config.js | 2 +- .../inline-imports-with-optimize/_config.js | 2 +- .../preserve-modules-with-inline/_config.js | 2 +- .../preserve-modules-with-manual/_config.js | 2 +- .../preserve-modules-with-optimize/_config.js | 2 +- test/hooks/index.js | 2 +- test/misc/optionList.js | 4 +-- test/misc/sanity-checks.js | 10 +++--- test/misc/write-bundle.js | 12 +++---- 40 files changed, 206 insertions(+), 46 deletions(-) create mode 100644 test/chunking-form/samples/dynamic-import-name/_config.js create mode 100644 test/chunking-form/samples/dynamic-import-name/_expected/amd/main.js create mode 100644 test/chunking-form/samples/dynamic-import-name/_expected/cjs/main.js create mode 100644 test/chunking-form/samples/dynamic-import-name/_expected/es/main.js create mode 100644 test/chunking-form/samples/dynamic-import-name/_expected/system/main.js create mode 100644 test/chunking-form/samples/dynamic-import-name/main.js create mode 100644 test/function/samples/dynamic-import-name-warn/_config.js create mode 100644 test/function/samples/dynamic-import-name-warn/_expected/amd/main.js create mode 100644 test/function/samples/dynamic-import-name-warn/_expected/cjs/main.js create mode 100644 test/function/samples/dynamic-import-name-warn/_expected/es/main.js create mode 100644 test/function/samples/dynamic-import-name-warn/_expected/system/main.js create mode 100644 test/function/samples/dynamic-import-name-warn/main.js create mode 100644 test/function/samples/dynamic-import-name/_config.js create mode 100644 test/function/samples/dynamic-import-name/_expected/amd/main.js create mode 100644 test/function/samples/dynamic-import-name/_expected/cjs/main.js create mode 100644 test/function/samples/dynamic-import-name/_expected/es/main.js create mode 100644 test/function/samples/dynamic-import-name/_expected/system/main.js create mode 100644 test/function/samples/dynamic-import-name/main.js diff --git a/bin/src/help.md b/bin/src/help.md index 6d95d741620..6258c36649b 100644 --- a/bin/src/help.md +++ b/bin/src/help.md @@ -25,6 +25,7 @@ Basic options: --chunkFileNames Name pattern for emitted secondary chunks --compact Minify wrapper code --context Specify top-level `this` value +--dynamicImportFunction Rename the dynamic `import()` function --entryFileNames Name pattern for emitted entry chunks --environment Settings passed to config file (see example) --no-esModule Do not add __esModule property diff --git a/docs/01-command-line-reference.md b/docs/01-command-line-reference.md index cad22f778c4..51f41d9a51b 100755 --- a/docs/01-command-line-reference.md +++ b/docs/01-command-line-reference.md @@ -85,6 +85,7 @@ export default { // can be an array (for multiple inputs) // danger zone amd, + dynamicImportFunction, esModule, exports, freeze, diff --git a/docs/02-javascript-api.md b/docs/02-javascript-api.md index 4d246b2979c..4cb6a3f85e9 100755 --- a/docs/02-javascript-api.md +++ b/docs/02-javascript-api.md @@ -134,6 +134,7 @@ const outputOptions = { // danger zone amd, + dynamicImportFunction, esModule, exports, freeze, diff --git a/docs/999-big-list-of-options.md b/docs/999-big-list-of-options.md index b6fa3a4ead9..38736b1fcf7 100755 --- a/docs/999-big-list-of-options.md +++ b/docs/999-big-list-of-options.md @@ -667,6 +667,13 @@ Default: `true` Whether to include the 'use strict' pragma at the top of generated non-ESM bundles. Strictly-speaking, ES modules are *always* in strict mode, so you shouldn't disable this without good reason. +#### output.dynamicImportFunction +Type: `string`
+CLI: `--dynamicImportFunction `
+Default: `import` + +This will rename the dynamic import function to the chosen name when outputting ESM bundles. This is useful for generating code that uses a dynamic import polyfill such as [this one](https://github.com/uupaa/dynamic-import-polyfill). + #### preserveSymlinks Type: `boolean`
CLI: `--preserveSymlinks`
diff --git a/src/Chunk.ts b/src/Chunk.ts index b0438056141..b15af569872 100644 --- a/src/Chunk.ts +++ b/src/Chunk.ts @@ -435,6 +435,7 @@ export default class Chunk { const renderOptions: RenderOptions = { compact: options.compact, + dynamicImportFunction: options.dynamicImportFunction, format: options.format, freeze: options.freeze !== false, indent: this.indentString, @@ -545,7 +546,13 @@ export default class Chunk { code: 'INVALID_OPTION', message: `Invalid format: ${options.format} - valid options are ${Object.keys( finalisers - ).join(', ')}` + ).join(', ')}.` + }); + } + if (options.dynamicImportFunction && options.format !== 'es') { + this.graph.warn({ + code: 'INVALID_OPTION', + message: '"output.dynamicImportFunction" is ignored for formats other than "esm".' }); } diff --git a/src/ast/nodes/Import.ts b/src/ast/nodes/Import.ts index 46ebba8c0f8..f285069d8d5 100644 --- a/src/ast/nodes/Import.ts +++ b/src/ast/nodes/Import.ts @@ -11,10 +11,10 @@ interface DynamicImportMechanism { right: string; } -const getDynamicImportMechanism = (format: string, compact: boolean): DynamicImportMechanism => { - switch (format) { +const getDynamicImportMechanism = (options: RenderOptions): DynamicImportMechanism => { + switch (options.format) { case 'cjs': { - const _ = compact ? '' : ' '; + const _ = options.compact ? '' : ' '; return { interopLeft: `Promise.resolve({${_}default:${_}require(`, interopRight: `)${_}})`, @@ -23,9 +23,9 @@ const getDynamicImportMechanism = (format: string, compact: boolean): DynamicImp }; } case 'amd': { - const _ = compact ? '' : ' '; - const resolve = compact ? 'c' : 'resolve'; - const reject = compact ? 'e' : 'reject'; + const _ = options.compact ? '' : ' '; + const resolve = options.compact ? 'c' : 'resolve'; + const reject = options.compact ? 'e' : 'reject'; return { interopLeft: `new Promise(function${_}(${resolve},${_}${reject})${_}{${_}require([`, interopRight: `],${_}function${_}(m)${_}{${_}${resolve}({${_}default:${_}m${_}})${_}},${_}${reject})${_}})`, @@ -38,6 +38,11 @@ const getDynamicImportMechanism = (format: string, compact: boolean): DynamicImp left: 'module.import(', right: ')' }; + case 'es': + return { + left: `${options.dynamicImportFunction || 'import'}(`, + right: ')' + }; } }; @@ -72,7 +77,7 @@ export default class Import extends NodeBase { return; } - const importMechanism = getDynamicImportMechanism(options.format, options.compact); + const importMechanism = getDynamicImportMechanism(options); if (importMechanism) { const leftMechanism = (this.resolutionInterop && importMechanism.interopLeft) || importMechanism.left; diff --git a/src/finalisers/iife.ts b/src/finalisers/iife.ts index 95a02278658..1a66a775376 100644 --- a/src/finalisers/iife.ts +++ b/src/finalisers/iife.ts @@ -50,7 +50,7 @@ export default function iife( if (hasExports && !name) { error({ code: 'INVALID_OPTION', - message: `You must supply output.name for IIFE bundles` + message: `You must supply "output.name" for IIFE bundles.` }); } diff --git a/src/finalisers/umd.ts b/src/finalisers/umd.ts index f4663bd4475..86c91032f29 100644 --- a/src/finalisers/umd.ts +++ b/src/finalisers/umd.ts @@ -45,7 +45,7 @@ export default function umd( if (hasExports && !options.name) { error({ code: 'INVALID_OPTION', - message: 'You must supply output.name for UMD bundles' + message: 'You must supply "output.name" for UMD bundles.' }); } diff --git a/src/rollup/index.ts b/src/rollup/index.ts index 42f9d060434..6ad366c878e 100644 --- a/src/rollup/index.ts +++ b/src/rollup/index.ts @@ -28,14 +28,14 @@ import { function checkOutputOptions(options: OutputOptions) { if (options.format === 'es6') { error({ - message: 'The `es6` output format is deprecated – use `esm` instead', + message: 'The "es6" output format is deprecated – use "esm" instead', url: `https://rollupjs.org/guide/en#output-format` }); } if (!options.format) { error({ - message: `You must specify output.format, which can be one of 'amd', 'cjs', 'system', 'esm', 'iife' or 'umd'`, + message: `You must specify "output.format", which can be one of "amd", "cjs", "system", "esm", "iife" or "umd".`, url: `https://rollupjs.org/guide/en#output-format` }); } @@ -88,18 +88,18 @@ function getInputOptions(rawInputOptions: GenericConfigObject): any { if (inputOptions.preserveModules) error({ code: 'INVALID_OPTION', - message: `preserveModules does not support the inlineDynamicImports option.` + message: `"preserveModules" does not support the "inlineDynamicImports" option.` }); if (inputOptions.manualChunks) error({ code: 'INVALID_OPTION', - message: '"manualChunks" option is not supported for inlineDynamicImports.' + message: '"manualChunks" option is not supported for "inlineDynamicImports".' }); if (inputOptions.experimentalOptimizeChunks) error({ code: 'INVALID_OPTION', - message: '"experimentalOptimizeChunks" option is not supported for inlineDynamicImports.' + message: '"experimentalOptimizeChunks" option is not supported for "inlineDynamicImports".' }); if ( (inputOptions.input instanceof Array && inputOptions.input.length > 1) || @@ -107,18 +107,18 @@ function getInputOptions(rawInputOptions: GenericConfigObject): any { ) error({ code: 'INVALID_OPTION', - message: 'Multiple inputs are not supported for inlineDynamicImports.' + message: 'Multiple inputs are not supported for "inlineDynamicImports".' }); } else if (inputOptions.preserveModules) { if (inputOptions.manualChunks) error({ code: 'INVALID_OPTION', - message: 'preserveModules does not support the manualChunks option.' + message: '"preserveModules" does not support the "manualChunks" option.' }); if (inputOptions.experimentalOptimizeChunks) error({ code: 'INVALID_OPTION', - message: 'preserveModules does not support the experimentalOptimizeChunks option.' + message: '"preserveModules" does not support the "experimentalOptimizeChunks" option.' }); } @@ -290,7 +290,7 @@ export default function rollup(rawInputOptions: GenericConfigObject): Promise { @@ -305,17 +305,17 @@ export default function rollup(rawInputOptions: GenericConfigObject): Promise console.log(result)); + +}); diff --git a/test/chunking-form/samples/dynamic-import-name/_expected/cjs/main.js b/test/chunking-form/samples/dynamic-import-name/_expected/cjs/main.js new file mode 100644 index 00000000000..64a6539d7e3 --- /dev/null +++ b/test/chunking-form/samples/dynamic-import-name/_expected/cjs/main.js @@ -0,0 +1,3 @@ +'use strict'; + +Promise.resolve(require('./foo.js')).then(result => console.log(result)); diff --git a/test/chunking-form/samples/dynamic-import-name/_expected/es/main.js b/test/chunking-form/samples/dynamic-import-name/_expected/es/main.js new file mode 100644 index 00000000000..31d9a65e153 --- /dev/null +++ b/test/chunking-form/samples/dynamic-import-name/_expected/es/main.js @@ -0,0 +1 @@ +foobar('./foo.js').then(result => console.log(result)); diff --git a/test/chunking-form/samples/dynamic-import-name/_expected/system/main.js b/test/chunking-form/samples/dynamic-import-name/_expected/system/main.js new file mode 100644 index 00000000000..ce0e7ba782a --- /dev/null +++ b/test/chunking-form/samples/dynamic-import-name/_expected/system/main.js @@ -0,0 +1,10 @@ +System.register([], function (exports, module) { + 'use strict'; + return { + execute: function () { + + module.import('./foo.js').then(result => console.log(result)); + + } + }; +}); diff --git a/test/chunking-form/samples/dynamic-import-name/main.js b/test/chunking-form/samples/dynamic-import-name/main.js new file mode 100644 index 00000000000..56ab47293cd --- /dev/null +++ b/test/chunking-form/samples/dynamic-import-name/main.js @@ -0,0 +1 @@ +import('./foo.js').then(result => console.log(result)); diff --git a/test/function/samples/dynamic-import-name-warn/_config.js b/test/function/samples/dynamic-import-name-warn/_config.js new file mode 100644 index 00000000000..df3d06293e3 --- /dev/null +++ b/test/function/samples/dynamic-import-name-warn/_config.js @@ -0,0 +1,32 @@ +const assert = require('assert'); + +module.exports = { + description: 'warns when specifying a custom importer function for formats other than "esm"', + context: { + require(path) { + assert.equal(path, './foo.js'); + return 42; + } + }, + options: { + input: 'main.js', + plugins: { + resolveDynamicImport() { + return false; + } + }, + output: { + dynamicImportFunction: 'myImporter', + format: 'cjs' + } + }, + exports(exports) { + return exports.fromFoo.then(value => assert.strictEqual(value, 42)); + }, + warnings: [ + { + code: 'INVALID_OPTION', + message: '"output.dynamicImportFunction" is ignored for formats other than "esm".' + } + ] +}; diff --git a/test/function/samples/dynamic-import-name-warn/_expected/amd/main.js b/test/function/samples/dynamic-import-name-warn/_expected/amd/main.js new file mode 100644 index 00000000000..b81e4d74b05 --- /dev/null +++ b/test/function/samples/dynamic-import-name-warn/_expected/amd/main.js @@ -0,0 +1,5 @@ +define(['require'], function (require) { 'use strict'; + + new Promise(function (resolve, reject) { require(['./foo.js'], resolve, reject) }); + +}); diff --git a/test/function/samples/dynamic-import-name-warn/_expected/cjs/main.js b/test/function/samples/dynamic-import-name-warn/_expected/cjs/main.js new file mode 100644 index 00000000000..b1acd589703 --- /dev/null +++ b/test/function/samples/dynamic-import-name-warn/_expected/cjs/main.js @@ -0,0 +1,3 @@ +'use strict'; + +Promise.resolve(require('./foo.js')); diff --git a/test/function/samples/dynamic-import-name-warn/_expected/es/main.js b/test/function/samples/dynamic-import-name-warn/_expected/es/main.js new file mode 100644 index 00000000000..51e216a3931 --- /dev/null +++ b/test/function/samples/dynamic-import-name-warn/_expected/es/main.js @@ -0,0 +1 @@ +foobar('./foo.js'); diff --git a/test/function/samples/dynamic-import-name-warn/_expected/system/main.js b/test/function/samples/dynamic-import-name-warn/_expected/system/main.js new file mode 100644 index 00000000000..0824bad8d3f --- /dev/null +++ b/test/function/samples/dynamic-import-name-warn/_expected/system/main.js @@ -0,0 +1,10 @@ +System.register([], function (exports, module) { + 'use strict'; + return { + execute: function () { + + module.import('./foo.js'); + + } + }; +}); diff --git a/test/function/samples/dynamic-import-name-warn/main.js b/test/function/samples/dynamic-import-name-warn/main.js new file mode 100644 index 00000000000..ed74de99fab --- /dev/null +++ b/test/function/samples/dynamic-import-name-warn/main.js @@ -0,0 +1 @@ +export const fromFoo = import('./foo.js'); diff --git a/test/function/samples/dynamic-import-name/_config.js b/test/function/samples/dynamic-import-name/_config.js new file mode 100644 index 00000000000..e31e98bbc76 --- /dev/null +++ b/test/function/samples/dynamic-import-name/_config.js @@ -0,0 +1,27 @@ +const assert = require('assert'); +let imported = false; + +module.exports = { + description: 'allows specifying a custom importer function', + context: { + myImporter(path) { + assert.equal(path, './foo.js'); + imported = true; + } + }, + options: { + input: 'main.js', + plugins: { + resolveDynamicImport() { + return false; + } + }, + output: { + dynamicImportFunction: 'myImporter', + format: 'esm' + } + }, + exports() { + assert.ok(imported); + } +}; diff --git a/test/function/samples/dynamic-import-name/_expected/amd/main.js b/test/function/samples/dynamic-import-name/_expected/amd/main.js new file mode 100644 index 00000000000..b81e4d74b05 --- /dev/null +++ b/test/function/samples/dynamic-import-name/_expected/amd/main.js @@ -0,0 +1,5 @@ +define(['require'], function (require) { 'use strict'; + + new Promise(function (resolve, reject) { require(['./foo.js'], resolve, reject) }); + +}); diff --git a/test/function/samples/dynamic-import-name/_expected/cjs/main.js b/test/function/samples/dynamic-import-name/_expected/cjs/main.js new file mode 100644 index 00000000000..b1acd589703 --- /dev/null +++ b/test/function/samples/dynamic-import-name/_expected/cjs/main.js @@ -0,0 +1,3 @@ +'use strict'; + +Promise.resolve(require('./foo.js')); diff --git a/test/function/samples/dynamic-import-name/_expected/es/main.js b/test/function/samples/dynamic-import-name/_expected/es/main.js new file mode 100644 index 00000000000..51e216a3931 --- /dev/null +++ b/test/function/samples/dynamic-import-name/_expected/es/main.js @@ -0,0 +1 @@ +foobar('./foo.js'); diff --git a/test/function/samples/dynamic-import-name/_expected/system/main.js b/test/function/samples/dynamic-import-name/_expected/system/main.js new file mode 100644 index 00000000000..0824bad8d3f --- /dev/null +++ b/test/function/samples/dynamic-import-name/_expected/system/main.js @@ -0,0 +1,10 @@ +System.register([], function (exports, module) { + 'use strict'; + return { + execute: function () { + + module.import('./foo.js'); + + } + }; +}); diff --git a/test/function/samples/dynamic-import-name/main.js b/test/function/samples/dynamic-import-name/main.js new file mode 100644 index 00000000000..bbe4a5cc219 --- /dev/null +++ b/test/function/samples/dynamic-import-name/main.js @@ -0,0 +1 @@ +import('./foo.js'); diff --git a/test/function/samples/inline-imports-with-manual/_config.js b/test/function/samples/inline-imports-with-manual/_config.js index 3c74806bc17..2b3af2a2835 100644 --- a/test/function/samples/inline-imports-with-manual/_config.js +++ b/test/function/samples/inline-imports-with-manual/_config.js @@ -9,6 +9,6 @@ module.exports = { }, error: { code: 'INVALID_OPTION', - message: '"manualChunks" option is not supported for inlineDynamicImports.' + message: '"manualChunks" option is not supported for "inlineDynamicImports".' } }; diff --git a/test/function/samples/inline-imports-with-multiple/_config.js b/test/function/samples/inline-imports-with-multiple/_config.js index 651f9083d82..4b5bfd77774 100644 --- a/test/function/samples/inline-imports-with-multiple/_config.js +++ b/test/function/samples/inline-imports-with-multiple/_config.js @@ -6,6 +6,6 @@ module.exports = { }, error: { code: 'INVALID_OPTION', - message: 'Multiple inputs are not supported for inlineDynamicImports.' + message: 'Multiple inputs are not supported for "inlineDynamicImports".' } }; diff --git a/test/function/samples/inline-imports-with-optimize/_config.js b/test/function/samples/inline-imports-with-optimize/_config.js index 5f012bdf5e8..5e350bebd32 100644 --- a/test/function/samples/inline-imports-with-optimize/_config.js +++ b/test/function/samples/inline-imports-with-optimize/_config.js @@ -7,6 +7,6 @@ module.exports = { }, error: { code: 'INVALID_OPTION', - message: '"experimentalOptimizeChunks" option is not supported for inlineDynamicImports.' + message: '"experimentalOptimizeChunks" option is not supported for "inlineDynamicImports".' } }; diff --git a/test/function/samples/preserve-modules-with-inline/_config.js b/test/function/samples/preserve-modules-with-inline/_config.js index 1dff01e2788..1f25bd9968d 100644 --- a/test/function/samples/preserve-modules-with-inline/_config.js +++ b/test/function/samples/preserve-modules-with-inline/_config.js @@ -7,6 +7,6 @@ module.exports = { }, error: { code: 'INVALID_OPTION', - message: 'preserveModules does not support the inlineDynamicImports option.' + message: '"preserveModules" does not support the "inlineDynamicImports" option.' } }; diff --git a/test/function/samples/preserve-modules-with-manual/_config.js b/test/function/samples/preserve-modules-with-manual/_config.js index 1b3725e0008..3d11ec5f9b9 100644 --- a/test/function/samples/preserve-modules-with-manual/_config.js +++ b/test/function/samples/preserve-modules-with-manual/_config.js @@ -9,6 +9,6 @@ module.exports = { }, error: { code: 'INVALID_OPTION', - message: 'preserveModules does not support the manualChunks option.' + message: '"preserveModules" does not support the "manualChunks" option.' } }; diff --git a/test/function/samples/preserve-modules-with-optimize/_config.js b/test/function/samples/preserve-modules-with-optimize/_config.js index 94b7edd55d7..ef6bc94f059 100644 --- a/test/function/samples/preserve-modules-with-optimize/_config.js +++ b/test/function/samples/preserve-modules-with-optimize/_config.js @@ -7,6 +7,6 @@ module.exports = { }, error: { code: 'INVALID_OPTION', - message: 'preserveModules does not support the experimentalOptimizeChunks option.' + message: '"preserveModules" does not support the "experimentalOptimizeChunks" option.' } }; diff --git a/test/hooks/index.js b/test/hooks/index.js index 769d295f995..ef6907f57cf 100644 --- a/test/hooks/index.js +++ b/test/hooks/index.js @@ -1211,7 +1211,7 @@ module.exports = input; else if (evt.code === 'ERROR' || evt.code === 'FATAL') reject(evt.error); }); }).catch(err => { - assert.equal(err.message, 'You must specify output.file or output.dir for the build.'); + assert.equal(err.message, 'You must specify "output.file" or "output.dir" for the build.'); assert.equal(warned, true); }); }); diff --git a/test/misc/optionList.js b/test/misc/optionList.js index 0dd93c024cd..ab34fa25c8c 100644 --- a/test/misc/optionList.js +++ b/test/misc/optionList.js @@ -1,3 +1,3 @@ exports.input = 'acorn, acornInjectPlugins, cache, chunkGroupingSize, context, experimentalCacheExpiry, experimentalOptimizeChunks, experimentalTopLevelAwait, external, inlineDynamicImports, input, manualChunks, moduleContext, onwarn, perf, plugins, preserveModules, preserveSymlinks, shimMissingExports, treeshake, watch'; -exports.flags = 'acorn, acornInjectPlugins, amd, assetFileNames, banner, c, cache, chunkFileNames, chunkGroupingSize, compact, config, context, d, dir, e, entryFileNames, environment, esModule, experimentalCacheExpiry, experimentalOptimizeChunks, experimentalTopLevelAwait, exports, extend, external, f, file, footer, format, freeze, g, globals, h, i, indent, inlineDynamicImports, input, interop, intro, m, manualChunks, moduleContext, n, name, namespaceToStringTag, noConflict, o, onwarn, outro, paths, perf, plugins, preferConst, preserveModules, preserveSymlinks, shimMissingExports, silent, sourcemap, sourcemapExcludeSources, sourcemapFile, strict, treeshake, v, w, watch'; -exports.output = 'amd, assetFileNames, banner, chunkFileNames, compact, dir, entryFileNames, esModule, exports, extend, file, footer, format, freeze, globals, indent, interop, intro, name, namespaceToStringTag, noConflict, outro, paths, preferConst, sourcemap, sourcemapExcludeSources, sourcemapFile, sourcemapPathTransform, strict'; +exports.flags = 'acorn, acornInjectPlugins, amd, assetFileNames, banner, c, cache, chunkFileNames, chunkGroupingSize, compact, config, context, d, dir, dynamicImportFunction, e, entryFileNames, environment, esModule, experimentalCacheExpiry, experimentalOptimizeChunks, experimentalTopLevelAwait, exports, extend, external, f, file, footer, format, freeze, g, globals, h, i, indent, inlineDynamicImports, input, interop, intro, m, manualChunks, moduleContext, n, name, namespaceToStringTag, noConflict, o, onwarn, outro, paths, perf, plugins, preferConst, preserveModules, preserveSymlinks, shimMissingExports, silent, sourcemap, sourcemapExcludeSources, sourcemapFile, strict, treeshake, v, w, watch'; +exports.output = 'amd, assetFileNames, banner, chunkFileNames, compact, dir, dynamicImportFunction, entryFileNames, esModule, exports, extend, file, footer, format, freeze, globals, indent, interop, intro, name, namespaceToStringTag, noConflict, outro, paths, preferConst, sourcemap, sourcemapExcludeSources, sourcemapFile, sourcemapPathTransform, strict'; diff --git a/test/misc/sanity-checks.js b/test/misc/sanity-checks.js index 9a89f4e52d0..e16b5ba2217 100644 --- a/test/misc/sanity-checks.js +++ b/test/misc/sanity-checks.js @@ -124,7 +124,7 @@ describe('sanity checks', () => { .then(bundle => { assert.throws(() => { bundle.generate({ file: 'x' }); - }, /You must specify output\.format, which can be one of 'amd', 'cjs', 'system', 'esm', 'iife' or 'umd'/); + }, /You must specify "output\.format", which can be one of "amd", "cjs", "system", "esm", "iife" or "umd"./); }); }); @@ -168,7 +168,7 @@ describe('sanity checks', () => { .then(bundle => { assert.throws(() => { bundle.generate({ file: 'x', format: 'es' }); - }, /You must set output\.dir instead of output\.file when generating multiple chunks\./); + }, /You must set "output\.dir" instead of "output\.file" when generating multiple chunks\./); }); }); @@ -196,7 +196,7 @@ describe('sanity checks', () => { .then(bundle => { assert.throws(() => { bundle.generate({ file: 'x', format: 'es' }); - }, /You must set output\.dir instead of output\.file when generating multiple chunks\./); + }, /You must set "output\.dir" instead of "output\.file" when generating multiple chunks\./); }); }); @@ -225,7 +225,7 @@ describe('sanity checks', () => { .then(bundle => { assert.throws(() => { bundle.generate({ file: 'x', format: 'es' }); - }, /You must set output\.dir instead of output\.file when providing named inputs\./); + }, /You must set "output\.dir" instead of "output\.file" when providing named inputs\./); }); }); @@ -242,7 +242,7 @@ describe('sanity checks', () => { .then(bundle => { assert.throws(() => { bundle.generate({ file: 'x', format: 'es' }); - }, /You must set output\.dir instead of output\.file when using the preserveModules option\./); + }, /You must set "output\.dir" instead of "output\.file" when using the "preserveModules" option\./); }); }); }); diff --git a/test/misc/write-bundle.js b/test/misc/write-bundle.js index dd2b8bfa7ed..9a14204457f 100644 --- a/test/misc/write-bundle.js +++ b/test/misc/write-bundle.js @@ -21,11 +21,11 @@ describe('bundle.write()', () => { .then(bundle => { assert.throws(() => { bundle.write(); - }, /You must specify output\.file/); + }, /You must specify "output\.file"/); assert.throws(() => { bundle.write({}); - }, /You must specify output\.file/); + }, /You must specify "output\.file"/); }); }); @@ -55,7 +55,7 @@ describe('bundle.write()', () => { .catch(err => { assert.throws(() => { throw err; - }, /You must supply output\.name for UMD bundles/); + }, /You must supply "output\.name" for UMD bundles/); }) .then(() => { return bundle.generate({ @@ -65,7 +65,7 @@ describe('bundle.write()', () => { .catch(err => { assert.throws(() => { throw err; - }, /You must supply output\.name for IIFE bundles/); + }, /You must supply "output\.name" for IIFE bundles/); }); }); @@ -87,7 +87,7 @@ describe('bundle.write()', () => { .then(bundle => { assert.throws(() => { return bundle.generate({ format: 'es6' }); - }, /The `es6` output format is deprecated – use `esm` instead/); + }, /The "es6" output format is deprecated – use "esm" instead/); }); }); @@ -110,7 +110,7 @@ describe('bundle.write()', () => { assert.equal(warnings.length, 0, 'No warnings for UNKNOWN'); assert.throws(() => { return Promise.all(options.output.map(o => bundle.write(o))); - }, /You must specify output\.file/); + }, /You must specify "output\.file"./); }); }); });