Skip to content

Commit 543e905

Browse files
committed
fix(dependency): Add webpack 5 specific serialization logic
For caching to work in webpack 5, these little additions are needed. I adapted from webpack source while testing against https://github.com/umpox/storybook-repod. Related to storybookjs/storybook#15702.
1 parent e4aa1bf commit 543e905

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

src/dependency.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import makeSerializable from "webpack/lib/util/makeSerializable.js";
99
// @ts-ignore: What's the right way to refer to this one?
1010
import NullDependency from "webpack/lib/dependencies/NullDependency.js";
1111

12+
// This won't be needed when only webpack 5+ can be supported. Patching for now.
13+
type Context = { write: (a: string) => void; read: () => string };
14+
1215
class DocGenDependency extends NullDependency {
1316
public codeBlock: string;
1417

@@ -18,9 +21,27 @@ class DocGenDependency extends NullDependency {
1821
this.codeBlock = codeBlock;
1922
}
2023

24+
get type(): string {
25+
return "docgen";
26+
}
27+
28+
getModuleEvaluationSideEffectsState(): boolean {
29+
return false;
30+
}
31+
2132
updateHash: webpack.dependencies.NullDependency["updateHash"] = (hash) => {
2233
hash.update(this.codeBlock);
2334
};
35+
36+
serialize(context: Context): void {
37+
const { write } = context;
38+
write(this.codeBlock);
39+
}
40+
41+
deserialize(context: Context): void {
42+
const { read } = context;
43+
this.codeBlock = read();
44+
}
2445
}
2546

2647
makeSerializable(

0 commit comments

Comments
 (0)