Skip to content

Commit

Permalink
feat: add process.spawn arg watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Feb 13, 2020
1 parent 69a9a20 commit 7699b6f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bin/cli.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env node

if (process.argv.includes("--watchspawn")) {
require("../lib/spawnHook").hook();
}

// Execa hook.
if (process.argv.includes("--execasync")) {
require("../lib/execaHook").hook();
Expand Down
25 changes: 25 additions & 0 deletions lib/spawnHook.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const childProcess = require("child_process");
const oldSpawn = childProcess.spawn;

const watchSpawn = (...args) => {
console.log("spawn called");
console.log(...args);

return oldSpawn.apply(this, ...args);
};
const hook = () => {
if (childProcess.spawn === oldSpawn) {
childProcess.spawn = watchSpawn;
}
};

const unhook = () => {
if (childProcess.spawn === watchSpawn) {
childProcess.spawn = oldSpawn;
}
};

module.exports = {
hook,
unhook
};

0 comments on commit 7699b6f

Please sign in to comment.