Fix @astrojs/prism edgecase with pnpm (#6485)

This commit is contained in:
Bjorn Lu 2023-03-10 03:44:14 +08:00 committed by GitHub
parent a9a6ae2981
commit d637d1ea5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 4 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fix `@astrojs/prism` edgecase with strict package managers

View file

@ -49,6 +49,16 @@ const ALWAYS_NOEXTERNAL = [
'@fontsource/*', '@fontsource/*',
]; ];
// These specifiers are usually dependencies written in CJS, but loaded through Vite's transform
// pipeline, which Vite doesn't support in development time. This hardcoded list temporarily
// fixes things until Vite can properly handle them, or when they support ESM.
const ONLY_DEV_EXTERNAL = [
// Imported by `<Code/>` which is processed by Vite
'shiki',
// Imported by `@astrojs/prism` which exposes `<Prism/>` that is processed by Vite
'prismjs/components/index.js',
];
/** Return a common starting point for all Vite actions */ /** Return a common starting point for all Vite actions */
export async function createVite( export async function createVite(
commandConfig: vite.InlineConfig, commandConfig: vite.InlineConfig,
@ -162,10 +172,7 @@ export async function createVite(
}, },
ssr: { ssr: {
noExternal: [...ALWAYS_NOEXTERNAL, ...astroPkgsConfig.ssr.noExternal], noExternal: [...ALWAYS_NOEXTERNAL, ...astroPkgsConfig.ssr.noExternal],
// shiki is imported by Code.astro, which is no-externalized (processed by Vite). external: [...(mode === 'dev' ? ONLY_DEV_EXTERNAL : []), ...astroPkgsConfig.ssr.external],
// However, shiki's deps are in CJS and trips up Vite's dev SSR transform, externalize
// shiki to load it with node instead.
external: [...(mode === 'dev' ? ['shiki'] : []), ...astroPkgsConfig.ssr.external],
}, },
}; };