summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Bjorn Lu <bjornlu.dev@gmail.com> 2023-03-10 03:44:14 +0800
committerGravatar GitHub <noreply@github.com> 2023-03-09 14:44:14 -0500
commitd637d1ea5b347b9c724adc895c9006c696ac8fc8 (patch)
tree66c95e8d02800a4ca61fdac68e2461ab3c8ab5f1
parenta9a6ae29812339ea00f3b9afd3de09bd9d3733a9 (diff)
downloadastro-d637d1ea5b347b9c724adc895c9006c696ac8fc8.tar.gz
astro-d637d1ea5b347b9c724adc895c9006c696ac8fc8.tar.zst
astro-d637d1ea5b347b9c724adc895c9006c696ac8fc8.zip
Fix `@astrojs/prism` edgecase with pnpm (#6485)
-rw-r--r--.changeset/tall-taxis-exercise.md5
-rw-r--r--packages/astro/src/core/create-vite.ts15
2 files changed, 16 insertions, 4 deletions
diff --git a/.changeset/tall-taxis-exercise.md b/.changeset/tall-taxis-exercise.md
new file mode 100644
index 000000000..18f2b6111
--- /dev/null
+++ b/.changeset/tall-taxis-exercise.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Fix `@astrojs/prism` edgecase with strict package managers
diff --git a/packages/astro/src/core/create-vite.ts b/packages/astro/src/core/create-vite.ts
index 7308a56df..f4316bc2c 100644
--- a/packages/astro/src/core/create-vite.ts
+++ b/packages/astro/src/core/create-vite.ts
@@ -49,6 +49,16 @@ const ALWAYS_NOEXTERNAL = [
'@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 */
export async function createVite(
commandConfig: vite.InlineConfig,
@@ -162,10 +172,7 @@ export async function createVite(
},
ssr: {
noExternal: [...ALWAYS_NOEXTERNAL, ...astroPkgsConfig.ssr.noExternal],
- // shiki is imported by Code.astro, which is no-externalized (processed by Vite).
- // 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],
+ external: [...(mode === 'dev' ? ONLY_DEV_EXTERNAL : []), ...astroPkgsConfig.ssr.external],
},
};