@@ -110,14 +110,7 @@ export class TypeScriptFileProcessor implements FileProcessor {
110110 if ( TypeScriptFileProcessor . isEntryPointFileName ( file ) ) {
111111 filesList . push ( TypeScriptFileProcessor . getEntryPointImport ( file ) ) ;
112112 }
113-
114- const includes = this . includesFromNearestTsconfigFile ( file ) ;
115- if ( includes . length ) {
116- // only include non-globbed includes
117- // TODO: support globbed includes
118- const nonGlobIncludes = includes . filter ( maybeGlob => ! maybeGlob . includes ( '*' ) ) ;
119- filesList . push ( ...nonGlobIncludes ) ;
120- }
113+ filesList . push ( ...( await this . includesFromNearestTsconfigFile ( file ) ) ) ;
121114
122115 for ( const fileName of filesList ) {
123116 const referencedFile = dependencyTree . transformReference ( fileName , file ) ;
@@ -201,20 +194,44 @@ export class TypeScriptFileProcessor implements FileProcessor {
201194 * Finds the tsconfig.json that this file is included by. Does this by searching in the same directory,
202195 * and then searching in each dir all the way to the root directory.
203196 */
204- private includesFromNearestTsconfigFile = memoize ( async ( file : Path ) : Promise < string [ ] > => {
205- const segments = path . dirname ( path . relative ( this . rootDir , file ) ) . split ( path . sep ) ;
206- while ( segments . length > 0 ) {
207- const maybeTsconfig = path . join ( this . rootDir , ...segments , 'tsconfig.json' ) ;
208- try {
209- const contents = JSON . parse ( await fs . promises . readFile ( file , 'utf8' ) ) ;
210- return 'includes' in contents ? ( contents [ 'includes' ] as string [ ] ) : [ ] ;
211- } catch ( err ) {
212- segments . pop ( ) ; // go up one dir
213- continue ;
197+ private includesFromNearestTsconfigFile = memoize (
198+ async ( file : Path ) : Promise < string [ ] > => {
199+ const segments = path
200+ . dirname ( path . relative ( this . rootDir , file ) )
201+ . split ( path . sep ) ;
202+ while ( segments . length > 0 ) {
203+ const maybeTsconfig = path . join (
204+ this . rootDir ,
205+ ...segments ,
206+ 'tsconfig.json' ,
207+ ) ;
208+ let contents : string ;
209+ try {
210+ contents = await fs . promises . readFile ( maybeTsconfig , 'utf8' ) ;
211+ } catch ( err ) {
212+ segments . pop ( ) ; // go up one dir
213+ continue ;
214+ }
215+
216+ const json = JSON . parse ( contents ) ;
217+ if ( ! ( 'include' in json ) ) {
218+ return [ ] ;
219+ }
220+
221+ const include = json [ 'include' ] as string [ ] ;
222+ const tsconfigDir = path . dirname ( maybeTsconfig ) ;
223+ return (
224+ include
225+ // filter out globbed includes
226+ // TODO: support globbed includes
227+ . filter ( ( maybeGlob ) => ! maybeGlob . includes ( '*' ) )
228+ // make the includes absolute
229+ . map ( ( include ) => path . join ( tsconfigDir , include ) )
230+ ) ;
214231 }
215- }
216- throw new Error ( `could not find tsconfig.json for ${ file } ` ) ;
217- } ) ;
232+ return [ ] ;
233+ } ,
234+ ) ;
218235
219236 // Finds an implicit 'import' in the entry point object literal, like:
220237 //
0 commit comments