Skip to content

Commit d0d2f4a

Browse files
committed
fix!: drop component support
1 parent 441e436 commit d0d2f4a

File tree

5 files changed

+102
-52
lines changed

5 files changed

+102
-52
lines changed

docs/content/4.api/3.components.md

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,14 @@
11
---
22
title: Components
3-
description: Components that are included with the module, including OgImage and OgImageScreenshot.
3+
description: The OgImage and OgImageScreenshot components have been removed in v6.
4+
deprecated: true
45
---
56

6-
## Introduction
7+
## Removed in v6
78

8-
It's recommended to use composables over components, as they are more flexible and will provide better type safety.
9+
The `<OgImage>` and `<OgImageScreenshot>` components have been removed. Use the composable equivalents instead:
910

10-
## `OgImage`
11+
- [`defineOgImage()`](/docs/og-image/api/define-og-image) — replaces `<OgImage>`
12+
- [`defineOgImageScreenshot()`](/docs/og-image/api/define-og-image-screenshot) — replaces `<OgImageScreenshot>`
1113

12-
Render a customisable OG Image.
13-
14-
Uses the [defineOgImage](/docs/og-image/api/define-og-image) composable.
15-
16-
```vue
17-
<template>
18-
<OgImage />
19-
</template>
20-
```
21-
22-
## `OgImageScreenshot`
23-
24-
Takes a screenshot of the page and uses it as the image.
25-
26-
Uses the [defineOgImageScreenshot](/docs/og-image/api/define-og-image-screenshot) composable.
27-
28-
```vue
29-
<template>
30-
<OgImageScreenshot />
31-
</template>
32-
```
14+
See the [v6 migration guide](/docs/og-image/migration-guide/v6) for details.

