MCPcopy
hub / github.com/webpack/webpack / apply

Method apply

lib/cache/IdleFileCachePlugin.js:46–244  ·  view source on GitHub ↗

* Applies the plugin by registering its hooks on the compiler. * @param {Compiler} compiler the compiler instance * @returns {void}

(compiler)

Source from the content-addressed store, hash-verified

44 * @returns {void}
45 */
46 apply(compiler) {
47 const strategy = this.strategy;
48 const idleTimeout = this.idleTimeout;
49 const idleTimeoutForInitialStore = Math.min(
50 idleTimeout,
51 this.idleTimeoutForInitialStore
52 );
53 const idleTimeoutAfterLargeChanges = this.idleTimeoutAfterLargeChanges;
54 const resolvedPromise = Promise.resolve();
55
56 let timeSpendInBuild = 0;
57 let timeSpendInStore = 0;
58 let avgTimeSpendInStore = 0;
59
60 /** @type {Map<string | typeof BUILD_DEPENDENCIES_KEY, () => Promise<void | void[]>>} */
61 const pendingIdleTasks = new Map();
62
63 compiler.cache.hooks.store.tap(
64 { name: PLUGIN_NAME, stage: Cache.STAGE_DISK },
65 (identifier, etag, data) => {
66 pendingIdleTasks.set(identifier, () =>
67 strategy.store(identifier, etag, data)
68 );
69 }
70 );
71
72 compiler.cache.hooks.get.tapPromise(
73 { name: PLUGIN_NAME, stage: Cache.STAGE_DISK },
74 (identifier, etag, gotHandlers) => {
75 const restore = () =>
76 strategy.restore(identifier, etag).then((cacheEntry) => {
77 if (cacheEntry === undefined) {
78 gotHandlers.push((result, callback) => {
79 if (result !== undefined) {
80 pendingIdleTasks.set(identifier, () =>
81 strategy.store(identifier, etag, result)
82 );
83 }
84 callback();
85 });
86 } else {
87 return cacheEntry;
88 }
89 });
90 const pendingTask = pendingIdleTasks.get(identifier);
91 if (pendingTask !== undefined) {
92 pendingIdleTasks.delete(identifier);
93 return pendingTask().then(restore);
94 }
95 return restore();
96 }
97 );
98
99 compiler.cache.hooks.storeBuildDependencies.tap(
100 { name: PLUGIN_NAME, stage: Cache.STAGE_DISK },
101 (dependencies) => {
102 pendingIdleTasks.set(BUILD_DEPENDENCIES_KEY, () =>
103 Promise.resolve().then(() =>

Callers

nothing calls this directly

Calls 15

tapMethod · 0.80
getReporterMethod · 0.80
afterAllStoredMethod · 0.80
logMethod · 0.80
resolveMethod · 0.65
restoreFunction · 0.50
fnFunction · 0.50
setMethod · 0.45
storeMethod · 0.45
getMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected