@mun-ui/ui 0.0.0-stage → 0.2.1
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 +114 -2
- package/bin/compile.mjs +38 -0
- package/bin/desktop.mjs +143 -0
- package/bin/dev-protocol.mjs +94 -0
- package/bin/formatter.mjs +109 -0
- package/bin/hot-reload.mjs +38 -0
- package/bin/mun.mjs +538 -0
- package/bin/native.mjs +133 -0
- package/bin/pnpm-workspace.mjs +58 -0
- package/bin/program-patch.mjs +104 -0
- package/bin/project.mjs +322 -0
- package/bin/watch.mjs +316 -0
- package/bin/workflow.mjs +261 -0
- package/dist/astro.d.ts +3 -0
- package/dist/astro.d.ts.map +1 -0
- package/dist/astro.js +3 -0
- package/dist/astro.js.map +1 -0
- package/dist/closures.d.ts +2 -0
- package/dist/closures.d.ts.map +1 -0
- package/dist/closures.js +2 -0
- package/dist/closures.js.map +1 -0
- package/dist/compiler/index.d.ts +2 -0
- package/dist/compiler/index.d.ts.map +1 -0
- package/dist/compiler/index.js +2 -0
- package/dist/compiler/index.js.map +1 -0
- package/dist/core.d.ts +3 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +3 -0
- package/dist/core.js.map +1 -0
- package/dist/experimental.d.ts +2 -0
- package/dist/experimental.d.ts.map +1 -0
- package/dist/experimental.js +2 -0
- package/dist/experimental.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/jsx-dev-runtime.d.ts +2 -0
- package/dist/jsx-dev-runtime.d.ts.map +1 -0
- package/dist/jsx-dev-runtime.js +2 -0
- package/dist/jsx-dev-runtime.js.map +1 -0
- package/dist/jsx-runtime.d.ts +2 -0
- package/dist/jsx-runtime.d.ts.map +1 -0
- package/dist/jsx-runtime.js +2 -0
- package/dist/jsx-runtime.js.map +1 -0
- package/dist/legacy.d.ts +3 -0
- package/dist/legacy.d.ts.map +1 -0
- package/dist/legacy.js +3 -0
- package/dist/legacy.js.map +1 -0
- package/dist/mun.d.ts +5 -0
- package/dist/mun.d.ts.map +1 -0
- package/dist/mun.js +4 -0
- package/dist/mun.js.map +1 -0
- package/dist/progressive-blur/index.d.ts +8 -0
- package/dist/progressive-blur/index.d.ts.map +1 -0
- package/dist/progressive-blur/index.js +8 -0
- package/dist/progressive-blur/index.js.map +1 -0
- package/dist/progressive-blur/plan.d.ts +3 -0
- package/dist/progressive-blur/plan.d.ts.map +1 -0
- package/dist/progressive-blur/plan.js +3 -0
- package/dist/progressive-blur/plan.js.map +1 -0
- package/dist/react-types.d.ts +2 -0
- package/dist/react-types.d.ts.map +1 -0
- package/dist/react-types.js +2 -0
- package/dist/react-types.js.map +1 -0
- package/dist/rendering-quality.d.ts +4 -0
- package/dist/rendering-quality.d.ts.map +1 -0
- package/dist/rendering-quality.js +4 -0
- package/dist/rendering-quality.js.map +1 -0
- package/dist/state.d.ts +2 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/state.js +2 -0
- package/dist/state.js.map +1 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/vite.d.ts +2 -0
- package/dist/vite.d.ts.map +1 -0
- package/dist/vite.js +2 -0
- package/dist/vite.js.map +1 -0
- package/editors/install.mjs +102 -0
- package/editors/lsp/mun-lsp.mjs +123 -0
- package/editors/lsp/service.mjs +306 -0
- package/editors/lsp/source.mjs +58 -0
- package/editors/vscode/client.mjs +40 -0
- package/editors/vscode/dev-client.mjs +83 -0
- package/editors/vscode/discovery.mjs +46 -0
- package/editors/vscode/export.mjs +42 -0
- package/editors/vscode/extension.cjs +226 -0
- package/editors/vscode/language-configuration.json +15 -0
- package/editors/vscode/package.json +119 -0
- package/editors/vscode/protocol.mjs +29 -0
- package/editors/vscode/syntaxes/mun.tmLanguage.json +130 -0
- package/native/Cargo.lock +3581 -0
- package/native/Cargo.toml +21 -0
- package/native/README.md +21 -0
- package/native/mun-native/Cargo.toml +23 -0
- package/native/mun-native/src/accessibility.rs +738 -0
- package/native/mun-native/src/dev.rs +604 -0
- package/native/mun-native/src/host_services.rs +202 -0
- package/native/mun-native/src/lib.rs +2843 -0
- package/native/mun-native/src/main.rs +204 -0
- package/native/mun-native/src/offscreen.rs +393 -0
- package/native/mun-native/src/rect.wgsl +63 -0
- package/native/mun-native/src/text.rs +401 -0
- package/native/mun-native/tests/offscreen_rendering.rs +161 -0
- package/native/mun-native/tests/stress.rs +408 -0
- package/native/mun-native/tests/window_lifecycle.rs +183 -0
- package/native/mun-runtime/Cargo.toml +13 -0
- package/native/mun-runtime/src/accessibility.rs +193 -0
- package/native/mun-runtime/src/collection.rs +1090 -0
- package/native/mun-runtime/src/gesture.rs +1070 -0
- package/native/mun-runtime/src/input.rs +325 -0
- package/native/mun-runtime/src/ir.rs +852 -0
- package/native/mun-runtime/src/kinetics.rs +500 -0
- package/native/mun-runtime/src/layout.rs +258 -0
- package/native/mun-runtime/src/layout_cache.rs +209 -0
- package/native/mun-runtime/src/lib.rs +52 -0
- package/native/mun-runtime/src/motion.rs +1162 -0
- package/native/mun-runtime/src/retained.rs +574 -0
- package/native/mun-runtime/src/runtime.rs +7449 -0
- package/native/mun-runtime/src/scene.rs +567 -0
- package/native/mun-runtime/src/scroll.rs +521 -0
- package/native/mun-runtime/src/scroll_view.rs +220 -0
- package/native/mun-runtime/src/text_edit.rs +670 -0
- package/native/mun-runtime/src/timeline.rs +1534 -0
- package/native/mun-runtime/src/validate.rs +677 -0
- package/native/mun-runtime/tests/accessibility_semantics.rs +168 -0
- package/native/mun-runtime/tests/compiler_contract.rs +110 -0
- package/native/mun-runtime/tests/flexible_frames.rs +47 -0
- package/native/mun-runtime/tests/host_services.rs +107 -0
- package/native/mun-runtime/tests/hot_update.rs +367 -0
- package/native/mun-runtime/tests/incremental_runtime.rs +323 -0
- package/native/mun-runtime/tests/ir_validation.rs +167 -0
- package/native/mun-runtime/tests/keyed_collections.rs +251 -0
- package/native/mun-runtime/tests/minimum_window_size.rs +80 -0
- package/native/mun-runtime/tests/native_controls_style.rs +491 -0
- package/native/mun-runtime/tests/native_demo.rs +285 -0
- package/native/mun-runtime/tests/native_layout_style.rs +175 -0
- package/native/mun-runtime/tests/native_settings_pane.rs +152 -0
- package/native/mun-runtime/tests/priority_proposals.rs +69 -0
- package/native/mun-runtime/tests/scroll_view.rs +403 -0
- package/native/mun-runtime/tests/text_editing.rs +491 -0
- package/native/mun-runtime/tests/text_proposals.rs +42 -0
- package/native/mun-runtime/tests/typography.rs +63 -0
- package/package.json +213 -3
- package/schemas/README.md +19 -0
- package/schemas/semantic-ui-ir-v1.schema.json +2061 -0
- package/templates/desktop/gitignore +5 -0
- package/templates/desktop/package.json +10 -0
- package/templates/desktop/src-tauri/Cargo.toml +14 -0
- package/templates/desktop/src-tauri/build.rs +1 -0
- package/templates/desktop/src-tauri/capabilities/main.json +12 -0
- package/templates/desktop/src-tauri/icons/icon.icns +0 -0
- package/templates/desktop/src-tauri/icons/icon.ico +0 -0
- package/templates/desktop/src-tauri/icons/icon.png +0 -0
- package/templates/desktop/src-tauri/src/main.rs +2 -0
- package/templates/desktop/src-tauri/tauri.conf.json +42 -0
- package/templates/desktop/vite.config.ts +10 -0
- package/templates/native/App.mun +15 -0
- package/templates/native/gitignore +3 -0
- package/templates/native/mun.toml +8 -0
- package/templates/project/gitignore +5 -0
- package/templates/project/index.html +13 -0
- package/templates/project/package.json +24 -0
- package/templates/project/src/App.mun +13 -0
- package/templates/project/src/index.css +30 -0
- package/templates/project/src/main.ts +5 -0
- package/templates/project/tsconfig.json +20 -0
- package/templates/project/vite.config.ts +6 -0
- package/templates/vite/src/App.css +134 -0
- package/templates/vite/src/App.tsx +91 -0
- package/templates/vite/src/index.css +23 -0
- package/templates/vite/vite.config.ts +10 -0
package/bin/watch.mjs
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process'
|
|
2
|
+
import { randomBytes } from 'node:crypto'
|
|
3
|
+
import { mkdirSync, mkdtempSync, rmSync, watch, writeFileSync } from 'node:fs'
|
|
4
|
+
import { createServer } from 'node:net'
|
|
5
|
+
import { tmpdir } from 'node:os'
|
|
6
|
+
import { dirname, resolve } from 'node:path'
|
|
7
|
+
import { DEV_PROTOCOL_VERSION, createFrameDecoder, encodeFrame, listenForHost } from './dev-protocol.mjs'
|
|
8
|
+
import { analyzeCompatibility } from './hot-reload.mjs'
|
|
9
|
+
import { createProgramUpdate } from './program-patch.mjs'
|
|
10
|
+
import { createProjectCompiler, discoverProject, requirePlatform } from './project.mjs'
|
|
11
|
+
import { hostBinary } from './workflow.mjs'
|
|
12
|
+
|
|
13
|
+
// Injectable scheduler and effects make races testable without wall-clock sleeps.
|
|
14
|
+
//
|
|
15
|
+
// `update(running, compiled, analysis)` applies a compatible change to the
|
|
16
|
+
// live process and resolves to the host's report, or throws `HotUpdateRejected`
|
|
17
|
+
// (the previous program and state stay live). Without `update`, or when the
|
|
18
|
+
// analysis demands it, the process is relaunched — and reported as such.
|
|
19
|
+
export class HotUpdateRejected extends Error {}
|
|
20
|
+
|
|
21
|
+
export function createDevLoop({ compile, launch, stop, update, analyze, report = () => {}, schedule = callback => setTimeout(callback, 80), cancel = clearTimeout, verbose = false }) {
|
|
22
|
+
let timer, running, current, busy = false, pending = false, closed = false
|
|
23
|
+
const idleWaiters = []
|
|
24
|
+
const ms = value => `${value.toFixed(value < 10 ? 1 : 0)} ms`
|
|
25
|
+
async function relaunch(compiled, reason) {
|
|
26
|
+
const started = performance.now()
|
|
27
|
+
if (running) { await stop(running); running = undefined }
|
|
28
|
+
if (closed) return
|
|
29
|
+
running = await launch(compiled)
|
|
30
|
+
current = compiled
|
|
31
|
+
if (reason) report(`${reason}\nRelaunched in ${ms(performance.now() - started)}`)
|
|
32
|
+
else report(`Launched in ${ms(performance.now() - started)}`)
|
|
33
|
+
}
|
|
34
|
+
async function rebuild() {
|
|
35
|
+
if (closed) return
|
|
36
|
+
if (busy) { pending = true; return }
|
|
37
|
+
busy = true
|
|
38
|
+
let compiled
|
|
39
|
+
try {
|
|
40
|
+
const started = performance.now()
|
|
41
|
+
try { compiled = await compile() }
|
|
42
|
+
catch (error) {
|
|
43
|
+
report(running ? `Compile failed\n${error.message}\nRunning previous valid build` : `Compile failed\n${error.message}`)
|
|
44
|
+
return
|
|
45
|
+
}
|
|
46
|
+
if (closed) return
|
|
47
|
+
if (compiled?.stats?.reused) return
|
|
48
|
+
report(`Compiled in ${ms(performance.now() - started)}`)
|
|
49
|
+
if (running && running.exited) { running = undefined; current = undefined }
|
|
50
|
+
if (!running) { await relaunch(compiled); return }
|
|
51
|
+
if (!update || !analyze) { await relaunch(compiled, 'Relaunched native app (state reset).'); return }
|
|
52
|
+
const analysisStarted = performance.now()
|
|
53
|
+
const analysis = analyze(current, compiled)
|
|
54
|
+
if (verbose) report(`Compatibility analysis: ${ms(performance.now() - analysisStarted)}`)
|
|
55
|
+
if (analysis.mode === 'restart') { await relaunch(compiled, `Structural change requires process restart: ${analysis.reason}`); return }
|
|
56
|
+
const updateStarted = performance.now()
|
|
57
|
+
let result
|
|
58
|
+
try { result = await update(running, compiled, analysis) }
|
|
59
|
+
catch (error) {
|
|
60
|
+
if (error instanceof HotUpdateRejected) { report(`Hot update rejected: ${error.message}\nRunning previous valid build`); return }
|
|
61
|
+
await relaunch(compiled, `Hot update unavailable (${error.message}); restarting`)
|
|
62
|
+
return
|
|
63
|
+
}
|
|
64
|
+
current = compiled
|
|
65
|
+
const lines = [`Hot reload applied in ${ms(performance.now() - updateStarted)}`]
|
|
66
|
+
if (result.preservedStates) lines.push(`Preserved ${result.preservedStates} state scope${result.preservedStates === 1 ? '' : 's'}`)
|
|
67
|
+
const reset = analysis.reset.length
|
|
68
|
+
if (reset) lines.push(`Reset ${reset} incompatible state scope${reset === 1 ? '' : 's'}${verbose ? `: ${analysis.reset.map(item => `${item.name} (${item.reason})`).join(', ')}` : ''}`)
|
|
69
|
+
if (verbose) lines.push(`Host apply ${(result.applyMicros / 1000).toFixed(2)} ms; nodes +${result.insertedNodes}/-${result.removedNodes}; added states ${analysis.added.length}, released ${analysis.removed.length}`)
|
|
70
|
+
report(lines.join('\n'))
|
|
71
|
+
} catch (error) { report(error.message) }
|
|
72
|
+
finally {
|
|
73
|
+
busy = false
|
|
74
|
+
for (const resolve of idleWaiters.splice(0)) resolve()
|
|
75
|
+
if (pending && !closed) { pending = false; changed() }
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function changed() {
|
|
79
|
+
if (closed) return
|
|
80
|
+
if (timer !== undefined) cancel(timer)
|
|
81
|
+
timer = schedule(() => { timer = undefined; void rebuild() })
|
|
82
|
+
}
|
|
83
|
+
async function close() {
|
|
84
|
+
closed = true
|
|
85
|
+
if (timer !== undefined) cancel(timer)
|
|
86
|
+
// Wait until an in-flight launch settles, then stop its process.
|
|
87
|
+
if (busy) await new Promise(resolve => idleWaiters.push(resolve))
|
|
88
|
+
if (running) { await stop(running); running = undefined }
|
|
89
|
+
}
|
|
90
|
+
return { changed, rebuild, close, get running() { return running } }
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function stopChild(child) {
|
|
94
|
+
if (child.exitCode !== null || child.signalCode !== null) return Promise.resolve()
|
|
95
|
+
return new Promise(resolve => {
|
|
96
|
+
const timer = setTimeout(() => child.kill('SIGKILL'), 2000)
|
|
97
|
+
child.once('close', () => { clearTimeout(timer); resolve() })
|
|
98
|
+
child.kill('SIGTERM')
|
|
99
|
+
})
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Launch the native host in explicit development mode, connected to a fresh loopback channel. */
|
|
103
|
+
async function launchDevHost(project, compiled, env, onEvent) {
|
|
104
|
+
const listener = await listenForHost({ irVersion: compiled.program.version, onEvent })
|
|
105
|
+
const directory = mkdtempSync(resolve(tmpdir(), 'mun-dev-'))
|
|
106
|
+
const path = resolve(directory, 'program.mun.ir.json')
|
|
107
|
+
writeFileSync(path, JSON.stringify(compiled.program))
|
|
108
|
+
let child
|
|
109
|
+
try {
|
|
110
|
+
child = spawn(hostBinary(project, compiled.program, env), ['--dev', path], {
|
|
111
|
+
cwd: project.root,
|
|
112
|
+
env: { ...env, MUN_DEV_ENDPOINT: listener.endpoint, MUN_DEV_TOKEN: listener.token },
|
|
113
|
+
stdio: 'inherit',
|
|
114
|
+
})
|
|
115
|
+
} catch (error) { listener.close(); rmSync(directory, { recursive: true, force: true }); throw error }
|
|
116
|
+
const running = { child, exited: false, program: compiled.program, metadata: compiled.metadata, revision: 0, runtimeDiagnostics: [] }
|
|
117
|
+
child.once('close', () => { running.exited = true; listener.close(); rmSync(directory, { recursive: true, force: true }) })
|
|
118
|
+
const failed = new Promise((_, reject) => {
|
|
119
|
+
child.once('error', reject)
|
|
120
|
+
child.once('close', code => reject(new Error(`Native app exited (${code}) before connecting`)))
|
|
121
|
+
})
|
|
122
|
+
const timeout = new Promise((_, reject) => setTimeout(() => reject(new Error('Native app did not connect within 60 s')), 60000).unref())
|
|
123
|
+
try { running.channel = await Promise.race([listener.connection, failed, timeout]) }
|
|
124
|
+
catch (error) { await stopChild(child); throw error }
|
|
125
|
+
return running
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function sourceForNode(metadata, id) {
|
|
129
|
+
if (!id) return undefined
|
|
130
|
+
return metadata?.nodes?.find(node => node.id === id && node.file && node.line && node.column)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const micros = value => `${(value / 1000).toFixed(2)} ms`
|
|
134
|
+
|
|
135
|
+
/** Host-side stages of an applied update (`update-applied.timings`). */
|
|
136
|
+
export function formatHostTimings(timings) {
|
|
137
|
+
return `Host: queue ${micros(timings.queueMicros)}, decode ${micros(timings.decodeMicros)}, patch ${micros(timings.patchMicros)}, load ${micros(timings.loadMicros)}, materialize ${micros(timings.materializeMicros)}, reconcile ${micros(timings.reconcileMicros)}`
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** First presented frame of a hot update (`update-presented`). */
|
|
141
|
+
export function formatPresentation(message) {
|
|
142
|
+
const frame = message.frame
|
|
143
|
+
const skipped = message.skippedFrames ? `; ${message.skippedFrames} skipped frame(s) while hidden` : ''
|
|
144
|
+
const superseded = message.supersededRevisions ? `; superseded ${message.supersededRevisions} unpresented revision(s)` : ''
|
|
145
|
+
return `Presented revision ${message.revision} ${micros(message.receiveToPresentMicros)} after receipt: layout ${micros(frame.layoutMicros)}, prepare ${micros(frame.prepareMicros)}, acquire ${micros(frame.acquireMicros)}, submit ${micros(frame.submitMicros)}, present ${micros(frame.presentMicros)}${skipped}${superseded}`
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export function formatRuntimeDiagnostic(message, metadata) {
|
|
149
|
+
const source = sourceForNode(metadata, message.node)
|
|
150
|
+
const location = source ? `${source.file}:${source.line}:${source.column}: ` : ''
|
|
151
|
+
const node = message.node && !source ? ` (at ${message.node})` : ''
|
|
152
|
+
return `${location}Runtime ${message.severity}: ${message.message}${node}`
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function enrichInspectorSnapshot(snapshot, metadata, devRevision, runtimeDiagnostics = []) {
|
|
156
|
+
const sources = new Map((metadata?.nodes ?? []).filter(node => node.file).map(node => [node.id, node]))
|
|
157
|
+
return {
|
|
158
|
+
...snapshot,
|
|
159
|
+
devRevision,
|
|
160
|
+
runtimeDiagnostics: runtimeDiagnostics.map(diagnostic => {
|
|
161
|
+
const source = sourceForNode(metadata, diagnostic.node)
|
|
162
|
+
return { ...diagnostic, ...(source ? { source: { file: source.file, line: source.line, column: source.column, endLine: source.endLine, endColumn: source.endColumn } } : {}) }
|
|
163
|
+
}),
|
|
164
|
+
nodes: snapshot.nodes.map(node => {
|
|
165
|
+
const span = sources.get(node.id)
|
|
166
|
+
if (!span) return node
|
|
167
|
+
return {
|
|
168
|
+
...node,
|
|
169
|
+
source: {
|
|
170
|
+
file: span.file,
|
|
171
|
+
line: span.line,
|
|
172
|
+
column: span.column,
|
|
173
|
+
endLine: span.endLine,
|
|
174
|
+
endColumn: span.endColumn,
|
|
175
|
+
},
|
|
176
|
+
}
|
|
177
|
+
}),
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export async function develop(project, { env, verbose = false }) {
|
|
182
|
+
requirePlatform(project)
|
|
183
|
+
const compiler = createProjectCompiler(project)
|
|
184
|
+
const log = message => console.log(message)
|
|
185
|
+
let loop
|
|
186
|
+
const onEvent = message => {
|
|
187
|
+
if (message.type === 'diagnostic') {
|
|
188
|
+
const running = loop?.running
|
|
189
|
+
if (running) {
|
|
190
|
+
running.runtimeDiagnostics ??= []
|
|
191
|
+
running.runtimeDiagnostics.push(message)
|
|
192
|
+
if (running.runtimeDiagnostics.length > 100) running.runtimeDiagnostics.splice(0, running.runtimeDiagnostics.length - 100)
|
|
193
|
+
}
|
|
194
|
+
console.error(formatRuntimeDiagnostic(message, running?.metadata))
|
|
195
|
+
} else if (message.type === 'protocol-error') console.error(`Dev protocol error: ${message.message}`)
|
|
196
|
+
else if (message.type === 'update-presented' && verbose) log(formatPresentation(message))
|
|
197
|
+
}
|
|
198
|
+
loop = createDevLoop({
|
|
199
|
+
verbose,
|
|
200
|
+
compile: () => {
|
|
201
|
+
const manifest = discoverProject(project.root).manifest
|
|
202
|
+
if (JSON.stringify(manifest) !== JSON.stringify(project.manifest)) { project = { ...project, manifest }; compiler.invalidate() }
|
|
203
|
+
requirePlatform(project)
|
|
204
|
+
const result = compiler.compile()
|
|
205
|
+
if (verbose && !result.stats.reused) {
|
|
206
|
+
for (const path of result.stats.changedFiles) log(`Changed: ${path}`)
|
|
207
|
+
const stats = result.stats
|
|
208
|
+
log(`Read ${stats.filesRead} file(s) in ${result.timings.read.toFixed(1)} ms; reparsed ${stats.filesReparsed} file(s); analysis+lowering ${(result.timings.lower ?? 0).toFixed(1)} ms`)
|
|
209
|
+
if (stats.viewInstancesLowered !== undefined) {
|
|
210
|
+
log(`Changed declarations: ${stats.changedDeclarations.join(', ') || 'none'}; affected Views: ${stats.affectedViews.join(', ') || 'none'}`)
|
|
211
|
+
log(`View instances lowered ${stats.viewInstancesLowered}, reused ${stats.viewInstancesReused}; relowered declarations: ${stats.relowered.join(', ')}`)
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return result
|
|
215
|
+
},
|
|
216
|
+
launch: compiled => launchDevHost(project, compiled, env, onEvent),
|
|
217
|
+
analyze: analyzeCompatibility,
|
|
218
|
+
update: async (running, compiled, analysis) => {
|
|
219
|
+
const started = performance.now()
|
|
220
|
+
const baseRevision = running.revision
|
|
221
|
+
const revision = baseRevision + 1
|
|
222
|
+
let update = createProgramUpdate(running.program, compiled.program, {
|
|
223
|
+
baseRevision,
|
|
224
|
+
revision,
|
|
225
|
+
preserve: analysis.preserve,
|
|
226
|
+
})
|
|
227
|
+
let reply = await running.channel.request(update.type, update.payload)
|
|
228
|
+
// A malformed/stale patch is safe to recover from: the host has not
|
|
229
|
+
// advanced its revision, so resend the exact same semantic update in full.
|
|
230
|
+
if (reply.type === 'update-rejected' && update.type === 'patch' && ['patch-invalid', 'patch-unavailable'].includes(reply.code) && reply.currentRevision === baseRevision) {
|
|
231
|
+
update = createProgramUpdate(running.program, compiled.program, {
|
|
232
|
+
baseRevision,
|
|
233
|
+
revision,
|
|
234
|
+
preserve: analysis.preserve,
|
|
235
|
+
patchRatio: 0,
|
|
236
|
+
})
|
|
237
|
+
reply = await running.channel.request('update', update.payload)
|
|
238
|
+
}
|
|
239
|
+
if (reply.type === 'update-rejected') throw new HotUpdateRejected(reply.message)
|
|
240
|
+
if (reply.type !== 'update-applied' || reply.revision !== revision) throw new Error(`Native host returned invalid dev revision ${reply.revision ?? '<missing>'}; expected ${revision}`)
|
|
241
|
+
running.program = compiled.program
|
|
242
|
+
running.metadata = compiled.metadata
|
|
243
|
+
running.revision = revision
|
|
244
|
+
running.runtimeDiagnostics = []
|
|
245
|
+
if (verbose) {
|
|
246
|
+
const reduction = update.fullBytes > 0 ? (100 * (1 - update.bytes / update.fullBytes)).toFixed(1) : '0.0'
|
|
247
|
+
log(`Runtime round trip ${(performance.now() - started).toFixed(1)} ms; ${update.type} ${(update.bytes / 1024).toFixed(1)} KiB vs full ${(update.fullBytes / 1024).toFixed(1)} KiB (${reduction}% smaller); ${update.operationCount} patch op(s); revision ${revision}`)
|
|
248
|
+
if (reply.timings) log(formatHostTimings(reply.timings))
|
|
249
|
+
}
|
|
250
|
+
return reply
|
|
251
|
+
},
|
|
252
|
+
stop: async running => { running.channel?.close(); await stopChild(running.child) },
|
|
253
|
+
report: log,
|
|
254
|
+
})
|
|
255
|
+
const session = await openInspectorEndpoint(project, () => loop.running)
|
|
256
|
+
console.log('Mün dev: state-preserving hot reload for compatible edits; structural changes relaunch. Ctrl-C to stop.')
|
|
257
|
+
const watcher = watch(project.root, { recursive: true }, (_, path) => {
|
|
258
|
+
if (!path || path.split(/[\\/]/u).some(part => part.startsWith('.') || ['node_modules', 'build', 'dist'].includes(part))) return
|
|
259
|
+
if (path.endsWith('.mun') || path === 'mun.toml' || path === 'mun.local.json') loop.changed()
|
|
260
|
+
})
|
|
261
|
+
watcher.on('error', error => console.error(`Watch error: ${error.message}`))
|
|
262
|
+
return new Promise(resolve => {
|
|
263
|
+
let closing = false
|
|
264
|
+
const close = async () => {
|
|
265
|
+
if (closing) return
|
|
266
|
+
closing = true
|
|
267
|
+
watcher.close()
|
|
268
|
+
session.close()
|
|
269
|
+
process.removeListener('SIGINT', close); process.removeListener('SIGTERM', close)
|
|
270
|
+
await loop.close()
|
|
271
|
+
resolve(0)
|
|
272
|
+
}
|
|
273
|
+
process.once('SIGINT', close); process.once('SIGTERM', close)
|
|
274
|
+
void loop.rebuild()
|
|
275
|
+
})
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Local inspector endpoint for `mun inspect` and editor tooling: loopback only,
|
|
280
|
+
* token in `.mun/dev/session.json` (owner-readable), same framing as the host link.
|
|
281
|
+
*/
|
|
282
|
+
async function openInspectorEndpoint(project, current) {
|
|
283
|
+
const token = randomBytes(24).toString('hex')
|
|
284
|
+
const server = createServer(socket => {
|
|
285
|
+
let authenticated = false
|
|
286
|
+
const decode = createFrameDecoder(async message => {
|
|
287
|
+
if (!authenticated) {
|
|
288
|
+
if (message.type !== 'hello' || message.token !== token) { socket.destroy(); return }
|
|
289
|
+
authenticated = true
|
|
290
|
+
return
|
|
291
|
+
}
|
|
292
|
+
const running = current()
|
|
293
|
+
let reply
|
|
294
|
+
if (message.type !== 'inspect') reply = { type: 'error', id: message.id, message: `Unsupported request ${message.type}` }
|
|
295
|
+
else if (!running?.channel || running.exited) reply = { type: 'error', id: message.id, message: 'No native app is running' }
|
|
296
|
+
else {
|
|
297
|
+
try {
|
|
298
|
+
const nativeReply = await running.channel.request('inspect', { includeValues: message.includeValues === true })
|
|
299
|
+
reply = {
|
|
300
|
+
...nativeReply,
|
|
301
|
+
...(nativeReply.snapshot ? { snapshot: enrichInspectorSnapshot(nativeReply.snapshot, running.metadata, running.revision, running.runtimeDiagnostics) } : {}),
|
|
302
|
+
id: message.id,
|
|
303
|
+
}
|
|
304
|
+
} catch (error) { reply = { type: 'error', id: message.id, message: error.message } }
|
|
305
|
+
}
|
|
306
|
+
socket.write(encodeFrame(reply))
|
|
307
|
+
})
|
|
308
|
+
socket.on('data', chunk => { try { decode(chunk) } catch { socket.destroy() } })
|
|
309
|
+
socket.on('error', () => {})
|
|
310
|
+
})
|
|
311
|
+
await new Promise((resolve, reject) => { server.once('error', reject); server.listen(0, '127.0.0.1', resolve) })
|
|
312
|
+
const file = resolve(project.root, '.mun', 'dev', 'session.json')
|
|
313
|
+
mkdirSync(dirname(file), { recursive: true })
|
|
314
|
+
writeFileSync(file, JSON.stringify({ protocol: DEV_PROTOCOL_VERSION, endpoint: `127.0.0.1:${server.address().port}`, token, pid: process.pid }), { mode: 0o600 })
|
|
315
|
+
return { close() { server.close(); rmSync(file, { force: true }) } }
|
|
316
|
+
}
|
package/bin/workflow.mjs
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { spawn, spawnSync } from 'node:child_process'
|
|
2
|
+
import { chmodSync, cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs'
|
|
3
|
+
import { tmpdir } from 'node:os'
|
|
4
|
+
import { connect } from 'node:net'
|
|
5
|
+
import { basename, dirname, resolve } from 'node:path'
|
|
6
|
+
import { createFrameDecoder, encodeFrame } from './dev-protocol.mjs'
|
|
7
|
+
import { fileURLToPath } from 'node:url'
|
|
8
|
+
import { discoverProject, compileProject, sourceFiles, validateAssets, requirePlatform, projectPath } from './project.mjs'
|
|
9
|
+
import { resolveNativeHost, nativeBinaryName } from './native.mjs'
|
|
10
|
+
import { formatSource } from './formatter.mjs'
|
|
11
|
+
import { develop } from './watch.mjs'
|
|
12
|
+
|
|
13
|
+
const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..')
|
|
14
|
+
const toolchain = JSON.parse(readFileSync(resolve(packageRoot, 'package.json'), 'utf8'))
|
|
15
|
+
|
|
16
|
+
export function projectEnvironment(project) {
|
|
17
|
+
const path = resolve(project.root, 'mun.local.json')
|
|
18
|
+
if (!existsSync(path)) return { ...process.env }
|
|
19
|
+
let local
|
|
20
|
+
try { local = JSON.parse(readFileSync(path, 'utf8')) } catch (error) { throw new Error(`${path}: ${error.message}`) }
|
|
21
|
+
if (!local || typeof local !== 'object' || Array.isArray(local) || Object.keys(local).some(key => key !== 'env')) throw new Error(`${path}: expected { "env": { "NAME": "value" } }`)
|
|
22
|
+
if (!local.env || typeof local.env !== 'object' || Array.isArray(local.env) || Object.values(local.env).some(value => typeof value !== 'string')) throw new Error(`${path}: env values must be strings.`)
|
|
23
|
+
return { ...process.env, ...local.env }
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function hostBinary(project, program, env) {
|
|
27
|
+
const host = resolveNativeHost(project.root, env, program.version)
|
|
28
|
+
if (host.kind === 'binary') return host.command
|
|
29
|
+
const target = resolve(project.root, '.mun', 'cargo')
|
|
30
|
+
const result = spawnSync(env.CARGO || 'cargo', ['build', '--release', '--locked', '--manifest-path', host.manifest, '-p', 'mun-native'], { stdio: 'inherit', env: { ...env, CARGO_TARGET_DIR: target } })
|
|
31
|
+
if (result.error || result.status !== 0) throw new Error(`Native release host build failed: ${result.error?.message ?? result.status}`)
|
|
32
|
+
return resolve(target, 'release', nativeBinaryName())
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function launchProgram(project, program, env) {
|
|
36
|
+
const directory = mkdtempSync(resolve(tmpdir(), 'mun-run-'))
|
|
37
|
+
const path = resolve(directory, 'program.mun.ir.json')
|
|
38
|
+
try {
|
|
39
|
+
writeFileSync(path, `${JSON.stringify(program, null, 2)}\n`)
|
|
40
|
+
const child = spawn(hostBinary(project, program, env), [path], { cwd: project.root, env, stdio: 'inherit' })
|
|
41
|
+
child.once('close', () => rmSync(directory, { recursive: true, force: true }))
|
|
42
|
+
child.once('error', () => rmSync(directory, { recursive: true, force: true }))
|
|
43
|
+
return child
|
|
44
|
+
} catch (error) { rmSync(directory, { recursive: true, force: true }); throw error }
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function xml(value) { return String(value).replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>').replaceAll('"', '"') }
|
|
48
|
+
|
|
49
|
+
function plistValue(value) {
|
|
50
|
+
if (typeof value === 'boolean') return value ? '<true/>' : '<false/>'
|
|
51
|
+
return `<string>${xml(value)}</string>`
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Info.plist for a macOS bundle whose CFBundleExecutable is the real native binary. */
|
|
55
|
+
export function macInfoPlist(manifest, executable, iconFile) {
|
|
56
|
+
const entries = {
|
|
57
|
+
CFBundleDevelopmentRegion: 'en',
|
|
58
|
+
CFBundleExecutable: executable,
|
|
59
|
+
CFBundleIdentifier: manifest.identifier,
|
|
60
|
+
CFBundleInfoDictionaryVersion: '6.0',
|
|
61
|
+
CFBundleName: manifest.name.slice(0, 15),
|
|
62
|
+
CFBundleDisplayName: manifest.window_title ?? manifest.name,
|
|
63
|
+
CFBundlePackageType: 'APPL',
|
|
64
|
+
CFBundleShortVersionString: manifest.version,
|
|
65
|
+
CFBundleVersion: manifest.version,
|
|
66
|
+
LSMinimumSystemVersion: '11.0',
|
|
67
|
+
NSHighResolutionCapable: true,
|
|
68
|
+
NSPrincipalClass: 'NSApplication',
|
|
69
|
+
...(iconFile ? { CFBundleIconFile: iconFile } : {}),
|
|
70
|
+
}
|
|
71
|
+
const body = Object.entries(entries).map(([key, value]) => `\t<key>${key}</key>\n\t${plistValue(value)}`).join('\n')
|
|
72
|
+
return `<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n<plist version="1.0">\n<dict>\n${body}\n</dict>\n</plist>\n`
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Executable file name for a packaged app: the manifest name, filesystem-safe. */
|
|
76
|
+
export function packagedExecutableName(manifest, platform = process.platform) {
|
|
77
|
+
const base = manifest.name.replace(/[^\p{L}\p{N} _-]/gu, '_').trim() || 'MunApp'
|
|
78
|
+
return platform === 'win32' ? `${base}.exe` : base
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function buildProject(project, program, env, packageApp = false, options = {}) {
|
|
82
|
+
requirePlatform(project)
|
|
83
|
+
validateAssets(project)
|
|
84
|
+
if (project.manifest.fonts?.length) throw new Error('Bundled font registration is not yet supported by the native renderer. Remove fonts until the renderer exposes this contract.')
|
|
85
|
+
if (!/^[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)+$/u.test(project.manifest.identifier)) throw new Error(`Invalid bundle identifier ${JSON.stringify(project.manifest.identifier)}: use reverse-DNS segments of letters, digits and hyphens (e.g. com.example.App).`)
|
|
86
|
+
if ((options.sign || options.notarizeProfile) && !(packageApp && process.platform === 'darwin')) throw new Error('--sign/--notarize-profile apply to macOS mun package only.')
|
|
87
|
+
if (options.notarizeProfile && !options.sign) throw new Error('Notarization requires --sign with a Developer ID Application identity.')
|
|
88
|
+
const binary = hostBinary(project, program, env)
|
|
89
|
+
const parent = projectPath(project.root, `.mun/${packageApp ? 'package' : 'build'}/${process.platform}-${process.arch}`)
|
|
90
|
+
mkdirSync(parent, { recursive: true })
|
|
91
|
+
const stage = mkdtempSync(resolve(parent, '.stage-'))
|
|
92
|
+
const name = project.manifest.name.replace(/[^A-Za-z0-9_-]/gu, '_') || 'MunApp'
|
|
93
|
+
const isApp = packageApp && process.platform === 'darwin'
|
|
94
|
+
const destination = projectPath(project.root, `.mun/${packageApp ? 'package' : 'build'}/${process.platform}-${process.arch}/${isApp ? `${name}.app` : name}`)
|
|
95
|
+
const executable = packagedExecutableName(project.manifest)
|
|
96
|
+
try {
|
|
97
|
+
const executableDir = isApp ? resolve(stage, 'Contents/MacOS') : stage
|
|
98
|
+
const resources = isApp ? resolve(stage, 'Contents/Resources') : resolve(stage, 'Resources')
|
|
99
|
+
mkdirSync(executableDir, { recursive: true })
|
|
100
|
+
mkdirSync(resources, { recursive: true })
|
|
101
|
+
// The native host itself is the application executable: with no
|
|
102
|
+
// arguments it loads Resources/program.mun.ir.json relative to its own
|
|
103
|
+
// location (bundle- or directory-relative, never the working directory).
|
|
104
|
+
cpSync(binary, resolve(executableDir, executable))
|
|
105
|
+
chmodSync(resolve(executableDir, executable), 0o755)
|
|
106
|
+
writeFileSync(resolve(resources, 'program.mun.ir.json'), `${JSON.stringify(program)}\n`)
|
|
107
|
+
writeFileSync(resolve(resources, 'application.json'), `${JSON.stringify(project.manifest, null, 2)}\n`)
|
|
108
|
+
for (const resource of project.manifest.resources ?? []) {
|
|
109
|
+
cpSync(projectPath(project.root, resource), resolve(resources, 'bundled', resource), { recursive: true })
|
|
110
|
+
}
|
|
111
|
+
let iconFile
|
|
112
|
+
if (project.manifest.icon) {
|
|
113
|
+
if (isApp && !project.manifest.icon.endsWith('.icns')) throw new Error('macOS application icons must be .icns files.')
|
|
114
|
+
iconFile = basename(project.manifest.icon)
|
|
115
|
+
cpSync(projectPath(project.root, project.manifest.icon), resolve(resources, iconFile))
|
|
116
|
+
}
|
|
117
|
+
if (isApp) writeFileSync(resolve(stage, 'Contents/Info.plist'), macInfoPlist(project.manifest, executable, iconFile))
|
|
118
|
+
rmSync(destination, { recursive: true, force: true })
|
|
119
|
+
renameSync(stage, destination)
|
|
120
|
+
} finally { rmSync(stage, { recursive: true, force: true }) }
|
|
121
|
+
|
|
122
|
+
if (isApp) {
|
|
123
|
+
const lint = spawnSync('plutil', ['-lint', resolve(destination, 'Contents/Info.plist')], { encoding: 'utf8' })
|
|
124
|
+
if (lint.status !== 0) throw new Error(`Generated Info.plist failed plutil -lint: ${lint.stdout}${lint.stderr}`)
|
|
125
|
+
}
|
|
126
|
+
if (options.sign) {
|
|
127
|
+
signMacApp(destination, options.sign, env)
|
|
128
|
+
console.log(`Packaged and signed (${options.sign}) native application: ${destination}`)
|
|
129
|
+
if (options.notarizeProfile) notarizeMacApp(destination, options.notarizeProfile, env)
|
|
130
|
+
} else {
|
|
131
|
+
console.log(`${packageApp ? 'Packaged (unsigned — not distribution-ready)' : 'Built'} native application: ${destination}`)
|
|
132
|
+
if (isApp) console.log('To sign: mun package --sign "Developer ID Application: …" [--notarize-profile <notarytool keychain profile>]')
|
|
133
|
+
}
|
|
134
|
+
return destination
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function run(command, args, env, what) {
|
|
138
|
+
const result = spawnSync(command, args, { encoding: 'utf8', env })
|
|
139
|
+
if (result.error || result.status !== 0) throw new Error(`${what} failed: ${result.error?.message ?? `${result.stdout}${result.stderr}`.trim()}`)
|
|
140
|
+
return result
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function signMacApp(app, identity, env) {
|
|
144
|
+
if (identity === '-') throw new Error('Ad-hoc signing is not distribution signing; pass a Developer ID Application identity to --sign.')
|
|
145
|
+
run('codesign', ['--force', '--options', 'runtime', '--timestamp', '--sign', identity, app], env, 'codesign')
|
|
146
|
+
run('codesign', ['--verify', '--strict', '--verbose=2', app], env, 'codesign --verify')
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function notarizeMacApp(app, profile, env) {
|
|
150
|
+
const archive = `${app}.zip`
|
|
151
|
+
try {
|
|
152
|
+
run('ditto', ['-c', '-k', '--keepParent', app, archive], env, 'ditto')
|
|
153
|
+
run('xcrun', ['notarytool', 'submit', archive, '--keychain-profile', profile, '--wait'], env, 'notarytool submit')
|
|
154
|
+
run('xcrun', ['stapler', 'staple', app], env, 'stapler staple')
|
|
155
|
+
console.log(`Notarized and stapled: ${app}`)
|
|
156
|
+
} finally { rmSync(archive, { force: true }) }
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** `mun inspect`: query the running `mun dev` session's native app. */
|
|
160
|
+
export async function inspectProject(project, { values = false, json = false } = {}) {
|
|
161
|
+
const file = resolve(project.root, '.mun', 'dev', 'session.json')
|
|
162
|
+
if (!existsSync(file)) throw new Error('No running mun dev session for this project.')
|
|
163
|
+
const session = JSON.parse(readFileSync(file, 'utf8'))
|
|
164
|
+
const [host, port] = session.endpoint.split(':')
|
|
165
|
+
if (host !== '127.0.0.1') throw new Error('Refusing non-loopback inspector endpoint.')
|
|
166
|
+
const socket = connect({ host, port: Number(port) })
|
|
167
|
+
const reply = await new Promise((resolvePromise, reject) => {
|
|
168
|
+
socket.once('error', error => reject(new Error(`Could not reach mun dev (${error.message}); is it still running?`)))
|
|
169
|
+
socket.on('data', createFrameDecoder(message => { resolvePromise(message); socket.end() }))
|
|
170
|
+
socket.once('connect', () => {
|
|
171
|
+
socket.write(encodeFrame({ type: 'hello', token: session.token }))
|
|
172
|
+
socket.write(encodeFrame({ type: 'inspect', id: 1, includeValues: values }))
|
|
173
|
+
})
|
|
174
|
+
})
|
|
175
|
+
if (reply.type === 'error') throw new Error(reply.message)
|
|
176
|
+
if (json) { console.log(JSON.stringify(reply.snapshot, null, 2)); return 0 }
|
|
177
|
+
console.log(formatSnapshot(reply.snapshot))
|
|
178
|
+
return 0
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export function formatSnapshot(snapshot) {
|
|
182
|
+
const nodes = new Map(snapshot.nodes.map(node => [node.id, node]))
|
|
183
|
+
const lines = [`${snapshot.title} — entry ${snapshot.entry}, runtime revision ${snapshot.revision}${snapshot.devRevision !== undefined ? `, dev revision ${snapshot.devRevision}` : ''}, ${snapshot.primitives ?? '?'} primitives${snapshot.activeAnimations ? ', animating' : ''}`]
|
|
184
|
+
if (snapshot.focus) lines.push(`focus: ${snapshot.focus}`)
|
|
185
|
+
const short = id => id.replace(/^@node\/entry\//u, '').replace(/\/kind\/[A-Za-z]+$/u, '')
|
|
186
|
+
const visit = (node, depth) => {
|
|
187
|
+
const frame = node.frame ? ` [${node.frame.map(value => Math.round(value)).join(', ')}]` : ''
|
|
188
|
+
const component = node.component ? ` <${node.component}>` : ''
|
|
189
|
+
const scroll = node.scrollOffset ? ` scroll=${node.scrollOffset.map(value => Math.round(value)).join(',')}` : ''
|
|
190
|
+
const source = node.source ? ` @ ${node.source.file}:${node.source.line}:${node.source.column}` : ''
|
|
191
|
+
lines.push(`${' '.repeat(depth)}${node.kind}${component}${frame}${scroll} ${short(node.id)}${source}`)
|
|
192
|
+
for (const child of node.children) if (nodes.has(child)) visit(nodes.get(child), depth + 1)
|
|
193
|
+
}
|
|
194
|
+
const root = snapshot.nodes.find(node => !node.parent)
|
|
195
|
+
if (root) visit(root, 0)
|
|
196
|
+
lines.push('state:')
|
|
197
|
+
for (const state of snapshot.states) {
|
|
198
|
+
const value = state.redacted ? '<redacted>' : 'value' in state ? JSON.stringify(state.value) : `<${state.valueKind}>`
|
|
199
|
+
lines.push(` ${state.name} = ${value}`)
|
|
200
|
+
}
|
|
201
|
+
return lines.join('\n')
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export async function projectCommand(command, options) {
|
|
205
|
+
let project
|
|
206
|
+
try { project = discoverProject(options.projectRoot ?? process.cwd()) }
|
|
207
|
+
catch (error) {
|
|
208
|
+
if (command !== 'doctor') throw error
|
|
209
|
+
console.log(`Mün ${toolchain.version}; ${process.platform}/${process.arch}\nWARNING: ${error.message}\nLSP: mun lsp --stdio`)
|
|
210
|
+
return 1
|
|
211
|
+
}
|
|
212
|
+
if (project.manifest.minimum_mun_version) {
|
|
213
|
+
const required = project.manifest.minimum_mun_version.split('.').map(Number)
|
|
214
|
+
const current = toolchain.version.split('.').map(Number)
|
|
215
|
+
const difference = current.map((value, i) => value - required[i]).find(value => value !== 0) ?? 0
|
|
216
|
+
if (difference < 0) throw new Error(`Project requires Mün >= ${project.manifest.minimum_mun_version}; selected CLI/compiler is ${toolchain.version}.`)
|
|
217
|
+
}
|
|
218
|
+
const env = projectEnvironment(project)
|
|
219
|
+
if (command === 'fmt') {
|
|
220
|
+
let changed = false
|
|
221
|
+
for (const path of sourceFiles(project)) {
|
|
222
|
+
const source = readFileSync(path, 'utf8'), crlf = source.includes('\r\n')
|
|
223
|
+
// Line endings are preserved: a CRLF checkout (Windows autocrlf) is not "unformatted".
|
|
224
|
+
const formatted = crlf ? formatSource(source.replace(/\r\n/gu, '\n')).replace(/\n/gu, '\r\n') : formatSource(source)
|
|
225
|
+
if (source !== formatted) { changed = true; console.log(`${options.check ? 'Needs formatting' : 'Formatted'}: ${path}`); if (!options.check) writeFileSync(path, formatted) }
|
|
226
|
+
}
|
|
227
|
+
return options.check && changed ? 1 : 0
|
|
228
|
+
}
|
|
229
|
+
if (command === 'dev') return develop(project, { env, verbose: options.verbose })
|
|
230
|
+
if (command === 'inspect') return inspectProject(project, options)
|
|
231
|
+
const program = compileProject(project)
|
|
232
|
+
if (command === 'check') { console.log(`Checked ${sourceFiles(project).length} Mün source file(s).`); return 0 }
|
|
233
|
+
if (command === 'doctor') {
|
|
234
|
+
console.log(`Mün CLI/compiler: ${toolchain.version}\nManifest: ${project.manifest.manifest_version}\nOS/architecture: ${process.platform}/${process.arch}\nEntry: ${project.entry}\nLSP: mun lsp --stdio`)
|
|
235
|
+
let fatal = false
|
|
236
|
+
try { validateAssets(project); console.log('Assets: OK') } catch (error) { console.log(`ERROR: ${error.message}`); fatal = true }
|
|
237
|
+
try {
|
|
238
|
+
const host = resolveNativeHost(project.root, env, program.version)
|
|
239
|
+
console.log(`Native host: ${host.kind === 'binary' ? host.command : 'Cargo fallback (locked release build)'}`)
|
|
240
|
+
if (host.kind === 'cargo') {
|
|
241
|
+
const rust = spawnSync(env.CARGO || 'cargo', ['--version'], { encoding: 'utf8', timeout: 5000 })
|
|
242
|
+
if (rust.status !== 0) { console.log('ERROR: Cargo fallback requires Rust/Cargo.'); fatal = true } else console.log(rust.stdout.trim())
|
|
243
|
+
}
|
|
244
|
+
} catch (error) { console.log(`ERROR: ${error.message}`); fatal = true }
|
|
245
|
+
if (process.platform === 'darwin') {
|
|
246
|
+
const xcode = spawnSync('xcode-select', ['-p'], { encoding: 'utf8', timeout: 5000 })
|
|
247
|
+
console.log(`${xcode.status === 0 ? 'Xcode' : 'WARNING: Xcode unavailable'}: ${xcode.stdout?.trim() ?? ''}`)
|
|
248
|
+
}
|
|
249
|
+
return fatal ? 1 : 0
|
|
250
|
+
}
|
|
251
|
+
if (command === 'build' || command === 'package') { buildProject(project, program, env, command === 'package', { sign: options.sign, notarizeProfile: options.notarizeProfile }); return 0 }
|
|
252
|
+
if (command === 'run') {
|
|
253
|
+
requirePlatform(project)
|
|
254
|
+
const child = launchProgram(project, program, env)
|
|
255
|
+
const stop = () => child.kill('SIGTERM')
|
|
256
|
+
process.once('SIGINT', stop); process.once('SIGTERM', stop)
|
|
257
|
+
try { return await new Promise((resolve, reject) => { child.once('error', reject); child.once('close', code => resolve(code ?? 1)) }) }
|
|
258
|
+
finally { process.removeListener('SIGINT', stop); process.removeListener('SIGTERM', stop) }
|
|
259
|
+
}
|
|
260
|
+
throw new Error(`Unsupported project command: ${command}`)
|
|
261
|
+
}
|
package/dist/astro.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"astro.d.ts","sourceRoot":"","sources":["../src/astro.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,cAAc,eAAe,CAAA"}
|
package/dist/astro.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"astro.js","sourceRoot":"","sources":["../src/astro.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,cAAc,eAAe,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"closures.d.ts","sourceRoot":"","sources":["../src/closures.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA"}
|
package/dist/closures.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"closures.js","sourceRoot":"","sources":["../src/closures.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/compiler/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/compiler/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAA"}
|
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,cAAc,cAAc,CAAA"}
|
package/dist/core.js
ADDED
package/dist/core.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,cAAc,cAAc,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"experimental.d.ts","sourceRoot":"","sources":["../src/experimental.ts"],"names":[],"mappings":"AAAA,cAAc,mCAAmC,CAAA"}
|