@nodii/dev 0.6.169 → 0.6.172

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/dist/core.js CHANGED
@@ -4,7 +4,7 @@ import { chmod, mkdir, readFile, rm, writeFile } from "node:fs/promises";
4
4
  import { homedir, platform } from "node:os";
5
5
  import { dirname, join } from "node:path";
6
6
 
7
- export const VERSION = "0.6.169";
7
+ export const VERSION = "0.6.172";
8
8
  export const configPath = () =>
9
9
  process.env.NODII_DEV_CONFIG_PATH ??
10
10
  join(homedir(), ".config/nodii-dev/config.json");
@@ -1,5 +1,5 @@
1
1
  import { createHash, randomUUID } from "node:crypto";
2
- import { mkdir, readFile, readdir, rename, rm, stat, writeFile } from "node:fs/promises";
2
+ import { mkdir, open, readFile, readdir, rename, rm, stat, writeFile } from "node:fs/promises";
3
3
  import { dirname, join } from "node:path";
4
4
  import { configPath } from "./core.js";
5
5
 
@@ -12,6 +12,15 @@ import { configPath } from "./core.js";
12
12
  // the lane or asks for an acknowledgement is always read fresh.
13
13
  export const READ_CACHE_TTL_MS = 15_000;
14
14
  const PRUNE_AFTER_MS = 60 * 60_000;
15
+ // A miss is single-flight across processes: the calls in flight at an expiry
16
+ // all missed together, so nodii-dev twice a second read the Freeze twice per
17
+ // 15 seconds. One process takes the path's lock and reads Dev; the others wait
18
+ // for its answer, up to WAIT_MS, then read Dev themselves. A lock older than
19
+ // LOCK_STALE_MS belongs to a process that died and is taken over.
20
+ const LOCK_STALE_MS = 10_000;
21
+ const WAIT_MS = 3_000;
22
+ const POLL_MS = 50;
23
+ const pause = (ms) => new Promise((done) => setTimeout(done, ms));
15
24
 
16
25
  const defaultDir = () => join(dirname(configPath()), "read-cache");
17
26
 
@@ -43,6 +52,36 @@ export function laneReadCache({ dir = defaultDir(), ttlMs = READ_CACHE_TTL_MS, n
43
52
  if (Math.random() < 0.05) await prune(dir, now());
44
53
  } catch {}
45
54
  },
