From 66d75e96410f1d3b17fc972746220d6682440a8f Mon Sep 17 00:00:00 2001 From: "zhanghang.heal" Date: Thu, 20 Nov 2025 15:14:29 +0800 Subject: [PATCH 1/2] feat(dts-plugin): add dts.generateTypes.deleteTsConfig field --- .changeset/serious-peaches-attend.md | 5 + apps/website-new/docs/en/configure/dts.mdx | 14 +- apps/website-new/docs/zh/configure/dts.mdx | 14 +- .../src/core/configurations/remotePlugin.ts | 1 + .../src/core/lib/typeScriptCompiler.ts | 6 +- .../container/ModuleFederationPlugin.check.ts | 166 +++++++++++------- .../types/plugins/ModuleFederationPlugin.ts | 2 +- 7 files changed, 135 insertions(+), 73 deletions(-) create mode 100644 .changeset/serious-peaches-attend.md diff --git a/.changeset/serious-peaches-attend.md b/.changeset/serious-peaches-attend.md new file mode 100644 index 00000000000..0c0dc930f0d --- /dev/null +++ b/.changeset/serious-peaches-attend.md @@ -0,0 +1,5 @@ +--- +'@module-federation/dts-plugin': patch +--- + +feat(dts-plugin): add dts.generateTypes.deleteTsConfig field diff --git a/apps/website-new/docs/en/configure/dts.mdx b/apps/website-new/docs/en/configure/dts.mdx index ebc383d5802..578fc097ac9 100644 --- a/apps/website-new/docs/en/configure/dts.mdx +++ b/apps/website-new/docs/en/configure/dts.mdx @@ -39,6 +39,7 @@ interface DtsRemoteOptions { extractThirdParty?: boolean; extractRemoteTypes?: boolean; abortOnError?: boolean; + deleteTsConfig?: boolean; } ``` @@ -50,7 +51,8 @@ When configuring `generateTypes` to `true`, the following configuration will be "abortOnError": false, "extractThirdParty": false, "extractRemoteTypes": false, - "compileInChildProcess": true + "compileInChildProcess": true, + "deleteTsConfig": true } ``` @@ -125,12 +127,20 @@ Whether to delete the generated type folder #### compilerInstance -- Type: `'tsc' | 'vue-tsc' | 'tspc' | string` +- Type: `'tsc' | 'tsgo' | 'vue-tsc' | 'tspc' | string` - Required: No - Default value: `'tsc'` Instance of compiled type +#### deleteTsConfig + +- Type: `boolean` +- Required: No +- Default value: `true` + +Whether to delete the temporary tsconfig configuration file. + ### consumeTypes - Type: `boolean | DtsHostOptions` diff --git a/apps/website-new/docs/zh/configure/dts.mdx b/apps/website-new/docs/zh/configure/dts.mdx index f3b34b0508a..27b598205b8 100644 --- a/apps/website-new/docs/zh/configure/dts.mdx +++ b/apps/website-new/docs/zh/configure/dts.mdx @@ -38,6 +38,7 @@ interface DtsRemoteOptions { extractThirdParty?: boolean; extractRemoteTypes?: boolean; abortOnError?: boolean; + deleteTsConfig?: boolean; } ``` @@ -49,7 +50,8 @@ interface DtsRemoteOptions { "abortOnError": false, "extractThirdParty": false, "extractRemoteTypes": false, - "compileInChildProcess": true + "compileInChildProcess": true, + "deleteTsConfig": true } ``` @@ -125,12 +127,20 @@ tsconfig 配置文件路径 #### compilerInstance -- 类型:`'tsc' | 'vue-tsc' | 'tspc' | string` +- 类型:`'tsc' | 'tsgo' | 'vue-tsc' | 'tspc' | string` - 是否必填:否 - 默认值:`'tsc'` 编译类型的示例 +#### deleteTsConfig + +- 类型:`boolean` +- 是否必填:否 +- 默认值:`true` + +是否删除临时 tsconfig 配置文件。 + ### consumeTypes - 类型:`boolean | DtsHostOptions` diff --git a/packages/dts-plugin/src/core/configurations/remotePlugin.ts b/packages/dts-plugin/src/core/configurations/remotePlugin.ts index 77d2ad7513e..1bc53d04b05 100644 --- a/packages/dts-plugin/src/core/configurations/remotePlugin.ts +++ b/packages/dts-plugin/src/core/configurations/remotePlugin.ts @@ -23,6 +23,7 @@ const defaultOptions = { extractRemoteTypes: false, extractThirdParty: false, outputDir: '', + deleteTsConfig: true, } satisfies Partial; function getEffectiveRootDir( diff --git a/packages/dts-plugin/src/core/lib/typeScriptCompiler.ts b/packages/dts-plugin/src/core/lib/typeScriptCompiler.ts index 744d64c4486..da9abd61f6a 100644 --- a/packages/dts-plugin/src/core/lib/typeScriptCompiler.ts +++ b/packages/dts-plugin/src/core/lib/typeScriptCompiler.ts @@ -23,6 +23,7 @@ import { TEMP_DIR } from '@module-federation/sdk'; import { RemoteOptions } from '../interfaces/RemoteOptions'; import { TsConfigJson } from '../interfaces/TsConfigJson'; +import { logger } from '../../server'; const STARTS_WITH_SLASH = /^\//; @@ -198,6 +199,7 @@ export const compileTs = async ( ? (remoteOptions.moduleFederationConfig.dts?.cwd ?? undefined) : undefined, ); + logger.debug(`tempTsConfigJsonPath: ${tempTsConfigJsonPath}`); try { const mfTypePath = retrieveMfTypesPath(tsConfig, remoteOptions); const thirdPartyExtractor = new ThirdPartyExtractor({ @@ -269,7 +271,9 @@ export const compileTs = async ( await thirdPartyExtractor.copyDts(); } - await rm(tempTsConfigJsonPath); + if (remoteOptions.deleteTsConfig) { + await rm(tempTsConfigJsonPath); + } } catch (err) { throw err; } diff --git a/packages/enhanced/src/schemas/container/ModuleFederationPlugin.check.ts b/packages/enhanced/src/schemas/container/ModuleFederationPlugin.check.ts index 8d57f33fba6..7a29debc075 100644 --- a/packages/enhanced/src/schemas/container/ModuleFederationPlugin.check.ts +++ b/packages/enhanced/src/schemas/container/ModuleFederationPlugin.check.ts @@ -448,7 +448,10 @@ const t = { }, bridge: { type: 'object', - properties: { disableAlias: { type: 'boolean', default: !1 } }, + properties: { + enableBridgeRouter: { type: 'boolean', default: !1 }, + disableAlias: { type: 'boolean', default: !1 }, + }, additionalProperties: !1, }, virtualRuntimeEntry: { type: 'boolean' }, @@ -3201,9 +3204,9 @@ function A( null === u ? (u = [e]) : u.push(e), y++; } - var k = r === y; - } else k = !0; - if (k) { + var R = r === y; + } else R = !0; + if (R) { if (void 0 !== e.consumeTypes) { let r = e.consumeTypes; const n = y, @@ -3217,8 +3220,8 @@ function A( null === u ? (u = [e]) : u.push(e), y++; } - var R = i === y; - if (((o = o || R), !o)) { + var k = i === y; + if (((o = o || k), !o)) { const e = y; if (y === e) if ( @@ -3829,7 +3832,7 @@ function A( : u.push(e), y++; } - (R = e === y), (o = o || R); + (k = e === y), (o = o || k); } if (o) (y = s), @@ -3842,9 +3845,9 @@ function A( null === u ? (u = [e]) : u.push(e), y++; } - k = n === y; - } else k = !0; - if (k) { + R = n === y; + } else R = !0; + if (R) { if (void 0 !== e.tsConfigPath) { const t = y; if ( @@ -3858,9 +3861,9 @@ function A( : u.push(e), y++; } - k = t === y; - } else k = !0; - if (k) { + R = t === y; + } else R = !0; + if (R) { if (void 0 !== e.extraOptions) { let t = e.extraOptions; const r = y; @@ -3877,9 +3880,9 @@ function A( : u.push(e), y++; } - k = r === y; - } else k = !0; - if (k) { + R = r === y; + } else R = !0; + if (R) { if (void 0 !== e.implementation) { const t = y; if ( @@ -3894,9 +3897,9 @@ function A( : u.push(e), y++; } - k = t === y; - } else k = !0; - if (k) { + R = t === y; + } else R = !0; + if (R) { if (void 0 !== e.cwd) { const t = y; if ( @@ -3912,9 +3915,9 @@ function A( : u.push(e), y++; } - k = t === y; - } else k = !0; - if (k) + R = t === y; + } else R = !0; + if (R) if ( void 0 !== e.displayErrorInTerminal @@ -3934,8 +3937,8 @@ function A( : u.push(e), y++; } - k = t === y; - } else k = !0; + R = t === y; + } else R = !0; } } } @@ -4134,7 +4137,10 @@ function A( { const t = y; for (const t in e) - if ('disableAlias' !== t) + if ( + 'enableBridgeRouter' !== t && + 'disableAlias' !== t + ) return ( (A.errors = [ { @@ -4145,17 +4151,43 @@ function A( ]), !1 ); - if ( - t === y && - void 0 !== e.disableAlias && - 'boolean' != typeof e.disableAlias - ) - return ( - (A.errors = [ - { params: { type: 'boolean' } }, - ]), - !1 - ); + if (t === y) { + if (void 0 !== e.enableBridgeRouter) { + const t = y; + if ( + 'boolean' != + typeof e.enableBridgeRouter + ) + return ( + (A.errors = [ + { + params: { type: 'boolean' }, + }, + ]), + !1 + ); + var C = t === y; + } else C = !0; + if (C) + if (void 0 !== e.disableAlias) { + const t = y; + if ( + 'boolean' != + typeof e.disableAlias + ) + return ( + (A.errors = [ + { + params: { + type: 'boolean', + }, + }, + ]), + !1 + ); + C = t === y; + } else C = !0; + } } } b = t === y; @@ -4189,8 +4221,8 @@ function A( null === u ? (u = [e]) : u.push(e), y++; } - var C = s === y; - if (((n = n || C), !n)) { + var V = s === y; + if (((n = n || V), !n)) { const t = y; if (y === t) if ( @@ -4237,9 +4269,9 @@ function A( : u.push(e), y++; } - var V = t === y; - } else V = !0; - if (V) { + var w = t === y; + } else w = !0; + if (w) { if ( void 0 !== e.disableHotTypesReload @@ -4259,9 +4291,9 @@ function A( : u.push(e), y++; } - V = t === y; - } else V = !0; - if (V) + w = t === y; + } else w = !0; + if (w) if ( void 0 !== e.disableDynamicRemoteTypeHints @@ -4281,8 +4313,8 @@ function A( : u.push(e), y++; } - V = t === y; - } else V = !0; + w = t === y; + } else w = !0; } } } else { @@ -4294,7 +4326,7 @@ function A( : u.push(e), y++; } - (C = t === y), (n = n || C); + (V = t === y), (n = n || V); } if (!n) { const e = { params: {} }; @@ -4324,8 +4356,8 @@ function A( null === u ? (u = [e]) : u.push(e), y++; } - var w = s === y; - if (((n = n || w), !n)) { + var F = s === y; + if (((n = n || F), !n)) { const t = y; if (y === t) if ( @@ -4370,9 +4402,9 @@ function A( : u.push(e), y++; } - var F = t === y; - } else F = !0; - if (F) { + var N = t === y; + } else N = !0; + if (N) { if ( void 0 !== e.disableAssetsAnalyze @@ -4392,9 +4424,9 @@ function A( : u.push(e), y++; } - F = t === y; - } else F = !0; - if (F) { + N = t === y; + } else N = !0; + if (N) { if ( void 0 !== e.fileName ) { @@ -4413,9 +4445,9 @@ function A( : u.push(e), y++; } - F = t === y; - } else F = !0; - if (F) + N = t === y; + } else N = !0; + if (N) if ( void 0 !== e.additionalData @@ -4435,8 +4467,8 @@ function A( : u.push(e), y++; } - F = t === y; - } else F = !0; + N = t === y; + } else N = !0; } } } @@ -4449,7 +4481,7 @@ function A( : u.push(e), y++; } - (w = t === y), (n = n || w); + (F = t === y), (n = n || F); } if (!n) { const e = { params: {} }; @@ -4500,8 +4532,8 @@ function A( : u.push(e), y++; } - var N = i === y; - if (((o = o || N), !o)) { + var z = i === y; + if (((o = o || z), !o)) { const e = y; if (y === e) if (Array.isArray(t)) @@ -4545,9 +4577,9 @@ function A( : u.push(e), y++; } - var z = e === y; + var U = e === y; } - if (z && e > 1) { + if (U && e > 1) { let e = t[1]; const r = y; if ( @@ -4566,7 +4598,7 @@ function A( : u.push(e), y++; } - z = r === y; + U = r === y; } } else { @@ -4580,7 +4612,7 @@ function A( : u.push(e), y++; } - (N = e === y), (o = o || N); + (z = e === y), (o = o || z); } if (!o) { const e = { params: {} }; diff --git a/packages/sdk/src/types/plugins/ModuleFederationPlugin.ts b/packages/sdk/src/types/plugins/ModuleFederationPlugin.ts index b398ca797fd..cb01a718ba4 100644 --- a/packages/sdk/src/types/plugins/ModuleFederationPlugin.ts +++ b/packages/sdk/src/types/plugins/ModuleFederationPlugin.ts @@ -1,6 +1,5 @@ import type webpack from 'webpack'; import { Stats } from '../stats'; -import { Manifest } from '../manifest'; /** * Modules that should be exposed by this container. When provided, property name is used as public name, otherwise public name is automatically inferred from request. */ @@ -175,6 +174,7 @@ export interface DtsRemoteOptions { }; extractRemoteTypes?: boolean; abortOnError?: boolean; + deleteTsConfig?: boolean; } export interface PluginDtsOptions { From ba51ba9923261cb5167a39c055a6544581f6e25d Mon Sep 17 00:00:00 2001 From: "zhanghang.heal" Date: Thu, 20 Nov 2025 15:40:36 +0800 Subject: [PATCH 2/2] fix: update dts ut --- .../dts-plugin/src/core/configurations/remotePlugin.test.ts | 2 ++ packages/dts-plugin/src/core/lib/typeScriptCompiler.test.ts | 4 ++++ packages/dts-plugin/src/server/Publisher.ts | 1 - 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/dts-plugin/src/core/configurations/remotePlugin.test.ts b/packages/dts-plugin/src/core/configurations/remotePlugin.test.ts index 9e4d092972c..8dd6c358e51 100644 --- a/packages/dts-plugin/src/core/configurations/remotePlugin.test.ts +++ b/packages/dts-plugin/src/core/configurations/remotePlugin.test.ts @@ -83,6 +83,7 @@ describe('hostPlugin', () => { implementation: '', generateAPITypes: false, context: process.cwd(), + deleteTsConfig: true, outputDir: '', abortOnError: true, extractRemoteTypes: false, @@ -152,6 +153,7 @@ describe('hostPlugin', () => { generateAPITypes: false, implementation: '', context: process.cwd(), + deleteTsConfig: true, outputDir: '', abortOnError: true, extractRemoteTypes: false, diff --git a/packages/dts-plugin/src/core/lib/typeScriptCompiler.test.ts b/packages/dts-plugin/src/core/lib/typeScriptCompiler.test.ts index 3c225ea3348..a2b7bf1bec0 100644 --- a/packages/dts-plugin/src/core/lib/typeScriptCompiler.test.ts +++ b/packages/dts-plugin/src/core/lib/typeScriptCompiler.test.ts @@ -53,6 +53,7 @@ describe('typeScriptCompiler', () => { hostRemoteTypesFolder: '@mf-types', abortOnError: true, outputDir: 'outputDir', + deleteTsConfig: true, }; it('retrieveMfTypesPath correctly calculate path', () => { @@ -127,6 +128,9 @@ describe('typeScriptCompiler', () => { children: [ { children: [ + { + name: 'HostOptions.d.ts', + }, { name: 'RemoteOptions.d.ts', }, diff --git a/packages/dts-plugin/src/server/Publisher.ts b/packages/dts-plugin/src/server/Publisher.ts index 5651cd2470b..6a905c77890 100644 --- a/packages/dts-plugin/src/server/Publisher.ts +++ b/packages/dts-plugin/src/server/Publisher.ts @@ -6,7 +6,6 @@ import { UpdateSubscriberAPIPayload, } from './message/API'; import { getIdentifier, fileLog } from './utils'; -import { FetchTypesPayload } from './message/Action'; import { RemoteInfo } from '../core/interfaces/HostOptions'; interface PublisherContext {