MCPcopy
hub / github.com/webpack/webpack / _loadEnv

Method _loadEnv

lib/DotenvPlugin.js:367–423  ·  lib/DotenvPlugin.js::DotenvPlugin._loadEnv

* Loads the provided compiler. * @private * @param {Compiler} compiler compiler * @param {ItemCacheFacade} itemCache item cache facade * @param {string} dir directory to read * @returns {Promise<{ parsed: Env, snapshot: Snapshot }>} parsed result and snapshot

(compiler, itemCache, dir)

Source from the content-addressed store, hash-verified

365 * @returns {Promise<{ parsed: Env, snapshot: Snapshot }>} parsed result and snapshot
366 */
367 async _loadEnv(compiler, itemCache, dir) {
368 const fs = /** @type {InputFileSystem} */ (compiler.inputFileSystem);
369 const fileSystemInfo = new FileSystemInfo(fs, {
370 unmanagedPaths: compiler.unmanagedPaths,
371 managedPaths: compiler.managedPaths,
372 immutablePaths: compiler.immutablePaths,
373 hashFunction: compiler.options.output.hashFunction
374 });
375
376 const result = await itemCache.getPromise();
377
378 if (result) {
379 const isSnapshotValid = await new Promise((resolve, reject) => {
380 fileSystemInfo.checkSnapshotValid(result.snapshot, (error, isValid) => {
381 if (error) {
382 reject(error);
383
384 return;
385 }
386
387 resolve(isValid);
388 });
389 });
390
391 if (isSnapshotValid) {
392 return { parsed: result.parsed, snapshot: result.snapshot };
393 }
394 }
395
396 const { parsed, fileDependencies, missingDependencies } =
397 await this._getParsed(
398 fs,
399 dir,
400 /** @type {string} */
401 (compiler.options.mode)
402 );
403
404 const startTime = Date.now();
405 const newSnapshot = await new Promise((resolve, reject) => {
406 fileSystemInfo.createSnapshot(
407 startTime,
408 fileDependencies,
409 null,
410 missingDependencies,
411 class="cm">// `.env` files are build dependencies
412 compiler.options.snapshot.buildDependencies,
413 (err, snapshot) => {
414 if (err) return reject(err);
415 resolve(snapshot);
416 }
417 );
418 });
419
420 await itemCache.storePromise({ parsed, snapshot: newSnapshot });
421
422 return { parsed, snapshot: newSnapshot };
423 }
424

Callers 1

applyMethod · 0.95

Calls 6

checkSnapshotValidMethod · 0.95
_getParsedMethod · 0.95
createSnapshotMethod · 0.95
resolveFunction · 0.85
getPromiseMethod · 0.45
storePromiseMethod · 0.45

Tested by

no test coverage detected