fix(migrate): resolve husky version from catalog during hooks check#1710
fix(migrate): resolve husky version from catalog during hooks check#1710fengmk2 wants to merge 1 commit into
Conversation
`vp migrate`'s git-hooks preflight could not determine the husky version
when it was pinned via a catalog reference (e.g. `"husky": "catalog:"`
in package.json with the real version in `pnpm-workspace.yaml`'s catalog).
`semver.coerce("catalog:")` returns null and the node_modules fallback is
empty during migration, so it warned:
Could not determine husky version from "catalog:" — please specify a
semver-compatible version (e.g., "^9.0.0") and re-run migration.
As a result pre-commit hooks were never configured and husky/lint-staged
were left in devDependencies, even when the catalog declared a compatible
v9.
`checkUnsupportedHuskyVersion` now resolves a `catalog:`/`catalog:<name>`
spec from the workspace catalog (pnpm-workspace.yaml, .yarnrc.yml, or
package.json `catalog`/`catalogs`) before falling back to node_modules.
Adds the `migration-husky-catalog-version` global snap test covering the
real-world setup.
✅ Deploy Preview for viteplus-preview canceled.
|
|
@cursor review |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 82f3a2a. Configure here.
| ); | ||
| } | ||
| return undefined; | ||
| } |
There was a problem hiding this comment.
New function duplicates existing catalog resolver logic
Low Severity
resolveCatalogSpecFromProject (~54 lines) duplicates the file-reading and resolution logic already present in createCatalogDependencyResolver (lines 1554–1604). The same pnpm-workspace.yaml, .yarnrc.yml, and package.json handling is repeated nearly verbatim. A simpler implementation could iterate over PackageManager values calling createCatalogDependencyResolver for each, reducing this to ~8 lines and ensuring both code paths stay in sync when catalog resolution logic changes.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 82f3a2a. Configure here.


Problem
vp migrate's git-hooks preflight could not determine the husky version when it was pinned via a catalog reference. In a pnpm catalog monorepo such as vite-task:package.json→"husky": "catalog:"pnpm-workspace.yaml→catalog: { husky: ^9.1.7 }(a compatible v9)semver.coerce("catalog:")returnsnull, and thenode_modulesfallback is empty during migration, so it warned:As a result, pre-commit hooks were never configured and
husky/lint-stagedwere left indevDependencies, even though the catalog declared a perfectly compatible version.Fix
checkUnsupportedHuskyVersionnow resolves acatalog:/catalog:<name>spec from the workspace catalog before falling back tonode_modules. A new read-only, package-manager-agnostic helperresolveCatalogSpecFromProjectlooks the spec up in:pnpm-workspace.yaml.yarnrc.ymlpackage.jsoncatalog/catalogs(including Bun'sworkspacesform)reusing the existing
createCatalogDependencyResolverFromCatalogs. The genuinely-uncoercible path (e.g."latest"with no catalog entry) still degrades to the same warning.Testing
migration-husky-catalog-versionmirroring the real-worldvite-tasksetup. It captured the bug before the fix; after the fix it shows no warning,husky/lint-stagedremoved,prepare→vp config,stagedconfig merged intovite.config.ts, and.vite-hooks/pre-commitcreated.migration-husky-latest-dist-tagstill warns (degradation path intact).vp check(format/lint/type-check) clean.Note
Low Risk
Narrow change to migration preflight catalog resolution for husky only; read-only lookups and existing fallbacks for non-catalog specs remain unchanged.
Overview
vp migrateno longer fails the git-hooks preflight when husky is declared ascatalog:/catalog:<name>inpackage.json. The migrator resolves that specifier from workspace catalog sources (pnpm-workspace.yaml,.yarnrc.yml,package.jsoncatalog/catalogs, including Bun workspaces) via a new read-onlyresolveCatalogSpecFromProject, then runs semver checks on the resolved range before falling back tonode_modulesor the existing “could not determine version” warning.A global snap test
migration-husky-catalog-versionlocks in the end-to-end behavior: migrate completes with Git hooks configured,husky/lint-stagedremoved,prepare→vp config,stagedmerged intovite.config.ts, and.vite-hooks/pre-commitcallingvp staged.Reviewed by Cursor Bugbot for commit 82f3a2a. Configure here.