Skip to content
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

fix: optimizeDeps.include not working with paths inside packages #13922

Merged
merged 1 commit into from Jul 22, 2023

Conversation

brc-dd
Copy link
Contributor

@brc-dd brc-dd commented Jul 22, 2023

Description

Currently using something like:

config: () => ({
  optimizeDeps: {
    include: [
      'vitepress > @vueuse/integrations/useFocusTrap',
      'vitepress > mark.js/src/vanilla.js',
      'vitepress > minisearch'
    ]
  }
}),

doesn't work consistently across projects. In case of monorepos, it fails to resolve deps when the include contains some path other than the package name itself - (e.g. @vueuse/integrations/useFocusTrap and mark.js/src/vanilla.js in this case). It works fine for minisearch because that's the package name itself.

The cause of this issue seems to be the fact that tryOptimizedResolve calls resolvePackageData with id instead of package name (e.g. @vueuse/integrations/useFocusTrap instead of @vueuse/integrations). Which results in resolvePackageData searching for package.json in wrong directories (e.g. '/Users/brc-dd/vitepress/node_modules/@vueuse/integrations/useFocusTrap/package.json' instead of '/Users/brc-dd/vitepress/node_modules/@vueuse/integrations/package.json').

This PR fixes that by passing npm package name instead of passing id directly.

Additional context

internal discord thread


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the PR Title Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@stackblitz
Copy link

stackblitz bot commented Jul 22, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@patak-dev
Copy link
Member

/ecosystem-ci run

@vite-ecosystem-ci
Copy link

vite-ecosystem-ci bot commented Jul 22, 2023

📝 Ran ecosystem CI: Open

suite result
analogjs ❌ failure
astro ✅ success
histoire ❌ failure
iles ❌ failure
ladle ✅ success
laravel ✅ success
marko ✅ success
nuxt ✅ success
nx ✅ success
previewjs ✅ success
qwik ✅ success
rakkas ✅ success
sveltekit ✅ success
unocss ✅ success
vite-plugin-pwa ✅ success
vite-plugin-ssr ✅ success
vite-plugin-react ✅ success
vite-plugin-react-pages ✅ success
vite-plugin-react-swc ✅ success
vite-plugin-svelte ✅ success
vite-plugin-vue ✅ success
vite-setup-catalogue ✅ success
vitepress ✅ success
vitest ✅ success

@patak-dev patak-dev merged commit 06e4f57 into vitejs:main Jul 22, 2023
15 checks passed
@brc-dd brc-dd deleted the fix/optimized-deps-resolver branch July 22, 2023 10:26
@averybross
Copy link

@brc-dd thank you so much for finding/patching this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants