Update a version range to include a new version, preserving the range prefix
(range: string, newVersion: string)
| 87 | |
| 88 | /** Update a version range to include a new version, preserving the range prefix */ |
| 89 | function updateRange(range: string, newVersion: string): string { |
| 90 | // Preserve workspace:/catalog: protocols |
| 91 | let protocol = ''; |
| 92 | let cleanRange = range; |
| 93 | const protoMatch = range.match(/^(workspace:|catalog:)/); |
| 94 | if (protoMatch) { |
| 95 | protocol = protoMatch[1]!; |
| 96 | cleanRange = range.slice(protocol.length); |
| 97 | } |
| 98 | |
| 99 | // Preserve the range prefix (^, ~, >=, etc.) |
| 100 | const prefixMatch = cleanRange.match(/^(\^|~|>=|>|<=|<|=)?/); |
| 101 | const prefix = prefixMatch?.[1] ?? '^'; |
| 102 | |
| 103 | // Handle wildcard ranges and workspace shorthand (workspace:^, workspace:~, workspace:*) |
| 104 | if (cleanRange === '*' || cleanRange === '' || cleanRange === '^' || cleanRange === '~') { |
| 105 | return range; // don't touch wildcards or workspace shorthands |
| 106 | } |
| 107 | |
| 108 | return `${protocol}${prefix}${newVersion}`; |
| 109 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…