-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf(resolve): refactor package.json handling for deep imports #12461
Conversation
Run & review this pull request in StackBlitz Codeflow. |
/ecosystem-ci run |
📝 Ran ecosystem CI: Open
|
Qwik, Nuxt, and Histoire are also currently failing on main (same errors). But Vitepress against main was successful, so there may be a regression for it 👀 |
I ran the VitePress test locally, and I can get the same error, but it's not always reproducible. When they do fail, I can confirm that the VitePress page has an empty I can confirm when running some repros that this PR improves the resolve speed slightly, so it's not slowing down the tests that causes it to timeout. Not really sure what to do here though, we could maybe test again when we start the minor. I'm guessing it's some sort of race condition, since running that failing test directly via |
cc @brc-dd in case you have some time to help us debugging this in VitePress before 4.3 |
Yeah, I'll look into this, it's probably just a flaky test IG 👀 Even in our repo, we sometimes have to rerun jobs. |
Ah, ok nvm. You guys already triggered it 3 times. |
Seems like some issue with one of our deps, appears to be working after bumping them: https://github.com/brc-dd/vite-ecosystem-ci/actions/runs/4448482529/attempts/1, https://github.com/brc-dd/vite-ecosystem-ci/actions/runs/4448586970/jobs/7811590602 |
/ecosystem-ci run vitepress |
Failed 🫠 |
/ecosystem-ci run vitepress |
Yeah it looks like something in this PR is causing it to happen more frequently, but I can't tell where. Thanks for looking into this though @brc-dd! |
/ecosystem-ci run vitepress |
/ecosystem-ci run vitepress |
Description
Partial revert of #5665. That PR was not
exports
friendly and we had to fix it in #10371, but it mixes both "root" package.json and "nearest" package.json, which needs to be handled separately.This PR refactors in a way that
pkg
passed toresolveDeepImport
andresolvePackageEntry
is always the "root" package.json. If further down the chain a resolve logic needs the "nearest" package.json, they can resolve it themselves.This change shouldn't break
resolvePackageEntry
(since that's root import only), but changesresolveDeepImport
slightly, where:exports
field, thebrowser
field (if available) will be derive from the "root" package.json (now), instead of the "nearest" package.json (before)I think the above is a bug fix though.
More details about `browser`
According to https://github.com/defunctzombie/package-browser-field-spec#alternate-main---basic:
It implies that
package.json
other than "root" should be checked too, but if we respect it, that means we have to check allpackage.json
that's part of the current file path, which is a lot of work even if thebrowser
field was never used.I think it's fine for now to check the
browser
field based on "root" package.json only as that's the more common case.Additional context
No benchmarks 😬 But I noticed this optimization as we're consistently trying to resolve
package.json
for long deep import paths due to:vite/packages/vite/src/node/plugins/resolve.ts
Lines 717 to 725 in 535c8c5
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).