@native-sdk/cli 0.5.0 → 0.5.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/build/app.zig +198 -13
- package/build/ts_run.mjs +58 -19
- package/build.zig +42 -0
- package/package.json +13 -9
- package/packages/core/package-lock.json +4 -3
- package/packages/core/package.json +3 -2
- package/packages/core/src/typed_ast.ts +11 -1
- package/src/platform/windows/webview2_host.cpp +24 -0
- package/src/primitives/canvas/layout_audit.zig +5 -5
- package/src/primitives/canvas/root.zig +5 -0
- package/src/primitives/canvas/tokens.zig +15 -0
- package/src/primitives/canvas/widget_builtin_tests.zig +309 -5
- package/src/primitives/canvas/widget_layout.zig +138 -2
- package/src/primitives/canvas/widget_metrics.zig +16 -8
- package/src/runtime/core.zig +16 -0
- package/src/runtime/effects.zig +1037 -133
- package/src/runtime/effects_fetch_tests.zig +42 -0
- package/src/runtime/effects_file_tests.zig +220 -0
- package/src/runtime/effects_tests.zig +287 -0
- package/src/runtime/ui_app.zig +131 -38
- package/src/runtime/ui_app_tests.zig +221 -0
- package/src/runtime/ui_app_window_tests.zig +182 -0
- package/src/tooling/package.zig +311 -8
- package/src/tooling/templates.zig +97 -9
- package/src/tooling/ts_core.zig +626 -13
- package/src/tooling/verbs.zig +88 -2
package/build/app.zig
CHANGED
|
@@ -70,6 +70,149 @@ const TsCoreStage = struct {
|
|
|
70
70
|
main_root: std.Build.LazyPath,
|
|
71
71
|
};
|
|
72
72
|
|
|
73
|
+
/// Whether the transpiler's TypeScript compiler (@typescript/old, the
|
|
74
|
+
/// exactly pinned npm alias of the real `typescript` package) RESOLVES
|
|
75
|
+
/// from the SDK's packages/core, by node's ancestor node_modules walk —
|
|
76
|
+
/// at the SDK's exactly pinned VERSION. The same semantics the CLI gates
|
|
77
|
+
/// on (src/tooling/ts_core.zig
|
|
78
|
+
/// transpilerResolution, this predicate's deliberate twin: keep the two
|
|
79
|
+
/// in lockstep).
|
|
80
|
+
///
|
|
81
|
+
/// Validation tracks ONLY what runtime loads, from the same origin
|
|
82
|
+
/// runtime resolves from: typed_ast.ts imports "@typescript/old" directly
|
|
83
|
+
/// and build/ts_run.mjs's load hook requires it from the target
|
|
84
|
+
/// packages/core/src module — src/ never carries a node_modules, so
|
|
85
|
+
/// packages/core is the walk origin that mirrors both. Covers every
|
|
86
|
+
/// layout: a repo checkout's packages/core/node_modules (nearest wins),
|
|
87
|
+
/// and the npm-installed CLI whose own `dependencies` carry the alias
|
|
88
|
+
/// (nested under the package on global prefixes, hoisted to the project
|
|
89
|
+
/// root on local ones, pnpm's sibling node_modules).
|
|
90
|
+
///
|
|
91
|
+
/// The @typescript/typescript6 wrapper is deliberately NOT probed:
|
|
92
|
+
/// nothing imports it at run time (typed_ast.ts bypasses its one-line
|
|
93
|
+
/// re-export on purpose), so holding the wrapper's resolution — or the
|
|
94
|
+
/// alias's version as seen FROM the wrapper's origin — against the pin
|
|
95
|
+
/// can only FALSE-REJECT healthy trees: npm's own conflict shape hoists
|
|
96
|
+
/// a consumer's conflicting `@typescript/old` at the project root while
|
|
97
|
+
/// our exact pin lands nested under the CLI, which is precisely the copy
|
|
98
|
+
/// runtime loads from packages/core; a consumer's own shadowing wrapper
|
|
99
|
+
/// must not sway the verdict either. The wrapper stays a DECLARED
|
|
100
|
+
/// dependency in both manifests — it is just not what validation vouches
|
|
101
|
+
/// for (see the twin's doc comment).
|
|
102
|
+
///
|
|
103
|
+
/// Resolvable means the alias's manifest AND its entrypoint are present
|
|
104
|
+
/// (see tsAliasedCompilerVersion for node's error shape and the
|
|
105
|
+
/// mid-extraction slivers) and its installed version equals the pin —
|
|
106
|
+
/// read from the SDK dependency's own packages/core/package.json (the
|
|
107
|
+
/// `npm:typescript@X.Y.Z` alias suffix in devDependencies —
|
|
108
|
+
/// tsParseAliasedCompilerPin, mirroring the twin's
|
|
109
|
+
/// parseAliasedCompilerPin), never hardcoded, so version bumps stay a
|
|
110
|
+
/// one-file change.
|
|
111
|
+
const TsToolchainResolution = union(enum) {
|
|
112
|
+
resolved,
|
|
113
|
+
unresolved,
|
|
114
|
+
/// The aliased compiler resolves, but at a version other than the
|
|
115
|
+
/// SDK's exact pin (strings allocated on b.allocator, freed never —
|
|
116
|
+
/// this is configure-time teaching data).
|
|
117
|
+
version_mismatch: struct { resolved: []const u8, pinned: []const u8 },
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
fn tsToolchainResolution(b: *std.Build, dep: *std.Build.Dependency) TsToolchainResolution {
|
|
121
|
+
const sdk_root = tsSdkRoot(b.allocator, b.graph.io, dep);
|
|
122
|
+
// The pin first: an SDK tree whose packages/core/package.json is
|
|
123
|
+
// missing or pinless is not one this gate can vouch for (the file
|
|
124
|
+
// ships in every layout), so it concludes unresolved and the teaching
|
|
125
|
+
// path acts.
|
|
126
|
+
const pinned = tsPinnedCompilerVersion(b, sdk_root) orelse return .unresolved;
|
|
127
|
+
const resolved = tsAliasedCompilerVersion(b, b.pathJoin(&.{ sdk_root, "packages", "core" })) orelse return .unresolved;
|
|
128
|
+
if (std.mem.eql(u8, resolved, pinned)) return .resolved;
|
|
129
|
+
return .{ .version_mismatch = .{ .resolved = resolved, .pinned = pinned } };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/// How runtime's `import "@typescript/old"` resolves, by node's walk FROM
|
|
133
|
+
/// `origin_dir` upward: the nearest ancestor
|
|
134
|
+
/// `node_modules/@typescript/old` wins (skipping ancestors that are
|
|
135
|
+
/// themselves a node_modules directory, as node does). Callers pass the
|
|
136
|
+
/// SDK's packages/core — the origin typed_ast.ts and ts_run.mjs resolve
|
|
137
|
+
/// the alias from. The walk must be a real ancestor walk, not a
|
|
138
|
+
/// fixed-sibling probe: npm hoists the alias to the install root on flat
|
|
139
|
+
/// layouts and nests it under the CLI on version conflicts. Resolvable
|
|
140
|
+
/// means the alias's manifest AND its entrypoint — the alias is the real
|
|
141
|
+
/// `typescript` package, whose `"main"` is ./lib/typescript.js (no
|
|
142
|
+
/// `"exports"`): a bare directory (an interrupted install, a pruned
|
|
143
|
+
/// node_modules) is MODULE_NOT_FOUND at run time, and a manifest without
|
|
144
|
+
/// its entrypoint (npm extraction is not atomic; package.json rides
|
|
145
|
+
/// first in the tarball) fails just as opaquely. Hardcoding it is safe
|
|
146
|
+
/// because the alias is exactly pinned (`npm:typescript@X.Y.Z` in both
|
|
147
|
+
/// manifests plus the lockfile) and drift-checked by check-version-sync.
|
|
148
|
+
/// A manifest without its entrypoint THROWS in node rather than
|
|
149
|
+
/// consulting a deeper ancestor, so it concludes unresolvable here too
|
|
150
|
+
/// (this predicate's deliberate twin: src/tooling/ts_core.zig's
|
|
151
|
+
/// aliasedCompilerVersion — keep the two in lockstep).
|
|
152
|
+
///
|
|
153
|
+
/// Returns the resolved alias's installed VERSION so the caller can hold
|
|
154
|
+
/// it against the SDK's pin; a resolvable-looking alias whose manifest
|
|
155
|
+
/// carries no version field returns null (every real npm install writes
|
|
156
|
+
/// one — its absence is a corrupt sliver, not a compiler to vouch for).
|
|
157
|
+
fn tsAliasedCompilerVersion(b: *std.Build, origin_dir: []const u8) ?[]const u8 {
|
|
158
|
+
const io = b.graph.io;
|
|
159
|
+
var dir: []const u8 = origin_dir;
|
|
160
|
+
while (true) {
|
|
161
|
+
if (!std.mem.eql(u8, std.fs.path.basename(dir), "node_modules")) {
|
|
162
|
+
found: {
|
|
163
|
+
const manifest_path = b.pathJoin(&.{ dir, "node_modules", "@typescript", "old", "package.json" });
|
|
164
|
+
std.Io.Dir.cwd().access(io, manifest_path, .{}) catch break :found;
|
|
165
|
+
std.Io.Dir.cwd().access(io, b.pathJoin(&.{ dir, "node_modules", "@typescript", "old", "lib", "typescript.js" }), .{}) catch return null;
|
|
166
|
+
const manifest = std.Io.Dir.cwd().readFileAlloc(io, manifest_path, b.allocator, .limited(64 * 1024)) catch return null;
|
|
167
|
+
return tsParseQuotedManifestValue(manifest, "\"version\"", "");
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
dir = std.fs.path.dirname(dir) orelse return null;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/// The version the SDK pins its aliased compiler to, read from the SDK
|
|
175
|
+
/// dependency's own packages/core/package.json — the same manifest the
|
|
176
|
+
/// CLI's gate reads, so both surfaces learn a version bump from one file.
|
|
177
|
+
fn tsPinnedCompilerVersion(b: *std.Build, sdk_root: []const u8) ?[]const u8 {
|
|
178
|
+
const manifest = std.Io.Dir.cwd().readFileAlloc(b.graph.io, b.pathJoin(&.{ sdk_root, "packages", "core", "package.json" }), b.allocator, .limited(64 * 1024)) catch return null;
|
|
179
|
+
const pin = tsParseQuotedManifestValue(manifest, "\"@typescript/old\"", "npm:typescript@") orelse return null;
|
|
180
|
+
// Exact X.Y.Z only (check-version-sync's pin shape), mirroring the
|
|
181
|
+
// twin's parseAliasedCompilerPin: a range is not a pin.
|
|
182
|
+
if (pin.len == 0) return null;
|
|
183
|
+
for (pin) |c| {
|
|
184
|
+
if (!std.ascii.isDigit(c) and c != '.') return null;
|
|
185
|
+
}
|
|
186
|
+
if (std.mem.count(u8, pin, ".") != 2) return null;
|
|
187
|
+
return pin;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/// Targeted scan for a manifest key's string value (the twin of
|
|
191
|
+
/// ts_core.zig's parsePackageVersion/parseAliasedCompilerPin scanners):
|
|
192
|
+
/// find `key`, expect `: "<required_prefix><value>"`, return `value`.
|
|
193
|
+
fn tsParseQuotedManifestValue(manifest_json: []const u8, comptime key: []const u8, comptime required_prefix: []const u8) ?[]const u8 {
|
|
194
|
+
const key_at = std.mem.indexOf(u8, manifest_json, key) orelse return null;
|
|
195
|
+
var rest = manifest_json[key_at + key.len ..];
|
|
196
|
+
rest = std.mem.trimStart(u8, rest, " \t\r\n");
|
|
197
|
+
if (rest.len == 0 or rest[0] != ':') return null;
|
|
198
|
+
rest = std.mem.trimStart(u8, rest[1..], " \t\r\n");
|
|
199
|
+
if (rest.len == 0 or rest[0] != '"') return null;
|
|
200
|
+
rest = rest[1..];
|
|
201
|
+
const end = std.mem.indexOfScalar(u8, rest, '"') orelse return null;
|
|
202
|
+
const value = rest[0..end];
|
|
203
|
+
if (!std.mem.startsWith(u8, value, required_prefix)) return null;
|
|
204
|
+
const suffix = value[required_prefix.len..];
|
|
205
|
+
if (suffix.len == 0) return null;
|
|
206
|
+
return suffix;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/// The SDK dependency's real root, resolved the way both the toolchain
|
|
210
|
+
/// check and its teaching name it.
|
|
211
|
+
fn tsSdkRoot(allocator: std.mem.Allocator, io: std.Io, dep: *std.Build.Dependency) []const u8 {
|
|
212
|
+
const raw_root = dep.builder.build_root.path orelse ".";
|
|
213
|
+
return std.Io.Dir.cwd().realPathFileAlloc(io, raw_root, allocator) catch raw_root;
|
|
214
|
+
}
|
|
215
|
+
|
|
73
216
|
fn tsCoreStage(b: *std.Build, dep: *std.Build.Dependency, app_root: []const u8) TsCoreStage {
|
|
74
217
|
if (!appFileExists(b, app_root, "src/app.native")) {
|
|
75
218
|
@panic("\nthis app has a TypeScript core (src/core.ts) but no view: TS apps render markup," ++
|
|
@@ -77,20 +220,50 @@ fn tsCoreStage(b: *std.Build, dep: *std.Build.Dependency, app_root: []const u8)
|
|
|
77
220
|
}
|
|
78
221
|
const node = b.findProgram(&.{"node"}, &.{}) catch {
|
|
79
222
|
@panic("\nbuilding a TypeScript app core needs node on PATH (the @native-sdk/core transpiler runs at" ++
|
|
80
|
-
" build time; the binary it emits ships no JS runtime).\nInstall Node.js 22+
|
|
81
|
-
" or `brew install node` — and re-run.\n");
|
|
82
|
-
};
|
|
83
|
-
dep.builder.build_root.handle.access(
|
|
84
|
-
dep.builder.graph.io,
|
|
85
|
-
"packages/core/node_modules/@typescript/typescript6",
|
|
86
|
-
.{},
|
|
87
|
-
) catch {
|
|
88
|
-
// Name the SDK dependency's real location (a checkout or the
|
|
89
|
-
// npm-installed @native-sdk/cli package — both carry
|
|
90
|
-
// packages/core with its lockfile, so `npm ci` works in place).
|
|
91
|
-
std.debug.panic("\nthe SDK's @native-sdk/core transpiler is missing its installed dependency.\nFix with:" ++
|
|
92
|
-
" cd {s}/packages/core && npm ci\n", .{dep.builder.build_root.path orelse "<sdk>"});
|
|
223
|
+
" build time; the binary it emits ships no JS runtime).\nInstall Node.js 22.15+ (on the 23 line: 23.5+)" ++
|
|
224
|
+
" — https://nodejs.org or `brew install node` — and re-run.\n");
|
|
93
225
|
};
|
|
226
|
+
switch (tsToolchainResolution(b, dep)) {
|
|
227
|
+
.resolved => {},
|
|
228
|
+
.unresolved => {
|
|
229
|
+
// Safety net for direct `zig build` users: the `native` CLI
|
|
230
|
+
// gates this itself, so reaching here means zig was invoked by
|
|
231
|
+
// hand against an SDK whose toolchain resolves nowhere. Name
|
|
232
|
+
// the SDK dependency's real location as a RESOLVED path and
|
|
233
|
+
// fail the configure phase cleanly — a teaching message, never
|
|
234
|
+
// a panic stack trace.
|
|
235
|
+
const sdk_root = tsSdkRoot(dep.builder.allocator, dep.builder.graph.io, dep);
|
|
236
|
+
std.debug.print(
|
|
237
|
+
\\
|
|
238
|
+
\\error: the @native-sdk/core transpiler cannot resolve its TypeScript toolchain
|
|
239
|
+
\\(its compiler, @typescript/old). On a repo checkout, install it once with:
|
|
240
|
+
\\ cd {s}/packages/core && npm ci --include=dev
|
|
241
|
+
\\(An npm-installed @native-sdk/cli carries the toolchain automatically; if it
|
|
242
|
+
\\is missing there, the install is broken - reinstall @native-sdk/cli.)
|
|
243
|
+
\\
|
|
244
|
+
\\
|
|
245
|
+
, .{sdk_root});
|
|
246
|
+
std.process.exit(1);
|
|
247
|
+
},
|
|
248
|
+
.version_mismatch => |mismatch| {
|
|
249
|
+
// The wrong-VERSION shape gets its own teaching (the CLI's
|
|
250
|
+
// gate mirrors it): a conflicting consumer-tree
|
|
251
|
+
// @typescript/old shadows the SDK's exact pin, and no install
|
|
252
|
+
// command fixes what is already installed — the conflict has
|
|
253
|
+
// to move.
|
|
254
|
+
std.debug.print(
|
|
255
|
+
\\
|
|
256
|
+
\\error: the @native-sdk/core transpiler's TypeScript compiler resolves at the
|
|
257
|
+
\\wrong version: @typescript/old resolves to typescript {s}, but the SDK pins
|
|
258
|
+
\\npm:typescript@{s}. Another package in this tree pins a conflicting
|
|
259
|
+
\\@typescript/old - align it with the SDK's pin (or remove it) and reinstall,
|
|
260
|
+
\\so the SDK's exact pin is the copy that resolves.
|
|
261
|
+
\\
|
|
262
|
+
\\
|
|
263
|
+
, .{ mismatch.resolved, mismatch.pinned });
|
|
264
|
+
std.process.exit(1);
|
|
265
|
+
},
|
|
266
|
+
}
|
|
94
267
|
|
|
95
268
|
// The transpiler runs through build/ts_run.mjs, not as `node cli.ts`:
|
|
96
269
|
// on the npm-installed layout the transpiler's .ts sources live inside
|
|
@@ -388,6 +561,18 @@ pub fn addAppArtifacts(b: *std.Build, dep: *std.Build.Dependency, app_options: A
|
|
|
388
561
|
.name = app_options.name,
|
|
389
562
|
.root_module = app_mod,
|
|
390
563
|
});
|
|
564
|
+
// Windows subsystem posture: release-shaped exes (`native build`,
|
|
565
|
+
// and therefore everything `native package --target windows` wraps)
|
|
566
|
+
// are GUI-subsystem, so launching the app never flashes a console
|
|
567
|
+
// window behind it. Debug exes keep the console subsystem — the dev
|
|
568
|
+
// loop's logs live there, and a double-clicked Debug binary opening
|
|
569
|
+
// its own log console is a feature. Redirected logging still works
|
|
570
|
+
// on GUI exes (handles inherit; only console AUTO-allocation is
|
|
571
|
+
// gated by the subsystem), so automation harnesses that pipe
|
|
572
|
+
// `app.exe > log 2>&1` keep their logs either way.
|
|
573
|
+
if (target.result.os.tag == .windows and app_optimize != .Debug) {
|
|
574
|
+
exe.subsystem = .windows;
|
|
575
|
+
}
|
|
391
576
|
linkPlatform(b, dep, target, app_mod, exe, selected_platform, web_engine, web_layer, cef_dir, cef_auto_install);
|
|
392
577
|
const install = b.addInstallArtifact(exe, .{});
|
|
393
578
|
b.getInstallStep().dependOn(&install.step);
|
package/build/ts_run.mjs
CHANGED
|
@@ -5,21 +5,28 @@
|
|
|
5
5
|
//
|
|
6
6
|
// node ts_run.mjs <module.ts> [args...]
|
|
7
7
|
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
//
|
|
8
|
+
// ONE code path for every layout: a load hook strips EVERY .ts module with
|
|
9
|
+
// the transpiler's own pinned TypeScript compiler (shipped as a dependency
|
|
10
|
+
// of @native-sdk/cli, or a repo checkout's `npm ci` install inside
|
|
11
|
+
// packages/core — either way resolved from the target module's location by
|
|
12
|
+
// node's ancestor node_modules walk). Node's own type stripping is never
|
|
13
|
+
// relied on: it refuses node_modules-resident .ts by design
|
|
14
|
+
// (ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING), and outside node_modules
|
|
15
|
+
// it only became DEFAULT in node 22.18 — so a checkout target on
|
|
16
|
+
// 22.15-22.17 would die with ERR_UNKNOWN_FILE_EXTENSION if the hook let it
|
|
17
|
+
// "fall through". Hooking everything makes the 22.15 floor true for both
|
|
18
|
+
// layouts. Then the runner imports the requested module with argv
|
|
19
|
+
// respliced so the target sees its usual shape (its own path at argv[1],
|
|
20
|
+
// its arguments from argv[2]).
|
|
19
21
|
//
|
|
20
|
-
// On node builds without module.registerHooks (
|
|
21
|
-
//
|
|
22
|
-
//
|
|
22
|
+
// On node builds without module.registerHooks (pre-22.15, or 23.0-23.4 —
|
|
23
|
+
// the hook landed in 22.15 and 23.5, so ">=22.15" alone is not the
|
|
24
|
+
// capability line) NO .ts target can run — node_modules-resident
|
|
25
|
+
// stripping is refused by design and default stripping outside
|
|
26
|
+
// node_modules only landed in 22.18, which is above this tier anyway —
|
|
27
|
+
// so the runner fails fast with one teaching line (upgrade to Node.js
|
|
28
|
+
// 22.15+, on the 23 line 23.5+) before importing it, instead of
|
|
29
|
+
// surfacing node's raw extension/stripping error.
|
|
23
30
|
|
|
24
31
|
import module, { createRequire } from 'node:module';
|
|
25
32
|
import { readFileSync } from 'node:fs';
|
|
@@ -36,15 +43,47 @@ const targetPath = resolve(target);
|
|
|
36
43
|
// exactly as when node runs it directly.
|
|
37
44
|
process.argv.splice(1, 1);
|
|
38
45
|
|
|
39
|
-
if (typeof module.registerHooks
|
|
46
|
+
if (typeof module.registerHooks !== 'function') {
|
|
47
|
+
// No load hooks on this node (pre-22.15, or a 23.0-23.4 build). Every
|
|
48
|
+
// .ts target needs the hook — node_modules-resident stripping is
|
|
49
|
+
// refused by design, and native default stripping outside node_modules
|
|
50
|
+
// is 22.18+ — so any .ts target would fail deep inside node with a raw
|
|
51
|
+
// extension/stripping error. Teach the fix instead.
|
|
52
|
+
if (targetPath.endsWith('.ts')) {
|
|
53
|
+
console.error(
|
|
54
|
+
`TypeScript apps need Node.js 22.15+ (on the 23 line: 23.5+); you're running ${process.version} - upgrade node and re-run.`,
|
|
55
|
+
);
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
40
59
|
let ts = null;
|
|
41
60
|
module.registerHooks({
|
|
42
61
|
load(url, context, nextLoad) {
|
|
43
|
-
if (url.startsWith('file:') && url.endsWith('.ts')
|
|
62
|
+
if (url.startsWith('file:') && url.endsWith('.ts')) {
|
|
44
63
|
const filePath = fileURLToPath(url);
|
|
45
|
-
// The transpiler's own
|
|
46
|
-
// location (packages/core/node_modules after the taught
|
|
47
|
-
|
|
64
|
+
// The transpiler's own pinned compiler, resolved from the target
|
|
65
|
+
// module's location (packages/core/node_modules after the taught
|
|
66
|
+
// `npm ci`, or the dependency npm installed beside the CLI). The
|
|
67
|
+
// ALIAS is required directly — not the @typescript/typescript6
|
|
68
|
+
// wrapper — because the wrapper's re-export resolves
|
|
69
|
+
// "@typescript/old" from the WRAPPER's own location, where a
|
|
70
|
+
// consumer tree's conflicting hoisted copy would win nearest-wins
|
|
71
|
+
// over our exact pin; resolving from the target finds our own
|
|
72
|
+
// nested/hoisted pin first (same reasoning as typed_ast.ts).
|
|
73
|
+
if (ts === null) {
|
|
74
|
+
try {
|
|
75
|
+
ts = createRequire(targetPath)('@typescript/old');
|
|
76
|
+
} catch {
|
|
77
|
+
// A missing toolchain reaches here only on a direct
|
|
78
|
+
// `node ts_run.mjs` run: every CLI verb gates resolution with
|
|
79
|
+
// a fuller per-layout teaching before this runner is spawned.
|
|
80
|
+
// Keep the direct-run error sane and name the checkout fix.
|
|
81
|
+
console.error(
|
|
82
|
+
`ts_run.mjs: the transpiler's TypeScript toolchain (@typescript/old) does not resolve from ${targetPath} - on a repo checkout, run \`npm ci --include=dev\` in packages/core.`,
|
|
83
|
+
);
|
|
84
|
+
process.exit(1);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
48
87
|
const { outputText } = ts.transpileModule(readFileSync(filePath, 'utf8'), {
|
|
49
88
|
fileName: filePath,
|
|
50
89
|
compilerOptions: {
|
package/build.zig
CHANGED
|
@@ -462,6 +462,48 @@ pub fn build(b: *std.Build) void {
|
|
|
462
462
|
.{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "\"gpuSurfaces\"" },
|
|
463
463
|
.{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "gpuFirstFrameLatencyNs: number" },
|
|
464
464
|
});
|
|
465
|
+
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-ts-toolchain-twins", "Verify the CLI's toolchain-resolution gate and its direct-`zig build` twin stay in lockstep (both resolve the aliased real compiler @typescript/old from packages/core — the same origin runtime imports it from — hold its resolved version against the manifest-read pin, never probe the unused @typescript/typescript6 wrapper, and teach instead of panicking)", &.{
|
|
466
|
+
// The resolution twins probe the aliased REAL compiler
|
|
467
|
+
// (@typescript/old — the package typed_ast.ts and ts_run.mjs
|
|
468
|
+
// actually load) — manifest AND entrypoint, in lockstep. The
|
|
469
|
+
// @typescript/typescript6 wrapper is never probed: nothing
|
|
470
|
+
// imports it at run time, and validating it false-rejects
|
|
471
|
+
// healthy conflict trees.
|
|
472
|
+
.{ .path = "src/tooling/ts_core.zig", .pattern = "\"node_modules\", \"@typescript\", \"old\", \"package.json\"" },
|
|
473
|
+
.{ .path = "src/tooling/ts_core.zig", .pattern = "\"node_modules\", \"@typescript\", \"old\", \"lib\", \"typescript.js\"" },
|
|
474
|
+
.{ .path = "build/app.zig", .pattern = "\"node_modules\", \"@typescript\", \"old\", \"package.json\"" },
|
|
475
|
+
.{ .path = "build/app.zig", .pattern = "\"node_modules\", \"@typescript\", \"old\", \"lib\", \"typescript.js\"" },
|
|
476
|
+
// The doctrine both twins document at their predicates: validate
|
|
477
|
+
// only what runtime loads, from runtime's own walk origin, and
|
|
478
|
+
// leave the declared-but-unimported wrapper out of the verdict.
|
|
479
|
+
.{ .path = "src/tooling/ts_core.zig", .pattern = "Validation tracks ONLY what runtime loads" },
|
|
480
|
+
.{ .path = "src/tooling/ts_core.zig", .pattern = "wrapper is deliberately NOT probed" },
|
|
481
|
+
.{ .path = "build/app.zig", .pattern = "Validation tracks ONLY what runtime loads" },
|
|
482
|
+
.{ .path = "build/app.zig", .pattern = "wrapper is deliberately NOT probed" },
|
|
483
|
+
// The reciprocal cross-references that keep the twins findable
|
|
484
|
+
// from each other.
|
|
485
|
+
.{ .path = "src/tooling/ts_core.zig", .pattern = "build/app.zig's tsToolchainResolution" },
|
|
486
|
+
.{ .path = "build/app.zig", .pattern = "transpilerResolution, this predicate's deliberate twin" },
|
|
487
|
+
// The version pin: both twins read the alias's RESOLVED
|
|
488
|
+
// package.json version and hold it against the exact
|
|
489
|
+
// `npm:typescript@X.Y.Z` pin read from the SDK's own
|
|
490
|
+
// packages/core/package.json (never hardcoded), and both carry
|
|
491
|
+
// the mismatch outcome plus its teaching naming the two versions.
|
|
492
|
+
.{ .path = "src/tooling/ts_core.zig", .pattern = "parseAliasedCompilerPin" },
|
|
493
|
+
.{ .path = "src/tooling/ts_core.zig", .pattern = "version_mismatch" },
|
|
494
|
+
.{ .path = "src/tooling/ts_core.zig", .pattern = "npm:typescript@{s}" },
|
|
495
|
+
.{ .path = "build/app.zig", .pattern = "tsPinnedCompilerVersion" },
|
|
496
|
+
.{ .path = "build/app.zig", .pattern = "version_mismatch" },
|
|
497
|
+
.{ .path = "build/app.zig", .pattern = "npm:typescript@{s}" },
|
|
498
|
+
// The teachings: the checkout's one production-config-safe npm ci
|
|
499
|
+
// command in both surfaces, the reinstall for npm layouts, and the
|
|
500
|
+
// build graph's clean configure-time failure (never a panic).
|
|
501
|
+
.{ .path = "src/tooling/ts_core.zig", .pattern = "pub const npm_ci_teaching_command = \"npm ci --include=dev\";" },
|
|
502
|
+
.{ .path = "src/tooling/ts_core.zig", .pattern = "reinstall @native-sdk/cli" },
|
|
503
|
+
.{ .path = "build/app.zig", .pattern = "npm ci --include=dev" },
|
|
504
|
+
.{ .path = "build/app.zig", .pattern = "cannot resolve its TypeScript toolchain" },
|
|
505
|
+
.{ .path = "build/app.zig", .pattern = "std.process.exit(1);" },
|
|
506
|
+
});
|
|
465
507
|
addFileContainsCheckStep(b, file_contains_checker, test_step, "test-app-test-entry-analysis", "Verify the managed app test step force-analyzes the entry point (UiApp.create's Model-defaults rule must teach at `native test`, not ambush at `native build`)", &.{
|
|
466
508
|
.{ .path = "build/app.zig", .pattern = "app_analysis.zig" },
|
|
467
509
|
.{ .path = "build/app.zig", .pattern = "if (@hasDecl(app, \"main\")) _ = &app.main;" },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@native-sdk/cli",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "The Native SDK: the complete toolkit for building native desktop applications — declarative markup, native rendering, WebView surfaces, and OS capabilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -27,15 +27,19 @@
|
|
|
27
27
|
"README.md",
|
|
28
28
|
"LICENSE"
|
|
29
29
|
],
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@typescript/old": "npm:typescript@6.0.3",
|
|
32
|
+
"@typescript/typescript6": "6.0.2"
|
|
33
|
+
},
|
|
30
34
|
"optionalDependencies": {
|
|
31
|
-
"@native-sdk/cli-darwin-arm64": "0.5.
|
|
32
|
-
"@native-sdk/cli-darwin-x64": "0.5.
|
|
33
|
-
"@native-sdk/cli-linux-arm64-gnu": "0.5.
|
|
34
|
-
"@native-sdk/cli-linux-arm64-musl": "0.5.
|
|
35
|
-
"@native-sdk/cli-linux-x64-gnu": "0.5.
|
|
36
|
-
"@native-sdk/cli-linux-x64-musl": "0.5.
|
|
37
|
-
"@native-sdk/cli-win32-arm64": "0.5.
|
|
38
|
-
"@native-sdk/cli-win32-x64": "0.5.
|
|
35
|
+
"@native-sdk/cli-darwin-arm64": "0.5.1",
|
|
36
|
+
"@native-sdk/cli-darwin-x64": "0.5.1",
|
|
37
|
+
"@native-sdk/cli-linux-arm64-gnu": "0.5.1",
|
|
38
|
+
"@native-sdk/cli-linux-arm64-musl": "0.5.1",
|
|
39
|
+
"@native-sdk/cli-linux-x64-gnu": "0.5.1",
|
|
40
|
+
"@native-sdk/cli-linux-x64-musl": "0.5.1",
|
|
41
|
+
"@native-sdk/cli-win32-arm64": "0.5.1",
|
|
42
|
+
"@native-sdk/cli-win32-x64": "0.5.1"
|
|
39
43
|
},
|
|
40
44
|
"repository": {
|
|
41
45
|
"type": "git",
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@native-sdk/core",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@native-sdk/core",
|
|
9
|
-
"version": "0.5.
|
|
9
|
+
"version": "0.5.1",
|
|
10
10
|
"devDependencies": {
|
|
11
|
-
"@typescript/
|
|
11
|
+
"@typescript/old": "npm:typescript@6.0.3",
|
|
12
|
+
"@typescript/typescript6": "6.0.2"
|
|
12
13
|
}
|
|
13
14
|
},
|
|
14
15
|
"node_modules/@typescript/old": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@native-sdk/core",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "The TypeScript authoring tier: the app-core subset, its dev-time transpiler to arena-backed Zig, and the SDK module cores import",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"gate": "node scripts/gate.mjs"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@typescript/
|
|
35
|
+
"@typescript/old": "npm:typescript@6.0.3",
|
|
36
|
+
"@typescript/typescript6": "6.0.2"
|
|
36
37
|
}
|
|
37
38
|
}
|
|
@@ -13,7 +13,17 @@
|
|
|
13
13
|
// - Every TYPE question goes through the named queries on `TypedAst` below.
|
|
14
14
|
// Checker/emitter code never touches `program.getTypeChecker()` directly.
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
// The IMPORT deliberately bypasses the `@typescript/typescript6` wrapper
|
|
17
|
+
// (which stays the declared dependency — it is the provider named above,
|
|
18
|
+
// and its own dependency IS this alias): the wrapper's lib/typescript.js
|
|
19
|
+
// re-exports "@typescript/old" resolved from the WRAPPER's location, so a
|
|
20
|
+
// consumer tree already carrying a conflicting hoisted @typescript/old
|
|
21
|
+
// would win node's nearest-wins walk there while our exactly pinned copy
|
|
22
|
+
// sat nested and unused. Importing the alias directly resolves it from
|
|
23
|
+
// THIS file — inside our package, where our own nested/hoisted exact pin
|
|
24
|
+
// is always the nearest — and the CLI's resolution gate additionally
|
|
25
|
+
// verifies the resolved version against the pin.
|
|
26
|
+
import tsImpl from "@typescript/old";
|
|
17
27
|
import path from "node:path";
|
|
18
28
|
import { fileURLToPath } from "node:url";
|
|
19
29
|
|
|
@@ -4480,6 +4480,23 @@ static bool windowsAppsUseDarkTheme() {
|
|
|
4480
4480
|
return dark;
|
|
4481
4481
|
}
|
|
4482
4482
|
|
|
4483
|
+
/* Standard-chrome titlebars follow the OS app color scheme: the
|
|
4484
|
+
* immersive-dark attribute flips the DWM caption to its dark palette,
|
|
4485
|
+
* so an app rendering the dark theme (apps follow the OS scheme through
|
|
4486
|
+
* the appearance channel by default) does not sit under a glaring white
|
|
4487
|
+
* titlebar. Hidden-titlebar windows own their caption fidelity already
|
|
4488
|
+
* (syncHiddenCaptionColor samples the presented header pixels — a
|
|
4489
|
+
* strictly better signal), and chromeless windows have no caption at
|
|
4490
|
+
* all, so both stay out of this. Older builds reject the attribute and
|
|
4491
|
+
* keep the system default. */
|
|
4492
|
+
static void applyStandardTitlebarColorScheme(Window &window) {
|
|
4493
|
+
if (!window.hwnd || windowUsesHiddenTitlebar(window) || windowIsChromeless(window)) return;
|
|
4494
|
+
const DwmApi &dwm = dwmApi();
|
|
4495
|
+
if (!dwm.set_window_attribute) return;
|
|
4496
|
+
const BOOL dark = windowsAppsUseDarkTheme() ? TRUE : FALSE;
|
|
4497
|
+
dwm.set_window_attribute(window.hwnd, kDwmwaUseImmersiveDarkMode, &dark, sizeof(dark));
|
|
4498
|
+
}
|
|
4499
|
+
|
|
4483
4500
|
/* Appearance from OS settings: the apps dark preference, disabled
|
|
4484
4501
|
* client-area animations as the reduce-motion signal, and the high
|
|
4485
4502
|
* contrast accessibility flag. Emitted once after START and again
|
|
@@ -4500,6 +4517,10 @@ static void emitAppearanceIfChanged(Host *host, bool force) {
|
|
|
4500
4517
|
host->appearance_color_scheme = dark;
|
|
4501
4518
|
host->appearance_reduce_motion = reduce_motion;
|
|
4502
4519
|
host->appearance_high_contrast = high_contrast;
|
|
4520
|
+
/* Standard-chrome captions track the scheme live: flipping the OS
|
|
4521
|
+
* theme flips the titlebar with the appearance event the app
|
|
4522
|
+
* re-themes from. */
|
|
4523
|
+
for (auto &entry : host->windows) applyStandardTitlebarColorScheme(entry.second);
|
|
4503
4524
|
WindowsEvent event = {};
|
|
4504
4525
|
event.kind = kAppearance;
|
|
4505
4526
|
event.color_scheme = dark;
|
|
@@ -4967,6 +4988,9 @@ static bool createNativeWindow(Host *host, Window &window) {
|
|
|
4967
4988
|
DragAcceptFiles(hwnd, TRUE);
|
|
4968
4989
|
window.hwnd = hwnd;
|
|
4969
4990
|
applyMenusToWindow(host, window);
|
|
4991
|
+
/* Before the first show, so a dark-scheme launch never flashes a
|
|
4992
|
+
* light caption. */
|
|
4993
|
+
applyStandardTitlebarColorScheme(window);
|
|
4970
4994
|
if (windowUsesHiddenTitlebar(window)) {
|
|
4971
4995
|
applyHiddenTitlebarFrame(window);
|
|
4972
4996
|
/* The create-time WM_NCCALCSIZE ran before this window was
|
|
@@ -69,11 +69,11 @@ pub const layout_audit_epsilon: f32 = 0.5;
|
|
|
69
69
|
/// call while the line breakers accumulate per-word measures, so an
|
|
70
70
|
/// exact-fit line can land one f32 ulp past its own frame (~1e-3 px) —
|
|
71
71
|
/// runtimes hide that under the pixel-snap wrap budget (`textWrapMaxWidth`
|
|
72
|
-
/// hands back
|
|
73
|
-
/// eighth of a point: far above accumulated float
|
|
74
|
-
/// smallest real overflow (a glyph) and below the
|
|
75
|
-
/// budget (
|
|
76
|
-
/// clean and genuine wraps still report.
|
|
72
|
+
/// hands back the full snap quantum, 1/scale). The audit widens its
|
|
73
|
+
/// simulated wrap by an eighth of a point: far above accumulated float
|
|
74
|
+
/// noise, below the smallest real overflow (a glyph) and below the
|
|
75
|
+
/// smallest runtime snap budget (1/scale at any real scale factor), so
|
|
76
|
+
/// exact-fit text stays clean and genuine wraps still report.
|
|
77
77
|
pub const layout_audit_wrap_slack: f32 = 0.125;
|
|
78
78
|
|
|
79
79
|
/// Findings reported per audit pass. A view with more than this many
|
|
@@ -695,6 +695,11 @@ pub const disclosureSettledOpen = @import("widget_tree.zig").disclosureSettledOp
|
|
|
695
695
|
pub const disclosureContentBottom = @import("widget_tree.zig").disclosureContentBottom;
|
|
696
696
|
pub const isWidgetConcealedByDisclosure = @import("widget_tree.zig").isWidgetConcealedByDisclosure;
|
|
697
697
|
pub const anchoredWidgetFrame = @import("widget_layout.zig").anchoredWidgetFrame;
|
|
698
|
+
/// Window-control reservation trigger (widget_layout.zig): true when a
|
|
699
|
+
/// laid-out tree left drag-header CONTENT under the OS window-control
|
|
700
|
+
/// cluster, so runtimes know to stamp `DesignTokens.window_controls`
|
|
701
|
+
/// and re-lay the view clear of it.
|
|
702
|
+
pub const windowDragContentUnderWindowControls = @import("widget_layout.zig").windowDragContentUnderWindowControls;
|
|
698
703
|
/// Split-pane geometry (widget_layout.zig): divider band width, the
|
|
699
704
|
/// fraction clamp band from the panes' min widths, and the in-place
|
|
700
705
|
/// subtree re-layout the runtime reconcile uses when it restores a
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const std = @import("std");
|
|
2
|
+
const geometry = @import("geometry");
|
|
2
3
|
const canvas = @import("root.zig");
|
|
3
4
|
const text_metrics = @import("text_metrics.zig");
|
|
4
5
|
const geist_theme = @import("themes/geist.zig");
|
|
@@ -1521,6 +1522,20 @@ pub const DesignTokens = struct {
|
|
|
1521
1522
|
/// actually draws. Not themed and not part of overrides: the runtime
|
|
1522
1523
|
/// stamps it after theme resolution.
|
|
1523
1524
|
text_measure: ?*const text_metrics.TextMeasureProvider = null,
|
|
1525
|
+
/// The OS window-control cluster's frame in the canvas's local
|
|
1526
|
+
/// coordinates (Windows: the DWM min/max/close buttons on the
|
|
1527
|
+
/// trailing edge; macOS: the traffic lights on the leading edge),
|
|
1528
|
+
/// for hidden-titlebar windows whose content extends under the
|
|
1529
|
+
/// band. Null (the default) lays out exactly as before. The runtime
|
|
1530
|
+
/// stamps it — like `text_measure`, never themed and not part of
|
|
1531
|
+
/// overrides — and only after a build proved the app's own drag
|
|
1532
|
+
/// header left content UNDER the cluster (an app that already pads
|
|
1533
|
+
/// via the chrome channel's insets keeps its byte-identical
|
|
1534
|
+
/// layout). `window_drag` widgets then lay their content out clear
|
|
1535
|
+
/// of the cluster (`widget_layout.windowControlsClearedContent`),
|
|
1536
|
+
/// so a header that never consumed the chrome insets still keeps
|
|
1537
|
+
/// its trailing status text out from under the caption buttons.
|
|
1538
|
+
window_controls: ?geometry.RectF = null,
|
|
1524
1539
|
|
|
1525
1540
|
pub fn theme(options: ThemeOptions) DesignTokens {
|
|
1526
1541
|
// The pack resolves the register (palette, control tables, and
|