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