Skip to content

Commit 5e5265d

Browse files
authored
Merge pull request #707 from dahlia/2.1-maintenance
Fix `fedify init` Astro + Bun projects
2 parents 71cbb7c + 3364cf9 commit 5e5265d

10 files changed

Lines changed: 334 additions & 68 deletions

File tree

CHANGES.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ Version 2.1.7
88

99
To be released.
1010

11+
### @fedify/init
12+
13+
- Fixed `fedify init` generating Astro projects for Bun with the Node.js
14+
adapter and `astro preview`, which could fail to run correctly on Bun.
15+
Astro + Bun projects now use *@nurodev/astro-bun* and run the built
16+
Bun server entry point instead. [[#707]]
17+
18+
[#707]: https://github.com/fedify-dev/fedify/pull/707
19+
1120

1221
Version 2.1.6
1322
-------------

deno.lock

Lines changed: 57 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/astro/README.md

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ A comprehensive example of building a federated server application using
77
[Fedify] with [Astro] via the [`@fedify/astro`] package. This sample
88
demonstrates how to create an ActivityPub-compatible federated social media
99
server that can interact with other federated platforms like Mastodon, Pleroma,
10-
and other ActivityPub implementations. It supports both [Deno] and [Node.js]
11-
runtimes.
10+
and other ActivityPub implementations. It supports [Deno], [Node.js], and
11+
[Bun] runtimes.
1212

1313
[Fedify]: https://fedify.dev
1414
[Astro]: https://astro.build/
1515
[`@fedify/astro`]: https://jsr.io/@fedify/astro
1616
[Deno]: https://deno.com/
1717
[Node.js]: https://nodejs.org/
18+
[Bun]: https://bun.sh/
1819

1920

2021
Features
@@ -30,7 +31,8 @@ Features
3031
- **Inbox Processing**: Real-time activity processing from federated instances
3132
- **Content Negotiation**: Same routes serve HTML for browsers and ActivityPub
3233
JSON for federated clients
33-
- **Dual Runtime**: Supports both Deno and Node.js via separate Astro configs
34+
- **Three Runtimes**: Supports Deno, Node.js, and Bun via separate Astro
35+
configs
3436
- **TypeScript**: Full type safety throughout the application
3537

3638

@@ -40,8 +42,10 @@ How it works
4042
- *astro.config.deno.ts* registers `fedifyIntegration()` to configure Vite's
4143
SSR settings for Fedify compatibility, and uses `@deno/astro-adapter` to
4244
run on Deno.
43-
- *astro.config.node.ts* registers `fedifyIntegration()` without any adapter
44-
for Node.js.
45+
- *astro.config.node.ts* registers `fedifyIntegration()` and uses
46+
`@astrojs/node` for Node.js.
47+
- *astro.config.bun.ts* registers `fedifyIntegration()` and uses
48+
`@nurodev/astro-bun` for Bun.
4549
- *src/lib/store.ts* defines in-memory stores for key pairs, follower
4650
relationships, and posts.
4751
- *src/lib/federation.ts* sets up the full `Federation` instance with:
@@ -111,6 +115,23 @@ pnpm dev
111115

112116
This uses *astro.config.node.ts* as the configuration file.
113117

118+
### Bun
119+
120+
To run the dev server with Bun:
121+
122+
~~~~ command
123+
bun run dev:bun
124+
~~~~
125+
126+
This uses *astro.config.bun.ts* as the configuration file.
127+
128+
To build and run the Bun server bundle:
129+
130+
~~~~ command
131+
bun run build:bun
132+
bun run preview:bun
133+
~~~~
134+
114135
### Testing
115136

116137
The application will be available at <http://localhost:4321/>.
@@ -139,6 +160,8 @@ Example usage scenarios
139160
deno task dev
140161
# or for Node.js
141162
pnpm dev
163+
# or for Bun
164+
bun run dev:bun
142165
~~~~
143166

144167
2. Visit the home page at <http://localhost:4321/> to see the demo account
@@ -216,13 +239,13 @@ Using as a template
216239
-------------------
217240

218241
If you are creating a new project based on this example, you only need the
219-
configuration file for your target runtime. Delete the unused one and rename
242+
configuration file for your target runtime. Delete the unused ones and rename
220243
the one you keep to *astro.config.ts*:
221244

222245
### For Deno
223246

224247
~~~~ command
225-
rm astro.config.node.ts
248+
rm astro.config.node.ts astro.config.bun.ts
226249
mv astro.config.deno.ts astro.config.ts
227250
~~~~
228251

@@ -241,7 +264,7 @@ Then remove the `--config` flags from *deno.json* tasks:
241264
### For Node.js
242265

243266
~~~~ command
244-
rm astro.config.deno.ts
267+
rm astro.config.deno.ts astro.config.bun.ts
245268
mv astro.config.node.ts astro.config.ts
246269
~~~~
247270

@@ -257,6 +280,25 @@ Then remove the `--config` flags from *package.json* scripts:
257280
}
258281
~~~~
259282

283+
### For Bun
284+
285+
~~~~ command
286+
rm astro.config.deno.ts astro.config.node.ts
287+
mv astro.config.bun.ts astro.config.ts
288+
~~~~
289+
290+
Then update *package.json* scripts to use Bun's SSR entry point after build:
291+
292+
~~~~ json
293+
{
294+
"scripts": {
295+
"dev": "bunx astro dev",
296+
"build": "bunx astro build",
297+
"preview": "bun ./dist/server/entry.mjs"
298+
}
299+
}
300+
~~~~
301+
260302

261303
Links
262304
-----

examples/astro/astro.config.bun.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import bun from "@nurodev/astro-bun";
2+
import { fedifyIntegration } from "@fedify/astro";
3+
import { defineConfig } from "astro/config";
4+
5+
// https://astro.build/config
6+
export default defineConfig({
7+
integrations: [fedifyIntegration()],
8+
output: "server",
9+
adapter: bun(),
10+
server: { host: true, allowedHosts: true },
11+
security: { allowedDomains: [{}] },
12+
});

examples/astro/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@
66
"scripts": {
77
"dev": "astro dev --config astro.config.node.ts",
88
"build": "astro build --config astro.config.node.ts",
9-
"preview": "astro preview --config astro.config.node.ts"
9+
"preview": "astro preview --config astro.config.node.ts",
10+
"dev:bun": "bunx astro dev --config astro.config.bun.ts",
11+
"build:bun": "bunx astro build --config astro.config.bun.ts",
12+
"preview:bun": "bun ./dist/server/entry.mjs"
1013
},
1114
"dependencies": {
1215
"@astrojs/node": "^9.5.4",
1316
"@deno/astro-adapter": "^0.3.2",
1417
"@fedify/astro": "workspace:^",
1518
"@fedify/fedify": "workspace:^",
1619
"@fedify/vocab": "workspace:^",
20+
"@nurodev/astro-bun": "^2.1.2",
1721
"astro": "catalog:"
1822
}
1923
}

packages/astro/README.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,12 @@ export const onRequest = fedifyMiddleware(
5252
For Deno users
5353
--------------
5454

55-
If you are using Deno, you should import `@deno/vite-adapter` in
55+
If you are using Deno, you should import `@deno/astro-adapter` in
5656
*astro.config.mjs* and use it as the adapter:
5757

5858
~~~~ typescript
5959
import { defineConfig } from "astro/config";
6060
import { fedifyIntegration } from "@fedify/astro";
61-
import deno from "@deno/vite-adapter";
6261
import deno from "@deno/astro-adapter";
6362

6463
export default defineConfig({
@@ -82,6 +81,38 @@ instead of `astro`:
8281
~~~~
8382

8483

84+
For Bun users
85+
-------------
86+
87+
If you are using Bun, install `@nurodev/astro-bun` and configure it as the
88+
Astro adapter:
89+
90+
~~~~ typescript
91+
import { defineConfig } from "astro/config";
92+
import { fedifyIntegration } from "@fedify/astro";
93+
import bun from "@nurodev/astro-bun";
94+
95+
export default defineConfig({
96+
integrations: [fedifyIntegration()],
97+
output: "server",
98+
adapter: bun(),
99+
});
100+
~~~~
101+
102+
Then use Bun to start Astro in development, and run the generated server entry
103+
point after building for preview or production:
104+
105+
~~~~ json
106+
{
107+
"scripts": {
108+
"dev": "bunx astro dev",
109+
"build": "bunx astro build",
110+
"preview": "bun ./dist/server/entry.mjs"
111+
}
112+
}
113+
~~~~
114+
115+
85116
How it works
86117
------------
87118

0 commit comments

Comments
 (0)