@@ -596,8 +596,8 @@ private void extractSource() throws IOException {
596
596
.collect (Collectors .toCollection (() -> new LinkedHashSet <>()));
597
597
598
598
DependencyInstallationResult dependencyInstallationResult = DependencyInstallationResult .empty ;
599
- if (!tsconfigFiles .isEmpty () && this . installDependencies ) {
600
- dependencyInstallationResult = this .installDependencies (filesToExtract );
599
+ if (!tsconfigFiles .isEmpty ()) {
600
+ dependencyInstallationResult = this .preparePackagesAndDependencies (filesToExtract );
601
601
}
602
602
603
603
// extract TypeScript projects and files
@@ -712,7 +712,8 @@ public static Path tryRelativize(Path from, Path to) {
712
712
}
713
713
714
714
/**
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.
716
717
* <p>
717
718
* Some packages must be downloaded while others exist within the same repo ("monorepos")
718
719
* but are not in a location where TypeScript would look for it.
@@ -730,10 +731,7 @@ public static Path tryRelativize(Path from, Path to) {
730
731
* The TypeScript parser wrapper then overrides module resolution so packages can be found
731
732
* under the virtual source root and via that package location mapping.
732
733
*/
733
- protected DependencyInstallationResult installDependencies (Set <Path > filesToExtract ) {
734
- if (!verifyYarnInstallation ()) {
735
- return DependencyInstallationResult .empty ;
736
- }
734
+ protected DependencyInstallationResult preparePackagesAndDependencies (Set <Path > filesToExtract ) {
737
735
final Path sourceRoot = LGTM_SRC ;
738
736
final Path virtualSourceRoot = toRealPath (Paths .get (EnvironmentVariables .getScratchDir ()));
739
737
@@ -836,29 +834,31 @@ protected DependencyInstallationResult installDependencies(Set<Path> filesToExtr
836
834
}
837
835
838
836
// 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
+ }
862
862
}
863
863
}
864
864
0 commit comments