@jxsuite/compiler 11.0.0 → 11.1.1
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/dist/cli.js +278 -275
- package/dist/compiler.js +120 -117
- package/package.json +8 -8
- package/src/child-separator.ts +260 -0
- package/src/shared.ts +26 -30
- package/src/site/build-time.ts +45 -0
- package/src/site/context-injection.ts +4 -0
- package/src/site/csp.ts +102 -0
- package/src/site/headers-emitter.ts +2 -1
- package/src/site/image-transform.ts +1 -1
- package/src/site/locale-negotiation.ts +44 -14
- package/src/site/site-build.ts +105 -29
- package/src/site/site-loader.ts +2 -1
- package/src/site/social-image.ts +159 -0
- package/src/site/validate-command.ts +54 -34
- package/src/targets/compile-client.ts +20 -9
- package/src/targets/compile-element.ts +14 -6
- package/src/targets/compile-server.ts +3 -2
- package/src/targets/compile-static.ts +5 -4
|
@@ -7,9 +7,13 @@
|
|
|
7
7
|
* root-relative JSON Pointer that resolves inside the file — the editor-resolution guarantee of
|
|
8
8
|
* the committed form (specs/extensions.md §5.4). Checked first and fatal, since walks 2–4
|
|
9
9
|
* compile those documents;
|
|
10
|
-
* 2. `project.json` against the generated entry schema (validateProjectFile)
|
|
10
|
+
* 2. `project.json` against the generated entry schema (validateProjectFile), and every
|
|
11
|
+
* `#/$defs/<Name>` type reference in its own `$defs` against those definitions alone
|
|
12
|
+
* (site-architecture.md §3.1);
|
|
11
13
|
* 3. Every document under `components/`, `pages/`, and `layouts/` against the bundled document schema
|
|
12
|
-
* (core + extension `$paths` union — the same schema the studio consumes)
|
|
14
|
+
* (core + extension `$paths` union — the same schema the studio consumes), and every type
|
|
15
|
+
* reference a well-formed one carries against its own `$defs` and then the project's
|
|
16
|
+
* (site-architecture.md §3.1);
|
|
13
17
|
* 4. Every project-local `*.class.json` against the generated class schema;
|
|
14
18
|
* 5. Every enabled extension's schema fragments compile standalone against the shipped default union
|
|
15
19
|
* resources.
|
|
@@ -25,6 +29,11 @@ import type { EraseWarning } from "@jxsuite/erase";
|
|
|
25
29
|
import { createRequire } from "node:module";
|
|
26
30
|
import { join, relative, resolve } from "node:path";
|
|
27
31
|
import { generateClassSchema } from "@jxsuite/schema";
|
|
32
|
+
import {
|
|
33
|
+
MAP_SUBSCHEMA_KEYWORDS,
|
|
34
|
+
SUBSCHEMA_KEYWORDS,
|
|
35
|
+
findDanglingTypeRefs,
|
|
36
|
+
} from "@jxsuite/schema/type-refs";
|
|
28
37
|
import { validateProjectFile } from "@jxsuite/schema/validate-project";
|
|
29
38
|
import { findA11yDefects } from "@jxsuite/schema/a11y";
|
|
30
39
|
import { findDialogDefects } from "@jxsuite/schema/dialogs";
|
|
@@ -190,6 +199,23 @@ export async function validateProjectTree(
|
|
|
190
199
|
if (!projectResult.valid) {
|
|
191
200
|
issues.push({ errors: projectResult.errors ?? [], file: projectResult.file });
|
|
192
201
|
}
|
|
202
|
+
/* The project's own type definitions. A reference inside them resolves against them alone, and
|
|
203
|
+
a document's resolves in its own `$defs` and then here (site-architecture.md §3.1). */
|
|
204
|
+
const projectDefs = readProjectDefs(root);
|
|
205
|
+
if (projectDefs !== undefined) {
|
|
206
|
+
const dangling = findDanglingTypeRefs({ $defs: projectDefs }).map(({ at, ref }) => ({
|
|
207
|
+
instancePath: at,
|
|
208
|
+
message: `type reference "${ref}" names no definition in project.json's $defs`,
|
|
209
|
+
}));
|
|
210
|
+
if (dangling.length > 0) {
|
|
211
|
+
const reported = issues.find((issue) => issue.file === projectResult.file);
|
|
212
|
+
if (reported === undefined) {
|
|
213
|
+
issues.push({ errors: dangling, file: projectResult.file });
|
|
214
|
+
} else {
|
|
215
|
+
reported.errors.push(...dangling);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
193
219
|
|
|
194
220
|
const { addFormats, Ajv } = await loadAjv();
|
|
195
221
|
|
|
@@ -244,7 +270,18 @@ export async function validateProjectTree(
|
|
|
244
270
|
* SAFETY: validateDoc just accepted `doc` against the bundled document schema, which is
|
|
245
271
|
* the JSON Schema rendering of JxElement.
|
|
246
272
|
*/
|
|
247
|
-
|
|
273
|
+
const wellFormed = doc as JxElement;
|
|
274
|
+
lint.push(...lintDocument(wellFormed, relative(root, file), scope));
|
|
275
|
+
const dangling = findDanglingTypeRefs(wellFormed, projectDefs);
|
|
276
|
+
if (dangling.length > 0) {
|
|
277
|
+
issues.push({
|
|
278
|
+
errors: dangling.map(({ at, ref }) => ({
|
|
279
|
+
instancePath: at,
|
|
280
|
+
message: `type reference "${ref}" names no definition in this document's $defs or in project.json's $defs`,
|
|
281
|
+
})),
|
|
282
|
+
file: relative(root, file),
|
|
283
|
+
});
|
|
284
|
+
}
|
|
248
285
|
} else {
|
|
249
286
|
issues.push({ errors: validateDoc.errors ?? [], file: relative(root, file) });
|
|
250
287
|
}
|
|
@@ -299,6 +336,20 @@ export async function validateProjectTree(
|
|
|
299
336
|
return { checked, issues, lint, valid: issues.length === 0 && !fatalLint };
|
|
300
337
|
}
|
|
301
338
|
|
|
339
|
+
/**
|
|
340
|
+
* The project's `$defs`, when `project.json` loads and declares an object. A project file the
|
|
341
|
+
* loader refuses answers `undefined` and hides nothing: walk 2 has already reported it, and walk 5
|
|
342
|
+
* keeps its own load.
|
|
343
|
+
*/
|
|
344
|
+
function readProjectDefs(root: string): JsonObject | undefined {
|
|
345
|
+
try {
|
|
346
|
+
const defs: unknown = loadProjectConfig(root).config.$defs;
|
|
347
|
+
return isJsonObject(defs) ? defs : undefined;
|
|
348
|
+
} catch {
|
|
349
|
+
return undefined;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
302
353
|
/** A document file as the validator takes it: its value, or why it has none. */
|
|
303
354
|
interface ReadDocumentFile {
|
|
304
355
|
document: JsonValue;
|
|
@@ -505,37 +556,6 @@ function collectUnresolvableRefs(entry: JsonValue): { ref: string; reason: strin
|
|
|
505
556
|
return out;
|
|
506
557
|
}
|
|
507
558
|
|
|
508
|
-
/** Keywords whose values map names to subschemas. */
|
|
509
|
-
const MAP_SUBSCHEMA_KEYWORDS = new Set([
|
|
510
|
-
"$defs",
|
|
511
|
-
"definitions",
|
|
512
|
-
"dependencies",
|
|
513
|
-
"dependentSchemas",
|
|
514
|
-
"patternProperties",
|
|
515
|
-
"properties",
|
|
516
|
-
]);
|
|
517
|
-
|
|
518
|
-
/** Every keyword position a subschema can occupy (see {@link MAP_SUBSCHEMA_KEYWORDS} for maps). */
|
|
519
|
-
const SUBSCHEMA_KEYWORDS = new Set([
|
|
520
|
-
...MAP_SUBSCHEMA_KEYWORDS,
|
|
521
|
-
"additionalItems",
|
|
522
|
-
"additionalProperties",
|
|
523
|
-
"allOf",
|
|
524
|
-
"anyOf",
|
|
525
|
-
"contains",
|
|
526
|
-
"contentSchema",
|
|
527
|
-
"else",
|
|
528
|
-
"if",
|
|
529
|
-
"items",
|
|
530
|
-
"not",
|
|
531
|
-
"oneOf",
|
|
532
|
-
"prefixItems",
|
|
533
|
-
"propertyNames",
|
|
534
|
-
"then",
|
|
535
|
-
"unevaluatedItems",
|
|
536
|
-
"unevaluatedProperties",
|
|
537
|
-
]);
|
|
538
|
-
|
|
539
559
|
/** Recursively list document files under a directory (absent directories yield nothing). */
|
|
540
560
|
function walkJsonFiles(dir: string): string[] {
|
|
541
561
|
if (!existsSync(dir)) {
|
|
@@ -33,7 +33,6 @@ import {
|
|
|
33
33
|
DEFAULT_LIT_HTML_SRC,
|
|
34
34
|
DEFAULT_REACTIVITY_SRC,
|
|
35
35
|
buildAttrs,
|
|
36
|
-
childSeparator,
|
|
37
36
|
colorSchemePrePaintScript,
|
|
38
37
|
compileExpression,
|
|
39
38
|
compileStatements,
|
|
@@ -87,6 +86,7 @@ import {
|
|
|
87
86
|
isTagExpression,
|
|
88
87
|
tagNameCandidates,
|
|
89
88
|
} from "@jxsuite/schema/guards";
|
|
89
|
+
import { blockChildren, joinChildren } from "../child-separator.ts";
|
|
90
90
|
import type { ClientClasses, CompileContext, MappedArrayFeatures, SrcImports } from "../shared.ts";
|
|
91
91
|
import {
|
|
92
92
|
canonicalMapRef,
|
|
@@ -714,9 +714,10 @@ function buildClientNode(
|
|
|
714
714
|
counter.needsLit = true;
|
|
715
715
|
const listKey = `_children${counter.l}`;
|
|
716
716
|
counter.l += 1;
|
|
717
|
-
const childrenTpl =
|
|
718
|
-
.map((c) => emitChildLit(c, nextContext.preformatted))
|
|
719
|
-
|
|
717
|
+
const childrenTpl = joinChildren(
|
|
718
|
+
source.children.map((c) => emitChildLit(c, nextContext.preformatted)),
|
|
719
|
+
{ preformatted: nextContext.preformatted, separator: "\n " },
|
|
720
|
+
);
|
|
720
721
|
bindings.set(
|
|
721
722
|
listKey,
|
|
722
723
|
nextContext.preformatted
|
|
@@ -734,9 +735,10 @@ function buildClientNode(
|
|
|
734
735
|
"Write it as the element's textContent.",
|
|
735
736
|
);
|
|
736
737
|
}
|
|
737
|
-
inner =
|
|
738
|
-
.map((c) => buildClientNode(c, nextContext, bindings, handlers, counter))
|
|
739
|
-
|
|
738
|
+
inner = joinChildren(
|
|
739
|
+
source.children.map((c) => buildClientNode(c, nextContext, bindings, handlers, counter)),
|
|
740
|
+
{ preformatted: nextContext.preformatted },
|
|
741
|
+
);
|
|
740
742
|
}
|
|
741
743
|
|
|
742
744
|
// Self-closing tags
|
|
@@ -963,14 +965,23 @@ function emitLitMapTemplate(def: JxMutableNode | null | undefined, preformatted
|
|
|
963
965
|
inner = mapRefsToLit(String(def.innerHTML));
|
|
964
966
|
} else if (isMappedArray(def.children)) {
|
|
965
967
|
// Legacy whole-children repeater nested inside a map template.
|
|
966
|
-
inner =
|
|
968
|
+
inner = blockChildren([`${emitArrayHole(def.children)}${guard}`], {
|
|
969
|
+
close: "\n ",
|
|
970
|
+
open: "\n ",
|
|
971
|
+
separator: "\n ",
|
|
972
|
+
});
|
|
967
973
|
} else if (Array.isArray(def.children)) {
|
|
968
974
|
const rendered = def.children.map((c) => {
|
|
969
975
|
const text = emitChildLit(c, inPre);
|
|
970
976
|
const isPart = isMappedArray(c) || (isString(c) && isTemplateString(c));
|
|
971
977
|
return isPart ? `${text}${guard}` : text;
|
|
972
978
|
});
|
|
973
|
-
inner =
|
|
979
|
+
inner = blockChildren(rendered, {
|
|
980
|
+
close: "\n ",
|
|
981
|
+
open: "\n ",
|
|
982
|
+
preformatted: inPre,
|
|
983
|
+
separator: "\n ",
|
|
984
|
+
});
|
|
974
985
|
}
|
|
975
986
|
|
|
976
987
|
const voidTags = new Set(["input", "br", "hr", "img", "meta", "link"]);
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* state and lit-html for rendering.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import { joinChildren, padChildren } from "../child-separator.ts";
|
|
8
9
|
import { erasedDocument } from "../erased.ts";
|
|
9
10
|
import { qualifyScripts } from "@jxsuite/schema/document-scripts";
|
|
10
11
|
import {
|
|
@@ -1268,8 +1269,8 @@ function emitLitChildren(
|
|
|
1268
1269
|
an instance's children, a child that emits a lit child part — a binding, a repeater, a chosen
|
|
1269
1270
|
tag — is followed by a guard: distribution moves its neighbours, and a part that ended at one
|
|
1270
1271
|
would clear its new parent on the next update (`LIT_PART_GUARD`). */
|
|
1271
|
-
return
|
|
1272
|
-
.map((child) => {
|
|
1272
|
+
return joinChildren(
|
|
1273
|
+
children.map((child) => {
|
|
1273
1274
|
if (isMappedArray(child)) {
|
|
1274
1275
|
return `${emitMappedArray(child, indent)}${guard}`;
|
|
1275
1276
|
}
|
|
@@ -1278,8 +1279,9 @@ function emitLitChildren(
|
|
|
1278
1279
|
(isString(child) && child.includes("${")) ||
|
|
1279
1280
|
(isNonNullObject(child) && isTagExpression(child.tagName));
|
|
1280
1281
|
return isPart ? `${text}${guard}` : text;
|
|
1281
|
-
})
|
|
1282
|
-
|
|
1282
|
+
}),
|
|
1283
|
+
{ lead: indent, preformatted, separator: "\n" },
|
|
1284
|
+
);
|
|
1283
1285
|
}
|
|
1284
1286
|
|
|
1285
1287
|
/**
|
|
@@ -1573,7 +1575,10 @@ function emitNodeInner(
|
|
|
1573
1575
|
if (def.children) {
|
|
1574
1576
|
return inPre
|
|
1575
1577
|
? emitLitChildren(def.children, def.style, "", true, inMap, scope, guardParts)
|
|
1576
|
-
:
|
|
1578
|
+
: padChildren(
|
|
1579
|
+
emitLitChildren(def.children, def.style, `${indent} `, false, inMap, scope, guardParts),
|
|
1580
|
+
{ close: `\n${indent}`, lead: `${indent} `, open: "\n" },
|
|
1581
|
+
);
|
|
1577
1582
|
}
|
|
1578
1583
|
return "";
|
|
1579
1584
|
}
|
|
@@ -1705,7 +1710,10 @@ function emitMappedArray(arrayDef: JxMappedArray, indent: string) {
|
|
|
1705
1710
|
if (mapDef.textContent !== undefined) {
|
|
1706
1711
|
inner = toLitTextContent(mapDef.textContent);
|
|
1707
1712
|
} else if (mapDef.children) {
|
|
1708
|
-
inner =
|
|
1713
|
+
inner = padChildren(
|
|
1714
|
+
emitLitChildren(mapDef.children, null, `${indent} `, false, true, mapScope),
|
|
1715
|
+
{ close: `\n${indent} `, lead: `${indent} `, open: "\n" },
|
|
1716
|
+
);
|
|
1709
1717
|
}
|
|
1710
1718
|
|
|
1711
1719
|
const body = `html\`\n${indent} <${tag}${attrsStr}\n${indent} >${inner}</${tag}>\n${indent}\``;
|
|
@@ -71,7 +71,8 @@ export interface SiteConnectorSpec {
|
|
|
71
71
|
* `"cloudflare-pages"`, `"node"`, `"bun"`
|
|
72
72
|
* @param {SiteMountSpec[]} [opts.mounts] - Extension server mounts, already sorted by order
|
|
73
73
|
* @param {SiteConnectorSpec[]} [opts.connectors] - Connector classes used by the mounts
|
|
74
|
-
* @param {ResolvedI18n | null} [opts.i18n] - Locale routing; drives the
|
|
74
|
+
* @param {ResolvedI18n | null} [opts.i18n] - Locale routing; drives the root negotiation
|
|
75
|
+
* middleware, registered at `base`
|
|
75
76
|
* @returns {string | null} Complete worker/server source string, or null
|
|
76
77
|
*/
|
|
77
78
|
export function compileSiteServer(
|
|
@@ -121,7 +122,7 @@ export function compileSiteServer(
|
|
|
121
122
|
* fallthrough. It has to be: on `/` it either redirects or hands the request straight back to
|
|
122
123
|
* whatever would have served it, and it cannot do the second from behind a terminal handler.
|
|
123
124
|
*/
|
|
124
|
-
const localeBlock = localeNegotiationMiddleware(i18n);
|
|
125
|
+
const localeBlock = localeNegotiationMiddleware(i18n, base);
|
|
125
126
|
|
|
126
127
|
const gateBlock =
|
|
127
128
|
entries.length === 0 && mounts.length === 0 ? "" : buildRequestGate(base, baseUrl);
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
* `compile-client.ts` (compiler.md §8.1, §9.1).
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
import { joinChildren } from "../child-separator.ts";
|
|
9
10
|
import {
|
|
10
11
|
buildAttrs,
|
|
11
|
-
childSeparator,
|
|
12
12
|
contentPropertyText,
|
|
13
13
|
colorSchemePrePaintScript,
|
|
14
14
|
compileStyles,
|
|
@@ -160,9 +160,10 @@ function buildStaticInner(def: JxMutableNode, tag: string, context: CompileConte
|
|
|
160
160
|
return content;
|
|
161
161
|
}
|
|
162
162
|
if (Array.isArray(def.children)) {
|
|
163
|
-
return
|
|
164
|
-
.map((child) => compileNode(child, context))
|
|
165
|
-
|
|
163
|
+
return joinChildren(
|
|
164
|
+
def.children.map((child) => compileNode(child, context)),
|
|
165
|
+
{ preformatted: context.preformatted },
|
|
166
|
+
);
|
|
166
167
|
}
|
|
167
168
|
return "";
|
|
168
169
|
}
|