55
+ /** Take the path's lock: a release function, or null while another live process holds it. */
56
+ async lock(path) {
57
+ const target = `${file(path)}.lock`;
58
+ for (let attempt = 0; attempt < 2; attempt += 1) {
59
+ try {
60
+ await mkdir(dir, { recursive: true, mode: 0o700 });
61
+ const handle = await open(target, "wx", 0o600);
62
+ await handle.writeFile(String(now()));
63
+ await handle.close();
64
+ return () => rm(target, { force: true }).catch(() => {});
65
+ } catch (error) {
66
+ if (error?.code !== "EEXIST") return () => {};
67
+ let at = Number.NaN;
68
+ try {
69
+ at = Number(await readFile(target, "utf8"));
70
+ } catch {}
71
+ if (now() - at < LOCK_STALE_MS) return null;
72
+ await rm(target, { force: true }).catch(() => {});
73
+ }
74
+ }
75
+ return null;
76
+ },
77
+ async locked(path) {
78
+ try {
79
+ await stat(`${file(path)}.lock`);
80
+ return true;
81
+ } catch {
82
+ return false;
83
+ }
84
+ },
46
85
  async drop(path) {
47
86
  try {
48
87
  await rm(file(path), { force: true });
@@ -65,9 +104,22 @@ export async function cachedGet(cache, request, path, keep = () => true) {
65
104
  if (!cache) return request("GET", path);
66
105
  const hit = await cache.get(path);
67
106
  if (hit !== undefined) return hit;
68
- const answer = await request("GET", path);
69
- if (keep(answer)) await cache.set(path, answer);
70
- return answer;
107
+ const release = cache.lock ? await cache.lock(path) : () => {};
108
+ if (!release) {
109
+ // Another process is reading Dev: wait for its answer. If it is not kept
110
+ // (it blocks or asks for an acknowledgement), the lock goes and we read Dev.
111
+ for (let waited = 0; waited < WAIT_MS && (await cache.locked(path)); waited += POLL_MS) await pause(POLL_MS);
112
+ const shared = await cache.get(path);
113
+ if (shared !== undefined) return shared;
114
+ return request("GET", path);
115
+ }
116
+ try {
117
+ const answer = await request("GET", path);
118
+ if (keep(answer)) await cache.set(path, answer);
119
+ return answer;
120
+ } finally {
121
+ await release();
122
+ }
71
123
  }
72
124
 
73
125
  /** A request function whose GETs go through the cache; every other method goes to Dev. */
package/dist/surface.js CHANGED
@@ -32,7 +32,7 @@ import { CliError, VERSION, devRequest, readConfig } from "./core.js";
32
32
  import { createRenderer } from "./vendor/render-templates.mjs";
33
33
 
34
34
  /** Bumped whenever the emitted code changes shape for the same inputs. */
35
- export const GENERATOR_FORMAT = 37;
35
+ export const GENERATOR_FORMAT = 39;
36
36
  export const TREE_DIR = "docs/figma-ux-ds/figma/surface-trees";
37
37
  export const GENERATED_SUFFIX = ".surface.generated.tsx";
38
38
  /** Where every generated product page lives, as a git glob (NODII-DEV-CLI-77). */
@@ -418,7 +418,8 @@ export function trimTree(entry, { row, version }) {
418
418
  for (const layer of layersOf(node)) {
419
419
  if (layer.type !== "INSTANCE" || exposed[layer.name]) continue;
420
420
  if (layer.isExposedInstance || overridden.has(layer.id) || layer.overrides?.some((o) => o.overriddenFields?.length)) {
421
- exposed[layer.name] = { key: keyOf(layer.componentId), props: propsOf(layer) };
421
+ const own = trim(layer, box);
422
+ exposed[layer.name] = { key: keyOf(layer.componentId), props: propsOf(layer), ...(own.children ? { children: own.children } : {}) };
422
423
  }
423
424
  }
424
425
  if (Object.keys(exposed).length) out.instance.exposed = exposed;
@@ -1310,16 +1311,23 @@ function hideable(code) {
1310
1311
  }
1311
1312
  return `<AlertAction>${held}</AlertAction>`;
1312
1313
  });
1313
- const strip = /<Tabs panelless value=\{(__s\d+)_tab\}/.exec(out);
1314
- const triggers = out.match(/<TabsTrigger\b/g) ?? [];
1315
- if (strip && triggers.length === 1) {
1316
- out = out.replace(/^([ \t]*)(<TabsTrigger\b[\s\S]*?<\/TabsTrigger>)/m, (_, pad, trigger) => {
1314
+ out = out.replace(/<Tabs panelless value=\{(__s\d+)_tab\}[\s\S]*?<\/Tabs>/g, (strip, scope) => {
1315
+ // A parent template may include a child strip that was already processed.
1316
+ if (strip.includes(`${scope}_visibleTabs`)) return strip;
1317
+ const used = new Set();
1318
+ return strip.replace(/^([ \t]*)(<TabsTrigger\b[\s\S]*?<\/TabsTrigger>)/gm, (_, pad, trigger) => {
1319
+ const current = /\bvalue="([^"]+)"/.exec(trigger)?.[1];
1320
+ if (!current) return `${pad}${trigger}`;
1317
1321
  const label = /\{("(?:[^"\\\n]|\\.)*")\}/.exec(trigger);
1318
- const value = (label && slug(JSON.parse(label[1]))) || "tab";
1319
- const body = trigger.replace(/\bvalue="tab"/, `value="${value}"`).split("\n").map((line, i) => (i === 0 ? `${pad} ${line}` : line ? ` ${line}` : line)).join("\n");
1320
- return `${pad}{(${strip[1]}_visibleTabs?.includes(${JSON.stringify(value)}) ?? true) && (\n${body}\n${pad})}`;
1322
+ const text = label ? JSON.parse(label[1]) : "";
1323
+ const named = text ? slug(/\d/.test(text) ? nameText(text) : text) : "";
1324
+ const candidate = /^tab(?:-\d+)?$/.test(current) && named ? named : current;
1325
+ const value = used.has(candidate) ? current : candidate;
1326
+ used.add(value);
1327
+ const body = trigger.replace(/\bvalue="[^"]+"/, `value="${value}"`).split("\n").map((line, i) => (i === 0 ? `${pad} ${line}` : line ? ` ${line}` : line)).join("\n");
1328
+ return `${pad}{(${scope}_visibleTabs?.includes(${JSON.stringify(value)}) ?? true) && (\n${body}\n${pad})}`;
1321
1329
  });
1322
- }
1330
+ });
1323
1331
  return out;
1324
1332
  }
1325
1333
 
@@ -1901,6 +1909,10 @@ function dataProps(views, propsType) {
1901
1909
  if (list) member(entry(list), "kind").set("\u0000kind", { raw: '"branch" | "leaf"' });
1902
1910
  }
1903
1911
  const itemList = (at, name) => (openers.some((o) => o.param === name) ? listAt(openers, at, name) : null);
1912
+ for (const m of body.matchAll(/onCheckedChange=\{([a-z][A-Za-z0-9]*) && \(\(checked\) => \1\(row\.id, checked\)\)\}/g)) {
1913
+ own(m[1], '(id: string, checked: Parameters<NonNullable<ComponentProps<typeof TableSelectionCell>["onCheckedChange"]>>[0]) => void');
1914
+ view.uses.add(m[1]);
1915
+ }
1904
1916
  // hub-492: absence of a handler keeps an inert row noninteractive.
