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

Correct .npmrc for newer versions of NPM #787

Open
wants to merge 12 commits into
base: npm-8.19
Choose a base branch
from
Prev Previous commit
Next Next commit
Update NpmBuildInfoExtractor.java
Added update to Auth prop for newer NPM versions
  • Loading branch information
Spaction authored Mar 21, 2024
commit c5f62e1f4d0a004ff2dc1c74fa2c73b477866f0f
Original file line number Diff line number Diff line change
@@ -189,9 +189,22 @@ private void createTempNpmrc(Path workingDir, List<String> commandArgs) throws I
npmrcBuilder.append("proxy = ").append(this.npmProxy).append("\n");
}

//Update Auth property for newer npm versions
if(this.npmDrive.compareVersionTo(workingDir, "8.19") >= 0)
String authProp = npmAuth.getProperty("_auth");

String newAuthKey = artifactoryManage.getUrl();
if (!StringUtils.endsWith(newAuthKey, "/")) {
newAuthKey += "/";
}
newAuthKey += "api/npm/:_auth";
newAuthKey = newAuthKey.replaceAll("^http(s)?:","") + ":_auth";
npmAuth.setProperty(newAuthKey, authProp);
npmAuth.remove("_auth");
}

// Save npm auth
npmAuth.forEach((key, value) -> npmrcBuilder.append(key).append("=").append(value).append("\n"));

// Write npmrc file
try (FileWriter fileWriter = new FileWriter(npmrcPath.toFile());
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter)) {