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 $nodeexe = "node$exe" 13 $nodebin = $(Get-Command $nodeexe -ErrorAction SilentlyContinue -ErrorVariable F).Source 14 if ($nodebin -eq $null) { 15 Write-Host "$nodeexe not found." 16 exit 1 17 } 18 $nodedir = $(New-Object -ComObject Scripting.FileSystemObject).GetFile("$nodebin").ParentFolder.Path 19 20 $npmclijs="$nodedir/node_modules/npm/bin/npm-cli.js" 21 $npmprefix=(& $nodeexe $npmclijs prefix -g) 22 if ($LASTEXITCODE -ne 0) { 23 Write-Host "Could not determine Node.js install directory" 24 exit 1 25 } 26 $npmprefixclijs="$npmprefix/node_modules/npm/bin/npm-cli.js" 27 28 # Support pipeline input 29 if ($MyInvocation.ExpectingInput) { 30 $input | & $nodeexe $npmprefixclijs $args 31 } else { 32 & $nodeexe $npmprefixclijs $args 33 } 34 $ret=$LASTEXITCODE 35 exit $ret 36