MCPcopy
hub / github.com/webpack/webpack / applyCacheDefaults

Function applyCacheDefaults

lib/config/defaults.js:626–695  ·  view source on GitHub ↗
(
	cache,
	{ name, mode, development, cacheUnaffected, compilerIndex, futureDefaults }
)

Source from the content-addressed store, hash-verified

624 * @returns {void}
625 */
626const applyCacheDefaults = (
627 cache,
628 { name, mode, development, cacheUnaffected, compilerIndex, futureDefaults }
629) => {
630 if (cache === false) return;
631 switch (cache.type) {
632 case "filesystem":
633 F(cache, "name", () =>
634 compilerIndex !== undefined
635 ? `${`${name}-${mode}`}__compiler${compilerIndex + 1}__`
636 : `${name}-${mode}`
637 );
638 D(cache, "version", "");
639 F(cache, "cacheDirectory", () => {
640 const cwd = process.cwd();
641 /** @type {string | undefined} */
642 let dir = cwd;
643 for (;;) {
644 try {
645 if (fs.statSync(path.join(dir, "package.json")).isFile()) break;
646 // eslint-disable-next-line no-empty
647 } catch (_err) {}
648 const parent = path.dirname(dir);
649 if (dir === parent) {
650 dir = undefined;
651 break;
652 }
653 dir = parent;
654 }
655 if (!dir) {
656 return path.resolve(cwd, ".cache/webpack");
657 } else if (process.versions.pnp === "1") {
658 return path.resolve(dir, ".pnp/.cache/webpack");
659 } else if (process.versions.pnp === "3") {
660 return path.resolve(dir, ".yarn/.cache/webpack");
661 }
662 return path.resolve(dir, "node_modules/.cache/webpack");
663 });
664 F(cache, "cacheLocation", () =>
665 path.resolve(
666 /** @type {NonNullable<FileCacheOptions["cacheDirectory"]>} */
667 (cache.cacheDirectory),
668 /** @type {NonNullable<FileCacheOptions["name"]>} */ (cache.name)
669 )
670 );
671 D(cache, "hashAlgorithm", futureDefaults ? "xxhash64" : "md4");
672 D(cache, "store", "pack");
673 D(cache, "compression", false);
674 D(cache, "profile", false);
675 D(cache, "idleTimeout", 60000);
676 D(cache, "idleTimeoutForInitialStore", 5000);
677 D(cache, "idleTimeoutAfterLargeChanges", 1000);
678 D(cache, "maxMemoryGenerations", development ? 5 : Infinity);
679 D(cache, "maxAge", 1000 * 60 * 60 * 24 * 60); // 1 month
680 D(cache, "allowCollectingMemory", development);
681 D(cache, "memoryCacheUnaffected", development && cacheUnaffected);
682 D(cache, "readonly", false);
683 D(

Callers 1

Calls 3

FFunction · 0.70
DFunction · 0.70
resolveMethod · 0.65

Tested by

no test coverage detected