tauri.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env node
  2. const cli = require('./main')
  3. const path = require('path')
  4. const [bin, script, ...arguments] = process.argv
  5. const binStem = path.parse(bin).name.toLowerCase()
  6. // We want to make a helpful binary name for the underlying CLI helper, if we
  7. // can successfully detect what command likely started the execution.
  8. let binName
  9. // Even if started by a package manager, the binary will be NodeJS.
  10. // Some distribution still use "nodejs" as the binary name.
  11. if (binStem === 'node' || binStem === 'nodejs') {
  12. const managerStem = process.env.npm_execpath
  13. ? path.parse(process.env.npm_execpath).name.toLowerCase()
  14. : null
  15. if (managerStem) {
  16. let manager
  17. switch (managerStem) {
  18. // Only supported package manager that has a different filename is npm.
  19. case 'npm-cli':
  20. manager = 'npm'
  21. break
  22. // Yarn and pnpm have the same stem name as their bin.
  23. // We assume all unknown package managers do as well.
  24. default:
  25. manager = managerStem
  26. break
  27. }
  28. binName = `${manager} run ${process.env.npm_lifecycle_event}`
  29. } else {
  30. // Assume running NodeJS if we didn't detect a manager from the env.
  31. // We normalize the path to prevent the script's absolute path being used.
  32. const scriptNormal = path.normalize(path.relative(process.cwd(), script))
  33. binName = `${binStem} ${scriptNormal}`
  34. }
  35. } else {
  36. // We don't know what started it, assume it's already stripped.
  37. arguments.unshift(bin)
  38. }
  39. cli.run(arguments, binName)