|
1 | 1 | import path from "path"; |
| 2 | +import createDebug from "debug"; |
2 | 3 | import * as webpack from "webpack"; |
3 | 4 | import ts from "typescript"; |
4 | 5 | import * as docGen from "react-docgen-typescript"; |
5 | 6 | import generateDocgenCodeBlock from "react-docgen-typescript-loader/dist/generateDocgenCodeBlock"; |
6 | 7 | import match from "micromatch"; |
7 | 8 |
|
| 9 | +const debugExclude = createDebug("docgen:exclude"); |
| 10 | +const debugInclude = createDebug("docgen:include"); |
| 11 | + |
8 | 12 | interface TypescriptOptions { |
9 | 13 | /** |
10 | 14 | * Specify the location of the tsconfig.json to use. Can not be used with |
@@ -142,8 +146,7 @@ export default class DocgenPlugin { |
142 | 146 | include = ["**/**.tsx"], |
143 | 147 | ...docgenOptions |
144 | 148 | } = this.options; |
145 | | - |
146 | | - const pathRegex = RegExp(`\\${path.sep}src.+\\.tsx`); |
| 149 | + |
147 | 150 | const isExcluded = matchGlob(exclude); |
148 | 151 | const isIncluded = matchGlob(include); |
149 | 152 |
|
@@ -171,18 +174,32 @@ export default class DocgenPlugin { |
171 | 174 | const modulesToProcess: Module[] = []; |
172 | 175 |
|
173 | 176 | compilation.modules.forEach((module: Module) => { |
174 | | - // Skip ignored / external modules |
175 | | - if ( |
176 | | - !module.built || |
177 | | - module.external || |
178 | | - !module.rawRequest || |
179 | | - isExcluded(module.request) || |
180 | | - !isIncluded(module.request) || |
181 | | - !pathRegex.test(module.request) |
182 | | - ) { |
| 177 | + if (!module.built) { |
| 178 | + debugExclude(`Ignoring un-built module: ${module.userRequest}`); |
| 179 | + return; |
| 180 | + } |
| 181 | + |
| 182 | + if (module.external) { |
| 183 | + debugExclude(`Ignoring external module: ${module.userRequest}`); |
| 184 | + return; |
| 185 | + } |
| 186 | + |
| 187 | + if (!module.rawRequest) { |
| 188 | + debugExclude(`Ignoring module without "rawRequest": ${module.userRequest}`); |
| 189 | + return; |
| 190 | + } |
| 191 | + |
| 192 | + if (isExcluded(module.request)) { |
| 193 | + debugExclude(`Module not matched in "exclude": ${module.userRequest}`); |
| 194 | + return; |
| 195 | + } |
| 196 | + |
| 197 | + if (!isIncluded(module.request)) { |
| 198 | + debugExclude(`Module not matched in "include": ${module.userRequest}`); |
183 | 199 | return; |
184 | 200 | } |
185 | 201 |
|
| 202 | + debugInclude(module.userRequest); |
186 | 203 | modulesToProcess.push(module); |
187 | 204 | }); |
188 | 205 |
|
|
0 commit comments