Skip to content

Commit 9ee322d

Browse files
committed
Attempt to handle caret ranges
1 parent 7929375 commit 9ee322d

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

scripts/install_plugin_modules.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ function assertFolder (name, version) {
108108

109109
// Helper function to apply version caps in a more readable way
110110
function applyCap (versionRange, latestVersion) {
111+
// Handle caret ranges (e.g., "^3.0.7")
112+
const caretRangeMatch = versionRange.match(/^\^(\d+\.\d+\.\d+)(.*)$/)
113+
if (caretRangeMatch) {
114+
return handleCaretRange(caretRangeMatch, latestVersion)
115+
}
116+
111117
// Handle hyphen ranges (e.g., "24.8.0 - 24.9.0")
112118
const hyphenRangeMatch = versionRange.match(/^(\d+\.\d+\.\d+)\s*-\s*(\d+\.\d+\.\d+)(.*)$/)
113119
if (hyphenRangeMatch) {
@@ -128,6 +134,43 @@ function applyCap (versionRange, latestVersion) {
128134
return versionRange
129135
}
130136

137+
// Handle caret ranges like "^3.0.7"
138+
function handleCaretRange (match, latestVersion) {
139+
const [, version, extraConstraints] = match
140+
const parsed = semver.parse(version)
141+
142+
// Calculate the upper bound implied by caret notation
143+
let upperBound
144+
if (parsed.major === 0) {
145+
if (parsed.minor === 0) {
146+
// ^0.0.x -> <0.0.(x+1)
147+
upperBound = `0.0.${parsed.patch + 1}`
148+
} else {
149+
// ^0.y.x -> <0.(y+1).0
150+
upperBound = `0.${parsed.minor + 1}.0`
151+
}
152+
} else {
153+
// ^x.y.z -> <(x+1).0.0
154+
upperBound = `${parsed.major + 1}.0.0`
155+
}
156+
157+
// Cap at the lower of: original caret upper bound or latest version
158+
const effectiveLatest = semver.lt(upperBound, latestVersion) ? upperBound : latestVersion
159+
160+
// Create properly formatted range that preserves caret semantics
161+
let result = `>=${version} <${effectiveLatest}`
162+
163+
// Add any extra constraints if they exist and would create a valid range
164+
if (extraConstraints && extraConstraints.trim()) {
165+
const combinedRange = `${result} ${extraConstraints.trim()}`
166+
if (semver.validRange(combinedRange)) {
167+
result = combinedRange
168+
}
169+
}
170+
171+
return result
172+
}
173+
131174
// Handle hyphen ranges like "24.8.0 - 24.9.0"
132175
function handleHyphenRange (match, latestVersion) {
133176
const [, lowerBound, upperBound, extraConstraints] = match

0 commit comments

Comments
 (0)