@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.
Files changed (176) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +114 -2
  3. package/bin/compile.mjs +38 -0
  4. package/bin/desktop.mjs +143 -0
  5. package/bin/dev-protocol.mjs +94 -0
  6. package/bin/formatter.mjs +109 -0
  7. package/bin/hot-reload.mjs +38 -0
  8. package/bin/mun.mjs +538 -0
  9. package/bin/native.mjs +133 -0
  10. package/bin/pnpm-workspace.mjs +58 -0
  11. package/bin/program-patch.mjs +104 -0
  12. package/bin/project.mjs +322 -0
  13. package/bin/watch.mjs +316 -0
  14. package/bin/workflow.mjs +261 -0
  15. package/dist/astro.d.ts +3 -0
  16. package/dist/astro.d.ts.map +1 -0
  17. package/dist/astro.js +3 -0
  18. package/dist/astro.js.map +1 -0
  19. package/dist/closures.d.ts +2 -0
  20. package/dist/closures.d.ts.map +1 -0
  21. package/dist/closures.js +2 -0
  22. package/dist/closures.js.map +1 -0
  23. package/dist/compiler/index.d.ts +2 -0
  24. package/dist/compiler/index.d.ts.map +1 -0
  25. package/dist/compiler/index.js +2 -0
  26. package/dist/compiler/index.js.map +1 -0
  27. package/dist/core.d.ts +3 -0
  28. package/dist/core.d.ts.map +1 -0
  29. package/dist/core.js +3 -0
  30. package/dist/core.js.map +1 -0
  31. package/dist/experimental.d.ts +2 -0
  32. package/dist/experimental.d.ts.map +1 -0
  33. package/dist/experimental.js +2 -0
  34. package/dist/experimental.js.map +1 -0
  35. package/dist/index.d.ts +3 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +3 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/jsx-dev-runtime.d.ts +2 -0
  40. package/dist/jsx-dev-runtime.d.ts.map +1 -0
  41. package/dist/jsx-dev-runtime.js +2 -0
  42. package/dist/jsx-dev-runtime.js.map +1 -0
  43. package/dist/jsx-runtime.d.ts +2 -0
  44. package/dist/jsx-runtime.d.ts.map +1 -0
  45. package/dist/jsx-runtime.js +2 -0
  46. package/dist/jsx-runtime.js.map +1 -0
  47. package/dist/legacy.d.ts +3 -0
  48. package/dist/legacy.d.ts.map +1 -0
  49. package/dist/legacy.js +3 -0
  50. package/dist/legacy.js.map +1 -0
  51. package/dist/mun.d.ts +5 -0
  52. package/dist/mun.d.ts.map +1 -0
  53. package/dist/mun.js +4 -0
  54. package/dist/mun.js.map +1 -0
  55. package/dist/progressive-blur/index.d.ts +8 -0
  56. package/dist/progressive-blur/index.d.ts.map +1 -0
  57. package/dist/progressive-blur/index.js +8 -0
  58. package/dist/progressive-blur/index.js.map +1 -0
  59. package/dist/progressive-blur/plan.d.ts +3 -0
  60. package/dist/progressive-blur/plan.d.ts.map +1 -0
  61. package/dist/progressive-blur/plan.js +3 -0
  62. package/dist/progressive-blur/plan.js.map +1 -0
  63. package/dist/react-types.d.ts +2 -0
  64. package/dist/react-types.d.ts.map +1 -0
  65. package/dist/react-types.js +2 -0
  66. package/dist/react-types.js.map +1 -0
  67. package/dist/rendering-quality.d.ts +4 -0
  68. package/dist/rendering-quality.d.ts.map +1 -0
  69. package/dist/rendering-quality.js +4 -0
  70. package/dist/rendering-quality.js.map +1 -0
  71. package/dist/state.d.ts +2 -0
  72. package/dist/state.d.ts.map +1 -0
  73. package/dist/state.js +2 -0
  74. package/dist/state.js.map +1 -0
  75. package/dist/types.d.ts +2 -0
  76. package/dist/types.d.ts.map +1 -0
  77. package/dist/types.js +2 -0
  78. package/dist/types.js.map +1 -0
  79. package/dist/vite.d.ts +2 -0
  80. package/dist/vite.d.ts.map +1 -0
  81. package/dist/vite.js +2 -0
  82. package/dist/vite.js.map +1 -0
  83. package/editors/install.mjs +102 -0
  84. package/editors/lsp/mun-lsp.mjs +123 -0
  85. package/editors/lsp/service.mjs +306 -0
  86. package/editors/lsp/source.mjs +58 -0
  87. package/editors/vscode/client.mjs +40 -0
  88. package/editors/vscode/dev-client.mjs +83 -0
  89. package/editors/vscode/discovery.mjs +46 -0
  90. package/editors/vscode/export.mjs +42 -0
  91. package/editors/vscode/extension.cjs +226 -0
  92. package/editors/vscode/language-configuration.json +15 -0
  93. package/editors/vscode/package.json +119 -0
  94. package/editors/vscode/protocol.mjs +29 -0
  95. package/editors/vscode/syntaxes/mun.tmLanguage.json +130 -0
  96. package/native/Cargo.lock +3581 -0
  97. package/native/Cargo.toml +21 -0
  98. package/native/README.md +21 -0
  99. package/native/mun-native/Cargo.toml +23 -0
  100. package/native/mun-native/src/accessibility.rs +738 -0
  101. package/native/mun-native/src/dev.rs +604 -0
  102. package/native/mun-native/src/host_services.rs +202 -0
  103. package/native/mun-native/src/lib.rs +2843 -0
  104. package/native/mun-native/src/main.rs +204 -0
  105. package/native/mun-native/src/offscreen.rs +393 -0
  106. package/native/mun-native/src/rect.wgsl +63 -0
  107. package/native/mun-native/src/text.rs +401 -0
  108. package/native/mun-native/tests/offscreen_rendering.rs +161 -0
  109. package/native/mun-native/tests/stress.rs +408 -0
  110. package/native/mun-native/tests/window_lifecycle.rs +183 -0
  111. package/native/mun-runtime/Cargo.toml +13 -0
  112. package/native/mun-runtime/src/accessibility.rs +193 -0
  113. package/native/mun-runtime/src/collection.rs +1090 -0
  114. package/native/mun-runtime/src/gesture.rs +1070 -0
  115. package/native/mun-runtime/src/input.rs +325 -0
  116. package/native/mun-runtime/src/ir.rs +852 -0
  117. package/native/mun-runtime/src/kinetics.rs +500 -0
  118. package/native/mun-runtime/src/layout.rs +258 -0
  119. package/native/mun-runtime/src/layout_cache.rs +209 -0
  120. package/native/mun-runtime/src/lib.rs +52 -0
  121. package/native/mun-runtime/src/motion.rs +1162 -0
  122. package/native/mun-runtime/src/retained.rs +574 -0
  123. package/native/mun-runtime/src/runtime.rs +7449 -0
  124. package/native/mun-runtime/src/scene.rs +567 -0
  125. package/native/mun-runtime/src/scroll.rs +521 -0
  126. package/native/mun-runtime/src/scroll_view.rs +220 -0
  127. package/native/mun-runtime/src/text_edit.rs +670 -0
  128. package/native/mun-runtime/src/timeline.rs +1534 -0
  129. package/native/mun-runtime/src/validate.rs +677 -0
  130. package/native/mun-runtime/tests/accessibility_semantics.rs +168 -0
  131. package/native/mun-runtime/tests/compiler_contract.rs +110 -0
  132. package/native/mun-runtime/tests/flexible_frames.rs +47 -0
  133. package/native/mun-runtime/tests/host_services.rs +107 -0
  134. package/native/mun-runtime/tests/hot_update.rs +367 -0
  135. package/native/mun-runtime/tests/incremental_runtime.rs +323 -0
  136. package/native/mun-runtime/tests/ir_validation.rs +167 -0
  137. package/native/mun-runtime/tests/keyed_collections.rs +251 -0
  138. package/native/mun-runtime/tests/minimum_window_size.rs +80 -0
  139. package/native/mun-runtime/tests/native_controls_style.rs +491 -0
  140. package/native/mun-runtime/tests/native_demo.rs +285 -0
  141. package/native/mun-runtime/tests/native_layout_style.rs +175 -0
  142. package/native/mun-runtime/tests/native_settings_pane.rs +152 -0
  143. package/native/mun-runtime/tests/priority_proposals.rs +69 -0
  144. package/native/mun-runtime/tests/scroll_view.rs +403 -0
  145. package/native/mun-runtime/tests/text_editing.rs +491 -0
  146. package/native/mun-runtime/tests/text_proposals.rs +42 -0
  147. package/native/mun-runtime/tests/typography.rs +63 -0
  148. package/package.json +213 -3
  149. package/schemas/README.md +19 -0
  150. package/schemas/semantic-ui-ir-v1.schema.json +2061 -0
  151. package/templates/desktop/gitignore +5 -0
  152. package/templates/desktop/package.json +10 -0
  153. package/templates/desktop/src-tauri/Cargo.toml +14 -0
  154. package/templates/desktop/src-tauri/build.rs +1 -0
  155. package/templates/desktop/src-tauri/capabilities/main.json +12 -0
  156. package/templates/desktop/src-tauri/icons/icon.icns +0 -0
  157. package/templates/desktop/src-tauri/icons/icon.ico +0 -0
  158. package/templates/desktop/src-tauri/icons/icon.png +0 -0
  159. package/templates/desktop/src-tauri/src/main.rs +2 -0
  160. package/templates/desktop/src-tauri/tauri.conf.json +42 -0
  161. package/templates/desktop/vite.config.ts +10 -0
  162. package/templates/native/App.mun +15 -0
  163. package/templates/native/gitignore +3 -0
  164. package/templates/native/mun.toml +8 -0
  165. package/templates/project/gitignore +5 -0
  166. package/templates/project/index.html +13 -0
  167. package/templates/project/package.json +24 -0
  168. package/templates/project/src/App.mun +13 -0
  169. package/templates/project/src/index.css +30 -0
  170. package/templates/project/src/main.ts +5 -0
  171. package/templates/project/tsconfig.json +20 -0
  172. package/templates/project/vite.config.ts +6 -0
  173. package/templates/vite/src/App.css +134 -0
  174. package/templates/vite/src/App.tsx +91 -0
  175. package/templates/vite/src/index.css +23 -0
  176. package/templates/vite/vite.config.ts +10 -0
