Skip to content

Commit f74e332

Browse files
committed
refactor(presets/zeabur): match our current zbpack
Zeabur now uses a general node server to build the Dockerfile. We simply extend "node-server" and "static". Expected behavior: * "nuxt build" selects the "zeabur" provider and generates the same output as "node." * "nuxt generate" selects the "zeabur-static" provider and generates the same output as "static."
1 parent 06dfda1 commit f74e332

2 files changed

Lines changed: 38 additions & 57 deletions

File tree

src/presets/zeabur/preset.ts

Lines changed: 3 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,8 @@
1-
import fsp from "node:fs/promises";
2-
import { writeFile } from "../_utils/fs.ts";
31
import { defineNitroPreset } from "../_utils/preset.ts";
4-
import type { Nitro } from "nitro/types";
5-
import { dirname, relative, resolve } from "pathe";
62

7-
// https://zeabur.com/docs/advanced/serverless-output-format
8-
9-
const zeabur = defineNitroPreset(
3+
const zeaburServer = defineNitroPreset(
104
{
11-
entry: "./zeabur/runtime/zeabur",
12-
output: {
13-
dir: "{{ rootDir }}/.zeabur/output",
14-
serverDir: "{{ output.dir }}/functions/__nitro.func",
15-
publicDir: "{{ output.dir }}/static",
16-
},
17-
hooks: {
18-
async compiled(nitro: Nitro) {
19-
const buildConfigPath = resolve(
20-
nitro.options.output.dir,
21-
"config.json"
22-
);
23-
const cfg = {
24-
containerized: false,
25-
routes: [{ src: ".*", dest: "/__nitro" }],
26-
};
27-
await writeFile(buildConfigPath, JSON.stringify(cfg, null, 2));
28-
29-
// Write ISR functions
30-
for (const [key, value] of Object.entries(nitro.options.routeRules)) {
31-
if (!value.isr) {
32-
continue;
33-
}
34-
const funcPrefix = resolve(
35-
nitro.options.output.serverDir,
36-
".." + key
37-
);
38-
await fsp.mkdir(dirname(funcPrefix), { recursive: true });
39-
await fsp.symlink(
40-
"./" +
41-
relative(dirname(funcPrefix), nitro.options.output.serverDir),
42-
funcPrefix + ".func",
43-
"junction"
44-
);
45-
await writeFile(
46-
funcPrefix + ".prerender-config.json",
47-
JSON.stringify({ type: "Prerender" })
48-
);
49-
}
50-
},
51-
},
5+
extends: "node-server",
526
},
537
{
548
name: "zeabur" as const,
@@ -59,19 +13,11 @@ const zeabur = defineNitroPreset(
5913
const zeaburStatic = defineNitroPreset(
6014
{
6115
extends: "static",
62-
output: {
63-
dir: "{{ rootDir }}/.zeabur/output",
64-
publicDir: "{{ output.dir }}/static",
65-
},
66-
commands: {
67-
preview: "npx serve ./static",
68-
},
6916
},
7017
{
7118
name: "zeabur-static" as const,
72-
7319
static: true,
7420
}
7521
);
7622

77-
export default [zeabur, zeaburStatic] as const;
23+
export default [zeaburServer, zeaburStatic] as const;

test/presets/zeabur.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { existsSync } from "node:fs";
2+
import fsp from "node:fs/promises";
3+
import { resolve } from "pathe";
4+
import { describe, expect, it } from "vitest";
5+
import { setupTest } from "../tests.ts";
6+
7+
describe("nitro:preset:zeabur-static", async () => {
8+
const ctx = await setupTest("zeabur-static");
9+
10+
it("should not generate a server folder", async () => {
11+
const contents = await fsp.readdir(resolve(ctx.outDir));
12+
expect(contents).toMatchInlineSnapshot(`
13+
[
14+
"nitro.json",
15+
"public",
16+
]
17+
`);
18+
});
19+
20+
it("output has public directory", async () => {
21+
// make output directory aligned with `nuxt generate`'s
22+
// output directory, which is ".output/public"
23+
expect(existsSync(resolve(ctx.outDir, "public", "favicon.ico"))).toBe(true);
24+
});
25+
});
26+
27+
describe("nitro:preset:zeabur", async () => {
28+
const ctx = await setupTest("zeabur");
29+
30+
it("output directory is .output/server and has index.mjs", async () => {
31+
// Zeabur sets ".output/server/index.mjs" as the entry point
32+
// https://github.com/zeabur/zbpack/blob/b8d76b5758fed32203cbdbf0456a9bc5c948dfc0/internal/nodejs/plan.go#L883
33+
expect(existsSync(resolve(ctx.outDir, "server", "index.mjs"))).toBe(true);
34+
});
35+
});

0 commit comments

Comments
 (0)