feat: add configurable sharing with semver resolution #1031
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is more of a plan than a final implementation, so that I can get some initial feedback. Actual function implementation and tests should follow accordingly.
The idea / feature is to add opt-in support for sharing configuration, with semver range matching and singleton/strictVersion enforcement. I tried to establish a resolution algorithm as used in webpack, with the same options that already exist in both implementations.
Changes:
So, implementation is mostly skeleton with TODO comments. Actual logic to be implemented after some feedback.
Package Resolution Flow:
Fast Path: Check for exact version match first (e.g.,
3.0.0===3.0.0)Singleton Mode (
singleton: true):requiredVersion: false→ use singleton regardless of version3.5.0satisfies^3.0.0) → use singletonstrictVersion: true→ use own bundle (fallback)strictVersion: false→ use singleton anyway (with warning)Non-Singleton Mode (
singleton: false):requiredVersionrangestrictVersion: true→ use own bundle (fallback)strictVersion: false→ use highest available version (with warning)Semver Support
Supports standard semver ranges (keeping runtime lightweight ~1-2KB):
*- any version3.0.0- exact match^3.0.0- same major (>= 3.0.0 < 4.0.0)~3.2.0- same major.minor (>= 3.2.0 < 3.3.0)>=3.0.0,<5.0.0,>3.0.0,<=5.0.0- comparison operators>=3.0.0 <5.0.0- compound ranges (space-separated AND)Backwards Compatibility
useShareConfig: false(exact version matching, current behavior)useShareConfig: true(enforces config with semver)Example