Skip to content

Commit 1be9d62

Browse files
authored
feat(dts-plugin): add dts.displayErrorInTerminal to help control display error (#3438)
1 parent 6e3afc6 commit 1be9d62

File tree

12 files changed

+76
-6
lines changed

12 files changed

+76
-6
lines changed

.changeset/empty-steaks-appear.md

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.displayErrorInTerminal to help control display error

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,3 +224,11 @@ tsconfig configuration file path
224224
- Default value: `undefined`
225225

226226
The working directory to run the compiler
227+
228+
### displayErrorInTerminal
229+
230+
- Type: `boolean`
231+
- Required: No
232+
- Default value: `true`
233+
234+
Whether print error log in terminal

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,19 @@ interface DtsHostOptions {
216216
- 默认值:`path.join(process.cwd(),'./tsconfig.json')`
217217

218218
tsconfig 配置文件路径
219+
220+
### cwd
221+
222+
- 类型:`string`
223+
- 是否必填:否
224+
- 默认值:`undefined`
225+
226+
运行 tsc 的路径,默认为项目根目录。
227+
228+
### displayErrorInTerminal
229+
230+
- 类型:`boolean`
231+
- 是否必填:否
232+
- 默认值:`true`
233+
234+
是否在 terminal 输出错误日志
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import { moduleFederationPlugin } from '@module-federation/sdk';
12
import { HostOptions } from './HostOptions';
23
import { RemoteOptions } from './RemoteOptions';
34

45
export interface DTSManagerOptions {
56
remote?: RemoteOptions;
67
host?: HostOptions;
78
extraOptions?: Record<string, any>;
9+
displayErrorInTerminal?: moduleFederationPlugin.PluginDtsOptions['displayErrorInTerminal'];
810
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ class DTSManager {
166166
logger.success('Federated types created correctly');
167167
} catch (error) {
168168
if (this.options.remote?.abortOnError === false) {
169-
logger.error(`Unable to compile federated types${error}`);
169+
if (this.options.displayErrorInTerminal) {
170+
logger.error(`Unable to compile federated types${error}`);
171+
}
170172
} else {
171173
throw error;
172174
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export class ConsumeTypesPlugin implements WebpackPluginInstance {
5252
...normalizedConsumeTypes,
5353
},
5454
extraOptions: dtsOptions.extraOptions || {},
55+
displayErrorInTerminal: dtsOptions.displayErrorInTerminal,
5556
};
5657

5758
validateOptions(finalOptions.host);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,17 @@ export class DevPlugin implements WebpackPluginInstance {
3636
readonly name = 'MFDevPlugin';
3737
private _options: moduleFederationPlugin.ModuleFederationPluginOptions;
3838
private _devWorker?: DevWorker;
39+
dtsOptions: moduleFederationPlugin.PluginDtsOptions;
3940
fetchTypesPromise: Promise<void>;
4041

4142
constructor(
4243
options: moduleFederationPlugin.ModuleFederationPluginOptions,
44+
dtsOptions: moduleFederationPlugin.PluginDtsOptions,
4345
fetchTypesPromise: Promise<void>,
4446
) {
4547
this._options = options;
4648
this.fetchTypesPromise = fetchTypesPromise;
49+
this.dtsOptions = dtsOptions;
4750
}
4851

4952
static ensureLiveReloadEntry(
@@ -173,6 +176,7 @@ export class DevPlugin implements WebpackPluginInstance {
173176
generateTypes: defaultGenerateTypes,
174177
consumeTypes: defaultConsumeTypes,
175178
extraOptions: {},
179+
displayErrorInTerminal: this.dtsOptions?.displayErrorInTerminal,
176180
},
177181
'mfOptions.dts',
178182
)(dts);

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export class DtsPlugin implements WebpackPluginInstance {
3131
generateTypes: defaultGenerateTypes,
3232
consumeTypes: defaultConsumeTypes,
3333
extraOptions: {},
34+
displayErrorInTerminal: true,
3435
},
3536
'mfOptions.dts',
3637
)(options.dts);
@@ -51,7 +52,9 @@ export class DtsPlugin implements WebpackPluginInstance {
5152

5253
// Because the plugin will delete dist/@mf-types.zip while generating types, which will be used in GenerateTypesPlugin
5354
// So it should apply after GenerateTypesPlugin
54-
new DevPlugin(options, generateTypesPromise).apply(compiler);
55+
new DevPlugin(options, normalizedDtsOptions, generateTypesPromise).apply(
56+
compiler,
57+
);
5558

5659
// The exposes files may use remote types, so it need to consume types first, otherwise the generate types will fail
5760
new GenerateTypesPlugin(

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export class GenerateTypesPlugin implements WebpackPluginInstance {
6565
...normalizedGenerateTypes,
6666
},
6767
extraOptions: dtsOptions.extraOptions || {},
68+
displayErrorInTerminal: dtsOptions.displayErrorInTerminal,
6869
};
6970

7071
if (dtsOptions.tsConfigPath && !finalOptions.remote.tsConfigPath) {
@@ -157,7 +158,12 @@ export class GenerateTypesPlugin implements WebpackPluginInstance {
157158
callback();
158159
} catch (err) {
159160
callback();
160-
console.error('Error in mf:generateTypes processAssets hook:', err);
161+
if (finalOptions.displayErrorInTerminal) {
162+
console.error(
163+
'Error in mf:generateTypes processAssets hook:',
164+
err,
165+
);
166+
}
161167
}
162168
},
163169
);

packages/manifest/src/StatsManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class StatsManager {
134134
(this._options?.library?.type as RemoteEntryType | undefined) ||
135135
'global',
136136
},
137-
types: getTypesMetaInfo(this._options, compiler.context),
137+
types: getTypesMetaInfo(this._options, compiler.context, compilation),
138138
globalName: globalName,
139139
pluginVersion: this._pluginVersion,
140140
};

0 commit comments

Comments
 (0)