@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.
Files changed (45) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +95 -0
  3. package/README.md +84 -2
  4. package/THIRD_PARTY_NOTICES.md +37 -0
  5. package/package.json +64 -4
  6. package/sdk/Cargo.lock +6813 -0
  7. package/sdk/LICENSE +202 -0
  8. package/sdk/NOTICE +95 -0
  9. package/sdk/THIRD_PARTY_NOTICES.md +37 -0
  10. package/sdk/bun.lock +539 -0
  11. package/sdk/package.json +60 -0
  12. package/sdk/preview/fixtures/empty.json +6 -0
  13. package/sdk/preview/fonts/NotoSans-LICENSE.txt +94 -0
  14. package/sdk/preview/fonts/NotoSans-Regular.ttf +0 -0
  15. package/sdk/preview/fonts/NotoSansCJK-LICENSE.txt +92 -0
  16. package/sdk/preview/fonts/NotoSansCJKsc-Regular.otf +0 -0
  17. package/sdk/preview/fonts/PROVENANCE.md +25 -0
  18. package/sdk/preview/fonts/fonts.json +60 -0
  19. package/sdk/preview/profiles/default.json +32 -0
  20. package/sdk/preview/scenarios/counter-capture.json +9 -0
  21. package/sdk/smoke/solid-smoke.ts +53 -0
  22. package/sdk/smoke/tsconfig.smoke.json +21 -0
  23. package/src/application.ts +70 -0
  24. package/src/build.ts +963 -0
  25. package/src/check-smoke.ts +8 -0
  26. package/src/compiler.ts +701 -0
  27. package/src/css.ts +337 -0
  28. package/src/dev.ts +164 -0
  29. package/src/host.ts +578 -0
  30. package/src/identity.ts +60 -0
  31. package/src/index.ts +27 -0
  32. package/src/internal.ts +20 -0
  33. package/src/native-process.ts +178 -0
  34. package/src/package-app.ts +178 -0
  35. package/src/preview-check.ts +267 -0
  36. package/src/preview.ts +69 -0
  37. package/src/public-api.d.ts +258 -0
  38. package/src/publication.ts +108 -0
  39. package/src/sdk-packages.ts +376 -0
  40. package/src/sdk.ts +11 -0
  41. package/src/smoke.ts +99 -0
  42. package/src/sync-ui-resources.ts +171 -0
  43. package/src/typecheck.ts +177 -0
  44. package/src/validate.ts +1085 -0
  45. package/src/watch.ts +531 -0
