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.
25 lines
624 B
TypeScript
25 lines
624 B
TypeScript
import fs from 'node:fs'
|
|
import util from 'node:util'
|
|
|
|
export async function safeStat (filePath: string): Promise<fs.Stats | undefined> {
|
|
try {
|
|
return await fs.promises.stat(filePath)
|
|
} catch (error) {
|
|
if (util.types.isNativeError(error) && 'code' in error && error.code === 'ENOENT') {
|
|
return undefined
|
|
}
|
|
throw error
|
|
}
|
|
}
|
|
|
|
export function safeStatSync (filePath: string): fs.Stats | undefined {
|
|
try {
|
|
return fs.statSync(filePath)
|
|
} catch (error) {
|
|
if (util.types.isNativeError(error) && 'code' in error && error.code === 'ENOENT') {
|
|
return undefined
|
|
}
|
|
throw error
|
|
}
|
|
}
|