@hewel/zgui-build 0.1.2 → 0.1.3
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 +41 -2
- package/package.json +1 -1
- package/sdk/Cargo.lock +4 -4
- package/sdk/bun.lock +41 -7
- package/sdk/package.json +4 -3
- package/src/build.ts +64 -633
- package/src/css.ts +558 -25
- package/src/dev.ts +4 -3
- package/src/host.ts +253 -75
- package/src/index.ts +8 -2
- package/src/manifest-policy.ts +648 -0
- package/src/package-app.ts +21 -23
- package/src/preview-check.ts +14 -5
- package/src/preview.ts +16 -16
- package/src/public-api.d.ts +11 -0
- package/src/sdk-packages.ts +73 -14
- package/src/typecheck.ts +6 -2
- package/src/validate.ts +8 -4
- package/src/watch.ts +50 -3
- package/src/native-process.ts +0 -178
package/src/package-app.ts
CHANGED
|
@@ -2,8 +2,7 @@ import type { PackageApplicationOptions, PackagedApplication } from "./index.ts"
|
|
|
2
2
|
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
|
-
import {
|
|
6
|
-
import { EXPECTED_HOST_API_VERSION, resolveNativeHost } from "./host.ts";
|
|
5
|
+
import { buildWithResolvedHost } from "./build.ts";
|
|
7
6
|
import { packagedSdkRoot, workspaceRoot } from "./sdk.ts";
|
|
8
7
|
|
|
9
8
|
const DISTRIBUTED_LICENSE_FILES = ["LICENSE", "NOTICE", "THIRD_PARTY_NOTICES.md"] as const;
|
|
@@ -65,6 +64,7 @@ export async function packageApplication(
|
|
|
65
64
|
hostSearchFrom,
|
|
66
65
|
extraCapabilities,
|
|
67
66
|
capabilitiesFile,
|
|
67
|
+
cssModuleInclude,
|
|
68
68
|
desktopEntry = false,
|
|
69
69
|
pureShell = false,
|
|
70
70
|
signal,
|
|
@@ -73,17 +73,20 @@ export async function packageApplication(
|
|
|
73
73
|
signal?.throwIfAborted();
|
|
74
74
|
const resolvedAppDir = path.resolve(appDirectory);
|
|
75
75
|
const outputDir = path.resolve(out);
|
|
76
|
-
const {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
76
|
+
const { application, resolveHost } = await buildWithResolvedHost(
|
|
77
|
+
app,
|
|
78
|
+
{
|
|
79
|
+
root,
|
|
80
|
+
appDirectory: resolvedAppDir,
|
|
81
|
+
bytecode,
|
|
82
|
+
hostSearchFrom,
|
|
83
|
+
extraCapabilities,
|
|
84
|
+
capabilitiesFile,
|
|
85
|
+
cssModuleInclude,
|
|
86
|
+
},
|
|
87
|
+
{ hostRoot, hostExecutable, signal },
|
|
88
|
+
);
|
|
89
|
+
const { dist, manifest } = application;
|
|
87
90
|
signal?.throwIfAborted();
|
|
88
91
|
|
|
89
92
|
if (pureShell && !manifest.capabilities?.shellSurfaces && !manifest.capabilities?.sessionLock) {
|
|
@@ -92,14 +95,9 @@ export async function packageApplication(
|
|
|
92
95
|
);
|
|
93
96
|
}
|
|
94
97
|
|
|
95
|
-
const host = await
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
root,
|
|
99
|
-
cwd: resolvedAppDir,
|
|
100
|
-
searchFrom: hostSearchFrom,
|
|
101
|
-
signal,
|
|
102
|
-
});
|
|
98
|
+
const host = await resolveHost();
|
|
99
|
+
const abi = host.abi;
|
|
100
|
+
if (!abi) throw new Error("Resolved zgui-host did not report ABI metadata");
|
|
103
101
|
signal?.throwIfAborted();
|
|
104
102
|
|
|
105
103
|
const bundleSource = await realpath(dist);
|
|
@@ -144,8 +142,8 @@ export async function packageApplication(
|
|
|
144
142
|
app,
|
|
145
143
|
id: manifest.id,
|
|
146
144
|
buildId: manifest.buildId,
|
|
147
|
-
hostApiVersion:
|
|
148
|
-
hostVersion:
|
|
145
|
+
hostApiVersion: abi.hostApiVersion,
|
|
146
|
+
hostVersion: abi.version,
|
|
149
147
|
hostSource: host.source,
|
|
150
148
|
executable: "bin/zgui-host",
|
|
151
149
|
bundle: "bundle",
|
package/src/preview-check.ts
CHANGED
|
@@ -2,8 +2,10 @@ import { mkdir, rename, writeFile } from "node:fs/promises";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
|
|
5
|
+
import { resolveNativeHost } from "./host.ts";
|
|
6
|
+
import type { ResolvedNativeHost } from "./index.ts";
|
|
7
|
+
|
|
5
8
|
const workspaceRoot = fileURLToPath(new URL("../../../", import.meta.url));
|
|
6
|
-
const nativeHost = path.join(workspaceRoot, "target/debug/zgui-host");
|
|
7
9
|
const maxSummaryBytes = 8 * 1024;
|
|
8
10
|
const exitCodes = new Set([0, 2, 3, 4, 5, 6, 7, 8, 9, 130]);
|
|
9
11
|
const usage =
|
|
@@ -81,6 +83,7 @@ function options(args: string[]) {
|
|
|
81
83
|
}
|
|
82
84
|
|
|
83
85
|
function execute(
|
|
86
|
+
host: ResolvedNativeHost,
|
|
84
87
|
command: "run" | "compare",
|
|
85
88
|
args: string[],
|
|
86
89
|
): {
|
|
@@ -91,8 +94,8 @@ function execute(
|
|
|
91
94
|
// Native stderr remains available live, including graphics setup diagnostics.
|
|
92
95
|
let child: Bun.SyncSubprocess<"pipe", "inherit">;
|
|
93
96
|
try {
|
|
94
|
-
child = Bun.spawnSync([
|
|
95
|
-
cwd:
|
|
97
|
+
child = Bun.spawnSync([host.executable, "preview", command, ...args], {
|
|
98
|
+
cwd: host.runRoot,
|
|
96
99
|
stdin: "ignore",
|
|
97
100
|
stdout: "pipe",
|
|
98
101
|
stderr: "inherit",
|
|
@@ -188,7 +191,13 @@ try {
|
|
|
188
191
|
}
|
|
189
192
|
root = selected.out;
|
|
190
193
|
result.stage = "run";
|
|
191
|
-
|
|
194
|
+
let host: ResolvedNativeHost;
|
|
195
|
+
try {
|
|
196
|
+
host = await resolveNativeHost({ root: workspaceRoot, allowCargoBuild: false });
|
|
197
|
+
} catch (error) {
|
|
198
|
+
throw failure("E_WORKER_CRASH", 9, `Cannot resolve native preview host: ${message(error)}`);
|
|
199
|
+
}
|
|
200
|
+
const run = execute(host, "run", [
|
|
192
201
|
"--bundle",
|
|
193
202
|
path.join(workspaceRoot, "apps/examples/counter/dist"),
|
|
194
203
|
"--profile",
|
|
@@ -211,7 +220,7 @@ try {
|
|
|
211
220
|
await writeFile(path.join(root, "run.stdout.json"), run.stdout, { flag: "wx" });
|
|
212
221
|
if (run.result.exitCode === 0) {
|
|
213
222
|
result.stage = "compare";
|
|
214
|
-
const comparison = execute("compare", [
|
|
223
|
+
const comparison = execute(host, "compare", [
|
|
215
224
|
"--baseline",
|
|
216
225
|
selected.baseline,
|
|
217
226
|
"--actual",
|
package/src/preview.ts
CHANGED
|
@@ -2,16 +2,16 @@ import type { PreviewApplicationOptions } from "./index.ts";
|
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
|
-
import {
|
|
5
|
+
import { buildWithResolvedHost } from "./build.ts";
|
|
6
6
|
import { devApplication } from "./dev.ts";
|
|
7
|
-
import {
|
|
8
|
-
import { runNativeHost } from "./native-process.ts";
|
|
7
|
+
import { runNativeHost } from "./host.ts";
|
|
9
8
|
import { packagedSdkRoot, workspaceRoot } from "./sdk.ts";
|
|
10
9
|
|
|
11
10
|
export async function previewApplication(
|
|
12
11
|
app: string,
|
|
13
12
|
{
|
|
14
13
|
root = workspaceRoot,
|
|
14
|
+
appDirectory = path.join(root, "apps/examples", app),
|
|
15
15
|
hostRoot,
|
|
16
16
|
hostExecutable,
|
|
17
17
|
watch = false,
|
|
@@ -24,6 +24,7 @@ export async function previewApplication(
|
|
|
24
24
|
),
|
|
25
25
|
signal,
|
|
26
26
|
onOutput,
|
|
27
|
+
bytecode = false,
|
|
27
28
|
...buildOptions
|
|
28
29
|
}: PreviewApplicationOptions = {},
|
|
29
30
|
): Promise<number> {
|
|
@@ -45,25 +46,24 @@ export async function previewApplication(
|
|
|
45
46
|
return devApplication(app, {
|
|
46
47
|
...buildOptions,
|
|
47
48
|
root,
|
|
49
|
+
appDirectory,
|
|
48
50
|
...(explicitHostRoot === undefined ? {} : { hostRoot: explicitHostRoot }),
|
|
49
51
|
hostExecutable,
|
|
50
52
|
mode: "preview",
|
|
51
53
|
hostArgs: args,
|
|
52
54
|
signal,
|
|
53
55
|
});
|
|
54
|
-
const {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
root,
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return runNativeHost(resolvedHost.executable, ["preview", "run", "--bundle", dist, ...args], {
|
|
66
|
-
root: runRoot,
|
|
56
|
+
const {
|
|
57
|
+
application: { dist },
|
|
58
|
+
resolveHost,
|
|
59
|
+
} = await buildWithResolvedHost(
|
|
60
|
+
app,
|
|
61
|
+
{ ...buildOptions, root, appDirectory, bytecode },
|
|
62
|
+
{ hostRoot: explicitHostRoot, hostExecutable, signal },
|
|
63
|
+
);
|
|
64
|
+
const host = await resolveHost();
|
|
65
|
+
return runNativeHost(host.executable, ["preview", "run", "--bundle", dist, ...args], {
|
|
66
|
+
root: host.runRoot,
|
|
67
67
|
signal,
|
|
68
68
|
});
|
|
69
69
|
}
|
package/src/public-api.d.ts
CHANGED
|
@@ -120,6 +120,14 @@ export interface BuildApplicationOptions {
|
|
|
120
120
|
hostSearchFrom?: readonly string[] | undefined;
|
|
121
121
|
extraCapabilities?: Capabilities;
|
|
122
122
|
capabilitiesFile?: string;
|
|
123
|
+
cssModuleInclude?: readonly string[] | undefined;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export interface SyncCssModuleTypesOptions {
|
|
127
|
+
project?: string | undefined;
|
|
128
|
+
appDirectory?: string | undefined;
|
|
129
|
+
include?: readonly string[] | undefined;
|
|
130
|
+
cwd?: string | undefined;
|
|
123
131
|
}
|
|
124
132
|
|
|
125
133
|
export interface ApplicationWatcher {
|
|
@@ -201,6 +209,8 @@ export interface ResolveNativeHostOptions {
|
|
|
201
209
|
export interface ResolvedNativeHost {
|
|
202
210
|
executable: string;
|
|
203
211
|
source: NativeHostSource;
|
|
212
|
+
/** Absolute working directory selected for native host commands. */
|
|
213
|
+
runRoot: string;
|
|
204
214
|
packageName?: string | undefined;
|
|
205
215
|
cargoRoot?: string | undefined;
|
|
206
216
|
abi?: NativeHostAbi | undefined;
|
|
@@ -230,6 +240,7 @@ export declare const buildApplication: (
|
|
|
230
240
|
app: string,
|
|
231
241
|
options?: BuildApplicationOptions,
|
|
232
242
|
) => Promise<PublishedApplication>;
|
|
243
|
+
export declare const syncCssModuleTypes: (options?: SyncCssModuleTypesOptions) => Promise<string[]>;
|
|
233
244
|
export declare const watchApplication: (
|
|
234
245
|
app: string,
|
|
235
246
|
options?: WatchApplicationOptions,
|
package/src/sdk-packages.ts
CHANGED
|
@@ -44,6 +44,13 @@ const SDK_PACKAGE_SPECS: Readonly<Record<SdkPackageName, SdkPackageSpec>> = {
|
|
|
44
44
|
};
|
|
45
45
|
|
|
46
46
|
const ALL_SDK_PACKAGES: readonly SdkPackageName[] = ["ui", "services"];
|
|
47
|
+
const OXLINT_OUTPUT_FILES = [
|
|
48
|
+
"oxlint/plugin.js",
|
|
49
|
+
"oxlint/solid.js",
|
|
50
|
+
"oxlint/ast.js",
|
|
51
|
+
"oxlint/scope.js",
|
|
52
|
+
"oxlint/style-analysis.js",
|
|
53
|
+
] as const;
|
|
47
54
|
|
|
48
55
|
const compilerCli = path.join(
|
|
49
56
|
path.dirname(createRequire(import.meta.url).resolve("tsrs/package.json")),
|
|
@@ -83,30 +90,41 @@ async function listFilesRecursive(dir: string, prefix = ""): Promise<string[]> {
|
|
|
83
90
|
|
|
84
91
|
async function newestInputMtimeMs(pkgDir: string): Promise<number> {
|
|
85
92
|
let newest = 0;
|
|
86
|
-
for (const cfg of ["tsconfig.json", "tsconfig.build.json"]) {
|
|
93
|
+
for (const cfg of ["tsconfig.json", "tsconfig.build.json", "tsconfig.oxlint.json"]) {
|
|
87
94
|
const full = path.join(pkgDir, cfg);
|
|
88
95
|
if (existsSync(full)) {
|
|
89
96
|
const info = await stat(full);
|
|
90
97
|
if (info.mtimeMs > newest) newest = info.mtimeMs;
|
|
91
98
|
}
|
|
92
99
|
}
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
100
|
+
for (const inputDir of [path.join(pkgDir, "src"), path.join(pkgDir, "oxlint/src")]) {
|
|
101
|
+
for (const rel of await listFilesRecursive(inputDir)) {
|
|
102
|
+
const info = await stat(path.join(inputDir, rel));
|
|
103
|
+
if (info.mtimeMs > newest) newest = info.mtimeMs;
|
|
104
|
+
}
|
|
97
105
|
}
|
|
98
106
|
return newest;
|
|
99
107
|
}
|
|
100
108
|
|
|
101
109
|
async function isPackageDistFresh(pkgDir: string, spec: SdkPackageSpec): Promise<boolean> {
|
|
102
110
|
const distDir = path.join(pkgDir, "dist");
|
|
103
|
-
const
|
|
111
|
+
const hasOxlintBuild = existsSync(path.join(pkgDir, "tsconfig.oxlint.json"));
|
|
112
|
+
const required = [
|
|
113
|
+
"index.js",
|
|
114
|
+
"index.d.ts",
|
|
115
|
+
...spec.handwrittenDts,
|
|
116
|
+
...(hasOxlintBuild ? OXLINT_OUTPUT_FILES : []),
|
|
117
|
+
];
|
|
104
118
|
let stampMtime = Number.POSITIVE_INFINITY;
|
|
105
119
|
for (const rel of required) {
|
|
106
120
|
const full = path.join(distDir, rel);
|
|
107
121
|
try {
|
|
108
122
|
const info = await stat(full);
|
|
109
|
-
if (
|
|
123
|
+
if (
|
|
124
|
+
rel === "index.js" ||
|
|
125
|
+
rel === "index.d.ts" ||
|
|
126
|
+
(hasOxlintBuild && (OXLINT_OUTPUT_FILES as readonly string[]).includes(rel))
|
|
127
|
+
) {
|
|
110
128
|
stampMtime = Math.min(stampMtime, info.mtimeMs);
|
|
111
129
|
}
|
|
112
130
|
} catch {
|
|
@@ -183,7 +201,7 @@ async function syncDirectoryInPlace(stagingDir: string, distDir: string): Promis
|
|
|
183
201
|
await removeEmptyDirs(distDir);
|
|
184
202
|
|
|
185
203
|
const now = new Date();
|
|
186
|
-
for (const sentinel of ["index.js", "index.d.ts"]) {
|
|
204
|
+
for (const sentinel of ["index.js", "index.d.ts", ...OXLINT_OUTPUT_FILES]) {
|
|
187
205
|
const target = path.join(distDir, sentinel);
|
|
188
206
|
if (existsSync(target)) {
|
|
189
207
|
await utimes(target, now, now).catch(() => {});
|
|
@@ -266,7 +284,10 @@ async function compileSinglePackage(
|
|
|
266
284
|
if (!existsSync(tsconfigPath)) {
|
|
267
285
|
throw new Error(`Missing SDK build tsconfig: ${tsconfigPath}`);
|
|
268
286
|
}
|
|
269
|
-
const stagingDir = path.join(
|
|
287
|
+
const stagingDir = path.join(
|
|
288
|
+
os.tmpdir(),
|
|
289
|
+
`zgui-dist-staging-${spec.name}-${process.pid}-${randomUUID()}`,
|
|
290
|
+
);
|
|
270
291
|
try {
|
|
271
292
|
const child = Bun.spawn(
|
|
272
293
|
[
|
|
@@ -305,6 +326,39 @@ async function compileSinglePackage(
|
|
|
305
326
|
await copyFile(srcPath, destPath);
|
|
306
327
|
}
|
|
307
328
|
|
|
329
|
+
const oxlintTsconfigPath = path.join(pkgDir, "tsconfig.oxlint.json");
|
|
330
|
+
if (existsSync(oxlintTsconfigPath)) {
|
|
331
|
+
const oxlintChild = Bun.spawn(
|
|
332
|
+
[
|
|
333
|
+
process.execPath,
|
|
334
|
+
compilerCli,
|
|
335
|
+
"--project",
|
|
336
|
+
oxlintTsconfigPath,
|
|
337
|
+
"--outDir",
|
|
338
|
+
path.join(stagingDir, "oxlint"),
|
|
339
|
+
"--pretty",
|
|
340
|
+
"false",
|
|
341
|
+
],
|
|
342
|
+
{
|
|
343
|
+
cwd: pkgDir,
|
|
344
|
+
stdin: "ignore",
|
|
345
|
+
stdout: "pipe",
|
|
346
|
+
stderr: "pipe",
|
|
347
|
+
},
|
|
348
|
+
);
|
|
349
|
+
const [oxCode, oxStdout, oxStderr] = await Promise.all([
|
|
350
|
+
oxlintChild.exited,
|
|
351
|
+
new Response(oxlintChild.stdout).text(),
|
|
352
|
+
new Response(oxlintChild.stderr).text(),
|
|
353
|
+
]);
|
|
354
|
+
if (oxCode !== 0 || oxlintChild.signalCode) {
|
|
355
|
+
const detail = `${oxStdout}${oxStderr}`.trim();
|
|
356
|
+
throw new Error(
|
|
357
|
+
`SDK oxlint build failed for ${spec.dir} (exit ${oxlintChild.signalCode ?? oxCode})${detail ? `:\n${detail}` : ""}`,
|
|
358
|
+
);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
308
362
|
let verifiedSheets = 0;
|
|
309
363
|
if (spec.verifyGeneratedStyles) {
|
|
310
364
|
verifiedSheets = await verifyGeneratedStyleSheets(stagingDir);
|
|
@@ -340,17 +394,22 @@ export async function buildSdkPackages({
|
|
|
340
394
|
|
|
341
395
|
export async function ensureSdkPackagesBuilt(
|
|
342
396
|
root: string = workspaceRoot,
|
|
343
|
-
{
|
|
397
|
+
{
|
|
398
|
+
silent = true,
|
|
399
|
+
packages = ALL_SDK_PACKAGES,
|
|
400
|
+
}: { silent?: boolean; packages?: readonly SdkPackageName[] } = {},
|
|
344
401
|
): Promise<void> {
|
|
345
402
|
const resolvedRoot = path.resolve(root);
|
|
346
403
|
if (!hasCheckoutSdkSources(resolvedRoot)) return;
|
|
347
404
|
|
|
348
|
-
const
|
|
405
|
+
const targetPackages = [...new Set(packages)];
|
|
406
|
+
const cacheKey = `${resolvedRoot}:${[...targetPackages].sort().join(",")}`;
|
|
407
|
+
const existing = inFlight.get(cacheKey);
|
|
349
408
|
if (existing) return existing;
|
|
350
409
|
|
|
351
410
|
const run = (async () => {
|
|
352
411
|
const stale: SdkPackageName[] = [];
|
|
353
|
-
for (const name of
|
|
412
|
+
for (const name of targetPackages) {
|
|
354
413
|
const spec = SDK_PACKAGE_SPECS[name];
|
|
355
414
|
if (!(await isPackageDistFresh(path.join(resolvedRoot, spec.dir), spec))) {
|
|
356
415
|
stale.push(name);
|
|
@@ -367,10 +426,10 @@ export async function ensureSdkPackagesBuilt(
|
|
|
367
426
|
});
|
|
368
427
|
})();
|
|
369
428
|
|
|
370
|
-
inFlight.set(
|
|
429
|
+
inFlight.set(cacheKey, run);
|
|
371
430
|
try {
|
|
372
431
|
await run;
|
|
373
432
|
} finally {
|
|
374
|
-
if (inFlight.get(
|
|
433
|
+
if (inFlight.get(cacheKey) === run) inFlight.delete(cacheKey);
|
|
375
434
|
}
|
|
376
435
|
}
|
package/src/typecheck.ts
CHANGED
|
@@ -98,6 +98,10 @@ async function discoverPackageConfigs(root: string): Promise<string[]> {
|
|
|
98
98
|
break;
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
|
+
const oxlintConfigPath = path.join(pkgDir, "tsconfig.oxlint.json");
|
|
102
|
+
if (await fileExists(oxlintConfigPath)) {
|
|
103
|
+
configs.push(oxlintConfigPath);
|
|
104
|
+
}
|
|
101
105
|
}
|
|
102
106
|
return configs;
|
|
103
107
|
}
|
|
@@ -122,7 +126,7 @@ async function discoverAppConfigs(root: string, appFilter?: string): Promise<str
|
|
|
122
126
|
const config = path.join(appDir, "tsconfig.json");
|
|
123
127
|
if (!(await fileExists(config))) continue;
|
|
124
128
|
// Run outside ENOENT guard so CSS Module type generation failures surface instead of silently skipping.
|
|
125
|
-
await syncCssModuleTypes(appDir,
|
|
129
|
+
await syncCssModuleTypes({ appDirectory: appDir, project: config });
|
|
126
130
|
configs.push(config);
|
|
127
131
|
}
|
|
128
132
|
}
|
|
@@ -130,7 +134,7 @@ async function discoverAppConfigs(root: string, appFilter?: string): Promise<str
|
|
|
130
134
|
const directDir = path.resolve(root, appFilter);
|
|
131
135
|
const directConfig = path.join(directDir, "tsconfig.json");
|
|
132
136
|
if (await fileExists(directConfig)) {
|
|
133
|
-
await syncCssModuleTypes(directDir,
|
|
137
|
+
await syncCssModuleTypes({ appDirectory: directDir, project: directConfig });
|
|
134
138
|
configs.push(directConfig);
|
|
135
139
|
} else {
|
|
136
140
|
throw new Error(`No app tsconfig.json found for --app ${appFilter}`);
|
package/src/validate.ts
CHANGED
|
@@ -1048,14 +1048,18 @@ export function validateGraph(
|
|
|
1048
1048
|
const signals = graph.modules.filter(input =>
|
|
1049
1049
|
/\/@solidjs\/signals\/dist\/(?:(?:prod|observe)\/index|dev)\.js$/.test(input),
|
|
1050
1050
|
);
|
|
1051
|
-
if (runtimes.length
|
|
1051
|
+
if (runtimes.length > 1 || signals.length > 1) {
|
|
1052
|
+
const details = [
|
|
1053
|
+
...(runtimes.length > 1 ? [`solid-js: ${runtimes.join(", ")}`] : []),
|
|
1054
|
+
...(signals.length > 1 ? [`@solidjs/signals: ${signals.join(", ")}`] : []),
|
|
1055
|
+
];
|
|
1052
1056
|
throw new Error(
|
|
1053
|
-
`Expected
|
|
1057
|
+
`Expected single Solid runtime instances, found solid=${runtimes.length}, signals=${signals.length} (${details.join("; ")})`,
|
|
1054
1058
|
);
|
|
1055
1059
|
}
|
|
1056
|
-
if (runtimes.length
|
|
1060
|
+
if (runtimes.length !== 1 && signals.length !== 1) {
|
|
1057
1061
|
throw new Error(
|
|
1058
|
-
`Expected
|
|
1062
|
+
`Expected one reactive Solid runtime, found solid=${runtimes.length}, signals=${signals.length}`,
|
|
1059
1063
|
);
|
|
1060
1064
|
}
|
|
1061
1065
|
for (const input of graph.modules) {
|
package/src/watch.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { randomUUID } from "node:crypto";
|
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { tmpdir } from "node:os";
|
|
7
7
|
import { publishApplication } from "./build.ts";
|
|
8
|
-
import { syncCssModuleTypes } from "./css.ts";
|
|
8
|
+
import { resolveCssModuleWatchDirectories, syncCssModuleTypes } from "./css.ts";
|
|
9
9
|
import { workspaceRoot } from "./sdk.ts";
|
|
10
10
|
import {
|
|
11
11
|
buildSdkPackages,
|
|
@@ -107,6 +107,7 @@ export function watchApplication(
|
|
|
107
107
|
strictTypecheck = false,
|
|
108
108
|
extraCapabilities,
|
|
109
109
|
capabilitiesFile,
|
|
110
|
+
cssModuleInclude,
|
|
110
111
|
onSuccess = ({ dist, manifest }) => console.log(`Published ${dist} ${manifest.buildId}`),
|
|
111
112
|
onError = error =>
|
|
112
113
|
console.error(
|
|
@@ -127,6 +128,7 @@ export function watchApplication(
|
|
|
127
128
|
}: WatchDependencies = {},
|
|
128
129
|
): ApplicationWatcher {
|
|
129
130
|
if (!/^[a-z][a-z0-9-]*$/.test(app)) throw new Error(`Invalid application name: ${app}`);
|
|
131
|
+
const callerCwd = process.cwd();
|
|
130
132
|
root = path.resolve(root);
|
|
131
133
|
appDirectory = path.resolve(appDirectory);
|
|
132
134
|
if (capabilitiesFile !== undefined) capabilitiesFile = path.resolve(capabilitiesFile);
|
|
@@ -152,7 +154,45 @@ export function watchApplication(
|
|
|
152
154
|
const watchers: FSWatcher[] = [];
|
|
153
155
|
let targetWatcher: FSWatcher | undefined;
|
|
154
156
|
const dependencyWatchers = new Map<string, FSWatcher>();
|
|
157
|
+
const externalSourceWatchers = new Map<string, FSWatcher>();
|
|
155
158
|
let graphModules = new Set<string>();
|
|
159
|
+
const isSameOrInside = (candidate: string, ancestor: string): boolean => {
|
|
160
|
+
const rel = path.relative(ancestor, candidate);
|
|
161
|
+
return (
|
|
162
|
+
rel === "" || (!rel.startsWith(`..${path.sep}`) && rel !== ".." && !path.isAbsolute(rel))
|
|
163
|
+
);
|
|
164
|
+
};
|
|
165
|
+
const syncCssTypesOptions = {
|
|
166
|
+
appDirectory,
|
|
167
|
+
include: cssModuleInclude,
|
|
168
|
+
cwd: callerCwd,
|
|
169
|
+
};
|
|
170
|
+
async function refreshExternalSourceWatchers() {
|
|
171
|
+
const directories = await resolveCssModuleWatchDirectories(syncCssTypesOptions);
|
|
172
|
+
const wanted = new Set(
|
|
173
|
+
directories.filter(
|
|
174
|
+
directory =>
|
|
175
|
+
!isSameOrInside(directory, appDirectory) &&
|
|
176
|
+
!isSameOrInside(directory, uiPackageDir) &&
|
|
177
|
+
!isSameOrInside(directory, servicesPackageDir),
|
|
178
|
+
),
|
|
179
|
+
);
|
|
180
|
+
for (const [directory, watcher] of externalSourceWatchers) {
|
|
181
|
+
if (!wanted.has(directory)) {
|
|
182
|
+
watcher.close();
|
|
183
|
+
externalSourceWatchers.delete(directory);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
for (const directory of wanted) {
|
|
187
|
+
if (externalSourceWatchers.has(directory)) continue;
|
|
188
|
+
if (closed || controller.signal.aborted) return;
|
|
189
|
+
const watcher = watch(directory, { recursive: true }, (_event, filename) =>
|
|
190
|
+
changed(filename, directory),
|
|
191
|
+
);
|
|
192
|
+
watcher.on("error", report);
|
|
193
|
+
externalSourceWatchers.set(directory, watcher);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
156
196
|
const report = (error: unknown) => {
|
|
157
197
|
if (!closed && !controller.signal.aborted) onError(error);
|
|
158
198
|
};
|
|
@@ -220,7 +260,8 @@ export function watchApplication(
|
|
|
220
260
|
status = undefined;
|
|
221
261
|
cancelActiveTypecheck();
|
|
222
262
|
controller.signal.throwIfAborted();
|
|
223
|
-
await
|
|
263
|
+
await refreshExternalSourceWatchers();
|
|
264
|
+
await syncCssModuleTypes(syncCssTypesOptions);
|
|
224
265
|
let previousDirectory: string | null;
|
|
225
266
|
try {
|
|
226
267
|
previousDirectory = await realpath(path.join(appDirectory, "dist"));
|
|
@@ -255,7 +296,7 @@ export function watchApplication(
|
|
|
255
296
|
async onCompile(result) {
|
|
256
297
|
graphModules = new Set(result.graph.modules);
|
|
257
298
|
await watchDependencyManifests(result.graph.modules);
|
|
258
|
-
await syncCssModuleTypes(
|
|
299
|
+
await syncCssModuleTypes(syncCssTypesOptions);
|
|
259
300
|
if (!asyncTypecheck) {
|
|
260
301
|
await typecheck(path.join(appDirectory, "tsconfig.json"), { signal: controller.signal });
|
|
261
302
|
}
|
|
@@ -394,9 +435,12 @@ export function watchApplication(
|
|
|
394
435
|
parts.some(
|
|
395
436
|
part =>
|
|
396
437
|
part === "dist" ||
|
|
438
|
+
part === "dist-package" ||
|
|
439
|
+
part === "target" ||
|
|
397
440
|
part === ".zgui-generations" ||
|
|
398
441
|
part === "node_modules" ||
|
|
399
442
|
part.startsWith(".dist-") ||
|
|
443
|
+
part.startsWith(".shell-compose-stage-") ||
|
|
400
444
|
part === BUILD_STATUS_FILE ||
|
|
401
445
|
part.startsWith(`${BUILD_STATUS_FILE}.`) ||
|
|
402
446
|
part === NATIVE_STATUS_FILE ||
|
|
@@ -505,6 +549,8 @@ export function watchApplication(
|
|
|
505
549
|
const initialized = (async () => {
|
|
506
550
|
await ensureSdk(root, { silent: true });
|
|
507
551
|
if (closed || controller.signal.aborted) return;
|
|
552
|
+
await refreshExternalSourceWatchers();
|
|
553
|
+
if (closed || controller.signal.aborted) return;
|
|
508
554
|
temporary = await mkdtemp(path.join(tmpdir(), "zgui-compiler-"));
|
|
509
555
|
await writeFile(path.join(temporary, "invalidate"), "");
|
|
510
556
|
if (!closed && !controller.signal.aborted) startCompiler();
|
|
@@ -517,6 +563,7 @@ export function watchApplication(
|
|
|
517
563
|
cancelActiveTypecheck();
|
|
518
564
|
controller.abort();
|
|
519
565
|
signal?.removeEventListener("abort", abort);
|
|
566
|
+
for (const watcher of externalSourceWatchers.values()) watcher.close();
|
|
520
567
|
for (const watcher of dependencyWatchers.values()) watcher.close();
|
|
521
568
|
targetWatcher?.close();
|
|
522
569
|
for (const watcher of watchers) watcher.close();
|