Skip to content

Commit e368342

Browse files
committedOct 30, 2024·
fix: replace #nuxt-og-image with #og-image
1 parent 80af9db commit e368342

File tree

20 files changed

+61
-61
lines changed

20 files changed

+61
-61
lines changed
 

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
"h3",
130130
"nitropack",
131131
"@vue/runtime-core",
132-
"#nuxt-og-image/components",
132+
"#og-image/components",
133133
"sharp",
134134
"unstorage",
135135
"unstorage/drivers/fs",

‎src/compatibility.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ export async function applyNitroPresetCompatibility(nitroConfig: NitroConfig, op
140140
const satoriEnabled = typeof options.compatibility?.satori !== 'undefined' ? !!options.compatibility.satori : !!compatibility.satori
141141
const chromiumEnabled = typeof options.compatibility?.chromium !== 'undefined' ? !!options.compatibility.chromium : !!compatibility.chromium
142142
// renderers
143-
nitroConfig.alias!['#nuxt-og-image/renderers/satori'] = satoriEnabled ? resolve('./runtime/nitro/og-image/satori/renderer') : 'unenv/runtime/mock/empty'
144-
nitroConfig.alias!['#nuxt-og-image/renderers/chromium'] = chromiumEnabled ? resolve('./runtime/nitro/og-image/chromium/renderer') : 'unenv/runtime/mock/empty'
143+
nitroConfig.alias!['#og-image/renderers/satori'] = satoriEnabled ? resolve('./runtime/nitro/og-image/satori/renderer') : 'unenv/runtime/mock/empty'
144+
nitroConfig.alias!['#og-image/renderers/chromium'] = chromiumEnabled ? resolve('./runtime/nitro/og-image/chromium/renderer') : 'unenv/runtime/mock/empty'
145145

146146
const resolvedCompatibility: Partial<Omit<RuntimeCompatibilitySchema, 'wasm'>> = {}
147147
function applyBinding(key: keyof Omit<RuntimeCompatibilitySchema, 'wasm'>) {
@@ -159,7 +159,7 @@ export async function applyNitroPresetCompatibility(nitroConfig: NitroConfig, op
159159
// @ts-expect-error untyped
160160
resolvedCompatibility[key] = binding
161161
return {
162-
[`#nuxt-og-image/bindings/${key}`]: binding === false ? 'unenv/runtime/mock/empty' : resolve(`./runtime/nitro/og-image/bindings/${key}/${binding}`),
162+
[`#og-image/bindings/${key}`]: binding === false ? 'unenv/runtime/mock/empty' : resolve(`./runtime/nitro/og-image/bindings/${key}/${binding}`),
163163
}
164164
}
165165
nitroConfig.alias = defu(
@@ -178,7 +178,7 @@ export async function applyNitroPresetCompatibility(nitroConfig: NitroConfig, op
178178
nitroConfig.rollupConfig = nitroConfig.rollupConfig || {}
179179
nitroConfig.wasm = defu(compatibility.wasm, nitroConfig.wasm)
180180

181-
nitroConfig.virtual!['#nuxt-og-image/compatibility'] = () => `export default ${JSON.stringify(resolvedCompatibility)}`
181+
nitroConfig.virtual!['#og-image/compatibility'] = () => `export default ${JSON.stringify(resolvedCompatibility)}`
182182
addTemplate({
183183
filename: 'nuxt-og-image/compatibility.mjs',
184184
getContents() {

‎src/module.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ export default defineNuxtModule<ModuleOptions>({
199199
logger.warn('Nuxt OG Image is enabled but SSR is disabled.\n\nYou should enable SSR (`ssr: true`) or disable the module (`ogImage: { enabled: false }`).')
200200
return
201201
}
202-
nuxt.options.alias['#nuxt-og-image'] = resolve('./runtime')
203-
nuxt.options.alias['#nuxt-og-image-cache'] = resolve('./runtime/nitro/og-image/cache/lru')
202+
nuxt.options.alias['#og-image'] = resolve('./runtime')
203+
nuxt.options.alias['#og-image-cache'] = resolve('./runtime/nitro/og-image/cache/lru')
204204

205205
const preset = resolveNitroPreset(nuxt.options.nitro)
206206
const targetCompatibility = getPresetNitroPresetCompatibility(preset)
@@ -215,7 +215,7 @@ export default defineNuxtModule<ModuleOptions>({
215215

216216
if (!nuxt.options.dev) {
217217
addBuildPlugin(TreeShakeComposablesPlugin, { server: true, client: true, build: true })
218-
nuxt.options.alias['#nuxt-og-image-cache'] = resolve('./runtime/nitro/og-image/cache/mock')
218+
nuxt.options.alias['#og-image-cache'] = resolve('./runtime/nitro/og-image/cache/mock')
219219
}
220220
}
221221

@@ -491,7 +491,7 @@ export default defineNuxtModule<ModuleOptions>({
491491
options: { mode: 'server' },
492492
})
493493
nuxt.options.nitro.virtual = nuxt.options.nitro.virtual || {}
494-
nuxt.options.nitro.virtual['#nuxt-og-image-virtual/component-names.mjs'] = () => {
494+
nuxt.options.nitro.virtual['#og-image-virtual/component-names.mjs'] = () => {
495495
return `export const componentNames = ${JSON.stringify(ogImageComponentCtx.components)}`
496496
}
497497

@@ -505,7 +505,7 @@ export default defineNuxtModule<ModuleOptions>({
505505
nuxt.hook('unocss:config', (_unoCssConfig) => {
506506
unoCssConfig = { ..._unoCssConfig.theme }
507507
})
508-
nuxt.options.nitro.virtual['#nuxt-og-image-virtual/unocss-config.mjs'] = () => {
508+
nuxt.options.nitro.virtual['#og-image-virtual/unocss-config.mjs'] = () => {
509509
return `export const theme = ${JSON.stringify(unoCssConfig)}`
510510
}
511511

@@ -537,12 +537,12 @@ declare module 'nitropack' {
537537
}
538538
}
539539
540-
declare module '#nuxt-og-image/components' {
540+
declare module '#og-image/components' {
541541
export interface OgImageComponents {
542542
${componentImports}
543543
}
544544
}
545-
declare module '#nuxt-og-image/unocss-config' {
545+
declare module '#og-image/unocss-config' {
546546
export type theme = any
547547
}
548548
`

‎src/runtime/nitro/og-image/chromium/renderer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Browser } from 'playwright-core'
22
import type { Renderer } from '../../../types'
3-
import { createBrowser } from '#nuxt-og-image/bindings/chromium'
3+
import { createBrowser } from '#og-image/bindings/chromium'
44
import { createError } from 'h3'
55
import { createScreenshot } from './screenshot'
66

‎src/runtime/nitro/og-image/context.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {
77
import type ChromiumRenderer from './chromium/renderer'
88
import type SatoriRenderer from './satori/renderer'
99
import { useNitroApp } from '#imports'
10-
import { htmlPayloadCache, prerenderOptionsCache } from '#nuxt-og-image-cache'
10+
import { htmlPayloadCache, prerenderOptionsCache } from '#og-image-cache'
1111
import { defu } from 'defu'
1212
import { parse } from 'devalue'
1313
import { createError, getQuery } from 'h3'

‎src/runtime/nitro/og-image/instances.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ const satoriRendererInstance: { instance?: typeof SatoriRenderer } = { instance:
77
const chromiumRendererInstance: { instance?: typeof ChromiumRenderer } = { instance: undefined }
88

99
export async function useSatoriRenderer() {
10-
satoriRendererInstance.instance = satoriRendererInstance.instance || await import('#nuxt-og-image/renderers/satori').then(m => m.default)
10+
satoriRendererInstance.instance = satoriRendererInstance.instance || await import('#og-image/renderers/satori').then(m => m.default)
1111
return satoriRendererInstance.instance!
1212
}
1313

1414
export async function useChromiumRenderer() {
15-
chromiumRendererInstance.instance = chromiumRendererInstance.instance || await import('#nuxt-og-image/renderers/chromium').then(m => m.default)
15+
chromiumRendererInstance.instance = chromiumRendererInstance.instance || await import('#og-image/renderers/chromium').then(m => m.default)
1616
return chromiumRendererInstance.instance!
1717
}

‎src/runtime/nitro/og-image/satori/instances.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,24 @@ const resvgInstance: { instance?: { initWasmPromise: Promise<void>, Resvg: typeo
1111
const satoriInstance: { instance?: { initWasmPromise: Promise<void>, satori: typeof _satori } } = { instance: undefined }
1212

1313
export async function useResvg() {
14-
resvgInstance.instance = resvgInstance.instance || await import('#nuxt-og-image/bindings/resvg').then(m => m.default)
14+
resvgInstance.instance = resvgInstance.instance || await import('#og-image/bindings/resvg').then(m => m.default)
1515
await resvgInstance.instance!.initWasmPromise
1616
return resvgInstance.instance!.Resvg
1717
}
1818

1919
export async function useSatori() {
20-
satoriInstance.instance = satoriInstance.instance || await import('#nuxt-og-image/bindings/satori').then(m => m.default)
20+
satoriInstance.instance = satoriInstance.instance || await import('#og-image/bindings/satori').then(m => m.default)
2121
await satoriInstance.instance!.initWasmPromise
2222
return satoriInstance.instance!.satori
2323
}
2424

2525
export async function useSharp() {
26-
sharpInstance.instance = sharpInstance.instance || await import('#nuxt-og-image/bindings/sharp').then(m => m.default)
26+
sharpInstance.instance = sharpInstance.instance || await import('#og-image/bindings/sharp').then(m => m.default)
2727
return sharpInstance.instance!
2828
}
2929

3030
export async function useCssInline() {
31-
cssInlineInstance.instance = cssInlineInstance.instance || await import('#nuxt-og-image/bindings/css-inline').then(m => m.default)
31+
cssInlineInstance.instance = cssInlineInstance.instance || await import('#og-image/bindings/css-inline').then(m => m.default)
3232
await cssInlineInstance.instance!.initWasmPromise
3333
return cssInlineInstance.instance!.cssInline
3434
}

‎src/runtime/nitro/og-image/satori/plugins/unocss.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { VNode } from '../../../../types'
2-
import { theme } from '#nuxt-og-image/virtual/unocss-config.mjs'
2+
import { theme } from '#og-image-virtual/unocss-config.mjs'
33
import { createGenerator } from '@unocss/core'
44
import presetWind from '@unocss/preset-wind'
55
import { defineSatoriTransformer } from '../utils'

‎src/runtime/nitro/og-image/satori/renderer.ts

+16-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { SatoriOptions } from 'satori'
22
import type { OgImageRenderEventContext, Renderer, ResolvedFontConfig } from '../../../types'
3-
import { theme } from '#nuxt-og-image/virtual/unocss-config.mjs'
4-
import { fontCache } from '#nuxt-og-image-cache'
3+
import { fontCache } from '#og-image-cache'
4+
import { theme } from '#og-image-virtual/unocss-config.mjs'
55
import { defu } from 'defu'
66
import { normaliseFontInput, useOgImageRuntimeConfig } from '../../../shared'
77
import { loadFont } from './font'
@@ -15,20 +15,21 @@ async function resolveFonts(event: OgImageRenderEventContext) {
1515
const normalisedFonts = normaliseFontInput([...event.options.fonts || [], ...fonts])
1616
const localFontPromises: Promise<ResolvedFontConfig>[] = []
1717
const preloadedFonts: ResolvedFontConfig[] = []
18-
for (const font of normalisedFonts) {
19-
if (await fontCache.hasItem(font.cacheKey)) {
20-
font.data = await fontCache.getItemRaw(font.cacheKey)
21-
preloadedFonts.push(font)
22-
}
23-
else {
24-
if (!fontPromises[font.cacheKey]) {
25-
fontPromises[font.cacheKey] = loadFont(event, font).then(async (_font) => {
26-
if (_font?.data)
27-
await fontCache.setItemRaw(_font.cacheKey, _font.data)
28-
return _font
29-
})
18+
if (fontCache) {
19+
for (const font of normalisedFonts) {
20+
if (await fontCache.hasItem(font.cacheKey)) {
21+
font.data = await fontCache.getItemRaw(font.cacheKey)
22+
preloadedFonts.push(font)
23+
} else {
24+
if (!fontPromises[font.cacheKey]) {
25+
fontPromises[font.cacheKey] = loadFont(event, font).then(async (_font) => {
26+
if (_font?.data)
27+
await fontCache?.setItemRaw(_font.cacheKey, _font.data)
28+
return _font
29+
})
30+
}
31+
localFontPromises.push(fontPromises[font.cacheKey])
3032
}
31-
localFontPromises.push(fontPromises[font.cacheKey])
3233
}
3334
}
3435
const awaitedFonts = await Promise.all(localFontPromises)

‎src/runtime/nitro/og-image/satori/transforms/emojis.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { NuxtIslandResponse } from 'nuxt/dist/core/runtime/nitro/renderer'
22
import type { OgImageRenderEventContext } from '../../../../types'
3-
import { emojiCache } from '#nuxt-og-image-cache'
3+
import { emojiCache } from '#og-image-cache'
44

55
const charMap = {
66
'2049': 'exclamation-question-mark',

‎src/runtime/nitro/og-image/templates/html.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { FontConfig, OgImageRenderEventContext } from '../../../types'
2-
import { theme } from '#nuxt-og-image/virtual/unocss-config.mjs'
2+
import { theme } from '#og-image-virtual/unocss-config.mjs'
33
import { renderSSRHead } from '@unhead/ssr'
44
import { createHeadCore } from '@unhead/vue'
55
import { createError } from 'h3'

‎src/runtime/nitro/plugins/prerender.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { defineNitroPlugin } from '#imports'
2-
import { prerenderOptionsCache } from '#nuxt-og-image-cache'
2+
import { prerenderOptionsCache } from '#og-image-cache'
33
import { parseURL } from 'ufo'
44
import { isInternalRoute } from '../../pure'
55
import { extractAndNormaliseOgImageOptions, resolvePathCacheKey } from '../og-image/context'

‎src/runtime/nitro/routes/debug.json.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @ts-expect-error virtual module
2-
import compatibility from '#nuxt-og-image/compatibility'
2+
import compatibility from '#og-image/compatibility'
33
// @ts-expect-error untyped
4-
import { componentNames } from '#nuxt-og-image-virtual/component-names.mjs'
4+
import { componentNames } from '#og-image-virtual/component-names.mjs'
55

66
import { defineEventHandler, setHeader } from 'h3'
77

‎src/runtime/nitro/util/options.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { DefineOgImageInput, OgImageOptions, OgImagePrebuilt } from '../../types'
22
// @ts-expect-error untyped
3-
import { componentNames } from '#nuxt-og-image-virtual/component-names.mjs'
3+
import { componentNames } from '#og-image-virtual/component-names.mjs'
44

55
export function normaliseOptions(_options: DefineOgImageInput): OgImageOptions | OgImagePrebuilt {
66
const options = { ..._options } as OgImageOptions

‎src/runtime/nuxt/components/Templates/Community/NuxtSeo.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
66
import { useSiteConfig } from '#imports'
7-
import { useOgImageRuntimeConfig } from '#nuxt-og-image/shared'
7+
import { useOgImageRuntimeConfig } from '#og-image/shared'
88
import { computed, defineComponent, h, resolveComponent } from 'vue'
99
1010
// convert to typescript props

‎src/runtime/nuxt/composables/defineOgImageComponent.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { OgImageComponents } from '#nuxt-og-image/components'
1+
import type { OgImageComponents } from '#og-image/components'
22
import type { ExtractComponentProps, OgImageOptions } from '../../types'
33
import { defineOgImage } from './defineOgImage'
44

‎src/runtime/nuxt/composables/mock.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { OgImageComponents } from '#nuxt-og-image/components'
1+
import type { OgImageComponents } from '#og-image/components'
22
import type { DefineOgImageInput, ExtractComponentProps, OgImageOptions, OgImagePageScreenshotOptions } from '../../types'
33

44
export function defineOgImage(_options: DefineOgImageInput = {}) {}

‎src/runtime/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { OgImageComponents } from '#nuxt-og-image/components'
1+
import type { OgImageComponents } from '#og-image/components'
22
import type { ResvgRenderOptions } from '@resvg/resvg-js'
33
import type { AllowedComponentProps, Component, ComponentCustomProps, VNodeProps } from '@vue/runtime-core'
44
import type { H3Error, H3Event } from 'h3'

‎test/fixtures/zero-runtime/components/OgImage/0.NuxtSeo.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
66
import { useSiteConfig } from '#imports'
7-
import { useOgImageRuntimeConfig } from '#nuxt-og-image/shared'
7+
import { useOgImageRuntimeConfig } from '#og-image/shared'
88
import { computed, defineComponent, h, resolveComponent } from 'vue'
99
1010
// convert to typescript props

‎virtual.d.ts

+13-14
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,64 @@
1-
declare module '#nuxt-og-image/components' {
1+
declare module '#og-image/components' {
22
import type { Component } from 'vue'
33

44
const components: Record<string, Component>
55
export default components
66
}
7-
declare module '#nuxt-og-image/renderers/satori' {
7+
declare module '#og-image/renderers/satori' {
88
import type Renderer from './src/runtime/types'
99

1010
const renderer: Renderer | { __unenv__: true } | undefined
1111
export default renderer
1212
}
13-
declare module '#nuxt-og-image/renderers/chromium' {
13+
declare module '#og-image/renderers/chromium' {
1414
import type Renderer from './src/runtime/types'
1515

1616
const renderer: Renderer | { __unenv__: true } | undefined
1717
export default renderer
1818
}
1919

20-
declare module '#nuxt-og-image/bindings/satori' {
20+
declare module '#og-image/bindings/satori' {
2121
const satori: typeof import('satori').satori
2222
export default satori
2323
}
2424

25-
declare module '#nuxt-og-image/bindings/resvg' {
25+
declare module '#og-image/bindings/resvg' {
2626
interface WasmResvg {
2727
initWasmPromise: Promise<void>
2828
Resvg: import('resvg').Resvg
2929
}
3030
const instance: WasmResvg
3131
export default instance
3232
}
33-
declare module '#nuxt-og-image/bindings/chromium' {
33+
declare module '#og-image/bindings/chromium' {
3434
export const createBrowser: () => Promise<Browser | void>
3535
}
3636

37-
declare module '#nuxt-og-image/bindings/css-inline' {
37+
declare module '#og-image/bindings/css-inline' {
3838
import type _CssInline from 'css-inline'
3939

4040
const cssInline: _CssInline
4141
export default cssInline
4242
}
4343

44-
declare module '#nuxt-og-image/bindings/sharp' {
44+
declare module '#og-image/bindings/sharp' {
4545
import type _sharp from 'sharp'
4646

4747
const sharp: _sharp
4848
export default sharp
4949
}
5050

51-
declare module '#nuxt-og-image-virtual/component-names.mjs' {
51+
declare module '#og-image-virtual/component-names.mjs' {
5252
const componentNames: string[]
5353
export default componentNames
5454
}
5555

56-
declare module '#nuxt-og-image-virtual/unocss-config.mjs' {
57-
const theme: Record<string, any>
58-
export default theme
56+
declare module '#og-image-virtual/unocss-config.mjs' {
57+
export const theme: Record<string, any>
5958
}
6059

61-
declare module '#nuxt-og-image-cache' {
62-
import type { OgImageOptions } from '#nuxt-og-image/types'
60+
declare module '#og-image-cache' {
61+
import type { OgImageOptions } from '#og-image/types'
6362
import type { Storage } from 'unstorage'
6463

6564
export const htmlPayloadCache: Storage<{ expiresAt: number, value: OgImageOptions }>

0 commit comments

Comments
 (0)
Please sign in to comment.