@@ -8,7 +8,7 @@ const execPromised = promisify(exec)
88
99const axios = require ( 'axios' )
1010
11- const { decryptValue } = require ( '../../../db/utils' )
11+ const { encryptValue , decryptValue } = require ( '../../../db/utils' )
1212
1313async function cloneRepository ( url , branch , workingDir ) {
1414 try {
@@ -119,6 +119,10 @@ module.exports.init = async function (app) {
119119 }
120120 const result = await app . db . controllers . Snapshot . exportSnapshot ( snapshot , exportOptions )
121121 const snapshotExport = app . db . views . ProjectSnapshot . snapshotExport ( result )
122+ if ( snapshotExport . settings ?. settings ?. palette ?. npmrc ) {
123+ const enc = encryptValue ( repoOptions . credentialSecret , snapshotExport . settings . settings ?. palette ?. npmrc )
124+ snapshotExport . settings . settings . palette . npmrc = { $ : enc }
125+ }
122126 const snapshotFile = path . join ( workingDir , repoOptions . path || 'snapshot.json' ) . replace ( / " / g, '' )
123127 await fs . writeFile ( snapshotFile , JSON . stringify ( snapshotExport , null , 4 ) )
124128
@@ -202,6 +206,12 @@ module.exports.init = async function (app) {
202206 }
203207 } )
204208 }
209+ if ( snapshot . settings ?. settings ?. palette ?. npmrc ) {
210+ const npmrc = snapshot . settings . settings . palette . npmrc
211+ if ( typeof npmrc === 'object' && npmrc . $ ) {
212+ snapshot . settings . settings . palette . npmrc = decryptValue ( repoOptions . credentialSecret , npmrc . $ )
213+ }
214+ }
205215 return snapshot
206216 } catch ( err ) {
207217 throw new Error ( 'Failed to read snapshot file: ' + err . message )
0 commit comments