@@ -44,6 +44,12 @@ function Require-Npm {
4444 }
4545}
4646
47+ function Get-NpmPath {
48+ $cmd = Get-Command npm - ErrorAction Stop
49+ # On Windows this is typically ...\npm.cmd
50+ return $cmd.Source
51+ }
52+
4753function Read-Secure ([string ]$msg ) {
4854 $secure = Read-Host $msg - AsSecureString
4955 $bstr = [Runtime.InteropServices.Marshal ]::SecureStringToBSTR($secure )
@@ -74,9 +80,7 @@ function SetCfg([string]$k, [string]$v) {
7480
7581function DelCfg ([string ]$k ) {
7682 if ($DryRun ) { Info " DRYRUN: npm config delete --global $k " ; return }
77- try {
78- npm config delete -- global $k | Out-Null
79- } catch {}
83+ try { npm config delete -- global $k | Out-Null } catch {}
8084}
8185
8286# IMPORTANT: Do NOT name parameters as $args (PowerShell automatic variable).
@@ -94,11 +98,13 @@ function Run-NpmInstall([string[]]$npmArgs) {
9498 return
9599 }
96100
97- # Logging enabled: capture stdout/stderr to file AND show on console
101+ # Logging enabled: use the resolved npm path (e.g., npm.cmd) for compatibility
102+ $npmPath = Get-NpmPath
98103 Info " Logging enabled. Log file: $LogPath "
104+ Info (" Resolved npm path: " + $npmPath )
99105
100106 $psi = New-Object System.Diagnostics.ProcessStartInfo
101- $psi.FileName = " npm "
107+ $psi.FileName = $npmPath
102108 $psi.Arguments = ($npmArgs -join " " )
103109 $psi.RedirectStandardOutput = $true
104110 $psi.RedirectStandardError = $true
@@ -109,14 +115,10 @@ function Run-NpmInstall([string[]]$npmArgs) {
109115 $p.StartInfo = $psi
110116 [void ]$p.Start ()
111117
112- $outTask = $p.StandardOutput.ReadToEndAsync ()
113- $errTask = $p.StandardError.ReadToEndAsync ()
114-
118+ $stdout = $p.StandardOutput.ReadToEnd ()
119+ $stderr = $p.StandardError.ReadToEnd ()
115120 $p.WaitForExit ()
116121
117- $stdout = $outTask.Result
118- $stderr = $errTask.Result
119-
120122 if ($stdout ) { Write-Host $stdout }
121123 if ($stderr ) { Write-Host $stderr }
122124
@@ -126,6 +128,7 @@ function Run-NpmInstall([string[]]$npmArgs) {
126128 " Package: $PackageName @latest"
127129 " VerboseInstall: $VerboseInstall "
128130 " Registry: $registry /"
131+ " ResolvedNpm: $npmPath "
129132 " Command: npm " + ($npmArgs -join " " )
130133 " "
131134 " ---- STDOUT ----"
@@ -203,6 +206,7 @@ try {
203206 SetCfg " ${authPrefix} :username" " ms"
204207 SetCfg " ${authPrefix} :_password" $patB64
205208 SetCfg " ${authPrefix} :email" " npm@example.com"
209+ # NOTE: always-auth intentionally not set (deprecated/invalid in modern npm)
206210
207211 Info " "
208212 Info (" Command: npm " + ($npmInstallArgs -join " " ))
0 commit comments