Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions scripts/lib/resolve-catalog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,27 @@ describe("resolveCatalogDependencies", () => {
/Expected key 'missing' in root workspace catalog/,
);
});

it("resolves version-qualified overrides without changing their selectors", () => {
assert.deepStrictEqual(
resolveCatalogDependencies(
{
"undici@^8": "catalog:",
"ws@^8": "catalog:",
"@clerk/backend@^3": "catalog:",
"@scope/parent@^1>undici@^8": "catalog:",
"parent@^1>@clerk/backend@^3": "catalog:",
},
{ ...catalog, undici: "8.11.2", ws: "8.21.0" },
"apps/desktop",
),
{
"undici@^8": "8.11.2",
"ws@^8": "8.21.0",
"@clerk/backend@^3": "3.18.1",
"@scope/parent@^1>undici@^8": "8.11.2",
"parent@^1>@clerk/backend@^3": "3.18.1",
},
);
});
});
10 changes: 6 additions & 4 deletions scripts/lib/resolve-catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ export function resolveCatalogDependencies(
}

const catalogKey = spec.slice("catalog:".length).trim();
// An override key can be a selector such as `@scope/parent>effect`; like
// pnpm, a bare `catalog:` there means the catalog entry of the package
// the selector ends in.
const lookupKey = catalogKey.length > 0 ? catalogKey : (name.split(">").at(-1) ?? name);
// Overrides can include a parent selector and a version range. A bare
// `catalog:` looks up the final package name, keeping its scope intact.
const selector = name.split(">").at(-1) ?? name;
const versionIndex = selector.indexOf("@", 1);
const packageName = versionIndex === -1 ? selector : selector.slice(0, versionIndex);
const lookupKey = catalogKey.length > 0 ? catalogKey : packageName;
const resolved = catalog[lookupKey];

if (typeof resolved !== "string" || resolved.length === 0) {
Expand Down
Loading