Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

exit watch process on EOF / Ctrl-D#358

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
RyanZim merged 4 commits intopostcss:masterfromtverlaan:tv_exit_on_stdin_eof
Nov 17, 2020

Conversation

tverlaan
Copy link
Contributor

It's quite common to be able to exit from a running process with Ctrl-D. This also makes it possible to integrate postcss-cli in external applications as is also mentioned in this webpack PR:webpack/webpack#1311.

I could also make it an additional flag if that is preferred.

@RyanZim
Copy link
Collaborator

What's the use-case for this?

@tverlaan
Copy link
ContributorAuthor

I embed the postcss-cli watcher in my own application (more info can be found in the webpack-pr I linked). When my application exits it closes stdin for the postcss-cli watcher, however postcss-cli keeps running in the background. On exiting/starting my application multiple times I create multiple orphaned opencss-cli watcher processes. I have to manually kill them.

@coveralls

This comment has been minimized.

@coveralls

This comment has been minimized.

@RyanZim
Copy link
Collaborator

Why can't your application just send SIGINT/Ctrl+C to the postcss-cli process when it closes?

@tverlaan
Copy link
ContributorAuthor

I think it potentially could, but then it would only be for postcss-cli. An external application that starts postcss-cli usually controls stdin & stdout, therefor it makes most sense to use mechanisms that are already available. Non-daemon applications usually bind to stdin&stdout and therefor it would make sense if it responds to this. The external application is not sending signals, it's just closing and opening stdin/stdout for the child process.
Webpack,Brunch &create-react-app all implement it like this and I'd rather stick to the same solution here.

@RyanZim
Copy link
Collaborator

RyanZim commentedNov 11, 2020
edited
Loading

OK, fair enough. I still think it's a bit of an odd pattern, but if the ecosystem has it, I guess we can do it. This will need an automated test written, though, before I can merge this.

@tverlaan
Copy link
ContributorAuthor

It's quite common for UNIX cli tools to behave like this, shells for example:https://unix.stackexchange.com/questions/110240/why-does-ctrl-d-eof-exit-the-shell

I hope the test is ok like this :-)

@RyanZim
Copy link
Collaborator

It's quite common for UNIX cli tools to behave like this, shells for example:https://unix.stackexchange.com/questions/110240/why-does-ctrl-d-eof-exit-the-shell

This behavior is indeed standard for interactive programs, like shells or REPLs, that are controlled by user input on stdin, I find it odd for a program that does not read stdin for anything else in watch mode, that's all.

@RyanZim
Copy link
Collaborator

Looks great, only one problem; I tested applying the commit with the test to master, and the new test passes even without your original patch, so something with the test isn't working correctly. 🙁

@tverlaan
Copy link
ContributorAuthor

Nice catch! I changed the implementation a bit, the test works properly now. I think thecatch(err) was actually preventing a clean exit which was actually pointing to a flawed implementation from my side. Should be fixed now.

@RyanZim
Copy link
Collaborator

I messed around a bit, the test was sort of failing for the wrong reason earlier; here's a patch to make it better:

diff --git a/test/watch.js b/test/watch.jsindex a6cf2e4..4a51a11 100644--- a/test/watch.js+++ b/test/watch.js@@ -8,6 +8,7 @@ const chokidar = require('chokidar')  const ENV = require('./helpers/env.js') const read = require('./helpers/read.js')+const tmp = require('./helpers/tmp.js')  // XXX: All the tests in this file are skipped on the CI; too flacky there const testCb = process.env.CI ? test.cb.skip : test.cb@@ -287,13 +288,17 @@ testCb("--watch doesn't exit on CssSyntaxError", (t) => { })  testCb('--watch does exit on closing stdin (Ctrl-D/EOF)', (t) => {-  t.plan(0)+  t.plan(1)    const cp = spawn(-    `node ${path.resolve('bin/postcss')} -o output.css -w --no-map`,+    `./bin/postcss test/fixtures/a.css -o ${tmp()} -w --no-map`,     { shell: true }   )+   cp.on('error', t.end)-  cp.on('exit', t.end)+  cp.on('exit', (code) => {+    t.is(code, 0)+    t.end()+  })   cp.stdin.end() })

Copy that text into a file, then rungit apply <file> from the working directory on your branch, commit & push, and this should be good to merge.

@tverlaan
Copy link
ContributorAuthor

Thanks a lot! I'm not familiar enough with the testing framework and checking if thecode = 0 explicitly looks a lot better than just passing it along.
Also,git apply - allows for reading from stdin, no need for the tempfile :-)

@RyanZimRyanZim merged commitb19fbdc intopostcss:masterNov 17, 2020
@tverlaantverlaan deleted the tv_exit_on_stdin_eof branchNovember 17, 2020 09:19
@RyanZim
Copy link
Collaborator

Published v8.3.0 🎉

tverlaan reacted with laugh emoji

@bug-tape
Copy link

It would have been nice to have this new behaviour only with a new command line argument. This change effectively stopped my docker containers. Luckily this was not a big problem, only surprising. Docker has a simple solution for that:stdin_open: true.

joshuadavidthomas reacted with thumbs up emoji

@RyanZim
Copy link
Collaborator

@bug-tape Ah, sorry about that. I didn't think it would affect any existing use-cases, but apparently it did yours. I'll try to be more cautious in the future.

bug-tape reacted with heart emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@RyanZimRyanZimRyanZim approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@tverlaan@RyanZim@coveralls@bug-tape

[8]ページ先頭

©2009-2025 Movatter.jp