fix(create): normalize sub-package vite-plus and drop aliased vite/vitest#1697
Draft
fengmk2 wants to merge 2 commits into
Draft
fix(create): normalize sub-package vite-plus and drop aliased vite/vitest#1697fengmk2 wants to merge 2 commits into
fengmk2 wants to merge 2 commits into
Conversation
…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.
✅ Deploy Preview for viteplus-preview canceled.
|
… 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two clean-up fixes for
vp create vite:monorepo:packages/utils/package.jsonkeeps\"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 onneedVitePlus, which only flips true whenvite/vitest/oxlint/oxfmt/tsdown/@vitest/browser*is present — none of which the library template has. Soapps/websiteended up withvite-plus: catalog:whilepackages/utilsstayed pinned, leaving sub-packages drifted.Fix: in
rewritePackageJson, also normalize an existingvite-plusvalue to the canonical spec (catalog:in catalog-supporting monorepos, orVITE_PLUS_VERSIONunder force-override). Scoped to catalog-supporting PMs sovp migrateon npm/standalone doesn't silently overwrite a user's pinned version.apps/website/package.jsonretains aliasedvite/vitestdevDependencies left bycreate-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 tovp ...and no user file imports'vite'/'vitest', sovite-plusprovides them transitively. The dangling keys are dead weight.Fix: in
executeMonorepoTemplate, after the per-package migrator runs onapps/website, strip theviteandvitestkeys from devDependencies. (Only invp create, notvp migrate.)CI coverage
New monorepo-only assertion step in
.github/workflows/test-vp-create.ymlruns across all 4 package managers and verifies:apps/websitedevDependencies contain neithervitenorvitestapps/websiteandpackages/utilsdeclarevite-plusvite-plusspec matches across both sub-packages (npm is skipped since its non-catalogvp migratepath 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)test-vp-creatematrix (pnpm/npm/yarn/bun × monorepo template) passes the new assertion step