@native-sdk/cli 0.4.4 → 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.
Files changed (94) hide show
  1. package/build/app.zig +371 -5
  2. package/build/ts_run.mjs +102 -0
  3. package/build.zig +255 -1
  4. package/build.zig.zon +1 -0
  5. package/package.json +19 -10
  6. package/packages/core/package-lock.json +44 -0
  7. package/packages/core/package.json +38 -0
  8. package/packages/core/rt/rt.zig +1579 -0
  9. package/packages/core/sdk/bytes_text_methods.d.ts +88 -0
  10. package/packages/core/sdk/core.ts +694 -0
  11. package/packages/core/sdk/events.ts +137 -0
  12. package/packages/core/sdk/text.ts +519 -0
  13. package/packages/core/src/checker.ts +1869 -0
  14. package/packages/core/src/cli.ts +68 -0
  15. package/packages/core/src/devhost.ts +291 -0
  16. package/packages/core/src/devhost_resolver.mjs +22 -0
  17. package/packages/core/src/diagnostics.ts +417 -0
  18. package/packages/core/src/emitter.ts +8815 -0
  19. package/packages/core/src/infer.ts +1515 -0
  20. package/packages/core/src/modules.ts +173 -0
  21. package/packages/core/src/ownership.ts +740 -0
  22. package/packages/core/src/text_polyfill.ts +337 -0
  23. package/packages/core/src/text_tables.ts +408 -0
  24. package/packages/core/src/transpile.ts +146 -0
  25. package/packages/core/src/typed_ast.ts +546 -0
  26. package/packages/core/src/types.ts +815 -0
  27. package/skill-data/native-ui/SKILL.md +14 -0
  28. package/skill-data/ts-core/SKILL.md +493 -0
  29. package/skill-data/zig/SKILL.md +10 -0
  30. package/src/app_runner/root.zig +24 -0
  31. package/src/app_runner/ts_core_main.zig +231 -0
  32. package/src/platform/windows/webview2_host.cpp +24 -0
  33. package/src/primitives/app_manifest/comptime_scene.zig +341 -0
  34. package/src/primitives/app_manifest/root.zig +5 -0
  35. package/src/primitives/canvas/commands.zig +14 -7
  36. package/src/primitives/canvas/layout_audit.zig +5 -5
  37. package/src/primitives/canvas/lazy_tls.zig +73 -0
  38. package/src/primitives/canvas/render_generic_resources.zig +22 -15
  39. package/src/primitives/canvas/root.zig +11 -0
  40. package/src/primitives/canvas/tests.zig +1 -0
  41. package/src/primitives/canvas/text_atlas.zig +40 -32
  42. package/src/primitives/canvas/text_layout_cache.zig +29 -22
  43. package/src/primitives/canvas/text_measure_cache.zig +56 -41
  44. package/src/primitives/canvas/text_spans.zig +39 -26
  45. package/src/primitives/canvas/tokens.zig +69 -0
  46. package/src/primitives/canvas/ui.zig +125 -0
  47. package/src/primitives/canvas/ui_markup.zig +22 -3
  48. package/src/primitives/canvas/ui_markup_compiled.zig +97 -7
  49. package/src/primitives/canvas/ui_markup_compiled_tests.zig +275 -0
  50. package/src/primitives/canvas/ui_markup_contract.zig +68 -14
  51. package/src/primitives/canvas/ui_markup_contract_tests.zig +257 -2
  52. package/src/primitives/canvas/ui_markup_reflect.zig +214 -0
  53. package/src/primitives/canvas/ui_markup_view.zig +105 -1
  54. package/src/primitives/canvas/ui_markup_view_tests.zig +336 -0
  55. package/src/primitives/canvas/ui_schema.zig +8 -0
  56. package/src/primitives/canvas/ui_schema_tests.zig +5 -4
  57. package/src/primitives/canvas/widget_builtin_tests.zig +309 -5
  58. package/src/primitives/canvas/widget_invalidation.zig +14 -7
  59. package/src/primitives/canvas/widget_layout.zig +138 -2
  60. package/src/primitives/canvas/widget_metrics.zig +16 -8
  61. package/src/primitives/canvas/widget_render.zig +25 -15
  62. package/src/primitives/canvas/widget_render_controls.zig +15 -9
  63. package/src/primitives/canvas/widget_runtime_tests.zig +44 -0
  64. package/src/root.zig +7 -0
  65. package/src/runtime/canvas_frame.zig +57 -36
  66. package/src/runtime/canvas_images.zig +9 -3
  67. package/src/runtime/canvas_widget_control_tests.zig +5 -6
  68. package/src/runtime/canvas_widget_runtime.zig +7 -4
  69. package/src/runtime/core.zig +16 -0
  70. package/src/runtime/effects.zig +1525 -133
  71. package/src/runtime/effects_fetch_tests.zig +42 -0
  72. package/src/runtime/effects_file_tests.zig +220 -0
  73. package/src/runtime/effects_host_tests.zig +594 -0
  74. package/src/runtime/effects_tests.zig +287 -0
  75. package/src/runtime/root.zig +18 -0
  76. package/src/runtime/session_replay.zig +7 -1
  77. package/src/runtime/tests.zig +2 -0
  78. package/src/runtime/ts_core_host.zig +1505 -0
  79. package/src/runtime/ts_core_host_tests.zig +1408 -0
  80. package/src/runtime/ts_ui_app.zig +469 -0
  81. package/src/runtime/ui_app.zig +189 -38
  82. package/src/runtime/ui_app_tests.zig +221 -0
  83. package/src/runtime/ui_app_window_tests.zig +182 -0
  84. package/src/runtime/view_canvas.zig +24 -17
  85. package/src/runtime/view_widget_tree.zig +2 -2
  86. package/src/tooling/codesign.zig +212 -105
  87. package/src/tooling/doctor.zig +78 -0
  88. package/src/tooling/manifest.zig +47 -0
  89. package/src/tooling/package.zig +435 -20
  90. package/src/tooling/raw_manifest.zig +15 -0
  91. package/src/tooling/root.zig +1 -0
  92. package/src/tooling/templates.zig +777 -34
  93. package/src/tooling/ts_core.zig +1099 -0
  94. package/src/tooling/verbs.zig +105 -2
