Skip to content

Commit 52c8542

Browse files
ehmickysindresorhus
authored andcommitted
Local binaries should have higher priority than global binaries (#10)
1 parent 879ba92 commit 52c8542

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const npmRunPath = options => {
2222

2323
// Ensure the running `node` binary is used
2424
const execPathDir = path.resolve(options.cwd, options.execPath, '..');
25-
result.unshift(execPathDir);
25+
result.push(execPathDir);
2626

2727
return result.concat(options.path).join(path.delimiter);
2828
};

test.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,33 @@ import npmRunPath from '.';
44

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

1111
t.is(
12-
npmRunPath.env({env: {PATH: 'foo'}}).PATH.split(path.delimiter)[1],
12+
npmRunPath.env({env: {PATH: 'foo'}}).PATH.split(path.delimiter)[0],
1313
path.join(__dirname, 'node_modules/.bin')
1414
);
1515
});
1616

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-
);
17+
test('push `execPath` later in the PATH', t => {
18+
const pathEnv = npmRunPath({path: ''}).split(path.delimiter);
19+
t.is(pathEnv[pathEnv.length - 2], path.dirname(process.execPath));
2220
});
2321

2422
test('can change `execPath` with the `execPath` option', t => {
25-
t.is(
26-
npmRunPath({path: '', execPath: 'test/test'}).split(path.delimiter)[0],
27-
path.resolve(process.cwd(), 'test')
23+
const pathEnv = npmRunPath({path: '', execPath: 'test/test'}).split(
24+
path.delimiter
2825
);
26+
t.is(pathEnv[pathEnv.length - 2], path.resolve(process.cwd(), 'test'));
2927
});
3028

3129
test('the `execPath` option is relative to the `cwd` option', t => {
32-
t.is(
33-
npmRunPath({path: '', execPath: 'test/test', cwd: '/dir'}).split(path.delimiter)[0],
34-
path.normalize('/dir/test')
35-
);
30+
const pathEnv = npmRunPath({
31+
path: '',
32+
execPath: 'test/test',
33+
cwd: '/dir'
34+
}).split(path.delimiter);
35+
t.is(pathEnv[pathEnv.length - 2], path.normalize('/dir/test'));
3636
});

0 commit comments

Comments
 (0)