fix(migrate): tolerate nested npm overrides during bootstrap detection - #2267
Open
charpeni wants to merge 1 commit into
Open
fix(migrate): tolerate nested npm overrides during bootstrap detection#2267charpeni wants to merge 1 commit into
charpeni wants to merge 1 commit into
Conversation
✅ Deploy Preview for viteplus-preview canceled.
|
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
overrideSpecSatisfiesVitePlusso a non-string override value never reachesspec.startsWith(), which crashedvp migratewithTypeError: spec.startsWith is not a function{"overrides": {"vite": {"rollup": "..."}}}) as not satisfying the managed override, so the bootstrap stays pending andensureOverrideEntrieswrites the managed aliasviteandvitest)Why
npm supports nested
overridesobjects (a user override scoped under a dependency), butdetectVitePlusBootstrapPendingassumed every override value is a string. A valid package.json with a nested override under a managed key crashed migration during bootstrap detection.A nested object never aliases the dependency itself, so it cannot satisfy the managed Vite+ override. Returning
falsemakes detection report the bootstrap as pending, and the existing rewrite then sets the managed spec — after which detection converges. The single guard covers every caller (overridesSatisfyVitePlusacross npm/bun/pnpm/yarn sources,npmVitePlusManagedDependenciesPending, andensureOverrideEntries), and also hardens against other non-string values, such as a numeric scalar read frompnpm-workspace.yamloverrides.When the project does not use vitest directly, a user override scoped under
vitestis left intact, matching the existing contract documented inremoveManagedVitestEntry. Note that under a managed key the rewrite replaces the nested object with the managed string spec, dropping any user sub-overrides scoped beneath it (e.g. avite > rolluppin); preserving those via npm's nested"."syntax is left as a possible follow-up.Fixes #2002.
Validation
pnpm -F vite-plus exec vitest run src/migration/__tests__/migrator.spec.ts -t 'tolerates nested npm override objects'— fails without the fix with the exact reported crash (TypeError: spec.startsWith is not a functionatoverrideSpecSatisfiesVitePlus, reached viadetectVitePlusBootstrapPending), passes with itsrc/migration/__tests__/migrator.spec.tsrun — no changes to any existing test outcomeusesVitest = true(both rewritten to managed specs, detection converges) and a nested object in yarnresolutions(converges without crashing)packages/cliis clean