Skip to content

Commit d68f6a7

Browse files
committed
Expand envVars in Windows PATH, use NodeJS's existsSync which handles symlink for Python 3 from Windows Store
1 parent ff88c50 commit d68f6a7

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/misc.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
import { getCacheDir, getCoreDir, getEnvBinDir, getEnvDir } from './core';
1010

11-
import fs from 'fs-plus';
11+
import fs from 'fs';
12+
import fsPlus from 'fs-plus';
1213
import os from 'os';
1314
import path from 'path';
1415
import 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

Comments
 (0)