Skip to content

Commit

Permalink
Run transform hooks again in watch mode on files that errored (#3388)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Feb 14, 2020
1 parent f3d3cd8 commit 305363a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/watch/index.ts
Expand Up @@ -229,6 +229,9 @@ export class Task {
this.watchFile(id);
}
}
if (error.id) {
this.cache.modules = this.cache.modules.filter(module => module.id !== error.id);
}
throw error;
});
}
Expand Down
52 changes: 52 additions & 0 deletions test/watch/index.js
Expand Up @@ -881,6 +881,58 @@ describe('rollup.watch', () => {
});
});

it('runs transforms again on previously erroring files that were changed back', () => {
const brokenFiles = new Set();
const INITIAL_CONTENT = 'export default 42;';
sander.writeFileSync('test/_tmp/input/main.js', INITIAL_CONTENT);
const watcher = rollup.watch({
input: 'test/_tmp/input/main.js',
plugins: {
transform(code, id) {
if (code.includes('broken')) {
brokenFiles.add(id);
throw new Error('Broken in transform');
} else {
brokenFiles.delete(id);
}
},
generateBundle() {
if (brokenFiles.size > 0) {
throw new Error('Broken in generate');
}
}
},
output: {
file: 'test/_tmp/output/bundle.js',
format: 'cjs'
},
watch: { chokidar }
});
return sequence(watcher, [
'START',
'BUNDLE_START',
'BUNDLE_END',
'END',
() => {
assert.strictEqual(run('../_tmp/output/bundle.js'), 42);
sander.writeFileSync('test/_tmp/input/main.js', 'export default "broken";');
},
'START',
'BUNDLE_START',
'ERROR',
() => {
sander.writeFileSync('test/_tmp/input/main.js', INITIAL_CONTENT);
},
'START',
'BUNDLE_START',
'BUNDLE_END',
'END',
() => {
assert.strictEqual(run('../_tmp/output/bundle.js'), 42);
}
]);
});

describe('addWatchFile', () => {
it('supports adding additional watch files in plugin hooks', () => {
const watchChangeIds = [];
Expand Down

0 comments on commit 305363a

Please sign in to comment.