Skip to content

Commit 4d5387f

Browse files
dodok8claude
andcommitted
Add runtime-specific Elysia templates
Split Elysia template into runtime-specific versions (Deno, Bun, Node.js) to properly handle different runtime APIs and configurations. Deno uses Deno.serve() API, Bun and Node use Elysia's .listen() method with @elysiajs/node adapter for Node. Update webframeworks.ts to support all package managers (deno, bun, npm, yarn, pnpm) with appropriate dependencies and configurations for each runtime. Add --allow-env and --allow-net flags for Deno tasks since Elysia requires environment access. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent c76f9a0 commit 4d5387f

4 files changed

Lines changed: 95 additions & 16 deletions

File tree

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { fedify } from "@fedify/elysia";
22
import { Elysia } from "elysia";
33
import federation from "./federation.ts";
4-
import { getLogger } from "@logtape/logtape";
4+
import "./logging.ts";
55

6-
const logger = getLogger("/* logger */");
76
const app = new Elysia();
87

98
app
109
.use(fedify(federation, () => undefined))
11-
.listen(3000)
10+
.get("/", () => "Hello, Fedify!")
11+
.listen(3000, () => {
12+
console.log("Server started at http://localhost:3000");
13+
})
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { fedify } from "@fedify/elysia";
2+
import { Elysia } from "elysia";
3+
import federation from "./federation.ts";
4+
import "./logging.ts";
5+
6+
const app = new Elysia();
7+
8+
app
9+
.use(fedify(federation, () => undefined))
10+
.get("/", () => "Hello, Fedify!")
11+
12+
Deno.serve(
13+
{
14+
port: 3000,
15+
onListen: ({ port, hostname }) =>
16+
console.log("Server started at http://" + hostname + ":" + port),
17+
},
18+
app.fetch,
19+
)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { fedify } from "@fedify/elysia";
2+
import { Elysia } from "elysia";
3+
import federation from "./federation.ts";
4+
import "./logging.ts";
5+
import { node } from '@elysiajs/node'
6+
7+
const app = new Elysia({ adapter: node() });
8+
9+
app
10+
.use(fedify(federation, () => undefined))
11+
.get("/", () => "Hello, Fedify!")
12+
.listen(3000, () => {
13+
console.log("Server started at http://localhost:3000");
14+
})

packages/cli/src/init/webframeworks.ts

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,25 +81,69 @@ const webFrameworks: WebFrameworks = {
8181
},
8282
elysia: {
8383
label: "ElysiaJS",
84-
packageManagers: ["bun"],
84+
packageManagers: PACKAGE_MANAGER,
8585
init: ({ projectName, packageManager: pm }) => ({
86-
dependencies: {
87-
elysia: "^1.3.6",
88-
"@fedify/elysia": PACKAGE_VERSION,
89-
},
90-
devDependencies: {
91-
"@types/bun": "^1.2.19",
92-
},
86+
dependencies: pm === "deno"
87+
? {
88+
elysia: "npm:elysia@^1.3.6",
89+
"@fedify/elysia": PACKAGE_VERSION,
90+
}
91+
: pm === "bun"
92+
? {
93+
elysia: "^1.3.6",
94+
"@fedify/elysia": PACKAGE_VERSION,
95+
}
96+
: {
97+
elysia: "^1.3.6",
98+
"@elysiajs/node": "^1.4.2",
99+
"@fedify/elysia": PACKAGE_VERSION,
100+
...(pm === "pnpm"
101+
? {
102+
"@sinclair/typebox": "^0.34.41",
103+
"openapi-types": "^12.1.3",
104+
}
105+
: {}),
106+
},
107+
devDependencies: pm === "bun"
108+
? { "@types/bun": "^1.2.19" }
109+
: pm === "deno"
110+
? {}
111+
: {
112+
tsx: "^4.21.0",
113+
"@types/node": "^25.0.3",
114+
typescript: "^5.9.3",
115+
},
93116
federationFile: "src/federation.ts",
94117
loggingFile: "src/logging.ts",
95118
files: {
96-
"src/index.ts": readTemplate("elysia/index.ts")
97-
.replace(/\/\* logger \*\//, projectName),
119+
"src/index.ts": readTemplate(
120+
`elysia/index/${packageManagerToRuntime(pm)}.ts`,
121+
).replace(/\/\* logger \*\//, projectName),
122+
},
123+
compilerOptions: pm === "deno" || pm === "bun" ? undefined : {
124+
"lib": ["ESNext", "DOM"],
125+
"target": "ESNext",
126+
"module": "NodeNext",
127+
"moduleResolution": "NodeNext",
128+
"allowImportingTsExtensions": true,
129+
"verbatimModuleSyntax": true,
130+
"noEmit": true,
131+
"strict": true,
98132
},
99-
compilerOptions: undefined,
100133
tasks: {
101-
"dev": "bun run --hot ./src/index.ts",
102-
"prod": "bun run ./src/index.ts",
134+
"dev": pm === "deno"
135+
? "deno serve --allow-env --allow-net --watch ./src/index.ts"
136+
: pm === "bun"
137+
? "bun run --hot ./src/index.ts"
138+
: "tsx watch src/index.ts",
139+
...(pm === "deno"
140+
? { "prod": "deno serve --allow-env --allow-net ./src/index.ts" }
141+
: pm === "bun"
142+
? { "prod": "bun run ./src/index.ts" }
143+
: {
144+
"build": "tsc src/index.ts --outDir dist",
145+
"start": "NODE_ENV=production node dist/index.js",
146+
}),
103147
},
104148
instruction: getInstruction(pm, 3000),
105149
}),

0 commit comments

Comments
 (0)