From 7e384c4cef90bc434695450f4f563b00622b6908 Mon Sep 17 00:00:00 2001 From: "moxey.eth" Date: Thu, 7 Mar 2024 13:39:10 +1100 Subject: [PATCH] revert --- src/index.ts | 71 ++++++++---------------------------------------- src/package.json | 1 - 2 files changed, 12 insertions(+), 60 deletions(-) diff --git a/src/index.ts b/src/index.ts index 69b8bbc..a82b478 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,69 +1,22 @@ -import type { ImageResponse as ImageResponseType } from "@vercel/og"; +import * as Og from "@vercel/og"; import { type HonoElement, toReactNode } from "./utils.js"; -// Determine what instance of the module to import based on the runtime -// (Next.js has it's own compiled version of @vercel/og). -function importModule(): Promise { - return import( - typeof process.env.NEXT_RUNTIME !== "undefined" - ? process.env.NEXT_RUNTIME === "edge" - ? "./next/dist/compiled/@vercel/og/index.edge.js" - : "./next/dist/compiled/@vercel/og/index.node.js" - : "@vercel/og" - ); -} +const pkg = Og; export type ImageResponseOptions = ConstructorParameters< - typeof ImageResponseType + typeof Og.ImageResponse >[1]; -export class ImageResponse extends Response { - public static displayName = "ImageResponse"; - constructor(element: HonoElement, options: ImageResponseOptions = {}) { - const readable = new ReadableStream({ - async start(controller) { - const OGImageResponse = (await importModule()).ImageResponse; - const imageResponse = new OGImageResponse( - toReactNode(element), - options, - ) as Response; - - if (!imageResponse.body) return controller.close(); - - const reader = imageResponse.body!.getReader(); - while (true) { - const { done, value } = await reader.read(); - if (done) { - return controller.close(); - } - controller.enqueue(value); - } - }, - }); - - super(readable, { - headers: { - "content-type": "image/png", - "cache-control": - process.env.NODE_ENV === "development" - ? "no-cache, no-store" - : "public, immutable, no-transform, max-age=31536000", - ...options.headers, - }, - status: options.status, - statusText: options.statusText, - }); +export class ImageResponse extends Og.ImageResponse { + constructor(element: HonoElement, options?: ImageResponseOptions) { + super(toReactNode(element), options); } } -export const unstable_createNodejsStream = async ( +export const unstable_createNodejsStream = ( element: HonoElement, - options?: Parameters< - typeof import("@vercel/og").unstable_createNodejsStream - >[1], -) => { - const mod = await importModule(); - return "unstable_createNodejsStream" in mod - ? mod.unstable_createNodejsStream(toReactNode(element), options) - : undefined; -}; + options?: Parameters[1], +) => + "unstable_createNodejsStream" in pkg + ? pkg.unstable_createNodejsStream(toReactNode(element), options) + : undefined; \ No newline at end of file diff --git a/src/package.json b/src/package.json index 091d428..41ca27f 100644 --- a/src/package.json +++ b/src/package.json @@ -22,7 +22,6 @@ "dependencies": { "@wevm/vercel-og": "~0.6.11", "@vercel/og": "~0.6.2", - "next": "^14.1.3", "workers-og": "~0.0.20" } }