Skip to content

Commit c779f3c

Browse files
committed
fix: JS IllegalStateException due to unavailable lock files
1 parent 04b5a6f commit c779f3c

File tree

1 file changed

+25
-0
lines changed
  • src/main/java/org/jboss/tools/intellij/componentanalysis

1 file changed

+25
-0
lines changed

src/main/java/org/jboss/tools/intellij/componentanalysis/CAService.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,31 @@ public static boolean performAnalysis(String packageManager,
8080
tempDirectory = Files.createTempDirectory("rhda-idea");
8181
tempManifest = Files.createFile(Path.of(tempDirectory.toString(),fileName));
8282
Files.write(tempManifest,PsiDocumentManager.getInstance(file.getProject()).getCachedDocument(file).getText().getBytes());
83+
84+
if (packageManager.equals("npm")) {
85+
Path parentDir = Path.of(filePath).getParent();
86+
List<String> lockFiles = new ArrayList<>();
87+
if (Files.exists(parentDir.resolve("package-lock.json"))) {
88+
lockFiles.add("package-lock.json");
89+
}
90+
if (Files.exists(parentDir.resolve("pnpm-lock.yaml"))) {
91+
lockFiles.add("pnpm-lock.yaml");
92+
}
93+
if (Files.exists(parentDir.resolve("yarn.lock"))) {
94+
lockFiles.add("yarn.lock");
95+
}
96+
// Check the number of lockfiles
97+
if (lockFiles.size() > 1) {
98+
throw new RuntimeException("Multiple lockfiles detected: " + String.join(", ", lockFiles));
99+
} else if (lockFiles.size() == 1) {
100+
// Copy the single lockfile to tempDirectory
101+
Path lockFilePath = parentDir.resolve(lockFiles.get(0));
102+
Path targetLockFilePath = tempDirectory.resolve(lockFiles.get(0));
103+
Files.copy(lockFilePath, targetLockFilePath);
104+
} else {
105+
throw new RuntimeException("No lockfile found. Please generate a lockfile (package-lock.json, pnpm-lock.yaml, or yarn.lock).");
106+
}
107+
}
83108
} catch (IOException e) {
84109
throw new RuntimeException(e);
85110
}

0 commit comments

Comments
 (0)