(lockPath: string)
| 717 | } |
| 718 | |
| 719 | async function acquireServeLock(lockPath: string): Promise<ServeLock> { |
| 720 | await fsp.mkdir(path.dirname(lockPath), { recursive: true }); |
| 721 | try { |
| 722 | return await createServeLock(lockPath); |
| 723 | } catch (error) { |
| 724 | if (!(error && typeof error === 'object' && 'code' in error) || error.code !== 'EEXIST') { |
| 725 | throw error; |
| 726 | } |
| 727 | } |
| 728 | |
| 729 | const existing = readServeLock(lockPath); |
| 730 | if (existing?.pid && isProcessAlive(existing.pid)) { |
| 731 | throw new Error(createI18n().t('cli.lock.alreadyRunning', { |
| 732 | lockPath, |
| 733 | pid: existing.pid, |
| 734 | })); |
| 735 | } |
| 736 | |
| 737 | await fsp.rm(lockPath, { force: true }); |
| 738 | return createServeLock(lockPath); |
| 739 | } |
| 740 | |
| 741 | async function createServeLock(lockPath: string): Promise<ServeLock> { |
| 742 | const handle = await fsp.open(lockPath, 'wx'); |
no test coverage detected