Skip to content

Commit ba6ac9a

Browse files
committed
add cache.idleTimeoutForInitialStore
to allow to force an initial store
1 parent f68d465 commit ba6ac9a

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

declarations/WebpackOptions.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,9 +432,13 @@ export interface FileCacheOptions {
432432
*/
433433
hashAlgorithm?: string;
434434
/**
435-
* Time in ms after which idle period cache storing should happen (only for store: 'pack' or 'idle')
435+
* Time in ms after which idle period the cache storing should happen (only for store: 'pack' or 'idle')
436436
*/
437437
idleTimeout?: number;
438+
/**
439+
* Time in ms after which idle period the initial cache storing should happen (only for store: 'pack' or 'idle')
440+
*/
441+
idleTimeoutForInitialStore?: number;
438442
/**
439443
* Display log info. (debug: all access and errors with stack trace, verbose: all access, info: all write access, warning: only failed serialization)
440444
*/

lib/cache/FileCachePlugin.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,11 @@ class FileCachePlugin {
126126
? { debug: 4, verbose: 3, info: 2, warning: 1 }[this.options.loglevel]
127127
: 0;
128128
const store = this.options.store || "pack";
129-
const idleTimeout = this.options.idleTimeout || 0;
129+
const idleTimeout = this.options.idleTimeout || 10000;
130+
const idleTimeoutForInitialStore = Math.min(
131+
idleTimeout,
132+
this.options.idleTimeoutForInitialStore || 0
133+
);
130134

131135
const resolvedPromise = Promise.resolve();
132136

@@ -345,6 +349,7 @@ class FileCachePlugin {
345349

346350
let currentIdlePromise;
347351
let isIdle = false;
352+
let isInitialStore = true;
348353
const processIdleTasks = () => {
349354
if (isIdle) {
350355
if (pendingPromiseFactories.size > 0) {
@@ -359,10 +364,16 @@ class FileCachePlugin {
359364
currentIdlePromise = Promise.all(promises).then(() => {
360365
currentIdlePromise = undefined;
361366
});
362-
currentIdlePromise.then(processIdleTasks);
363-
} else if (store === "pack") {
367+
currentIdlePromise.then(() => {
368+
// Allow to exit the process inbetween
369+
setTimeout(processIdleTasks, 0).unref();
370+
});
371+
return;
372+
}
373+
if (store === "pack") {
364374
currentIdlePromise = serializePack();
365375
}
376+
isInitialStore = false;
366377
}
367378
};
368379
let idleTimer = undefined;
@@ -371,7 +382,8 @@ class FileCachePlugin {
371382
idleTimer = undefined;
372383
isIdle = true;
373384
resolvedPromise.then(processIdleTasks);
374-
}, idleTimeout);
385+
}, isInitialStore ? idleTimeoutForInitialStore : idleTimeout);
386+
idleTimer.unref();
375387
});
376388
compiler.cache.hooks.endIdle.tap("FileCachePlugin", () => {
377389
if (idleTimer) {

schemas/WebpackOptions.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,12 @@
169169
"type": "string"
170170
},
171171
"idleTimeout": {
172-
"description": "Time in ms after which idle period cache storing should happen (only for store: 'pack' or 'idle')",
172+
"description": "Time in ms after which idle period the cache storing should happen (only for store: 'pack' or 'idle')",
173+
"type": "number",
174+
"minimum": 0
175+
},
176+
"idleTimeoutForInitialStore": {
177+
"description": "Time in ms after which idle period the initial cache storing should happen (only for store: 'pack' or 'idle')",
173178
"type": "number",
174179
"minimum": 0
175180
},

0 commit comments

Comments
 (0)