Merge pull request #13708 from webpack/bugfix/crash-unsafe-cache

fixes #13691
This commit is contained in:
Tobias Koppers 2021-07-05 13:43:20 +02:00 committed by GitHub
commit 6bccc34eab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 41 additions and 4 deletions

View File

@ -766,6 +766,7 @@ class NormalModuleFactory extends ModuleFactory {
if (!unsafeCacheData.has(module)) {
unsafeCacheData.set(module, module.getUnsafeCacheData());
}
this._restoredUnsafeCacheEntries.add(module);
}
callback(null, factoryResult);

View File

@ -265,7 +265,7 @@ class AssetGenerator extends Generator {
* @returns {Set<string>} available types (do not mutate)
*/
getTypes(module) {
if (module.buildInfo.dataUrl || this.emit === false) {
if ((module.buildInfo && module.buildInfo.dataUrl) || this.emit === false) {
return JS_TYPES;
} else {
return JS_AND_ASSET_TYPES;
@ -289,7 +289,7 @@ class AssetGenerator extends Generator {
return originalSource.size();
}
default:
if (module.buildInfo.dataUrl) {
if (module.buildInfo && module.buildInfo.dataUrl) {
const originalSource = module.originalSource();
if (!originalSource) {

View File

@ -116,7 +116,7 @@ class JsonGenerator extends Generator {
* @returns {number} estimate size of the module
*/
getSize(module, type) {
let data = module.buildInfo.jsonData;
let data = module.buildInfo && module.buildInfo.jsonData;
if (!data) return 0;
return stringifySafe(data).length + 10;
}
@ -145,7 +145,7 @@ class JsonGenerator extends Generator {
concatenationScope
}
) {
const data = module.buildInfo.jsonData;
const data = module.buildInfo && module.buildInfo.jsonData;
if (data === undefined) {
return new RawSource(
runtimeTemplate.missingModuleStatement({

View File

@ -0,0 +1,5 @@
import "./unchanged-module.js";
import "./unchanged-module.json";
new URL("./unchanged-module.svg", import.meta.url);
export default "0";

View File

@ -0,0 +1,5 @@
import value from "./changing-module";
it("should compile and cleanup correctly", () => {
expect(value).toBe(WATCH_STEP);
});

View File

@ -0,0 +1,3 @@
import "./unchanged-module.js";
import "./unchanged-module.json";
new URL("./unchanged-module.svg", import.meta.url);

View File

@ -0,0 +1 @@
export default 42;

View File

@ -0,0 +1 @@
{}

View File

@ -0,0 +1 @@
<svg></svg>

After

Width:  |  Height:  |  Size: 12 B

View File

@ -0,0 +1,5 @@
import "./unchanged-module.js";
import "./unchanged-module.json";
new URL("./unchanged-module.svg", import.meta.url);
export default "1";

View File

@ -0,0 +1,5 @@
import "./unchanged-module.js";
import "./unchanged-module.json";
new URL("./unchanged-module.svg", import.meta.url);
export default "2";

View File

@ -0,0 +1,10 @@
/** @type {import("../../../../").Configuration} */
module.exports = {
mode: "development",
cache: {
type: "memory"
},
module: {
unsafeCache: true
}
};