mirror of
https://github.com/pnpm/pnpm.git
synced 2026-05-12 18:49:41 -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.
23 lines
687 B
TypeScript
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
|
|
}
|