tauri.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env node
  2. // Copyright 2019-2024 Tauri Programme within The Commons Conservancy
  3. // SPDX-License-Identifier: Apache-2.0
  4. // SPDX-License-Identifier: MIT
  5. const cli = require('./main')
  6. const path = require('path')
  7. const [bin, script, ...args] = process.argv
  8. const binStem = path.parse(bin).name.toLowerCase()
  9. // We want to make a helpful binary name for the underlying CLI helper, if we
  10. // can successfully detect what command likely started the execution.
  11. let binName
  12. // deno run -A npm:@tauri-apps/cli or deno task tauri
  13. if (globalThis.navigator?.userAgent?.includes('Deno')) {
  14. binName = bin
  15. }
  16. // Even if started by a package manager, the binary will be NodeJS.
  17. // Some distribution still use "nodejs" as the binary name.
  18. else if (binStem.match(/(nodejs|node|bun)\-?([0-9]*)*$/g)) {
  19. const managerStem = process.env.npm_execpath
  20. ? path.parse(process.env.npm_execpath).name.toLowerCase()
  21. : null
  22. if (managerStem) {
  23. let manager
  24. switch (managerStem) {
  25. // Only supported package manager that has a different filename is npm.
  26. case 'npm-cli':
  27. manager = 'npm'
  28. break
  29. // Yarn, pnpm, and bun have the same stem name as their bin.
  30. // We assume all unknown package managers do as well.
  31. default:
  32. manager = managerStem
  33. break
  34. }
  35. binName = `${manager} run ${process.env.npm_lifecycle_event}`
  36. } else {
  37. // Assume running NodeJS if we didn't detect a manager from the env.
  38. // We normalize the path to prevent the script's absolute path being used.
  39. const scriptNormal = path.normalize(path.relative(process.cwd(), script))
  40. binName = `${binStem} ${scriptNormal}`
  41. }
  42. } else {
  43. // We don't know what started it, assume it's already stripped.
  44. args.unshift(bin)
  45. }
  46. cli.run(args, binName).catch((err) => {
  47. cli.logError(err.message)
  48. process.exit(1)
  49. })