@@ -17,7 +17,7 @@ import type {
1717import * as fs from 'node:fs'
1818import { existsSync } from 'node:fs'
1919import { readFile } from 'node:fs/promises'
20- import { addBuildPlugin , addComponent , addComponentsDir , addImports , addPlugin , addServerHandler , addServerPlugin , addTemplate , createResolver , defineNuxtModule , hasNuxtModule , hasNuxtModuleCompatibility } from '@nuxt/kit'
20+ import { addBuildPlugin , addComponent , addComponentsDir , addImports , addPlugin , addServerHandler , addServerPlugin , addTemplate , addTypeTemplate , createResolver , defineNuxtModule , hasNuxtModule , hasNuxtModuleCompatibility } from '@nuxt/kit'
2121import { defu } from 'defu'
2222import { installNuxtSiteConfig } from 'nuxt-site-config/kit'
2323import { hash } from 'ohash'
@@ -38,7 +38,7 @@ import {
3838 getPresetNitroPresetCompatibility ,
3939 resolveNitroPreset ,
4040} from './compatibility'
41- import { extendTypes , getNuxtModuleOptions , isNuxtGenerate } from './kit'
41+ import { getNuxtModuleOptions , isNuxtGenerate } from './kit'
4242import { normaliseFontInput } from './pure'
4343import { logger } from './runtime/logger'
4444import { checkLocalChrome , downloadFont , hasResolvableDependency , isUndefinedOrTruthy } from './util'
@@ -155,7 +155,6 @@ export default defineNuxtModule<ModuleOptions>({
155155 name : 'nuxt-og-image' ,
156156 compatibility : {
157157 nuxt : '>=3.16.0' ,
158- bridge : false ,
159158 } ,
160159 configKey : 'ogImage' ,
161160 } ,
@@ -222,7 +221,7 @@ export default defineNuxtModule<ModuleOptions>({
222221 const basePath = config . zeroRuntime ? './runtime/server/routes/__zero-runtime' : './runtime/server/routes'
223222 let publicDirAbs = nuxt . options . dir . public
224223 if ( ! isAbsolute ( publicDirAbs ) ) {
225- publicDirAbs = publicDirAbs in nuxt . options . alias ? nuxt . options . alias [ publicDirAbs ] : resolve ( nuxt . options . rootDir , publicDirAbs )
224+ publicDirAbs = ( publicDirAbs in nuxt . options . alias ? nuxt . options . alias [ publicDirAbs ] : resolve ( nuxt . options . rootDir , publicDirAbs ) ) || ''
226225 }
227226 if ( isProviderEnabledForEnv ( 'satori' , nuxt , config ) ) {
228227 let attemptSharpUsage = false
@@ -463,6 +462,8 @@ export default defineNuxtModule<ModuleOptions>({
463462 from : resolve ( `./runtime/app/composables/${ name } ` ) ,
464463 } )
465464 if ( ! nuxt . options . dev ) {
465+ nuxt . options . optimization . treeShake . composables . client = nuxt . options . optimization . treeShake . composables . client || { }
466+ nuxt . options . optimization . treeShake . composables . client [ 'nuxt-og-image' ] = nuxt . options . optimization . treeShake . composables . client [ 'nuxt-og-image' ] || [ ]
466467 nuxt . options . optimization . treeShake . composables . client [ 'nuxt-og-image' ] . push ( name )
467468 }
468469 } )
@@ -578,23 +579,24 @@ export default defineNuxtModule<ModuleOptions>({
578579 return `export const theme = ${ JSON . stringify ( unoCssConfig ) } `
579580 }
580581
581- extendTypes ( 'nuxt-og-image' , ( { typesPath } ) => {
582- // need to map our components to types so we can import them
583- const componentImports = ogImageComponentCtx . components . map ( ( component ) => {
584- const relativeComponentPath = relative ( resolve ( nuxt ! . options . rootDir , nuxt ! . options . buildDir , 'module' ) , component . path ! )
585- // remove dirNames from component name
586- const name = config . componentDirs
587- // need to sort by longest first so we don't replace the wrong part of the string
588- . sort ( ( a , b ) => b . length - a . length )
589- . reduce ( ( name , dir ) => {
590- // only replace from the start of the string
591- return name . replace ( new RegExp ( `^${ dir } ` ) , '' )
592- } , component . pascalName )
593- return ` '${ name } ': typeof import('${ relativeComponentPath } ')['default']`
594- } ) . join ( '\n' )
595- return `
596- declare module 'nitropack' {
597- interface NitroRouteRules {
582+ addTypeTemplate ( {
583+ filename : 'module/nuxt-og-image.d.ts' ,
584+ getContents : ( data ) => {
585+ const typesPath = relative ( resolve ( data . nuxt ! . options . rootDir , data . nuxt ! . options . buildDir , 'module' ) , resolve ( 'runtime/types' ) )
586+ // need to map our components to types so we can import them
587+ const componentImports = ogImageComponentCtx . components . map ( ( component ) => {
588+ const relativeComponentPath = relative ( resolve ( nuxt ! . options . rootDir , nuxt ! . options . buildDir , 'module' ) , component . path ! )
589+ // remove dirNames from component name
590+ const name = config . componentDirs
591+ // need to sort by longest first so we don't replace the wrong part of the string
592+ . sort ( ( a , b ) => b . length - a . length )
593+ . reduce ( ( name , dir ) => {
594+ // only replace from the start of the string
595+ return name . replace ( new RegExp ( `^${ dir } ` ) , '' )
596+ } , component . pascalName )
597+ return ` '${ name } ': typeof import('${ relativeComponentPath } ')['default']`
598+ } ) . join ( '\n' )
599+ const types = `interface NitroRouteRules {
598600 ogImage?: false | import('${ typesPath } ').OgImageOptions & Record<string, any>
599601 }
600602 interface NitroRouteConfig {
@@ -603,7 +605,14 @@ declare module 'nitropack' {
603605 interface NitroRuntimeHooks {
604606 'nuxt-og-image:context': (ctx: import('${ typesPath } ').OgImageRenderEventContext) => void | Promise<void>
605607 'nuxt-og-image:satori:vnodes': (vnodes: import('${ typesPath } ').VNode, ctx: import('${ typesPath } ').OgImageRenderEventContext) => void | Promise<void>
606- }
608+ }`
609+ return `
610+ declare module 'nitropack' {
611+ ${ types }
612+ }
613+
614+ declare module 'nitropack/types' {
615+ ${ types }
607616}
608617
609618declare module '#og-image/components' {
@@ -614,7 +623,13 @@ ${componentImports}
614623declare module '#og-image/unocss-config' {
615624 export type theme = any
616625}
626+
627+ export {}
617628`
629+ } ,
630+ } , {
631+ nitro : true ,
632+ nuxt : true ,
618633 } )
619634
620635 const cacheEnabled = typeof config . runtimeCacheStorage !== 'undefined' && config . runtimeCacheStorage !== false
0 commit comments