@homepages/concrete 1.0.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/CHANGELOG.md +59 -0
- package/README.md +174 -0
- package/codemods/manifest.json +9 -0
- package/dist/artifact/playground/client/assets/index-BSA1yutg.css +1 -0
- package/dist/artifact/playground/client/assets/index-JloQyj8h.js +1101 -0
- package/dist/artifact/playground/client/index.html +13 -0
- package/dist/artifact/playground/client/island-canvas-host.mjs +1 -0
- package/dist/artifact/playground/host.mjs +127 -0
- package/dist/asset-modules.d.ts +99 -0
- package/dist/base.css +220 -0
- package/dist/browser/site-config.d.ts +18 -0
- package/dist/browser/site-config.js +56 -0
- package/dist/browser/submit-lead.d.ts +98 -0
- package/dist/browser/submit-lead.js +188 -0
- package/dist/browser.d.ts +3 -0
- package/dist/browser.js +4 -0
- package/dist/cli/build/artifact.js +225 -0
- package/dist/cli/build/captures.js +67 -0
- package/dist/cli/build/esbuild.js +127 -0
- package/dist/cli/build/fixtures.js +96 -0
- package/dist/cli/build/icons.js +76 -0
- package/dist/cli/build/index.js +38 -0
- package/dist/cli/build/playground.js +31 -0
- package/dist/cli/build/sections.js +236 -0
- package/dist/cli/build/source.js +62 -0
- package/dist/cli/build/static.js +156 -0
- package/dist/cli/capture/bundle.js +37 -0
- package/dist/cli/capture/capture-browser.js +51 -0
- package/dist/cli/capture/capture.js +121 -0
- package/dist/cli/check/analyze.js +95 -0
- package/dist/cli/check/index.js +19 -0
- package/dist/cli/check/load-workspace.js +119 -0
- package/dist/cli/check/messages.js +16 -0
- package/dist/cli/check/render/class-conflicts.js +39 -0
- package/dist/cli/check/render/html.js +86 -0
- package/dist/cli/check/render/inputs.js +53 -0
- package/dist/cli/check/render/invariants.js +58 -0
- package/dist/cli/check/render/island-frames.js +72 -0
- package/dist/cli/check/render/marker-coverage.js +102 -0
- package/dist/cli/check/render/nav.js +64 -0
- package/dist/cli/check/report.js +73 -0
- package/dist/cli/check/stages/bundles.js +129 -0
- package/dist/cli/check/stages/composition.js +67 -0
- package/dist/cli/check/stages/contracts.js +22 -0
- package/dist/cli/check/stages/dependencies.js +261 -0
- package/dist/cli/check/stages/fixtures.js +74 -0
- package/dist/cli/check/stages/lint.js +41 -0
- package/dist/cli/check/stages/logic.js +63 -0
- package/dist/cli/check/stages/render.js +144 -0
- package/dist/cli/check/stages/sections.js +83 -0
- package/dist/cli/check/stages/stylesheet.js +31 -0
- package/dist/cli/check/stages/typecheck.js +68 -0
- package/dist/cli/check/stages/workspace.js +26 -0
- package/dist/cli/commands.js +342 -0
- package/dist/cli/currency/cache.js +89 -0
- package/dist/cli/currency/decide.js +65 -0
- package/dist/cli/currency/opt-out.js +16 -0
- package/dist/cli/currency/preamble.js +183 -0
- package/dist/cli/currency/prompt.js +28 -0
- package/dist/cli/currency/refresh.js +44 -0
- package/dist/cli/currency/resolve-latest.js +185 -0
- package/dist/cli/currency/version-order.js +38 -0
- package/dist/cli/dev/crop.js +22 -0
- package/dist/cli/dev/hmr.js +26 -0
- package/dist/cli/dev/http.js +129 -0
- package/dist/cli/dev/index.js +70 -0
- package/dist/cli/dev/islands.js +390 -0
- package/dist/cli/dev/load-template.js +46 -0
- package/dist/cli/dev/request-error.js +22 -0
- package/dist/cli/dev/server.js +307 -0
- package/dist/cli/dev/tsconfig-paths.js +95 -0
- package/dist/cli/dev/vite.js +85 -0
- package/dist/cli/dev/workspace-reader.js +274 -0
- package/dist/cli/io.d.ts +14 -0
- package/dist/cli/media/cache.js +125 -0
- package/dist/cli/media/derive.js +252 -0
- package/dist/cli/media/deriver-plugin.js +71 -0
- package/dist/cli/property/index.js +180 -0
- package/dist/cli/property/library.js +137 -0
- package/dist/cli/publish/client.js +119 -0
- package/dist/cli/publish/freshness.js +66 -0
- package/dist/cli/publish/git.js +43 -0
- package/dist/cli/publish/index.js +207 -0
- package/dist/cli/publish/pack.js +78 -0
- package/dist/cli/publish/report.js +98 -0
- package/dist/cli/publish/target.js +87 -0
- package/dist/cli/publish/wire.js +29 -0
- package/dist/cli/tar.js +87 -0
- package/dist/cli/upgrade/codemod.js +56 -0
- package/dist/cli/upgrade/index.js +263 -0
- package/dist/cli/upgrade/manifest.js +72 -0
- package/dist/cli/upgrade/plan.js +68 -0
- package/dist/cli/upgrade/stage.js +71 -0
- package/dist/cli/version.d.ts +12 -0
- package/dist/cli/version.js +15 -0
- package/dist/cli/workspace.js +108 -0
- package/dist/cli.d.ts +6 -0
- package/dist/cli.js +94 -0
- package/dist/css/compile.js +77 -0
- package/dist/css/graph.js +109 -0
- package/dist/css/inline.js +132 -0
- package/dist/css/rules.js +65 -0
- package/dist/design-system/format-variants.js +127 -0
- package/dist/eslint/authoring.js +46 -0
- package/dist/eslint/correctness.js +42 -0
- package/dist/eslint/rules/editor-declaration.js +103 -0
- package/dist/eslint/rules/editor-reason.js +135 -0
- package/dist/eslint/rules/island-imports.js +20 -0
- package/dist/eslint/rules/jsx-visitor.js +20 -0
- package/dist/eslint/rules/no-client-runtime.js +88 -0
- package/dist/eslint/rules/no-editor-globals.js +60 -0
- package/dist/eslint/rules/no-hard-coded-color.js +183 -0
- package/dist/eslint/rules/no-inline-style.js +24 -0
- package/dist/eslint/rules/no-marker-literal.js +37 -0
- package/dist/eslint/rules/no-nondeterminism.js +44 -0
- package/dist/eslint/rules/no-px-breakpoint.js +44 -0
- package/dist/eslint/rules/no-raw-values.js +45 -0
- package/dist/eslint/rules/serializable-props.js +95 -0
- package/dist/eslint.d.ts +6 -0
- package/dist/eslint.js +26 -0
- package/dist/fixtures/brand.d.ts +4 -0
- package/dist/fixtures/brand.js +9 -0
- package/dist/fixtures/bundle-rule.js +67 -0
- package/dist/fixtures/canonical.d.ts +149 -0
- package/dist/fixtures/image-dimensions.js +59 -0
- package/dist/fixtures/load.js +154 -0
- package/dist/fixtures/media-plugin.js +141 -0
- package/dist/fixtures/media.js +165 -0
- package/dist/fixtures/property.js +210 -0
- package/dist/fixtures/resolve.js +202 -0
- package/dist/fixtures/rows.js +108 -0
- package/dist/fixtures/synthesize-empties.js +42 -0
- package/dist/fixtures.d.ts +213 -0
- package/dist/fixtures.js +37 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.js +37 -0
- package/dist/islands/client-module.js +97 -0
- package/dist/islands/marker.d.ts +43 -0
- package/dist/islands/marker.js +44 -0
- package/dist/node_modules/.pnpm/fflate@0.8.3/node_modules/fflate/esm/browser.js +687 -0
- package/dist/packages/external/concrete/package.js +5 -0
- package/dist/packages/internal/fact-interpolation/dist/index.js +22 -0
- package/dist/packages/internal/fill-bake/dist/bake-property-ref.js +111 -0
- package/dist/packages/internal/fill-bake/dist/display.js +9 -0
- package/dist/packages/internal/fill-bake/dist/index.js +6 -0
- package/dist/packages/internal/fill-bake/dist/reconcile-cross-section.js +170 -0
- package/dist/packages/internal/fill-vocabulary/dist/facts.d.ts +32 -0
- package/dist/packages/internal/fill-vocabulary/dist/facts.js +131 -0
- package/dist/packages/internal/fill-vocabulary/dist/row-planners.js +73 -0
- package/dist/packages/internal/format-geometry/dist/capture.js +404 -0
- package/dist/packages/internal/format-geometry/dist/format.d.ts +41 -0
- package/dist/packages/internal/format-geometry/dist/geometry.js +58 -0
- package/dist/packages/internal/format-geometry/dist/index.js +4 -0
- package/dist/packages/internal/image-descriptor/dist/index.d.ts +35 -0
- package/dist/packages/internal/image-ladder/dist/crop.js +82 -0
- package/dist/packages/internal/image-ladder/dist/encode.js +23 -0
- package/dist/packages/internal/image-ladder/dist/index.js +4 -0
- package/dist/packages/internal/image-ladder/dist/policy.js +102 -0
- package/dist/packages/internal/island-runtime/dist/capture-holds.d.ts +13 -0
- package/dist/packages/internal/island-runtime/dist/capture-holds.js +45 -0
- package/dist/packages/internal/island-runtime/dist/contract.d.ts +176 -0
- package/dist/packages/internal/island-runtime/dist/contract.js +94 -0
- package/dist/packages/internal/island-runtime/dist/editor-instance-context.js +15 -0
- package/dist/packages/internal/island-runtime/dist/index.d.ts +103 -0
- package/dist/packages/internal/island-runtime/dist/index.js +163 -0
- package/dist/packages/internal/island-runtime/dist/use-capture-ready.d.ts +19 -0
- package/dist/packages/internal/island-runtime/dist/use-capture-ready.js +39 -0
- package/dist/packages/internal/island-runtime/dist/use-editor.d.ts +22 -0
- package/dist/packages/internal/island-runtime/dist/use-editor.js +54 -0
- package/dist/packages/internal/island-runtime/dist/viewport-schedule.js +105 -0
- package/dist/packages/internal/property-facts/dist/derive-facts-view.js +25 -0
- package/dist/packages/internal/property-facts/dist/index.js +3 -0
- package/dist/packages/internal/property-facts/dist/property-facts-CSdkSuD7.js +181 -0
- package/dist/packages/internal/section-contracts/dist/cap-contract.js +59 -0
- package/dist/packages/internal/section-contracts/dist/catalog.js +102 -0
- package/dist/packages/internal/section-contracts/dist/choose-select-contract.js +24 -0
- package/dist/packages/internal/section-contracts/dist/count-bounds-contract.js +48 -0
- package/dist/packages/internal/section-contracts/dist/display-contract.js +30 -0
- package/dist/packages/internal/section-contracts/dist/display-evidence-contract.js +17 -0
- package/dist/packages/internal/section-contracts/dist/group-contract.js +21 -0
- package/dist/packages/internal/section-contracts/dist/index.js +26 -0
- package/dist/packages/internal/section-contracts/dist/interpolation-contract.js +48 -0
- package/dist/packages/internal/section-contracts/dist/list-fill-contract.js +53 -0
- package/dist/packages/internal/section-contracts/dist/list-scalar-contract.js +70 -0
- package/dist/packages/internal/section-contracts/dist/name-title-contract.js +27 -0
- package/dist/packages/internal/section-contracts/dist/nested-slot-contract.js +12 -0
- package/dist/packages/internal/section-contracts/dist/option-source-contract.js +22 -0
- package/dist/packages/internal/section-contracts/dist/poi-curation-contract.js +18 -0
- package/dist/packages/internal/section-contracts/dist/pooling-field-contract.js +30 -0
- package/dist/packages/internal/section-contracts/dist/record-collection-contract.js +24 -0
- package/dist/packages/internal/section-contracts/dist/row-contract.js +37 -0
- package/dist/packages/internal/section-contracts/dist/row-fill-contract.js +38 -0
- package/dist/packages/internal/section-contracts/dist/runners.js +181 -0
- package/dist/packages/internal/section-contracts/dist/select-contract.js +28 -0
- package/dist/packages/internal/section-contracts/dist/source-contract.js +48 -0
- package/dist/packages/internal/section-contracts/dist/source-filter-contract.js +15 -0
- package/dist/packages/internal/section-contracts/dist/sources-contract.js +28 -0
- package/dist/packages/internal/section-contracts/dist/url-contract.js +20 -0
- package/dist/packages/internal/source-resolution/dist/index.js +222 -0
- package/dist/packages/internal/template-artifact/dist/hash.js +50 -0
- package/dist/packages/internal/template-artifact/dist/index.js +7 -0
- package/dist/packages/internal/template-artifact/dist/layout.js +165 -0
- package/dist/packages/internal/template-artifact/dist/manifest.js +73 -0
- package/dist/packages/internal/template-artifact/dist/sha256.js +138 -0
- package/dist/packages/internal/template-artifact/dist/verify.js +275 -0
- package/dist/packages/internal/template-contracts/dist/collection-editing.js +38 -0
- package/dist/packages/internal/template-contracts/dist/content-categories.d.ts +10 -0
- package/dist/packages/internal/template-contracts/dist/content-categories.js +17 -0
- package/dist/packages/internal/template-contracts/dist/document-value.d.ts +33 -0
- package/dist/packages/internal/template-contracts/dist/facts-view.d.ts +81 -0
- package/dist/packages/internal/template-contracts/dist/facts-view.js +136 -0
- package/dist/packages/internal/template-contracts/dist/layout.js +17 -0
- package/dist/packages/internal/template-contracts/dist/markers.d.ts +40 -0
- package/dist/packages/internal/template-contracts/dist/markers.js +41 -0
- package/dist/packages/internal/template-contracts/dist/poi-row.d.ts +63 -0
- package/dist/packages/internal/template-contracts/dist/select-key.js +13 -0
- package/dist/packages/internal/template-contracts/dist/slot-catalog.d.ts +1112 -0
- package/dist/packages/internal/template-contracts/dist/slot-catalog.js +1109 -0
- package/dist/packages/internal/template-contracts/dist/slot-overrides.js +11 -0
- package/dist/packages/internal/template-contracts/dist/tour-value.d.ts +45 -0
- package/dist/packages/internal/template-contracts/dist/video-value.d.ts +63 -0
- package/dist/playground/host/page-state.js +12 -0
- package/dist/playground/host/paths.js +9 -0
- package/dist/playground/layout.js +24 -0
- package/dist/playground/wire.js +36 -0
- package/dist/playground-island-runtime.d.ts +3 -0
- package/dist/playground-island-runtime.js +4 -0
- package/dist/primitives/FrameShell.d.ts +29 -0
- package/dist/primitives/FrameShell.js +34 -0
- package/dist/primitives/Image.d.ts +119 -0
- package/dist/primitives/Image.js +173 -0
- package/dist/primitives/Section.d.ts +22 -0
- package/dist/primitives/Section.js +26 -0
- package/dist/primitives/Tour.d.ts +43 -0
- package/dist/primitives/Tour.js +72 -0
- package/dist/primitives/Video.d.ts +57 -0
- package/dist/primitives/Video.js +116 -0
- package/dist/primitives/embed-playback.js +50 -0
- package/dist/primitives/index.d.ts +11 -0
- package/dist/primitives/marker-attrs.js +44 -0
- package/dist/primitives/object-fit.js +11 -0
- package/dist/primitives/picture-sources.d.ts +24 -0
- package/dist/primitives/picture-sources.js +52 -0
- package/dist/primitives/probe-context.js +24 -0
- package/dist/primitives/slot-bindings.d.ts +96 -0
- package/dist/primitives/slot-bindings.js +226 -0
- package/dist/primitives/slot-document.d.ts +35 -0
- package/dist/primitives/slot-document.js +37 -0
- package/dist/primitives/slot-group.d.ts +40 -0
- package/dist/primitives/slot-group.js +45 -0
- package/dist/primitives/slot-list.d.ts +21 -0
- package/dist/primitives/slot-list.js +23 -0
- package/dist/primitives/slot-media.d.ts +71 -0
- package/dist/primitives/slot-media.js +98 -0
- package/dist/primitives/slot-scalar.d.ts +53 -0
- package/dist/primitives/slot-scalar.js +98 -0
- package/dist/primitives/slot.d.ts +26 -0
- package/dist/primitives/slot.js +28 -0
- package/dist/rules/registry.js +479 -0
- package/dist/schema/compute.d.ts +22 -0
- package/dist/schema/compute.js +30 -0
- package/dist/schema/define-schema.d.ts +27 -0
- package/dist/schema/define-schema.js +73 -0
- package/dist/schema/extract-fill-spec.js +246 -0
- package/dist/schema/extract-used-facts.js +176 -0
- package/dist/schema/fact.d.ts +65 -0
- package/dist/schema/fact.js +33 -0
- package/dist/schema/fill-builders.d.ts +387 -0
- package/dist/schema/fill-builders.js +263 -0
- package/dist/schema/fill-declaration.d.ts +76 -0
- package/dist/schema/fill-declaration.js +43 -0
- package/dist/schema/fill-spec.d.ts +18 -0
- package/dist/schema/fill-spec.js +170 -0
- package/dist/schema/format-presets.d.ts +27 -0
- package/dist/schema/format-presets.js +76 -0
- package/dist/schema/format.d.ts +22 -0
- package/dist/schema/format.js +40 -0
- package/dist/schema/formats.d.ts +6 -0
- package/dist/schema/formats.js +7 -0
- package/dist/schema/layout.d.ts +32 -0
- package/dist/schema/layout.js +30 -0
- package/dist/schema/manifest.js +300 -0
- package/dist/schema/property-facts.d.ts +83 -0
- package/dist/schema/runtime-values.d.ts +88 -0
- package/dist/schema/section-nav.d.ts +38 -0
- package/dist/schema/section-nav.js +29 -0
- package/dist/schema/section-props.d.ts +98 -0
- package/dist/schema/section-schema.d.ts +53 -0
- package/dist/schema/section-schema.js +54 -0
- package/dist/schema/slot-builders.d.ts +497 -0
- package/dist/schema/slot-builders.js +331 -0
- package/dist/schema/slot-types.d.ts +110 -0
- package/dist/schema/slot-types.js +187 -0
- package/dist/section/declare.d.ts +44 -0
- package/dist/section/declare.js +27 -0
- package/dist/section/discovery.js +76 -0
- package/dist/section/groups.js +74 -0
- package/dist/section/materialize.js +28 -0
- package/dist/section/placements.js +28 -0
- package/dist/section/section.d.ts +69 -0
- package/dist/section/section.js +101 -0
- package/dist/site-analytics.d.ts +1 -0
- package/dist/site-analytics.js +15 -0
- package/dist/site-runtime/analytics.js +97 -0
- package/dist/site-runtime/site-integrations.js +97 -0
- package/dist/styles.css +60 -0
- package/dist/template/define-template.d.ts +139 -0
- package/dist/template/define-template.js +98 -0
- package/dist/template/logic-build.js +191 -0
- package/dist/template/logic-shim.d.ts +43 -0
- package/dist/template/logic-shim.js +52 -0
- package/dist/template/logic-transform.js +92 -0
- package/dist/template/materialize.js +107 -0
- package/dist/template/reconcile.d.ts +67 -0
- package/dist/template/reconcile.js +25 -0
- package/dist/template/running-copy.js +58 -0
- package/guide/reference/cli/INDEX.md +79 -0
- package/guide/reference/cli/build.md +48 -0
- package/guide/reference/cli/check.md +49 -0
- package/guide/reference/cli/dev.md +46 -0
- package/guide/reference/cli/property-add.md +53 -0
- package/guide/reference/cli/property-list.md +46 -0
- package/guide/reference/cli/publish.md +54 -0
- package/guide/reference/cli/upgrade.md +48 -0
- package/guide/reference/rules/INDEX.md +190 -0
- package/package.json +137 -0
- package/tsconfig.base.json +16 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { declaringModule } from "../../../section/section.js";
|
|
2
|
+
import { TEMPLATE_FILE, workspacePath } from "../load-workspace.js";
|
|
3
|
+
import { describeError } from "../messages.js";
|
|
4
|
+
import { recordPlacements } from "../../../section/placements.js";
|
|
5
|
+
import { materializeTemplate } from "../../../template/materialize.js";
|
|
6
|
+
import { createElement } from "react";
|
|
7
|
+
import { isAbsolute } from "node:path";
|
|
8
|
+
|
|
9
|
+
//#region src/cli/check/stages/composition.ts
|
|
10
|
+
function compositionStage(ctx) {
|
|
11
|
+
const { workspace, discovered } = ctx;
|
|
12
|
+
if (workspace?.template === null || workspace === void 0 || discovered === void 0) return Promise.resolve({ skipped: "the workspace stage could not load template.ts and its sections" });
|
|
13
|
+
const { root, template } = workspace;
|
|
14
|
+
const moduleOf = /* @__PURE__ */ new Map();
|
|
15
|
+
for (const [file, exports] of workspace.modules) for (const value of Object.values(exports)) if (!moduleOf.has(value)) moduleOf.set(value, workspacePath(root, file));
|
|
16
|
+
const locate = (page) => moduleOf.get(page);
|
|
17
|
+
const violations = [];
|
|
18
|
+
for (const page of template.pages) {
|
|
19
|
+
let markup;
|
|
20
|
+
try {
|
|
21
|
+
markup = recordPlacements(createElement(page.page)).markup;
|
|
22
|
+
} catch (cause) {
|
|
23
|
+
violations.push({
|
|
24
|
+
rule: "pages/composition-invalid",
|
|
25
|
+
file: locate(page.page) ?? "template.ts",
|
|
26
|
+
message: `Page "${page.id}" throws when it is rendered under the page probe: ${describeError(cause)}`
|
|
27
|
+
});
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (markup === "") continue;
|
|
31
|
+
const excerpt = markup.replace(/\s+/g, " ").trim();
|
|
32
|
+
violations.push({
|
|
33
|
+
rule: "pages/non-section-markup",
|
|
34
|
+
file: locate(page.page) ?? "template.ts",
|
|
35
|
+
message: `Page "${page.id}" emits markup that is not a section: ${excerpt.length > 80 ? `${excerpt.slice(0, 77)}…` : excerpt}. A page may contain only sections and components that contain only sections; the platform has nowhere to put page markup.`
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
if (violations.length > 0) return Promise.resolve({ violations });
|
|
39
|
+
let composition;
|
|
40
|
+
try {
|
|
41
|
+
composition = materializeTemplate(template, { locate });
|
|
42
|
+
} catch (cause) {
|
|
43
|
+
return Promise.resolve({ violations: [{
|
|
44
|
+
rule: "pages/composition-invalid",
|
|
45
|
+
file: TEMPLATE_FILE,
|
|
46
|
+
message: describeError(cause)
|
|
47
|
+
}] });
|
|
48
|
+
}
|
|
49
|
+
ctx.composition = composition;
|
|
50
|
+
const exported = new Set(discovered.map((entry) => entry.section));
|
|
51
|
+
const reported = /* @__PURE__ */ new Set();
|
|
52
|
+
for (const placement of composition.placements) {
|
|
53
|
+
if (exported.has(placement.section) || reported.has(placement.section)) continue;
|
|
54
|
+
reported.add(placement.section);
|
|
55
|
+
const at = declaringModule(placement.section);
|
|
56
|
+
const file = at !== void 0 && isAbsolute(at) && at.startsWith(root) ? workspacePath(root, at) : TEMPLATE_FILE;
|
|
57
|
+
violations.push({
|
|
58
|
+
rule: "pages/section-not-exported",
|
|
59
|
+
file,
|
|
60
|
+
message: `Section "${placement.key}" is placed but exported by no module. Export it from ${file} so the build can bundle it alone.`
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return Promise.resolve({ violations });
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
//#endregion
|
|
67
|
+
export { compositionStage };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { contractRuleId } from "../../../rules/registry.js";
|
|
2
|
+
import { collectSectionContractViolations } from "../../../packages/internal/section-contracts/dist/runners.js";
|
|
3
|
+
import "../../../packages/internal/section-contracts/dist/index.js";
|
|
4
|
+
|
|
5
|
+
//#region src/cli/check/stages/contracts.ts
|
|
6
|
+
function contractsStage(ctx) {
|
|
7
|
+
if (ctx.sections === void 0) return Promise.resolve({ skipped: "the sections stage could not materialize the placed sections" });
|
|
8
|
+
const violations = [];
|
|
9
|
+
for (const { key, file, schema, fillSpec } of ctx.sections) for (const violation of collectSectionContractViolations({
|
|
10
|
+
key,
|
|
11
|
+
schema,
|
|
12
|
+
fillSpec
|
|
13
|
+
})) violations.push({
|
|
14
|
+
rule: contractRuleId(violation.contract),
|
|
15
|
+
file,
|
|
16
|
+
message: violation.message
|
|
17
|
+
});
|
|
18
|
+
return Promise.resolve({ violations });
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
export { contractsStage };
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { join, relative, sep } from "node:path";
|
|
2
|
+
import { readFile, readdir, realpath, stat } from "node:fs/promises";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { execFile } from "node:child_process";
|
|
5
|
+
import { promisify } from "node:util";
|
|
6
|
+
|
|
7
|
+
//#region src/cli/check/stages/dependencies.ts
|
|
8
|
+
const execFileAsync = promisify(execFile);
|
|
9
|
+
/** Real `execFile`-backed runner. Never throws on a non-zero exit: `npm audit` and
|
|
10
|
+
* `npm ls` both use exit codes to report findings, not tool failure, so the caller
|
|
11
|
+
* must always get the payload to parse. */
|
|
12
|
+
const defaultRunCommand = async (cmd, args, cwd) => {
|
|
13
|
+
try {
|
|
14
|
+
const shell = process.platform === "win32";
|
|
15
|
+
const { stdout } = await execFileAsync(cmd, [...args], {
|
|
16
|
+
cwd,
|
|
17
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
18
|
+
shell
|
|
19
|
+
});
|
|
20
|
+
return {
|
|
21
|
+
stdout,
|
|
22
|
+
code: 0
|
|
23
|
+
};
|
|
24
|
+
} catch (err) {
|
|
25
|
+
const e = err;
|
|
26
|
+
return {
|
|
27
|
+
stdout: typeof e.stdout === "string" ? e.stdout : "",
|
|
28
|
+
code: typeof e.code === "number" ? e.code : 1
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
/** A vulnerability at or above this severity fails the check. */
|
|
33
|
+
const AUDIT_FAIL_ON = ["high", "critical"];
|
|
34
|
+
const LOCKFILE = "package-lock.json";
|
|
35
|
+
async function isFile(p) {
|
|
36
|
+
try {
|
|
37
|
+
return (await stat(p)).isFile();
|
|
38
|
+
} catch {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async function isDir(p) {
|
|
43
|
+
try {
|
|
44
|
+
return (await stat(p)).isDirectory();
|
|
45
|
+
} catch {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** `fs.realpath`, or `undefined` if the path is missing or unresolvable
|
|
50
|
+
* (e.g. a broken symlink or a genuine symlink loop, which trips `ELOOP`). */
|
|
51
|
+
async function realPathOrUndefined(p) {
|
|
52
|
+
try {
|
|
53
|
+
return await realpath(p);
|
|
54
|
+
} catch {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async function readJsonIfPresent(path) {
|
|
59
|
+
if (!await isFile(path)) return void 0;
|
|
60
|
+
const text = await readFile(path, "utf8");
|
|
61
|
+
return JSON.parse(text);
|
|
62
|
+
}
|
|
63
|
+
function safeJsonParse(text) {
|
|
64
|
+
try {
|
|
65
|
+
return JSON.parse(text);
|
|
66
|
+
} catch {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const NO_LOCKFILE = {
|
|
71
|
+
rule: "dependencies/lockfile-missing",
|
|
72
|
+
gates: [
|
|
73
|
+
"dependencies/lockfile-stale",
|
|
74
|
+
"dependencies/single-react",
|
|
75
|
+
"dependencies/audit-severity"
|
|
76
|
+
],
|
|
77
|
+
reason: "no package-lock.json at the workspace root, so there is no npm-resolved tree to grade.",
|
|
78
|
+
fix: "Run npm install and commit the package-lock.json it writes: a template without one cannot be reproduced, and these gates have nothing to read until it exists."
|
|
79
|
+
};
|
|
80
|
+
const NPM_LS_UNRUNNABLE = {
|
|
81
|
+
rule: "dependencies/lockfile-stale",
|
|
82
|
+
gates: ["dependencies/lockfile-stale"],
|
|
83
|
+
reason: "npm ls returned no parseable report, so the lockfile was never inspected.",
|
|
84
|
+
fix: "Run npm ls --json --package-lock-only in the workspace and fix whatever stops it reporting (usually npm missing from PATH), then re-run concrete check."
|
|
85
|
+
};
|
|
86
|
+
const NPM_AUDIT_UNRUNNABLE = {
|
|
87
|
+
rule: "dependencies/audit-severity",
|
|
88
|
+
gates: ["dependencies/audit-severity"],
|
|
89
|
+
reason: "npm audit returned no parseable report, so no advisory was ever read.",
|
|
90
|
+
fix: "Run npm audit --json in the workspace and fix whatever stops it reporting (usually npm missing from PATH, or no network access), then re-run concrete check."
|
|
91
|
+
};
|
|
92
|
+
const npmLsNodeSchema = z.lazy(() => z.looseObject({
|
|
93
|
+
invalid: z.boolean().optional(),
|
|
94
|
+
dependencies: z.record(z.string(), npmLsNodeSchema).optional()
|
|
95
|
+
}));
|
|
96
|
+
const npmLsPayloadSchema = z.looseObject({
|
|
97
|
+
problems: z.array(z.unknown()).optional(),
|
|
98
|
+
dependencies: z.record(z.string(), npmLsNodeSchema).optional()
|
|
99
|
+
});
|
|
100
|
+
function anyInvalid(nodes) {
|
|
101
|
+
if (!nodes) return false;
|
|
102
|
+
for (const node of Object.values(nodes)) {
|
|
103
|
+
if (node.invalid === true) return true;
|
|
104
|
+
if (anyInvalid(node.dependencies)) return true;
|
|
105
|
+
}
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
async function lockfileStaleGate(run, root) {
|
|
109
|
+
const { stdout, code } = await run("npm", [
|
|
110
|
+
"ls",
|
|
111
|
+
"--json",
|
|
112
|
+
"--package-lock-only"
|
|
113
|
+
], root);
|
|
114
|
+
const parsed = npmLsPayloadSchema.safeParse(safeJsonParse(stdout));
|
|
115
|
+
if (!parsed.success) return {
|
|
116
|
+
violations: [],
|
|
117
|
+
unmeasured: NPM_LS_UNRUNNABLE
|
|
118
|
+
};
|
|
119
|
+
if (!(code !== 0 || (parsed.data.problems?.length ?? 0) > 0 || anyInvalid(parsed.data.dependencies))) return { violations: [] };
|
|
120
|
+
return { violations: [{
|
|
121
|
+
rule: "dependencies/lockfile-stale",
|
|
122
|
+
file: LOCKFILE,
|
|
123
|
+
message: "The lockfile does not satisfy package.json, so npm ci would fail. Run npm install and commit the updated lockfile."
|
|
124
|
+
}] };
|
|
125
|
+
}
|
|
126
|
+
const SINGLE_REACT_FIX = "Two copies of React break hydration. React is a peer of everything here, so deduplicate with npm dedupe, or align the dependency that pins its own copy.";
|
|
127
|
+
const packageManifestSchema = z.looseObject({ version: z.string().optional() });
|
|
128
|
+
async function readVersion(pkgDir) {
|
|
129
|
+
try {
|
|
130
|
+
const raw = await readJsonIfPresent(join(pkgDir, "package.json"));
|
|
131
|
+
const parsed = packageManifestSchema.safeParse(raw);
|
|
132
|
+
return parsed.success && parsed.data.version !== void 0 ? parsed.data.version : "unknown version";
|
|
133
|
+
} catch {
|
|
134
|
+
return "unknown version";
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/** True when `entry` is worth descending into: a real directory, or a symlink whose
|
|
138
|
+
* target is one. `Dirent.isDirectory()` reports the dirent's OWN type, not what it
|
|
139
|
+
* resolves to: a symlink to a directory (exactly how `npm link` and npm workspaces
|
|
140
|
+
* lay out linked packages) reports `false`, so trusting it blindly makes the walk
|
|
141
|
+
* blind to every linked package's own `node_modules`. `isDir` re-`stat`s, which
|
|
142
|
+
* follows the link. */
|
|
143
|
+
async function isTraversableDir(dir, entry) {
|
|
144
|
+
if (entry.isDirectory()) return true;
|
|
145
|
+
if (!entry.isSymbolicLink()) return false;
|
|
146
|
+
return isDir(join(dir, entry.name));
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Walks `node_modules` for a nested `react` or `react-dom`: one whose own
|
|
150
|
+
* `node_modules` (not the workspace's top-level one) holds a copy. `owner` is the
|
|
151
|
+
* name of the package whose private `node_modules` directory holds the offending
|
|
152
|
+
* copy, so the message can point straight at what to dedupe.
|
|
153
|
+
*
|
|
154
|
+
* `topLevelReal` maps "react"/"react-dom" to the REAL (symlink-resolved) path of the
|
|
155
|
+
* workspace's own top-level copy, if any; see `visitReactCandidate` for why identity
|
|
156
|
+
* is checked against it rather than against walk depth. `visited` is the set of real
|
|
157
|
+
* directory paths already walked: a defense against a symlink cycle (a linked
|
|
158
|
+
* package whose own `node_modules` loops back to an ancestor already on the path)
|
|
159
|
+
* turning this into infinite recursion.
|
|
160
|
+
*/
|
|
161
|
+
async function walkForNestedReact(dir, atTopLevel, owner, out, topLevelReal, visited) {
|
|
162
|
+
const real = await realPathOrUndefined(dir);
|
|
163
|
+
if (real === void 0 || visited.has(real)) return;
|
|
164
|
+
visited.add(real);
|
|
165
|
+
let entries;
|
|
166
|
+
try {
|
|
167
|
+
entries = await readdir(dir, { withFileTypes: true });
|
|
168
|
+
} catch {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
for (const entry of entries) {
|
|
172
|
+
if (!await isTraversableDir(dir, entry)) continue;
|
|
173
|
+
if (entry.name.startsWith("@")) {
|
|
174
|
+
const scopeDir = join(dir, entry.name);
|
|
175
|
+
let scoped;
|
|
176
|
+
try {
|
|
177
|
+
scoped = await readdir(scopeDir, { withFileTypes: true });
|
|
178
|
+
} catch {
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
for (const inner of scoped) {
|
|
182
|
+
if (!await isTraversableDir(scopeDir, inner)) continue;
|
|
183
|
+
await visitReactCandidate(join(scopeDir, inner.name), `${entry.name}/${inner.name}`, atTopLevel, owner, out, topLevelReal, visited);
|
|
184
|
+
}
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
await visitReactCandidate(join(dir, entry.name), entry.name, atTopLevel, owner, out, topLevelReal, visited);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
async function visitReactCandidate(pkgDir, name, atTopLevel, owner, out, topLevelReal, visited) {
|
|
191
|
+
if (!atTopLevel && (name === "react" || name === "react-dom")) {
|
|
192
|
+
if ((await realPathOrUndefined(pkgDir) ?? pkgDir) !== topLevelReal.get(name)) out.push({
|
|
193
|
+
name,
|
|
194
|
+
version: await readVersion(pkgDir),
|
|
195
|
+
owner,
|
|
196
|
+
dir: pkgDir
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
const nested = join(pkgDir, "node_modules");
|
|
200
|
+
if (await isDir(nested)) await walkForNestedReact(nested, false, name, out, topLevelReal, visited);
|
|
201
|
+
}
|
|
202
|
+
async function singleReactGate(root) {
|
|
203
|
+
const nodeModules = join(root, "node_modules");
|
|
204
|
+
const offenders = [];
|
|
205
|
+
const topLevelReal = /* @__PURE__ */ new Map();
|
|
206
|
+
for (const name of ["react", "react-dom"]) {
|
|
207
|
+
const real = await realPathOrUndefined(join(nodeModules, name));
|
|
208
|
+
if (real !== void 0) topLevelReal.set(name, real);
|
|
209
|
+
}
|
|
210
|
+
await walkForNestedReact(nodeModules, true, "", offenders, topLevelReal, /* @__PURE__ */ new Set());
|
|
211
|
+
return offenders.map((offender) => ({
|
|
212
|
+
rule: "dependencies/single-react",
|
|
213
|
+
file: relative(root, offender.dir).split(sep).join("/"),
|
|
214
|
+
message: `A nested copy of ${offender.name}@${offender.version} is bundled inside ${offender.owner}'s own node_modules. ${SINGLE_REACT_FIX}`
|
|
215
|
+
}));
|
|
216
|
+
}
|
|
217
|
+
const npmAuditPayloadSchema = z.looseObject({ metadata: z.looseObject({ vulnerabilities: z.record(z.string(), z.number()).optional() }).optional() });
|
|
218
|
+
async function auditSeverityGate(run, root) {
|
|
219
|
+
const { stdout } = await run("npm", ["audit", "--json"], root);
|
|
220
|
+
const parsed = npmAuditPayloadSchema.safeParse(safeJsonParse(stdout));
|
|
221
|
+
const vulnerabilities = parsed.success ? parsed.data.metadata?.vulnerabilities : void 0;
|
|
222
|
+
if (vulnerabilities === void 0) return {
|
|
223
|
+
violations: [],
|
|
224
|
+
unmeasured: NPM_AUDIT_UNRUNNABLE
|
|
225
|
+
};
|
|
226
|
+
const offendingSeverities = AUDIT_FAIL_ON.filter((severity) => (vulnerabilities[severity] ?? 0) > 0);
|
|
227
|
+
if (offendingSeverities.length === 0) return { violations: [] };
|
|
228
|
+
const counts = offendingSeverities.map((severity) => `${String(vulnerabilities[severity] ?? 0)} ${severity}`).join(", ");
|
|
229
|
+
return { violations: [{
|
|
230
|
+
rule: "dependencies/audit-severity",
|
|
231
|
+
file: LOCKFILE,
|
|
232
|
+
message: `npm audit found ${counts} severity advisories. Run npm audit fix, or upgrade the package the advisory names.`
|
|
233
|
+
}] };
|
|
234
|
+
}
|
|
235
|
+
/** Grades the workspace at `root` against every `dependencies/*` rule. Spawns npm
|
|
236
|
+
* through `run` (twice, unless there is no lockfile, in which case never) and never
|
|
237
|
+
* throws on what npm reports. */
|
|
238
|
+
async function dependencyGates(root, run = defaultRunCommand) {
|
|
239
|
+
if (!await isFile(join(root, LOCKFILE))) return {
|
|
240
|
+
violations: [],
|
|
241
|
+
unmeasured: [NO_LOCKFILE]
|
|
242
|
+
};
|
|
243
|
+
const lockfileStale = await lockfileStaleGate(run, root);
|
|
244
|
+
const singleReact = await singleReactGate(root);
|
|
245
|
+
const auditSeverity = await auditSeverityGate(run, root);
|
|
246
|
+
const violations = [
|
|
247
|
+
...lockfileStale.violations,
|
|
248
|
+
...singleReact,
|
|
249
|
+
...auditSeverity.violations
|
|
250
|
+
];
|
|
251
|
+
const unmeasured = [];
|
|
252
|
+
if (lockfileStale.unmeasured !== void 0) unmeasured.push(lockfileStale.unmeasured);
|
|
253
|
+
if (auditSeverity.unmeasured !== void 0) unmeasured.push(auditSeverity.unmeasured);
|
|
254
|
+
return {
|
|
255
|
+
violations,
|
|
256
|
+
unmeasured
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
//#endregion
|
|
261
|
+
export { AUDIT_FAIL_ON, defaultRunCommand, dependencyGates };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { TEMPLATE_FILE } from "../load-workspace.js";
|
|
2
|
+
import { resolveEdit } from "../../../template/materialize.js";
|
|
3
|
+
import { loadFixtures } from "../../../fixtures/load.js";
|
|
4
|
+
import { findFixturesReachableFromBundle } from "../../../fixtures/bundle-rule.js";
|
|
5
|
+
import { resolveFixture, uniquePlacements } from "../../../fixtures/resolve.js";
|
|
6
|
+
import { synthesizeEmptyFixtures } from "../../../fixtures/synthesize-empties.js";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
|
|
9
|
+
//#region src/cli/check/stages/fixtures.ts
|
|
10
|
+
/**
|
|
11
|
+
* The template's rules as the platform's reconcile runner takes them: reads and edits
|
|
12
|
+
* addressed to the instance each section key resolves to, exactly as the template
|
|
13
|
+
* logic bundle addresses them.
|
|
14
|
+
*/
|
|
15
|
+
function bakeReconcileRules(template, composition) {
|
|
16
|
+
const { instanceBySection } = composition;
|
|
17
|
+
return template.reconcile.map((rule) => ({
|
|
18
|
+
description: rule.description,
|
|
19
|
+
reads: rule.reads.flatMap((ref) => {
|
|
20
|
+
const instanceId = instanceBySection[ref.section];
|
|
21
|
+
return instanceId === void 0 ? [] : [{
|
|
22
|
+
instanceId,
|
|
23
|
+
slot: ref.slot
|
|
24
|
+
}];
|
|
25
|
+
}),
|
|
26
|
+
fn: ({ site, facts }) => rule.fn({
|
|
27
|
+
site,
|
|
28
|
+
facts
|
|
29
|
+
}).map((edit) => resolveEdit(edit, instanceBySection))
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
/** The synthesized empties, each tagged with the (instance, slot) it emptied. */
|
|
33
|
+
function emptiesOf(first, composition) {
|
|
34
|
+
const instances = uniquePlacements(composition.placements).map((p) => p.instance);
|
|
35
|
+
const prefix = `${first.id}/empty/`;
|
|
36
|
+
return synthesizeEmptyFixtures(first, composition.placements).map((fixture) => {
|
|
37
|
+
const rest = fixture.id.slice(prefix.length);
|
|
38
|
+
const instance = instances.find((id) => rest.startsWith(`${id}/`)) ?? "";
|
|
39
|
+
return {
|
|
40
|
+
fixture,
|
|
41
|
+
emptied: {
|
|
42
|
+
instance,
|
|
43
|
+
slot: rest.slice(instance.length + 1)
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
async function fixturesStage(ctx) {
|
|
49
|
+
const { workspace, composition } = ctx;
|
|
50
|
+
if (workspace?.template === null || workspace === void 0 || composition === void 0) return { skipped: "the composition stage could not derive the placed instances fixtures resolve over" };
|
|
51
|
+
const loaded = await loadFixtures({ root: ctx.root });
|
|
52
|
+
const violations = [...loaded.violations];
|
|
53
|
+
const reconcile = bakeReconcileRules(workspace.template, composition);
|
|
54
|
+
const resolved = [];
|
|
55
|
+
for (const fixture of loaded.fixtures) {
|
|
56
|
+
const result = resolveFixture(fixture, {
|
|
57
|
+
placements: composition.placements,
|
|
58
|
+
reconcile
|
|
59
|
+
});
|
|
60
|
+
violations.push(...result.violations);
|
|
61
|
+
if (result.resolved !== null) resolved.push(result.resolved);
|
|
62
|
+
}
|
|
63
|
+
violations.push(...await findFixturesReachableFromBundle({
|
|
64
|
+
root: ctx.root,
|
|
65
|
+
entries: [join(ctx.root, TEMPLATE_FILE)]
|
|
66
|
+
}));
|
|
67
|
+
const first = resolved[0];
|
|
68
|
+
ctx.corpus = [...resolved.map((fixture) => ({ fixture })), ...first === void 0 ? [] : emptiesOf(first, composition)];
|
|
69
|
+
ctx.assets = loaded.assets;
|
|
70
|
+
return { violations };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
//#endregion
|
|
74
|
+
export { bakeReconcileRules, fixturesStage };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { eslintRuleByEngineId, isConcreteRuleId } from "../../../rules/registry.js";
|
|
2
|
+
import { concreteConfig } from "../../../eslint.js";
|
|
3
|
+
import { workspacePath } from "../load-workspace.js";
|
|
4
|
+
import { ESLint } from "eslint";
|
|
5
|
+
|
|
6
|
+
//#region src/cli/check/stages/lint.ts
|
|
7
|
+
function registeredRule(engineId) {
|
|
8
|
+
const registered = eslintRuleByEngineId(engineId);
|
|
9
|
+
if (registered !== void 0) return registered.id;
|
|
10
|
+
const bare = engineId.startsWith("concrete/") ? engineId.slice(9) : "";
|
|
11
|
+
if (isConcreteRuleId(bare)) return bare;
|
|
12
|
+
throw new Error(`check: the preset reported "${engineId}", which the rule registry does not list.`);
|
|
13
|
+
}
|
|
14
|
+
async function lintStage(ctx) {
|
|
15
|
+
const { root } = ctx;
|
|
16
|
+
const results = await new ESLint({
|
|
17
|
+
cwd: root,
|
|
18
|
+
overrideConfigFile: true,
|
|
19
|
+
overrideConfig: [{ ignores: [
|
|
20
|
+
"**/node_modules/**",
|
|
21
|
+
"**/.concrete/**",
|
|
22
|
+
"**/dist/**"
|
|
23
|
+
] }, ...concreteConfig],
|
|
24
|
+
errorOnUnmatchedPattern: false
|
|
25
|
+
}).lintFiles(["**/*.ts", "**/*.tsx"]);
|
|
26
|
+
const violations = [];
|
|
27
|
+
for (const result of results) for (const message of result.messages) {
|
|
28
|
+
if (message.severity !== 2) continue;
|
|
29
|
+
const file = workspacePath(root, result.filePath);
|
|
30
|
+
violations.push({
|
|
31
|
+
rule: message.ruleId === null ? "lint/parse-error" : registeredRule(message.ruleId),
|
|
32
|
+
file,
|
|
33
|
+
line: message.line,
|
|
34
|
+
message: message.message.split(root).join(".")
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return { violations };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
export { lintStage };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { TEMPLATE_FILE } from "../load-workspace.js";
|
|
2
|
+
import { describeError } from "../messages.js";
|
|
3
|
+
import { buildSectionLogic, buildTemplateLogic } from "../../../template/logic-build.js";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
|
|
6
|
+
//#region src/cli/check/stages/logic.ts
|
|
7
|
+
/** How many rules a built template logic bundle carries, read by importing it. */
|
|
8
|
+
async function bundledRuleCount(bundle) {
|
|
9
|
+
const { reconcile } = await import(`data:text/javascript;base64,${Buffer.from(bundle).toString("base64")}`);
|
|
10
|
+
return Array.isArray(reconcile) ? reconcile.length : 0;
|
|
11
|
+
}
|
|
12
|
+
async function logicStage(ctx) {
|
|
13
|
+
const { workspace, discovered, composition } = ctx;
|
|
14
|
+
const template = workspace?.template ?? null;
|
|
15
|
+
if (template === null || discovered === void 0 || composition === void 0) return { skipped: "the composition stage could not derive the placed sections" };
|
|
16
|
+
const violations = [];
|
|
17
|
+
const sections = /* @__PURE__ */ new Map();
|
|
18
|
+
for (const [key, section] of composition.sections) {
|
|
19
|
+
const site = discovered.find((candidate) => candidate.section === section);
|
|
20
|
+
if (site === void 0) continue;
|
|
21
|
+
try {
|
|
22
|
+
sections.set(key, await buildSectionLogic({
|
|
23
|
+
module: join(ctx.root, site.module),
|
|
24
|
+
exportName: site.exportName
|
|
25
|
+
}));
|
|
26
|
+
} catch (cause) {
|
|
27
|
+
violations.push({
|
|
28
|
+
rule: "logic/section-build-failed",
|
|
29
|
+
file: site.module,
|
|
30
|
+
message: `Section "${key}"'s logic bundle does not build: ${describeError(cause)}`
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
let templateLogic;
|
|
35
|
+
try {
|
|
36
|
+
templateLogic = await buildTemplateLogic({
|
|
37
|
+
templateFile: join(ctx.root, TEMPLATE_FILE),
|
|
38
|
+
instances: composition.instances
|
|
39
|
+
});
|
|
40
|
+
const bundled = await bundledRuleCount(templateLogic);
|
|
41
|
+
const authored = template.reconcile.length;
|
|
42
|
+
if (bundled !== authored) violations.push({
|
|
43
|
+
rule: "logic/reconcile-not-exported",
|
|
44
|
+
file: TEMPLATE_FILE,
|
|
45
|
+
message: `defineTemplate() was handed ${String(authored)} reconcile rule(s), but the template logic bundle carries ${String(bundled)}. The bundle reads the named export, so declare the rules as \`export const reconcile = [...]\` in ${TEMPLATE_FILE} and pass that same array to defineTemplate({ reconcile }).`
|
|
46
|
+
});
|
|
47
|
+
} catch (cause) {
|
|
48
|
+
violations.push({
|
|
49
|
+
rule: "logic/template-build-failed",
|
|
50
|
+
file: TEMPLATE_FILE,
|
|
51
|
+
message: `The template logic bundle does not build or evaluate: ${describeError(cause)}`
|
|
52
|
+
});
|
|
53
|
+
return { violations };
|
|
54
|
+
}
|
|
55
|
+
if (violations.length === 0) ctx.logic = {
|
|
56
|
+
sections,
|
|
57
|
+
template: templateLogic
|
|
58
|
+
};
|
|
59
|
+
return { violations };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
export { logicStage };
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { isCollectionSlotType } from "../../../packages/internal/template-contracts/dist/slot-catalog.js";
|
|
2
|
+
import { describeError } from "../messages.js";
|
|
3
|
+
import { renderInputs } from "../render/inputs.js";
|
|
4
|
+
import { collectionEditing } from "../../../packages/internal/template-contracts/dist/collection-editing.js";
|
|
5
|
+
import { checkClassConflicts } from "../render/class-conflicts.js";
|
|
6
|
+
import { parseHtml } from "../render/html.js";
|
|
7
|
+
import { checkRenderInvariants } from "../render/invariants.js";
|
|
8
|
+
import { checkItemIndices, collectMarkerCoverage } from "../render/marker-coverage.js";
|
|
9
|
+
import { createElement } from "react";
|
|
10
|
+
import { renderToStaticMarkup } from "react-dom/server";
|
|
11
|
+
|
|
12
|
+
//#region src/cli/check/stages/render.ts
|
|
13
|
+
function editingViewOf(spec) {
|
|
14
|
+
return {
|
|
15
|
+
type: spec.type ?? "",
|
|
16
|
+
...spec.element !== void 0 ? { element: spec.element } : {},
|
|
17
|
+
...spec.fields !== void 0 ? { fields: spec.fields } : {}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function fieldIsLocked(field) {
|
|
21
|
+
return typeof field === "object" && field !== null && field.locked === true;
|
|
22
|
+
}
|
|
23
|
+
const INVARIANT_RULE = {
|
|
24
|
+
"sentinel-text": "render/sentinel-text",
|
|
25
|
+
"broken-image": "render/broken-image",
|
|
26
|
+
"unresolved-media": "render/unresolved-media"
|
|
27
|
+
};
|
|
28
|
+
const INVARIANT_FIX = {
|
|
29
|
+
"sentinel-text": "A value reached the page without a formatter. Format it, or render nothing when it is absent.",
|
|
30
|
+
"broken-image": "Render a placeholder, or nothing, when an image slot is empty; never an <img> with no src.",
|
|
31
|
+
"unresolved-media": "State media by value, as an entry of the fixture's property, so the load mints its URL; never a hand-written media path."
|
|
32
|
+
};
|
|
33
|
+
/** What the corpus proved about one section, unioned over every render of it. */
|
|
34
|
+
var SectionEvidence = class {
|
|
35
|
+
entry;
|
|
36
|
+
marked = /* @__PURE__ */ new Set();
|
|
37
|
+
selectable = /* @__PURE__ */ new Set();
|
|
38
|
+
unitWithItems = /* @__PURE__ */ new Set();
|
|
39
|
+
rowFields = /* @__PURE__ */ new Map();
|
|
40
|
+
escapedGroup = /* @__PURE__ */ new Set();
|
|
41
|
+
findings = /* @__PURE__ */ new Map();
|
|
42
|
+
constructor(entry) {
|
|
43
|
+
this.entry = entry;
|
|
44
|
+
}
|
|
45
|
+
report(rule, message) {
|
|
46
|
+
const key = `${rule}|${message}`;
|
|
47
|
+
if (!this.findings.has(key)) this.findings.set(key, {
|
|
48
|
+
rule,
|
|
49
|
+
file: this.entry.file,
|
|
50
|
+
message
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
function renderStage(ctx) {
|
|
55
|
+
const { composition, sections, corpus } = ctx;
|
|
56
|
+
if (composition === void 0 || sections === void 0) return Promise.resolve({ skipped: "the sections stage could not materialize the placed sections" });
|
|
57
|
+
if (corpus === void 0 || corpus.length === 0) return Promise.resolve({ skipped: "no fixture resolved, so the render corpus is empty" });
|
|
58
|
+
const assets = ctx.assets ?? /* @__PURE__ */ new Map();
|
|
59
|
+
const imported = ctx.workspace?.assets ?? /* @__PURE__ */ new Map();
|
|
60
|
+
const carriesMedia = (url) => {
|
|
61
|
+
const path = new URL(url, "http://workspace.invalid").pathname;
|
|
62
|
+
return assets.has(path) || imported.has(path);
|
|
63
|
+
};
|
|
64
|
+
const evidence = new Map(sections.map((entry) => [entry.key, new SectionEvidence(entry)]));
|
|
65
|
+
for (const { corpus: { emptied }, instanceId, entry, props, where } of renderInputs(composition, sections, corpus)) {
|
|
66
|
+
const proof = evidence.get(entry.key);
|
|
67
|
+
if (proof === void 0) continue;
|
|
68
|
+
const { section, schema } = proof.entry;
|
|
69
|
+
const Component = section;
|
|
70
|
+
let first;
|
|
71
|
+
let second;
|
|
72
|
+
try {
|
|
73
|
+
first = renderToStaticMarkup(createElement(Component, props));
|
|
74
|
+
second = renderToStaticMarkup(createElement(Component, props));
|
|
75
|
+
} catch (cause) {
|
|
76
|
+
proof.report("render/unrenderable", `${where}: the section throws when it renders: ${describeError(cause)}`);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const coverage = collectMarkerCoverage(parseHtml(first));
|
|
80
|
+
for (const id of coverage.slotIds) proof.marked.add(id);
|
|
81
|
+
for (const id of coverage.selectableSlotIds) proof.selectable.add(id);
|
|
82
|
+
for (const [slotId, fields] of coverage.rowFieldsBySlot) {
|
|
83
|
+
const seen = proof.rowFields.get(slotId) ?? /* @__PURE__ */ new Set();
|
|
84
|
+
for (const field of fields) seen.add(field);
|
|
85
|
+
proof.rowFields.set(slotId, seen);
|
|
86
|
+
}
|
|
87
|
+
const groupOf = /* @__PURE__ */ new Map();
|
|
88
|
+
for (const group of schema.groups ?? []) for (const member of group.members.flatMap((row) => typeof row === "string" ? [row] : [...row])) groupOf.set(member, group.id);
|
|
89
|
+
for (const [slotId, instances] of coverage.enclosingGroupsBySlot) {
|
|
90
|
+
const group = groupOf.get(slotId);
|
|
91
|
+
if (group !== void 0 && instances.some((groups) => !groups.has(group))) proof.escapedGroup.add(slotId);
|
|
92
|
+
}
|
|
93
|
+
for (const conflict of checkClassConflicts(first)) proof.report("render/section-root-margin", `The section root carries margin utility "${conflict.token}". Zero margin on the root is what lets consecutive sections butt edge-to-edge; space content with padding instead.`);
|
|
94
|
+
const slots = schema.slots;
|
|
95
|
+
if (emptied !== void 0 && emptied.instance === instanceId && slots[emptied.slot]?.locked !== true && slots[emptied.slot] !== void 0) {
|
|
96
|
+
if (!coverage.slotIds.has(emptied.slot)) proof.report("render/missing-slot-marker", `Slot "${emptied.slot}" is marked when it has a value but vanishes from the DOM when it is empty (${where}). Render the marked element unconditionally; branch on the binding's \`present\` inside it to change what an empty slot looks like.`);
|
|
97
|
+
else if (!coverage.selectableSlotIds.has(emptied.slot)) proof.report("render/missing-slot-marker", `Slot "${emptied.slot}" is selectable when it has a value, but every copy is flagged non-selectable when it is empty (${where}). Keep one rendering of the empty state selectable.`);
|
|
98
|
+
}
|
|
99
|
+
for (const [slotId, spec] of Object.entries(slots)) {
|
|
100
|
+
if (!isCollectionSlotType(spec.type ?? "")) continue;
|
|
101
|
+
const scopes = coverage.itemScopesBySlot.get(slotId) ?? [];
|
|
102
|
+
const granularity = collectionEditing(editingViewOf(spec));
|
|
103
|
+
if (granularity === "unit" && scopes.some((scope) => scope.indices.length > 0)) proof.unitWithItems.add(slotId);
|
|
104
|
+
if (granularity !== "item" || spec.locked === true) continue;
|
|
105
|
+
const rows = props.slots[slotId];
|
|
106
|
+
if (!Array.isArray(rows)) continue;
|
|
107
|
+
for (const problem of checkItemIndices(rows.length, scopes)) proof.report("render/missing-slot-marker", `Slot "${slotId}" (${spec.type ?? "collection"}): ${problem}. Render each row as a SlotGroup over bindItems(...), which emits the row index from the array position.`);
|
|
108
|
+
}
|
|
109
|
+
if (first !== second) {
|
|
110
|
+
proof.report("render/determinism-drift", `${where} rendered differently twice from the same input. A section must be a pure function of its props: no clock, no random, no unstable iteration order.`);
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
for (const violation of checkRenderInvariants(first, carriesMedia)) proof.report(INVARIANT_RULE[violation.rule], `${where}: ${violation.detail}. ${INVARIANT_FIX[violation.rule]}`);
|
|
114
|
+
}
|
|
115
|
+
const violations = [];
|
|
116
|
+
for (const proof of evidence.values()) {
|
|
117
|
+
const slots = proof.entry.schema.slots;
|
|
118
|
+
violations.push(...proof.findings.values());
|
|
119
|
+
const at = (rule, message) => void violations.push({
|
|
120
|
+
rule,
|
|
121
|
+
file: proof.entry.file,
|
|
122
|
+
message
|
|
123
|
+
});
|
|
124
|
+
for (const slotId of proof.unitWithItems) at("render/unit-collection-item-marker", `Slot "${slotId}" declares a single-slot item, so it is edited as one card, but its rendering emits data-slot-item row markers the editor never uses. Declare the item as a record if its rows should be individually editable, or render the rows as plain elements.`);
|
|
125
|
+
for (const [slotId, spec] of Object.entries(slots)) {
|
|
126
|
+
if (spec.fields == null || spec.locked === true || !isCollectionSlotType(spec.type ?? "")) continue;
|
|
127
|
+
const declared = Object.entries(spec.fields).filter(([, field]) => !fieldIsLocked(field)).map(([field]) => field);
|
|
128
|
+
const seen = proof.rowFields.get(slotId) ?? /* @__PURE__ */ new Set();
|
|
129
|
+
const missing = declared.filter((field) => !seen.has(field));
|
|
130
|
+
if (missing.length === 0) continue;
|
|
131
|
+
at("render/missing-slot-marker", `Row field${missing.length === 1 ? "" : "s"} ${missing.map((f) => `"${f}"`).join(", ")} of "${slotId}" never render as data-slot-field in any fixture, so the editor cannot select ${missing.length === 1 ? "it" : "them"} on any row. Render each row field through its binding, or declare it locked: true.`);
|
|
132
|
+
}
|
|
133
|
+
for (const slotId of proof.escapedGroup) at("render/group-ancestry", `Slot "${slotId}" belongs to a group but is marked on an element outside that group's element, so the editor resolves it to no group. Move the marked element inside the SlotGroup, or render the outside copy with selectable={false}.`);
|
|
134
|
+
for (const [slotId, spec] of Object.entries(slots)) {
|
|
135
|
+
if (spec.locked === true) continue;
|
|
136
|
+
if (!proof.marked.has(slotId)) at("render/missing-slot-marker", `Slot "${slotId}" is editable but never renders as data-slot-id in any fixture, so the editor cannot select it. Render it through its own Slot primitive, which owns the marker.`);
|
|
137
|
+
else if (!proof.selectable.has(slotId)) at("render/missing-slot-marker", `Slot "${slotId}" reaches the DOM only on elements flagged non-selectable, so the editor can never select it. Render at least one copy without selectable={false}.`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return Promise.resolve({ violations });
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
//#endregion
|
|
144
|
+
export { renderStage };
|