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;
|
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;
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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": {
|
||||||
|
|
|
@ -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);
|
||||||
});
|
});
|
||||||
|
|
|
@ -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",
|
||||||
},
|
},
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue