Skip to content

Commit

Permalink
fix(enhanced): abort process if not find expose modules
Browse files Browse the repository at this point in the history
  • Loading branch information
2heal1 committed Dec 20, 2024
1 parent 9120f93 commit 9bb1a4d
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .changeset/shaggy-flowers-cry.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
'@module-federation/sdk': patch
---

fix(enhanced): add abortOnMissExpose field
fix(enhanced): abort process if not find expose modules
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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;
Expand All @@ -50,7 +47,6 @@ class ContainerEntryDependency extends Dependency {
this.injectRuntimeEntry = injectRuntimeEntry;
this.experiments = experiments;
this.dataPrefetch = dataPrefetch;
this.abortOnMissingExposes = abortOnMissingExposes;
}

/**
Expand Down
25 changes: 7 additions & 18 deletions packages/enhanced/src/lib/container/ContainerEntryModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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;
Expand All @@ -93,7 +90,6 @@ class ContainerEntryModule extends Module {
this._injectRuntimeEntry = injectRuntimeEntry;
this._experiments = experiments;
this._dataPrefetch = dataPrefetch;
this._abortOnMissingExposes = abortOnMissingExposes;
}

/**
Expand All @@ -109,7 +105,6 @@ class ContainerEntryModule extends Module {
read(),
read(),
read(),
read(),
);
obj.deserialize(context);
return obj;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -378,7 +368,6 @@ class ContainerEntryModule extends Module {
write(this._injectRuntimeEntry);
write(this._experiments);
write(this._dataPrefetch);
write(this._abortOnMissingExposes);
super.serialize(context);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export default class ContainerEntryModuleFactory extends ModuleFactory {
dep.injectRuntimeEntry,
dep.experiments,
dep.dataPrefetch,
dep.abortOnMissingExposes,
),
});
}
Expand Down
2 changes: 0 additions & 2 deletions packages/enhanced/src/lib/container/ContainerPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ class ContainerPlugin {
federationRuntimePluginInstance.entryFilePath,
this._options.experiments,
this._options.dataPrefetch,
this._options.abortOnMissingExposes,
);
dep.loc = { name };

Expand Down Expand Up @@ -287,7 +286,6 @@ class ContainerPlugin {
federationRuntimePluginInstance.entryFilePath,
this._options.experiments,
this._options.dataPrefetch,
this._options.abortOnMissingExposes,
);

dep.loc = { name };
Expand Down
4 changes: 0 additions & 4 deletions packages/sdk/src/types/plugins/ContainerPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 0 additions & 4 deletions packages/sdk/src/types/plugins/ModuleFederationPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 9bb1a4d

Please sign in to comment.