Skip to content

Commit 2fc4050

Browse files
authored
feat(dts-plugin): add dts.generateTypes.deleteTsConfig field (#4225)
1 parent 9dfcbb3 commit 2fc4050

File tree

10 files changed

+141
-74
lines changed

10 files changed

+141
-74
lines changed
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+
feat(dts-plugin): add dts.generateTypes.deleteTsConfig field

apps/website-new/docs/en/configure/dts.mdx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ interface DtsRemoteOptions {
3939
extractThirdParty?: boolean;
4040
extractRemoteTypes?: boolean;
4141
abortOnError?: boolean;
42+
deleteTsConfig?: boolean;
4243
}
4344
```
4445

@@ -50,7 +51,8 @@ When configuring `generateTypes` to `true`, the following configuration will be
5051
"abortOnError": false,
5152
"extractThirdParty": false,
5253
"extractRemoteTypes": false,
53-
"compileInChildProcess": true
54+
"compileInChildProcess": true,
55+
"deleteTsConfig": true
5456
}
5557
```
5658

@@ -125,12 +127,20 @@ Whether to delete the generated type folder
125127

126128
#### compilerInstance
127129

128-
- Type: `'tsc' | 'vue-tsc' | 'tspc' | string`
130+
- Type: `'tsc' | 'tsgo' | 'vue-tsc' | 'tspc' | string`
129131
- Required: No
130132
- Default value: `'tsc'`
131133

132134
Instance of compiled type
133135

136+
#### deleteTsConfig
137+
138+
- Type: `boolean`
139+
- Required: No
140+
- Default value: `true`
141+
142+
Whether to delete the temporary tsconfig configuration file.
143+
134144
### consumeTypes
135145

136146
- Type: `boolean | DtsHostOptions`

apps/website-new/docs/zh/configure/dts.mdx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ interface DtsRemoteOptions {
3838
extractThirdParty?: boolean;
3939
extractRemoteTypes?: boolean;
4040
abortOnError?: boolean;
41+
deleteTsConfig?: boolean;
4142
}
4243
```
4344

@@ -49,7 +50,8 @@ interface DtsRemoteOptions {
4950
"abortOnError": false,
5051
"extractThirdParty": false,
5152
"extractRemoteTypes": false,
52-
"compileInChildProcess": true
53+
"compileInChildProcess": true,
54+
"deleteTsConfig": true
5355
}
5456
```
5557

@@ -125,12 +127,20 @@ tsconfig 配置文件路径
125127

126128
#### compilerInstance
127129

128-
- 类型:`'tsc' | 'vue-tsc' | 'tspc' | string`
130+
- 类型:`'tsc' | 'tsgo' | 'vue-tsc' | 'tspc' | string`
129131
- 是否必填:否
130132
- 默认值:`'tsc'`
131133

132134
编译类型的示例
133135

136+
#### deleteTsConfig
137+
138+
- 类型:`boolean`
139+
- 是否必填:否
140+
- 默认值:`true`
141+
142+
是否删除临时 tsconfig 配置文件。
143+
134144
### consumeTypes
135145

136146
- 类型:`boolean | DtsHostOptions`

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ describe('hostPlugin', () => {
8383
implementation: '',
8484
generateAPITypes: false,
8585
context: process.cwd(),
86+
deleteTsConfig: true,
8687
outputDir: '',
8788
abortOnError: true,
8889
extractRemoteTypes: false,
@@ -152,6 +153,7 @@ describe('hostPlugin', () => {
152153
generateAPITypes: false,
153154
implementation: '',
154155
context: process.cwd(),
156+
deleteTsConfig: true,
155157
outputDir: '',
156158
abortOnError: true,
157159
extractRemoteTypes: false,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const defaultOptions = {
2323
extractRemoteTypes: false,
2424
extractThirdParty: false,
2525
outputDir: '',
26+
deleteTsConfig: true,
2627
} satisfies Partial<RemoteOptions>;
2728

2829
function getEffectiveRootDir(

packages/dts-plugin/src/core/lib/typeScriptCompiler.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ describe('typeScriptCompiler', () => {
5353
hostRemoteTypesFolder: '@mf-types',
5454
abortOnError: true,
5555
outputDir: 'outputDir',
56+
deleteTsConfig: true,
5657
};
5758

5859
it('retrieveMfTypesPath correctly calculate path', () => {
@@ -127,6 +128,9 @@ describe('typeScriptCompiler', () => {
127128
children: [
128129
{
129130
children: [
131+
{
132+
name: 'HostOptions.d.ts',
133+
},
130134
{
131135
name: 'RemoteOptions.d.ts',
132136
},

packages/dts-plugin/src/core/lib/typeScriptCompiler.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { TEMP_DIR } from '@module-federation/sdk';
2323

2424
import { RemoteOptions } from '../interfaces/RemoteOptions';
2525
import { TsConfigJson } from '../interfaces/TsConfigJson';
26+
import { logger } from '../../server';
2627

2728
const STARTS_WITH_SLASH = /^\//;
2829

@@ -198,6 +199,7 @@ export const compileTs = async (
198199
? (remoteOptions.moduleFederationConfig.dts?.cwd ?? undefined)
199200
: undefined,
200201
);
202+
logger.debug(`tempTsConfigJsonPath: ${tempTsConfigJsonPath}`);
201203
try {
202204
const mfTypePath = retrieveMfTypesPath(tsConfig, remoteOptions);
203205
const thirdPartyExtractor = new ThirdPartyExtractor({
@@ -269,7 +271,9 @@ export const compileTs = async (
269271
await thirdPartyExtractor.copyDts();
270272
}
271273

272-
await rm(tempTsConfigJsonPath);
274+
if (remoteOptions.deleteTsConfig) {
275+
await rm(tempTsConfigJsonPath);
276+
}
273277
} catch (err) {
274278
throw err;
275279
}

packages/dts-plugin/src/server/Publisher.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
UpdateSubscriberAPIPayload,
77
} from './message/API';
88
import { getIdentifier, fileLog } from './utils';
9-
import { FetchTypesPayload } from './message/Action';
109
import { RemoteInfo } from '../core/interfaces/HostOptions';
1110

1211
interface PublisherContext {

0 commit comments

Comments
 (0)