Skip to content

Commit bac4e02

Browse files
mribbonslukekarrys
authored andcommitted
add ps1 scripts
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
1 parent 6162f9f commit bac4e02

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

bin/npm.ps1

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env pwsh
2+
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
3+
4+
$exe=""
5+
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
6+
# Fix case when both the Windows and Linux builds of Node
7+
# are installed in the same directory
8+
$exe=".exe"
9+
}
10+
$ret=0
11+
12+
$nodebin = $(Get-Command "node$exe" -ErrorAction SilentlyContinue -ErrorVariable F).Source
13+
if ($nodebin -eq $null) {
14+
Write-Host "node$exe not found."
15+
exit 1
16+
}
17+
$nodedir = $(New-Object -ComObject Scripting.FileSystemObject).GetFile("$nodebin").ParentFolder.Path
18+
19+
# Support pipeline input
20+
if ($MyInvocation.ExpectingInput) {
21+
$input | & "node$exe" "$nodedir/node_modules/npm/bin/npm-cli.js" $args
22+
} else {
23+
& "node$exe" "$nodedir/node_modules/npm/bin/npm-cli.js" $args
24+
}
25+
$ret=$LASTEXITCODE
26+
exit $ret

bin/npx.ps1

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env pwsh
2+
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
3+
4+
$exe=""
5+
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
6+
# Fix case when both the Windows and Linux builds of Node
7+
# are installed in the same directory
8+
$exe=".exe"
9+
}
10+
$ret=0
11+
12+
$nodebin = $(Get-Command "node$exe" -ErrorAction SilentlyContinue -ErrorVariable F).Source
13+
if ($nodebin -eq $null) {
14+
Write-Host "node$exe not found."
15+
exit 1
16+
}
17+
$nodedir = $(New-Object -ComObject Scripting.FileSystemObject).GetFile("$nodebin").ParentFolder.Path
18+
19+
# Support pipeline input
20+
if ($MyInvocation.ExpectingInput) {
21+
$input | & "node$exe" "$nodedir/node_modules/npm/bin/npx-cli.js" $args
22+
} else {
23+
& "node$exe" "$nodedir/node_modules/npm/bin/npx-cli.js" $args
24+
}
25+
$ret=$LASTEXITCODE
26+
exit $ret

0 commit comments

Comments
 (0)