@@ -110,16 +110,20 @@ function processModule(
110110
111111/** Get the contents of the tsconfig in the system */
112112function getTSConfigFile ( tsconfigPath : string ) : ts . ParsedCommandLine {
113- const basePath = path . dirname ( tsconfigPath ) ;
114- const configFile = ts . readConfigFile ( tsconfigPath , ts . sys . readFile ) ;
115-
116- return ts . parseJsonConfigFileContent (
117- configFile . config ,
118- ts . sys ,
119- basePath ,
120- { } ,
121- tsconfigPath
122- ) ;
113+ try {
114+ const basePath = path . dirname ( tsconfigPath ) ;
115+ const configFile = ts . readConfigFile ( tsconfigPath , ts . sys . readFile ) ;
116+
117+ return ts . parseJsonConfigFileContent (
118+ configFile . config ,
119+ ts . sys ,
120+ basePath ,
121+ { } ,
122+ tsconfigPath
123+ ) ;
124+ } catch ( error ) {
125+ return { } as ts . ParsedCommandLine ;
126+ }
123127}
124128
125129/** Create a glob matching function. */
@@ -137,7 +141,7 @@ export default class DocgenPlugin {
137141
138142 apply ( compiler : webpack . Compiler ) {
139143 const {
140- tsconfigPath,
144+ tsconfigPath = "./tsconfig.json" ,
141145 docgenCollectionName = "STORYBOOK_REACT_CLASSES" ,
142146 setDisplayName = true ,
143147 typePropName = "type" ,
@@ -158,16 +162,12 @@ export default class DocgenPlugin {
158162
159163 if ( userCompilerOptions ) {
160164 compilerOptions = { ...compilerOptions , ...userCompilerOptions } ;
161- }
162-
163- if ( tsconfigPath ) {
165+ } else {
164166 const { options } = getTSConfigFile ( tsconfigPath ) ;
165167 compilerOptions = { ...compilerOptions , ...options } ;
166168 }
167169
168- const parser =
169- ( tsconfigPath && docGen . withCustomConfig ( tsconfigPath , docgenOptions ) ) ||
170- docGen . withCompilerOptions ( compilerOptions , docgenOptions ) ;
170+ const parser = docGen . withCompilerOptions ( compilerOptions , docgenOptions ) ;
171171
172172 compiler . hooks . make . tap ( this . name , ( compilation ) => {
173173 compilation . hooks . seal . tap ( this . name , ( ) => {
@@ -185,17 +185,23 @@ export default class DocgenPlugin {
185185 }
186186
187187 if ( ! module . rawRequest ) {
188- debugExclude ( `Ignoring module without "rawRequest": ${ module . userRequest } ` ) ;
188+ debugExclude (
189+ `Ignoring module without "rawRequest": ${ module . userRequest } `
190+ ) ;
189191 return ;
190192 }
191193
192194 if ( isExcluded ( module . request ) ) {
193- debugExclude ( `Module not matched in "exclude": ${ module . userRequest } ` ) ;
195+ debugExclude (
196+ `Module not matched in "exclude": ${ module . userRequest } `
197+ ) ;
194198 return ;
195199 }
196200
197201 if ( ! isIncluded ( module . request ) ) {
198- debugExclude ( `Module not matched in "include": ${ module . userRequest } ` ) ;
202+ debugExclude (
203+ `Module not matched in "include": ${ module . userRequest } `
204+ ) ;
199205 return ;
200206 }
201207
0 commit comments