Skip to content

Commit

Permalink
Merge pull request #13708 from webpack/bugfix/crash-unsafe-cache
Browse files Browse the repository at this point in the history
fixes #13691
  • Loading branch information
sokra committed Jul 5, 2021
2 parents 4fb4540 + e6f0989 commit 6bccc34
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/NormalModuleFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,7 @@ class NormalModuleFactory extends ModuleFactory {
if (!unsafeCacheData.has(module)) {
unsafeCacheData.set(module, module.getUnsafeCacheData());
}
this._restoredUnsafeCacheEntries.add(module);
}

callback(null, factoryResult);
Expand Down
4 changes: 2 additions & 2 deletions lib/asset/AssetGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions lib/json/JsonGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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({
Expand Down
5 changes: 5 additions & 0 deletions test/watchCases/cache/unsafe-cache/0/changing-module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import "./unchanged-module.js";
import "./unchanged-module.json";
new URL("./unchanged-module.svg", import.meta.url);

export default "0";
5 changes: 5 additions & 0 deletions test/watchCases/cache/unsafe-cache/0/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import value from "./changing-module";

it("should compile and cleanup correctly", () => {
expect(value).toBe(WATCH_STEP);
});
3 changes: 3 additions & 0 deletions test/watchCases/cache/unsafe-cache/0/proxy-module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import "./unchanged-module.js";
import "./unchanged-module.json";
new URL("./unchanged-module.svg", import.meta.url);
1 change: 1 addition & 0 deletions test/watchCases/cache/unsafe-cache/0/unchanged-module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 42;
1 change: 1 addition & 0 deletions test/watchCases/cache/unsafe-cache/0/unchanged-module.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions test/watchCases/cache/unsafe-cache/0/unchanged-module.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions test/watchCases/cache/unsafe-cache/1/changing-module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import "./unchanged-module.js";
import "./unchanged-module.json";
new URL("./unchanged-module.svg", import.meta.url);

export default "1";
5 changes: 5 additions & 0 deletions test/watchCases/cache/unsafe-cache/2/changing-module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import "./unchanged-module.js";
import "./unchanged-module.json";
new URL("./unchanged-module.svg", import.meta.url);

export default "2";
10 changes: 10 additions & 0 deletions test/watchCases/cache/unsafe-cache/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** @type {import("../../../../").Configuration} */
module.exports = {
mode: "development",
cache: {
type: "memory"
},
module: {
unsafeCache: true
}
};

0 comments on commit 6bccc34

Please sign in to comment.