Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

Move og utils to a shared package (#1545)

Sean Boult079861179432
diff --git a/apps/aot/package.json b/apps/aot/package.json
index f7bda73f..297225dc 100644
--- a/apps/aot/package.json
+++ b/apps/aot/package.json
@@ -34,7 +34,7 @@
"@repo/db": "workspace:*",
"@repo/lint": "workspace:*",
"@repo/monaco": "workspace:*",
- "@repo/og-image": "workspace:*",
+ "@repo/og-utils": "workspace:*",
"@repo/tsconfig": "workspace:*",
"@repo/ui": "workspace:*",
"@tailwindcss/container-queries": "^0.1.1",
diff --git a/apps/og-image/app/api/aot-2023/route.tsx b/apps/og-image/app/api/aot-2023/route.tsx
index 57d01a6f..36df8e27 100644
--- a/apps/og-image/app/api/aot-2023/route.tsx
+++ b/apps/og-image/app/api/aot-2023/route.tsx
@@ -1,23 +1,20 @@
-import { ImageResponse } from '@vercel/og';
-// import { fetchFont } from 'utils/fetchFont';
-export const runtime = 'edge';
+import { ImageResponse } from "@vercel/og";
+
+export const runtime = "edge";
export async function GET() {
- // const [inter700] = await Promise.all([fetchFont('Inter', 700)]);
return new ImageResponse(
- (
- <div tw="relative flex flex-col">
- <img
- src="https://utfs.io/f/7d4db93c-176d-4f25-b82d-8517f6bd053c-5juvoi.png"
- tw="w-full"
- alt="gg"
- />
- <div tw="absolute font-semibold flex-grow h-full text-5xl text-red-600 flex w-full justify-end">
- {/* //Todo: Can change to other status programmatically or hardcoded */}
- {/* <div tw="absolute bottom-0 p-5 px-10">Coming December 1st</div> */}
- </div>
+ <div tw="relative flex flex-col">
+ <img
+ src="https://utfs.io/f/7d4db93c-176d-4f25-b82d-8517f6bd053c-5juvoi.png"
+ tw="w-full"
+ alt="gg"
+ />
+ <div tw="absolute font-semibold flex-grow h-full text-5xl text-red-600 flex w-full justify-end">
+ {/* //Todo: Can change to other status programmatically or hardcoded */}
+ {/* <div tw="absolute bottom-0 p-5 px-10">Coming December 1st</div> */}
</div>
- ),
+ </div>,
{
width: 1200,
height: 630,
diff --git a/apps/og-image/app/api/challenge/route.tsx b/apps/og-image/app/api/challenge/route.tsx
index 45910ba5..caffa847 100644
--- a/apps/og-image/app/api/challenge/route.tsx
+++ b/apps/og-image/app/api/challenge/route.tsx
@@ -1,6 +1,5 @@
import { ImageResponse } from '@vercel/og';
-import { challengeParam } from 'utils/zodParams';
-import { fetchFont } from 'utils/fetchFont';
+import { fetchFont, challengeParam } from '@repo/og-utils';
import { Logo3d } from 'app/components/logo3d';
import { Grid } from 'app/components/grid';
@@ -53,7 +52,7 @@ export async function GET(req: Request) {
const random_mogus_coord = mogus_coords[Math.floor(Math.random() * mogus_coords.length)] ?? '';
let title = props.title === null ? null : props.title.split(' | ')[0]?.trim();
if (title && title?.length > 45) {
- title = title.slice(0, 40) + '…';
+ title = `${title.slice(0, 40) }…`;
}
const HOST =
diff --git a/apps/og-image/app/api/font/route.tsx b/apps/og-image/app/api/font/route.tsx
index 1641db1c..b41b0bef 100644
--- a/apps/og-image/app/api/font/route.tsx
+++ b/apps/og-image/app/api/font/route.tsx
@@ -3,7 +3,7 @@
* @link https://github.com/vercel/satori/blob/main/playground/pages/api/font.ts
*/
import type { NextRequest } from 'next/server';
-import { fontParams } from 'utils/zodParams';
+import { fontParams } from '@repo/og-utils';
export const runtime = 'edge';
diff --git a/apps/og-image/app/api/user/route.tsx b/apps/og-image/app/api/user/route.tsx
index 4cd2d68f..21ae5bd2 100644
--- a/apps/og-image/app/api/user/route.tsx
+++ b/apps/og-image/app/api/user/route.tsx
@@ -1,6 +1,5 @@
import { ImageResponse } from '@vercel/og';
-import { userParam } from 'utils/zodParams';
-import { fetchFont } from 'utils/fetchFont';
+import { fetchFont, userParam } from '@repo/og-utils';
import { Grid } from 'app/components/grid';
import { Logo } from 'app/components/logo';
diff --git a/apps/og-image/app/page.tsx b/apps/og-image/app/page.tsx
index 49764d75..f34ce890 100644
--- a/apps/og-image/app/page.tsx
+++ b/apps/og-image/app/page.tsx
@@ -1,9 +1,10 @@
+/* eslint-disable eslint-comments/disable-enable-pair */
/* eslint-disable @next/next/no-img-element */
'use client';
import Head from 'next/head';
import { useEffect, useState } from 'react';
-import { challengeParam, userParam } from 'utils/zodParams';
+import { challengeParam, userParam } from '@repo/og-utils';
import './app.css';
const ogImageUrl = process.env.VERCEL_URL ? `https://${process.env.VERCEL_URL}/api/landing` : '';
diff --git a/apps/og-image/next.config.js b/apps/og-image/next.config.js
index edf4f1df..c39c8200 100644
--- a/apps/og-image/next.config.js
+++ b/apps/og-image/next.config.js
@@ -4,7 +4,7 @@ const config = {
typescript: {
ignoreBuildErrors: false,
},
-
+ transpilePackages: ["@repo/og-utils"],
eslint: {
ignoreDuringBuilds: true,
},
diff --git a/apps/og-image/package.json b/apps/og-image/package.json
index 348c8333..68edc745 100644
--- a/apps/og-image/package.json
+++ b/apps/og-image/package.json
@@ -2,19 +2,6 @@
"name": "@repo/og-image",
"private": true,
"type": "module",
- "exports": {
- ".": "./utils/zodParams.ts"
- },
- "typesVersions": {
- "*": {
- "*": [
- "./utils/zodParams.ts"
- ],
- "types": [
- "./utils/zodParams.ts"
- ]
- }
- },
"scripts": {
"build": "next build",
"dev": "next dev --turbo -p 4200",
@@ -24,11 +11,11 @@
"@vercel/og": "^1.0.0",
"next": "14.2.5",
"react": "18.2.0",
- "react-dom": "18.2.0",
- "zod": "3.23.3"
+ "react-dom": "18.2.0"
},
"devDependencies": {
"@repo/lint": "workspace:*",
+ "@repo/og-utils": "workspace:*",
"@repo/tsconfig": "workspace:*",
"@types/node": "^20.4.2",
"@types/react": "^18.2.20",
diff --git a/apps/web/package.json b/apps/web/package.json
index 193b1e2b..81c8baa0 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -31,7 +31,7 @@
"@repo/db": "workspace:*",
"@repo/lint": "workspace:*",
"@repo/monaco": "workspace:*",
- "@repo/og-image": "workspace:*",
+ "@repo/og-utils": "workspace:*",
"@repo/ui": "workspace:*",
"@sentry/nextjs": "^7.73.0",
"@t3-oss/env-nextjs": "^0.6.0",
diff --git a/apps/web/src/app/metadata.ts b/apps/web/src/app/metadata.ts
index fef49f8c..d5d85df3 100644
--- a/apps/web/src/app/metadata.ts
+++ b/apps/web/src/app/metadata.ts
@@ -1,5 +1,5 @@
import type { Metadata } from 'next';
-import { challengeParam, userParam } from '@repo/og-image';
+import { challengeParam, userParam } from '@repo/og-utils';
export const OG_URL =
process.env.NODE_ENV !== 'production' ? 'http://localhost:4200' : 'https://og.typehero.dev';
diff --git a/packages/og-utils/.eslintrc.js b/packages/og-utils/.eslintrc.js
new file mode 100644
index 00000000..6c5b786f
--- /dev/null
+++ b/packages/og-utils/.eslintrc.js
@@ -0,0 +1,8 @@
+/** @type {import("eslint").Linter.Config} */
+module.exports = {
+ root: true,
+ extends: [require.resolve('@repo/lint/node')],
+ parserOptions: {
+ project: `${__dirname}/tsconfig.json`,
+ },
+};
diff --git a/packages/og-utils/package.json b/packages/og-utils/package.json
new file mode 100644
index 00000000..f514393b
--- /dev/null
+++ b/packages/og-utils/package.json
@@ -0,0 +1,33 @@
+{
+ "name": "@repo/og-utils",
+ "version": "0.0.0",
+ "private": true,
+ "exports": {
+ ".": "./src/index.ts"
+ },
+ "typesVersions": {
+ "*": {
+ "*": [
+ "./src/index.ts"
+ ]
+ }
+ },
+ "scripts": {
+ "clean": "rm -rf .next dist node_modules",
+ "format": "prettier . --check --cache --cache-location=\"node_modules/.cache/prettiercache\"",
+ "format:fix": "prettier . --write --cache --cache-location=\"node_modules/.cache/prettiercache\" --log-level=warn",
+ "lint": "eslint . --cache --cache-location \"node_modules/.cache/.eslintcache\" --max-warnings 0",
+ "lint:fix": "eslint . --fix --cache --cache-location \"node_modules/.cache/.eslintcache\" --max-warnings 0",
+ "typecheck": "tsc --noEmit"
+ },
+ "devDependencies": {
+ "@repo/lint": "workspace:*",
+ "@repo/tsconfig": "workspace:*",
+ "@types/node": "^20.4.2",
+ "eslint": "^8.45.0",
+ "typescript": "^5.3.3"
+ },
+ "dependencies": {
+ "zod": "3.23.3"
+ }
+}
diff --git a/apps/og-image/utils/fetchFont.ts b/packages/og-utils/src/fetchFont.ts
similarity index 100%
rename from apps/og-image/utils/fetchFont.ts
rename to packages/og-utils/src/fetchFont.ts
diff --git a/packages/og-utils/src/index.ts b/packages/og-utils/src/index.ts
new file mode 100644
index 00000000..00bc21ff
--- /dev/null
+++ b/packages/og-utils/src/index.ts
@@ -0,0 +1,2 @@
+export * from './fetchFont';
+export * from './zodParams';
diff --git a/apps/og-image/utils/zodParams.ts b/packages/og-utils/src/zodParams.ts
similarity index 98%
rename from apps/og-image/utils/zodParams.ts
rename to packages/og-utils/src/zodParams.ts
index 49f45d22..d6979e88 100644
--- a/apps/og-image/utils/zodParams.ts
+++ b/packages/og-utils/src/zodParams.ts
@@ -64,6 +64,6 @@ export const userParam = zodParams(
z.object({
username: truncatedWordSchema({ maxCharacters: 70 }),
avatar: z.string().optional(),
- dateSince: z.string()
+ dateSince: z.string(),
}),
);
diff --git a/packages/og-utils/tsconfig.json b/packages/og-utils/tsconfig.json
new file mode 100644
index 00000000..e29a5ed3
--- /dev/null
+++ b/packages/og-utils/tsconfig.json
@@ -0,0 +1,8 @@
+{
+ "extends": "@repo/tsconfig/base.json",
+ "compilerOptions": {
+ "tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json"
+ },
+ "include": ["src/**/*.ts"],
+ "exclude": ["node_modules"]
+}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 8da34d80..4b432a53 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -91,10 +91,10 @@ importers:
version: 2.6.0-beta.12
next:
specifier: 14.2.5
next-themes:
specifier: ^0.2.1
react:
specifier: 18.2.0
version: 18.2.0
@@ -158,7 +158,7 @@ importers:
eslint-plugin-import:
specifier: ^2.27.5
+ version: 2.27.5([email protected])
postcss:
specifier: ^8.4.31
version: 8.4.31
@@ -197,10 +197,10 @@ importers:
version: 2.0.0
next:
specifier: 14.2.5
next-themes:
specifier: ^0.2.1
react:
specifier: 18.2.0
version: 18.2.0
@@ -229,9 +229,9 @@ importers:
'@repo/monaco':
specifier: workspace:*
version: link:../../packages/monaco
- '@repo/og-image':
+ '@repo/og-utils':
specifier: workspace:*
- version: link:../og-image
+ version: link:../../packages/og-utils
'@repo/tsconfig':
specifier: workspace:*
version: link:../../tooling/config-typescript
@@ -307,20 +307,20 @@ importers:
version: 1.0.0
next:
specifier: 14.2.5
react:
specifier: 18.2.0
version: 18.2.0
react-dom:
specifier: 18.2.0
version: 18.2.0([email protected])
- zod:
- specifier: 3.23.3
- version: 3.23.3
devDependencies:
'@repo/lint':
specifier: workspace:*
version: link:../../tooling/config-eslint
+ '@repo/og-utils':
+ specifier: workspace:*
+ version: link:../../packages/og-utils
'@repo/tsconfig':
specifier: workspace:*
version: link:../../tooling/config-typescript
@@ -375,15 +375,15 @@ importers:
'@repo/monaco':
specifier: workspace:*
version: link:../../packages/monaco
- '@repo/og-image':
+ '@repo/og-utils':
specifier: workspace:*
- version: link:../og-image
+ version: link:../../packages/og-utils
'@repo/ui':
specifier: workspace:*
version: link:../../packages/ui
'@sentry/nextjs':
specifier: ^7.73.0
'@t3-oss/env-nextjs':
specifier: ^0.6.0
@@ -401,7 +401,7 @@ importers:
'@uploadthing/react':
specifier: ^6.2.2
'@vercel/analytics':
specifier: ^1.1.1
version: 1.1.1
@@ -410,10 +410,10 @@ importers:
version: 0.2.1
'@vercel/speed-insights':
specifier: ^1.0.12
'@vercel/toolbar':
specifier: ^0.1.18
algoliasearch:
specifier: ^4.20.0
version: 4.20.0
@@ -449,10 +449,10 @@ importers:
version: 5.0.7
next:
specifier: 14.2.5
next-themes:
specifier: ^0.2.1
react:
specifier: 18.2.0
version: 18.2.0
@@ -476,7 +476,7 @@ importers:
react-instantsearch-nextjs:
specifier: ^0.1.5
react-intersection-observer:
specifier: ^9.5.2
version: 9.5.2([email protected])
@@ -564,7 +564,7 @@ importers:
eslint-plugin-import:
specifier: ^2.27.5
+ version: 2.27.5([email protected])
postcss:
specifier: ^8.4.31
version: 8.4.31
@@ -725,6 +725,28 @@ importers:
specifier: ^5.3.3
version: 5.3.3
+ packages/og-utils:
+ dependencies:
+ zod:
+ specifier: 3.23.3
+ version: 3.23.3
+ devDependencies:
+ '@repo/lint':
+ specifier: workspace:*
+ version: link:../../tooling/config-eslint
+ '@repo/tsconfig':
+ specifier: workspace:*
+ version: link:../../tooling/config-typescript
+ '@types/node':
+ specifier: ^20.4.2
+ version: 20.10.4
+ eslint:
+ specifier: ^8.45.0
+ version: 8.56.0
+ typescript:
+ specifier: ^5.3.3
+ version: 5.3.3
+
packages/ui:
dependencies:
'@radix-ui/react-alert-dialog':
@@ -859,7 +881,7 @@ importers:
dependencies:
'@next/eslint-plugin-next':
specifier: canary
- version: 15.0.0-canary.138
+ version: 15.0.0-canary.139
'@repo/tsconfig':
specifier: workspace:*
version: link:../config-typescript
@@ -871,7 +893,7 @@ importers:
'@vercel/style-guide':
specifier: ^4.0.2
eslint:
specifier: ^8.45.0
version: 8.45.0
@@ -1953,8 +1975,8 @@ packages:
resolution: {integrity: sha512-YJqyq6vk39JQfvaNtN83t/p5Jy45+bazRL+V4QI8FPd3FBqFYMEsULiwRLgSJMgFqkk4t4JbeZurz+gILEAFpA==}
- resolution: {integrity: sha512-yvipz4UdJ/FSnyTxqMaHMHERh27VrweuuxS/xiLXQ7oc5OfiyEtJvhWN1M5jptl8A6c8j+9bu9mv8IvI5qoJhQ==}
+ resolution: {integrity: sha512-ghqijxdELk+ngJQ5px60Z74RrstkYOwEyDcf9JK+IwHDij6KJ9V5dhKuqU6C5PwpzPj/gdtPC8j27MbJ+s59/g==}
resolution: {integrity: sha512-/9zVxJ+K9lrzSGli1///ujyRfon/ZneeZ+v4ptpiPoOU+GKZnm8Wj8ELWU1Pm7GHltYRBklmXMTUqM/DqQ99FQ==}
@@ -9235,7 +9257,7 @@ snapshots:
dependencies:
glob: 7.1.7
dependencies:
fast-glob: 3.3.1
@@ -10662,7 +10684,7 @@ snapshots:
localforage: 1.10.0
tslib: 2.6.0
dependencies:
'@rollup/plugin-commonjs': 24.0.0([email protected])
'@sentry/core': 7.73.0
@@ -10674,7 +10696,7 @@ snapshots:
'@sentry/vercel-edge': 7.73.0
'@sentry/webpack-plugin': 1.20.0
chalk: 3.0.0
react: 18.2.0
rollup: 2.78.0
stacktrace-parser: 0.1.10
@@ -11176,7 +11198,7 @@ snapshots:
'@uploadthing/[email protected]': {}
dependencies:
'@uploadthing/dropzone': 0.1.1
'@uploadthing/shared': 6.2.0(@uploadthing/[email protected])
@@ -11186,7 +11208,7 @@ snapshots:
tailwind-merge: 1.14.0
uploadthing: 6.3.1
optionalDependencies:
transitivePeerDependencies:
- '@uploadthing/mime-types'
@@ -11229,12 +11251,12 @@ snapshots:
satori: 0.0.46
yoga-wasm-web: 0.3.0
optionalDependencies:
react: 18.2.0
dependencies:
'@babel/core': 7.22.10
'@babel/eslint-parser': 7.22.10(@babel/[email protected])([email protected])
@@ -11256,7 +11278,7 @@ snapshots:
eslint-plugin-unicorn: 43.0.2([email protected])
prettier-plugin-packagejson: 2.4.3([email protected])
optionalDependencies:
- '@next/eslint-plugin-next': 15.0.0-canary.138
+ '@next/eslint-plugin-next': 15.0.0-canary.139
eslint: 8.45.0
prettier: 3.1.1
typescript: 5.3.3
@@ -11266,7 +11288,7 @@ snapshots:
- jest
- supports-color
dependencies:
'@tinyhttp/app': 1.3.0
chokidar: 3.5.3
@@ -11275,7 +11297,7 @@ snapshots:
get-port: 5.1.1
strip-ansi: 6.0.1
optionalDependencies:
react: 18.2.0
'@vitest/[email protected]':
@@ -12736,7 +12758,7 @@ snapshots:
doctrine: 2.1.0
eslint: 8.45.0
eslint-import-resolver-node: 0.3.7
has: 1.0.3
is-core-module: 2.12.1
is-glob: 4.0.3
@@ -14619,15 +14641,15 @@ snapshots:
react: 18.3.1
dependencies:
react: 18.2.0
react-dom: 18.2.0([email protected])
dependencies:
react: 18.2.0
react-dom: 18.2.0([email protected])
@@ -14637,7 +14659,7 @@ snapshots:
react: 18.2.0
react-dom: 18.3.1([email protected])
dependencies:
'@next/env': 14.2.5
'@swc/helpers': 0.5.5
@@ -14658,12 +14680,11 @@ snapshots:
'@next/swc-win32-arm64-msvc': 14.2.5
'@next/swc-win32-ia32-msvc': 14.2.5
'@next/swc-win32-x64-msvc': 14.2.5
- '@playwright/test': 1.38.0
transitivePeerDependencies:
- '@babel/core'
- babel-plugin-macros
dependencies:
'@next/env': 14.2.5
'@swc/helpers': 0.5.5
@@ -14684,6 +14705,7 @@ snapshots:
'@next/swc-win32-arm64-msvc': 14.2.5
'@next/swc-win32-ia32-msvc': 14.2.5
'@next/swc-win32-x64-msvc': 14.2.5
+ '@playwright/test': 1.38.0
transitivePeerDependencies:
- '@babel/core'
- babel-plugin-macros
@@ -15335,9 +15357,9 @@ snapshots:
react: 18.2.0
use-sync-external-store: 1.2.0([email protected])
dependencies: