@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/sdk-packages.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
-
import { existsSync, type Dirent } from "node:fs";
|
|
2
|
+
import { existsSync, readdirSync, type Dirent } from "node:fs";
|
|
3
3
|
import {
|
|
4
4
|
copyFile,
|
|
5
5
|
mkdir,
|
|
@@ -44,13 +44,32 @@ const SDK_PACKAGE_SPECS: Readonly<Record<SdkPackageName, SdkPackageSpec>> = {
|
|
|
44
44
|
};
|
|
45
45
|
|
|
46
46
|
const ALL_SDK_PACKAGES: readonly SdkPackageName[] = ["ui", "services"];
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
"oxlint/
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
47
|
+
|
|
48
|
+
/** Derive sorted `oxlint/**\/*.js` outputs from `oxlint/src/**\/*.ts` (excluding `.d.ts`). */
|
|
49
|
+
export function listOxlintOutputFiles(pkgDir: string): readonly string[] {
|
|
50
|
+
const oxlintSrcDir = path.join(pkgDir, "oxlint/src");
|
|
51
|
+
if (!existsSync(oxlintSrcDir)) {
|
|
52
|
+
throw new Error(`Missing oxlint source directory: ${oxlintSrcDir}`);
|
|
53
|
+
}
|
|
54
|
+
const outputs: string[] = [];
|
|
55
|
+
const walk = (dir: string, prefix: string): void => {
|
|
56
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
57
|
+
const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
58
|
+
const full = path.join(dir, entry.name);
|
|
59
|
+
if (entry.isDirectory()) {
|
|
60
|
+
walk(full, rel);
|
|
61
|
+
} else if (entry.isFile() && entry.name.endsWith(".ts") && !entry.name.endsWith(".d.ts")) {
|
|
62
|
+
outputs.push(`oxlint/${rel.slice(0, -3)}.js`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
walk(oxlintSrcDir, "");
|
|
67
|
+
outputs.sort();
|
|
68
|
+
if (outputs.length === 0) {
|
|
69
|
+
throw new Error(`No TypeScript sources found under ${oxlintSrcDir}`);
|
|
70
|
+
}
|
|
71
|
+
return outputs;
|
|
72
|
+
}
|
|
54
73
|
|
|
55
74
|
const compilerCli = path.join(
|
|
56
75
|
path.dirname(createRequire(import.meta.url).resolve("tsrs/package.json")),
|
|
@@ -109,22 +128,14 @@ async function newestInputMtimeMs(pkgDir: string): Promise<number> {
|
|
|
109
128
|
async function isPackageDistFresh(pkgDir: string, spec: SdkPackageSpec): Promise<boolean> {
|
|
110
129
|
const distDir = path.join(pkgDir, "dist");
|
|
111
130
|
const hasOxlintBuild = existsSync(path.join(pkgDir, "tsconfig.oxlint.json"));
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
"index.d.ts",
|
|
115
|
-
...spec.handwrittenDts,
|
|
116
|
-
...(hasOxlintBuild ? OXLINT_OUTPUT_FILES : []),
|
|
117
|
-
];
|
|
131
|
+
const oxlintOutputs = hasOxlintBuild ? listOxlintOutputFiles(pkgDir) : [];
|
|
132
|
+
const required = ["index.js", "index.d.ts", ...spec.handwrittenDts, ...oxlintOutputs];
|
|
118
133
|
let stampMtime = Number.POSITIVE_INFINITY;
|
|
119
134
|
for (const rel of required) {
|
|
120
135
|
const full = path.join(distDir, rel);
|
|
121
136
|
try {
|
|
122
137
|
const info = await stat(full);
|
|
123
|
-
if (
|
|
124
|
-
rel === "index.js" ||
|
|
125
|
-
rel === "index.d.ts" ||
|
|
126
|
-
(hasOxlintBuild && (OXLINT_OUTPUT_FILES as readonly string[]).includes(rel))
|
|
127
|
-
) {
|
|
138
|
+
if (rel === "index.js" || rel === "index.d.ts" || oxlintOutputs.includes(rel)) {
|
|
128
139
|
stampMtime = Math.min(stampMtime, info.mtimeMs);
|
|
129
140
|
}
|
|
130
141
|
} catch {
|
|
@@ -201,7 +212,12 @@ async function syncDirectoryInPlace(stagingDir: string, distDir: string): Promis
|
|
|
201
212
|
await removeEmptyDirs(distDir);
|
|
202
213
|
|
|
203
214
|
const now = new Date();
|
|
204
|
-
|
|
215
|
+
const sentinels = [
|
|
216
|
+
"index.js",
|
|
217
|
+
"index.d.ts",
|
|
218
|
+
...stagedFiles.filter(rel => rel.startsWith("oxlint/") && rel.endsWith(".js")),
|
|
219
|
+
];
|
|
220
|
+
for (const sentinel of sentinels) {
|
|
205
221
|
const target = path.join(distDir, sentinel);
|
|
206
222
|
if (existsSync(target)) {
|
|
207
223
|
await utimes(target, now, now).catch(() => {});
|
package/src/sync-ui-resources.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { mkdir } from "node:fs/promises";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
|
|
5
|
-
const REVISION = "
|
|
5
|
+
const REVISION = "b985e19296b625f6f9ee1b66d6a5ff09d9de7ff6";
|
|
6
6
|
const workspaceRoot = fileURLToPath(new URL("../../../", import.meta.url));
|
|
7
7
|
|
|
8
8
|
export interface ResourceSnapshot {
|
|
@@ -96,6 +96,56 @@ export function adaptUpstreamCss(name: string, className: string, css: string):
|
|
|
96
96
|
);
|
|
97
97
|
case "CollapsibleStyle":
|
|
98
98
|
return `${css}\n.zui-collapsible__content[data-collapsed] { visibility: hidden; }`;
|
|
99
|
+
case "TableStyle":
|
|
100
|
+
return css
|
|
101
|
+
.replace(
|
|
102
|
+
`.${className}[data-sticky-header="true"] .zui-table__head`,
|
|
103
|
+
'.zui-table__head[data-sticky="true"]',
|
|
104
|
+
)
|
|
105
|
+
.replace(
|
|
106
|
+
`.${className} .zui-table__row[data-selected="true"] .zui-table__cell`,
|
|
107
|
+
'.zui-table__cell[data-selected="true"]',
|
|
108
|
+
)
|
|
109
|
+
.replace(
|
|
110
|
+
".zui-table__row:hover .zui-table__cell",
|
|
111
|
+
".zui-table__row:hover > .zui-table__cell",
|
|
112
|
+
)
|
|
113
|
+
.replace(
|
|
114
|
+
".zui-table__footer .zui-table__cell",
|
|
115
|
+
".zui-table__footer > .zui-table__row > .zui-table__cell",
|
|
116
|
+
)
|
|
117
|
+
.replaceAll(
|
|
118
|
+
/(\.zui-table__(?:body|footer)) (\.zui-table__row:(?:first|last)-child)/g,
|
|
119
|
+
"$1 > $2",
|
|
120
|
+
)
|
|
121
|
+
.replaceAll(
|
|
122
|
+
/(\.zui-table__row:(?:first|last)-child) \.zui-table__cell/g,
|
|
123
|
+
"$1 > .zui-table__cell",
|
|
124
|
+
);
|
|
125
|
+
case "DataTableStyle":
|
|
126
|
+
return `${css
|
|
127
|
+
.replace(
|
|
128
|
+
"border: 1px solid var(--zui-color-border);\n border-radius: var(--zui-radius-md);\n max-height:",
|
|
129
|
+
"border: none;\n --zgui-scrollbar-mode: overlay;\n max-height:",
|
|
130
|
+
)
|
|
131
|
+
.replace(
|
|
132
|
+
'.zui-data-table__grid[data-virtualized="true"] .zui-table__body .zui-table__cell',
|
|
133
|
+
'.zui-data-table__layout-row[data-fixed="true"] > .zui-table__row > .zui-table__cell',
|
|
134
|
+
)}
|
|
135
|
+
.zui-data-table__layout-row { flex-shrink: 0; }
|
|
136
|
+
.zui-data-table__frame {
|
|
137
|
+
width: 100%;
|
|
138
|
+
min-width: 0;
|
|
139
|
+
overflow-x: auto;
|
|
140
|
+
overflow-y: hidden;
|
|
141
|
+
border: 1px solid var(--zui-color-border);
|
|
142
|
+
border-radius: var(--zui-radius-md);
|
|
143
|
+
}`;
|
|
144
|
+
case "DatePickerStyle":
|
|
145
|
+
return css.replace(
|
|
146
|
+
".zui-date-picker__surface {\n width: auto;",
|
|
147
|
+
".zui-popover.zui-date-picker__surface {\n width: max-content;",
|
|
148
|
+
);
|
|
99
149
|
default:
|
|
100
150
|
return css;
|
|
101
151
|
}
|
package/src/validate.ts
CHANGED
|
@@ -13,6 +13,8 @@ const globals = new Set([
|
|
|
13
13
|
"performance",
|
|
14
14
|
"setTimeout",
|
|
15
15
|
"clearTimeout",
|
|
16
|
+
"setInterval",
|
|
17
|
+
"clearInterval",
|
|
16
18
|
"requestAnimationFrame",
|
|
17
19
|
"cancelAnimationFrame",
|
|
18
20
|
"queueMicrotask",
|
|
@@ -22,6 +24,7 @@ const globals = new Set([
|
|
|
22
24
|
"Symbol",
|
|
23
25
|
"Error",
|
|
24
26
|
"AggregateError",
|
|
27
|
+
"DOMException",
|
|
25
28
|
"EvalError",
|
|
26
29
|
"RangeError",
|
|
27
30
|
"ReferenceError",
|
|
@@ -53,6 +56,16 @@ const globals = new Set([
|
|
|
53
56
|
"ArrayBuffer",
|
|
54
57
|
"SharedArrayBuffer",
|
|
55
58
|
"DataView",
|
|
59
|
+
"URL",
|
|
60
|
+
"URLSearchParams",
|
|
61
|
+
"TextEncoder",
|
|
62
|
+
"TextDecoder",
|
|
63
|
+
"Event",
|
|
64
|
+
"CustomEvent",
|
|
65
|
+
"EventTarget",
|
|
66
|
+
"AbortController",
|
|
67
|
+
"AbortSignal",
|
|
68
|
+
"crypto",
|
|
56
69
|
"Atomics",
|
|
57
70
|
"JSON",
|
|
58
71
|
"Promise",
|
|
@@ -78,6 +91,8 @@ const workerDisallowedGlobals = new Set([
|
|
|
78
91
|
"performance",
|
|
79
92
|
"setTimeout",
|
|
80
93
|
"clearTimeout",
|
|
94
|
+
"setInterval",
|
|
95
|
+
"clearInterval",
|
|
81
96
|
"requestAnimationFrame",
|
|
82
97
|
"cancelAnimationFrame",
|
|
83
98
|
]);
|
|
@@ -335,41 +350,73 @@ function hasArgumentsBinding(ancestors: readonly AncestorFrame[]): boolean {
|
|
|
335
350
|
return false;
|
|
336
351
|
}
|
|
337
352
|
|
|
338
|
-
|
|
353
|
+
const definedTypeofValues = new Set([
|
|
354
|
+
"object",
|
|
355
|
+
"function",
|
|
356
|
+
"string",
|
|
357
|
+
"number",
|
|
358
|
+
"boolean",
|
|
359
|
+
"symbol",
|
|
360
|
+
"bigint",
|
|
361
|
+
]);
|
|
362
|
+
|
|
363
|
+
function isTypeofIdentifier(node: unknown, name: string): boolean {
|
|
364
|
+
return (
|
|
365
|
+
isAstNode(node) &&
|
|
366
|
+
node.type === "UnaryExpression" &&
|
|
367
|
+
node.operator === "typeof" &&
|
|
368
|
+
isAstNode(node.argument) &&
|
|
369
|
+
node.argument.type === "Identifier" &&
|
|
370
|
+
node.argument.name === name
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
function matchTypeofComparison(
|
|
375
|
+
expr: AstNode,
|
|
376
|
+
name: string,
|
|
377
|
+
): { equal: boolean; literal: string } | null {
|
|
378
|
+
if (expr.type !== "BinaryExpression") return null;
|
|
379
|
+
const op = expr.operator;
|
|
380
|
+
const equal = op === "===" || op === "==";
|
|
381
|
+
const notEqual = op === "!==" || op === "!=";
|
|
382
|
+
if (!equal && !notEqual) return null;
|
|
383
|
+
if (isTypeofIdentifier(expr.left, name) && isStringLiteral(expr.right)) {
|
|
384
|
+
return { equal, literal: expr.right.value };
|
|
385
|
+
}
|
|
386
|
+
if (isTypeofIdentifier(expr.right, name) && isStringLiteral(expr.left)) {
|
|
387
|
+
return { equal, literal: expr.left.value };
|
|
388
|
+
}
|
|
389
|
+
return null;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// True when `expr` evaluating to `whenTruthy` guarantees `typeof <name> !== "undefined"`.
|
|
393
|
+
function provesDefinedWhen(expr: unknown, name: string, whenTruthy: boolean): boolean {
|
|
339
394
|
if (!isAstNode(expr)) return false;
|
|
340
395
|
if (expr.type === "ParenthesizedExpression") {
|
|
341
|
-
return
|
|
396
|
+
return provesDefinedWhen(expr.expression, name, whenTruthy);
|
|
397
|
+
}
|
|
398
|
+
if (expr.type === "UnaryExpression" && expr.operator === "!") {
|
|
399
|
+
return provesDefinedWhen(expr.argument, name, !whenTruthy);
|
|
342
400
|
}
|
|
343
|
-
if (expr.type === "LogicalExpression"
|
|
344
|
-
|
|
401
|
+
if (expr.type === "LogicalExpression") {
|
|
402
|
+
if (expr.operator === "&&") {
|
|
403
|
+
return whenTruthy
|
|
404
|
+
? provesDefinedWhen(expr.left, name, true) || provesDefinedWhen(expr.right, name, true)
|
|
405
|
+
: provesDefinedWhen(expr.left, name, false) && provesDefinedWhen(expr.right, name, false);
|
|
406
|
+
}
|
|
407
|
+
if (expr.operator === "||") {
|
|
408
|
+
return whenTruthy
|
|
409
|
+
? provesDefinedWhen(expr.left, name, true) && provesDefinedWhen(expr.right, name, true)
|
|
410
|
+
: provesDefinedWhen(expr.left, name, false) || provesDefinedWhen(expr.right, name, false);
|
|
411
|
+
}
|
|
412
|
+
return false;
|
|
345
413
|
}
|
|
346
|
-
|
|
347
|
-
|
|
414
|
+
const cmp = matchTypeofComparison(expr, name);
|
|
415
|
+
if (!cmp) return false;
|
|
416
|
+
if (whenTruthy) {
|
|
417
|
+
return cmp.equal ? definedTypeofValues.has(cmp.literal) : cmp.literal === "undefined";
|
|
348
418
|
}
|
|
349
|
-
|
|
350
|
-
const op = expr.operator;
|
|
351
|
-
const matches = expectedUndefined ? op === "===" || op === "==" : op === "!==" || op === "!=";
|
|
352
|
-
if (!matches) return false;
|
|
353
|
-
const left = expr.left;
|
|
354
|
-
const right = expr.right;
|
|
355
|
-
return (
|
|
356
|
-
(isAstNode(left) &&
|
|
357
|
-
left.type === "UnaryExpression" &&
|
|
358
|
-
left.operator === "typeof" &&
|
|
359
|
-
isAstNode(left.argument) &&
|
|
360
|
-
left.argument.type === "Identifier" &&
|
|
361
|
-
left.argument.name === name &&
|
|
362
|
-
isStringLiteral(right) &&
|
|
363
|
-
right.value === "undefined") ||
|
|
364
|
-
(isAstNode(right) &&
|
|
365
|
-
right.type === "UnaryExpression" &&
|
|
366
|
-
right.operator === "typeof" &&
|
|
367
|
-
isAstNode(right.argument) &&
|
|
368
|
-
right.argument.type === "Identifier" &&
|
|
369
|
-
right.argument.name === name &&
|
|
370
|
-
isStringLiteral(left) &&
|
|
371
|
-
left.value === "undefined")
|
|
372
|
-
);
|
|
419
|
+
return cmp.equal && cmp.literal === "undefined";
|
|
373
420
|
}
|
|
374
421
|
|
|
375
422
|
function isTypeofGuarded(name: string, ancestors: readonly AncestorFrame[]): boolean {
|
|
@@ -384,23 +431,25 @@ function isTypeofGuarded(name: string, ancestors: readonly AncestorFrame[]): boo
|
|
|
384
431
|
}
|
|
385
432
|
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
386
433
|
const frame = ancestors[i]!;
|
|
387
|
-
if (frame.node.type === "LogicalExpression") {
|
|
388
|
-
if (
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
(frame.node.operator === "&&" &&
|
|
393
|
-
frame.key === "right" &&
|
|
394
|
-
hasTypeofCheck(frame.node.left, name, false))
|
|
395
|
-
) {
|
|
434
|
+
if (frame.node.type === "LogicalExpression" && frame.key === "right") {
|
|
435
|
+
if (frame.node.operator === "&&" && provesDefinedWhen(frame.node.left, name, true)) {
|
|
436
|
+
return true;
|
|
437
|
+
}
|
|
438
|
+
if (frame.node.operator === "||" && provesDefinedWhen(frame.node.left, name, false)) {
|
|
396
439
|
return true;
|
|
397
440
|
}
|
|
398
441
|
}
|
|
399
442
|
if (frame.node.type === "IfStatement" || frame.node.type === "ConditionalExpression") {
|
|
400
|
-
if (frame.key === "consequent" &&
|
|
401
|
-
if (frame.key === "alternate" &&
|
|
443
|
+
if (frame.key === "consequent" && provesDefinedWhen(frame.node.test, name, true)) return true;
|
|
444
|
+
if (frame.key === "alternate" && provesDefinedWhen(frame.node.test, name, false)) return true;
|
|
445
|
+
}
|
|
446
|
+
if (
|
|
447
|
+
isFunctionNode(frame.node) ||
|
|
448
|
+
frame.node.type === "StaticBlock" ||
|
|
449
|
+
frame.node.type === "Program"
|
|
450
|
+
) {
|
|
451
|
+
break;
|
|
402
452
|
}
|
|
403
|
-
if (isFunctionNode(frame.node) || frame.node.type === "Program") break;
|
|
404
453
|
}
|
|
405
454
|
return false;
|
|
406
455
|
}
|
|
@@ -512,8 +561,8 @@ export function validateModule(
|
|
|
512
561
|
}
|
|
513
562
|
};
|
|
514
563
|
|
|
515
|
-
function checkIdentifierReference(name: string, scope: Scope): void {
|
|
516
|
-
if (isTypeofGuarded(name, ancestors)) return;
|
|
564
|
+
function checkIdentifierReference(name: string, scope: Scope, allowTypeofGuard = true): void {
|
|
565
|
+
if (allowTypeofGuard && isTypeofGuarded(name, ancestors)) return;
|
|
517
566
|
if (
|
|
518
567
|
bundled &&
|
|
519
568
|
!hasBinding(scope, name) &&
|
|
@@ -554,7 +603,7 @@ export function validateModule(
|
|
|
554
603
|
if (isAssignmentTarget) {
|
|
555
604
|
const name = pattern.name as string;
|
|
556
605
|
markWrite(name, scope);
|
|
557
|
-
checkIdentifierReference(name, scope);
|
|
606
|
+
checkIdentifierReference(name, scope, false);
|
|
558
607
|
}
|
|
559
608
|
break;
|
|
560
609
|
case "MemberExpression":
|
|
@@ -863,10 +912,7 @@ export function validateModule(
|
|
|
863
912
|
pushAndWalk(node, "right", node.right, scope);
|
|
864
913
|
break;
|
|
865
914
|
case "UpdateExpression":
|
|
866
|
-
|
|
867
|
-
markWrite(node.argument.name as string, scope);
|
|
868
|
-
}
|
|
869
|
-
pushAndWalk(node, "argument", node.argument, scope);
|
|
915
|
+
walkPattern(node, "argument", node.argument, scope, true);
|
|
870
916
|
break;
|
|
871
917
|
case "MemberExpression":
|
|
872
918
|
pushAndWalk(node, "object", node.object, scope);
|
package/src/watch.ts
CHANGED
|
@@ -105,6 +105,10 @@ export function watchApplication(
|
|
|
105
105
|
appDirectory = path.join(root, "apps/examples", app),
|
|
106
106
|
development = false,
|
|
107
107
|
strictTypecheck = false,
|
|
108
|
+
preflight,
|
|
109
|
+
hostRoot,
|
|
110
|
+
hostExecutable,
|
|
111
|
+
hostSearchFrom,
|
|
108
112
|
extraCapabilities,
|
|
109
113
|
capabilitiesFile,
|
|
110
114
|
cssModuleInclude,
|
|
@@ -305,6 +309,10 @@ export function watchApplication(
|
|
|
305
309
|
root,
|
|
306
310
|
appDirectory,
|
|
307
311
|
development,
|
|
312
|
+
preflight,
|
|
313
|
+
hostRoot,
|
|
314
|
+
hostExecutable,
|
|
315
|
+
hostSearchFrom,
|
|
308
316
|
extraCapabilities,
|
|
309
317
|
capabilitiesFile,
|
|
310
318
|
signal: controller.signal,
|