@@ -0,0 +1,177 @@
1
+ import type { Dirent } from "node:fs";
2
+ import { readdir, access } from "node:fs/promises";
3
+ import { createRequire } from "node:module";
4
+ import path from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ import { syncCssModuleTypes } from "./css.ts";
7
+ import { ensureSdkPackagesBuilt } from "./sdk-packages.ts";
8
+
9
+ const compilerCli = path.join(
10
+ path.dirname(createRequire(import.meta.url).resolve("tsrs/package.json")),
11
+ "bin/tsrs",
12
+ );
13
+ const stdio = { stdin: "ignore", stdout: "pipe", stderr: "pipe" } as const;
14
+
15
+ function command(configPath: string): string[] {
16
+ return [
17
+ process.execPath,
18
+ compilerCli,
19
+ "--project",
20
+ path.resolve(configPath),
21
+ "--noEmit",
22
+ "--pretty",
23
+ "false",
24
+ ];
25
+ }
26
+
27
+ export function typecheckProject(configPath: string): void {
28
+ const child = Bun.spawnSync(command(configPath), stdio);
29
+ if (!child.success) {
30
+ const diagnostics = `${child.stdout.toString()}${child.stderr.toString()}`.trim();
31
+ throw new Error(diagnostics || `TypeScript exited with ${child.signalCode ?? child.exitCode}`);
32
+ }
33
+ }
34
+
35
+ // Dev compilation must leave the event loop free for file changes and shutdown.
36
+ export async function typecheckProjectAsync(
37
+ configPath: string,
38
+ { signal }: { signal?: AbortSignal } = {},
39
+ ): Promise<void> {
40
+ signal?.throwIfAborted();
41
+ const child = Bun.spawn(command(configPath), stdio);
42
+ let killTimer: ReturnType<typeof setTimeout> | undefined;
43
+ const abort = () => {
44
+ child.kill("SIGTERM");
45
+ killTimer = setTimeout(() => child.kill("SIGKILL"), 1000);
46
+ killTimer.unref();
47
+ };
48
+ signal?.addEventListener("abort", abort, { once: true });
49
+ if (signal?.aborted) abort();
50
+ try {
51
+ const [code, stdout, stderr] = await Promise.all([
52
+ child.exited,
53
+ new Response(child.stdout).text(),
54
+ new Response(child.stderr).text(),
55
+ ]);
56
+ if (code !== 0 || child.signalCode) {
57
+ throw new Error(
58
+ `${stdout}${stderr}`.trim() || `TypeScript exited with ${child.signalCode ?? code}`,
59
+ );
60
+ }
61
+ } finally {
62
+ clearTimeout(killTimer);
63
+ signal?.removeEventListener("abort", abort);
64
+ signal?.throwIfAborted();
65
+ }
66
+ }
67
+
68
+ async function fileExists(filePath: string): Promise<boolean> {
69
+ try {
70
+ await access(filePath);
71
+ return true;
72
+ } catch (error) {
73
+ if ((error as NodeJS.ErrnoException).code === "ENOENT") return false;
74
+ throw error;
75
+ }
76
+ }
77
+
78
+ async function readSortedEntries(directory: string): Promise<Dirent[]> {
79
+ try {
80
+ const entries = await readdir(directory, { withFileTypes: true });
81
+ return entries.sort((a, b) => a.name.localeCompare(b.name));
82
+ } catch (error) {
83
+ if ((error as NodeJS.ErrnoException).code === "ENOENT") return [];
84
+ throw error;
85
+ }
86
+ }
87
+
88
+ async function discoverPackageConfigs(root: string): Promise<string[]> {
89
+ const packagesDir = path.join(root, "packages");
90
+ const configs: string[] = [];
91
+ for (const entry of await readSortedEntries(packagesDir)) {
92
+ if (!entry.isDirectory()) continue;
93
+ const pkgDir = path.join(packagesDir, entry.name);
94
+ for (const candidate of ["tsconfig.json", "tsconfig.native.json"]) {
95
+ const configPath = path.join(pkgDir, candidate);
96
+ if (await fileExists(configPath)) {
97
+ configs.push(configPath);
98
+ break;
99
+ }
100
+ }
101
+ }
102
+ return configs;
103
+ }
104
+
105
+ async function discoverTypeTestConfigs(root: string): Promise<string[]> {
106
+ const typesDir = path.join(root, "tests/types");
107
+ return (await readSortedEntries(typesDir))
108
+ .filter(entry => entry.isFile() && /^tsconfig.*\.json$/.test(entry.name))
109
+ .map(entry => path.join(typesDir, entry.name));
110
+ }
111
+
112
+ async function discoverAppConfigs(root: string, appFilter?: string): Promise<string[]> {
113
+ const configs: string[] = [];
114
+ for (const group of ["apps/devtools", "apps/examples"]) {
115
+ const groupDir = path.join(root, group);
116
+ for (const entry of await readSortedEntries(groupDir)) {
117
+ if (!entry.isDirectory()) continue;
118
+ if (appFilter && entry.name !== appFilter && `${group}/${entry.name}` !== appFilter) {
119
+ continue;
120
+ }
121
+ const appDir = path.join(groupDir, entry.name);
122
+ const config = path.join(appDir, "tsconfig.json");
123
+ if (!(await fileExists(config))) continue;
124
+ // Run outside ENOENT guard so CSS Module type generation failures surface instead of silently skipping.
125
+ await syncCssModuleTypes(appDir, { root });
126
+ configs.push(config);
127
+ }
128
+ }
129
+ if (appFilter && configs.length === 0) {
130
+ const directDir = path.resolve(root, appFilter);
131
+ const directConfig = path.join(directDir, "tsconfig.json");
132
+ if (await fileExists(directConfig)) {
133
+ await syncCssModuleTypes(directDir, { root });
134
+ configs.push(directConfig);
135
+ } else {
136
+ throw new Error(`No app tsconfig.json found for --app ${appFilter}`);
137
+ }
138
+ }
139
+ return configs;
140
+ }
141
+
142
+ export async function typecheckWorkspace(
143
+ root = fileURLToPath(new URL("../../../", import.meta.url)),
144
+ { app }: { app?: string } = {},
145
+ ): Promise<void> {
146
+ await ensureSdkPackagesBuilt(root);
147
+ const configs = app
148
+ ? await discoverAppConfigs(root, app)
149
+ : [
150
+ ...(await discoverPackageConfigs(root)),
151
+ ...(await discoverTypeTestConfigs(root)),
152
+ ...(await discoverAppConfigs(root)),
153
+ ];
154
+ for (const config of configs) {
155
+ typecheckProject(config);
156
+ console.log(`Typechecked ${path.relative(root, config)}`);
157
+ }
158
+ }
159
+
160
+ if (import.meta.main) {
161
+ try {
162
+ const args = process.argv.slice(2);
163
+ let app: string | undefined;
164
+ for (let i = 0; i < args.length; i++) {
165
+ if (args[i] === "--app") {
166
+ app = args[++i];
167
+ if (!app) throw new Error("--app requires an application name or directory");
168
+ } else {
169
+ throw new Error(`Unknown option: ${args[i]}`);
170
+ }
171
+ }
172
+ await typecheckWorkspace(undefined, { app });
173
+ } catch (error) {
174
+ console.error(error instanceof Error ? error.message : String(error));
175
+ process.exitCode = 1;
176
+ }
177
+ }