88
99import { getCacheDir , getCoreDir , getEnvBinDir , getEnvDir } from './core' ;
1010
11- import fs from 'fs-plus' ;
11+ import fs from 'fs' ;
12+ import fsPlus from 'fs-plus' ;
1213import os from 'os' ;
1314import path from 'path' ;
1415import qs from 'querystringify' ;
@@ -66,6 +67,14 @@ export function patchOSEnviron({
6667 process . env . PATH = [ extraPath , process . env . PATH ] . join ( path . delimiter ) ;
6768 }
6869
70+ // Expand Windows environment variables in %xxx% format
71+ const reWindowsEnvVar = / \% ( [ ^ \% ] + ) \% / g;
72+ while ( IS_WINDOWS && reWindowsEnvVar . test ( process . env . PATH ) ) {
73+ process . env . PATH = process . env . PATH . replace ( reWindowsEnvVar , ( _ , envvar ) => {
74+ return process . env [ envvar ] || '' ;
75+ } ) ;
76+ }
77+
6978 // copy PATH to Path (Windows issue)
7079 if ( process . env . Path ) {
7180 process . env . Path = process . env . PATH ;
@@ -80,7 +89,7 @@ export function runCommand(cmd, args, callback = undefined, options = {}) {
8089 let tmpDir = null ;
8190
8291 options . spawnOptions = options . spawnOptions || { } ;
83- if ( ! options . spawnOptions . cwd && fs . isDirectorySync ( getEnvBinDir ( ) ) ) {
92+ if ( ! options . spawnOptions . cwd && fsPlus . isDirectorySync ( getEnvBinDir ( ) ) ) {
8493 options . spawnOptions . cwd = getEnvBinDir ( ) ;
8594 }
8695
@@ -122,7 +131,7 @@ export function runCommand(cmd, args, callback = undefined, options = {}) {
122131
123132 if ( tmpDir ) {
124133 try {
125- fs . removeSync ( tmpDir ) ;
134+ fsPlus . removeSync ( tmpDir ) ;
126135 } catch ( err ) {
127136 console . warn ( err ) ;
128137 }
@@ -173,7 +182,7 @@ export async function getPythonExecutable(
173182 for ( const location of locations ) {
174183 for ( const exename of exenames ) {
175184 const executable = path . normalize ( path . join ( location , exename ) ) . replace ( / " / g, '' ) ;
176- if ( fs . isFileSync ( executable ) && ( await isCompatiblePython ( executable ) ) ) {
185+ if ( fs . existsSync ( executable ) && ( await isCompatiblePython ( executable ) ) ) {
177186 return executable ;
178187 }
179188 }
0 commit comments