MCPcopy
hub / github.com/webpack/webpack / _getEnv

Method _getEnv

lib/DotenvPlugin.js:432–454  ·  view source on GitHub ↗

* Generate env variables * @private * @param {Prefix} prefixes expose only environment variables that start with these prefixes * @param {Env} parsed parsed env variables * @returns {Env} env variables

(prefixes, parsed)

Source from the content-addressed store, hash-verified

430 * @returns {Env} env variables
431 */
432 _getEnv(prefixes, parsed) {
433 // Always expand environment variables (like Vite does)
434 // Make a copy of process.env so that dotenv-expand doesn't modify global process.env
435 const processEnv = { ...process.env };
436 expand({ parsed, processEnv });
437 const env = /** @type {Env} */ (Object.create(null));
438
439 // Get all keys from parser and process.env
440 const keys = [...Object.keys(parsed), ...Object.keys(process.env)];
441
442 // Prioritize actual env variables from `process.env`, fallback to parsed
443 for (const key of keys) {
444 if (prefixes.some((prefix) => key.startsWith(prefix))) {
445 env[key] =
446 Object.prototype.hasOwnProperty.call(process.env, key) &&
447 process.env[key]
448 ? process.env[key]
449 : parsed[key];
450 }
451 }
452
453 return env;
454 }
455
456 /**
457 * Load a file with proper path resolution

Callers 1

applyMethod · 0.95

Calls 4

expandFunction · 0.85
keysMethod · 0.65
createMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected