Skip to content

Commit

Permalink
add ps1 scripts
Browse files Browse the repository at this point in the history
Resolves UNC path issues because powershell.exe
supports UNC, while cmd.exe doesn't.
(Which is why npm.cmd doesn't work within
UNC paths, even under powershell)

Resolves #6280
  • Loading branch information
mribbons authored and lukekarrys committed Jun 23, 2023
1 parent aef96c0 commit aa4bf21
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
26 changes: 26 additions & 0 deletions bin/npm.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/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

$nodebin = $(Get-Command "node$exe" -ErrorAction SilentlyContinue -ErrorVariable F).Source
if ($nodebin -eq $null) {
Write-Host "node$exe not found."
exit 1
}
$nodedir = $(New-Object -ComObject Scripting.FileSystemObject).GetFile("$nodebin").ParentFolder.Path

# Support pipeline input
if ($MyInvocation.ExpectingInput) {
$input | & "node$exe" "$nodedir/node_modules/npm/bin/npm-cli.js" $args
} else {
& "node$exe" "$nodedir/node_modules/npm/bin/npm-cli.js" $args
}
$ret=$LASTEXITCODE
exit $ret
26 changes: 26 additions & 0 deletions bin/npx.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/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

$nodebin = $(Get-Command "node$exe" -ErrorAction SilentlyContinue -ErrorVariable F).Source
if ($nodebin -eq $null) {
Write-Host "node$exe not found."
exit 1
}
$nodedir = $(New-Object -ComObject Scripting.FileSystemObject).GetFile("$nodebin").ParentFolder.Path

# Support pipeline input
if ($MyInvocation.ExpectingInput) {
$input | & "node$exe" "$nodedir/node_modules/npm/bin/npx-cli.js" $args
} else {
& "node$exe" "$nodedir/node_modules/npm/bin/npx-cli.js" $args
}
$ret=$LASTEXITCODE
exit $ret

0 comments on commit aa4bf21

Please sign in to comment.