mirror of https://github.com/webpack/webpack.git
fix: `JsonExportsDependency` cache
This commit is contained in:
parent
3de7b0d330
commit
a86bff2874
|
@ -19,8 +19,6 @@ const NullDependency = require("./NullDependency");
|
|||
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
||||
/** @typedef {import("../util/Hash")} Hash */
|
||||
|
||||
/** @typedef {{exportsDepth:number}} JsonDependencyOptions */
|
||||
|
||||
/**
|
||||
* @param {number} exportsDepth exportsDepth
|
||||
* @returns {((data: RawJsonData, curDepth?: number) => ExportSpec[] | undefined)} value
|
||||
|
@ -54,12 +52,12 @@ const getExportsWithDepth = exportsDepth =>
|
|||
class JsonExportsDependency extends NullDependency {
|
||||
/**
|
||||
* @param {JsonData} data json data
|
||||
* @param {JsonDependencyOptions} options options
|
||||
* @param {number} exportsDepth the depth of json exports to analyze
|
||||
*/
|
||||
constructor(data, options) {
|
||||
constructor(data, exportsDepth) {
|
||||
super();
|
||||
this.data = data;
|
||||
this.options = options;
|
||||
this.exportsDepth = exportsDepth;
|
||||
}
|
||||
|
||||
get type() {
|
||||
|
@ -73,7 +71,7 @@ class JsonExportsDependency extends NullDependency {
|
|||
*/
|
||||
getExports(moduleGraph) {
|
||||
return {
|
||||
exports: getExportsWithDepth(this.options.exportsDepth)(
|
||||
exports: getExportsWithDepth(this.exportsDepth)(
|
||||
this.data && /** @type {RawJsonData} */ (this.data.get())
|
||||
),
|
||||
dependencies: undefined
|
||||
|
@ -96,6 +94,7 @@ class JsonExportsDependency extends NullDependency {
|
|||
serialize(context) {
|
||||
const { write } = context;
|
||||
write(this.data);
|
||||
write(this.exportsDepth);
|
||||
super.serialize(context);
|
||||
}
|
||||
|
||||
|
@ -105,6 +104,7 @@ class JsonExportsDependency extends NullDependency {
|
|||
deserialize(context) {
|
||||
const { read } = context;
|
||||
this.data = read();
|
||||
this.exportsDepth = read();
|
||||
super.deserialize(context);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,9 +64,7 @@ class JsonParser extends Parser {
|
|||
buildMeta.defaultObject =
|
||||
typeof data === "object" ? "redirect-warn" : false;
|
||||
state.module.addDependency(
|
||||
new JsonExportsDependency(jsonData, {
|
||||
exportsDepth: this.options.exportsDepth
|
||||
})
|
||||
new JsonExportsDependency(jsonData, this.options.exportsDepth)
|
||||
);
|
||||
return state;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue