Skip to content

Commit 2543aa4

Browse files
committed
fix: Pass generator/parser options correctly
1 parent f6e2133 commit 2543aa4

1 file changed

Lines changed: 32 additions & 10 deletions

File tree

src/plugin.ts

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import { matcher } from "micromatch";
99

1010
import { LoaderOptions } from "./types";
1111
import DocGenDependency from "./dependency";
12-
import { generateDocgenCodeBlock } from "./generateDocgenCodeBlock";
12+
import {
13+
generateDocgenCodeBlock,
14+
GeneratorOptions,
15+
} from "./generateDocgenCodeBlock";
1316

1417
const debugExclude = createDebug("docgen:exclude");
1518

@@ -68,8 +71,15 @@ export default class DocgenPlugin implements WebpackPluginInstance {
6871

6972
apply(compiler: Compiler): void {
7073
const pluginName = "DocGenPlugin";
71-
const { docgenOptions, compilerOptions } = this.getOptions();
72-
const docGenParser = docGen.withCompilerOptions(compilerOptions);
74+
const {
75+
docgenOptions,
76+
compilerOptions,
77+
generateOptions,
78+
} = this.getOptions();
79+
const docGenParser = docGen.withCompilerOptions(
80+
compilerOptions,
81+
docgenOptions
82+
);
7383
const { exclude = [], include = ["**/**.tsx"] } = this.options;
7484
const isExcluded = matchGlob(exclude);
7585
const isIncluded = matchGlob(include);
@@ -116,11 +126,7 @@ export default class DocgenPlugin implements WebpackPluginInstance {
116126
filename: nameForCondition,
117127
source: nameForCondition,
118128
componentDocs,
119-
docgenCollectionName:
120-
docgenOptions.docgenCollectionName ||
121-
"STORYBOOK_REACT_CLASSES",
122-
setDisplayName: docgenOptions.setDisplayName || true,
123-
typePropName: docgenOptions.typePropName || "type",
129+
...generateOptions,
124130
}).substring(module.userRequest.length)
125131
)
126132
);
@@ -141,12 +147,20 @@ export default class DocgenPlugin implements WebpackPluginInstance {
141147
}
142148

143149
getOptions(): {
144-
docgenOptions: LoaderOptions;
150+
docgenOptions: docGen.ParserOptions;
151+
generateOptions: {
152+
docgenCollectionName: GeneratorOptions["docgenCollectionName"];
153+
setDisplayName: GeneratorOptions["setDisplayName"];
154+
typePropName: GeneratorOptions["typePropName"];
155+
};
145156
compilerOptions: ts.CompilerOptions;
146157
} {
147158
const {
148159
tsconfigPath = "./tsconfig.json",
149160
compilerOptions: userCompilerOptions,
161+
docgenCollectionName,
162+
setDisplayName,
163+
typePropName,
150164
...docgenOptions
151165
} = this.options;
152166

@@ -166,7 +180,15 @@ export default class DocgenPlugin implements WebpackPluginInstance {
166180
compilerOptions = { ...compilerOptions, ...tsOptions };
167181
}
168182

169-
return { docgenOptions, compilerOptions };
183+
return {
184+
docgenOptions,
185+
generateOptions: {
186+
docgenCollectionName: docgenCollectionName || "STORYBOOK_REACT_CLASSES",
187+
setDisplayName: setDisplayName || true,
188+
typePropName: typePropName || "type",
189+
},
190+
compilerOptions,
191+
};
170192
}
171193
}
172194

0 commit comments

Comments
 (0)