avoid copying source types and sizes cache from unsafe cache to cached module
fixes #13827 avoid pre-computing source types and sizes on cleanup for not-built modules (e. g. from unsafe cache) improve eror message when asset rendering fails
This commit is contained in:
parent
937957fc54
commit
cdc9efefbe
|
@ -350,18 +350,20 @@ class NormalModule extends Module {
|
|||
this.resource = m.resource;
|
||||
this.matchResource = m.matchResource;
|
||||
this.loaders = m.loaders;
|
||||
this._sourceTypes = m._sourceTypes;
|
||||
this._sourceSizes = m._sourceSizes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assuming this module is in the cache. Remove internal references to allow freeing some memory.
|
||||
*/
|
||||
cleanupForCache() {
|
||||
// Make sure to cache types and sizes before cleanup
|
||||
if (this._sourceTypes === undefined) this.getSourceTypes();
|
||||
for (const type of this._sourceTypes) {
|
||||
this.size(type);
|
||||
// Make sure to cache types and sizes before cleanup when this module has been built
|
||||
// They are accessed by the stats and we don't want them to crash after cleanup
|
||||
// TODO reconsider this for webpack 6
|
||||
if (this.buildInfo) {
|
||||
if (this._sourceTypes === undefined) this.getSourceTypes();
|
||||
for (const type of this._sourceTypes) {
|
||||
this.size(type);
|
||||
}
|
||||
}
|
||||
super.cleanupForCache();
|
||||
this.parser = undefined;
|
||||
|
|
|
@ -172,24 +172,29 @@ class AssetModulesPlugin {
|
|||
);
|
||||
if (modules) {
|
||||
for (const module of modules) {
|
||||
const codeGenResult = codeGenerationResults.get(
|
||||
module,
|
||||
chunk.runtime
|
||||
);
|
||||
result.push({
|
||||
render: () => codeGenResult.sources.get(type),
|
||||
filename:
|
||||
module.buildInfo.filename ||
|
||||
codeGenResult.data.get("filename"),
|
||||
info:
|
||||
module.buildInfo.assetInfo ||
|
||||
codeGenResult.data.get("assetInfo"),
|
||||
auxiliary: true,
|
||||
identifier: `assetModule${chunkGraph.getModuleId(module)}`,
|
||||
hash:
|
||||
module.buildInfo.fullContentHash ||
|
||||
codeGenResult.data.get("fullContentHash")
|
||||
});
|
||||
try {
|
||||
const codeGenResult = codeGenerationResults.get(
|
||||
module,
|
||||
chunk.runtime
|
||||
);
|
||||
result.push({
|
||||
render: () => codeGenResult.sources.get(type),
|
||||
filename:
|
||||
module.buildInfo.filename ||
|
||||
codeGenResult.data.get("filename"),
|
||||
info:
|
||||
module.buildInfo.assetInfo ||
|
||||
codeGenResult.data.get("assetInfo"),
|
||||
auxiliary: true,
|
||||
identifier: `assetModule${chunkGraph.getModuleId(module)}`,
|
||||
hash:
|
||||
module.buildInfo.fullContentHash ||
|
||||
codeGenResult.data.get("fullContentHash")
|
||||
});
|
||||
} catch (e) {
|
||||
e.message += `\nduring rendering of asset ${module.identifier()}`;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -235,7 +235,7 @@ const describeCases = config => {
|
|||
rimraf.sync(outputDirectory);
|
||||
fs.mkdirSync(outputDirectory, { recursive: true });
|
||||
const deprecationTracker = deprecationTracking.start();
|
||||
require("..")(options, (err, stats) => {
|
||||
const onCompiled = (err, stats) => {
|
||||
const deprecations = deprecationTracker();
|
||||
if (err) return handleFatalError(err, done);
|
||||
const statOptions = {
|
||||
|
@ -570,7 +570,21 @@ const describeCases = config => {
|
|||
done();
|
||||
})
|
||||
.catch(done);
|
||||
});
|
||||
};
|
||||
if (config.cache) {
|
||||
const compiler = require("..")(options);
|
||||
compiler.run(err => {
|
||||
if (err) return handleFatalError(err, done);
|
||||
compiler.run((error, stats) => {
|
||||
compiler.close(err => {
|
||||
if (err) return handleFatalError(err, done);
|
||||
onCompiled(error, stats);
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
require("..")(options, onCompiled);
|
||||
}
|
||||
}, 30000);
|
||||
|
||||
const {
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
import url from "package";
|
||||
|
||||
it("should create a data url", () => {
|
||||
expect(url.protocol).toBe("data:");
|
||||
});
|
1
test/configCases/asset-modules/unsafe-cache-13827/node_modules/package/file.svg
generated
vendored
Normal file
1
test/configCases/asset-modules/unsafe-cache-13827/node_modules/package/file.svg
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 600 600"><title>icon-square-small</title><path fill="#FFF" d="M300 .1L565 150v299.9L300 599.8 35 449.9V150z"/><path fill="#8ED6FB" d="M517.7 439.5L308.8 557.8v-92L439 394.1l78.7 45.4zm14.3-12.9V179.4l-76.4 44.1v159l76.4 44.1zM81.5 439.5l208.9 118.2v-92l-130.2-71.6-78.7 45.4zm-14.3-12.9V179.4l76.4 44.1v159l-76.4 44.1zm8.9-263.2L290.4 42.2v89l-137.3 75.5-1.1.6-75.9-43.9zm446.9 0L308.8 42.2v89L446 206.8l1.1.6 75.9-44z"/><path fill="#1C78C0" d="M290.4 444.8L162 374.1V234.2l128.4 74.1v136.5zm18.4 0l128.4-70.6v-140l-128.4 74.1v136.5zM299.6 303zm-129-85l129-70.9L428.5 218l-128.9 74.4-129-74.4z"/></svg>
|
After Width: | Height: | Size: 656 B |
1
test/configCases/asset-modules/unsafe-cache-13827/node_modules/package/index.js
generated
vendored
Normal file
1
test/configCases/asset-modules/unsafe-cache-13827/node_modules/package/index.js
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
export default new URL("file.svg", import.meta.url);
|
|
@ -0,0 +1,12 @@
|
|||
/** @type {import("../../../../").Configuration} */
|
||||
module.exports = {
|
||||
mode: "development",
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
dependency: "url",
|
||||
type: "asset"
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue