Skip to content

Commit

Permalink
fix: npm - cannot find the generated package-lock.json (#90)
Browse files Browse the repository at this point in the history
in case directory has spaces, need to invoke npm ls command from that
directory , without prefix flag, this change fixes an error of not
finding the package-lock.json in a directory that contains spaces


Signed-off-by: Zvi Grinberg <[email protected]>
  • Loading branch information
zvigrinberg authored Feb 13, 2024
1 parent f453223 commit ce7e0d5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/redhat/exhort/impl/ExhortApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public String getEndpoint() {
public static final void main(String[] args) throws IOException, InterruptedException, ExecutionException {
System.setProperty("EXHORT_DEV_MODE", "true");
AnalysisReport analysisReport = new ExhortApi()
.stackAnalysis("/home/zgrinber/git/exhort-java-api/src/test/resources/tst_manifests/maven/deps_with_ignore_on_artifact/pom.xml").get();
.stackAnalysisMixed("/home/zgrinber/.jenkins/workspace/run RHDA Analysis/package.json").get().json;
// ObjectMapper om = new ObjectMapper().configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, false);
// System.out.println(om.writerWithDefaultPrettyPrinter().writeValueAsString(analysisReport));
// AnalysisReport analysisReport = new ExhortApi()
Expand Down Expand Up @@ -170,8 +170,8 @@ static HttpClient.Version getHttpVersion() {

private String commonHookBeginning(boolean startOfApi) {
if(startOfApi) {
LOG.info("Start of exhort-java-api client");
generateClientRequestId();
LOG.info("Start of exhort-java-api client");
}
else {
if(Objects.isNull(getClientRequestId())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,25 @@ private JsonNode buildNpmDependencyTree(Path manifestPath, boolean includeTransi
manifestPath.getParent().toString() };
// execute the clean command
Operations.runProcess(createPackageLock, npmEnvs);
String[] npmAllDeps;
Path workDir=null;
if(!manifestPath.getParent().toString().trim().contains(" ")) {


var npmAllDeps = new String[] { npm, "ls", includeTransitive ? "--all" : "", "--omit=dev", "--package-lock-only",
"--json", "--prefix", manifestPath.getParent().toString() };
npmAllDeps = new String[]{npm, "ls", includeTransitive ? "--all" : "", "--omit=dev", "--package-lock-only",
"--json", "--prefix", manifestPath.getParent().toString()};
}
else {
npmAllDeps = new String[]{npm, "ls", includeTransitive ? "--all" : "", "--omit=dev", "--package-lock-only",
"--json"};
workDir = manifestPath.getParent();
}
// execute the clean command
String npmOutput;
if (npmEnvs != null) {
npmOutput = Operations.runProcessGetOutput(null, npmAllDeps,
npmOutput = Operations.runProcessGetOutput(workDir, npmAllDeps,
npmEnvs.entrySet().stream().map(e -> e.getKey() + "=" + e.getValue()).toArray(String[]::new));
} else {
npmOutput = Operations.runProcessGetOutput(null, npmAllDeps);
npmOutput = Operations.runProcessGetOutput(workDir, npmAllDeps);
}
if(debugLoggingIsNeeded()) {
log.log(System.Logger.Level.INFO,String.format("Npm Listed Install Pacakges in Json : %s %s",System.lineSeparator(),npmOutput));
Expand Down

0 comments on commit ce7e0d5

Please sign in to comment.