From 973585cb8253e19899417ae75c5b6c9b7308440f Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sun, 12 Oct 2025 23:05:07 +0200 Subject: [PATCH 1/2] fix: spawning of `gpg` to read config --- lib/config.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/config.js b/lib/config.js index 6703ec87..c94e28a2 100644 --- a/lib/config.js +++ b/lib/config.js @@ -18,11 +18,15 @@ export function getNcurcPath() { } } +let mergedConfig; export function getMergedConfig(dir, home) { - const globalConfig = getConfig(GLOBAL_CONFIG, home); - const projectConfig = getConfig(PROJECT_CONFIG, dir); - const localConfig = getConfig(LOCAL_CONFIG, dir); - return Object.assign(globalConfig, projectConfig, localConfig); + if (mergedConfig == null) { + const globalConfig = getConfig(GLOBAL_CONFIG, home); + const projectConfig = getConfig(PROJECT_CONFIG, dir); + const localConfig = getConfig(LOCAL_CONFIG, dir); + mergedConfig = Object.assign(globalConfig, projectConfig, localConfig); + } + return mergedConfig; }; export function getConfig(configType, dir) { @@ -31,7 +35,7 @@ export function getConfig(configType, dir) { if (existsSync(encryptedConfigPath)) { console.warn('Encrypted config detected, spawning gpg to decrypt it...'); const { status, stdout } = - spawnSync('gpg', ['--decrypt', encryptedConfigPath]); + spawnSync(process.env.GPG_BIN || 'gpg', ['--decrypt', encryptedConfigPath]); if (status === 0) { return JSON.parse(stdout.toString('utf-8')); } @@ -69,7 +73,7 @@ export function writeConfig(configType, obj, dir) { const tmpFile = path.join(tmpDir, 'config.json'); try { writeJson(tmpFile, obj); - const { status } = spawnSync('gpg', + const { status } = spawnSync(process.env.GPG_BIN || 'gpg', ['--default-recipient-self', '--yes', '--encrypt', '--output', encryptedConfigPath, tmpFile] ); if (status !== 0) { From 926f90da458d20174b2252778cd956f1c604e479 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Mon, 13 Oct 2025 12:24:05 +0200 Subject: [PATCH 2/2] fixup! fix: spawning of `gpg` to read config --- lib/auth.js | 3 ++- lib/config.js | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/auth.js b/lib/auth.js index a0cf5b4a..ffabe13a 100644 --- a/lib/auth.js +++ b/lib/auth.js @@ -3,7 +3,7 @@ import { ClientRequest } from 'node:http'; import ghauth from 'ghauth'; -import { getMergedConfig, getNcurcPath } from './config.js'; +import { clearCachedConfig, getMergedConfig, getNcurcPath } from './config.js'; export default lazy(auth); @@ -89,6 +89,7 @@ async function auth( mode: 0o600 /* owner read/write */ }); // Try again reading the file + clearCachedConfig(); ({ username, token } = getMergedConfig()); } check(username, token); diff --git a/lib/config.js b/lib/config.js index c94e28a2..1b34b5c5 100644 --- a/lib/config.js +++ b/lib/config.js @@ -28,6 +28,9 @@ export function getMergedConfig(dir, home) { } return mergedConfig; }; +export function clearCachedConfig() { + mergedConfig = null; +} export function getConfig(configType, dir) { const configPath = getConfigPath(configType, dir);