Skip to content

Commit

Permalink
update configs when watcher is restarted, and print deprecation warni…
Browse files Browse the repository at this point in the history
…ngs in watch mode
  • Loading branch information
Rich-Harris committed Aug 20, 2017
1 parent 941b3a4 commit 38e2fca
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
39 changes: 23 additions & 16 deletions bin/src/run/watch.js
Expand Up @@ -13,29 +13,36 @@ 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;

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 => {
Expand Down
10 changes: 9 additions & 1 deletion src/watch/index.js
Expand Up @@ -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
Expand Down Expand Up @@ -142,6 +142,7 @@ class Task {
this.chokidarOptionsHash = JSON.stringify(chokidarOptions);

this.filter = createFilter(watchOptions.include, watchOptions.exclude);
this.deprecations = watchOptions._deprecations;
}

close() {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 38e2fca

Please sign in to comment.