@homepages/concrete 5.0.0 → 6.0.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/CHANGELOG.md +342 -0
- package/README.md +28 -17
- package/codemods/fill-is-a-source.mjs +533 -0
- package/codemods/manifest.json +16 -0
- package/codemods/reads-replace-reconcile.mjs +285 -0
- package/dist/artifact/playground/client/assets/{index-D1fwOGVK.js → index-u3T7DiSN.js} +96 -96
- package/dist/artifact/playground/client/index.html +1 -1
- package/dist/artifact/playground/host.mjs +23 -23
- package/dist/base.css +3 -8
- package/dist/browser/site-config.js +1 -16
- package/dist/browser/submit-lead.js +0 -31
- package/dist/cli/build/artifact.js +16 -23
- package/dist/cli/build/captures.js +0 -6
- package/dist/cli/build/esbuild.js +0 -17
- package/dist/cli/build/fixtures.js +15 -30
- package/dist/cli/build/icons.js +0 -3
- package/dist/cli/build/index.js +1 -1
- package/dist/cli/build/playground.js +4 -8
- package/dist/cli/build/sections.js +9 -30
- package/dist/cli/build/source.js +52 -27
- package/dist/cli/build/static.js +4 -25
- package/dist/cli/capture/bundle.js +0 -9
- package/dist/cli/capture/capture-browser.js +0 -14
- package/dist/cli/capture/capture.js +1 -8
- package/dist/cli/check/analyze.js +2 -5
- package/dist/cli/check/index.js +1 -1
- package/dist/cli/check/line-endings.js +52 -0
- package/dist/cli/check/load-workspace.js +3 -8
- package/dist/cli/check/portable-names.js +48 -0
- package/dist/cli/check/render/class-conflicts.js +0 -5
- package/dist/cli/check/render/html.js +0 -1
- package/dist/cli/check/render/invariants.js +0 -5
- package/dist/cli/check/render/island-frames.js +0 -25
- package/dist/cli/check/render/marker-coverage.js +0 -20
- package/dist/cli/check/render/nav.js +0 -33
- package/dist/cli/check/report.js +0 -3
- package/dist/cli/check/stages/bundles.js +1 -9
- package/dist/cli/check/stages/composition.js +3 -2
- package/dist/cli/check/stages/dependencies.js +7 -38
- package/dist/cli/check/stages/fixtures.js +3 -31
- package/dist/cli/check/stages/lint.js +2 -2
- package/dist/cli/check/stages/logic.js +3 -34
- package/dist/cli/check/stages/relations.js +46 -0
- package/dist/cli/check/stages/render.js +0 -1
- package/dist/cli/check/stages/sections.js +3 -3
- package/dist/cli/check/stages/stylesheet.js +1 -1
- package/dist/cli/check/stages/typecheck.js +5 -11
- package/dist/cli/check/stages/workspace.js +36 -14
- package/dist/cli/commands.js +9 -56
- package/dist/cli/currency/cache.js +4 -17
- package/dist/cli/currency/decide.js +0 -14
- package/dist/cli/currency/opt-out.js +0 -7
- package/dist/cli/currency/preamble.js +3 -24
- package/dist/cli/currency/prompt.js +0 -1
- package/dist/cli/currency/refresh.js +5 -12
- package/dist/cli/currency/resolve-latest.js +3 -64
- package/dist/cli/currency/version-order.js +0 -12
- package/dist/cli/dev/crop.js +0 -2
- package/dist/cli/dev/http.js +0 -13
- package/dist/cli/dev/index.js +3 -4
- package/dist/cli/dev/islands.js +25 -70
- package/dist/cli/dev/listen.js +26 -0
- package/dist/cli/dev/load-template.js +0 -1
- package/dist/cli/dev/request-error.js +0 -4
- package/dist/cli/dev/server.js +46 -52
- package/dist/cli/dev/tsconfig-paths.js +0 -13
- package/dist/cli/dev/vite.js +9 -38
- package/dist/cli/dev/workspace-reader.js +4 -34
- package/dist/cli/media/cache.js +4 -51
- package/dist/cli/media/derive.js +2 -94
- package/dist/cli/media/deriver-plugin.js +0 -2
- package/dist/cli/media/frame-rung-floor.js +0 -6
- package/dist/cli/property/index.js +0 -4
- package/dist/cli/property/library.js +6 -24
- package/dist/cli/publish/client.js +0 -1
- package/dist/cli/publish/freshness.js +0 -2
- package/dist/cli/publish/git.js +2 -8
- package/dist/cli/publish/index.js +8 -15
- package/dist/cli/publish/pack.js +5 -6
- package/dist/cli/publish/report.js +0 -6
- package/dist/cli/publish/target.js +16 -13
- package/dist/cli/publish/wire.js +0 -6
- package/dist/cli/tar.js +2 -9
- package/dist/cli/upgrade/codemod.js +0 -8
- package/dist/cli/upgrade/index.js +0 -24
- package/dist/cli/upgrade/manifest.js +0 -12
- package/dist/cli/upgrade/plan.js +0 -17
- package/dist/cli/upgrade/stage.js +12 -15
- package/dist/cli/version.js +0 -8
- package/dist/cli/workspace.js +2 -34
- package/dist/cli.js +4 -21
- package/dist/css/compile.js +25 -28
- package/dist/css/graph.js +3 -10
- package/dist/css/inline.js +3 -16
- package/dist/css/rules.js +6 -43
- package/dist/design-system/format-variants.js +0 -22
- package/dist/eslint/authoring.js +0 -2
- package/dist/eslint/correctness.js +0 -7
- package/dist/eslint/rules/editor-reason.js +0 -11
- package/dist/eslint/rules/island-ids.js +0 -1
- package/dist/eslint/rules/jsx-visitor.js +0 -13
- package/dist/eslint/rules/no-editor-globals.js +0 -2
- package/dist/eslint/rules/no-raw-values.js +0 -1
- package/dist/fixtures/brand.js +0 -1
- package/dist/fixtures/bundle-rule.js +4 -9
- package/dist/fixtures/canonical.d.ts +20 -0
- package/dist/fixtures/image-dimensions.js +0 -1
- package/dist/fixtures/load.js +8 -17
- package/dist/fixtures/media-plugin.js +4 -31
- package/dist/fixtures/media.js +0 -21
- package/dist/fixtures/package-stylesheets.js +0 -6
- package/dist/fixtures/property.js +16 -15
- package/dist/fixtures/resolve.js +102 -29
- package/dist/fixtures/rows.js +12 -11
- package/dist/fixtures/synthesize-empties.js +0 -4
- package/dist/fixtures.d.ts +19 -4
- package/dist/fixtures.js +0 -18
- package/dist/index.d.ts +8 -9
- package/dist/index.js +2 -11
- package/dist/islands/client-module.js +0 -11
- package/dist/islands/marker.js +0 -33
- package/dist/node_modules/.pnpm/fflate@0.8.3/node_modules/fflate/esm/browser.js +0 -20
- package/dist/packages/external/concrete/package.js +1 -1
- package/dist/packages/internal/fill-bake/dist/bake-property-ref.js +21 -35
- package/dist/packages/internal/fill-bake/dist/compute-reads.js +4 -0
- package/dist/packages/internal/fill-bake/dist/derive-source.js +40 -0
- package/dist/packages/internal/fill-bake/dist/display.js +0 -1
- package/dist/packages/internal/fill-bake/dist/index.js +4 -4
- package/dist/packages/internal/fill-vocabulary/dist/origination.js +106 -0
- package/dist/packages/internal/fill-vocabulary/dist/row-planners.js +1 -49
- package/dist/packages/internal/format-geometry/dist/capture.js +10 -240
- package/dist/packages/internal/format-geometry/dist/geometry.js +0 -6
- package/dist/packages/internal/image-ladder/dist/crop.js +0 -12
- package/dist/packages/internal/image-ladder/dist/policy.js +0 -14
- package/dist/packages/internal/island-runtime/dist/capture-holds.js +0 -13
- package/dist/packages/internal/island-runtime/dist/contract.js +0 -34
- package/dist/packages/internal/island-runtime/dist/editor-instance-context.js +0 -1
- package/dist/packages/internal/island-runtime/dist/index.js +0 -34
- package/dist/packages/internal/island-runtime/dist/island-id-context.js +0 -1
- package/dist/packages/internal/island-runtime/dist/use-capture-ready.js +0 -15
- package/dist/packages/internal/island-runtime/dist/use-editor.js +0 -10
- package/dist/packages/internal/island-runtime/dist/use-island-id.js +0 -32
- package/dist/packages/internal/property-facts/dist/derive-facts-view.js +2 -17
- package/dist/packages/internal/property-facts/dist/index.js +1 -1
- package/dist/packages/internal/property-facts/dist/{property-facts-CSdkSuD7.js → property-facts-5pxZnlkh.js} +13 -2
- package/dist/packages/internal/section-contracts/dist/cap-contract.js +1 -18
- package/dist/packages/internal/section-contracts/dist/catalog.js +16 -8
- package/dist/packages/internal/section-contracts/dist/choose-select-contract.js +12 -16
- package/dist/packages/internal/section-contracts/dist/count-bounds-contract.js +5 -11
- package/dist/packages/internal/section-contracts/dist/display-contract.js +2 -0
- package/dist/packages/internal/section-contracts/dist/display-evidence-contract.js +2 -8
- package/dist/packages/internal/section-contracts/dist/fill-spec-view.js +13 -0
- package/dist/packages/internal/section-contracts/dist/index.js +2 -1
- package/dist/packages/internal/section-contracts/dist/interpolation-contract.js +16 -42
- package/dist/packages/internal/section-contracts/dist/list-fill-contract.js +24 -43
- package/dist/packages/internal/section-contracts/dist/name-title-contract.js +11 -18
- package/dist/packages/internal/section-contracts/dist/poi-curation-contract.js +10 -12
- package/dist/packages/internal/section-contracts/dist/pooling-field-contract.js +3 -13
- package/dist/packages/internal/section-contracts/dist/row-fill-contract.js +6 -18
- package/dist/packages/internal/section-contracts/dist/runners.js +21 -13
- package/dist/packages/internal/section-contracts/dist/source-contract.js +13 -2
- package/dist/packages/internal/section-contracts/dist/writer-reads-fact-contract.js +31 -0
- package/dist/packages/internal/source-resolution/dist/index.js +1 -9
- package/dist/packages/internal/template-artifact/dist/hash.js +0 -8
- package/dist/packages/internal/template-artifact/dist/index.js +1 -1
- package/dist/packages/internal/template-artifact/dist/layout.js +0 -39
- package/dist/packages/internal/template-artifact/dist/manifest.js +1 -9
- package/dist/packages/internal/template-artifact/dist/sha256.js +0 -1
- package/dist/packages/internal/template-artifact/dist/verify.js +2 -4
- package/dist/packages/internal/template-contracts/dist/collection-editing.js +0 -16
- package/dist/packages/internal/template-contracts/dist/content-categories.js +0 -4
- package/dist/packages/internal/template-contracts/dist/facts-view.d.ts +16 -10
- package/dist/packages/internal/template-contracts/dist/facts-view.js +15 -28
- package/dist/packages/internal/template-contracts/dist/layout.js +0 -7
- package/dist/packages/internal/template-contracts/dist/markers.js +0 -29
- package/dist/packages/internal/template-contracts/dist/select-key.js +0 -6
- package/dist/packages/internal/template-contracts/dist/slot-catalog.d.ts +56 -34
- package/dist/packages/internal/template-contracts/dist/slot-catalog.js +22 -389
- package/dist/platform/file-url.js +8 -0
- package/dist/platform/fs.js +73 -0
- package/dist/platform/names.js +63 -0
- package/dist/platform/order.js +7 -0
- package/dist/platform/paths.js +66 -0
- package/dist/platform/process.js +97 -0
- package/dist/playground/host/page-state.js +0 -2
- package/dist/playground/host/paths.js +0 -1
- package/dist/playground/layout.js +0 -7
- package/dist/playground/wire.js +0 -8
- package/dist/primitives/FrameShell.js +0 -18
- package/dist/primitives/Image.d.ts +5 -1
- package/dist/primitives/Image.js +2 -68
- package/dist/primitives/Section.js +0 -13
- package/dist/primitives/Tour.js +0 -26
- package/dist/primitives/Video.js +0 -32
- package/dist/primitives/embed-playback.js +0 -1
- package/dist/primitives/marker-attrs.js +0 -17
- package/dist/primitives/picture-sources.js +6 -1
- package/dist/primitives/probe-context.js +0 -7
- package/dist/primitives/slot-bindings.js +0 -46
- package/dist/primitives/slot-document.js +0 -11
- package/dist/primitives/slot-group.js +0 -9
- package/dist/primitives/slot-media.js +0 -27
- package/dist/primitives/slot-scalar.js +0 -4
- package/dist/primitives/slot.js +0 -6
- package/dist/rules/registry.js +42 -24
- package/dist/schema/compute.d.ts +46 -8
- package/dist/schema/compute.js +21 -15
- package/dist/schema/define-schema.d.ts +1 -1
- package/dist/schema/define-schema.js +37 -17
- package/dist/schema/extract-fill-spec.js +93 -180
- package/dist/schema/extract-used-facts.js +16 -158
- package/dist/schema/fact.d.ts +25 -12
- package/dist/schema/fact.js +7 -11
- package/dist/schema/fill-builders.d.ts +91 -366
- package/dist/schema/fill-builders.js +21 -259
- package/dist/schema/fill-declaration.d.ts +7 -69
- package/dist/schema/fill-declaration.js +5 -34
- package/dist/schema/fill-spec.js +59 -148
- package/dist/schema/format-presets.js +0 -12
- package/dist/schema/format.js +0 -7
- package/dist/schema/layout.js +0 -10
- package/dist/schema/manifest.js +0 -39
- package/dist/schema/property-facts.d.ts +20 -0
- package/dist/schema/section-nav.js +0 -15
- package/dist/schema/section-schema.d.ts +0 -1
- package/dist/schema/section-schema.js +4 -20
- package/dist/schema/slot-builders.d.ts +128 -117
- package/dist/schema/slot-builders.js +18 -201
- package/dist/schema/slot-ref.d.ts +63 -0
- package/dist/schema/slot-ref.js +33 -0
- package/dist/schema/slot-types.d.ts +3 -2
- package/dist/schema/slot-types.js +11 -20
- package/dist/section/declare.d.ts +14 -10
- package/dist/section/declare.js +13 -2
- package/dist/section/discovery.js +6 -21
- package/dist/section/groups.js +0 -6
- package/dist/section/materialize.js +0 -5
- package/dist/section/placements.js +0 -4
- package/dist/section/section.d.ts +8 -5
- package/dist/section/section.js +7 -29
- package/dist/styles.css +5 -0
- package/dist/template/define-template.d.ts +0 -4
- package/dist/template/define-template.js +1 -15
- package/dist/template/logic-build.js +8 -35
- package/dist/template/logic-shim.d.ts +4 -5
- package/dist/template/logic-shim.js +2 -6
- package/dist/template/logic-transform.js +0 -6
- package/dist/template/materialize.js +52 -43
- package/dist/template/mirror-types.js +43 -0
- package/dist/template/running-copy.js +5 -20
- package/dist/template/section-reads.js +83 -0
- package/guide/reference/cli/INDEX.md +12 -6
- package/guide/reference/cli/build.md +1 -1
- package/guide/reference/cli/check.md +1 -1
- package/guide/reference/cli/dev.md +3 -3
- package/guide/reference/cli/property-add.md +1 -1
- package/guide/reference/cli/property-list.md +1 -1
- package/guide/reference/cli/publish.md +4 -2
- package/guide/reference/cli/upgrade.md +1 -1
- package/guide/reference/rules/INDEX.md +26 -13
- package/package.json +4 -2
- package/dist/packages/internal/fact-interpolation/dist/index.js +0 -22
- package/dist/packages/internal/fill-bake/dist/reconcile-cross-section.js +0 -170
- package/dist/packages/internal/fill-vocabulary/dist/facts.d.ts +0 -32
- package/dist/packages/internal/fill-vocabulary/dist/facts.js +0 -131
- package/dist/packages/internal/template-contracts/dist/slot-overrides.js +0 -11
- package/dist/schema/fill-spec.d.ts +0 -18
- package/dist/template/reconcile.d.ts +0 -67
- package/dist/template/reconcile.js +0 -25
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
// A template carries no cross-section logic, and a compute reads only what it declares.
|
|
2
|
+
//
|
|
3
|
+
// Before this release a template could hand `defineTemplate` a `reconcile` list of
|
|
4
|
+
// `rule(…)` calls that wrote `set(…)` edits into other sections, and a slot could derive
|
|
5
|
+
// its value with `compute((f) => …)` over the whole derive-time `Facts` view, its reads
|
|
6
|
+
// recovered by tracing the callback. Both are gone. A slot that depends on another
|
|
7
|
+
// section says so on its own `source:` — a slot ref (`source: Hero.slots.title`) to
|
|
8
|
+
// mirror it, or `compute({ reads: [Hero.slots.title] }, (title) => …)` to derive from it —
|
|
9
|
+
// and a compute's callback takes one positional value per ref it declares. `rule`, `set`,
|
|
10
|
+
// the `Facts` view type and `FactsNarrative` are no longer exported; the row types
|
|
11
|
+
// (`FactsUnit`, `FactsAddress`, …) stay, as the values a ref hands a callback.
|
|
12
|
+
//
|
|
13
|
+
// What this codemod does, in every `.ts` and `.tsx` under the workspace:
|
|
14
|
+
//
|
|
15
|
+
// - Deletes a `reconcile` that holds no rule: `reconcile: []` on `defineTemplate`, or a
|
|
16
|
+
// `reconcile` naming a top-level `const reconcile = []` in the same file, which goes
|
|
17
|
+
// with it. Almost every template has only ever carried the empty list.
|
|
18
|
+
// - Drops `rule`, `set`, `Facts` and `FactsNarrative` from a framework import once
|
|
19
|
+
// nothing in the file uses them any more.
|
|
20
|
+
//
|
|
21
|
+
// What it leaves to you, reported per file:
|
|
22
|
+
//
|
|
23
|
+
// - A `reconcile` that holds rules. Each rule becomes a `source:` on the slot it sets:
|
|
24
|
+
// a mirror where it copied a value, a `compute({ reads }, …)` where it derived one.
|
|
25
|
+
// A mirror follows its upstream until the author overrides it, which is what a rule
|
|
26
|
+
// that re-ran on every edit did.
|
|
27
|
+
// - A one-argument `compute(fn)` whose callback takes the facts view. Declare what it
|
|
28
|
+
// reads — `compute({ reads: [fact.property.units] }, (units) => …)` — and take the
|
|
29
|
+
// values as parameters. A `compute(() => X)` that reads nothing is unchanged.
|
|
30
|
+
// - A use of `Facts` or `FactsNarrative`: type a helper by the values it is handed
|
|
31
|
+
// (`readonly FactsUnit[]`, `FactsAddress`), and read the description as
|
|
32
|
+
// `fact.description`.
|
|
33
|
+
|
|
34
|
+
import { readdir, readFile, writeFile } from "node:fs/promises";
|
|
35
|
+
import { join, relative, sep } from "node:path";
|
|
36
|
+
|
|
37
|
+
import ts from "typescript";
|
|
38
|
+
|
|
39
|
+
const CONCRETE = "@homepages/concrete";
|
|
40
|
+
|
|
41
|
+
/** The names this release took out of the barrel. */
|
|
42
|
+
const RETIRED = new Set(["rule", "set", "Facts", "FactsNarrative"]);
|
|
43
|
+
|
|
44
|
+
const EXTENSIONS = [".ts", ".tsx"];
|
|
45
|
+
const SKIP_DIRS = new Set(["node_modules", ".concrete", ".git", "dist", "build"]);
|
|
46
|
+
|
|
47
|
+
async function sourceFiles(root) {
|
|
48
|
+
const found = [];
|
|
49
|
+
async function walk(dir) {
|
|
50
|
+
for (const entry of await readdir(dir, { withFileTypes: true })) {
|
|
51
|
+
if (entry.isDirectory()) {
|
|
52
|
+
if (!SKIP_DIRS.has(entry.name)) await walk(join(dir, entry.name));
|
|
53
|
+
} else if (EXTENSIONS.some((ext) => entry.name.endsWith(ext)) && !entry.name.endsWith(".d.ts")) {
|
|
54
|
+
found.push(join(dir, entry.name));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
await walk(root);
|
|
59
|
+
return found.sort();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const isEmptyArray = (node) => node !== undefined && ts.isArrayLiteralExpression(node) && node.elements.length === 0;
|
|
63
|
+
|
|
64
|
+
function lineOf(sf, pos) {
|
|
65
|
+
return sf.getLineAndCharacterOfPosition(pos).line + 1;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Where the `//` comment lines directly above `lineStart` begin — the comment that
|
|
69
|
+
// describes a member, which would be left describing nothing.
|
|
70
|
+
function commentLinesAbove(text, lineStart) {
|
|
71
|
+
let start = lineStart;
|
|
72
|
+
while (start > 0) {
|
|
73
|
+
const previous = text.lastIndexOf("\n", start - 2) + 1;
|
|
74
|
+
if (!/^[ \t]*\/\/[^\n]*\n$/.test(text.slice(previous, start))) break;
|
|
75
|
+
start = previous;
|
|
76
|
+
}
|
|
77
|
+
return start;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// The span that deletes one member of a comma-separated list — an object literal's
|
|
81
|
+
// property — together with its comma and, when it sat on a line of its own, that line
|
|
82
|
+
// and the comment lines directly above it.
|
|
83
|
+
function memberSpan(sf, node) {
|
|
84
|
+
const text = sf.text;
|
|
85
|
+
let start = node.getStart(sf);
|
|
86
|
+
let end = node.getEnd();
|
|
87
|
+
let after = end;
|
|
88
|
+
while (after < text.length && (text[after] === " " || text[after] === "\t")) after++;
|
|
89
|
+
const trailingComma = text[after] === ",";
|
|
90
|
+
if (trailingComma) end = after + 1;
|
|
91
|
+
|
|
92
|
+
const lineStart = text.lastIndexOf("\n", start - 1) + 1;
|
|
93
|
+
const ownLine = /^[ \t]*$/.test(text.slice(lineStart, start));
|
|
94
|
+
if (ownLine) {
|
|
95
|
+
let lineEnd = end;
|
|
96
|
+
while (lineEnd < text.length && (text[lineEnd] === " " || text[lineEnd] === "\t")) lineEnd++;
|
|
97
|
+
if (text[lineEnd] === "\n") return { start: commentLinesAbove(text, lineStart), end: lineEnd + 1 };
|
|
98
|
+
}
|
|
99
|
+
if (trailingComma) {
|
|
100
|
+
while (end < text.length && text[end] === " ") end++;
|
|
101
|
+
return { start, end };
|
|
102
|
+
}
|
|
103
|
+
// The last member of a one-line list: take the separator before it instead.
|
|
104
|
+
let before = start;
|
|
105
|
+
while (before > 0 && (text[before - 1] === " " || text[before - 1] === "\t")) before--;
|
|
106
|
+
if (text[before - 1] === ",") start = before - 1;
|
|
107
|
+
return { start, end };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// A top-level statement, its leading comments with it, up to the end of its line.
|
|
111
|
+
function statementSpan(sf, statement) {
|
|
112
|
+
const text = sf.text;
|
|
113
|
+
let end = statement.getEnd();
|
|
114
|
+
if (text[end] === "\n") end++;
|
|
115
|
+
let start = statement.getFullStart();
|
|
116
|
+
// Keep the blank line that separated it from what came before.
|
|
117
|
+
while (start < text.length && text[start] === "\n" && text[start + 1] === "\n") start++;
|
|
118
|
+
return { start, end };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** The top-level `const <name> = …` statement and its initializer, when the file declares one. */
|
|
122
|
+
function topLevelConst(sf, name) {
|
|
123
|
+
for (const statement of sf.statements) {
|
|
124
|
+
if (!ts.isVariableStatement(statement)) continue;
|
|
125
|
+
const declarations = statement.declarationList.declarations;
|
|
126
|
+
for (const declaration of declarations) {
|
|
127
|
+
if (ts.isIdentifier(declaration.name) && declaration.name.text === name) {
|
|
128
|
+
return { statement, initializer: declaration.initializer, alone: declarations.length === 1 };
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** The parameter count of the function a top-level name holds, or `undefined` when the file cannot say. */
|
|
136
|
+
function arityOf(sf, name) {
|
|
137
|
+
for (const statement of sf.statements) {
|
|
138
|
+
if (ts.isFunctionDeclaration(statement) && statement.name?.text === name) return statement.parameters.length;
|
|
139
|
+
}
|
|
140
|
+
const declared = topLevelConst(sf, name);
|
|
141
|
+
const init = declared?.initializer;
|
|
142
|
+
if (init !== undefined && (ts.isArrowFunction(init) || ts.isFunctionExpression(init))) return init.parameters.length;
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const RECONCILE_BY_HAND =
|
|
147
|
+
"`defineTemplate` no longer takes `reconcile`. Move each rule onto the slot it sets — `source: Section.slots.<slot>` where it copied a value, `compute({ reads: [...] }, (…) => …)` where it derived one — then delete `reconcile` and its rules";
|
|
148
|
+
|
|
149
|
+
/** Rewrites one file's text, or returns `null` when nothing in it is this codemod's. */
|
|
150
|
+
function rewrite(text, fileName) {
|
|
151
|
+
const sf = ts.createSourceFile(fileName, text, ts.ScriptTarget.Latest, true, fileName.endsWith(".tsx") ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
|
|
152
|
+
|
|
153
|
+
// What this file imports from the framework, local name → exported name.
|
|
154
|
+
const imported = new Map();
|
|
155
|
+
const importDecls = [];
|
|
156
|
+
for (const statement of sf.statements) {
|
|
157
|
+
if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier)) continue;
|
|
158
|
+
if (statement.moduleSpecifier.text !== CONCRETE) continue;
|
|
159
|
+
const bindings = statement.importClause?.namedBindings;
|
|
160
|
+
if (bindings === undefined || !ts.isNamedImports(bindings)) continue;
|
|
161
|
+
importDecls.push(statement);
|
|
162
|
+
for (const element of bindings.elements) imported.set(element.name.text, (element.propertyName ?? element.name).text);
|
|
163
|
+
}
|
|
164
|
+
if (importDecls.length === 0) return null;
|
|
165
|
+
const localOf = (exported) => [...imported].find(([, name]) => name === exported)?.[0];
|
|
166
|
+
const defineTemplateName = localOf("defineTemplate");
|
|
167
|
+
const computeName = localOf("compute");
|
|
168
|
+
|
|
169
|
+
const edits = [];
|
|
170
|
+
const yours = [];
|
|
171
|
+
|
|
172
|
+
function visit(node) {
|
|
173
|
+
if (ts.isCallExpression(node) && ts.isIdentifier(node.expression)) {
|
|
174
|
+
const callee = node.expression.text;
|
|
175
|
+
if (callee === defineTemplateName) templateCall(node);
|
|
176
|
+
if (callee === computeName && node.arguments.length === 1) legacyCompute(node);
|
|
177
|
+
}
|
|
178
|
+
ts.forEachChild(node, visit);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function templateCall(call) {
|
|
182
|
+
const input = call.arguments[0];
|
|
183
|
+
if (input === undefined || !ts.isObjectLiteralExpression(input)) return;
|
|
184
|
+
for (const property of input.properties) {
|
|
185
|
+
const key = property.name !== undefined && ts.isIdentifier(property.name) ? property.name.text : undefined;
|
|
186
|
+
if (key !== "reconcile") continue;
|
|
187
|
+
const value = ts.isShorthandPropertyAssignment(property)
|
|
188
|
+
? property.name
|
|
189
|
+
: ts.isPropertyAssignment(property)
|
|
190
|
+
? property.initializer
|
|
191
|
+
: undefined;
|
|
192
|
+
if (isEmptyArray(value)) {
|
|
193
|
+
edits.push(memberSpan(sf, property));
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
if (value !== undefined && ts.isIdentifier(value)) {
|
|
197
|
+
const declared = topLevelConst(sf, value.text);
|
|
198
|
+
if (declared !== undefined && declared.alone && isEmptyArray(declared.initializer)) {
|
|
199
|
+
edits.push(memberSpan(sf, property));
|
|
200
|
+
edits.push(statementSpan(sf, declared.statement));
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
yours.push(`${RECONCILE_BY_HAND} (line ${String(lineOf(sf, property.getStart(sf)))})`);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function legacyCompute(call) {
|
|
209
|
+
const fn = call.arguments[0];
|
|
210
|
+
const line = String(lineOf(sf, call.getStart(sf)));
|
|
211
|
+
let arity;
|
|
212
|
+
if (ts.isArrowFunction(fn) || ts.isFunctionExpression(fn)) arity = fn.parameters.length;
|
|
213
|
+
else if (ts.isIdentifier(fn)) arity = arityOf(sf, fn.text);
|
|
214
|
+
else return;
|
|
215
|
+
if (arity === 0) return;
|
|
216
|
+
const what = arity === undefined ? `\`compute(${fn.getText(sf)})\`, if \`${fn.getText(sf)}\` takes the facts view,` : "`compute((f) => …)`";
|
|
217
|
+
yours.push(
|
|
218
|
+
`${what} at line ${line} reads the whole \`Facts\` view, which is gone — declare what it reads, \`compute({ reads: [fact.…] }, (…values) => …)\`, and take each value as a parameter`,
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
visit(sf);
|
|
223
|
+
|
|
224
|
+
// Every identifier in the file that is not inside an import or a span being deleted.
|
|
225
|
+
const removed = (pos) => edits.some((edit) => pos >= edit.start && pos < edit.end);
|
|
226
|
+
const referenced = new Set();
|
|
227
|
+
(function collect(node) {
|
|
228
|
+
if (ts.isImportDeclaration(node)) return;
|
|
229
|
+
if (ts.isIdentifier(node) && !removed(node.getStart(sf))) referenced.add(node.text);
|
|
230
|
+
ts.forEachChild(node, collect);
|
|
231
|
+
})(sf);
|
|
232
|
+
|
|
233
|
+
for (const [local, exported] of imported) {
|
|
234
|
+
if ((exported === "Facts" || exported === "FactsNarrative") && referenced.has(local)) {
|
|
235
|
+
yours.push(
|
|
236
|
+
`\`${exported}\` is gone — type a helper by the values its compute hands it (\`readonly FactsUnit[]\`, \`FactsAddress\`), and read the description as \`fact.description\``,
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// The imports: a retired name nothing uses any more goes, and an import left empty with it.
|
|
242
|
+
for (const decl of importDecls) {
|
|
243
|
+
const bindings = decl.importClause.namedBindings;
|
|
244
|
+
const kept = bindings.elements.filter((element) => {
|
|
245
|
+
const exported = (element.propertyName ?? element.name).text;
|
|
246
|
+
return !(RETIRED.has(exported) && !referenced.has(element.name.text));
|
|
247
|
+
});
|
|
248
|
+
if (kept.length === bindings.elements.length) continue;
|
|
249
|
+
if (kept.length === 0 && decl.importClause.name === undefined) {
|
|
250
|
+
edits.push(statementSpan(sf, decl));
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
const multiline = bindings.getText(sf).includes("\n");
|
|
254
|
+
const specifiers = kept.map((element) => element.getText(sf));
|
|
255
|
+
const clause = multiline ? `{\n${specifiers.map((s) => ` ${s},`).join("\n")}\n}` : `{ ${specifiers.join(", ")} }`;
|
|
256
|
+
edits.push({ start: bindings.getStart(sf), end: bindings.getEnd(), text: clause });
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (edits.length === 0 && yours.length === 0) return null;
|
|
260
|
+
edits.sort((a, b) => b.start - a.start);
|
|
261
|
+
let out = text;
|
|
262
|
+
for (const edit of edits) out = out.slice(0, edit.start) + (edit.text ?? "") + out.slice(edit.end);
|
|
263
|
+
return { text: edits.length === 0 ? null : out, yours: [...new Set(yours)] };
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/** @param {string} root @returns {Promise<{rewritten: string[], notRewritten: {file: string, reason: string}[]}>} */
|
|
267
|
+
export default async function readsReplaceReconcile(root) {
|
|
268
|
+
const rewritten = [];
|
|
269
|
+
const notRewritten = [];
|
|
270
|
+
const name = (file) => relative(root, file).split(sep).join("/");
|
|
271
|
+
|
|
272
|
+
for (const file of await sourceFiles(root)) {
|
|
273
|
+
const text = await readFile(file, "utf8");
|
|
274
|
+
if (!text.includes(CONCRETE)) continue;
|
|
275
|
+
if (!/\breconcile\b|\bcompute\s*\(|\bFacts(?:Narrative)?\b|\brule\b|\bset\b/.test(text)) continue;
|
|
276
|
+
const result = rewrite(text, file);
|
|
277
|
+
if (result === null) continue;
|
|
278
|
+
if (result.text !== null && result.text !== text) {
|
|
279
|
+
await writeFile(file, result.text, "utf8");
|
|
280
|
+
rewritten.push(name(file));
|
|
281
|
+
}
|
|
282
|
+
for (const reason of result.yours) notRewritten.push({ file: name(file), reason: `by hand: ${reason}` });
|
|
283
|
+
}
|
|
284
|
+
return { rewritten, notRewritten };
|
|
285
|
+
}
|