77 */
88import orga from '@orgajs/rollup'
99import { parse as parseMetadata } from '@orgajs/metadata'
10+ import astroJSXRenderer from 'astro/jsx/renderer.js'
1011import { addAstroFragment } from './lib/plugin/recma-add-astro-fragment.js'
1112
1213/**
@@ -19,8 +20,14 @@ export default function org({ recmaPlugins, ...options }) {
1920 hooks : {
2021 // @ts -ignore - addPageExtension, addContentEntryType are internal APIs
2122 'astro:config:setup' : async ( /** @type {SetupHookParams } */ params ) => {
22- const { addPageExtension, addContentEntryType, updateConfig } = params
23+ const {
24+ addPageExtension,
25+ addContentEntryType,
26+ updateConfig,
27+ addRenderer,
28+ } = params
2329 addPageExtension ( '.org' )
30+ addRenderer ( astroJSXRenderer )
2431
2532 addContentEntryType ( {
2633 extensions : [ '.org' ] ,
@@ -34,20 +41,44 @@ export default function org({ recmaPlugins, ...options }) {
3441 slug : Array . isArray ( data . slug ) ? data . slug [ 0 ] : data . slug ,
3542 }
3643 } ,
44+ handlePropagation : true ,
3745 } )
3846
47+ // TODO: add org-components support
48+ // const components = new URL('org-components', config.srcDir)
49+
3950 updateConfig ( {
4051 vite : {
52+ /** @type {import('vite').Plugin[] } */
4153 plugins : [
4254 {
4355 enforce : 'pre' ,
4456 ...orga ( {
4557 ...options ,
4658 jsxImportSource : 'astro' ,
59+ // providerImportSource: components.pathname,
4760 recmaPlugins : [ ...( recmaPlugins ?? [ ] ) , addAstroFragment ] ,
4861 elementAttributeNameCase : 'html' ,
4962 development : false ,
5063 } ) ,
64+ configResolved ( resolved ) {
65+ // HACK: move ourselves before Astro's JSX plugin to transform things in the right order
66+ const jsxPluginIndex = resolved . plugins . findIndex (
67+ ( p ) => p . name === 'astro:jsx'
68+ )
69+ if ( jsxPluginIndex !== - 1 ) {
70+ const myPluginIndex = resolved . plugins . findIndex (
71+ ( p ) => p . name === '@orgajs/rollup'
72+ )
73+ if ( myPluginIndex !== - 1 ) {
74+ const myPlugin = resolved . plugins [ myPluginIndex ]
75+ // @ts -ignore-error ignore readonly annotation
76+ resolved . plugins . splice ( myPluginIndex , 1 )
77+ // @ts -ignore-error ignore readonly annotation
78+ resolved . plugins . splice ( jsxPluginIndex , 0 , myPlugin )
79+ }
80+ }
81+ } ,
5182 } ,
5283 {
5384 name : '@orgajs/org-postprocess' ,
@@ -57,7 +88,6 @@ export default function org({ recmaPlugins, ...options }) {
5788 */
5889 transform ( code , id ) {
5990 if ( ! id . endsWith ( '.org' ) ) return
60- // console.log(code)
6191 return { code, map : null }
6292 } ,
6393 } ,
0 commit comments