@bractjs/bractjs 0.1.9 → 0.1.11

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bractjs/bractjs",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
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",
@@ -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";
@@ -19,7 +19,14 @@ export async function runBuild(config: BractJSConfig): Promise<void> {
19
19
  const routeFilePaths = routes.map((r) => join(appDir, r.filePath));
20
20
  const rootFilePath = join(appDir, "root.tsx");
21
21
 
22
- // ── 1. Server bundle ────────────────────────────────────────────────────
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
- // ── 2. Client bundle (code-split) ───────────────────────────────────────
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
- // ── 3. Hash + rename output files ──────────────────────────────────────
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 publicPath = "/" + hashedPath.replace(/^build\//, "build/");
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
- // ── 4. Write manifest ──────────────────────────────────────────────────
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");
@@ -18,7 +18,7 @@ export const hmrClientScript: string = `
18
18
  import('/_bractjs/devtools.js').then(function(m) {
19
19
  if (typeof m.injectDevtools === 'function') m.injectDevtools();
20
20
  }).catch(function() {
21
- // DevTools module not available skip silently.
21
+ // DevTools module not available - skip silently.
22
22
  });
23
23
  }
24
24
 
@@ -32,7 +32,7 @@ export const hmrClientScript: string = `
32
32
  } else if (msg.type === "hmr:route" && msg.pattern != null && msg.chunkUrl) {
33
33
  // Validate chunk URL is a same-origin relative path before importing.
34
34
  // Prevents a compromised/MITM'd dev WS from executing arbitrary URLs.
35
- if (typeof msg.chunkUrl !== 'string' || !/^\/build\//.test(msg.chunkUrl)) {
35
+ if (typeof msg.chunkUrl !== 'string' || !/^\\/build\\//.test(msg.chunkUrl)) {
36
36
  return;
37
37
  }
38
38
  // Cache-bust so the browser re-fetches the rebuilt chunk.