@nodii/dev 0.6.149 → 0.6.150
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 +6 -1
- package/dist/cli.js +1 -1
- package/dist/core.js +1 -1
- package/dist/flags.js +1 -1
- package/dist/review.js +59 -2
- package/dist/surface.js +24 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -938,7 +938,7 @@ run the same command again.
|
|
|
938
938
|
### Product pages from Surfaces: `surface generate` (MW8-17)
|
|
939
939
|
|
|
940
940
|
```sh
|
|
941
|
-
nodii-dev surface generate <componentSetKey|route> [--write] [--check] [--fetch] [--figma-version V] [--report FILE] [--post-scoreboard ISSUE] [--resume]
|
|
941
|
+
nodii-dev surface generate <componentSetKey|route> [--write] [--check] [--fetch] [--figma-version V [--node ID]] [--report FILE] [--post-scoreboard ISSUE] [--resume]
|
|
942
942
|
nodii-dev surface generate --all [--module M] [--type page|dialog] [--write] [--check] [--fetch] [--figma-version V] [--report FILE] [--post-scoreboard ISSUE] [--resume]
|
|
943
943
|
```
|
|
944
944
|
|
|
@@ -959,6 +959,11 @@ product-page catalog names the Surface by its published component-set key
|
|
|
959
959
|
version unlabelled. A file with no published rows, or with no version the
|
|
960
960
|
publish closed among its newest 40, is refused with
|
|
961
961
|
`SURFACE_FILE_NOT_PUBLISHED`. `--figma-version V` names a version outright.
|
|
962
|
+
A Surface new to its file is not in the published listing yet
|
|
963
|
+
(`SURFACE_NOT_PUBLISHED`); `--node ID` (only with `--fetch --figma-version V`
|
|
964
|
+
and one named key) locates its set at V, and the read is refused with
|
|
965
|
+
`SURFACE_NODE_KEY_MISMATCH` unless that set's key is the catalog row's. The
|
|
966
|
+
key stays the reference and the node id is not stored (cli-144).
|
|
962
967
|
Without `--fetch`, the committed tree under
|
|
963
968
|
`docs/figma-ux-ds/figma/surface-trees/<fileKey>/<componentSetKey>.json` is
|
|
964
969
|
read and Figma is not called.
|
package/dist/cli.js
CHANGED
|
@@ -185,7 +185,7 @@ Usage: nodii-dev <command> [options] [--json]
|
|
|
185
185
|
# values not bound to a variable and non-DS instances; submit reports the
|
|
186
186
|
# same on any Surface node a set touches (refuses where the host enforces).
|
|
187
187
|
# Reads Figma on Dev's token; exit 1 = SURFACES_CHECK_FAILED
|
|
188
|
-
surface generate <componentSetKey|route> [--write] [--check] [--fetch] [--figma-version V] [--report FILE] [--post-scoreboard ISSUE] [--resume]
|
|
188
|
+
surface generate <componentSetKey|route> [--write] [--check] [--fetch] [--figma-version V [--node ID]] [--report FILE] [--post-scoreboard ISSUE] [--resume]
|
|
189
189
|
surface generate --all [--module M] [--type page|dialog] [--write] [--check] [--fetch] [--figma-version V] [--report FILE] [--post-scoreboard ISSUE] [--resume]
|
|
190
190
|
# a Surface -> its product page's presentational code, from Code Connect
|
|
191
191
|
# (MW8-17), in a design-system checkout. --fetch reads Figma (FIGMA_PAT, one
|
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.150";
|
|
8
8
|
export const configPath = () =>
|
|
9
9
|
process.env.NODII_DEV_CONFIG_PATH ??
|
|
10
10
|
join(homedir(), ".config/nodii-dev/config.json");
|
package/dist/flags.js
CHANGED
|
@@ -77,7 +77,7 @@ export const COMMAND_FLAGS = {
|
|
|
77
77
|
"figma apply": ["file", "figma-version", "lane-reads"],
|
|
78
78
|
"figma lock": ["title", "scope", "lane-reads"],
|
|
79
79
|
"figma scope": ["scope", "lane-reads"],
|
|
80
|
-
"surface generate": ["write", "check", "fetch", "all", "module", "type", "figma-version", "report", "post-scoreboard", "resume"],
|
|
80
|
+
"surface generate": ["write", "check", "fetch", "all", "module", "type", "figma-version", "node", "report", "post-scoreboard", "resume"],
|
|
81
81
|
};
|
|
82
82
|
|
|
83
83
|
/** Refuse a flag the command does not declare (USAGE, exit 2), naming the valid ones. */
|
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 { holdsSet, scopeText } from "./figma.js";
|
|
15
16
|
import { gitPrivatePath } from "./safety.js";
|
|
16
17
|
import { GENERATED_PAGE_GLOB, GENERATED_SUFFIX, hasGeneratedPageStamp } from "./surface.js";
|
|
17
18
|
import { VALUE_FLAGS } from "./impact.js";
|
|
@@ -639,6 +640,52 @@ export async function laneChangeSetNodes(request, agentId, fileKeys, templates =
|
|
|
639
640
|
return scoped;
|
|
640
641
|
}
|
|
641
642
|
|
|
643
|
+
/**
|
|
644
|
+
* NODII-DEV-CLI-141 (MW1-57.6): a Surfaces file whose Freeze boundary names no
|
|
645
|
+
* component set is checked on the lock scopes the lane's agent holds there
|
|
646
|
+
* (Dev's lock check), never silently as the whole shared file. Each page,
|
|
647
|
+
* section or component scope is a frame; a create scope has no node of its
|
|
648
|
+
* own, so the set's live items are. Findings in the scope still block: nothing
|
|
649
|
+
* here is file debt, and the whole file is not read. A whole-file lock, or no
|
|
650
|
+
* held set, leaves the file whole, and wholeFile says why.
|
|
651
|
+
* Returns { scoped: { fileKey: { changeSets, nodes, items, templates, lockScopes, fileDebt: false } }, wholeFile: [{ fileKey, reason }] }.
|
|
652
|
+
*/
|
|
653
|
+
export async function laneSurfaceScopes(request, agentId, boundary, templates = []) {
|
|
654
|
+
const candidates = [...new Set(boundary.filter((file) => !file.componentSetKeys?.length).map((file) => file.fileKey))];
|
|
655
|
+
const result = { scoped: {}, wholeFile: [] };
|
|
656
|
+
if (!candidates.length) return result;
|
|
657
|
+
const files = (await request("GET", "/api/v1/design/files")).data ?? [];
|
|
658
|
+
const surfaces = new Set(files.filter((file) => file.kind === "surfaces").map((file) => file.fileKey));
|
|
659
|
+
for (const fileKey of candidates.filter((key) => surfaces.has(key))) {
|
|
660
|
+
const check = agentId ? (await request("GET", `/api/v1/design/files/${encode(fileKey)}/lock/check?agentId=${encode(agentId)}`)).data : null;
|
|
661
|
+
if (!holdsSet(check)) {
|
|
662
|
+
result.wholeFile.push({ fileKey, reason: `the lane's agent holds no change set in ${fileKey}, so it has no scope to check and the whole file is checked (CLI-141)` });
|
|
663
|
+
continue;
|
|
664
|
+
}
|
|
665
|
+
const scopes = (check.scopes ?? []).filter((s) => !s.releasedAt && (!s.changeSetId || s.changeSetId === check.changeSetId));
|
|
666
|
+
if (!scopes.length || scopes.some((s) => s.kind === "file")) {
|
|
667
|
+
result.wholeFile.push({ fileKey, reason: `${check.changeSetId} holds the whole file, so the whole file is checked (CLI-141)` });
|
|
668
|
+
continue;
|
|
669
|
+
}
|
|
670
|
+
const nodes = new Set();
|
|
671
|
+
const items = [];
|
|
672
|
+
const add = (nodeId, extra) => { if (!nodes.has(nodeId)) items.push({ nodeId, ...extra }); nodes.add(nodeId); };
|
|
673
|
+
for (const s of scopes) if (s.nodeId && ["page", "section", "component"].includes(s.kind)) add(s.nodeId, { changeSet: check.changeSetId });
|
|
674
|
+
if (scopes.some((s) => !s.nodeId)) {
|
|
675
|
+
const set = (await request("GET", `/api/v1/design/change-sets/${encode(check.changeSetId)}`)).data;
|
|
676
|
+
for (const item of set?.items ?? []) if (item.decision !== "withdrawn" && item.change !== "removed" && item.figmaNodeId) add(item.figmaNodeId, { changeSet: check.changeSetId });
|
|
677
|
+
}
|
|
678
|
+
const touched = templates.filter((unit) => unit.fileKey === fileKey);
|
|
679
|
+
for (const unit of touched) add(unit.nodeId, { template: unit.template });
|
|
680
|
+
result.scoped[fileKey] = {
|
|
681
|
+
changeSets: [check.changeSetId], nodes: [...nodes], items,
|
|
682
|
+
templates: [...new Set(touched.map((unit) => unit.template))],
|
|
683
|
+
lockScopes: [...new Set(scopes.map(scopeText))], fileDebt: false,
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
return result;
|
|
687
|
+
}
|
|
688
|
+
|
|
642
689
|
/** A Figma link's file key and node id (`1-2` in a link, `1:2` in the API), or null. */
|
|
643
690
|
export function figmaLinkNode(url) {
|
|
644
691
|
let parsed;
|
|
@@ -747,7 +794,7 @@ export async function swapFor(swaps, { fileKey, nodeId }, readSet) {
|
|
|
747
794
|
* Without a Swap in Dev whose change set holds the node (swapFor), or when
|
|
748
795
|
* Dev's Swaps or change sets can't be read, the missing node stays a finding.
|
|
749
796
|
*/
|
|
750
|
-
export async function figmaFindings(figma, { catalog, check, changeSets = {}, swaps, readSet, lookupSet }) {
|
|
797
|
+
export async function figmaFindings(figma, { catalog, check, changeSets = {}, swaps, readSet, lookupSet, wholeFile = [] }) {
|
|
751
798
|
const scopedFrames = Object.entries(changeSets).flatMap(([fileKey, scoped]) => scoped.nodes.map((nodeId) => {
|
|
752
799
|
const item = scoped.items?.find((x) => x.nodeId === nodeId);
|
|
753
800
|
return { fileKey, nodeId, state: "default", ...(item ? { changeSet: item.changeSet } : {}) };
|
|
@@ -802,6 +849,8 @@ export async function figmaFindings(figma, { catalog, check, changeSets = {}, sw
|
|
|
802
849
|
// verdict as it is (a whole-file DS check is never required, MW2-38.3).
|
|
803
850
|
const fileDebt = [];
|
|
804
851
|
for (const [fileKey, scoped] of Object.entries(changeSets)) {
|
|
852
|
+
// CLI-141: a Surfaces file scoped by its lock is never read whole.
|
|
853
|
+
if (scoped.fileDebt === false) continue;
|
|
805
854
|
const units = new Set(scoped.nodes);
|
|
806
855
|
let data;
|
|
807
856
|
try { data = (await check(fileKey, {})).payload.data; }
|
|
@@ -835,6 +884,8 @@ export async function figmaFindings(figma, { catalog, check, changeSets = {}, sw
|
|
|
835
884
|
...(scopedFiles.some(([, scoped]) => scoped.changeSets.length) ? { changeSets: scopedFiles.filter(([, scoped]) => scoped.changeSets.length).map(([fileKey, scoped]) => ({ fileKey, ids: scoped.changeSets, nodes: (scoped.items ?? []).filter((x) => x.changeSet).length || scoped.nodes.length })) } : {}),
|
|
836
885
|
...(scopedFiles.some(([, scoped]) => scoped.templates?.length) ? { templates: scopedFiles.filter(([, scoped]) => scoped.templates?.length).map(([fileKey, scoped]) => ({ fileKey, paths: scoped.templates, nodes: (scoped.items ?? []).filter((x) => x.template).map((x) => x.nodeId) })) } : {}),
|
|
837
886
|
...(fileDebt.length ? { fileDebt } : {}),
|
|
887
|
+
...(scopedFiles.some(([, scoped]) => scoped.lockScopes?.length) ? { lockScopes: scopedFiles.filter(([, scoped]) => scoped.lockScopes?.length).map(([fileKey, scoped]) => ({ fileKey, changeSet: scoped.changeSets[0], scopes: scoped.lockScopes })) } : {}),
|
|
888
|
+
...(wholeFile.length ? { wholeFile } : {}),
|
|
838
889
|
},
|
|
839
890
|
};
|
|
840
891
|
}
|
|
@@ -1006,8 +1057,14 @@ export async function runLaneCheck(ref, flags, { request, lane, freeze, current,
|
|
|
1006
1057
|
catch (error) {
|
|
1007
1058
|
throw new ReviewerError(UNAVAILABLE, `the lane's change sets could not be read from Dev (${error?.code ?? "ERROR"}: ${error?.message ?? error}), so the Figma check cannot be scoped to their nodes (MW2-38.3) and did not fall back to the whole file`);
|
|
1008
1059
|
}
|
|
1060
|
+
let surfaceScopes;
|
|
1061
|
+
try { surfaceScopes = await laneSurfaceScopes(request, lane.agentId, boundary.filter((file) => !changeSets[file.fileKey]), touched); }
|
|
1062
|
+
catch (error) {
|
|
1063
|
+
throw new ReviewerError(UNAVAILABLE, `the lane's Figma lock scopes could not be read from Dev (${error?.code ?? "ERROR"}: ${error?.message ?? error}), so the Figma check cannot be scoped to them (CLI-141) and did not fall back to the whole file`);
|
|
1064
|
+
}
|
|
1065
|
+
changeSets = { ...changeSets, ...surfaceScopes.scoped };
|
|
1009
1066
|
let checked;
|
|
1010
|
-
try { checked = await figmaFindings(boundary, { catalog, check: designCheck, changeSets, swaps: () => removalSwaps(request), readSet: async (id) => (await request("GET", `/api/v1/design/change-sets/${encodeURIComponent(id)}`)).data }); }
|
|
1067
|
+
try { checked = await figmaFindings(boundary, { catalog, check: designCheck, changeSets, wholeFile: surfaceScopes.wholeFile, swaps: () => removalSwaps(request), readSet: async (id) => (await request("GET", `/api/v1/design/change-sets/${encodeURIComponent(id)}`)).data }); }
|
|
1011
1068
|
catch (error) {
|
|
1012
1069
|
if (error instanceof ReviewerError) throw error;
|
|
1013
1070
|
// A Figma outage (a read past its clock, no answer, rate limited) means
|
package/dist/surface.js
CHANGED
|
@@ -51,9 +51,11 @@ const FIGMA_API = "https://api.figma.com/v1";
|
|
|
51
51
|
export const MIN_FIGMA_INTERVAL_MS = 8_000;
|
|
52
52
|
const BACKOFF_MS = 30_000;
|
|
53
53
|
const SET_KEY = /^[0-9a-f]{40}$/;
|
|
54
|
+
/** A set's node id, as the REST API (5:0) or a Figma URL (5-0) writes it. */
|
|
55
|
+
const NODE_ID = /^(\d+)[:-](\d+)$/;
|
|
54
56
|
|
|
55
57
|
export const SURFACE_USAGE =
|
|
56
|
-
"surface generate <componentSetKey|route> [--write] [--check] [--fetch] [--figma-version V] [--report FILE] [--post-scoreboard ISSUE] [--resume]\n" +
|
|
58
|
+
"surface generate <componentSetKey|route> [--write] [--check] [--fetch] [--figma-version V [--node ID]] [--report FILE] [--post-scoreboard ISSUE] [--resume]\n" +
|
|
57
59
|
"surface generate --all [--module M] [--type page|dialog] [--write] [--check] [--fetch] [--figma-version V] [--report FILE] [--post-scoreboard ISSUE] [--resume]";
|
|
58
60
|
|
|
59
61
|
// ---------------------------------------------------------------------------
|
|
@@ -260,13 +262,21 @@ export async function lastPublishedVersion(figmaGet, fileKey, { library } = {})
|
|
|
260
262
|
throw new CliError("SURFACE_FILE_NOT_PUBLISHED", `${fileKey}: none of its newest ${MAX_VERSION_READS} versions closed at or before its last library publish (${publishedAt}); name a version with --figma-version`, 1);
|
|
261
263
|
}
|
|
262
264
|
|
|
263
|
-
/**
|
|
264
|
-
|
|
265
|
-
|
|
265
|
+
/**
|
|
266
|
+
* Read one Surface set at a file version and trim it to what the generator reads.
|
|
267
|
+
* `node` locates a set new to its file, not yet in its published listing (cli-144):
|
|
268
|
+
* the read is refused unless that node's set has the catalog row's key, which stays
|
|
269
|
+
* the reference (MW8-20); the node id is not kept.
|
|
270
|
+
*/
|
|
271
|
+
export async function fetchSurfaceTree(figmaGet, row, { index, version, node }) {
|
|
272
|
+
const nodeId = node ?? index.get(row.componentSetKey);
|
|
266
273
|
if (!nodeId) throw new CliError("SURFACE_NOT_PUBLISHED", `${row.componentSetName ?? row.id}: component set ${row.componentSetKey} is not among ${row.fileKey}'s published component sets`, 1);
|
|
267
274
|
const body = await figmaGet(`/files/${encodeURIComponent(row.fileKey)}/nodes?ids=${encodeURIComponent(nodeId)}${version ? `&version=${encodeURIComponent(version)}` : ""}`);
|
|
268
275
|
const entry = body.nodes?.[nodeId];
|
|
269
276
|
if (!entry?.document) throw new CliError("FIGMA_NOT_FOUND", `Figma returned no document for ${row.componentSetName ?? row.id}`, 1);
|
|
277
|
+
const found = node ? (entry.document.type === "COMPONENT_SET" ? (entry.componentSets?.[nodeId]?.key ?? null) : null) : row.componentSetKey;
|
|
278
|
+
if (found !== row.componentSetKey)
|
|
279
|
+
throw new CliError("SURFACE_NODE_KEY_MISMATCH", `${row.componentSetName ?? row.id}: node ${nodeId} at version ${version} is ${found ? `component set ${found}` : "not a component set"}, not the catalog's ${row.componentSetKey}; --node only locates the catalog row's own set (cli-144, MW8-20)`, 1);
|
|
270
280
|
return trimTree(entry, { row, version: version ?? body.version ?? null });
|
|
271
281
|
}
|
|
272
282
|
|
|
@@ -2722,6 +2732,14 @@ export async function surfaceCommand(action, rest, f, deps = {}) {
|
|
|
2722
2732
|
if (f.write && f.check) throw new CliError("USAGE", "--write and --check are separate runs: --write updates the files, --check refuses a difference", 2);
|
|
2723
2733
|
if (f.check && f.fetch) throw new CliError("USAGE", "--check regenerates from the committed trees and never reads Figma; drop --fetch", 2);
|
|
2724
2734
|
if (f.resume && !(f.fetch && f.write)) throw new CliError("USAGE", "--resume continues a stopped read: use it with --fetch --write", 2);
|
|
2735
|
+
// --node locates one named Surface that is new to its file at a named version (cli-144).
|
|
2736
|
+
const nodeMatch = f.node === undefined ? null : NODE_ID.exec(String(f.node));
|
|
2737
|
+
if (f.node !== undefined) {
|
|
2738
|
+
if (!nodeMatch) throw new CliError("USAGE", `--node needs a component set's node id, for example 5:0: got ${f.node === true ? "nothing" : f.node}`, 2);
|
|
2739
|
+
if (!f.fetch || !f["figma-version"] || f["figma-version"] === true) throw new CliError("USAGE", "--node reads Figma at a named version: use it with --fetch --figma-version V", 2);
|
|
2740
|
+
if (f.all || !SET_KEY.test(rest[0] ?? "")) throw new CliError("USAGE", "--node locates one Surface: name it by its component-set key, not --all or a route", 2);
|
|
2741
|
+
}
|
|
2742
|
+
const node = nodeMatch ? `${nodeMatch[1]}:${nodeMatch[2]}` : undefined;
|
|
2725
2743
|
const postTo = f["post-scoreboard"];
|
|
2726
2744
|
if (postTo === true || postTo === "") throw new CliError("USAGE", "--post-scoreboard needs an issue key, for example DESIGN-SYSTEM-249", 2);
|
|
2727
2745
|
const { env = process.env, exec = execFileSync, log = (line) => process.stderr.write(`${line}\n`), figmaGet: injected, docs, cwd } = deps;
|
|
@@ -2791,7 +2809,7 @@ export async function surfaceCommand(action, rest, f, deps = {}) {
|
|
|
2791
2809
|
continue;
|
|
2792
2810
|
}
|
|
2793
2811
|
}
|
|
2794
|
-
if (!indexes.has(row.fileKey)) indexes.set(row.fileKey, await setIndex(figmaGet, row.fileKey));
|
|
2812
|
+
if (!node && !indexes.has(row.fileKey)) indexes.set(row.fileKey, await setIndex(figmaGet, row.fileKey));
|
|
2795
2813
|
// --all covers a module: one unpublished Surface is reported, and the rest still generate.
|
|
2796
2814
|
// A Surface named on its own stays a refusal, because the run has nothing else to do.
|
|
2797
2815
|
if (f.all && !indexes.get(row.fileKey).has(row.componentSetKey)) {
|
|
@@ -2800,7 +2818,7 @@ export async function surfaceCommand(action, rest, f, deps = {}) {
|
|
|
2800
2818
|
continue;
|
|
2801
2819
|
}
|
|
2802
2820
|
log(`reading ${row.componentSetName ?? row.id} from Figma at version ${version}`);
|
|
2803
|
-
tree = await fetchSurfaceTree(figmaGet, row, { index: indexes.get(row.fileKey), version });
|
|
2821
|
+
tree = await fetchSurfaceTree(figmaGet, row, { index: indexes.get(row.fileKey), version, node });
|
|
2804
2822
|
} catch (error) {
|
|
2805
2823
|
// --all keeps what it read and scores it; a Surface named on its own has nothing to keep.
|
|
2806
2824
|
if (!f.all || error?.code !== "FIGMA_RATE_LIMITED") throw error;
|