File tree Expand file tree Collapse file tree
packages/astro-expressive-code Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ ' astro-expressive-code ' : patch
3+ ---
4+
5+ Fixes an issue where the deprecated, but still available ` theme ` option was not being taken into account during SSR bundle trimming.
Original file line number Diff line number Diff line change 1+ ---
2+ ' astro-expressive-code ' : patch
3+ ---
4+
5+ Improves the error message when the ` <Code> ` component is being used on a page without having the Astro integration enabled in the project.
Original file line number Diff line number Diff line change @@ -11,6 +11,25 @@ async function createRenderer() {
1111 const { astroConfig, ecConfigFileOptions, ecIntegrationOptions = { } } = await import ( 'virtual:astro-expressive-code/config' )
1212 const { createAstroRenderer, mergeEcConfigOptions } = await import ( 'virtual:astro-expressive-code/api' )
1313
14+ if ( typeof mergeEcConfigOptions !== 'function' ) {
15+ throw new Error (
16+ `You are trying to use Expressive Code's \`<Code>\` component, but the Expressive Code
17+ Astro integration is not enabled in your project.
18+
19+ If you are using Starlight, ensure that its default Expressive Code integration
20+ was not disabled by you or your themes or plugins.
21+
22+ If you are not a Starlight user, ensure that Expressive Code was added to
23+ \`integrations\` in your Astro config file.
24+
25+ In case you don't want to use Expressive Code, you can import Astro's own \`<Code>\`
26+ component from \`astro:components\` instead.`
27+ . split ( / \r ? \n [ \t ] * \r ? \n / )
28+ . map ( ( s ) => s . replace ( / \s + / g, ' ' ) . trim ( ) )
29+ . join ( '\n\n' )
30+ )
31+ }
32+
1433 const strIntegrationOptions = JSON . stringify ( ecIntegrationOptions )
1534 if ( strIntegrationOptions . includes ( '"[Function]"' ) || strIntegrationOptions . includes ( "'[Circular]'" ) ) {
1635 throw new Error (
Original file line number Diff line number Diff line change @@ -58,7 +58,12 @@ export function vitePluginAstroExpressiveCode({
5858 // Prepare Shiki-related SSR bundle trimming
5959 const shikiConfig = typeof processedEcConfig . shiki === 'object' ? processedEcConfig . shiki : { }
6060 const configuredEngine = shikiConfig . engine === 'javascript' ? 'javascript' : 'oniguruma'
61- const configuredBundledThemes : string [ ] = ( processedEcConfig . themes ?? [ ] ) . filter ( ( theme ) => typeof theme === 'string' )
61+ // Extract any bundled theme names from the config, supporting the deprecated `theme` option
62+ // and the current `themes` option
63+ const anyThemeOrThemes = processedEcConfig as unknown as { theme : string | string [ ] ; themes : string | string [ ] }
64+ const effectiveThemesOrTheme = anyThemeOrThemes . themes ?? anyThemeOrThemes . theme ?? [ ]
65+ const effectiveThemes = Array . isArray ( effectiveThemesOrTheme ) ? effectiveThemesOrTheme : [ effectiveThemesOrTheme ]
66+ const configuredBundledThemes = effectiveThemes . filter ( ( theme ) => typeof theme === 'string' )
6267 const shikiAssetRegExp = / (?< = \n ) \s * \{ [ \s \S ] * ?" i d " : " ( .* ?) " , [ \s \S ] * ?\n \s * \} , ? \s * \n / g
6368
6469 const noQuery = ( source : string ) => source . split ( '?' ) [ 0 ]
You can’t perform that action at this time.
0 commit comments