Skip to content

Commit

Permalink
fix(powershell): fallback to script root if globalPrefix does not exi…
Browse files Browse the repository at this point in the history
…st (#7450)

This matches the behavior of the bash and cmd scripts.
  • Loading branch information
lukekarrys authored Apr 30, 2024
1 parent bc4c342 commit 2558283
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
6 changes: 5 additions & 1 deletion bin/npm.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ if (-not (Test-Path $NODE_EXE)) {
}

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

if ($LASTEXITCODE -ne 0) {
Write-Host "Could not determine Node.js install directory"
exit 1
}

$NPM_CLI_JS="$NPM_PREFIX/node_modules/npm/bin/npm-cli.js"
$NPM_PREFIX_NPM_CLI_JS="$NPM_PREFIX/node_modules/npm/bin/npm-cli.js"
if (Test-Path $NPM_PREFIX_NPM_CLI_JS) {
$NPM_CLI_JS=$NPM_PREFIX_NPM_CLI_JS
}

# Support pipeline input
if ($MyInvocation.ExpectingInput) {
Expand Down
6 changes: 5 additions & 1 deletion bin/npx.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ if (-not (Test-Path $NODE_EXE)) {
}

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

if ($LASTEXITCODE -ne 0) {
Write-Host "Could not determine Node.js install directory"
exit 1
}

$NPX_CLI_JS="$NPM_PREFIX/node_modules/npm/bin/npx-cli.js"
$NPM_PREFIX_NPX_CLI_JS="$NPM_PREFIX/node_modules/npm/bin/npx-cli.js"
if (Test-Path $NPM_PREFIX_NPX_CLI_JS) {
$NPX_CLI_JS=$NPM_PREFIX_NPX_CLI_JS
}

# Support pipeline input
if ($MyInvocation.ExpectingInput) {
Expand Down
10 changes: 5 additions & 5 deletions tap-snapshots/test/lib/commands/doctor.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -731,11 +731,11 @@ Object {
"warn": Array [
String(
doctor getGitPath Error: test error
doctor at which {STACK}
doctor at Doctor.getGitPath {STACK}
doctor at Doctor.exec {STACK}
doctor at processTicksAndRejections {STACK}
doctor at MockNpm.exec {STACK}
doctor at {STACK}
doctor at {STACK}
doctor at {STACK}
doctor at {STACK}
doctor at {STACK}
),
],
}
Expand Down
2 changes: 1 addition & 1 deletion test/lib/commands/doctor.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const cleanCacheSha = (str) =>
str.replace(/content-v2\/sha512\/[^"]+/g, 'content-v2/sha512/{sha}')

t.cleanSnapshot = p => cleanCacheSha(cleanDate(cleanCwd(p)))
.replace(/\s\((\{CWD\}|node:).*\d+:\d+\)$/gm, ' {STACK}')
.replace(/(doctor\s+at\s).*$/gm, '$1{STACK}')

const npmManifest = (version) => {
return {
Expand Down

0 comments on commit 2558283

Please sign in to comment.