diff --git a/.changeset/empty-steaks-appear.md b/.changeset/empty-steaks-appear.md new file mode 100644 index 0000000000..8168610e0f --- /dev/null +++ b/.changeset/empty-steaks-appear.md @@ -0,0 +1,5 @@ +--- +'@module-federation/dts-plugin': patch +--- + +feat(dts-plugin): add dts.displayErrorInTerminal to help control display error diff --git a/packages/dts-plugin/src/core/interfaces/DTSManagerOptions.ts b/packages/dts-plugin/src/core/interfaces/DTSManagerOptions.ts index 13590eb74c..99cded775e 100644 --- a/packages/dts-plugin/src/core/interfaces/DTSManagerOptions.ts +++ b/packages/dts-plugin/src/core/interfaces/DTSManagerOptions.ts @@ -1,3 +1,4 @@ +import { moduleFederationPlugin } from '@module-federation/sdk'; import { HostOptions } from './HostOptions'; import { RemoteOptions } from './RemoteOptions'; @@ -5,4 +6,5 @@ export interface DTSManagerOptions { remote?: RemoteOptions; host?: HostOptions; extraOptions?: Record; + displayErrorInTerminal?: moduleFederationPlugin.PluginDtsOptions['displayErrorInTerminal']; } diff --git a/packages/dts-plugin/src/core/lib/DTSManager.ts b/packages/dts-plugin/src/core/lib/DTSManager.ts index 183f6316f0..ab1c6e3d7e 100644 --- a/packages/dts-plugin/src/core/lib/DTSManager.ts +++ b/packages/dts-plugin/src/core/lib/DTSManager.ts @@ -166,7 +166,9 @@ class DTSManager { logger.success('Federated types created correctly'); } catch (error) { if (this.options.remote?.abortOnError === false) { - logger.error(`Unable to compile federated types${error}`); + if (this.options.displayErrorInTerminal) { + logger.error(`Unable to compile federated types${error}`); + } } else { throw error; } diff --git a/packages/dts-plugin/src/plugins/ConsumeTypesPlugin.ts b/packages/dts-plugin/src/plugins/ConsumeTypesPlugin.ts index fd9be8a41a..ac1a899607 100644 --- a/packages/dts-plugin/src/plugins/ConsumeTypesPlugin.ts +++ b/packages/dts-plugin/src/plugins/ConsumeTypesPlugin.ts @@ -52,6 +52,7 @@ export class ConsumeTypesPlugin implements WebpackPluginInstance { ...normalizedConsumeTypes, }, extraOptions: dtsOptions.extraOptions || {}, + displayErrorInTerminal: dtsOptions.displayErrorInTerminal, }; validateOptions(finalOptions.host); diff --git a/packages/dts-plugin/src/plugins/DevPlugin.ts b/packages/dts-plugin/src/plugins/DevPlugin.ts index 5a9a178e75..a46e2858c5 100644 --- a/packages/dts-plugin/src/plugins/DevPlugin.ts +++ b/packages/dts-plugin/src/plugins/DevPlugin.ts @@ -36,14 +36,17 @@ export class DevPlugin implements WebpackPluginInstance { readonly name = 'MFDevPlugin'; private _options: moduleFederationPlugin.ModuleFederationPluginOptions; private _devWorker?: DevWorker; + dtsOptions: moduleFederationPlugin.PluginDtsOptions; fetchTypesPromise: Promise; constructor( options: moduleFederationPlugin.ModuleFederationPluginOptions, + dtsOptions: moduleFederationPlugin.PluginDtsOptions, fetchTypesPromise: Promise, ) { this._options = options; this.fetchTypesPromise = fetchTypesPromise; + this.dtsOptions = dtsOptions; } static ensureLiveReloadEntry( @@ -173,6 +176,7 @@ export class DevPlugin implements WebpackPluginInstance { generateTypes: defaultGenerateTypes, consumeTypes: defaultConsumeTypes, extraOptions: {}, + displayErrorInTerminal: this.dtsOptions?.displayErrorInTerminal, }, 'mfOptions.dts', )(dts); diff --git a/packages/dts-plugin/src/plugins/DtsPlugin.ts b/packages/dts-plugin/src/plugins/DtsPlugin.ts index 0c2835f806..84d1a9bdd5 100644 --- a/packages/dts-plugin/src/plugins/DtsPlugin.ts +++ b/packages/dts-plugin/src/plugins/DtsPlugin.ts @@ -31,6 +31,7 @@ export class DtsPlugin implements WebpackPluginInstance { generateTypes: defaultGenerateTypes, consumeTypes: defaultConsumeTypes, extraOptions: {}, + displayErrorInTerminal: true, }, 'mfOptions.dts', )(options.dts); @@ -51,7 +52,9 @@ export class DtsPlugin implements WebpackPluginInstance { // Because the plugin will delete dist/@mf-types.zip while generating types, which will be used in GenerateTypesPlugin // So it should apply after GenerateTypesPlugin - new DevPlugin(options, generateTypesPromise).apply(compiler); + new DevPlugin(options, normalizedDtsOptions, generateTypesPromise).apply( + compiler, + ); // The exposes files may use remote types, so it need to consume types first, otherwise the generate types will fail new GenerateTypesPlugin( diff --git a/packages/dts-plugin/src/plugins/GenerateTypesPlugin.ts b/packages/dts-plugin/src/plugins/GenerateTypesPlugin.ts index 13ae3cde2e..3fe6a22747 100644 --- a/packages/dts-plugin/src/plugins/GenerateTypesPlugin.ts +++ b/packages/dts-plugin/src/plugins/GenerateTypesPlugin.ts @@ -65,6 +65,7 @@ export class GenerateTypesPlugin implements WebpackPluginInstance { ...normalizedGenerateTypes, }, extraOptions: dtsOptions.extraOptions || {}, + displayErrorInTerminal: dtsOptions.displayErrorInTerminal, }; if (dtsOptions.tsConfigPath && !finalOptions.remote.tsConfigPath) { diff --git a/packages/sdk/src/types/plugins/ModuleFederationPlugin.ts b/packages/sdk/src/types/plugins/ModuleFederationPlugin.ts index eaebe46717..70105e26ac 100644 --- a/packages/sdk/src/types/plugins/ModuleFederationPlugin.ts +++ b/packages/sdk/src/types/plugins/ModuleFederationPlugin.ts @@ -167,6 +167,7 @@ export interface PluginDtsOptions { extraOptions?: Record; implementation?: string; cwd?: string; + displayErrorInTerminal?: boolean; } export type AsyncBoundaryOptions = {