Allow windows to find commands without .exe

This commit is contained in:
Ian Wahbe 2021-08-30 21:36:03 -07:00
parent a2250cc9ef
commit 70833d3a3c
3 changed files with 13 additions and 9 deletions

View file

@ -604,7 +604,7 @@ func getNodeProgramDependencies(rootDir string, transitive bool) ([]programDepen
if _, err = os.Stat(yarnFile); err == nil {
ex, err = executable.FindExecutable("yarn")
if err != nil {
return nil, errors.Wrapf(err, "Found %s but not yarn", yarnFile)
return nil, errors.Wrapf(err, "Found %s but not %s", yarnFile, ex)
}
cmdArgs := []string{"list", "--json"}
cmd := exec.Command(ex, cmdArgs...)

View file

@ -17,9 +17,20 @@ const unableToFindProgramTemplate = "unable to find program: %s"
// FindExecutable attempts to find the needed executable in various locations on the
// filesystem, eventually resorting to searching in $PATH.
func FindExecutable(program string) (string, error) {
var err error
var ex string
if runtime.GOOS == "windows" && !strings.HasSuffix(program, ".exe") {
program = fmt.Sprintf("%s.exe", program)
exe := fmt.Sprintf("%s.exe", program)
ex, err = findExecutableNoExe(exe)
if err != nil {
return ex, nil
}
}
return findExecutableNoExe(program)
}
func findExecutableNoExe(program string) (string, error) {
// look in the same directory
cwd, err := os.Getwd()
if err != nil {

View file

@ -1147,13 +1147,6 @@ func TestAboutNodeJS(t *testing.T) {
}
}()
e.ImportDirectory(dir)
if runtime.GOOS == WindowsOS {
// Because there is a package-lock.json file, and we delete the yarn
// file, pulumi will use the package-lock file for the about.
assert.NoError(t, os.Remove(filepath.Join(e.RootPath, "yarn.lock")),
"removing yarn.lock")
}
e.RunCommand("yarn", "link", "@pulumi/pulumi")
e.RunCommand("yarn", "install")
e.RunCommand("pulumi", "login", "--cloud-url", e.LocalURL())