source dump of claude code
at main 43 lines 1.3 kB view raw
1/** 2 * Lazy accessor for proper-lockfile. 3 * 4 * proper-lockfile depends on graceful-fs, which monkey-patches every fs 5 * method on first require (~8ms). Static imports of proper-lockfile pull this 6 * cost into the startup path even when no locking happens (e.g. `--help`). 7 * 8 * Import this module instead of `proper-lockfile` directly. The underlying 9 * package is only loaded the first time a lock function is actually called. 10 */ 11 12import type { CheckOptions, LockOptions, UnlockOptions } from 'proper-lockfile' 13 14type Lockfile = typeof import('proper-lockfile') 15 16let _lockfile: Lockfile | undefined 17 18function getLockfile(): Lockfile { 19 if (!_lockfile) { 20 // eslint-disable-next-line @typescript-eslint/no-require-imports 21 _lockfile = require('proper-lockfile') as Lockfile 22 } 23 return _lockfile 24} 25 26export function lock( 27 file: string, 28 options?: LockOptions, 29): Promise<() => Promise<void>> { 30 return getLockfile().lock(file, options) 31} 32 33export function lockSync(file: string, options?: LockOptions): () => void { 34 return getLockfile().lockSync(file, options) 35} 36 37export function unlock(file: string, options?: UnlockOptions): Promise<void> { 38 return getLockfile().unlock(file, options) 39} 40 41export function check(file: string, options?: CheckOptions): Promise<boolean> { 42 return getLockfile().check(file, options) 43}