Files
pnpm/global/packages/src/globalPackageDir.ts
Zoltan Kochan 5d5818e44f style: enforce node: protocol for builtin imports (#10951)
Add n/prefer-node-protocol rule and autofix all bare builtin imports
to use the node: prefix. Simplify the simple-import-sort builtins
pattern to just ^node: since all imports now use the prefix.
2026-03-13 07:59:51 +01:00

29 lines
837 B
TypeScript

import fs from 'node:fs'
import path from 'node:path'
import util from 'node:util'
export function getHashLink (globalDir: string, hash: string): string {
return path.join(globalDir, hash)
}
export function resolveInstallDir (globalDir: string, hash: string): string | null {
const linkPath = getHashLink(globalDir, hash)
try {
const stats = fs.lstatSync(linkPath)
if (!stats.isSymbolicLink()) return null
return fs.realpathSync(linkPath)
} catch (err) {
if (util.types.isNativeError(err) && 'code' in err && err.code === 'ENOENT') {
return null
}
throw err
}
}
export function createInstallDir (globalDir: string): string {
const name = `${process.pid.toString(16)}-${Date.now().toString(16)}`
const dir = path.join(globalDir, name)
fs.mkdirSync(dir, { recursive: true })
return dir
}