@nodii/dev 0.6.187 → 0.6.189
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/review.js +75 -2
- package/dist/surface.js +19 -11
- 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.189";
|
|
8
8
|
export const configPath = () =>
|
|
9
9
|
process.env.NODII_DEV_CONFIG_PATH ??
|
|
10
10
|
join(homedir(), ".config/nodii-dev/config.json");
|
package/dist/review.js
CHANGED
|
@@ -12,6 +12,7 @@ import { promisify } from "node:util";
|
|
|
12
12
|
import { CliError, encode } from "./core.js";
|
|
13
13
|
import { pickerPrompt } from "./gather.js";
|
|
14
14
|
import { componentSetsIn, designCatalogSets } from "./figma-scope.js";
|
|
15
|
+
import { figmaClient, figmaToken } from "./design.js";
|
|
15
16
|
import { holdsSet, scopeText } from "./figma.js";
|
|
16
17
|
import { gitPrivatePath } from "./safety.js";
|
|
17
18
|
import { GENERATED_PAGE_GLOB, GENERATED_SUFFIX, hasGeneratedPageStamp } from "./surface.js";
|
|
@@ -687,7 +688,7 @@ export const frameUrl = (fileKey, nodeId) => `https://www.figma.com/design/${fil
|
|
|
687
688
|
* or, for a DS component set, its own node as the design catalogue
|
|
688
689
|
* publishes it under the key (NODII-DEV-CLI-70); a whole-file boundary is the whole file.
|
|
689
690
|
*/
|
|
690
|
-
export async function boundaryFrames(figma, { catalog, lookupSet = designCatalogSets() } = {}) {
|
|
691
|
+
export async function boundaryFrames(figma, { catalog, lookupSet = designCatalogSets(), resolveKey = figmaKeyResolver() } = {}) {
|
|
691
692
|
const surfaces = figma.some((file) => file.componentSetKeys?.length) ? await catalog() : [];
|
|
692
693
|
const frames = [];
|
|
693
694
|
for (const file of figma) {
|
|
@@ -699,11 +700,83 @@ export async function boundaryFrames(figma, { catalog, lookupSet = designCatalog
|
|
|
699
700
|
if (error?.code === "FIGMA_KEY_UNKNOWN") throw new ReviewerError("CRASH", `the Freeze's Figma boundary: ${error.message}`);
|
|
700
701
|
throw error;
|
|
701
702
|
}
|
|
702
|
-
for (const key of keys)
|
|
703
|
+
for (const key of keys) {
|
|
704
|
+
const seen = new Set();
|
|
705
|
+
for (const frame of await framesAsNodes(file.fileKey, key, sets.get(key).frames, resolveKey)) {
|
|
706
|
+
if (seen.has(frame.nodeId)) continue;
|
|
707
|
+
seen.add(frame.nodeId);
|
|
708
|
+
frames.push({ fileKey: file.fileKey, ...frame });
|
|
709
|
+
}
|
|
710
|
+
}
|
|
703
711
|
}
|
|
704
712
|
return frames;
|
|
705
713
|
}
|
|
706
714
|
|
|
715
|
+
/**
|
|
716
|
+
* hub-594: since SWAP-7cb36363 the DS catalog maps a Surface's
|
|
717
|
+
* states to published component KEYS, not node ids. Figma's /nodes takes
|
|
718
|
+
* node ids only (a key is a 400), so each key is resolved to its node first.
|
|
719
|
+
* A state key Figma does not know (an unpublished state) falls back to its
|
|
720
|
+
* set's own node; when neither resolves, the boundary is a named CRASH.
|
|
721
|
+
*/
|
|
722
|
+
async function framesAsNodes(fileKey, setKey, frames, resolveKey) {
|
|
723
|
+
const isKey = (id) => COMPONENT_KEY.test(String(id ?? ""));
|
|
724
|
+
if (!frames.some((frame) => isKey(frame.nodeId))) return frames;
|
|
725
|
+
const homeIn = async (key) => {
|
|
726
|
+
const home = await resolveKey(key, fileKey);
|
|
727
|
+
return home?.nodeId && (!home.fileKey || home.fileKey === fileKey) ? String(home.nodeId) : null;
|
|
728
|
+
};
|
|
729
|
+
let setNode;
|
|
730
|
+
const out = [];
|
|
731
|
+
const unresolved = [];
|
|
732
|
+
for (const frame of frames) {
|
|
733
|
+
if (!isKey(frame.nodeId)) { out.push(frame); continue; }
|
|
734
|
+
let nodeId = await homeIn(frame.nodeId);
|
|
735
|
+
if (!nodeId) {
|
|
736
|
+
setNode ??= { nodeId: await homeIn(setKey) };
|
|
737
|
+
nodeId = setNode.nodeId;
|
|
738
|
+
}
|
|
739
|
+
if (!nodeId) { unresolved.push(`${frame.state} (${frame.nodeId})`); continue; }
|
|
740
|
+
out.push({ ...frame, nodeId });
|
|
741
|
+
}
|
|
742
|
+
if (unresolved.length)
|
|
743
|
+
throw new ReviewerError("CRASH", `the Freeze's Figma boundary: set ${setKey} in ${fileKey} names state component keys Figma resolves to no node, and the set's own key resolves to none either: ${unresolved.join(", ")}. Publish the set, or name its frames by node id.`);
|
|
744
|
+
return out;
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
const COMPONENT_KEY = /^[0-9a-f]{40}$/;
|
|
748
|
+
|
|
749
|
+
/**
|
|
750
|
+
* Figma's published components and component sets of a file, on FIGMA_PAT:
|
|
751
|
+
* two listing reads per file, cached, so a Surface with many states costs no
|
|
752
|
+
* per-key read (the machine paces Figma at one call per 8 s). A key the file
|
|
753
|
+
* does not publish resolves to null.
|
|
754
|
+
*/
|
|
755
|
+
export function figmaKeyResolver({ env = process.env, figmaGet } = {}) {
|
|
756
|
+
let get = figmaGet;
|
|
757
|
+
const files = new Map();
|
|
758
|
+
const listing = async (path) => {
|
|
759
|
+
try { return (await get(path)).meta ?? {}; }
|
|
760
|
+
catch (error) {
|
|
761
|
+
if (error instanceof CliError && error.code === "FIGMA_NOT_FOUND") return {};
|
|
762
|
+
throw error;
|
|
763
|
+
}
|
|
764
|
+
};
|
|
765
|
+
const homes = (fileKey) => {
|
|
766
|
+
if (!files.has(fileKey))
|
|
767
|
+
files.set(fileKey, (async () => {
|
|
768
|
+
get ??= figmaClient(figmaToken(env));
|
|
769
|
+
const byKey = new Map();
|
|
770
|
+
for (const kind of ["components", "component_sets"])
|
|
771
|
+
for (const row of (await listing(`/files/${encodeURIComponent(fileKey)}/${kind}`))[kind] ?? [])
|
|
772
|
+
if (row?.key && row?.node_id) byKey.set(String(row.key), { fileKey, nodeId: String(row.node_id) });
|
|
773
|
+
return byKey;
|
|
774
|
+
})());
|
|
775
|
+
return files.get(fileKey);
|
|
776
|
+
};
|
|
777
|
+
return async (key, fileKey) => (fileKey ? (await homes(fileKey)).get(key) ?? null : null);
|
|
778
|
+
}
|
|
779
|
+
|
|
707
780
|
/**
|
|
708
781
|
* MW2-38.3: the nodes of the change sets a lane's agent holds in each
|
|
709
782
|
* boundary file Dev registers as the design system. Returns
|
package/dist/surface.js
CHANGED
|
@@ -34,7 +34,7 @@ import { MIN_FIGMA_INTERVAL_MS, figmaRest } from "./figma-rest.js";
|
|
|
34
34
|
import { createRenderer } from "./vendor/render-templates.mjs";
|
|
35
35
|
|
|
36
36
|
/** Bumped whenever the emitted code changes shape for the same inputs. */
|
|
37
|
-
export const GENERATOR_FORMAT =
|
|
37
|
+
export const GENERATOR_FORMAT = 45;
|
|
38
38
|
/**
|
|
39
39
|
* DS parts that are an item of their parent's own list or grid, so they take no sizing
|
|
40
40
|
* wrapper: a Detail Section / Row's facts are the section grid's cells, a Right Pane / Row
|
|
@@ -2710,27 +2710,35 @@ function emitChildren(children, emitOne, ctx) {
|
|
|
2710
2710
|
}
|
|
2711
2711
|
|
|
2712
2712
|
const LABEL_FOR = /<Label\b[^>]*?\bhtmlFor=\{([A-Za-z_$][\w$]*)\}/;
|
|
2713
|
-
const LABELLED_CONTROL = /<(?:Checkbox|Switch|RadioGroupItem)(?=[\s/>])/;
|
|
2713
|
+
const LABELLED_CONTROL = /<(?:Checkbox|Switch|RadioGroupItem|Textarea|Input|SelectField)(?=[\s/>])/;
|
|
2714
2714
|
/**
|
|
2715
2715
|
* A DS Label beside its control names it: the Label template emits htmlFor={x}, so the
|
|
2716
|
-
* Checkbox, Switch or
|
|
2717
|
-
*
|
|
2716
|
+
* Checkbox, Switch, RadioGroupItem, Textarea, Input or SelectField next to it (in the same
|
|
2717
|
+
* container) takes id={x}, or, when that control already has an id of its own, the Label's
|
|
2718
|
+
* htmlFor takes that id. Without it the label isn't tied to the control and the control has
|
|
2718
2719
|
* no accessible name (DESIGN-SYSTEM-817). Each label names the one control beside it.
|
|
2719
2720
|
*/
|
|
2720
2721
|
function pairLabelledControls(codes) {
|
|
2722
|
+
const out = [...codes];
|
|
2721
2723
|
const labelOf = codes.map((c) => LABEL_FOR.exec(c ?? "")?.[1] ?? null);
|
|
2722
2724
|
const used = new Set();
|
|
2723
|
-
|
|
2725
|
+
codes.forEach((code, i) => {
|
|
2724
2726
|
const control = code ? LABELLED_CONTROL.exec(code) : null;
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
if (/\sid=/.test(open)) return code;
|
|
2727
|
+
// A container that holds a Label of its own is already paired, at its own level.
|
|
2728
|
+
if (!control || /<Label\b/.test(code)) return;
|
|
2728
2729
|
const at = [i + 1, i - 1].find((j) => labelOf[j] && !used.has(j));
|
|
2729
|
-
if (at === undefined) return
|
|
2730
|
+
if (at === undefined) return;
|
|
2730
2731
|
used.add(at);
|
|
2731
|
-
const
|
|
2732
|
-
|
|
2732
|
+
const open = code.slice(control.index, control.index + openTagEnd(code.slice(control.index)) + 1);
|
|
2733
|
+
const own = /\sid=("(?:[^"\\\n]|\\.)*"|\{[^{}]*\})/.exec(open)?.[1];
|
|
2734
|
+
// The control keeps its own id; its Label points at it.
|
|
2735
|
+
if (own) out[at] = out[at].replace(LABEL_FOR, (tag) => tag.replace(/htmlFor=\{[^}]*\}/, `htmlFor=${own}`));
|
|
2736
|
+
else {
|
|
2737
|
+
const end = control.index + control[0].length;
|
|
2738
|
+
out[i] = `${code.slice(0, end)} id={${labelOf[at]}}${code.slice(end)}`;
|
|
2739
|
+
}
|
|
2733
2740
|
});
|
|
2741
|
+
return out;
|
|
2734
2742
|
}
|
|
2735
2743
|
|
|
2736
2744
|
/** What the DescriptionList template emits for one field: one DescriptionItem in its list. */
|