RFC: BunCatalogManager — Bun Dependency Catalog Support for Nx #36096
yrybak-op8
started this conversation in
Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Nx already ships package-manager-specific catalog managers for pnpm (
PnpmCatalogManager) and Yarn (YarnCatalogManager). This RFC proposes adding aBunCatalogManagerthat brings Bun catalog support to the same level of integration.Bun catalog docs: https://bun.com/docs/pm/catalogs
pnpm manager:
packages/nx/src/utils/catalog/pnpm-manager.tsYarn manager:
packages/nx/src/utils/catalog/yarn-manager.tsMotivation
Nx supports Bun as a package manager, but the dependency catalog system in
packages/nx/src/utils/catalog/does not cover Bun. ThegetCatalogManagerfactory inmanager-factory.tscurrently returnsnullfor Bun workspaces:As a result, any
catalog:reference in a Bun workspace is silently left unresolved byresolveCatalogReferenceIfNeeded,resolveCatalogSpecifiers, andgetCatalogDependenciesFromPackageJson. This breaks:@nx/dependency-checkslint rulenx migratecatalog version updatesBun Catalog Format
Bun stores catalog definitions inside the root
package.json, not in a separate file. It supports four locations, all of which must be handled:Workspace package references use the same
catalog:protocol as pnpm and Yarn:{ "dependencies": { "react": "catalog:", // default catalog "react": "catalog:react18" // named catalog } }The lookup priority when both
workspaces.catalogand a top-levelcatalogare present should follow Bun's own resolution order (workspaces-nested takes precedence when theworkspacesfield is an object).What Needs to Change
1. New file:
packages/nx/src/utils/catalog/bun-manager.tsThe implementation follows the exact same structure as
PnpmCatalogManagerandYarnCatalogManager. The key differences are:pnpm-workspace.yaml.yarnrc.ymlpackage.json@zkochan/js-yaml)@zkochan/js-yaml)catalog/catalogscatalog/catalogsworkspaces.catalog,workspaces.catalogs, top-levelcatalog, top-levelcatalogsgetCatalogDefinitionsmust merge both location variants into the sharedCatalogDefinitionsshape:Important:
updateCatalogVersionsmust write back topackage.jsonusing JSON, not YAML. It also must not clobber unrelated fields — only update the specificcatalogorcatalogskey that was the source of the resolved definition.2. Register in
manager-factory.ts3. New test file:
packages/nx/src/utils/catalog/bun-manager.spec.tsShould mirror the structure of
pnpm-manager.spec.tsandyarn-manager.spec.ts, with additional test cases covering:workspaces.catalogand top-levelcatalogare presentupdateCatalogVersionswriting valid JSON back topackage.jsonwithout destroying unrelated fieldsScope of Integration
Once
getCatalogManagerreturns aBunCatalogManager, the following already-wired call sites get Bun support for free — no further changes needed:resolveCatalogReferenceIfNeededpackages/nx/src/utils/catalog/index.tsresolveCatalogSpecifierspackages/nx/src/utils/catalog/index.tsgetCatalogDependenciesFromPackageJsonpackages/nx/src/utils/catalog/index.ts@nx/dependency-checkslint ruleresolveCatalogSpecifiersnx migratecatalog updatesupdateCatalogVersionsresolveCatalogReferenceIfNeededFeedback Requested
BunCatalogManagerthe right abstraction, or should the commoncatalog:logic be extracted into a shared base class that pnpm/Yarn/Bun all extend?workspaces.catalogand top-levelcatalogbehave — hard error or silent preference?catalog:defaultalias) that differ from pnpm and need special casing?Beta Was this translation helpful? Give feedback.
All reactions