Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { readFileSync } from 'node:fs'
- import { createRequire } from 'node:module'
- import { dirname, join } from 'node:path'
- import { fileURLToPath } from 'node:url'
- let pnp: typeof import('pnpapi') | undefined = undefined
- if (process.versions.pnp) {
- try {
- pnp = createRequire(import.meta.url)(`pnpapi`)
- } catch {}
- }
- function test() {
- if (!pnp) {
- console.log(`Running in Node.js environment`)
- return
- }
- console.log(`Running in PnP environment`)
- if (typeof pnp.VERSIONS['getAllLocators'] !== `number`) {
- console.error(`The version of the PnP API is too old`)
- process.exit(1)
- }
- pnp.getDependencyTreeRoots().forEach(locator => {
- const info = pnp.getPackageInformation(locator)
- console.log(`- ${locator.name}: (${info.packageLocation})`)
- })
- // Get all the packages in current workspace
- pnp.getAllLocators().forEach(locator => {
- const info = pnp.getPackageInformation(locator)
- console.log(` - ${locator.name}: (${info.packageLocation})`)
- })
- const baseDir = dirname(fileURLToPath(import.meta.url))
- // Get one package information by name
- const normalised = pnp.resolveToUnqualified(`esbuild`, baseDir, { considerBuiltins: false })
- if (!normalised) {
- console.error(`Package not found`)
- process.exit(1)
- }
- const locator = pnp.findPackageLocator(normalised)
- console.log(JSON.stringify(locator, null, 2))
- const info = pnp.getPackageInformation(locator)
- console.log(JSON.stringify(info, null, 2))
- // -->
- // {
- // "packageDependencies": {},
- // "packagePeers": {},
- // "linkType": "HARD",
- // "discardFromLookup": false,
- // "packageLocation": "E:\\repo\\koishi\\cordis-test\\.yarn\\cache\\koishi-npm-4.17.7-43020a5508-08ffffd724.zip\\node_modules\\koishi\\"
- // }
- const pkgData = join(normalised, `package.json`)
- const pkg = readFileSync(pkgData, `utf8`)
- {
- const { name, version } = JSON.parse(pkg)
- console.log(`Package: ${name}@${version}`) // --> Package: koishi@4.17.7
- }
- }
- test()
Advertisement
Comments
-
- API BNOT WORK HELP HE ASLO TAKET MY IP AND TAKERT ALL MY LTC AND HE TAKERT LTC SO HE GET NO FEES AND NOW ALL MY LTC IS GONE :( RIP LTC
-
- DISSLIKE
Add Comment
Please, Sign In to add comment
Advertisement