Skip to content

Commit

Permalink
feat(dts-plugin): add dts.displayErrorInTerminal to help control disp…
Browse files Browse the repository at this point in the history
…lay error
  • Loading branch information
2heal1 committed Jan 15, 2025
1 parent 6e3afc6 commit 6b89a05
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/empty-steaks-appear.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.displayErrorInTerminal to help control display error
2 changes: 2 additions & 0 deletions packages/dts-plugin/src/core/interfaces/DTSManagerOptions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { moduleFederationPlugin } from '@module-federation/sdk';
import { HostOptions } from './HostOptions';
import { RemoteOptions } from './RemoteOptions';

export interface DTSManagerOptions {
remote?: RemoteOptions;
host?: HostOptions;
extraOptions?: Record<string, any>;
displayErrorInTerminal?: moduleFederationPlugin.PluginDtsOptions['displayErrorInTerminal'];
}
4 changes: 3 additions & 1 deletion packages/dts-plugin/src/core/lib/DTSManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions packages/dts-plugin/src/plugins/ConsumeTypesPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export class ConsumeTypesPlugin implements WebpackPluginInstance {
...normalizedConsumeTypes,
},
extraOptions: dtsOptions.extraOptions || {},
displayErrorInTerminal: dtsOptions.displayErrorInTerminal,
};

validateOptions(finalOptions.host);
Expand Down
4 changes: 4 additions & 0 deletions packages/dts-plugin/src/plugins/DevPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,17 @@ export class DevPlugin implements WebpackPluginInstance {
readonly name = 'MFDevPlugin';
private _options: moduleFederationPlugin.ModuleFederationPluginOptions;
private _devWorker?: DevWorker;
dtsOptions: moduleFederationPlugin.PluginDtsOptions;
fetchTypesPromise: Promise<void>;

constructor(
options: moduleFederationPlugin.ModuleFederationPluginOptions,
dtsOptions: moduleFederationPlugin.PluginDtsOptions,
fetchTypesPromise: Promise<void>,
) {
this._options = options;
this.fetchTypesPromise = fetchTypesPromise;
this.dtsOptions = dtsOptions;
}

static ensureLiveReloadEntry(
Expand Down Expand Up @@ -173,6 +176,7 @@ export class DevPlugin implements WebpackPluginInstance {
generateTypes: defaultGenerateTypes,
consumeTypes: defaultConsumeTypes,
extraOptions: {},
displayErrorInTerminal: this.dtsOptions?.displayErrorInTerminal,
},
'mfOptions.dts',
)(dts);
Expand Down
5 changes: 4 additions & 1 deletion packages/dts-plugin/src/plugins/DtsPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class DtsPlugin implements WebpackPluginInstance {
generateTypes: defaultGenerateTypes,
consumeTypes: defaultConsumeTypes,
extraOptions: {},
displayErrorInTerminal: true,
},
'mfOptions.dts',
)(options.dts);
Expand All @@ -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(
Expand Down
1 change: 1 addition & 0 deletions packages/dts-plugin/src/plugins/GenerateTypesPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class GenerateTypesPlugin implements WebpackPluginInstance {
...normalizedGenerateTypes,
},
extraOptions: dtsOptions.extraOptions || {},
displayErrorInTerminal: dtsOptions.displayErrorInTerminal,
};

if (dtsOptions.tsConfigPath && !finalOptions.remote.tsConfigPath) {
Expand Down
1 change: 1 addition & 0 deletions packages/sdk/src/types/plugins/ModuleFederationPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ export interface PluginDtsOptions {
extraOptions?: Record<string, any>;
implementation?: string;
cwd?: string;
displayErrorInTerminal?: boolean;
}

export type AsyncBoundaryOptions = {
Expand Down

0 comments on commit 6b89a05

Please sign in to comment.