From 9bb1a4d39fe039de628e766996da4b0361fbb933 Mon Sep 17 00:00:00 2001 From: 2heal1 Date: Fri, 20 Dec 2024 10:35:05 +0800 Subject: [PATCH] fix(enhanced): abort process if not find expose modules --- .changeset/shaggy-flowers-cry.md | 2 +- .../lib/container/ContainerEntryDependency.ts | 4 --- .../src/lib/container/ContainerEntryModule.ts | 25 ++++++------------- .../container/ContainerEntryModuleFactory.ts | 1 - .../src/lib/container/ContainerPlugin.ts | 2 -- .../sdk/src/types/plugins/ContainerPlugin.ts | 4 --- .../types/plugins/ModuleFederationPlugin.ts | 4 --- 7 files changed, 8 insertions(+), 34 deletions(-) diff --git a/.changeset/shaggy-flowers-cry.md b/.changeset/shaggy-flowers-cry.md index 2e7976a95b8..81d0608025d 100644 --- a/.changeset/shaggy-flowers-cry.md +++ b/.changeset/shaggy-flowers-cry.md @@ -4,4 +4,4 @@ '@module-federation/sdk': patch --- -fix(enhanced): add abortOnMissExpose field +fix(enhanced): abort process if not find expose modules diff --git a/packages/enhanced/src/lib/container/ContainerEntryDependency.ts b/packages/enhanced/src/lib/container/ContainerEntryDependency.ts index 6434bcff4ab..6552f89e5e5 100644 --- a/packages/enhanced/src/lib/container/ContainerEntryDependency.ts +++ b/packages/enhanced/src/lib/container/ContainerEntryDependency.ts @@ -23,7 +23,6 @@ class ContainerEntryDependency extends Dependency { /** Additional experimental options for container plugin customization */ public experiments: containerPlugin.ContainerPluginOptions['experiments']; public dataPrefetch: containerPlugin.ContainerPluginOptions['dataPrefetch']; - public abortOnMissingExposes: containerPlugin.ContainerPluginOptions['abortOnMissingExposes']; /** * @param {string} name entry name @@ -32,7 +31,6 @@ class ContainerEntryDependency extends Dependency { * @param {string[]} injectRuntimeEntry the path of injectRuntime file. * @param {containerPlugin.ContainerPluginOptions['experiments']} experiments additional experiments options * @param {containerPlugin.ContainerPluginOptions['dataPrefetch']} dataPrefetch whether enable dataPrefetch - * @param {containerPlugin.ContainerPluginOptions['abortOnMissingExposes']} abortOnMissingExposes whether abort the compile if miss module */ constructor( name: string, @@ -41,7 +39,6 @@ class ContainerEntryDependency extends Dependency { injectRuntimeEntry: string, experiments: containerPlugin.ContainerPluginOptions['experiments'], dataPrefetch: containerPlugin.ContainerPluginOptions['dataPrefetch'], - abortOnMissingExposes: containerPlugin.ContainerPluginOptions['abortOnMissingExposes'], ) { super(); this.name = name; @@ -50,7 +47,6 @@ class ContainerEntryDependency extends Dependency { this.injectRuntimeEntry = injectRuntimeEntry; this.experiments = experiments; this.dataPrefetch = dataPrefetch; - this.abortOnMissingExposes = abortOnMissingExposes; } /** diff --git a/packages/enhanced/src/lib/container/ContainerEntryModule.ts b/packages/enhanced/src/lib/container/ContainerEntryModule.ts index 41823441f22..58e2461b2c0 100644 --- a/packages/enhanced/src/lib/container/ContainerEntryModule.ts +++ b/packages/enhanced/src/lib/container/ContainerEntryModule.ts @@ -66,7 +66,6 @@ class ContainerEntryModule extends Module { private _injectRuntimeEntry: string; private _experiments: containerPlugin.ContainerPluginOptions['experiments']; private _dataPrefetch: containerPlugin.ContainerPluginOptions['dataPrefetch']; - private _abortOnMissingExposes: containerPlugin.ContainerPluginOptions['abortOnMissingExposes']; /** * @param {string} name container entry name @@ -75,7 +74,6 @@ class ContainerEntryModule extends Module { * @param {string} injectRuntimeEntry the path of injectRuntime file. * @param {containerPlugin.ContainerPluginOptions['experiments']} experiments additional experiments options * @param {containerPlugin.ContainerPluginOptions['dataPrefetch']} dataPrefetch whether enable dataPrefetch - * @param {containerPlugin.ContainerPluginOptions['abortOnMissingExposes']} abortOnMissingExposes whether abort the compile if miss module */ constructor( name: string, @@ -84,7 +82,6 @@ class ContainerEntryModule extends Module { injectRuntimeEntry: string, experiments: containerPlugin.ContainerPluginOptions['experiments'], dataPrefetch: containerPlugin.ContainerPluginOptions['dataPrefetch'], - abortOnMissingExposes: containerPlugin.ContainerPluginOptions['abortOnMissingExposes'], ) { super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, null); this._name = name; @@ -93,7 +90,6 @@ class ContainerEntryModule extends Module { this._injectRuntimeEntry = injectRuntimeEntry; this._experiments = experiments; this._dataPrefetch = dataPrefetch; - this._abortOnMissingExposes = abortOnMissingExposes; } /** @@ -109,7 +105,6 @@ class ContainerEntryModule extends Module { read(), read(), read(), - read(), ); obj.deserialize(context); return obj; @@ -240,18 +235,13 @@ class ContainerEntryModule extends Module { let str; if (modules.some((m) => !m.module)) { - if (this._abortOnMissingExposes) { - logger.error( - getShortErrorMsg(BUILD_001, buildDescMap, { - exposeModules: modules.filter((m) => !m.module), - FEDERATION_WEBPACK_PATH: process.env['FEDERATION_WEBPACK_PATH'], - }), - ); - process.exit(1); - } - str = runtimeTemplate.throwMissingModuleErrorBlock({ - request: modules.map((m) => m.request).join(', '), - }); + logger.error( + getShortErrorMsg(BUILD_001, buildDescMap, { + exposeModules: modules.filter((m) => !m.module), + FEDERATION_WEBPACK_PATH: process.env['FEDERATION_WEBPACK_PATH'], + }), + ); + process.exit(1); } else { str = `return ${runtimeTemplate.blockPromise({ block, @@ -378,7 +368,6 @@ class ContainerEntryModule extends Module { write(this._injectRuntimeEntry); write(this._experiments); write(this._dataPrefetch); - write(this._abortOnMissingExposes); super.serialize(context); } } diff --git a/packages/enhanced/src/lib/container/ContainerEntryModuleFactory.ts b/packages/enhanced/src/lib/container/ContainerEntryModuleFactory.ts index c28fec9a0b9..56a33c33397 100644 --- a/packages/enhanced/src/lib/container/ContainerEntryModuleFactory.ts +++ b/packages/enhanced/src/lib/container/ContainerEntryModuleFactory.ts @@ -40,7 +40,6 @@ export default class ContainerEntryModuleFactory extends ModuleFactory { dep.injectRuntimeEntry, dep.experiments, dep.dataPrefetch, - dep.abortOnMissingExposes, ), }); } diff --git a/packages/enhanced/src/lib/container/ContainerPlugin.ts b/packages/enhanced/src/lib/container/ContainerPlugin.ts index 7b30fceb747..0a5c5339445 100644 --- a/packages/enhanced/src/lib/container/ContainerPlugin.ts +++ b/packages/enhanced/src/lib/container/ContainerPlugin.ts @@ -207,7 +207,6 @@ class ContainerPlugin { federationRuntimePluginInstance.entryFilePath, this._options.experiments, this._options.dataPrefetch, - this._options.abortOnMissingExposes, ); dep.loc = { name }; @@ -287,7 +286,6 @@ class ContainerPlugin { federationRuntimePluginInstance.entryFilePath, this._options.experiments, this._options.dataPrefetch, - this._options.abortOnMissingExposes, ); dep.loc = { name }; diff --git a/packages/sdk/src/types/plugins/ContainerPlugin.ts b/packages/sdk/src/types/plugins/ContainerPlugin.ts index cfb2c6fb521..da350d51707 100644 --- a/packages/sdk/src/types/plugins/ContainerPlugin.ts +++ b/packages/sdk/src/types/plugins/ContainerPlugin.ts @@ -103,10 +103,6 @@ export interface ContainerPluginOptions { federationRuntime?: false | 'hoisted'; }; dataPrefetch?: DataPrefetch; - /** - * If not find exposes module , it will throw error when abortOnMissingExposes is true - */ - abortOnMissingExposes?: boolean; } /** * Modules that should be exposed by this container. Property names are used as public paths. diff --git a/packages/sdk/src/types/plugins/ModuleFederationPlugin.ts b/packages/sdk/src/types/plugins/ModuleFederationPlugin.ts index 7cf84f1340b..074ab98329a 100644 --- a/packages/sdk/src/types/plugins/ModuleFederationPlugin.ts +++ b/packages/sdk/src/types/plugins/ModuleFederationPlugin.ts @@ -229,10 +229,6 @@ export interface ModuleFederationPluginOptions { implementation?: string; manifest?: boolean | PluginManifestOptions; - /** - * If not find exposes module , it will throw error when abortOnMissingExposes is true - */ - abortOnMissingExposes?: boolean; dev?: boolean | PluginDevOptions; dts?: boolean | PluginDtsOptions; async?: boolean | AsyncBoundaryOptions;