Skip to content

Commit 9911ea7

Browse files
committed
Optimize execution of bypass
1 parent 95731cd commit 9911ea7

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

bypass.js

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env node
22

3-
const fs = require('fs')
43
const path = require('path')
54
const spawn = require('child_process').spawn
65

@@ -10,28 +9,21 @@ var command = process.argv[1]
109
var argv = process.argv.slice(2)
1110

1211
var index = PATH.indexOf(path.dirname(command))
13-
if(index >= 0) PATH = PATH.slice(index+1)
12+
if(index >= 0)
13+
{
14+
PATH = PATH.slice(index+1)
15+
process.env.PATH = PATH
16+
}
1417

15-
command = path.basename(command)
1618

17-
function onExit(code, signal)
19+
spawn(path.basename(command), argv, {stdio: 'inherit'})
20+
.on('exit', function(code, signal)
1821
{
1922
process.exit(code || signal)
20-
}
21-
22-
for(var index in PATH)
23+
})
24+
.on('error', function(error)
2325
{
24-
var fullCommand = path.join(PATH[index], command)
25-
26-
try
27-
{
28-
fs.accessSync(fullCommand, fs.X_OK)
29-
30-
return spawn(fullCommand, argv, {stdio: 'inherit'}).on('exit', onExit)
31-
}
32-
catch(e)
33-
{}
34-
}
35-
26+
if(error.code === 'ENOENT') return process.exit(127)
3627

37-
process.exit(127)
28+
throw error
29+
})

0 commit comments

Comments
 (0)