Skip to content

Commit b0dbc68

Browse files
add debug logs
1 parent 90d42b6 commit b0dbc68

3 files changed

Lines changed: 42 additions & 11 deletions

File tree

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@
2323
"dist"
2424
],
2525
"dependencies": {
26+
"debug": "^4.1.1",
2627
"endent": "^2.0.1",
2728
"micromatch": "^4.0.2",
2829
"react-docgen-typescript": "^1.16.6",
2930
"react-docgen-typescript-loader": "^3.7.2",
3031
"tslib": "^2.0.0"
3132
},
3233
"devDependencies": {
34+
"@types/debug": "^4.1.5",
3335
"@types/micromatch": "^4.0.1",
3436
"@types/node": "^14.0.12",
3537
"@types/webpack": "^4.41.17",

readme.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ This plugins support all parser options from [react-docgen-typescript](https://g
4646
| exclude | glob[] | Glob patterns to ignore and not generate docgen information for. (Great for ignoring large icon libraries) | [] |
4747
| include | glob[] | Glob patterns to generate docgen information for | ['**/**.tsx'] |
4848

49+
## Debugging
50+
51+
If you want to see how this plugins is including and excluding modules set the `DEBUG` environment variable.
52+
53+
- `DEBUG=docgen:*` - All logs
54+
- `DEBUG=docgen:include` - Included modules
55+
- `DEBUG=docgen:exclude` - Excluded modules
56+
57+
```bash
58+
DEBUG=docgen:* npm run storybook
59+
```
60+
4961
## Prior Art
5062

5163
- [sn-client](https://github.com/SenseNet/sn-client/) - Inspired by this custom webpack plugin

src/index.ts

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import path from "path";
2+
import createDebug from "debug";
23
import * as webpack from "webpack";
34
import ts from "typescript";
45
import * as docGen from "react-docgen-typescript";
56
import generateDocgenCodeBlock from "react-docgen-typescript-loader/dist/generateDocgenCodeBlock";
67
import match from "micromatch";
78

9+
const debugExclude = createDebug("docgen:exclude");
10+
const debugInclude = createDebug("docgen:include");
11+
812
interface TypescriptOptions {
913
/**
1014
* Specify the location of the tsconfig.json to use. Can not be used with
@@ -142,8 +146,7 @@ export default class DocgenPlugin {
142146
include = ["**/**.tsx"],
143147
...docgenOptions
144148
} = this.options;
145-
146-
const pathRegex = RegExp(`\\${path.sep}src.+\\.tsx`);
149+
147150
const isExcluded = matchGlob(exclude);
148151
const isIncluded = matchGlob(include);
149152

@@ -171,18 +174,32 @@ export default class DocgenPlugin {
171174
const modulesToProcess: Module[] = [];
172175

173176
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}`);
183199
return;
184200
}
185201

202+
debugInclude(module.userRequest);
186203
modulesToProcess.push(module);
187204
});
188205

0 commit comments

Comments
 (0)