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

fix: prevent crash on errors in watch mode #10628

Merged
merged 1 commit into from
Aug 26, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/seven-poems-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/package': patch
---

fix: prevent crash on errors in watch mode
25 changes: 20 additions & 5 deletions packages/package/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ export async function watch(options) {
const events = pending.slice();
pending.length = 0;

let errored = false;

for (const { file, type } of events) {
if (type === 'unlink') {
for (const candidate of [
Expand All @@ -116,14 +118,27 @@ export async function watch(options) {

if (type === 'add' || type === 'change') {
console.log(`Processing ${file.name}`);
await process_file(input, output, file, options.config.preprocess, alias, analyse_code);
validate();
try {
await process_file(input, output, file, options.config.preprocess, alias, analyse_code);
} catch (e) {
errored = true;
console.error(e);
}
}
}

if (!errored && options.types) {
try {
await emit_dts(input, output, options.cwd, alias, files);
console.log('Updated .d.ts files');
} catch (e) {
errored = true;
console.error(e);
}
}

if (options.types) {
await emit_dts(input, output, options.cwd, alias, files);
console.log('Updated .d.ts files');
if (!errored) {
validate();
}

console.log(message);
Expand Down
10 changes: 10 additions & 0 deletions packages/package/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,22 @@ if (!process.env.CI) {
await settled();
compare('Test.svelte');
compare('Test.svelte.d.ts');

// doesn't crash on an error
write('src/lib/post-error.svelte', '<button on:={foo}>click me</button>');
await settled();

// recovers on subsequent change
write('src/lib/post-error.svelte', '<button on:click={foo}>click me</button>');
await settled();
compare('post-error.svelte');
} finally {
watcher.close();

remove('src/lib/Test.svelte');
remove('src/lib/a.js');
remove('src/lib/b.ts');
remove('src/lib/post-error.svelte');
}
});
}
Expand Down
1 change: 1 addition & 0 deletions packages/package/test/watch/expected/post-error.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<button on:click={foo}>click me</button>