Failed to parse past path entries on D:
johnkazer opened this issue · comments
John Kazer commented
I have two path entries 'D:....' but whichSync failed to iterate over pathEnv beyond these when trying to find the 'git' path. I changed the order so the 'D:...' entries were last and whichSync parsed everything up to but not including those moved 'D:...' entries. When moved, there were the 14th and 15th path entries.
John Gardner commented
@johnkazer Just out of curiosity, what's the output you get if you run the following script?
node that-script-below.js
"use strict";
which("git").then(output => {
console.log(output);
});
/**
* Locate a program file in the user's $PATH.
*
* If found, the returned {@link Promise} resolves to the absolute
* pathname of the named executable. Otherwise, it resolves to the
* empty string. Rejects with an error if the execution failed.
*
* @example which("curl") == "/usr/bin/curl"
* @example which("nada") == ""
* @param {String} name
* @return {Promise}
*/
function which(name){
return new Promise((resolve, reject) => {
if(!name) return resolve("");
const {exec} = require("child_process");
const cmdStr = "win32" === process.platform
? `@for %g in (ECHO ${name.replace(/%/g, "%%")}) do`
+ " @for %e in (%PATHEXT%) do"
+ " @for %i in (%g%e) do "
+ ' @if NOT "%~$PATH:i"=="" echo %~$PATH:i'
: `command -v '${name.replace(/'/g, `'"'"'`)}' 2>/dev/null`;
exec(cmdStr, {windowsHide: true}, (error, output) => error
? reject(error)
: resolve(output.split(/\r?\n/).filter(Boolean)[0] || ""));
});
}