Skip to content

Commit b5083d6

Browse files
committed
sigh, use @vercel/og or next/og conditionally based on version
1 parent 090185c commit b5083d6

File tree

12 files changed

+69
-14
lines changed

12 files changed

+69
-14
lines changed

tests/fixtures/wasm-src/next.config.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,28 @@ module.exports = {
2828
ignoreDuringBuilds: true,
2929
},
3030
outputFileTracingRoot: __dirname,
31+
32+
// there is no single way to use `next/og` or `@vercel/og` depending on Next.js version
33+
// - next@<14 doesn't have 'next/og' export
34+
// - next turbopack builds doesn't work with `@vercel/og`
35+
// so this adds `next-og-alias` alias depending on next version for both webpack and turbopack
36+
// so we can test this in all the versions
37+
webpack: (config) => {
38+
const hasNextOg = !satisfies(require('next/package.json').version, '<14.0.0', {
39+
includePrerelease: true,
40+
})
41+
42+
if (!hasNextOg) {
43+
config.resolve.alias['next-og-alias$'] = '@vercel/og'
44+
} else {
45+
config.resolve.alias['next-og-alias$'] = 'next/og'
46+
}
47+
48+
return config
49+
},
50+
turbopack: {
51+
resolveAlias: {
52+
'next-og-alias': 'next/og',
53+
},
54+
},
3155
}

tests/fixtures/wasm-src/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"@vercel/og": "latest",
1212
"next": "latest",
1313
"react": "18.2.0",
14-
"react-dom": "18.2.0"
14+
"react-dom": "18.2.0",
15+
"semver": "^7.7.2"
1516
}
1617
}

tests/fixtures/wasm-src/src/app/og-node/route.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { ImageResponse } from '@vercel/og'
1+
// see next.config for details about 'next-og-alias'
2+
import { ImageResponse } from 'next-og-alias'
23

34
export async function GET() {
45
return new ImageResponse(<div>hi</div>, {

tests/fixtures/wasm-src/src/app/og/route.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { ImageResponse } from '@vercel/og'
1+
// see next.config for details about 'next-og-alias'
2+
import { ImageResponse } from 'next-og-alias'
23

34
export async function GET() {
45
return new ImageResponse(<div>hi</div>, {

tests/fixtures/wasm-src/src/pages/api/og-wrong-runtime.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// /pages/api/og.jsx
2-
import { ImageResponse } from '@vercel/og'
1+
// see next.config for details about 'next-og-alias'
2+
import { ImageResponse } from 'next-og-alias'
33

44
export default function () {
55
return new ImageResponse(

tests/fixtures/wasm-src/src/pages/api/og.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// /pages/api/og.jsx
2-
import { ImageResponse } from '@vercel/og'
1+
// see next.config for details about 'next-og-alias'
2+
import { ImageResponse } from 'next-og-alias'
33

44
export const config = {
55
runtime: 'edge',

tests/fixtures/wasm/app/og-node/route.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { ImageResponse } from '@vercel/og'
1+
// see next.config for details about 'next-og-alias'
2+
import { ImageResponse } from 'next-og-alias'
23

34
export async function GET() {
45
return new ImageResponse(<div>hi</div>, {

tests/fixtures/wasm/app/og/route.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { ImageResponse } from '@vercel/og'
1+
// see next.config for details about 'next-og-alias'
2+
import { ImageResponse } from 'next-og-alias'
23

34
export async function GET() {
45
return new ImageResponse(<div>hi</div>, {

tests/fixtures/wasm/next.config.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const { platform } = require('process')
22
const fsPromises = require('fs/promises')
3+
const { satisfies } = require('semver')
34

45
// Next.js uses `fs.promises.copyFile` to copy files from `.next`to the `.next/standalone` directory
56
// It tries copying the same file twice in parallel. Unix is fine with that, but Windows fails
@@ -28,4 +29,28 @@ module.exports = {
2829
ignoreDuringBuilds: true,
2930
},
3031
outputFileTracingRoot: __dirname,
32+
outputFileTracingRoot: __dirname,
33+
// there is no single way to use `next/og` or `@vercel/og` depending on Next.js version
34+
// - next@<14 doesn't have 'next/og' export
35+
// - next turbopack builds doesn't work with `@vercel/og`
36+
// so this adds `next-og-alias` alias depending on next version for both webpack and turbopack
37+
// so we can test this in all the versions
38+
webpack: (config) => {
39+
const hasNextOg = !satisfies(require('next/package.json').version, '<14.0.0', {
40+
includePrerelease: true,
41+
})
42+
43+
if (!hasNextOg) {
44+
config.resolve.alias['next-og-alias$'] = '@vercel/og'
45+
} else {
46+
config.resolve.alias['next-og-alias$'] = 'next/og'
47+
}
48+
49+
return config
50+
},
51+
turbopack: {
52+
resolveAlias: {
53+
'next-og-alias': 'next/og',
54+
},
55+
},
3156
}

tests/fixtures/wasm/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"@vercel/og": "latest",
1212
"next": "latest",
1313
"react": "18.2.0",
14-
"react-dom": "18.2.0"
14+
"react-dom": "18.2.0",
15+
"semver": "^7.7.2"
1516
}
1617
}

0 commit comments

Comments
 (0)