@@ -6,11 +6,29 @@ import type {
66 QwikVitePluginOptions ,
77 SymbolMapperFn
88} from "@builder.io/qwik/optimizer" ;
9+ import type { RenderOptions } from "@builder.io/qwik/server" ;
910import type { AstroConfig , AstroIntegration } from "astro" ;
10- import { createResolver , defineIntegration , watchDirectory } from "astro-integration-kit" ;
11+ import { createResolver , defineIntegration , watchDirectory , withPlugins } from "astro-integration-kit" ;
1112import { z } from "astro/zod" ;
1213import { type PluginOption , build , createFilter } from "vite" ;
1314import type { InlineConfig } from "vite" ;
15+ import aikMod from '@inox-tools/aik-mod' ;
16+
17+ // TODO: contributing this back to aik-mod where we export the type
18+ type DefineModuleOptions = {
19+ constExports ?: Record < string , unknown > ;
20+ defaultExport ?: unknown ;
21+ } ;
22+
23+ type SetupPropsWithAikMod =
24+ Parameters <
25+ NonNullable < AstroIntegration [ "hooks" ] [ "astro:config:setup" ] >
26+ > [ 0 ] & {
27+ defineModule : (
28+ name : string ,
29+ options : DefineModuleOptions
30+ ) => string ;
31+ } ;
1432
1533declare global {
1634 var symbolMapperFn : SymbolMapperFn ;
@@ -26,12 +44,14 @@ const FilterPatternSchema = z.union([
2644 z . null ( )
2745] ) ;
2846
47+ const name = "@qwikdev/astro" ;
48+
2949/**
3050 * This project uses Astro Integration Kit.
3151 * @see https://astro-integration-kit.netlify.app/
3252 */
3353export default defineIntegration ( {
34- name : "@qwikdev/astro" ,
54+ name,
3555 optionsSchema : z
3656 . object ( {
3757 /**
@@ -48,11 +68,12 @@ export default defineIntegration({
4868 * Enable debug mode with the qwikVite plugin.
4969 */
5070 debug : z . boolean ( ) . optional ( ) ,
51-
5271 /**
53- * Use node's readFileSync to read the manifest. Common for deployment providers that don't support dynamic json imports. When false, please ensure your deployment provider supports dynamic json imports, through environment variables or other means.
72+ * Options passed into each Qwik component's `renderToStream` call.
5473 */
55- isNode : z . boolean ( ) . optional ( ) . default ( true )
74+ renderOpts : z . custom < RenderOptions > ( ( data ) => {
75+ return typeof data === "object" && data !== null ;
76+ } ) . optional ( )
5677 } )
5778 . optional ( ) ,
5879
@@ -77,7 +98,7 @@ export default defineIntegration({
7798
7899 const lifecycleHooks : AstroIntegration [ "hooks" ] = {
79100 "astro:config:setup" : async ( setupProps ) => {
80- const { addRenderer, updateConfig, config } = setupProps ;
101+ const { addRenderer, updateConfig, config, defineModule } = setupProps as SetupPropsWithAikMod ;
81102 astroConfig = config ;
82103 // integration HMR support
83104 watchDirectory ( setupProps , resolver ( ) ) ;
@@ -86,6 +107,12 @@ export default defineIntegration({
86107 serverEntrypoint : resolver ( "../server.ts" )
87108 } ) ;
88109
110+ defineModule ( 'virtual:qwikdev-astro' , {
111+ constExports : {
112+ renderOpts : options ?. renderOpts ?? { }
113+ }
114+ } ) ;
115+
89116 /** Relative paths, as the Qwik optimizer handles normalization */
90117 srcDir = getRelativePath ( astroConfig . root . pathname , astroConfig . srcDir . pathname ) ;
91118
@@ -319,12 +346,14 @@ export default defineIntegration({
319346 }
320347 } ;
321348
322- return {
323- hooks : lifecycleHooks
324- } ;
349+ return withPlugins ( {
350+ name,
351+ hooks : lifecycleHooks ,
352+ plugins : [ aikMod ]
353+ } ) ;
325354 }
326355} ) ;
327356
328357function getRelativePath ( from : string , to : string ) {
329358 return to . replace ( from , "" ) || "." ;
330- }
359+ }
0 commit comments