@homepages/concrete 4.0.0 → 6.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 +359 -0
- package/README.md +28 -17
- package/codemods/fill-is-a-source.mjs +533 -0
- package/codemods/manifest.json +18 -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 -13
- 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 +22 -36
- 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 +5 -30
- 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 +62 -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.d.ts +3 -2
- 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 +33 -18
- 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/runtime-values.d.ts +6 -18
- package/dist/schema/section-nav.js +0 -15
- package/dist/schema/section-props.d.ts +7 -9
- 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,533 @@
|
|
|
1
|
+
// 6.0.0 — one `fill()`, declared as a kind of `source:`.
|
|
2
|
+
//
|
|
3
|
+
// Before this release a slot's fill was one of eleven builders (`textBlock`, `listFill`,
|
|
4
|
+
// `imageAssign`, `videoAssign`, `tourAssign`, `documentAssign`, `contactAssign`,
|
|
5
|
+
// `chooseFrom`, `nameRows`) under its own `fill:` key, its instruction split across up
|
|
6
|
+
// to six prose keys (`voice`, `content`, `pick`, `structureHint`, and the two enums
|
|
7
|
+
// `structure` and `perspective`). Now a slot declares its origin once, in `source:`, and
|
|
8
|
+
// a fill is `fill({ brief, none?, count?, cap?, reads? })`: what the model DOES is the
|
|
9
|
+
// slot's own fact, the one prose key is `brief`, and `none` is the switch `true`.
|
|
10
|
+
//
|
|
11
|
+
// What this codemod does, in every `.ts` and `.tsx` under the workspace:
|
|
12
|
+
//
|
|
13
|
+
// - Rewrites each builder call whose argument is an object literal to `fill({…})`: the
|
|
14
|
+
// prose keys merge into `brief` exactly as the platform merges a stored decision's, one
|
|
15
|
+
// paragraph each — `content` (else `pick`), `Voice: <voice>`, `Form: <structureHint>`,
|
|
16
|
+
// then each enum as the canonical sentence below (`third` is the default and is
|
|
17
|
+
// dropped), then the `none` bar as `Produce nothing when: <none>`. A ported fill and
|
|
18
|
+
// one published before this release read the same. `none` becomes `true` (a blank
|
|
19
|
+
// one, which never switched anything on, is dropped); `cap` and `reads` carry over;
|
|
20
|
+
// `count` carries over, with a `min: 0` dropped (zero is reachable only through
|
|
21
|
+
// `none`).
|
|
22
|
+
// - Renames a slot builder's `fill:` option to `source:`.
|
|
23
|
+
// - Gives every decision that used to read the platform's standing slice of property
|
|
24
|
+
// facts that slice as an explicit `reads`: a fill now sees exactly its own `reads`, so
|
|
25
|
+
// a migrated one sees what it saw. The eight refs are hoisted once, into
|
|
26
|
+
// `fill-reads.ts` at the workspace root, as `PROPERTY` — yours to prune per decision.
|
|
27
|
+
// - Rewrites the imports: the old builder names out, `fill` and `PROPERTY` in.
|
|
28
|
+
//
|
|
29
|
+
// What it leaves to you, reported per file:
|
|
30
|
+
//
|
|
31
|
+
// - Each `none` bar it folded into a brief, by line: the joined paragraph restates the
|
|
32
|
+
// brief's own exclusion more often than not, so rewrite it as the brief's last
|
|
33
|
+
// sentence saying when producing nothing is right.
|
|
34
|
+
// - `order: "walkthrough"` is dropped. A walkthrough seated EVERY photo; a pick keeps
|
|
35
|
+
// what its brief admits, so add a clause dropping anything that is not a photograph
|
|
36
|
+
// of the property (a logo, a flyer).
|
|
37
|
+
// - `fallback` is dropped: a pick that abstains now lands empty. Re-author the chain as
|
|
38
|
+
// a `none` pick plus a contact-bound slot and a `compute()` over the pick.
|
|
39
|
+
// - `contactAssign` has no replacement: bind the contact's field with
|
|
40
|
+
// `source: fact.contact.*`, or write the choice as a text fill reading the contacts.
|
|
41
|
+
// - A brief interpolating `${facts.…}`: declare the fact in `reads` and refer to it by
|
|
42
|
+
// name instead.
|
|
43
|
+
// - A builder call whose argument is not an object literal (a hoisted options object, a
|
|
44
|
+
// spread) — the prose keys cannot be merged without seeing them.
|
|
45
|
+
|
|
46
|
+
import { readdir, readFile, stat, writeFile } from "node:fs/promises";
|
|
47
|
+
import { dirname, join, relative, sep } from "node:path";
|
|
48
|
+
|
|
49
|
+
import ts from "typescript";
|
|
50
|
+
|
|
51
|
+
const CONCRETE = "@homepages/concrete";
|
|
52
|
+
|
|
53
|
+
/** The builders `fill()` replaced. */
|
|
54
|
+
const BUILDERS = new Set([
|
|
55
|
+
"textBlock",
|
|
56
|
+
"listFill",
|
|
57
|
+
"imageAssign",
|
|
58
|
+
"videoAssign",
|
|
59
|
+
"tourAssign",
|
|
60
|
+
"documentAssign",
|
|
61
|
+
"contactAssign",
|
|
62
|
+
"chooseFrom",
|
|
63
|
+
"nameRows",
|
|
64
|
+
]);
|
|
65
|
+
|
|
66
|
+
/** The types that went with them. */
|
|
67
|
+
const RETIRED_TYPES = new Set(["BuiltDecision", "ChosenRows", "DecisionKind", "DisplayChoice", "NamedRows", "RowOrigination", "TextStructure"]);
|
|
68
|
+
|
|
69
|
+
/** The builders whose executor read the standing slice — the ones a migrated fill gives `reads: PROPERTY`. */
|
|
70
|
+
const SLICE_READERS = new Set(["textBlock", "listFill", "chooseFrom", "nameRows"]);
|
|
71
|
+
|
|
72
|
+
/** The slot builders whose options object carries the origin. */
|
|
73
|
+
const SLOT_BUILDERS = new Set(["text.short", "text.medium", "text.long", "image", "video", "tour", "document", "list.of", "select", "select.of", "number", "url"]);
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The canonical sentence each enum value becomes — the platform's own merge of a
|
|
77
|
+
* stored decision's prose keys uses the same words in the same order, so a template
|
|
78
|
+
* ported here and a section published before this release send the model the same
|
|
79
|
+
* brief. `third` is the default person and has no sentence.
|
|
80
|
+
*/
|
|
81
|
+
const STRUCTURE_SENTENCE = {
|
|
82
|
+
single_sentence: "Write one sentence.",
|
|
83
|
+
paragraph: "Write one paragraph.",
|
|
84
|
+
bullet_list: "Write a bulleted list.",
|
|
85
|
+
value: "Answer with the bare value alone, never a sentence.",
|
|
86
|
+
};
|
|
87
|
+
const PERSPECTIVE_SENTENCE = {
|
|
88
|
+
first: "Write in the first person.",
|
|
89
|
+
second: "Write in the second person, addressing the reader.",
|
|
90
|
+
third: null,
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/** The standing slice, as refs. */
|
|
94
|
+
const PROPERTY_REFS = [
|
|
95
|
+
"fact.property.address",
|
|
96
|
+
"fact.property.latitude",
|
|
97
|
+
"fact.property.longitude",
|
|
98
|
+
"fact.property.property_type",
|
|
99
|
+
"fact.property.listing_intent",
|
|
100
|
+
"fact.property.units",
|
|
101
|
+
"fact.description",
|
|
102
|
+
"fact.document_notes",
|
|
103
|
+
];
|
|
104
|
+
|
|
105
|
+
const READS_MODULE = "fill-reads.ts";
|
|
106
|
+
const READS_CONST = "PROPERTY";
|
|
107
|
+
|
|
108
|
+
const READS_SOURCE = `// The property facts every fill was shown before \`fill()\` read exactly its own
|
|
109
|
+
// \`reads\`: the platform's standing slice, hoisted here once by the 6.0.0 upgrade so
|
|
110
|
+
// each migrated fill still sees what it saw. It is yours: drop from a fill's \`reads\`
|
|
111
|
+
// whatever its brief does not use, and delete this file once nothing imports it.
|
|
112
|
+
import { fact } from "${CONCRETE}";
|
|
113
|
+
|
|
114
|
+
export const ${READS_CONST} = [
|
|
115
|
+
${PROPERTY_REFS.map((ref) => ` ${ref},`).join("\n")}
|
|
116
|
+
] as const;
|
|
117
|
+
`;
|
|
118
|
+
|
|
119
|
+
/** The column a rewritten `fill({…})` must end by to stay on one line. */
|
|
120
|
+
const LINE_WIDTH = 140;
|
|
121
|
+
|
|
122
|
+
const EXTENSIONS = [".ts", ".tsx"];
|
|
123
|
+
const SKIP_DIRS = new Set(["node_modules", ".concrete", ".git", "dist", "build"]);
|
|
124
|
+
|
|
125
|
+
async function sourceFiles(root) {
|
|
126
|
+
const found = [];
|
|
127
|
+
async function walk(dir) {
|
|
128
|
+
for (const entry of await readdir(dir, { withFileTypes: true })) {
|
|
129
|
+
if (entry.isDirectory()) {
|
|
130
|
+
if (!SKIP_DIRS.has(entry.name)) await walk(join(dir, entry.name));
|
|
131
|
+
} else if (EXTENSIONS.some((ext) => entry.name.endsWith(ext)) && !entry.name.endsWith(".d.ts")) {
|
|
132
|
+
found.push(join(dir, entry.name));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
await walk(root);
|
|
137
|
+
return found.sort();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
async function exists(path) {
|
|
141
|
+
try {
|
|
142
|
+
await stat(path);
|
|
143
|
+
return true;
|
|
144
|
+
} catch {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// ----- prose ---------------------------------------------------------------
|
|
150
|
+
|
|
151
|
+
/** One piece of the brief: literal text, or an expression the author computed. */
|
|
152
|
+
function prosePart(node, sf) {
|
|
153
|
+
if (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) return { text: node.text };
|
|
154
|
+
if (ts.isTemplateExpression(node)) return { template: node.getText(sf).slice(1, -1) };
|
|
155
|
+
return { expr: node.getText(sf) };
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* The label the `none` bar is folded into the brief under. The platform folds a stored
|
|
160
|
+
* decision's bar the same way, so a ported fill and a published one read the same.
|
|
161
|
+
*/
|
|
162
|
+
const NONE_LABEL = "Produce nothing when: ";
|
|
163
|
+
|
|
164
|
+
const escapeTemplate = (text) => text.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${");
|
|
165
|
+
|
|
166
|
+
/** Each piece becomes one paragraph of the brief, as the platform's own merge joins them. */
|
|
167
|
+
const PARAGRAPH = "\n\n";
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* The merged brief as source text, and its literal content for the interpolation scan.
|
|
171
|
+
* A piece carries an optional `label` (`Voice: `, `Form: `) the merge prefixes it with.
|
|
172
|
+
*/
|
|
173
|
+
function briefSource(parts) {
|
|
174
|
+
const kept = parts.filter((p) => p.text === undefined || p.text.trim() !== "");
|
|
175
|
+
const label = (p) => p.label ?? "";
|
|
176
|
+
if (kept.every((p) => p.text !== undefined)) {
|
|
177
|
+
const text = kept.map((p) => `${label(p)}${p.text.trim()}`).join(PARAGRAPH);
|
|
178
|
+
return { source: JSON.stringify(text), scanned: text };
|
|
179
|
+
}
|
|
180
|
+
const pieces = kept.map((p) => {
|
|
181
|
+
if (p.text !== undefined) return escapeTemplate(`${label(p)}${p.text.trim()}`);
|
|
182
|
+
if (p.template !== undefined) return `${escapeTemplate(label(p))}${p.template}`;
|
|
183
|
+
return `${escapeTemplate(label(p))}\${${p.expr}}`;
|
|
184
|
+
});
|
|
185
|
+
const scanned = kept.map((p) => `${label(p)}${p.text ?? p.template ?? ""}`).join(PARAGRAPH);
|
|
186
|
+
return { source: `\`${pieces.join("\\n\\n")}\``, scanned };
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// ----- one builder call ------------------------------------------------------
|
|
190
|
+
|
|
191
|
+
/** The object literal's members by name, or why the call cannot be read. */
|
|
192
|
+
function membersOf(arg, sf) {
|
|
193
|
+
if (arg === undefined) return { members: new Map() };
|
|
194
|
+
if (!ts.isObjectLiteralExpression(arg)) return { refused: "its options are not an object literal, so the prose keys cannot be merged" };
|
|
195
|
+
const members = new Map();
|
|
196
|
+
const properties = new Map();
|
|
197
|
+
for (const property of arg.properties) {
|
|
198
|
+
if (ts.isPropertyAssignment(property) && (ts.isIdentifier(property.name) || ts.isStringLiteral(property.name))) {
|
|
199
|
+
members.set(property.name.text, property.initializer);
|
|
200
|
+
properties.set(property.name.text, property);
|
|
201
|
+
} else if (ts.isShorthandPropertyAssignment(property)) {
|
|
202
|
+
members.set(property.name.text, property.name);
|
|
203
|
+
properties.set(property.name.text, property);
|
|
204
|
+
} else {
|
|
205
|
+
return { refused: `its options carry \`${property.getText(sf).slice(0, 40)}\`, which cannot be merged without seeing it` };
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return { members, properties };
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* The comments an author wrote inside a builder's options, by the key each sits above,
|
|
213
|
+
* so the port can carry them to the entry that key became. Those after the last key are
|
|
214
|
+
* filed under `""`.
|
|
215
|
+
*/
|
|
216
|
+
function commentsOf(arg, properties, sf) {
|
|
217
|
+
const byKey = new Map();
|
|
218
|
+
if (arg === undefined || !ts.isObjectLiteralExpression(arg)) return byKey;
|
|
219
|
+
const grab = (pos) => (ts.getLeadingCommentRanges(sf.text, pos) ?? []).map((range) => sf.text.slice(range.pos, range.end));
|
|
220
|
+
for (const [key, property] of properties) {
|
|
221
|
+
const found = grab(property.getFullStart());
|
|
222
|
+
if (found.length > 0) byKey.set(key, found);
|
|
223
|
+
}
|
|
224
|
+
const last = arg.properties.at(-1);
|
|
225
|
+
if (last !== undefined) {
|
|
226
|
+
const after = arg.properties.hasTrailingComma ? sf.text.indexOf(",", last.getEnd()) + 1 : last.getEnd();
|
|
227
|
+
const found = grab(after);
|
|
228
|
+
if (found.length > 0) byKey.set("", found);
|
|
229
|
+
}
|
|
230
|
+
return byKey;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/** `{ min: 0, max: N }` → `{ max: N }`; everything else as written. */
|
|
234
|
+
function countSource(node, sf, yours) {
|
|
235
|
+
if (!ts.isObjectLiteralExpression(node)) return node.getText(sf);
|
|
236
|
+
const { members, refused } = membersOf(node, sf);
|
|
237
|
+
if (refused !== undefined) return node.getText(sf);
|
|
238
|
+
const min = members.get("min");
|
|
239
|
+
const max = members.get("max");
|
|
240
|
+
if (max === undefined) {
|
|
241
|
+
yours.push("a `count` with no `max` — a count is `N`, `{ max }` or `{ min, max }`; state the ceiling");
|
|
242
|
+
return node.getText(sf);
|
|
243
|
+
}
|
|
244
|
+
if (min === undefined || (ts.isNumericLiteral(min) && Number(min.text) === 0)) return `{ max: ${max.getText(sf)} }`;
|
|
245
|
+
return `{ min: ${min.getText(sf)}, max: ${max.getText(sf)} }`;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* The `fill({…})` text one builder call becomes, or `refused` with the reason. `yours`
|
|
250
|
+
* collects what the port leaves to the author.
|
|
251
|
+
*/
|
|
252
|
+
function fillCall(name, call, sf, yours) {
|
|
253
|
+
const indent = lineIndent(sf, call.getStart(sf));
|
|
254
|
+
const column = sf.getLineAndCharacterOfPosition(call.getStart(sf)).character;
|
|
255
|
+
if (name === "contactAssign") {
|
|
256
|
+
return { refused: "`contactAssign` has no replacement — bind the contact's field with `source: fact.contact.*`, or write the choice as a text fill reading the contacts" };
|
|
257
|
+
}
|
|
258
|
+
if (call.arguments.length > 1) return { refused: `\`${name}\` takes one options object` };
|
|
259
|
+
const { members, properties, refused } = membersOf(call.arguments[0], sf);
|
|
260
|
+
if (refused !== undefined) return { refused: `\`${name}(…)\`: ${refused}` };
|
|
261
|
+
|
|
262
|
+
const part = (key) => (members.has(key) ? prosePart(members.get(key), sf) : undefined);
|
|
263
|
+
const enumSentence = (key, table) => {
|
|
264
|
+
const node = members.get(key);
|
|
265
|
+
if (node === undefined) return undefined;
|
|
266
|
+
if (!ts.isStringLiteral(node)) return prosePart(node, sf);
|
|
267
|
+
const sentence = table[node.text];
|
|
268
|
+
return sentence === null || sentence === undefined ? undefined : { text: sentence };
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
// The platform's own merge, piece for piece: `content ?? pick` (one brief under two
|
|
272
|
+
// names — an executor always read them as one), then the voice, the form, the
|
|
273
|
+
// structure's sentence and the person's.
|
|
274
|
+
const content = part("content");
|
|
275
|
+
const body = content !== undefined && (content.text === undefined || content.text.trim() !== "") ? content : part("pick");
|
|
276
|
+
const labelled = (key, label) => {
|
|
277
|
+
const piece = part(key);
|
|
278
|
+
return piece === undefined ? undefined : { ...piece, label };
|
|
279
|
+
};
|
|
280
|
+
// `none` was a second brief; it is a switch now, and its bar joins the one brief. A
|
|
281
|
+
// blank one never switched abstention on, so it folds nothing and is dropped.
|
|
282
|
+
const bar = labelled("none", NONE_LABEL);
|
|
283
|
+
const abstains = bar !== undefined && (bar.text === undefined || bar.text.trim() !== "");
|
|
284
|
+
const parts = [
|
|
285
|
+
body,
|
|
286
|
+
labelled("voice", "Voice: "),
|
|
287
|
+
labelled("structureHint", "Form: "),
|
|
288
|
+
enumSentence("structure", STRUCTURE_SENTENCE),
|
|
289
|
+
enumSentence("perspective", PERSPECTIVE_SENTENCE),
|
|
290
|
+
].filter((p) => p !== undefined);
|
|
291
|
+
if (parts.length === 0) return { refused: `\`${name}(…)\` states no prose at all — write its \`brief\`` };
|
|
292
|
+
if (abstains) {
|
|
293
|
+
parts.push(bar);
|
|
294
|
+
const line = sf.getLineAndCharacterOfPosition(members.get("none").getStart(sf)).line + 1;
|
|
295
|
+
yours.push(
|
|
296
|
+
`\`none\` is \`true\` now, and its bar is the brief's last paragraph (\`${NONE_LABEL.trim()} …\`) — rewrite it as the brief's own sentence saying when producing nothing is right, at line ${line}`,
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
const brief = briefSource(parts);
|
|
300
|
+
if (/\$\{\s*facts\./.test(brief.scanned)) {
|
|
301
|
+
yours.push("a brief interpolates `${facts.…}` — declare that fact in `reads` and refer to it by name");
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
if (members.has("order")) {
|
|
305
|
+
yours.push(
|
|
306
|
+
"`order: \"walkthrough\"` is gone and a pick keeps only what its brief admits — say to keep and order every photograph, and to drop anything that is not a photograph of the property",
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
if (members.has("fallback")) {
|
|
310
|
+
yours.push(
|
|
311
|
+
"`fallback` is gone — a pick that abstains lands empty. Keep the `none` pick, bind the fallback's slot with `source: fact.contact.*`, and choose between them with `compute({ reads: [pick] }, …)`",
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// Each entry keeps the comments written above the key(s) it came from — the prose
|
|
316
|
+
// keys' and the dropped keys' above the brief — so nothing the author wrote is lost.
|
|
317
|
+
const comments = commentsOf(call.arguments[0], properties, sf);
|
|
318
|
+
const entries = [];
|
|
319
|
+
const entry = (text, ...keys) => entries.push({ text, comments: keys.flatMap((key) => comments.get(key) ?? []) });
|
|
320
|
+
if (SLICE_READERS.has(name)) {
|
|
321
|
+
const declared = members.get("reads");
|
|
322
|
+
if (declared === undefined) entry(`reads: ${READS_CONST}`);
|
|
323
|
+
else if (ts.isArrayLiteralExpression(declared)) {
|
|
324
|
+
const items = declared.elements.map((e) => e.getText(sf));
|
|
325
|
+
entry(`reads: [...${READS_CONST}${items.length === 0 ? "" : `, ${items.join(", ")}`}]`, "reads");
|
|
326
|
+
} else entry(`reads: [...${READS_CONST}, ...${declared.getText(sf)}]`, "reads");
|
|
327
|
+
} else if (members.has("reads")) {
|
|
328
|
+
entry(`reads: ${members.get("reads").getText(sf)}`, "reads");
|
|
329
|
+
}
|
|
330
|
+
const carried = new Set(["reads", "count", "cap", ...(abstains ? ["none"] : [])]);
|
|
331
|
+
entry(`brief: ${brief.source}`, ...[...members.keys()].filter((key) => !carried.has(key)));
|
|
332
|
+
if (abstains) entry("none: true", "none");
|
|
333
|
+
if (members.has("count")) entry(`count: ${countSource(members.get("count"), sf, yours)}`, "count");
|
|
334
|
+
if (members.has("cap")) entry(`cap: ${members.get("cap").getText(sf)}`, "cap");
|
|
335
|
+
const trailing = comments.get("") ?? [];
|
|
336
|
+
|
|
337
|
+
const inner = `${indent} `;
|
|
338
|
+
const place = (comment) => `${inner}${comment}`;
|
|
339
|
+
const commented = trailing.length > 0 || entries.some((e) => e.comments.length > 0);
|
|
340
|
+
const oneLine = `fill({ ${entries.map((e) => e.text).join(", ")} })`;
|
|
341
|
+
const text =
|
|
342
|
+
!commented && column + oneLine.length <= LINE_WIDTH && !oneLine.includes("\n")
|
|
343
|
+
? oneLine
|
|
344
|
+
: `fill({\n${[...entries.flatMap((e) => [...e.comments.map(place), `${inner}${e.text},`]), ...trailing.map(place)].join("\n")}\n${indent}})`;
|
|
345
|
+
return { text, readsSlice: SLICE_READERS.has(name) };
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// ----- one file --------------------------------------------------------------
|
|
349
|
+
|
|
350
|
+
/** The dotted callee name of a call: `text.medium`, `list.of`, `image`. */
|
|
351
|
+
function calleeName(call) {
|
|
352
|
+
const callee = call.expression;
|
|
353
|
+
if (ts.isIdentifier(callee)) return callee.text;
|
|
354
|
+
if (ts.isPropertyAccessExpression(callee) && ts.isIdentifier(callee.expression)) return `${callee.expression.text}.${callee.name.text}`;
|
|
355
|
+
return undefined;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function lineIndent(sf, pos) {
|
|
359
|
+
const { line } = sf.getLineAndCharacterOfPosition(pos);
|
|
360
|
+
const start = sf.getPositionOfLineAndCharacter(line, 0);
|
|
361
|
+
return /^[ \t]*/.exec(sf.text.slice(start))[0];
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// Where `fill` joins an import list: its sorted place when the author kept the list
|
|
365
|
+
// sorted, else where the first builder it replaces stood.
|
|
366
|
+
function insertionIndex(kept, fillAt) {
|
|
367
|
+
const key = (specifier) => specifier.replace(/^type\s+/, "").toLowerCase();
|
|
368
|
+
const sorted = kept.every((k, i) => i === 0 || key(kept[i - 1]) <= key(k));
|
|
369
|
+
if (!sorted) return fillAt ?? kept.length;
|
|
370
|
+
const at = kept.findIndex((k) => key(k) > "fill");
|
|
371
|
+
return at === -1 ? kept.length : at;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/** Rewrites one file's text, or returns `null` when nothing in it is this codemod's. */
|
|
375
|
+
function rewrite(text, fileName, readsImport) {
|
|
376
|
+
const sf = ts.createSourceFile(fileName, text, ts.ScriptTarget.Latest, true, fileName.endsWith(".tsx") ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
|
|
377
|
+
|
|
378
|
+
// The builder names this file imports from the framework — a local function that
|
|
379
|
+
// happens to share one is not ours to touch.
|
|
380
|
+
const imported = new Map();
|
|
381
|
+
const importDecls = [];
|
|
382
|
+
for (const statement of sf.statements) {
|
|
383
|
+
if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier)) continue;
|
|
384
|
+
if (statement.moduleSpecifier.text !== CONCRETE) continue;
|
|
385
|
+
const bindings = statement.importClause?.namedBindings;
|
|
386
|
+
if (bindings === undefined || !ts.isNamedImports(bindings)) continue;
|
|
387
|
+
importDecls.push(statement);
|
|
388
|
+
for (const element of bindings.elements) imported.set(element.name.text, (element.propertyName ?? element.name).text);
|
|
389
|
+
}
|
|
390
|
+
const builderOf = (identifier) => {
|
|
391
|
+
const original = imported.get(identifier);
|
|
392
|
+
return original !== undefined && BUILDERS.has(original) ? original : undefined;
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
const edits = [];
|
|
396
|
+
const yours = [];
|
|
397
|
+
const refusedNames = new Set();
|
|
398
|
+
let usesFill = false;
|
|
399
|
+
let usesReads = false;
|
|
400
|
+
|
|
401
|
+
function visit(node) {
|
|
402
|
+
if (ts.isCallExpression(node) && ts.isIdentifier(node.expression)) {
|
|
403
|
+
const builder = builderOf(node.expression.text);
|
|
404
|
+
if (builder !== undefined) {
|
|
405
|
+
const result = fillCall(builder, node, sf, yours);
|
|
406
|
+
if (result.refused !== undefined) {
|
|
407
|
+
yours.push(result.refused);
|
|
408
|
+
refusedNames.add(node.expression.text);
|
|
409
|
+
ts.forEachChild(node, visit);
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
edits.push({ start: node.getStart(sf), end: node.getEnd(), text: result.text });
|
|
413
|
+
usesFill = true;
|
|
414
|
+
if (result.readsSlice) usesReads = true;
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
// A slot builder's `fill:` option is its `source:` now.
|
|
419
|
+
if (ts.isCallExpression(node) && SLOT_BUILDERS.has(calleeName(node) ?? "")) {
|
|
420
|
+
for (const arg of node.arguments) {
|
|
421
|
+
if (!ts.isObjectLiteralExpression(arg)) continue;
|
|
422
|
+
const hasSource = arg.properties.some((p) => p.name !== undefined && ts.isIdentifier(p.name) && p.name.text === "source");
|
|
423
|
+
for (const property of arg.properties) {
|
|
424
|
+
if (!ts.isPropertyAssignment(property) || !ts.isIdentifier(property.name) || property.name.text !== "fill") continue;
|
|
425
|
+
if (hasSource) {
|
|
426
|
+
yours.push("a slot declares both `source:` and `fill:` — keep the one origin it has");
|
|
427
|
+
continue;
|
|
428
|
+
}
|
|
429
|
+
edits.push({ start: property.name.getStart(sf), end: property.name.getEnd(), text: "source" });
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
ts.forEachChild(node, visit);
|
|
434
|
+
}
|
|
435
|
+
visit(sf);
|
|
436
|
+
|
|
437
|
+
// The imports: the builders that were rewritten and the retired types out of every
|
|
438
|
+
// framework import, `fill` into the first that imports values — never an
|
|
439
|
+
// `import type`, where it would type-check as nothing and the call would not bind.
|
|
440
|
+
const importYours = [];
|
|
441
|
+
if (importDecls.length > 0) {
|
|
442
|
+
const fillHost = importDecls.find((decl) => !decl.importClause.isTypeOnly);
|
|
443
|
+
const alreadyFill = importDecls.some(
|
|
444
|
+
(decl) => !decl.importClause.isTypeOnly && decl.importClause.namedBindings.elements.some((e) => !e.isTypeOnly && e.name.text === "fill"),
|
|
445
|
+
);
|
|
446
|
+
for (const decl of importDecls) {
|
|
447
|
+
const bindings = decl.importClause.namedBindings;
|
|
448
|
+
const kept = [];
|
|
449
|
+
let fillAt;
|
|
450
|
+
for (const element of bindings.elements) {
|
|
451
|
+
const original = (element.propertyName ?? element.name).text;
|
|
452
|
+
if (BUILDERS.has(original) && !refusedNames.has(element.name.text)) {
|
|
453
|
+
fillAt ??= kept.length;
|
|
454
|
+
continue;
|
|
455
|
+
}
|
|
456
|
+
if (RETIRED_TYPES.has(original)) {
|
|
457
|
+
importYours.push(`\`${original}\` is gone — a fill is typed \`FillBinding\`, and nothing else from the old builders survives`);
|
|
458
|
+
fillAt ??= kept.length;
|
|
459
|
+
continue;
|
|
460
|
+
}
|
|
461
|
+
kept.push(element.getText(sf));
|
|
462
|
+
}
|
|
463
|
+
if (decl === fillHost && usesFill && !alreadyFill) kept.splice(insertionIndex(kept, fillAt), 0, "fill");
|
|
464
|
+
const changed = kept.length !== bindings.elements.length || kept.some((k, i) => k !== bindings.elements[i].getText(sf));
|
|
465
|
+
if (!changed) continue;
|
|
466
|
+
if (kept.length === 0) {
|
|
467
|
+
edits.push({ start: decl.getFullStart(), end: decl.getEnd(), text: "" });
|
|
468
|
+
continue;
|
|
469
|
+
}
|
|
470
|
+
const multiline = bindings.getText(sf).includes("\n");
|
|
471
|
+
const indent = lineIndent(sf, bindings.elements[0]?.getStart(sf) ?? bindings.getStart(sf));
|
|
472
|
+
const clause = multiline ? `{\n${kept.map((k) => `${indent}${k},`).join("\n")}\n}` : `{ ${kept.join(", ")} }`;
|
|
473
|
+
edits.push({ start: bindings.getStart(sf), end: bindings.getEnd(), text: clause });
|
|
474
|
+
}
|
|
475
|
+
const lastDecl = importDecls.at(-1);
|
|
476
|
+
const added = [];
|
|
477
|
+
if (usesFill && !alreadyFill && fillHost === undefined) added.push(`\nimport { fill } from "${CONCRETE}";`);
|
|
478
|
+
// A file a first run already ported in part (a call it could not see, fixed by hand
|
|
479
|
+
// and run again) already imports the hoisted reads.
|
|
480
|
+
const importsReads = sf.statements.some(
|
|
481
|
+
(s) =>
|
|
482
|
+
ts.isImportDeclaration(s) &&
|
|
483
|
+
s.importClause?.namedBindings !== undefined &&
|
|
484
|
+
ts.isNamedImports(s.importClause.namedBindings) &&
|
|
485
|
+
s.importClause.namedBindings.elements.some((e) => e.name.text === READS_CONST),
|
|
486
|
+
);
|
|
487
|
+
if (usesReads && readsImport !== undefined && !importsReads) added.push(`\nimport { ${READS_CONST} } from "${readsImport}";`);
|
|
488
|
+
if (added.length > 0) edits.push({ start: lastDecl.getEnd(), end: lastDecl.getEnd(), text: added.join("") });
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
if (edits.length === 0 && yours.length === 0 && importYours.length === 0) return null;
|
|
492
|
+
edits.sort((a, b) => b.start - a.start);
|
|
493
|
+
let out = text;
|
|
494
|
+
for (const edit of edits) out = out.slice(0, edit.start) + edit.text + out.slice(edit.end);
|
|
495
|
+
return { text: edits.length === 0 ? null : out, yours: [...new Set([...yours, ...importYours])], usesReads };
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/** The extensionless relative specifier from `file` to the hoisted reads module. */
|
|
499
|
+
function readsSpecifier(root, file) {
|
|
500
|
+
const target = join(root, READS_MODULE.replace(/\.ts$/, ""));
|
|
501
|
+
let rel = relative(dirname(file), target).split(sep).join("/");
|
|
502
|
+
if (!rel.startsWith(".")) rel = `./${rel}`;
|
|
503
|
+
return rel;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
/** @param {string} root @returns {Promise<{rewritten: string[], notRewritten: {file: string, reason: string}[]}>} */
|
|
507
|
+
export default async function fillIsASource(root) {
|
|
508
|
+
const rewritten = [];
|
|
509
|
+
const notRewritten = [];
|
|
510
|
+
const readsFile = join(root, READS_MODULE);
|
|
511
|
+
let needsReads = false;
|
|
512
|
+
const name = (file) => relative(root, file).split(sep).join("/");
|
|
513
|
+
|
|
514
|
+
for (const file of await sourceFiles(root)) {
|
|
515
|
+
if (file === readsFile) continue;
|
|
516
|
+
const text = await readFile(file, "utf8");
|
|
517
|
+
if (![...BUILDERS, ...RETIRED_TYPES].some((b) => text.includes(b)) && !/\bfill\s*:/.test(text)) continue;
|
|
518
|
+
const result = rewrite(text, file, readsSpecifier(root, file));
|
|
519
|
+
if (result === null) continue;
|
|
520
|
+
if (result.text !== null && result.text !== text) {
|
|
521
|
+
await writeFile(file, result.text, "utf8");
|
|
522
|
+
rewritten.push(name(file));
|
|
523
|
+
if (result.usesReads) needsReads = true;
|
|
524
|
+
}
|
|
525
|
+
for (const reason of result.yours) notRewritten.push({ file: name(file), reason: `by hand: ${reason}` });
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
if (needsReads && !(await exists(readsFile))) {
|
|
529
|
+
await writeFile(readsFile, READS_SOURCE, "utf8");
|
|
530
|
+
rewritten.push(READS_MODULE);
|
|
531
|
+
}
|
|
532
|
+
return { rewritten, notRewritten };
|
|
533
|
+
}
|
package/codemods/manifest.json
CHANGED
|
@@ -39,6 +39,24 @@
|
|
|
39
39
|
"platform-namespace"
|
|
40
40
|
],
|
|
41
41
|
"manual": []
|
|
42
|
+
},
|
|
43
|
+
"5.0.0": {
|
|
44
|
+
"codemods": [],
|
|
45
|
+
"manual": [
|
|
46
|
+
"declare each contact field a section reads on its `fact.property.contacts` list, then read it under the key you declared it with."
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
"6.0.0": {
|
|
50
|
+
"codemods": [
|
|
51
|
+
"fill-is-a-source",
|
|
52
|
+
"reads-replace-reconcile"
|
|
53
|
+
],
|
|
54
|
+
"manual": [
|
|
55
|
+
"rebuild and publish again \u2014 no source changes; an artifact built by an earlier version is refused, and one built by this version is not.",
|
|
56
|
+
"where `concrete upgrade` reports a fill as yours \u2014 a walkthrough gallery, a photo pick with a contact fallback, a `contactAssign`, a brief interpolating `${facts.\u2026}`, or a builder whose options are not an object literal \u2014 finish that fill by the line it prints; then drop from each fill's `reads` whatever its brief does not use.",
|
|
57
|
+
"where `concrete upgrade` reports a `none` bar it folded into a brief, rewrite that brief's last paragraph (`Produce nothing when: \u2026`) as the brief's own sentence saying when producing nothing is right.",
|
|
58
|
+
"where `concrete upgrade` reports a `reconcile` that holds rules, move each rule onto the slot it sets \u2014 `source: Section.slots.<slot>` where it copied a value, `compute({ reads }, \u2026)` where it derived one; where it reports a `compute((f) => \u2026)`, declare what the callback reads and take each value as a parameter."
|
|
59
|
+
]
|
|
42
60
|
}
|
|
43
61
|
}
|
|
44
62
|
}
|