Skip to content

Commit c14842f

Browse files
authored
feat(dts-plugin): support tspc (#3662)
1 parent ebe7d89 commit c14842f

File tree

8 files changed

+104
-4
lines changed

8 files changed

+104
-4
lines changed

.changeset/tasty-horses-juggle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/sdk': patch
3+
---
4+
5+
feat(dts-plugin): support tspc

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,11 @@ Whether to delete the generated type folder
125125

126126
#### compilerInstance
127127

128-
- Type: `'tsc' | 'vue-tsc'`
128+
- Type: `'tsc' | 'vue-tsc' | 'tspc' | string`
129129
- Required: No
130130
- Default value: `'tsc'`
131131

132-
Example of compiled type
132+
Instance of compiled type
133133

134134
### consumeTypes
135135

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[
2+
"overview",
3+
"TYPE-001"
4+
]
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Overview
2+
3+
Type errors are divided into two types: fixed error code errors and scenario-related errors.
4+
5+
## Fixed error code errors
6+
7+
This type of error can be clearly captured in the code, and a fixed error code is assigned to each error. The error code consists of the error type and ID, such as `TYPE-001`. You can find the specified page based on the error code to understand the cause of the error and the solution.
8+
9+
### Error code list
10+
11+
* [TYPE-001](./TYPE-001)
12+
13+
## Scenario-related errors
14+
15+
This type of error is generated based on the user's specific scenario and has no fixed error code. The error message and handling method will vary depending on the scenario.
16+
17+
### Generated type contains aliases
18+
19+
**Phenomenon description**
20+
21+
The type generated by the producer contains aliases and cannot be processed normally in the consumer.
22+
23+
**How ​​to solve**
24+
25+
1. Install [typescript-transform-paths](https://www.npmjs.com/package/typescript-transform-paths) and [ts-patch](https://www.npmjs.com/package/ts-patch)
26+
27+
2. Apply `typescript-transform-paths` in `tsconfig.json`
28+
29+
```diff
30+
{
31+
"compilerOptions": {
32+
+ "plugins": [
33+
+ { "transform": "typescript-transform-paths" },
34+
+ {
35+
+ "transform": "typescript-transform-paths",
36+
+ "afterDeclarations": true
37+
+ }
38+
+ ],
39+
},
40+
}
41+
```
42+
43+
3. Set [dts.generateTypes.compilerInstance](../../../configure/dts#compilerinstance) to `tspc`(`ts-patch` cli)
44+
4. Regenerate types

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ tsconfig 配置文件路径
125125

126126
#### compilerInstance
127127

128-
- 类型:`'tsc' | 'vue-tsc'`
128+
- 类型:`'tsc' | 'vue-tsc' | 'tspc' | string`
129129
- 是否必填:否
130130
- 默认值:`'tsc'`
131131

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[
2+
"overview",
3+
"TYPE-001"
4+
]
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# 概览
2+
3+
类型错误分为两种类型:固定错误码错误和场景相关错误。
4+
5+
## 固定错误码错误
6+
7+
这类错误在代码中能够被明确捕获,并且会为每个错误分配一个固定的错误码。错误码由错误类型和 ID 组成,例如 `TYPE-001`。你可以根据错误码找到指定的页面,了解错误原因和解决方案。
8+
9+
### 错误码列表
10+
11+
* [TYPE-001](./TYPE-001)
12+
13+
## 场景相关错误
14+
15+
这类错误是根据用户的具体场景产生的,没有固定的错误码。其错误信息和处理方式会根据不同的场景而有所变化。
16+
17+
### 生成类型包含别名
18+
19+
**现象描述**
20+
21+
生产者生成的类型含有别名,在消费者中无法正常处理。
22+
23+
**如何解决**
24+
25+
1. 安装 [typescript-transform-paths](https://www.npmjs.com/package/typescript-transform-paths)[ts-patch](https://www.npmjs.com/package/ts-patch)
26+
2.`tsconfig.json` 中应用 `typescript-transform-paths`
27+
28+
```diff
29+
{
30+
"compilerOptions": {
31+
+ "plugins": [
32+
+ { "transform": "typescript-transform-paths" },
33+
+ {
34+
+ "transform": "typescript-transform-paths",
35+
+ "afterDeclarations": true
36+
+ }
37+
+ ],
38+
},
39+
}
40+
```
41+
42+
3. 设置 [dts.generateTypes.compilerInstance](../../../configure/dts#compilerinstance)`tspc`(`ts-patch` cli)
43+
4. 重新生成类型

packages/sdk/src/types/plugins/ModuleFederationPlugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export interface DtsRemoteOptions {
165165
deleteTypesFolder?: boolean;
166166
additionalFilesToCompile?: string[];
167167
compileInChildProcess?: boolean;
168-
compilerInstance?: 'tsc' | 'vue-tsc';
168+
compilerInstance?: 'tsc' | 'vue-tsc' | 'tspc' | string;
169169
generateAPITypes?: boolean;
170170
extractThirdParty?: boolean;
171171
extractRemoteTypes?: boolean;

0 commit comments

Comments
 (0)