@yourrealm/sdk 0.0.0-alpha.1378.ce03c8dc
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/LICENSE-EXCEPTION +26 -0
- package/README.md +34 -0
- package/dist/chunk-3R6KEFOI.js +22 -0
- package/dist/chunk-67BDAMYX.js +376 -0
- package/dist/chunk-AITGS27R.js +139 -0
- package/dist/chunk-CMAEHQ4F.js +6 -0
- package/dist/chunk-MLKGABMK.js +9 -0
- package/dist/chunk-O3UIK34B.js +1430 -0
- package/dist/chunk-VHTUSZUX.js +176 -0
- package/dist/cli.js +9006 -0
- package/dist/docker.js +54 -0
- package/dist/index.js +1053 -0
- package/dist/ingress.js +436 -0
- package/dist/jsx-runtime.js +2 -0
- package/dist/preact.js +22 -0
- package/dist/service-url.js +11 -0
- package/dist/services.js +213 -0
- package/dist/test.js +5069 -0
- package/dist/ui.js +254 -0
- package/dist/worker-protocol.js +89 -0
- package/package.json +112 -0
- package/src/app-icon.ts +74 -0
- package/src/apply.ts +52 -0
- package/src/bundle-ui.ts +211 -0
- package/src/bundle.ts +546 -0
- package/src/cli/build-dev-landing.ts +84 -0
- package/src/cli/build-install-panel.ts +90 -0
- package/src/cli/build-runtime.ts +133 -0
- package/src/cli/build.ts +63 -0
- package/src/cli/dev.ts +107 -0
- package/src/cli/down.ts +60 -0
- package/src/cli/main.ts +56 -0
- package/src/cli/test.ts +61 -0
- package/src/cli/validate.ts +37 -0
- package/src/compile.ts +100 -0
- package/src/create-app.ts +982 -0
- package/src/deep-merge.ts +33 -0
- package/src/dev/fixture.ts +48 -0
- package/src/dev/install-handler.ts +383 -0
- package/src/dev/server.ts +968 -0
- package/src/dev/stack.ts +108 -0
- package/src/dev/state.ts +159 -0
- package/src/docker.ts +96 -0
- package/src/errors.ts +61 -0
- package/src/factory.ts +481 -0
- package/src/garage.ts +56 -0
- package/src/generator/hash.ts +6 -0
- package/src/generator/resolve-refs.ts +207 -0
- package/src/grants-builder.ts +100 -0
- package/src/grants.ts +260 -0
- package/src/home-api.ts +172 -0
- package/src/home-cookie.ts +10 -0
- package/src/home-registry.ts +120 -0
- package/src/home.ts +187 -0
- package/src/host-registry.ts +143 -0
- package/src/http-header.ts +20 -0
- package/src/identifiers.ts +49 -0
- package/src/index.ts +66 -0
- package/src/info.ts +64 -0
- package/src/ini.ts +50 -0
- package/src/json.ts +14 -0
- package/src/jsx-runtime/index.ts +5 -0
- package/src/keys.ts +29 -0
- package/src/mysql.ts +56 -0
- package/src/pack-build.ts +108 -0
- package/src/pack.ts +115 -0
- package/src/peer-registry.ts +121 -0
- package/src/peer-world.ts +117 -0
- package/src/permission-meta.ts +116 -0
- package/src/permissions.ts +108 -0
- package/src/pkg-root.ts +34 -0
- package/src/postgres.ts +79 -0
- package/src/preact/index.ts +27 -0
- package/src/redis.ts +43 -0
- package/src/ref.ts +271 -0
- package/src/remote-registry.ts +33 -0
- package/src/required-host-kinds.ts +110 -0
- package/src/resolve-context.ts +111 -0
- package/src/resolve.ts +471 -0
- package/src/runtime/docker/compose/compose-schema.ts +118 -0
- package/src/runtime/docker/compose/convert-to-docker-compose.ts +278 -0
- package/src/runtime/docker/compose/default-hardening.ts +21 -0
- package/src/runtime/docker/compose/effects.ts +107 -0
- package/src/runtime/docker/compose/index.ts +17 -0
- package/src/runtime/docker/compose/labels.ts +39 -0
- package/src/runtime/docker/compose/types.ts +78 -0
- package/src/runtime/docker/home-proxy-server/index.ts +177 -0
- package/src/runtime/docker/home-proxy-server/protocol.ts +53 -0
- package/src/runtime/docker/ingress/build-config.ts +819 -0
- package/src/runtime/docker/ingress/index.ts +16 -0
- package/src/runtime/docker/ingress/types.ts +182 -0
- package/src/runtime/docker/log-frames.ts +121 -0
- package/src/runtime/docker/logs-server/index.ts +366 -0
- package/src/runtime/docker/spawn-server/context-key.ts +82 -0
- package/src/runtime/docker/spawn-server/index.ts +492 -0
- package/src/runtime/docker/spawn-server/protocol.ts +70 -0
- package/src/runtime/docker/spawn-server/spec.ts +122 -0
- package/src/runtime/docker/stats-server/disks.ts +161 -0
- package/src/runtime/docker/stats-server/index.ts +322 -0
- package/src/runtime/home-client/index.ts +71 -0
- package/src/runtime/log-line.ts +24 -0
- package/src/runtime/logs-client/index.ts +175 -0
- package/src/runtime/spawn-client/index.ts +93 -0
- package/src/runtime/spawn-client/kaniko.ts +79 -0
- package/src/runtime/stats-client/index.ts +65 -0
- package/src/runtime/stats-sample.ts +95 -0
- package/src/safe-json.ts +37 -0
- package/src/sandbox.ts +1209 -0
- package/src/schema/build-apps.ts +38 -0
- package/src/schema/home.ts +217 -0
- package/src/schema/host.ts +792 -0
- package/src/schema/inputs.ts +26 -0
- package/src/schema/nodes.ts +75 -0
- package/src/schema/peer.ts +400 -0
- package/src/schema/public-domain.ts +116 -0
- package/src/schema/remote.ts +74 -0
- package/src/security.ts +594 -0
- package/src/serialize.ts +21 -0
- package/src/service-definition.ts +284 -0
- package/src/service-url.ts +64 -0
- package/src/service.ts +39 -0
- package/src/services/index.ts +5 -0
- package/src/shared.ts +65 -0
- package/src/speculative-silo.ts +96 -0
- package/src/stable-secret.ts +14 -0
- package/src/surfaces.ts +264 -0
- package/src/tailwind-bin.ts +56 -0
- package/src/test/boot.ts +192 -0
- package/src/test/compile.ts +501 -0
- package/src/test/describe.ts +117 -0
- package/src/test/index.ts +11 -0
- package/src/test/ingress-fixture.ts +37 -0
- package/src/test/types.ts +318 -0
- package/src/trusted-headers.ts +79 -0
- package/src/types.ts +126 -0
- package/src/ui/components/aside.tsx +96 -0
- package/src/ui/components/badge.tsx +42 -0
- package/src/ui/components/button.tsx +59 -0
- package/src/ui/components/card.tsx +106 -0
- package/src/ui/components/checkbox.tsx +37 -0
- package/src/ui/components/code-block.tsx +29 -0
- package/src/ui/components/combobox.tsx +119 -0
- package/src/ui/components/config-field.tsx +284 -0
- package/src/ui/components/dialog.tsx +137 -0
- package/src/ui/components/domain-editor.tsx +317 -0
- package/src/ui/components/domain-list.ts +205 -0
- package/src/ui/components/dropdown-menu.tsx +73 -0
- package/src/ui/components/empty-state.tsx +51 -0
- package/src/ui/components/highlight.ts +59 -0
- package/src/ui/components/icons.tsx +101 -0
- package/src/ui/components/image-posture.tsx +85 -0
- package/src/ui/components/input.tsx +28 -0
- package/src/ui/components/label.tsx +16 -0
- package/src/ui/components/line-chart.tsx +113 -0
- package/src/ui/components/page.tsx +39 -0
- package/src/ui/components/permission-row.tsx +262 -0
- package/src/ui/components/permission-section.tsx +51 -0
- package/src/ui/components/pie-chart.tsx +245 -0
- package/src/ui/components/schema-block.tsx +60 -0
- package/src/ui/components/separator.tsx +42 -0
- package/src/ui/components/sheet.tsx +130 -0
- package/src/ui/components/sidebar.tsx +650 -0
- package/src/ui/components/silo-picker.tsx +510 -0
- package/src/ui/components/skeleton.tsx +13 -0
- package/src/ui/components/sonner.tsx +33 -0
- package/src/ui/components/switch.tsx +58 -0
- package/src/ui/components/table-view.ts +219 -0
- package/src/ui/components/table.tsx +506 -0
- package/src/ui/components/tabs.tsx +59 -0
- package/src/ui/components/timeago.tsx +84 -0
- package/src/ui/components/tooltip.tsx +56 -0
- package/src/ui/components.json +21 -0
- package/src/ui/dev/dev-shell.tsx +145 -0
- package/src/ui/home/home-grid.tsx +177 -0
- package/src/ui/hooks/use-mobile.ts +19 -0
- package/src/ui/index.ts +189 -0
- package/src/ui/install/adapter.ts +193 -0
- package/src/ui/install/deploy-targets-picker.tsx +185 -0
- package/src/ui/install/install-app-panel.tsx +912 -0
- package/src/ui/install/install-error.tsx +62 -0
- package/src/ui/install/perms-inactive.ts +50 -0
- package/src/ui/install/required-fields.ts +37 -0
- package/src/ui/install/tabs-form.tsx +557 -0
- package/src/ui/tokens.css +279 -0
- package/src/ui/utils.ts +78 -0
- package/src/ui-error.ts +139 -0
- package/src/ui-runtime/dev-landing-entry.tsx +258 -0
- package/src/ui-runtime/index.ts +83 -0
- package/src/ui-runtime/install-entry.tsx +119 -0
- package/src/ui-runtime/mount.ts +367 -0
- package/src/ui-runtime/runtime.css +56 -0
- package/src/ui-surface.ts +451 -0
- package/src/valkey.ts +43 -0
- package/src/worker/extract-tar.ts +125 -0
- package/src/worker/identity.ts +183 -0
- package/src/worker/index.ts +16 -0
- package/src/worker/public-ip.ts +92 -0
- package/src/worker/queue.ts +54 -0
- package/src/worker/reconcile.ts +127 -0
- package/src/worker/start-worker.ts +227 -0
- package/src/worker/ui-proxy.ts +335 -0
- package/src/worker/uplink.ts +523 -0
- package/src/worker/validate.ts +34 -0
- package/src/worker/verify-relay.ts +102 -0
- package/src/worker-protocol/app-dirs.ts +94 -0
- package/src/worker-protocol/home-proxy-paths.ts +76 -0
- package/src/worker-protocol/index.ts +55 -0
- package/src/worker-protocol/ingress.ts +166 -0
- package/src/worker-protocol/logs-socket-path.ts +50 -0
- package/src/worker-protocol/networks.ts +39 -0
- package/src/worker-protocol/node-version.ts +70 -0
- package/src/worker-protocol/silo-paths.ts +114 -0
- package/src/worker-protocol/spawn-paths.ts +165 -0
- package/src/worker-protocol/stats-socket-path.ts +40 -0
- package/src/worker-protocol/update-files.ts +77 -0
- package/src/worker-protocol/uplink/constants.ts +86 -0
- package/src/worker-protocol/uplink/errors.ts +61 -0
- package/src/worker-protocol/uplink/frame.ts +114 -0
- package/src/worker-protocol/uplink/identity.ts +40 -0
- package/src/worker-protocol/uplink/index.ts +63 -0
- package/src/worker-protocol/uplink/methods.ts +462 -0
- package/src/worker-protocol/uplink/mux.ts +646 -0
- package/src/worker-protocol/uplink/protocol.ts +11 -0
- package/src/worker-protocol/uplink/rpc.ts +309 -0
- package/src/worker-protocol/uplink/session.ts +540 -0
- package/src/worker-protocol/uplink/test-support.ts +188 -0
- package/src/worker-protocol/worker-mount.ts +27 -0
- package/src/worker-protocol/worker-state.ts +190 -0
- package/src/xml.ts +49 -0
- package/src/yaml.ts +15 -0
package/src/bundle-ui.ts
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
// Per-surface iframe bundling.
|
|
2
|
+
//
|
|
3
|
+
// Each `ui.pages.*` / `ui.widgets.*` declared on a realm.ts app becomes its own
|
|
4
|
+
// ESM bundle + per-surface CSS file. Both are content-addressed (sha-256 of the
|
|
5
|
+
// JS bytes — the CSS is a sibling of the same hash) and served by Home at
|
|
6
|
+
// `/api/ui-bundles/<hash>.{js,css}`. The iframe HTML loads the runtime first
|
|
7
|
+
// (chrome + tokens + @yourrealm/sdk/ui base), then the per-surface CSS, then
|
|
8
|
+
// the surface bundle; the runtime mounts the bundle's default export.
|
|
9
|
+
//
|
|
10
|
+
// The SDK subpaths and `zod` are externalized (EXTERNAL_SPECIFIERS below) so
|
|
11
|
+
// Home's iframe importmap resolves them once for every surface: inlined, a
|
|
12
|
+
// surface is ~414 KB raw (~71 KB gzipped); external, single-digit KB.
|
|
13
|
+
//
|
|
14
|
+
// CSS comes from Tailwind v4 with `@source` pointing at the per-surface JS
|
|
15
|
+
// bundle, so it emits only the utilities that bundle's class strings use on top
|
|
16
|
+
// of runtime.css (chrome + every @yourrealm/sdk/ui component class).
|
|
17
|
+
|
|
18
|
+
import { dirname, join } from "@std/path";
|
|
19
|
+
import { esbuildBinIn } from "./bundle.ts";
|
|
20
|
+
import { RealmCompileError } from "./errors.ts";
|
|
21
|
+
import { sha256Hex } from "./generator/hash.ts";
|
|
22
|
+
import { isPacked } from "./pack.ts";
|
|
23
|
+
import { extractUiSurfaceKeys, type SurfaceDescriptor } from "./sandbox.ts";
|
|
24
|
+
import { mergePackedSource } from "./surfaces.ts";
|
|
25
|
+
import { pkgRoot } from "./pkg-root.ts";
|
|
26
|
+
import { findTailwindBin } from "./tailwind-bin.ts";
|
|
27
|
+
|
|
28
|
+
const EVAL_PKG_DIR = pkgRoot(import.meta.url);
|
|
29
|
+
|
|
30
|
+
const EXTERNAL_SPECIFIERS = [
|
|
31
|
+
"@yourrealm/sdk/ui",
|
|
32
|
+
"@yourrealm/sdk/services",
|
|
33
|
+
"@yourrealm/sdk/preact",
|
|
34
|
+
// JSX automatic runtime: esbuild emits `import { jsx as _jsx } from
|
|
35
|
+
// "@yourrealm/sdk/jsx-runtime"` for every <Component/> (--jsx-import-source
|
|
36
|
+
// below). External so the importmap gives all surfaces one preact instance.
|
|
37
|
+
"@yourrealm/sdk/jsx-runtime",
|
|
38
|
+
// Registry-gate helpers a `verifyAnonymousRequest` hook closes over at module
|
|
39
|
+
// load (e.g. Forge). The iframe never runs the gate, but the surface bundle
|
|
40
|
+
// imports the names, so the importmap resolves them to the runtime. The
|
|
41
|
+
// `@yourrealm/sdk` entry below already covers this subpath; it is listed
|
|
42
|
+
// explicitly to mirror the importmap.
|
|
43
|
+
"@yourrealm/sdk/docker",
|
|
44
|
+
"@yourrealm/sdk",
|
|
45
|
+
"zod",
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Bundled iframe artifact for one ui surface. `jsBytes` is the ESM
|
|
50
|
+
* source Home serves at `/api/ui-bundles/<hash>.js`; `cssBytes` is
|
|
51
|
+
* the matching per-surface utility CSS served at the same hash with
|
|
52
|
+
* `.css`. `hash` is the content address of the JS bytes — CSS is a 1:1
|
|
53
|
+
* sibling, so two surfaces with identical JS share one hash and one CSS.
|
|
54
|
+
*/
|
|
55
|
+
export interface UiSurfaceBundle {
|
|
56
|
+
hash: string;
|
|
57
|
+
jsBytes: string;
|
|
58
|
+
cssBytes: string;
|
|
59
|
+
surface: SurfaceDescriptor;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function findNodeModules(startDir: string): string | null {
|
|
63
|
+
let dir = startDir;
|
|
64
|
+
while (true) {
|
|
65
|
+
const candidate = join(dir, "node_modules");
|
|
66
|
+
try {
|
|
67
|
+
Deno.statSync(candidate);
|
|
68
|
+
try {
|
|
69
|
+
Deno.statSync(join(candidate, "@yourrealm", "sdk"));
|
|
70
|
+
return candidate;
|
|
71
|
+
} catch {
|
|
72
|
+
// node_modules exists but doesn't expose @yourrealm/sdk - keep walking
|
|
73
|
+
}
|
|
74
|
+
} catch {
|
|
75
|
+
// no node_modules at this level
|
|
76
|
+
}
|
|
77
|
+
const parent = dirname(dir);
|
|
78
|
+
if (parent === dir) return null;
|
|
79
|
+
dir = parent;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function entryFor(surface: SurfaceDescriptor): string {
|
|
84
|
+
const accessor = surface.kind === "page" ? "pages" : "widgets";
|
|
85
|
+
return [
|
|
86
|
+
`import app from "./realm.tsx";`,
|
|
87
|
+
`if (!app || !app.ui || !app.ui.${accessor} || !app.ui.${accessor}[${JSON.stringify(surface.key)}]) {`,
|
|
88
|
+
` throw new Error("ui.${accessor}.${surface.key} not declared on createApp output");`,
|
|
89
|
+
`}`,
|
|
90
|
+
`export default app.ui.${accessor}[${JSON.stringify(surface.key)}];`,
|
|
91
|
+
"",
|
|
92
|
+
].join("\n");
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async function esbuildEntry(entryFile: string, nodeModules: string | null): Promise<string> {
|
|
96
|
+
const externals = EXTERNAL_SPECIFIERS.flatMap((s) => ["--external:" + s]);
|
|
97
|
+
// The same binary bundle() spawns: bare `esbuild` only resolves when the
|
|
98
|
+
// invoking package happens to have it on PATH.
|
|
99
|
+
const cmd = new Deno.Command(esbuildBinIn(nodeModules), {
|
|
100
|
+
args: [
|
|
101
|
+
entryFile,
|
|
102
|
+
"--bundle",
|
|
103
|
+
"--format=esm",
|
|
104
|
+
"--platform=neutral",
|
|
105
|
+
"--main-fields=module,main",
|
|
106
|
+
"--target=es2020",
|
|
107
|
+
"--jsx=automatic",
|
|
108
|
+
"--jsx-import-source=@yourrealm/sdk",
|
|
109
|
+
// Strips esbuild's module-header comments, which carry the random
|
|
110
|
+
// temp-dir path and would make the hash non-deterministic across runs,
|
|
111
|
+
// along with all other whitespace. Identifier names are preserved.
|
|
112
|
+
"--minify-whitespace",
|
|
113
|
+
...externals,
|
|
114
|
+
],
|
|
115
|
+
stdout: "piped",
|
|
116
|
+
stderr: "piped",
|
|
117
|
+
});
|
|
118
|
+
const { code, stdout, stderr } = await cmd.output();
|
|
119
|
+
if (code !== 0) {
|
|
120
|
+
const err = new TextDecoder().decode(stderr);
|
|
121
|
+
throw new RealmCompileError({ kind: "eval", message: err });
|
|
122
|
+
}
|
|
123
|
+
return new TextDecoder().decode(stdout);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const PER_SURFACE_CSS_TEMPLATE = `@import "tailwindcss/utilities" layer(utilities);
|
|
127
|
+
@import "tailwindcss/theme.css" theme(reference);
|
|
128
|
+
@source ".";
|
|
129
|
+
`;
|
|
130
|
+
|
|
131
|
+
async function tailwindForSurface(jsBundleDir: string, tailwindBin: string): Promise<string> {
|
|
132
|
+
// Tailwind v4 scans the directory pointed at by `@source` for class strings
|
|
133
|
+
// (.js files included), so each surface gets its own dir and Tailwind sees
|
|
134
|
+
// only that surface's bundle — no class bleed between siblings.
|
|
135
|
+
const cssIn = join(jsBundleDir, "in.css");
|
|
136
|
+
const cssOut = join(jsBundleDir, "out.css");
|
|
137
|
+
await Deno.writeTextFile(cssIn, PER_SURFACE_CSS_TEMPLATE);
|
|
138
|
+
const cmd = new Deno.Command(tailwindBin, {
|
|
139
|
+
args: ["--input", cssIn, "--output", cssOut, "--minify"],
|
|
140
|
+
cwd: jsBundleDir,
|
|
141
|
+
stdout: "piped",
|
|
142
|
+
stderr: "piped",
|
|
143
|
+
});
|
|
144
|
+
const { code, stderr } = await cmd.output();
|
|
145
|
+
if (code !== 0) {
|
|
146
|
+
const err = new TextDecoder().decode(stderr);
|
|
147
|
+
throw new RealmCompileError({
|
|
148
|
+
kind: "eval",
|
|
149
|
+
message: `tailwindcss for surface failed:\n${err}`,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
return await Deno.readTextFile(cssOut);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Bundle every ui surface declared on a realm.ts app. Each surface
|
|
157
|
+
* produces both an ESM JS bundle and a per-surface CSS file (utilities
|
|
158
|
+
* Tailwind extracted from the bundle's class strings).
|
|
159
|
+
*
|
|
160
|
+
* `source` is the original realm.ts text; `bundledCode` is the
|
|
161
|
+
* quickjs-shaped IIFE produced by `bundle(source)` and used here only
|
|
162
|
+
* to enumerate surface keys via the sandbox.
|
|
163
|
+
*
|
|
164
|
+
* The returned bundles map surface kind+key → JS + CSS bytes + content
|
|
165
|
+
* hash. Identical render code under the same key produces the same
|
|
166
|
+
* hash; Home can therefore content-deduplicate across uploads.
|
|
167
|
+
*/
|
|
168
|
+
export async function bundleUiSurfaces(
|
|
169
|
+
source: string,
|
|
170
|
+
bundledCode: string,
|
|
171
|
+
): Promise<UiSurfaceBundle[]> {
|
|
172
|
+
const surfaces = await extractUiSurfaceKeys(bundledCode);
|
|
173
|
+
if (surfaces.length === 0) return [];
|
|
174
|
+
|
|
175
|
+
// The iframe entry imports `./realm.tsx` and reads `app.ui.<kind>[key]`, so it
|
|
176
|
+
// needs the merged source (surfaces attached on the app), not the raw packed
|
|
177
|
+
// artifact. Single-file sources pass through.
|
|
178
|
+
if (isPacked(source)) source = await mergePackedSource(source);
|
|
179
|
+
|
|
180
|
+
const resolveDir = Deno.env.get("ESBUILD_RESOLVE_DIR") ?? EVAL_PKG_DIR ?? Deno.cwd();
|
|
181
|
+
const tailwindBin = findTailwindBin(resolveDir);
|
|
182
|
+
const tmpDir = await Deno.makeTempDir({ prefix: "realm-ui-bundle-" });
|
|
183
|
+
try {
|
|
184
|
+
const nodeModules = findNodeModules(resolveDir);
|
|
185
|
+
if (nodeModules) {
|
|
186
|
+
await Deno.symlink(nodeModules, join(tmpDir, "node_modules"));
|
|
187
|
+
}
|
|
188
|
+
// Always .tsx so esbuild's tsx loader handles both plain TS and JSX: the
|
|
189
|
+
// source is opaque text, and authors pick whichever syntax they prefer.
|
|
190
|
+
await Deno.writeTextFile(join(tmpDir, "realm.tsx"), source);
|
|
191
|
+
|
|
192
|
+
const bundles: UiSurfaceBundle[] = [];
|
|
193
|
+
for (const surface of surfaces) {
|
|
194
|
+
const entryName = `entry-${surface.kind}-${surface.key}.tsx`;
|
|
195
|
+
const entryPath = join(tmpDir, entryName);
|
|
196
|
+
await Deno.writeTextFile(entryPath, entryFor(surface));
|
|
197
|
+
const jsBytes = await esbuildEntry(entryPath, nodeModules);
|
|
198
|
+
// Each surface gets its own scratch dir for tailwind so the
|
|
199
|
+
// @source "." scan only picks up this one bundle's classes.
|
|
200
|
+
const surfaceDir = join(tmpDir, `surface-${surface.kind}-${surface.key}`);
|
|
201
|
+
await Deno.mkdir(surfaceDir);
|
|
202
|
+
await Deno.writeTextFile(join(surfaceDir, "bundle.js"), jsBytes);
|
|
203
|
+
const cssBytes = await tailwindForSurface(surfaceDir, tailwindBin);
|
|
204
|
+
const hash = await sha256Hex(jsBytes);
|
|
205
|
+
bundles.push({ hash, jsBytes, cssBytes, surface });
|
|
206
|
+
}
|
|
207
|
+
return bundles;
|
|
208
|
+
} finally {
|
|
209
|
+
await Deno.remove(tmpDir, { recursive: true }).catch(() => {});
|
|
210
|
+
}
|
|
211
|
+
}
|