@@ -18,20 +18,27 @@ export function getNcurcPath() {
1818 }
1919}
2020
21+ let mergedConfig ;
2122export 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} ;
31+ export function clearCachedConfig ( ) {
32+ mergedConfig = null ;
33+ }
2734
2835export function getConfig ( configType , dir ) {
2936 const configPath = getConfigPath ( configType , dir ) ;
3037 const encryptedConfigPath = configPath + '.gpg' ;
3138 if ( existsSync ( encryptedConfigPath ) ) {
3239 console . warn ( 'Encrypted config detected, spawning gpg to decrypt it...' ) ;
3340 const { status, stdout } =
34- spawnSync ( 'gpg' , [ '--decrypt' , encryptedConfigPath ] ) ;
41+ spawnSync ( process . env . GPG_BIN || 'gpg' , [ '--decrypt' , encryptedConfigPath ] ) ;
3542 if ( status === 0 ) {
3643 return JSON . parse ( stdout . toString ( 'utf-8' ) ) ;
3744 }
@@ -69,7 +76,7 @@ export function writeConfig(configType, obj, dir) {
6976 const tmpFile = path . join ( tmpDir , 'config.json' ) ;
7077 try {
7178 writeJson ( tmpFile , obj ) ;
72- const { status } = spawnSync ( 'gpg' ,
79+ const { status } = spawnSync ( process . env . GPG_BIN || 'gpg' ,
7380 [ '--default-recipient-self' , '--yes' , '--encrypt' , '--output' , encryptedConfigPath , tmpFile ]
7481 ) ;
7582 if ( status !== 0 ) {
0 commit comments