@hewel/zgui-build 0.1.3 → 0.1.6
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 +4 -4
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/package.json +1 -1
- package/sdk/Cargo.lock +397 -46
- package/sdk/THIRD_PARTY_NOTICES.md +1 -1
- package/sdk/bun.lock +8 -7
- package/sdk/package.json +2 -1
- package/src/build.ts +108 -31
- package/src/compiler.ts +22 -1
- package/src/dev.ts +14 -3
- package/src/host.ts +54 -3
- package/src/identity.ts +4 -2
- package/src/internal.ts +1 -0
- package/src/manifest-policy.ts +165 -47
- package/src/package-app.ts +38 -7
- package/src/preview.ts +9 -1
- package/src/public-api.d.ts +36 -0
- package/src/publication.ts +2 -0
- package/src/sdk-packages.ts +36 -20
- package/src/sync-ui-resources.ts +51 -1
- package/src/validate.ts +95 -49
- package/src/watch.ts +8 -0
package/src/manifest-policy.ts
CHANGED
|
@@ -18,7 +18,7 @@ export async function readManifestPolicy(
|
|
|
18
18
|
assets: ReadonlyMap<string, Uint8Array>,
|
|
19
19
|
overlays: CapabilityOverlays,
|
|
20
20
|
): Promise<
|
|
21
|
-
Pick<Manifest, "id" | "window" | "capabilities" | "fonts"> & {
|
|
21
|
+
Pick<Manifest, "id" | "window" | "resourceProfile" | "capabilities" | "fonts"> & {
|
|
22
22
|
workerEntries: { name: string; entry: string }[];
|
|
23
23
|
}
|
|
24
24
|
> {
|
|
@@ -35,6 +35,7 @@ export async function readManifestPolicy(
|
|
|
35
35
|
zgui?: {
|
|
36
36
|
id?: unknown;
|
|
37
37
|
window?: unknown;
|
|
38
|
+
resourceProfile?: unknown;
|
|
38
39
|
capabilities?: unknown;
|
|
39
40
|
workers?: unknown;
|
|
40
41
|
fonts?: unknown;
|
|
@@ -44,6 +45,7 @@ export async function readManifestPolicy(
|
|
|
44
45
|
const id = zgui?.id === undefined ? `dev.example.${app}` : zgui.id;
|
|
45
46
|
requireManifestText(id, "zgui.id");
|
|
46
47
|
const window = parseWindowDeclaration(zgui?.window);
|
|
48
|
+
const resourceProfile = parseResourceProfile(zgui?.resourceProfile);
|
|
47
49
|
const capabilities = await mergeCapabilities(zgui?.capabilities, overlays);
|
|
48
50
|
const workerEntries = parseWorkerDeclarations(zgui?.workers, appDirectory);
|
|
49
51
|
const fonts = parseFonts(zgui?.fonts, assets);
|
|
@@ -52,6 +54,7 @@ export async function readManifestPolicy(
|
|
|
52
54
|
workerEntries,
|
|
53
55
|
fonts,
|
|
54
56
|
...(window ? { window } : {}),
|
|
57
|
+
...(resourceProfile ? { resourceProfile } : {}),
|
|
55
58
|
...(capabilities ? { capabilities } : {}),
|
|
56
59
|
};
|
|
57
60
|
}
|
|
@@ -225,6 +228,69 @@ function parseNetworkOrigin(
|
|
|
225
228
|
return { canonical, insecure: scheme === "http" || scheme === "ws", host };
|
|
226
229
|
}
|
|
227
230
|
|
|
231
|
+
const systemFileFlags = [
|
|
232
|
+
"read",
|
|
233
|
+
"write",
|
|
234
|
+
"trash",
|
|
235
|
+
"volumes",
|
|
236
|
+
"thumbnails",
|
|
237
|
+
"openExternal",
|
|
238
|
+
] as const;
|
|
239
|
+
|
|
240
|
+
function parseDirectoryGrants(
|
|
241
|
+
value: unknown,
|
|
242
|
+
field: string,
|
|
243
|
+
): NonNullable<NonNullable<Capabilities["files"]>["directories"]> {
|
|
244
|
+
if (!Array.isArray(value)) throw new Error(`${field} must be an array`);
|
|
245
|
+
const seen = new Set<string>();
|
|
246
|
+
return (value as unknown[]).map(item => {
|
|
247
|
+
if (!item || typeof item !== "object" || Array.isArray(item))
|
|
248
|
+
throw new Error(`${field} entries must be objects`);
|
|
249
|
+
const record = item as Record<string, unknown>;
|
|
250
|
+
if (!Object.keys(record).every(key => key === "path" || key === "mode"))
|
|
251
|
+
throw new Error(`${field} entry contains unknown keys`);
|
|
252
|
+
if (
|
|
253
|
+
!capabilityString(record.path) ||
|
|
254
|
+
!capabilityPath(record.path, "directory") ||
|
|
255
|
+
(record.mode !== "read" && record.mode !== "readwrite")
|
|
256
|
+
)
|
|
257
|
+
throw new Error(`${field} contains invalid entries`);
|
|
258
|
+
if (seen.has(record.path)) throw new Error(`${field} contains duplicate path ${record.path}`);
|
|
259
|
+
seen.add(record.path);
|
|
260
|
+
return { path: record.path, mode: record.mode };
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const handoffKeys = ["unixSockets", "namedSockets", "commands"] as const;
|
|
265
|
+
type HandoffKey = (typeof handoffKeys)[number];
|
|
266
|
+
|
|
267
|
+
function parseHandoff(value: unknown, field: string): Capabilities["descriptorHandoff"] {
|
|
268
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
269
|
+
throw new Error(`${field} must be an object`);
|
|
270
|
+
const recipients: Partial<Record<HandoffKey, string[]>> = {};
|
|
271
|
+
for (const [name, list] of Object.entries(value as Record<string, unknown>)) {
|
|
272
|
+
const key = handoffKeys.find(candidate => candidate === name);
|
|
273
|
+
if (!key) throw new Error(`Unknown capability: ${field}.${name}`);
|
|
274
|
+
if (!Array.isArray(list)) throw new Error(`${field}.${key} must be an array`);
|
|
275
|
+
const entries = new Set<string>();
|
|
276
|
+
for (const item of list as unknown[]) {
|
|
277
|
+
if (
|
|
278
|
+
!capabilityString(item) ||
|
|
279
|
+
(key === "unixSockets" && !capabilityPath(item, "host")) ||
|
|
280
|
+
(key === "namedSockets" && !HOST_NAME.test(item)) ||
|
|
281
|
+
(key === "commands" &&
|
|
282
|
+
(item === "." || item === ".." || (item.includes("/") && !item.startsWith("/"))))
|
|
283
|
+
) {
|
|
284
|
+
throw new Error(`${field}.${key} contains invalid entries`);
|
|
285
|
+
}
|
|
286
|
+
if (entries.has(item)) throw new Error(`${field}.${key} contains duplicates`);
|
|
287
|
+
entries.add(item);
|
|
288
|
+
}
|
|
289
|
+
if (entries.size) recipients[key] = [...entries].sort();
|
|
290
|
+
}
|
|
291
|
+
return Object.keys(recipients).length ? recipients : undefined;
|
|
292
|
+
}
|
|
293
|
+
|
|
228
294
|
/** Validate each source before any of its grants can enter the union. */
|
|
229
295
|
function parseCapabilities(input: unknown, source: string): Capabilities {
|
|
230
296
|
if (input !== undefined && (input === null || typeof input !== "object" || Array.isArray(input)))
|
|
@@ -236,10 +302,17 @@ function parseCapabilities(input: unknown, source: string): Capabilities {
|
|
|
236
302
|
switch (key) {
|
|
237
303
|
case "shellSurfaces":
|
|
238
304
|
case "sessionLock":
|
|
305
|
+
case "offscreenCapture":
|
|
239
306
|
case "controlChannel":
|
|
307
|
+
case "singleInstance":
|
|
240
308
|
if (typeof value !== "boolean") throw new Error(`${field} must be a boolean`);
|
|
241
309
|
if (value) capabilities[key] = true;
|
|
242
310
|
break;
|
|
311
|
+
case "descriptorHandoff": {
|
|
312
|
+
const recipients = parseHandoff(value, field);
|
|
313
|
+
if (recipients) capabilities.descriptorHandoff = recipients;
|
|
314
|
+
break;
|
|
315
|
+
}
|
|
243
316
|
case "clipboard": {
|
|
244
317
|
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
245
318
|
throw new Error(`${field} must be an object`);
|
|
@@ -270,31 +343,38 @@ function parseCapabilities(input: unknown, source: string): Capabilities {
|
|
|
270
343
|
case "files": {
|
|
271
344
|
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
272
345
|
throw new Error(`${field} must be an object`);
|
|
346
|
+
const files: NonNullable<Capabilities["files"]> = {};
|
|
273
347
|
for (const [subKey, subVal] of Object.entries(value as Record<string, unknown>)) {
|
|
348
|
+
if (subKey === "allowBookmarks" || subKey === "readOnlyGrants") {
|
|
349
|
+
if (typeof subVal !== "boolean")
|
|
350
|
+
throw new Error(`${field}.${subKey} must be a boolean`);
|
|
351
|
+
if (subKey === "allowBookmarks" && !subVal) files.allowBookmarks = false;
|
|
352
|
+
if (subKey === "readOnlyGrants" && subVal) files.readOnlyGrants = true;
|
|
353
|
+
continue;
|
|
354
|
+
}
|
|
274
355
|
if (subKey !== "directories") throw new Error(`Unknown capability: ${field}.${subKey}`);
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
if (
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
dirs.push({ path: record.path, mode: record.mode });
|
|
356
|
+
const dirs = parseDirectoryGrants(subVal, `${field}.directories`);
|
|
357
|
+
if (dirs.length) files.directories = dirs;
|
|
358
|
+
}
|
|
359
|
+
if (Object.keys(files).length) capabilities.files = files;
|
|
360
|
+
break;
|
|
361
|
+
}
|
|
362
|
+
case "systemFiles": {
|
|
363
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
364
|
+
throw new Error(`${field} must be an object`);
|
|
365
|
+
const systemFiles: NonNullable<Capabilities["systemFiles"]> = {};
|
|
366
|
+
for (const [subKey, subVal] of Object.entries(value as Record<string, unknown>)) {
|
|
367
|
+
if (subKey === "directories") {
|
|
368
|
+
const dirs = parseDirectoryGrants(subVal, `${field}.directories`);
|
|
369
|
+
if (dirs.length) systemFiles.directories = dirs;
|
|
370
|
+
} else {
|
|
371
|
+
const flag = systemFileFlags.find(candidate => candidate === subKey);
|
|
372
|
+
if (!flag) throw new Error(`Unknown capability: ${field}.${subKey}`);
|
|
373
|
+
if (typeof subVal !== "boolean") throw new Error(`${field}.${flag} must be a boolean`);
|
|
374
|
+
if (subVal) systemFiles[flag] = true;
|
|
295
375
|
}
|
|
296
|
-
if (dirs.length) capabilities.files = { directories: dirs };
|
|
297
376
|
}
|
|
377
|
+
if (Object.keys(systemFiles).length) capabilities.systemFiles = systemFiles;
|
|
298
378
|
break;
|
|
299
379
|
}
|
|
300
380
|
case "network": {
|
|
@@ -409,13 +489,14 @@ function parseCapabilities(input: unknown, source: string): Capabilities {
|
|
|
409
489
|
case "imagePrefixes":
|
|
410
490
|
case "unixSockets":
|
|
411
491
|
case "commands":
|
|
492
|
+
case "namedImagePrefixes":
|
|
412
493
|
case "namedSockets": {
|
|
413
494
|
if (!Array.isArray(value)) throw new Error(`${field} must be an array`);
|
|
414
495
|
const entries = new Set<string>();
|
|
415
496
|
for (const item of value as unknown[]) {
|
|
416
497
|
if (
|
|
417
498
|
!capabilityString(item) ||
|
|
418
|
-
(key === "namedSockets" && !HOST_NAME.test(item)) ||
|
|
499
|
+
((key === "namedSockets" || key === "namedImagePrefixes") && !HOST_NAME.test(item)) ||
|
|
419
500
|
((key === "imagePrefixes" || key === "unixSockets") && !capabilityPath(item, "host"))
|
|
420
501
|
)
|
|
421
502
|
throw new Error(`${field} contains invalid entries`);
|
|
@@ -429,23 +510,25 @@ function parseCapabilities(input: unknown, source: string): Capabilities {
|
|
|
429
510
|
throw new Error(`Unknown capability: ${field}`);
|
|
430
511
|
}
|
|
431
512
|
}
|
|
513
|
+
for (const key of handoffKeys) {
|
|
514
|
+
if (capabilities.descriptorHandoff?.[key]?.some(entry => !capabilities[key]?.includes(entry)))
|
|
515
|
+
throw new Error(`${source}.descriptorHandoff.${key} must also be declared in ${key}`);
|
|
516
|
+
}
|
|
432
517
|
return capabilities;
|
|
433
518
|
}
|
|
434
519
|
|
|
435
520
|
/**
|
|
436
521
|
* Build-time overlays may grant `shellSurfaces: true`, sealing that grant into the package.
|
|
437
|
-
* Only the base package may
|
|
438
|
-
*
|
|
522
|
+
* Only the base package may enable `sessionLock` or `singleInstance`. A runtime
|
|
523
|
+
* `--extensions-overlay` cannot add those flags or shell surface authority.
|
|
439
524
|
*/
|
|
440
525
|
function capabilityOverlay(input: unknown, source: string): Capabilities {
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
throw new Error(`${source}.sessionLock: true may only be declared in base package.json`);
|
|
448
|
-
return parseCapabilities(input, source);
|
|
526
|
+
const capabilities = parseCapabilities(input, source);
|
|
527
|
+
for (const key of ["sessionLock", "singleInstance"] as const) {
|
|
528
|
+
if (capabilities[key])
|
|
529
|
+
throw new Error(`${source}.${key}: true may only be declared in base package.json`);
|
|
530
|
+
}
|
|
531
|
+
return capabilities;
|
|
449
532
|
}
|
|
450
533
|
|
|
451
534
|
async function mergeCapabilities(
|
|
@@ -467,28 +550,57 @@ async function mergeCapabilities(
|
|
|
467
550
|
sources.push(capabilityOverlay(overlay, source));
|
|
468
551
|
}
|
|
469
552
|
const merged: Capabilities = {};
|
|
470
|
-
for (const
|
|
553
|
+
for (const source of sources.slice(1)) {
|
|
554
|
+
for (const key of handoffKeys) {
|
|
555
|
+
if (
|
|
556
|
+
source.descriptorHandoff?.[key]?.some(
|
|
557
|
+
entry => !base.descriptorHandoff?.[key]?.includes(entry),
|
|
558
|
+
)
|
|
559
|
+
)
|
|
560
|
+
throw new Error(`overlays cannot grant capabilities.descriptorHandoff.${key}`);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
if (base.descriptorHandoff) merged.descriptorHandoff = base.descriptorHandoff;
|
|
564
|
+
for (const key of ["shellSurfaces", "offscreenCapture", "controlChannel"] as const)
|
|
471
565
|
if (sources.some(source => source[key])) merged[key] = true;
|
|
472
566
|
if (base.sessionLock) merged.sessionLock = true;
|
|
473
|
-
|
|
567
|
+
if (base.singleInstance) merged.singleInstance = true;
|
|
568
|
+
for (const key of [
|
|
569
|
+
"imagePrefixes",
|
|
570
|
+
"namedImagePrefixes",
|
|
571
|
+
"unixSockets",
|
|
572
|
+
"namedSockets",
|
|
573
|
+
"commands",
|
|
574
|
+
] as const) {
|
|
474
575
|
const union = new Set(sources.flatMap(source => source[key] ?? []));
|
|
475
576
|
if (union.size) merged[key] = [...union].sort();
|
|
476
577
|
}
|
|
477
578
|
if (sources.some(source => source.clipboard?.read)) merged.clipboard = { read: true };
|
|
478
579
|
const sqliteDatabases = new Set(sources.flatMap(source => source.sqlite?.databases ?? []));
|
|
479
580
|
if (sqliteDatabases.size) merged.sqlite = { databases: [...sqliteDatabases].sort() };
|
|
480
|
-
const
|
|
481
|
-
|
|
482
|
-
const
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
}
|
|
581
|
+
const mergeDirs = (key: "files" | "systemFiles") => {
|
|
582
|
+
const dirs = new Map<string, "read" | "readwrite">();
|
|
583
|
+
for (const { path: dirPath, mode } of sources.flatMap(
|
|
584
|
+
source => source[key]?.directories ?? [],
|
|
585
|
+
)) {
|
|
586
|
+
if (!dirs.has(dirPath) || mode === "readwrite") dirs.set(dirPath, mode);
|
|
587
|
+
}
|
|
588
|
+
return [...dirs.entries()]
|
|
589
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
590
|
+
.map(([dirPath, mode]) => ({ path: dirPath, mode }));
|
|
591
|
+
};
|
|
592
|
+
const files: NonNullable<Capabilities["files"]> = {};
|
|
593
|
+
const fileDirs = mergeDirs("files");
|
|
594
|
+
if (fileDirs.length) files.directories = fileDirs;
|
|
595
|
+
if (sources.some(source => source.files?.allowBookmarks === false)) files.allowBookmarks = false;
|
|
596
|
+
if (sources.some(source => source.files?.readOnlyGrants)) files.readOnlyGrants = true;
|
|
597
|
+
if (Object.keys(files).length) merged.files = files;
|
|
598
|
+
const systemFiles: NonNullable<Capabilities["systemFiles"]> = {};
|
|
599
|
+
const systemDirs = mergeDirs("systemFiles");
|
|
600
|
+
if (systemDirs.length) systemFiles.directories = systemDirs;
|
|
601
|
+
for (const flag of systemFileFlags)
|
|
602
|
+
if (sources.some(source => source.systemFiles?.[flag])) systemFiles[flag] = true;
|
|
603
|
+
if (Object.keys(systemFiles).length) merged.systemFiles = systemFiles;
|
|
492
604
|
const networkSources = sources
|
|
493
605
|
.map(source => source.network)
|
|
494
606
|
.filter((net): net is NonNullable<Capabilities["network"]> => net !== undefined);
|
|
@@ -576,6 +688,12 @@ async function mergeCapabilities(
|
|
|
576
688
|
return Object.keys(merged).length ? merged : undefined;
|
|
577
689
|
}
|
|
578
690
|
|
|
691
|
+
function parseResourceProfile(input: unknown): "extended" | undefined {
|
|
692
|
+
if (input === undefined || input === "standard") return undefined;
|
|
693
|
+
if (input === "extended") return "extended";
|
|
694
|
+
throw new Error('package.json zgui.resourceProfile must be "standard" or "extended"');
|
|
695
|
+
}
|
|
696
|
+
|
|
579
697
|
const WINDOW_KEYS = new Set(["title", "width", "height", "minWidth", "minHeight", "resizable"]);
|
|
580
698
|
|
|
581
699
|
function parseWindowDeclaration(input: unknown): WindowDeclaration | undefined {
|
package/src/package-app.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { existsSync } from "node:fs";
|
|
|
3
3
|
import { chmod, copyFile, cp, mkdir, realpath, rm, writeFile } from "node:fs/promises";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { buildWithResolvedHost } from "./build.ts";
|
|
6
|
+
import { preflightBundle } from "./host.ts";
|
|
6
7
|
import { packagedSdkRoot, workspaceRoot } from "./sdk.ts";
|
|
7
8
|
|
|
8
9
|
const DISTRIBUTED_LICENSE_FILES = ["LICENSE", "NOTICE", "THIRD_PARTY_NOTICES.md"] as const;
|
|
@@ -23,12 +24,28 @@ function sanitizeDesktopField(value: string): string {
|
|
|
23
24
|
return value.replace(/[\r\n]+/g, " ").trim();
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
function buildLauncherScript(
|
|
27
|
-
|
|
27
|
+
function buildLauncherScript({
|
|
28
|
+
pureShell = false,
|
|
29
|
+
headless = false,
|
|
30
|
+
}: {
|
|
31
|
+
pureShell?: boolean;
|
|
32
|
+
headless?: boolean;
|
|
33
|
+
}): string {
|
|
34
|
+
const extraFlags = `${pureShell ? " --pure-shell" : ""}${headless ? " --headless" : ""}`;
|
|
28
35
|
return `#!/usr/bin/env sh
|
|
29
36
|
set -eu
|
|
30
37
|
DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
|
31
|
-
|
|
38
|
+
# Preserve the launcher diagnostics. A leading -- forces literal app arguments.
|
|
39
|
+
case "\${1-}:$#" in
|
|
40
|
+
--help:1|-h:1|--version:1|-V:1)
|
|
41
|
+
exec "$DIR/bin/zgui-host" "$@" ;;
|
|
42
|
+
--version:2|-V:2)
|
|
43
|
+
if [ "$2" = --json ]; then exec "$DIR/bin/zgui-host" "$@"; fi ;;
|
|
44
|
+
--exit-after-ms:2)
|
|
45
|
+
exec "$DIR/bin/zgui-host" --bundle "$DIR/bundle"${extraFlags} "$@" ;;
|
|
46
|
+
--:*) shift ;;
|
|
47
|
+
esac
|
|
48
|
+
exec "$DIR/bin/zgui-host" --bundle "$DIR/bundle"${extraFlags} -- "$@"
|
|
32
49
|
`;
|
|
33
50
|
}
|
|
34
51
|
|
|
@@ -41,11 +58,19 @@ function buildDesktopEntry({
|
|
|
41
58
|
id: string;
|
|
42
59
|
execPath: string;
|
|
43
60
|
}): string {
|
|
61
|
+
// Desktop Entry escaping precedes Exec's quoted-argument escaping.
|
|
62
|
+
const executable = execPath
|
|
63
|
+
.replaceAll("%", "%%")
|
|
64
|
+
.replace(/["`$\\]/g, "\\$&")
|
|
65
|
+
.replaceAll("\\", "\\\\")
|
|
66
|
+
.replaceAll("\n", "\\n")
|
|
67
|
+
.replaceAll("\r", "\\r")
|
|
68
|
+
.replaceAll("\t", "\\t");
|
|
44
69
|
return `[Desktop Entry]
|
|
45
70
|
Type=Application
|
|
46
71
|
Version=1.0
|
|
47
72
|
Name=${sanitizeDesktopField(name)}
|
|
48
|
-
Exec
|
|
73
|
+
Exec="${executable}" -- %F
|
|
49
74
|
Terminal=false
|
|
50
75
|
Categories=Utility;
|
|
51
76
|
StartupWMClass=${sanitizeDesktopField(id)}
|
|
@@ -59,6 +84,7 @@ export async function packageApplication(
|
|
|
59
84
|
appDirectory = path.join(root, "apps/examples", app),
|
|
60
85
|
out = path.join(appDirectory, "dist-package"),
|
|
61
86
|
bytecode = false,
|
|
87
|
+
preflight = "auto",
|
|
62
88
|
hostRoot,
|
|
63
89
|
hostExecutable,
|
|
64
90
|
hostSearchFrom,
|
|
@@ -67,18 +93,20 @@ export async function packageApplication(
|
|
|
67
93
|
cssModuleInclude,
|
|
68
94
|
desktopEntry = false,
|
|
69
95
|
pureShell = false,
|
|
96
|
+
headless = false,
|
|
70
97
|
signal,
|
|
71
98
|
}: PackageApplicationOptions = {},
|
|
72
99
|
): Promise<PackagedApplication> {
|
|
73
100
|
signal?.throwIfAborted();
|
|
74
101
|
const resolvedAppDir = path.resolve(appDirectory);
|
|
75
102
|
const outputDir = path.resolve(out);
|
|
76
|
-
const { application, resolveHost } = await buildWithResolvedHost(
|
|
103
|
+
const { application, resolveHost, preflightedDirectory } = await buildWithResolvedHost(
|
|
77
104
|
app,
|
|
78
105
|
{
|
|
79
106
|
root,
|
|
80
107
|
appDirectory: resolvedAppDir,
|
|
81
108
|
bytecode,
|
|
109
|
+
preflight,
|
|
82
110
|
hostSearchFrom,
|
|
83
111
|
extraCapabilities,
|
|
84
112
|
capabilitiesFile,
|
|
@@ -95,12 +123,15 @@ export async function packageApplication(
|
|
|
95
123
|
);
|
|
96
124
|
}
|
|
97
125
|
|
|
126
|
+
const bundleSource = preflightedDirectory ?? (await realpath(dist));
|
|
98
127
|
const host = await resolveHost();
|
|
99
128
|
const abi = host.abi;
|
|
100
129
|
if (!abi) throw new Error("Resolved zgui-host did not report ABI metadata");
|
|
101
130
|
signal?.throwIfAborted();
|
|
131
|
+
if (preflight === "auto" && preflightedDirectory === undefined && abi.preflight === true) {
|
|
132
|
+
await preflightBundle(host, bundleSource, { signal });
|
|
133
|
+
}
|
|
102
134
|
|
|
103
|
-
const bundleSource = await realpath(dist);
|
|
104
135
|
const stagingDir = `${outputDir}.staging-${process.pid}-${Date.now()}`;
|
|
105
136
|
const binDir = path.join(stagingDir, "bin");
|
|
106
137
|
const bundleDir = path.join(stagingDir, "bundle");
|
|
@@ -121,7 +152,7 @@ export async function packageApplication(
|
|
|
121
152
|
await copyFile(source, path.join(licensesDir, filename));
|
|
122
153
|
licensePaths.push(`licenses/${filename}`);
|
|
123
154
|
}
|
|
124
|
-
await writeFile(launcherPath, buildLauncherScript(
|
|
155
|
+
await writeFile(launcherPath, buildLauncherScript({ pureShell, headless }), "utf8");
|
|
125
156
|
await chmod(launcherPath, 0o755);
|
|
126
157
|
|
|
127
158
|
if (desktopEntry) {
|
package/src/preview.ts
CHANGED
|
@@ -25,6 +25,9 @@ export async function previewApplication(
|
|
|
25
25
|
signal,
|
|
26
26
|
onOutput,
|
|
27
27
|
bytecode = false,
|
|
28
|
+
preflight,
|
|
29
|
+
maxJsHeapUsedBytes,
|
|
30
|
+
maxJsHeapPostDisposeBytes,
|
|
28
31
|
...buildOptions
|
|
29
32
|
}: PreviewApplicationOptions = {},
|
|
30
33
|
): Promise<number> {
|
|
@@ -41,12 +44,17 @@ export async function previewApplication(
|
|
|
41
44
|
"--out",
|
|
42
45
|
output,
|
|
43
46
|
];
|
|
47
|
+
if (maxJsHeapUsedBytes !== undefined)
|
|
48
|
+
args.push("--max-js-heap-used-bytes", String(maxJsHeapUsedBytes));
|
|
49
|
+
if (maxJsHeapPostDisposeBytes !== undefined)
|
|
50
|
+
args.push("--max-js-heap-post-dispose-bytes", String(maxJsHeapPostDisposeBytes));
|
|
44
51
|
onOutput?.(output);
|
|
45
52
|
if (watch)
|
|
46
53
|
return devApplication(app, {
|
|
47
54
|
...buildOptions,
|
|
48
55
|
root,
|
|
49
56
|
appDirectory,
|
|
57
|
+
preflight,
|
|
50
58
|
...(explicitHostRoot === undefined ? {} : { hostRoot: explicitHostRoot }),
|
|
51
59
|
hostExecutable,
|
|
52
60
|
mode: "preview",
|
|
@@ -58,7 +66,7 @@ export async function previewApplication(
|
|
|
58
66
|
resolveHost,
|
|
59
67
|
} = await buildWithResolvedHost(
|
|
60
68
|
app,
|
|
61
|
-
{ ...buildOptions, root, appDirectory, bytecode },
|
|
69
|
+
{ ...buildOptions, root, appDirectory, bytecode, preflight },
|
|
62
70
|
{ hostRoot: explicitHostRoot, hostExecutable, signal },
|
|
63
71
|
);
|
|
64
72
|
const host = await resolveHost();
|
package/src/public-api.d.ts
CHANGED
|
@@ -13,6 +13,20 @@ export type FileDirectoryGrant = {
|
|
|
13
13
|
|
|
14
14
|
export type FilesCapabilities = {
|
|
15
15
|
directories?: FileDirectoryGrant[];
|
|
16
|
+
/** Defaults to true for legacy gesture-authorized bookmarks. */
|
|
17
|
+
allowBookmarks?: boolean;
|
|
18
|
+
/** Prevent the persistence or restoration of readwrite workspace grants. */
|
|
19
|
+
readOnlyGrants?: boolean;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type SystemFilesCapabilities = {
|
|
23
|
+
read?: boolean;
|
|
24
|
+
write?: boolean;
|
|
25
|
+
trash?: boolean;
|
|
26
|
+
volumes?: boolean;
|
|
27
|
+
thumbnails?: boolean;
|
|
28
|
+
openExternal?: boolean;
|
|
29
|
+
directories?: FileDirectoryGrant[];
|
|
16
30
|
};
|
|
17
31
|
|
|
18
32
|
export type NetworkOriginRule = {
|
|
@@ -28,17 +42,29 @@ export type NetworkCapabilities = {
|
|
|
28
42
|
allowPrivateNetworks?: boolean;
|
|
29
43
|
};
|
|
30
44
|
|
|
45
|
+
export interface DescriptorHandoffCapabilities {
|
|
46
|
+
readonly unixSockets?: readonly string[];
|
|
47
|
+
readonly namedSockets?: readonly string[];
|
|
48
|
+
readonly commands?: readonly string[];
|
|
49
|
+
}
|
|
50
|
+
|
|
31
51
|
export type Capabilities = {
|
|
32
52
|
shellSurfaces?: boolean;
|
|
33
53
|
sessionLock?: boolean;
|
|
54
|
+
offscreenCapture?: boolean;
|
|
34
55
|
imagePrefixes?: string[];
|
|
56
|
+
namedImagePrefixes?: string[];
|
|
35
57
|
unixSockets?: string[];
|
|
36
58
|
namedSockets?: string[];
|
|
37
59
|
commands?: string[];
|
|
60
|
+
descriptorHandoff?: Readonly<DescriptorHandoffCapabilities>;
|
|
38
61
|
controlChannel?: boolean;
|
|
62
|
+
/** Base package launch policy; overlays cannot enable this. */
|
|
63
|
+
singleInstance?: boolean;
|
|
39
64
|
clipboard?: ClipboardCapabilities;
|
|
40
65
|
sqlite?: SqliteCapabilities;
|
|
41
66
|
files?: FilesCapabilities;
|
|
67
|
+
systemFiles?: SystemFilesCapabilities;
|
|
42
68
|
network?: NetworkCapabilities;
|
|
43
69
|
};
|
|
44
70
|
|
|
@@ -53,6 +79,7 @@ export type WindowDeclaration = {
|
|
|
53
79
|
minHeight?: number;
|
|
54
80
|
resizable?: boolean;
|
|
55
81
|
};
|
|
82
|
+
export type ResourceProfile = "standard" | "extended";
|
|
56
83
|
export type ResolvedApplication = { app: string; appDirectory: string; root: string };
|
|
57
84
|
export type PublishedApplication = { dist: string; manifest: Manifest };
|
|
58
85
|
|
|
@@ -70,6 +97,7 @@ export type Manifest = {
|
|
|
70
97
|
assets: string[];
|
|
71
98
|
fonts: FontDeclaration[];
|
|
72
99
|
window?: WindowDeclaration;
|
|
100
|
+
resourceProfile?: ResourceProfile;
|
|
73
101
|
capabilities?: Capabilities;
|
|
74
102
|
styleSystem: {
|
|
75
103
|
name: "lightningcss";
|
|
@@ -115,6 +143,7 @@ export interface BuildApplicationOptions {
|
|
|
115
143
|
appDirectory?: string;
|
|
116
144
|
development?: boolean;
|
|
117
145
|
bytecode?: boolean;
|
|
146
|
+
preflight?: boolean | "auto" | undefined;
|
|
118
147
|
hostRoot?: string;
|
|
119
148
|
hostExecutable?: string;
|
|
120
149
|
hostSearchFrom?: readonly string[] | undefined;
|
|
@@ -150,7 +179,10 @@ export type DevMode = "desktop" | "preview";
|
|
|
150
179
|
|
|
151
180
|
export interface DevApplicationOptions extends Omit<BuildApplicationOptions, "development"> {
|
|
152
181
|
strictTypecheck?: boolean | undefined;
|
|
182
|
+
headless?: boolean | undefined;
|
|
153
183
|
hostArgs?: string[];
|
|
184
|
+
/** Working directory for the native process, independent of bundle and Cargo paths. */
|
|
185
|
+
hostCwd?: string;
|
|
154
186
|
hostRoot?: string;
|
|
155
187
|
hostExecutable?: string;
|
|
156
188
|
mode?: DevMode;
|
|
@@ -166,6 +198,8 @@ export interface PreviewApplicationOptions extends Omit<
|
|
|
166
198
|
fixture?: string;
|
|
167
199
|
scenario?: string;
|
|
168
200
|
out?: string;
|
|
201
|
+
maxJsHeapUsedBytes?: number | undefined;
|
|
202
|
+
maxJsHeapPostDisposeBytes?: number | undefined;
|
|
169
203
|
onOutput?: (directory: string) => void;
|
|
170
204
|
}
|
|
171
205
|
|
|
@@ -190,6 +224,7 @@ export interface NativeHostAbi {
|
|
|
190
224
|
bytecodeFormat?: string | undefined;
|
|
191
225
|
quickjsAbi?: string | undefined;
|
|
192
226
|
styleProfile?: string | undefined;
|
|
227
|
+
preflight?: boolean | undefined;
|
|
193
228
|
}
|
|
194
229
|
|
|
195
230
|
export interface ResolveNativeHostOptions {
|
|
@@ -223,6 +258,7 @@ export interface PackageApplicationOptions extends Omit<BuildApplicationOptions,
|
|
|
223
258
|
hostExecutable?: string | undefined;
|
|
224
259
|
desktopEntry?: boolean | undefined;
|
|
225
260
|
pureShell?: boolean | undefined;
|
|
261
|
+
headless?: boolean | undefined;
|
|
226
262
|
signal?: AbortSignal | undefined;
|
|
227
263
|
}
|
|
228
264
|
|
package/src/publication.ts
CHANGED
|
@@ -70,6 +70,7 @@ export async function activatePublication(
|
|
|
70
70
|
export async function publishGeneration(
|
|
71
71
|
appDirectory: string,
|
|
72
72
|
files: ReadonlyMap<string, Uint8Array>,
|
|
73
|
+
options?: { verify?: (packageDirectory: string) => Promise<void> },
|
|
73
74
|
): Promise<string> {
|
|
74
75
|
const generations = path.join(appDirectory, ".zgui-generations");
|
|
75
76
|
await mkdir(generations, { recursive: true });
|
|
@@ -86,6 +87,7 @@ export async function publishGeneration(
|
|
|
86
87
|
await writeFile(destination, bytes, { flag: "wx" });
|
|
87
88
|
}
|
|
88
89
|
await rename(staging, generation);
|
|
90
|
+
await options?.verify?.(generation);
|
|
89
91
|
const dist = await activatePublication(appDirectory, generation);
|
|
90
92
|
published = true;
|
|
91
93
|
return dist;
|