Skip to content

Commit 7699b6f

Browse files
committed
feat: add process.spawn arg watcher
1 parent 69a9a20 commit 7699b6f

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

bin/cli.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#!/usr/bin/env node
22

3+
if (process.argv.includes("--watchspawn")) {
4+
require("../lib/spawnHook").hook();
5+
}
6+
37
// Execa hook.
48
if (process.argv.includes("--execasync")) {
59
require("../lib/execaHook").hook();

lib/spawnHook.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const childProcess = require("child_process");
2+
const oldSpawn = childProcess.spawn;
3+
4+
const watchSpawn = (...args) => {
5+
console.log("spawn called");
6+
console.log(...args);
7+
8+
return oldSpawn.apply(this, ...args);
9+
};
10+
const hook = () => {
11+
if (childProcess.spawn === oldSpawn) {
12+
childProcess.spawn = watchSpawn;
13+
}
14+
};
15+
16+
const unhook = () => {
17+
if (childProcess.spawn === watchSpawn) {
18+
childProcess.spawn = oldSpawn;
19+
}
20+
};
21+
22+
module.exports = {
23+
hook,
24+
unhook
25+
};

0 commit comments

Comments
 (0)