@skathi-native/cli 0.0.0 → 0.1.0-beta.2

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 (81) hide show
  1. package/aot-inputs.ts +294 -0
  2. package/ascii.ts +397 -0
  3. package/build.ts +1236 -0
  4. package/check/builtins.json +1219 -0
  5. package/check/builtins.ts +112 -0
  6. package/check/codes.ts +178 -0
  7. package/check/command.ts +105 -0
  8. package/check/config.ts +76 -0
  9. package/check/finding.ts +30 -0
  10. package/check/graph.ts +69 -0
  11. package/check/highlight.ts +40 -0
  12. package/check/index.ts +308 -0
  13. package/check/packages.ts +54 -0
  14. package/check/program.ts +209 -0
  15. package/check/report.ts +219 -0
  16. package/check/rules.ts +307 -0
  17. package/check/schema.ts +69 -0
  18. package/check/typing.ts +703 -0
  19. package/cli/assets.ts +114 -0
  20. package/cli/build-app.ts +587 -0
  21. package/cli/config.ts +646 -0
  22. package/cli/create.ts +327 -0
  23. package/cli/dev.ts +92 -0
  24. package/cli/elf.ts +142 -0
  25. package/cli/help.ts +160 -0
  26. package/cli/host-fetch.ts +178 -0
  27. package/cli/host.ts +378 -0
  28. package/cli/icon.ts +303 -0
  29. package/cli/macos-bundle.ts +451 -0
  30. package/cli/pe.ts +429 -0
  31. package/cli/platform.ts +74 -0
  32. package/cli/sk.ts +290 -0
  33. package/cli/skpk.ts +268 -0
  34. package/cli/stamp.ts +254 -0
  35. package/cli/term.ts +176 -0
  36. package/cli/versioninfo.ts +123 -0
  37. package/css-prefixes.ts +118 -0
  38. package/devtools/apps.ts +68 -0
  39. package/devtools/commands.ts +860 -0
  40. package/devtools/ctl.ts +166 -0
  41. package/package.json +52 -3
  42. package/prod.ts +701 -0
  43. package/runtime-path.ts +24 -0
  44. package/tailwind.ts +76 -0
  45. package/templates/minimal/assets/hello.txt +1 -0
  46. package/templates/minimal/src/App.vue +142 -0
  47. package/templates/minimal/src/main.ts +4 -0
  48. package/templates/showcase/assets/hello.txt +1 -0
  49. package/templates/showcase/assets/media/aurora.png +0 -0
  50. package/templates/showcase/assets/media/clip.mp4 +0 -0
  51. package/templates/showcase/assets/media/sticker.tgs +0 -0
  52. package/templates/showcase/src/App.vue +128 -0
  53. package/templates/showcase/src/components/Card.vue +41 -0
  54. package/templates/showcase/src/components/Icon.vue +29 -0
  55. package/templates/showcase/src/components/Missing.vue +26 -0
  56. package/templates/showcase/src/components/Page.vue +41 -0
  57. package/templates/showcase/src/components/Titlebar.vue +128 -0
  58. package/templates/showcase/src/engine.ts +33 -0
  59. package/templates/showcase/src/icons.ts +22 -0
  60. package/templates/showcase/src/main.ts +7 -0
  61. package/templates/showcase/src/pages/AudioPage.vue +124 -0
  62. package/templates/showcase/src/pages/FilesPage.vue +91 -0
  63. package/templates/showcase/src/pages/FormsPage.vue +139 -0
  64. package/templates/showcase/src/pages/GraphicsPage.vue +156 -0
  65. package/templates/showcase/src/pages/HomePage.vue +141 -0
  66. package/templates/showcase/src/pages/LocalePage.vue +71 -0
  67. package/templates/showcase/src/pages/MediaPage.vue +85 -0
  68. package/templates/showcase/src/pages/MotionPage.vue +199 -0
  69. package/templates/showcase/src/pages/NetworkPage.vue +103 -0
  70. package/templates/showcase/src/pages/PermissionsPage.vue +80 -0
  71. package/templates/showcase/src/pages/StoragePage.vue +117 -0
  72. package/templates/showcase/src/pages/StylesPage.vue +199 -0
  73. package/templates/showcase/src/pages/SystemPage.vue +89 -0
  74. package/templates/showcase/src/pages/TrayPage.vue +66 -0
  75. package/templates/showcase/src/pages/WindowPage.vue +128 -0
  76. package/templates/showcase/src/product.ts +2 -0
  77. package/templates/showcase/src/router.ts +149 -0
  78. package/templates/showcase/src/stores/counter.ts +9 -0
  79. package/templates/showcase/src/stores/desktop.ts +115 -0
  80. package/templates/showcase/src/styles.css +140 -0
  81. package/vitecompat.ts +1151 -0
