@@ -111,6 +111,14 @@ export class TypeScriptFileProcessor implements FileProcessor {
111
111
filesList . push ( TypeScriptFileProcessor . getEntryPointImport ( file ) ) ;
112
112
}
113
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
+ }
121
+
114
122
for ( const fileName of filesList ) {
115
123
const referencedFile = dependencyTree . transformReference ( fileName , file ) ;
116
124
if ( Array . isArray ( referencedFile ) ) {
@@ -189,6 +197,25 @@ export class TypeScriptFileProcessor implements FileProcessor {
189
197
} ,
190
198
) ;
191
199
200
+ /**
201
+ * Finds the tsconfig.json that this file is included by. Does this by searching in the same directory,
202
+ * and then searching in each dir all the way to the root directory.
203
+ */
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 ;
214
+ }
215
+ }
216
+ throw new Error ( `could not find tsconfig.json for ${ file } ` ) ;
217
+ } ) ;
218
+
192
219
// Finds an implicit 'import' in the entry point object literal, like:
193
220
//
194
221
// export const entryPoint: DynamicEntryPoint = {
0 commit comments