Skip to content

Commit 1d691ef

Browse files
authored
fix(dts-plugin): add expose file imported files to tsconfig files (#3895)
1 parent 96d1346 commit 1d691ef

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

.changeset/stale-roses-drive.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/dts-plugin': patch
3+
---
4+
5+
fix(dts-plugin): add expose file imported files to tsconfig files

packages/dts-plugin/src/core/configurations/remotePlugin.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,19 @@ function getEffectiveRootDir(
5353
);
5454
}
5555

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+
5669
const readTsConfig = (
5770
{
5871
tsConfigPath,
@@ -121,20 +134,24 @@ const readTsConfig = (
121134
);
122135

123136
const excludeExtensions = ['.mdx', '.md'];
124-
const filesToCompile = [
137+
const rootFiles = [
125138
...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),
126146
...configContent.fileNames.filter(
127147
(filename) =>
128148
filename.endsWith('.d.ts') &&
129149
!filename.startsWith(outDirWithoutTypesFolder),
130150
),
131-
...additionalFilesToCompile,
132-
].filter(
133-
(filename) => !excludeExtensions.some((ext) => filename.endsWith(ext)),
134-
);
151+
];
135152

136153
rawTsConfigJson.include = [];
137-
rawTsConfigJson.files = filesToCompile;
154+
rawTsConfigJson.files = [...new Set(filesToCompile)];
138155
rawTsConfigJson.exclude = [];
139156
'references' in rawTsConfigJson && delete rawTsConfigJson.references;
140157

0 commit comments

Comments
 (0)