Skip to content

Commit 8f3a440

Browse files
fix(enhanced): allow dts plugin to be disabled (#2321)
Co-authored-by: ScriptedAlchemy <[email protected]> Co-authored-by: Hanric <[email protected]>
1 parent 323e827 commit 8f3a440

File tree

12 files changed

+71
-27
lines changed

12 files changed

+71
-27
lines changed

.changeset/dry-walls-enjoy.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@module-federation/dts-plugin': patch
3+
'@module-federation/enhanced': patch
4+
'website-new': patch
5+
'@module-federation/sdk': patch
6+
---
7+
8+
fix: detect whether the project is ts

.changeset/sour-kangaroos-enjoy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/enhanced': patch
3+
---
4+
5+
allow dts plugin to be disabled

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The `PluginDtsOptions` types are as follows:
1313
interface PluginDtsOptions {
1414
generateTypes?: boolean | DtsRemoteOptions;
1515
consumeTypes?: boolean | DtsHostOptions;
16+
tsConfigPath?: string;
1617
}
1718
```
1819

@@ -102,7 +103,7 @@ Whether to throw an error when a problem is encountered during type generation
102103
- Type: `string`
103104
- Required: No
104105
- Default value: `path.join(process.cwd(),'./tsconfig.json')`
105-
106+
> priority: dts.generateTypes.tsConfigPath > dts.tsConfigPath
106107
tsconfig configuration file path
107108

108109
#### typesFolder
@@ -206,3 +207,11 @@ Before loading type files, whether to delete the previously loaded `typesFolder`
206207
- Default value: `'@mf-types'`
207208

208209
`typesFolder` corresponding to `remotes` directory configuration
210+
211+
### tsConfigPath
212+
213+
- Type: `string`
214+
- Required: No
215+
- Default value: `path.join(process.cwd(),'./tsconfig.json')`
216+
217+
tsconfig configuration file path

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
interface PluginDtsOptions {
1414
generateTypes?: boolean | DtsRemoteOptions;
1515
consumeTypes?: boolean | DtsHostOptions;
16+
tsConfigPath?: string;
1617
}
1718
```
1819

@@ -102,6 +103,7 @@ interface DtsRemoteOptions {
102103
- 类型:`string`
103104
- 是否必填:否
104105
- 默认值:`path.join(process.cwd(),'./tsconfig.json')`
106+
> 优先级:dts.generateTypes.tsConfigPath > dts.tsConfigPath
105107
106108
tsconfig 配置文件路径
107109

@@ -206,3 +208,11 @@ interface DtsHostOptions {
206208
- 默认值:`'@mf-types'`
207209

208210
对应 `remotes` 目录配置的 `typesFolder`
211+
212+
### tsConfigPath
213+
214+
- 类型:`string`
215+
- 是否必填:否
216+
- 默认值:`path.join(process.cwd(),'./tsconfig.json')`
217+
218+
tsconfig 配置文件路径

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@
152152
"@vitest/coverage-istanbul": "1.2.2",
153153
"@vitest/coverage-v8": "1.2.2",
154154
"@vitest/ui": "1.2.2",
155-
"antora-navigator-extension": "https://gitlab.com/opendevise/oss/antora-navigator-extension/-/archive/main/antora-navigator-extension-main.tar.gz",
156155
"autoprefixer": "10.4.17",
157156
"babel-jest": "29.7.0",
158157
"babel-loader": "9.1.3",

packages/dts-plugin/src/plugins/DevPlugin.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,10 @@ export class DevPlugin implements WebpackPluginInstance {
138138
const defaultConsumeTypes = { consumeAPITypes: true };
139139
const normalizedDtsOptions =
140140
normalizeOptions<moduleFederationPlugin.PluginDtsOptions>(
141-
isTSProject(undefined, compiler.context),
141+
isTSProject(
142+
typeof dts === 'object' ? dts.tsConfigPath : undefined,
143+
compiler.context,
144+
),
142145
{
143146
// remote types dist(.dev-server) not be used currently, so no need to set extractThirdParty etc
144147
generateTypes: defaultGenerateTypes,
@@ -150,7 +153,7 @@ export class DevPlugin implements WebpackPluginInstance {
150153

151154
const normalizedGenerateTypes =
152155
normalizeOptions<moduleFederationPlugin.DtsRemoteOptions>(
153-
normalizedDtsOptions === false,
156+
Boolean(normalizedDtsOptions),
154157
defaultGenerateTypes,
155158
'mfOptions.dts.generateTypes',
156159
)(
@@ -202,9 +205,24 @@ export class DevPlugin implements WebpackPluginInstance {
202205
abortOnError: false,
203206
...normalizedConsumeTypes,
204207
};
208+
205209
const extraOptions = normalizedDtsOptions
206210
? normalizedDtsOptions.extraOptions || {}
207211
: {};
212+
213+
if (!remote && !host && normalizedDev.disableLiveReload) {
214+
return;
215+
}
216+
217+
if (
218+
remote &&
219+
!remote?.tsConfigPath &&
220+
typeof normalizedDtsOptions === 'object' &&
221+
normalizedDtsOptions.tsConfigPath
222+
) {
223+
remote.tsConfigPath = normalizedDtsOptions.tsConfigPath;
224+
}
225+
208226
this._devWorker = createDevWorker({
209227
name,
210228
remote: remote,

packages/dts-plugin/src/plugins/GenerateTypesPlugin.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ export class GenerateTypesPlugin implements WebpackPluginInstance {
5151
extraOptions: dtsOptions.extraOptions || {},
5252
};
5353

54+
if (dtsOptions.tsConfigPath && !finalOptions.remote.tsConfigPath) {
55+
finalOptions.remote.tsConfigPath = dtsOptions.tsConfigPath;
56+
}
57+
5458
validateOptions(finalOptions.remote);
5559
const isProd = !isDev();
5660
const getGenerateTypesFn = () => {

packages/dts-plugin/src/plugins/TypesPlugin.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ class TypesPlugin implements WebpackPluginInstance {
2626
const defaultConsumeTypes = { abortOnError: false, consumeAPITypes: true };
2727
const normalizedDtsOptions =
2828
normalizeOptions<moduleFederationPlugin.PluginDtsOptions>(
29-
isTSProject(undefined, compiler.context),
29+
isTSProject(
30+
typeof options.dts === 'object'
31+
? options.dts.tsConfigPath
32+
: undefined,
33+
compiler.context,
34+
),
3035
{
3136
generateTypes: defaultGenerateTypes,
3237
consumeTypes: defaultConsumeTypes,

packages/enhanced/src/lib/container/ModuleFederationPlugin.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ class ModuleFederationPlugin implements WebpackPluginInstance {
8888
}
8989
}
9090

91-
new DtsPlugin(options).apply(compiler);
91+
if (options.dts !== false) {
92+
new DtsPlugin(options).apply(compiler);
93+
}
9294

9395
if (
9496
library &&

packages/enhanced/src/schemas/container/ModuleFederationPlugin.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,10 @@ export default {
645645
type: 'object',
646646
additionalProperties: true,
647647
},
648+
tsConfigPath: {
649+
description: 'The tsconfig path of the project.',
650+
type: 'string',
651+
},
648652
implementation: {
649653
description: 'The implementation of the DTS Manager.',
650654
type: 'string',

0 commit comments

Comments
 (0)