From ef7486d3f5256e3cd752e853df9950ac03d469e4 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Thu, 4 Jul 2019 16:16:36 +0200 Subject: [PATCH 1/7] Make tests run on Node 12, fix watcher cleanup issue (#2982) * Make tests run on Node 12, fix watcher cleanup issue * Just do not run leak test on Node 12 --- .circleci/config.yml | 19 +++++++++++++++++++ package.json | 1 + src/watch/index.ts | 14 +++++++------- .../catch-dynamic-import-failure/_config.js | 3 ++- .../dynamic-import-expression/_config.js | 5 ++++- .../dynamic-import-rewriting/_config.js | 5 ++++- 6 files changed, 37 insertions(+), 10 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 70ff0652971..bbd2f6a3d1c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -9,6 +9,15 @@ unit_tests: &unit_tests name: Run unit tests. command: npm run ci:test +unit_tests_12: &unit_tests_12 + steps: + - checkout + - restore_cache: + key: dependency-cache-{{ checksum "package-lock.json" }} + - run: + name: Run unit tests. + command: npm run ci:test_12 + jobs: analysis: docker: @@ -42,6 +51,10 @@ jobs: docker: - image: rollupcabal/circleci-node-v10:latest <<: *unit_tests + node-v12-latest: + docker: + - image: rollupcabal/circleci-node-v12:latest + <<: *unit_tests_12 workflows: version: 2 @@ -69,3 +82,9 @@ workflows: filters: tags: only: /.*/ + - node-v12-latest: + requires: + - analysis + filters: + tags: + only: /.*/ diff --git a/package.json b/package.json index 5019e432ea1..070b411537a 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "ci:coverage": "npm run test:coverage", "ci:lint": "npm run lint:nofix && npm run security", "ci:test": "npm run build:test && npm run build:bootstrap && npm run test:all", + "ci:test_12": "npm run build:test && npm run build:bootstrap && npm run test:only && npm run test:typescript", "lint": "npm run lint:ts -- --fix && npm run lint:js -- --fix && npm run lint:markdown", "lint:nofix": "npm run lint:ts && npm run lint:js && npm run lint:markdown", "lint:ts": "tslint --project .", diff --git a/src/watch/index.ts b/src/watch/index.ts index 5086697cf0b..f2757497549 100644 --- a/src/watch/index.ts +++ b/src/watch/index.ts @@ -211,26 +211,26 @@ export class Task { return rollup(options) .then(result => { if (this.closed) return undefined as any; - + const previouslyWatched = this.watched; const watched = (this.watched = new Set()); this.cache = result.cache; this.watchFiles = result.watchFiles; - (this.cache.modules as ModuleJSON[]).forEach(module => { + for (const module of this.cache.modules as ModuleJSON[]) { if (module.transformDependencies) { module.transformDependencies.forEach(depId => { watched.add(depId); this.watchFile(depId, true); }); } - }); - this.watchFiles.forEach(id => { + } + for (const id of this.watchFiles) { watched.add(id); this.watchFile(id); - }); - this.watched.forEach(id => { + } + for (const id of previouslyWatched) { if (!watched.has(id)) deleteTask(id, this, this.chokidarOptionsHash); - }); + } return Promise.all(this.outputs.map(output => result.write(output))).then(() => result); }) diff --git a/test/function/samples/catch-dynamic-import-failure/_config.js b/test/function/samples/catch-dynamic-import-failure/_config.js index 475d2078603..98030f30575 100644 --- a/test/function/samples/catch-dynamic-import-failure/_config.js +++ b/test/function/samples/catch-dynamic-import-failure/_config.js @@ -10,7 +10,8 @@ module.exports = { return exports.then(result => { assert.strictEqual(result[0].message, 'exists-named'); assert.strictEqual(result[1].message, 'exists-default'); - assert.strictEqual(result[2].message, "Cannot find module 'does-not-exist'"); + const expectedError = "Cannot find module 'does-not-exist'"; + assert.strictEqual(result[2].message.slice(0, expectedError.length), expectedError); }); } }; diff --git a/test/function/samples/dynamic-import-expression/_config.js b/test/function/samples/dynamic-import-expression/_config.js index 4844bfc3fd4..e759d62c9af 100644 --- a/test/function/samples/dynamic-import-expression/_config.js +++ b/test/function/samples/dynamic-import-expression/_config.js @@ -24,6 +24,9 @@ module.exports = { ] }, exports(exports) { - return exports.catch(err => assert.strictEqual(err.message, "Cannot find module 'x/y'")); + const expectedError = "Cannot find module 'x/y'"; + return exports.catch(err => + assert.strictEqual(err.message.slice(0, expectedError.length), expectedError) + ); } }; diff --git a/test/function/samples/dynamic-import-rewriting/_config.js b/test/function/samples/dynamic-import-rewriting/_config.js index 5d2dce5b68c..a34764a8406 100644 --- a/test/function/samples/dynamic-import-rewriting/_config.js +++ b/test/function/samples/dynamic-import-rewriting/_config.js @@ -13,6 +13,9 @@ module.exports = { ] }, exports(exports) { - return exports.promise.catch(err => assert.equal(err.message, "Cannot find module 'asdf'")); + const expectedError = "Cannot find module 'asdf'"; + return exports.promise.catch(err => + assert.strictEqual(err.message.slice(0, expectedError.length), expectedError) + ); } }; From b1afb6ea0816b444c33d63a8d187aeccda3207d9 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Thu, 4 Jul 2019 16:34:10 +0200 Subject: [PATCH 2/7] Do not skip onwarn handler when --silent is used (#2981) * Do not skip onwarn with --silent * Update documentation --- bin/src/run/batchWarnings.ts | 2 +- bin/src/run/build.ts | 9 +++++---- docs/01-command-line-reference.md | 4 ++-- docs/999-big-list-of-options.md | 2 +- src/utils/mergeOptions.ts | 7 ++----- test/cli/samples/silent-onwarn/_config.js | 10 ++++++++++ test/cli/samples/silent-onwarn/_expected.js | 5 +++++ test/cli/samples/silent-onwarn/main.js | 5 +++++ .../samples/silent-onwarn/rollup.config.js | 20 +++++++++++++++++++ 9 files changed, 51 insertions(+), 13 deletions(-) create mode 100644 test/cli/samples/silent-onwarn/_config.js create mode 100644 test/cli/samples/silent-onwarn/_expected.js create mode 100644 test/cli/samples/silent-onwarn/main.js create mode 100644 test/cli/samples/silent-onwarn/rollup.config.js diff --git a/bin/src/run/batchWarnings.ts b/bin/src/run/batchWarnings.ts index 7fa1d5dd74a..463ec8e69d0 100644 --- a/bin/src/run/batchWarnings.ts +++ b/bin/src/run/batchWarnings.ts @@ -253,7 +253,7 @@ const deferredHandlers: { let lastUrl: string; nestedByMessage.forEach(({ key: message, items }) => { - title(`${plugin} plugin: ${message}`); + title(`Plugin ${plugin}: ${message}`); items.forEach(warning => { if (warning.url !== lastUrl) info((lastUrl = warning.url as string)); diff --git a/bin/src/run/build.ts b/bin/src/run/build.ts index 73fb65a2e2f..274194c909f 100644 --- a/bin/src/run/build.ts +++ b/bin/src/run/build.ts @@ -77,13 +77,14 @@ export default function build( ); }) .then((bundle?: RollupBuild) => { - warnings.flush(); - if (!silent) + if (!silent) { + warnings.flush(); stderr( tc.green(`created ${tc.bold(files.join(', '))} in ${tc.bold(ms(Date.now() - start))}`) ); - if (bundle && bundle.getTimings) { - printTimings(bundle.getTimings()); + if (bundle && bundle.getTimings) { + printTimings(bundle.getTimings()); + } } }) .catch((err: any) => { diff --git a/docs/01-command-line-reference.md b/docs/01-command-line-reference.md index 40dea3ad64c..e3a50604e7c 100755 --- a/docs/01-command-line-reference.md +++ b/docs/01-command-line-reference.md @@ -165,7 +165,7 @@ $ rollup --config $ rollup --config my.config.js ``` -You can also export a function that returns any of the above configuration formats. This function will be passed the current command line arguments so that you can dynamically adapt your configuration to respect e.g. `--silent`. You can even define your own command line options if you prefix them with `config`: +You can also export a function that returns any of the above configuration formats. This function will be passed the current command line arguments so that you can dynamically adapt your configuration to respect e.g. [`--silent`](guide/en/#--silent). You can even define your own command line options if you prefix them with `config`: ```javascript // rollup.config.js @@ -254,7 +254,7 @@ Rebuild the bundle when its source files change on disk. #### `--silent` -Don't print warnings to the console. +Don't print warnings to the console. If your configuration file contains an `onwarn` handler, this handler will still be called. To manually prevent that, you can access the command line options in your configuration file as described at the end of [Configuration Files](guide/en/#configuration-files). #### `--environment ` diff --git a/docs/999-big-list-of-options.md b/docs/999-big-list-of-options.md index fcbb5273c65..8649dcac4a4 100755 --- a/docs/999-big-list-of-options.md +++ b/docs/999-big-list-of-options.md @@ -317,7 +317,7 @@ Be aware that manual chunks can change the behaviour of the application if side- #### onwarn Type: `(warning: RollupWarning, defaultHandler: (warning: string | RollupWarning) => void) => void;` -A function that will intercept warning messages. If not supplied, warnings will be deduplicated and printed to the console. +A function that will intercept warning messages. If not supplied, warnings will be deduplicated and printed to the console. When using the [`--silent`](guide/en/#--silent) CLI option, this handler is the only way to get notified about warnings. The function receives two arguments: the warning object and the default handler. Warnings objects have, at a minimum, a `code` and a `message` property, allowing you to control how different kinds of warnings are handled. Other properties are added depending on the type of warning. diff --git a/src/utils/mergeOptions.ts b/src/utils/mergeOptions.ts index 873fe30fb72..5456aede10a 100644 --- a/src/utils/mergeOptions.ts +++ b/src/utils/mergeOptions.ts @@ -58,12 +58,9 @@ const defaultOnWarn: WarningHandler = warning => { const getOnWarn = ( config: GenericConfigObject, - command: CommandConfigObject, defaultOnWarnHandler: WarningHandler = defaultOnWarn ): WarningHandler => - command.silent - ? () => {} - : config.onwarn + config.onwarn ? warning => (config.onwarn as WarningHandlerWithDefault)(warning, defaultOnWarnHandler) : defaultOnWarnHandler; @@ -225,7 +222,7 @@ function getInputOptions( input: getOption('input', []), manualChunks: getOption('manualChunks'), moduleContext: config.moduleContext as any, - onwarn: getOnWarn(config, command, defaultOnWarnHandler), + onwarn: getOnWarn(config, defaultOnWarnHandler), perf: getOption('perf', false), plugins: config.plugins as any, preserveModules: getOption('preserveModules'), diff --git a/test/cli/samples/silent-onwarn/_config.js b/test/cli/samples/silent-onwarn/_config.js new file mode 100644 index 00000000000..0bbc667c79a --- /dev/null +++ b/test/cli/samples/silent-onwarn/_config.js @@ -0,0 +1,10 @@ +const assert = require('assert'); + +module.exports = { + description: 'triggers onwarn with --silent', + command: 'rollup -c --silent', + stderr: stderr => { + assert.equal(stderr, ''); + return true; + } +}; diff --git a/test/cli/samples/silent-onwarn/_expected.js b/test/cli/samples/silent-onwarn/_expected.js new file mode 100644 index 00000000000..29af3b17871 --- /dev/null +++ b/test/cli/samples/silent-onwarn/_expected.js @@ -0,0 +1,5 @@ +var doIt = () => console.log('main'); + +doIt(); + +export default doIt; diff --git a/test/cli/samples/silent-onwarn/main.js b/test/cli/samples/silent-onwarn/main.js new file mode 100644 index 00000000000..0be80e4f2dc --- /dev/null +++ b/test/cli/samples/silent-onwarn/main.js @@ -0,0 +1,5 @@ +import doIt from './main.js'; + +export default () => console.log('main'); + +doIt(); diff --git a/test/cli/samples/silent-onwarn/rollup.config.js b/test/cli/samples/silent-onwarn/rollup.config.js new file mode 100644 index 00000000000..8a1950bb762 --- /dev/null +++ b/test/cli/samples/silent-onwarn/rollup.config.js @@ -0,0 +1,20 @@ +import assert from 'assert'; + +const warnings = []; + +export default { + input: 'main.js', + output: { + format: 'esm' + }, + onwarn(warning) { + warnings.push(warning); + }, + plugins: { + generateBundle(bundle) { + assert.strictEqual(warnings.length, 1); + assert.strictEqual(warnings[0].code, 'CIRCULAR_DEPENDENCY'); + } + } + +} From ee4f0fef04d2db250b92ddfae4fe0d56a754a40c Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Thu, 4 Jul 2019 16:34:36 +0200 Subject: [PATCH 3/7] Update changelog --- CHANGELOG.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1526990a654..423c31cb435 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # rollup changelog +## 1.16.5 +*2019-07-04* + +### Bug Fixes +* onwarn should still be called when --silent is used (#2982) +* Properly clean up watchers for files that are deleted between builds (#2982) + +### Pull Requests +* [#2981](https://github.com/rollup/rollup/pull/2981): Do not skip onwarn handler when --silent is used (@lukastaegert) +* [#2982](https://github.com/rollup/rollup/pull/2982): Make tests run on Node 12, fix watcher cleanup issue (@lukastaegert) + ## 1.16.4 *2019-07-02* @@ -8,7 +19,7 @@ * Use the correct TypeScript type for Sourcemap.version (#2976) ### Pull Requests -* [#2965](https://github.com/rollup/rollup/pull/2974): Use async readFile in getRollupDefaultPlugin (@kaksmet) +* [#2965](https://github.com/rollup/rollup/pull/2965): Use async readFile in getRollupDefaultPlugin (@kaksmet) * [#2974](https://github.com/rollup/rollup/pull/2974): Align TS types, docs and implementation for this.warn and this.error (@lukastaegert) * [#2976](https://github.com/rollup/rollup/pull/2976): Fix sourcemap type and update dependencies (@lukastaegert) From c4dbb51f7ec338de06f5e20db92135595e3f59ac Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Thu, 4 Jul 2019 16:34:43 +0200 Subject: [PATCH 4/7] 1.16.5 --- 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 fe08802f6c5..c9742d52f6d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "rollup", - "version": "1.16.4", + "version": "1.16.5", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 070b411537a..8680c5d16ef 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rollup", - "version": "1.16.4", + "version": "1.16.5", "description": "Next-generation ES module bundler", "main": "dist/rollup.js", "module": "dist/rollup.es.js", From 61f021ed326298bd2d20e019f300ba907e20db9d Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Thu, 4 Jul 2019 18:14:19 +0200 Subject: [PATCH 5/7] Always forward AST nodes for unresolvable dynamic imports (#2984) --- src/Module.ts | 21 +++++++++---------- .../dynamic-import-unresolvable/_config.js | 20 ++++++++++++++++++ .../dynamic-import-unresolvable/_expected.js | 3 +++ .../dynamic-import-unresolvable/main.js | 3 +++ 4 files changed, 36 insertions(+), 11 deletions(-) create mode 100644 test/form/samples/dynamic-import-unresolvable/_config.js create mode 100644 test/form/samples/dynamic-import-unresolvable/_expected.js create mode 100644 test/form/samples/dynamic-import-unresolvable/main.js diff --git a/src/Module.ts b/src/Module.ts index 34458441aa4..acf5541094d 100644 --- a/src/Module.ts +++ b/src/Module.ts @@ -302,18 +302,17 @@ export default class Module { getDynamicImportExpressions(): (string | Node)[] { return this.dynamicImports.map(({ node }) => { const importArgument = node.parent.arguments[0]; - if (importArgument instanceof TemplateLiteral) { - if (importArgument.expressions.length === 0 && importArgument.quasis.length === 1) { - return importArgument.quasis[0].value.cooked; - } - } else if (importArgument instanceof Literal) { - if (typeof importArgument.value === 'string') { - return importArgument.value; - } - } else { - return importArgument; + if ( + importArgument instanceof TemplateLiteral && + importArgument.quasis.length === 1 && + importArgument.quasis[0].value.cooked + ) { + return importArgument.quasis[0].value.cooked; + } + if (importArgument instanceof Literal && typeof importArgument.value === 'string') { + return importArgument.value; } - return undefined as any; + return importArgument; }); } diff --git a/test/form/samples/dynamic-import-unresolvable/_config.js b/test/form/samples/dynamic-import-unresolvable/_config.js new file mode 100644 index 00000000000..6f64fe7a3ed --- /dev/null +++ b/test/form/samples/dynamic-import-unresolvable/_config.js @@ -0,0 +1,20 @@ +const assert = require('assert'); + +module.exports = { + solo: true, + description: 'Returns the raw AST nodes for unresolvable dynamic imports', + options: { + plugins: [ + { + resolveDynamicImport(specifier) { + assert.ok(specifier); + assert.strictEqual(typeof specifier, 'object'); + if (specifier.type !== 'TemplateLiteral' && specifier.type !== 'Literal') { + throw new Error(`Unexpected specifier type ${specifier.type}.`); + } + return false; + } + } + ] + } +}; diff --git a/test/form/samples/dynamic-import-unresolvable/_expected.js b/test/form/samples/dynamic-import-unresolvable/_expected.js new file mode 100644 index 00000000000..10da593b0b0 --- /dev/null +++ b/test/form/samples/dynamic-import-unresolvable/_expected.js @@ -0,0 +1,3 @@ +import(`${globalVar}`); +import(`My ${globalVar}`); +import(7); diff --git a/test/form/samples/dynamic-import-unresolvable/main.js b/test/form/samples/dynamic-import-unresolvable/main.js new file mode 100644 index 00000000000..10da593b0b0 --- /dev/null +++ b/test/form/samples/dynamic-import-unresolvable/main.js @@ -0,0 +1,3 @@ +import(`${globalVar}`); +import(`My ${globalVar}`); +import(7); From 365e363966e2874518e3a466966b22dcd931556a Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Thu, 4 Jul 2019 18:16:01 +0200 Subject: [PATCH 6/7] Update changelog --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 423c31cb435..dede88c6a3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # rollup changelog +## 1.16.6 +*2019-07-04* + +### Bug Fixes +* Do not pass undefined to resolveDynamicImport for unresolvable template literals (#2984) + +### Pull Requests +* [#2984](https://github.com/rollup/rollup/pull/2984): Always forward AST nodes for unresolvable dynamic imports (@lukastaegert) + ## 1.16.5 *2019-07-04* From 198a7b610d229516095ea1bbec7e380e3b76345d Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Thu, 4 Jul 2019 18:16:08 +0200 Subject: [PATCH 7/7] 1.16.6 --- 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 c9742d52f6d..d621394a918 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "rollup", - "version": "1.16.5", + "version": "1.16.6", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 8680c5d16ef..2d753dc9926 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rollup", - "version": "1.16.5", + "version": "1.16.6", "description": "Next-generation ES module bundler", "main": "dist/rollup.js", "module": "dist/rollup.es.js",