@@ -0,0 +1,451 @@
1
+ // The macOS side of `sk build`: a copy of the host becomes one app's `.app`.
2
+ //
3
+ // <exeName>.app/Contents/{Info.plist, PkgInfo, MacOS/<exeName> (the bare host, verbatim),
4
+ // Resources/app.skpk, Resources/AppIcon.icns}
5
+ //
6
+ // Nothing is written into the Mach-O (it would break the host's signature); the payload is a file in
7
+ // the bundle, covered by its signature. The bundle is assembled as `<out>.partial` and renamed.
8
+ // `codesign` runs only on macOS: ad hoc without an identity (Apple Silicon needs it), otherwise
9
+ // hardened runtime, a secure timestamp and the entitlements JSC's JIT and the microphone and
10
+ // camera need. Notarisation is the author's step. The rest is platform-free, so it is tested on Windows.
11
+
12
+ import { spawnSync } from "node:child_process";
13
+ import {
14
+ chmodSync,
15
+ closeSync,
16
+ copyFileSync,
17
+ existsSync,
18
+ mkdirSync,
19
+ openSync,
20
+ readFileSync,
21
+ readSync,
22
+ renameSync,
23
+ rmSync,
24
+ statSync,
25
+ writeFileSync,
26
+ } from "node:fs";
27
+ import { basename, dirname, extname, join } from "node:path";
28
+ import { decodePng, encodePng, isPng, parseIco, resizeRgba } from "./icon";
29
+
30
+ export type PlistValue = string | number | boolean | PlistValue[] | { [key: string]: PlistValue };
31
+
32
+ const XML_INVALID =
33
+ /[\u0000-\u0008\u000B\u000C\u000E-\u001F￾￿]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/;
34
+
35
+ export function xmlText(s: string, where = "plist"): string {
36
+ const bad = XML_INVALID.exec(s);
37
+ if (bad) {
38
+ const code = bad[0].charCodeAt(0).toString(16).padStart(4, "0");
39
+ throw new Error(`${where}: U+${code} cannot appear in a property list (XML 1.0)`);
40
+ }
41
+ return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
42
+ }
43
+
44
+ function plistLines(value: PlistValue, depth: number, where: string, out: string[]) {
45
+ const pad = "\t".repeat(depth);
46
+ if (typeof value === "string") out.push(`${pad}<string>${xmlText(value, where)}</string>`);
47
+ else if (typeof value === "boolean") out.push(`${pad}<${value}/>`);
48
+ else if (typeof value === "number") {
49
+ if (!Number.isFinite(value)) throw new Error(`${where}: ${value} is not a plist number`);
50
+ out.push(Number.isInteger(value) ? `${pad}<integer>${value}</integer>` : `${pad}<real>${value}</real>`);
51
+ } else if (Array.isArray(value)) {
52
+ if (!value.length) out.push(`${pad}<array/>`);
53
+ else {
54
+ out.push(`${pad}<array>`);
55
+ value.forEach((v, i) => plistLines(v, depth + 1, `${where}[${i}]`, out));
56
+ out.push(`${pad}</array>`);
57
+ }
58
+ } else {
59
+ const keys = Object.keys(value);
60
+ if (!keys.length) out.push(`${pad}<dict/>`);
61
+ else {
62
+ out.push(`${pad}<dict>`);
63
+ for (const k of keys) {
64
+ out.push(`${pad}\t<key>${xmlText(k, where)}</key>`);
65
+ plistLines(value[k]!, depth + 1, `${where}.${k}`, out);
66
+ }
67
+ out.push(`${pad}</dict>`);
68
+ }
69
+ }
70
+ }
71
+
72
+ export function plistXml(root: { [key: string]: PlistValue }): string {
73
+ const out = [
74
+ '<?xml version="1.0" encoding="UTF-8"?>',
75
+ '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">',
76
+ '<plist version="1.0">',
77
+ ];
78
+ plistLines(root, 0, "plist", out);
79
+ out.push("</plist>", "");
80
+ return out.join("\n");
81
+ }
82
+
83
+ export interface MacInfo {
84
+ bundleId: string;
85
+ name: string;
86
+ executable: string;
87
+ version: string;
88
+ build?: string;
89
+ iconFile: string | null;
90
+ minimumSystemVersion: string;
91
+ category?: string | null;
92
+ copyright?: string | null;
93
+ microphoneUsageDescription?: string | null;
94
+ cameraUsageDescription?: string | null;
95
+ urlSchemes?: string[];
96
+ }
97
+
98
+ export function infoPlist(m: MacInfo): { [key: string]: PlistValue } {
99
+ const d: { [key: string]: PlistValue } = {
100
+ CFBundleDevelopmentRegion: "en",
101
+ CFBundleDisplayName: m.name,
102
+ CFBundleExecutable: m.executable,
103
+ };
104
+ if (m.iconFile) d.CFBundleIconFile = m.iconFile;
105
+ d.CFBundleIdentifier = m.bundleId;
106
+ d.CFBundleInfoDictionaryVersion = "6.0";
107
+ d.CFBundleName = m.name;
108
+ d.CFBundlePackageType = "APPL";
109
+ d.CFBundleShortVersionString = m.version;
110
+ d.CFBundleSignature = "????";
111
+ if (m.urlSchemes?.length) {
112
+ d.CFBundleURLTypes = [{ CFBundleURLName: m.bundleId, CFBundleURLSchemes: [...m.urlSchemes] }];
113
+ }
114
+ d.CFBundleVersion = m.build ?? m.version;
115
+ if (m.category) d.LSApplicationCategoryType = m.category;
116
+ d.LSMinimumSystemVersion = m.minimumSystemVersion;
117
+ if (m.cameraUsageDescription) {
118
+ d.NSCameraUsageDescription = m.cameraUsageDescription;
119
+ // macOS 14+ lists an iPhone as a camera only for an app that opts in.
120
+ d.NSCameraUseContinuityCameraDeviceType = true;
121
+ }
122
+ d.NSHighResolutionCapable = true;
123
+ if (m.copyright) d.NSHumanReadableCopyright = m.copyright;
124
+ if (m.microphoneUsageDescription) d.NSMicrophoneUsageDescription = m.microphoneUsageDescription;
125
+ return d;
126
+ }
127
+
128
+ export function entitlements(m: Pick<MacInfo, "microphoneUsageDescription" | "cameraUsageDescription">): {
129
+ [key: string]: PlistValue;
130
+ } {
131
+ const d: { [key: string]: PlistValue } = { "com.apple.security.cs.allow-jit": true };
132
+ if (m.microphoneUsageDescription) d["com.apple.security.device.audio-input"] = true;
133
+ if (m.cameraUsageDescription) d["com.apple.security.device.camera"] = true;
134
+ return d;
135
+ }
136
+
137
+ // "icns" u32be total length, then entries: OSType(4) u32be length (incl. these 8 bytes) data.
138
+ // Since 10.7 every entry may hold a PNG, so an icns is a list of PNGs labelled by size.
139
+
140
+ /** The PNG-bearing types, smallest first: [OSType, pixels]. `@2x` types share a size with a 1x one. */
141
+ export const ICNS_TYPES: readonly (readonly [string, number])[] = [
142
+ ["icp4", 16],
143
+ ["ic11", 32], // 16@2x
144
+ ["icp5", 32],
145
+ ["ic12", 64], // 32@2x
146
+ ["ic07", 128],
147
+ ["ic13", 256], // 128@2x
148
+ ["ic08", 256],
149
+ ["ic14", 512], // 256@2x
150
+ ["ic09", 512],
151
+ ["ic10", 1024], // 512@2x
152
+ ];
153
+
154
+ export interface IcnsEntry {
155
+ type: string;
156
+ data: Uint8Array;
157
+ }
158
+
159
+ export function encodeIcns(entries: IcnsEntry[]): Uint8Array {
160
+ const total = 8 + entries.reduce((n, e) => n + 8 + e.data.length, 0);
161
+ const out = new Uint8Array(total);
162
+ const dv = new DataView(out.buffer);
163
+ const tag = (o: number, s: string) => {
164
+ if (!/^[\x20-\x7e]{4}$/.test(s)) throw new Error(`icns: ${JSON.stringify(s)} is not an OSType`);
165
+ for (let i = 0; i < 4; i++) out[o + i] = s.charCodeAt(i);
166
+ };
167
+ tag(0, "icns");
168
+ dv.setUint32(4, total);
169
+ let o = 8;
170
+ for (const e of entries) {
171
+ tag(o, e.type);
172
+ dv.setUint32(o + 4, 8 + e.data.length);
173
+ out.set(e.data, o + 8);
174
+ o += 8 + e.data.length;
175
+ }
176
+ return out;
177
+ }
178
+
179
+ export function parseIcns(bytes: Uint8Array, label = "icns"): IcnsEntry[] {
180
+ const dv = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
181
+ const tag = (o: number) => String.fromCharCode(...bytes.subarray(o, o + 4));
182
+ if (bytes.length < 8 || tag(0) !== "icns") throw new Error(`${label}: not an .icns (no "icns" magic)`);
183
+ if (dv.getUint32(4) !== bytes.length) {
184
+ throw new Error(`${label}: the header says ${dv.getUint32(4)} bytes, the file is ${bytes.length}`);
185
+ }
186
+ const entries: IcnsEntry[] = [];
187
+ for (let o = 8; o < bytes.length;) {
188
+ if (o + 8 > bytes.length) throw new Error(`${label}: truncated entry header at ${o}`);
189
+ const len = dv.getUint32(o + 4);
190
+ if (len < 8 || o + len > bytes.length) throw new Error(`${label}: entry ${tag(o)} at ${o} claims ${len} bytes`);
191
+ entries.push({ type: tag(o), data: bytes.subarray(o + 8, o + len) });
192
+ o += len;
193
+ }
194
+ return entries;
195
+ }
196
+
197
+ export interface Icns {
198
+ bytes: Uint8Array;
199
+ sizes: number[];
200
+ verbatim: boolean;
201
+ }
202
+
203
+ function sourcePng(path: string, bytes: Uint8Array): Uint8Array {
204
+ if (extname(path).toLowerCase() === ".ico") {
205
+ const pngs = parseIco(bytes, path).filter((img) => isPng(img.data));
206
+ if (!pngs.length) {
207
+ throw new Error(
208
+ `${path}: the .ico holds only BMP images — give macos.icon a square .png (1024 px is best) or an .icns`,
209
+ );
210
+ }
211
+ return pngs.reduce((a, b) => (b.width > a.width ? b : a)).data;
212
+ }
213
+ if (!isPng(bytes))
214
+ throw new Error(`${path}: a macOS icon must be an .icns, a square .png, or an .ico holding PNG images`);
215
+ return bytes;
216
+ }
217
+
218
+ export function icnsFromPng(png: Uint8Array, label = "png"): Icns {
219
+ const img = decodePng(png, label);
220
+ if (img.width !== img.height) {
221
+ throw new Error(`${label}: an app icon must be square (this one is ${img.width}×${img.height})`);
222
+ }
223
+ if (img.width < 16) throw new Error(`${label}: ${img.width}px is smaller than the smallest icon size (16)`);
224
+ const bySize = new Map<number, Uint8Array>();
225
+ const entries: IcnsEntry[] = [];
226
+ for (const [type, size] of ICNS_TYPES) {
227
+ if (size > img.width) continue;
228
+ let data = bySize.get(size);
229
+ if (!data) {
230
+ data = size === img.width ? png : encodePng(resizeRgba(img, size, size));
231
+ bySize.set(size, data);
232
+ }
233
+ entries.push({ type, data });
234
+ }
235
+ return { bytes: encodeIcns(entries), sizes: [...bySize.keys()], verbatim: false };
236
+ }
237
+
238
+ export function icnsFrom(path: string): Icns {
239
+ const bytes = new Uint8Array(readFileSync(path));
240
+ if (extname(path).toLowerCase() === ".icns") {
241
+ const entries = parseIcns(bytes, path);
242
+ const sizes = new Set<number>();
243
+ for (const e of entries) {
244
+ const known = ICNS_TYPES.find(([t]) => t === e.type);
245
+ if (known) sizes.add(known[1]);
246
+ }
247
+ return { bytes, sizes: [...sizes].sort((a, b) => a - b), verbatim: true };
248
+ }
249
+ return icnsFromPng(sourcePng(path, bytes), path);
250
+ }
251
+
252
+ const CPU: Record<number, string> = {
253
+ 0x0100000c: "arm64",
254
+ 0x01000007: "x86_64",
255
+ 0x0000000c: "arm",
256
+ 0x00000007: "i386",
257
+ };
258
+
259
+ export function machOArchs(path: string): string[] | null {
260
+ let head: Uint8Array;
261
+ try {
262
+ const fd = openSync(path, "r");
263
+ try {
264
+ head = new Uint8Array(4096);
265
+ head = head.subarray(0, readSync(fd, head, 0, head.length, 0));
266
+ } finally {
267
+ closeSync(fd);
268
+ }
269
+ } catch {
270
+ return null;
271
+ }
272
+ if (head.length < 8) return null;
273
+ const dv = new DataView(head.buffer, head.byteOffset, head.byteLength);
274
+ const le = dv.getUint32(0, true);
275
+ if (le === 0xfeedfacf || le === 0xfeedface)
276
+ return [CPU[dv.getUint32(4, true)] ?? `cpu 0x${dv.getUint32(4, true).toString(16)}`];
277
+ const be = dv.getUint32(0);
278
+ if (be === 0xcafebabe || be === 0xcafebabf) {
279
+ const n = dv.getUint32(4);
280
+ const stride = be === 0xcafebabf ? 32 : 20;
281
+ // Java class files share 0xcafebabe; their "count" is a version number in the 40s+.
282
+ if (n === 0 || n > 16 || 8 + n * stride > head.length) return null;
283
+ const archs: string[] = [];
284
+ for (let i = 0; i < n; i++) {
285
+ const cpu = dv.getUint32(8 + i * stride);
286
+ archs.push(CPU[cpu] ?? `cpu 0x${cpu.toString(16)}`);
287
+ }
288
+ return archs;
289
+ }
290
+ return null;
291
+ }
292
+
293
+ export function bundlePayloadPath(exe: string): string | null {
294
+ const macos = dirname(exe);
295
+ const contents = dirname(macos);
296
+ const bundle = dirname(contents);
297
+ if (basename(macos) !== "MacOS" || basename(contents) !== "Contents") return null;
298
+ if (extname(bundle).toLowerCase() !== ".app") return null;
299
+ return join(contents, "Resources", "app.skpk");
300
+ }
301
+
302
+ export const PAYLOAD_FILE = "app.skpk";
303
+ export const ICON_NAME = "AppIcon";
304
+
305
+ export interface AppBundleOptions {
306
+ host: string;
307
+ out: string;
308
+ executable: string;
309
+ payload: Uint8Array;
310
+ icns?: Uint8Array | null;
311
+ infoPlist: string;
312
+ log?: (line: string) => void;
313
+ }
314
+
315
+ export interface AppBundleResult {
316
+ app: string;
317
+ executable: string;
318
+ bytes: number;
319
+ payloadBytes: number;
320
+ iconBytes: number;
321
+ ms: { copy: number; total: number };
322
+ }
323
+
324
+ export function writeAppBundle(options: AppBundleOptions): AppBundleResult {
325
+ const t0 = performance.now();
326
+ if (!options.executable || /[/\\:]/.test(options.executable)) {
327
+ throw new Error(`${JSON.stringify(options.executable)} is not a file name for Contents/MacOS`);
328
+ }
329
+ const partial = `${options.out}.partial`;
330
+ rmSync(partial, { recursive: true, force: true });
331
+ const contents = join(partial, "Contents");
332
+ const macosDir = join(contents, "MacOS");
333
+ const resources = join(contents, "Resources");
334
+ let done = false;
335
+ try {
336
+ mkdirSync(macosDir, { recursive: true });
337
+ mkdirSync(resources, { recursive: true });
338
+ const exe = join(macosDir, options.executable);
339
+ copyFileSync(options.host, exe);
340
+ chmodSync(exe, 0o755);
341
+ const tCopy = performance.now();
342
+ writeFileSync(join(resources, PAYLOAD_FILE), options.payload);
343
+ if (options.icns) writeFileSync(join(resources, `${ICON_NAME}.icns`), options.icns);
344
+ writeFileSync(join(contents, "Info.plist"), options.infoPlist);
345
+ writeFileSync(join(contents, "PkgInfo"), "APPL????");
346
+
347
+ if (existsSync(options.out)) {
348
+ try {
349
+ rmSync(options.out, { recursive: true, force: true });
350
+ } catch (e) {
351
+ throw new Error(
352
+ `${options.out} cannot be replaced — is it running? Quit it and build again. (${(e as Error).message})`,
353
+ );
354
+ }
355
+ }
356
+ renameSync(partial, options.out);
357
+ done = true;
358
+ const app = options.out;
359
+ const executable = join(app, "Contents", "MacOS", options.executable);
360
+ const bytes =
361
+ statSync(executable).size +
362
+ options.payload.length +
363
+ (options.icns?.length ?? 0) +
364
+ Buffer.byteLength(options.infoPlist) +
365
+ 8;
366
+ return {
367
+ app,
368
+ executable,
369
+ bytes,
370
+ payloadBytes: options.payload.length,
371
+ iconBytes: options.icns?.length ?? 0,
372
+ ms: { copy: Math.round(tCopy - t0), total: Math.round(performance.now() - t0) },
373
+ };
374
+ } finally {
375
+ if (!done) rmSync(partial, { recursive: true, force: true });
376
+ }
377
+ }
378
+
379
+ /** `-` is ad hoc: no certificate, no hardened runtime, nothing to notarise. */
380
+ export const AD_HOC = "-";
381
+
382
+ export function codesignArgs(app: string, identity: string, entitlementsPath: string | null): string[] {
383
+ if (identity === AD_HOC) return ["--force", "--sign", AD_HOC, app];
384
+ return [
385
+ "--force",
386
+ "--options",
387
+ "runtime",
388
+ "--timestamp",
389
+ ...(entitlementsPath ? ["--entitlements", entitlementsPath] : []),
390
+ "--sign",
391
+ identity,
392
+ app,
393
+ ];
394
+ }
395
+
396
+ export interface SignPlan {
397
+ identity: string | null;
398
+ note: string | null;
399
+ }
400
+
401
+ const shellWord = (s: string) => (/^[\w@%+=:,./-]+$/.test(s) ? s : `'${s.replace(/'/g, `'\\''`)}'`);
402
+
403
+ export function signPlan(input: {
404
+ want: string | false | undefined;
405
+ app: string;
406
+ entitlements: string;
407
+ codesign: string | null;
408
+ onMac: boolean;
409
+ }): SignPlan {
410
+ const { want, app, codesign } = input;
411
+ if (want === false) return { identity: null, note: "not signed (signing is off)" };
412
+ if (!input.onMac) {
413
+ const args = codesignArgs(app, want ?? AD_HOC, input.entitlements);
414
+ return {
415
+ identity: null,
416
+ note:
417
+ `not signed: codesign runs on macOS only. On a Mac: codesign ${args.map(shellWord).join(" ")}` +
418
+ (want ? "" : " (Apple Silicon wants at least this ad-hoc signature on the bundle)"),
419
+ };
420
+ }
421
+ if (!codesign) {
422
+ if (want)
423
+ throw new Error(
424
+ `codesign is not on PATH, so ${app} cannot be signed as ${JSON.stringify(want)} — xcode-select --install`,
425
+ );
426
+ return {
427
+ identity: null,
428
+ note: "not signed: codesign is not on PATH (xcode-select --install) — the executable keeps only its linker signature",
429
+ };
430
+ }
431
+ return { identity: want ?? AD_HOC, note: null };
432
+ }
433
+
434
+ export function signBundle(
435
+ codesign: string,
436
+ app: string,
437
+ identity: string,
438
+ entitlementsPath: string | null,
439
+ log: (line: string) => void = () => {},
440
+ ): { ms: number } {
441
+ const t0 = performance.now();
442
+ const args = codesignArgs(app, identity, entitlementsPath);
443
+ log(`codesign ${args.join(" ")}`);
444
+ const r = spawnSync(codesign, args, { encoding: "utf8" });
445
+ if (r.status !== 0) {
446
+ throw new Error(`codesign failed (exit ${r.status ?? r.error?.message}):\n${(r.stderr ?? "").trim()}`);
447
+ }
448
+ const v = spawnSync(codesign, ["--verify", "--strict", "--verbose=2", app], { encoding: "utf8" });
449
+ if (v.status !== 0) throw new Error(`codesign --verify rejected ${app}:\n${(v.stderr ?? "").trim()}`);
450
+ return { ms: Math.round(performance.now() - t0) };
451
+ }