Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/serious-peaches-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/dts-plugin': patch
---

feat(dts-plugin): add dts.generateTypes.deleteTsConfig field
14 changes: 12 additions & 2 deletions apps/website-new/docs/en/configure/dts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ interface DtsRemoteOptions {
extractThirdParty?: boolean;
extractRemoteTypes?: boolean;
abortOnError?: boolean;
deleteTsConfig?: boolean;
}
```

Expand All @@ -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
}
```

Expand Down Expand Up @@ -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`
Expand Down
14 changes: 12 additions & 2 deletions apps/website-new/docs/zh/configure/dts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ interface DtsRemoteOptions {
extractThirdParty?: boolean;
extractRemoteTypes?: boolean;
abortOnError?: boolean;
deleteTsConfig?: boolean;
}
```

Expand All @@ -49,7 +50,8 @@ interface DtsRemoteOptions {
"abortOnError": false,
"extractThirdParty": false,
"extractRemoteTypes": false,
"compileInChildProcess": true
"compileInChildProcess": true,
"deleteTsConfig": true
}
```

Expand Down Expand Up @@ -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`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ describe('hostPlugin', () => {
implementation: '',
generateAPITypes: false,
context: process.cwd(),
deleteTsConfig: true,
outputDir: '',
abortOnError: true,
extractRemoteTypes: false,
Expand Down Expand Up @@ -152,6 +153,7 @@ describe('hostPlugin', () => {
generateAPITypes: false,
implementation: '',
context: process.cwd(),
deleteTsConfig: true,
outputDir: '',
abortOnError: true,
extractRemoteTypes: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const defaultOptions = {
extractRemoteTypes: false,
extractThirdParty: false,
outputDir: '',
deleteTsConfig: true,
} satisfies Partial<RemoteOptions>;

function getEffectiveRootDir(
Expand Down
4 changes: 4 additions & 0 deletions packages/dts-plugin/src/core/lib/typeScriptCompiler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ describe('typeScriptCompiler', () => {
hostRemoteTypesFolder: '@mf-types',
abortOnError: true,
outputDir: 'outputDir',
deleteTsConfig: true,
};

it('retrieveMfTypesPath correctly calculate path', () => {
Expand Down Expand Up @@ -127,6 +128,9 @@ describe('typeScriptCompiler', () => {
children: [
{
children: [
{
name: 'HostOptions.d.ts',
},
{
name: 'RemoteOptions.d.ts',
},
Expand Down
6 changes: 5 additions & 1 deletion packages/dts-plugin/src/core/lib/typeScriptCompiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = /^\//;

Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -269,7 +271,9 @@ export const compileTs = async (
await thirdPartyExtractor.copyDts();
}

await rm(tempTsConfigJsonPath);
if (remoteOptions.deleteTsConfig) {
await rm(tempTsConfigJsonPath);
}
} catch (err) {
throw err;
}
Expand Down
1 change: 0 additions & 1 deletion packages/dts-plugin/src/server/Publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading
Loading