npm-prefix.js 834 B

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/env node
  2. // This is a single-use bin to help windows discover the proper prefix for npm
  3. // without having to load all of npm first
  4. // It does not accept argv params
  5. const path = require('node:path')
  6. const Config = require('@npmcli/config')
  7. const { definitions, flatten, shorthands } = require('@npmcli/config/lib/definitions')
  8. const config = new Config({
  9. npmPath: path.dirname(__dirname),
  10. // argv is explicitly not looked at since prefix is not something that can be changed via argv
  11. argv: [],
  12. definitions,
  13. flatten,
  14. shorthands,
  15. excludeNpmCwd: false,
  16. })
  17. async function main () {
  18. try {
  19. await config.load()
  20. // eslint-disable-next-line no-console
  21. console.log(config.globalPrefix)
  22. } catch (err) {
  23. // eslint-disable-next-line no-console
  24. console.error(err)
  25. process.exit(1)
  26. }
  27. }
  28. main()