()
| 412 | } |
| 413 | |
| 414 | private readConfig(): ConfigFile | null { |
| 415 | // A process-lifetime cache misses another CLI's opt-out. Read the tiny file |
| 416 | // before recording, persistence and sending, including between HTTP chunks. |
| 417 | let config: ConfigFile | null = null; |
| 418 | try { |
| 419 | const raw = JSON.parse(fs.readFileSync(this.configPath, 'utf8')) as ConfigFile; |
| 420 | if (typeof raw.enabled === 'boolean' && (typeof raw.machine_id === 'string' || |
| 421 | (!raw.enabled && raw.machine_id === null))) config = raw; |
| 422 | } catch { /* absent config retains the documented default */ } |
| 423 | if (this.configCache !== undefined && |
| 424 | (this.configCache?.machine_id !== config?.machine_id || |
| 425 | (this.configCache?.enabled && !config?.enabled))) this.clearPending(); |
| 426 | this.configCache = config; |
| 427 | return config; |
| 428 | } |
| 429 | |
| 430 | private writeConfig(config: ConfigFile): void { |
| 431 | const temp = `${this.configPath}.${process.pid}.${randomUUID()}.tmp`; |
no test coverage detected