Skip to content

Commit 14ebe02

Browse files
Merge pull request #17 from rosen-vladimirov/vladimirov/fix-getting-path-on-win
fix: get path on Windows from executable name
2 parents 1037fc0 + 7e039ae commit 14ebe02

File tree

9 files changed

+27
-7
lines changed

9 files changed

+27
-7
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@ jspm_packages
3838

3939
xunit.xml
4040
*.tgz
41-
!integration-tests/local-module/local-module-1.0.0.tgz
41+
!integration-tests/local-module/local-module-1.0.0.tgz
42+
!integration-tests/local-module-2/local-module-2-1.0.0.tgz

integration-tests/linux.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ describe("Integration tests", () => {
77
});
88

99
it("finds correct path to executable when package name and executable name differ", () => {
10-
const pathToPackage = require("../").getPath("local-module", "lm");
11-
assert.deepEqual(pathToPackage.replace(/\/node\/18\..+?\..+?\//, "/node/NODE_VERSION/"), "/opt/hostedtoolcache/node/NODE_VERSION/x64/lib/node_modules/local-module")
10+
const pathToPackage = require("../").getPath("local-module-2", "lm2");
11+
assert.deepEqual(pathToPackage.replace(/\/node\/18\..+?\..+?\//, "/node/NODE_VERSION/"), "/opt/hostedtoolcache/node/NODE_VERSION/x64/lib/node_modules/local-module-2")
1212
});
1313

1414
it("finds correct path to executable when only package name is used", () => {

integration-tests/linux.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/bash
22

33
npm i -g ./local-module/local-module-1.0.0.tgz
4+
npm i -g ./local-module-2/local-module-2-1.0.0.tgz
45
../node_modules/mocha/bin/_mocha --recursive --reporter spec-xunit-file --timeout 1500 linux.js
407 Bytes
Binary file not shown.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env node
2+
3+
console.log("Successfully run local-module-2");
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "local-module-2",
3+
"version": "1.0.0",
4+
"description": "Local package used for testing, with executable name that is not the same as package name",
5+
"main": "index.js",
6+
"bin": {
7+
"lm2": "./local.js"
8+
},
9+
"scripts": {
10+
"test": "echo \"Error: no test specified\" && exit 1"
11+
},
12+
"author": "Rosen Vladimirov",
13+
"license": "Apache-2.0"
14+
}
15+

integration-tests/windows.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
npm i -g local-module\local-module-1.0.0.tgz && node ..\node_modules\mocha\bin\_mocha --recursive --reporter spec-xunit-file --timeout 5000 windows.js
1+
npm i -g local-module\local-module-1.0.0.tgz && npm i -g local-module-2\local-module-2-1.0.0.tgz && node ..\node_modules\mocha\bin\_mocha --recursive --reporter spec-xunit-file --timeout 5000 windows.js

integration-tests/windows.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ describe("Integration tests", () => {
77
});
88

99
it("finds correct path to executable when package name and executable name differ", () => {
10-
const pathToPackage = require("../").getPath("local-module", "lm");
11-
assert.deepEqual(pathToPackage.replace(/\/node\/18\..+?\..+?\//, "/node/NODE_VERSION/"), "C:\\npm\\prefix\\node_modules\\local-module");
10+
const pathToPackage = require("../").getPath("local-module-2", "lm2");
11+
assert.deepEqual(pathToPackage.replace(/\/node\/18\..+?\..+?\//, "/node/NODE_VERSION/"), "C:\\npm\\prefix\\node_modules\\local-module-2");
1212
});
1313

1414
it("finds correct path to executable when only package name is used", () => {

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ const getVerifiedPath = (suggestedPath, packageName) => {
125125

126126
const getPathFromExecutableNameOnWindows = (packageName, executableName) => {
127127
try {
128-
const whereResult = (spawnSyncWrapper("where", executableName) || "").split("\n");
128+
const whereResult = (spawnSyncWrapper("where", [executableName]) || "").split("\n");
129129

130130
for (const line of whereResult) {
131131
const pathToExecutable = line && line.trim();

0 commit comments

Comments
 (0)