Skip to content

Commit

Permalink
Force trigger tracing og font file for nodejs runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Apr 25, 2023
1 parent f12aa35 commit 8bcc456
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/next/src/compiled/@vercel/og/index.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -18145,4 +18145,6 @@ export {
* Copyright © 2015 Gilmore Davidson under the MIT license: http://gilmoreorless.mit-license.org/
*/
/*! Copyright Twitter Inc. and other contributors. Licensed under MIT */
//# sourceMappingURL=index.node.js.map
//# sourceMappingURL=index.node.js.map
function __traceRequiredFiles() { fetch(new URL("./noto-sans-v27-latin-regular.ttf", import.meta.url)); }
__traceRequiredFiles;
16 changes: 16 additions & 0 deletions packages/next/taskfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,22 @@ export async function copy_vercel_og(task, opts) {
)
.target('src/compiled/@vercel/og')

const nodeSource = await fs.readFile(
join(
dirname(require.resolve('@vercel/og/package.json')),
'dist/index.node.js'
),
'utf8'
)
await fs.writeFile(
join(__dirname, 'src/compiled/@vercel/og/index.node.js'),
nodeSource +
`
function __traceRequiredFiles() { fetch(new URL("./noto-sans-v27-latin-regular.ttf", import.meta.url)); }
__traceRequiredFiles;
`
)

// Types are not bundled, include satori types here
await task
.source(
Expand Down
14 changes: 14 additions & 0 deletions test/e2e/app-dir/metadata-dynamic-routes/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,20 @@ createNextDescribe(
/\/\(group\)\/twitter-image-\w{6}\/\[\[\.\.\.__metadata_id__\]\]\/route/
)
})

it('should include default og font files in file trace', async () => {
const fileTrace = JSON.parse(
await next.readFile(
'.next/server/app/opengraph-image/[[...__metadata_id__]]/route.js.nft.json'
)
)

// @vercel/og default font should be traced
const isTraced = fileTrace.files.some((filePath) =>
/\/noto-sans-v27-latin-regular\.\w+\.ttf/.test(filePath)
)
expect(isTraced).toBe(true)
})
}
}
)

0 comments on commit 8bcc456

Please sign in to comment.