@moku-labs/native 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +229 -0
- package/dist/index.cjs +4127 -0
- package/dist/index.d.cts +615 -0
- package/dist/index.d.mts +613 -0
- package/dist/index.mjs +4055 -0
- package/dist/rolldown-runtime-8H4AJuhK.mjs +14 -0
- package/package.json +79 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 moku-labs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
# @moku-labs/native
|
|
2
|
+
|
|
3
|
+
**Compose system plugins, get native installers — the entire permission surface is codegenned, never hand-maintained.**
|
|
4
|
+
|
|
5
|
+
`@moku-labs/native` is the Moku family's node-only native packager: a [`@moku-labs/core`](https://github.com/moku-labs/core) Layer-2 framework that wraps [Tauri 2](https://v2.tauri.app) end-to-end. It generates a gitignored Tauri project, codegens the permission surface (Tauri capabilities, the `Info.ios.plist` sidecar, `AndroidManifest.xml` needs) from whichever system plugins your app composed, and drives `tauri build` for all five targets — macOS, Windows, Linux, iOS, Android. It is not a runtime and ships nothing inside your app: the generated Tauri project is disposable build output, never committed source.
|
|
6
|
+
|
|
7
|
+
<br/>
|
|
8
|
+
|
|
9
|
+
[](https://www.npmjs.com/package/@moku-labs/native)
|
|
10
|
+
[](#requirements)
|
|
11
|
+
[](#requirements)
|
|
12
|
+
[](https://github.com/moku-labs/core)
|
|
13
|
+
[](./LICENSE)
|
|
14
|
+
|
|
15
|
+
<br/>
|
|
16
|
+
|
|
17
|
+
[Quick start](#quick-start) · [Two apps, one contract](#two-apps-one-contract) · [Plugins](#plugins) · [Configuration](#configuration) · [Events](#events) · [Docs](#docs)
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Why @moku-labs/native
|
|
22
|
+
|
|
23
|
+
- **The composition IS the permission surface.** Declare `{ name: "notification" }` once in `config.system` and the capability registry resolves it into npm/crate dependencies, Rust plugin init, capability JSON, and mobile permission needs — no hand-edited `tauri.conf.json`, no drifting plist.
|
|
24
|
+
- **Generated, gitignored, regenerable.** `.moku/tauri/` is build output, not source. Delete it, run a build, and the write-if-changed generators reproduce it byte-for-byte — the "minimal troubles" promise lives here.
|
|
25
|
+
- **One subprocess seam.** Only the `tauri` plugin spawns processes — everything reaching `@tauri-apps/cli` goes through its argv builders, entropy-gated secret scrubbing, error taxonomy, and process-group dev lifecycle.
|
|
26
|
+
- **A packager, not a runtime.** Node-only, the deploy/CLI analogue for native packaging. Nothing here executes inside your shipped app; your web app stays exactly what it was.
|
|
27
|
+
- **Secrets stay in env vars.** Config carries env-var *references* only (`signing.android.keystorePasswordEnv`), doctor checks presence without reading values, and every subprocess output line is scrubbed before it can reach a log.
|
|
28
|
+
|
|
29
|
+
## Quick start
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
bun add @moku-labs/native
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
> [!NOTE]
|
|
36
|
+
> **Status: `0.x` — early.** `@moku-labs/core` and `@moku-labs/common` install transitively as regular dependencies — one `bun add` is the whole install. A real `node` binary on PATH is a hard prerequisite (`@tauri-apps/cli` cannot run under bun); `native doctor` checks it.
|
|
37
|
+
|
|
38
|
+
A native app is its own `createApp` — typically `src/native.ts`, beside your web app:
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
// src/system.ts — the system-plugin composition, shared with your web app
|
|
42
|
+
export const systemPlugins = [{ name: "store" }, { name: "deep-link" }];
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
// src/native.ts — the native createApp (Layer 3)
|
|
47
|
+
import { createApp } from "@moku-labs/native";
|
|
48
|
+
import { systemPlugins } from "./system";
|
|
49
|
+
|
|
50
|
+
export const native = createApp({
|
|
51
|
+
config: {
|
|
52
|
+
app: { name: "MyApp", identifier: "com.example.myapp" },
|
|
53
|
+
web: {
|
|
54
|
+
build: "bun run build",
|
|
55
|
+
dev: { command: "bun run dev", url: "http://localhost:5173" },
|
|
56
|
+
dist: "dist"
|
|
57
|
+
},
|
|
58
|
+
system: systemPlugins,
|
|
59
|
+
capabilities: { "deep-link": { mode: "scheme", scheme: "myapp" } }
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
// scripts/native-build.ts — one thin script per verb
|
|
66
|
+
import { native } from "../src/native";
|
|
67
|
+
|
|
68
|
+
await native.start();
|
|
69
|
+
await native.cli.build({ target: "macos" }); // installers land in dist-native/macos/
|
|
70
|
+
await native.stop();
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
> [!IMPORTANT]
|
|
74
|
+
> Add `.moku/` and `dist-native/` to your `.gitignore`. The generated Tauri project is never committed — it is fully regenerable output.
|
|
75
|
+
|
|
76
|
+
## How it works
|
|
77
|
+
|
|
78
|
+
```mermaid
|
|
79
|
+
flowchart LR
|
|
80
|
+
U["You<br/>(typed cli verbs)"] --> CLI["cli<br/>branded output,<br/>live progress"]
|
|
81
|
+
CLI --> B["build<br/>phase pipeline"]
|
|
82
|
+
CLI --> D["doctor<br/>parallel checks"]
|
|
83
|
+
B --> P["project<br/>registry + codegen"]
|
|
84
|
+
B --> T["tauri<br/>subprocess seam"]
|
|
85
|
+
D --> P
|
|
86
|
+
D --> T
|
|
87
|
+
T --> A["installers in<br/>dist-native/<target>/"]
|
|
88
|
+
classDef u fill:#0b7285,stroke:#08525f,color:#fff;
|
|
89
|
+
classDef m fill:#1864ab,stroke:#0d3d6e,color:#fff;
|
|
90
|
+
class U,A u
|
|
91
|
+
class CLI,B,D,P,T m
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Each `build.run({ target })` walks the phase pipeline `scaffold → codegen → icons → compile → bundle → collect` (the `PHASE_ORDER` constant), emitting a global `native:phase` event per phase and `native:complete` on success — which is exactly what `cli` renders as live progress. `project` and `tauri` never call each other; `build` orchestrates them, `doctor` reads them, `cli` fronts all four.
|
|
95
|
+
|
|
96
|
+
### The composition is the contract
|
|
97
|
+
|
|
98
|
+
`config.system` is a name-only array — `ReadonlyArray<{ name: string }>` — and that one list drives the whole packaging surface. The `project` plugin resolves each name against its capability registry (`store`, `notification`, `clipboard-manager`, `tray`, `deep-link`) into a `ResolvedCapability`: npm package + crate ranges, Rust init line, capability permissions, per-platform applicability, and conf fragments. Unknown names fail at composition time, not at build time. In v1 the mobile permission surface is conf-only by verified design — the official Tauri plugins self-merge their own manifest needs — so zero fragile XML patching ships at all.
|
|
99
|
+
|
|
100
|
+
## Two apps, one contract
|
|
101
|
+
|
|
102
|
+
Your project runs **two `createApp`s side by side**: the web/node app you already have, and the native app (`src/native.ts`) from this framework. Plugins are bound to their own framework's chain, so native plugins can never be composed into the web app — the two apps integrate at the edges instead:
|
|
103
|
+
|
|
104
|
+
- **`src/system.ts` is the shared contract.** Both apps import the same array of `{ name }` system-plugin declarations. The web app uses it to know which capabilities exist; the native app codegens the entire permission surface from it. One list, no drift — this is the cross-team contract.
|
|
105
|
+
- **Scripts stay thin, one verb each.** `package.json` wires per-verb consumer scripts that call the native app's typed `cli` verbs — there is no argv CLI to parse:
|
|
106
|
+
|
|
107
|
+
```jsonc
|
|
108
|
+
{
|
|
109
|
+
"scripts": {
|
|
110
|
+
"native:dev": "bun run scripts/native-dev.ts",
|
|
111
|
+
"native:build": "bun run scripts/native-build.ts",
|
|
112
|
+
"native:doctor": "bun run scripts/native-doctor.ts",
|
|
113
|
+
"native:clean": "bun run scripts/native-clean.ts"
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
// scripts/native-doctor.ts
|
|
120
|
+
import { native } from "../src/native";
|
|
121
|
+
|
|
122
|
+
await native.start();
|
|
123
|
+
const ok = await native.cli.doctor();
|
|
124
|
+
await native.stop();
|
|
125
|
+
if (!ok) process.exitCode = 1;
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
- **Directory roles.** `projectDir` (default **`.moku/tauri/`**) is the generated Tauri project — gitignored, fully regenerable, never committed. `outDir` (default **`dist-native/`**) is where finished installers are collected, per target (`dist-native/macos/`, `dist-native/android/`, …).
|
|
129
|
+
|
|
130
|
+
## Plugins
|
|
131
|
+
|
|
132
|
+
| Plugin | Tier | Key API | Responsibility |
|
|
133
|
+
|---|---|---|---|
|
|
134
|
+
| [`project`](./src/plugins/project/README.md) | Complex | `generate` · `completeness` · `patchMobile` · `clean` · `resolve` | Capability registry + `.moku/tauri` generators + write-if-changed writer + mobile init-once-then-patch. Owns the generated tree as *files*; never spawns. |
|
|
135
|
+
| [`tauri`](./src/plugins/tauri/README.md) | Standard | `icon` · `build` · `mobileInit` · `dev` · `version` | The framework's **only** subprocess seam: `@tauri-apps/cli` argv builders, injectable spawn, process-group dev lifecycle, error taxonomy, secret scrubbing. |
|
|
136
|
+
| [`build`](./src/plugins/build/README.md) | Standard | `run` · `runAll` | Sequential per-target phase pipeline; emits `native:phase`/`native:complete`; owns the `collect` phase (bundle-location table → `dist-native/<target>/`). |
|
|
137
|
+
| [`doctor`](./src/plugins/doctor/README.md) | Complex | `run` | Per-target toolchain/completeness/version-skew diagnosis via a `checks/` registry, run in parallel — one broken check never sinks the report. |
|
|
138
|
+
| [`cli`](./src/plugins/cli/README.md) | Standard | `build` · `dev` · `doctor` · `clean` | Typed verb surface — no argv parsing. Branded rendering (`@moku-labs/common/cli`), live progress via event hooks. |
|
|
139
|
+
|
|
140
|
+
Every lower-level surface stays reachable on the composed app: `native.project.generate(…)`, `native.tauri.version()`, `native.build.runAll()`, `native.doctor.run()` — `cli` is convenience, not a gate.
|
|
141
|
+
|
|
142
|
+
## Configuration
|
|
143
|
+
|
|
144
|
+
The substantive surface is **global** `Config` — every plugin reads it via `ctx.global`; per-plugin configs are minimal seams.
|
|
145
|
+
|
|
146
|
+
| Field | Type | Default | Notes |
|
|
147
|
+
|---|---|---|---|
|
|
148
|
+
| `app` | `{ name: string; identifier: string; version?: string }` | `{ name: "", identifier: "" }` | Required — validated at composition time: non-empty `name`, reverse-DNS `identifier`. |
|
|
149
|
+
| `web` | `{ build: string; dev: { command: string; url: string }; dist: string; cwd?: string }` | `build: "bun run build"`, `dev.command: "bun run dev"`, `dev.url: "http://localhost:5173"`, `dist: "dist"` | Web build/dev wiring codegenned into `tauri.conf.json`; `cwd` for monorepo layouts. |
|
|
150
|
+
| `system` | `ReadonlyArray<{ name: string }>` | `[]` | The composed system plugins — the shared cross-team contract. Unknown names throw at init. |
|
|
151
|
+
| `capabilities` | `Partial<CapabilityConfigMap>` | `{}` | Per-capability packaging parameters. `deep-link` requires `{ mode: "scheme", scheme: string }`. |
|
|
152
|
+
| `targets` | `readonly Target[]` | all five (`macos`, `windows`, `linux`, `ios`, `android`) | Which targets this app ships; the `runAll`/`doctor` default scope. |
|
|
153
|
+
| `projectDir` | `string` | `".moku/tauri"` | Generated Tauri project root (contains `src-tauri/`). Gitignored build output. |
|
|
154
|
+
| `outDir` | `string` | `"dist-native"` | Installer delivery root — `collect` copies finished artifacts to `outDir/<target>/`. |
|
|
155
|
+
| `signing` | `SigningConfig` | `{}` | Env-var **references** and config-safe identifiers only — never raw secrets. `android: { keystorePath?, keystorePasswordEnv?, keyAlias? }`, `windows: { certificateThumbprint? }`. |
|
|
156
|
+
|
|
157
|
+
Per-plugin knobs, overridable via `createApp({ pluginConfigs })`:
|
|
158
|
+
|
|
159
|
+
| Plugin | Knob | Default | Purpose |
|
|
160
|
+
|---|---|---|---|
|
|
161
|
+
| `tauri` | `spawnImpl` / `nodePath` | `undefined` / `undefined` | Test seam / explicit `node` path (default: real process-group spawn, PATH-walked node). |
|
|
162
|
+
| `tauri` | `readiness` | `{ intervalMs: 250, timeoutMs: 60_000 }` | `dev()`'s devUrl readiness poll — there is no stdout "ready" marker. |
|
|
163
|
+
| `doctor` | `probeImpl` | `undefined` | Test seam for binary probes (default: real `which`/`--version` subprocesses). |
|
|
164
|
+
| `cli` | `renderImpl` / `confirmImpl` | `undefined` / `undefined` | Test seams (default: branded console + styled confirm from `@moku-labs/common/cli`). |
|
|
165
|
+
|
|
166
|
+
## Events
|
|
167
|
+
|
|
168
|
+
Two **global framework events** are declared in `src/config.ts` — emitted by `build`, hooked by `cli`, hookable by any plugin without a depends edge:
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
"native:phase": {
|
|
172
|
+
target: Target;
|
|
173
|
+
phase: NativePhase; // "scaffold" | "codegen" | "icons" | "compile" | "bundle" | "collect"
|
|
174
|
+
status: "start" | "progress" | "done" | "error";
|
|
175
|
+
durationMs?: number;
|
|
176
|
+
detail?: string; // progress ticks ("Compiling tauri 3/50"), skip reasons, error text
|
|
177
|
+
};
|
|
178
|
+
"native:complete": {
|
|
179
|
+
target: Target;
|
|
180
|
+
outPath: string; // dist-native/<target>/
|
|
181
|
+
artifacts: readonly string[];
|
|
182
|
+
durationMs: number;
|
|
183
|
+
};
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
One **per-plugin event** is declared by `doctor` (hookable via a `depends: [doctorPlugin]` edge):
|
|
187
|
+
|
|
188
|
+
```ts
|
|
189
|
+
"doctor:check": CheckResult; // { id, target: Target | "host", status: "pass" | "warn" | "fail", message, fixIt? }
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
> [!TIP]
|
|
193
|
+
> Compile progress details carry real crate counts parsed from cargo output — never a synthesized percentage.
|
|
194
|
+
|
|
195
|
+
## Scripts
|
|
196
|
+
|
|
197
|
+
```sh
|
|
198
|
+
bun run build # Build with tsdown
|
|
199
|
+
bun run lint # Biome check + ESLint
|
|
200
|
+
bun run lint:fix # Auto-fix lint issues
|
|
201
|
+
bun run format # Format with Biome
|
|
202
|
+
bun run test # Run all tests (vitest)
|
|
203
|
+
bun run test:unit # Unit tests only
|
|
204
|
+
bun run test:integration # Integration tests only
|
|
205
|
+
bun run test:coverage # Tests with coverage (90% threshold)
|
|
206
|
+
bun run validate # publint + are-the-types-wrong (publish readiness)
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Development
|
|
210
|
+
|
|
211
|
+
- **Adding a plugin** — create `src/plugins/<name>/` with `index.ts` (the `createPlugin` call), `types.ts`, and an API factory; register the instance in `src/index.ts`'s plugin array and re-export it from `src/plugins/index.ts`. Consumer apps can also author their own plugins with the exported `createPlugin` and pass them to `createApp({ plugins: [...] })`.
|
|
212
|
+
- **Tests** — plugin-specific tests are colocated (`src/plugins/<name>/__tests__/unit/` and `__tests__/integration/`); root `tests/` holds framework-level integration only. All subprocess/render/probe seams are injectable, so the suite runs without any native toolchain.
|
|
213
|
+
|
|
214
|
+
## Requirements
|
|
215
|
+
|
|
216
|
+
- **Node `>= 24`** and **Bun `>= 1.3.14`** — use `bun` exclusively (never npm/yarn/pnpm). A real `node` binary must also be on PATH for `@tauri-apps/cli`.
|
|
217
|
+
- **TypeScript** in strict mode, with `exactOptionalPropertyTypes` and `noUncheckedIndexedAccess`.
|
|
218
|
+
- **[`@moku-labs/core`](https://github.com/moku-labs/core)** — the micro-kernel this framework is built on (direct dependency).
|
|
219
|
+
- Native toolchains (Rust, Xcode, Android SDK/NDK) only for the targets you actually build — `native doctor` tells you what's missing per target.
|
|
220
|
+
|
|
221
|
+
## Docs
|
|
222
|
+
|
|
223
|
+
- Per-plugin references: [`project`](./src/plugins/project/README.md) · [`tauri`](./src/plugins/tauri/README.md) · [`build`](./src/plugins/build/README.md) · [`doctor`](./src/plugins/doctor/README.md) · [`cli`](./src/plugins/cli/README.md)
|
|
224
|
+
- LLM-ready docs: [`llms.txt`](./llms.txt) (concise) · [`llms-full.txt`](./llms-full.txt) (full type/event/config reference)
|
|
225
|
+
- [Moku Core specification](https://github.com/moku-labs/core/tree/main/specification) — the three-layer model, factory chain, lifecycle, and event system this framework implements.
|
|
226
|
+
|
|
227
|
+
## License
|
|
228
|
+
|
|
229
|
+
[MIT](./LICENSE) © [moku-labs](https://github.com/moku-labs)
|