Skip to content

feat: add fallback version support for share filtering #3910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: pr5-request-pattern-filtering
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
e9bf9dc
feat: add fallback version support for share filtering
ScriptedAlchemy Jul 15, 2025
3757776
fix: add fallbackVersion to ConsumeOptions type definition
ScriptedAlchemy Jul 15, 2025
f2d0b3e
fix: add fallbackVersion support to ProvideSharedPlugin and fix unit …
ScriptedAlchemy Jul 15, 2025
ee9024a
test: enhance fallback version unit tests with comprehensive scenarios
ScriptedAlchemy Jul 15, 2025
15a6a4d
fix: add missing layer configuration for multi consume in layers-cons…
ScriptedAlchemy Jul 15, 2025
e4ef1b3
fix: add layer property to consumed module results from shareConfig
ScriptedAlchemy Jul 15, 2025
bdbf532
fix: align layers-consume-loader test expectations with share-filter …
ScriptedAlchemy Jul 15, 2025
41b60f3
fix: correct layers-consume-loader test expectations back to expect l…
ScriptedAlchemy Jul 15, 2025
eaa661e
fix: resolve provide-filters test failures by fixing fallback version…
ScriptedAlchemy Jul 15, 2025
eb8de60
fix: correct pattern matching in ProvideSharedPlugin for share filtering
ScriptedAlchemy Jul 15, 2025
918b2ec
fix: update warnings.js to match actual warning message format
ScriptedAlchemy Jul 15, 2025
3296fd4
fix: implement provide-filters functionality to match share-filter br…
ScriptedAlchemy Jul 15, 2025
e6f51d0
Merge branch 'pr5-request-pattern-filtering' into pr6-fallback-versio…
ScriptedAlchemy Jul 16, 2025
ef6d731
Merge branch 'pr5-request-pattern-filtering' into pr6-fallback-versio…
ScriptedAlchemy Jul 16, 2025
55f32c4
Merge branch 'pr5-request-pattern-filtering' into pr6-fallback-versio…
ScriptedAlchemy Jul 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion INCREMENTAL_PR_PLAN_REVISED.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## Overview
Based on a detailed diff analysis, this document provides a more accurate breakdown of changes into focused, incremental PRs. Each PR represents a distinct feature, fix, or refactor that can be merged independently.

**IMPORTANT**: All PRs should be compared against the `share-filter` branch as the base branch for measuring changes and creating pull requests.

## Updated PR Sequence

### PR 1: Runtime Safety Fixes
Expand Down Expand Up @@ -128,6 +130,8 @@ shared: {
---

### PR 6: Fallback Version Support
**Branch from**: `pr5-request-pattern-filtering`
**Compare against**: `share-filter` branch
**Size**: Small (~6 files)
**Risk**: Low
**Type**: Feature
Expand All @@ -140,7 +144,7 @@ shared: {
- Unit tests for fallback version
- Integration tests

**Depends on**: PR 4
**Depends on**: PR 4 and PR 5

**API**:
```javascript
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
import type { SemVerRange } from 'webpack/lib/util/semver';

export interface ConsumeSharedModuleExcludeOptions {
request?: string | RegExp;
version?: string;
fallbackVersion?: string;
}

export interface ConsumeSharedModuleIncludeOptions {
request?: string | RegExp;
version?: string;
fallbackVersion?: string;
}

export type ConsumeOptions = {
/**
* fallback request
Expand Down Expand Up @@ -51,29 +65,18 @@ export type ConsumeOptions = {
*/
issuerLayer?: string | null;
/**
* Include filters for consuming shared modules
* Filter object for consuming shared modules.
* Modules matching the criteria in this object will be excluded.
*/
include?: {
/**
* Version requirement that must be satisfied for the shared module to be included
*/
version?: string;
/**
* Request pattern that must match for the shared module to be included
*/
request?: string | RegExp;
};
exclude?: ConsumeSharedModuleExcludeOptions;
/**
* Exclude filters for consuming shared modules
* Filter object for consuming shared modules.
* Only modules matching the criteria in this object will be included.
*/
exclude?: {
/**
* Version requirement that if satisfied will exclude the shared module
*/
version?: string;
/**
* Request pattern that if matched will exclude the shared module
*/
request?: string | RegExp;
};
include?: ConsumeSharedModuleIncludeOptions;
/**
* Enable reconstructed lookup for node_modules paths for this share item
*/
nodeModulesReconstructedLookup?: boolean;
};
const TYPES = new Set(['consume-shared']);
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface IncludeExcludeOptions {
version?: string;
fallbackVersion?: string;
}

/**
* Advanced configuration for modules that should be consumed from share scope.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ export interface ProvidesObject {
*/
[k: string]: ProvidesConfig | ProvidesItem;
}

export interface IncludeExcludeOptions {
request?: string | RegExp;
version?: string;
fallbackVersion?: string;
}

/**
* Advanced configuration for modules that should be provided as shared modules to the share scope.
*/
Expand Down Expand Up @@ -73,29 +80,15 @@ export interface ProvidesConfig {
*/
request?: string;
/**
* Include filters for providing shared modules.
* Filter for the shared module.
*/
exclude?: IncludeExcludeOptions;
/**
* Filter for the shared module.
*/
include?: {
/**
* Version requirement that must be satisfied for the module to be provided.
*/
version?: string;
/**
* Request pattern that must match for the module to be provided.
*/
request?: string | RegExp;
};
include?: IncludeExcludeOptions;
/**
* Exclude filters for providing shared modules.
* Node modules reconstructed lookup.
*/
exclude?: {
/**
* Version requirement that if satisfied will exclude the module from being provided.
*/
version?: string;
/**
* Request pattern that if matched will exclude the module from being provided.
*/
request?: string | RegExp;
};
nodeModulesReconstructedLookup?: any;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ const { dependencies } = require(
) as typeof import('webpack');

class ConsumeSharedFallbackDependency extends dependencies.ModuleDependency {
layer?: string | null;

/**
* @param {string} request the request
* @param {string | null} layer the layer for the fallback module
*/
constructor(request: string) {
constructor(request: string, layer?: string | null) {
super(request);
this.layer = layer;
}

override get type(): string {
Expand Down
7 changes: 6 additions & 1 deletion packages/enhanced/src/lib/sharing/ConsumeSharedModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ const makeSerializable = require(
* @property {boolean} eager include the fallback module in a sync way
* @property {string | null=} layer Share a specific layer of the module, if the module supports layers
* @property {string | null=} issuerLayer Issuer layer in which the module should be resolved
* @property {{ version?: string; fallbackVersion?: string }} exclude Options for excluding certain versions
* @property {{ version?: string; fallbackVersion?: string }} include Options for including only certain versions
*/

const TYPES = new Set(['consume-shared']);
Expand Down Expand Up @@ -173,7 +175,10 @@ class ConsumeSharedModule extends Module {
this.buildMeta = {};
this.buildInfo = {};
if (this.options.import) {
const dep = new ConsumeSharedFallbackDependency(this.options.import);
const dep = new ConsumeSharedFallbackDependency(
this.options.import,
this.options.layer,
);
if (this.options.eager) {
this.addDependency(dep);
} else {
Expand Down
Loading
Loading