@@ -20,12 +20,12 @@ import { LoaderOptions } from "./types";
2020
2121class DocGenDependency extends NullDependency {
2222 public static Template : NullDependency . Template ;
23- private componentDocs : docGen . ComponentDoc [ ] ;
23+ private codeBlock : string ;
2424
25- constructor ( request : string , componentDocs : docGen . ComponentDoc [ ] ) {
25+ constructor ( request : string , codeBlock : string ) {
2626 super ( request ) ;
2727
28- this . componentDocs = componentDocs ;
28+ this . codeBlock = codeBlock ;
2929 }
3030
3131 // TODO: Note if you want that modules correctly invalidate and cache you need to add updateHash to your Dependency and hash the type info (because that might change depending on outside factors (other modules)
@@ -35,45 +35,11 @@ makeSerializable(
3535 DocGenDependency ,
3636 "react-docgen-typescript-plugin/dist/dependency"
3737) ;
38-
39- type Options = {
40- parser : docGen . FileParser ;
41- docgenOptions : LoaderOptions ;
42- } ;
43-
4438class DocGenTemplate extends NullDependency . Template {
45- private options : Options ;
46-
47- constructor ( options : Options ) {
48- super ( ) ;
49-
50- this . options = options ;
51- }
52-
53- apply (
54- dependency : NullDependency ,
55- source : ReplaceSource ,
56- { module } : { module : Module }
57- ) : void {
58- const { userRequest } = module ;
59-
60- if ( ! dependency . componentDocs . length ) {
61- return ;
39+ apply ( dependency : NullDependency , source : ReplaceSource ) : void {
40+ if ( dependency . codeBlock ) {
41+ source . insert ( 0 , dependency . codeBlock ) ;
6242 }
63-
64- source . insert (
65- 0 ,
66- generateDocgenCodeBlock ( {
67- filename : userRequest ,
68- source : userRequest ,
69- componentDocs : dependency . componentDocs ,
70- docgenCollectionName :
71- this . options . docgenOptions . docgenCollectionName ||
72- "STORYBOOK_REACT_CLASSES" ,
73- setDisplayName : this . options . docgenOptions . setDisplayName || true ,
74- typePropName : this . options . docgenOptions . typePropName || "type" ,
75- } ) . substring ( userRequest . length )
76- ) ;
7743 }
7844}
7945
0 commit comments