@nodii/dev 0.6.188 → 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/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
|