Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit 07a8772

Browse files
files depend on .d.ts files referenced via include
1 parent ed5dc97 commit 07a8772

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/processors/typescript.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ export class TypeScriptFileProcessor implements FileProcessor {
163163
}
164164
}
165165

166+
const includes = await this.includesFromNearestTsconfigFile(file);
167+
for (const include of includes) {
168+
importedFiles.add(include);
169+
}
170+
166171
return Promise.resolve(importedFiles);
167172
}
168173

@@ -189,6 +194,33 @@ export class TypeScriptFileProcessor implements FileProcessor {
189194
},
190195
);
191196

197+
private async includesFromNearestTsconfigFile(file: Path): Promise<string[]> {
198+
const tsconfigPath = ts.findConfigFile(
199+
path.dirname(file),
200+
ts.sys.fileExists,
201+
);
202+
if (!tsconfigPath || !tsconfigPath.startsWith(this.rootDir)) {
203+
return [];
204+
}
205+
206+
const json = ts.parseJsonText(
207+
tsconfigPath,
208+
await fs.promises.readFile(tsconfigPath, 'utf-8'),
209+
);
210+
const parsed = ts.parseJsonSourceFileConfigFileContent(
211+
json,
212+
ts.sys,
213+
path.dirname(tsconfigPath),
214+
);
215+
return parsed.fileNames.filter(
216+
(fileName) =>
217+
// only include .d.ts files. all other references should be made using `import` or `require`.
218+
fileName.endsWith('.d.ts') &&
219+
// files do not depend on themselves
220+
fileName !== file,
221+
);
222+
}
223+
192224
// Finds an implicit 'import' in the entry point object literal, like:
193225
//
194226
// export const entryPoint: DynamicEntryPoint = {

0 commit comments

Comments
 (0)