Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run transform hooks again in watch mode on files that errored #3388

Merged
merged 1 commit into from Feb 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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