mirror of https://github.com/webpack/webpack.git
feat: add readonly flag for filesystem cache
This commit is contained in:
parent
b330c93e73
commit
c3b643aa79
|
@ -1027,7 +1027,7 @@ export interface FileCacheOptions {
|
|||
*/
|
||||
profile?: boolean;
|
||||
/**
|
||||
* Set filesystem cache in readonly mode. Main usage is for parallel webpack builds with warmed up cache.
|
||||
* Enable/disable readonly mode.
|
||||
*/
|
||||
readonly?: boolean;
|
||||
/**
|
||||
|
|
|
@ -1216,6 +1216,8 @@ class PackFileCacheStrategy {
|
|||
* @returns {Promise<void>} promise
|
||||
*/
|
||||
store(identifier, etag, data) {
|
||||
if (this.readonly) return Promise.resolve();
|
||||
|
||||
return this._getPack().then(pack => {
|
||||
pack.set(identifier, etag === null ? null : etag.toString(), data);
|
||||
});
|
||||
|
@ -1242,16 +1244,11 @@ class PackFileCacheStrategy {
|
|||
}
|
||||
|
||||
storeBuildDependencies(dependencies) {
|
||||
if (this.readonly) return;
|
||||
this.newBuildDependencies.addAll(dependencies);
|
||||
}
|
||||
|
||||
afterAllStored() {
|
||||
if (this.readonly) {
|
||||
this.logger.log(`Readonly mode. Skip storing cache.`);
|
||||
this.packPromise = undefined;
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
const packPromise = this.packPromise;
|
||||
if (packPromise === undefined) return Promise.resolve();
|
||||
const reportProgress = ProgressPlugin.getReporter(this.compiler);
|
||||
|
|
|
@ -1255,7 +1255,7 @@
|
|||
"type": "boolean"
|
||||
},
|
||||
"readonly": {
|
||||
"description": "Set filesystem cache in readonly mode. Main usage is for parallel webpack builds with warmed up cache.",
|
||||
"description": "Enable/disable readonly mode.",
|
||||
"type": "boolean"
|
||||
},
|
||||
"store": {
|
||||
|
|
|
@ -210,6 +210,7 @@ sum([1,2,3])
|
|||
});
|
||||
await compile({ entry: `./src/main.js` });
|
||||
const firstCacheFiles = (await readdir(cachePath)).sort();
|
||||
// cSpell:words Mtimes
|
||||
const firstMtimes = firstCacheFiles.map(
|
||||
f => fs.statSync(path.join(cachePath, f)).mtime
|
||||
);
|
||||
|
@ -230,6 +231,7 @@ import 'lodash';
|
|||
expect(cacheFiles).toStrictEqual(firstCacheFiles);
|
||||
expect(
|
||||
firstCacheFiles.map(f => fs.statSync(path.join(cachePath, f)).mtime)
|
||||
// cSpell:words Mtimes
|
||||
).toStrictEqual(firstMtimes);
|
||||
}, 120000);
|
||||
}, 20000);
|
||||
});
|
||||
|
|
|
@ -323,13 +323,13 @@ Object {
|
|||
"cache-readonly": Object {
|
||||
"configs": Array [
|
||||
Object {
|
||||
"description": "Set filesystem cache in readonly mode. Main usage is for parallel webpack builds with warmed up cache.",
|
||||
"description": "Enable/disable readonly mode.",
|
||||
"multiple": false,
|
||||
"path": "cache.readonly",
|
||||
"type": "boolean",
|
||||
},
|
||||
],
|
||||
"description": "Set filesystem cache in readonly mode. Main usage is for parallel webpack builds with warmed up cache.",
|
||||
"description": "Enable/disable readonly mode.",
|
||||
"multiple": false,
|
||||
"simpleType": "boolean",
|
||||
},
|
||||
|
|
|
@ -4262,7 +4262,7 @@ declare interface FileCacheOptions {
|
|||
profile?: boolean;
|
||||
|
||||
/**
|
||||
* Set filesystem cache in readonly mode. Main usage is for parallel webpack builds with warmed up cache.
|
||||
* Enable/disable readonly mode.
|
||||
*/
|
||||
readonly?: boolean;
|
||||
|
||||
|
|
Loading…
Reference in New Issue