Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling NPM without the user's shell profile. #2123

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ private static File findMainScript() {
List<String> cmdLine = System.getProperty("os.name").toLowerCase().contains("win")
// npm is a batch script, so on windows we need to use cmd.exe in order to execute it
? Arrays.asList("cmd.exe", "/c", String.format("\"%s\" root -g", npm.getAbsolutePath()))
: Arrays.asList(npm.getAbsolutePath(), "root", "-g");
//ProcessBuilder doesn't execute a shell, some npm functionality requires the user's shell profile
: Arrays.asList("/bin/sh", "--login", "-c", npm.getAbsolutePath() + " root -g");
Copy link
Contributor

@mykola-mokhnach mykola-mokhnach Feb 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would probably fail if the path to npm contains spaces.
We must properly escape it

ProcessBuilder pb = new ProcessBuilder(cmdLine);
String nodeModulesRoot;
try {
Expand Down
Loading