Skip to content
This repository was archived by the owner on Mar 15, 2025. It is now read-only.

Commit 2af81f8

Browse files
authored
Fixes for dev workflow (#221)
* Properly restart server on code changes on Linux (based on sveltejs/template#213) * Add a short delay before reloading to wait for any dependencies to finish saving
1 parent 5c83285 commit 2af81f8

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

packages/viewer/rollup.config.js

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,17 @@ const production = !process.env.ROLLUP_WATCH;
1111
function serve() {
1212
let server;
1313

14-
async function toExit() {
15-
if (server) server.kill(0);
14+
function killServer() {
15+
if (server) {
16+
/* On linux, server.kill() only kills the parent shell (sh) process but not the child sirv instance
17+
See https://nodejs.org/docs/latest-v14.x/api/child_process.html#child_process_subprocess_kill_signal
18+
Passing the negation of PID of a detached process to 'kill' stops all its children */
19+
try {
20+
spawn("kill", ["--", `-${server.pid}`], { shell: true });
21+
} catch (_) {
22+
server.kill();
23+
}
24+
}
1625
}
1726

1827
return {
@@ -23,22 +32,24 @@ function serve() {
2332
["run", "start", "--", `../../${process.argv.slice(4)}`],
2433
{
2534
stdio: ["ignore", "inherit", "inherit"],
26-
shell: true,
35+
detached: true,
2736
}
2837
);
2938
}
30-
31-
// if server has already started, kill it and wait a short while
39+
// if server has already started, kill it and restart
3240
if (server) {
3341
server.on("exit", startServer);
34-
server.kill();
42+
killServer();
3543
} else {
3644
startServer();
3745
}
3846

39-
process.on("SIGTERM", toExit);
40-
process.on("exit", toExit);
47+
process.on("SIGTERM", killServer);
48+
process.on("exit", killServer);
4149
},
50+
/* Rollup restarts on detecting changes to this config file.
51+
This hook makes sure the previously started instance is stopped before starting a new one */
52+
closeWatcher: killServer,
4253
};
4354
}
4455

@@ -91,5 +102,9 @@ export default [
91102
output: [
92103
{ file: "dist/cli.js", format: "cjs", interop: false, sourcemap: false },
93104
],
105+
watch: {
106+
clearScreen: false,
107+
buildDelay: 100,
108+
},
94109
},
95110
];

0 commit comments

Comments
 (0)