diff --git a/.changeset/orange-days-kiss.md b/.changeset/orange-days-kiss.md new file mode 100644 index 0000000000..f513aa2ea7 --- /dev/null +++ b/.changeset/orange-days-kiss.md @@ -0,0 +1,5 @@ +--- +'@module-federation/dts-plugin': patch +--- + +fix(dts-plugin): cache file should have name as its unique path diff --git a/packages/dts-plugin/src/core/configurations/remotePlugin.test.ts b/packages/dts-plugin/src/core/configurations/remotePlugin.test.ts index 34b7a57eac..75c6a39050 100644 --- a/packages/dts-plugin/src/core/configurations/remotePlugin.test.ts +++ b/packages/dts-plugin/src/core/configurations/remotePlugin.test.ts @@ -57,7 +57,7 @@ describe('hostPlugin', () => { incremental: true, tsBuildInfoFile: resolve( remoteOptions.context, - 'node_modules/.cache/.tsbuildinfo', + `node_modules/.cache/${remoteOptions.moduleFederationConfig.name}/.tsbuildinfo`, ), }, files: ['./src/components/button', './src/components/anotherButton'], @@ -76,7 +76,7 @@ describe('hostPlugin', () => { typesFolder: '@mf-types', compiledTypesFolder: 'compiled-types', hostRemoteTypesFolder: '@mf-types', - deleteTypesFolder: true, + deleteTypesFolder: false, moduleFederationConfig, compilerInstance: 'tsc', compileInChildProcess: false, @@ -126,7 +126,7 @@ describe('hostPlugin', () => { incremental: true, tsBuildInfoFile: resolve( remoteOptions.context, - 'node_modules/.cache/.tsbuildinfo', + `node_modules/.cache/${remoteOptions.moduleFederationConfig.name}/.tsbuildinfo`, ), }, exclude: [], diff --git a/packages/dts-plugin/src/core/configurations/remotePlugin.ts b/packages/dts-plugin/src/core/configurations/remotePlugin.ts index 67d4be5730..5f7c5a3f1a 100644 --- a/packages/dts-plugin/src/core/configurations/remotePlugin.ts +++ b/packages/dts-plugin/src/core/configurations/remotePlugin.ts @@ -61,6 +61,7 @@ const readTsConfig = ( context, additionalFilesToCompile, outputDir, + moduleFederationConfig, }: Required, mapComponentsToExpose: Record, ): TsConfigJson => { @@ -97,13 +98,16 @@ const readTsConfig = ( noEmit: false, declaration: true, outDir, - incremental: true, - tsBuildInfoFile: resolve(context, 'node_modules/.cache/.tsbuildinfo'), }; rawTsConfigJson.compilerOptions = rawTsConfigJson.compilerOptions || {}; rawTsConfigJson.compilerOptions = { + incremental: true, + tsBuildInfoFile: resolve( + context, + `node_modules/.cache/${moduleFederationConfig.name}/.tsbuildinfo`, + ), ...rawTsConfigJson.compilerOptions, ...defaultCompilerOptions, }; @@ -183,6 +187,14 @@ export const retrieveRemoteConfig = (options: RemoteOptions) => { const mapComponentsToExpose = resolveExposes(remoteOptions); const tsConfig = readTsConfig(remoteOptions, mapComponentsToExpose); + if ( + tsConfig.compilerOptions.incremental && + tsConfig.compilerOptions.tsBuildInfoFile && + options.deleteTypesFolder !== true + ) { + remoteOptions.deleteTypesFolder = false; + } + return { tsConfig, mapComponentsToExpose,