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

Allow --experimental-local to cleanly exit on x/CTRL-C #2400

Merged
merged 4 commits into from
Dec 15, 2022
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/tasty-toes-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

Cleanly exit `wrangler dev --experimental-local` when pressing `x`/`q`/`CTRL-C`
17 changes: 17 additions & 0 deletions packages/wrangler/src/dev.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -512,11 +512,28 @@ export async function startDev(args: StartDevOptions) {
);
}
const devReactElement = render(await getDevReactElement(config));

// In the bootstrapper script `bin/wrangler.js`, we open an IPC channel, so
// IPC messages from this process are propagated through the bootstrapper.
// Normally, Node's SIGINT handler would close this for us, but interactive
// mode enables raw mode on stdin which disables the built-in handler. The
// following line disconnects from the IPC channel when we press `x` or
// CTRL-C in interactive mode, ensuring no open handles, and allowing for a
// clean exit. Note, if we called `stop()` using the dev API, we don't want
// to disconnect here, as the user may still need IPC. We also don't want
// to disconnect if this file was imported in Jest (not the case with E2E
// tests), as that would stop communication with the test runner.
let apiStopped = false;
void devReactElement.waitUntilExit().then(() => {
if (!apiStopped && typeof jest === "undefined") process.disconnect?.();
});

rerender = devReactElement.rerender;
return {
devReactElement,
watcher,
stop: async () => {
apiStopped = true;
devReactElement.unmount();
await watcher?.close();
},
Expand Down