File tree Expand file tree Collapse file tree 4 files changed +22
-0
lines changed Expand file tree Collapse file tree 4 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -54,6 +54,7 @@ Future<void> main(List<String> args) async {
54
54
var graph = StylesheetGraph (
55
55
ImportCache (loadPaths: options.loadPaths, logger: options.logger));
56
56
if (options.watch) {
57
+ ensureWatchWillExit ();
57
58
await watch (options, graph);
58
59
return ;
59
60
}
Original file line number Diff line number Diff line change @@ -94,6 +94,14 @@ String? getEnvironmentVariable(String name) => throw '';
94
94
int get exitCode => throw '' ;
95
95
set exitCode (int value) => throw '' ;
96
96
97
+ /// Attaches a listener to exit when stdin closes.
98
+ ///
99
+ /// The listener is *not* attached when stdin is a TTY because it would
100
+ /// interfere with the Unix background job system. If we read from stdin and
101
+ /// then Ctrl+Z to move the process to the background, it will incorrectly
102
+ /// cause the job to stop. See: https://github.com/brunch/brunch/issues/998.
103
+ void ensureWatchWillExit () => throw '' ;
104
+
97
105
/// Recursively watches the directory at [path] for modifications.
98
106
///
99
107
/// Returns a future that completes with a single-subscription stream once the
Original file line number Diff line number Diff line change @@ -196,6 +196,9 @@ final stderr = Stderr(process.stderr);
196
196
@JS ('process.stdout.isTTY' )
197
197
external bool ? get isTTY;
198
198
199
+ @JS ('process.stdin.isTTY' )
200
+ external bool ? get isStdinTTY;
201
+
199
202
bool get hasTerminal => isTTY == true ;
200
203
201
204
bool get isWindows => process.platform == 'win32' ;
@@ -213,6 +216,12 @@ int get exitCode => process.exitCode;
213
216
214
217
set exitCode (int code) => process.exitCode = code;
215
218
219
+ void ensureWatchWillExit () {
220
+ if (isStdinTTY == true ) {
221
+ process.stdin.on ('end' , allowInterop (() => process.exit (0 )));
222
+ }
223
+ }
224
+
216
225
Future <Stream <WatchEvent >> watchDir (String path, {bool poll = false }) {
217
226
var watcher = chokidar.watch (
218
227
path, ChokidarOptions (disableGlobbing: true , usePolling: poll));
Original file line number Diff line number Diff line change @@ -87,6 +87,10 @@ DateTime modificationTime(String path) {
87
87
88
88
String ? getEnvironmentVariable (String name) => io.Platform .environment[name];
89
89
90
+ void ensureWatchWillExit () {
91
+ if (! io.stdin.hasTerminal) io.stdin.listen (null , onDone: () => io.exit (0 ));
92
+ }
93
+
90
94
Future <Stream <WatchEvent >> watchDir (String path, {bool poll = false }) async {
91
95
var watcher = poll ? PollingDirectoryWatcher (path) : DirectoryWatcher (path);
92
96
You can’t perform that action at this time.
0 commit comments