feat: add readonly flag for filesystem cache

This commit is contained in:
Shipov Mikhail 2021-06-17 12:23:28 +03:00 committed by alexander.akait
parent b330c93e73
commit c3b643aa79
6 changed files with 11 additions and 12 deletions

View File

@ -1027,7 +1027,7 @@ export interface FileCacheOptions {
*/ */
profile?: boolean; 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; readonly?: boolean;
/** /**

View File

@ -1216,6 +1216,8 @@ class PackFileCacheStrategy {
* @returns {Promise<void>} promise * @returns {Promise<void>} promise
*/ */
store(identifier, etag, data) { store(identifier, etag, data) {
if (this.readonly) return Promise.resolve();
return this._getPack().then(pack => { return this._getPack().then(pack => {
pack.set(identifier, etag === null ? null : etag.toString(), data); pack.set(identifier, etag === null ? null : etag.toString(), data);
}); });
@ -1242,16 +1244,11 @@ class PackFileCacheStrategy {
} }
storeBuildDependencies(dependencies) { storeBuildDependencies(dependencies) {
if (this.readonly) return;
this.newBuildDependencies.addAll(dependencies); this.newBuildDependencies.addAll(dependencies);
} }
afterAllStored() { afterAllStored() {
if (this.readonly) {
this.logger.log(`Readonly mode. Skip storing cache.`);
this.packPromise = undefined;
return Promise.resolve();
}
const packPromise = this.packPromise; const packPromise = this.packPromise;
if (packPromise === undefined) return Promise.resolve(); if (packPromise === undefined) return Promise.resolve();
const reportProgress = ProgressPlugin.getReporter(this.compiler); const reportProgress = ProgressPlugin.getReporter(this.compiler);

View File

@ -1255,7 +1255,7 @@
"type": "boolean" "type": "boolean"
}, },
"readonly": { "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" "type": "boolean"
}, },
"store": { "store": {

View File

@ -210,6 +210,7 @@ sum([1,2,3])
}); });
await compile({ entry: `./src/main.js` }); await compile({ entry: `./src/main.js` });
const firstCacheFiles = (await readdir(cachePath)).sort(); const firstCacheFiles = (await readdir(cachePath)).sort();
// cSpell:words Mtimes
const firstMtimes = firstCacheFiles.map( const firstMtimes = firstCacheFiles.map(
f => fs.statSync(path.join(cachePath, f)).mtime f => fs.statSync(path.join(cachePath, f)).mtime
); );
@ -230,6 +231,7 @@ import 'lodash';
expect(cacheFiles).toStrictEqual(firstCacheFiles); expect(cacheFiles).toStrictEqual(firstCacheFiles);
expect( expect(
firstCacheFiles.map(f => fs.statSync(path.join(cachePath, f)).mtime) firstCacheFiles.map(f => fs.statSync(path.join(cachePath, f)).mtime)
// cSpell:words Mtimes
).toStrictEqual(firstMtimes); ).toStrictEqual(firstMtimes);
}, 120000); }, 20000);
}); });

View File

@ -323,13 +323,13 @@ Object {
"cache-readonly": Object { "cache-readonly": Object {
"configs": Array [ "configs": Array [
Object { 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, "multiple": false,
"path": "cache.readonly", "path": "cache.readonly",
"type": "boolean", "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, "multiple": false,
"simpleType": "boolean", "simpleType": "boolean",
}, },

2
types.d.ts vendored
View File

@ -4262,7 +4262,7 @@ declare interface FileCacheOptions {
profile?: boolean; 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; readonly?: boolean;