Fix @astrojs/prism
edgecase with pnpm
#6485
Merged
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.
Changes
Fixes #6402
Firstly, I don't like what I'm doing, but it's the best solution at the mean time 😬
This PR makes
astro
addprismjs/components/index.js
tovite.ssr.external
in dev time to fix using@astrojs/prism
in a pnpm setup.This is needed because while we do automatic externalizing of transitive deps of Astro libraries, in which case we externalize
prismjs
by default,prismjs/components/index.js
is not covered. In this case, when Vite decides whether toexternal
ornoExternal
this import, it checks whether it's import-able from the project root. With pnpm, it's not, so it getsnoExternal
and that doesn't work with CJS files.Ideally the fix would be in Vite to externalize things base on the real import path, in which case should be
@astrojs/prism
instead of the project root.Testing
Tested manually with the issue repo.
Docs
This PR fixes this edgecase so I think we don't need docs for it. The issue in general is a bit hard to explain in docs without digging into Vite internals.