@@ -137,30 +137,40 @@ const getEnvSourceName = (source) => {
137137 return printFn ( name )
138138}
139139
140- // Takes a set of environment variables in the format provided by @netlify /config, augments it with variables from both
141- // dot-env files and the process itself, and injects into `process.env`.
142- export const injectEnvVariables = async ( { devConfig, env, site } ) => {
143- const environment = new Map ( Object . entries ( env ) )
140+ /**
141+ * @param {{devConfig: any, env: Record<string, { sources: string[], value: string}>, site: any} } param0
142+ * @returns {Promise<Record<string, { sources: string[], value: string}>> }
143+ */
144+ export const getDotEnvVariables = async ( { devConfig, env, site } ) => {
144145 const dotEnvFiles = await loadDotEnvFiles ( { envFiles : devConfig . envFiles , projectDir : site . root } )
145-
146146 dotEnvFiles . forEach ( ( { env : fileEnv , file } ) => {
147+ const newSourceName = `${ file } file`
148+
147149 Object . keys ( fileEnv ) . forEach ( ( key ) => {
148- const newSourceName = `${ file } file`
149- const sources = environment . has ( key ) ? [ newSourceName , ...environment . get ( key ) . sources ] : [ newSourceName ]
150+ const sources = key in env ? [ newSourceName , ...env [ key ] . sources ] : [ newSourceName ]
150151
151152 if ( sources . includes ( 'internal' ) ) {
152153 return
153154 }
154155
155- environment . set ( key , {
156+ env [ key ] = {
156157 sources,
157158 value : fileEnv [ key ] ,
158- } )
159+ }
159160 } )
160161 } )
161162
163+ return env
164+ }
165+
166+ /**
167+ * Takes a set of environment variables in the format provided by @netlify/config and injects them into `process.env`
168+ * @param {Record<string, { sources: string[], value: string}> } env
169+ * @return {void }
170+ */
171+ export const injectEnvVariables = ( env ) => {
162172 // eslint-disable-next-line fp/no-loops
163- for ( const [ key , variable ] of environment ) {
173+ for ( const [ key , variable ] of Object . entries ( env ) ) {
164174 const existsInProcess = process . env [ key ] !== undefined
165175 const [ usedSource , ...overriddenSources ] = existsInProcess ? [ 'process' , ...variable . sources ] : variable . sources
166176 const usedSourceName = getEnvSourceName ( usedSource )
0 commit comments