Skip to content
Merged
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
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ To be released.

### @fedify/cli

- Added \[SvelteKit\] option to `fedify init` command. This option allows
users to initialize a new Fedify project with SvelteKit integration.
[[#892], [#971] by Jang Hanarae\]
- Added `fedify.com.es` as a tunneling service. The CLI pins the service's
SSH host key and rejects a mismatched server before exposing a local port.
[[#940]]
Expand All @@ -158,7 +161,9 @@ To be released.
`@js-temporal/polyfill` to `temporal-polyfill`.
[[#823], [#925]]

[#892]: https://github.com/fedify-dev/fedify/issues/892
[#940]: https://github.com/fedify-dev/fedify/pull/940
[#971]: https://github.com/fedify-dev/fedify/pull/971

### @fedify/debugger

Expand All @@ -175,6 +180,8 @@ To be released.
the package manager is `npm` or `pnpm`:
[[#950]]
[[#952] by Jang Hanarae\]
- Supported \[SvelteKit\] as a web framework option in
`fedify init`. [[#892], [#971] by Jang Hanarae\]

[#950]: https://github.com/fedify-dev/fedify/issues/950
[#952]: https://github.com/fedify-dev/fedify/pull/952
Expand Down
3 changes: 3 additions & 0 deletions changes.d/cli/init-sveltekit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Added [SvelteKit] option to `fedify init` command. This option allows users
to initialize a new Fedify project with SvelteKit integration.
[[#892], [#971] by Jang Hanarae]
6 changes: 6 additions & 0 deletions changes.d/init/sveltekit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
links:
'#971': https://github.com/fedify-dev/fedify/pull/971
---
- Supported [SvelteKit] as a web framework option in
`fedify init`. [[#892], [#971] by Jang Hanarae]
1 change: 1 addition & 0 deletions docs/tutorial/microblog.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ Select *Hono*, *npm*, *in-process*, and *in-memory* in order:
Express
Nuxt
SolidStart
SvelteKit


? Choose the package manager to use
Expand Down
3 changes: 2 additions & 1 deletion packages/init/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Supported options
The initializer supports the following project configurations:

- **Web frameworks**: Bare-bones, [Astro], [Elysia], [Express], [Hono],
[Next.js], [Nitro], [Nuxt], [SolidStart]
[Next.js], [Nitro], [Nuxt], [SolidStart], [SvelteKit]
- **Package managers**: Deno, pnpm, Bun, Yarn, npm
- **Key-value stores**: In-Memory, Deno KV, Redis, PostgreSQL
- **Message queues**: In-Process, Deno KV, Redis, PostgreSQL, AMQP
Expand All @@ -39,6 +39,7 @@ The initializer supports the following project configurations:
[Nitro]: https://nitro.build/
[Nuxt]: https://nuxt.com/
[SolidStart]: https://start.solidjs.com/
[SvelteKit]: https://svelte.dev/

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Point the SvelteKit reference to the SvelteKit documentation.

The current reference opens the generic Svelte homepage. Use the SvelteKit documentation URL already used in CHANGES.md.

Proposed fix
-[SvelteKit]: https://svelte.dev/
+[SvelteKit]: https://svelte.dev/docs/kit
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/init/README.md` at line 42, Update the SvelteKit link reference in
the README to use the SvelteKit documentation URL already established in
CHANGES.md instead of the generic Svelte homepage.



Installation
Expand Down
1 change: 1 addition & 0 deletions packages/init/src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const WEB_FRAMEWORK = [
"express",
"nuxt",
"solidstart",
"sveltekit",
] as const;
/** All supported message queue backend identifiers. */
export const MESSAGE_QUEUE = Object.keys(mq) as readonly (keyof typeof mq)[];
Expand Down
30 changes: 15 additions & 15 deletions packages/init/src/json/deps.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
{
"@hongminhee/x-forwarded-fetch": "^0.2.0",
"@hono/hono": "^4.12.27",
"@logtape/logtape": "^2.2.1",
"@hono/hono": "^4.12.33",
"@logtape/logtape": "^2.3.0",
"@std/dotenv": "^0.225.7",
"npm:@astrojs/node": "^11.0.2",
"npm:@astrojs/node": "^11.0.3",
"npm:@deno/astro-adapter": "^0.6.0",
"npm:@dotenvx/dotenvx": "^1.75.1",
"npm:@elysiajs/node": "^1.4.5",
"npm:@hono/node-server": "^1.19.12",
"npm:@nuxt/kit": "^4.4.8",
"npm:@sinclair/typebox": "^0.34.49",
"npm:@nuxt/kit": "^4.5.1",
"npm:@sinclair/typebox": "^0.34.52",
"npm:@solidjs/router": "^0.16.1",
"npm:@solidjs/start": "^1.3.2",
"npm:@types/bun": "^1.3.14",
"npm:@types/express": "^4.17.21",
"npm:@types/node@20": "^20.11.2",
"npm:@types/node@22": "^22.17.0",
"npm:@types/node@25": "^25.5.0",
"npm:astro": "^7.0.7",
"npm:create-astro": "^5.2.2",
"npm:astro": "^7.1.6",
"npm:create-astro": "^5.2.3",
"npm:elysia": "^1.4.29",
"npm:express": "^5.2.1",
"npm:h3": "^1.15.0",
"npm:hono": "^4.12.27",
"npm:nuxi": "^3.36.0",
"npm:nuxt": "^4.4.8",
"npm:hono": "^4.12.33",
"npm:nuxi": "^3.37.0",
"npm:nuxt": "^4.5.1",
"npm:openapi-types": "^12.1.3",
"npm:oxfmt": "^0.56.0",
"npm:oxlint": "^1.71.0",
"npm:prettier": "^3.8.4",
"npm:oxfmt": "^0.61.0",
"npm:oxlint": "^1.76.0",
"npm:prettier": "^3.9.6",
"npm:prettier-plugin-astro": "^0.14.1",
"npm:solid-js": "^1.9.13",
"npm:tsx": "^4.22.4",
"npm:solid-js": "^1.9.14",
"npm:tsx": "^4.23.1",
"npm:typescript": "^5.9.3",
"npm:vinxi": "^0.5.11",
"npm:x-forwarded-fetch": "^0.2.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/init/src/json/kv.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"pnpm"
],
"dependencies": {
"npm:mysql2": "^3.22.5"
"npm:mysql2": "^3.23.2"
},
"imports": {
"@fedify/mysql": {
Expand Down
2 changes: 1 addition & 1 deletion packages/init/src/json/mq.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"pnpm"
],
"dependencies": {
"npm:mysql2": "^3.22.5"
"npm:mysql2": "^3.23.2"
},
"imports": {
"@fedify/mysql": {
Expand Down
7 changes: 7 additions & 0 deletions packages/init/src/templates/sveltekit/hooks.server.ts.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { fedifyHook } from "@fedify/sveltekit";
import { sequence } from "@sveltejs/kit/hooks";
import federation from "$lib/federation";

export const handle = sequence(
fedifyHook(federation),
);
Comment on lines +1 to +7

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the SvelteKit server entry.
rg -n -C 3 'logging|federation|fedifyHook' \
  packages/init/src/templates/sveltekit/hooks.server.ts.tpl

# Locate and inspect the template that generates src/lib/federation.ts.
fd -t f -g 'federation.ts.tpl' packages/init/src/templates -x \
  rg -n -C 3 'logging|federation' {}

Repository: fedify-dev/fedify

Length of output: 892


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== target template =="
cat -n packages/init/src/templates/sveltekit/hooks.server.ts.tpl

echo
echo "== federation template(s) =="
fd -t f -g 'federation.ts.tpl' packages/init/src/templates -x sh -c 'printf "\n--- %s ---\n" "$1"; cat -n "$1"' sh {}

echo
echo "== generate hook and logging references =="
rg -n -C 4 'logging|src/lib/logging|hooks\.server|federation\.ts.tpl' packages/init/src

echo
echo "== static init flow snippets =="
fd -t f 'sveltekit\.ts|hooks\.server\.ts\.tpl|federation\.ts\.tpl' packages/init/src -x sh -c 'echo "--- $1 linecount ---"; wc -l "$1"' sh {}

Repository: fedify-dev/fedify

Length of output: 30074


Load LogTape in the SvelteKit server entry.

The generated src/lib/logging.ts is not imported by src/hooks.server.ts or the default src/lib/federation.ts, so the logging configuration is not evaluated. Import $lib/logging in packages/init/src/templates/sveltekit/hooks.server.ts.tpl before constructing handle.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/init/src/templates/sveltekit/hooks.server.ts.tpl` around lines 1 -
7, Import $lib/logging in the generated hooks.server.ts template before
constructing the handle sequence, ensuring the logging configuration is
evaluated before fedifyHook(federation) runs. Keep the existing federation
import and handle composition unchanged.

2 changes: 1 addition & 1 deletion packages/init/src/test/action.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { pipe, tap, when } from "@fxts/core";
import { set } from "../utils.ts";
import type { TestInitCommand } from "../command.ts";
import { set } from "../utils.ts";
import { checkRequiredDbs } from "./db.ts";
import { fillEmptyOptions } from "./fill.ts";
import runTests from "./run.ts";
Expand Down
1 change: 1 addition & 0 deletions packages/init/src/test/lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const BANNED_LOOKUP_REASONS: Record<string, string> = {
"solidstart,deno,*,*": "Error occurred while loading submodules in Deno",
"astro,deno,*,*": "Astro doesn't support remote packages in Deno",
"nuxt,deno,*,*": "Nuxt doesn't support remote packages in Deno",
"sveltekit,deno,*,*": "SvelteKit doesn't support remote packages in Deno",
};
const BANNED_LOOKUP_CASES: LookupCasePattern[] = Object.keys(
BANNED_LOOKUP_REASONS,
Expand Down
9 changes: 6 additions & 3 deletions packages/init/src/test/port.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,12 @@ export async function replacePortInApp(
return;
}

if (wf === "astro") {
// Insert server.port into the Astro config
const configPath = join(dir, "astro.config.ts");
if (wf === "astro" || wf === "sveltekit") {
// Insert server.port into the Astro or Vite config
const configPath = join(
dir,
wf === "astro" ? "astro.config.ts" : "vite.config.ts",
);
const content = await readFile(configPath, "utf8");
await writeFile(
configPath,
Expand Down
6 changes: 3 additions & 3 deletions packages/init/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import type { RequiredNotNull } from "./utils.ts";
/** Supported package manager identifiers: `"deno"`, `"pnpm"`, `"bun"`, `"yarn"`, `"npm"`. */
export type PackageManager = typeof PACKAGE_MANAGER[number];

/** Supported web framework identifiers: `"hono"`, `"nitro"`, `"next"`, `"elysia"`, `"astro"`, `"express"`. */
/** Supported web framework identifiers: `"bare-bones"`, `"hono"`, `"nitro"`, `"next"`, `"elysia"`, `"astro"`, `"express"`, `"nuxt"`, `"solidstart"`, `"sveltekit"`. */
export type WebFramework = typeof WEB_FRAMEWORK[number];

/** Supported message queue identifiers: `"denokv"`, `"redis"`, `"postgres"`, `"amqp"`. */
/** Supported message queue identifiers: `"in-process"`, `"redis"`, `"postgres"`, `"mysql"`, `"amqp"`, `"denokv"`. */
export type MessageQueue = typeof MESSAGE_QUEUE[number];

/** Supported key-value store identifiers: `"denokv"`, `"redis"`, `"postgres"`. */
/** Supported key-value store identifiers: `"in-memory"`, `"redis"`, `"postgres"`, `"mysql"`, `"denokv"`. */
export type KvStore = typeof KV_STORE[number];

/** A mapping from each {@link MessageQueue} identifier to its description. */
Expand Down
2 changes: 2 additions & 0 deletions packages/init/src/webframeworks/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import next from "./next.ts";
import nitro from "./nitro.ts";
import nuxt from "./nuxt.ts";
import solidstart from "./solidstart.ts";
import sveltekit from "./sveltekit.ts";

/**
* Registry of all supported web framework configurations.
Expand All @@ -26,6 +27,7 @@ const webFrameworks: WebFrameworks = {
nitro,
nuxt,
solidstart,
sveltekit,
} as const;

export default webFrameworks;
73 changes: 73 additions & 0 deletions packages/init/src/webframeworks/sveltekit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { PACKAGE_MANAGER } from "../const.ts";
import deps from "../json/deps.json" with { type: "json" };
import { PACKAGE_VERSION, readTemplate } from "../lib.ts";
import type { PackageManager, WebFrameworkDescription } from "../types.ts";
import { defaultDenoDependencies, defaultDevDependencies } from "./const.ts";
import { getInstruction, nodeBunDevToolTasks, pmToRt } from "./utils.ts";

const sveltekitDescription: WebFrameworkDescription = {
label: "SvelteKit",
packageManagers: PACKAGE_MANAGER,
defaultPort: 5173,
init: async ({ packageManager: pm, testMode }) => ({
command: Array.from(getInitCommand(pm)),
dependencies: {
"@fedify/sveltekit": PACKAGE_VERSION,
...(pm === "deno" ? defaultDenoDependencies : {}),
},
devDependencies: {
...defaultDevDependencies,
"typescript": deps["npm:typescript"],
"@types/node": deps["npm:@types/node@25"],
...(pmToRt(pm) === "deno"
? {}
: { "@dotenvx/dotenvx": deps["npm:@dotenvx/dotenvx"] }),
},
federationFile: "src/lib/federation.ts",
loggingFile: "src/lib/logging.ts",
env: testMode ? { HOST: "127.0.0.1" } : {} as Record<string, string>,
files: {
"src/hooks.server.ts": await readTemplate("sveltekit/hooks.server.ts"),
},
tasks: pmToRt(pm) === "deno" ? {} : { ...TASKS },
instruction: getInstruction(pm, 5173),
}),
};

export default sveltekitDescription;

/**
* Returns the shell command array to scaffold a new SvelteKit project
* in the current directory using the given package manager.
*/
function* getInitCommand(pm: PackageManager) {
yield* getSvelteKitInitCommand(pm);
yield* [
".",
"--template",
"minimal",
"--types",
"ts",
"--no-add-ons",
"--no-dir-check",
"--no-download-check",
"--install",
pm,
];
}

const getSvelteKitInitCommand = (pm: PackageManager): string[] =>
pm === "bun"
? ["bunx", "sv", "create"]
: pm === "deno"
? ["deno", "run", "-A", "npm:sv", "create"]
: pm === "npm"
? ["npx", "sv", "create"]
: [pm, "dlx", "sv", "create"];

const TASKS = {
"dev": "dotenvx run -- vite dev",
"build": "dotenvx run -- vite build",
"preview": "dotenvx run -- vite preview",
...nodeBunDevToolTasks,
};
Loading