Skip to content

feat: vercel support #637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: graphite-base/637
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,4 @@ dist
**/.wrangler
**/.DS_Store
.aider*
**/tsup.config.bundled*
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
"build": "npx turbo build",
"check-types": "npx turbo check-types",
"fmt": "yarn biome check --write .",
"dev-docs": "cd docs && yarn dlx mintlify@latest dev",
"dev-docs-middleware": "cd packages/misc/docs-middleware && yarn dev",
"deploy-docs-middleware": "cd packages/misc/docs-middleware && yarn deploy",
"docs-broken-links": "cd docs && yarn dlx mintlify@latest broken-links",
"docs-bump": "git checkout main && git pull --ff && date > docs/.bump && git add docs/.bump && git commit -m \"chore: bump mintlify\" && git push origin main"
"docs:dev": "cd docs && yarn dlx mintlify@latest dev",
"docs:broken-links": "cd docs && yarn dlx mintlify@latest broken-links",
"docs:bump": "git checkout main && git pull --ff && date > docs/.bump && git add docs/.bump && git commit -m \"chore: bump mintlify\" && git push origin main",
"docs-middleware:dev": "cd packages/misc/docs-middleware && yarn dev",
"docs-middleware:deploy": "cd packages/misc/docs-middleware && yarn deploy",
"examples:template": "tsx scripts/template-platforms.ts"
},
"devDependencies": {
"@biomejs/biome": "^1.9.4",
Expand Down
75 changes: 39 additions & 36 deletions packages/actor-core-cli/src/utils/platforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,41 +59,44 @@ const PLATFORMS = {

// return { files };
// },
// vercel: ({ files, version, pkgJson, actorImports, actorMap }) => {
// files["package.json"] = stringifyJson({
// ...pkgJson,
// scripts: {
// ...pkgJson.scripts,
// dev: "next dev",
// build: "next build",
// start: "next start",
// },
// devDependencies: {
// "@actor-core/vercel": version,
// next: "^14.0.0",
// ...pkgJson.devDependencies,
// },
// });

// files["src/api/actor/route.ts"] = dedent`
// import { createHandler } from "@actor-core/vercel"
// ${actorImports("./src/api/actor/route.ts")}

// const handler = createHandler({
// actors: { ${actorMap} }
// });

// export const GET = handler.GET;
// export const POST = handler.POST;
// export const PUT = handler.PUT;
// export const DELETE = handler.DELETE;
// export const PATCH = handler.PATCH;
// export const HEAD = handler.HEAD;
// export const OPTIONS = handler.OPTIONS;
// `;

// return { files };
// },
vercel: ({ files, version, pkgJson, actorImports, actorMap }) => {
deployable: true,
files["package.json"] = stringifyJson({
...pkgJson,
scripts: {
...pkgJson.scripts,
dev: "next dev",
build: "next build",
start: "next start",
deploy: "vercel deploy",
},
devDependencies: {
"@actor-core/vercel": version,
next: "^14.0.0",
"vercel": "^41.3.2",
...pkgJson.devDependencies,
},
});

files["src/api/actor/route.ts"] = dedent`
import { createHandler } from "@actor-core/vercel"
${actorImports("./src/api/actor/route.ts")}

const handler = createHandler({
actors: { ${actorMap} }
});

export const GET = handler.GET;
export const POST = handler.POST;
export const PUT = handler.PUT;
export const DELETE = handler.DELETE;
export const PATCH = handler.PATCH;
export const HEAD = handler.HEAD;
export const OPTIONS = handler.OPTIONS;
`;

return { files };
},
rivet: {
deployable: true,
modify: ({ files, pkgJson, actorMap, actorImports, version }) => {
Expand Down Expand Up @@ -316,8 +319,8 @@ export const PLATFORM_NAMES = {
"cloudflare-workers": "Cloudflare Workers",
bun: "Bun",
nodejs: "Node.js",
vercel: "Vercel",
// supabase: "Supabase",
// vercel: "Vercel",
// deno: "Deno",
} satisfies Record<Platform, string>;

Expand Down
41 changes: 41 additions & 0 deletions packages/platforms/vercel/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "@actor-core/vercel",
"version": "0.3.0",
"files": [
"src",
"dist",
"package.json"
],
"type": "module",
"exports": {
".": {
"import": {
"types": "./dist/mod.d.ts",
"default": "./dist/mod.js"
},
"require": {
"types": "./dist/mod.d.cts",
"default": "./dist/mod.cjs"
}
}
},
"sideEffects": false,
"scripts": {
"build": "tsup src/mod.ts",
"dev": "yarn build --watch",
"check-types": "tsc --noEmit"
},
"peerDependencies": {
"actor-core": "workspace:*"
},
"devDependencies": {
"@actor-core/redis": "workspace:*",
"hono": "^4.7.0",
"next": "^15.1.7",
"tsup": "^8.3.6",
"typescript": "^5.5.2"
},
"dependencies": {
"@hono/node-server": "^1.13.8"
}
}
5 changes: 5 additions & 0 deletions packages/platforms/vercel/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { RedisConfig } from "@actor-core/redis";

export interface Config extends RedisConfig {
// Add any Vercel-specific config options here if needed
}
34 changes: 34 additions & 0 deletions packages/platforms/vercel/src/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { createRouter } from "@actor-core/redis";
import type { Config } from "./config";
import type { NextRequest } from "next/server";

export function createHandler(config: Config) {
const app = createRouter(config, {
// Vercel doesn't need WebSocket upgrade handling as it's handled differently
getUpgradeWebSocket: undefined,
});

return {
GET: async (request: NextRequest) => {
return app.fetch(request);
},
POST: async (request: NextRequest) => {
return app.fetch(request);
},
PUT: async (request: NextRequest) => {
return app.fetch(request);
},
DELETE: async (request: NextRequest) => {
return app.fetch(request);
},
PATCH: async (request: NextRequest) => {
return app.fetch(request);
},
HEAD: async (request: NextRequest) => {
return app.fetch(request);
},
OPTIONS: async (request: NextRequest) => {
return app.fetch(request);
},
};
}
9 changes: 9 additions & 0 deletions packages/platforms/vercel/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"paths": {
"@/*": ["./src/*"]
}
},
"include": ["src/**/*"]
}
4 changes: 4 additions & 0 deletions packages/platforms/vercel/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import defaultConfig from "../../../tsup.base.ts";
import { defineConfig } from "tsup";

export default defineConfig(defaultConfig);
4 changes: 4 additions & 0 deletions packages/platforms/vercel/turbo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "https://turbo.build/schema.json",
"extends": ["//"]
}
12 changes: 9 additions & 3 deletions scripts/template_platforms.ts → scripts/template-platforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { spawnSync } from "node:child_process";
import fs from "node:fs";
import path from "node:path";

import { getExamples } from "../packages/create-actor/src/macros";
import { getExamples } from "../packages/actor-core-cli/src/macros";

async function main() {
const examples = await getExamples();
Expand All @@ -14,7 +14,7 @@ async function main() {

for (const example of Object.values(examples)) {
for (const platform of example.supports) {
spawnSync(
const result = spawnSync(
createActorPath,
[
"--overwrite",
Expand All @@ -27,10 +27,16 @@ async function main() {
],
{ stdio: "inherit" },
);

if (result.status === null) {
throw new Error(`Process failed to execute for ${example.slug}/${platform}: ${result.error?.message || 'Unknown error'}`);
} else if (result.status !== 0) {
throw new Error(`Process exited with code ${result.status} for ${example.slug}/${platform}`);
}
}
}

fs.writeFileSync(path.join(targetDir, ".gitignore"), "*\n");
//fs.writeFileSync(path.join(targetDir, ".gitignore"), "*\n");
}

main().catch(console.error);
Loading