npm.ps1 997 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env pwsh
  2. $basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
  3. $exe=""
  4. if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
  5. # Fix case when both the Windows and Linux builds of Node
  6. # are installed in the same directory
  7. $exe=".exe"
  8. }
  9. $ret=0
  10. $nodeexe = "node$exe"
  11. $nodebin = $(Get-Command $nodeexe -ErrorAction SilentlyContinue -ErrorVariable F).Source
  12. if ($nodebin -eq $null) {
  13. Write-Host "$nodeexe not found."
  14. exit 1
  15. }
  16. $nodedir = $(New-Object -ComObject Scripting.FileSystemObject).GetFile("$nodebin").ParentFolder.Path
  17. $npmclijs="$nodedir/node_modules/npm/bin/npm-cli.js"
  18. $npmprefix=(& $nodeexe $npmclijs prefix -g)
  19. if ($LASTEXITCODE -ne 0) {
  20. Write-Host "Could not determine Node.js install directory"
  21. exit 1
  22. }
  23. $npmprefixclijs="$npmprefix/node_modules/npm/bin/npm-cli.js"
  24. # Support pipeline input
  25. if ($MyInvocation.ExpectingInput) {
  26. $input | & $nodeexe $npmprefixclijs $args
  27. } else {
  28. & $nodeexe $npmprefixclijs $args
  29. }
  30. $ret=$LASTEXITCODE
  31. exit $ret