@@ -130,6 +130,8 @@ public void npmCiRunTask() throws Exception {
130130
131131 ProcessBuilder processBuilder = new ProcessBuilder (npmExe .getAbsolutePath (), "run" , npmTaskName );
132132 processBuilder .directory (projectDir );
133+
134+ addNodeToPath (processBuilder , installDir );
133135 processBuilder .environment ().putAll (environment );
134136 Process process = processBuilder .start ();
135137
@@ -163,6 +165,19 @@ public void apply(Project project) {
163165 project .getExtensions ().create (EXTENSION_NAME , Extension .class , project );
164166 }
165167
168+ private static void addNodeToPath (ProcessBuilder processBuilder , File installDir ) {
169+ // Add node binary directory to PATH for npm to find node executable
170+ File nodeDir = new File (installDir , "node" );
171+ String currentPath = processBuilder .environment ().get ("PATH" );
172+ if (currentPath == null ) {
173+ currentPath = processBuilder .environment ().get ("Path" ); // Windows
174+ }
175+ String nodeBinPath = nodeDir .getAbsolutePath ();
176+ String pathSeparator = System .getProperty ("path.separator" );
177+ String newPath = nodeBinPath + pathSeparator + (currentPath != null ? currentPath : "" );
178+ processBuilder .environment ().put ("PATH" , newPath );
179+ }
180+
166181 private static String nvmRc (File file ) throws IOException {
167182 String str = new String (Files .readAllBytes (file .toPath ()), StandardCharsets .UTF_8 ).trim ();
168183 return "v" + str ;
0 commit comments