Commit 183f8e7
authored
fix(migrate): resolve husky version from catalog during hooks check (#1710)
## 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](https://github.com/voidzero-dev/vite-task):
- `package.json` → `"husky": "catalog:"`
- `pnpm-workspace.yaml` → `catalog: { husky: ^9.1.7 }` (a compatible v9)
`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 though the
catalog declared a perfectly compatible version.
## Fix
`checkUnsupportedHuskyVersion` now resolves a `catalog:` /
`catalog:<name>` spec from the workspace catalog **before** falling back
to `node_modules`. A new read-only, package-manager-agnostic helper
`resolveCatalogSpecFromProject` looks the spec up in:
- `pnpm-workspace.yaml`
- `.yarnrc.yml`
- `package.json` `catalog` / `catalogs` (including Bun's `workspaces`
form)
reusing the existing `createCatalogDependencyResolverFromCatalogs`. The
genuinely-uncoercible path (e.g. `"latest"` with no catalog entry) still
degrades to the same warning.
## Testing
- Added global snap test `migration-husky-catalog-version` mirroring the
real-world `vite-task` setup. It captured the bug before the fix; after
the fix it shows no warning, `husky`/`lint-staged` removed, `prepare` →
`vp config`, `staged` config merged into `vite.config.ts`, and
`.vite-hooks/pre-commit` created.
- All existing husky/hook global snap tests re-run with no snapshot
drift.
- `migration-husky-latest-dist-tag` still warns (degradation path
intact).
- 107 migration unit tests pass; `vp check` (format/lint/type-check)
clean.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Low Risk**
> Behavior change is limited to husky version preflight during optional
git-hooks setup; existing semver and node_modules paths are unchanged
when catalog resolution does not apply.
>
> **Overview**
> **Git hooks preflight** now resolves `"husky": "catalog:"` through the
**active package manager’s catalog** (via existing
`createCatalogDependencyResolver`) before falling back to
`node_modules`, so compatible v9 catalog pins no longer trigger a false
“could not determine husky version” warning and skip hook migration.
>
> **`packageManager`** is threaded into `preflightGitHooksSetup`,
`checkUnsupportedHuskyVersion`, `setupGitHooks`, and `installGitHooks`
from **migrate**, **create**, and the already-on-Vite+ hooks path so
catalog lookup stays scoped to pnpm vs yarn vs bun (e.g. yarn ignores a
stray `pnpm-workspace.yaml`).
>
> Adds a **global snap test** `migration-husky-catalog-version` and
**unit tests** for allow, reject husky <9, and foreign-catalog
behavior.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
834fd3a. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 7ec9124 commit 183f8e7
9 files changed
Lines changed: 224 additions & 22 deletions
File tree
- packages/cli
- snap-tests-global/migration-husky-catalog-version
- .husky
- src
- create
- migration
- __tests__
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
Lines changed: 14 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
Lines changed: 57 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
Lines changed: 13 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
983 | 983 | | |
984 | 984 | | |
985 | 985 | | |
986 | | - | |
| 986 | + | |
987 | 987 | | |
988 | 988 | | |
989 | 989 | | |
| |||
1247 | 1247 | | |
1248 | 1248 | | |
1249 | 1249 | | |
1250 | | - | |
| 1250 | + | |
1251 | 1251 | | |
1252 | 1252 | | |
1253 | 1253 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
1831 | 1832 | | |
1832 | 1833 | | |
1833 | 1834 | | |
| 1835 | + | |
| 1836 | + | |
| 1837 | + | |
| 1838 | + | |
| 1839 | + | |
| 1840 | + | |
| 1841 | + | |
| 1842 | + | |
| 1843 | + | |
| 1844 | + | |
| 1845 | + | |
| 1846 | + | |
| 1847 | + | |
| 1848 | + | |
| 1849 | + | |
| 1850 | + | |
| 1851 | + | |
| 1852 | + | |
| 1853 | + | |
| 1854 | + | |
| 1855 | + | |
| 1856 | + | |
| 1857 | + | |
| 1858 | + | |
| 1859 | + | |
| 1860 | + | |
| 1861 | + | |
| 1862 | + | |
| 1863 | + | |
| 1864 | + | |
| 1865 | + | |
| 1866 | + | |
| 1867 | + | |
| 1868 | + | |
| 1869 | + | |
| 1870 | + | |
| 1871 | + | |
| 1872 | + | |
| 1873 | + | |
| 1874 | + | |
| 1875 | + | |
| 1876 | + | |
| 1877 | + | |
| 1878 | + | |
| 1879 | + | |
| 1880 | + | |
| 1881 | + | |
| 1882 | + | |
| 1883 | + | |
| 1884 | + | |
| 1885 | + | |
| 1886 | + | |
| 1887 | + | |
| 1888 | + | |
| 1889 | + | |
| 1890 | + | |
| 1891 | + | |
| 1892 | + | |
| 1893 | + | |
| 1894 | + | |
| 1895 | + | |
| 1896 | + | |
| 1897 | + | |
| 1898 | + | |
| 1899 | + | |
| 1900 | + | |
| 1901 | + | |
| 1902 | + | |
| 1903 | + | |
| 1904 | + | |
| 1905 | + | |
| 1906 | + | |
| 1907 | + | |
| 1908 | + | |
| 1909 | + | |
| 1910 | + | |
| 1911 | + | |
| 1912 | + | |
| 1913 | + | |
| 1914 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
354 | 354 | | |
355 | 355 | | |
356 | 356 | | |
357 | | - | |
| 357 | + | |
358 | 358 | | |
359 | 359 | | |
360 | 360 | | |
| |||
817 | 817 | | |
818 | 818 | | |
819 | 819 | | |
820 | | - | |
| 820 | + | |
821 | 821 | | |
822 | 822 | | |
823 | 823 | | |
| |||
1032 | 1032 | | |
1033 | 1033 | | |
1034 | 1034 | | |
1035 | | - | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
1036 | 1044 | | |
1037 | 1045 | | |
1038 | 1046 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1589 | 1589 | | |
1590 | 1590 | | |
1591 | 1591 | | |
1592 | | - | |
1593 | | - | |
1594 | | - | |
1595 | | - | |
1596 | | - | |
1597 | | - | |
1598 | | - | |
1599 | | - | |
1600 | | - | |
1601 | | - | |
| 1592 | + | |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
1602 | 1599 | | |
1603 | 1600 | | |
1604 | 1601 | | |
| |||
1609 | 1606 | | |
1610 | 1607 | | |
1611 | 1608 | | |
1612 | | - | |
| 1609 | + | |
| 1610 | + | |
| 1611 | + | |
1613 | 1612 | | |
1614 | 1613 | | |
1615 | 1614 | | |
| |||
2795 | 2794 | | |
2796 | 2795 | | |
2797 | 2796 | | |
2798 | | - | |
2799 | | - | |
| 2797 | + | |
| 2798 | + | |
| 2799 | + | |
| 2800 | + | |
| 2801 | + | |
| 2802 | + | |
2800 | 2803 | | |
2801 | 2804 | | |
2802 | 2805 | | |
2803 | 2806 | | |
2804 | 2807 | | |
2805 | 2808 | | |
2806 | 2809 | | |
| 2810 | + | |
2807 | 2811 | | |
2808 | 2812 | | |
2809 | 2813 | | |
2810 | 2814 | | |
2811 | 2815 | | |
2812 | 2816 | | |
| 2817 | + | |
| 2818 | + | |
| 2819 | + | |
| 2820 | + | |
| 2821 | + | |
| 2822 | + | |
| 2823 | + | |
| 2824 | + | |
| 2825 | + | |
2813 | 2826 | | |
2814 | 2827 | | |
2815 | 2828 | | |
| |||
2881 | 2894 | | |
2882 | 2895 | | |
2883 | 2896 | | |
| 2897 | + | |
2884 | 2898 | | |
2885 | 2899 | | |
2886 | | - | |
| 2900 | + | |
2887 | 2901 | | |
2888 | 2902 | | |
2889 | 2903 | | |
| |||
2918 | 2932 | | |
2919 | 2933 | | |
2920 | 2934 | | |
| 2935 | + | |
| 2936 | + | |
| 2937 | + | |
2921 | 2938 | | |
2922 | | - | |
| 2939 | + | |
| 2940 | + | |
| 2941 | + | |
| 2942 | + | |
2923 | 2943 | | |
2924 | 2944 | | |
2925 | 2945 | | |
| |||
2936 | 2956 | | |
2937 | 2957 | | |
2938 | 2958 | | |
2939 | | - | |
| 2959 | + | |
2940 | 2960 | | |
2941 | 2961 | | |
2942 | 2962 | | |
| |||
2956 | 2976 | | |
2957 | 2977 | | |
2958 | 2978 | | |
| 2979 | + | |
2959 | 2980 | | |
2960 | | - | |
| 2981 | + | |
2961 | 2982 | | |
2962 | 2983 | | |
2963 | 2984 | | |
| |||
0 commit comments