Skip to content

Commit 25626cf

Browse files
chore: lint
1 parent b638b36 commit 25626cf

File tree

5 files changed

+173
-64
lines changed

5 files changed

+173
-64
lines changed

apps/website-new/docs/en/configure/advanced-sharing.mdx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ new ModuleFederationPlugin({
8383
});
8484
```
8585

86-
## Enhanced Sharing Options: Layers and Filtering
86+
## Layers
8787

8888
### `layer`
8989

@@ -217,7 +217,8 @@ You can use both `layer` and `issuerLayer` in the same shared config.
217217

218218
This combination is powerful for creating highly specific sharing boundaries, ensuring that shared modules behave correctly and are isolated as needed within different parts of a complex, layered application.
219219

220-
### `include` / `exclude`
220+
221+
## `include` / `exclude`
221222

222223
- Type: `IncludeExcludeOptions`
223224
- Required: No
@@ -239,10 +240,10 @@ interface IncludeExcludeOptions {
239240

240241
- **`fallbackVersion?: string`**:\n - **Only used with `exclude.version`** when an `import` (local fallback) is specified.\n - Provides the version string of the local fallback module for the exclusion check, avoiding a dynamic lookup.\n - If this `fallbackVersion` satisfies the `exclude.version` range, the local fallback is excluded.
241242

242-
## Why Version Exclusion Matters
243+
### Why Version Exclusion Matters
243244
The version exclusion feature addresses several critical use cases in microfrontend architectures:
244245

245-
### Use Case 1: Preventing Problematic Dependency Versions
246+
#### Use Case 1: Preventing Problematic Dependency Versions
246247
Sometimes specific versions of dependencies have known bugs or incompatibilities. With version exclusion, you can:
247248
```ts
248249
shared: {
@@ -255,7 +256,7 @@ shared: {
255256
```
256257
This ensures that even if a federated module tries to provide version 2.3.0, it will be ignored, preventing potential application failures.
257258

258-
### Use Case 2: Controlled Migration Paths
259+
#### Use Case 2: Controlled Migration Paths
259260
When gradually migrating to newer versions across multiple teams:
260261
```ts
261262
shared: {
@@ -268,7 +269,7 @@ shared: {
268269
```
269270
This configuration prevents sharing of very old versions while still allowing a controlled range of compatible versions.
270271

271-
### Use Case 3: Performance Optimization with `fallbackVersion`
272+
#### Use Case 3: Performance Optimization with `fallbackVersion`
272273
The `fallbackVersion` property provides a performance optimization that avoids filesystem lookups:
273274
```ts
274275
shared: {
@@ -284,7 +285,7 @@ shared: {
284285
```
285286
By explicitly specifying `fallbackVersion`, the system can immediately determine whether to use the fallback without having to parse package.json files, which improves build performance.
286287

287-
### Use Case 4: Preventing Loading of Incompatible Singletons
288+
#### Use Case 4: Preventing Loading of Incompatible Singletons
288289
For singleton libraries like React, loading incompatible versions can cause runtime errors:
289290
```ts
290291
shared: {
@@ -343,7 +344,9 @@ In this Next.js-style example:
343344
- `react` is configured differently for `rsc` (React Server Components) layer and `client` layer. Each uses its own `layer`, `issuerLayer`, and `shareScope` to ensure proper isolation and version control.
344345
- `next/` prefix sharing is applied to the `client` layer, excluding certain subpaths that might not be needed or could cause issues on the client.
345346

346-
## Node Modules Path Resolution
347+
## nodeModulesReconstructedLookup
348+
349+
This section covers the nodeModulesReconstructedLookup experiment, which helps with sharing modules that use relative imports internally.
347350

348351
Module Federation offers an experimental feature `nodeModulesReconstructedLookup` to solve a common issue with sharing modules that use relative imports internally.
349352

packages/enhanced/src/lib/sharing/ProvideSharedPlugin.ts

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,10 @@ class ProvideSharedPlugin {
204204
}
205205

206206
// Process normal prefix matches
207-
for (const [prefixKey, originalPrefixConfig] of prefixMatchProvides) {
207+
for (const [
208+
prefixKey,
209+
originalPrefixConfig,
210+
] of prefixMatchProvides) {
208211
const lookupPrefix = originalPrefixConfig.request || prefixKey;
209212

210213
if (request.startsWith(lookupPrefix) && resource) {
@@ -235,8 +238,12 @@ class ProvideSharedPlugin {
235238
shareKey: finalShareKey,
236239
request: request, // Full matched request
237240
// Clear request-based include/exclude as they were for the remainder
238-
include: originalPrefixConfig.include ? { ...originalPrefixConfig.include, request: undefined } : undefined,
239-
exclude: originalPrefixConfig.exclude ? { ...originalPrefixConfig.exclude, request: undefined } : undefined,
241+
include: originalPrefixConfig.include
242+
? { ...originalPrefixConfig.include, request: undefined }
243+
: undefined,
244+
exclude: originalPrefixConfig.exclude
245+
? { ...originalPrefixConfig.exclude, request: undefined }
246+
: undefined,
240247
};
241248

242249
this.provideSharedModule(
@@ -285,7 +292,10 @@ class ProvideSharedPlugin {
285292
}
286293

287294
// Also check for prefix matches with the module path after node_modules
288-
for (const [prefixKeyPM, originalPrefixConfigPM] of prefixMatchProvides) {
295+
for (const [
296+
prefixKeyPM,
297+
originalPrefixConfigPM,
298+
] of prefixMatchProvides) {
289299
const lookupPM = originalPrefixConfigPM.request || prefixKeyPM;
290300
if (modulePathAfterNodeModules.startsWith(lookupPM)) {
291301
const remainderPM = modulePathAfterNodeModules.slice(
@@ -440,26 +450,32 @@ class ProvideSharedPlugin {
440450
let requestIncludeFailed = false;
441451
if (config.include.request) {
442452
const includeRequestValue = config.include.request;
443-
const requestActuallyMatches = (includeRequestValue instanceof RegExp)
444-
? includeRequestValue.test(resource)
445-
: resource === includeRequestValue;
453+
const requestActuallyMatches =
454+
includeRequestValue instanceof RegExp
455+
? includeRequestValue.test(resource)
456+
: resource === includeRequestValue;
446457
if (!requestActuallyMatches) {
447458
requestIncludeFailed = true;
448459
}
449460
}
450461

451462
// Skip if any specified include condition failed
452-
const shouldSkipVersion = typeof config.include.version === 'string' && versionIncludeFailed;
463+
const shouldSkipVersion =
464+
typeof config.include.version === 'string' && versionIncludeFailed;
453465
const shouldSkipRequest = config.include.request && requestIncludeFailed;
454466

455-
if ( shouldSkipVersion || shouldSkipRequest ) {
467+
if (shouldSkipVersion || shouldSkipRequest) {
456468
return;
457469
}
458470
}
459471

460472
if (config.exclude) {
461473
let versionExcludeMatches = false;
462-
if (typeof config.exclude.version === 'string' && typeof version === 'string' && version) {
474+
if (
475+
typeof config.exclude.version === 'string' &&
476+
typeof version === 'string' &&
477+
version
478+
) {
463479
if (satisfy(version, config.exclude.version)) {
464480
versionExcludeMatches = true;
465481
}
@@ -468,9 +484,10 @@ class ProvideSharedPlugin {
468484
let requestExcludeMatches = false;
469485
if (config.exclude.request) {
470486
const excludeRequestValue = config.exclude.request;
471-
const requestActuallyMatchesExclude = (excludeRequestValue instanceof RegExp)
472-
? excludeRequestValue.test(resource)
473-
: resource === excludeRequestValue;
487+
const requestActuallyMatchesExclude =
488+
excludeRequestValue instanceof RegExp
489+
? excludeRequestValue.test(resource)
490+
: resource === excludeRequestValue;
474491
if (requestActuallyMatchesExclude) {
475492
requestExcludeMatches = true;
476493
}

0 commit comments

Comments
 (0)