@@ -53,6 +53,19 @@ function getEffectiveRootDir(
53
53
) ;
54
54
}
55
55
56
+ const getDependentFiles = (
57
+ rootFiles : string [ ] ,
58
+ configContent : typescript . ParsedCommandLine ,
59
+ rootDir : string ,
60
+ ) : string [ ] => {
61
+ const program = typescript . createProgram ( rootFiles , configContent . options ) ;
62
+ const sourceFiles = program . getSourceFiles ( ) ;
63
+ const dependentFiles = sourceFiles
64
+ . map ( ( file ) => file . fileName )
65
+ . filter ( ( file ) => ! file . endsWith ( '.d.ts' ) && file . startsWith ( rootDir ) ) ;
66
+ return dependentFiles . length ? dependentFiles : rootFiles ;
67
+ } ;
68
+
56
69
const readTsConfig = (
57
70
{
58
71
tsConfigPath,
@@ -121,20 +134,24 @@ const readTsConfig = (
121
134
) ;
122
135
123
136
const excludeExtensions = [ '.mdx' , '.md' ] ;
124
- const filesToCompile = [
137
+ const rootFiles = [
125
138
...Object . values ( mapComponentsToExpose ) ,
139
+ ...additionalFilesToCompile ,
140
+ ] . filter (
141
+ ( filename ) => ! excludeExtensions . some ( ( ext ) => filename . endsWith ( ext ) ) ,
142
+ ) ;
143
+
144
+ const filesToCompile = [
145
+ ...getDependentFiles ( rootFiles , configContent , rootDir ) ,
126
146
...configContent . fileNames . filter (
127
147
( filename ) =>
128
148
filename . endsWith ( '.d.ts' ) &&
129
149
! filename . startsWith ( outDirWithoutTypesFolder ) ,
130
150
) ,
131
- ...additionalFilesToCompile ,
132
- ] . filter (
133
- ( filename ) => ! excludeExtensions . some ( ( ext ) => filename . endsWith ( ext ) ) ,
134
- ) ;
151
+ ] ;
135
152
136
153
rawTsConfigJson . include = [ ] ;
137
- rawTsConfigJson . files = filesToCompile ;
154
+ rawTsConfigJson . files = [ ... new Set ( filesToCompile ) ] ;
138
155
rawTsConfigJson . exclude = [ ] ;
139
156
'references' in rawTsConfigJson && delete rawTsConfigJson . references ;
140
157
0 commit comments