fix(install): address review feedback on ensureNvmCaCertsInDotEnv

- Make platform/execPath injectable for testability (consistent with
  service-env builders)
- Use regex anchor for NODE_EXTRA_CA_CERTS check so commented-out lines
  don't prevent writing the active entry
This commit is contained in:
GodsBoy 2026-03-20 19:01:41 +02:00
parent 4c8fd51664
commit 7345a70f86

View File

@ -142,8 +142,12 @@ function ensureNvmCaCertsInDotEnv(params: {
env: Record<string, string | undefined>;
json: boolean;
warnings: string[];
platform?: NodeJS.Platform;
execPath?: string;
}): void {
if (process.platform !== "linux" || !isNvmNode(params.env, process.execPath)) {
const platform = params.platform ?? process.platform;
const execPath = params.execPath ?? process.execPath;
if (platform !== "linux" || !isNvmNode(params.env, execPath)) {
return;
}
if (params.env.NODE_EXTRA_CA_CERTS) {
@ -158,7 +162,7 @@ function ensureNvmCaCertsInDotEnv(params: {
const stateDir = resolveGatewayStateDir(params.env);
const envFile = path.join(stateDir, ".env");
const existing = fs.existsSync(envFile) ? fs.readFileSync(envFile, "utf8") : "";
if (existing.includes("NODE_EXTRA_CA_CERTS")) {
if (/^NODE_EXTRA_CA_CERTS=/m.test(existing)) {
return;
}
const line = `NODE_EXTRA_CA_CERTS=${caBundle}\n`;