Deno: Deno.exit terminates entire process when using run --watch

Created on 20 Sep 2020  路  6Comments  路  Source: denoland/deno

I'm running my script with deno run --watch --unstable myscript.ts. When it encounters a call to Deno.exit, the script terminates, including the file watcher.

I expected Deno.exit to terminate the script, but keep the file watcher alive. This is how Node's process.exit behaves when used with nodemon.

It seems culprit is the current implementation, which is just a passthrough to std::process::exit. I'm still familiarizing myself with Deno and V8, but is the solution something like tearing down the active runtime without exiting the main process?

bug cli

All 6 comments

Keep the file watcher alive to do what?

I thought Deno would continue to check for file changes, even after my script calls Deno.exit. Instead, I need to re-run deno run --watch --unstable myscript.ts manually. Minimal example of my script/output:

let someErrorCondition = true;

if (someErrorCondition) {
  console.log('Exiting');
  Deno.exit(1);
}

console.log('Finished');
$ deno --version
deno 1.4.1
v8 8.7.75
typescript 4.0.2
$ deno run --unstable --watch main.ts
Check file:///Users/sidd/code/issue/main.ts
Finished
Watcher Process terminated! Restarting on file change...
Watcher File change detected! Restarting!
Check file:///Users/sidd/code/issue/main.ts
Exiting
$

I expected to see the "Process terminated! Restarting on file change..." message after my script logged "Exiting", so I could make some changes to the script, and the script would re-run.

If you exit your programme, you exit your program. I personally would find it surprising that if my programme has exited, that it suddenly restarts.

Like a "watch" in a browser, if the code changes and the page is still open, it reloads. If you close the page, you close the page. Anything else would be surprising in my opinion.

I see, I thought my use case was the most common. This is totally possible to solve in userland, so I can use some other tool to get quick feedback while developing.

I was surprised because tools in other environments continue to watch for files after their corresponding "exit" method is called, like cargo watch in Rust, nodemon in Node, and Guard in Ruby.

I agree that this is pretty unexpected - when the program exits by natural means (no more tasks to do), it also restarts when the file changes. I think that should also apply to Deno.exit(). The program should not be concerned with if it was started in --watch mode or not.

May I work on this issue?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

motss picture motss  路  3Comments

kitsonk picture kitsonk  路  3Comments

zugende picture zugende  路  3Comments

doutchnugget picture doutchnugget  路  3Comments

benjamingr picture benjamingr  路  3Comments