@tschk/moonshine-cli 0.4.1 → 0.4.49
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/README.md +108 -18
- package/bin/moonshine.ts +31 -17
- package/package.json +28 -14
- package/src/adopt/gaps.ts +33 -6
- package/src/adopt/plan.ts +77 -11
- package/src/adopt/project.ts +12 -2
- package/src/adopt/report.ts +2 -2
- package/src/adopt/scan.ts +18 -3
- package/src/adopt/templates.ts +157 -79
- package/src/adopt/types.ts +6 -3
- package/src/adopt.ts +15 -17
- package/src/build.ts +50 -3
- package/src/compile-graph.ts +6 -0
- package/src/compile-output.ts +1 -0
- package/src/compile.ts +72 -64
- package/src/config.ts +2 -1
- package/src/dev.ts +12 -1
- package/src/new.ts +193 -67
- package/src/preview-native.ts +150 -0
- package/src/preview-worker.ts +38 -0
- package/src/preview.ts +64 -14
package/README.md
CHANGED
|
@@ -12,12 +12,32 @@ bun packages/cli/bin/moonshine.ts preview
|
|
|
12
12
|
Commands:
|
|
13
13
|
|
|
14
14
|
- `adopt [dir] [--dry-run] [--yes|-y] [--force]`
|
|
15
|
-
- `new <name> [--react|--solid|--crepus] [--adapter bun|node|cloudflare|vercel] [--vite]`
|
|
15
|
+
- `new <name> [--native|--react|--solid|--crepus] [--adapter bun|node|cloudflare|vercel] [--vite]`
|
|
16
16
|
- `build [dir] [--adapter bun|node|cloudflare|vercel]`
|
|
17
17
|
- `inspect [path] [--json]`
|
|
18
18
|
- `preview [dir] [--port <n>]`
|
|
19
19
|
- `dev [dir]`
|
|
20
|
-
- `compile [
|
|
20
|
+
- `compile <source> [--ssr|--react] [--compiler <path>]`
|
|
21
|
+
|
|
22
|
+
Native preview runs the bundled server in a fresh Bun child process. Stopping
|
|
23
|
+
preview stops that process; dev rebuilds start a new one so Bun's module caches
|
|
24
|
+
cannot serve the previous build. Production artifacts continue to run directly.
|
|
25
|
+
|
|
26
|
+
`new` defaults to the independent Moonshine DOM runtime with Bun SSR and an
|
|
27
|
+
explicit SPA entry. `moonshine new app --adapter node` selects Node production
|
|
28
|
+
output; build and dev honor the configured adapter, and `bun run start` runs
|
|
29
|
+
`node .moonshine/server.js`. Native routes require matching Bun, Node or Cloudflare
|
|
30
|
+
runtimes; `--adapter vercel` selects a bundled native Node 22 function under
|
|
31
|
+
`.moonshine/.vercel/output`. Native Vercel Edge, caching, request context and
|
|
32
|
+
hydration are unsupported. Cloudflare emits a self-contained
|
|
33
|
+
worker and `wrangler.jsonc` with an `ASSETS` binding and `nodejs_compat`; run it
|
|
34
|
+
with your installed Wrangler. Native Cloudflare caching/revalidation, islands
|
|
35
|
+
and request context are unsupported. `--vite` uses the same DOM runtime for a client app.
|
|
36
|
+
`--solid` is an alias for this independent native scaffold, including with
|
|
37
|
+
`--vite`; it installs no Solid runtime and does not automatically compile authored
|
|
38
|
+
Solid source. React and Crepus scaffolds remain explicit legacy options. Project `public/`
|
|
39
|
+
files are copied to the build and served at root URLs; symlinks and generated
|
|
40
|
+
asset collisions are rejected.
|
|
21
41
|
|
|
22
42
|
## `adopt`
|
|
23
43
|
|
|
@@ -44,12 +64,26 @@ Two adoption paths, decided by what it finds:
|
|
|
44
64
|
|
|
45
65
|
No source file is ever edited. For the aliasing path, every specifier the
|
|
46
66
|
adapter implements is remapped through `compilerOptions.paths`, which Bun
|
|
47
|
-
honours in both `bun run` and `Bun.build`.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
`moonshine/routes
|
|
51
|
-
|
|
52
|
-
|
|
67
|
+
honours in both `bun run` and `Bun.build`. Template adoption delegates to the
|
|
68
|
+
external Crepus CLI's `moonshine-ssr` emitter (select it with `--compiler <path>`).
|
|
69
|
+
Unchanged `.ssr.ts` components go into `moonshine/components/`; generated `.ts`
|
|
70
|
+
route wrappers (reusing existing `.tsx` paths from earlier adoption) go into `moonshine/routes/`. Config selects native SSR and discovers the generated route wrappers. It adds no React renderer or Crepus React bridge dependencies
|
|
71
|
+
and preserves the app's existing dependencies. Missing compilers fail before writes. If every discovered template fails emission,
|
|
72
|
+
adoption exits nonzero before changing config, dependencies or generated files,
|
|
73
|
+
and lists the per-file compiler diagnostics. Partial success still reports failures.
|
|
74
|
+
|
|
75
|
+
Route wrappers expose only `scope: { params, data }`. Port other state and handlers
|
|
76
|
+
explicitly; scripts are not executed. SSR does not bind interactive browser events
|
|
77
|
+
or hydrate. Use `moonshine compile` to emit a DOM component and author an explicit
|
|
78
|
+
SPA `clientFile` for browser behavior. Review generated forms and accessibility
|
|
79
|
+
before replacing the original: accepted markup may lose form/submit semantics;
|
|
80
|
+
Vue v-model remains read-only without authored handlers. Verified Vue/Svelte email
|
|
81
|
+
fixtures preserve type, explicit name, required, IDs, label associations and
|
|
82
|
+
`aria-label`; review other frontend and attribute combinations. Component styles are also limited: Svelte/Vue
|
|
83
|
+
`<style>` blocks and scoped CSS are not preserved, and Astro `<style>` blocks can
|
|
84
|
+
fail compilation. Port styles to authored CSS imports until Crepus provides a
|
|
85
|
+
stylesheet asset contract. Crepus also does not copy referenced images or other
|
|
86
|
+
assets; review generated URLs and include assets explicitly in the application build.
|
|
53
87
|
|
|
54
88
|
Which files each template frontend claims:
|
|
55
89
|
|
|
@@ -65,8 +99,7 @@ Plain `.html` is deliberately not claimed: an `index.html` is left alone.
|
|
|
65
99
|
Only the markup is compiled. Svelte `<script>` blocks, Vue's Composition API,
|
|
66
100
|
Astro's `---` frontmatter and the Angular component class are **not** executed —
|
|
67
101
|
no runes, stores, lifecycle hooks, imports, data fetching, DI or pipes — and that
|
|
68
|
-
logic has to be ported to moonshine signals.
|
|
69
|
-
not support are hard errors reported per file, not silent drops:
|
|
102
|
+
logic has to be ported to moonshine signals. Known frontend restrictions include:
|
|
70
103
|
|
|
71
104
|
- **Astro** rejects any uppercase component tag (`<Layout>` — the frontend
|
|
72
105
|
resolves no modules), `<slot />`, `{...spread}`, `transition:*` and
|
|
@@ -79,14 +112,13 @@ not support are hard errors reported per file, not silent drops:
|
|
|
79
112
|
`moonshine/components/` and stays unmounted until you write a route module that
|
|
80
113
|
imports it. Filenames are not guessed into URLs.
|
|
81
114
|
|
|
82
|
-
Because
|
|
83
|
-
editing a template.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
adopting against it would produce quietly wrong pages.
|
|
115
|
+
Because emission happens at adopt time, re-run `moonshine adopt --force` after
|
|
116
|
+
editing a template. The installed Crepus CLI owns frontend support and diagnostics;
|
|
117
|
+
there is no WASM or React fallback. Failed recompilation of an existing generated
|
|
118
|
+
route aborts adoption before writes. Routes for removed source templates are not
|
|
119
|
+
tracked or deleted automatically; review and retire those stale routes explicitly. Emitted TypeScript is syntax-checked before it
|
|
120
|
+
is planned. Unsupported IR failures are reported per file; this is not proof that
|
|
121
|
+
all accepted markup preserves original application semantics.
|
|
90
122
|
|
|
91
123
|
### Confirmation
|
|
92
124
|
|
|
@@ -105,3 +137,61 @@ script logic.
|
|
|
105
137
|
See [DESIGN.md](../../DESIGN.md), [docs/ROUTING.md](../../docs/ROUTING.md),
|
|
106
138
|
[docs/DEPLOYMENT.md](../../docs/DEPLOYMENT.md), and
|
|
107
139
|
[docs/MANIFEST.md](../../docs/MANIFEST.md).
|
|
140
|
+
|
|
141
|
+
## `compile`
|
|
142
|
+
|
|
143
|
+
`moonshine compile view.svelte` delegates parsing and lowering to Crepus and writes
|
|
144
|
+
`view.dom.ts` for the independent DOM runtime. `--ssr` writes `view.ssr.ts`;
|
|
145
|
+
`--react` explicitly selects React source output (`view.react.tsx`) and retains legacy JSON IR
|
|
146
|
+
input (`view.tsx`). Native JSON IR generation is unavailable. Supported frontend extensions
|
|
147
|
+
are `.crepus`, `.jsx`, `.tsx`, `.csx`, `.svelte`, `.vue`, `.astro`, `.ng` and `.html`.
|
|
148
|
+
The command invokes `crepus web build` in an isolated output directory and copies
|
|
149
|
+
the generated modules unchanged. Install a Crepus CLI with `moonshine-dom` and
|
|
150
|
+
`moonshine-ssr` emit targets, or select a binary with `--compiler <path>`.
|
|
151
|
+
The native output is a component, not a mounted application entry: import it and
|
|
152
|
+
mount it with the DOM renderer. Template fragments receive expression readers,
|
|
153
|
+
writable bindings and event handlers through their explicit scope/handler contract.
|
|
154
|
+
Authored JSX/TSX modules preserve their imports, exports, state and closures for
|
|
155
|
+
execution by the native runtime. Supported syntax depends on the installed Crepus
|
|
156
|
+
compiler; unsupported constructs fail. Compilation does not execute source scripts
|
|
157
|
+
or install a host runtime. Compiler failures leave existing output untouched.
|
|
158
|
+
|
|
159
|
+
For imports above the entry directory, pass `--site <project-root>`; the source
|
|
160
|
+
and reachable local modules must stay inside that root. A version 1
|
|
161
|
+
`crepus-module-manifest.json` lets the CLI validate and copy the complete JS/TS
|
|
162
|
+
graph. Its optional `sourceModule` names the inventoried output when allocation
|
|
163
|
+
remaps the source entry, including SFCs beside same-named JavaScript companions.
|
|
164
|
+
The entry facade must reference that module; target, path, inventory and import
|
|
165
|
+
validation still apply. Older manifests retain their original filename mapping.
|
|
166
|
+
Compiler files live under `.moonshine-compiled/<output-name>/<content-hash>/`,
|
|
167
|
+
and the public `.dom.ts` or `.ssr.ts` entry re-exports them. Module bytes stay
|
|
168
|
+
unchanged. Sources and DOM/SSR targets have separate directories. Publication
|
|
169
|
+
switches the public entry only after the graph is ready. Older versions remain
|
|
170
|
+
for existing imports; unused versions can be removed when no process uses them.
|
|
171
|
+
|
|
172
|
+
Template routes whose final segment is `index`, starts with `+`, or ends in
|
|
173
|
+
`.data`, `.server` or `.client` use a directory `index.ts` wrapper so Moonshine’s
|
|
174
|
+
route filename conventions preserve the URL. Conflicting output paths and stale
|
|
175
|
+
flat wrappers at these reserved paths require manual resolution before adoption;
|
|
176
|
+
no generated files are deleted automatically.
|
|
177
|
+
|
|
178
|
+
Without that module manifest, filesystem imports (including reexports and literal
|
|
179
|
+
dynamic imports) are rejected instead of discarding companion files. Template
|
|
180
|
+
adoption currently accepts single-file emission only. CSS, binary assets and
|
|
181
|
+
computed asset expressions still need an upstream asset contract; the JS/TS graph
|
|
182
|
+
inventory does not provide one. Bare package imports remain unchanged.
|
|
183
|
+
Native output retaining `react`, `react-dom`, `solid-js`, `svelte` or `vue` runtime imports
|
|
184
|
+
is rejected, including subpaths and transitive generated modules. The same boundary
|
|
185
|
+
covers `@vue/reactivity`, `@vue/runtime-core`, `@vue/runtime-dom`, `@vue/shared` and
|
|
186
|
+
`@vue/server-renderer`.
|
|
187
|
+
Those host primitives cannot
|
|
188
|
+
drive the native renderer. Crepus must lower supported primitives to Moonshine
|
|
189
|
+
or report unsupported imports. Type-only declarations are unaffected;
|
|
190
|
+
the explicit legacy `--react` target keeps its existing dependency contract.
|
|
191
|
+
|
|
192
|
+
Native CLI installs do not require React/Solid renderers or Crepus/WASM. Legacy
|
|
193
|
+
renderers and the historical WASM frontend probe are optional peers. React and
|
|
194
|
+
Crepus scaffolds install their selected renderer explicitly. Legacy
|
|
195
|
+
preview resolves that renderer from the application first, then the CLI install;
|
|
196
|
+
if absent, its error names the package to install. Native preview uses the
|
|
197
|
+
compiled native renderer without loading a host renderer.
|
package/bin/moonshine.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { compileCommand } from "../src/compile";
|
|
5
|
-
import { devCommand } from "../src/dev";
|
|
6
|
-
import { inspectCommand } from "../src/inspect";
|
|
7
|
-
import { newCommand } from "../src/new";
|
|
8
|
-
import { previewCommand } from "../src/preview";
|
|
2
|
+
// oxlint-disable-next-line unicorn/require-module-specifiers -- Top-level await requires an explicit module.
|
|
3
|
+
export {};
|
|
9
4
|
|
|
10
5
|
const [cmd, ...args] = Bun.argv.slice(2);
|
|
11
6
|
|
|
@@ -13,17 +8,23 @@ function usage(code = 0): never {
|
|
|
13
8
|
console.error(`moonshine — Bun-first hyperminimal UI runtime
|
|
14
9
|
|
|
15
10
|
Usage:
|
|
16
|
-
moonshine new <name> [--react|--solid|--crepus] [--adapter bun|node|cloudflare|vercel] [--vite]
|
|
11
|
+
moonshine new <name> [--native|--react|--solid|--crepus] [--adapter bun|node|cloudflare|vercel] [--vite]
|
|
12
|
+
--native independent runtime (default; server uses Bun)
|
|
17
13
|
--react add React renderer
|
|
18
|
-
--solid
|
|
14
|
+
--solid alias for the independent native app
|
|
19
15
|
--crepus add Crepus renderer
|
|
20
16
|
--adapter deployment target (default: bun)
|
|
21
|
-
--vite client-only Vite SPA
|
|
17
|
+
--vite client-only Vite SPA (native or --react)
|
|
22
18
|
moonshine adopt [dir] Convert the app you are standing in to moonshine
|
|
23
19
|
--dry-run print the plan, write nothing
|
|
24
20
|
--yes, -y skip the confirmation prompt
|
|
25
21
|
--force rewrite an existing moonshine.config.ts
|
|
26
|
-
|
|
22
|
+
--compiler <path> Crepus compiler for native template adoption
|
|
23
|
+
moonshine compile <source> Crepus frontend → independent .dom.ts
|
|
24
|
+
--ssr emit .ssr.ts instead
|
|
25
|
+
--react explicit legacy React output (.tsx); accepts JSON IR
|
|
26
|
+
--compiler <path> Crepus compiler (default: crepus on PATH)
|
|
27
|
+
--site <root> source root for imports outside the entry directory
|
|
27
28
|
moonshine build [dir] Build project into .moonshine/manifest.json
|
|
28
29
|
--adapter bun|node|cloudflare|vercel
|
|
29
30
|
moonshine inspect [path] Inspect build manifest
|
|
@@ -37,29 +38,42 @@ Usage:
|
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
switch (cmd) {
|
|
40
|
-
case "new":
|
|
41
|
+
case "new": {
|
|
42
|
+
const { newCommand } = await import("../src/new");
|
|
41
43
|
await newCommand(args);
|
|
42
44
|
break;
|
|
45
|
+
}
|
|
43
46
|
case "adopt": {
|
|
47
|
+
const { adoptCommand } = await import("../src/adopt");
|
|
44
48
|
const result = await adoptCommand(args);
|
|
45
49
|
if (result.code !== 0) process.exit(result.code);
|
|
46
50
|
break;
|
|
47
51
|
}
|
|
48
|
-
case "compile":
|
|
52
|
+
case "compile": {
|
|
53
|
+
const { compileCommand } = await import("../src/compile");
|
|
49
54
|
await compileCommand(args);
|
|
50
55
|
break;
|
|
51
|
-
|
|
56
|
+
}
|
|
57
|
+
case "build": {
|
|
58
|
+
const { buildCommand } = await import("../src/build");
|
|
52
59
|
await buildCommand(args);
|
|
53
60
|
break;
|
|
54
|
-
|
|
61
|
+
}
|
|
62
|
+
case "inspect": {
|
|
63
|
+
const { inspectCommand } = await import("../src/inspect");
|
|
55
64
|
await inspectCommand(args);
|
|
56
65
|
break;
|
|
57
|
-
|
|
66
|
+
}
|
|
67
|
+
case "preview": {
|
|
68
|
+
const { previewCommand } = await import("../src/preview");
|
|
58
69
|
await previewCommand(args);
|
|
59
70
|
break;
|
|
60
|
-
|
|
71
|
+
}
|
|
72
|
+
case "dev": {
|
|
73
|
+
const { devCommand } = await import("../src/dev");
|
|
61
74
|
await devCommand(args);
|
|
62
75
|
break;
|
|
76
|
+
}
|
|
63
77
|
case "-h":
|
|
64
78
|
case "--help":
|
|
65
79
|
case "help":
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tschk/moonshine-cli",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.49",
|
|
4
4
|
"description": "Bun CLI for moonshine — new, dev, build, preview, inspect, compile",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"type": "module",
|
|
@@ -19,17 +19,14 @@
|
|
|
19
19
|
"crepus"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@tschk/
|
|
23
|
-
"@tschk/
|
|
24
|
-
"@tschk/moonshine-
|
|
25
|
-
"@tschk/moonshine-
|
|
26
|
-
"@tschk/moonshine-
|
|
27
|
-
"@tschk/moonshine-
|
|
28
|
-
"@tschk/moonshine-
|
|
29
|
-
"@tschk/moonshine-
|
|
30
|
-
"@tschk/moonshine-server": "^0.4.1",
|
|
31
|
-
"@tschk/moonshine-tanstack": "^0.4.1",
|
|
32
|
-
"@tschk/moonshine-waku": "^0.4.1"
|
|
22
|
+
"@tschk/moonshine-compiler": "^0.4.48",
|
|
23
|
+
"@tschk/moonshine-deploy-bun": "^0.4.48",
|
|
24
|
+
"@tschk/moonshine-framework": "^0.4.48",
|
|
25
|
+
"@tschk/moonshine-next": "^0.4.48",
|
|
26
|
+
"@tschk/moonshine-react-router": "^0.4.48",
|
|
27
|
+
"@tschk/moonshine-server": "^0.4.48",
|
|
28
|
+
"@tschk/moonshine-tanstack": "^0.4.48",
|
|
29
|
+
"@tschk/moonshine-waku": "^0.4.48"
|
|
33
30
|
},
|
|
34
31
|
"scripts": {
|
|
35
32
|
"format": "bunx prettier --check .",
|
|
@@ -37,7 +34,24 @@
|
|
|
37
34
|
"typecheck": "exit 0",
|
|
38
35
|
"test": "bun test"
|
|
39
36
|
},
|
|
40
|
-
"
|
|
41
|
-
"@tschk/moonshine-
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@tschk/moonshine-react": "^0.4.48",
|
|
39
|
+
"@tschk/crepus-moonshine": "^0.4.48",
|
|
40
|
+
"@tschk/crepuscularity-wasm": "^0.1.3",
|
|
41
|
+
"@tschk/moonshine-solid": "^0.4.48"
|
|
42
|
+
},
|
|
43
|
+
"peerDependenciesMeta": {
|
|
44
|
+
"@tschk/moonshine-react": {
|
|
45
|
+
"optional": true
|
|
46
|
+
},
|
|
47
|
+
"@tschk/crepus-moonshine": {
|
|
48
|
+
"optional": true
|
|
49
|
+
},
|
|
50
|
+
"@tschk/crepuscularity-wasm": {
|
|
51
|
+
"optional": true
|
|
52
|
+
},
|
|
53
|
+
"@tschk/moonshine-solid": {
|
|
54
|
+
"optional": true
|
|
55
|
+
}
|
|
42
56
|
}
|
|
43
57
|
}
|
package/src/adopt/gaps.ts
CHANGED
|
@@ -16,6 +16,20 @@ export async function findManualWork(
|
|
|
16
16
|
if (!manual.includes(text)) manual.push(text);
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
+
if (scan.framework === "waku") {
|
|
20
|
+
note(
|
|
21
|
+
"Waku RSC, server actions, slices, interceptors and middleware are not implemented; route discovery does not replace their runtime.",
|
|
22
|
+
);
|
|
23
|
+
note(
|
|
24
|
+
"Waku getConfig() is not read; render/staticPaths settings need Moonshine route configuration.",
|
|
25
|
+
);
|
|
26
|
+
if (files.some((file) => file.startsWith(`${scan.routesDir}/_api/`))) {
|
|
27
|
+
note(
|
|
28
|
+
"Waku _api paths support named HTTP method exports and handler(request); the Waku-specific second context argument requires porting.",
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
19
33
|
for (const candidate of [
|
|
20
34
|
"middleware.ts",
|
|
21
35
|
"middleware.js",
|
|
@@ -39,7 +53,7 @@ export async function findManualWork(
|
|
|
39
53
|
}
|
|
40
54
|
}
|
|
41
55
|
|
|
42
|
-
const results: { file: string; source: string }[] = Array.from({
|
|
56
|
+
const results: { file: string; source: string }[] = Array.from({
|
|
43
57
|
length: files.length,
|
|
44
58
|
}) as { file: string; source: string }[];
|
|
45
59
|
let currentIndex = 0;
|
|
@@ -150,7 +164,7 @@ export function templateManualWork(
|
|
|
150
164
|
if (!templateGlobs(framework) || templates.length === 0) return [];
|
|
151
165
|
const boundary: Readonly<Record<string, string>> = {
|
|
152
166
|
svelte:
|
|
153
|
-
"<script> blocks are not executed: runes, stores, reactive statements, lifecycle hooks and event handler bodies are
|
|
167
|
+
"<script> blocks are not executed: runes, stores, reactive statements, lifecycle hooks and event handler bodies are discarded, not run. Port that logic to moonshine signals.",
|
|
154
168
|
vue: "<script> blocks are not executed: the Composition API, reactive refs, computed properties and lifecycle hooks do not run. Port that logic to moonshine signals.",
|
|
155
169
|
astro:
|
|
156
170
|
"The `---` frontmatter is blanked, never executed: imports, top-level awaits, data fetching and `Astro.props` do not run. Only the markup below it is compiled.",
|
|
@@ -166,21 +180,34 @@ export function templateManualWork(
|
|
|
166
180
|
const notes: string[] = [boundary[framework]!];
|
|
167
181
|
if (rejects[framework]) notes.push(rejects[framework]!);
|
|
168
182
|
notes.push(
|
|
169
|
-
"
|
|
183
|
+
"Native SSR components contain unchanged Crepus compiler output produced at adopt time. Re-run `moonshine adopt --force` after editing a template.",
|
|
170
184
|
);
|
|
185
|
+
notes.push(
|
|
186
|
+
"Generated routes for removed source templates are not tracked or deleted automatically; review the generated route directory and retire stale routes explicitly.",
|
|
187
|
+
);
|
|
188
|
+
notes.push(
|
|
189
|
+
"Native adoption renders SSR only, without hydration or browser handlers. Route scope exposes only params and data; port all other state, writable bindings and handlers explicitly. Source scripts are never executed. Referenced images/assets are not emitted or copied by Crepus; review generated URLs and include assets explicitly in the application build. Use moonshine compile for an explicit DOM component and author a clientFile for SPA behavior.",
|
|
190
|
+
);
|
|
191
|
+
notes.push(
|
|
192
|
+
"Review generated forms and accessibility before replacing the original: accepted markup may lose form/submit semantics; v-model remains read-only without authored handlers. Verified Vue/Svelte email fixtures preserve type, explicit name, required, IDs, label associations and aria-label; review other frontend and attribute combinations.",
|
|
193
|
+
);
|
|
194
|
+
if (["svelte", "vue", "astro"].includes(framework))
|
|
195
|
+
notes.push(
|
|
196
|
+
"Component styles are not preserved by native emission: Svelte/Vue <style> blocks and scoped CSS are lost, and Astro <style> blocks can fail compilation. Port styles to authored CSS imports until Crepus supplies a stylesheet asset contract.",
|
|
197
|
+
);
|
|
171
198
|
if (framework === "angular") {
|
|
172
199
|
notes.push(
|
|
173
|
-
"Angular has no file-based routing, so no component is mounted at a URL. The generated
|
|
200
|
+
"Angular has no file-based routing, so no component is mounted at a URL. The generated SSR component is compiled but unrouted until you write route modules that render it.",
|
|
174
201
|
);
|
|
175
202
|
}
|
|
176
203
|
for (const template of templates) {
|
|
177
204
|
if (!template.ok) {
|
|
178
205
|
notes.push(
|
|
179
|
-
`${template.file}: did not compile — ${template.error}. No route was generated for it;
|
|
206
|
+
`${template.file}: did not compile — ${template.error}. No route was generated for it; the compiler diagnostic must be resolved before mounting it.`,
|
|
180
207
|
);
|
|
181
208
|
} else if (!template.route) {
|
|
182
209
|
notes.push(
|
|
183
|
-
`${template.file}: compiled (${template.nodes} nodes) but maps to no URL, so it is not mounted. Its
|
|
210
|
+
`${template.file}: compiled (${template.nodes} nodes) but maps to no URL, so it is not mounted. Its SSR component is in ${template.generated} — import that from a route module to render it.`,
|
|
184
211
|
);
|
|
185
212
|
}
|
|
186
213
|
}
|
package/src/adopt/plan.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { AdoptChange, AdoptPlan, AdoptScan, Framework } from "./types.js";
|
|
|
6
6
|
import { RUNTIME_DEPS, readJson, toPosix } from "./scan.js";
|
|
7
7
|
import { planTemplateRoutes } from "./templates.js";
|
|
8
8
|
import { scanProject } from "./project.js";
|
|
9
|
-
import { detectMoonshineRoot, packagePath } from "../new.js";
|
|
9
|
+
import { detectMoonshineRoot, packagePath, localOverrides } from "../new.js";
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Where the project will find `@tschk/moonshine-next` on disk. Only installed
|
|
@@ -53,6 +53,14 @@ export function aliasPaths(
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
function planTsconfig(scan: AdoptScan): AdoptChange {
|
|
56
|
+
if (templateGlobs(scan.framework))
|
|
57
|
+
return {
|
|
58
|
+
file: "tsconfig.json",
|
|
59
|
+
action: "none",
|
|
60
|
+
details: [],
|
|
61
|
+
summary: "native templates need no JSX or host import aliases",
|
|
62
|
+
alreadyApplied: true,
|
|
63
|
+
};
|
|
56
64
|
const path = join(scan.projectDir, "tsconfig.json");
|
|
57
65
|
const existing =
|
|
58
66
|
readJson<{ compilerOptions?: Record<string, unknown> }>(path) ?? {};
|
|
@@ -102,7 +110,11 @@ function planConfig(scan: AdoptScan, force: boolean): AdoptChange {
|
|
|
102
110
|
const entries: Record<string, unknown> = {
|
|
103
111
|
runtime: "bun",
|
|
104
112
|
adapter: "bun",
|
|
105
|
-
renderer: "react",
|
|
113
|
+
renderer: templateGlobs(scan.framework) ? "native" : "react",
|
|
114
|
+
...(templateGlobs(scan.framework) && { mode: "ssr" }),
|
|
115
|
+
...(["next-app", "next-pages"].includes(scan.framework) && {
|
|
116
|
+
requestContext: true,
|
|
117
|
+
}),
|
|
106
118
|
...(scan.routesDir && { routesDir: scan.routesDir }),
|
|
107
119
|
...(scan.convention && { convention: scan.convention }),
|
|
108
120
|
};
|
|
@@ -128,12 +140,14 @@ export default defineConfig(${JSON.stringify(entries, null, 2)});
|
|
|
128
140
|
};
|
|
129
141
|
}
|
|
130
142
|
|
|
131
|
-
function planPackageJson(scan: AdoptScan): AdoptChange {
|
|
143
|
+
async function planPackageJson(scan: AdoptScan): Promise<AdoptChange> {
|
|
132
144
|
const path = join(scan.projectDir, "package.json");
|
|
133
145
|
const pkg =
|
|
134
146
|
readJson<{
|
|
135
147
|
dependencies?: Record<string, string>;
|
|
136
148
|
scripts?: Record<string, string>;
|
|
149
|
+
devDependencies?: Record<string, string>;
|
|
150
|
+
overrides?: Record<string, string>;
|
|
137
151
|
}>(path) ?? {};
|
|
138
152
|
const root = detectMoonshineRoot();
|
|
139
153
|
const version = `^${cliVersion()}`;
|
|
@@ -143,9 +157,15 @@ function planPackageJson(scan: AdoptScan): AdoptChange {
|
|
|
143
157
|
const adapter = adapterFor(scan.framework);
|
|
144
158
|
const template = templateGlobs(scan.framework) !== undefined;
|
|
145
159
|
for (const name of [
|
|
146
|
-
...
|
|
160
|
+
...(template
|
|
161
|
+
? RUNTIME_DEPS.filter(
|
|
162
|
+
(pkgName) =>
|
|
163
|
+
pkgName !== "@tschk/moonshine-react" &&
|
|
164
|
+
pkgName !== "@tschk/moonshine-compiler",
|
|
165
|
+
)
|
|
166
|
+
: RUNTIME_DEPS),
|
|
147
167
|
...(adapter ? [adapter.pkg] : []),
|
|
148
|
-
...(template ? ["@tschk/
|
|
168
|
+
...(template ? ["@tschk/moonshine-dom"] : []),
|
|
149
169
|
] as string[]) {
|
|
150
170
|
if (dependencies[name]) continue;
|
|
151
171
|
const spec = packagePath(name, root, version);
|
|
@@ -154,6 +174,21 @@ function planPackageJson(scan: AdoptScan): AdoptChange {
|
|
|
154
174
|
added.push(name);
|
|
155
175
|
}
|
|
156
176
|
|
|
177
|
+
const devDependencies = { ...pkg.devDependencies };
|
|
178
|
+
const addedDev: string[] = [];
|
|
179
|
+
if (template)
|
|
180
|
+
for (const name of ["@tschk/moonshine-cli", "@tschk/moonshine-compiler"]) {
|
|
181
|
+
if (!dependencies[name] && !devDependencies[name]) {
|
|
182
|
+
devDependencies[name] = packagePath(name, root, version)!;
|
|
183
|
+
addedDev.push(name);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
const overrides =
|
|
187
|
+
template && root
|
|
188
|
+
? { ...(await localOverrides(root)), ...pkg.overrides }
|
|
189
|
+
: pkg.overrides;
|
|
190
|
+
const overridesChanged =
|
|
191
|
+
JSON.stringify(overrides) !== JSON.stringify(pkg.overrides);
|
|
157
192
|
const scripts = { ...pkg.scripts };
|
|
158
193
|
const repointed: string[] = [];
|
|
159
194
|
const mapping: Record<string, string> = {
|
|
@@ -174,8 +209,14 @@ function planPackageJson(scan: AdoptScan): AdoptChange {
|
|
|
174
209
|
repointed.push(key);
|
|
175
210
|
}
|
|
176
211
|
|
|
177
|
-
const alreadyApplied =
|
|
212
|
+
const alreadyApplied =
|
|
213
|
+
added.length === 0 &&
|
|
214
|
+
addedDev.length === 0 &&
|
|
215
|
+
!overridesChanged &&
|
|
216
|
+
repointed.length === 0;
|
|
178
217
|
const parts: string[] = [];
|
|
218
|
+
if (addedDev.length) parts.push(`+${addedDev.length} dev dependencies`);
|
|
219
|
+
if (overridesChanged) parts.push("local workspace overrides");
|
|
179
220
|
if (added.length) parts.push(`+${added.length} dependencies`);
|
|
180
221
|
if (repointed.length)
|
|
181
222
|
parts.push(`scripts ${repointed.join(", ")} → moonshine`);
|
|
@@ -187,32 +228,57 @@ function planPackageJson(scan: AdoptScan): AdoptChange {
|
|
|
187
228
|
...added.map(
|
|
188
229
|
(name) => `dependencies["${name}"] = "${dependencies[name]}"`,
|
|
189
230
|
),
|
|
231
|
+
...addedDev.map(
|
|
232
|
+
(name) => `devDependencies["${name}"] = "${devDependencies[name]}"`,
|
|
233
|
+
),
|
|
234
|
+
...(overridesChanged
|
|
235
|
+
? ["local workspace overrides (existing overrides preserved)"]
|
|
236
|
+
: []),
|
|
190
237
|
...repointed.map((key) => `scripts["${key}"] = "${scripts[key]}"`),
|
|
191
238
|
],
|
|
192
239
|
summary: alreadyApplied ? "already adopted" : parts.join(", "),
|
|
193
240
|
alreadyApplied,
|
|
194
|
-
contents:
|
|
241
|
+
contents:
|
|
242
|
+
JSON.stringify(
|
|
243
|
+
{
|
|
244
|
+
...pkg,
|
|
245
|
+
dependencies,
|
|
246
|
+
...(template ? { devDependencies } : {}),
|
|
247
|
+
...(overrides ? { overrides } : {}),
|
|
248
|
+
scripts,
|
|
249
|
+
},
|
|
250
|
+
null,
|
|
251
|
+
2,
|
|
252
|
+
) + "\n",
|
|
195
253
|
};
|
|
196
254
|
}
|
|
197
255
|
|
|
198
256
|
function cliVersion(): string {
|
|
199
257
|
const pkg = readJson<{ version?: string }>(
|
|
200
|
-
join(import.meta.dir, "
|
|
258
|
+
join(import.meta.dir, "../..", "package.json"),
|
|
201
259
|
);
|
|
202
260
|
return pkg?.version ?? "0.3.2";
|
|
203
261
|
}
|
|
204
262
|
|
|
205
263
|
export async function planAdoption(
|
|
206
264
|
projectDir: string,
|
|
207
|
-
options: { force?: boolean } = {},
|
|
265
|
+
options: { force?: boolean; compiler?: string } = {},
|
|
208
266
|
): Promise<AdoptPlan> {
|
|
209
|
-
const scan = await scanProject(projectDir);
|
|
267
|
+
const scan = await scanProject(projectDir, options);
|
|
268
|
+
if (
|
|
269
|
+
scan.templates.length > 0 &&
|
|
270
|
+
scan.templates.every((template) => !template.ok)
|
|
271
|
+
) {
|
|
272
|
+
throw new Error(
|
|
273
|
+
`No templates compiled; resolve the compiler diagnostics before adopting:\n${scan.templates.map((template) => ` ${template.file}: ${template.error ?? "native emission failed"}`).join("\n")}`,
|
|
274
|
+
);
|
|
275
|
+
}
|
|
210
276
|
return {
|
|
211
277
|
scan,
|
|
212
278
|
changes: [
|
|
213
279
|
planTsconfig(scan),
|
|
214
280
|
planConfig(scan, options.force ?? false),
|
|
215
|
-
planPackageJson(scan),
|
|
281
|
+
await planPackageJson(scan),
|
|
216
282
|
...(await planTemplateRoutes(scan)),
|
|
217
283
|
],
|
|
218
284
|
// Aliasing covers every specifier the adapter implements, so nothing in the
|
package/src/adopt/project.ts
CHANGED
|
@@ -15,7 +15,10 @@ import { compileTemplates } from "./templates.js";
|
|
|
15
15
|
import { findConventions } from "./conventions.js";
|
|
16
16
|
import { ALIAS_CAVEATS, findManualWork, templateManualWork } from "./gaps.js";
|
|
17
17
|
|
|
18
|
-
export async function scanProject(
|
|
18
|
+
export async function scanProject(
|
|
19
|
+
projectDir: string,
|
|
20
|
+
options: { compiler?: string } = {},
|
|
21
|
+
): Promise<AdoptScan> {
|
|
19
22
|
const dir = resolve(projectDir);
|
|
20
23
|
const pkg = readJson<PackageJson>(join(dir, "package.json"));
|
|
21
24
|
const files = sourceFiles(dir);
|
|
@@ -28,11 +31,12 @@ export async function scanProject(projectDir: string): Promise<AdoptScan> {
|
|
|
28
31
|
|
|
29
32
|
const globs = templateGlobs(detected.framework);
|
|
30
33
|
const templates = globs
|
|
31
|
-
? await compileTemplates(dir, detected.framework, globs)
|
|
34
|
+
? await compileTemplates(dir, detected.framework, globs, options.compiler)
|
|
32
35
|
: [];
|
|
33
36
|
|
|
34
37
|
const routes: { path: string; file: string }[] = [];
|
|
35
38
|
if (
|
|
39
|
+
!globs &&
|
|
36
40
|
detected.routesDir &&
|
|
37
41
|
detected.convention &&
|
|
38
42
|
existsSync(join(dir, detected.routesDir))
|
|
@@ -50,6 +54,12 @@ export async function scanProject(projectDir: string): Promise<AdoptScan> {
|
|
|
50
54
|
}
|
|
51
55
|
}
|
|
52
56
|
|
|
57
|
+
if (globs)
|
|
58
|
+
for (const template of templates) {
|
|
59
|
+
if (template.ok && template.route !== undefined && template.generated)
|
|
60
|
+
routes.push({ path: template.route, file: template.generated });
|
|
61
|
+
}
|
|
62
|
+
|
|
53
63
|
return {
|
|
54
64
|
projectDir: dir,
|
|
55
65
|
framework: detected.framework,
|
package/src/adopt/report.ts
CHANGED
|
@@ -26,7 +26,7 @@ export function formatReport(plan: AdoptPlan, dryRun: boolean): string {
|
|
|
26
26
|
if (scan.templates.length) {
|
|
27
27
|
const ok = scan.templates.filter((t) => t.ok);
|
|
28
28
|
push(
|
|
29
|
-
` templates ${ok.length}/${scan.templates.length} compiled to
|
|
29
|
+
` templates ${ok.length}/${scan.templates.length} compiled to native SSR`,
|
|
30
30
|
);
|
|
31
31
|
for (const template of scan.templates) {
|
|
32
32
|
const mark = template.ok
|
|
@@ -35,7 +35,7 @@ export function formatReport(plan: AdoptPlan, dryRun: boolean): string {
|
|
|
35
35
|
: "no url"
|
|
36
36
|
: "FAILED";
|
|
37
37
|
push(
|
|
38
|
-
` ${template.file.padEnd(34)} ${mark.padEnd(7)} ${template.ok ? `${template.nodes} nodes${template.route ? ` → ${template.route}` : ""}` : template.error}`,
|
|
38
|
+
` ${template.file.padEnd(34)} ${mark.padEnd(7)} ${template.ok ? `${template.nodes === undefined ? "native SSR" : `${template.nodes} nodes`}${template.route ? ` → ${template.route}` : ""}` : template.error}`,
|
|
39
39
|
);
|
|
40
40
|
}
|
|
41
41
|
}
|
package/src/adopt/scan.ts
CHANGED
|
@@ -201,6 +201,24 @@ export function detectFramework(
|
|
|
201
201
|
const deps = allDeps(pkg);
|
|
202
202
|
const template = detectTemplateFramework(projectDir, deps);
|
|
203
203
|
if (template) return template;
|
|
204
|
+
if (
|
|
205
|
+
deps.waku ||
|
|
206
|
+
["waku.config.ts", "waku.config.js", "waku.config.mjs"].some((file) =>
|
|
207
|
+
existsSync(join(projectDir, file)),
|
|
208
|
+
)
|
|
209
|
+
) {
|
|
210
|
+
if (existsSync(join(projectDir, "src/pages"))) {
|
|
211
|
+
return { framework: "waku", routesDir: "src/pages", convention: "waku" };
|
|
212
|
+
}
|
|
213
|
+
const routesDir = findMoonshineRoutes(projectDir);
|
|
214
|
+
return {
|
|
215
|
+
framework: "waku",
|
|
216
|
+
...(routesDir && {
|
|
217
|
+
routesDir,
|
|
218
|
+
convention: "moonshine" as RouteConvention,
|
|
219
|
+
}),
|
|
220
|
+
};
|
|
221
|
+
}
|
|
204
222
|
for (const dir of ["app", "src/app"]) {
|
|
205
223
|
if (
|
|
206
224
|
existsSync(join(projectDir, dir, "page.tsx")) ||
|
|
@@ -227,9 +245,6 @@ export function detectFramework(
|
|
|
227
245
|
...(routesDir && { routesDir, convention: "moonshine" as RouteConvention }),
|
|
228
246
|
});
|
|
229
247
|
|
|
230
|
-
if (deps.waku || existsSync(join(projectDir, "waku.config.ts"))) {
|
|
231
|
-
return routed("waku");
|
|
232
|
-
}
|
|
233
248
|
if (deps["@tanstack/react-router"] || deps["@tanstack/react-start"]) {
|
|
234
249
|
return routed("tanstack");
|
|
235
250
|
}
|