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

"snowpack dev" requires two Ctrl-C to exit. #368

Closed
FredKSchott opened this issue May 28, 2020 · 9 comments
Closed

"snowpack dev" requires two Ctrl-C to exit. #368

FredKSchott opened this issue May 28, 2020 · 9 comments
Labels
bug Something isn't working contributors welcome! contributors welcome! good first issue Good for newcomers

Comments

@FredKSchott
Copy link
Owner

Original Discussion: https://www.pika.dev/npm/snowpack/discuss/244
/cc @quasor, @acoyfellow, @FredKSchott

It should only require one.

@FredKSchott FredKSchott added bug Something isn't working contributors welcome! contributors welcome! good first issue Good for newcomers labels May 28, 2020
@mojiwa
Copy link
Contributor

mojiwa commented May 28, 2020

So, I don't know if this is a Windows specific issue (I'm using Powershell on Windows 10), but I did find a sort of workaround here:
https://stackoverflow.com/questions/10021373/what-is-the-windows-equivalent-of-process-onsigint-in-node-js

Effectively creating a custom handler for the user input for Ctrl+C on Windows and then having that method process the "SIGINT" event so it gets picked up properly by the handler.

// Inside \\node_modules\snowpack\dist-src\commands\dev.js
// but edited directly in \\node_modules\snowpack\dist-node\index.js

if (process.platform === "win32") {
 var rl = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
 });
 rl.on("SIGINT", function() {
  process.emit("SIGINT");
 });
}
process.on("SIGINT", function() {
 hmrEngine.disconnectAllClients();
 process.exit(0);
});

It works, but causes no confirmation message to appear - need to look into that.
Interestingly though, CTRL+Break works fine on Windows without the above "fix".

@quasor
Copy link

quasor commented May 29, 2020

FWIW I’m on latest MacOS when reporting.

@mojiwa
Copy link
Contributor

mojiwa commented May 29, 2020

FWIW I’m on latest MacOS when reporting.

I suppose it's possible to remove the windows check and manually handle the user input regardless of OS... I haven't tried on my Mac yet though.

@stramel
Copy link
Contributor

stramel commented May 29, 2020

I noticed this on my windows machine as well using Git Bash

@mojiwa
Copy link
Contributor

mojiwa commented May 29, 2020

FWIW I’m on latest MacOS when reporting.

Confirms... the "fix" also works for Mac by removing the if statement:

// Inside \\node_modules\snowpack\dist-src\commands\dev.js
// but edited directly in \\node_modules\snowpack\dist-node\index.js
var rl = require('readline').createInterface({
 input: process.stdin,
 output: process.stdout
});
rl.on("SIGINT", function() {
 process.emit("SIGINT");
});
  
process.on("SIGINT", function() {
 hmrEngine.disconnectAllClients();
 process.exit(0);
});

I read somewhere that it's possible one of the other watchers is swallowing the initial ctrl+c command from the user, but I've not looked into that yet.

@mojiwa
Copy link
Contributor

mojiwa commented May 29, 2020

I noticed this on my windows machine as well using Git Bash

I noticed the same thing as well. Implementing the above does work on Git Bash as well.

@FredKSchott
Copy link
Owner Author

Sounds like that's the fix then for all environments. Would love a PR if you can add one, @mojiwa!

@mojiwa
Copy link
Contributor

mojiwa commented May 29, 2020

Sounds like that's the fix then for all environments. Would love a PR if you can add one, @mojiwa!

Absolutely. I'll raise one this evening.

@FredKSchott
Copy link
Owner Author

Resolved via #380

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working contributors welcome! contributors welcome! good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants