Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

How to handle other code that explicitly references the exe? #46

Open
dsherret opened this issue Feb 16, 2021 · 2 comments
Open

How to handle other code that explicitly references the exe? #46

dsherret opened this issue Feb 16, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@dsherret
Copy link
Collaborator

Unfortunately there is some code like this in powershell scripts for npm global binaries (ex. in yarn.ps1):

#!/usr/bin/env pwsh
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent

$exe=""
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
  # Fix case when both the Windows and Linux builds of Node
  # are installed in the same directory
  $exe=".exe"
}
$ret=0
if (Test-Path "$basedir/node$exe") {
  & "$basedir/node$exe"  "$basedir/node_modules/yarn/bin/yarn.js" $args
  $ret=$LASTEXITCODE
} else {
  & "node$exe"  "$basedir/node_modules/yarn/bin/yarn.js" $args
  $ret=$LASTEXITCODE
}
exit $ret
> yarn bootstrap
& : The term 'node.exe' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\USERS\<user>\APPDATA\ROAMING\NPM\yarn.ps1:15 char:5
+   & "node$exe"  "$basedir/node_modules/yarn/bin/yarn.js" $args
+     ~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (node.exe:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

The problem is that I don't believe an exe shim can be used here. I think the downstream code needs to be fixed 😢

@dsherret
Copy link
Collaborator Author

Opened npm/cmd-shim#51

@dsherret dsherret added the enhancement New feature or request label Oct 30, 2021
@dsherret
Copy link
Collaborator Author

I've been thinking about this and I think there should be an "exe fallback" path below the shims that exists only on Windows that is symlinks to the current global command executable. It's not ideal because it wouldn't use the current directory's symlink, but at least it would allow for things to run in these scenarios.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant