Skip to content

Commit f643fd7

Browse files
authored
Merge pull request #14716 from erik-krogh/invalid-main
JS: catch when the main: path is invalid on Windows
2 parents 45ae4ed + ae577d1 commit f643fd7

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -892,10 +892,15 @@ protected DependencyInstallationResult preparePackagesAndDependencies(Set<Path>
892892
// For named packages, find the main file.
893893
String name = packageJson.getName();
894894
if (name != null) {
895-
Path entryPoint = guessPackageMainFile(path, packageJson, FileType.TYPESCRIPT.getExtensions());
896-
if (entryPoint == null) {
897-
// Try a TypeScript-recognized JS extension instead
898-
entryPoint = guessPackageMainFile(path, packageJson, Arrays.asList(".js", ".jsx"));
895+
Path entryPoint = null;
896+
try {
897+
entryPoint = guessPackageMainFile(path, packageJson, FileType.TYPESCRIPT.getExtensions());
898+
if (entryPoint == null) {
899+
// Try a TypeScript-recognized JS extension instead
900+
entryPoint = guessPackageMainFile(path, packageJson, Arrays.asList(".js", ".jsx"));
901+
}
902+
} catch (InvalidPathException ignore) {
903+
// can happen if the `main:` field is invalid. E.g. on Windows a path like `dist/*.js` will crash.
899904
}
900905
if (entryPoint != null) {
901906
System.out.println(relativePath + ": Main file set to " + sourceRoot.relativize(entryPoint));

0 commit comments

Comments
 (0)