@native-sdk/cli 0.9.4 → 0.10.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/README.md +3 -3
- package/build/app.zig +75 -57
- package/build/ts_run.mjs +1 -1
- package/build.zig +20 -2
- package/package.json +11 -10
- package/packages/core/package-lock.json +12 -11
- package/packages/core/package.json +2 -2
- package/packages/core/scripts/compiler_command.mjs +1 -1
- package/packages/core/scripts/run_external_core_compiler.mjs +19 -9
- package/packages/core/scripts/run_external_service_compiler.mjs +17 -8
- package/packages/core/scripts/vendor_service_packages.mjs +121 -8
- package/packages/core/sdk/events.d.ts +33 -4
- package/packages/core/sdk/events.ts +45 -6
- package/packages/core/src/checker.ts +103 -8
- package/packages/core/src/modules.ts +6 -2
- package/packages/core/src/sqlite_cli.ts +22 -2
- package/packages/core/src/typed_ast.ts +4 -2
- package/packages/core/src/types.ts +8 -8
- package/schemas/app.schema.json +446 -0
- package/skill-data/core/SKILL.md +53 -15
- package/skill-data/core/references/project-anatomy.md +6 -6
- package/skill-data/native-ui/SKILL.md +26 -5
- package/skill-data/ts-core/SKILL.md +6 -6
- package/skill-data/ts-services/references/service-surface.md +1 -1
- package/skills/native-sdk/SKILL.md +2 -2
- package/src/app_runner/root.zig +25 -0
- package/src/automation/snapshot.zig +91 -3
- package/src/platform/macos/appkit_host.h +66 -2
- package/src/platform/macos/appkit_host.m +735 -24
- package/src/platform/macos/cef_host.mm +208 -9
- package/src/platform/macos/root.zig +205 -3
- package/src/platform/null_platform.zig +50 -1
- package/src/platform/null_platform_tests.zig +53 -0
- package/src/platform/root.zig +12 -0
- package/src/platform/types.zig +73 -0
- package/src/platform/windows/root.zig +88 -15
- package/src/primitives/app_manifest/tests.zig +19 -0
- package/src/primitives/app_manifest/validation.zig +14 -2
- package/src/primitives/canvas/font_ttf.zig +24 -0
- package/src/primitives/canvas/gpu.zig +5 -0
- package/src/primitives/canvas/reference.zig +41 -16
- package/src/primitives/canvas/reference_tests.zig +63 -0
- package/src/primitives/canvas/render_tests.zig +1 -1
- package/src/primitives/canvas/root.zig +1 -0
- package/src/primitives/canvas/serialization.zig +1 -0
- package/src/primitives/canvas/test_support.zig +1 -0
- package/src/primitives/canvas/text.zig +1 -0
- package/src/primitives/canvas/text_layout.zig +84 -15
- package/src/primitives/canvas/text_layout_hash.zig +3 -1
- package/src/primitives/canvas/text_layout_types.zig +3 -0
- package/src/primitives/canvas/text_metrics.zig +28 -1
- package/src/primitives/canvas/text_tests.zig +61 -6
- package/src/primitives/canvas/ui.zig +9 -0
- package/src/primitives/canvas/ui_markup.zig +29 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +32 -0
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +4 -2
- package/src/primitives/canvas/ui_markup_contract.zig +7 -0
- package/src/primitives/canvas/ui_markup_contract_tests.zig +21 -0
- package/src/primitives/canvas/ui_markup_tests.zig +6 -0
- package/src/primitives/canvas/ui_markup_view.zig +28 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +32 -3
- package/src/primitives/canvas/ui_schema.zig +9 -0
- package/src/primitives/canvas/ui_schema_tests.zig +5 -3
- package/src/primitives/canvas/ui_tests.zig +4 -2
- package/src/primitives/canvas/widget_render.zig +13 -2
- package/src/primitives/canvas/widget_render_controls.zig +1 -0
- package/src/primitives/canvas/widget_semantics_tests.zig +3 -1
- package/src/root.zig +6 -0
- package/src/runtime/automation_snapshot.zig +3 -0
- package/src/runtime/canvas_fonts.zig +87 -0
- package/src/runtime/core.zig +1 -0
- package/src/runtime/flow.zig +8 -1
- package/src/runtime/native_command_event_tests.zig +58 -0
- package/src/runtime/state.zig +14 -0
- package/src/runtime/system_services.zig +62 -0
- package/src/runtime/ts_ui_app.zig +161 -33
- package/src/runtime/ui_app.zig +33 -1
- package/src/runtime/ui_app_tests.zig +63 -0
- package/src/runtime/validation.zig +87 -1
- package/src/tooling/android.zig +5 -4
- package/src/tooling/buildgraph.zig +24 -8
- package/src/tooling/db.zig +1 -1
- package/src/tooling/doctor.zig +1 -1
- package/src/tooling/ios.zig +5 -4
- package/src/tooling/json_to_zon.zig +136 -0
- package/src/tooling/manifest.zig +199 -35
- package/src/tooling/package.zig +33 -0
- package/src/tooling/raw_manifest.zig +11 -0
- package/src/tooling/root.zig +2 -0
- package/src/tooling/templates.zig +210 -116
- package/src/tooling/ts_core.zig +11 -7
- package/src/tooling/update.zig +576 -0
- package/src/tooling/verbs.zig +7 -6
- package/src/tooling/web_engine.zig +17 -1
- package/src/updater/c_api.zig +123 -0
- package/src/updater/feed.zig +215 -0
- package/src/updater/root.zig +10 -0
package/src/tooling/manifest.zig
CHANGED
|
@@ -2,6 +2,7 @@ const std = @import("std");
|
|
|
2
2
|
const app_icon_tool = @import("app_icon");
|
|
3
3
|
const app_manifest = @import("app_manifest");
|
|
4
4
|
const diagnostics = @import("diagnostics");
|
|
5
|
+
const json_to_zon = @import("json_to_zon.zig");
|
|
5
6
|
const raw_manifest = @import("raw_manifest.zig");
|
|
6
7
|
const web_engine_tool = @import("web_engine.zig");
|
|
7
8
|
|
|
@@ -62,6 +63,7 @@ pub const Metadata = struct {
|
|
|
62
63
|
shortcuts: []const ShortcutMetadata = &.{},
|
|
63
64
|
file_associations: []const FileAssociationMetadata = &.{},
|
|
64
65
|
url_schemes: []const UrlSchemeMetadata = &.{},
|
|
66
|
+
updates: UpdateMetadata = .{},
|
|
65
67
|
dmg: DmgMetadata = .{},
|
|
66
68
|
|
|
67
69
|
pub fn displayName(self: Metadata) []const u8 {
|
|
@@ -208,6 +210,8 @@ pub const Metadata = struct {
|
|
|
208
210
|
allocator.free(scheme.role);
|
|
209
211
|
}
|
|
210
212
|
if (self.url_schemes.len > 0) allocator.free(self.url_schemes);
|
|
213
|
+
if (self.updates.feed_url) |value| allocator.free(value);
|
|
214
|
+
if (self.updates.public_key) |value| allocator.free(value);
|
|
211
215
|
if (self.dmg.volume_name) |value| allocator.free(value);
|
|
212
216
|
if (self.dmg.background) |value| allocator.free(value);
|
|
213
217
|
for (self.dmg.items) |item| {
|
|
@@ -415,6 +419,16 @@ pub const DmgMetadata = struct {
|
|
|
415
419
|
items: []const DmgItemMetadata = &.{},
|
|
416
420
|
};
|
|
417
421
|
|
|
422
|
+
pub const UpdateMetadata = struct {
|
|
423
|
+
feed_url: ?[]const u8 = null,
|
|
424
|
+
public_key: ?[]const u8 = null,
|
|
425
|
+
check_on_start: bool = false,
|
|
426
|
+
|
|
427
|
+
pub fn enabled(self: UpdateMetadata) bool {
|
|
428
|
+
return self.feed_url != null;
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
|
|
418
432
|
pub const FrontendDevMetadata = struct {
|
|
419
433
|
url: []const u8,
|
|
420
434
|
command: []const []const u8 = &.{},
|
|
@@ -461,107 +475,135 @@ const RawMenuItem = raw_manifest.RawMenuItem;
|
|
|
461
475
|
const RawShortcut = raw_manifest.RawShortcut;
|
|
462
476
|
const RawFileAssociation = raw_manifest.RawFileAssociation;
|
|
463
477
|
const RawUrlScheme = raw_manifest.RawUrlScheme;
|
|
478
|
+
const RawUpdates = raw_manifest.RawUpdates;
|
|
464
479
|
const RawDmg = raw_manifest.RawDmg;
|
|
465
480
|
const RawDmgItem = raw_manifest.RawDmgItem;
|
|
466
481
|
|
|
482
|
+
pub const json_name = "app.json";
|
|
483
|
+
pub const zon_name = "app.zon";
|
|
484
|
+
|
|
485
|
+
/// Resolve the conventional manifest in the current app directory. JSON is
|
|
486
|
+
/// the authoring default; app.zon remains a fully supported fallback. When a
|
|
487
|
+
/// project temporarily contains both (for example while migrating), app.json
|
|
488
|
+
/// is authoritative so every CLI boundary makes the same choice.
|
|
489
|
+
pub fn defaultPath(io: std.Io) ?[]const u8 {
|
|
490
|
+
if (pathExists(io, json_name)) return json_name;
|
|
491
|
+
if (pathExists(io, zon_name)) return zon_name;
|
|
492
|
+
return null;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
fn pathExists(io: std.Io, path: []const u8) bool {
|
|
496
|
+
const stat = std.Io.Dir.cwd().statFile(io, path, .{}) catch return false;
|
|
497
|
+
return stat.kind == .file;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
pub fn isJsonPath(path: []const u8) bool {
|
|
501
|
+
return json_to_zon.isJsonPath(path);
|
|
502
|
+
}
|
|
503
|
+
|
|
467
504
|
pub fn validateFile(allocator: std.mem.Allocator, io: std.Io, path: []const u8) !ValidationResult {
|
|
468
505
|
const source = try readFile(allocator, io, path);
|
|
469
506
|
defer allocator.free(source);
|
|
470
507
|
|
|
471
|
-
const metadata =
|
|
508
|
+
const metadata = parseTextForPath(allocator, path, source) catch |err| return .{
|
|
472
509
|
.ok = false,
|
|
473
|
-
.message =
|
|
510
|
+
.message = parseFailureMessage(allocator, path, source, err),
|
|
474
511
|
};
|
|
475
512
|
defer metadata.deinit(allocator);
|
|
476
513
|
|
|
477
514
|
if (metadata.description) |description| {
|
|
478
515
|
app_manifest.validateDescription(description) catch return .{
|
|
479
516
|
.ok = false,
|
|
480
|
-
.message = "app
|
|
517
|
+
.message = "app manifest description is invalid - it must be one non-empty line of at most 256 bytes with no control characters (it becomes the About panel credits line)",
|
|
481
518
|
};
|
|
482
519
|
}
|
|
483
520
|
if (metadata.theme) |theme_name| {
|
|
484
521
|
if (!isKnownThemePack(theme_name)) return .{
|
|
485
522
|
.ok = false,
|
|
486
|
-
.message = "app
|
|
523
|
+
.message = "app manifest theme is invalid - expected one of: house, geist",
|
|
487
524
|
};
|
|
488
525
|
}
|
|
489
526
|
if (metadata.theme_accent) |accent| {
|
|
490
527
|
if (!isHexColor(accent)) return .{
|
|
491
528
|
.ok = false,
|
|
492
|
-
.message = "app
|
|
529
|
+
.message = "app manifest theme_accent is invalid - expected a #rrggbb hex color (e.g. \"#df2670\")",
|
|
493
530
|
};
|
|
494
531
|
}
|
|
495
|
-
validateIconPaths(metadata.icons) catch return .{ .ok = false, .message = "app
|
|
532
|
+
validateIconPaths(metadata.icons) catch return .{ .ok = false, .message = "app manifest icons are invalid" };
|
|
496
533
|
if (try checkIconSources(allocator, io, std.fs.path.dirname(path) orelse ".", metadata.icons)) |icon_message| {
|
|
497
534
|
return .{ .ok = false, .message = icon_message };
|
|
498
535
|
}
|
|
499
|
-
const permissions = parsePermissions(allocator, metadata.permissions) catch return .{ .ok = false, .message = "app
|
|
536
|
+
const permissions = parsePermissions(allocator, metadata.permissions) catch return .{ .ok = false, .message = "app manifest permissions are invalid" };
|
|
500
537
|
defer allocator.free(permissions);
|
|
501
|
-
const capabilities = parseCapabilities(allocator, metadata.capabilities) catch return .{ .ok = false, .message = "app
|
|
538
|
+
const capabilities = parseCapabilities(allocator, metadata.capabilities) catch return .{ .ok = false, .message = "app manifest capabilities are invalid" };
|
|
502
539
|
defer allocator.free(capabilities);
|
|
503
540
|
const persist = convertPersist(metadata.persist);
|
|
504
541
|
app_manifest.validateImages(.{ .max_image_pixel_bytes = metadata.images.max_image_pixel_bytes }) catch return .{
|
|
505
542
|
.ok = false,
|
|
506
|
-
.message = "app
|
|
543
|
+
.message = "app manifest images.max_image_pixel_bytes must be between 1048576 (the default) and 8388608 bytes; allocation is lazy once per used slot, up to 16 slots",
|
|
507
544
|
};
|
|
508
545
|
if (!validServicePackages(metadata.service_packages)) return .{
|
|
509
546
|
.ok = false,
|
|
510
|
-
.message = "app
|
|
547
|
+
.message = "app manifest service_packages must use safe npm names, exact X.Y.Z versions, unique names, and lowercase SHA-256 content hashes",
|
|
511
548
|
};
|
|
512
549
|
if (!validServiceCarrier(metadata.service_carrier)) return .{
|
|
513
550
|
.ok = false,
|
|
514
|
-
.message = "app
|
|
551
|
+
.message = "app manifest service_carrier must be \"auto\", \"in_process\", or \"child\"",
|
|
515
552
|
};
|
|
516
553
|
if (metadata.service_pool_size) |pool_size| {
|
|
517
554
|
if (pool_size < 1 or pool_size > 16) return .{
|
|
518
555
|
.ok = false,
|
|
519
|
-
.message = "app
|
|
556
|
+
.message = "app manifest service_pool_size must be between 1 and 16",
|
|
520
557
|
};
|
|
521
558
|
}
|
|
522
|
-
const bridge_commands = parseBridgeCommands(allocator, metadata.bridge_commands) catch return .{ .ok = false, .message = "app
|
|
559
|
+
const bridge_commands = parseBridgeCommands(allocator, metadata.bridge_commands) catch return .{ .ok = false, .message = "app manifest bridge commands are invalid" };
|
|
523
560
|
defer {
|
|
524
561
|
for (bridge_commands) |command| allocator.free(command.permissions);
|
|
525
562
|
allocator.free(bridge_commands);
|
|
526
563
|
}
|
|
527
564
|
const frontend = if (metadata.frontend) |frontend_value| convertFrontend(frontend_value) else null;
|
|
528
|
-
const security = convertSecurity(metadata.security) catch return .{ .ok = false, .message = "app
|
|
529
|
-
const windows = convertWindows(allocator, metadata.windows) catch return .{ .ok = false, .message = "app
|
|
565
|
+
const security = convertSecurity(metadata.security) catch return .{ .ok = false, .message = "app manifest security policy is invalid" };
|
|
566
|
+
const windows = convertWindows(allocator, metadata.windows) catch return .{ .ok = false, .message = "app manifest windows are invalid" };
|
|
530
567
|
defer allocator.free(windows);
|
|
531
|
-
const shell = parseShell(allocator, metadata.shell) catch return .{ .ok = false, .message = "app
|
|
568
|
+
const shell = parseShell(allocator, metadata.shell) catch return .{ .ok = false, .message = "app manifest shell is invalid" };
|
|
532
569
|
defer deinitParsedShell(allocator, shell);
|
|
533
|
-
const commands = parseCommands(allocator, metadata.commands) catch return .{ .ok = false, .message = "app
|
|
570
|
+
const commands = parseCommands(allocator, metadata.commands) catch return .{ .ok = false, .message = "app manifest commands are invalid" };
|
|
534
571
|
defer allocator.free(commands);
|
|
535
|
-
const menus = parseMenus(allocator, metadata.menus) catch return .{ .ok = false, .message = "app
|
|
572
|
+
const menus = parseMenus(allocator, metadata.menus) catch return .{ .ok = false, .message = "app manifest menus are invalid" };
|
|
536
573
|
defer deinitParsedMenus(allocator, menus);
|
|
537
|
-
const shortcuts = parseShortcuts(allocator, metadata.shortcuts) catch return .{ .ok = false, .message = "app
|
|
574
|
+
const shortcuts = parseShortcuts(allocator, metadata.shortcuts) catch return .{ .ok = false, .message = "app manifest shortcuts are invalid" };
|
|
538
575
|
defer allocator.free(shortcuts);
|
|
539
|
-
const file_associations = parseFileAssociations(allocator, metadata.file_associations) catch return .{ .ok = false, .message = "app
|
|
576
|
+
const file_associations = parseFileAssociations(allocator, metadata.file_associations) catch return .{ .ok = false, .message = "app manifest file associations are invalid" };
|
|
540
577
|
defer allocator.free(file_associations);
|
|
541
|
-
const url_schemes = parseUrlSchemes(allocator, metadata.url_schemes) catch return .{ .ok = false, .message = "app
|
|
578
|
+
const url_schemes = parseUrlSchemes(allocator, metadata.url_schemes) catch return .{ .ok = false, .message = "app manifest URL schemes are invalid" };
|
|
542
579
|
defer allocator.free(url_schemes);
|
|
580
|
+
const updates = convertUpdates(metadata.updates) catch return .{ .ok = false, .message = "app manifest updates are invalid - updates require an HTTPS feed_url and a base64 Ed25519 public_key; check_on_start requires both" };
|
|
543
581
|
// General manifest validation owns only values the app explicitly
|
|
544
582
|
// declared. Archive-time fallbacks (notably display_name as the volume
|
|
545
583
|
// name) are validated when a macOS archive is actually requested, so an
|
|
546
584
|
// otherwise valid display name does not make every `native check` fail.
|
|
547
|
-
validateDmgSettings(metadata.dmg) catch return .{ .ok = false, .message = "app
|
|
585
|
+
validateDmgSettings(metadata.dmg) catch return .{ .ok = false, .message = "app manifest dmg settings are invalid - check the volume/bundle names, window/icon geometry, and positions; an explicit items list needs exactly one app and unique safe destination names" };
|
|
548
586
|
if (try checkDmgSources(allocator, io, std.fs.path.dirname(path) orelse ".", metadata.dmg)) |dmg_message| {
|
|
549
587
|
return .{ .ok = false, .message = dmg_message };
|
|
550
588
|
}
|
|
551
|
-
const manifest_web_engine = parseWebEngine(metadata.web_engine) catch return .{ .ok = false, .message = "app
|
|
552
|
-
|
|
589
|
+
const manifest_web_engine = parseWebEngine(metadata.web_engine) catch return .{ .ok = false, .message = "app manifest web engine is invalid" };
|
|
590
|
+
if (metadata.updates.enabled() and manifest_web_engine == .chromium) return .{
|
|
591
|
+
.ok = false,
|
|
592
|
+
.message = "native updates currently require web_engine = \"system\" on macOS; the Chromium host does not yet provide the updater UI/install lifecycle",
|
|
593
|
+
};
|
|
594
|
+
const manifest_webview_layer = parseWebViewLayer(metadata.webview_layer) catch return .{ .ok = false, .message = "app manifest webview_layer is invalid - expected \"auto\", \"include\", or \"exclude\"" };
|
|
553
595
|
if (!std.mem.eql(u8, metadata.core_compiler, "external")) {
|
|
554
596
|
if (std.mem.eql(u8, metadata.core_compiler, "transpiler")) {
|
|
555
|
-
return .{ .ok = false, .message = "app
|
|
597
|
+
return .{ .ok = false, .message = "app manifest core_compiler = \"transpiler\" names the removed TS-to-Zig transpiled lane (v0.7.0 removed it) - TypeScript cores compile through the external core compiler now; delete the setting (or spell it \"external\")" };
|
|
556
598
|
}
|
|
557
|
-
return .{ .ok = false, .message = "app
|
|
599
|
+
return .{ .ok = false, .message = "app manifest core_compiler is invalid - expected \"external\" (the default and only lane)" };
|
|
558
600
|
}
|
|
559
|
-
const platform_settings = parsePlatformSettings(allocator, metadata.platforms) catch return .{ .ok = false, .message = "app
|
|
601
|
+
const platform_settings = parsePlatformSettings(allocator, metadata.platforms) catch return .{ .ok = false, .message = "app manifest platforms are invalid" };
|
|
560
602
|
defer allocator.free(platform_settings);
|
|
561
603
|
|
|
562
604
|
const manifest: app_manifest.Manifest = .{
|
|
563
605
|
.identity = .{ .id = metadata.id, .name = metadata.name, .display_name = metadata.display_name, .description = metadata.description },
|
|
564
|
-
.version = parseVersion(metadata.version) catch return .{ .ok = false, .message = "app
|
|
606
|
+
.version = parseVersion(metadata.version) catch return .{ .ok = false, .message = "app manifest version is invalid" },
|
|
565
607
|
.permissions = permissions,
|
|
566
608
|
.capabilities = capabilities,
|
|
567
609
|
.dock_visible = metadata.dock_visible,
|
|
@@ -578,6 +620,7 @@ pub fn validateFile(allocator: std.mem.Allocator, io: std.Io, path: []const u8)
|
|
|
578
620
|
.shortcuts = shortcuts,
|
|
579
621
|
.file_associations = file_associations,
|
|
580
622
|
.url_schemes = url_schemes,
|
|
623
|
+
.updates = updates,
|
|
581
624
|
.cef = .{ .dir = metadata.cef.dir, .auto_install = metadata.cef.auto_install },
|
|
582
625
|
.webview_layer = manifest_webview_layer,
|
|
583
626
|
.package = .{ .web_engine = manifest_web_engine },
|
|
@@ -585,12 +628,12 @@ pub fn validateFile(allocator: std.mem.Allocator, io: std.Io, path: []const u8)
|
|
|
585
628
|
app_manifest.validateManifest(manifest) catch |err| return .{
|
|
586
629
|
.ok = false,
|
|
587
630
|
.message = switch (err) {
|
|
588
|
-
error.MissingTrayCapability => "app
|
|
631
|
+
error.MissingTrayCapability => "app manifest dock_visible = false requires the \"tray\" capability: an accessory app has no Dock/app-switcher route back to hidden windows - add \"tray\" to capabilities and install a status item, or keep dock_visible = true (the default)",
|
|
589
632
|
error.WebViewLayerConflict => web_layer_conflict_message,
|
|
590
633
|
else => "manifest fields failed semantic validation",
|
|
591
634
|
},
|
|
592
635
|
};
|
|
593
|
-
return .{ .ok = true, .message = "app.zon is valid" };
|
|
636
|
+
return .{ .ok = true, .message = if (isJsonPath(path)) "app.json is valid" else "app.zon is valid" };
|
|
594
637
|
}
|
|
595
638
|
|
|
596
639
|
/// Re-parse a failed manifest with std.zon diagnostics enabled so the
|
|
@@ -616,12 +659,21 @@ fn zonParseFailureMessage(allocator: std.mem.Allocator, source: []const u8) ?[]c
|
|
|
616
659
|
}
|
|
617
660
|
}
|
|
618
661
|
|
|
662
|
+
fn parseFailureMessage(allocator: std.mem.Allocator, path: []const u8, source: []const u8, err: anyerror) []const u8 {
|
|
663
|
+
if (!isJsonPath(path)) return zonParseFailureMessage(allocator, source) orelse "app.zon metadata could not be parsed";
|
|
664
|
+
if (err == error.NullNotAllowed) return "app.json cannot contain null values - omit optional fields instead";
|
|
665
|
+
return std.fmt.allocPrint(allocator, "{s} could not be parsed as a Native SDK manifest ({s})", .{ std.fs.path.basename(path), @errorName(err) }) catch "app.json metadata could not be parsed";
|
|
666
|
+
}
|
|
667
|
+
|
|
619
668
|
pub fn readMetadata(allocator: std.mem.Allocator, io: std.Io, path: []const u8) !Metadata {
|
|
620
669
|
const source = try readFile(allocator, io, path);
|
|
621
670
|
defer allocator.free(source);
|
|
622
|
-
return
|
|
671
|
+
return parseTextForPath(allocator, path, source);
|
|
623
672
|
}
|
|
624
673
|
|
|
674
|
+
/// Parse legacy ZON text. Kept as the focused test/helper API; file-backed
|
|
675
|
+
/// callers use parseTextForPath so app.json and app.zon share one conversion
|
|
676
|
+
/// and semantic-validation pipeline.
|
|
625
677
|
pub fn parseText(allocator: std.mem.Allocator, source: []const u8) !Metadata {
|
|
626
678
|
var arena = std.heap.ArenaAllocator.init(allocator);
|
|
627
679
|
defer arena.deinit();
|
|
@@ -629,6 +681,22 @@ pub fn parseText(allocator: std.mem.Allocator, source: []const u8) !Metadata {
|
|
|
629
681
|
const source_z = try scratch.dupeZ(u8, source);
|
|
630
682
|
@setEvalBranchQuota(4000);
|
|
631
683
|
const raw = try std.zon.parse.fromSliceAlloc(RawManifest, scratch, source_z, null, .{});
|
|
684
|
+
return metadataFromRaw(allocator, raw);
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
pub fn parseJsonText(allocator: std.mem.Allocator, source: []const u8) !Metadata {
|
|
688
|
+
try json_to_zon.validateSource(allocator, source);
|
|
689
|
+
var arena = std.heap.ArenaAllocator.init(allocator);
|
|
690
|
+
defer arena.deinit();
|
|
691
|
+
const raw = try std.json.parseFromSliceLeaky(RawManifest, arena.allocator(), source, .{ .ignore_unknown_fields = false });
|
|
692
|
+
return metadataFromRaw(allocator, raw);
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
pub fn parseTextForPath(allocator: std.mem.Allocator, path: []const u8, source: []const u8) !Metadata {
|
|
696
|
+
return if (isJsonPath(path)) parseJsonText(allocator, source) else parseText(allocator, source);
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
fn metadataFromRaw(allocator: std.mem.Allocator, raw: RawManifest) !Metadata {
|
|
632
700
|
return .{
|
|
633
701
|
.id = try allocator.dupe(u8, raw.id),
|
|
634
702
|
.name = try allocator.dupe(u8, raw.name),
|
|
@@ -664,10 +732,28 @@ pub fn parseText(allocator: std.mem.Allocator, source: []const u8) !Metadata {
|
|
|
664
732
|
.shortcuts = try convertRawShortcuts(allocator, raw.shortcuts),
|
|
665
733
|
.file_associations = try convertRawFileAssociations(allocator, raw.file_associations),
|
|
666
734
|
.url_schemes = try convertRawUrlSchemes(allocator, raw.url_schemes),
|
|
735
|
+
.updates = try duplicateRawUpdates(allocator, raw.updates),
|
|
667
736
|
.dmg = try convertRawDmg(allocator, raw.dmg),
|
|
668
737
|
};
|
|
669
738
|
}
|
|
670
739
|
|
|
740
|
+
fn duplicateRawUpdates(allocator: std.mem.Allocator, raw: RawUpdates) !UpdateMetadata {
|
|
741
|
+
return .{
|
|
742
|
+
.feed_url = try duplicateOptionalString(allocator, raw.feed_url),
|
|
743
|
+
.public_key = try duplicateOptionalString(allocator, raw.public_key),
|
|
744
|
+
.check_on_start = raw.check_on_start,
|
|
745
|
+
};
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
fn convertUpdates(updates: UpdateMetadata) !app_manifest.UpdateConfig {
|
|
749
|
+
if (updates.feed_url == null and updates.public_key == null and !updates.check_on_start) return .{};
|
|
750
|
+
const feed_url = updates.feed_url orelse return error.InvalidUpdates;
|
|
751
|
+
const public_key = updates.public_key orelse return error.InvalidUpdates;
|
|
752
|
+
if (!std.mem.startsWith(u8, feed_url, "https://")) return error.InvalidUpdates;
|
|
753
|
+
if (public_key.len == 0) return error.InvalidUpdates;
|
|
754
|
+
return .{ .feed_url = feed_url, .public_key = public_key, .check_on_start = updates.check_on_start };
|
|
755
|
+
}
|
|
756
|
+
|
|
671
757
|
fn duplicateRawServicePackages(allocator: std.mem.Allocator, packages: []const raw_manifest.RawServicePackage) ![]const ServicePackageMetadata {
|
|
672
758
|
if (packages.len == 0) return &.{};
|
|
673
759
|
const out = try allocator.alloc(ServicePackageMetadata, packages.len);
|
|
@@ -1685,7 +1771,7 @@ fn parseWebViewLayer(value: []const u8) !app_manifest.WebViewLayer {
|
|
|
1685
1771
|
/// The teaching message every boundary prints for the same
|
|
1686
1772
|
/// contradiction: a manifest that excludes the web layer while declaring
|
|
1687
1773
|
/// web content.
|
|
1688
|
-
pub const web_layer_conflict_message = "app
|
|
1774
|
+
pub const web_layer_conflict_message = "the app manifest sets webview_layer = \"exclude\" but the app declares web content (a frontend block, the \"webview\" capability, a shell webview view, or the Chromium web engine - from web_engine or --web-engine) - remove the web declarations or drop the exclude";
|
|
1689
1775
|
|
|
1690
1776
|
/// The same contradiction arriving through the CLI flag instead of the
|
|
1691
1777
|
/// manifest field: `--web-layer exclude` against an app that declares
|
|
@@ -2386,8 +2472,86 @@ fn validatePathSegment(segment: []const u8) !void {
|
|
|
2386
2472
|
}
|
|
2387
2473
|
|
|
2388
2474
|
fn parseVersionNumber(value: []const u8) !u32 {
|
|
2389
|
-
if (value.len == 0) return error.InvalidVersion;
|
|
2390
|
-
return std.fmt.parseUnsigned(u32, value, 10);
|
|
2475
|
+
if (value.len == 0 or (value.len > 1 and value[0] == '0')) return error.InvalidVersion;
|
|
2476
|
+
return std.fmt.parseUnsigned(u32, value, 10) catch error.InvalidVersion;
|
|
2477
|
+
}
|
|
2478
|
+
|
|
2479
|
+
test "manifest versions use canonical numeric components" {
|
|
2480
|
+
try std.testing.expectEqual(@as(u32, 10), (try parseVersion("1.10.0")).minor);
|
|
2481
|
+
try std.testing.expectError(error.InvalidVersion, parseVersion("1.010.0"));
|
|
2482
|
+
try std.testing.expectError(error.InvalidVersion, parseVersion("01.0.0"));
|
|
2483
|
+
try std.testing.expectError(error.InvalidVersion, parseVersion("1.0.00"));
|
|
2484
|
+
}
|
|
2485
|
+
|
|
2486
|
+
test "manifest validation rejects leading-zero versions" {
|
|
2487
|
+
var tmp = std.testing.tmpDir(.{});
|
|
2488
|
+
defer tmp.cleanup();
|
|
2489
|
+
try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "app.json", .data =
|
|
2490
|
+
\\{ "id": "com.example.version", "name": "version", "version": "1.010.0" }
|
|
2491
|
+
});
|
|
2492
|
+
const path = try std.fmt.allocPrint(std.testing.allocator, ".zig-cache/tmp/{s}/app.json", .{tmp.sub_path});
|
|
2493
|
+
defer std.testing.allocator.free(path);
|
|
2494
|
+
const result = try validateFile(std.testing.allocator, std.testing.io, path);
|
|
2495
|
+
try std.testing.expect(!result.ok);
|
|
2496
|
+
try std.testing.expectEqualStrings("app manifest version is invalid", result.message);
|
|
2497
|
+
}
|
|
2498
|
+
|
|
2499
|
+
test "JSON manifest parser accepts schema metadata and rejects unknown fields" {
|
|
2500
|
+
const metadata = try parseJsonText(std.testing.allocator,
|
|
2501
|
+
\\{
|
|
2502
|
+
\\ "$schema": "https://schema.native-sdk.dev/app/v1.json",
|
|
2503
|
+
\\ "id": "com.example.json",
|
|
2504
|
+
\\ "name": "json-app",
|
|
2505
|
+
\\ "version": "1.2.3",
|
|
2506
|
+
\\ "capabilities": ["native_views"],
|
|
2507
|
+
\\ "windows": [{ "label": "main", "width": 640, "height": 480 }]
|
|
2508
|
+
\\}
|
|
2509
|
+
);
|
|
2510
|
+
defer metadata.deinit(std.testing.allocator);
|
|
2511
|
+
try std.testing.expectEqualStrings("com.example.json", metadata.id);
|
|
2512
|
+
try std.testing.expectEqualStrings("native_views", metadata.capabilities[0]);
|
|
2513
|
+
try std.testing.expectEqual(@as(f32, 640), metadata.windows[0].width);
|
|
2514
|
+
|
|
2515
|
+
try std.testing.expectError(error.UnknownField, parseJsonText(std.testing.allocator,
|
|
2516
|
+
\\{ "id": "com.example.json", "name": "json-app", "version": "1.2.3", "typo": true }
|
|
2517
|
+
));
|
|
2518
|
+
try std.testing.expectError(error.NullNotAllowed, parseJsonText(std.testing.allocator,
|
|
2519
|
+
\\{ "id": "com.example.json", "name": "json-app", "version": "1.2.3", "theme": null }
|
|
2520
|
+
));
|
|
2521
|
+
}
|
|
2522
|
+
|
|
2523
|
+
test "JSON manifest parser carries native update configuration" {
|
|
2524
|
+
const metadata = try parseJsonText(std.testing.allocator,
|
|
2525
|
+
\\{
|
|
2526
|
+
\\ "id": "com.example.updates",
|
|
2527
|
+
\\ "name": "updates",
|
|
2528
|
+
\\ "version": "1.2.3",
|
|
2529
|
+
\\ "updates": {
|
|
2530
|
+
\\ "feed_url": "https://example.com/native-update.json",
|
|
2531
|
+
\\ "public_key": "11qYAYKxCrfVS/7TyWQHOg7hcvPapiMlrwIaaPcHURo=",
|
|
2532
|
+
\\ "check_on_start": true
|
|
2533
|
+
\\ }
|
|
2534
|
+
\\}
|
|
2535
|
+
);
|
|
2536
|
+
defer metadata.deinit(std.testing.allocator);
|
|
2537
|
+
try std.testing.expect(metadata.updates.enabled());
|
|
2538
|
+
try std.testing.expect(metadata.updates.check_on_start);
|
|
2539
|
+
try std.testing.expectEqualStrings("https://example.com/native-update.json", metadata.updates.feed_url.?);
|
|
2540
|
+
}
|
|
2541
|
+
|
|
2542
|
+
test "JSON file validation rejects null with a teaching diagnostic regardless of extension case" {
|
|
2543
|
+
var cwd = std.Io.Dir.cwd();
|
|
2544
|
+
const root = ".zig-cache/test-validate-json-null";
|
|
2545
|
+
try cwd.deleteTree(std.testing.io, root);
|
|
2546
|
+
defer cwd.deleteTree(std.testing.io, root) catch {};
|
|
2547
|
+
try cwd.createDirPath(std.testing.io, root);
|
|
2548
|
+
try cwd.writeFile(std.testing.io, .{ .sub_path = root ++ "/APP.JSON", .data =
|
|
2549
|
+
\\{ "id": "com.example.json", "name": "json-app", "version": "1.2.3", "theme": null }
|
|
2550
|
+
});
|
|
2551
|
+
|
|
2552
|
+
const result = try validateFile(std.testing.allocator, std.testing.io, root ++ "/APP.JSON");
|
|
2553
|
+
try std.testing.expect(!result.ok);
|
|
2554
|
+
try std.testing.expectEqualStrings("app.json cannot contain null values - omit optional fields instead", result.message);
|
|
2391
2555
|
}
|
|
2392
2556
|
|
|
2393
2557
|
test "manifest metadata parser reads identity version and lists" {
|
|
@@ -3296,7 +3460,7 @@ test "validate rejects a web-declaring manifest that excludes the web layer" {
|
|
|
3296
3460
|
|
|
3297
3461
|
const result = try validateFile(gpa, std.testing.io, root ++ "/app.zon");
|
|
3298
3462
|
try std.testing.expect(!result.ok);
|
|
3299
|
-
try std.testing.expect(std.mem.indexOf(u8, result.message, "
|
|
3463
|
+
try std.testing.expect(std.mem.indexOf(u8, result.message, "webview_layer = \"exclude\"") != null);
|
|
3300
3464
|
try std.testing.expect(std.mem.indexOf(u8, result.message, "declares web content") != null);
|
|
3301
3465
|
|
|
3302
3466
|
// A native-only manifest with the same exclude is valid.
|
package/src/tooling/package.zig
CHANGED
|
@@ -83,6 +83,9 @@ pub const PackageOptions = struct {
|
|
|
83
83
|
cef_dir: []const u8 = web_engine_tool.default_cef_dir,
|
|
84
84
|
signing: SigningConfig = .{},
|
|
85
85
|
archive: bool = false,
|
|
86
|
+
/// Emit the ZIP consumed by the native updater. macOS only; unlike the
|
|
87
|
+
/// user-facing DMG, this archive contains exactly the packaged .app.
|
|
88
|
+
update_archive: bool = false,
|
|
86
89
|
/// The process environment, when the caller has one (the CLI). The
|
|
87
90
|
/// Android artifact probes it for the SDK/NDK toolchain to assemble
|
|
88
91
|
/// the debug APK; without it the generated project is still complete
|
|
@@ -153,6 +156,7 @@ pub const PackageStats = struct {
|
|
|
153
156
|
web_engine: WebEngine = .system,
|
|
154
157
|
web_layer: ?manifest_tool.WebLayer = null,
|
|
155
158
|
archive_path: ?[]const u8 = null,
|
|
159
|
+
update_archive_path: ?[]const u8 = null,
|
|
156
160
|
/// The Windows subsystem verdict: `console` when the package
|
|
157
161
|
/// wrapped a CONSOLE-subsystem exe (the app will flash a terminal
|
|
158
162
|
/// window behind itself on every launch), `gui` for a GUI-subsystem
|
|
@@ -217,6 +221,10 @@ pub fn createPackage(allocator: std.mem.Allocator, io: std.Io, options: PackageO
|
|
|
217
221
|
return err;
|
|
218
222
|
};
|
|
219
223
|
try validateWebEngineTarget(options.target, options.web_engine);
|
|
224
|
+
if (options.metadata.updates.enabled() and options.target == .macos and options.web_engine == .chromium) {
|
|
225
|
+
std.debug.print("error: native updates currently require the system macOS host; package with --web-engine system or remove the updates block\n", .{});
|
|
226
|
+
return error.UnsupportedUpdateHost;
|
|
227
|
+
}
|
|
220
228
|
if (options.target == .macos and options.archive) {
|
|
221
229
|
manifest_tool.validateDmgPackageSettings(options.metadata) catch |err| {
|
|
222
230
|
std.debug.print("error: app.zon dmg settings are invalid ({s})\n", .{@errorName(err)});
|
|
@@ -239,6 +247,11 @@ pub fn createPackage(allocator: std.mem.Allocator, io: std.Io, options: PackageO
|
|
|
239
247
|
stats.archive_path = path;
|
|
240
248
|
}
|
|
241
249
|
}
|
|
250
|
+
if (options.update_archive) {
|
|
251
|
+
if (options.target != .macos) return error.UnsupportedUpdateTarget;
|
|
252
|
+
if (!options.metadata.updates.enabled()) return error.UpdatesNotConfigured;
|
|
253
|
+
stats.update_archive_path = try createUpdateArchive(allocator, io, options);
|
|
254
|
+
}
|
|
242
255
|
return stats;
|
|
243
256
|
}
|
|
244
257
|
|
|
@@ -283,6 +296,26 @@ pub fn printDiagnostic(stats: PackageStats) void {
|
|
|
283
296
|
if (stats.archive_path) |archive| {
|
|
284
297
|
std.debug.print(" archive: {s}\n", .{archive});
|
|
285
298
|
}
|
|
299
|
+
if (stats.update_archive_path) |archive| {
|
|
300
|
+
std.debug.print(" update archive: {s}\n", .{archive});
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
fn createUpdateArchive(allocator: std.mem.Allocator, io: std.Io, options: PackageOptions) ![]const u8 {
|
|
305
|
+
const parent = std.fs.path.dirname(options.output_path) orelse ".";
|
|
306
|
+
const archive_name = try std.fmt.allocPrint(allocator, "{s}-{s}-macos-{s}-update.zip", .{ options.metadata.name, options.metadata.version, options.optimize });
|
|
307
|
+
defer allocator.free(archive_name);
|
|
308
|
+
const archive_path = try std.fs.path.join(allocator, &.{ parent, archive_name });
|
|
309
|
+
errdefer allocator.free(archive_path);
|
|
310
|
+
const app_path = try absolutePathAlloc(allocator, io, options.output_path);
|
|
311
|
+
defer allocator.free(app_path);
|
|
312
|
+
const archive_command_path = try absolutePathAlloc(allocator, io, archive_path);
|
|
313
|
+
defer allocator.free(archive_command_path);
|
|
314
|
+
if (!runArchiveCommand(io, &.{ "/usr/bin/ditto", "-c", "-k", "--sequesterRsrc", "--keepParent", app_path, archive_command_path }, null)) {
|
|
315
|
+
std.debug.print("error: update archive creation failed for {s}\n", .{archive_path});
|
|
316
|
+
return error.UpdateArchiveFailed;
|
|
317
|
+
}
|
|
318
|
+
return archive_path;
|
|
286
319
|
}
|
|
287
320
|
|
|
288
321
|
pub fn createLocalPackage(io: std.Io, output_path: []const u8) !PackageStats {
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
const web_engine = @import("web_engine.zig");
|
|
2
2
|
|
|
3
3
|
pub const RawManifest = struct {
|
|
4
|
+
/// Editor-only JSON Schema association. The manifest tooling ignores the
|
|
5
|
+
/// value after parsing; app.json scaffolds point it at the published SDK
|
|
6
|
+
/// schema so editors can complete and validate the full manifest surface.
|
|
7
|
+
@"$schema": ?[]const u8 = null,
|
|
4
8
|
id: []const u8,
|
|
5
9
|
name: []const u8,
|
|
6
10
|
display_name: ?[]const u8 = null,
|
|
@@ -44,9 +48,16 @@ pub const RawManifest = struct {
|
|
|
44
48
|
shortcuts: []const RawShortcut = &.{},
|
|
45
49
|
file_associations: []const RawFileAssociation = &.{},
|
|
46
50
|
url_schemes: []const RawUrlScheme = &.{},
|
|
51
|
+
updates: RawUpdates = .{},
|
|
47
52
|
dmg: RawDmg = .{},
|
|
48
53
|
};
|
|
49
54
|
|
|
55
|
+
pub const RawUpdates = struct {
|
|
56
|
+
feed_url: ?[]const u8 = null,
|
|
57
|
+
public_key: ?[]const u8 = null,
|
|
58
|
+
check_on_start: bool = false,
|
|
59
|
+
};
|
|
60
|
+
|
|
50
61
|
pub const RawImages = struct {
|
|
51
62
|
max_image_pixel_bytes: usize = 1024 * 1024,
|
|
52
63
|
};
|
package/src/tooling/root.zig
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
pub const templates = @import("templates.zig");
|
|
2
2
|
pub const manifest = @import("manifest.zig");
|
|
3
3
|
pub const raw_manifest = @import("raw_manifest.zig");
|
|
4
|
+
pub const json_to_zon = @import("json_to_zon.zig");
|
|
4
5
|
pub const assets = @import("assets.zig");
|
|
5
6
|
pub const codesign = @import("codesign.zig");
|
|
6
7
|
pub const doctor = @import("doctor.zig");
|
|
@@ -19,6 +20,7 @@ pub const ios = @import("ios.zig");
|
|
|
19
20
|
pub const android = @import("android.zig");
|
|
20
21
|
pub const xcodeproj = @import("xcodeproj.zig");
|
|
21
22
|
pub const db = @import("db.zig");
|
|
23
|
+
pub const update = @import("update.zig");
|
|
22
24
|
|
|
23
25
|
test {
|
|
24
26
|
@import("std").testing.refAllDecls(@This());
|