Skip to content

Commit

Permalink
feat: inject "node_modules/.bin" path
Browse files Browse the repository at this point in the history
Not needed but a nice feature I often need...
  • Loading branch information
laggingreflex committed Dec 5, 2021
1 parent a3c90cf commit 209ed83
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const Path = require('path');
const { spawnSync } = require('child_process');
const parse = require('./command-parser');

Expand Down Expand Up @@ -37,7 +38,20 @@ function run(cmd, env) {
return;
}

const newEnv = Object.assign({}, process.env, env);
let newEnv = Object.assign({}, process.env, env);
setNodeModulesBinPath(newEnv);

return spawnSync(cmd[0], cmd.slice(1), { stdio: 'inherit', shell: true, env: newEnv });
}

function setNodeModulesBinPath(env = process.env) {
for (const PATH in env) {
if (PATH.toLowerCase() === 'path') {
const path = env[PATH];
const split = path.split(';');
split.push(Path.join('node_modules', '.bin'));
env[PATH] = split.join(';');
break;
}
}
}

0 comments on commit 209ed83

Please sign in to comment.