Skip to content

Commit cb160c6

Browse files
committed
fix: normalize npm prefix paths
Signed-off-by: Ruben Romero Montes <rromerom@redhat.com>
1 parent 3e365da commit cb160c6

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

src/main/java/com/redhat/exhort/providers/JavaScriptNpmProvider.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
*/
1616
package com.redhat.exhort.providers;
1717

18+
import java.nio.file.Path;
19+
1820
import com.redhat.exhort.tools.Ecosystem;
1921
import com.redhat.exhort.tools.Operations;
20-
import java.nio.file.Path;
2122

2223
/**
2324
* Concrete implementation of the {@link JavaScriptProvider} used for converting dependency trees
@@ -37,10 +38,22 @@ protected String lockFileName() {
3738
return LOCK_FILE;
3839
}
3940

41+
/**
42+
* Helper method to normalize paths for npm on Windows.
43+
* npm's --prefix option has issues with Windows backslash paths.
44+
*/
45+
private String normalizePath(Path path) {
46+
if (Operations.isWindows()) {
47+
// Convert Windows backslashes to forward slashes for npm
48+
return path.toString().replace('\\', '/');
49+
}
50+
return path.toString();
51+
}
52+
4053
@Override
4154
protected String[] updateLockFileCmd(Path manifestDir) {
4255
return new String[] {
43-
packageManager(), "i", "--package-lock-only", "--prefix", manifestDir.toString()
56+
packageManager(), "i", "--package-lock-only", "--prefix", normalizePath(manifestDir)
4457
};
4558
}
4659

@@ -55,7 +68,7 @@ protected String[] listDepsCmd(boolean includeTransitive, Path manifestDir) {
5568
"--package-lock-only",
5669
"--json",
5770
"--prefix",
58-
manifestDir.toString()
71+
normalizePath(manifestDir)
5972
};
6073
}
6174
return new String[] {

0 commit comments

Comments
 (0)