Files
pnpm/workspace/state/src/loadWorkspaceState.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

23 lines
687 B
TypeScript

import fs from 'node:fs'
import util from 'node:util'
import { logger } from '@pnpm/logger'
import { getFilePath } from './filePath.js'
import type { WorkspaceState } from './types.js'
export function loadWorkspaceState (workspaceDir: string): WorkspaceState | undefined {
logger.debug({ msg: 'loading workspace state' })
const cacheFile = getFilePath(workspaceDir)
let cacheFileContent: string
try {
cacheFileContent = fs.readFileSync(cacheFile, 'utf-8')
} catch (error) {
if (util.types.isNativeError(error) && 'code' in error && error.code === 'ENOENT') {
return undefined
}
throw error
}
return JSON.parse(cacheFileContent) as WorkspaceState
}