fix(optimizer): skip null-valued exports in expandGlobIds glob resolution#22611
Open
LeSingh1 wants to merge 3 commits into
Open
fix(optimizer): skip null-valued exports in expandGlobIds glob resolution#22611LeSingh1 wants to merge 3 commits into
LeSingh1 wants to merge 3 commits into
Conversation
The previous test used vi.mock to stub resolvePackageData, but vitest's isolate:false shares the module graph across test files. By the time expandGlobIds.spec.ts runs, packages.ts is already cached, so the mock never intercepts the real call and the function returns [] early. Replace the mock with a real temp-dir fixture: write an actual package.json under a mkdtemp directory, point the config root there, and let resolvePackageData resolve it naturally. Matches the pattern used by other tests in this directory.
fs.mkdtempSync on macOS returns a path under /var/folders/... which is a symlink to /private/var/folders/.... Vite's resolvePackageData uses realpaths internally, so the fixture root mismatched and the test failed only on node-24/macOS CI. Wrap mkdtempSync with fs.realpathSync to normalise the path.
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.
Fixes #22586.
When using glob patterns in
optimizeDeps.include(e.g.my-pkg/*), Vite expands the pattern against the package'sexportsfield. The non-glob path of that expansion unconditionally added every export key to the candidate list, including keys with anullvalue.Per the Node.js docs, a
nullexport value is how packages mark subpaths as intentionally private and unreachable:For example, a package with this in its
package.json:{ "exports": { ".": "./dist/index.js", "./utils": "./dist/utils.js", "./internal": null } }When a user adds
"my-pkg/*"tooptimizeDeps.include, the old code would includemy-pkg/internalin the resolved list. Vite then tries to bundle that path, fails to find a file for it, and throws a build error.The glob branch already handled this correctly by calling
getFirstExportStringValuewhich returnsundefinedfornull, triggering an earlycontinue. The non-glob branch just needed the same null check.The fix is a single guard in
expandGlobIdsinsidepackages/vite/src/node/optimizer/resolve.ts:A unit test is added that confirms null-valued export keys are excluded from the resolved list while non-null ones are still included.