docs/content/6.migration-guide/v6.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,44 @@ Install @nuxt/fonts (only needed for custom fonts):
167167
npx nuxi module add @nuxt/fonts
168168
```
169169

170+
### `<OgImage>` and `<OgImageScreenshot>` Components Removed
171+
172+
The `<OgImage>` and `<OgImageScreenshot>` Vue components have been removed. Use the equivalent composables instead:
173+
174+
```diff
175+
- <template>
176+
- <OgImage />
177+
- </template>
178+
179+
+ <script setup>
180+
+ defineOgImage()
181+
+ </script>
182+
```
183+
184+
```diff
185+
- <template>
186+
- <OgImageScreenshot />
187+
- </template>
188+
189+
+ <script setup>
190+
+ defineOgImageScreenshot()
191+
+ </script>
192+
```
193+
194+
The migration CLI handles this automatically.
195+
196+
### `componentOptions` Config Removed
197+
198+
The `ogImage.componentOptions` config option has been removed as there are no longer any components to configure.
199+
200+
```diff
201+
export default defineNuxtConfig({
202+
ogImage: {
203+
- componentOptions: { global: true },
204+
}
205+
})
206+
```
207+
170208
### `defineOgImageComponent` Deprecated
171209

172210
The `defineOgImageComponent()` composable is deprecated. Use `defineOgImage()` with the component name as the first argument.

src/cli.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,24 @@ async function checkMigrationNeeded(rootDir: string): Promise<MigrationCheck> {
228228
return result
229229
}
230230

231+
// Convert Vue template attrs like `title="Hello" :width="1200"` to a JS object string
232+
function attrsToProps(attrs: string): string {
233+
if (!attrs)
234+
return ''
235+
const props: string[] = []
236+
// Match :prop="expr" or prop="value" or prop (boolean)
237+
const attrRegex = /:(\w+)="([^"]*)"|(\w+)="([^"]*)"|(\w+)/g
238+
for (const m of attrs.matchAll(attrRegex)) {
239+
if (m[1]) // dynamic :prop="expr"
240+
props.push(`${m[1]}: ${m[2]}`)
241+
else if (m[3]) // static prop="value"
242+
props.push(`${m[3]}: '${m[4]}'`)
243+
else if (m[5]) // boolean prop
244+
props.push(`${m[5]}: true`)
245+
}
246+
return props.length ? `{ ${props.join(', ')} }` : ''
247+
}
248+
231249
// Migrate defineOgImage API
232250
function migrateDefineOgImageApi(dryRun: boolean): { changes: Array<{ file: string, count: number }> } {
233251
const cwd = process.cwd()
@@ -241,6 +259,42 @@ function migrateDefineOgImageApi(dryRun: boolean): { changes: Array<{ file: stri
241259
let modified = false
242260
let changeCount = 0
243261

262+
// Pattern 0: <OgImageScreenshot /> and <OgImage /> component usage → composable
263+
// Handles self-closing and open/close tags, with or without props
264+
content = content.replace(/<OgImageScreenshot([^>]*?)\/>/g, (_match, attrs: string) => {
265+
modified = true
266+
changeCount++
267+
const propsStr = attrsToProps(attrs.trim())
268+
return propsStr
269+
? `<!-- Migrated: use defineOgImageScreenshot(${propsStr}) in <script setup> -->`
270+
: `<!-- Migrated: use defineOgImageScreenshot() in <script setup> -->`
271+
})
272+
content = content.replace(/<OgImageScreenshot([^>]*)>[\s\S]*?<\/OgImageScreenshot>/g, (_match, attrs: string) => {
273+
modified = true
274+
changeCount++
275+
const propsStr = attrsToProps(attrs.trim())
276+
return propsStr
277+
? `<!-- Migrated: use defineOgImageScreenshot(${propsStr}) in <script setup> -->`
278+
: `<!-- Migrated: use defineOgImageScreenshot() in <script setup> -->`
279+
})
280+
// OgImage but not OgImageScreenshot (use word boundary via negative lookahead)
281+
content = content.replace(/<OgImage(?!Screenshot)([^>]*?)\/>/g, (_match, attrs: string) => {
282+
modified = true
283+
changeCount++
284+
const propsStr = attrsToProps(attrs.trim())
285+
return propsStr
286+
? `<!-- Migrated: use defineOgImage(${propsStr}) in <script setup> -->`
287+
: `<!-- Migrated: use defineOgImage() in <script setup> -->`
288+
})
289+
content = content.replace(/<OgImage(?!Screenshot)([^>]*)>[\s\S]*?<\/OgImage>/g, (_match, attrs: string) => {
290+
modified = true
291+
changeCount++
292+
const propsStr = attrsToProps(attrs.trim())
293+
return propsStr
294+
? `<!-- Migrated: use defineOgImage(${propsStr}) in <script setup> -->`
295+
: `<!-- Migrated: use defineOgImage() in <script setup> -->`
296+
})
297+
244298
// Pattern 1: defineOgImageComponent → defineOgImage
245299
if (/defineOgImageComponent\s*\(/.test(content)) {
246300
content = content.replace(/defineOgImageComponent\s*\(/g, 'defineOgImage(')
@@ -430,6 +484,7 @@ async function runMigrate(args: string[]): Promise<void> {
430484
if (migrationCheck.needsNuxtFonts) {
431485
tasks.push('Install @nuxt/fonts module')
432486
}
487+
tasks.push('Migrate <OgImage> and <OgImageScreenshot> components to composables')
433488
tasks.push('Update defineOgImage() calls to new API')
434489

435490
p.note(tasks.map(t => `• ${t}`).join('\n'), 'Migration tasks')

src/module.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { AddComponentOptions } from '@nuxt/kit'
21
import type { Nuxt } from '@nuxt/schema'
32
import type { ResvgRenderOptions } from '@resvg/resvg-js'
43
import type { SatoriOptions } from 'satori'
@@ -17,7 +16,7 @@ import type {
1716
import * as fs from 'node:fs'
1817
import { existsSync } from 'node:fs'
1918
import { readFile } from 'node:fs/promises'
20-
import { addBuildPlugin, addComponent, addComponentsDir, addImports, addPlugin, addServerHandler, addServerPlugin, addTemplate, addVitePlugin, createResolver, defineNuxtModule, getNuxtModuleVersion, hasNuxtModule, hasNuxtModuleCompatibility, updateTemplates } from '@nuxt/kit'
19+
import { addBuildPlugin, addComponentsDir, addImports, addPlugin, addServerHandler, addServerPlugin, addTemplate, addVitePlugin, createResolver, defineNuxtModule, getNuxtModuleVersion, hasNuxtModule, hasNuxtModuleCompatibility, updateTemplates } from '@nuxt/kit'
2120
import { defu } from 'defu'
2221
import { installNuxtSiteConfig } from 'nuxt-site-config/kit'
2322
import { hash } from 'ohash'
@@ -98,10 +97,6 @@ export interface ModuleOptions {
9897
* @false false
9998
*/
10099
debug: boolean
101-
/**
102-
* Options to pass to the <OgImage> and <OgImageScreenshot> component.
103-
*/
104-
componentOptions?: Pick<AddComponentOptions, 'global'>
105100
/**
106101
* Configure the runtime cache storage for generated OG images.
107102
* - `true` - Use Nitro's default cache storage (default)
@@ -737,12 +732,6 @@ export default defineNuxtModule<ModuleOptions>({
737732
}
738733
})
739734

740-
addComponent({
741-
name: 'OgImageScreenshot',
742-
filePath: resolve(`./runtime/app/components/OgImage/OgImageScreenshot`),
743-
...config.componentOptions,
744-
})
745-
746735
const basePluginPath = `./runtime/app/plugins${config.zeroRuntime ? '/__zero-runtime' : ''}`
747736
// allows us to add og images using route rules without calling defineOgImage
748737
addPlugin({ mode: 'server', src: resolve(`${basePluginPath}/route-rule-og-image.server`) })
@@ -914,7 +903,7 @@ export default defineNuxtModule<ModuleOptions>({
914903
valid = true
915904

916905
if (valid && fs.existsSync(component.filePath)) {
917-
// Only validate .vue files - non-vue files (like OgImageScreenshot.ts) are runtime components, not templates
906+
// Only validate .vue files - non-vue files are runtime components, not templates
918907
if (!component.filePath.endsWith('.vue'))
919908
return
920909

src/runtime/app/components/OgImage/OgImageScreenshot.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)