@@ -11,6 +11,7 @@
11
11
 
12
12
  const std = @import("std");
13
13
  const buildgraph = @import("buildgraph.zig");
14
+ const ts_core = @import("ts_core.zig");
14
15
  const toolchain = @import("toolchain.zig");
15
16
  const manifest_tool = @import("manifest.zig");
16
17
  const dev_tool = @import("dev.zig");
@@ -50,6 +51,27 @@ pub fn run(allocator: std.mem.Allocator, io: std.Io, verb: Verb, options: Option
50
51
  }
51
52
  const metadata = try manifest_tool.readMetadata(allocator, io, "app.zon");
52
53
 
54
+ // Tree detection happens here too (the build graph re-derives it), so
55
+ // a both-cores tree fails with one clean teaching message before any
56
+ // zig invocation.
57
+ const core_tree = ts_core.detect(io);
58
+ if (core_tree == .both) return ts_core.failBothCores();
59
+ if (core_tree == .ts) {
60
+ // Keep the app's editor surface fresh (node_modules/@native-sdk/core,
61
+ // the pre-publish copy stock tsc resolves): best-effort by design —
62
+ // build truth never depends on it, so an unresolvable framework here
63
+ // is not this verb's failure (the graph below reports its own).
64
+ if (buildgraph.resolveFrameworkRoot(allocator, io, options.base_env) catch null) |framework_root| {
65
+ defer allocator.free(framework_root);
66
+ ts_core.selfHealEditorPackage(allocator, io, framework_root);
67
+ // The build graph runs the transpiler inside `zig build`; gate
68
+ // its toolchain resolution before any zig spawns — but ONLY
69
+ // for graphs the CLI itself generates (see the preflight's own
70
+ // doc for why ejected apps must flow past it).
71
+ try tsToolchainPreflight(allocator, io, ".", framework_root);
72
+ }
73
+ }
74
+
53
75
  const zig_exe = try toolchain.resolveZig(allocator, io, options.base_env, .{ .assume_yes = options.assume_yes });
54
76
  defer allocator.free(zig_exe);
55
77
 
