@homepages/concrete 10.0.0 → 11.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 +29 -0
- package/codemods/manifest.json +5 -158
- package/dist/artifact/playground/client/assets/index-ByeGGedv.js +1259 -0
- package/dist/artifact/playground/client/assets/index-CxWPYOH2.css +1 -0
- package/dist/artifact/playground/client/index.html +2 -2
- package/dist/artifact/playground/client/island-canvas-host.mjs +1 -1
- package/dist/artifact/playground/host.mjs +26 -26
- package/dist/base.css +1 -8
- package/dist/cli/build/artifact.js +1 -1
- package/dist/cli/build/fixtures.js +3 -2
- package/dist/cli/check/stages/sections.js +1 -1
- package/dist/cli/dev/workspace-reader.js +3 -2
- package/dist/css/compile.js +3 -6
- package/dist/css/rules.js +1 -51
- package/dist/design-system/format-variants.js +1 -1
- package/dist/fixtures/resolve.js +5 -1
- package/dist/fixtures/rows.js +2 -2
- package/dist/index.d.ts +5 -5
- package/dist/packages/external/concrete/package.js +1 -1
- package/dist/packages/internal/fill-vocabulary/dist/holder.js +3 -14
- package/dist/packages/internal/media-resolution/dist/document.js +3 -3
- package/dist/packages/internal/media-resolution/dist/image.js +3 -3
- package/dist/packages/internal/media-resolution/dist/tour.js +6 -6
- package/dist/packages/internal/media-resolution/dist/video.js +9 -9
- package/dist/packages/internal/section-contracts/dist/fill-verb-contract.js +1 -0
- package/dist/packages/internal/section-contracts/dist/runners.js +1 -3
- package/dist/packages/internal/section-contracts/dist/source-contract.js +3 -3
- package/dist/packages/internal/section-contracts/dist/sources-contract.js +0 -2
- package/dist/packages/internal/template-artifact/dist/index.js +2 -2
- package/dist/packages/internal/template-artifact/dist/layout.js +11 -11
- package/dist/packages/internal/template-artifact/dist/manifest.js +1 -1
- package/dist/packages/internal/template-artifact/dist/verify.js +13 -17
- package/dist/packages/internal/template-contracts/dist/document-value.d.ts +3 -5
- package/dist/packages/internal/template-contracts/dist/fill-builders.js +2 -6
- package/dist/packages/internal/template-contracts/dist/fill-spec-schema.js +4 -1
- package/dist/packages/internal/template-contracts/dist/list.js +0 -14
- package/dist/packages/internal/template-contracts/dist/primitive-descriptors.js +1 -1
- package/dist/packages/internal/template-contracts/dist/runtime-values.d.ts +6 -7
- package/dist/packages/internal/template-contracts/dist/slot-builders.js +0 -2
- package/dist/packages/internal/template-contracts/dist/slot-ref.d.ts +6 -1
- package/dist/packages/internal/template-contracts/dist/tour-value.d.ts +2 -4
- package/dist/packages/internal/template-contracts/dist/video-value.d.ts +3 -4
- package/dist/primitives/Image.d.ts +2 -2
- package/dist/primitives/Tour.d.ts +2 -2
- package/dist/primitives/Video.d.ts +2 -2
- package/dist/primitives/slot-bindings.js +6 -13
- package/dist/primitives/slot-document.d.ts +1 -1
- package/dist/primitives/slot-download.d.ts +3 -1
- package/dist/primitives/slot-media.d.ts +5 -2
- package/dist/primitives/slot-media.js +1 -1
- package/dist/rules/registry.js +0 -6
- package/dist/schema/format-presets.d.ts +1 -1
- package/dist/schema/section-schema.d.ts +5 -5
- package/dist/styles.css +4 -4
- package/dist/template/define-template.js +0 -1
- package/guide/reference/cli/INDEX.md +2 -2
- package/guide/reference/cli/build.md +1 -1
- package/guide/reference/cli/check.md +1 -1
- package/guide/reference/cli/dev.md +1 -1
- package/guide/reference/cli/property-add.md +1 -1
- package/guide/reference/cli/property-list.md +1 -1
- package/guide/reference/cli/publish.md +1 -1
- package/guide/reference/cli/upgrade.md +1 -1
- package/guide/reference/rules/INDEX.md +1 -2
- package/package.json +2 -2
- package/codemods/fill-is-a-source.mjs +0 -533
- package/codemods/framework-namespace.mjs +0 -107
- package/codemods/list-grammar.mjs +0 -923
- package/codemods/object-form-only.mjs +0 -39
- package/codemods/platform-namespace.mjs +0 -83
- package/codemods/process-builders.mjs +0 -198
- package/codemods/reads-replace-reconcile.mjs +0 -285
- package/codemods/registry-keys-only.mjs +0 -113
- package/codemods/slot-object.mjs +0 -1097
- package/codemods/steps/content-object-fields.mjs +0 -324
- package/codemods/steps/list-object-form.mjs +0 -686
- package/codemods/steps/registry-key-reads.mjs +0 -276
- package/codemods/steps/select-object-form.mjs +0 -210
- package/codemods/table-rows.mjs +0 -568
- package/codemods/theme-collapse.mjs +0 -396
- package/codemods/unlayer-author-css.mjs +0 -194
- package/codemods/unwrap-object-fields.mjs +0 -310
- package/codemods/viewer-slot-document.mjs +0 -131
- package/codemods/write-property-as-facts-document.mjs +0 -716
- package/codemods/write-the-address-line.mjs +0 -255
- package/codemods/write-the-registry-members.mjs +0 -653
- package/codemods/write-the-select-from.mjs +0 -141
- package/codemods/write-the-sole-from.mjs +0 -369
- package/codemods/write-the-table-from.mjs +0 -267
- package/codemods/write-the-whole-item.mjs +0 -512
- package/codemods/writeback-drop.mjs +0 -168
- package/codemods/written-contact-address.mjs +0 -162
- package/codemods/written-media-category.mjs +0 -227
- package/codemods/written-ref-kinds-name-the-layer.mjs +0 -172
- package/codemods/written-uploads-replace-pool-reads.mjs +0 -454
- package/codemods/written-uploads-sort-into-lists.mjs +0 -405
- package/codemods/written-uploads-stated-in-sorted-lists.mjs +0 -295
- package/codemods/written-video-sources-drop.mjs +0 -144
- package/codemods/written-without-pick-none.mjs +0 -146
- package/codemods/written-without-retired-knowledge.mjs +0 -223
- package/codemods/written-without-the-media-key.mjs +0 -202
- package/codemods/written-without-the-property-type.mjs +0 -249
- package/dist/artifact/playground/client/assets/index-BFNHB7VM.css +0 -1
- package/dist/artifact/playground/client/assets/index-Div1yo6s.js +0 -1259
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
// 7.0.0 — every list and every select takes one options object, and every row field
|
|
2
|
-
// declares its origin.
|
|
3
|
-
//
|
|
4
|
-
// 6.x deprecated `list.of(item, opts)`, `list.of({ …fields }, opts)`, `select.of(values,
|
|
5
|
-
// opts)` and the display entry's positional `select(cases, opts)` beside the object form,
|
|
6
|
-
// and shipped the rewrite for each as a codemod step. This release removes them, along
|
|
7
|
-
// with the `image` builder's `sourceFilter` option and the record form's exemption from
|
|
8
|
-
// the rule that every row field declares where its value comes from: a record list's row
|
|
9
|
-
// field with no row member, `fill()` or `compute()` is refused by `concrete check`,
|
|
10
|
-
// whatever built the list.
|
|
11
|
-
//
|
|
12
|
-
// What this codemod does is run the two steps, in one pass over the workspace:
|
|
13
|
-
//
|
|
14
|
-
// - `steps/select-object-form.mjs` — `select.of(VALUES, { … })` and `select(CASES, { … })`
|
|
15
|
-
// become `select({ …, options: … })`. First, so a record's select field is already in
|
|
16
|
-
// the object form when the list step reads which field keyed its rows.
|
|
17
|
-
// - `steps/list-object-form.mjs` — every `list.of` becomes `list({ …, item })` or a
|
|
18
|
-
// `fields` list whose every row field declares its origin.
|
|
19
|
-
//
|
|
20
|
-
// What it leaves to you is what the steps report, per file: each is a `Manual:` line on a
|
|
21
|
-
// file they rewrote (a generated brief to replace, the row members a bound row's fill now
|
|
22
|
-
// has to read), or a call they could not read. `sourceFilter` has no rewrite: drop it, and
|
|
23
|
-
// where the slot is a unit's floor plan, bind the unit's `floor_plans` member from a
|
|
24
|
-
// `fact.property.units` list, whose picker offers that unit's floor plans.
|
|
25
|
-
|
|
26
|
-
import listObjectForm from "./steps/list-object-form.mjs";
|
|
27
|
-
import selectObjectForm from "./steps/select-object-form.mjs";
|
|
28
|
-
|
|
29
|
-
/** @param {string} root @returns {Promise<{rewritten: string[], notRewritten: {file: string, reason: string}[]}>} */
|
|
30
|
-
export default async function objectFormOnly(root) {
|
|
31
|
-
const rewritten = new Set();
|
|
32
|
-
const notRewritten = [];
|
|
33
|
-
for (const step of [selectObjectForm, listObjectForm]) {
|
|
34
|
-
const report = await step(root);
|
|
35
|
-
for (const file of report.rewritten) rewritten.add(file);
|
|
36
|
-
notRewritten.push(...report.notRewritten);
|
|
37
|
-
}
|
|
38
|
-
return { rewritten: [...rewritten], notRewritten };
|
|
39
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
// 4.0.0 — the three names the PLATFORM stamps spell `concrete-` too.
|
|
2
|
-
//
|
|
3
|
-
// `framework-namespace` (3.0.0) moved every name concrete itself derives and deliberately
|
|
4
|
-
// left three behind: `.tr-frame`, `.tr-root` and `#tr-site-config`. Those are stamped
|
|
5
|
-
// onto a rendered artifact by the publish and capture surfaces rather than derived here —
|
|
6
|
-
// `FRAME_ROOT_CLASS` in `@homepages/format-geometry`, the published `<body>` class and
|
|
7
|
-
// the per-site config island — and concrete's `base.css` only styles the first of them.
|
|
8
|
-
// Moving them then would have meant either a runtime flag threaded through four platform
|
|
9
|
-
// packages or a break for the older framework, which was still serving a live customer
|
|
10
|
-
// off the same names. That framework is gone, so they move now.
|
|
11
|
-
//
|
|
12
|
-
// What that means for a workspace: a stylesheet selecting `.tr-frame` or `.tr-root`, or
|
|
13
|
-
// a script reading `#tr-site-config`, is on borrowed time. The platform stamps both
|
|
14
|
-
// spellings for a transition window, so pages built before this release keep working,
|
|
15
|
-
// and once that window closes the old names match nothing. This codemod applies exactly
|
|
16
|
-
// those three renames, in every `.css`, `.ts` and `.tsx` under the workspace —
|
|
17
|
-
// selectors, `className` and `id` strings, `getElementById` arguments and comments alike.
|
|
18
|
-
//
|
|
19
|
-
// Nothing is ever reported as yours: the map is total and mechanical, so whatever this
|
|
20
|
-
// rewrote is not yours to check afterwards.
|
|
21
|
-
|
|
22
|
-
import { readdir, readFile, writeFile } from "node:fs/promises";
|
|
23
|
-
import { join, relative } from "node:path";
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* The §4.2 map, whole. Three names, none of them a custom property: two classes and one
|
|
27
|
-
* element id, so none carries a leading `--`.
|
|
28
|
-
*/
|
|
29
|
-
const RENAMES = new Map([
|
|
30
|
-
["tr-frame", "concrete-frame"],
|
|
31
|
-
["tr-root", "concrete-root"],
|
|
32
|
-
["tr-site-config", "concrete-site-config"],
|
|
33
|
-
]);
|
|
34
|
-
|
|
35
|
-
const escaped = (name) => name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* One name from the map, bounded.
|
|
39
|
-
*
|
|
40
|
-
* The two boundaries are what keep a workspace's own `--tr-frame-bg` or `.tr-rooted`
|
|
41
|
-
* clear of this map, and what makes `tr-frame` miss the `--tr-frame-window-*` properties
|
|
42
|
-
* and `tr-frame-*` counters `framework-namespace` already moved.
|
|
43
|
-
*/
|
|
44
|
-
const NAME = new RegExp(
|
|
45
|
-
`(?<![\\w-])(?:${[...RENAMES.keys()]
|
|
46
|
-
.sort((a, b) => b.length - a.length)
|
|
47
|
-
.map(escaped)
|
|
48
|
-
.join("|")})(?![\\w-])`,
|
|
49
|
-
"g",
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
/** The file kinds a workspace spells these names in. */
|
|
53
|
-
const EXTENSIONS = [".css", ".ts", ".tsx"];
|
|
54
|
-
const SKIP_DIRS = new Set(["node_modules", ".concrete", ".git", "dist", "build"]);
|
|
55
|
-
|
|
56
|
-
/** Every source file under `root`, absolute, skipping build output and dependencies. */
|
|
57
|
-
async function sourceFiles(root) {
|
|
58
|
-
const found = [];
|
|
59
|
-
async function walk(dir) {
|
|
60
|
-
for (const entry of await readdir(dir, { withFileTypes: true })) {
|
|
61
|
-
if (entry.isDirectory()) {
|
|
62
|
-
if (!SKIP_DIRS.has(entry.name)) await walk(join(dir, entry.name));
|
|
63
|
-
} else if (EXTENSIONS.some((extension) => entry.name.endsWith(extension))) {
|
|
64
|
-
found.push(join(dir, entry.name));
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
await walk(root);
|
|
69
|
-
return found.sort();
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/** @param {string} root @returns {Promise<{rewritten: string[], notRewritten: {file: string, reason: string}[]}>} */
|
|
73
|
-
export default async function platformNamespace(root) {
|
|
74
|
-
const rewritten = [];
|
|
75
|
-
for (const file of await sourceFiles(root)) {
|
|
76
|
-
const before = await readFile(file, "utf8");
|
|
77
|
-
const after = before.replace(NAME, (name) => RENAMES.get(name) ?? name);
|
|
78
|
-
if (after === before) continue;
|
|
79
|
-
await writeFile(file, after);
|
|
80
|
-
rewritten.push(relative(root, file).split("\\").join("/"));
|
|
81
|
-
}
|
|
82
|
-
return { rewritten, notRewritten: [] };
|
|
83
|
-
}
|
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
// A media slot's `process` lists built processes, never strings.
|
|
2
|
-
//
|
|
3
|
-
// A process is built by its builder — `process.cutout()`, `process.autocrop({ brief })` —
|
|
4
|
-
// which emits the object the platform runs, so a process can take options (an
|
|
5
|
-
// auto-crop's brief). `image({ process: ["cutout"] })` no longer compiles.
|
|
6
|
-
//
|
|
7
|
-
// What this codemod does, in every `.ts` and `.tsx` under the workspace that imports this
|
|
8
|
-
// package: in the options object of an `image`, `video`, `tour`, `document` or `media`
|
|
9
|
-
// call, each string in a `process` list naming a process becomes its builder's call —
|
|
10
|
-
// `"cutout"` becomes `process.cutout()` — and `process` is added to the file's import
|
|
11
|
-
// from the framework. A file that already uses a `process` of its own (Node's global, a
|
|
12
|
-
// local) imports it as `mediaProcess` instead. A file reaching the framework through a
|
|
13
|
-
// namespace import (`import * as c`) calls `c.process.cutout()` and imports nothing.
|
|
14
|
-
//
|
|
15
|
-
// What it hands back, by line: a `process` spelled through a variable, and a string
|
|
16
|
-
// naming no process the builders construct.
|
|
17
|
-
|
|
18
|
-
import { readdir, readFile, writeFile } from "node:fs/promises";
|
|
19
|
-
import { join, relative, sep } from "node:path";
|
|
20
|
-
|
|
21
|
-
import ts from "typescript";
|
|
22
|
-
|
|
23
|
-
const CONCRETE = "@homepages/concrete";
|
|
24
|
-
const EXTENSIONS = [".ts", ".tsx"];
|
|
25
|
-
const SKIP_DIRS = new Set(["node_modules", ".concrete", ".git", "dist", "build"]);
|
|
26
|
-
|
|
27
|
-
// The media builders, by the name a call reaches them under (`image`, `c.image`).
|
|
28
|
-
const MEDIA_CALL = /(^|\.)(image|video|tour|document|media)$/;
|
|
29
|
-
|
|
30
|
-
// The processes a string named before the builders, and the builder each now is.
|
|
31
|
-
const BUILT = new Set(["cutout"]);
|
|
32
|
-
|
|
33
|
-
async function sourceFiles(root) {
|
|
34
|
-
const found = [];
|
|
35
|
-
async function walk(dir) {
|
|
36
|
-
for (const entry of await readdir(dir, { withFileTypes: true })) {
|
|
37
|
-
if (entry.isDirectory()) {
|
|
38
|
-
if (!SKIP_DIRS.has(entry.name)) await walk(join(dir, entry.name));
|
|
39
|
-
} else if (EXTENSIONS.some((ext) => entry.name.endsWith(ext)) && !entry.name.endsWith(".d.ts")) {
|
|
40
|
-
found.push(join(dir, entry.name));
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
await walk(root);
|
|
45
|
-
return found.sort();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function lineOf(sf, pos) {
|
|
49
|
-
return sf.getLineAndCharacterOfPosition(pos).line + 1;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function nameOf(property) {
|
|
53
|
-
const name = property.name;
|
|
54
|
-
return name !== undefined && (ts.isIdentifier(name) || ts.isStringLiteral(name)) ? name.text : undefined;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function frameworkImports(sf, isFramework) {
|
|
58
|
-
return sf.statements.filter(
|
|
59
|
-
(statement) => ts.isImportDeclaration(statement) && ts.isStringLiteral(statement.moduleSpecifier) && isFramework(statement.moduleSpecifier.text),
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Whether the file already binds or reads an identifier `process` (Node's global, a local)
|
|
64
|
-
// — importing the framework's under that name would shadow it.
|
|
65
|
-
function usesProcess(sf) {
|
|
66
|
-
let found = false;
|
|
67
|
-
const visit = (node) => {
|
|
68
|
-
if (found) return;
|
|
69
|
-
if (ts.isIdentifier(node) && node.text === "process") {
|
|
70
|
-
const parent = node.parent;
|
|
71
|
-
const isKey = (ts.isPropertyAssignment(parent) || ts.isPropertySignature(parent) || ts.isPropertyDeclaration(parent)) && parent.name === node;
|
|
72
|
-
const isMember = ts.isPropertyAccessExpression(parent) && parent.name === node;
|
|
73
|
-
if (!isKey && !isMember) found = true;
|
|
74
|
-
}
|
|
75
|
-
ts.forEachChild(node, visit);
|
|
76
|
-
};
|
|
77
|
-
visit(sf);
|
|
78
|
-
return found;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// The edit adding `specifier` to a named import: in alphabetical place when the list is
|
|
82
|
-
// sorted, else last; on its own line when the list breaks one per line.
|
|
83
|
-
function addSpecifier(sf, text, declaration, specifier) {
|
|
84
|
-
const named = declaration.importClause.namedBindings;
|
|
85
|
-
const elements = named.elements;
|
|
86
|
-
const names = elements.map((element) => element.name.text);
|
|
87
|
-
const sorted = names.every((name, index) => index === 0 || names[index - 1].localeCompare(name, "en", { sensitivity: "base" }) <= 0);
|
|
88
|
-
const key = specifier.split(" ")[0];
|
|
89
|
-
let index = sorted ? names.findIndex((name) => name.localeCompare(key, "en", { sensitivity: "base" }) > 0) : -1;
|
|
90
|
-
if (index === -1) index = elements.length;
|
|
91
|
-
const multiline = text.slice(named.getStart(sf), named.getEnd()).includes("\n");
|
|
92
|
-
if (multiline) {
|
|
93
|
-
const anchor = elements[Math.min(index, elements.length - 1)];
|
|
94
|
-
const lineStart = text.lastIndexOf("\n", anchor.getStart(sf) - 1) + 1;
|
|
95
|
-
const indent = text.slice(lineStart, anchor.getStart(sf));
|
|
96
|
-
if (index < elements.length) return { start: lineStart, end: lineStart, insert: `${indent}${specifier},\n` };
|
|
97
|
-
const last = elements[elements.length - 1];
|
|
98
|
-
const hasTrailingComma = elements.hasTrailingComma;
|
|
99
|
-
return hasTrailingComma
|
|
100
|
-
? { start: text.indexOf(",", last.getEnd()) + 1, end: text.indexOf(",", last.getEnd()) + 1, insert: `\n${indent}${specifier},` }
|
|
101
|
-
: { start: last.getEnd(), end: last.getEnd(), insert: `,\n${indent}${specifier}` };
|
|
102
|
-
}
|
|
103
|
-
if (index < elements.length) {
|
|
104
|
-
const at = elements[index].getStart(sf);
|
|
105
|
-
return { start: at, end: at, insert: `${specifier}, ` };
|
|
106
|
-
}
|
|
107
|
-
const end = elements[elements.length - 1].getEnd();
|
|
108
|
-
return { start: end, end, insert: `, ${specifier}` };
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Rewrites one file's text; `undefined` when it declares no `process` on a media slot.
|
|
113
|
-
* `isFramework` decides which import specifiers are the framework.
|
|
114
|
-
*/
|
|
115
|
-
export function rewriteSource(fileName, text, isFramework = (specifier) => specifier === CONCRETE) {
|
|
116
|
-
if (!text.includes("process")) return undefined;
|
|
117
|
-
const kind = fileName.endsWith(".tsx") ? ts.ScriptKind.TSX : ts.ScriptKind.TS;
|
|
118
|
-
const sf = ts.createSourceFile(fileName, text, ts.ScriptTarget.Latest, true, kind);
|
|
119
|
-
const imports = frameworkImports(sf, isFramework);
|
|
120
|
-
if (imports.length === 0) return undefined;
|
|
121
|
-
|
|
122
|
-
const namespace = imports.map((statement) => statement.importClause?.namedBindings).find((bindings) => bindings !== undefined && ts.isNamespaceImport(bindings));
|
|
123
|
-
const existing = imports
|
|
124
|
-
.flatMap((statement) => {
|
|
125
|
-
const bindings = statement.importClause?.namedBindings;
|
|
126
|
-
return bindings !== undefined && ts.isNamedImports(bindings) && !statement.importClause.isTypeOnly ? [...bindings.elements] : [];
|
|
127
|
-
})
|
|
128
|
-
.find((element) => (element.propertyName ?? element.name).text === "process" && !element.isTypeOnly);
|
|
129
|
-
const local = existing !== undefined ? existing.name.text : usesProcess(sf) ? "mediaProcess" : "process";
|
|
130
|
-
const callee = namespace !== undefined ? `${namespace.name.text}.process` : local;
|
|
131
|
-
|
|
132
|
-
const edits = [];
|
|
133
|
-
const reasons = [];
|
|
134
|
-
const visit = (node) => {
|
|
135
|
-
if (ts.isObjectLiteralExpression(node) && ts.isCallExpression(node.parent) && node.parent.arguments[0] === node) {
|
|
136
|
-
const media = MEDIA_CALL.exec(node.parent.expression.getText(sf))?.[2];
|
|
137
|
-
if (media !== undefined) {
|
|
138
|
-
for (const property of node.properties) {
|
|
139
|
-
if (!ts.isPropertyAssignment(property) || nameOf(property) !== "process") continue;
|
|
140
|
-
const list = property.initializer;
|
|
141
|
-
if (!ts.isArrayLiteralExpression(list)) {
|
|
142
|
-
reasons.push(
|
|
143
|
-
`line ${String(lineOf(sf, property.getStart(sf)))}: this ${media} slot's \`process\` is not a list written in place — build each entry with its builder (\`process.cutout()\`)`,
|
|
144
|
-
);
|
|
145
|
-
continue;
|
|
146
|
-
}
|
|
147
|
-
for (const entry of list.elements) {
|
|
148
|
-
if (!ts.isStringLiteralLike(entry)) continue;
|
|
149
|
-
if (!BUILT.has(entry.text)) {
|
|
150
|
-
reasons.push(`line ${String(lineOf(sf, entry.getStart(sf)))}: \`process\` names "${entry.text}", which no builder constructs — remove it`);
|
|
151
|
-
continue;
|
|
152
|
-
}
|
|
153
|
-
edits.push({ start: entry.getStart(sf), end: entry.getEnd(), insert: `${callee}.${entry.text}()` });
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
ts.forEachChild(node, visit);
|
|
159
|
-
};
|
|
160
|
-
visit(sf);
|
|
161
|
-
if (edits.length === 0) return reasons.length > 0 ? { text, changed: false, reasons } : undefined;
|
|
162
|
-
|
|
163
|
-
if (namespace === undefined && existing === undefined) {
|
|
164
|
-
const specifier = local === "process" ? "process" : `process as ${local}`;
|
|
165
|
-
const named = imports.find((statement) => {
|
|
166
|
-
const bindings = statement.importClause?.namedBindings;
|
|
167
|
-
return bindings !== undefined && ts.isNamedImports(bindings) && bindings.elements.length > 0 && !statement.importClause.isTypeOnly;
|
|
168
|
-
});
|
|
169
|
-
if (named !== undefined) {
|
|
170
|
-
edits.push(addSpecifier(sf, text, named, specifier));
|
|
171
|
-
} else {
|
|
172
|
-
const after = imports[imports.length - 1].getEnd();
|
|
173
|
-
edits.push({ start: after, end: after, insert: `\nimport { ${specifier} } from ${imports[0].moduleSpecifier.getText(sf)};` });
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
let out = text;
|
|
178
|
-
for (const edit of edits.sort((a, b) => b.start - a.start)) out = out.slice(0, edit.start) + edit.insert + out.slice(edit.end);
|
|
179
|
-
return { text: out, changed: true, reasons };
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/** @param {string} root @returns {Promise<{rewritten: string[], notRewritten: {file: string, reason: string}[]}>} */
|
|
183
|
-
export default async function processBuilders(root) {
|
|
184
|
-
const rewritten = [];
|
|
185
|
-
const notRewritten = [];
|
|
186
|
-
for (const file of await sourceFiles(root)) {
|
|
187
|
-
const before = await readFile(file, "utf8");
|
|
188
|
-
const result = rewriteSource(file, before);
|
|
189
|
-
if (result === undefined) continue;
|
|
190
|
-
const rel = relative(root, file).split(sep).join("/");
|
|
191
|
-
if (result.changed) {
|
|
192
|
-
await writeFile(file, result.text, "utf8");
|
|
193
|
-
rewritten.push(rel);
|
|
194
|
-
}
|
|
195
|
-
for (const reason of result.reasons) notRewritten.push({ file: rel, reason });
|
|
196
|
-
}
|
|
197
|
-
return { rewritten, notRewritten };
|
|
198
|
-
}
|
|
@@ -1,285 +0,0 @@
|
|
|
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
|
-
}
|