From bb2e01087b8a626144d38fed1d96c67de60e0262 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Tue, 11 Feb 2020 07:55:13 +0100 Subject: [PATCH] Rename esm to es everywhere, add systemjs alias --- ...n-esm-import.js => fix-acorn-es-import.js} | 4 +- cli/help.md | 2 +- docs/00-introduction.md | 2 +- docs/01-command-line-reference.md | 4 +- docs/04-tutorial.md | 2 +- docs/05-plugin-development.md | 2 +- docs/999-big-list-of-options.md | 26 ++++----- rollup.config.js | 8 +-- src/Chunk.ts | 6 +-- src/finalisers/{esm.ts => es.ts} | 2 +- src/finalisers/index.ts | 4 +- src/rollup/rollup.ts | 49 ++++++----------- src/rollup/types.d.ts | 1 + src/utils/parseOptions.ts | 53 +++++++++++++------ .../emit-chunk-worklet/index-es.html | 2 +- .../emit-chunk-worklet/index-es.html | 2 +- ...e7d2-esm.js => chunk-main2-bb2aced4-es.js} | 0 .../_expected/es/entry-main1-352fcfce-es.js | 3 ++ .../_expected/es/entry-main1-d5bffcd6-esm.js | 3 -- .../_expected/es/entry-main2-2d73322a-esm.js | 1 - .../_expected/es/entry-main2-8ebb5d84-es.js | 1 + ...foo-esm-ts.ts.js => entry-foo-es-ts.ts.js} | 0 .../_expected/es/entry-main-es-ts.ts.js | 4 ++ .../_expected/es/entry-main-esm-ts.ts.js | 4 -- ...try-no-ext-esm-.js => entry-no-ext-es-.js} | 0 ...bar-esm-ts.ts.js => entry-bar-es-ts.ts.js} | 0 ...baz-esm-ts.ts.js => entry-baz-es-ts.ts.js} | 0 .../config-plugin-entry/rollup.config.js | 2 +- .../_config.js | 3 +- .../emit-file-multiple-dirs/rollup.config.js | 2 +- test/cli/samples/format-aliases/_config.js | 4 ++ .../samples/format-aliases/_expected/amd.js | 11 ++++ .../samples/format-aliases/_expected/cjs.js | 11 ++++ .../format-aliases/_expected/commonjs.js | 11 ++++ .../samples/format-aliases/_expected/es.js | 3 ++ .../samples/format-aliases/_expected/esm.js | 3 ++ .../samples/format-aliases/_expected/iife.js | 12 +++++ .../format-aliases/_expected/module.js | 3 ++ .../format-aliases/_expected/system.js | 13 +++++ .../format-aliases/_expected/systemjs.js | 13 +++++ .../samples/format-aliases/_expected/umd.js | 15 ++++++ .../format-aliases/_expected/undefined.js | 3 ++ test/cli/samples/format-aliases/main.js | 3 ++ .../samples/format-aliases/rollup.config.js | 24 +++++++++ .../merge-deprecations/rollup.config.js | 4 +- .../samples/silent-onwarn/rollup.config.js | 2 +- .../stdin/config-file/rollup.config.js | 4 +- .../_expected/{esm.js => es.js} | 0 .../no-stdin-config-file/rollup.config.js | 4 +- .../warn-broken-sourcemap/rollup.config.js | 2 +- .../warn-broken-sourcemaps/rollup.config.js | 2 +- .../warn-circular-multiple/rollup.config.js | 2 +- .../samples/warn-circular/rollup.config.js | 2 +- .../warn-eval-multiple/rollup.config.js | 2 +- test/cli/samples/warn-eval/rollup.config.js | 2 +- test/cli/samples/warn-plugin/rollup.config.js | 2 +- test/cli/samples/watch/rollup.config.js | 2 +- test/file-hashes/index.js | 2 +- .../samples/augment-chunk-hash/_config.js | 4 +- test/file-hashes/samples/format/_config.js | 2 +- test/form/index.js | 2 +- .../dynamic-import-name-warn/_config.js | 4 +- .../samples/dynamic-import-name/_config.js | 2 +- .../virtual-modules-conflict/_config.js | 15 +++--- .../virtual-modules/_config.js | 15 +++--- test/hooks/index.js | 18 +++---- test/misc/bundle-information.js | 18 +++---- test/misc/deprecations.js | 4 +- test/misc/misc.js | 8 +-- test/misc/sanity-checks.js | 2 +- test/misc/write-bundle.js | 2 +- 71 files changed, 288 insertions(+), 161 deletions(-) rename build-plugins/{fix-acorn-esm-import.js => fix-acorn-es-import.js} (89%) rename src/finalisers/{esm.ts => es.ts} (99%) rename test/chunking-form/samples/filenames-patterns/_expected/es/{chunk-main2-5251e7d2-esm.js => chunk-main2-bb2aced4-es.js} (100%) create mode 100644 test/chunking-form/samples/filenames-patterns/_expected/es/entry-main1-352fcfce-es.js delete mode 100644 test/chunking-form/samples/filenames-patterns/_expected/es/entry-main1-d5bffcd6-esm.js delete mode 100644 test/chunking-form/samples/filenames-patterns/_expected/es/entry-main2-2d73322a-esm.js create mode 100644 test/chunking-form/samples/filenames-patterns/_expected/es/entry-main2-8ebb5d84-es.js rename test/chunking-form/samples/preserve-modules-filename-pattern/_expected/es/{entry-foo-esm-ts.ts.js => entry-foo-es-ts.ts.js} (100%) create mode 100644 test/chunking-form/samples/preserve-modules-filename-pattern/_expected/es/entry-main-es-ts.ts.js delete mode 100644 test/chunking-form/samples/preserve-modules-filename-pattern/_expected/es/entry-main-esm-ts.ts.js rename test/chunking-form/samples/preserve-modules-filename-pattern/_expected/es/{entry-no-ext-esm-.js => entry-no-ext-es-.js} (100%) rename test/chunking-form/samples/preserve-modules-filename-pattern/_expected/es/nested/{entry-bar-esm-ts.ts.js => entry-bar-es-ts.ts.js} (100%) rename test/chunking-form/samples/preserve-modules-filename-pattern/_expected/es/nested/{entry-baz-esm-ts.ts.js => entry-baz-es-ts.ts.js} (100%) create mode 100644 test/cli/samples/format-aliases/_config.js create mode 100644 test/cli/samples/format-aliases/_expected/amd.js create mode 100644 test/cli/samples/format-aliases/_expected/cjs.js create mode 100644 test/cli/samples/format-aliases/_expected/commonjs.js create mode 100644 test/cli/samples/format-aliases/_expected/es.js create mode 100644 test/cli/samples/format-aliases/_expected/esm.js create mode 100644 test/cli/samples/format-aliases/_expected/iife.js create mode 100644 test/cli/samples/format-aliases/_expected/module.js create mode 100644 test/cli/samples/format-aliases/_expected/system.js create mode 100644 test/cli/samples/format-aliases/_expected/systemjs.js create mode 100644 test/cli/samples/format-aliases/_expected/umd.js create mode 100644 test/cli/samples/format-aliases/_expected/undefined.js create mode 100644 test/cli/samples/format-aliases/main.js create mode 100644 test/cli/samples/format-aliases/rollup.config.js rename test/cli/samples/stdin/no-stdin-config-file/_expected/{esm.js => es.js} (100%) diff --git a/build-plugins/fix-acorn-esm-import.js b/build-plugins/fix-acorn-es-import.js similarity index 89% rename from build-plugins/fix-acorn-esm-import.js rename to build-plugins/fix-acorn-es-import.js index bdb5284ce98..408e06eaa9a 100644 --- a/build-plugins/fix-acorn-esm-import.js +++ b/build-plugins/fix-acorn-es-import.js @@ -3,11 +3,11 @@ const newAcornImport = "import * as acorn from 'acorn';\nimport { Parser } from // by default, rollup-plugin-commonjs will translate require statements as default imports // which can cause issues for secondary tools that use the ESM version of acorn -export default function fixAcornEsmImport() { +export default function fixAcornEsImport() { let found = false; return { - name: 'fix-acorn-esm-import', + name: 'fix-acorn-es-import', renderChunk(code) { return code.replace(expectedAcornImport, () => { found = true; diff --git a/cli/help.md b/cli/help.md index 644278ab178..76858a876fb 100644 --- a/cli/help.md +++ b/cli/help.md @@ -9,7 +9,7 @@ Basic options: is unspecified, defaults to rollup.config.js) -d, --dir Directory for chunks (if absent, prints to stdout) -e, --external Comma-separate list of module IDs to exclude --f, --format Type of output (amd, cjs, esm, iife, umd) +-f, --format Type of output (amd, cjs, es, iife, umd, system) -g, --globals Comma-separate list of `moduleID:Global` pairs -h, --help Show this help message -i, --input Input (alternative to ) diff --git a/docs/00-introduction.md b/docs/00-introduction.md index daf2abc7233..0023b4f62c3 100755 --- a/docs/00-introduction.md +++ b/docs/00-introduction.md @@ -86,4 +86,4 @@ Rollup can import existing CommonJS modules [through a plugin](https://github.co #### Publishing ES Modules -To make sure your ES modules are immediately usable by tools that work with CommonJS such as Node.js and webpack, you can use Rollup to compile to UMD or CommonJS format, and then point to that compiled version with the `main` property in your `package.json` file. If your `package.json` file also has a `module` field, ESM-aware tools like Rollup and [webpack 2+](https://webpack.js.org/) will [import the ES module version](https://github.com/rollup/rollup/wiki/pkg.module) directly. +To make sure your ES modules are immediately usable by tools that work with CommonJS such as Node.js and webpack, you can use Rollup to compile to UMD or CommonJS format, and then point to that compiled version with the `main` property in your `package.json` file. If your `package.json` file also has a `module` field, ES-module-aware tools like Rollup and [webpack 2+](https://webpack.js.org/) will [import the ES module version](https://github.com/rollup/rollup/wiki/pkg.module) directly. diff --git a/docs/01-command-line-reference.md b/docs/01-command-line-reference.md index 1cb74a4a9ac..382d39c4651 100755 --- a/docs/01-command-line-reference.md +++ b/docs/01-command-line-reference.md @@ -128,7 +128,7 @@ export default [{ }, { file: 'dist/bundle-b2.js', - format: 'esm' + format: 'es' } ] }]; @@ -213,7 +213,7 @@ Many options have command line equivalents. In those cases, any arguments passed is unspecified, defaults to rollup.config.js) -d, --dir Directory for chunks (if absent, prints to stdout) -e, --external Comma-separate list of module IDs to exclude --f, --format Type of output (amd, cjs, esm, iife, umd) +-f, --format Type of output (amd, cjs, es, iife, umd, system) -g, --globals Comma-separate list of `moduleID:Global` pairs -h, --help Show this help message -i, --input Input (alternative to ) diff --git a/docs/04-tutorial.md b/docs/04-tutorial.md index ad253a27548..aebe743f958 100755 --- a/docs/04-tutorial.md +++ b/docs/04-tutorial.md @@ -378,7 +378,7 @@ Notice how both entry points import the same shared chunk. Rollup will never dup You can build the same code for the browser via native ES modules, an AMD loader or SystemJS. -For example, with `-f esm` for native modules: +For example, with `-f es` for native modules: ``` rollup src/main.js src/main2.js -f esm -d dist diff --git a/docs/05-plugin-development.md b/docs/05-plugin-development.md index 3a5bf662c4e..2ad23845673 100644 --- a/docs/05-plugin-development.md +++ b/docs/05-plugin-development.md @@ -580,7 +580,7 @@ document.body.appendChild(image); Similar to assets, emitted chunks can be referenced from within JS code via `import.meta.ROLLUP_FILE_URL_referenceId` as well. -The following example will detect imports prefixed with `register-paint-worklet:` and generate the necessary code and separate chunk to generate a CSS paint worklet. Note that this will only work in modern browsers and will only work if the output format is set to `esm`. +The following example will detect imports prefixed with `register-paint-worklet:` and generate the necessary code and separate chunk to generate a CSS paint worklet. Note that this will only work in modern browsers and will only work if the output format is set to `es`. ```js // plugin diff --git a/docs/999-big-list-of-options.md b/docs/999-big-list-of-options.md index 95b50094f8a..4881a091b98 100755 --- a/docs/999-big-list-of-options.md +++ b/docs/999-big-list-of-options.md @@ -91,21 +91,21 @@ export default { When using the command line interface, multiple inputs can be provided by using the option multiple times. When provided as the first options, it is equivalent to not prefix them with `--input`: ```sh -rollup --format esm --input src/entry1.js --input src/entry2.js +rollup --format es --input src/entry1.js --input src/entry2.js # is equivalent to -rollup src/entry1.js src/entry2.js --format esm +rollup src/entry1.js src/entry2.js --format es ``` Chunks can be named by adding an `=` to the provided value: ```sh -rollup main=src/entry1.js other=src/entry2.js --format esm +rollup main=src/entry1.js other=src/entry2.js --format es ``` File names containing spaces can be specified by using quotes: ```sh -rollup "main entry"="src/entry 1.js" "src/other entry.js" --format esm +rollup "main entry"="src/entry 1.js" "src/other entry.js" --format es ``` #### output.dir @@ -128,7 +128,7 @@ Specifies the format of the generated bundle. One of the following: * `amd` – Asynchronous Module Definition, used with module loaders like RequireJS * `cjs` – CommonJS, suitable for Node and other bundlers -* `esm` – Keep the bundle as an ES module file, suitable for other bundlers and inclusion as a ` diff --git a/test/chunking-form/samples/emit-file/emit-chunk-worklet/index-es.html b/test/chunking-form/samples/emit-file/emit-chunk-worklet/index-es.html index af223f6c5c1..d458b71c059 100644 --- a/test/chunking-form/samples/emit-file/emit-chunk-worklet/index-es.html +++ b/test/chunking-form/samples/emit-file/emit-chunk-worklet/index-es.html @@ -2,7 +2,7 @@ - ESM + ES diff --git a/test/chunking-form/samples/filenames-patterns/_expected/es/chunk-main2-5251e7d2-esm.js b/test/chunking-form/samples/filenames-patterns/_expected/es/chunk-main2-bb2aced4-es.js similarity index 100% rename from test/chunking-form/samples/filenames-patterns/_expected/es/chunk-main2-5251e7d2-esm.js rename to test/chunking-form/samples/filenames-patterns/_expected/es/chunk-main2-bb2aced4-es.js diff --git a/test/chunking-form/samples/filenames-patterns/_expected/es/entry-main1-352fcfce-es.js b/test/chunking-form/samples/filenames-patterns/_expected/es/entry-main1-352fcfce-es.js new file mode 100644 index 00000000000..989bb35ec89 --- /dev/null +++ b/test/chunking-form/samples/filenames-patterns/_expected/es/entry-main1-352fcfce-es.js @@ -0,0 +1,3 @@ +import { l as log, d as dep } from './chunk-main2-bb2aced4-es.js'; + +log(dep); diff --git a/test/chunking-form/samples/filenames-patterns/_expected/es/entry-main1-d5bffcd6-esm.js b/test/chunking-form/samples/filenames-patterns/_expected/es/entry-main1-d5bffcd6-esm.js deleted file mode 100644 index a3165a74ff8..00000000000 --- a/test/chunking-form/samples/filenames-patterns/_expected/es/entry-main1-d5bffcd6-esm.js +++ /dev/null @@ -1,3 +0,0 @@ -import { l as log, d as dep } from './chunk-main2-5251e7d2-esm.js'; - -log(dep); diff --git a/test/chunking-form/samples/filenames-patterns/_expected/es/entry-main2-2d73322a-esm.js b/test/chunking-form/samples/filenames-patterns/_expected/es/entry-main2-2d73322a-esm.js deleted file mode 100644 index 8c65aad6124..00000000000 --- a/test/chunking-form/samples/filenames-patterns/_expected/es/entry-main2-2d73322a-esm.js +++ /dev/null @@ -1 +0,0 @@ -export { l as default } from './chunk-main2-5251e7d2-esm.js'; diff --git a/test/chunking-form/samples/filenames-patterns/_expected/es/entry-main2-8ebb5d84-es.js b/test/chunking-form/samples/filenames-patterns/_expected/es/entry-main2-8ebb5d84-es.js new file mode 100644 index 00000000000..eee53e0b1e0 --- /dev/null +++ b/test/chunking-form/samples/filenames-patterns/_expected/es/entry-main2-8ebb5d84-es.js @@ -0,0 +1 @@ +export { l as default } from './chunk-main2-bb2aced4-es.js'; diff --git a/test/chunking-form/samples/preserve-modules-filename-pattern/_expected/es/entry-foo-esm-ts.ts.js b/test/chunking-form/samples/preserve-modules-filename-pattern/_expected/es/entry-foo-es-ts.ts.js similarity index 100% rename from test/chunking-form/samples/preserve-modules-filename-pattern/_expected/es/entry-foo-esm-ts.ts.js rename to test/chunking-form/samples/preserve-modules-filename-pattern/_expected/es/entry-foo-es-ts.ts.js diff --git a/test/chunking-form/samples/preserve-modules-filename-pattern/_expected/es/entry-main-es-ts.ts.js b/test/chunking-form/samples/preserve-modules-filename-pattern/_expected/es/entry-main-es-ts.ts.js new file mode 100644 index 00000000000..341e9d48d9b --- /dev/null +++ b/test/chunking-form/samples/preserve-modules-filename-pattern/_expected/es/entry-main-es-ts.ts.js @@ -0,0 +1,4 @@ +export { default as foo } from './entry-foo-es-ts.ts.js'; +export { default as bar } from './nested/entry-bar-es-ts.ts.js'; +export { default as baz } from './nested/entry-baz-es-ts.ts.js'; +export { default as noExt } from './entry-no-ext-es-.js'; diff --git a/test/chunking-form/samples/preserve-modules-filename-pattern/_expected/es/entry-main-esm-ts.ts.js b/test/chunking-form/samples/preserve-modules-filename-pattern/_expected/es/entry-main-esm-ts.ts.js deleted file mode 100644 index 227d3f5e37a..00000000000 --- a/test/chunking-form/samples/preserve-modules-filename-pattern/_expected/es/entry-main-esm-ts.ts.js +++ /dev/null @@ -1,4 +0,0 @@ -export { default as foo } from './entry-foo-esm-ts.ts.js'; -export { default as bar } from './nested/entry-bar-esm-ts.ts.js'; -export { default as baz } from './nested/entry-baz-esm-ts.ts.js'; -export { default as noExt } from './entry-no-ext-esm-.js'; diff --git a/test/chunking-form/samples/preserve-modules-filename-pattern/_expected/es/entry-no-ext-esm-.js b/test/chunking-form/samples/preserve-modules-filename-pattern/_expected/es/entry-no-ext-es-.js similarity index 100% rename from test/chunking-form/samples/preserve-modules-filename-pattern/_expected/es/entry-no-ext-esm-.js rename to test/chunking-form/samples/preserve-modules-filename-pattern/_expected/es/entry-no-ext-es-.js diff --git a/test/chunking-form/samples/preserve-modules-filename-pattern/_expected/es/nested/entry-bar-esm-ts.ts.js b/test/chunking-form/samples/preserve-modules-filename-pattern/_expected/es/nested/entry-bar-es-ts.ts.js similarity index 100% rename from test/chunking-form/samples/preserve-modules-filename-pattern/_expected/es/nested/entry-bar-esm-ts.ts.js rename to test/chunking-form/samples/preserve-modules-filename-pattern/_expected/es/nested/entry-bar-es-ts.ts.js diff --git a/test/chunking-form/samples/preserve-modules-filename-pattern/_expected/es/nested/entry-baz-esm-ts.ts.js b/test/chunking-form/samples/preserve-modules-filename-pattern/_expected/es/nested/entry-baz-es-ts.ts.js similarity index 100% rename from test/chunking-form/samples/preserve-modules-filename-pattern/_expected/es/nested/entry-baz-esm-ts.ts.js rename to test/chunking-form/samples/preserve-modules-filename-pattern/_expected/es/nested/entry-baz-es-ts.ts.js diff --git a/test/cli/samples/config-plugin-entry/rollup.config.js b/test/cli/samples/config-plugin-entry/rollup.config.js index 07498e7db6a..0688f0c1e4d 100644 --- a/test/cli/samples/config-plugin-entry/rollup.config.js +++ b/test/cli/samples/config-plugin-entry/rollup.config.js @@ -1,6 +1,6 @@ export default { output: { - format: 'esm' + format: 'es' }, plugins: [ { diff --git a/test/cli/samples/deconflict-entry-point-in-subdir/_config.js b/test/cli/samples/deconflict-entry-point-in-subdir/_config.js index c68bead7d16..e45bfaeb3b0 100644 --- a/test/cli/samples/deconflict-entry-point-in-subdir/_config.js +++ b/test/cli/samples/deconflict-entry-point-in-subdir/_config.js @@ -1,5 +1,4 @@ module.exports = { description: 'deconflict entry points with the same name in different directories', - command: - 'rollup --input main.js --input sub/main.js --format esm --dir _actual' + command: 'rollup --input main.js --input sub/main.js --format es --dir _actual' }; diff --git a/test/cli/samples/emit-file-multiple-dirs/rollup.config.js b/test/cli/samples/emit-file-multiple-dirs/rollup.config.js index 5131be2d2f9..416e64898e3 100644 --- a/test/cli/samples/emit-file-multiple-dirs/rollup.config.js +++ b/test/cli/samples/emit-file-multiple-dirs/rollup.config.js @@ -7,7 +7,7 @@ export default { }, { dir: "_actual/dist2", - format: "esm" + format: "es" } ], plugins: [{ diff --git a/test/cli/samples/format-aliases/_config.js b/test/cli/samples/format-aliases/_config.js new file mode 100644 index 00000000000..f9f9d685f72 --- /dev/null +++ b/test/cli/samples/format-aliases/_config.js @@ -0,0 +1,4 @@ +module.exports = { + description: 'supports format aliases', + command: 'rollup --config' +}; diff --git a/test/cli/samples/format-aliases/_expected/amd.js b/test/cli/samples/format-aliases/_expected/amd.js new file mode 100644 index 00000000000..e6cfcfbac80 --- /dev/null +++ b/test/cli/samples/format-aliases/_expected/amd.js @@ -0,0 +1,11 @@ +define(['exports', 'external'], function (exports, external) { 'use strict'; + + external = external && external.hasOwnProperty('default') ? external['default'] : external; + + console.log('main'); + + exports.value = external; + + Object.defineProperty(exports, '__esModule', { value: true }); + +}); diff --git a/test/cli/samples/format-aliases/_expected/cjs.js b/test/cli/samples/format-aliases/_expected/cjs.js new file mode 100644 index 00000000000..ac291c6fe1b --- /dev/null +++ b/test/cli/samples/format-aliases/_expected/cjs.js @@ -0,0 +1,11 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } + +var external = _interopDefault(require('external')); + +console.log('main'); + +exports.value = external; diff --git a/test/cli/samples/format-aliases/_expected/commonjs.js b/test/cli/samples/format-aliases/_expected/commonjs.js new file mode 100644 index 00000000000..ac291c6fe1b --- /dev/null +++ b/test/cli/samples/format-aliases/_expected/commonjs.js @@ -0,0 +1,11 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } + +var external = _interopDefault(require('external')); + +console.log('main'); + +exports.value = external; diff --git a/test/cli/samples/format-aliases/_expected/es.js b/test/cli/samples/format-aliases/_expected/es.js new file mode 100644 index 00000000000..20ede6e8221 --- /dev/null +++ b/test/cli/samples/format-aliases/_expected/es.js @@ -0,0 +1,3 @@ +export { default as value } from 'external'; + +console.log('main'); diff --git a/test/cli/samples/format-aliases/_expected/esm.js b/test/cli/samples/format-aliases/_expected/esm.js new file mode 100644 index 00000000000..20ede6e8221 --- /dev/null +++ b/test/cli/samples/format-aliases/_expected/esm.js @@ -0,0 +1,3 @@ +export { default as value } from 'external'; + +console.log('main'); diff --git a/test/cli/samples/format-aliases/_expected/iife.js b/test/cli/samples/format-aliases/_expected/iife.js new file mode 100644 index 00000000000..1cc901f0135 --- /dev/null +++ b/test/cli/samples/format-aliases/_expected/iife.js @@ -0,0 +1,12 @@ +var bundle = (function (exports, external) { + 'use strict'; + + external = external && external.hasOwnProperty('default') ? external['default'] : external; + + console.log('main'); + + exports.value = external; + + return exports; + +}({}, external)); diff --git a/test/cli/samples/format-aliases/_expected/module.js b/test/cli/samples/format-aliases/_expected/module.js new file mode 100644 index 00000000000..20ede6e8221 --- /dev/null +++ b/test/cli/samples/format-aliases/_expected/module.js @@ -0,0 +1,3 @@ +export { default as value } from 'external'; + +console.log('main'); diff --git a/test/cli/samples/format-aliases/_expected/system.js b/test/cli/samples/format-aliases/_expected/system.js new file mode 100644 index 00000000000..4a614a259f8 --- /dev/null +++ b/test/cli/samples/format-aliases/_expected/system.js @@ -0,0 +1,13 @@ +System.register('bundle', ['external'], function (exports) { + 'use strict'; + return { + setters: [function (module) { + exports('value', module.default); + }], + execute: function () { + + console.log('main'); + + } + }; +}); diff --git a/test/cli/samples/format-aliases/_expected/systemjs.js b/test/cli/samples/format-aliases/_expected/systemjs.js new file mode 100644 index 00000000000..4a614a259f8 --- /dev/null +++ b/test/cli/samples/format-aliases/_expected/systemjs.js @@ -0,0 +1,13 @@ +System.register('bundle', ['external'], function (exports) { + 'use strict'; + return { + setters: [function (module) { + exports('value', module.default); + }], + execute: function () { + + console.log('main'); + + } + }; +}); diff --git a/test/cli/samples/format-aliases/_expected/umd.js b/test/cli/samples/format-aliases/_expected/umd.js new file mode 100644 index 00000000000..eb63711ef35 --- /dev/null +++ b/test/cli/samples/format-aliases/_expected/umd.js @@ -0,0 +1,15 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('external')) : + typeof define === 'function' && define.amd ? define(['exports', 'external'], factory) : + (global = global || self, factory(global.bundle = {}, global.external)); +}(this, (function (exports, external) { 'use strict'; + + external = external && external.hasOwnProperty('default') ? external['default'] : external; + + console.log('main'); + + exports.value = external; + + Object.defineProperty(exports, '__esModule', { value: true }); + +}))); diff --git a/test/cli/samples/format-aliases/_expected/undefined.js b/test/cli/samples/format-aliases/_expected/undefined.js new file mode 100644 index 00000000000..20ede6e8221 --- /dev/null +++ b/test/cli/samples/format-aliases/_expected/undefined.js @@ -0,0 +1,3 @@ +export { default as value } from 'external'; + +console.log('main'); diff --git a/test/cli/samples/format-aliases/main.js b/test/cli/samples/format-aliases/main.js new file mode 100644 index 00000000000..fc807f8119c --- /dev/null +++ b/test/cli/samples/format-aliases/main.js @@ -0,0 +1,3 @@ +import value from 'external'; +console.log('main'); +export { value }; diff --git a/test/cli/samples/format-aliases/rollup.config.js b/test/cli/samples/format-aliases/rollup.config.js new file mode 100644 index 00000000000..b8c75fc2454 --- /dev/null +++ b/test/cli/samples/format-aliases/rollup.config.js @@ -0,0 +1,24 @@ +export default { + input: 'main.js', + external: 'external', + output: [ + undefined, + 'es', + 'esm', + 'module', + 'cjs', + 'commonjs', + 'system', + 'systemjs', + 'amd', + 'iife', + 'umd' + ].map(format => ({ + file: `_actual/${format}.js`, + format, + name: 'bundle', + globals: { + external: 'external' + } + })) +}; diff --git a/test/cli/samples/merge-deprecations/rollup.config.js b/test/cli/samples/merge-deprecations/rollup.config.js index 67003241f2d..1a5b1160a29 100644 --- a/test/cli/samples/merge-deprecations/rollup.config.js +++ b/test/cli/samples/merge-deprecations/rollup.config.js @@ -3,11 +3,11 @@ var replace = require( 'rollup-plugin-replace' ); module.exports = { entry: 'main.js', input: 'main.js', - format: 'esm', + format: 'es', dest: '_actual/bundle1.js', output: { file: '_actual/bundle2.js', - format: 'esm' + format: 'es' }, plugins: [ replace( { 'ANSWER': 42 } ) diff --git a/test/cli/samples/silent-onwarn/rollup.config.js b/test/cli/samples/silent-onwarn/rollup.config.js index 8a1950bb762..051e24861d9 100644 --- a/test/cli/samples/silent-onwarn/rollup.config.js +++ b/test/cli/samples/silent-onwarn/rollup.config.js @@ -5,7 +5,7 @@ const warnings = []; export default { input: 'main.js', output: { - format: 'esm' + format: 'es' }, onwarn(warning) { warnings.push(warning); diff --git a/test/cli/samples/stdin/config-file/rollup.config.js b/test/cli/samples/stdin/config-file/rollup.config.js index 4590feac09c..90a4208fea1 100644 --- a/test/cli/samples/stdin/config-file/rollup.config.js +++ b/test/cli/samples/stdin/config-file/rollup.config.js @@ -10,14 +10,14 @@ export default [ input: '-', output: { file: '_actual/es.js', - format: 'esm' + format: 'es' } }, { input: 'a.mjs', output: { file: '_actual/no-stdin.js', - format: 'esm' + format: 'es' } } ]; diff --git a/test/cli/samples/stdin/no-stdin-config-file/_expected/esm.js b/test/cli/samples/stdin/no-stdin-config-file/_expected/es.js similarity index 100% rename from test/cli/samples/stdin/no-stdin-config-file/_expected/esm.js rename to test/cli/samples/stdin/no-stdin-config-file/_expected/es.js diff --git a/test/cli/samples/stdin/no-stdin-config-file/rollup.config.js b/test/cli/samples/stdin/no-stdin-config-file/rollup.config.js index ead39f6eaa1..586e950c8a4 100644 --- a/test/cli/samples/stdin/no-stdin-config-file/rollup.config.js +++ b/test/cli/samples/stdin/no-stdin-config-file/rollup.config.js @@ -9,8 +9,8 @@ export default [ { input: 'a.mjs', output: { - file: '_actual/esm.js', - format: 'esm' + file: '_actual/es.js', + format: 'es' } } ]; diff --git a/test/cli/samples/warn-broken-sourcemap/rollup.config.js b/test/cli/samples/warn-broken-sourcemap/rollup.config.js index d29788efcb6..12d5c2f69a4 100644 --- a/test/cli/samples/warn-broken-sourcemap/rollup.config.js +++ b/test/cli/samples/warn-broken-sourcemap/rollup.config.js @@ -9,7 +9,7 @@ module.exports = { } ], output: { - format: 'esm', + format: 'es', file: 'bundle', sourcemap: true } diff --git a/test/cli/samples/warn-broken-sourcemaps/rollup.config.js b/test/cli/samples/warn-broken-sourcemaps/rollup.config.js index c490546377b..f0054f99215 100644 --- a/test/cli/samples/warn-broken-sourcemaps/rollup.config.js +++ b/test/cli/samples/warn-broken-sourcemaps/rollup.config.js @@ -21,7 +21,7 @@ module.exports = { } ], output: { - format: 'esm', + format: 'es', file: 'bundle', sourcemap: true } diff --git a/test/cli/samples/warn-circular-multiple/rollup.config.js b/test/cli/samples/warn-circular-multiple/rollup.config.js index 3fcdc63ccf3..f5c018248fc 100644 --- a/test/cli/samples/warn-circular-multiple/rollup.config.js +++ b/test/cli/samples/warn-circular-multiple/rollup.config.js @@ -1,6 +1,6 @@ module.exports = { input: 'main.js', output: { - format: 'esm' + format: 'es' } }; diff --git a/test/cli/samples/warn-circular/rollup.config.js b/test/cli/samples/warn-circular/rollup.config.js index 3fcdc63ccf3..f5c018248fc 100644 --- a/test/cli/samples/warn-circular/rollup.config.js +++ b/test/cli/samples/warn-circular/rollup.config.js @@ -1,6 +1,6 @@ module.exports = { input: 'main.js', output: { - format: 'esm' + format: 'es' } }; diff --git a/test/cli/samples/warn-eval-multiple/rollup.config.js b/test/cli/samples/warn-eval-multiple/rollup.config.js index 3fcdc63ccf3..f5c018248fc 100644 --- a/test/cli/samples/warn-eval-multiple/rollup.config.js +++ b/test/cli/samples/warn-eval-multiple/rollup.config.js @@ -1,6 +1,6 @@ module.exports = { input: 'main.js', output: { - format: 'esm' + format: 'es' } }; diff --git a/test/cli/samples/warn-eval/rollup.config.js b/test/cli/samples/warn-eval/rollup.config.js index 3fcdc63ccf3..f5c018248fc 100644 --- a/test/cli/samples/warn-eval/rollup.config.js +++ b/test/cli/samples/warn-eval/rollup.config.js @@ -1,6 +1,6 @@ module.exports = { input: 'main.js', output: { - format: 'esm' + format: 'es' } }; diff --git a/test/cli/samples/warn-plugin/rollup.config.js b/test/cli/samples/warn-plugin/rollup.config.js index bd985d99739..55404aa5ab5 100644 --- a/test/cli/samples/warn-plugin/rollup.config.js +++ b/test/cli/samples/warn-plugin/rollup.config.js @@ -13,7 +13,7 @@ module.exports = { } ], output: { - format: 'esm', + format: 'es', plugins: [ { name: 'second-plugin', diff --git a/test/cli/samples/watch/rollup.config.js b/test/cli/samples/watch/rollup.config.js index 1b6e0556847..9dcbc4192f0 100644 --- a/test/cli/samples/watch/rollup.config.js +++ b/test/cli/samples/watch/rollup.config.js @@ -2,7 +2,7 @@ export default { input: 'main.js', output: { file: '_actual.js', - format: 'esm' + format: 'es' }, watch: { clearScreen: false diff --git a/test/file-hashes/index.js b/test/file-hashes/index.js index 60f46cf4b98..c03a467e4b9 100644 --- a/test/file-hashes/index.js +++ b/test/file-hashes/index.js @@ -15,7 +15,7 @@ runTestSuiteWithSamples('file hashes', path.resolve(__dirname, 'samples'), (dir, .then(bundle => bundle.generate( extend( - { format: 'esm', chunkFileNames: '[hash]', entryFileNames: '[hash]' }, + { format: 'es', chunkFileNames: '[hash]', entryFileNames: '[hash]' }, options.output ) ) diff --git a/test/file-hashes/samples/augment-chunk-hash/_config.js b/test/file-hashes/samples/augment-chunk-hash/_config.js index 4cc7c0f564e..06b9498eb86 100644 --- a/test/file-hashes/samples/augment-chunk-hash/_config.js +++ b/test/file-hashes/samples/augment-chunk-hash/_config.js @@ -5,7 +5,7 @@ module.exports = { options1: { input: 'main', output: { - format: 'esm', + format: 'es', entryFileNames: '[name]-[hash].js', chunkFileNames: '[name]-[hash].js' }, @@ -27,7 +27,7 @@ module.exports = { options2: { input: 'main', output: { - format: 'esm', + format: 'es', entryFileNames: '[name]-[hash].js', chunkFileNames: '[name]-[hash].js' }, diff --git a/test/file-hashes/samples/format/_config.js b/test/file-hashes/samples/format/_config.js index 604f450a8ca..1ea5521d2bd 100644 --- a/test/file-hashes/samples/format/_config.js +++ b/test/file-hashes/samples/format/_config.js @@ -3,7 +3,7 @@ module.exports = { options1: { input: 'main', output: { - format: 'esm' + format: 'es' } }, options2: { diff --git a/test/form/index.js b/test/form/index.js index 56eac6ecfe6..378646f4bb2 100644 --- a/test/form/index.js +++ b/test/form/index.js @@ -53,7 +53,7 @@ runTestSuiteWithSamples('form', path.resolve(__dirname, 'samples'), (dir, config }; if (isSingleFormatTest) { - return runRollupTest(dir + '/_actual.js', dir + '/_expected.js', 'esm'); + return runRollupTest(dir + '/_actual.js', dir + '/_expected.js', 'es'); } (config.formats || FORMATS).forEach(format => diff --git a/test/function/samples/dynamic-import-name-warn/_config.js b/test/function/samples/dynamic-import-name-warn/_config.js index 14c0cff4675..581dde7a8fa 100644 --- a/test/function/samples/dynamic-import-name-warn/_config.js +++ b/test/function/samples/dynamic-import-name-warn/_config.js @@ -1,7 +1,7 @@ const assert = require('assert'); module.exports = { - description: 'warns when specifying a custom importer function for formats other than "esm"', + description: 'warns when specifying a custom importer function for formats other than "es"', context: { require(path) { assert.equal(path, './foo.js'); @@ -26,7 +26,7 @@ module.exports = { warnings: [ { code: 'INVALID_OPTION', - message: '"output.dynamicImportFunction" is ignored for formats other than "esm".' + message: '"output.dynamicImportFunction" is ignored for formats other than "es".' } ] }; diff --git a/test/function/samples/dynamic-import-name/_config.js b/test/function/samples/dynamic-import-name/_config.js index e31e98bbc76..917b20a396f 100644 --- a/test/function/samples/dynamic-import-name/_config.js +++ b/test/function/samples/dynamic-import-name/_config.js @@ -18,7 +18,7 @@ module.exports = { }, output: { dynamicImportFunction: 'myImporter', - format: 'esm' + format: 'es' } }, exports() { diff --git a/test/function/samples/preserve-modules/virtual-modules-conflict/_config.js b/test/function/samples/preserve-modules/virtual-modules-conflict/_config.js index dbd42c766d4..6739c34f66c 100644 --- a/test/function/samples/preserve-modules/virtual-modules-conflict/_config.js +++ b/test/function/samples/preserve-modules/virtual-modules-conflict/_config.js @@ -22,14 +22,11 @@ module.exports = { ] }, bundle(bundle) { - return bundle - .generate({ format: 'esm' }) - .then(generated => - assert.deepEqual(generated.output.map(chunk => chunk.fileName), [ - 'main.js', - '_virtual/_virtualModule.js', - '_virtual/_virtualModule2.js' - ]) - ); + return bundle.generate({ format: 'es' }).then(generated => + assert.deepEqual( + generated.output.map(chunk => chunk.fileName), + ['main.js', '_virtual/_virtualModule.js', '_virtual/_virtualModule2.js'] + ) + ); } }; diff --git a/test/function/samples/preserve-modules/virtual-modules/_config.js b/test/function/samples/preserve-modules/virtual-modules/_config.js index 591d4d4b317..17cbf8b541b 100644 --- a/test/function/samples/preserve-modules/virtual-modules/_config.js +++ b/test/function/samples/preserve-modules/virtual-modules/_config.js @@ -22,14 +22,11 @@ module.exports = { ] }, bundle(bundle) { - return bundle - .generate({ format: 'esm' }) - .then(generated => - assert.deepEqual(generated.output.map(chunk => chunk.fileName), [ - 'main.js', - '_virtual/_virtualModule', - 'lib/lib.js' - ]) - ); + return bundle.generate({ format: 'es' }).then(generated => + assert.deepEqual( + generated.output.map(chunk => chunk.fileName), + ['main.js', '_virtual/_virtualModule', 'lib/lib.js'] + ) + ); } }; diff --git a/test/hooks/index.js b/test/hooks/index.js index c1984e6d55e..62ba5d14c94 100644 --- a/test/hooks/index.js +++ b/test/hooks/index.js @@ -86,7 +86,7 @@ describe('hooks', () => { .then(bundle => bundle.write({ file: path.join(TEMP_DIR, 'bundle.js'), - format: 'esm' + format: 'es' }) ) .then(() => { @@ -628,7 +628,7 @@ describe('hooks', () => { } ] }) - .then(bundle => bundle.write({ format: 'esm', file })) + .then(bundle => bundle.write({ format: 'es', file })) .then(() => { assert.strictEqual(callCount, 1); return sander.rimraf(TEMP_DIR); @@ -856,7 +856,7 @@ describe('hooks', () => { } ] }) - .then(bundle => bundle.generate({ format: 'esm' })) + .then(bundle => bundle.generate({ format: 'es' })) .then(() => { assert.strictEqual(renderStartCount, 1, 'renderStart count'); assert.strictEqual(generateBundleCount, 1, 'generateBundle count'); @@ -892,7 +892,7 @@ describe('hooks', () => { } ] }) - .then(bundle => bundle.generate({ format: 'esm' })) + .then(bundle => bundle.generate({ format: 'es' })) .catch(err => { assert.ok(err); }) @@ -907,7 +907,7 @@ describe('hooks', () => { const watcher = rollup.watch({ input: 'input', output: { - format: 'esm' + format: 'es' }, plugins: [loader({ input: `alert('hello')` })] }); @@ -931,7 +931,7 @@ describe('hooks', () => { const watcher = rollup.watch({ input: 'input', output: { - format: 'esm', + format: 'es', file: 'bundle.js' }, plugins: [loader({ input: `import('dep')`, dep: `console.log('dep')` })] @@ -956,7 +956,7 @@ describe('hooks', () => { const watcher = rollup.watch({ input: 'input', output: { - format: 'esm', + format: 'es', sourcemapFile: 'bundle.map', dir: 'ignored' }, @@ -1006,7 +1006,7 @@ describe('hooks', () => { bundle.generate({ entryFileNames: '[name].js', chunkFileNames: 'generated-[name].js', - format: 'esm' + format: 'es' }) ) .then(() => { @@ -1055,7 +1055,7 @@ describe('hooks', () => { }) .then(bundle => bundle.generate({ - format: 'esm', + format: 'es', dir: 'dist', entryFileNames: '[name]-[hash].js' }) diff --git a/test/misc/bundle-information.js b/test/misc/bundle-information.js index 3bf50a9ebc9..70acf942b23 100644 --- a/test/misc/bundle-information.js +++ b/test/misc/bundle-information.js @@ -17,7 +17,7 @@ describe('The bundle object', () => { }) .then(bundle => bundle.generate({ - format: 'esm', + format: 'es', dir: 'dist', chunkFileNames: 'generated-[name]-[hash].js', entryFileNames: '[name]-[hash].js' @@ -121,7 +121,7 @@ describe('The bundle object', () => { }) .then(bundle => bundle.generate({ - format: 'esm', + format: 'es', dir: 'dist', chunkFileNames: 'generated-[name].js' }) @@ -165,7 +165,7 @@ describe('The bundle object', () => { }) .then(bundle => bundle.generate({ - format: 'esm', + format: 'es', dir: 'dist', entryFileNames: '[name].js', chunkFileNames: '[name].js' @@ -199,7 +199,7 @@ describe('The bundle object', () => { }) .then(bundle => bundle.generate({ - format: 'esm', + format: 'es', dir: 'dist', entryFileNames: '[name].js', chunkFileNames: 'generated-[name].js' @@ -258,7 +258,7 @@ describe('The bundle object', () => { }) .then(bundle => bundle.generate({ - format: 'esm', + format: 'es', dir: 'dist', entryFileNames: '[name].js', chunkFileNames: 'generated-[name].js' @@ -306,7 +306,7 @@ describe('The bundle object', () => { }) .then(bundle => bundle.generate({ - format: 'esm', + format: 'es', dir: 'dist', entryFileNames: '[name].js', chunkFileNames: 'generated-[name].js' @@ -361,7 +361,7 @@ describe('The bundle object', () => { }) .then(bundle => bundle.generate({ - format: 'esm', + format: 'es', dir: 'dist', entryFileNames: '[name].js', chunkFileNames: 'generated-[name].js' @@ -478,7 +478,7 @@ console.log(other);Promise.all([import('./dynamic1'), import('./dynamic2')]).the }) .then(bundle => bundle.generate({ - format: 'esm' + format: 'es' }) ) .then(({ output: [output] }) => { @@ -530,7 +530,7 @@ console.log(other);Promise.all([import('./dynamic1'), import('./dynamic2')]).the }) .then(bundle => bundle.generate({ - format: 'esm' + format: 'es' }) ) .then(({ output: [output] }) => { diff --git a/test/misc/deprecations.js b/test/misc/deprecations.js index ff6e0a6e2b1..adaf27c0119 100644 --- a/test/misc/deprecations.js +++ b/test/misc/deprecations.js @@ -3,10 +3,10 @@ const rollup = require('../../dist/rollup'); const { loader } = require('../utils.js'); describe('deprecations', () => { - it('supports esm format alias', () => { + it('supports es format alias', () => { return rollup .rollup({ input: 'x', plugins: [loader({ x: 'export const x = function () {}' })] }) - .then(bundle => bundle.generate({ format: 'esm' })) + .then(bundle => bundle.generate({ format: 'es' })) .then(({ output: [{ code }] }) => { assert.equal(code, 'const x = function () {};\n\nexport { x };\n'); }); diff --git a/test/misc/misc.js b/test/misc/misc.js index e5c9950b6fb..55a0d487da3 100644 --- a/test/misc/misc.js +++ b/test/misc/misc.js @@ -133,12 +133,12 @@ describe('misc', () => { .then(bundle => Promise.all([ bundle - .generate({ format: 'esm' }) + .generate({ format: 'es' }) .then(generated => assert.equal(generated.output[0].code, "import 'the-answer';\n", 'no render path 1') ), bundle - .generate({ format: 'esm', paths: id => `//unpkg.com/${id}@?module` }) + .generate({ format: 'es', paths: id => `//unpkg.com/${id}@?module` }) .then(generated => assert.equal( generated.output[0].code, @@ -147,7 +147,7 @@ describe('misc', () => { ) ), bundle - .generate({ format: 'esm' }) + .generate({ format: 'es' }) .then(generated => assert.equal(generated.output[0].code, "import 'the-answer';\n", 'no render path 2') ) @@ -164,7 +164,7 @@ describe('misc', () => { }) ], output: { - format: 'esm' + format: 'es' } }; diff --git a/test/misc/sanity-checks.js b/test/misc/sanity-checks.js index e5371fb98a0..a4e8b665042 100644 --- a/test/misc/sanity-checks.js +++ b/test/misc/sanity-checks.js @@ -107,7 +107,7 @@ describe('sanity checks', () => { .then(bundle => { assert.throws(() => { bundle.generate({ file: 'x', format: 'vanilla' }); - }, /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", "es", "iife" or "umd"./); }); }); diff --git a/test/misc/write-bundle.js b/test/misc/write-bundle.js index 6b2e4adc474..5be5b07c6df 100644 --- a/test/misc/write-bundle.js +++ b/test/misc/write-bundle.js @@ -20,7 +20,7 @@ describe('bundle.write()', () => { }, /You must supply an options object/); assert.throws(() => { - bundle.write({format: 'esm'}); + bundle.write({format: 'es'}); }, /You must specify "output\.file"/); }); });