Skip to content

Commit 90d42b6

Browse files
clean up code
1 parent 0a9e7ba commit 90d42b6

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

src/index.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ function getTSConfigFile(tsconfigPath: string): ts.ParsedCommandLine {
118118
);
119119
}
120120

121+
/** Create a glob matching function. */
122+
const matchGlob = (globs: string[]) => (filename: string) =>
123+
Boolean(filename && globs.find((g) => match([filename], g).length));
124+
121125
/** Inject typescript docgen information into modules at the end of a build */
122126
export default class DocgenPlugin {
123127
private name = "React Docgen Typescript Plugin";
@@ -128,7 +132,6 @@ export default class DocgenPlugin {
128132
}
129133

130134
apply(compiler: webpack.Compiler) {
131-
const pathRegex = RegExp(`\\${path.sep}src.+\\.tsx`);
132135
const {
133136
tsconfigPath,
134137
docgenCollectionName = "STORYBOOK_REACT_CLASSES",
@@ -139,6 +142,11 @@ export default class DocgenPlugin {
139142
include = ["**/**.tsx"],
140143
...docgenOptions
141144
} = this.options;
145+
146+
const pathRegex = RegExp(`\\${path.sep}src.+\\.tsx`);
147+
const isExcluded = matchGlob(exclude);
148+
const isIncluded = matchGlob(include);
149+
142150
let compilerOptions = {
143151
jsx: ts.JsxEmit.React,
144152
module: ts.ModuleKind.CommonJS,
@@ -154,11 +162,6 @@ export default class DocgenPlugin {
154162
compilerOptions = { ...compilerOptions, ...options };
155163
}
156164

157-
const isExcluded = (filename: string) =>
158-
Boolean(filename && exclude.find((i) => match([filename], i).length));
159-
const isIncluded = (filename: string) =>
160-
Boolean(filename && include.find((i) => match([filename], i).length));
161-
162165
const parser =
163166
(tsconfigPath && docGen.withCustomConfig(tsconfigPath, docgenOptions)) ||
164167
docGen.withCompilerOptions(compilerOptions, docgenOptions);

0 commit comments

Comments
 (0)