From 38e2fca9f337a9300f9890692fbef13c44a9f59d Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 20 Aug 2017 10:47:47 -0400 Subject: [PATCH] update configs when watcher is restarted, and print deprecation warnings in watch mode --- bin/src/run/watch.js | 39 +++++++++++++++++++++++---------------- src/watch/index.js | 10 +++++++++- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/bin/src/run/watch.js b/bin/src/run/watch.js index c29b4c37008..cede6add640 100644 --- a/bin/src/run/watch.js +++ b/bin/src/run/watch.js @@ -13,22 +13,6 @@ export default function watch(configFile, configs, command, silent) { const warnings = batchWarnings(); - configs = configs.map(options => { - const merged = mergeOptions(options, command); - const onwarn = merged.inputOptions.onwarn; - if ( onwarn ) { - merged.inputOptions.onwarn = warning => { - onwarn( warning, warnings.add ); - }; - } else { - merged.inputOptions.onwarn = warnings.add; - } - - return Object.assign({}, merged.inputOptions, { - output: merged.outputOptions - }); - }); - let watcher; let configWatcher; let closed = false; @@ -36,6 +20,29 @@ export default function watch(configFile, configs, command, silent) { function start(configs) { stderr(`\x1B[2J\x1B[0f${chalk.underline( `rollup v${rollup.VERSION}` )}`); // clear, move to top-left + configs = configs.map(options => { + const merged = mergeOptions(options, command); + const onwarn = merged.inputOptions.onwarn; + if ( onwarn ) { + merged.inputOptions.onwarn = warning => { + onwarn( warning, warnings.add ); + }; + } else { + merged.inputOptions.onwarn = warnings.add; + } + + const result = Object.assign({}, merged.inputOptions, { + output: merged.outputOptions + }); + + if (merged.deprecations.length) { + if (!result.watch) result.watch = {}; + result.watch._deprecations = merged.deprecations; + } + + return result; + }); + watcher = rollup.watch(configs); watcher.on('event', event => { diff --git a/src/watch/index.js b/src/watch/index.js index 9475e95d01f..c2bac1c58e7 100644 --- a/src/watch/index.js +++ b/src/watch/index.js @@ -90,7 +90,7 @@ class Task { treeshake: config.treeshake, plugins: config.plugins, external: config.external, - onwarn: config.onwarn, + onwarn: config.onwarn || (warning => console.warn(warning.message)), // eslint-disable-line no-console acorn: config.acorn, context: config.context, moduleContext: config.moduleContext @@ -142,6 +142,7 @@ class Task { this.chokidarOptionsHash = JSON.stringify(chokidarOptions); this.filter = createFilter(watchOptions.include, watchOptions.exclude); + this.deprecations = watchOptions._deprecations; } close() { @@ -174,6 +175,13 @@ class Task { output: this.outputFiles }); + if (this.deprecations) { + this.inputOptions.onwarn({ + code: 'DEPRECATED_OPTIONS', + deprecations: this.deprecations + }); + } + return rollup(options) .then(bundle => { if (this.closed) return;