@nodii/dev 0.6.66 → 0.6.67
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/design.js +1 -1
- package/dist/review.js +55 -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.67";
|
|
8
8
|
export const configPath = () =>
|
|
9
9
|
process.env.NODII_DEV_CONFIG_PATH ??
|
|
10
10
|
join(homedir(), ".config/nodii-dev/config.json");
|
package/dist/design.js
CHANGED
|
@@ -133,7 +133,7 @@ export async function fetchNodes(figmaGet, fileKey, nodeIds) {
|
|
|
133
133
|
const nodes = {};
|
|
134
134
|
// A whole page is a large document: fetch pages one per call.
|
|
135
135
|
for (const part of chunks(ids, nodeIds.length ? IDS_PER_CALL : 1)) {
|
|
136
|
-
const response = await figmaGet(`/files/${encodeURIComponent(fileKey)}/nodes?ids=${encodeURIComponent(part.join(","))}`);
|
|
136
|
+
const response = await figmaGet(`/files/${encodeURIComponent(fileKey)}/nodes?ids=${encodeURIComponent(part.join(","))}&geometry=omit`);
|
|
137
137
|
for (const id of part) nodes[id] = response.nodes?.[id] ?? null;
|
|
138
138
|
}
|
|
139
139
|
return nodes;
|
package/dist/review.js
CHANGED
|
@@ -26,6 +26,8 @@ export const MAX_DIFF_CHARS = 600_000;
|
|
|
26
26
|
export const CODE_NOT_REQUIRED = { decision: "DEC-0085" };
|
|
27
27
|
const PASSING = { rules: ["CLEAN"], figma: ["CLEAN", "NOT_APPLICABLE"], code: ["CLEAN", "NOT_REQUIRED"] };
|
|
28
28
|
const UNAVAILABLE = "REVIEWER_UNAVAILABLE";
|
|
29
|
+
// Figma errors that mean Figma was not reachable in time, not that the design failed.
|
|
30
|
+
const FIGMA_OUTAGE = ["FIGMA_TIMEOUT", "FIGMA_UNREACHABLE", "FIGMA_RATE_LIMITED"];
|
|
29
31
|
|
|
30
32
|
class ReviewerError extends Error {
|
|
31
33
|
constructor(outcome, message) {
|
|
@@ -353,9 +355,47 @@ export function boundaryFrames(figma, surfaces) {
|
|
|
353
355
|
});
|
|
354
356
|
}
|
|
355
357
|
|
|
356
|
-
/**
|
|
357
|
-
|
|
358
|
-
|
|
358
|
+
/**
|
|
359
|
+
* MW2-38.3: the nodes of the change sets a lane's agent holds in each
|
|
360
|
+
* boundary file Dev registers as the design system. Returns
|
|
361
|
+
* { fileKey: { changeSets: [id], nodes: [nodeId] } } for files with at least
|
|
362
|
+
* one node. Dev's holderAgentId filter is checked again here, because a Dev
|
|
363
|
+
* without it ignores the parameter and lists every set on the file. Items the
|
|
364
|
+
* lane withdrew are left out; rejected items stay in until withdrawn. A
|
|
365
|
+
* removed item's node is gone from Figma, so there is nothing to check.
|
|
366
|
+
*/
|
|
367
|
+
export async function laneChangeSetNodes(request, agentId, fileKeys) {
|
|
368
|
+
if (!agentId || !fileKeys.length) return {};
|
|
369
|
+
const files = (await request("GET", "/api/v1/design/files")).data ?? [];
|
|
370
|
+
const ds = new Set(files.filter((file) => file.kind === "design-system").map((file) => file.fileKey));
|
|
371
|
+
const scoped = {};
|
|
372
|
+
for (const fileKey of [...new Set(fileKeys)].filter((key) => ds.has(key))) {
|
|
373
|
+
const rows = (await request("GET", `/api/v1/design/change-sets?holderAgentId=${encodeURIComponent(agentId)}&fileKey=${encodeURIComponent(fileKey)}&limit=500`)).data ?? [];
|
|
374
|
+
const held = rows.filter((row) => row.holder?.agent?.id === agentId && row.fileKey === fileKey && row.state !== "abandoned");
|
|
375
|
+
const nodes = new Set();
|
|
376
|
+
const changeSets = [];
|
|
377
|
+
for (const row of held) {
|
|
378
|
+
const set = (await request("GET", `/api/v1/design/change-sets/${encodeURIComponent(row.id)}`)).data;
|
|
379
|
+
const live = (set?.items ?? []).filter((item) => item.decision !== "withdrawn" && item.change !== "removed" && item.figmaNodeId);
|
|
380
|
+
if (!live.length) continue;
|
|
381
|
+
changeSets.push(row.id);
|
|
382
|
+
for (const item of live) nodes.add(item.figmaNodeId);
|
|
383
|
+
}
|
|
384
|
+
if (nodes.size) scoped[fileKey] = { changeSets, nodes: [...nodes] };
|
|
385
|
+
}
|
|
386
|
+
return scoped;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* DEV-REV-9, design-check part: designCheck on every boundary frame; per-state
|
|
391
|
+
* frame comparison is Q-162. A boundary file with held change-set nodes
|
|
392
|
+
* (MW2-38.3, from laneChangeSetNodes) is checked on those nodes only, never
|
|
393
|
+
* as the whole file.
|
|
394
|
+
*/
|
|
395
|
+
export async function figmaFindings(figma, { catalog, check, changeSets = {} }) {
|
|
396
|
+
const scopedFrames = Object.entries(changeSets).flatMap(([fileKey, scoped]) => scoped.nodes.map((nodeId) => ({ fileKey, nodeId, state: "default" })));
|
|
397
|
+
const rest = figma.filter((file) => !changeSets[file.fileKey]);
|
|
398
|
+
const frames = [...scopedFrames, ...boundaryFrames(rest, rest.some((file) => file.componentSetKeys?.length) ? await catalog() : [])];
|
|
359
399
|
const findings = [];
|
|
360
400
|
const versions = new Set();
|
|
361
401
|
for (const frame of frames) {
|
|
@@ -378,6 +418,7 @@ export async function figmaFindings(figma, { catalog, check }) {
|
|
|
378
418
|
frames: frames.map((frame) => ({ fileKey: frame.fileKey, nodeId: frame.nodeId, state: frame.state, frameUrl: frame.nodeId ? frameUrl(frame.fileKey, frame.nodeId) : `https://www.figma.com/design/${frame.fileKey}` })),
|
|
379
419
|
libraryVersions: [...versions],
|
|
380
420
|
frameComparison: "not_built",
|
|
421
|
+
...(scopedFrames.length ? { changeSets: Object.entries(changeSets).map(([fileKey, scoped]) => ({ fileKey, ids: scoped.changeSets, nodes: scoped.nodes.length })), rule: "MW2-38.3" } : {}),
|
|
381
422
|
},
|
|
382
423
|
};
|
|
383
424
|
}
|
|
@@ -480,10 +521,20 @@ export async function runLaneCheck(ref, flags, { request, lane, freeze, current,
|
|
|
480
521
|
} else {
|
|
481
522
|
const boundary = freeze.boundaries.figma;
|
|
482
523
|
try {
|
|
524
|
+
let changeSets;
|
|
525
|
+
try { changeSets = await laneChangeSetNodes(request, lane.agentId, boundary.map((file) => file.fileKey)); }
|
|
526
|
+
catch (error) {
|
|
527
|
+
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`);
|
|
528
|
+
}
|
|
483
529
|
let checked;
|
|
484
|
-
try { checked = await figmaFindings(boundary, { catalog, check: designCheck }); }
|
|
530
|
+
try { checked = await figmaFindings(boundary, { catalog, check: designCheck, changeSets }); }
|
|
485
531
|
catch (error) {
|
|
486
532
|
if (error instanceof ReviewerError) throw error;
|
|
533
|
+
// A Figma outage (a read past its clock, no answer, rate limited) means
|
|
534
|
+
// the check did not run: recorded as not run with the reason, never as
|
|
535
|
+
// a failure, so an outage never blocks a push.
|
|
536
|
+
if (FIGMA_OUTAGE.includes(error?.code))
|
|
537
|
+
throw new ReviewerError(UNAVAILABLE, `not run: Figma did not answer the design check (${error.code}: ${error?.message ?? error}); nothing was checked, so rerun nodii-dev lane check once Figma answers`);
|
|
487
538
|
throw new ReviewerError(["FIGMA_TOKEN_REQUIRED", "DS_CATALOG_UNAVAILABLE"].includes(error?.code) ? UNAVAILABLE : "CRASH", `design check failed (${error?.code ?? "ERROR"}: ${error?.message ?? error})`);
|
|
488
539
|
}
|
|
489
540
|
figma = round("figma", checked.findings, checked.inputs);
|