Skip to content

Commit 973585c

Browse files
committed
fix: spawning of gpg to read config
1 parent 9b642b0 commit 973585c

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

lib/config.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@ export function getNcurcPath() {
1818
}
1919
}
2020

21+
let mergedConfig;
2122
export function getMergedConfig(dir, home) {
22-
const globalConfig = getConfig(GLOBAL_CONFIG, home);
23-
const projectConfig = getConfig(PROJECT_CONFIG, dir);
24-
const localConfig = getConfig(LOCAL_CONFIG, dir);
25-
return Object.assign(globalConfig, projectConfig, localConfig);
23+
if (mergedConfig == null) {
24+
const globalConfig = getConfig(GLOBAL_CONFIG, home);
25+
const projectConfig = getConfig(PROJECT_CONFIG, dir);
26+
const localConfig = getConfig(LOCAL_CONFIG, dir);
27+
mergedConfig = Object.assign(globalConfig, projectConfig, localConfig);
28+
}
29+
return mergedConfig;
2630
};
2731

2832
export function getConfig(configType, dir) {
@@ -31,7 +35,7 @@ export function getConfig(configType, dir) {
3135
if (existsSync(encryptedConfigPath)) {
3236
console.warn('Encrypted config detected, spawning gpg to decrypt it...');
3337
const { status, stdout } =
34-
spawnSync('gpg', ['--decrypt', encryptedConfigPath]);
38+
spawnSync(process.env.GPG_BIN || 'gpg', ['--decrypt', encryptedConfigPath]);
3539
if (status === 0) {
3640
return JSON.parse(stdout.toString('utf-8'));
3741
}
@@ -69,7 +73,7 @@ export function writeConfig(configType, obj, dir) {
6973
const tmpFile = path.join(tmpDir, 'config.json');
7074
try {
7175
writeJson(tmpFile, obj);
72-
const { status } = spawnSync('gpg',
76+
const { status } = spawnSync(process.env.GPG_BIN || 'gpg',
7377
['--default-recipient-self', '--yes', '--encrypt', '--output', encryptedConfigPath, tmpFile]
7478
);
7579
if (status !== 0) {

0 commit comments

Comments
 (0)