(filePath: string)
| 104 | } |
| 105 | |
| 106 | function readEntryFile(filePath: string): RegistryEntry | null { |
| 107 | try { |
| 108 | const raw = fs.readFileSync(filePath, "utf-8"); |
| 109 | const data = JSON.parse(raw) as Partial<RegistryEntry>; |
| 110 | if ( |
| 111 | typeof data?.dir !== "string" || |
| 112 | typeof data?.name !== "string" || |
| 113 | typeof data?.version !== "string" || |
| 114 | typeof data?.port !== "number" || |
| 115 | (typeof data?.pid !== "number" && data?.pid !== null) || |
| 116 | (data?.status !== "running" && data?.status !== "stopped") |
| 117 | ) { |
| 118 | return null; |
| 119 | } |
| 120 | |
| 121 | return { |
| 122 | dir: canonicalizeDir(data.dir), |
| 123 | name: data.name, |
| 124 | version: data.version, |
| 125 | port: data.port, |
| 126 | pid: data.pid, |
| 127 | status: data.status, |
| 128 | startedAt: data.startedAt, |
| 129 | stoppedAt: data.stoppedAt, |
| 130 | updatedAt: data.updatedAt, |
| 131 | }; |
| 132 | } catch { |
| 133 | return null; |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | function createTmpPath(entryPath: string): string { |
| 138 | const suffix = `${process.pid}.${Date.now()}.${Math.random().toString(16).slice(2)}`; |
no test coverage detected