1905
1917
  for (const m of body.matchAll(/onClick=\{([a-z][A-Za-z0-9]*)\?\.\(row\) \? undefined : ([a-z][A-Za-z0-9]*) \? \2\(row\) : ([a-z][A-Za-z0-9]*) && /g)) {
1906
1918
  const list = listAt(openers, m.index, "row");
@@ -2331,18 +2343,25 @@ function emitNode(node, ctx) {
2331
2343
  .filter(([, e]) => ds.byKey.has(e.key))
2332
2344
  .map(([layer, e]) => [layer, { nodeId: ds.byKey.get(e.key), values: valuesOf(e.props) }]),
2333
2345
  );
2334
- const slotContent = (prop) => {
2346
+ const slotContent = (prop, nestedPath = []) => {
2335
2347
  if (DATA_SLOTS.get(node.instance.set)?.has(prop)) {
2336
2348
  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)`);
2337
2349
  return `<>{${prop}}</>`;
2338
2350
  }
2339
- const slotNode = (node.children ?? []).find((c) => c.type === "SLOT" && c.slot === prop);
2351
+ let owner = node;
2352
+ for (const layer of nestedPath) owner = owner?.instance?.exposed?.[layer] ?? owner?.exposed?.[layer];
2353
+ const slotNode = (owner?.children ?? []).find((c) => c.type === "SLOT" && c.slot === prop);
2354
+ if (nestedPath.length && !slotNode) {
2355
+ const detail = `nested slot ${nestedPath.join(" › ")} › ${prop} is absent from the saved tree; regenerate with --fetch to preserve its content`;
2356
+ note(path, "template", detail);
2357
+ return comment(`unmapped: ${detail}`);
2358
+ }
2340
2359
  if (slotNode && !slotNode.layout && (slotNode.children ?? []).filter((c) => c.visible !== false && !c.absolute).length > 1) {
2341
2360
  note(`${path} › ${prop}`, "layout", `slot ${prop} has no auto layout`);
2342
2361
  return comment(`unmapped: slot ${JSON.stringify(prop)} has no auto layout`);
2343
2362
  }
2344
2363
  const textOwner = TEXT_PROPERTY_PARTS.has(node.instance.set) ? node.instance.set : ctx.textOwner;
2345
- 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}` };
2364
+ 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}` };
2346
2365
  const inner = emitChildren(slotNode?.children ?? [], (c) => emitNode(c, slotCtx), slotCtx);
2347
2366
  return inner.length === 0 ? "<></>" : inner.length === 1 ? inner[0] : `<>\n${inner.map((x) => indent(x, 1)).join("\n")}\n</>`;
2348
2367
  };
@@ -3209,7 +3228,8 @@ function tableOf(node, ctx) {
3209
3228
  const rowsName = mark(ctx, listName, "rows", null);
3210
3229
  let selectedKey = "isSelected";
3211
3230
  while (keys.includes(selectedKey)) selectedKey += "Row";
3212
- const selection = dataRows.some(p => p.cells.some(c => c.selected)) ? ` selected={row.${selectedKey}}` : "";
3231
+ const selectable = dataRows.some(p => p.cells.some(c => /<TableSelectionCell\b/.test(c.code ?? "")));
3232
+ const selection = selectable || dataRows.some(p => p.cells.some(c => c.selected)) ? ` selected={row.${selectedKey}}` : "";
3213
3233
  // A row is a door to its record when the page passes a handler (U03-7; NODII-DEV-CLI-83).
3214
3234
  const rowClick = mark(ctx, listName, "onRowClick", null);
3215
3235
  const inert = mark(ctx, listName, "isRowInert", null);
@@ -3273,6 +3293,13 @@ function tableOf(node, ctx) {
3273
3293
  open = own.slice(0, end + 1).replace(/\s*\/>$/, ">");
3274
3294
  close = `</${tag}>`;
3275
3295
  }
3296
+ // Selection is record data even when the drawing shows every row unchecked.
3297
+ if (/^<TableSelectionCell\b/.test(open)) {
3298
+ const change = mark(ctx, listName, "onRowSelectionChange", null);
3299
+ open = open.replace(/\bchecked=\{(?:true|false)\}/, `checked={row.${selectedKey}}`)
3300
+ .replace(/\bonCheckedChange=\{(?:__s\d+_)?onSelect\}/, `onCheckedChange={${change} && ((checked) => ${change}(row.id, checked))}`);
3301
+ return indent(`${open.slice(0, -1)} />`, depth + 4);
3302
+ }
3276
3303
  // Two-line templates own the presentation; both lines belong to each row.
3277
3304
  // Reserve every header key before naming secondary fields, so a column
3278
3305
  // called "Environment secondary" cannot alias Environment's second line.
@@ -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 ? options.slot(section.propertyName) : "<></>";
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(context, setNode, props, depth, label, reads = null, exposed = null) {
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 = value && typeof value === "object" ? value : { nodeId: value };
325
- return swapHandle(context, String(swap.nodeId), depth, label, swap.values);
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.169",
3
+ "version": "0.6.172",
4
4
  "description": "Agent CLI for Nodii Dev, reached through the platform edge",
5
5
  "type": "module",
6
6
  "bin": {