Skip to content

Commit ad48c4e

Browse files
committed
JS: Always prepare package.json files
1 parent 675c64d commit ad48c4e

File tree

2 files changed

+32
-32
lines changed

2 files changed

+32
-32
lines changed

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

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,8 @@ private void extractSource() throws IOException {
596596
.collect(Collectors.toCollection(() -> new LinkedHashSet<>()));
597597

598598
DependencyInstallationResult dependencyInstallationResult = DependencyInstallationResult.empty;
599-
if (!tsconfigFiles.isEmpty() && this.installDependencies) {
600-
dependencyInstallationResult = this.installDependencies(filesToExtract);
599+
if (!tsconfigFiles.isEmpty()) {
600+
dependencyInstallationResult = this.preparePackagesAndDependencies(filesToExtract);
601601
}
602602

603603
// extract TypeScript projects and files
@@ -712,7 +712,8 @@ public static Path tryRelativize(Path from, Path to) {
712712
}
713713

714714
/**
715-
* Installs dependencies for use by the TypeScript type checker.
715+
* Prepares <tt>package.json</tt> files in a virtual source root, and, if enabled,
716+
* installs dependencies for use by the TypeScript type checker.
716717
* <p>
717718
* Some packages must be downloaded while others exist within the same repo ("monorepos")
718719
* but are not in a location where TypeScript would look for it.
@@ -730,10 +731,7 @@ public static Path tryRelativize(Path from, Path to) {
730731
* The TypeScript parser wrapper then overrides module resolution so packages can be found
731732
* under the virtual source root and via that package location mapping.
732733
*/
733-
protected DependencyInstallationResult installDependencies(Set<Path> filesToExtract) {
734-
if (!verifyYarnInstallation()) {
735-
return DependencyInstallationResult.empty;
736-
}
734+
protected DependencyInstallationResult preparePackagesAndDependencies(Set<Path> filesToExtract) {
737735
final Path sourceRoot = LGTM_SRC;
738736
final Path virtualSourceRoot = toRealPath(Paths.get(EnvironmentVariables.getScratchDir()));
739737

@@ -836,29 +834,31 @@ protected DependencyInstallationResult installDependencies(Set<Path> filesToExtr
836834
}
837835

838836
// Install dependencies
839-
for (Path file : packageJsonFiles.keySet()) {
840-
Path virtualFile = virtualSourceRoot.resolve(sourceRoot.relativize(file));
841-
System.out.println("Installing dependencies from " + virtualFile);
842-
ProcessBuilder pb =
843-
new ProcessBuilder(
844-
Arrays.asList(
845-
"yarn",
846-
"install",
847-
"--non-interactive",
848-
"--ignore-scripts",
849-
"--ignore-platform",
850-
"--ignore-engines",
851-
"--ignore-optional",
852-
"--no-default-rc",
853-
"--no-bin-links",
854-
"--pure-lockfile"));
855-
pb.directory(virtualFile.getParent().toFile());
856-
pb.redirectOutput(Redirect.INHERIT);
857-
pb.redirectError(Redirect.INHERIT);
858-
try {
859-
pb.start().waitFor(this.installDependenciesTimeout, TimeUnit.MILLISECONDS);
860-
} catch (IOException | InterruptedException ex) {
861-
throw new ResourceError("Could not install dependencies from " + file, ex);
837+
if (this.installDependencies && verifyYarnInstallation()) {
838+
for (Path file : packageJsonFiles.keySet()) {
839+
Path virtualFile = virtualSourceRoot.resolve(sourceRoot.relativize(file));
840+
System.out.println("Installing dependencies from " + virtualFile);
841+
ProcessBuilder pb =
842+
new ProcessBuilder(
843+
Arrays.asList(
844+
"yarn",
845+
"install",
846+
"--non-interactive",
847+
"--ignore-scripts",
848+
"--ignore-platform",
849+
"--ignore-engines",
850+
"--ignore-optional",
851+
"--no-default-rc",
852+
"--no-bin-links",
853+
"--pure-lockfile"));
854+
pb.directory(virtualFile.getParent().toFile());
855+
pb.redirectOutput(Redirect.INHERIT);
856+
pb.redirectError(Redirect.INHERIT);
857+
try {
858+
pb.start().waitFor(this.installDependenciesTimeout, TimeUnit.MILLISECONDS);
859+
} catch (IOException | InterruptedException ex) {
860+
throw new ResourceError("Could not install dependencies from " + file, ex);
861+
}
862862
}
863863
}
864864

javascript/extractor/src/com/semmle/js/extractor/test/AutoBuildTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ public void extractTypeScriptFiles(
131131
}
132132

133133
@Override
134-
protected DependencyInstallationResult installDependencies(Set<Path> filesToExtract) {
135-
// never install dependencies during testing
134+
protected DependencyInstallationResult preparePackagesAndDependencies(Set<Path> filesToExtract) {
135+
// currently disabled in tests
136136
return DependencyInstallationResult.empty;
137137
}
138138

0 commit comments

Comments
 (0)