Persist root CA only after trust-store install succeeds (fixes #118)
Fixes #118.
Problem
installCertificateAuthority writes the root CA cert + encrypted key to their canonical paths before attempting the trust-store install. If addToTrustStores fails or is declined (e.g. the Windows "Security Warning" → No), the on-disk state remains and certificateFor's !existsSync(rootCAKeyPath) guard skips re-installation forever. The browser stays broken with NET::ERR_CERT_AUTHORITY_INVALID and devcert never re-prompts. See #118 for the full repro.
Fix
src/certificate-authority.ts: generate the cert + key into temp paths, runaddToTrustStoresfirst, and write to the canonical paths only after the trust install succeeds. If it throws, clean up the temp files and propagate.src/platforms/win32.ts: rethrow whencertutil -addstorefails. The current swallow is what hides the user's "No" click from the caller — without rethrowing, the reorder in (1) doesn't help, because Windows would still report success. The Firefox open-failure tolerance is preserved (most users don't have Firefox).
I considered the alternative of leaving the swallow in place and using certutil -verifystore -user root <fingerprint> to detect missing-from-store after the fact. Rethrowing the underlying error is simpler, surfaces the real failure to the caller, and matches the existing macOS/Linux behavior where run('sudo', [...]) already propagates.
Cross-platform impact
addToTrustStores on all three platforms reads the cert from its path argument as a one-time input (no assumptions about the path being canonical):
- macOS (
security add-trusted-cert ... <path>) - Linux (
cp <path> /usr/local/share/ca-certificates/devcert.crt) - Windows (
certutil -addstore -user root <path>)
So passing a temp path is safe everywhere. The removeFromTrustStores calls in uninstall() look up by the existing canonical path / by subject name, so the initial uninstall() at the top of installCertificateAuthority is unaffected.
Tests
The package's npm test script is a stub (echo Ha.; exit 1) and there are no test files, so no test changes. npm run build passes.