From b6251df9e485a507a82469e52e13b70d4bad25d2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 25 Feb 2020 06:23:55 +0100 Subject: [PATCH 01/11] Bump codecov from 3.6.1 to 3.6.5 (#3392) Bumps [codecov](https://github.com/codecov/codecov-node) from 3.6.1 to 3.6.5. - [Release notes](https://github.com/codecov/codecov-node/releases) - [Commits](https://github.com/codecov/codecov-node/commits) Signed-off-by: dependabot[bot] --- package-lock.json | 172 ++++++++++++++++++++++++++++++---------------- 1 file changed, 114 insertions(+), 58 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5a4e890cb01..aee8b007305 100644 --- a/package-lock.json +++ b/package-lock.json @@ -334,6 +334,12 @@ "any-observable": "^0.3.0" } }, + "@tootallnate/once": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-1.0.0.tgz", + "integrity": "sha512-KYyTT/T6ALPkIRd2Ge080X/BsXvy9O0hcWTtMWkPvwAwF99+vn6Dv4GzrFT/Nn1LePr+FFDbRXXlqmsy9lw2zA==", + "dev": true + }, "@types/braces": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/@types/braces/-/braces-3.0.0.tgz", @@ -480,12 +486,29 @@ "dev": true }, "agent-base": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-4.3.0.tgz", - "integrity": "sha512-salcGninV0nPrwpGNn4VTXBb1SOuXQBiqbrNXoeizJsHrsL6ERFM2Ne3JUSBWRE6aeNJI2ROP/WEEIDUiDe3cg==", + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.0.tgz", + "integrity": "sha512-j1Q7cSCqN+AwrmDd+pzgqc0/NpC655x2bUf5ZjRIO77DcNBFmh+OgRNzF6OKdCC9RSCb19fGd99+bhXFdkRNqw==", "dev": true, "requires": { - "es6-promisify": "^5.0.0" + "debug": "4" + }, + "dependencies": { + "debug": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", + "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true + } } }, "aggregate-error": { @@ -1188,16 +1211,27 @@ "dev": true }, "codecov": { - "version": "3.6.1", - "resolved": "https://registry.npmjs.org/codecov/-/codecov-3.6.1.tgz", - "integrity": "sha512-IUJB6WG47nWK7o50etF8jBadxdMw7DmoQg05yIljstXFBGB6clOZsIj6iD4P82T2YaIU3qq+FFu8K9pxgkCJDQ==", + "version": "3.6.5", + "resolved": "https://registry.npmjs.org/codecov/-/codecov-3.6.5.tgz", + "integrity": "sha512-v48WuDMUug6JXwmmfsMzhCHRnhUf8O3duqXvltaYJKrO1OekZWpB/eH6iIoaxMl8Qli0+u3OxptdsBOYiD7VAQ==", "dev": true, "requires": { - "argv": "^0.0.2", - "ignore-walk": "^3.0.1", - "js-yaml": "^3.13.1", - "teeny-request": "^3.11.3", - "urlgrey": "^0.4.4" + "argv": "0.0.2", + "ignore-walk": "3.0.3", + "js-yaml": "3.13.1", + "teeny-request": "6.0.1", + "urlgrey": "0.4.4" + }, + "dependencies": { + "ignore-walk": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/ignore-walk/-/ignore-walk-3.0.3.tgz", + "integrity": "sha512-m7o6xuOaT1aqheYHKf8W6J5pYH85ZI9w077erOzLje3JsB1gkafkAhHHY19dqjulgIZHFm32Cp5uNZgcQqdJKw==", + "dev": true, + "requires": { + "minimatch": "^3.0.4" + } + } } }, "collection-visit": { @@ -1651,21 +1685,6 @@ "integrity": "sha1-wsNYJlYkfDnqEHyx5mUrb58kUjw=", "dev": true }, - "es6-promise": { - "version": "4.2.8", - "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.8.tgz", - "integrity": "sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w==", - "dev": true - }, - "es6-promisify": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/es6-promisify/-/es6-promisify-5.0.0.tgz", - "integrity": "sha1-UQnWLz5W6pZ8S2NQWu8IKRyKUgM=", - "dev": true, - "requires": { - "es6-promise": "^4.0.3" - } - }, "es6-shim": { "version": "0.35.5", "resolved": "https://registry.npmjs.org/es6-shim/-/es6-shim-0.35.5.tgz", @@ -2827,20 +2846,54 @@ "integrity": "sha512-a4u9BeERWGu/S8JiWEAQcdrg9v4QArtP9keViQjGMdff20fBdd8waotXaNmODqBe6uZ3Nafi7K/ho4gCQHV3Ig==", "dev": true }, + "http-proxy-agent": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-4.0.1.tgz", + "integrity": "sha512-k0zdNgqWTGA6aeIRVpvfVob4fL52dTfaehylg0Y4UvSySvOq/Y+BOyPrgpUrA7HylqvU8vIZGsRuXmspskV0Tg==", + "dev": true, + "requires": { + "@tootallnate/once": "1", + "agent-base": "6", + "debug": "4" + }, + "dependencies": { + "debug": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", + "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true + } + } + }, "https-proxy-agent": { - "version": "2.2.4", - "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-2.2.4.tgz", - "integrity": "sha512-OmvfoQ53WLjtA9HeYP9RNrWMJzzAz1JGaSFr1nijg0PVR1JaD/xbJq1mdEIIlxGpXp9eSe/O2LgU9DJmTPd0Eg==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-4.0.0.tgz", + "integrity": "sha512-zoDhWrkR3of1l9QAL8/scJZyLu8j/gBkcwcaQOZh7Gyh/+uJQzGVETdgT30akuwkpL8HTRfssqI3BZuV18teDg==", "dev": true, "requires": { - "agent-base": "^4.3.0", - "debug": "^3.1.0" + "agent-base": "5", + "debug": "4" }, "dependencies": { + "agent-base": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-5.1.1.tgz", + "integrity": "sha512-TMeqbNl2fMW0nMjTEPOwe3J/PRFP4vqeoNuQMG0HlMrtm5QxKqdvAkZ1pRBQ/ulIyDD5Yq0nJ7YbdD8ey0TO3g==", + "dev": true + }, "debug": { - "version": "3.2.6", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz", - "integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==", + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", + "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", "dev": true, "requires": { "ms": "^2.1.1" @@ -3037,6 +3090,7 @@ "resolved": "https://registry.npmjs.org/ignore-walk/-/ignore-walk-3.0.1.tgz", "integrity": "sha512-DTVlMx3IYPe0/JJcYP7Gxg7ttZZu3IInhuEhbchuqneY9wWe5Ojy2mXLBaQFUQmo0AW2r3qG7m1mg86js+gnlQ==", "dev": true, + "optional": true, "requires": { "minimatch": "^3.0.4" } @@ -3678,7 +3732,7 @@ }, "jsesc": { "version": "0.5.0", - "resolved": "http://registry.npmjs.org/jsesc/-/jsesc-0.5.0.tgz", + "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-0.5.0.tgz", "integrity": "sha1-597mbjXW/Bb3EP6R1c9p9w8IkR0=", "dev": true }, @@ -6328,6 +6382,15 @@ } } }, + "stream-events": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/stream-events/-/stream-events-1.0.5.tgz", + "integrity": "sha512-E1GUzBSgvct8Jsb3v2X15pjzN1tYebtbLaMg+eBOUOAxgbLoSbT2NS91ckc5lJD1KfLjId+jXJRgo0qnV5Nerg==", + "dev": true, + "requires": { + "stubs": "^3.0.0" + } + }, "string-argv": { "version": "0.3.1", "resolved": "https://registry.npmjs.org/string-argv/-/string-argv-0.3.1.tgz", @@ -6411,6 +6474,12 @@ "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=", "dev": true }, + "stubs": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/stubs/-/stubs-3.0.0.tgz", + "integrity": "sha1-6NK6H6nJBXAwPAMLaQD31fiavls=", + "dev": true + }, "supports-color": { "version": "5.5.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", @@ -6489,29 +6558,16 @@ } }, "teeny-request": { - "version": "3.11.3", - "resolved": "https://registry.npmjs.org/teeny-request/-/teeny-request-3.11.3.tgz", - "integrity": "sha512-CKncqSF7sH6p4rzCgkb/z/Pcos5efl0DmolzvlqRQUNcpRIruOhY9+T1FsIlyEbfWd7MsFpodROOwHYh2BaXzw==", + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/teeny-request/-/teeny-request-6.0.1.tgz", + "integrity": "sha512-TAK0c9a00ELOqLrZ49cFxvPVogMUFaWY8dUsQc/0CuQPGF+BOxOQzXfE413BAk2kLomwNplvdtMpeaeGWmoc2g==", "dev": true, "requires": { - "https-proxy-agent": "^2.2.1", + "http-proxy-agent": "^4.0.0", + "https-proxy-agent": "^4.0.0", "node-fetch": "^2.2.0", + "stream-events": "^1.0.5", "uuid": "^3.3.2" - }, - "dependencies": { - "debug": { - "version": "3.2.6", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz", - "integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==", - "requires": { - "ms": "^2.1.1" - } - }, - "ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" - } } }, "terser": { @@ -6855,9 +6911,9 @@ "dev": true }, "uuid": { - "version": "3.3.2", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.2.tgz", - "integrity": "sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA==", + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", + "integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==", "dev": true }, "v8-compile-cache": { From 1d8a09e8a2045f50285be68b2aae1f59305a38c4 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Wed, 26 Feb 2020 09:10:45 +0100 Subject: [PATCH 02/11] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5c0594c913..854af373fb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Pull Requests * [#3390](https://github.com/rollup/rollup/pull/3390): fix typo: this.addWatchfile (@mistlog) +* [#3392](https://github.com/rollup/rollup/pull/3392): Bump codecov from 3.6.1 to 3.6.5 ## 1.31.1 *2020-02-14* From 1b5f505b5c49eca6216ca7d53d6c7772d3108917 Mon Sep 17 00:00:00 2001 From: Jake Archibald Date: Wed, 26 Feb 2020 17:05:57 +0100 Subject: [PATCH 03/11] Update resolveFileUrl docs (#3404) Fixes #3404 --- docs/05-plugin-development.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/05-plugin-development.md b/docs/05-plugin-development.md index 7686f344363..eefbd4f03d2 100644 --- a/docs/05-plugin-development.md +++ b/docs/05-plugin-development.md @@ -262,16 +262,15 @@ Type: `({chunkId: string, fileName: string, format: string, moduleId: string, re Kind: `sync, first`
Phase: `generate` -Allows to customize how Rollup resolves URLs of files that were emitted by plugins via `this.emitAsset` or `this.emitChunk`. By default, Rollup will generate code for `import.meta.ROLLUP_ASSET_URL_assetReferenceId` and `import.meta.ROLLUP_CHUNK_URL_chunkReferenceId` that should correctly generate absolute URLs of emitted files independent of the output format and the host system where the code is deployed. +Allows to customize how Rollup resolves URLs of files that were emitted by plugins via `this.emitFile`. By default, Rollup will generate code for `import.meta.ROLLUP_FILE_URL_referenceId` that should correctly generate absolute URLs of emitted files independent of the output format and the host system where the code is deployed. For that, all formats except CommonJS and UMD assume that they run in a browser environment where `URL` and `document` are available. In case that fails or to generate more optimized code, this hook can be used to customize this behaviour. To do that, the following information is available: -- `assetReferenceId`: The asset reference id if we are resolving `import.meta.ROLLUP_ASSET_URL_assetReferenceId`, otherwise `null`. - `chunkId`: The id of the chunk this file is referenced from. -- `chunkReferenceId`: The chunk reference id if we are resolving `import.meta.ROLLUP_CHUNK_URL_chunkReferenceId`, otherwise `null`. - `fileName`: The path and file name of the emitted asset, relative to `output.dir` without a leading `./`. - `format`: The rendered output format. - `moduleId`: The id of the original module this file is referenced from. Useful for conditionally resolving certain assets differently. +- `referenceId`: The reference id of the file. - `relativePath`: The path and file name of the emitted file, relative to the chunk the file is referenced from. This will path will contain no leading `./` but may contain a leading `../`. Note that since this hook has access to the filename of the current chunk, its return value will not be considered when generating the hash of this chunk. From 07223ebc8de219f7876ccf3c4e8253b4d1807212 Mon Sep 17 00:00:00 2001 From: kzc Date: Fri, 28 Feb 2020 00:40:37 -0500 Subject: [PATCH 04/11] introduce CLI --plugin support (#3379) * introduce CLI --plugin support - provide plugin prefixes as required - support new and old styles of plugin naming Examples: --plugin rollup-plugin-buble --plugin @rollup/plugin-buble --plugin buble -p "@rollup/plugin-replace={DBG:true}" -p node-resolve,commonjs -p "terser={output:{beautify:true}}" -p "/absolute/path/to/plugin={A:1}" -p "../relative/path/to/plugin={B:2}" * Add documentation, fix error handling * Fix markdown formatting * Remove trailing slash * Fix examples in documentation Co-authored-by: Lukas Taegert-Atkinson --- cli/help.md | 1 + cli/run/build.ts | 16 +--- cli/run/index.ts | 91 ++++++++++++++++--- cli/run/loadConfigFile.ts | 4 +- docs/01-command-line-reference.md | 42 +++++++++ src/utils/mergeOptions.ts | 2 + test/cli/samples/plugin/absolute/_config.js | 5 + test/cli/samples/plugin/absolute/_expected.js | 1 + test/cli/samples/plugin/absolute/my-plugin.js | 14 +++ test/cli/samples/plugin/advanced/_config.js | 5 + .../samples/plugin/advanced/_expected/cjs.js | 17 ++++ .../samples/plugin/advanced/_expected/es.js | 13 +++ test/cli/samples/plugin/advanced/main.js | 4 + .../plugin/advanced/node_modules/foo/index.js | 10 ++ .../advanced/node_modules/print/index.js | 3 + .../samples/plugin/advanced/rollup.config.js | 18 ++++ test/cli/samples/plugin/basic/_config.js | 4 + test/cli/samples/plugin/basic/_expected.js | 14 +++ test/cli/samples/plugin/basic/main.js | 10 ++ .../cli/samples/plugin/cannot-load/_config.js | 10 ++ .../plugin/invalid-argument/_config.js | 10 ++ test/cli/samples/plugin/object/_config.js | 5 + test/cli/samples/plugin/object/_expected.js | 5 + test/cli/samples/plugin/relative/_config.js | 5 + test/cli/samples/plugin/relative/_expected.js | 1 + test/misc/optionList.js | 2 +- 26 files changed, 286 insertions(+), 26 deletions(-) create mode 100644 test/cli/samples/plugin/absolute/_config.js create mode 100644 test/cli/samples/plugin/absolute/_expected.js create mode 100644 test/cli/samples/plugin/absolute/my-plugin.js create mode 100644 test/cli/samples/plugin/advanced/_config.js create mode 100644 test/cli/samples/plugin/advanced/_expected/cjs.js create mode 100644 test/cli/samples/plugin/advanced/_expected/es.js create mode 100644 test/cli/samples/plugin/advanced/main.js create mode 100644 test/cli/samples/plugin/advanced/node_modules/foo/index.js create mode 100644 test/cli/samples/plugin/advanced/node_modules/print/index.js create mode 100644 test/cli/samples/plugin/advanced/rollup.config.js create mode 100644 test/cli/samples/plugin/basic/_config.js create mode 100644 test/cli/samples/plugin/basic/_expected.js create mode 100644 test/cli/samples/plugin/basic/main.js create mode 100644 test/cli/samples/plugin/cannot-load/_config.js create mode 100644 test/cli/samples/plugin/invalid-argument/_config.js create mode 100644 test/cli/samples/plugin/object/_config.js create mode 100644 test/cli/samples/plugin/object/_expected.js create mode 100644 test/cli/samples/plugin/relative/_config.js create mode 100644 test/cli/samples/plugin/relative/_expected.js diff --git a/cli/help.md b/cli/help.md index 0e7520d1ae2..f4aaf073ab5 100644 --- a/cli/help.md +++ b/cli/help.md @@ -16,6 +16,7 @@ Basic options: -m, --sourcemap Generate sourcemap (`-m inline` for inline map) -n, --name Name for UMD export -o, --file Single output file (if absent, prints to stdout) +-p, --plugin Use the plugin specified (may be repeated) -v, --version Show version number -w, --watch Watch files in bundle and rebuild on changes --amd.id ID for AMD module (default is anonymous) diff --git a/cli/run/build.ts b/cli/run/build.ts index 8182b9cce72..bb339882c73 100644 --- a/cli/run/build.ts +++ b/cli/run/build.ts @@ -13,13 +13,11 @@ export default function build( outputOptions: OutputOptions[], warnings: BatchWarnings, silent = false -) { +): Promise { const useStdout = !outputOptions[0].file && !outputOptions[0].dir; const start = Date.now(); - const files = useStdout - ? ['stdout'] - : outputOptions.map(t => relativeId(t.file || t.dir!)); + const files = useStdout ? ['stdout'] : outputOptions.map(t => relativeId(t.file || t.dir!)); if (!silent) { let inputFiles: string | undefined; if (typeof inputOptions.input === 'string') { @@ -61,13 +59,11 @@ export default function build( process.stdout.write('\n' + tc.cyan(tc.bold('//→ ' + file.fileName + ':')) + '\n'); process.stdout.write(source); } - return null + return null; }); } - return Promise.all(outputOptions.map(output => bundle.write(output))).then( - () => bundle - ); + return Promise.all(outputOptions.map(output => bundle.write(output))).then(() => bundle); }) .then((bundle: RollupBuild | null) => { if (!silent) { @@ -79,9 +75,5 @@ export default function build( printTimings(bundle.getTimings()); } } - }) - .catch((err: Error) => { - warnings.flush(); - handleError(err); }); } diff --git a/cli/run/index.ts b/cli/run/index.ts index d44a32a101b..7316f8ed471 100644 --- a/cli/run/index.ts +++ b/cli/run/index.ts @@ -1,6 +1,7 @@ import { realpathSync } from 'fs'; +import * as path from 'path'; import relative from 'require-relative'; -import { WarningHandler } from '../../src/rollup/types'; +import { InputOptions, WarningHandler } from '../../src/rollup/types'; import mergeOptions, { GenericConfigObject } from '../../src/utils/mergeOptions'; import { getAliasName } from '../../src/utils/relativeId'; import { handleError } from '../logging'; @@ -107,18 +108,86 @@ async function execute( } else { for (const config of configs) { const warnings = batchWarnings(); - const { inputOptions, outputOptions, optionError } = mergeOptions({ - command, - config, - defaultOnWarnHandler: warnings.add - }); - if (optionError) { - (inputOptions.onwarn as WarningHandler)({ code: 'UNKNOWN_OPTION', message: optionError }); + try { + const { inputOptions, outputOptions, optionError } = mergeOptions({ + command, + config, + defaultOnWarnHandler: warnings.add + }); + if (optionError) { + (inputOptions.onwarn as WarningHandler)({ code: 'UNKNOWN_OPTION', message: optionError }); + } + if (command.stdin !== false) { + inputOptions.plugins!.push(stdinPlugin()); + } + if (command.plugin) { + const plugins = Array.isArray(command.plugin) ? command.plugin : [command.plugin]; + for (const plugin of plugins) { + if (/[={}]/.test(plugin)) { + // -p plugin=value + // -p "{transform(c,i){...}}" + loadAndRegisterPlugin(inputOptions, plugin); + } else { + // split out plugins joined by commas + // -p node-resolve,commonjs,buble + plugin + .split(',') + .forEach((plugin: string) => loadAndRegisterPlugin(inputOptions, plugin)); + } + } + } + await build(inputOptions, outputOptions, warnings, command.silent); + } catch (err) { + warnings.flush(); + handleError(err); + } + } + } +} + +function loadAndRegisterPlugin(inputOptions: InputOptions, pluginText: string) { + let plugin: any = null; + let pluginArg: any = undefined; + if (pluginText[0] === '{') { + // -p "{transform(c,i){...}}" + plugin = new Function('return ' + pluginText); + } else { + const match = pluginText.match(/^([@.\/\\\w|^{}|-]+)(=(.*))?$/); + if (match) { + // -p plugin + // -p plugin=arg + pluginText = match[1]; + pluginArg = new Function('return ' + match[3])(); + } else { + throw new Error(`Invalid --plugin argument format: ${JSON.stringify(pluginText)}`); + } + if (!/^\.|^rollup-plugin-|[@\/\\]/.test(pluginText)) { + // Try using plugin prefix variations first if applicable. + // Prefix order is significant - left has higher precedence. + for (const prefix of ['@rollup/plugin-', 'rollup-plugin-']) { + try { + plugin = require(prefix + pluginText); + break; + } catch (ex) { + // if this does not work, we try requiring the actual name below + } } - if (command.stdin !== false) { - inputOptions.plugins!.push(stdinPlugin()); + } + if (!plugin) { + try { + if (pluginText[0] == '.') pluginText = path.resolve(pluginText); + plugin = require(pluginText); + } catch (ex) { + throw new Error(`Cannot load plugin "${pluginText}"`); } - await build(inputOptions, outputOptions, warnings, command.silent); } } + if (typeof plugin === 'object' && pluginText in plugin) { + // some plugins do not use `export default` for their entry point. + // attempt to use the plugin name as the named import name. + plugin = plugin[pluginText]; + } + inputOptions.plugins!.push( + typeof plugin === 'function' ? plugin.call(plugin, pluginArg) : plugin + ); } diff --git a/cli/run/loadConfigFile.ts b/cli/run/loadConfigFile.ts index da7a911fc95..e506150c3a3 100644 --- a/cli/run/loadConfigFile.ts +++ b/cli/run/loadConfigFile.ts @@ -1,4 +1,4 @@ -import path from 'path'; +import * as path from 'path'; import tc from 'turbocolor'; import * as rollup from '../../src/node-entry'; import { RollupBuild, RollupOutput } from '../../src/rollup/types'; @@ -73,4 +73,4 @@ export default function loadConfigFile( return Array.isArray(configs) ? configs : [configs]; }); }); -} \ No newline at end of file +} diff --git a/docs/01-command-line-reference.md b/docs/01-command-line-reference.md index 1cb74a4a9ac..b2aa9f0c4f5 100755 --- a/docs/01-command-line-reference.md +++ b/docs/01-command-line-reference.md @@ -220,6 +220,7 @@ Many options have command line equivalents. In those cases, any arguments passed -m, --sourcemap Generate sourcemap (`-m inline` for inline map) -n, --name Name for UMD export -o, --file Single output file (if absent, prints to stdout) +-p, --plugin Use the plugin specified (may be repeated) -v, --version Show version number -w, --watch Watch files in bundle and rebuild on changes --amd.id ID for AMD module (default is anonymous) @@ -268,6 +269,47 @@ The flags listed below are only available via the command line interface. All ot Print the help document. +#### `-p `, `--plugin ` + +Use the specified plugin. There are several ways to specify plugins here: + +- Via a relative path: + + ``` + rollup -i input.js -f es -p ./my-plugin.js + ``` + + The file should export a plugin object or a function returning such an object. +- Via the name of a plugin that is installed in a local or global `node_modules` folder: + + ``` + rollup -i input.js -f es -p @rollup/plugin-node-resolve + ``` + + If the plugin name does not start with `rollup-plugin-` or `@rollup/plugin-`, Rollup will automatically try adding these prefixes: + + ``` + rollup -i input.js -f es -p node-resolve + ``` + +- Via an inline implementation: + + ``` + rollup -i input.js -f es -p '{transform: (c, i) => `/* ${JSON.stringify(i)} */\n${c}`}' + ``` + +If you want to load more than one plugin, you can repeat the option or supply a comma-separated list of names: + +``` +rollup -i input.js -f es -p node-resolve -p commonjs,json +``` + +By default, plugins that export functions will be called with no argument to create the plugin. You can however pass a custom argument as well: + +``` +rollup -i input.js -f es -p 'terser={output: {beautify: true, indent_level: 2}}' +``` + #### `-v`/`--version` Print the installed version number. diff --git a/src/utils/mergeOptions.ts b/src/utils/mergeOptions.ts index 46f71f43d23..a8e5ae00c08 100644 --- a/src/utils/mergeOptions.ts +++ b/src/utils/mergeOptions.ts @@ -98,6 +98,7 @@ export const commandAliases: { [key: string]: string } = { m: 'sourcemap', n: 'name', o: 'file', + p: 'plugin', v: 'version', w: 'watch' }; @@ -158,6 +159,7 @@ export default function mergeOptions({ Object.keys(commandAliases), 'config', 'environment', + 'plugin', 'silent', 'stdin' ), diff --git a/test/cli/samples/plugin/absolute/_config.js b/test/cli/samples/plugin/absolute/_config.js new file mode 100644 index 00000000000..9f8cebd1f00 --- /dev/null +++ b/test/cli/samples/plugin/absolute/_config.js @@ -0,0 +1,5 @@ +module.exports = { + description: 'CLI --plugin /absolute/path', + skipIfWindows: true, + command: `echo 'console.log(VALUE);' | rollup -p "\`pwd\`/my-plugin={VALUE: 'absolute', ZZZ: 1}"` +}; diff --git a/test/cli/samples/plugin/absolute/_expected.js b/test/cli/samples/plugin/absolute/_expected.js new file mode 100644 index 00000000000..3a3206b062c --- /dev/null +++ b/test/cli/samples/plugin/absolute/_expected.js @@ -0,0 +1 @@ +console.log("absolute"); diff --git a/test/cli/samples/plugin/absolute/my-plugin.js b/test/cli/samples/plugin/absolute/my-plugin.js new file mode 100644 index 00000000000..800515033ef --- /dev/null +++ b/test/cli/samples/plugin/absolute/my-plugin.js @@ -0,0 +1,14 @@ +module.exports = function(options) { + if (options === void 0) options = {}; + return { + transform(code) { + // dumb search and replace for test purposes + for (var key in options) { + const rx = new RegExp(key, 'g'); + const value = JSON.stringify(options[key]); + code = code.replace(rx, value); + } + return code; + } + }; +}; diff --git a/test/cli/samples/plugin/advanced/_config.js b/test/cli/samples/plugin/advanced/_config.js new file mode 100644 index 00000000000..8028fd603e7 --- /dev/null +++ b/test/cli/samples/plugin/advanced/_config.js @@ -0,0 +1,5 @@ +module.exports = { + description: 'advanced CLI --plugin functionality with rollup config', + skipIfWindows: true, + command: `rollup -c -p node-resolve,commonjs -p "terser={output: {beautify: true, indent_level: 2}}"` +}; diff --git a/test/cli/samples/plugin/advanced/_expected/cjs.js b/test/cli/samples/plugin/advanced/_expected/cjs.js new file mode 100644 index 00000000000..7cbd6c70f5f --- /dev/null +++ b/test/cli/samples/plugin/advanced/_expected/cjs.js @@ -0,0 +1,17 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: !0 +}); + +var t = function() { + function t(t) { + this.x = t; + } + return t.prototype.output = function() { + var t; + t = this.x, console.log(t); + }, t; +}(); + +new t(123).output(), exports.Bar = t; diff --git a/test/cli/samples/plugin/advanced/_expected/es.js b/test/cli/samples/plugin/advanced/_expected/es.js new file mode 100644 index 00000000000..6b0e9e7249a --- /dev/null +++ b/test/cli/samples/plugin/advanced/_expected/es.js @@ -0,0 +1,13 @@ +var t = function() { + function t(t) { + this.x = t; + } + return t.prototype.output = function() { + var t; + t = this.x, console.log(t); + }, t; +}(); + +new t(123).output(); + +export { t as Bar }; diff --git a/test/cli/samples/plugin/advanced/main.js b/test/cli/samples/plugin/advanced/main.js new file mode 100644 index 00000000000..e04e2255af9 --- /dev/null +++ b/test/cli/samples/plugin/advanced/main.js @@ -0,0 +1,4 @@ +import {Foo} from "foo"; +var foo = new Foo(123); +foo.output(); +export {Foo as Bar}; diff --git a/test/cli/samples/plugin/advanced/node_modules/foo/index.js b/test/cli/samples/plugin/advanced/node_modules/foo/index.js new file mode 100644 index 00000000000..87e1bc97c38 --- /dev/null +++ b/test/cli/samples/plugin/advanced/node_modules/foo/index.js @@ -0,0 +1,10 @@ +var print = require('print'); + +exports.Foo = class { + constructor(x) { + this.x = x; + } + output() { + print(this.x); + } +}; diff --git a/test/cli/samples/plugin/advanced/node_modules/print/index.js b/test/cli/samples/plugin/advanced/node_modules/print/index.js new file mode 100644 index 00000000000..be89775f9d0 --- /dev/null +++ b/test/cli/samples/plugin/advanced/node_modules/print/index.js @@ -0,0 +1,3 @@ +module.exports = function(value) { + console.log(value); +}; diff --git a/test/cli/samples/plugin/advanced/rollup.config.js b/test/cli/samples/plugin/advanced/rollup.config.js new file mode 100644 index 00000000000..8cfd5b78416 --- /dev/null +++ b/test/cli/samples/plugin/advanced/rollup.config.js @@ -0,0 +1,18 @@ +const buble = require('rollup-plugin-buble'); + +export default { + input: 'main.js', + plugins: [ + buble() + ], + output: [ + { + file: '_actual/cjs.js', + format: 'cjs' + }, + { + file: '_actual/es.js', + format: 'esm' + } + ] +}; diff --git a/test/cli/samples/plugin/basic/_config.js b/test/cli/samples/plugin/basic/_config.js new file mode 100644 index 00000000000..2cfebb4e7ec --- /dev/null +++ b/test/cli/samples/plugin/basic/_config.js @@ -0,0 +1,4 @@ +module.exports = { + description: 'basic CLI --plugin functionality', + command: `rollup main.js -f cjs --plugin rollup-plugin-buble` +}; diff --git a/test/cli/samples/plugin/basic/_expected.js b/test/cli/samples/plugin/basic/_expected.js new file mode 100644 index 00000000000..e83de861ed5 --- /dev/null +++ b/test/cli/samples/plugin/basic/_expected.js @@ -0,0 +1,14 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +var Bar = function Bar(x) { + this.x = value; +}; +Bar.prototype.value = function value () { + return this.x; +}; +var bar = new Bar(123); +console.log(bar.value()); + +exports.Bar = Bar; diff --git a/test/cli/samples/plugin/basic/main.js b/test/cli/samples/plugin/basic/main.js new file mode 100644 index 00000000000..49486331fe7 --- /dev/null +++ b/test/cli/samples/plugin/basic/main.js @@ -0,0 +1,10 @@ +export class Bar { + constructor(x) { + this.x = value; + } + value() { + return this.x; + } +} +var bar = new Bar(123); +console.log(bar.value()); diff --git a/test/cli/samples/plugin/cannot-load/_config.js b/test/cli/samples/plugin/cannot-load/_config.js new file mode 100644 index 00000000000..dc942ccb073 --- /dev/null +++ b/test/cli/samples/plugin/cannot-load/_config.js @@ -0,0 +1,10 @@ +const { assertStderrIncludes } = require('../../../../utils.js'); + +module.exports = { + description: 'unknown CLI --plugin results in an error', + skipIfWindows: true, + command: `echo "console.log(123);" | rollup --plugin foobar`, + error(err) { + assertStderrIncludes(err.message, '[!] Error: Cannot load plugin "foobar"'); + } +}; diff --git a/test/cli/samples/plugin/invalid-argument/_config.js b/test/cli/samples/plugin/invalid-argument/_config.js new file mode 100644 index 00000000000..21f29a3e3d7 --- /dev/null +++ b/test/cli/samples/plugin/invalid-argument/_config.js @@ -0,0 +1,10 @@ +const { assertStderrIncludes } = require('../../../../utils.js'); + +module.exports = { + description: 'invalid CLI --plugin argument format', + skipIfWindows: true, + command: `echo "console.log(123);" | rollup --plugin 'foo bar'`, + error(err) { + assertStderrIncludes(err.message, '[!] Error: Invalid --plugin argument format: "foo bar"'); + } +}; diff --git a/test/cli/samples/plugin/object/_config.js b/test/cli/samples/plugin/object/_config.js new file mode 100644 index 00000000000..f102a47afeb --- /dev/null +++ b/test/cli/samples/plugin/object/_config.js @@ -0,0 +1,5 @@ +module.exports = { + description: 'CLI --plugin object', + skipIfWindows: true, + command: `echo 'console.log(42);' | rollup -f cjs -p '{transform: c => c + String.fromCharCode(10) + c}'` +}; diff --git a/test/cli/samples/plugin/object/_expected.js b/test/cli/samples/plugin/object/_expected.js new file mode 100644 index 00000000000..19a108d7e99 --- /dev/null +++ b/test/cli/samples/plugin/object/_expected.js @@ -0,0 +1,5 @@ +'use strict'; + +console.log(42); + +console.log(42); diff --git a/test/cli/samples/plugin/relative/_config.js b/test/cli/samples/plugin/relative/_config.js new file mode 100644 index 00000000000..177951ac68e --- /dev/null +++ b/test/cli/samples/plugin/relative/_config.js @@ -0,0 +1,5 @@ +module.exports = { + description: 'CLI --plugin ../relative/path', + skipIfWindows: true, + command: `echo 'console.log(VALUE);' | rollup -p "../absolute/my-plugin={VALUE: 'relative', ZZZ: 1}"` +}; diff --git a/test/cli/samples/plugin/relative/_expected.js b/test/cli/samples/plugin/relative/_expected.js new file mode 100644 index 00000000000..1059ebb529a --- /dev/null +++ b/test/cli/samples/plugin/relative/_expected.js @@ -0,0 +1 @@ +console.log("relative"); diff --git a/test/misc/optionList.js b/test/misc/optionList.js index 9332c129202..3fab4a66075 100644 --- a/test/misc/optionList.js +++ b/test/misc/optionList.js @@ -1,3 +1,3 @@ exports.input = 'acorn, acornInjectPlugins, cache, chunkGroupingSize, context, experimentalCacheExpiry, experimentalOptimizeChunks, external, inlineDynamicImports, input, manualChunks, moduleContext, onwarn, perf, plugins, preserveModules, preserveSymlinks, shimMissingExports, strictDeprecations, treeshake, watch'; -exports.flags = 'acorn, acornInjectPlugins, amd, assetFileNames, banner, c, cache, chunkFileNames, chunkGroupingSize, compact, config, context, d, dir, dynamicImportFunction, e, entryFileNames, environment, esModule, experimentalCacheExpiry, experimentalOptimizeChunks, exports, extend, external, externalLiveBindings, f, file, footer, format, freeze, g, globals, h, hoistTransitiveImports, 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, stdin, strict, strictDeprecations, treeshake, v, w, watch'; +exports.flags = 'acorn, acornInjectPlugins, amd, assetFileNames, banner, c, cache, chunkFileNames, chunkGroupingSize, compact, config, context, d, dir, dynamicImportFunction, e, entryFileNames, environment, esModule, experimentalCacheExpiry, experimentalOptimizeChunks, exports, extend, external, externalLiveBindings, f, file, footer, format, freeze, g, globals, h, hoistTransitiveImports, i, indent, inlineDynamicImports, input, interop, intro, m, manualChunks, moduleContext, n, name, namespaceToStringTag, noConflict, o, onwarn, outro, p, paths, perf, plugin, plugins, preferConst, preserveModules, preserveSymlinks, shimMissingExports, silent, sourcemap, sourcemapExcludeSources, sourcemapFile, stdin, strict, strictDeprecations, treeshake, v, w, watch'; exports.output = 'amd, assetFileNames, banner, chunkFileNames, compact, dir, dynamicImportFunction, entryFileNames, esModule, exports, extend, externalLiveBindings, file, footer, format, freeze, globals, hoistTransitiveImports, indent, interop, intro, name, namespaceToStringTag, noConflict, outro, paths, plugins, preferConst, sourcemap, sourcemapExcludeSources, sourcemapFile, sourcemapPathTransform, strict'; From f3320a0a1d65d79cb57f8d3ea979f39785d20843 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Fri, 28 Feb 2020 06:44:59 +0100 Subject: [PATCH 05/11] Update changelog --- CHANGELOG.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 854af373fb7..ba561abf56e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,16 @@ # rollup changelog -## 1.31.2 -*unreleased* +## 1.32.0 +*2020-02-28* + +### Features +* Allow adding plugins on the command line via `--plugin ` (#3379) ### Pull Requests +* [#3379](https://github.com/rollup/rollup/pull/3379): introduce CLI --plugin support (@kzc) * [#3390](https://github.com/rollup/rollup/pull/3390): fix typo: this.addWatchfile (@mistlog) * [#3392](https://github.com/rollup/rollup/pull/3392): Bump codecov from 3.6.1 to 3.6.5 +* [#3404](https://github.com/rollup/rollup/pull/3404): Update resolveFileUrl docs (@jakearchibald) ## 1.31.1 *2020-02-14* From 9d68d8e83fbd57fece136493ce3b6f24b7d7b7b1 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Fri, 28 Feb 2020 06:45:11 +0100 Subject: [PATCH 06/11] 1.32.0 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index aee8b007305..a3f029d68a5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "rollup", - "version": "1.31.1", + "version": "1.32.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index b6164a8e9bd..cd80a1d25bb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rollup", - "version": "1.31.1", + "version": "1.32.0", "description": "Next-generation ES module bundler", "main": "dist/rollup.js", "module": "dist/rollup.es.js", From 6f0f62b667446228ee2392993c81766e0aaeb346 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Thu, 5 Mar 2020 06:18:20 +0100 Subject: [PATCH 07/11] Structure lifecycle hooks, add links to build time hooks (#3418) * Structure lifecycle hooks, add links to build time hooks * Update docs/05-plugin-development.md Co-Authored-By: Jake Archibald * Add links to output generation hooks, apply review comments. * Improve some wordings Co-authored-by: Jake Archibald --- docs/05-plugin-development.md | 360 ++++++++++++++++++---------------- 1 file changed, 194 insertions(+), 166 deletions(-) diff --git a/docs/05-plugin-development.md b/docs/05-plugin-development.md index eefbd4f03d2..82936f73878 100644 --- a/docs/05-plugin-development.md +++ b/docs/05-plugin-development.md @@ -63,21 +63,183 @@ Type: `string` The name of the plugin, for use in error messages and warnings. -### Hooks +### Build Hooks -In addition to properties defining the identity of your plugin, you may also specify properties that correspond to available build hooks. Hooks can affect how a build is run, provide information about a build, or modify a build once complete. There are different kinds of hooks: +To interact with the build process, your plugin object includes 'hooks'. Hooks are functions which are called at various stages of the build. Hooks can affect how a build is run, provide information about a build, or modify a build once complete. There are different kinds of hooks: -* `async`: The hook can also return a promise resolving to the same type of value; otherwise, the hook is marked as `sync` -* `first`: If several plugins implement this hook, the hooks are run sequentially until a hook returns a value other than `null` or `undefined` -* `sequential`: If this hook returns a promise, then other hooks of this kind will only be executed once this hook has resolved -* `parallel`: If this hook returns a promise, then other hooks of this kind will not wait for this hook to be resolved +* `async`: The hook may also return a promise resolving to the same type of value; otherwise, the hook is marked as `sync`. +* `first`: If several plugins implement this hook, the hooks are run sequentially until a hook returns a value other than `null` or `undefined`. +* `sequential`: If several plugins implement this hook, all of them will be run in the specified plugin order. If a hook is async, subsequent hooks of this kind will wait until the current hook is resolved. +* `parallel`: If several plugins implement this hook, all of them will be run in the specified plugin order. If a hook is async, subsequent hooks of this kind will be run in parallel and not wait for the current hook. -Furthermore, hooks can be run either during the `build` phase of the Rollup build, which is triggered by `rollup.rollup()`, or during the `generate` phase, which is triggered by `bundle.generate()` or `bundle.write()`. Plugins that only use `generate` phase hooks can also be passed in via the output options to `bundle.generate()` or `bundle.write()` and therefore run only for certain outputs. +Build hooks are run during the build phase, which is triggered by `rollup.rollup(inputOptions)`. They are mainly concerned with locating, providing and transforming input files before they are processed by Rollup. The first hook of the build phase is [options](guide/en/#options), the last one is always [buildEnd](guide/en/#buidend). Additionally in watch mode, the [watchChange](guide/en/#watchchange) hook can be triggered at any time to notify a new run will be triggered once the current run has generated its outputs. + +See [Output Generation Hooks](guide/en/#output-generation-hooks) for hooks that run during the output generation phase to modify the generated output. + +#### `buildEnd` +Type: `(error?: Error) => void`
+Kind: `async, parallel`
+Previous Hook: [`transform`](guide/en/#transform), [`resolveId`](guide/en/#resolveid) or [`resolveDynamicImport`](guide/en/#resolvedynamicimport).
+Next Hook: [`outputOptions`](guide/en/#outputoptions) in the output generation phase as this is the last hook of the build phase. + +Called when rollup has finished bundling, but before `generate` or `write` is called; you can also return a Promise. If an error occurred during the build, it is passed on to this hook. + +#### `buildStart` +Type: `(options: InputOptions) => void`
+Kind: `async, parallel`
+Previous Hook: [`options`](guide/en/#options)
+Next Hook: [`resolveId`](guide/en/#resolveid) to resolve each entry point in parallel. + +Called on each `rollup.rollup` build. This is the recommended hook to use when you need access to the options passed to `rollup.rollup()` as it will take the transformations by all [`options`](guide/en/#options) hooks into account. + +#### `load` +Type: `(id: string) => string | null | { code: string, map?: string | SourceMap, ast? : ESTree.Program, moduleSideEffects?: boolean | null, syntheticNamedExports?: boolean | null }`
+Kind: `async, first`
+Previous Hook: [`resolveId`](guide/en/#resolveid) or [`resolveDynamicImport`](guide/en/#resolvedynamicimport) where the loaded id was resolved.
+Next Hook: [`transform`](guide/en/#transform) to transform the loaded file. + +Defines a custom loader. Returning `null` defers to other `load` functions (and eventually the default behavior of loading from the file system). To prevent additional parsing overhead in case e.g. this hook already used `this.parse` to generate an AST for some reason, this hook can optionally return a `{ code, ast, map }` object. The `ast` must be a standard ESTree AST with `start` and `end` properties for each node. If the transformation does not move code, you can preserve existing sourcemaps by setting `map` to `null`. Otherwise you might need to generate the source map. See [the section on source code transformations](#source-code-transformations). + +If `false` is returned for `moduleSideEffects` and no other module imports anything from this module, then this module will not be included in the bundle without checking for actual side-effects inside the module. If `true` is returned, Rollup will use its default algorithm to include all statements in the module that have side-effects (such as modifying a global or exported variable). If `null` is returned or the flag is omitted, then `moduleSideEffects` will be determined by the first `resolveId` hook that resolved this module, the `treeshake.moduleSideEffects` option, or eventually default to `true`. The `transform` hook can override this. + +If `true` is returned for `syntheticNamedExports`, this module will fallback the resolution of any missing named export to properties of the `default` export. The `transform` hook can override this. This option allows to have dynamic named exports that might not be declared in the module, such as in this example: + +**dep.js: (`{syntheticNamedExports: true}`)** + +``` +export default { + foo: 42, + bar: 'hello' +} +``` + +**main.js: (entry point)** + +```js +import { foo, bar } from './dep.js' +console.log(foo, bar); +``` + +You can use [`this.getModuleInfo`](guide/en/#thisgetmoduleinfomoduleid-string--moduleinfo) to find out the previous values of `moduleSideEffects` and `syntheticNamedExports` inside this hook. + +#### `options` +Type: `(options: InputOptions) => InputOptions | null`
+Kind: `sync, sequential`
+Previous Hook: This is the first hook of the build phase.
+Next Hook: [`buildStart`](guide/en/#buildstart) + +Replaces or manipulates the options object passed to `rollup.rollup`. Returning `null` does not replace anything. If you just need to read the options, it is recommended to use the [`buildStart`](guide/en/#buildstart) hook as that hook has access to the options after the transformations from all `options` hooks have been taken into account. + +This is the only hook that does not have access to most [plugin context](guide/en/#plugin-context) utility functions as it is run before rollup is fully configured. + +#### `resolveDynamicImport` +Type: `(specifier: string | ESTree.Node, importer: string) => string | false | null | {id: string, external?: boolean}`
+Kind: `async, first`
+Previous Hook: [`transform`](guide/en/#transform) where the importing file was transformed.
+Next Hook: [`load`](guide/en/#load) if the hook resolved with an id that has not yet been loaded, [`resolveId`](guide/en/#resolveid) if the dynamic import contains a string and was not resolved by the hook, otherwise [`buildEnd`](guide/en/#buildend). + +Defines a custom resolver for dynamic imports. Returning `false` signals that the import should be kept as it is and not be passed to other resolvers thus making it external. Similar to the [`resolveId`](guide/en/#resolveid) hook, you can also return an object to resolve the import to a different id while marking it as external at the same time. + +In case a dynamic import is passed a string as argument, a string returned from this hook will be interpreted as an existing module id while returning `null` will defer to other resolvers and eventually to `resolveId` . + +In case a dynamic import is not passed a string as argument, this hook gets access to the raw AST nodes to analyze and behaves slightly different in the following ways: +- If all plugins return `null`, the import is treated as `external` without a warning. +- If a string is returned, this string is *not* interpreted as a module id but is instead used as a replacement for the import argument. It is the responsibility of the plugin to make sure the generated code is valid. +- To resolve such an import to an existing module, you can still return an object `{id, external}`. + +Note that the return value of this hook will not be passed to `resolveId` afterwards; if you need access to the static resolution algorithm, you can use [`this.resolve(source, importer)`](guide/en/#thisresolvesource-string-importer-string-options-skipself-boolean--promiseid-string-external-boolean--null) on the plugin context. + +#### `resolveId` +Type: `(source: string, importer: string) => string | false | null | {id: string, external?: boolean, moduleSideEffects?: boolean | null, syntheticNamedExports?: boolean | null}`
+Kind: `async, first`
+Previous Hook: [`buildStart`](guide/en/#buildstart) if we are resolving an entry point, [`transform`](guide/en/#transform) if we are resolving an import, or as fallback for [`resolveDynamicImport`](guide/en/#resolvedynamicimport). Additionally this hook can be triggered during the build phase from plugin hooks by calling [`this.emitFile`](guide/en/#thisemitfileemittedfile-emittedchunk--emittedasset--string) to emit an entry point or at any time by calling [`this.resolve`](guide/en/#thisresolvesource-string-importer-string-options-skipself-boolean--promiseid-string-external-boolean--null) to manually resolve an id.
+Next Hook: [`load`](guide/en/#load) if the resolved id that has not yet been loaded, otherwise [`buildEnd`](guide/en/#buildend). + +Defines a custom resolver. A resolver can be useful for e.g. locating third-party dependencies. Returning `null` defers to other `resolveId` functions and eventually the default resolution behavior; returning `false` signals that `source` should be treated as an external module and not included in the bundle. If this happens for a relative import, the id will be renormalized the same way as when the `external` option is used. + +If you return an object, then it is possible to resolve an import to a different id while excluding it from the bundle at the same time. This allows you to replace dependencies with external dependencies without the need for the user to mark them as "external" manually via the `external` option: + +```js +resolveId(source) { + if (source === 'my-dependency') { + return {id: 'my-dependency-develop', external: true}; + } + return null; +} +``` + +Relative ids, i.e. starting with `./` or `../`, will **not** be renormalized when returning an object. If you want this behaviour, return an absolute file system location as `id` instead. + +If `false` is returned for `moduleSideEffects` in the first hook that resolves a module id and no other module imports anything from this module, then this module will not be included without checking for actual side-effects inside the module. If `true` is returned, Rollup will use its default algorithm to include all statements in the module that have side-effects (such as modifying a global or exported variable). If `null` is returned or the flag is omitted, then `moduleSideEffects` will be determined by the `treeshake.moduleSideEffects` option or default to `true`. The `load` and `transform` hooks can override this. + +If `true` is returned for `syntheticNamedExports`, this module will fallback the resolution of any missing named export to properties of the `default` export. The `load` and `transform` hooks can override this. This option allows to have dynamic named exports that might not be declared in the module, such as in this example: + +**dep.js: (`{syntheticNamedExports: true}`)** + +``` +export default { + foo: 42, + bar: 'hello' +} +``` + +**main.js: (entry point)** + +```js +import { foo, bar } from './dep.js' +console.log(foo, bar); +``` + +#### `transform` +Type: `(code: string, id: string) => string | null | { code: string, map?: string | SourceMap, ast? : ESTree.Program, moduleSideEffects?: boolean | null, syntheticNamedExports?: boolean | null }`
+Kind: `async, sequential`
+Previous Hook: [`load`](guide/en/#load) where the currently handled file was loaded.
+NextHook: [`resolveId`](guide/en/#resolveid) and [`resolveDynamicImport`](guide/en/#resolvedynamicimport) to resolve all discovered static and dynamic imports in parallel if present, otherwise [`buildEnd`](guide/en/#buildend). + +Can be used to transform individual modules. To prevent additional parsing overhead in case e.g. this hook already used `this.parse` to generate an AST for some reason, this hook can optionally return a `{ code, ast, map }` object. The `ast` must be a standard ESTree AST with `start` and `end` properties for each node. If the transformation does not move code, you can preserve existing sourcemaps by setting `map` to `null`. Otherwise you might need to generate the source map. See [the section on source code transformations](#source-code-transformations). + +Note that in watch mode, the result of this hook is cached when rebuilding and the hook is only triggered again for a module `id` if either the `code` of the module has changed or a file has changed that was added via `this.addWatchFile` the last time the hook was triggered for this module. + +If `false` is returned for `moduleSideEffects` and no other module imports anything from this module, then this module will not be included without checking for actual side-effects inside the module. If `true` is returned, Rollup will use its default algorithm to include all statements in the module that have side-effects (such as modifying a global or exported variable). If `null` is returned or the flag is omitted, then `moduleSideEffects` will be determined by the first `resolveId` hook that resolved this module, the `treeshake.moduleSideEffects` option, or eventually default to `true`. + +If `true` is returned for `syntheticNamedExports`, this module will fallback the resolution of any missing named export to properties of the `default` export. This option allows to have dynamic named exports that might not be declared in the module, such as in this example: + +**dep.js: (`{syntheticNamedExports: true}`)** + +``` +export default { + foo: 42, + bar: 'hello' +} +``` + +**main.js: (entry point)** + +```js +import { foo, bar } from './dep.js' +console.log(foo, bar); +``` + +You can use [`this.getModuleInfo`](guide/en/#thisgetmoduleinfomoduleid-string--moduleinfo) to find out the previous value of `moduleSideEffects` inside this hook. + +#### `watchChange` +Type: `(id: string) => void`
+Kind: `sync, sequential`
+Previous/Next Hook: This hook can be triggered at any time both during the build and the output generation phases. If that is the case, the current build will still proceed but a new build will be scheduled to start once the current build has completed, starting again with [`options`](guide/en/#options). + +Notifies a plugin whenever rollup has detected a change to a monitored file in `--watch` mode. This hook cannot be used by output plugins. + +### Output Generation Hooks + +Output generation hooks can provide information about a generated bundle and modify a build once complete. They work the same way and have the same types as [Build Hooks](guide/en/#build-hooks) but are called separately for each call to `bundle.generate(outputOptions)` or `bundle.write(outputOptions)`. Plugins that only use output generation hooks can also be passed in via the output options and therefore run only for certain outputs. + +The first hook of the output generation phase is [outputOptions](guide/en/#outputoptions), the last one is either [generateBundle](guide/en/#generatebundle) if the output was successfully generated via `bundle.generate(...)`, [writeBundle](guide/en/#writebundle) if the output was successfully generated via `bundle.write(...)`, or [renderError](guide/en/#rendererror) if an error occurred at any time during the output generation. #### `augmentChunkHash` Type: `(preRenderedChunk: PreRenderedChunk) => string`
Kind: `sync, sequential`
-Phase: `generate` +Previous Hook: [`banner`](guide/en/#banner), [`footer`](guide/en/#footer), [`intro`](guide/en/#intro), [`outro`](guide/en/#outro).
+Next Hook: [`resolveFileUrl`](guide/en/#resolvefileurl) for each use of `import.meta.ROLLUP_FILE_URL_referenceId` and [`resolveImportMeta`](guide/en/#resolveimportmeta) for all other accesses to `import.meta`. Then [`renderChunk`](guide/en/#renderchunk) for each chunk. Can be used to augment the hash of individual chunks. Called for each Rollup output chunk. Returning a falsy value will not modify the hash. @@ -95,35 +257,24 @@ augmentChunkHash(chunkInfo) { #### `banner` Type: `string | (() => string)`
Kind: `async, parallel`
-Phase: `generate` +Previous Hook: [`renderStart`](guide/en/#renderstart)
+Next Hook: [`augmentChunkHash`](guide/en/#augmentchunkhash) for each chunk that would contain a hash in the file name. Then [`resolveFileUrl`](guide/en/#resolvefileurl) for each use of `import.meta.ROLLUP_FILE_URL_referenceId` and [`resolveImportMeta`](guide/en/#resolveimportmeta) for all other accesses to `import.meta`. Then [`renderChunk`](guide/en/#renderchunk) for each chunk. Cf. [`output.banner/output.footer`](guide/en/#outputbanneroutputfooter). -#### `buildEnd` -Type: `(error?: Error) => void`
-Kind: `async, parallel`
-Phase: `build` - -Called when rollup has finished bundling, but before `generate` or `write` is called; you can also return a Promise. If an error occurred during the build, it is passed on to this hook. - -#### `buildStart` -Type: `(options: InputOptions) => void`
-Kind: `async, parallel`
-Phase: `build` - -Called on each `rollup.rollup` build. This is the recommended hook to use when you need access to the options passed to `rollup.rollup()` as it will take the transformations by all [`options`](guide/en/#options) hooks into account. - #### `footer` Type: `string | (() => string)`
Kind: `async, parallel`
-Phase: `generate` +Previous Hook: [`renderStart`](guide/en/#renderstart)
+Next Hook: [`augmentChunkHash`](guide/en/#augmentchunkhash) for each chunk that would contain a hash in the file name. Then [`resolveFileUrl`](guide/en/#resolvefileurl) for each use of `import.meta.ROLLUP_FILE_URL_referenceId` and [`resolveImportMeta`](guide/en/#resolveimportmeta) for all other accesses to `import.meta`. Then [`renderChunk`](guide/en/#renderchunk) for each chunk. Cf. [`output.banner/output.footer`](guide/en/#outputbanneroutputfooter). #### `generateBundle` Type: `(options: OutputOptions, bundle: { [fileName: string]: AssetInfo | ChunkInfo }, isWrite: boolean) => void`
Kind: `async, sequential`
-Phase: `generate` +Previous Hook: [`renderChunk`](guide/en/#renderchunk)
+Next Hook: [`writeBundle`](guide/en/#writebundle) if the output was generated via `bundle.write(...)`, otherwise this is the last hook of the output generation phase and may again be followed by [`outputOptions`](guide/en/#outputoptions) if another output is generated. Called at the end of `bundle.generate()` or immediately before the files are written in `bundle.write()`. To modify the files after they have been written, use the [`writeBundle`](guide/en/#writebundle) hook. `bundle` provides the full list of files being written or generated along with their details: @@ -164,103 +315,56 @@ You can prevent files from being emitted by deleting them from the bundle object #### `intro` Type: `string | (() => string)`
Kind: `async, parallel`
-Phase: `generate` +Previous Hook: [`renderStart`](guide/en/#renderstart)
+Next Hook: [`augmentChunkHash`](guide/en/#augmentchunkhash) for each chunk that would contain a hash in the file name. Then [`resolveFileUrl`](guide/en/#resolvefileurl) for each use of `import.meta.ROLLUP_FILE_URL_referenceId` and [`resolveImportMeta`](guide/en/#resolveimportmeta) for all other accesses to `import.meta`. Then [`renderChunk`](guide/en/#renderchunk) for each chunk. Cf. [`output.intro/output.outro`](guide/en/#outputintrooutputoutro). -#### `load` -Type: `(id: string) => string | null | { code: string, map?: string | SourceMap, ast? : ESTree.Program, moduleSideEffects?: boolean | null, syntheticNamedExports?: boolean | null }`
-Kind: `async, first`
-Phase: `build` - -Defines a custom loader. Returning `null` defers to other `load` functions (and eventually the default behavior of loading from the file system). To prevent additional parsing overhead in case e.g. this hook already used `this.parse` to generate an AST for some reason, this hook can optionally return a `{ code, ast, map }` object. The `ast` must be a standard ESTree AST with `start` and `end` properties for each node. If the transformation does not move code, you can preserve existing sourcemaps by setting `map` to `null`. Otherwise you might need to generate the source map. See [the section on source code transformations](#source-code-transformations). - -If `false` is returned for `moduleSideEffects` and no other module imports anything from this module, then this module will not be included in the bundle without checking for actual side-effects inside the module. If `true` is returned, Rollup will use its default algorithm to include all statements in the module that have side-effects (such as modifying a global or exported variable). If `null` is returned or the flag is omitted, then `moduleSideEffects` will be determined by the first `resolveId` hook that resolved this module, the `treeshake.moduleSideEffects` option, or eventually default to `true`. The `transform` hook can override this. - -If `true` is returned for `syntheticNamedExports`, this module will fallback the resolution of any missing named export to properties of the `default` export. The `transform` hook can override this. This option allows to have dynamic named exports that might not be declared in the module, such as in this example: - -**dep.js: (`{syntheticNamedExports: true}`)** - -``` -export default { - foo: 42, - bar: 'hello' -} -``` - -**main.js: (entry point)** - -```js -import { foo, bar } from './dep.js' -console.log(foo, bar); -``` - -You can use [`this.getModuleInfo`](guide/en/#thisgetmoduleinfomoduleid-string--moduleinfo) to find out the previous values of `moduleSideEffects` and `syntheticNamedExports` inside this hook. - -#### `options` -Type: `(options: InputOptions) => InputOptions | null`
-Kind: `sync, sequential`
-Phase: `build` - -Replaces or manipulates the options object passed to `rollup.rollup`. Returning `null` does not replace anything. If you just need to read the options, it is recommended to use the [`buildStart`](guide/en/#buildstart) hook as that hook has access to the options after the transformations from all `options` hooks have been taken into account. - -This is the only hook that does not have access to most [plugin context](guide/en/#plugin-context) utility functions as it is run before rollup is fully configured. - #### `outputOptions` Type: `(outputOptions: OutputOptions) => OutputOptions | null`
Kind: `sync, sequential`
-Phase: `generate` +Previous Hook: [`buildEnd`](guide/en/#buildend) if this is the first time an output is generated, otherwise either [`generateBundle`](guide/en/#generatebundle), [`writeBundle`](guide/en/#writebundle) or [`renderError`](guide/en/#rendererror) depending on the previously generated output. This is the first hook of the output generation phase.
+Next Hook: [`renderStart`](guide/en/#renderstart). Replaces or manipulates the output options object passed to `bundle.generate()` or `bundle.write()`. Returning `null` does not replace anything. If you just need to read the output options, it is recommended to use the [`renderStart`](guide/en/#renderstart) hook as this hook has access to the output options after the transformations from all `outputOptions` hooks have been taken into account. #### `outro` Type: `string | (() => string)`
Kind: `async, parallel`
-Phase: `generate` +Previous Hook: [`renderStart`](guide/en/#renderstart)
+Next Hook: [`augmentChunkHash`](guide/en/#augmentchunkhash) for each chunk that would contain a hash in the file name. Then [`resolveFileUrl`](guide/en/#resolvefileurl) for each use of `import.meta.ROLLUP_FILE_URL_referenceId` and [`resolveImportMeta`](guide/en/#resolveimportmeta) for all other accesses to `import.meta`. Then [`renderChunk`](guide/en/#renderchunk) for each chunk. Cf. [`output.intro/output.outro`](guide/en/#outputintrooutputoutro). #### `renderChunk` Type: `(code: string, chunk: ChunkInfo, options: OutputOptions) => string | { code: string, map: SourceMap } | null`
Kind: `async, sequential`
-Phase: `generate` +Previous Hook: [`resolveFileUrl`](guide/en/#resolvefileurl) or [`resolveImportMeta`](guide/en/#resolveimportmeta) if `import.meta` properties are used. Before that [`augmentChunkHash`](guide/en/#augmentchunkhash) if there are chunks that would contain a hash in the file name. Before that [`banner`](guide/en/#banner), [`footer`](guide/en/#footer), [`intro`](guide/en/#intro), [`outro`](guide/en/#outro).
+Next Hook: [`generateBundle`](guide/en/#generatebundle). Can be used to transform individual chunks. Called for each Rollup output chunk file. Returning `null` will apply no transformations. #### `renderError` Type: `(error: Error) => void`
Kind: `async, parallel`
-Phase: `generate` +Previous Hook: Any hook from [`renderStart`](guide/en/#renderstart) to [`renderChunk`](guide/en/#renderchunk).
+Next Hook: If it is called, this is the last hook of the output generation phase and may again be followed by [`outputOptions`](guide/en/#outputoptions) if another output is generated. Called when rollup encounters an error during `bundle.generate()` or `bundle.write()`. The error is passed to this hook. To get notified when generation completes successfully, use the `generateBundle` hook. #### `renderStart` Type: `(outputOptions: OutputOptions, inputOptions: InputOptions) => void`
Kind: `async, parallel`
-Phase: `generate` +Previous Hook: [`outputOptions`](guide/en/#outputoptions)
+Next Hook: [`banner`](guide/en/#banner), [`footer`](guide/en/#footer), [`intro`](guide/en/#intro) and [`outro`](guide/en/#outro) run in parallel. Called initially each time `bundle.generate()` or `bundle.write()` is called. To get notified when generation has completed, use the `generateBundle` and `renderError` hooks. This is the recommended hook to use when you need access to the output options passed to `bundle.generate()` or `bundle.write()` as it will take the transformations by all [`outputOptions`](guide/en/#outputoptions) hooks into account. It also receives the input options passed to `rollup.rollup()` so that plugins that can be used as output plugins, i.e. plugins that only use `generate` phase hooks, can get access to them. -#### `resolveDynamicImport` -Type: `(specifier: string | ESTree.Node, importer: string) => string | false | null | {id: string, external?: boolean}`
-Kind: `async, first`
-Phase: `build` - -Defines a custom resolver for dynamic imports. Returning `false` signals that the import should be kept as it is and not be passed to other resolvers thus making it external. Similar to the [`resolveId`](guide/en/#resolveid) hook, you can also return an object to resolve the import to a different id while marking it as external at the same time. - -In case a dynamic import is passed a string as argument, a string returned from this hook will be interpreted as an existing module id while returning `null` will defer to other resolvers and eventually to `resolveId` . - -In case a dynamic import is not passed a string as argument, this hook gets access to the raw AST nodes to analyze and behaves slightly different in the following ways: -- If all plugins return `null`, the import is treated as `external` without a warning. -- If a string is returned, this string is *not* interpreted as a module id but is instead used as a replacement for the import argument. It is the responsibility of the plugin to make sure the generated code is valid. -- To resolve such an import to an existing module, you can still return an object `{id, external}`. - -Note that the return value of this hook will not be passed to `resolveId` afterwards; if you need access to the static resolution algorithm, you can use [`this.resolve(source, importer)`](guide/en/#thisresolvesource-string-importer-string-options-skipself-boolean--promiseid-string-external-boolean--null) on the plugin context. - #### `resolveFileUrl` Type: `({chunkId: string, fileName: string, format: string, moduleId: string, referenceId: string, relativePath: string}) => string | null`
Kind: `sync, first`
-Phase: `generate` +Previous Hook: [`augmentChunkHash`](guide/en/#augmentchunkhash) if there are chunks that would contain a hash in the file name. Before that [`banner`](guide/en/#banner), [`footer`](guide/en/#footer), [`intro`](guide/en/#intro), [`outro`](guide/en/#outro).
+Next Hook: [`renderChunk`](guide/en/#renderchunk) for each chunk. Allows to customize how Rollup resolves URLs of files that were emitted by plugins via `this.emitFile`. By default, Rollup will generate code for `import.meta.ROLLUP_FILE_URL_referenceId` that should correctly generate absolute URLs of emitted files independent of the output format and the host system where the code is deployed. @@ -284,50 +388,11 @@ resolveFileUrl({fileName}) { } ``` -#### `resolveId` -Type: `(source: string, importer: string) => string | false | null | {id: string, external?: boolean, moduleSideEffects?: boolean | null, syntheticNamedExports?: boolean | null}`
-Kind: `async, first`
-Phase: `build` - -Defines a custom resolver. A resolver can be useful for e.g. locating third-party dependencies. Returning `null` defers to other `resolveId` functions and eventually the default resolution behavior; returning `false` signals that `source` should be treated as an external module and not included in the bundle. If this happens for a relative import, the id will be renormalized the same way as when the `external` option is used. - -If you return an object, then it is possible to resolve an import to a different id while excluding it from the bundle at the same time. This allows you to replace dependencies with external dependencies without the need for the user to mark them as "external" manually via the `external` option: - -```js -resolveId(source) { - if (source === 'my-dependency') { - return {id: 'my-dependency-develop', external: true}; - } - return null; -} -``` - -Relative ids, i.e. starting with `./` or `../`, will **not** be renormalized when returning an object. If you want this behaviour, return an absolute file system location as `id` instead. - -If `false` is returned for `moduleSideEffects` in the first hook that resolves a module id and no other module imports anything from this module, then this module will not be included without checking for actual side-effects inside the module. If `true` is returned, Rollup will use its default algorithm to include all statements in the module that have side-effects (such as modifying a global or exported variable). If `null` is returned or the flag is omitted, then `moduleSideEffects` will be determined by the `treeshake.moduleSideEffects` option or default to `true`. The `load` and `transform` hooks can override this. - -If `true` is returned for `syntheticNamedExports`, this module will fallback the resolution of any missing named export to properties of the `default` export. The `load` and `transform` hooks can override this. This option allows to have dynamic named exports that might not be declared in the module, such as in this example: - -**dep.js: (`{syntheticNamedExports: true}`)** - -``` -export default { - foo: 42, - bar: 'hello' -} -``` - -**main.js: (entry point)** - -```js -import { foo, bar } from './dep.js' -console.log(foo, bar); -``` - #### `resolveImportMeta` Type: `(property: string | null, {chunkId: string, moduleId: string, format: string}) => string | null`
Kind: `sync, first`
-Phase: `generate` +Previous Hook: [`augmentChunkHash`](guide/en/#augmentchunkhash) if there are chunks that would contain a hash in the file name. Before that [`banner`](guide/en/#banner), [`footer`](guide/en/#footer), [`intro`](guide/en/#intro), [`outro`](guide/en/#outro).
+Next Hook: [`renderChunk`](guide/en/#renderchunk) for each chunk. Allows to customize how Rollup handles `import.meta` and `import.meta.someProperty`, in particular `import.meta.url`. In ES modules, `import.meta` is an object and `import.meta.url` contains the URL of the current module, e.g. `http://server.net/bundle.js` for browsers or `file:///path/to/bundle.js` in Node. @@ -347,48 +412,11 @@ resolveImportMeta(property, {moduleId}) { Note that since this hook has access to the filename of the current chunk, its return value will not be considered when generating the hash of this chunk. -#### `transform` -Type: `(code: string, id: string) => string | null | { code: string, map?: string | SourceMap, ast? : ESTree.Program, moduleSideEffects?: boolean | null, syntheticNamedExports?: boolean | null }`
-Kind: `async, sequential`
-Phase: `build` - -Can be used to transform individual modules. To prevent additional parsing overhead in case e.g. this hook already used `this.parse` to generate an AST for some reason, this hook can optionally return a `{ code, ast, map }` object. The `ast` must be a standard ESTree AST with `start` and `end` properties for each node. If the transformation does not move code, you can preserve existing sourcemaps by setting `map` to `null`. Otherwise you might need to generate the source map. See [the section on source code transformations](#source-code-transformations). - -Note that in watch mode, the result of this hook is cached when rebuilding and the hook is only triggered again for a module `id` if either the `code` of the module has changed or a file has changed that was added via `this.addWatchFile` the last time the hook was triggered for this module. - -If `false` is returned for `moduleSideEffects` and no other module imports anything from this module, then this module will not be included without checking for actual side-effects inside the module. If `true` is returned, Rollup will use its default algorithm to include all statements in the module that have side-effects (such as modifying a global or exported variable). If `null` is returned or the flag is omitted, then `moduleSideEffects` will be determined by the first `resolveId` hook that resolved this module, the `treeshake.moduleSideEffects` option, or eventually default to `true`. - -If `true` is returned for `syntheticNamedExports`, this module will fallback the resolution of any missing named export to properties of the `default` export. This option allows to have dynamic named exports that might not be declared in the module, such as in this example: - -**dep.js: (`{syntheticNamedExports: true}`)** - -``` -export default { - foo: 42, - bar: 'hello' -} -``` - -**main.js: (entry point)** - -```js -import { foo, bar } from './dep.js' -console.log(foo, bar); -``` - -You can use [`this.getModuleInfo`](guide/en/#thisgetmoduleinfomoduleid-string--moduleinfo) to find out the previous value of `moduleSideEffects` inside this hook. - -#### `watchChange` -Type: `(id: string) => void`
-Kind: `sync, sequential`
-Phase: `build` (can also be triggered during `generate` but cannot be used by output plugins) - -Notifies a plugin whenever rollup has detected a change to a monitored file in `--watch` mode. - #### `writeBundle` Type: `( bundle: { [fileName: string]: AssetInfo | ChunkInfo }) => void`
Kind: `async, parallel`
-Phase: `generate` +Previous Hook: [`generateBundle`](guide/en/#generatebundle)
+Next Hook: If it is called, this is the last hook of the output generation phase and may again be followed by [`outputOptions`](guide/en/#outputoptions) if another output is generated. Called only at the end of `bundle.write()` once all files have been written. Similar to the [`generateBundle`](guide/en/#generatebundle) hook, `bundle` provides the full list of files being written along with their details. From baf382abfda39067f5dc79096b6c32393e05ba97 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Thu, 5 Mar 2020 06:29:27 +0100 Subject: [PATCH 08/11] Fix internal documentation links --- docs/04-tutorial.md | 2 +- docs/05-plugin-development.md | 6 +++--- docs/999-big-list-of-options.md | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/04-tutorial.md b/docs/04-tutorial.md index ad253a27548..1fa4a0f97a4 100755 --- a/docs/04-tutorial.md +++ b/docs/04-tutorial.md @@ -240,7 +240,7 @@ _Note: Only the data we actually need gets imported – `name` and `devDependenc ### Using output plugins -Some plugins can also be applied specifically to some outputs. See [plugin hooks](guide/en/#hooks) for the technical details of what output-specific plugins can do. In a nut-shell, those plugins can only modify code after the main analysis of Rollup has completed. Rollup will warn if an incompatible plugin is used as an output-specific plugin. One possible use-case is minification of bundles to be consumed in a browser. +Some plugins can also be applied specifically to some outputs. See [plugin hooks](guide/en/#build-hooks) for the technical details of what output-specific plugins can do. In a nut-shell, those plugins can only modify code after the main analysis of Rollup has completed. Rollup will warn if an incompatible plugin is used as an output-specific plugin. One possible use-case is minification of bundles to be consumed in a browser. Let us extend the previous example to provide a minified build together with the non-minified one. To that end, we install `rollup-plugin-terser`: diff --git a/docs/05-plugin-development.md b/docs/05-plugin-development.md index 82936f73878..91094855d8f 100644 --- a/docs/05-plugin-development.md +++ b/docs/05-plugin-development.md @@ -4,7 +4,7 @@ title: Plugin Development ### Plugins Overview -A Rollup plugin is an object with one or more of the [properties](guide/en/#properties) and [hooks](guide/en/#hooks) described below, and which follows our [conventions](guide/en/#conventions). A plugin should be distributed as a package which exports a function that can be called with plugin specific options and returns such an object. +A Rollup plugin is an object with one or more of the [properties](guide/en/#properties), [build hooks](guide/en/#build-hooks), and [output generation hooks](guide/en/#output-generation-hooks) described below, and which follows our [conventions](guide/en/#conventions). A plugin should be distributed as a package which exports a function that can be called with plugin specific options and returns such an object. Plugins allow you to customise Rollup's behaviour by, for example, transpiling code before bundling, or finding third-party modules in your `node_modules` folder. For an example on how to use them, see [Using plugins](guide/en/#using-plugins). @@ -72,7 +72,7 @@ To interact with the build process, your plugin object includes 'hooks'. Hooks a * `sequential`: If several plugins implement this hook, all of them will be run in the specified plugin order. If a hook is async, subsequent hooks of this kind will wait until the current hook is resolved. * `parallel`: If several plugins implement this hook, all of them will be run in the specified plugin order. If a hook is async, subsequent hooks of this kind will be run in parallel and not wait for the current hook. -Build hooks are run during the build phase, which is triggered by `rollup.rollup(inputOptions)`. They are mainly concerned with locating, providing and transforming input files before they are processed by Rollup. The first hook of the build phase is [options](guide/en/#options), the last one is always [buildEnd](guide/en/#buidend). Additionally in watch mode, the [watchChange](guide/en/#watchchange) hook can be triggered at any time to notify a new run will be triggered once the current run has generated its outputs. +Build hooks are run during the build phase, which is triggered by `rollup.rollup(inputOptions)`. They are mainly concerned with locating, providing and transforming input files before they are processed by Rollup. The first hook of the build phase is [options](guide/en/#options), the last one is always [buildEnd](guide/en/#buildend). Additionally in watch mode, the [watchChange](guide/en/#watchchange) hook can be triggered at any time to notify a new run will be triggered once the current run has generated its outputs. See [Output Generation Hooks](guide/en/#output-generation-hooks) for hooks that run during the output generation phase to modify the generated output. @@ -443,7 +443,7 @@ More properties may be supported in future, as and when they prove necessary. ### Plugin Context -A number of utility functions and informational bits can be accessed from within most [hooks](guide/en/#hooks) via `this`: +A number of utility functions and informational bits can be accessed from within most [hooks](guide/en/#build-hooks) via `this`: #### `this.addWatchFile(id: string) => void` diff --git a/docs/999-big-list-of-options.md b/docs/999-big-list-of-options.md index f8826dd65b1..0519b5fc686 100755 --- a/docs/999-big-list-of-options.md +++ b/docs/999-big-list-of-options.md @@ -231,7 +231,7 @@ Type: `OutputPlugin | (OutputPlugin | void)[]` Adds a plugin just to this output. See [Using output plugins](guide/en/#using-output-plugins) for more information on how to use output-specific plugins and [Plugins](guide/en/#plugin-development) on how to write your own. For plugins imported from packages, remember to call the imported plugin function (i.e. `commonjs()`, not just `commonjs`). Falsy plugins will be ignored, which can be used to easily activate or deactivate plugins. -Not every plugin can be used here. `output.plugins` is limited to plugins that only use hooks that run during `bundle.generate()` or `bundle.write()`, i.e. after Rollup's main analysis is complete. If you are a plugin author, see [Plugin hooks](guide/en/#hooks) to find out which hooks can be used. +Not every plugin can be used here. `output.plugins` is limited to plugins that only use hooks that run during `bundle.generate()` or `bundle.write()`, i.e. after Rollup's main analysis is complete. If you are a plugin author, see [output generation hooks](guide/en/#output-generation-hooks) to find out which hooks can be used. The following will add minification to one of the outputs: From 1e6284fb4d9300bb2551d28a60b2aea5b104496c Mon Sep 17 00:00:00 2001 From: timiyay Date: Fri, 6 Mar 2020 16:29:37 +1100 Subject: [PATCH 09/11] Missing exports errors now print the importing module (#3401) * Missing exports errors now print the importing module Prior to this change, we only printed the imported module that failed, with no context on which module was attempting the import. This could be difficult to debug in large codebases, especially when importing commonly-used modules. * rephrase missing export message The phrasing attempts to match the "imported by" style elsewhere in the codebase * Tests now expect new missing export message format * Use relative module id when displaying missing export message --- src/Module.ts | 4 +++- test/function/samples/circular-missed-reexports-2/_config.js | 2 +- test/function/samples/default-not-reexported/_config.js | 2 +- .../_config.js | 2 +- test/function/samples/import-of-unexported-fails/_config.js | 2 +- test/function/samples/reexport-missing-error/_config.js | 2 +- 6 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Module.ts b/src/Module.ts index 2e194f552e9..c7dd98a9d4e 100644 --- a/src/Module.ts +++ b/src/Module.ts @@ -157,7 +157,9 @@ function handleMissingExport( return importingModule.error( { code: 'MISSING_EXPORT', - message: `'${exportName}' is not exported by ${relativeId(importedModule)}`, + message: `'${exportName}' is not exported by ${relativeId( + importedModule + )}, imported by ${relativeId(importingModule.id)}`, url: `https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module` }, importerStart! diff --git a/test/function/samples/circular-missed-reexports-2/_config.js b/test/function/samples/circular-missed-reexports-2/_config.js index df2bf9004dd..e17a190410c 100644 --- a/test/function/samples/circular-missed-reexports-2/_config.js +++ b/test/function/samples/circular-missed-reexports-2/_config.js @@ -16,7 +16,7 @@ module.exports = { file: path.resolve(__dirname, 'dep2.js'), line: 1 }, - message: "'doesNotExist' is not exported by dep1.js", + message: "'doesNotExist' is not exported by dep1.js, imported by dep2.js", pos: 9, url: 'https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module', watchFiles: [ diff --git a/test/function/samples/default-not-reexported/_config.js b/test/function/samples/default-not-reexported/_config.js index 947141dbbbb..be866dd0b30 100644 --- a/test/function/samples/default-not-reexported/_config.js +++ b/test/function/samples/default-not-reexported/_config.js @@ -4,7 +4,7 @@ module.exports = { description: 'default export is not re-exported with export *', error: { code: 'MISSING_EXPORT', - message: `'default' is not exported by foo.js`, + message: `'default' is not exported by foo.js, imported by main.js`, pos: 7, watchFiles: [ path.resolve(__dirname, 'main.js'), diff --git a/test/function/samples/error-after-transform-should-throw-correct-location/_config.js b/test/function/samples/error-after-transform-should-throw-correct-location/_config.js index 23001b3ba56..58c2caa9550 100644 --- a/test/function/samples/error-after-transform-should-throw-correct-location/_config.js +++ b/test/function/samples/error-after-transform-should-throw-correct-location/_config.js @@ -20,7 +20,7 @@ module.exports = { }, error: { code: 'MISSING_EXPORT', - message: `'default' is not exported by empty.js`, + message: `'default' is not exported by empty.js, imported by main.js`, pos: 44, watchFiles: [path.resolve(__dirname, 'main.js'), path.resolve(__dirname, 'empty.js')], loc: { diff --git a/test/function/samples/import-of-unexported-fails/_config.js b/test/function/samples/import-of-unexported-fails/_config.js index 0db25ac0ad5..6f5fa5552b2 100644 --- a/test/function/samples/import-of-unexported-fails/_config.js +++ b/test/function/samples/import-of-unexported-fails/_config.js @@ -4,7 +4,7 @@ module.exports = { description: 'marking an imported, but unexported, identifier should throw', error: { code: 'MISSING_EXPORT', - message: `'default' is not exported by empty.js`, + message: `'default' is not exported by empty.js, imported by main.js`, pos: 7, watchFiles: [path.resolve(__dirname, 'main.js'), path.resolve(__dirname, 'empty.js')], loc: { diff --git a/test/function/samples/reexport-missing-error/_config.js b/test/function/samples/reexport-missing-error/_config.js index 032dc7b3c7e..5a17f6c2bd5 100644 --- a/test/function/samples/reexport-missing-error/_config.js +++ b/test/function/samples/reexport-missing-error/_config.js @@ -4,7 +4,7 @@ module.exports = { description: 'reexporting a missing identifier should print an error', error: { code: 'MISSING_EXPORT', - message: `'foo' is not exported by empty.js`, + message: `'foo' is not exported by empty.js, imported by main.js`, pos: 9, watchFiles: [path.resolve(__dirname, 'main.js'), path.resolve(__dirname, 'empty.js')], loc: { From 85c54ee3e52b402ab26144df2926379879a708f2 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Fri, 6 Mar 2020 06:47:25 +0100 Subject: [PATCH 10/11] Avoid invalid code when "else" branch is simplified (#3421) * Make sure there is always whitespace between "else" and the subsequent statement to avoid invalid code when the alternate branch is simplified. * Fix comment --- src/ast/nodes/IfStatement.ts | 3 +++ .../samples/if-statement-insert-whitespace/_config.js | 11 +++++++++++ .../samples/if-statement-insert-whitespace/main.js | 8 ++++++++ 3 files changed, 22 insertions(+) create mode 100644 test/function/samples/if-statement-insert-whitespace/_config.js create mode 100644 test/function/samples/if-statement-insert-whitespace/main.js diff --git a/src/ast/nodes/IfStatement.ts b/src/ast/nodes/IfStatement.ts index ad629bf667b..d1152429f32 100644 --- a/src/ast/nodes/IfStatement.ts +++ b/src/ast/nodes/IfStatement.ts @@ -82,6 +82,9 @@ export default class IfStatement extends StatementBase implements DeoptimizableE } if (this.alternate !== null) { if (this.alternate.included) { + if (code.original.charCodeAt(this.alternate.start - 1) === 101 /* e */) { + code.prependLeft(this.alternate.start, ' '); + } this.alternate.render(code, options); } else { code.remove(this.consequent.end, this.alternate.end); diff --git a/test/function/samples/if-statement-insert-whitespace/_config.js b/test/function/samples/if-statement-insert-whitespace/_config.js new file mode 100644 index 00000000000..bad60394fb9 --- /dev/null +++ b/test/function/samples/if-statement-insert-whitespace/_config.js @@ -0,0 +1,11 @@ +module.exports = { + description: 'inserts necessary white-space when simplifying if-statements (#3419)', + options: { + external: 'external' + }, + context: { + require(required) { + return false; + } + } +}; diff --git a/test/function/samples/if-statement-insert-whitespace/main.js b/test/function/samples/if-statement-insert-whitespace/main.js new file mode 100644 index 00000000000..c4c71f41329 --- /dev/null +++ b/test/function/samples/if-statement-insert-whitespace/main.js @@ -0,0 +1,8 @@ +let works = false; +const makeItWork = () => works = true; + +import value from 'external'; + +if (value) {} else"production"!=="local"?makeItWork():void 0; + +assert.ok(works); From eeda078b042c2969b1f0910c8e03b5a2572e9dfc Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 5 Mar 2020 21:53:09 -0800 Subject: [PATCH 11/11] Update generated code of getInteropBlock() to work with null prototype objects (#3420) Co-authored-by: Lukas Taegert-Atkinson --- src/finalisers/shared/getInteropBlock.ts | 2 +- .../_expected/amd/generated-dep.js | 2 +- .../amd/_virtual/_external_commonjs-external | 2 +- .../_expected/amd/commonjs.js | 2 +- .../_expected/amd/main.js | 2 +- test/form/samples/compact/_expected/amd.js | 4 ++-- test/form/samples/compact/_expected/iife.js | 4 ++-- test/form/samples/compact/_expected/umd.js | 2 +- .../_expected/amd.js | 2 +- .../_expected/iife.js | 2 +- .../_expected/umd.js | 2 +- .../export-default-import/_expected/amd.js | 2 +- .../export-default-import/_expected/iife.js | 2 +- .../export-default-import/_expected/umd.js | 2 +- .../external-deshadowing/_expected/amd.js | 2 +- .../external-deshadowing/_expected/iife.js | 2 +- .../external-deshadowing/_expected/umd.js | 2 +- .../_expected/amd.js | 2 +- .../_expected/iife.js | 2 +- .../_expected/umd.js | 2 +- .../samples/external-imports/_expected/amd.js | 2 +- .../samples/external-imports/_expected/iife.js | 2 +- .../samples/external-imports/_expected/umd.js | 2 +- .../guessed-global-names/_expected/amd.js | 2 +- .../guessed-global-names/_expected/iife.js | 2 +- .../guessed-global-names/_expected/umd.js | 2 +- .../samples/paths-function/_expected/amd.js | 2 +- .../samples/paths-function/_expected/iife.js | 2 +- .../samples/paths-function/_expected/umd.js | 2 +- .../samples/paths-relative/_expected/amd.js | 2 +- .../samples/paths-relative/_expected/iife.js | 2 +- .../samples/paths-relative/_expected/umd.js | 2 +- test/form/samples/paths/_expected/amd.js | 2 +- test/form/samples/paths/_expected/iife.js | 2 +- test/form/samples/paths/_expected/umd.js | 2 +- .../_expected/amd.js | 2 +- .../_expected/iife.js | 2 +- .../_expected/umd.js | 2 +- .../reexport-external-default/_expected/amd.js | 2 +- .../_expected/iife.js | 2 +- .../reexport-external-default/_expected/umd.js | 2 +- .../_expected/amd.js | 2 +- .../_expected/iife.js | 2 +- .../_expected/umd.js | 2 +- .../_expected/amd.js | 2 +- .../_expected/iife.js | 2 +- .../_expected/umd.js | 2 +- .../form/samples/url-external/_expected/amd.js | 2 +- .../samples/url-external/_expected/iife.js | 2 +- .../form/samples/url-external/_expected/umd.js | 2 +- .../_expected/amd.js | 2 +- .../_expected/iife.js | 2 +- .../_expected/umd.js | 2 +- .../_config.js | 18 ++++++++++++++++++ .../default-export-with-null-prototype/main.js | 3 +++ 55 files changed, 76 insertions(+), 55 deletions(-) create mode 100644 test/function/samples/default-export-with-null-prototype/_config.js create mode 100644 test/function/samples/default-export-with-null-prototype/main.js diff --git a/src/finalisers/shared/getInteropBlock.ts b/src/finalisers/shared/getInteropBlock.ts index 3aabf076edb..0e458e54b9d 100644 --- a/src/finalisers/shared/getInteropBlock.ts +++ b/src/finalisers/shared/getInteropBlock.ts @@ -20,7 +20,7 @@ export default function getInteropBlock( } return ( - `${name}${_}=${_}${name}${_}&&${_}${name}.hasOwnProperty('default')${_}?` + + `${name}${_}=${_}${name}${_}&&${_}Object.prototype.hasOwnProperty.call(${name},${_}'default')${_}?` + `${_}${name}['default']${_}:${_}${name};` ); }) diff --git a/test/chunking-form/samples/avoid-chunk-import-hoisting/_expected/amd/generated-dep.js b/test/chunking-form/samples/avoid-chunk-import-hoisting/_expected/amd/generated-dep.js index 4fc2383a2a2..aaf66da1323 100644 --- a/test/chunking-form/samples/avoid-chunk-import-hoisting/_expected/amd/generated-dep.js +++ b/test/chunking-form/samples/avoid-chunk-import-hoisting/_expected/amd/generated-dep.js @@ -1,6 +1,6 @@ define(['exports', 'lib'], function (exports, value) { 'use strict'; - value = value && value.hasOwnProperty('default') ? value['default'] : value; + value = value && Object.prototype.hasOwnProperty.call(value, 'default') ? value['default'] : value; var dep = 2 * value; diff --git a/test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/_virtual/_external_commonjs-external b/test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/_virtual/_external_commonjs-external index ad2b06d6161..aac3dad0875 100644 --- a/test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/_virtual/_external_commonjs-external +++ b/test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/_virtual/_external_commonjs-external @@ -1,6 +1,6 @@ define(['external'], function (external) { 'use strict'; - external = external && external.hasOwnProperty('default') ? external['default'] : external; + external = external && Object.prototype.hasOwnProperty.call(external, 'default') ? external['default'] : external; diff --git a/test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/commonjs.js b/test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/commonjs.js index 6f1ab74a4e9..bd160dfd08e 100644 --- a/test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/commonjs.js +++ b/test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/commonjs.js @@ -1,6 +1,6 @@ define(['exports', 'external', './other', './_virtual/_external_commonjs-external', './_virtual/other.js_commonjs-proxy'], function (exports, external, other, _external_commonjsExternal, other$1) { 'use strict'; - external = external && external.hasOwnProperty('default') ? external['default'] : external; + external = external && Object.prototype.hasOwnProperty.call(external, 'default') ? external['default'] : external; const { value } = other$1; diff --git a/test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/main.js b/test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/main.js index 5e740cc642c..48e1747cfda 100644 --- a/test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/main.js +++ b/test/chunking-form/samples/preserve-modules-commonjs/_expected/amd/main.js @@ -1,6 +1,6 @@ define(['external', './commonjs'], function (external, commonjs) { 'use strict'; - external = external && external.hasOwnProperty('default') ? external['default'] : external; + external = external && Object.prototype.hasOwnProperty.call(external, 'default') ? external['default'] : external; console.log(commonjs.default, external); diff --git a/test/form/samples/compact/_expected/amd.js b/test/form/samples/compact/_expected/amd.js index ae3955b3c27..6be712a0259 100644 --- a/test/form/samples/compact/_expected/amd.js +++ b/test/form/samples/compact/_expected/amd.js @@ -1,6 +1,6 @@ -define(['external'],function(x){'use strict';x=x&&x.hasOwnProperty('default')?x['default']:x;var self=/*#__PURE__*/Object.freeze({[Symbol.toStringTag]:'Module',__proto__:null,get default(){return foo}});console.log(self); +define(['external'],function(x){'use strict';x=x&&Object.prototype.hasOwnProperty.call(x,'default')?x['default']:x;var self=/*#__PURE__*/Object.freeze({[Symbol.toStringTag]:'Module',__proto__:null,get default(){return foo}});console.log(self); function foo () { console.log( x ); } // trailing comment -return foo;}); \ No newline at end of file +return foo;}); diff --git a/test/form/samples/compact/_expected/iife.js b/test/form/samples/compact/_expected/iife.js index 110ab76bfb1..d17c5d43442 100644 --- a/test/form/samples/compact/_expected/iife.js +++ b/test/form/samples/compact/_expected/iife.js @@ -1,6 +1,6 @@ -var foo=(function(x){'use strict';x=x&&x.hasOwnProperty('default')?x['default']:x;var self=/*#__PURE__*/Object.freeze({[Symbol.toStringTag]:'Module',__proto__:null,get default(){return foo}});console.log(self); +var foo=(function(x){'use strict';x=x&&Object.prototype.hasOwnProperty.call(x,'default')?x['default']:x;var self=/*#__PURE__*/Object.freeze({[Symbol.toStringTag]:'Module',__proto__:null,get default(){return foo}});console.log(self); function foo () { console.log( x ); } // trailing comment -return foo;}(x)); \ No newline at end of file +return foo;}(x)); diff --git a/test/form/samples/compact/_expected/umd.js b/test/form/samples/compact/_expected/umd.js index 93901234cfc..18250d221e0 100644 --- a/test/form/samples/compact/_expected/umd.js +++ b/test/form/samples/compact/_expected/umd.js @@ -1,4 +1,4 @@ -(function(g,f){typeof exports==='object'&&typeof module!=='undefined'?module.exports=f(require('external')):typeof define==='function'&&define.amd?define(['external'],f):(g=g||self,g.foo=f(g.x));}(this,(function(x){'use strict';x=x&&x.hasOwnProperty('default')?x['default']:x;var self=/*#__PURE__*/Object.freeze({[Symbol.toStringTag]:'Module',__proto__:null,get default(){return foo}});console.log(self); +(function(g,f){typeof exports==='object'&&typeof module!=='undefined'?module.exports=f(require('external')):typeof define==='function'&&define.amd?define(['external'],f):(g=g||self,g.foo=f(g.x));}(this,(function(x){'use strict';x=x&&Object.prototype.hasOwnProperty.call(x,'default')?x['default']:x;var self=/*#__PURE__*/Object.freeze({[Symbol.toStringTag]:'Module',__proto__:null,get default(){return foo}});console.log(self); function foo () { console.log( x ); } diff --git a/test/form/samples/deconflict-format-specific-globals/_expected/amd.js b/test/form/samples/deconflict-format-specific-globals/_expected/amd.js index 3e5eb19d02c..f5bf6f86c8d 100644 --- a/test/form/samples/deconflict-format-specific-globals/_expected/amd.js +++ b/test/form/samples/deconflict-format-specific-globals/_expected/amd.js @@ -19,7 +19,7 @@ define(['module', 'require', 'external'], function (module, require, external) { } } - external = external && external.hasOwnProperty('default') ? external['default'] : external; + external = external && Object.prototype.hasOwnProperty.call(external, 'default') ? external['default'] : external; console.log(external); diff --git a/test/form/samples/deconflict-format-specific-globals/_expected/iife.js b/test/form/samples/deconflict-format-specific-globals/_expected/iife.js index e8aa89b3fcb..31905bacc66 100644 --- a/test/form/samples/deconflict-format-specific-globals/_expected/iife.js +++ b/test/form/samples/deconflict-format-specific-globals/_expected/iife.js @@ -1,7 +1,7 @@ var bundle = (function (external) { 'use strict'; - external = external && external.hasOwnProperty('default') ? external['default'] : external; + external = external && Object.prototype.hasOwnProperty.call(external, 'default') ? external['default'] : external; console.log(external); diff --git a/test/form/samples/deconflict-format-specific-globals/_expected/umd.js b/test/form/samples/deconflict-format-specific-globals/_expected/umd.js index 27e967c3740..3fdf74e1f46 100644 --- a/test/form/samples/deconflict-format-specific-globals/_expected/umd.js +++ b/test/form/samples/deconflict-format-specific-globals/_expected/umd.js @@ -4,7 +4,7 @@ (global = global || self, global.bundle = factory(global.external)); }(this, (function (external) { 'use strict'; - external = external && external.hasOwnProperty('default') ? external['default'] : external; + external = external && Object.prototype.hasOwnProperty.call(external, 'default') ? external['default'] : external; console.log(external); diff --git a/test/form/samples/export-default-import/_expected/amd.js b/test/form/samples/export-default-import/_expected/amd.js index 2be38062460..9fab6961904 100644 --- a/test/form/samples/export-default-import/_expected/amd.js +++ b/test/form/samples/export-default-import/_expected/amd.js @@ -1,6 +1,6 @@ define(['exports', 'x'], function (exports, x) { 'use strict'; - x = x && x.hasOwnProperty('default') ? x['default'] : x; + x = x && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; diff --git a/test/form/samples/export-default-import/_expected/iife.js b/test/form/samples/export-default-import/_expected/iife.js index ccb224f947a..4158e308c99 100644 --- a/test/form/samples/export-default-import/_expected/iife.js +++ b/test/form/samples/export-default-import/_expected/iife.js @@ -1,7 +1,7 @@ var myBundle = (function (exports, x) { 'use strict'; - x = x && x.hasOwnProperty('default') ? x['default'] : x; + x = x && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; diff --git a/test/form/samples/export-default-import/_expected/umd.js b/test/form/samples/export-default-import/_expected/umd.js index c37652e46a8..b8886fbc23d 100644 --- a/test/form/samples/export-default-import/_expected/umd.js +++ b/test/form/samples/export-default-import/_expected/umd.js @@ -4,7 +4,7 @@ (global = global || self, factory(global.myBundle = {}, global.x)); }(this, (function (exports, x) { 'use strict'; - x = x && x.hasOwnProperty('default') ? x['default'] : x; + x = x && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; diff --git a/test/form/samples/external-deshadowing/_expected/amd.js b/test/form/samples/external-deshadowing/_expected/amd.js index ddf292350fa..851ae0a309d 100644 --- a/test/form/samples/external-deshadowing/_expected/amd.js +++ b/test/form/samples/external-deshadowing/_expected/amd.js @@ -1,6 +1,6 @@ define(['exports', 'a', 'b'], function (exports, a, Test$1) { 'use strict'; - Test$1 = Test$1 && Test$1.hasOwnProperty('default') ? Test$1['default'] : Test$1; + Test$1 = Test$1 && Object.prototype.hasOwnProperty.call(Test$1, 'default') ? Test$1['default'] : Test$1; const Test = () => { console.log(a.Test); diff --git a/test/form/samples/external-deshadowing/_expected/iife.js b/test/form/samples/external-deshadowing/_expected/iife.js index a316d064806..c8e2234e4b7 100644 --- a/test/form/samples/external-deshadowing/_expected/iife.js +++ b/test/form/samples/external-deshadowing/_expected/iife.js @@ -1,7 +1,7 @@ var myBundle = (function (exports, a, Test$1) { 'use strict'; - Test$1 = Test$1 && Test$1.hasOwnProperty('default') ? Test$1['default'] : Test$1; + Test$1 = Test$1 && Object.prototype.hasOwnProperty.call(Test$1, 'default') ? Test$1['default'] : Test$1; const Test = () => { console.log(a.Test); diff --git a/test/form/samples/external-deshadowing/_expected/umd.js b/test/form/samples/external-deshadowing/_expected/umd.js index 7016fd90016..c3a21806bb2 100644 --- a/test/form/samples/external-deshadowing/_expected/umd.js +++ b/test/form/samples/external-deshadowing/_expected/umd.js @@ -4,7 +4,7 @@ (global = global || self, factory(global.myBundle = {}, global.a, global.b)); }(this, (function (exports, a, Test$1) { 'use strict'; - Test$1 = Test$1 && Test$1.hasOwnProperty('default') ? Test$1['default'] : Test$1; + Test$1 = Test$1 && Object.prototype.hasOwnProperty.call(Test$1, 'default') ? Test$1['default'] : Test$1; const Test = () => { console.log(a.Test); diff --git a/test/form/samples/external-imports-custom-names/_expected/amd.js b/test/form/samples/external-imports-custom-names/_expected/amd.js index 0061bcfe708..990a9471fd7 100644 --- a/test/form/samples/external-imports-custom-names/_expected/amd.js +++ b/test/form/samples/external-imports-custom-names/_expected/amd.js @@ -1,6 +1,6 @@ define(['jquery'], function ($) { 'use strict'; - $ = $ && $.hasOwnProperty('default') ? $['default'] : $; + $ = $ && Object.prototype.hasOwnProperty.call($, 'default') ? $['default'] : $; $( function () { $( 'body' ).html( '

hello world!

' ); diff --git a/test/form/samples/external-imports-custom-names/_expected/iife.js b/test/form/samples/external-imports-custom-names/_expected/iife.js index 9d27440261b..1104f0e03bd 100644 --- a/test/form/samples/external-imports-custom-names/_expected/iife.js +++ b/test/form/samples/external-imports-custom-names/_expected/iife.js @@ -1,7 +1,7 @@ (function ($) { 'use strict'; - $ = $ && $.hasOwnProperty('default') ? $['default'] : $; + $ = $ && Object.prototype.hasOwnProperty.call($, 'default') ? $['default'] : $; $( function () { $( 'body' ).html( '

hello world!

' ); diff --git a/test/form/samples/external-imports-custom-names/_expected/umd.js b/test/form/samples/external-imports-custom-names/_expected/umd.js index fd75ee31755..e657b318686 100644 --- a/test/form/samples/external-imports-custom-names/_expected/umd.js +++ b/test/form/samples/external-imports-custom-names/_expected/umd.js @@ -4,7 +4,7 @@ (global = global || self, factory(global.jQuery)); }(this, (function ($) { 'use strict'; - $ = $ && $.hasOwnProperty('default') ? $['default'] : $; + $ = $ && Object.prototype.hasOwnProperty.call($, 'default') ? $['default'] : $; $( function () { $( 'body' ).html( '

hello world!

' ); diff --git a/test/form/samples/external-imports/_expected/amd.js b/test/form/samples/external-imports/_expected/amd.js index 987d30e41b4..aebc9376930 100644 --- a/test/form/samples/external-imports/_expected/amd.js +++ b/test/form/samples/external-imports/_expected/amd.js @@ -1,6 +1,6 @@ define(['factory', 'baz', 'shipping-port', 'alphabet'], function (factory, baz, containers, alphabet) { 'use strict'; - factory = factory && factory.hasOwnProperty('default') ? factory['default'] : factory; + factory = factory && Object.prototype.hasOwnProperty.call(factory, 'default') ? factory['default'] : factory; var alphabet__default = 'default' in alphabet ? alphabet['default'] : alphabet; factory( null ); diff --git a/test/form/samples/external-imports/_expected/iife.js b/test/form/samples/external-imports/_expected/iife.js index fb0f172d051..89e8261b043 100644 --- a/test/form/samples/external-imports/_expected/iife.js +++ b/test/form/samples/external-imports/_expected/iife.js @@ -1,7 +1,7 @@ (function (factory, baz, containers, alphabet) { 'use strict'; - factory = factory && factory.hasOwnProperty('default') ? factory['default'] : factory; + factory = factory && Object.prototype.hasOwnProperty.call(factory, 'default') ? factory['default'] : factory; var alphabet__default = 'default' in alphabet ? alphabet['default'] : alphabet; factory( null ); diff --git a/test/form/samples/external-imports/_expected/umd.js b/test/form/samples/external-imports/_expected/umd.js index b997f310acb..041d0464080 100644 --- a/test/form/samples/external-imports/_expected/umd.js +++ b/test/form/samples/external-imports/_expected/umd.js @@ -4,7 +4,7 @@ (global = global || self, factory(global.factory, global.baz, global.containers, global.alphabet)); }(this, (function (factory, baz, containers, alphabet) { 'use strict'; - factory = factory && factory.hasOwnProperty('default') ? factory['default'] : factory; + factory = factory && Object.prototype.hasOwnProperty.call(factory, 'default') ? factory['default'] : factory; var alphabet__default = 'default' in alphabet ? alphabet['default'] : alphabet; factory( null ); diff --git a/test/form/samples/guessed-global-names/_expected/amd.js b/test/form/samples/guessed-global-names/_expected/amd.js index 9d13ee97532..61394b470af 100644 --- a/test/form/samples/guessed-global-names/_expected/amd.js +++ b/test/form/samples/guessed-global-names/_expected/amd.js @@ -1,6 +1,6 @@ define(['unchanged', 'changed', 'special-character', 'with/slash', './relative'], function (unchanged, changedName, specialCharacter, slash, relative_js) { 'use strict'; - changedName = changedName && changedName.hasOwnProperty('default') ? changedName['default'] : changedName; + changedName = changedName && Object.prototype.hasOwnProperty.call(changedName, 'default') ? changedName['default'] : changedName; console.log(unchanged.foo, changedName, specialCharacter.bar, slash.baz, relative_js.quux); diff --git a/test/form/samples/guessed-global-names/_expected/iife.js b/test/form/samples/guessed-global-names/_expected/iife.js index 4ecb13ccfde..127fd3d059b 100644 --- a/test/form/samples/guessed-global-names/_expected/iife.js +++ b/test/form/samples/guessed-global-names/_expected/iife.js @@ -1,7 +1,7 @@ (function (unchanged, changedName, specialCharacter, slash, relative_js) { 'use strict'; - changedName = changedName && changedName.hasOwnProperty('default') ? changedName['default'] : changedName; + changedName = changedName && Object.prototype.hasOwnProperty.call(changedName, 'default') ? changedName['default'] : changedName; console.log(unchanged.foo, changedName, specialCharacter.bar, slash.baz, relative_js.quux); diff --git a/test/form/samples/guessed-global-names/_expected/umd.js b/test/form/samples/guessed-global-names/_expected/umd.js index 52632f59939..6133022812e 100644 --- a/test/form/samples/guessed-global-names/_expected/umd.js +++ b/test/form/samples/guessed-global-names/_expected/umd.js @@ -4,7 +4,7 @@ (global = global || self, factory(global.unchanged, global.changedName, global.specialCharacter, global.slash, global.relative_js)); }(this, (function (unchanged, changedName, specialCharacter, slash, relative_js) { 'use strict'; - changedName = changedName && changedName.hasOwnProperty('default') ? changedName['default'] : changedName; + changedName = changedName && Object.prototype.hasOwnProperty.call(changedName, 'default') ? changedName['default'] : changedName; console.log(unchanged.foo, changedName, specialCharacter.bar, slash.baz, relative_js.quux); diff --git a/test/form/samples/paths-function/_expected/amd.js b/test/form/samples/paths-function/_expected/amd.js index fe9f13f94ed..e9cd1a89377 100644 --- a/test/form/samples/paths-function/_expected/amd.js +++ b/test/form/samples/paths-function/_expected/amd.js @@ -1,6 +1,6 @@ define(['https://unpkg.com/foo'], function (foo) { 'use strict'; - foo = foo && foo.hasOwnProperty('default') ? foo['default'] : foo; + foo = foo && Object.prototype.hasOwnProperty.call(foo, 'default') ? foo['default'] : foo; assert.equal( foo, 42 ); diff --git a/test/form/samples/paths-function/_expected/iife.js b/test/form/samples/paths-function/_expected/iife.js index e1c212ba377..57e136764ba 100644 --- a/test/form/samples/paths-function/_expected/iife.js +++ b/test/form/samples/paths-function/_expected/iife.js @@ -1,7 +1,7 @@ (function (foo) { 'use strict'; - foo = foo && foo.hasOwnProperty('default') ? foo['default'] : foo; + foo = foo && Object.prototype.hasOwnProperty.call(foo, 'default') ? foo['default'] : foo; assert.equal( foo, 42 ); diff --git a/test/form/samples/paths-function/_expected/umd.js b/test/form/samples/paths-function/_expected/umd.js index 9ec1d24990b..10e1ffcde7a 100644 --- a/test/form/samples/paths-function/_expected/umd.js +++ b/test/form/samples/paths-function/_expected/umd.js @@ -4,7 +4,7 @@ (global = global || self, factory(global.foo)); }(this, (function (foo) { 'use strict'; - foo = foo && foo.hasOwnProperty('default') ? foo['default'] : foo; + foo = foo && Object.prototype.hasOwnProperty.call(foo, 'default') ? foo['default'] : foo; assert.equal( foo, 42 ); diff --git a/test/form/samples/paths-relative/_expected/amd.js b/test/form/samples/paths-relative/_expected/amd.js index 46535010cb4..434ca8bb4f6 100644 --- a/test/form/samples/paths-relative/_expected/amd.js +++ b/test/form/samples/paths-relative/_expected/amd.js @@ -1,6 +1,6 @@ define(['../foo'], function (foo) { 'use strict'; - foo = foo && foo.hasOwnProperty('default') ? foo['default'] : foo; + foo = foo && Object.prototype.hasOwnProperty.call(foo, 'default') ? foo['default'] : foo; assert.equal( foo, 42 ); diff --git a/test/form/samples/paths-relative/_expected/iife.js b/test/form/samples/paths-relative/_expected/iife.js index e1c212ba377..57e136764ba 100644 --- a/test/form/samples/paths-relative/_expected/iife.js +++ b/test/form/samples/paths-relative/_expected/iife.js @@ -1,7 +1,7 @@ (function (foo) { 'use strict'; - foo = foo && foo.hasOwnProperty('default') ? foo['default'] : foo; + foo = foo && Object.prototype.hasOwnProperty.call(foo, 'default') ? foo['default'] : foo; assert.equal( foo, 42 ); diff --git a/test/form/samples/paths-relative/_expected/umd.js b/test/form/samples/paths-relative/_expected/umd.js index e62e957c412..5dee3d68723 100644 --- a/test/form/samples/paths-relative/_expected/umd.js +++ b/test/form/samples/paths-relative/_expected/umd.js @@ -4,7 +4,7 @@ (global = global || self, factory(global.foo)); }(this, (function (foo) { 'use strict'; - foo = foo && foo.hasOwnProperty('default') ? foo['default'] : foo; + foo = foo && Object.prototype.hasOwnProperty.call(foo, 'default') ? foo['default'] : foo; assert.equal( foo, 42 ); diff --git a/test/form/samples/paths/_expected/amd.js b/test/form/samples/paths/_expected/amd.js index fe9f13f94ed..e9cd1a89377 100644 --- a/test/form/samples/paths/_expected/amd.js +++ b/test/form/samples/paths/_expected/amd.js @@ -1,6 +1,6 @@ define(['https://unpkg.com/foo'], function (foo) { 'use strict'; - foo = foo && foo.hasOwnProperty('default') ? foo['default'] : foo; + foo = foo && Object.prototype.hasOwnProperty.call(foo, 'default') ? foo['default'] : foo; assert.equal( foo, 42 ); diff --git a/test/form/samples/paths/_expected/iife.js b/test/form/samples/paths/_expected/iife.js index e1c212ba377..57e136764ba 100644 --- a/test/form/samples/paths/_expected/iife.js +++ b/test/form/samples/paths/_expected/iife.js @@ -1,7 +1,7 @@ (function (foo) { 'use strict'; - foo = foo && foo.hasOwnProperty('default') ? foo['default'] : foo; + foo = foo && Object.prototype.hasOwnProperty.call(foo, 'default') ? foo['default'] : foo; assert.equal( foo, 42 ); diff --git a/test/form/samples/paths/_expected/umd.js b/test/form/samples/paths/_expected/umd.js index 9ec1d24990b..10e1ffcde7a 100644 --- a/test/form/samples/paths/_expected/umd.js +++ b/test/form/samples/paths/_expected/umd.js @@ -4,7 +4,7 @@ (global = global || self, factory(global.foo)); }(this, (function (foo) { 'use strict'; - foo = foo && foo.hasOwnProperty('default') ? foo['default'] : foo; + foo = foo && Object.prototype.hasOwnProperty.call(foo, 'default') ? foo['default'] : foo; assert.equal( foo, 42 ); diff --git a/test/form/samples/reexport-external-default-and-name/_expected/amd.js b/test/form/samples/reexport-external-default-and-name/_expected/amd.js index 6884f896916..dfc278c15be 100644 --- a/test/form/samples/reexport-external-default-and-name/_expected/amd.js +++ b/test/form/samples/reexport-external-default-and-name/_expected/amd.js @@ -1,6 +1,6 @@ define(['exports', 'external'], function (exports, external) { 'use strict'; - external = external && external.hasOwnProperty('default') ? external['default'] : external; + external = external && Object.prototype.hasOwnProperty.call(external, 'default') ? external['default'] : external; const value = 42; diff --git a/test/form/samples/reexport-external-default-and-name/_expected/iife.js b/test/form/samples/reexport-external-default-and-name/_expected/iife.js index bd001fe2f10..87e6a78278e 100644 --- a/test/form/samples/reexport-external-default-and-name/_expected/iife.js +++ b/test/form/samples/reexport-external-default-and-name/_expected/iife.js @@ -1,7 +1,7 @@ var bundle = (function (exports, external) { 'use strict'; - external = external && external.hasOwnProperty('default') ? external['default'] : external; + external = external && Object.prototype.hasOwnProperty.call(external, 'default') ? external['default'] : external; const value = 42; diff --git a/test/form/samples/reexport-external-default-and-name/_expected/umd.js b/test/form/samples/reexport-external-default-and-name/_expected/umd.js index 474467c55ce..6fca71d7f4c 100644 --- a/test/form/samples/reexport-external-default-and-name/_expected/umd.js +++ b/test/form/samples/reexport-external-default-and-name/_expected/umd.js @@ -4,7 +4,7 @@ (global = global || self, factory(global.bundle = {}, global.external)); }(this, (function (exports, external) { 'use strict'; - external = external && external.hasOwnProperty('default') ? external['default'] : external; + external = external && Object.prototype.hasOwnProperty.call(external, 'default') ? external['default'] : external; const value = 42; diff --git a/test/form/samples/reexport-external-default/_expected/amd.js b/test/form/samples/reexport-external-default/_expected/amd.js index 44863dc1288..cea23a3414e 100644 --- a/test/form/samples/reexport-external-default/_expected/amd.js +++ b/test/form/samples/reexport-external-default/_expected/amd.js @@ -1,6 +1,6 @@ define(['external1', 'external2'], function (external1, external2) { 'use strict'; - external2 = external2 && external2.hasOwnProperty('default') ? external2['default'] : external2; + external2 = external2 && Object.prototype.hasOwnProperty.call(external2, 'default') ? external2['default'] : external2; console.log(external1.foo); diff --git a/test/form/samples/reexport-external-default/_expected/iife.js b/test/form/samples/reexport-external-default/_expected/iife.js index 7d9a819618e..1d6ec76f1bc 100644 --- a/test/form/samples/reexport-external-default/_expected/iife.js +++ b/test/form/samples/reexport-external-default/_expected/iife.js @@ -1,7 +1,7 @@ var bundle = (function (external1, external2) { 'use strict'; - external2 = external2 && external2.hasOwnProperty('default') ? external2['default'] : external2; + external2 = external2 && Object.prototype.hasOwnProperty.call(external2, 'default') ? external2['default'] : external2; console.log(external1.foo); diff --git a/test/form/samples/reexport-external-default/_expected/umd.js b/test/form/samples/reexport-external-default/_expected/umd.js index a32c5a8463a..0525bd5d5fe 100644 --- a/test/form/samples/reexport-external-default/_expected/umd.js +++ b/test/form/samples/reexport-external-default/_expected/umd.js @@ -4,7 +4,7 @@ (global = global || self, global.bundle = factory(global.external1, global.external2)); }(this, (function (external1, external2) { 'use strict'; - external2 = external2 && external2.hasOwnProperty('default') ? external2['default'] : external2; + external2 = external2 && Object.prototype.hasOwnProperty.call(external2, 'default') ? external2['default'] : external2; console.log(external1.foo); diff --git a/test/form/samples/relative-external-with-global/_expected/amd.js b/test/form/samples/relative-external-with-global/_expected/amd.js index 084748c64a2..6e925ec17b2 100644 --- a/test/form/samples/relative-external-with-global/_expected/amd.js +++ b/test/form/samples/relative-external-with-global/_expected/amd.js @@ -1,6 +1,6 @@ define(['./lib/throttle'], function (throttle) { 'use strict'; - throttle = throttle && throttle.hasOwnProperty('default') ? throttle['default'] : throttle; + throttle = throttle && Object.prototype.hasOwnProperty.call(throttle, 'default') ? throttle['default'] : throttle; const fn = throttle( () => { console.log( '.' ); diff --git a/test/form/samples/relative-external-with-global/_expected/iife.js b/test/form/samples/relative-external-with-global/_expected/iife.js index 0d3e8842090..e371c2b3b25 100644 --- a/test/form/samples/relative-external-with-global/_expected/iife.js +++ b/test/form/samples/relative-external-with-global/_expected/iife.js @@ -1,7 +1,7 @@ (function (throttle) { 'use strict'; - throttle = throttle && throttle.hasOwnProperty('default') ? throttle['default'] : throttle; + throttle = throttle && Object.prototype.hasOwnProperty.call(throttle, 'default') ? throttle['default'] : throttle; const fn = throttle( () => { console.log( '.' ); diff --git a/test/form/samples/relative-external-with-global/_expected/umd.js b/test/form/samples/relative-external-with-global/_expected/umd.js index be024920ad5..1a772d6991c 100644 --- a/test/form/samples/relative-external-with-global/_expected/umd.js +++ b/test/form/samples/relative-external-with-global/_expected/umd.js @@ -4,7 +4,7 @@ (global = global || self, factory(global.Lib.throttle)); }(this, (function (throttle) { 'use strict'; - throttle = throttle && throttle.hasOwnProperty('default') ? throttle['default'] : throttle; + throttle = throttle && Object.prototype.hasOwnProperty.call(throttle, 'default') ? throttle['default'] : throttle; const fn = throttle( () => { console.log( '.' ); diff --git a/test/form/samples/resolve-external-dynamic-imports/_expected/amd.js b/test/form/samples/resolve-external-dynamic-imports/_expected/amd.js index 9a4d9c1e6ef..814956b8125 100644 --- a/test/form/samples/resolve-external-dynamic-imports/_expected/amd.js +++ b/test/form/samples/resolve-external-dynamic-imports/_expected/amd.js @@ -19,7 +19,7 @@ define(['require', 'exports', 'external'], function (require, exports, myExterna } } - myExternal = myExternal && myExternal.hasOwnProperty('default') ? myExternal['default'] : myExternal; + myExternal = myExternal && Object.prototype.hasOwnProperty.call(myExternal, 'default') ? myExternal['default'] : myExternal; const test = () => myExternal; diff --git a/test/form/samples/resolve-external-dynamic-imports/_expected/iife.js b/test/form/samples/resolve-external-dynamic-imports/_expected/iife.js index 5e0d818f0ca..ab83517366c 100644 --- a/test/form/samples/resolve-external-dynamic-imports/_expected/iife.js +++ b/test/form/samples/resolve-external-dynamic-imports/_expected/iife.js @@ -1,7 +1,7 @@ var bundle = (function (exports, myExternal) { 'use strict'; - myExternal = myExternal && myExternal.hasOwnProperty('default') ? myExternal['default'] : myExternal; + myExternal = myExternal && Object.prototype.hasOwnProperty.call(myExternal, 'default') ? myExternal['default'] : myExternal; const test = () => myExternal; diff --git a/test/form/samples/resolve-external-dynamic-imports/_expected/umd.js b/test/form/samples/resolve-external-dynamic-imports/_expected/umd.js index db633c3cc02..a68206b6984 100644 --- a/test/form/samples/resolve-external-dynamic-imports/_expected/umd.js +++ b/test/form/samples/resolve-external-dynamic-imports/_expected/umd.js @@ -4,7 +4,7 @@ (global = global || self, factory(global.bundle = {}, global.myExternal)); }(this, (function (exports, myExternal) { 'use strict'; - myExternal = myExternal && myExternal.hasOwnProperty('default') ? myExternal['default'] : myExternal; + myExternal = myExternal && Object.prototype.hasOwnProperty.call(myExternal, 'default') ? myExternal['default'] : myExternal; const test = () => myExternal; diff --git a/test/form/samples/url-external/_expected/amd.js b/test/form/samples/url-external/_expected/amd.js index c435682c098..3ac4177a2a5 100644 --- a/test/form/samples/url-external/_expected/amd.js +++ b/test/form/samples/url-external/_expected/amd.js @@ -1,6 +1,6 @@ define(['https://external.com/external.js'], function (external) { 'use strict'; - external = external && external.hasOwnProperty('default') ? external['default'] : external; + external = external && Object.prototype.hasOwnProperty.call(external, 'default') ? external['default'] : external; console.log(external); diff --git a/test/form/samples/url-external/_expected/iife.js b/test/form/samples/url-external/_expected/iife.js index 549bf95badc..146f82abcee 100644 --- a/test/form/samples/url-external/_expected/iife.js +++ b/test/form/samples/url-external/_expected/iife.js @@ -1,7 +1,7 @@ (function (external) { 'use strict'; - external = external && external.hasOwnProperty('default') ? external['default'] : external; + external = external && Object.prototype.hasOwnProperty.call(external, 'default') ? external['default'] : external; console.log(external); diff --git a/test/form/samples/url-external/_expected/umd.js b/test/form/samples/url-external/_expected/umd.js index 8002a385ed2..f5e7523eaee 100644 --- a/test/form/samples/url-external/_expected/umd.js +++ b/test/form/samples/url-external/_expected/umd.js @@ -4,7 +4,7 @@ (global = global || self, factory(global.external)); }(this, (function (external) { 'use strict'; - external = external && external.hasOwnProperty('default') ? external['default'] : external; + external = external && Object.prototype.hasOwnProperty.call(external, 'default') ? external['default'] : external; console.log(external); diff --git a/test/form/samples/use-global-map-for-export-name/_expected/amd.js b/test/form/samples/use-global-map-for-export-name/_expected/amd.js index 3ee270a88f1..45be980cc49 100644 --- a/test/form/samples/use-global-map-for-export-name/_expected/amd.js +++ b/test/form/samples/use-global-map-for-export-name/_expected/amd.js @@ -1,6 +1,6 @@ define(['leaflet'], function (L) { 'use strict'; - L = L && L.hasOwnProperty('default') ? L['default'] : L; + L = L && Object.prototype.hasOwnProperty.call(L, 'default') ? L['default'] : L; L.terminator = function(options) { }; diff --git a/test/form/samples/use-global-map-for-export-name/_expected/iife.js b/test/form/samples/use-global-map-for-export-name/_expected/iife.js index 325179b7c1a..72d2db0e424 100644 --- a/test/form/samples/use-global-map-for-export-name/_expected/iife.js +++ b/test/form/samples/use-global-map-for-export-name/_expected/iife.js @@ -1,7 +1,7 @@ (function (L) { 'use strict'; - L = L && L.hasOwnProperty('default') ? L['default'] : L; + L = L && Object.prototype.hasOwnProperty.call(L, 'default') ? L['default'] : L; L.terminator = function(options) { }; diff --git a/test/form/samples/use-global-map-for-export-name/_expected/umd.js b/test/form/samples/use-global-map-for-export-name/_expected/umd.js index d1cebac3105..b5fd446c60d 100644 --- a/test/form/samples/use-global-map-for-export-name/_expected/umd.js +++ b/test/form/samples/use-global-map-for-export-name/_expected/umd.js @@ -4,7 +4,7 @@ (global = global || self, factory(global.L)); }(this, (function (L) { 'use strict'; - L = L && L.hasOwnProperty('default') ? L['default'] : L; + L = L && Object.prototype.hasOwnProperty.call(L, 'default') ? L['default'] : L; L.terminator = function(options) { }; diff --git a/test/function/samples/default-export-with-null-prototype/_config.js b/test/function/samples/default-export-with-null-prototype/_config.js new file mode 100644 index 00000000000..8912ca75d4c --- /dev/null +++ b/test/function/samples/default-export-with-null-prototype/_config.js @@ -0,0 +1,18 @@ +module.exports = { + description: 'default exports of objects with null prototypes are supported', + options: { + external: ['foo'], + output: { + format: 'iife', + globals: { foo: 'foo' } + }, + plugins: [ + { + renderChunk: code => ` + const foo = { __proto__: null, bar: 42 }; + ${code} + ` + } + ] + } +}; diff --git a/test/function/samples/default-export-with-null-prototype/main.js b/test/function/samples/default-export-with-null-prototype/main.js new file mode 100644 index 00000000000..60a3a136372 --- /dev/null +++ b/test/function/samples/default-export-with-null-prototype/main.js @@ -0,0 +1,3 @@ +import foo from 'foo'; + +assert.equal(foo.bar, 42);