Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: rewrite powershell scripts to use PSScriptRoot #7422

Merged
merged 3 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 15 additions & 25 deletions bin/npm.ps1
Original file line number Diff line number Diff line change
@@ -1,35 +1,25 @@
#!/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
$RET=0

$nodeexe = "node$exe"
$nodebin = $(Get-Command $nodeexe -ErrorAction SilentlyContinue -ErrorVariable F).Source
if ($nodebin -eq $null) {
Write-Host "$nodeexe not found."
exit 1
$NODE_EXE="$PSScriptRoot/node.exe"
if (-not (Test-Path $NODE_EXE)) {
$NODE_EXE="$PSScriptRoot/node"
wraithgar marked this conversation as resolved.
Show resolved Hide resolved
}
$nodedir = $(New-Object -ComObject Scripting.FileSystemObject).GetFile("$nodebin").ParentFolder.Path

$npmprefixjs="$nodedir/node_modules/npm/bin/npm-prefix.js"
$npmprefix=(& $nodeexe $npmprefixjs)
if ($LASTEXITCODE -ne 0) {
Write-Host "Could not determine Node.js install directory"
exit 1
if (-not (Test-Path $NODE_EXE)) {
$NODE_EXE="node"
}
$npmprefixclijs="$npmprefix/node_modules/npm/bin/npm-cli.js"

$NPM_PREFIX_JS="$PSScriptRoot/node_modules/npm/bin/npm-prefix.js"
$NPM_PREFIX=(& $NODE_EXE $NPM_PREFIX_JS)
$NPM_CLI_JS="$NPM_PREFIX/node_modules/npm/bin/npm-cli.js"

# Support pipeline input
if ($MyInvocation.ExpectingInput) {
$input | & $nodeexe $npmprefixclijs $args
$input | & $NODE_EXE $NPM_CLI_JS $args
} else {
& $nodeexe $npmprefixclijs $args
& $NODE_EXE $NPM_CLI_JS $args
}
$ret=$LASTEXITCODE
exit $ret

$RET=$LASTEXITCODE
wraithgar marked this conversation as resolved.
Show resolved Hide resolved
exit $RET
40 changes: 15 additions & 25 deletions bin/npx.ps1
Original file line number Diff line number Diff line change
@@ -1,35 +1,25 @@
#!/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
$RET=0

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

$npmprefixjs="$nodedir/node_modules/npm/bin/npm-prefix.js"
$npmprefix=(& $nodeexe $npmprefixjs)
if ($LASTEXITCODE -ne 0) {
Write-Host "Could not determine Node.js install directory"
exit 1
if (-not (Test-Path $NODE_EXE)) {
$NODE_EXE="node"
}
$npmprefixclijs="$npmprefix/node_modules/npm/bin/npx-cli.js"

$NPM_PREFIX_JS="$PSScriptRoot/node_modules/npm/bin/npm-prefix.js"
$NPM_PREFIX=(& $NODE_EXE $NPM_PREFIX_JS)
$NPX_CLI_JS="$NPM_PREFIX/node_modules/npm/bin/npx-cli.js"

# Support pipeline input
if ($MyInvocation.ExpectingInput) {
$input | & $nodeexe $npmprefixclijs $args
$input | & $NODE_EXE $NPX_CLI_JS $args
} else {
& $nodeexe $npmprefixclijs $args
& $NODE_EXE $NPX_CLI_JS $args
}
$ret=$LASTEXITCODE
exit $ret

$RET=$LASTEXITCODE
exit $RET