Skip to content

Commit a198e74

Browse files
committed
chore(deps): upgrade
1 parent 18b48ce commit a198e74

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@icebreakers/monorepo': patch
3+
---
4+
5+
Handle pnpm `catalog:` version specifiers during `monorepo up` so catalog-managed dependencies are preserved without semver parsing errors.

packages/monorepo/src/commands/upgrade/pkg-json.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,25 @@ import { coerce, gte, minVersion } from 'semver'
33
import { name as pkgName, version as pkgVersion } from '../../constants'
44
import { scriptsEntries } from './scripts'
55

6-
function isWorkspace(version?: string) {
7-
if (typeof version === 'string') {
8-
return version.startsWith('workspace:')
9-
}
10-
return false
11-
}
6+
const NON_OVERRIDABLE_PREFIXES = ['workspace:', 'catalog:']
127

138
function parseVersion(input: unknown) {
149
if (typeof input !== 'string' || input.trim().length === 0) {
1510
return null
1611
}
17-
return minVersion(input) ?? coerce(input)
12+
try {
13+
return minVersion(input) ?? coerce(input)
14+
}
15+
catch {
16+
return null
17+
}
18+
}
19+
20+
function hasNonOverridablePrefix(version?: string) {
21+
if (typeof version !== 'string') {
22+
return false
23+
}
24+
return NON_OVERRIDABLE_PREFIXES.some(prefix => version.startsWith(prefix))
1825
}
1926

2027
function shouldAssignVersion(currentVersion: unknown, nextVersion: string) {
@@ -65,7 +72,7 @@ export function setPkgJson(
6572
}
6673

6774
const targetVersion = targetDeps[depName]
68-
if (isWorkspace(targetVersion)) {
75+
if (hasNonOverridablePrefix(targetVersion)) {
6976
continue
7077
}
7178
if (shouldAssignVersion(targetVersion, depVersion)) {
@@ -84,13 +91,13 @@ export function setPkgJson(
8491
if (depName === pkgName) {
8592
const nextVersion = `^${pkgVersion}`
8693
const targetVersion = targetDevDeps[depName]
87-
if (!isWorkspace(targetVersion) && shouldAssignVersion(targetVersion, nextVersion)) {
94+
if (!hasNonOverridablePrefix(targetVersion) && shouldAssignVersion(targetVersion, nextVersion)) {
8895
targetDevDeps[depName] = nextVersion
8996
}
9097
}
9198
else {
9299
const targetVersion = targetDevDeps[depName]
93-
if (isWorkspace(targetVersion)) {
100+
if (hasNonOverridablePrefix(targetVersion)) {
94101
continue
95102
}
96103
if (shouldAssignVersion(targetVersion, depVersion)) {

packages/monorepo/test/commands/upgrade.pkg-json.coverage.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ describe('upgrade pkg-json helpers coverage', () => {
1212
'dep-keep': '^1.0.0',
1313
'dep-update': '^1.2.0',
1414
'dep-empty': '',
15+
'dep-catalog': '^1.3.0',
1516
},
1617
devDependencies: {
1718
'@icebreakers/monorepo': '^0.0.1',
@@ -26,6 +27,7 @@ describe('upgrade pkg-json helpers coverage', () => {
2627
'dep-update': '^1.0.0',
2728
'dep-empty': ' ',
2829
'dep-workspace': 'workspace:*',
30+
'dep-catalog': 'catalog:crossEnv',
2931
},
3032
devDependencies: {
3133
'@icebreakers/monorepo': '^0.2.0',
@@ -49,6 +51,7 @@ describe('upgrade pkg-json helpers coverage', () => {
4951
'dep-update': '^1.2.0',
5052
'dep-empty': '',
5153
'dep-workspace': 'workspace:*',
54+
'dep-catalog': 'catalog:crossEnv',
5255
})
5356
expect(target.devDependencies?.['dep-dev-update']).toBe('workspace:^2.0.0')
5457
expect(target.devDependencies?.['dep-dev-stale']).toBe('^2.0.0')

0 commit comments

Comments
 (0)