@bractjs/bractjs 0.1.8 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/build/bundler.ts +18 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bractjs/bractjs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"description": "Production-grade SSR framework for Bun + React 19. File-based routing, streaming SSR, server actions, typed routes.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/bractjs/bractjs#readme",
|
package/src/build/bundler.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { join, basename, extname, resolve } from "node:path";
|
|
2
|
-
import { rename } from "node:fs/promises";
|
|
2
|
+
import { rename, rm } from "node:fs/promises";
|
|
3
3
|
import type { BractJSConfig } from "../server/serve.ts";
|
|
4
4
|
import { scanRoutes } from "../server/scanner.ts";
|
|
5
5
|
import { contentHash } from "./hash.ts";
|
|
@@ -16,10 +16,17 @@ export async function runBuild(config: BractJSConfig): Promise<void> {
|
|
|
16
16
|
// ── 0. Codegen — typed routes ───────────────────────────────────────────
|
|
17
17
|
await writeRouteTypes(appDir);
|
|
18
18
|
const routes = await scanRoutes(appDir);
|
|
19
|
-
const routeFilePaths = routes.map((r) => r.filePath);
|
|
19
|
+
const routeFilePaths = routes.map((r) => join(appDir, r.filePath));
|
|
20
20
|
const rootFilePath = join(appDir, "root.tsx");
|
|
21
21
|
|
|
22
|
-
// ── 1.
|
|
22
|
+
// ── 1. Clean stale artefacts ────────────────────────────────────────────
|
|
23
|
+
const buildDir = config.buildDir ?? "build";
|
|
24
|
+
await Promise.all([
|
|
25
|
+
rm(join(buildDir, "client"), { recursive: true, force: true }),
|
|
26
|
+
rm(join(buildDir, "server"), { recursive: true, force: true }),
|
|
27
|
+
]);
|
|
28
|
+
|
|
29
|
+
// ── 2. Server bundle ────────────────────────────────────────────────────
|
|
23
30
|
const pkgRoot = join(import.meta.dir, "../..");
|
|
24
31
|
const serverResult = await Bun.build({
|
|
25
32
|
entrypoints: [join(pkgRoot, "src/server/index.ts")],
|
|
@@ -30,7 +37,7 @@ export async function runBuild(config: BractJSConfig): Promise<void> {
|
|
|
30
37
|
});
|
|
31
38
|
if (!serverResult.success) throw new AggregateError(serverResult.logs, "Server build failed");
|
|
32
39
|
|
|
33
|
-
// ──
|
|
40
|
+
// ── 3. Client bundle (code-split) ───────────────────────────────────────
|
|
34
41
|
const clientResult = await Bun.build({
|
|
35
42
|
entrypoints: [join(pkgRoot, "src/client/entry.tsx"), rootFilePath, ...routeFilePaths],
|
|
36
43
|
target: "browser",
|
|
@@ -45,7 +52,7 @@ export async function runBuild(config: BractJSConfig): Promise<void> {
|
|
|
45
52
|
});
|
|
46
53
|
if (!clientResult.success) throw new AggregateError(clientResult.logs, "Client build failed");
|
|
47
54
|
|
|
48
|
-
// ──
|
|
55
|
+
// ── 4. Hash + rename output files ──────────────────────────────────────
|
|
49
56
|
const routeChunks = new Map<string, string>();
|
|
50
57
|
let clientEntry = "";
|
|
51
58
|
let rootChunk: string | undefined;
|
|
@@ -62,7 +69,11 @@ export async function runBuild(config: BractJSConfig): Promise<void> {
|
|
|
62
69
|
const hashedPath = `${base}.${hash}${ext}`;
|
|
63
70
|
await rename(artifact.path, hashedPath);
|
|
64
71
|
|
|
65
|
-
const
|
|
72
|
+
const hashedAbs = resolve(hashedPath);
|
|
73
|
+
const cwdAbs = resolve(".");
|
|
74
|
+
const publicPath = hashedAbs.startsWith(cwdAbs + "/")
|
|
75
|
+
? "/" + hashedAbs.slice(cwdAbs.length + 1).replace(/\\/g, "/")
|
|
76
|
+
: "/" + hashedPath.replace(/^build\//, "build/");
|
|
66
77
|
const absPath = resolve(artifact.path);
|
|
67
78
|
const rel = absPath.startsWith(outdirAbs + "/") ? absPath.slice(outdirAbs.length + 1) : basename(artifact.path);
|
|
68
79
|
const outBase = basename(artifact.path, extname(artifact.path));
|
|
@@ -80,7 +91,7 @@ export async function runBuild(config: BractJSConfig): Promise<void> {
|
|
|
80
91
|
}
|
|
81
92
|
}
|
|
82
93
|
|
|
83
|
-
// ──
|
|
94
|
+
// ── 5. Write manifest ──────────────────────────────────────────────────
|
|
84
95
|
const manifest = generateManifest({ clientEntry, rootChunk, routeChunks });
|
|
85
96
|
await writeManifest(manifest, "build");
|
|
86
97
|
console.log("[bract] build complete →", Object.keys(manifest.routes).length, "routes");
|