package/bin/mun.mjs ADDED
@@ -0,0 +1,538 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { spawnSync } from 'node:child_process'
4
+ import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs'
5
+ import { basename, dirname, relative, resolve, sep } from 'node:path'
6
+ import { fileURLToPath } from 'node:url'
7
+ import { updatePnpmWorkspaceOverrides } from './pnpm-workspace.mjs'
8
+ import { installEditors } from '../editors/install.mjs'
9
+ import { runNativeSource } from './native.mjs'
10
+ import { projectCommand } from './workflow.mjs'
11
+ import { detectProjectTarget, frontendCommand } from './desktop.mjs'
12
+
13
+ const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..')
14
+ const packageManifest = JSON.parse(readFileSync(resolve(packageRoot, 'package.json'), 'utf8'))
15
+ const supportedPackageManagers = ['pnpm', 'npm', 'yarn', 'bun']
16
+ const argv = process.argv.slice(2)
17
+ const command = argv[0]
18
+ const positionals = []
19
+ const options = {
20
+ force: false,
21
+ noInstall: false,
22
+ packageManager: undefined,
23
+ help: false,
24
+ local: false,
25
+ localRoot: undefined,
26
+ renderer: undefined,
27
+ editor: 'all',
28
+ global: false,
29
+ projectRoot: undefined,
30
+ }
31
+
32
+ function takeValue(argument, index, longName) {
33
+ if (argument === longName) {
34
+ const value = argv[index + 1]
35
+ if (!value || value.startsWith('-')) throw new Error(`${longName} requires a value.`)
36
+ return { value, consumed: 1 }
37
+ }
38
+ if (argument.startsWith(`${longName}=`)) return { value: argument.slice(longName.length + 1), consumed: 0 }
39
+ return undefined
40
+ }
41
+
42
+ try {
43
+ for (let index = 1; index < argv.length; index += 1) {
44
+ const argument = argv[index]
45
+ if (argument === '--') continue
46
+ if (argument === '--force') options.force = true
47
+ else if (argument === '--no-install' || argument === '--skip-install') options.noInstall = true
48
+ else if (argument === '--local') options.local = true
49
+ else if (argument === '--global') options.global = true
50
+ else if (argument === '--help' || argument === '-h') options.help = true
51
+ else if (argument === '--check') options.check = true
52
+ else if (argument === '--verbose') options.verbose = true
53
+ else if (argument === '--values') options.values = true
54
+ else if (argument === '--json') options.json = true
55
+ else if (argument === '--version' || argument === '-v') options.version = true
56
+ else {
57
+ const packageManager = takeValue(argument, index, '--package-manager') ?? takeValue(argument, index, '--pm')
58
+ const localRoot = takeValue(argument, index, '--local-root')
59
+ const renderer = takeValue(argument, index, '--renderer')
60
+ const editor = takeValue(argument, index, '--editor')
61
+ const project = takeValue(argument, index, '--project')
62
+ const target = takeValue(argument, index, '--target')
63
+ const sign = takeValue(argument, index, '--sign')
64
+ const notarize = takeValue(argument, index, '--notarize-profile')
65
+ if (sign) { options.sign = sign.value; index += sign.consumed }
66
+ else if (notarize) { options.notarizeProfile = notarize.value; index += notarize.consumed }
67
+ else if (target) {
68
+ options.target = target.value
69
+ index += target.consumed
70
+ } else if (packageManager) {
71
+ options.packageManager = packageManager.value
72
+ index += packageManager.consumed
73
+ } else if (localRoot) {
74
+ options.local = true
75
+ options.localRoot = localRoot.value
76
+ index += localRoot.consumed
77
+ } else if (renderer) {
78
+ options.renderer = renderer.value
79
+ index += renderer.consumed
80
+ } else if (editor) {
81
+ options.editor = editor.value
82
+ index += editor.consumed
83
+ } else if (project) {
84
+ options.projectRoot = project.value
85
+ index += project.consumed
86
+ } else {
87
+ positionals.push(argument)
88
+ }
89
+ }
90
+ }
91
+ } catch (error) {
92
+ console.error(`Mün ${command ?? 'command'} failed: ${error instanceof Error ? error.message : String(error)}`)
93
+ printHelp()
94
+ process.exitCode = 1
95
+ process.exit(process.exitCode)
96
+ }
97
+
98
+ const projectFiles = [
99
+ ['templates/project/gitignore', '.gitignore'],
100
+ ['templates/project/index.html', 'index.html'],
101
+ ['templates/project/package.json', 'package.json'],
102
+ ['templates/project/tsconfig.json', 'tsconfig.json'],
103
+ ['templates/project/vite.config.ts', 'vite.config.ts'],
104
+ ['templates/project/src/App.mun', 'src/App.mun'],
105
+ ['templates/project/src/index.css', 'src/index.css'],
106
+ ['templates/project/src/main.ts', 'src/main.ts'],
107
+ ]
108
+
109
+ const localPackagePaths = {
110
+ '@mun-ui/ui': '.',
111
+ '@mun-ui/astro': 'packages/astro',
112
+ '@mun-ui/animation': 'packages/animation',
113
+ '@mun-ui/core': 'packages/core',
114
+ '@mun-ui/desktop': 'packages/desktop',
115
+ '@mun-ui/compiler': 'packages/compiler',
116
+ '@mun-ui/execution': 'packages/execution',
117
+ '@mun-ui/legacy-react': 'packages/legacy-react',
118
+ '@mun-ui/progressive-blur': 'packages/progressive-blur',
119
+ '@mun-ui/react': 'packages/react',
120
+ '@mun-ui/vue': 'packages/vue',
121
+ '@mun-ui/web': 'packages/web',
122
+ '@mun-ui/vite': 'packages/vite',
123
+ }
124
+
125
+ function template(source) {
126
+ return readFileSync(resolve(packageRoot, source), 'utf8')
127
+ .replaceAll('__MUN_VERSION__', packageManifest.version)
128
+ }
129
+
130
+ function writeTemplates(projectRoot, files) {
131
+ for (const [source, destination] of files) {
132
+ const target = resolve(projectRoot, destination)
133
+ mkdirSync(dirname(target), { recursive: true })
134
+ writeFileSync(target, template(source)
135
+ .replaceAll('__MUN_PROJECT_NAME__', projectName(projectRoot))
136
+ .replaceAll('__MUN_PROJECT_CRATE__', projectName(projectRoot).replace(/[^a-z0-9-]/gu, '-'))
137
+ .replaceAll('__MUN_PROJECT_APP_NAME__', projectAppName(projectRoot)))
138
+ }
139
+ }
140
+
141
+ function projectName(projectRoot) {
142
+ const name = basename(projectRoot)
143
+ .toLowerCase()
144
+ .replace(/[^a-z0-9._-]+/gu, '-')
145
+ .replace(/^[._-]+|[._-]+$/gu, '')
146
+ return name || 'mun-app'
147
+ }
148
+
149
+ function projectAppName(projectRoot) {
150
+ const words = basename(projectRoot).split(/[^A-Za-z0-9]+/u).filter(Boolean)
151
+ const name = words.map(word => `${word[0].toUpperCase()}${word.slice(1)}`).join('') || 'Mun'
152
+ return /^[A-Za-z]/u.test(name) ? `${name}App` : `Mun${name}App`
153
+ }
154
+
155
+ function detectPackageManager(projectRoot) {
156
+ const userAgent = process.env.npm_config_user_agent ?? ''
157
+ for (const manager of ['pnpm', 'yarn', 'bun', 'npm']) {
158
+ if (userAgent.startsWith(`${manager}/`)) return manager
159
+ }
160
+ if (existsSync(resolve(projectRoot, 'pnpm-lock.yaml')) || existsSync(resolve(projectRoot, 'pnpm-workspace.yaml'))) return 'pnpm'
161
+ if (existsSync(resolve(projectRoot, 'yarn.lock'))) return 'yarn'
162
+ if (existsSync(resolve(projectRoot, 'bun.lockb')) || existsSync(resolve(projectRoot, 'bun.lock'))) return 'bun'
163
+ return 'npm'
164
+ }
165
+
166
+ function packageManagerFor(projectRoot, { local = false } = {}) {
167
+ if (local) {
168
+ assertLocalPackageManager()
169
+ return 'pnpm'
170
+ }
171
+ const packageManager = options.packageManager ?? detectPackageManager(projectRoot)
172
+ if (!supportedPackageManagers.includes(packageManager)) {
173
+ throw new Error(`Unsupported package manager: ${packageManager}. Use pnpm, npm, yarn, or bun.`)
174
+ }
175
+ return packageManager
176
+ }
177
+
178
+ function installDependencies(projectRoot, packageManager) {
179
+ console.log(`Installing dependencies with ${packageManager}...`)
180
+ const result = spawnSync(packageManager, ['install'], { cwd: projectRoot, stdio: 'inherit' })
181
+ if (result.error) throw new Error(`Could not run ${packageManager}: ${result.error.message}`)
182
+ if (result.status !== 0) throw new Error(`${packageManager} install failed with exit code ${result.status ?? 1}.`)
183
+ }
184
+
185
+ function normalizeLocalRoot(value = packageRoot) {
186
+ return resolve(process.cwd(), value)
187
+ }
188
+
189
+ function assertLocalPackageManager() {
190
+ if (options.packageManager && options.packageManager !== 'pnpm') {
191
+ throw new Error('Local Mün source linking currently requires pnpm. Remove --pm or use --pm pnpm.')
192
+ }
193
+ }
194
+
195
+ function packageRunCommand(packageManager, script) {
196
+ if (packageManager === 'npm' || packageManager === 'bun') return `${packageManager} run ${script}`
197
+ return `${packageManager} ${script}`
198
+ }
199
+
200
+ function shellPath(path) {
201
+ if (/^[A-Za-z0-9_./~-]+$/u.test(path)) return path
202
+ return `'${path.replaceAll("'", "'\\''")}'`
203
+ }
204
+
205
+ function displayProjectPath(projectRoot) {
206
+ const path = relative(process.cwd(), projectRoot)
207
+ if (!path || path === '.') return '.'
208
+ if (!path.startsWith('..') && !path.startsWith(sep)) return path
209
+ return projectRoot
210
+ }
211
+
212
+ function printScaffoldNextSteps(projectRoot, packageManager, installed) {
213
+ const steps = []
214
+ const projectPath = displayProjectPath(projectRoot)
215
+ if (projectPath !== '.') steps.push(`cd ${shellPath(projectPath)}`)
216
+ if (!installed) steps.push(`${packageManager} install`)
217
+ steps.push(packageRunCommand(packageManager, 'dev'))
218
+ console.log(`\nNext steps:\n${steps.map(step => ` ${step}`).join('\n')}`)
219
+ }
220
+
221
+ function printInstallRecovery(projectRoot, packageManager) {
222
+ const projectPath = displayProjectPath(projectRoot)
223
+ const prefix = projectPath === '.' ? '' : ` cd ${shellPath(projectPath)}\n`
224
+ console.error('\nThe project files are ready, but dependency installation did not finish.')
225
+ console.error(`Retry with:\n${prefix} ${packageManager} install`)
226
+ }
227
+
228
+ function assertSourceCheckout(localRoot) {
229
+ const manifestPath = resolve(localRoot, 'package.json')
230
+ if (!existsSync(manifestPath)) throw new Error(`Local Mün checkout has no package.json: ${localRoot}`)
231
+ const manifest = JSON.parse(readFileSync(manifestPath, 'utf8'))
232
+ if (manifest.name !== '@mun-ui/ui') throw new Error(`Local checkout is not @mun-ui/ui: ${localRoot}`)
233
+ for (const relativePath of Object.values(localPackagePaths)) {
234
+ if (relativePath === '.') continue
235
+ if (!existsSync(resolve(localRoot, relativePath, 'package.json'))) {
236
+ throw new Error(`Local Mün checkout is incomplete; missing ${relativePath}/package.json in ${localRoot}`)
237
+ }
238
+ }
239
+ return localRoot
240
+ }
241
+
242
+ function detectRenderer(projectRoot) {
243
+ const manifestPath = resolve(projectRoot, 'package.json')
244
+ if (!existsSync(manifestPath)) throw new Error(`Target project has no package.json: ${projectRoot}`)
245
+ const manifest = JSON.parse(readFileSync(manifestPath, 'utf8'))
246
+ const dependencies = { ...manifest.dependencies, ...manifest.devDependencies, ...manifest.peerDependencies }
247
+ const hasAstro = Boolean(dependencies.astro)
248
+ const hasReact = Boolean(dependencies.react || dependencies['react-dom'])
249
+ const hasVue = Boolean(dependencies.vue)
250
+ if (hasAstro) return 'astro'
251
+ if (hasReact && hasVue) {
252
+ throw new Error('Both React and Vue are present in the target project. Pass --renderer astro, react, vue, or web explicitly.')
253
+ }
254
+ if (hasVue) return 'vue'
255
+ if (hasReact) return 'react'
256
+ return 'web'
257
+ }
258
+
259
+ function linkSpecifier(path) {
260
+ return `link:${path.split(sep).join('/')}`
261
+ }
262
+
263
+ function configureLocalDependencies(projectRoot, localRoot, renderer = 'react', { includeRootPackage = true } = {}) {
264
+ if (!['astro', 'react', 'vue', 'web'].includes(renderer)) {
265
+ throw new Error(`Unsupported Mün renderer: ${renderer}. Use astro, react, vue, or web.`)
266
+ }
267
+ localRoot = assertSourceCheckout(localRoot)
268
+ const manifestPath = resolve(projectRoot, 'package.json')
269
+ if (!existsSync(manifestPath)) throw new Error(`Target project has no package.json: ${projectRoot}`)
270
+ const manifest = JSON.parse(readFileSync(manifestPath, 'utf8'))
271
+ manifest.dependencies ??= {}
272
+ manifest.devDependencies ??= {}
273
+
274
+ // Templates depend on @mun-ui/ui for its opt-in features; never let a local
275
+ // project resolve it from the registry.
276
+ const linkRootPackage = includeRootPackage || manifest.dependencies['@mun-ui/ui'] !== undefined
277
+ if (linkRootPackage) manifest.dependencies['@mun-ui/ui'] = linkSpecifier(localRoot)
278
+ if (manifest.devDependencies['@mun-ui/ui']) manifest.devDependencies['@mun-ui/ui'] = linkSpecifier(localRoot)
279
+ manifest.dependencies[`@mun-ui/${renderer}`] = linkSpecifier(resolve(localRoot, `packages/${renderer}`))
280
+ manifest.devDependencies['@mun-ui/vite'] = linkSpecifier(resolve(localRoot, 'packages/vite'))
281
+
282
+ // link: packages deliberately do not install their own dependency graph.
283
+ // Add the internal runtime/compiler plumbing directly so bundlers that
284
+ // resolve through the consumer's node_modules (Vite/Rolldown included)
285
+ // see the same graph as the Mün workspace.
286
+ for (const name of ['@mun-ui/animation', '@mun-ui/core', '@mun-ui/compiler', '@mun-ui/execution', '@mun-ui/web']) {
287
+ manifest.devDependencies[name] = linkSpecifier(resolve(localRoot, localPackagePaths[name]))
288
+ }
289
+ // Opt-in @mun-ui/ui features re-export internal modules; a linked @mun-ui/ui
290
+ // does not install them itself.
291
+ if (linkRootPackage) manifest.devDependencies['@mun-ui/progressive-blur'] = linkSpecifier(resolve(localRoot, localPackagePaths['@mun-ui/progressive-blur']))
292
+ // pnpm 11 moved overrides out of package.json and into pnpm-workspace.yaml.
293
+ // Keep every internal package pinned to this checkout so unpublished
294
+ // transitive @mun-ui/* dependencies never fall through to the registry.
295
+ if (manifest.pnpm?.overrides) {
296
+ delete manifest.pnpm.overrides
297
+ if (Object.keys(manifest.pnpm).length === 0) delete manifest.pnpm
298
+ }
299
+ if (manifest.dependencies['@mun-ui/desktop']) manifest.dependencies['@mun-ui/desktop'] = linkSpecifier(resolve(localRoot, 'packages/desktop'))
300
+ const selectedOverrideNames = [
301
+ '@mun-ui/animation',
302
+ '@mun-ui/core',
303
+ '@mun-ui/compiler',
304
+ '@mun-ui/execution',
305
+ '@mun-ui/web',
306
+ '@mun-ui/vite',
307
+ `@mun-ui/${renderer}`,
308
+ ]
309
+ if (manifest.dependencies['@mun-ui/desktop']) selectedOverrideNames.push('@mun-ui/desktop')
310
+ if (linkRootPackage) selectedOverrideNames.push('@mun-ui/progressive-blur')
311
+ const overridePaths = includeRootPackage
312
+ ? localPackagePaths
313
+ : Object.fromEntries([...new Set(selectedOverrideNames)].map(name => [name, localPackagePaths[name]]))
314
+ const overrides = Object.fromEntries(
315
+ Object.entries(overridePaths).map(([name, relativePath]) => [
316
+ name,
317
+ linkSpecifier(resolve(localRoot, relativePath)),
318
+ ]),
319
+ )
320
+
321
+ writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`)
322
+ updatePnpmWorkspaceOverrides(projectRoot, overrides)
323
+ console.log(`Linked Mün ${packageManifest.version} (${renderer}) from ${localRoot}`)
324
+ return manifest
325
+ }
326
+
327
+ function printHelp() {
328
+ console.log(`Mün UI CLI
329
+
330
+ Usage:
331
+ mun new <directory> [--target native|web|desktop]
332
+ mun create <directory> [--target native|web|desktop]
333
+ mun init [--target native|web|desktop]
334
+ mun dev [--verbose] # detected project target
335
+ mun inspect [--values] [--json]
336
+ mun run [input.mun] # project target (source file: legacy native)
337
+ mun check
338
+ mun fmt [--check]
339
+ mun build
340
+ mun package [--sign <identity>] [--notarize-profile <keychain-profile>]
341
+ mun doctor
342
+ mun compile <input.mun> [output.json]
343
+ mun link <project> [--renderer astro|react|vue|web] [--pm <manager>] [--no-install] [--local-root <path>]
344
+ mun lsp [--stdio]
345
+ mun lsp install [--editor ...] [--project <path>] [--global]
346
+ mun editor install [--editor vim|nvim|vscode|zed|helix|generic|all] [--project <path>] [--global]
347
+ mun editor export vscode [output.vsix]
348
+
349
+ Local checkout workflow:
350
+ # from the Mün repository
351
+ pnpm build
352
+ pnpm dev:link ../my-app
353
+
354
+ # or scaffold a separate app using this checkout without npm publication
355
+ node bin/mun.mjs create ../my-app --local
356
+
357
+ Initializer aliases after publishing:
358
+ npm create mun <directory>
359
+ pnpm create mun <directory>
360
+
361
+ new/create/init scaffold a web application with Vite by default. Use --target desktop for the Tauri system WebView, or --target native for the experimental native runtime.
362
+ --local rewrites Mün dependencies to link: paths pointing at the source checkout.
363
+ Local source mode always uses pnpm because it relies on pnpm workspace overrides.
364
+ --no-install leaves dependency installation to you and prints the exact commands to continue.
365
+ link auto-detects Astro, React, or Vue from the target package.json and otherwise uses Web.
366
+ Use --renderer to override detection. link adds the same local links and pnpm-workspace.yaml overrides to an existing project.`)
367
+ }
368
+
369
+ function compileCommand() {
370
+ if (positionals.length < 1 || positionals.length > 2) {
371
+ console.error('Usage: mun compile <input.mun> [output.json]')
372
+ return 1
373
+ }
374
+ const script = resolve(packageRoot, 'bin/compile.mjs')
375
+ const result = spawnSync(process.execPath, [script, ...positionals], {
376
+ cwd: process.cwd(),
377
+ stdio: 'inherit',
378
+ })
379
+ return result.status ?? 1
380
+ }
381
+
382
+ function runCommand() {
383
+ if (positionals.length > 1) throw new Error('Usage: mun run [input.mun]')
384
+ return positionals.length ? runNativeSource(positionals[0]) : dispatchProjectCommand('run')
385
+ }
386
+
387
+ function editorCommand() {
388
+ const action = positionals[0]
389
+ if (action === 'install') {
390
+ if (positionals.length > 1) options.editor = positionals[1]
391
+ return installEditors({ editor: options.editor, projectRoot: options.projectRoot ?? process.cwd(), global: options.global }) && 0
392
+ }
393
+ if (action === 'export' && positionals[1] === 'vscode') {
394
+ const script = resolve(packageRoot, 'editors/vscode/export.mjs')
395
+ const result = spawnSync(process.execPath, [script, ...positionals.slice(2)], { cwd: packageRoot, stdio: 'inherit' })
396
+ return result.status ?? 1
397
+ }
398
+ console.error('Usage: mun editor install [--editor vim|nvim|vscode|zed|helix|generic|all] [--project <path>] [--global]')
399
+ console.error(' mun editor export vscode [output.vsix]')
400
+ return 1
401
+ }
402
+
403
+ function scaffold(projectRoot, commandName) {
404
+ const targetExists = existsSync(projectRoot)
405
+ const targetIsNonEmpty = targetExists && readdirSync(projectRoot).length > 0
406
+ if (targetIsNonEmpty && !options.force) {
407
+ console.error(`Mün ${commandName} cannot use a non-empty directory: ${projectRoot}`)
408
+ console.error('Choose a new directory, use an empty directory, or re-run with --force.')
409
+ return 1
410
+ }
411
+ if (targetIsNonEmpty && options.force) {
412
+ console.warn('Using --force: Mün template files will be replaced; unrelated files will be kept.')
413
+ }
414
+
415
+ const target = options.target ?? (options.renderer === 'native' ? 'native' : 'web')
416
+ if (!['native', 'web', 'desktop'].includes(target)) throw new Error(`Unsupported project target: ${target}. Use native, web, or desktop.`)
417
+ if (target === 'native') {
418
+ if (options.renderer && options.renderer !== 'native') throw new Error('Native scaffolds do not use a Web renderer.')
419
+ if (options.packageManager) packageManagerFor(projectRoot)
420
+ if (options.local) assertSourceCheckout(normalizeLocalRoot(options.localRoot))
421
+ mkdirSync(projectRoot, { recursive: true })
422
+ writeTemplates(projectRoot, [
423
+ ['templates/native/mun.toml', 'mun.toml'],
424
+ ['templates/native/App.mun', 'Sources/App.mun'],
425
+ ['templates/native/gitignore', '.gitignore'],
426
+ ])
427
+ mkdirSync(resolve(projectRoot, 'Assets'), { recursive: true })
428
+ console.log(`Created experimental native Mün app in ${projectRoot}`)
429
+ console.log(`\nNext steps:\n cd ${projectRoot}\n mun dev`)
430
+ return 0
431
+ }
432
+ if (options.renderer && options.renderer !== 'web') {
433
+ throw new Error('The built-in project template uses the renderer-independent Web adapter. Use `mun link` to connect an existing React or Vue project.')
434
+ }
435
+
436
+ const packageManager = packageManagerFor(projectRoot, { local: options.local })
437
+ const localRoot = options.local ? assertSourceCheckout(normalizeLocalRoot(options.localRoot)) : undefined
438
+
439
+ mkdirSync(projectRoot, { recursive: true })
440
+ writeTemplates(projectRoot, projectFiles)
441
+ if (target === 'desktop') {
442
+ const files = ['package.json', 'vite.config.ts', 'gitignore', 'src-tauri/Cargo.toml', 'src-tauri/build.rs', 'src-tauri/src/main.rs', 'src-tauri/tauri.conf.json', 'src-tauri/capabilities/main.json']
443
+ mkdirSync(resolve(projectRoot, 'src-tauri/icons'), { recursive: true })
444
+ for (const icon of ['icon.png', 'icon.icns', 'icon.ico']) cpSync(resolve(packageRoot, `templates/desktop/src-tauri/icons/${icon}`), resolve(projectRoot, `src-tauri/icons/${icon}`))
445
+ writeTemplates(projectRoot, files.map(file => [`templates/desktop/${file}`, file === 'gitignore' ? '.gitignore' : file]))
446
+ }
447
+ if (localRoot) configureLocalDependencies(projectRoot, localRoot, 'web', { includeRootPackage: false })
448
+ console.log(`Created Mün app in ${projectRoot}`)
449
+ if (!options.noInstall) {
450
+ try {
451
+ installDependencies(projectRoot, packageManager)
452
+ } catch (error) {
453
+ printInstallRecovery(projectRoot, packageManager)
454
+ console.error(`Install error: ${error instanceof Error ? error.message : String(error)}`)
455
+ return 1
456
+ }
457
+ } else {
458
+ console.log('Skipped dependency installation (--no-install).')
459
+ }
460
+ printScaffoldNextSteps(projectRoot, packageManager, !options.noInstall)
461
+ return 0
462
+ }
463
+
464
+ function linkProject(target) {
465
+ const projectRoot = resolve(process.cwd(), target)
466
+ const localRoot = normalizeLocalRoot(options.localRoot)
467
+ const packageManager = packageManagerFor(projectRoot, { local: true })
468
+ const renderer = options.renderer ?? detectRenderer(projectRoot)
469
+ configureLocalDependencies(projectRoot, localRoot, renderer)
470
+ if (!options.noInstall) installDependencies(projectRoot, packageManager)
471
+ else {
472
+ console.log('Skipped dependency installation (--no-install).')
473
+ console.log(`\nNext step:\n ${packageManager} install`)
474
+ }
475
+ return 0
476
+ }
477
+
478
+ function dispatchProjectCommand(command) {
479
+ const project = detectProjectTarget(options.projectRoot ?? process.cwd())
480
+ return project && project.target !== 'native' ? frontendCommand(command, project, options) : projectCommand(command, options)
481
+ }
482
+
483
+ function main() {
484
+ if (command === '--version' || command === '-v') { console.log(packageManifest.version); return 0 }
485
+ if (command === '--help' || command === '-h') { printHelp(); return 0 }
486
+ if (options.help || !command) { printHelp(); return 0 }
487
+ if (options.version) { console.log(packageManifest.version); return 0 }
488
+ if (['check', 'fmt', 'build', 'package', 'doctor', 'dev', 'inspect'].includes(command)) {
489
+ if (positionals.length) throw new Error(`Usage: mun ${command} [--project <directory>]`)
490
+ return dispatchProjectCommand(command)
491
+ }
492
+ if (options.help || !command) {
493
+ printHelp()
494
+ return 0
495
+ }
496
+ if (command === 'compile') return compileCommand()
497
+ if (command === 'run') return runCommand()
498
+ if (command === 'create' || command === 'new') {
499
+ const target = positionals[0]
500
+ if (!target || positionals.length > 1) {
501
+ console.error('Usage: mun create <directory> [--pm <manager>] [--no-install] [--force] [--local]')
502
+ return 1
503
+ }
504
+ const projectRoot = resolve(process.cwd(), target)
505
+ return scaffold(projectRoot, 'create')
506
+ }
507
+ if (command === 'init') {
508
+ if (positionals.length > 0) {
509
+ console.error('Usage: mun init [--force] [--no-install] [--local]')
510
+ return 1
511
+ }
512
+ return scaffold(process.cwd(), 'init')
513
+ }
514
+ if (command === 'link') {
515
+ if (positionals.length !== 1) {
516
+ console.error('Usage: mun link <project> [--renderer react|vue|web] [--no-install] [--local-root <path>]')
517
+ return 1
518
+ }
519
+ return linkProject(positionals[0])
520
+ }
521
+ if (command === 'lsp') {
522
+ if (positionals[0] === 'install') return installEditors({ editor: options.editor, projectRoot: options.projectRoot ?? process.cwd(), global: options.global }) && 0
523
+ const script = resolve(packageRoot, 'editors/lsp/mun-lsp.mjs')
524
+ const result = spawnSync(process.execPath, [script, ...argv.slice(1)], { cwd: packageRoot, stdio: 'inherit' })
525
+ return result.status ?? 1
526
+ }
527
+ if (command === 'editor') return editorCommand()
528
+ console.error(`Unknown Mün command: ${command}`)
529
+ printHelp()
530
+ return 1
531
+ }
532
+
533
+ try {
534
+ process.exitCode = await main()
535
+ } catch (error) {
536
+ console.error(`Mün ${command ?? 'command'} failed: ${error instanceof Error ? error.message : String(error)}`)
537
+ process.exitCode = 1
538
+ }
package/bin/native.mjs ADDED
@@ -0,0 +1,133 @@
1
+ import { spawnSync } from 'node:child_process'
2
+ import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
3
+ import { homedir, tmpdir } from 'node:os'
4
+ import { dirname, relative, resolve, sep } from 'node:path'
5
+ import { fileURLToPath } from 'node:url'
6
+ import { compileMunUiProgram } from '@mun-ui/compiler'
7
+
8
+ const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..')
9
+ const packageManifest = JSON.parse(readFileSync(resolve(packageRoot, 'package.json'), 'utf8'))
10
+
11
+ function displayPath(path, cwd) {
12
+ const local = relative(cwd, path)
13
+ return local && !local.startsWith('..') ? local : path
14
+ }
15
+
16
+ export function nativeBinaryName() {
17
+ return process.platform === 'win32' ? 'mun-native.exe' : 'mun-native'
18
+ }
19
+
20
+ function nativeCacheRoot(env) {
21
+ if (env.MUN_CACHE_DIR) return resolve(env.MUN_CACHE_DIR)
22
+ if (process.platform === 'darwin') return resolve(homedir(), 'Library', 'Caches', 'Mun')
23
+ if (process.platform === 'win32') {
24
+ return resolve(env.LOCALAPPDATA || resolve(homedir(), 'AppData', 'Local'), 'Mun', 'Cache')
25
+ }
26
+ return resolve(env.XDG_CACHE_HOME || resolve(homedir(), '.cache'), 'mun')
27
+ }
28
+
29
+ function runProcess(command, args, options) {
30
+ const result = spawnSync(command, args, options)
31
+ if (result.error) throw new Error(`Could not run ${command}: ${result.error.message}`)
32
+ return result.status ?? 1
33
+ }
34
+
35
+ export function resolveNativeHost(cwd, env, irVersion) {
36
+ const override = env.MUN_NATIVE_HOST?.trim()
37
+ if (override) {
38
+ const command = override.includes('/') || override.includes('\\') || override.includes(sep)
39
+ ? resolve(cwd, override)
40
+ : override
41
+ return { kind: 'binary', command }
42
+ }
43
+
44
+ const binary = nativeBinaryName()
45
+ const key = `${process.platform}-${process.arch}`
46
+ const packaged = resolve(packageRoot, 'native', 'bin', key, binary)
47
+ if (existsSync(packaged)) {
48
+ verifyPackagedHost(resolve(packageRoot, 'native', 'bin', key, 'mun-native.json'), key, irVersion)
49
+ return { kind: 'binary', command: packaged }
50
+ }
51
+
52
+ // Building the host from source is a development path for repository
53
+ // checkouts (or an explicit opt-in); installed packages use a packaged host.
54
+ const manifest = resolve(packageRoot, 'native', 'Cargo.toml')
55
+ const developmentCheckout = existsSync(resolve(packageRoot, '.git'))
56
+ if (existsSync(manifest) && (developmentCheckout || env.MUN_NATIVE_BUILD_FROM_SOURCE === '1')) {
57
+ return { kind: 'cargo', manifest }
58
+ }
59
+
60
+ throw new Error(
61
+ `No Mün native host is packaged for ${key} in ${packageManifest.name}@${packageManifest.version}. ` +
62
+ 'Install a release that includes this platform, set MUN_NATIVE_HOST to a mun-native executable, ' +
63
+ 'or set MUN_NATIVE_BUILD_FROM_SOURCE=1 to build one with Cargo.',
64
+ )
65
+ }
66
+
67
+ /** Reject a packaged host assembled for another package version, IR contract or platform. */
68
+ function verifyPackagedHost(path, key, irVersion) {
69
+ let metadata
70
+ try {
71
+ metadata = JSON.parse(readFileSync(path, 'utf8'))
72
+ } catch (error) {
73
+ throw new Error(`Packaged Mün native host for ${key} has no readable metadata (${path}): ${error.message}`)
74
+ }
75
+ const expected = {
76
+ packageVersion: packageManifest.version,
77
+ semanticUiIrVersion: irVersion,
78
+ platform: process.platform,
79
+ arch: process.arch,
80
+ }
81
+ for (const [field, value] of Object.entries(expected)) {
82
+ if (metadata[field] !== value) {
83
+ throw new Error(
84
+ `Packaged Mün native host for ${key} was built for ${field} ${JSON.stringify(metadata[field])}, ` +
85
+ `but this ${packageManifest.name} requires ${JSON.stringify(value)}. Reinstall ${packageManifest.name} or set MUN_NATIVE_HOST.`,
86
+ )
87
+ }
88
+ }
89
+ }
90
+
91
+ export function runNativeSource(inputArg, {
92
+ cwd = process.cwd(),
93
+ env = process.env,
94
+ } = {}) {
95
+ const input = resolve(cwd, inputArg)
96
+ if (!input.endsWith('.mun')) {
97
+ throw new Error(`Mün run expects canonical .mun source: ${displayPath(input, cwd)}`)
98
+ }
99
+
100
+ const source = readFileSync(input, 'utf8')
101
+ const program = compileMunUiProgram(source, input)
102
+ const temporary = mkdtempSync(resolve(tmpdir(), 'mun-native-'))
103
+ const ir = resolve(temporary, 'program.mun.ir.json')
104
+
105
+ try {
106
+ writeFileSync(ir, `${JSON.stringify(program, null, 2)}\n`)
107
+ const host = resolveNativeHost(cwd, env, program.version)
108
+
109
+ if (host.kind === 'binary') {
110
+ return runProcess(host.command, [ir], { cwd, env, stdio: 'inherit' })
111
+ }
112
+
113
+ const cache = resolve(
114
+ nativeCacheRoot(env),
115
+ 'native',
116
+ packageManifest.version,
117
+ `${process.platform}-${process.arch}`,
118
+ )
119
+ mkdirSync(cache, { recursive: true })
120
+ const cargo = env.CARGO?.trim() || 'cargo'
121
+ return runProcess(
122
+ cargo,
123
+ ['run', '--locked', '--manifest-path', host.manifest, '-p', 'mun-native', '--', ir],
124
+ {
125
+ cwd: packageRoot,
126
+ env: { ...env, CARGO_TARGET_DIR: env.CARGO_TARGET_DIR || cache },
127
+ stdio: 'inherit',
128
+ },
129
+ )
130
+ } finally {
131
+ rmSync(temporary, { recursive: true, force: true })
132
+ }
133
+ }