Skip to content

[FEATURE] Powershell - Windows - Handle node.exe not on path, but node existing similar to cmd shims #51

@dsherret

Description

@dsherret

What / Why

I'm working on a generic binary version manager. Everything works decently well, but I recently ran into trouble with how this package generates powershell shims expecting node.exe on the path for Windows (in my case, only node.cmd and node.ps1 exist on the path).

The cmd shim seems fine and it will fallback to using node instead of node.exe when node.exe doesn't exist (you may categorize this difference between cmd and powershell as a bug).

Current Behavior

Example of yarn's script:

#!/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

Expected Behavior

It would do Test-Path for .exe and if that doesn't exist, then it would fallback to not providing a .exe file extension.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions