@hewel/zgui-build 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/NOTICE +95 -0
- package/README.md +84 -2
- package/THIRD_PARTY_NOTICES.md +37 -0
- package/package.json +64 -4
- package/sdk/Cargo.lock +6813 -0
- package/sdk/LICENSE +202 -0
- package/sdk/NOTICE +95 -0
- package/sdk/THIRD_PARTY_NOTICES.md +37 -0
- package/sdk/bun.lock +539 -0
- package/sdk/package.json +60 -0
- package/sdk/preview/fixtures/empty.json +6 -0
- package/sdk/preview/fonts/NotoSans-LICENSE.txt +94 -0
- package/sdk/preview/fonts/NotoSans-Regular.ttf +0 -0
- package/sdk/preview/fonts/NotoSansCJK-LICENSE.txt +92 -0
- package/sdk/preview/fonts/NotoSansCJKsc-Regular.otf +0 -0
- package/sdk/preview/fonts/PROVENANCE.md +25 -0
- package/sdk/preview/fonts/fonts.json +60 -0
- package/sdk/preview/profiles/default.json +32 -0
- package/sdk/preview/scenarios/counter-capture.json +9 -0
- package/sdk/smoke/solid-smoke.ts +53 -0
- package/sdk/smoke/tsconfig.smoke.json +21 -0
- package/src/application.ts +70 -0
- package/src/build.ts +963 -0
- package/src/check-smoke.ts +8 -0
- package/src/compiler.ts +701 -0
- package/src/css.ts +337 -0
- package/src/dev.ts +164 -0
- package/src/host.ts +578 -0
- package/src/identity.ts +60 -0
- package/src/index.ts +27 -0
- package/src/internal.ts +20 -0
- package/src/native-process.ts +178 -0
- package/src/package-app.ts +178 -0
- package/src/preview-check.ts +267 -0
- package/src/preview.ts +69 -0
- package/src/public-api.d.ts +258 -0
- package/src/publication.ts +108 -0
- package/src/sdk-packages.ts +376 -0
- package/src/sdk.ts +11 -0
- package/src/smoke.ts +99 -0
- package/src/sync-ui-resources.ts +171 -0
- package/src/typecheck.ts +177 -0
- package/src/validate.ts +1085 -0
- package/src/watch.ts +531 -0
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
export type ClipboardCapabilities = {
|
|
2
|
+
read?: boolean;
|
|
3
|
+
};
|
|
4
|
+
|
|
5
|
+
export type SqliteCapabilities = {
|
|
6
|
+
databases: string[];
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type FileDirectoryGrant = {
|
|
10
|
+
path: string;
|
|
11
|
+
mode: "read" | "readwrite";
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type FilesCapabilities = {
|
|
15
|
+
directories?: FileDirectoryGrant[];
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type NetworkCapabilities = {
|
|
19
|
+
origins?: string[];
|
|
20
|
+
allowInsecureHttp?: boolean;
|
|
21
|
+
allowPrivateNetworks?: boolean;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type Capabilities = {
|
|
25
|
+
shellSurfaces?: boolean;
|
|
26
|
+
sessionLock?: boolean;
|
|
27
|
+
imagePrefixes?: string[];
|
|
28
|
+
unixSockets?: string[];
|
|
29
|
+
namedSockets?: string[];
|
|
30
|
+
commands?: string[];
|
|
31
|
+
controlChannel?: boolean;
|
|
32
|
+
clipboard?: ClipboardCapabilities;
|
|
33
|
+
sqlite?: SqliteCapabilities;
|
|
34
|
+
files?: FilesCapabilities;
|
|
35
|
+
network?: NetworkCapabilities;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export type FontDeclaration = { family: string; path: string };
|
|
39
|
+
export type ChunkDeclaration = { path: string; sourceMap: string };
|
|
40
|
+
export type WorkerDeclaration = { name: string; path: string; sourceMap: string };
|
|
41
|
+
export type WindowDeclaration = {
|
|
42
|
+
title?: string;
|
|
43
|
+
width?: number;
|
|
44
|
+
height?: number;
|
|
45
|
+
minWidth?: number;
|
|
46
|
+
minHeight?: number;
|
|
47
|
+
resizable?: boolean;
|
|
48
|
+
};
|
|
49
|
+
export type ResolvedApplication = { app: string; appDirectory: string; root: string };
|
|
50
|
+
export type PublishedApplication = { dist: string; manifest: Manifest };
|
|
51
|
+
|
|
52
|
+
export type Manifest = {
|
|
53
|
+
schemaVersion: 2;
|
|
54
|
+
id: string;
|
|
55
|
+
hostApiVersion: 1;
|
|
56
|
+
entry: string;
|
|
57
|
+
sourceMap: string;
|
|
58
|
+
bytecodeFormat?: "qjs-bytecode-v1";
|
|
59
|
+
quickjsAbi?: string;
|
|
60
|
+
chunks?: ChunkDeclaration[];
|
|
61
|
+
workers?: WorkerDeclaration[];
|
|
62
|
+
styles: string[];
|
|
63
|
+
assets: string[];
|
|
64
|
+
fonts: FontDeclaration[];
|
|
65
|
+
window?: WindowDeclaration;
|
|
66
|
+
capabilities?: Capabilities;
|
|
67
|
+
styleSystem: {
|
|
68
|
+
name: "lightningcss";
|
|
69
|
+
profile: "lightningcss-v1";
|
|
70
|
+
configDigest: string;
|
|
71
|
+
};
|
|
72
|
+
artifactDigests: Record<string, string>;
|
|
73
|
+
buildId: string;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export type BuildInfo = {
|
|
77
|
+
schemaVersion: 2;
|
|
78
|
+
hostApiVersion: 1;
|
|
79
|
+
bun: string;
|
|
80
|
+
packageManager: string;
|
|
81
|
+
packages: Record<string, string>;
|
|
82
|
+
lockfile: { path: "bun.lock"; digest: string };
|
|
83
|
+
cargoLock: { path: "Cargo.lock"; digest: string };
|
|
84
|
+
engine: {
|
|
85
|
+
name: "QuickJS-NG";
|
|
86
|
+
revision: string;
|
|
87
|
+
rquickjsVersion: string;
|
|
88
|
+
rquickjsRevision: string;
|
|
89
|
+
};
|
|
90
|
+
conditions: string[];
|
|
91
|
+
target: "es2022";
|
|
92
|
+
solidRuntime: string;
|
|
93
|
+
graph: {
|
|
94
|
+
modules: string[];
|
|
95
|
+
chunks: {
|
|
96
|
+
fileName: string;
|
|
97
|
+
modules: string[];
|
|
98
|
+
imports: string[];
|
|
99
|
+
dynamicImports: string[];
|
|
100
|
+
exports: string[];
|
|
101
|
+
}[];
|
|
102
|
+
};
|
|
103
|
+
styleSystem: Manifest["styleSystem"];
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export interface BuildApplicationOptions {
|
|
107
|
+
root?: string;
|
|
108
|
+
appDirectory?: string;
|
|
109
|
+
development?: boolean;
|
|
110
|
+
bytecode?: boolean;
|
|
111
|
+
hostRoot?: string;
|
|
112
|
+
hostExecutable?: string;
|
|
113
|
+
hostSearchFrom?: readonly string[] | undefined;
|
|
114
|
+
extraCapabilities?: Capabilities;
|
|
115
|
+
capabilitiesFile?: string;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export interface ApplicationWatcher {
|
|
119
|
+
close(): Promise<void>;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export type TypecheckEvent =
|
|
123
|
+
| { status: "passed"; attemptId: string }
|
|
124
|
+
| { status: "failed"; attemptId: string; diagnostics: string };
|
|
125
|
+
|
|
126
|
+
export interface WatchApplicationOptions extends BuildApplicationOptions {
|
|
127
|
+
strictTypecheck?: boolean | undefined;
|
|
128
|
+
onSuccess?: ((result: PublishedApplication) => void) | undefined;
|
|
129
|
+
onError?: ((error: unknown) => void) | undefined;
|
|
130
|
+
onTypecheck?: ((event: TypecheckEvent) => void) | undefined;
|
|
131
|
+
signal?: AbortSignal | undefined;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export type DevMode = "desktop" | "preview";
|
|
135
|
+
|
|
136
|
+
export interface DevApplicationOptions extends Omit<BuildApplicationOptions, "development"> {
|
|
137
|
+
strictTypecheck?: boolean | undefined;
|
|
138
|
+
hostArgs?: string[];
|
|
139
|
+
hostRoot?: string;
|
|
140
|
+
hostExecutable?: string;
|
|
141
|
+
mode?: DevMode;
|
|
142
|
+
signal?: AbortSignal;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export interface PreviewApplicationOptions extends Omit<
|
|
146
|
+
DevApplicationOptions,
|
|
147
|
+
"hostArgs" | "mode"
|
|
148
|
+
> {
|
|
149
|
+
watch?: boolean;
|
|
150
|
+
profile?: string;
|
|
151
|
+
fixture?: string;
|
|
152
|
+
scenario?: string;
|
|
153
|
+
out?: string;
|
|
154
|
+
onOutput?: (directory: string) => void;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export interface NativeHostOptions {
|
|
158
|
+
root?: string | undefined;
|
|
159
|
+
signal?: AbortSignal | undefined;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export type PrepareNativeHostOptions = NativeHostOptions;
|
|
163
|
+
export type RunNativeHostOptions = NativeHostOptions;
|
|
164
|
+
|
|
165
|
+
export type NativeHostSource = "explicit" | "env" | "platform-package" | "cargo";
|
|
166
|
+
|
|
167
|
+
export interface NativeHostAbi {
|
|
168
|
+
name: "zgui-host";
|
|
169
|
+
version: string;
|
|
170
|
+
hostApiVersion: number;
|
|
171
|
+
schemaVersion: number;
|
|
172
|
+
platform: string;
|
|
173
|
+
engine?: string | undefined;
|
|
174
|
+
engineRevision?: string | undefined;
|
|
175
|
+
bytecodeFormat?: string | undefined;
|
|
176
|
+
quickjsAbi?: string | undefined;
|
|
177
|
+
styleProfile?: string | undefined;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export interface ResolveNativeHostOptions {
|
|
181
|
+
hostExecutable?: string | undefined;
|
|
182
|
+
hostRoot?: string | undefined;
|
|
183
|
+
root?: string | undefined;
|
|
184
|
+
cwd?: string | undefined;
|
|
185
|
+
env?: Record<string, string | undefined> | undefined;
|
|
186
|
+
platform?: string | undefined;
|
|
187
|
+
arch?: string | undefined;
|
|
188
|
+
searchFrom?: readonly string[] | undefined;
|
|
189
|
+
verifyAbi?: boolean | undefined;
|
|
190
|
+
allowCargoBuild?: boolean | undefined;
|
|
191
|
+
signal?: AbortSignal | undefined;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export interface ResolvedNativeHost {
|
|
195
|
+
executable: string;
|
|
196
|
+
source: NativeHostSource;
|
|
197
|
+
packageName?: string | undefined;
|
|
198
|
+
cargoRoot?: string | undefined;
|
|
199
|
+
abi?: NativeHostAbi | undefined;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export interface PackageApplicationOptions extends Omit<BuildApplicationOptions, "development"> {
|
|
203
|
+
out?: string | undefined;
|
|
204
|
+
bytecode?: boolean | undefined;
|
|
205
|
+
hostRoot?: string | undefined;
|
|
206
|
+
hostExecutable?: string | undefined;
|
|
207
|
+
desktopEntry?: boolean | undefined;
|
|
208
|
+
pureShell?: boolean | undefined;
|
|
209
|
+
signal?: AbortSignal | undefined;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export interface PackagedApplication {
|
|
213
|
+
out: string;
|
|
214
|
+
launcher: string;
|
|
215
|
+
executable: string;
|
|
216
|
+
bundle: string;
|
|
217
|
+
desktopEntry?: string | undefined;
|
|
218
|
+
host: ResolvedNativeHost;
|
|
219
|
+
manifest: Manifest;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export declare const buildApplication: (
|
|
223
|
+
app: string,
|
|
224
|
+
options?: BuildApplicationOptions,
|
|
225
|
+
) => Promise<PublishedApplication>;
|
|
226
|
+
export declare const watchApplication: (
|
|
227
|
+
app: string,
|
|
228
|
+
options?: WatchApplicationOptions,
|
|
229
|
+
) => ApplicationWatcher;
|
|
230
|
+
export declare const devApplication: (
|
|
231
|
+
app: string,
|
|
232
|
+
options?: DevApplicationOptions,
|
|
233
|
+
) => Promise<number>;
|
|
234
|
+
export declare const previewApplication: (
|
|
235
|
+
app: string,
|
|
236
|
+
options?: PreviewApplicationOptions,
|
|
237
|
+
) => Promise<number>;
|
|
238
|
+
export declare const packageApplication: (
|
|
239
|
+
app: string,
|
|
240
|
+
options?: PackageApplicationOptions,
|
|
241
|
+
) => Promise<PackagedApplication>;
|
|
242
|
+
export declare const resolveApplication: (
|
|
243
|
+
selector?: string,
|
|
244
|
+
options?: { cwd?: string; root?: string },
|
|
245
|
+
) => Promise<ResolvedApplication>;
|
|
246
|
+
export declare const prepareNativeHost: (options?: PrepareNativeHostOptions) => Promise<string>;
|
|
247
|
+
export declare const probeNativeHost: (
|
|
248
|
+
executable: string,
|
|
249
|
+
options?: { expectedHostApiVersion?: number; expectedSchemaVersion?: number },
|
|
250
|
+
) => NativeHostAbi;
|
|
251
|
+
export declare const resolveNativeHost: (
|
|
252
|
+
options?: ResolveNativeHostOptions,
|
|
253
|
+
) => Promise<ResolvedNativeHost>;
|
|
254
|
+
export declare const runNativeHost: (
|
|
255
|
+
executable: string,
|
|
256
|
+
args: readonly string[],
|
|
257
|
+
options?: RunNativeHostOptions,
|
|
258
|
+
) => Promise<number>;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { lstat, mkdir, rename, rm, symlink, writeFile } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
export const BUILD_STATUS_FILE = ".zgui-build-status.json";
|
|
6
|
+
export const NATIVE_STATUS_FILE = ".zgui-native-status.json";
|
|
7
|
+
|
|
8
|
+
export type TypecheckStatus =
|
|
9
|
+
| { status: "running"; diagnostics: null }
|
|
10
|
+
| { status: "passed"; diagnostics: null }
|
|
11
|
+
| { status: "failed"; diagnostics: string };
|
|
12
|
+
|
|
13
|
+
type BuildAttempt = {
|
|
14
|
+
schemaVersion: 1;
|
|
15
|
+
attemptId: string;
|
|
16
|
+
app: string;
|
|
17
|
+
previousDirectory: string | null;
|
|
18
|
+
typecheck?: TypecheckStatus;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type BuildStatus = BuildAttempt &
|
|
22
|
+
(
|
|
23
|
+
| { status: "building"; publicationDirectory: null; buildId: null; error: null }
|
|
24
|
+
| { status: "published"; publicationDirectory: string; buildId: string; error: null }
|
|
25
|
+
| {
|
|
26
|
+
status: "failed";
|
|
27
|
+
publicationDirectory: null;
|
|
28
|
+
buildId: null;
|
|
29
|
+
error: { code: "E_BUILD"; message: string };
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
export function resourcePath(name: string): string {
|
|
34
|
+
if (
|
|
35
|
+
!name ||
|
|
36
|
+
name.includes("\\") ||
|
|
37
|
+
name.includes("\0") ||
|
|
38
|
+
name.startsWith("/") ||
|
|
39
|
+
name.split("/").some(part => !part || part === "." || part === "..")
|
|
40
|
+
) {
|
|
41
|
+
throw new Error(`Non-canonical resource path: ${name}`);
|
|
42
|
+
}
|
|
43
|
+
return name;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export async function activatePublication(
|
|
47
|
+
appDirectory: string,
|
|
48
|
+
packageDirectory: string,
|
|
49
|
+
): Promise<string> {
|
|
50
|
+
const token = randomUUID();
|
|
51
|
+
const link = path.join(appDirectory, `.dist-${token}`);
|
|
52
|
+
const dist = path.join(appDirectory, "dist");
|
|
53
|
+
try {
|
|
54
|
+
try {
|
|
55
|
+
const existing = await lstat(dist);
|
|
56
|
+
if (!existing.isSymbolicLink())
|
|
57
|
+
throw new Error("dist must be absent or a package symlink; refusing to overwrite it");
|
|
58
|
+
} catch (error) {
|
|
59
|
+
if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
|
|
60
|
+
}
|
|
61
|
+
await symlink(path.relative(appDirectory, packageDirectory), link, "dir");
|
|
62
|
+
// Linux rename replaces the symlink atomically. Prior candidates remain pinned for active readers.
|
|
63
|
+
await rename(link, dist);
|
|
64
|
+
return dist;
|
|
65
|
+
} finally {
|
|
66
|
+
await rm(link, { force: true });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export async function publishGeneration(
|
|
71
|
+
appDirectory: string,
|
|
72
|
+
files: ReadonlyMap<string, Uint8Array>,
|
|
73
|
+
): Promise<string> {
|
|
74
|
+
const generations = path.join(appDirectory, ".zgui-generations");
|
|
75
|
+
await mkdir(generations, { recursive: true });
|
|
76
|
+
const token = randomUUID();
|
|
77
|
+
const staging = path.join(generations, `.building-${token}`);
|
|
78
|
+
const generation = path.join(generations, token);
|
|
79
|
+
let published = false;
|
|
80
|
+
try {
|
|
81
|
+
await mkdir(staging);
|
|
82
|
+
for (const [name, bytes] of files) {
|
|
83
|
+
resourcePath(name);
|
|
84
|
+
const destination = path.join(staging, name);
|
|
85
|
+
await mkdir(path.dirname(destination), { recursive: true });
|
|
86
|
+
await writeFile(destination, bytes, { flag: "wx" });
|
|
87
|
+
}
|
|
88
|
+
await rename(staging, generation);
|
|
89
|
+
const dist = await activatePublication(appDirectory, generation);
|
|
90
|
+
published = true;
|
|
91
|
+
return dist;
|
|
92
|
+
} finally {
|
|
93
|
+
await rm(staging, { recursive: true, force: true });
|
|
94
|
+
if (!published) await rm(generation, { recursive: true, force: true });
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export async function publishBuildStatus(appDirectory: string, status: BuildStatus): Promise<void> {
|
|
99
|
+
const bytes = JSON.stringify(status) + "\n";
|
|
100
|
+
if (Buffer.byteLength(bytes) > 16 * 1024) throw new Error("Build status exceeds 16 KiB");
|
|
101
|
+
const temporary = path.join(appDirectory, `${BUILD_STATUS_FILE}.${randomUUID()}.tmp`);
|
|
102
|
+
try {
|
|
103
|
+
await writeFile(temporary, bytes, { flag: "wx" });
|
|
104
|
+
await rename(temporary, path.join(appDirectory, BUILD_STATUS_FILE));
|
|
105
|
+
} finally {
|
|
106
|
+
await rm(temporary, { force: true });
|
|
107
|
+
}
|
|
108
|
+
}
|