mirror of
https://github.com/pnpm/pnpm.git
synced 2026-06-28 09:55:39 -04:00
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.
29 lines
837 B
TypeScript
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
|
|
}
|