@@ -57,7 +79,7 @@ pub fn run(allocator: std.mem.Allocator, io: std.Io, verb: Verb, options: Option
57
79
  defer argv.deinit(allocator);
58
80
  try argv.appendSlice(allocator, &.{ zig_exe, "build" });
59
81
 
60
- const ejected = buildgraph.fileExists(io, "build.zig");
82
+ const ejected = isEjectedAt(io, ".");
61
83
  var build_file: ?[]const u8 = null;
62
84
  defer if (build_file) |path| allocator.free(path);
63
85
  var prefix: ?[]const u8 = null;
@@ -106,7 +128,7 @@ pub fn run(allocator: std.mem.Allocator, io: std.Io, verb: Verb, options: Option
106
128
  .build => {
107
129
  if (!hasOptimizeFlag(options.forwarded_args)) {
108
130
  // Both build shapes register -Doptimize (addApp and the
109
- // expanded template's standardOptimizeOption).
131
+ // expanded template each b.option it by hand).
110
132
  try argv.append(allocator, "-Doptimize=ReleaseFast");
111
133
  release_fast = true;
112
134
  }
@@ -155,6 +177,33 @@ pub fn run(allocator: std.mem.Allocator, io: std.Io, verb: Verb, options: Option
155
177
  }
156
178
  }
157
179
 
180
+ /// The one generated-vs-ejected decision the verbs make: an app that owns
181
+ /// a build.zig at its root is EJECTED and the verbs drive it through plain
182
+ /// `zig build`; otherwise the CLI synthesizes the graph into .native/build/
183
+ /// (the module doc above). Named so the toolchain preflight and the argv
184
+ /// assembly cannot drift onto different predicates.
185
+ fn isEjectedAt(io: std.Io, app_root: []const u8) bool {
186
+ var buffer: [1024]u8 = undefined;
187
+ const path = std.fmt.bufPrint(&buffer, "{s}/build.zig", .{app_root}) catch return false;
188
+ return buildgraph.fileExists(io, path);
189
+ }
190
+
191
+ /// The pre-spawn TS toolchain gate, scoped to graphs the CLI generates.
192
+ /// Generated graphs wire `framework_root` — the CLI's own SDK — as the
193
+ /// app's dependency, so an unresolvable toolchain there fails HERE with
194
+ /// the CLI's teaching (the checkout's one `npm ci --include=dev`, or the
195
+ /// reinstall on an npm layout) instead of a configure-time error inside
196
+ /// the graph. npm-installed CLIs always resolve — the toolchain ships as
197
+ /// a CLI dependency. EJECTED apps own their build.zig.zon and may pin a
198
+ /// DIFFERENT SDK checkout than the CLI resolves, so gating the CLI's SDK
199
+ /// would false-fail a healthy app (direct `zig build` works); they flow
200
+ /// straight to the zig spawn, where build/app.zig's tsCoreStage safety
201
+ /// net teaches against the app's ACTUAL dependency SDK.
202
+ fn tsToolchainPreflight(allocator: std.mem.Allocator, io: std.Io, app_root: []const u8, framework_root: []const u8) !void {
203
+ if (isEjectedAt(io, app_root)) return;
204
+ try ts_core.ensureResolvedTranspiler(allocator, io, framework_root);
205
+ }
206
+
158
207
  fn hasOptimizeFlag(args: []const []const u8) bool {
159
208
  for (args) |arg| {
160
209
  if (std.mem.startsWith(u8, arg, "-Doptimize")) return true;
@@ -201,6 +250,60 @@ fn runZig(io: std.Io, verb: Verb, argv: []const []const u8) !void {
201
250
  return error.ZigBuildFailed;
202
251
  }
203
252
 
253
+ test "toolchain preflight: ejected TS apps skip the CLI-SDK gate, generated ones keep it" {
254
+ const allocator = std.testing.allocator;
255
+ const io = std.testing.io;
256
+ var cwd = std.Io.Dir.cwd();
257
+ const root = ".zig-cache/test-verbs-ts-preflight";
258
+ const sdk = root ++ "/sdk-checkout";
259
+ const ejected_app = root ++ "/ejected-app";
260
+ const generated_app = root ++ "/generated-app";
261
+ cwd.deleteTree(io, root) catch {};
262
+ defer cwd.deleteTree(io, root) catch {};
263
+
264
+ // A CLI framework root whose toolchain is ABSENT: packages/core/test
265
+ // marks the checkout layout, and no node_modules ever lands — the gate
266
+ // teaches `npm ci --include=dev` whenever it actually runs. The pin
267
+ // manifest rides along: the gate reads its exact compiler pin from
268
+ // packages/core/package.json, which every real layout carries.
269
+ try cwd.createDirPath(io, sdk ++ "/packages/core/test");
270
+ try cwd.writeFile(io, .{ .sub_path = sdk ++ "/packages/core/package.json", .data = "{ \"name\": \"@native-sdk/core\", \"version\": \"0.0.9\", \"devDependencies\": { \"@typescript/old\": \"npm:typescript@9.9.9\" } }" });
271
+
272
+ // The ejected-shaped TS layout: an app-owned build.zig (+ build.zig.zon)
273
+ // at the root, src/core.ts present. Its zon may pin a DIFFERENT SDK
274
+ // than the CLI's, so the preflight must NOT fail on the CLI SDK's
275
+ // missing toolchain — the verb reaches the spawn decision, where
276
+ // build/app.zig's in-graph teaching names the app's actual dependency.
277
+ try cwd.createDirPath(io, ejected_app ++ "/src");
278
+ try cwd.writeFile(io, .{ .sub_path = ejected_app ++ "/build.zig", .data = "// app-owned graph" });
279
+ try cwd.writeFile(io, .{ .sub_path = ejected_app ++ "/build.zig.zon", .data = ".{ .dependencies = .{ .native_sdk = .{ .path = \"../elsewhere\" } } }" });
280
+ try cwd.writeFile(io, .{ .sub_path = ejected_app ++ "/src/core.ts", .data = "// ts core" });
281
+ try std.testing.expectEqual(ts_core.CoreTree.ts, ts_core.detectAt(io, ejected_app));
282
+ try std.testing.expect(isEjectedAt(io, ejected_app));
283
+ try tsToolchainPreflight(allocator, io, ejected_app, sdk);
284
+
285
+ // The generated-shaped layout (no build.zig: the CLI synthesizes the
286
+ // graph against ITS OWN SDK) keeps the friendly pre-spawn gate: the
287
+ // absent toolchain still teaches before any zig spawn.
288
+ try cwd.createDirPath(io, generated_app ++ "/src");
289
+ try cwd.writeFile(io, .{ .sub_path = generated_app ++ "/src/core.ts", .data = "// ts core" });
290
+ try std.testing.expect(!isEjectedAt(io, generated_app));
291
+ try std.testing.expectError(error.MissingTranspiler, tsToolchainPreflight(allocator, io, generated_app, sdk));
292
+
293
+ // And a resolvable CLI SDK passes the generated gate silently: land the
294
+ // wrapper AND the aliased real compiler it re-exports, as npm does —
295
+ // the compiler at the version the staged pin manifest names.
296
+ const toolchain_manifest = "{ \"name\": \"@typescript/typescript6\", \"version\": \"0.0.2\", \"main\": \"./lib/typescript.js\" }";
297
+ const compiler_manifest = "{ \"name\": \"typescript\", \"version\": \"9.9.9\", \"main\": \"./lib/typescript.js\" }";
298
+ try cwd.createDirPath(io, sdk ++ "/packages/core/node_modules/@typescript/typescript6/lib");
299
+ try cwd.writeFile(io, .{ .sub_path = sdk ++ "/packages/core/node_modules/@typescript/typescript6/package.json", .data = toolchain_manifest });
300
+ try cwd.writeFile(io, .{ .sub_path = sdk ++ "/packages/core/node_modules/@typescript/typescript6/lib/typescript.js", .data = "// fake wrapper" });
301
+ try cwd.createDirPath(io, sdk ++ "/packages/core/node_modules/@typescript/old/lib");
302
+ try cwd.writeFile(io, .{ .sub_path = sdk ++ "/packages/core/node_modules/@typescript/old/package.json", .data = compiler_manifest });
303
+ try cwd.writeFile(io, .{ .sub_path = sdk ++ "/packages/core/node_modules/@typescript/old/lib/typescript.js", .data = "// fake compiler" });
304
+ try tsToolchainPreflight(allocator, io, generated_app, sdk);
305
+ }
306
+
204
307
  test "optimize flags are detected among forwarded args" {
205
308
  try std.testing.expect(hasOptimizeFlag(&.{"-Doptimize=Debug"}));
206
309
  try std.testing.expect(hasOptimizeFlag(&.{ "-Dautomation=true", "--release=safe" }));