Skip to content

Commit 5d82d0b

Browse files
fix: ps1 scripts in powershell 5.1 (#8469)
Fixes issue #8468: npm.ps1 and npx.ps1 fail on Windows PowerShell 5.1 when run in strict mode.
1 parent d006583 commit 5d82d0b

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

bin/npm.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env pwsh
22

3+
Set-StrictMode -Version 'Latest'
4+
35
$NODE_EXE="$PSScriptRoot/node.exe"
46
if (-not (Test-Path $NODE_EXE)) {
57
$NODE_EXE="$PSScriptRoot/node"
@@ -27,7 +29,7 @@ if ($MyInvocation.ExpectingInput) { # takes pipeline input
2729
} elseif (-not $MyInvocation.Line) { # used "-File" argument
2830
& $NODE_EXE $NPM_CLI_JS $args
2931
} else { # used "-Command" argument
30-
if ($MyInvocation.Statement) {
32+
if (($MyInvocation | Get-Member -Name 'Statement') -and $MyInvocation.Statement) {
3133
$NPM_ORIGINAL_COMMAND = $MyInvocation.Statement
3234
} else {
3335
$NPM_ORIGINAL_COMMAND = (

bin/npx.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env pwsh
22

3+
Set-StrictMode -Version 'Latest'
4+
35
$NODE_EXE="$PSScriptRoot/node.exe"
46
if (-not (Test-Path $NODE_EXE)) {
57
$NODE_EXE="$PSScriptRoot/node"
@@ -27,7 +29,7 @@ if ($MyInvocation.ExpectingInput) { # takes pipeline input
2729
} elseif (-not $MyInvocation.Line) { # used "-File" argument
2830
& $NODE_EXE $NPX_CLI_JS $args
2931
} else { # used "-Command" argument
30-
if ($MyInvocation.Statement) {
32+
if (($MyInvocation | Get-Member -Name 'Statement') -and $MyInvocation.Statement) {
3133
$NPX_ORIGINAL_COMMAND = $MyInvocation.Statement
3234
} else {
3335
$NPX_ORIGINAL_COMMAND = (

0 commit comments

Comments
 (0)