Skip to content

Commit b28c814

Browse files
fix: correct webpack semver usage with parseRange
- Import parseRange from webpack/lib/util/semver - Wrap all string version ranges with parseRange() for proper typing - Fix parameter order for webpack satisfy function: satisfy(range, version) - All semver comparisons now use proper webpack SemVerRange types 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 138fb56 commit b28c814

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import type { ModuleFactoryCreateDataContextInfo } from 'webpack/lib/ModuleFacto
4040
import type { ConsumeOptions } from '../../declarations/plugins/sharing/ConsumeSharedModule';
4141
import { createSchemaValidation } from '../../utils';
4242
import path from 'path';
43-
const { satisfy } = require(
43+
const { satisfy, parseRange } = require(
4444
normalizeWebpackPath('webpack/lib/util/semver'),
4545
) as typeof import('webpack/lib/util/semver');
4646
import {
@@ -326,7 +326,10 @@ class ConsumeSharedPlugin {
326326
// Only include if version satisfies the include constraint
327327
if (
328328
config.include &&
329-
satisfy(data['version'], config.include.version as string)
329+
satisfy(
330+
parseRange(config.include.version as string),
331+
data['version'],
332+
)
330333
) {
331334
// Validate singleton usage with include.version
332335
if (
@@ -356,8 +359,8 @@ class ConsumeSharedPlugin {
356359
) {
357360
if (
358361
satisfy(
362+
parseRange(config.include.version as string),
359363
config.include.fallbackVersion,
360-
config.include.version as string,
361364
)
362365
) {
363366
return resolveFilter(consumedModule);
@@ -384,7 +387,12 @@ class ConsumeSharedPlugin {
384387
typeof config.exclude.fallbackVersion === 'string' &&
385388
config.exclude.fallbackVersion
386389
) {
387-
if (satisfy(config.exclude.fallbackVersion, config.exclude.version)) {
390+
if (
391+
satisfy(
392+
parseRange(config.exclude.version),
393+
config.exclude.fallbackVersion,
394+
)
395+
) {
388396
return undefined as unknown as ConsumeSharedModule;
389397
}
390398
return consumedModule;
@@ -407,7 +415,7 @@ class ConsumeSharedPlugin {
407415
if (
408416
config.exclude &&
409417
typeof config.exclude.version === 'string' &&
410-
satisfy(data['version'], config.exclude.version)
418+
satisfy(parseRange(config.exclude.version), data['version'])
411419
) {
412420
return resolveFilter(
413421
undefined as unknown as ConsumeSharedModule,

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import type {
2424
import FederationRuntimePlugin from '../container/runtime/FederationRuntimePlugin';
2525
import { createSchemaValidation } from '../../utils';
2626
import path from 'path';
27-
const { satisfy } = require(
27+
const { satisfy, parseRange } = require(
2828
normalizeWebpackPath('webpack/lib/util/semver'),
2929
) as typeof import('webpack/lib/util/semver');
3030
import {
@@ -489,7 +489,7 @@ class ProvideSharedPlugin {
489489
let versionIncludeFailed = false;
490490
if (typeof config.include.version === 'string') {
491491
if (typeof version === 'string' && version) {
492-
if (!satisfy(version, config.include.version)) {
492+
if (!satisfy(parseRange(config.include.version), version)) {
493493
versionIncludeFailed = true;
494494
}
495495
} else {
@@ -544,7 +544,7 @@ class ProvideSharedPlugin {
544544
typeof version === 'string' &&
545545
version
546546
) {
547-
if (satisfy(version, config.exclude.version)) {
547+
if (satisfy(parseRange(config.exclude.version), version)) {
548548
versionExcludeMatches = true;
549549
}
550550
}
@@ -706,7 +706,7 @@ class ProvideSharedPlugin {
706706
let versionIncludeFailed = false;
707707
if (typeof config.include.version === 'string') {
708708
if (typeof version === 'string' && version) {
709-
if (!satisfy(version, config.include.version)) {
709+
if (!satisfy(parseRange(config.include.version), version)) {
710710
versionIncludeFailed = true;
711711
}
712712
} else {
@@ -764,7 +764,7 @@ class ProvideSharedPlugin {
764764
typeof version === 'string' &&
765765
version
766766
) {
767-
if (satisfy(version, config.exclude.version)) {
767+
if (satisfy(parseRange(config.exclude.version), version)) {
768768
versionExcludeMatches = true;
769769
}
770770
}
@@ -834,7 +834,7 @@ class ProvideSharedPlugin {
834834
if (config.include?.version) {
835835
const includeVersion = config.include.version;
836836
if (typeof includeVersion === 'string') {
837-
if (!satisfy(version, includeVersion)) {
837+
if (!satisfy(parseRange(includeVersion), version)) {
838838
return false; // Skip providing this module
839839
}
840840
}
@@ -844,7 +844,7 @@ class ProvideSharedPlugin {
844844
if (config.exclude?.version) {
845845
const excludeVersion = config.exclude.version;
846846
if (typeof excludeVersion === 'string') {
847-
if (satisfy(version, excludeVersion)) {
847+
if (satisfy(parseRange(excludeVersion), version)) {
848848
return false; // Skip providing this module
849849
}
850850
}

0 commit comments

Comments
 (0)