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
Next Next commit
Update NpmDriver.java
Include Version compare for NpmBuildInfoExtractor
  • Loading branch information
Spaction authored Mar 21, 2024
commit ea5ca90c32b1a4f218a63a1f0d05409caebe1bba
Original file line number Diff line number Diff line change
@@ -97,6 +97,32 @@ public JsonNode list(File workingDirectory, List<String> extraArgs) throws IOExc
}
}

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

List<Integer> currentComponents = Arrays.stream(currentVersion.split("\\."))
.map(Integer::parseInt)
.collect(Collectors.toList());
List<Integer> compareComponents = Arrays.stream(compareVersion.split("\\."))
.map(Integer::parseInt)
.collect(Collectors.toList());

int currentSize = currentComponents.size();
int compareSize = compareComponents.size();
int maxLength = Math.max(currentSize, compareSize);

for (int i = 0; i < maxLength; i++){
int currentComp = i < currentSize ? currentComponents.get(i) : 0;
int compareComp = i < compareSize ? compareComponents.get(i) : 0;

int comp = compareComp - currentComp;
if(comp != 0){
return comp;
}
}
return 0;
}

public String version(File workingDirectory) throws IOException, InterruptedException {
return runCommand(workingDirectory, new String[]{"--version"}, Collections.emptyList()).getRes();
}
@@ -131,4 +157,4 @@ private CommandResults runCommand(File workingDirectory, String[] args, List<Str

return npmCommandRes;
}
}
}