• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/// <reference types="node" />
2
3if (process.argv.length < 3) {
4    process.exit(1);
5}
6const directoryName = process.argv[2];
7const fs: { watch(directoryName: string, options: any, callback: () => {}): any } = require("fs");
8// main reason why we need separate process to check if it is safe to watch some path
9// is to guard against crashes that cannot be intercepted with protected blocks and
10// code in tsserver already can handle normal cases, like non-existing folders.
11// This means that here we treat any result (success or exception) from fs.watch as success since it does not tear down the process.
12// The only case that should be considered as failure - when watchGuard process crashes.
13try {
14    const watcher = fs.watch(directoryName, { recursive: true }, () => ({}));
15    watcher.close();
16}
17catch { /*ignore*/ }
18process.exit(0);
19