Skip to content
Open
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
5 changes: 4 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,14 @@ To be released.

### @fedify/init

- Supported [SvelteKit] as a web framework option in `fedify init` [[#892]]

- Fixed `fedify init`'s hydration test validation to run `format` before
`format:check`, which previously caused the entire test suite to fail when
the package manager is `npm` or `pnpm`: [[#950]] [[#952] by Jang Hanarae]

[SvelteKit]: https://kit.svelte.dev/
[#892]: https://github.com/fedify-dev/fedify/issues/892
[#950]: https://github.com/fedify-dev/fedify/issues/950
[#952]: https://github.com/fedify-dev/fedify/pull/952

Expand Down Expand Up @@ -5930,7 +5934,6 @@ Released on November 30, 2024.
- Let the `fedify lookup` command take multiple arguments.
[[#173], [#186] by PGD]

[SvelteKit]: https://kit.svelte.dev/
[#162]: https://github.com/fedify-dev/fedify/issues/162
[#170]: https://github.com/fedify-dev/fedify/issues/170
[#171]: https://github.com/fedify-dev/fedify/issues/171
Expand Down
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/


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
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),
);
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;
63 changes: 63 additions & 0 deletions packages/init/src/webframeworks/sveltekit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
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, getNodeBunDevToolTasks } 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"],
},
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: getNodeBunDevToolTasks(pm),
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"];