@1agh/maude 0.15.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/LICENSE +21 -0
- package/README.md +166 -0
- package/cli/bin/maude.exe +15 -0
- package/cli/bin/maude.mjs +45 -0
- package/cli/bin/mdcc.exe +10 -0
- package/cli/bin/mdcc.mjs +7 -0
- package/cli/cli-wrapper.cjs +67 -0
- package/cli/commands/config.mjs +94 -0
- package/cli/commands/design.mjs +386 -0
- package/cli/commands/help.mjs +57 -0
- package/cli/commands/init.mjs +178 -0
- package/cli/commands/version.mjs +7 -0
- package/cli/install.cjs +113 -0
- package/cli/lib/argv.mjs +37 -0
- package/cli/lib/argv.test.mjs +46 -0
- package/cli/lib/copy-tree.mjs +78 -0
- package/package.json +94 -0
- package/plugins/design/dev-server/annotations-context-toolbar.tsx +397 -0
- package/plugins/design/dev-server/annotations-layer.tsx +1717 -0
- package/plugins/design/dev-server/api.ts +674 -0
- package/plugins/design/dev-server/bin/_screenshot-playwright.mjs +50 -0
- package/plugins/design/dev-server/bin/bootstrap-check.sh +83 -0
- package/plugins/design/dev-server/bin/canvas-edit.sh +48 -0
- package/plugins/design/dev-server/bin/handoff.sh +27 -0
- package/plugins/design/dev-server/bin/screenshot.sh +232 -0
- package/plugins/design/dev-server/bin/server-up.sh +135 -0
- package/plugins/design/dev-server/bin/slug.sh +22 -0
- package/plugins/design/dev-server/bin/smoke.sh +272 -0
- package/plugins/design/dev-server/build.ts +267 -0
- package/plugins/design/dev-server/canvas-build.ts +219 -0
- package/plugins/design/dev-server/canvas-edit.ts +388 -0
- package/plugins/design/dev-server/canvas-header.ts +165 -0
- package/plugins/design/dev-server/canvas-icons.tsx +131 -0
- package/plugins/design/dev-server/canvas-lib-inline.ts +260 -0
- package/plugins/design/dev-server/canvas-lib-resolver.ts +85 -0
- package/plugins/design/dev-server/canvas-lib.tsx +1995 -0
- package/plugins/design/dev-server/canvas-meta.schema.json +181 -0
- package/plugins/design/dev-server/canvas-pipeline.ts +270 -0
- package/plugins/design/dev-server/canvas-shell.tsx +813 -0
- package/plugins/design/dev-server/client/app.jsx +2027 -0
- package/plugins/design/dev-server/client/hmr.mjs +85 -0
- package/plugins/design/dev-server/client/iframe-lazy.mjs +121 -0
- package/plugins/design/dev-server/client/index.html +15 -0
- package/plugins/design/dev-server/client/styles/0-reset.css +18 -0
- package/plugins/design/dev-server/client/styles/1-tokens.css +297 -0
- package/plugins/design/dev-server/client/styles/2-layout.css +35 -0
- package/plugins/design/dev-server/client/styles/3-shell.css +906 -0
- package/plugins/design/dev-server/client/styles/4-components.css +1268 -0
- package/plugins/design/dev-server/client/styles/5-utilities.css +4 -0
- package/plugins/design/dev-server/client/styles/_index.css +24 -0
- package/plugins/design/dev-server/client/styles.css +1419 -0
- package/plugins/design/dev-server/config.schema.json +147 -0
- package/plugins/design/dev-server/context-menu.tsx +343 -0
- package/plugins/design/dev-server/context.ts +173 -0
- package/plugins/design/dev-server/dist/client.bundle.js +20323 -0
- package/plugins/design/dev-server/dist/styles.css +2875 -0
- package/plugins/design/dev-server/examples/README.md +9 -0
- package/plugins/design/dev-server/examples/perf-100-artboards.tsx +113 -0
- package/plugins/design/dev-server/fs-watch.ts +63 -0
- package/plugins/design/dev-server/handoff.ts +721 -0
- package/plugins/design/dev-server/history.ts +125 -0
- package/plugins/design/dev-server/hmr-broadcast.ts +114 -0
- package/plugins/design/dev-server/http.ts +413 -0
- package/plugins/design/dev-server/input-router.tsx +485 -0
- package/plugins/design/dev-server/inspect.ts +365 -0
- package/plugins/design/dev-server/locator.ts +159 -0
- package/plugins/design/dev-server/mem.ts +97 -0
- package/plugins/design/dev-server/runtime-bundle.ts +235 -0
- package/plugins/design/dev-server/server.mjs +1246 -0
- package/plugins/design/dev-server/server.ts +131 -0
- package/plugins/design/dev-server/test/_helpers.ts +81 -0
- package/plugins/design/dev-server/test/active-state.test.ts +145 -0
- package/plugins/design/dev-server/test/annotations-api.test.ts +146 -0
- package/plugins/design/dev-server/test/annotations-layer.test.ts +419 -0
- package/plugins/design/dev-server/test/binary-smoke.test.ts +47 -0
- package/plugins/design/dev-server/test/bundle-smoke.test.ts +29 -0
- package/plugins/design/dev-server/test/canvas-build.test.ts +78 -0
- package/plugins/design/dev-server/test/canvas-edit.test.ts +139 -0
- package/plugins/design/dev-server/test/canvas-header.test.ts +127 -0
- package/plugins/design/dev-server/test/canvas-lib-inline.test.ts +146 -0
- package/plugins/design/dev-server/test/canvas-lib-resolver.test.ts +112 -0
- package/plugins/design/dev-server/test/canvas-meta-api.test.ts +236 -0
- package/plugins/design/dev-server/test/canvas-pipeline.test.ts +180 -0
- package/plugins/design/dev-server/test/canvas-route.test.ts +176 -0
- package/plugins/design/dev-server/test/fs-watch.test.ts +41 -0
- package/plugins/design/dev-server/test/handoff-static-frames.test.ts +215 -0
- package/plugins/design/dev-server/test/handoff.test.ts +281 -0
- package/plugins/design/dev-server/test/history-rollback.test.ts +62 -0
- package/plugins/design/dev-server/test/hmr-broadcast.test.ts +108 -0
- package/plugins/design/dev-server/test/input-router.test.ts +316 -0
- package/plugins/design/dev-server/test/locator.test.ts +214 -0
- package/plugins/design/dev-server/test/perf-harness.ts +193 -0
- package/plugins/design/dev-server/test/phase-3.6-smoke.test.ts +77 -0
- package/plugins/design/dev-server/test/runtime-bundle.test.ts +69 -0
- package/plugins/design/dev-server/test/server-lifecycle.test.ts +28 -0
- package/plugins/design/dev-server/test/tool-palette.test.tsx +55 -0
- package/plugins/design/dev-server/test/use-annotation-selection.test.tsx +77 -0
- package/plugins/design/dev-server/test/use-artboard-drag.test.ts +325 -0
- package/plugins/design/dev-server/test/use-selection-set.test.tsx +166 -0
- package/plugins/design/dev-server/test/use-snap-guides.test.ts +190 -0
- package/plugins/design/dev-server/test/use-tool-mode.test.tsx +93 -0
- package/plugins/design/dev-server/test/ws-handshake.test.ts +33 -0
- package/plugins/design/dev-server/tool-palette.tsx +278 -0
- package/plugins/design/dev-server/tsconfig.json +26 -0
- package/plugins/design/dev-server/use-annotation-selection.tsx +92 -0
- package/plugins/design/dev-server/use-annotations-visibility.tsx +43 -0
- package/plugins/design/dev-server/use-artboard-drag.tsx +445 -0
- package/plugins/design/dev-server/use-selection-set.tsx +224 -0
- package/plugins/design/dev-server/use-snap-guides.tsx +215 -0
- package/plugins/design/dev-server/use-tool-mode.tsx +114 -0
- package/plugins/design/dev-server/ws.ts +90 -0
- package/plugins/design/templates/_shell.html +177 -0
- package/plugins/design/templates/canvas.tsx.template +54 -0
- package/plugins/design/templates/design-system-inspiration/_MAPPING.md +277 -0
- package/plugins/design/templates/design-system-inspiration/_README.md +71 -0
- package/plugins/design/templates/design-system-inspiration/audience-consumer/components-banner.html +68 -0
- package/plugins/design/templates/design-system-inspiration/audience-consumer/components-empty-state-generous.html +39 -0
- package/plugins/design/templates/design-system-inspiration/audience-consumer/components-feature-grid.html +62 -0
- package/plugins/design/templates/design-system-inspiration/audience-consumer/components-marketing-card.html +63 -0
- package/plugins/design/templates/design-system-inspiration/audience-consumer/components-testimonial.html +80 -0
- package/plugins/design/templates/design-system-inspiration/audience-developer/components-code-block.html +71 -0
- package/plugins/design/templates/design-system-inspiration/audience-developer/components-diff-view.html +65 -0
- package/plugins/design/templates/design-system-inspiration/audience-developer/components-log-stream.html +62 -0
- package/plugins/design/templates/design-system-inspiration/audience-developer/components-monospace-table.html +57 -0
- package/plugins/design/templates/design-system-inspiration/audience-developer/components-terminal-pane.html +67 -0
- package/plugins/design/templates/design-system-inspiration/audience-developer/type-mono.html +57 -0
- package/plugins/design/templates/design-system-inspiration/audience-pro/colors-presence.html +74 -0
- package/plugins/design/templates/design-system-inspiration/audience-pro/components-command-palette.html +90 -0
- package/plugins/design/templates/design-system-inspiration/audience-pro/components-keyboard.html +51 -0
- package/plugins/design/templates/design-system-inspiration/audience-pro/components-list.html +89 -0
- package/plugins/design/templates/design-system-inspiration/audience-pro/components-shortcuts-overlay.html +85 -0
- package/plugins/design/templates/design-system-inspiration/audience-pro/components-toast-menu.html +80 -0
- package/plugins/design/templates/design-system-inspiration/core/INDEX.md.tpl +25 -0
- package/plugins/design/templates/design-system-inspiration/core/README.orchestration.md.tpl +71 -0
- package/plugins/design/templates/design-system-inspiration/core/README.philosophy.md.tpl +77 -0
- package/plugins/design/templates/design-system-inspiration/core/SKILL.md.tpl +50 -0
- package/plugins/design/templates/design-system-inspiration/core/colors_and_type.css.tpl +111 -0
- package/plugins/design/templates/design-system-inspiration/core/config.json.tpl +28 -0
- package/plugins/design/templates/design-system-inspiration/core/preview/_layout.css +113 -0
- package/plugins/design/templates/design-system-inspiration/core/preview/colors-accent.html +48 -0
- package/plugins/design/templates/design-system-inspiration/core/preview/colors-surfaces.html +49 -0
- package/plugins/design/templates/design-system-inspiration/core/preview/colors-text.html +52 -0
- package/plugins/design/templates/design-system-inspiration/core/preview/components-buttons.html +83 -0
- package/plugins/design/templates/design-system-inspiration/core/preview/components-cards.html +79 -0
- package/plugins/design/templates/design-system-inspiration/core/preview/components-inputs.html +82 -0
- package/plugins/design/templates/design-system-inspiration/core/preview/motion.html +66 -0
- package/plugins/design/templates/design-system-inspiration/core/preview/spacing-scale.html +53 -0
- package/plugins/design/templates/design-system-inspiration/core/preview/type-scale.html +62 -0
- package/plugins/design/templates/design-system-inspiration/foundations/borders.html +39 -0
- package/plugins/design/templates/design-system-inspiration/foundations/elevation.html +46 -0
- package/plugins/design/templates/design-system-inspiration/foundations/focus.html +48 -0
- package/plugins/design/templates/design-system-inspiration/foundations/grid.html +51 -0
- package/plugins/design/templates/design-system-inspiration/foundations/iconography.html +73 -0
- package/plugins/design/templates/design-system-inspiration/foundations/opacity.html +45 -0
- package/plugins/design/templates/design-system-inspiration/foundations/radii.html +40 -0
- package/plugins/design/templates/design-system-inspiration/foundations/selection.html +45 -0
- package/plugins/design/templates/design-system-inspiration/meta/accessibility.html +62 -0
- package/plugins/design/templates/design-system-inspiration/meta/i18n.html +73 -0
- package/plugins/design/templates/design-system-inspiration/meta/presence-multiplayer.html +71 -0
- package/plugins/design/templates/design-system-inspiration/meta/tokens-index.html +80 -0
- package/plugins/design/templates/design-system-inspiration/patterns/patterns-auth.html +78 -0
- package/plugins/design/templates/design-system-inspiration/patterns/patterns-data-density.html +61 -0
- package/plugins/design/templates/design-system-inspiration/patterns/patterns-error-pages.html +70 -0
- package/plugins/design/templates/design-system-inspiration/patterns/patterns-form-layouts.html +70 -0
- package/plugins/design/templates/design-system-inspiration/patterns/patterns-onboarding.html +71 -0
- package/plugins/design/templates/design-system-inspiration/patterns/patterns-pricing.html +83 -0
- package/plugins/design/templates/design-system-inspiration/platform-desktop/components-resize-panels.html +63 -0
- package/plugins/design/templates/design-system-inspiration/platform-desktop/ui_kits-desktop-index.html +55 -0
- package/plugins/design/templates/design-system-inspiration/platform-desktop/ui_kits-desktop-showcase.html +302 -0
- package/plugins/design/templates/design-system-inspiration/platform-mobile/components-bottom-sheet.html +63 -0
- package/plugins/design/templates/design-system-inspiration/platform-mobile/components-pull-to-refresh.html +74 -0
- package/plugins/design/templates/design-system-inspiration/platform-mobile/components-segmented-control.html +51 -0
- package/plugins/design/templates/design-system-inspiration/platform-mobile/components-tab-bar.html +57 -0
- package/plugins/design/templates/design-system-inspiration/platform-mobile/ui_kits-mobile-index.html +58 -0
- package/plugins/design/templates/design-system-inspiration/platform-mobile/ui_kits-mobile-showcase.html +237 -0
- package/plugins/design/templates/design-system-inspiration/status/colors-status.html +49 -0
- package/plugins/design/templates/design-system-inspiration/status/components-status.html +63 -0
- package/plugins/design/templates/design-system-inspiration/status/skeletons.html +74 -0
- package/plugins/design/templates/design-system-inspiration/theme-both/colors-themes-side-by-side.html +59 -0
- package/plugins/design/templates/design-system-inspiration/universal/components-callout.html +74 -0
- package/plugins/design/templates/design-system-inspiration/universal/components-dialogs.html +81 -0
- package/plugins/design/templates/design-system-inspiration/universal/components-tables.html +101 -0
- package/plugins/design/templates/design-system-inspiration/universal/components-toggles.html +74 -0
- package/plugins/design/templates/design-system-inspiration/universal/components-tooltips.html +74 -0
- package/plugins/design/templates/design-system-inspiration/universal/empty-state.html.tpl +34 -0
- package/plugins/design/templates/design-system-inspiration/universal/logo.html +42 -0
- package/plugins/design/templates/ds-specimen.tsx.template +59 -0
- package/plugins/flow/.claude-plugin/config.schema.json +398 -0
- package/plugins/flow/README.md +45 -0
- package/plugins/flow/templates/ai-skeleton/INDEX.md +50 -0
- package/plugins/flow/templates/ai-skeleton/README.md +46 -0
- package/plugins/flow/templates/ai-skeleton/browser/har/.gitkeep +0 -0
- package/plugins/flow/templates/ai-skeleton/browser/snapshots/.gitkeep +0 -0
- package/plugins/flow/templates/ai-skeleton/business/README.md +12 -0
- package/plugins/flow/templates/ai-skeleton/context/README.md +12 -0
- package/plugins/flow/templates/ai-skeleton/decisions/README.md +20 -0
- package/plugins/flow/templates/ai-skeleton/design-import/.gitkeep +0 -0
- package/plugins/flow/templates/ai-skeleton/dev-logs/.gitkeep +0 -0
- package/plugins/flow/templates/ai-skeleton/device/.gitkeep +0 -0
- package/plugins/flow/templates/ai-skeleton/docs/README.md +5 -0
- package/plugins/flow/templates/ai-skeleton/logs/.gitkeep +0 -0
- package/plugins/flow/templates/ai-skeleton/logs/README.md +13 -0
- package/plugins/flow/templates/ai-skeleton/plans/README.md +16 -0
- package/plugins/flow/templates/ai-skeleton/plans/archive/.gitkeep +0 -0
- package/plugins/flow/templates/ai-skeleton/release-guide.md +35 -0
- package/plugins/flow/templates/ai-skeleton/reviews/README.md +15 -0
- package/plugins/flow/templates/ai-skeleton/scenarios/README.md +26 -0
- package/plugins/flow/templates/ai-skeleton/scenarios/_lib/.gitkeep +0 -0
- package/plugins/flow/templates/ai-skeleton/state/STATE.md +25 -0
- package/plugins/flow/templates/ai-skeleton/templates/HANDOFF.md +32 -0
- package/plugins/flow/templates/ai-skeleton/workflows.config.json +74 -0
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
// React 19 runtime bundle — single bundled copy of React + ReactDOM + JSX
|
|
2
|
+
// runtime served at `/_canvas-runtime/<pkg>.js`. Every TSX canvas resolves its
|
|
3
|
+
// `import "react"` / `import "react/jsx-dev-runtime"` etc. through an importmap
|
|
4
|
+
// that points at these URLs, so a multi-canvas session never re-downloads the
|
|
5
|
+
// runtime. DDR-019, Phase 3.6 Task 6.
|
|
6
|
+
//
|
|
7
|
+
// Design:
|
|
8
|
+
// - One Bun.build per logical sub-path. We split into four entries
|
|
9
|
+
// ('react', 'react-dom/client', 'react/jsx-runtime', 'react/jsx-dev-runtime')
|
|
10
|
+
// rather than one mega-bundle so the browser cache key per import is stable
|
|
11
|
+
// across React minor version changes (each bundle is re-keyed by content
|
|
12
|
+
// hash; an unaffected sub-path keeps its cache entry).
|
|
13
|
+
// - Lazy: first GET against /_canvas-runtime/<name>.js builds the bundle
|
|
14
|
+
// in-process. Subsequent GETs hit the cache. The build is cheap (~150 ms
|
|
15
|
+
// cold for React + ReactDOM combined) but enough that we don't want to pay
|
|
16
|
+
// it for every page nav.
|
|
17
|
+
// - Etag-aware: returns the bundle's content hash so the browser can 304.
|
|
18
|
+
// - In dev we externalise *nothing* — the four bundles together are
|
|
19
|
+
// self-contained. The importmap wires them together at runtime.
|
|
20
|
+
|
|
21
|
+
import { dirname } from 'node:path';
|
|
22
|
+
import { fileURLToPath } from 'node:url';
|
|
23
|
+
|
|
24
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
25
|
+
|
|
26
|
+
export const RUNTIME_PACKAGES = [
|
|
27
|
+
'react',
|
|
28
|
+
'react-dom',
|
|
29
|
+
'react-dom/client',
|
|
30
|
+
'react/jsx-runtime',
|
|
31
|
+
'react/jsx-dev-runtime',
|
|
32
|
+
// Phase 4 — Pixi.js v8 available as a per-iframe runtime bundle. Lazy-built
|
|
33
|
+
// on first request; canvases that don't `import 'pixi.js'` never pay the
|
|
34
|
+
// ~500 KB bundle cost. Reserved for future snapshot-to-texture rendering
|
|
35
|
+
// (DDR-024 deferred path) and any high-end designer-tool overlays a canvas
|
|
36
|
+
// wants to draw via WebGL.
|
|
37
|
+
'pixi.js',
|
|
38
|
+
] as const;
|
|
39
|
+
|
|
40
|
+
export type RuntimePackage = (typeof RUNTIME_PACKAGES)[number];
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Discover the public export keys of a package at build time. React + ReactDOM
|
|
44
|
+
* ship CJS in npm; `export * from "..."` against a CJS module produces empty
|
|
45
|
+
* ESM bindings (the spec only allows `export *` to re-export static bindings,
|
|
46
|
+
* and CJS has none). We work around this by dynamically `import()`ing the
|
|
47
|
+
* package in the host Bun process, enumerating `Object.keys`, and emitting an
|
|
48
|
+
* explicit named-re-export list. Robust to React version bumps (every new
|
|
49
|
+
* named export — public or `__INTERNAL_*` — gets carried automatically).
|
|
50
|
+
*
|
|
51
|
+
* React 19's `__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE`
|
|
52
|
+
* is the canonical bridge ReactDOM uses to read React's shared internal state;
|
|
53
|
+
* if we drop it the runtime fails with "Cannot read properties of undefined
|
|
54
|
+
* (reading 'S')" on first ReactDOM.createRoot() call. Auto-discovery is the
|
|
55
|
+
* only sustainable answer.
|
|
56
|
+
*/
|
|
57
|
+
const namedExportsCache = new Map<RuntimePackage, readonly string[]>();
|
|
58
|
+
async function namedExportsFor(pkg: RuntimePackage): Promise<readonly string[]> {
|
|
59
|
+
const hit = namedExportsCache.get(pkg);
|
|
60
|
+
if (hit) return hit;
|
|
61
|
+
const mod = (await import(pkg)) as Record<string, unknown>;
|
|
62
|
+
// `default` is auto-emitted from our synthetic entry separately; skip here.
|
|
63
|
+
const keys = Object.keys(mod)
|
|
64
|
+
.filter((k) => k !== 'default')
|
|
65
|
+
.sort();
|
|
66
|
+
namedExportsCache.set(pkg, keys);
|
|
67
|
+
return keys;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* URL slug used in `/_canvas-runtime/<slug>.js`. Maps package specifier to a
|
|
72
|
+
* filename-safe form. Inverse of {@link packageForSlug}.
|
|
73
|
+
*
|
|
74
|
+
* Slashes → `_`. Dots in package names → `-` (so `pixi.js` → `pixi-js` and
|
|
75
|
+
* the trailing `.js` extension on the URL stays unambiguous; without this,
|
|
76
|
+
* `packageForSlug` would strip `.js` and resolve `pixi.js.js` → `pixi`).
|
|
77
|
+
*/
|
|
78
|
+
export function slugFor(pkg: RuntimePackage): string {
|
|
79
|
+
return pkg.replace(/\//g, '_').replace(/\./g, '-');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function packageForSlug(slug: string): RuntimePackage | null {
|
|
83
|
+
const want = slug.replace(/\.js$/, '');
|
|
84
|
+
for (const p of RUNTIME_PACKAGES) {
|
|
85
|
+
if (slugFor(p) === want) return p;
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
interface BundleCacheEntry {
|
|
91
|
+
js: string;
|
|
92
|
+
etag: string;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const cache = new Map<RuntimePackage, BundleCacheEntry>();
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Build (or fetch from cache) a single runtime sub-bundle. Self-contained:
|
|
99
|
+
* each entry includes everything it needs; the four bundles only share state
|
|
100
|
+
* at the browser level (via React's module-singleton convention — multiple
|
|
101
|
+
* imports of "react" resolve to the same module thanks to the importmap).
|
|
102
|
+
*/
|
|
103
|
+
export async function getRuntimeBundle(pkg: RuntimePackage): Promise<BundleCacheEntry> {
|
|
104
|
+
const hit = cache.get(pkg);
|
|
105
|
+
if (hit) return hit;
|
|
106
|
+
|
|
107
|
+
// A throwaway entrypoint that re-exports every member of the target package.
|
|
108
|
+
// We use named re-exports (default + an enumerated namespace) so the bundle
|
|
109
|
+
// produces real ESM exports even when the source package is CJS (React +
|
|
110
|
+
// ReactDOM are CJS in their npm distribution; `export * from` against a CJS
|
|
111
|
+
// module gives static analyzers nothing to bind, so Bun.build silently emits
|
|
112
|
+
// an empty export shape — manual destructure works around that).
|
|
113
|
+
// Synthetic entrypoint anchored inside the dev-server dir so Bun.build's
|
|
114
|
+
// default resolver walks UP from HERE and finds dev-server/node_modules/react
|
|
115
|
+
// (regardless of where the process happens to be launched from).
|
|
116
|
+
const entryName = `${HERE}/.runtime-bundle-${slugFor(pkg)}-entry.tsx`;
|
|
117
|
+
const exportNames = await namedExportsFor(pkg);
|
|
118
|
+
const namedLines = exportNames.map((n) => ` ${n}`).join(',\n');
|
|
119
|
+
// The `as any` cast tolerates names like `__INTERNAL_DO_NOT_USE_OR_WARN`
|
|
120
|
+
// that aren't declared in the package's .d.ts; the destructure still
|
|
121
|
+
// succeeds at runtime, which is what matters.
|
|
122
|
+
const entryContent = `import * as __mod__ from ${JSON.stringify(pkg)};\n${
|
|
123
|
+
exportNames.length > 0
|
|
124
|
+
? `const {\n${namedLines}\n} = __mod__ as any;\n` + `export {\n${namedLines}\n};\n`
|
|
125
|
+
: ''
|
|
126
|
+
}export default __mod__;\n`;
|
|
127
|
+
|
|
128
|
+
// Externalise the OTHER three runtime packages so they don't get bundled
|
|
129
|
+
// multiple times into this one. The importmap re-stitches at runtime — the
|
|
130
|
+
// browser resolves every reference to a single module URL per package, so
|
|
131
|
+
// React's module-singleton invariant is preserved (no Invalid-Hook-Call).
|
|
132
|
+
//
|
|
133
|
+
// Bun's `external` field is package-name prefixed — listing "react" also
|
|
134
|
+
// marks "react/jsx-runtime" external, which would defeat the per-subpath
|
|
135
|
+
// bundles. We instead pin externals via a `onResolve` plugin so each
|
|
136
|
+
// specifier is matched literally (exact-string compare). Any specifier NOT
|
|
137
|
+
// in `externalSpecifiers` falls through to the default node_modules resolver
|
|
138
|
+
// and gets inlined.
|
|
139
|
+
const externalSpecifiers = new Set<string>(
|
|
140
|
+
RUNTIME_PACKAGES.filter((p) => p !== pkg).flatMap((p) => [p, ...subPathExternals(p)])
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
const built = await Bun.build({
|
|
144
|
+
entrypoints: [entryName],
|
|
145
|
+
target: 'browser',
|
|
146
|
+
format: 'esm',
|
|
147
|
+
minify: false,
|
|
148
|
+
splitting: false,
|
|
149
|
+
define: {
|
|
150
|
+
// Force React's production module (smaller, no dev-only `let React`
|
|
151
|
+
// reassignment that triggers Bun.build's bundler-rename collision with
|
|
152
|
+
// the `import * as React from "react"` namespace binding). The dev
|
|
153
|
+
// variant has extra console-error scaffolding that's not worth the
|
|
154
|
+
// bundler edge-case it forces us through.
|
|
155
|
+
'process.env.NODE_ENV': '"production"',
|
|
156
|
+
},
|
|
157
|
+
plugins: [
|
|
158
|
+
{
|
|
159
|
+
name: 'synthetic-entry',
|
|
160
|
+
setup(builder) {
|
|
161
|
+
// Resolve the synthetic entrypoint to itself.
|
|
162
|
+
builder.onResolve({ filter: new RegExp(`^${escapeRegex(entryName)}$`) }, (args) => ({
|
|
163
|
+
path: args.path,
|
|
164
|
+
namespace: 'synth',
|
|
165
|
+
}));
|
|
166
|
+
builder.onLoad({ filter: /.*/, namespace: 'synth' }, () => ({
|
|
167
|
+
contents: entryContent,
|
|
168
|
+
loader: 'tsx',
|
|
169
|
+
}));
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
name: 'exact-externals',
|
|
174
|
+
setup(builder) {
|
|
175
|
+
// Match every bare specifier — JS, JSX, TS, TSX, "react", "react-dom",
|
|
176
|
+
// sub-paths, file-relative imports. We use a broad `filter` and
|
|
177
|
+
// decide externalisation in the callback so we don't need to escape
|
|
178
|
+
// every sub-path into the regex.
|
|
179
|
+
builder.onResolve({ filter: /.*/ }, (args) => {
|
|
180
|
+
if (externalSpecifiers.has(args.path)) {
|
|
181
|
+
return { path: args.path, external: true };
|
|
182
|
+
}
|
|
183
|
+
return null;
|
|
184
|
+
});
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
],
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
if (!built.success) {
|
|
191
|
+
const msg = built.logs
|
|
192
|
+
.map((l) => {
|
|
193
|
+
const lvl = (l as { level?: string }).level ?? 'error';
|
|
194
|
+
return `[${lvl}] ${l.message}`;
|
|
195
|
+
})
|
|
196
|
+
.join('\n');
|
|
197
|
+
throw new Error(`Failed to build runtime bundle for "${pkg}":\n${msg || '(no log messages)'}`);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const out = built.outputs[0];
|
|
201
|
+
if (!out) throw new Error(`Bun.build produced no output for runtime bundle "${pkg}"`);
|
|
202
|
+
const js = await out.text();
|
|
203
|
+
const etag = Bun.hash(js).toString(16);
|
|
204
|
+
const entry = { js, etag };
|
|
205
|
+
cache.set(pkg, entry);
|
|
206
|
+
return entry;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function escapeRegex(s: string): string {
|
|
210
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Additional specifiers that resolve to the same package (e.g. `react-dom` is
|
|
215
|
+
* served via the `react-dom/client` bundle but downstream imports might use
|
|
216
|
+
* `react-dom` bare). Listed alongside the canonical specifier in the externals
|
|
217
|
+
* list so internal imports of these sibling paths don't drag the runtime back
|
|
218
|
+
* into the bundle.
|
|
219
|
+
*/
|
|
220
|
+
function subPathExternals(_pkg: RuntimePackage): string[] {
|
|
221
|
+
// Phase 5.1 — `react-dom` is now its own RUNTIME_PACKAGES entry (so
|
|
222
|
+
// `createPortal` is bundled and reachable). No aliases needed; the package
|
|
223
|
+
// list already covers every specifier the importmap routes.
|
|
224
|
+
return [];
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Pre-warm every sub-bundle. Called eagerly at server boot when the
|
|
229
|
+
* MDCC_PREWARM_RUNTIME env var is set; otherwise bundles build on first GET.
|
|
230
|
+
* The warm-up adds ~200 ms to startup; default off because the dev-server's
|
|
231
|
+
* own cold-start is already the longest tail.
|
|
232
|
+
*/
|
|
233
|
+
export async function prewarmRuntimeBundles(): Promise<void> {
|
|
234
|
+
await Promise.all(RUNTIME_PACKAGES.map(getRuntimeBundle));
|
|
235
|
+
}
|