Skip to content

Commit eb8de60

Browse files
fix: correct pattern matching in ProvideSharedPlugin for share filtering
- Fixed regex pattern to properly match only '..' paths instead of both '.' and '..' - Updated test configurations to include .js extension for proper matching - Added proper filtering warnings when modules are excluded by include/exclude filters - Ensures modules failing filters are not provided to share scope and generate warnings 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent eaa661e commit eb8de60

File tree

2 files changed

+11
-28
lines changed

2 files changed

+11
-28
lines changed

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

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class ProvideSharedPlugin {
145145
actualRequest,
146146
config.layer,
147147
);
148-
if (/^(\/|[A-Za-z]:\\|\\\\|\.\.?(\/|$))/.test(actualRequest)) {
148+
if (/^(\/|[A-Za-z]:\\|\\\\|\.\.(\/|$))/.test(actualRequest)) {
149149
resolvedProvideMap.set(lookupKey, {
150150
config,
151151
version: config.version,
@@ -478,17 +478,11 @@ class ProvideSharedPlugin {
478478
const shouldSkipRequest = config.include.request && requestIncludeFailed;
479479

480480
if (shouldSkipVersion || shouldSkipRequest) {
481-
console.log(
482-
`[DEBUG] Skipping module ${key} due to include filter failure`,
483-
{
484-
shouldSkipVersion,
485-
shouldSkipRequest,
486-
versionIncludeFailed,
487-
requestIncludeFailed,
488-
version,
489-
includeVersion: config.include.version,
490-
},
481+
const error = new WebpackError(
482+
`Shared module "${key}" (${resource}) version "${version}" does not satisfy include filter: ${config.include.version}`,
491483
);
484+
error.file = `shared module ${key} -> ${resource}`;
485+
compilation.warnings.push(error);
492486
return;
493487
}
494488

@@ -549,15 +543,11 @@ class ProvideSharedPlugin {
549543

550544
// Skip if any specified exclude condition matched
551545
if (versionExcludeMatches || requestExcludeMatches) {
552-
console.log(
553-
`[DEBUG] Skipping module ${key} due to exclude filter match`,
554-
{
555-
versionExcludeMatches,
556-
requestExcludeMatches,
557-
version,
558-
excludeVersion: config.exclude.version,
559-
},
546+
const error = new WebpackError(
547+
`Shared module "${key}" (${resource}) version "${version}" matches exclude filter: ${config.exclude.version}`,
560548
);
549+
error.file = `shared module ${key} -> ${resource}`;
550+
compilation.warnings.push(error);
561551
return;
562552
}
563553

@@ -576,13 +566,6 @@ class ProvideSharedPlugin {
576566
}
577567

578568
const lookupKey = createLookupKeyForSharing(resource, config.layer);
579-
console.log(`[DEBUG] Adding module ${key} to resolvedProvideMap`, {
580-
lookupKey,
581-
version,
582-
resource,
583-
includeVersion: config.include?.version,
584-
excludeVersion: config.exclude?.version,
585-
});
586569
resolvedProvideMap.set(lookupKey, {
587570
config,
588571
version,

packages/enhanced/test/configCases/sharing/provide-filters/webpack.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ module.exports = {
2121
version: '^2.0.0',
2222
},
2323
},
24-
'./version-include-fail': {
24+
'./version-include-fail.js': {
2525
shareKey: 'version-include-fail',
2626
version: '1.2.0',
2727
include: {
2828
version: '^2.0.0',
2929
},
3030
},
31-
'./version-exclude-fail': {
31+
'./version-exclude-fail.js': {
3232
shareKey: 'version-exclude-fail',
3333
version: '2.0.0',
3434
exclude: {

0 commit comments

Comments
 (0)