Skip to content

Commit 15fe40f

Browse files
ehmickysindresorhus
authored andcommitted
Give execPath a higher priority than local binaries (#8)
1 parent 4b54659 commit 15fe40f

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const npmRunPath = options => {
2020
}
2121

2222
// Ensure the running `node` binary is used
23-
result.push(path.dirname(process.execPath));
23+
result.unshift(path.dirname(process.execPath));
2424

2525
return result.concat(options.path).join(path.delimiter);
2626
};

test.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,19 @@ import npmRunPath from '.';
44

55
test('main', t => {
66
t.is(
7-
npmRunPath({path: ''}).split(path.delimiter)[0],
7+
npmRunPath({path: ''}).split(path.delimiter)[1],
88
path.join(__dirname, 'node_modules/.bin')
99
);
1010

1111
t.is(
12-
npmRunPath.env({env: {PATH: 'foo'}}).PATH.split(path.delimiter)[0],
12+
npmRunPath.env({env: {PATH: 'foo'}}).PATH.split(path.delimiter)[1],
1313
path.join(__dirname, 'node_modules/.bin')
1414
);
1515
});
16+
17+
test('push `execPath` to the front of the PATH', t => {
18+
t.is(
19+
npmRunPath({path: ''}).split(path.delimiter)[0],
20+
path.dirname(process.execPath)
21+
);
22+
});

0 commit comments

Comments
 (0)