Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit aa4bf21

Browse files
mribbonslukekarrys
authored andcommittedJun 23, 2023
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 aef96c0 commit aa4bf21

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
 

‎bin/npm.ps1

+26
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

+26
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)
Please sign in to comment.