MCPcopy
hub / github.com/webpack/webpack / expand

Function expand

lib/DotenvPlugin.js:165–196  ·  view source on GitHub ↗

* Expand environment variables in parsed object * ported from https://github.com/motdotla/dotenv-expand * @param {{ parsed: Env, processEnv: Record<string, string | undefined> }} options expand options * @returns {{ parsed: Env }} expanded options

(options)

Source from the content-addressed store, hash-verified

163 * @returns {{ parsed: Env }} expanded options
164 */
165function expand(options) {
166 // for use with progressive expansion
167 const runningParsed = /** @type {Env} */ (Object.create(null));
168 const processEnv = options.processEnv;
169
170 // dotenv.config() ran before this so the assumption is process.env has already been set
171 for (const key in options.parsed) {
172 let value = options.parsed[key];
173
174 // short-circuit scenario: process.env was already set prior to the file value
175 value =
176 Object.prototype.hasOwnProperty.call(processEnv, key) &&
177 processEnv[key] !== value
178 ? /** @type {string} */ (processEnv[key])
179 : expandValue(value, processEnv, runningParsed);
180
181 const resolvedValue = _resolveEscapeSequences(value);
182
183 options.parsed[key] = resolvedValue;
184 // for use with progressive expansion
185 runningParsed[key] = resolvedValue;
186 }
187
188 // Part of `dotenv-expand` code, but we don't need it because of we don't modify `process.env`
189 // for (const processKey in options.parsed) {
190 // if (processEnv) {
191 // processEnv[processKey] = options.parsed[processKey];
192 // }
193 // }
194
195 return options;
196}
197
198/**
199 * Format environment variables as DefinePlugin definitions

Callers 1

_getEnvMethod · 0.85

Calls 4

expandValueFunction · 0.85
_resolveEscapeSequencesFunction · 0.85
createMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected