Skip to content

Commit

Permalink
Declare processConfigsErr before use (#2858)
Browse files Browse the repository at this point in the history
* Declare processConfigsErr before use

* Add test to check watch.clearScreen:false no longer causes an error

* Use a more powerful killing mechanism

* Use a timeout to kill on windows
  • Loading branch information
humphd authored and lukastaegert committed May 17, 2019
1 parent 6a79bc1 commit 7aaec61
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 5 deletions.
3 changes: 1 addition & 2 deletions bin/src/run/watch.ts
Expand Up @@ -42,6 +42,7 @@ export default function watch(

const warnings = batchWarnings();

let processConfigsErr: any;
const initialConfigs = processConfigs(configs);

const clearScreen = initialConfigs.every(config => config.watch.clearScreen !== false);
Expand All @@ -52,8 +53,6 @@ export default function watch(
let watcher: Watcher;
let configWatcher: Watcher;

let processConfigsErr: any;

function processConfigs(configs: RollupWatchOptions[]): RollupWatchOptions[] {
return configs.map(options => {
const merged = mergeOptions({
Expand Down
Expand Up @@ -4,7 +4,6 @@ module.exports = {
input: ['main-a'],
manualChunks(id) {
if (id[id.length - 5] === '-') {
console.log(id, id[id.length - 4]);
return `chunk-${id[id.length - 4]}`;
}
}
Expand Down
10 changes: 8 additions & 2 deletions test/cli/index.js
Expand Up @@ -25,8 +25,8 @@ runTestSuiteWithSamples(

const command = 'node ' + path.resolve(__dirname, '../../bin') + path.sep + config.command;

exec(command, {}, (err, code, stderr) => {
if (err) {
const childProcess = exec(command, { timeout: 2000 }, (err, code, stderr) => {
if (err && !err.killed) {
if (config.error) {
const shouldContinue = config.error(err);
if (!shouldContinue) return done();
Expand Down Expand Up @@ -111,6 +111,12 @@ runTestSuiteWithSamples(
}
}
});

childProcess.stderr.on('data', data => {
if (config.abortOnStderr && config.abortOnStderr(data)) {
childProcess.kill('SIGINT');
}
});
}
);
},
Expand Down
9 changes: 9 additions & 0 deletions test/cli/samples/watch/_config.js
@@ -0,0 +1,9 @@
module.exports = {
description: 'does not fail in watch-mode with clearScreen: false',
command: 'rollup -cw',
abortOnStderr(data) {
if (data.includes('created')) {
return true;
}
}
};
Empty file.
1 change: 1 addition & 0 deletions test/cli/samples/watch/foo.js
@@ -0,0 +1 @@
export var foo = 42;
3 changes: 3 additions & 0 deletions test/cli/samples/watch/main.js
@@ -0,0 +1,3 @@
import { foo } from './foo.js';

assert.equal( foo, 42 );
10 changes: 10 additions & 0 deletions test/cli/samples/watch/rollup.config.js
@@ -0,0 +1,10 @@
export default {
input: 'main.js',
output: {
file: '_actual.js',
format: 'esm'
},
watch: {
clearScreen: false
}
};

0 comments on commit 7aaec61

Please sign in to comment.