@nodii/dev 0.6.171 → 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 +1 -1
- package/dist/read-cache.js +56 -4
- package/dist/surface.js +28 -13
- package/dist/vendor/render-templates.mjs +36 -4
- package/package.json +1 -1
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.
|
|
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");
|
package/dist/read-cache.js
CHANGED
|
@@ -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
|
|
69
|
-
if (
|
|
70
|
-
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
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
|
|
1319
|
-
const
|
|
1320
|
-
|
|
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
|
|
|
@@ -2335,18 +2343,25 @@ function emitNode(node, ctx) {
|
|
|
2335
2343
|
.filter(([, e]) => ds.byKey.has(e.key))
|
|
2336
2344
|
.map(([layer, e]) => [layer, { nodeId: ds.byKey.get(e.key), values: valuesOf(e.props) }]),
|
|
2337
2345
|
);
|
|
2338
|
-
const slotContent = (prop) => {
|
|
2346
|
+
const slotContent = (prop, nestedPath = []) => {
|
|
2339
2347
|
if (DATA_SLOTS.get(node.instance.set)?.has(prop)) {
|
|
2340
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)`);
|
|
2341
2349
|
return `<>{${prop}}</>`;
|
|
2342
2350
|
}
|
|
2343
|
-
|
|
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
|
+
}
|
|
2344
2359
|
if (slotNode && !slotNode.layout && (slotNode.children ?? []).filter((c) => c.visible !== false && !c.absolute).length > 1) {
|
|
2345
2360
|
note(`${path} › ${prop}`, "layout", `slot ${prop} has no auto layout`);
|
|
2346
2361
|
return comment(`unmapped: slot ${JSON.stringify(prop)} has no auto layout`);
|
|
2347
2362
|
}
|
|
2348
2363
|
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}` };
|
|
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}` };
|
|
2350
2365
|
const inner = emitChildren(slotNode?.children ?? [], (c) => emitNode(c, slotCtx), slotCtx);
|
|
2351
2366
|
return inner.length === 0 ? "<></>" : inner.length === 1 ? inner[0] : `<>\n${inner.map((x) => indent(x, 1)).join("\n")}\n</>`;
|
|
2352
2367
|
};
|
|
@@ -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: () => {
|