@@ -4,7 +4,7 @@ import os from 'node:os';
44import { readJson , writeJson } from './file.js' ;
55import { existsSync , mkdtempSync , rmSync } from 'node:fs' ;
66import { spawnSync } from 'node:child_process' ;
7- import { runSync } from './run.js' ;
7+ import { forceRunAsync , runSync } from './run.js' ;
88
99export const GLOBAL_CONFIG = Symbol ( 'globalConfig' ) ;
1010export const PROJECT_CONFIG = Symbol ( 'projectConfig' ) ;
@@ -33,6 +33,15 @@ export function clearCachedConfig() {
3333 mergedConfig = null ;
3434}
3535
36+ export async function encryptValue ( input ) {
37+ console . warn ( 'Spawning gpg to encrypt the config value' ) ;
38+ return forceRunAsync ( process . env . GPG_BIN || 'gpg' , [ '--default-recipient-self' , '--encrypt' , '--armor' ] , {
39+ captureStdout : true ,
40+ ignoreFailure : false ,
41+ spawnArgs : { input }
42+ } ) ;
43+ }
44+
3645function setOwnProperty ( target , key , value ) {
3746 return Object . defineProperty ( target , key , {
3847 __proto__ : null ,
@@ -42,13 +51,13 @@ function setOwnProperty(target, key, value) {
4251 } ) ;
4352}
4453function addEncryptedPropertyGetter ( target , key , input ) {
45- if ( input . startsWith ( '-----BEGIN PGP MESSAGE-----\n' ) ) {
54+ if ( input . startsWith ?. ( '-----BEGIN PGP MESSAGE-----\n' ) ) {
4655 return Object . defineProperty ( target , key , {
4756 __proto__ : null ,
4857 configurable : true ,
4958 get ( ) {
5059 console . warn ( `The config value for ${ key } is encrypted, spawning gpg to decrypt it...` ) ;
51- const value = runSync ( 'gpg' , [ '--decrypt' ] , { input } ) ;
60+ const value = runSync ( process . env . GPG_BIN || 'gpg' , [ '--decrypt' ] , { input } ) ;
5261 setOwnProperty ( target , key , value ) ;
5362 return value ;
5463 } ,
0 commit comments