@nodii/dev 0.6.171 → 0.6.173
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/README.md +159 -6
- package/dist/cli.js +20 -4
- package/dist/coordinator-watch.js +76 -13
- package/dist/core.js +11 -1
- package/dist/design.js +18 -30
- package/dist/doctor.js +62 -1
- package/dist/figma-rest.js +272 -0
- package/dist/figma-scope.js +2 -2
- package/dist/flags.js +1 -0
- package/dist/freeze.js +10 -5
- package/dist/hooks.js +62 -16
- package/dist/lane-runtime.js +103 -0
- package/dist/lanes.js +1 -1
- package/dist/nudges.js +7 -4
- package/dist/publish-compare.js +3 -2
- package/dist/read-cache.js +56 -4
- package/dist/receipt.js +38 -3
- package/dist/safety.js +30 -11
- package/dist/starting.js +14 -44
- package/dist/surface-corpus.js +830 -0
- package/dist/surface.js +38 -49
- package/dist/vendor/render-templates.mjs +36 -4
- package/package.json +3 -3
package/dist/surface.js
CHANGED
|
@@ -22,17 +22,19 @@
|
|
|
22
22
|
// committed trees (no Figma call) and refuses any product page whose
|
|
23
23
|
// generated file differs.
|
|
24
24
|
//
|
|
25
|
-
// Figma reads (only with --fetch)
|
|
26
|
-
//
|
|
25
|
+
// Figma reads (only with --fetch) go through the machine's shared client
|
|
26
|
+
// (./figma-rest.js, cli-170): one call per 8 s per token across the machine, a
|
|
27
|
+
// 429 retried at most twice after Retry-After, pinned tree reads cached.
|
|
27
28
|
import { execFileSync } from "node:child_process";
|
|
28
29
|
import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
29
30
|
import { tmpdir } from "node:os";
|
|
30
31
|
import { basename, dirname, join, relative, resolve } from "node:path";
|
|
31
32
|
import { CliError, VERSION, devRequest, readConfig } from "./core.js";
|
|
33
|
+
import { MIN_FIGMA_INTERVAL_MS, figmaRest } from "./figma-rest.js";
|
|
32
34
|
import { createRenderer } from "./vendor/render-templates.mjs";
|
|
33
35
|
|
|
34
36
|
/** Bumped whenever the emitted code changes shape for the same inputs. */
|
|
35
|
-
export const GENERATOR_FORMAT =
|
|
37
|
+
export const GENERATOR_FORMAT = 39;
|
|
36
38
|
export const TREE_DIR = "docs/figma-ux-ds/figma/surface-trees";
|
|
37
39
|
export const GENERATED_SUFFIX = ".surface.generated.tsx";
|
|
38
40
|
/** Where every generated product page lives, as a git glob (NODII-DEV-CLI-77). */
|
|
@@ -47,9 +49,7 @@ const COLOUR_CATALOG = "packages/tokens/src/generated/colour-v2-catalog.json";
|
|
|
47
49
|
const TYPE_EDGES_CATALOG = "packages/tokens/src/generated/type-edges-v2-catalog.json";
|
|
48
50
|
/** How many versions to read back from the newest, looking for the one the last publish closed (8 s each). */
|
|
49
51
|
const MAX_VERSION_READS = 40;
|
|
50
|
-
|
|
51
|
-
export const MIN_FIGMA_INTERVAL_MS = 8_000;
|
|
52
|
-
const BACKOFF_MS = 30_000;
|
|
52
|
+
export { MIN_FIGMA_INTERVAL_MS };
|
|
53
53
|
const SET_KEY = /^[0-9a-f]{40}$/;
|
|
54
54
|
/** A set's node id, as the REST API (5:0) or a Figma URL (5-0) writes it. */
|
|
55
55
|
const NODE_ID = /^(\d+)[:-](\d+)$/;
|
|
@@ -161,38 +161,12 @@ export const generatedPath = (root, row) => join(root, row.sourcePath.replace(/\
|
|
|
161
161
|
// ---------------------------------------------------------------------------
|
|
162
162
|
|
|
163
163
|
/**
|
|
164
|
-
*
|
|
165
|
-
*
|
|
164
|
+
* The Figma REST GET of a Surface read: the machine's shared client (cli-170),
|
|
165
|
+
* with this command's waits. Calls on one token are queued across the machine,
|
|
166
|
+
* one per `minIntervalMs`; a 429 waits Retry-After and is sent again at most
|
|
167
|
+
* twice; a 5xx waits 30 s doubling; a read at a pinned version is cached.
|
|
166
168
|
*/
|
|
167
|
-
export
|
|
168
|
-
let last = -Infinity;
|
|
169
|
-
return async function figmaGet(path) {
|
|
170
|
-
for (let attempt = 1; ; attempt++) {
|
|
171
|
-
const wait = last + minIntervalMs - now();
|
|
172
|
-
if (wait > 0) await sleep(wait);
|
|
173
|
-
last = now();
|
|
174
|
-
let response;
|
|
175
|
-
try {
|
|
176
|
-
response = await fetchImpl(`${FIGMA_API}${path}`, { headers: { "X-Figma-Token": token }, signal: AbortSignal.timeout(180_000) });
|
|
177
|
-
} catch (error) {
|
|
178
|
-
if (attempt >= attempts) throw new CliError("FIGMA_UNREACHABLE", `Cannot reach Figma: ${error.message}`);
|
|
179
|
-
await sleep(BACKOFF_MS);
|
|
180
|
-
continue;
|
|
181
|
-
}
|
|
182
|
-
if (response.ok) return response.json();
|
|
183
|
-
// A 429 is never retried: it means stop reading (DS-249 ruling), so it falls through to the throw.
|
|
184
|
-
if (response.status >= 500 && attempt < attempts) {
|
|
185
|
-
const ms = BACKOFF_MS * 2 ** (attempt - 1);
|
|
186
|
-
log(`Figma answered ${response.status} for ${path.split("?")[0]}; waiting ${Math.round(ms / 1000)} s`);
|
|
187
|
-
await sleep(ms);
|
|
188
|
-
continue;
|
|
189
|
-
}
|
|
190
|
-
const code = { 404: "FIGMA_NOT_FOUND", 403: "FIGMA_FORBIDDEN", 429: "FIGMA_RATE_LIMITED" }[response.status] ?? "FIGMA_ERROR";
|
|
191
|
-
const retryAfter = Number(response.headers?.get?.("retry-after"));
|
|
192
|
-
throw new CliError(code, `Figma answered ${response.status} for ${path.split("?")[0]}`, 1, { status: response.status, ...(retryAfter > 0 ? { retryAfterSeconds: retryAfter } : {}) });
|
|
193
|
-
}
|
|
194
|
-
};
|
|
195
|
-
}
|
|
169
|
+
export const pacedFigma = (token, options = {}) => figmaRest(token, options);
|
|
196
170
|
|
|
197
171
|
/** component-set key → node id in one Surfaces file, one call per file per run. */
|
|
198
172
|
export async function setIndex(figmaGet, fileKey) {
|
|
@@ -418,7 +392,8 @@ export function trimTree(entry, { row, version }) {
|
|
|
418
392
|
for (const layer of layersOf(node)) {
|
|
419
393
|
if (layer.type !== "INSTANCE" || exposed[layer.name]) continue;
|
|
420
394
|
if (layer.isExposedInstance || overridden.has(layer.id) || layer.overrides?.some((o) => o.overriddenFields?.length)) {
|
|
421
|
-
|
|
395
|
+
const own = trim(layer, box);
|
|
396
|
+
exposed[layer.name] = { key: keyOf(layer.componentId), props: propsOf(layer), ...(own.children ? { children: own.children } : {}) };
|
|
422
397
|
}
|
|
423
398
|
}
|
|
424
399
|
if (Object.keys(exposed).length) out.instance.exposed = exposed;
|
|
@@ -1310,16 +1285,23 @@ function hideable(code) {
|
|
|
1310
1285
|
}
|
|
1311
1286
|
return `<AlertAction>${held}</AlertAction>`;
|
|
1312
1287
|
});
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1288
|
+
out = out.replace(/<Tabs panelless value=\{(__s\d+)_tab\}[\s\S]*?<\/Tabs>/g, (strip, scope) => {
|
|
1289
|
+
// A parent template may include a child strip that was already processed.
|
|
1290
|
+
if (strip.includes(`${scope}_visibleTabs`)) return strip;
|
|
1291
|
+
const used = new Set();
|
|
1292
|
+
return strip.replace(/^([ \t]*)(<TabsTrigger\b[\s\S]*?<\/TabsTrigger>)/gm, (_, pad, trigger) => {
|
|
1293
|
+
const current = /\bvalue="([^"]+)"/.exec(trigger)?.[1];
|
|
1294
|
+
if (!current) return `${pad}${trigger}`;
|
|
1317
1295
|
const label = /\{("(?:[^"\\\n]|\\.)*")\}/.exec(trigger);
|
|
1318
|
-
const
|
|
1319
|
-
const
|
|
1320
|
-
|
|
1296
|
+
const text = label ? JSON.parse(label[1]) : "";
|
|
1297
|
+
const named = text ? slug(/\d/.test(text) ? nameText(text) : text) : "";
|
|
1298
|
+
const candidate = /^tab(?:-\d+)?$/.test(current) && named ? named : current;
|
|
1299
|
+
const value = used.has(candidate) ? current : candidate;
|
|
1300
|
+
used.add(value);
|
|
1301
|
+
const body = trigger.replace(/\bvalue="[^"]+"/, `value="${value}"`).split("\n").map((line, i) => (i === 0 ? `${pad} ${line}` : line ? ` ${line}` : line)).join("\n");
|
|
1302
|
+
return `${pad}{(${scope}_visibleTabs?.includes(${JSON.stringify(value)}) ?? true) && (\n${body}\n${pad})}`;
|
|
1321
1303
|
});
|
|
1322
|
-
}
|
|
1304
|
+
});
|
|
1323
1305
|
return out;
|
|
1324
1306
|
}
|
|
1325
1307
|
|
|
@@ -2335,18 +2317,25 @@ function emitNode(node, ctx) {
|
|
|
2335
2317
|
.filter(([, e]) => ds.byKey.has(e.key))
|
|
2336
2318
|
.map(([layer, e]) => [layer, { nodeId: ds.byKey.get(e.key), values: valuesOf(e.props) }]),
|
|
2337
2319
|
);
|
|
2338
|
-
const slotContent = (prop) => {
|
|
2320
|
+
const slotContent = (prop, nestedPath = []) => {
|
|
2339
2321
|
if (DATA_SLOTS.get(node.instance.set)?.has(prop)) {
|
|
2340
2322
|
note(`${path} › ${prop}`, LIFTED, `slot ${prop} of ${node.instance.set} is the page's own content, passed through as a prop (NODII-DEV-CLI-83)`);
|
|
2341
2323
|
return `<>{${prop}}</>`;
|
|
2342
2324
|
}
|
|
2343
|
-
|
|
2325
|
+
let owner = node;
|
|
2326
|
+
for (const layer of nestedPath) owner = owner?.instance?.exposed?.[layer] ?? owner?.exposed?.[layer];
|
|
2327
|
+
const slotNode = (owner?.children ?? []).find((c) => c.type === "SLOT" && c.slot === prop);
|
|
2328
|
+
if (nestedPath.length && !slotNode) {
|
|
2329
|
+
const detail = `nested slot ${nestedPath.join(" › ")} › ${prop} is absent from the saved tree; regenerate with --fetch to preserve its content`;
|
|
2330
|
+
note(path, "template", detail);
|
|
2331
|
+
return comment(`unmapped: ${detail}`);
|
|
2332
|
+
}
|
|
2344
2333
|
if (slotNode && !slotNode.layout && (slotNode.children ?? []).filter((c) => c.visible !== false && !c.absolute).length > 1) {
|
|
2345
2334
|
note(`${path} › ${prop}`, "layout", `slot ${prop} has no auto layout`);
|
|
2346
2335
|
return comment(`unmapped: slot ${JSON.stringify(prop)} has no auto layout`);
|
|
2347
2336
|
}
|
|
2348
2337
|
const textOwner = TEXT_PROPERTY_PARTS.has(node.instance.set) ? node.instance.set : ctx.textOwner;
|
|
2349
|
-
const slotCtx = { ...ctx, depth: 0, parent: slotNode, grand: null, path: `${path} › ${prop}`, root: false, textOwner, inTable: false, inSlot: true, chain: slotNode ? [...chain, slotNode] : chain, layer: `${ctx.layer} › ${prop}` };
|
|
2338
|
+
const slotCtx = { ...ctx, depth: 0, parent: slotNode, grand: null, path: `${path} › ${prop}`, root: false, textOwner, inTable: false, inSlot: true, chain: slotNode ? [...chain, slotNode] : chain, layer: `${ctx.layer}${nestedPath.map(part => ` › ${part}`).join("")} › ${prop}` };
|
|
2350
2339
|
const inner = emitChildren(slotNode?.children ?? [], (c) => emitNode(c, slotCtx), slotCtx);
|
|
2351
2340
|
return inner.length === 0 ? "<></>" : inner.length === 1 ? inner[0] : `<>\n${inner.map((x) => indent(x, 1)).join("\n")}\n</>`;
|
|
2352
2341
|
};
|
|
@@ -67,6 +67,13 @@ export function loadSnapshot(root, { fileSnapshot } = {}) {
|
|
|
67
67
|
"snapshots",
|
|
68
68
|
"compliance-surfaces.snapshot.json"
|
|
69
69
|
),
|
|
70
|
+
join(root, "code-connect", "snapshots", "tenant-surfaces.snapshot.json"),
|
|
71
|
+
join(
|
|
72
|
+
root,
|
|
73
|
+
"code-connect",
|
|
74
|
+
"snapshots",
|
|
75
|
+
"document-cloud-surfaces.snapshot.json"
|
|
76
|
+
),
|
|
70
77
|
];
|
|
71
78
|
const contexts = new Map();
|
|
72
79
|
for (const path of paths) {
|
|
@@ -192,7 +199,9 @@ export function renderSections(sections, imports, options = {}) {
|
|
|
192
199
|
: "<></>";
|
|
193
200
|
} else if (section.type === "SLOT") {
|
|
194
201
|
// Slot content is whatever the designer drops in — any ReactNode.
|
|
195
|
-
out += options.slot
|
|
202
|
+
out += options.slot
|
|
203
|
+
? options.slot(section.propertyName, section.slotPath ?? [])
|
|
204
|
+
: "<></>";
|
|
196
205
|
} else if (section.type === "ERROR") {
|
|
197
206
|
throw new RenderError(
|
|
198
207
|
`template produced an ERROR section: ${section.message}`
|
|
@@ -279,7 +288,15 @@ export function createRenderer(root, docs, options = {}) {
|
|
|
279
288
|
return props;
|
|
280
289
|
}
|
|
281
290
|
|
|
282
|
-
function makeInstance(
|
|
291
|
+
function makeInstance(
|
|
292
|
+
context,
|
|
293
|
+
setNode,
|
|
294
|
+
props,
|
|
295
|
+
depth,
|
|
296
|
+
label,
|
|
297
|
+
reads = null,
|
|
298
|
+
exposed = null
|
|
299
|
+
) {
|
|
283
300
|
const need = (name, type) => {
|
|
284
301
|
reads?.add(name);
|
|
285
302
|
const prop = props.get(name);
|
|
@@ -321,8 +338,15 @@ export function createRenderer(root, docs, options = {}) {
|
|
|
321
338
|
// A swap is a node id, or { nodeId, values } when the caller has the
|
|
322
339
|
// swapped instance's own property values (renderInstance's `values`).
|
|
323
340
|
const value = need(name, "INSTANCE_SWAP").value;
|
|
324
|
-
const swap =
|
|
325
|
-
|
|
341
|
+
const swap =
|
|
342
|
+
value && typeof value === "object" ? value : { nodeId: value };
|
|
343
|
+
return swapHandle(
|
|
344
|
+
context,
|
|
345
|
+
String(swap.nodeId),
|
|
346
|
+
depth,
|
|
347
|
+
label,
|
|
348
|
+
swap.values
|
|
349
|
+
);
|
|
326
350
|
},
|
|
327
351
|
getSlot: (name) => {
|
|
328
352
|
need(name, "SLOT");
|
|
@@ -630,6 +654,14 @@ export function createRenderer(root, docs, options = {}) {
|
|
|
630
654
|
1,
|
|
631
655
|
`${label} > ${layerName}`
|
|
632
656
|
);
|
|
657
|
+
// A template may call findInstance(...).getSlot directly, without executing
|
|
658
|
+
// the nested template. Preserve the owner on the slot sections themselves.
|
|
659
|
+
const getSlot = handle.getSlot;
|
|
660
|
+
handle.getSlot = (name) => {
|
|
661
|
+
const sections = getSlot(name);
|
|
662
|
+
for (const section of sections) section.slotPath = [layerName];
|
|
663
|
+
return sections;
|
|
664
|
+
};
|
|
633
665
|
return {
|
|
634
666
|
...handle,
|
|
635
667
|
executeTemplate: () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nodii/dev",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.173",
|
|
4
4
|
"description": "Agent CLI for Nodii Dev, reached through the platform edge",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
},
|
|
17
17
|
"scripts": {
|
|
18
18
|
"build": "node build.mjs",
|
|
19
|
-
"lint": "node --check src/*.js && node --check test/*.test.js && node --check test/helpers/*.js && node --check scripts/*.mjs",
|
|
19
|
+
"lint": "node --check src/*.js && node --check test/*.test.js && node --check test/setup.mjs && node --check test/helpers/*.js && node --check scripts/*.mjs",
|
|
20
20
|
"format": "git diff --check",
|
|
21
|
-
"test": "node --test test/*.test.js",
|
|
21
|
+
"test": "node --test --import ./test/setup.mjs test/*.test.js",
|
|
22
22
|
"pack:smoke": "node scripts/pack-smoke.mjs",
|
|
23
23
|
"edge-routes:refresh": "node scripts/edge-routes.mjs",
|
|
24
24
|
"edge-routes:check": "node scripts/edge-routes.mjs --check",
|