Skip to content

fix(create): normalize sub-package vite-plus and drop aliased vite/vitest#1697

Draft
fengmk2 wants to merge 2 commits into
mainfrom
fix/create-monorepo-vite-plus-catalog-and-vite-cleanup
Draft

fix(create): normalize sub-package vite-plus and drop aliased vite/vitest#1697
fengmk2 wants to merge 2 commits into
mainfrom
fix/create-monorepo-vite-plus-catalog-and-vite-cleanup

Conversation

@fengmk2
Copy link
Copy Markdown
Member

@fengmk2 fengmk2 commented May 27, 2026

Summary

Two clean-up fixes for vp create vite:monorepo:

  • packages/utils/package.json keeps \"vite-plus\": \"^x.y.z\" inherited from the remote library template (github:sxzz/tsdown-templates/vite-plus). The per-package migrator's catalog rewrite is gated on needVitePlus, which only flips true when vite/vitest/oxlint/oxfmt/tsdown/@vitest/browser* is present — none of which the library template has. So apps/website ended up with vite-plus: catalog: while packages/utils stayed pinned, leaving sub-packages drifted.

    Fix: in rewritePackageJson, also normalize an existing vite-plus value to the canonical spec (catalog: in catalog-supporting monorepos, or VITE_PLUS_VERSION under force-override). Scoped to catalog-supporting PMs so vp migrate on npm/standalone doesn't silently overwrite a user's pinned version.

  • apps/website/package.json retains aliased vite / vitest devDependencies left by create-vite vanilla-ts. The migrator only rewrites their value (e.g. vite: catalog:), it doesn't drop the keys. But in a freshly-scaffolded project the CLI scripts have already been rewritten to vp ... and no user file imports 'vite' / 'vitest', so vite-plus provides them transitively. The dangling keys are dead weight.

    Fix: in executeMonorepoTemplate, after the per-package migrator runs on apps/website, strip the vite and vitest keys from devDependencies. (Only in vp create, not vp migrate.)

CI coverage

New monorepo-only assertion step in .github/workflows/test-vp-create.yml runs across all 4 package managers and verifies:

  • apps/website devDependencies contain neither vite nor vitest
  • both apps/website and packages/utils declare vite-plus
  • for pnpm/yarn/bun, the vite-plus spec matches across both sub-packages (npm is skipped since its non-catalog vp migrate path keeps user pins untouched)

Test plan

  • vp test run packages/cli — 407 passed (added 2 unit cases covering the pnpm-normalize and npm-leave-alone paths)
  • CI: test-vp-create matrix (pnpm/npm/yarn/bun × monorepo template) passes the new assertion step

…test

In `vp create vite:monorepo`:

- `packages/utils/package.json` inherited `"vite-plus": "^x.y.z"` from the
  remote library template and the per-package migrator never touched it
  (the existing rewrite only fires when `needVitePlus` is triggered by
  vite/vitest/oxlint/etc.). The result was sub-package drift —
  `apps/website` had `"vite-plus": "catalog:"` while `packages/utils`
  stayed pinned. Normalize an existing `vite-plus` value to the canonical
  spec (`catalog:` or `VITE_PLUS_VERSION`) whenever the project supports
  catalogs, so siblings stay aligned. Scoped to catalog-supporting PMs so
  `vp migrate` on npm/standalone doesn't silently overwrite a user pin.

- `apps/website/package.json` kept aliased `vite`/`vitest` devDeps left
  by `create-vite` because the migrator only rewrote their value
  (`vite: catalog:`) instead of removing the key. In a freshly-scaffolded
  project the CLI scripts have been rewritten to `vp ...` and no user
  code imports `'vite'`/`'vitest'`, so `vite-plus` brings them in
  transitively — drop the keys to keep the generated package.json clean.

Also extend the `test-vp-create` workflow with a monorepo-only assertion
step that catches regressions: `apps/website` must have no
`vite`/`vitest` in devDependencies, both sub-packages must declare
`vite-plus`, and (for pnpm/yarn/bun) the `vite-plus` spec must match
across them.
@fengmk2 fengmk2 added the test: create-e2e Run `vp create` e2e tests label May 27, 2026
@fengmk2 fengmk2 self-assigned this May 27, 2026
@netlify
Copy link
Copy Markdown

netlify Bot commented May 27, 2026

Deploy Preview for viteplus-preview canceled.

Name Link
🔨 Latest commit 0132c60
🔍 Latest deploy log https://app.netlify.com/projects/viteplus-preview/deploys/6a16bd60470b58000895cfb6

… auto-add to migrations

Address review findings on the new vite-plus normalize path:

- Preserve protocol-prefixed specs (`catalog:named`, `workspace:*`, `link:`,
  `file:`, `npm:`, `github:`, `git+`/`git:`, `http(s)://`) so deliberate
  user pins survive `vp migrate`. Previously the new normalize rule
  rewrote anything that wasn't literally `catalog:` — silently clobbering
  named-catalog references, workspace and link protocols, and aliased pins.

- Split the vitest peer-dep auto-add back behind `needVitePlus` only. A
  pure normalize pass (sub-package only needed its pinned `^x.y.z`
  re-aligned to `catalog:`) must not also inject a `vitest` devDep just
  because the project happens to have a `vitest-browser-*` peer.

- Drop the now-redundant `const version = canonicalVitePlusSpec` alias.

Also update `snap-tests-global/new-vite-monorepo-bun/snap.txt` to drop the
stripped `"vite": "catalog:"` line in apps/website (matches the cleanup in
`executeMonorepoTemplate`), and add an existsSync guard to the workflow's
node -e assertion so a missing sub-package package.json surfaces with a
targeted message instead of an opaque ENOENT.

Test coverage: yarn + bun catalog normalize, protocol-prefix preservation,
and "pure normalize must not auto-add vitest". 410 passed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test: create-e2e Run `vp create` e2e tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant