sordo 0.4.0 → 1.0.0
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/CHANGELOG.md +6 -116
- package/README.md +8 -175
- package/bin/sordo.ts +1 -4
- package/package.json +17 -41
- package/src/agents-md.ts +1 -0
- package/src/ai.ts +1 -0
- package/src/build.ts +1 -0
- package/src/client.ts +1 -0
- package/src/config.ts +1 -0
- package/src/dev.ts +1 -0
- package/src/index.ts +1 -55
- package/src/middleware.ts +1 -0
- package/src/plugin.ts +1 -0
- package/src/render.ts +1 -0
- package/src/router.ts +1 -0
- package/src/server.ts +1 -0
- package/CLAUDE.md +0 -124
- package/src/adapters/bun.ts +0 -59
- package/src/adapters/edge.ts +0 -75
- package/src/adapters/types.ts +0 -43
- package/src/agents-md/collect.ts +0 -113
- package/src/agents-md/generate.ts +0 -44
- package/src/agents-md/index.ts +0 -9
- package/src/agents-md/render.ts +0 -150
- package/src/agents-md/subprocess-entry.ts +0 -92
- package/src/agents-md/subprocess-runner.ts +0 -111
- package/src/agents-md/write.ts +0 -38
- package/src/agents-md/zod-to-json-schema.ts +0 -18
- package/src/ai/context.ts +0 -72
- package/src/ai/define.ts +0 -15
- package/src/ai/errors.ts +0 -51
- package/src/ai/index.ts +0 -36
- package/src/ai/middleware.ts +0 -21
- package/src/ai/registry.ts +0 -96
- package/src/ai/run.ts +0 -185
- package/src/ai/scan.ts +0 -42
- package/src/ai/stream.ts +0 -71
- package/src/ai/triggers.ts +0 -124
- package/src/ai/types.ts +0 -67
- package/src/ai/validate.ts +0 -82
- package/src/build/assets.ts +0 -48
- package/src/build/client-entry.ts +0 -43
- package/src/build/css.ts +0 -102
- package/src/build/embedded.ts +0 -66
- package/src/build/hash.ts +0 -21
- package/src/build/index.ts +0 -480
- package/src/build/macros/agents-hash.macro.ts +0 -9
- package/src/build/macros/agents.macro.ts +0 -21
- package/src/build/macros/env.macro.ts +0 -25
- package/src/build/macros/inline-assets.macro.ts +0 -28
- package/src/build/macros/manifest.macro.ts +0 -8
- package/src/build/macros/routes.macro.ts +0 -10
- package/src/build/page-entry.ts +0 -136
- package/src/build/scan-islands.ts +0 -39
- package/src/build/server-entry.ts +0 -256
- package/src/cli/ansi.ts +0 -41
- package/src/cli/build.ts +0 -195
- package/src/cli/commands/add/apply.ts +0 -31
- package/src/cli/commands/add/component-diff.ts +0 -116
- package/src/cli/commands/add/diff.ts +0 -153
- package/src/cli/commands/add/internal.ts +0 -41
- package/src/cli/commands/add/load-catalog.ts +0 -22
- package/src/cli/commands/add/peer-deps.ts +0 -115
- package/src/cli/commands/add/registry-fetch.ts +0 -122
- package/src/cli/commands/add/shadcn.ts +0 -285
- package/src/cli/commands/add/source.ts +0 -273
- package/src/cli/commands/add/stamper.ts +0 -73
- package/src/cli/commands/add/tokens.ts +0 -81
- package/src/cli/commands/add/ui-paths.ts +0 -113
- package/src/cli/commands/add.ts +0 -427
- package/src/cli/commands/deploy.ts +0 -143
- package/src/cli/commands/migrate.ts +0 -149
- package/src/cli/commands/secret.ts +0 -316
- package/src/cli/commands/ui/build.ts +0 -111
- package/src/cli/commands/ui/init.ts +0 -135
- package/src/cli/commands/ui/migrate/git-guard.ts +0 -19
- package/src/cli/commands/ui/migrate/radix.ts +0 -67
- package/src/cli/commands/ui/migrate/rtl.ts +0 -148
- package/src/cli/commands/ui/shadcn.ts +0 -82
- package/src/cli/commands/ui/view.ts +0 -63
- package/src/cli/commands/ui.ts +0 -86
- package/src/cli/commands/update.ts +0 -134
- package/src/cli/commands/upgrade.ts +0 -53
- package/src/cli/commands/view.ts +0 -34
- package/src/cli/dev.ts +0 -393
- package/src/cli/doctor/config-checks.ts +0 -63
- package/src/cli/doctor/deps.ts +0 -295
- package/src/cli/doctor/hydrate.ts +0 -65
- package/src/cli/doctor/monorepo.ts +0 -158
- package/src/cli/doctor/probes.ts +0 -16
- package/src/cli/doctor/report.ts +0 -72
- package/src/cli/doctor/toolchain.ts +0 -95
- package/src/cli/doctor/types.ts +0 -36
- package/src/cli/doctor.ts +0 -127
- package/src/cli/index.ts +0 -168
- package/src/cli/log.ts +0 -135
- package/src/cli/run/affected.ts +0 -79
- package/src/cli/run/cache-key.ts +0 -177
- package/src/cli/run/cache-store.ts +0 -0
- package/src/cli/run/files.ts +0 -96
- package/src/cli/run/git.ts +0 -13
- package/src/cli/run/runner.ts +0 -189
- package/src/cli/run/workspace.ts +0 -216
- package/src/cli/run.ts +0 -184
- package/src/cli/start.ts +0 -99
- package/src/cli/update-check.ts +0 -157
- package/src/client/index.ts +0 -65
- package/src/client/link.tsx +0 -61
- package/src/client/page.ts +0 -250
- package/src/config/define.ts +0 -5
- package/src/config/env.ts +0 -36
- package/src/config/load.ts +0 -152
- package/src/config/schema.ts +0 -135
- package/src/config/secrets.ts +0 -108
- package/src/dev/client.ts +0 -112
- package/src/dev/hot.ts +0 -24
- package/src/dev/index.ts +0 -4
- package/src/dev/tree.ts +0 -95
- package/src/dev/watcher.ts +0 -95
- package/src/internal/hmr-client.ts +0 -52
- package/src/internal/open-in-editor.ts +0 -23
- package/src/internal/runtime.ts +0 -30
- package/src/middleware/cookie-jar.ts +0 -135
- package/src/middleware/cookies.ts +0 -60
- package/src/middleware/index.ts +0 -127
- package/src/middleware/request-id.ts +0 -22
- package/src/middleware/response-helpers.ts +0 -25
- package/src/plugin/index.ts +0 -109
- package/src/render/bootstrap.ts +0 -44
- package/src/render/dev-error.tsx +0 -73
- package/src/render/index.tsx +0 -261
- package/src/render/island.tsx +0 -33
- package/src/render/meta.tsx +0 -48
- package/src/render/shell.tsx +0 -41
- package/src/router/conflict.ts +0 -20
- package/src/router/filesystem.ts +0 -37
- package/src/router/index.ts +0 -247
- package/src/router/match.ts +0 -91
- package/src/router/pattern.ts +0 -88
- package/src/server/index.ts +0 -250
- package/src/server/inline-assets.ts +0 -39
- package/src/types.ts +0 -53
- package/src/ui/schema.ts +0 -68
- package/src/ui/types.ts +0 -10
- package/templates/_internal/cn.ts +0 -6
- package/templates/_internal/slot.ts +0 -50
- package/templates/_internal/variants.ts +0 -1
- package/templates/themes/neutral/tokens.css +0 -46
- package/templates/themes/slate/tokens.css +0 -46
- package/templates/themes/stone/tokens.css +0 -46
- package/templates/themes/zinc/tokens.css +0 -46
- package/templates/tokens.css +0 -46
package/src/build/index.ts
DELETED
|
@@ -1,480 +0,0 @@
|
|
|
1
|
-
import { bunAdapter } from "../adapters/bun.ts";
|
|
2
|
-
import { edgeAdapter } from "../adapters/edge.ts";
|
|
3
|
-
import type { Adapter } from "../adapters/types.ts";
|
|
4
|
-
import { scanAgents, scanJobs, scanTools } from "../ai/scan.ts";
|
|
5
|
-
import type { JobSummary, Plugin } from "../plugin/index.ts";
|
|
6
|
-
import { scanRoutes } from "../router/filesystem.ts";
|
|
7
|
-
import { type BuiltAsset, copyAssets } from "./assets.ts";
|
|
8
|
-
import { generateClientEntry } from "./client-entry.ts";
|
|
9
|
-
import { buildCss, type CssOption } from "./css.ts";
|
|
10
|
-
import {
|
|
11
|
-
collectClientChunks,
|
|
12
|
-
type EmbeddedEntry,
|
|
13
|
-
generateEmbeddedManifest,
|
|
14
|
-
} from "./embedded.ts";
|
|
15
|
-
import {
|
|
16
|
-
generatePageEntry,
|
|
17
|
-
type HydrateDefault,
|
|
18
|
-
type HydratedPage,
|
|
19
|
-
scanHydratedPages,
|
|
20
|
-
stripServerExportsPlugin,
|
|
21
|
-
} from "./page-entry.ts";
|
|
22
|
-
import { type IslandEntry, scanIslands } from "./scan-islands.ts";
|
|
23
|
-
import { generateServerEntry } from "./server-entry.ts";
|
|
24
|
-
|
|
25
|
-
export type { BuiltAsset };
|
|
26
|
-
|
|
27
|
-
export interface ClientManifest {
|
|
28
|
-
entry: string | null;
|
|
29
|
-
islands: Record<string, string>;
|
|
30
|
-
// Whole-tree hydrated routes: bunPattern → page entry chunk URL.
|
|
31
|
-
pages: Record<string, string>;
|
|
32
|
-
// Hashed stylesheet URL. Present only when `css` is configured.
|
|
33
|
-
css?: string;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface BuildCounts {
|
|
37
|
-
routes: number;
|
|
38
|
-
islands: number;
|
|
39
|
-
agents: number;
|
|
40
|
-
tools: number;
|
|
41
|
-
jobs: number;
|
|
42
|
-
hydratedPages: number;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export interface BuildResult {
|
|
46
|
-
clientManifest: ClientManifest;
|
|
47
|
-
// Hydrated route → bytes of its entry chunk plus every chunk it statically
|
|
48
|
-
// imports (what a cold visit downloads). Empty when no route hydrates.
|
|
49
|
-
clientBytes: Record<string, number>;
|
|
50
|
-
serverEntry: string;
|
|
51
|
-
assets: BuiltAsset[];
|
|
52
|
-
counts: BuildCounts;
|
|
53
|
-
artifacts: string[];
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export interface BuildOptions {
|
|
57
|
-
appDir: string;
|
|
58
|
-
outDir?: string;
|
|
59
|
-
target?: "bun" | "edge";
|
|
60
|
-
mode?: "development" | "production";
|
|
61
|
-
port?: number;
|
|
62
|
-
// Emit a single standalone executable (Bun runtime + bundle) via
|
|
63
|
-
// `bun build --compile`. Only honored when target === "bun" && mode ===
|
|
64
|
-
// "production"; otherwise silently ignored. See spec 04 §"Single-binary
|
|
65
|
-
// executable".
|
|
66
|
-
compile?: boolean;
|
|
67
|
-
plugins?: Plugin[];
|
|
68
|
-
// `render.hydrate` from config: "pages" hydrates every route unless it
|
|
69
|
-
// exports `hydrate = false`. Default "off".
|
|
70
|
-
hydrate?: HydrateDefault;
|
|
71
|
-
// Stylesheet entry (`config.css`). Relative paths resolve against cwd.
|
|
72
|
-
css?: CssOption;
|
|
73
|
-
// `adapter.edge.assets`: with "external" the edge build writes client
|
|
74
|
-
// outputs + public/ to <outDir>/worker-assets instead of inlining them.
|
|
75
|
-
edgeAssets?: "inline" | "external";
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const PUBLIC_PREFIX = "/_sordo/client/";
|
|
79
|
-
|
|
80
|
-
export async function build(options: BuildOptions): Promise<BuildResult> {
|
|
81
|
-
const appDir = absolutize(options.appDir);
|
|
82
|
-
const outDir = absolutize(options.outDir ?? ".sordo");
|
|
83
|
-
const target = options.target ?? "bun";
|
|
84
|
-
const mode = options.mode ?? "production";
|
|
85
|
-
const plugins = options.plugins ?? [];
|
|
86
|
-
|
|
87
|
-
if (options.compile === true && target === "edge") {
|
|
88
|
-
throw new Error(
|
|
89
|
-
'sordo build: adapter.bun.compile is only supported with target "bun" (got target "edge"). Remove --compile or set target: "bun".',
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
// Compile path: embed assets into the binary. Bun + production only.
|
|
93
|
-
const compile =
|
|
94
|
-
options.compile === true && target === "bun" && mode === "production";
|
|
95
|
-
|
|
96
|
-
for (const p of plugins) {
|
|
97
|
-
if (!p.hooks?.onBuildStart) continue;
|
|
98
|
-
try {
|
|
99
|
-
await p.hooks.onBuildStart(options);
|
|
100
|
-
} catch (err) {
|
|
101
|
-
throw wrapHookError(p.name, "onBuildStart", err);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// genDir lives under appDir so generated entries can resolve react/react-dom
|
|
106
|
-
// via the normal upward node_modules walk. outDir holds only built artifacts.
|
|
107
|
-
const genDir = `${appDir}/sordo-gen`;
|
|
108
|
-
const clientOutDir = `${outDir}/client`;
|
|
109
|
-
const serverOutDir = `${outDir}/server`;
|
|
110
|
-
// Hashed chunk names change per edit; without this, stale chunks pile up
|
|
111
|
-
// and get globbed into compiled binaries.
|
|
112
|
-
await Bun.$`rm -rf ${clientOutDir} ${serverOutDir} ${`${outDir}/inline-assets.json`}`.quiet();
|
|
113
|
-
|
|
114
|
-
const islands = await scanIslands(appDir);
|
|
115
|
-
const entries = await scanRoutes(appDir);
|
|
116
|
-
const agentMods = await scanAgents(appDir);
|
|
117
|
-
const toolMods = await scanTools(appDir);
|
|
118
|
-
const jobMods = await scanJobs(appDir);
|
|
119
|
-
const hasUserMiddleware = await Bun.file(`${appDir}/middleware.ts`).exists();
|
|
120
|
-
|
|
121
|
-
if (plugins.length > 0) {
|
|
122
|
-
const summary: JobSummary[] = jobMods.map((j) => ({
|
|
123
|
-
name: j.name,
|
|
124
|
-
filePath: j.filePath,
|
|
125
|
-
}));
|
|
126
|
-
for (const p of plugins) {
|
|
127
|
-
if (!p.hooks?.onJobsCollect) continue;
|
|
128
|
-
try {
|
|
129
|
-
await p.hooks.onJobsCollect(summary);
|
|
130
|
-
} catch (err) {
|
|
131
|
-
throw wrapHookError(p.name, "onJobsCollect", err);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const manifest: ClientManifest = { entry: null, islands: {}, pages: {} };
|
|
137
|
-
const frameworkRoot = resolveFrameworkRoot();
|
|
138
|
-
const hydratedPages = await scanHydratedPages(
|
|
139
|
-
entries,
|
|
140
|
-
options.hydrate ?? "off",
|
|
141
|
-
);
|
|
142
|
-
let clientBytes: Record<string, number> = {};
|
|
143
|
-
|
|
144
|
-
const clientEntryPath = `${genDir}/client-entry.ts`;
|
|
145
|
-
await Bun.write(
|
|
146
|
-
clientEntryPath,
|
|
147
|
-
generateClientEntry(islands, { frameworkRoot }),
|
|
148
|
-
);
|
|
149
|
-
const pageEntryPaths = new Map<string, HydratedPage>();
|
|
150
|
-
for (const page of hydratedPages) {
|
|
151
|
-
const path = `${genDir}/${page.id}.ts`;
|
|
152
|
-
await Bun.write(path, generatePageEntry(page, { frameworkRoot }));
|
|
153
|
-
pageEntryPaths.set(path, page);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const entrypoints = [
|
|
157
|
-
...(islands.length > 0 ? [clientEntryPath] : []),
|
|
158
|
-
...pageEntryPaths.keys(),
|
|
159
|
-
];
|
|
160
|
-
|
|
161
|
-
// Zero-island, zero-hydrated-page project: write nothing to client/.
|
|
162
|
-
if (entrypoints.length > 0) {
|
|
163
|
-
// Under `bun test`, the process's first Bun.build that resolves several
|
|
164
|
-
// absolute route paths can spuriously report "Could not resolve".
|
|
165
|
-
// Resolving them once through the runtime resolver primes the shared cache.
|
|
166
|
-
for (const file of [
|
|
167
|
-
...islands.map((i) => i.filePath),
|
|
168
|
-
...hydratedPages.map((p) => p.entry.filePath),
|
|
169
|
-
]) {
|
|
170
|
-
Bun.resolveSync(file, appDir);
|
|
171
|
-
}
|
|
172
|
-
// One build for islands + every page so React and shared components
|
|
173
|
-
// land in common chunks instead of one copy per entry.
|
|
174
|
-
const clientResult = await Bun.build({
|
|
175
|
-
entrypoints,
|
|
176
|
-
target: "browser",
|
|
177
|
-
splitting: true,
|
|
178
|
-
minify: mode === "production",
|
|
179
|
-
outdir: clientOutDir,
|
|
180
|
-
naming: "[name]-[hash].[ext]",
|
|
181
|
-
// React picks its dev or prod build from NODE_ENV; without this the
|
|
182
|
-
// browser bundle ships React's development build in production.
|
|
183
|
-
define: { "process.env.NODE_ENV": JSON.stringify(mode) },
|
|
184
|
-
plugins: [
|
|
185
|
-
stripServerExportsPlugin(hydratedPages.map((p) => p.entry.filePath)),
|
|
186
|
-
],
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
if (!clientResult.success) {
|
|
190
|
-
const msgs = clientResult.logs
|
|
191
|
-
.map((l) => l.message ?? String(l))
|
|
192
|
-
.join("\n");
|
|
193
|
-
throw new Error(`sordo build: client bundle failed\n${msgs}`);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
populateClientManifest(
|
|
197
|
-
manifest,
|
|
198
|
-
clientResult.outputs,
|
|
199
|
-
islands,
|
|
200
|
-
hydratedPages,
|
|
201
|
-
clientOutDir,
|
|
202
|
-
);
|
|
203
|
-
clientBytes = await measurePageBytes(manifest.pages, clientOutDir);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
if (options.css !== undefined) {
|
|
207
|
-
const css =
|
|
208
|
-
typeof options.css === "string"
|
|
209
|
-
? absolutize(options.css)
|
|
210
|
-
: { ...options.css, entry: absolutize(options.css.entry) };
|
|
211
|
-
const cssOut = await buildCss({
|
|
212
|
-
css,
|
|
213
|
-
appDir,
|
|
214
|
-
clientOutDir,
|
|
215
|
-
publicPrefix: PUBLIC_PREFIX,
|
|
216
|
-
mode,
|
|
217
|
-
});
|
|
218
|
-
manifest.css = cssOut.href;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// Non-compiled servers (bun + edge) serve every client output (island and
|
|
222
|
-
// page chunks, the CSS sheet and its assets) from bytes inlined at build
|
|
223
|
-
// time; compile mode embeds client/ into the binary instead.
|
|
224
|
-
let inlineAssetsPath: string | undefined;
|
|
225
|
-
const externalAssets = target === "edge" && options.edgeAssets === "external";
|
|
226
|
-
if (!compile && !externalAssets) {
|
|
227
|
-
const clientFiles = (await collectClientChunks(clientOutDir)).map((c) => ({
|
|
228
|
-
url: c.url,
|
|
229
|
-
path: c.src,
|
|
230
|
-
}));
|
|
231
|
-
if (clientFiles.length > 0) {
|
|
232
|
-
inlineAssetsPath = `${outDir}/inline-assets.json`;
|
|
233
|
-
await Bun.write(inlineAssetsPath, JSON.stringify(clientFiles, null, 2));
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
// Manifest must hit disk before the server entry is generated — the server
|
|
238
|
-
// entry pulls it back in via the MANIFEST macro, which reads from this path
|
|
239
|
-
// at bundle time.
|
|
240
|
-
const manifestPath = `${outDir}/manifest.json`;
|
|
241
|
-
await Bun.write(manifestPath, JSON.stringify(manifest, null, 2));
|
|
242
|
-
|
|
243
|
-
const routesMacroPath = `${frameworkRoot}/build/macros/routes.macro.ts`;
|
|
244
|
-
const envMacroPath = `${frameworkRoot}/build/macros/env.macro.ts`;
|
|
245
|
-
const manifestMacroPath = `${frameworkRoot}/build/macros/manifest.macro.ts`;
|
|
246
|
-
const agentsHashMacroPath = `${frameworkRoot}/build/macros/agents-hash.macro.ts`;
|
|
247
|
-
const agentsMacroPath = `${frameworkRoot}/build/macros/agents.macro.ts`;
|
|
248
|
-
const inlineAssetsMacroPath = `${frameworkRoot}/build/macros/inline-assets.macro.ts`;
|
|
249
|
-
|
|
250
|
-
const serverEntrySource = generateServerEntry({
|
|
251
|
-
appDir,
|
|
252
|
-
entries,
|
|
253
|
-
agents: agentMods,
|
|
254
|
-
tools: toolMods,
|
|
255
|
-
jobs: jobMods,
|
|
256
|
-
hasUserMiddleware,
|
|
257
|
-
frameworkRoot,
|
|
258
|
-
routesMacroPath,
|
|
259
|
-
envMacroPath,
|
|
260
|
-
manifestMacroPath,
|
|
261
|
-
agentsHashMacroPath,
|
|
262
|
-
agentsMacroPath,
|
|
263
|
-
manifestPath,
|
|
264
|
-
inlineAssets: inlineAssetsPath
|
|
265
|
-
? { macroPath: inlineAssetsMacroPath, listPath: inlineAssetsPath }
|
|
266
|
-
: undefined,
|
|
267
|
-
target,
|
|
268
|
-
port: options.port,
|
|
269
|
-
compile,
|
|
270
|
-
});
|
|
271
|
-
const serverEntryPath = `${genDir}/server-entry.ts`;
|
|
272
|
-
await Bun.write(serverEntryPath, serverEntrySource);
|
|
273
|
-
|
|
274
|
-
// In compile mode the server entry imports ./embedded-manifest.ts; generate it
|
|
275
|
-
// before the compile step so `with { type: "file" }` imports resolve. Client
|
|
276
|
-
// chunks already exist on disk (the client build ran above); public assets are
|
|
277
|
-
// enumerated without writing the dist/assets sidecar.
|
|
278
|
-
if (compile) {
|
|
279
|
-
const publicAssets = await copyAssets(appDir, outDir, { write: false });
|
|
280
|
-
const chunkEntries = await collectClientChunks(clientOutDir);
|
|
281
|
-
const embedded: EmbeddedEntry[] = [
|
|
282
|
-
...publicAssets.map((a) => ({ url: a.publicPath, src: a.src })),
|
|
283
|
-
...chunkEntries,
|
|
284
|
-
];
|
|
285
|
-
await Bun.write(
|
|
286
|
-
`${genDir}/embedded-manifest.ts`,
|
|
287
|
-
generateEmbeddedManifest(embedded),
|
|
288
|
-
);
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
const adapter: Adapter = target === "edge" ? edgeAdapter : bunAdapter;
|
|
292
|
-
|
|
293
|
-
// Server bundle is intentionally NOT minified: spec acceptance requires the
|
|
294
|
-
// inlined route table to be grep-verifiable in the output, and minification
|
|
295
|
-
// mangles property names on object literals.
|
|
296
|
-
//
|
|
297
|
-
// Compile mode skips this stage entirely: `bun build --compile` runs against
|
|
298
|
-
// the source entry (see bunAdapter) so file/macro import attributes survive.
|
|
299
|
-
let serverEntryOut: string | undefined;
|
|
300
|
-
if (!compile) {
|
|
301
|
-
const serverResult = await Bun.build({
|
|
302
|
-
entrypoints: [serverEntryPath],
|
|
303
|
-
target: adapter.buildTarget,
|
|
304
|
-
outdir: serverOutDir,
|
|
305
|
-
minify: false,
|
|
306
|
-
});
|
|
307
|
-
|
|
308
|
-
if (!serverResult.success) {
|
|
309
|
-
const msgs = serverResult.logs
|
|
310
|
-
.map((l) => l.message ?? String(l))
|
|
311
|
-
.join("\n");
|
|
312
|
-
throw new Error(`sordo build: server bundle failed\n${msgs}`);
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
const serverOutput =
|
|
316
|
-
serverResult.outputs.find((o) => o.kind === "entry-point") ??
|
|
317
|
-
serverResult.outputs[0];
|
|
318
|
-
serverEntryOut = serverOutput
|
|
319
|
-
? serverOutput.path
|
|
320
|
-
: `${serverOutDir}/server-entry.js`;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
const assets = await copyAssets(appDir, outDir, { write: !compile });
|
|
324
|
-
|
|
325
|
-
const emitted = await adapter.emit(
|
|
326
|
-
{ serverEntryOut, serverEntrySrc: serverEntryPath, assets, clientOutDir },
|
|
327
|
-
{ appDir, outDir, mode, compile, edgeAssets: options.edgeAssets },
|
|
328
|
-
);
|
|
329
|
-
|
|
330
|
-
const result: BuildResult = {
|
|
331
|
-
clientManifest: manifest,
|
|
332
|
-
clientBytes,
|
|
333
|
-
serverEntry: emitted.serverEntry,
|
|
334
|
-
assets: emitted.assets,
|
|
335
|
-
counts: {
|
|
336
|
-
routes: entries.length,
|
|
337
|
-
islands: islands.length,
|
|
338
|
-
agents: agentMods.length,
|
|
339
|
-
tools: toolMods.length,
|
|
340
|
-
jobs: jobMods.length,
|
|
341
|
-
hydratedPages: hydratedPages.length,
|
|
342
|
-
},
|
|
343
|
-
artifacts: emitted.extraFiles ?? [],
|
|
344
|
-
};
|
|
345
|
-
|
|
346
|
-
for (const p of plugins) {
|
|
347
|
-
if (!p.hooks?.onBuildEnd) continue;
|
|
348
|
-
try {
|
|
349
|
-
await p.hooks.onBuildEnd(result);
|
|
350
|
-
} catch (err) {
|
|
351
|
-
throw wrapHookError(p.name, "onBuildEnd", err);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
return result;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
function wrapHookError(name: string, hook: string, err: unknown): Error {
|
|
359
|
-
const msg = (err as Error)?.message ?? String(err);
|
|
360
|
-
const wrapped = new Error(`[plugin ${name}] ${hook}: ${msg}`);
|
|
361
|
-
(wrapped as Error & { cause?: unknown }).cause = err;
|
|
362
|
-
return wrapped;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
function populateClientManifest(
|
|
366
|
-
manifest: ClientManifest,
|
|
367
|
-
outputs: Array<{ path: string; kind: string }>,
|
|
368
|
-
islands: IslandEntry[],
|
|
369
|
-
pages: HydratedPage[],
|
|
370
|
-
clientOutDir: string,
|
|
371
|
-
): void {
|
|
372
|
-
const pageById = new Map(pages.map((p) => [p.id, p]));
|
|
373
|
-
for (const out of outputs) {
|
|
374
|
-
if (out.kind !== "entry-point") continue;
|
|
375
|
-
const stem = outputStem(out.path);
|
|
376
|
-
const page = pageById.get(stem);
|
|
377
|
-
if (page) {
|
|
378
|
-
manifest.pages[page.entry.bunPattern] = toPublicUrl(
|
|
379
|
-
out.path,
|
|
380
|
-
clientOutDir,
|
|
381
|
-
);
|
|
382
|
-
} else if (stem === "client-entry") {
|
|
383
|
-
manifest.entry = toPublicUrl(out.path, clientOutDir);
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
// Map island source paths to chunk URLs by inspecting output filenames.
|
|
388
|
-
// `splitting: true` emits chunks named after the source's basename plus hash.
|
|
389
|
-
// We match by basename.
|
|
390
|
-
const remainingIslands = new Map<string, IslandEntry>();
|
|
391
|
-
for (const i of islands) {
|
|
392
|
-
const base = i.relPath.replace(/\.[tj]sx?$/, "");
|
|
393
|
-
remainingIslands.set(base.split("/").pop() ?? base, i);
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
for (const out of outputs) {
|
|
397
|
-
if (out.kind === "entry-point") continue;
|
|
398
|
-
const island = remainingIslands.get(outputStem(out.path));
|
|
399
|
-
if (island) {
|
|
400
|
-
manifest.islands[island.name] = toPublicUrl(out.path, clientOutDir);
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
// For any islands we couldn't disambiguate via filename, fall back to the
|
|
405
|
-
// entry chunk so hydration still has *something* to load. (Splitting may
|
|
406
|
-
// inline a small island directly into the entry, in which case there's no
|
|
407
|
-
// separate chunk to surface.)
|
|
408
|
-
for (const i of islands) {
|
|
409
|
-
if (!manifest.islands[i.name] && manifest.entry) {
|
|
410
|
-
manifest.islands[i.name] = manifest.entry;
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
function outputStem(path: string): string {
|
|
416
|
-
const fname = path.split("/").pop() ?? "";
|
|
417
|
-
return fname.replace(/-[A-Za-z0-9]+\.(js|mjs)$/, "");
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
const STATIC_IMPORT_RE =
|
|
421
|
-
/(?:import|export)\s*(?:[^"'`;]*?from\s*)?["'](\.\/[^"']+)["']/g;
|
|
422
|
-
|
|
423
|
-
// Sum each hydrated route's entry chunk and its static import closure. Chunks
|
|
424
|
-
// shared with other routes (React) count toward every route that needs them.
|
|
425
|
-
async function measurePageBytes(
|
|
426
|
-
pages: Record<string, string>,
|
|
427
|
-
clientOutDir: string,
|
|
428
|
-
): Promise<Record<string, number>> {
|
|
429
|
-
const sizes = new Map<string, { bytes: number; deps: string[] }>();
|
|
430
|
-
const read = async (rel: string) => {
|
|
431
|
-
const hit = sizes.get(rel);
|
|
432
|
-
if (hit) return hit;
|
|
433
|
-
const file = Bun.file(`${clientOutDir}/${rel}`);
|
|
434
|
-
const text = (await file.exists()) ? await file.text() : "";
|
|
435
|
-
const deps = [...text.matchAll(STATIC_IMPORT_RE)]
|
|
436
|
-
.map((m) => (m[1] ?? "").slice(2))
|
|
437
|
-
.filter(Boolean);
|
|
438
|
-
const info = { bytes: new TextEncoder().encode(text).length, deps };
|
|
439
|
-
sizes.set(rel, info);
|
|
440
|
-
return info;
|
|
441
|
-
};
|
|
442
|
-
const out: Record<string, number> = {};
|
|
443
|
-
for (const [route, url] of Object.entries(pages)) {
|
|
444
|
-
const seen = new Set<string>();
|
|
445
|
-
const queue = [url.slice(PUBLIC_PREFIX.length)];
|
|
446
|
-
let total = 0;
|
|
447
|
-
while (queue.length > 0) {
|
|
448
|
-
const rel = queue.pop() as string;
|
|
449
|
-
if (seen.has(rel)) continue;
|
|
450
|
-
seen.add(rel);
|
|
451
|
-
const info = await read(rel);
|
|
452
|
-
total += info.bytes;
|
|
453
|
-
queue.push(...info.deps);
|
|
454
|
-
}
|
|
455
|
-
out[route] = total;
|
|
456
|
-
}
|
|
457
|
-
return out;
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
function toPublicUrl(absPath: string, clientOutDir: string): string {
|
|
461
|
-
const rel = absPath.startsWith(clientOutDir)
|
|
462
|
-
? absPath.slice(clientOutDir.length)
|
|
463
|
-
: `/${absPath.split("/").pop() ?? ""}`;
|
|
464
|
-
return PUBLIC_PREFIX + rel.replace(/^\/+/, "");
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
function absolutize(p: string): string {
|
|
468
|
-
if (p.startsWith("/")) return p.replace(/\/+$/, "");
|
|
469
|
-
return (
|
|
470
|
-
process.cwd().replace(/\/+$/, "") +
|
|
471
|
-
"/" +
|
|
472
|
-
p.replace(/^\.\//, "").replace(/\/+$/, "")
|
|
473
|
-
);
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
function resolveFrameworkRoot(): string {
|
|
477
|
-
// import.meta.dir is set by Bun for ES modules — points at src/build/.
|
|
478
|
-
const here = import.meta.dir;
|
|
479
|
-
return here.replace(/\/build\/?$/, "");
|
|
480
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
// Bun macro: hashes AGENTS.md (if present) for dev-banner cache busting.
|
|
2
|
-
// Returns "" when the file is absent. Consumed by spec 05 (dev/HMR) — declared
|
|
3
|
-
// here so the macro contract from spec 04 holds even before dev paths land.
|
|
4
|
-
export async function AGENTS_HASH(appDir: string): Promise<string> {
|
|
5
|
-
const file = Bun.file(`${appDir.replace(/\/+$/, "")}/AGENTS.md`);
|
|
6
|
-
if (!(await file.exists())) return "";
|
|
7
|
-
const bytes = await file.bytes();
|
|
8
|
-
return Bun.hash.xxHash64(bytes).toString(16);
|
|
9
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type ScannedModule,
|
|
3
|
-
scanAgents,
|
|
4
|
-
scanJobs,
|
|
5
|
-
scanTools,
|
|
6
|
-
} from "../../ai/scan.ts";
|
|
7
|
-
|
|
8
|
-
// Bun macros: invoked at build time via
|
|
9
|
-
// import { AGENTS, TOOLS, JOBS } from "...agents.macro.ts" with { type: "macro" }
|
|
10
|
-
// Return values are inlined as JSON literals; runtime never scans the FS.
|
|
11
|
-
export async function AGENTS(appDir: string): Promise<ScannedModule[]> {
|
|
12
|
-
return await scanAgents(appDir);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export async function TOOLS(appDir: string): Promise<ScannedModule[]> {
|
|
16
|
-
return await scanTools(appDir);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export async function JOBS(appDir: string): Promise<ScannedModule[]> {
|
|
20
|
-
return await scanJobs(appDir);
|
|
21
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { loadConfig } from "../../config/load.ts";
|
|
2
|
-
|
|
3
|
-
// Build-time macro: returns the literal record of public env values that will
|
|
4
|
-
// be inlined into the server bundle. Source: `config.env.public` names plus
|
|
5
|
-
// `PREFIX_*` glob entries matched against the build host's `Bun.env`. Absent
|
|
6
|
-
// names become the empty string per spec 08.
|
|
7
|
-
export async function PUBLIC_ENV(): Promise<Record<string, string>> {
|
|
8
|
-
const { config } = await loadConfig();
|
|
9
|
-
const env = (typeof Bun !== "undefined" ? Bun.env : process.env) as Record<
|
|
10
|
-
string,
|
|
11
|
-
string | undefined
|
|
12
|
-
>;
|
|
13
|
-
const out: Record<string, string> = {};
|
|
14
|
-
for (const entry of config.env.public) {
|
|
15
|
-
if (entry.endsWith("*")) {
|
|
16
|
-
const prefix = entry.slice(0, -1);
|
|
17
|
-
for (const k of Object.keys(env)) {
|
|
18
|
-
if (k.startsWith(prefix)) out[k] = env[k] ?? "";
|
|
19
|
-
}
|
|
20
|
-
} else {
|
|
21
|
-
out[entry] = env[entry] ?? "";
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return out;
|
|
25
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { InlineAsset } from "../../server/inline-assets.ts";
|
|
2
|
-
|
|
3
|
-
// Bun macro: reads the build's client outputs (listed in a JSON file the build
|
|
4
|
-
// writes) and inlines their bytes into the server bundle, so the bun and edge
|
|
5
|
-
// servers serve them with no filesystem access at runtime.
|
|
6
|
-
// import { INLINE_ASSETS } from "...inline-assets.macro.ts" with { type: "macro" }
|
|
7
|
-
// const A = await INLINE_ASSETS("/abs/out/inline-assets.json")
|
|
8
|
-
export async function INLINE_ASSETS(
|
|
9
|
-
listPath: string,
|
|
10
|
-
): Promise<Record<string, InlineAsset>> {
|
|
11
|
-
const list = (await Bun.file(listPath).json()) as Array<{
|
|
12
|
-
url: string;
|
|
13
|
-
path: string;
|
|
14
|
-
}>;
|
|
15
|
-
const out: Record<string, InlineAsset> = {};
|
|
16
|
-
for (const { url, path } of list) {
|
|
17
|
-
const file = Bun.file(path);
|
|
18
|
-
const type = file.type || "application/octet-stream";
|
|
19
|
-
out[url] = type.startsWith("text/")
|
|
20
|
-
? { type, body: await file.text(), base64: false }
|
|
21
|
-
: {
|
|
22
|
-
type,
|
|
23
|
-
body: Buffer.from(await file.arrayBuffer()).toString("base64"),
|
|
24
|
-
base64: true,
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
return out;
|
|
28
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
// Bun macro: reads the on-disk client manifest produced by the build pipeline
|
|
2
|
-
// and inlines it into the importer as a JSON literal. Invoked from the
|
|
3
|
-
// generated server entry as:
|
|
4
|
-
// import { MANIFEST } from "...manifest.macro.ts" with { type: "macro" }
|
|
5
|
-
// const M = await MANIFEST("/abs/path/to/manifest.json")
|
|
6
|
-
export async function MANIFEST(path: string) {
|
|
7
|
-
return await Bun.file(path).json();
|
|
8
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { scanRoutes } from "../../router/filesystem.ts";
|
|
2
|
-
|
|
3
|
-
// Bun macro: invoked at build time via
|
|
4
|
-
// import { ROUTES } from "...routes.macro.ts" with { type: "macro" }
|
|
5
|
-
// const TABLE = await ROUTES("/abs/app/dir")
|
|
6
|
-
// The macro return value is inlined as a JSON literal — neither this file nor
|
|
7
|
-
// `scanRoutes` ends up in the production server bundle. See spec 04.
|
|
8
|
-
export async function ROUTES(appDir: string) {
|
|
9
|
-
return await scanRoutes(appDir);
|
|
10
|
-
}
|