@@ -108,6 +108,12 @@ function assertFolder (name, version) {
108
108
109
109
// Helper function to apply version caps in a more readable way
110
110
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
+
111
117
// Handle hyphen ranges (e.g., "24.8.0 - 24.9.0")
112
118
const hyphenRangeMatch = versionRange . match ( / ^ ( \d + \. \d + \. \d + ) \s * - \s * ( \d + \. \d + \. \d + ) ( .* ) $ / )
113
119
if ( hyphenRangeMatch ) {
@@ -128,6 +134,43 @@ function applyCap (versionRange, latestVersion) {
128
134
return versionRange
129
135
}
130
136
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
+
131
174
// Handle hyphen ranges like "24.8.0 - 24.9.0"
132
175
function handleHyphenRange ( match , latestVersion ) {
133
176
const [ , lowerBound , upperBound , extraConstraints ] = match
0 commit comments