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
Corrections
Info corrections
  • Loading branch information
Spaction committed Mar 21, 2024
commit 5d0010cfa3756659c363ac213daa2829431d0a80
Original file line number Diff line number Diff line change
@@ -97,8 +97,8 @@ public JsonNode list(File workingDirectory, List<String> extraArgs) throws IOExc
}
}

public int compareVersionTo(File workingDirectory, String compareVersion){
String currentVersion = this.version(workingDirectory);
public int compareVersionTo(File workingDirectory, String compareVersion) throws IOException, InterruptedException {
String currentVersion = version(workingDirectory);

List<Integer> currentComponents = Arrays.stream(currentVersion.split("\\."))
.map(Integer::parseInt)
Original file line number Diff line number Diff line change
@@ -190,17 +190,19 @@ private void createTempNpmrc(Path workingDir, List<String> commandArgs) throws I
}

//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 += "/";
if( this.npmDriver.compareVersionTo(workingDir.toFile(), "8.19") >= 0){
try (ArtifactoryManager artifactoryManager = artifactoryManagerBuilder.build()) {
String authProp = npmAuth.getProperty("_auth");

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

// Save npm auth
Loading
Oops, something went wrong.