@nodii/dev 0.6.116 → 0.6.117
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/cli.js +6 -3
- package/dist/core.js +1 -1
- package/dist/design.js +48 -4
- package/dist/figma.js +132 -4
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -212,6 +212,9 @@ Usage: nodii-dev <command> [options] [--json]
|
|
|
212
212
|
# submit gate on the same body, as design check --change-set; never writes
|
|
213
213
|
# --lane-reads (submit, resubmit, --dry-run): Dev runs no job and answers on
|
|
214
214
|
# the request from your MCP and REST reads; it names any read it still needs
|
|
215
|
+
# reads over 8 MB go up to the set in chunks first (hub-310), and a chunk
|
|
216
|
+
# that drops is sent again; the dry run of a submit past 300 node ids
|
|
217
|
+
# runs in parts and reports once
|
|
215
218
|
# SUBMIT.json: { figmaVersion, writeUp, items: [{ figmaNodeId, change, context,
|
|
216
219
|
# variants: [{ nodeId, name, context, afterPngBase64 }] }] } (DEC-0204);
|
|
217
220
|
# a missing writeUp, context or variant name, or an item with no variants,
|
|
@@ -1344,10 +1347,10 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
1344
1347
|
return emit(await figmaFilePublished(rest[0], await publishedBody(f)).catch((error) => { throw laneReadsRefusal(error); }), json, (p) => figmaFilePublishedText(p.data));
|
|
1345
1348
|
// --dry-run runs Dev's dry run of the submit gate (design check --change-set)
|
|
1346
1349
|
// on the same body, and never writes (CLI-18).
|
|
1347
|
-
const dryRun = async (id, text, file) => {
|
|
1350
|
+
const dryRun = async (id, text, file, { split = false } = {}) => {
|
|
1348
1351
|
const laneReads = f["lane-reads"] ? await readLaneReads(f["lane-reads"]) : undefined;
|
|
1349
1352
|
const result = await designCheckChangeSet(undefined, { "change-set": id, ...(text ? { file } : {}), ...(f["figma-version"] ? { "figma-version": f["figma-version"] } : {}), ...(f.sync ? { sync: true } : {}), ...(f.async ? { async: true } : {}) },
|
|
1350
|
-
{ read: async () => text, ...(laneReads ? { laneReads } : {}) }).catch((error) => { throw laneReadsRefusal(error); });
|
|
1353
|
+
{ read: async () => text, split, ...(laneReads ? { laneReads } : {}) }).catch((error) => { throw laneReadsRefusal(error); });
|
|
1351
1354
|
emit(result.payload, json, result.human);
|
|
1352
1355
|
if (result.exitCode) {
|
|
1353
1356
|
if (!json) console.error(`DS_CONFORMANCE_FAILED: ${result.payload.data.findings.length} finding(s)`);
|
|
@@ -1359,7 +1362,7 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
1359
1362
|
// The same body checks as the real submit, which needs --file.
|
|
1360
1363
|
const text = f.file ? await readFile(f.file, "utf8") : null;
|
|
1361
1364
|
checkSubmitPayload(text ? JSON.parse(text) : { figmaVersion: f["figma-version"] }, f.file || "the submit (no --file)");
|
|
1362
|
-
return dryRun(rest[0], text, f.file);
|
|
1365
|
+
return dryRun(rest[0], text, f.file, { split: true });
|
|
1363
1366
|
}
|
|
1364
1367
|
if (action === "resubmit" && f["dry-run"]) {
|
|
1365
1368
|
if (!rest[0] || !rest[1]) throw new CliError("USAGE", "figma resubmit CHANGE_SET PAYLOAD.json --dry-run", 2);
|
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.117";
|
|
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
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// library main.
|
|
9
9
|
import { readFile } from "node:fs/promises";
|
|
10
10
|
import { CliError, devRequest } from "./core.js";
|
|
11
|
-
import { conformanceLines, figmaConformance, figmaFileKey, submitMode, surfacesCheck } from "./figma.js";
|
|
11
|
+
import { conformanceLines, figmaConformance, figmaFileKey, laneReadsBody, submitMode, surfacesCheck } from "./figma.js";
|
|
12
12
|
import { checkConformance, neededMains, VERSION as CHECK_VERSION } from "./vendor/ds-conformance.mjs";
|
|
13
13
|
|
|
14
14
|
const FIGMA_API = "https://api.figma.com/v1";
|
|
@@ -439,13 +439,48 @@ export function designCheckText({ data }) {
|
|
|
439
439
|
return [...lines, ...conformanceLines(data)].join("\n");
|
|
440
440
|
}
|
|
441
441
|
|
|
442
|
+
// Dev's dry run checks at most this many node ids (an item and each of its
|
|
443
|
+
// variants count one each), refused CONFORMANCE_TOO_MANY_NODES past it.
|
|
444
|
+
export const DRY_RUN_MAX_NODES = 300;
|
|
445
|
+
const itemNodes = (item) => 1 + (item.variants?.length ?? 0);
|
|
446
|
+
/** A submit body's items in runs of at most `max` node ids; an item larger than that runs alone. */
|
|
447
|
+
export function dryRunGroups(items, max = DRY_RUN_MAX_NODES) {
|
|
448
|
+
const groups = [];
|
|
449
|
+
let group = [];
|
|
450
|
+
let nodes = 0;
|
|
451
|
+
for (const item of items) {
|
|
452
|
+
if (group.length > 0 && nodes + itemNodes(item) > max) {
|
|
453
|
+
groups.push(group);
|
|
454
|
+
group = [];
|
|
455
|
+
nodes = 0;
|
|
456
|
+
}
|
|
457
|
+
group.push(item);
|
|
458
|
+
nodes += itemNodes(item);
|
|
459
|
+
}
|
|
460
|
+
if (group.length > 0) groups.push(group);
|
|
461
|
+
return groups;
|
|
462
|
+
}
|
|
463
|
+
// The dry runs of a split body, as one report: it passes when every run passed.
|
|
464
|
+
function mergedReports(reports) {
|
|
465
|
+
const all = (key) => reports.flatMap((r) => r[key] ?? []);
|
|
466
|
+
const sum = (key) => reports.reduce((n, r) => n + (r.checked?.[key] ?? 0), 0);
|
|
467
|
+
return {
|
|
468
|
+
version: reports[0]?.version,
|
|
469
|
+
passed: reports.every((r) => Boolean(r.passed)),
|
|
470
|
+
checked: { roots: sum("roots"), mains: sum("mains"), images: sum("images"), libraryVersion: reports.find((r) => r.checked?.libraryVersion)?.checked.libraryVersion ?? null },
|
|
471
|
+
findings: all("findings"), staleOverrides: all("staleOverrides"), libraryUpdatePending: all("libraryUpdatePending"),
|
|
472
|
+
outOfScope: all("outOfScope"), outOfScopeNodes: reports.reduce((n, r) => n + (r.outOfScopeNodes ?? 0), 0), warnings: all("warnings"),
|
|
473
|
+
staleVersion: reports.find((r) => r.staleVersion)?.staleVersion ?? null,
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
|
|
442
477
|
/**
|
|
443
478
|
* `design check --change-set CS-1 [--file SUBMIT.json] [--figma-version V]`: Dev's own dry run of
|
|
444
479
|
* the submit gate on a change set (checkDesignConformance): the same checks
|
|
445
480
|
* plus the submit-time guards against the set's items: IMAGE_NOT_TRUECOLOR
|
|
446
481
|
* refuses; STALE_FIGMA_VERSION is a warning. Changes no state.
|
|
447
482
|
*/
|
|
448
|
-
export async function designCheckChangeSet(target, flags, { request = devRequest, send, progress, read = (f) => readFile(f, "utf8"), laneReads } = {}) {
|
|
483
|
+
export async function designCheckChangeSet(target, flags, { request = devRequest, send, progress, read = (f) => readFile(f, "utf8"), laneReads, split = false } = {}) {
|
|
449
484
|
const id = flags["change-set"];
|
|
450
485
|
// On the lane's reads Dev answers on the request, with no job (hub-295).
|
|
451
486
|
const sync = laneReads ? true : submitMode(flags);
|
|
@@ -465,10 +500,19 @@ export async function designCheckChangeSet(target, flags, { request = devRequest
|
|
|
465
500
|
if (!body || typeof body !== "object" || Array.isArray(body)) throw new CliError("USAGE", `${flags.file}: expected the submit body, a JSON object`, 2);
|
|
466
501
|
}
|
|
467
502
|
if (flags["figma-version"]) body = { ...body, figmaVersion: String(flags["figma-version"]) };
|
|
468
|
-
|
|
503
|
+
// hub-310: large reads go up once, in chunks, and every run names them.
|
|
504
|
+
if (laneReads) body = { ...body, ...(await laneReadsBody(id, laneReads, { request, ...(progress ? { progress } : {}) })) };
|
|
505
|
+
// A submit body past the dry run's node limit runs in parts, each under it;
|
|
506
|
+
// a re-submit's can't be split, since it must name every rejected item.
|
|
507
|
+
const groups = split && Array.isArray(body.items) ? dryRunGroups(body.items) : [];
|
|
469
508
|
let p;
|
|
470
509
|
try {
|
|
471
|
-
|
|
510
|
+
const run = (b) => figmaConformance(id, b, { request, sync, ...(send ? { send } : {}), ...(progress ? { progress } : {}) });
|
|
511
|
+
if (groups.length > 1) {
|
|
512
|
+
const reports = [];
|
|
513
|
+
for (const items of groups) reports.push((await run({ ...body, items })).data ?? {});
|
|
514
|
+
p = { data: mergedReports(reports) };
|
|
515
|
+
} else p = await run(body);
|
|
472
516
|
} catch (error) {
|
|
473
517
|
// A cold run reads every root and main from Figma and can outlast the
|
|
474
518
|
// edge's gateway (504, an HTML page). Dev keeps the mains it read for 5
|
package/dist/figma.js
CHANGED
|
@@ -369,7 +369,8 @@ export async function figmaResubmit(id, file, { request = devRequest, read = (f)
|
|
|
369
369
|
const body = assertContext(resubmitPayload(text, file), { resubmit: true, file });
|
|
370
370
|
try {
|
|
371
371
|
// On the lane's reads Dev answers on the request, with no job (hub-295).
|
|
372
|
-
|
|
372
|
+
const reads = await laneReadsBody(id, laneReads, { request, ...(options.progress ? { progress: options.progress } : {}) });
|
|
373
|
+
return await submitCall(id, "resubmit", { ...body, ...reads }, { request, ...options, ...(laneReads ? { sync: true } : {}) });
|
|
373
374
|
} catch (error) {
|
|
374
375
|
if (error?.code === "FIGMA_READS_NEEDED") throw laneReadsRefusal(error);
|
|
375
376
|
const say = RESUBMIT_REFUSALS[error?.code];
|
|
@@ -748,12 +749,13 @@ export function checkSubmitPayload(payload, file = "the submit body") {
|
|
|
748
749
|
return assertContext(payload, { file });
|
|
749
750
|
}
|
|
750
751
|
|
|
751
|
-
export async function figmaSubmit(id, payload, { request = devRequest, file = "the submit body", laneReads, ...options } = {}) {
|
|
752
|
+
export async function figmaSubmit(id, payload, { request = devRequest, file = "the submit body", laneReads, progress, ...options } = {}) {
|
|
752
753
|
checkSubmitPayload(payload, file);
|
|
753
754
|
// On the lane's reads Dev answers on the request, with no job (hub-295).
|
|
754
755
|
const sync = laneReads ? { sync: true } : {};
|
|
755
|
-
|
|
756
|
-
|
|
756
|
+
const reads = await laneReadsBody(id, laneReads, { request, ...(progress ? { progress } : {}) });
|
|
757
|
+
return changeSetCall(id, (method, path, body) => submitCall(id, "submit", body, { request, ...options, ...(progress ? { progress } : {}), ...sync }))(
|
|
758
|
+
"POST", `/api/v1/design/change-sets/${encode(id)}/submit`, { ...payload, ...reads }).catch((error) => {
|
|
757
759
|
throw laneReadsRefusal(error);
|
|
758
760
|
});
|
|
759
761
|
}
|
|
@@ -1027,6 +1029,132 @@ export const figmaWithdrawItemsText = (id, d = {}) => {
|
|
|
1027
1029
|
].join("\n");
|
|
1028
1030
|
};
|
|
1029
1031
|
|
|
1032
|
+
// hub-310 (hub-ee's design of 7 Nov): reads larger than this go up to
|
|
1033
|
+
// Dev in chunks of about this size, by id, so no submit body passes Dev's 32 MB
|
|
1034
|
+
// cap. Smaller reads still go inline. One read bigger than this goes up in
|
|
1035
|
+
// parts (laneReadsParts).
|
|
1036
|
+
export const LANE_READS_CHUNK_BYTES = 8 * 1024 * 1024;
|
|
1037
|
+
const jsonBytes = (value) => Buffer.byteLength(JSON.stringify(value));
|
|
1038
|
+
// The lists that hold the bulk of a lane's reads; everything else rides in the
|
|
1039
|
+
// first chunk.
|
|
1040
|
+
const CHUNKED_LISTS = ["nodes", "documents", "rest"];
|
|
1041
|
+
|
|
1042
|
+
/**
|
|
1043
|
+
* The lane's reads as chunks of about `limit` bytes each, every one at the
|
|
1044
|
+
* reads' Figma version. The first carries the small parts (pages, gone, base,
|
|
1045
|
+
* publish, restReads); nodes, documents and REST answers are split entry by
|
|
1046
|
+
* entry. One entry larger than `limit` goes alone, in a chunk of just that
|
|
1047
|
+
* entry at the reads' version, which goes up in parts. Dev puts them back together.
|
|
1048
|
+
*/
|
|
1049
|
+
export function laneReadsChunks(reads, limit = LANE_READS_CHUNK_BYTES) {
|
|
1050
|
+
const { figmaVersion } = reads;
|
|
1051
|
+
const small = Object.fromEntries(Object.entries(reads).filter(([key]) => !CHUNKED_LISTS.includes(key)));
|
|
1052
|
+
const chunks = [];
|
|
1053
|
+
const alone = [];
|
|
1054
|
+
let chunk = { ...small, nodes: [] };
|
|
1055
|
+
let used = jsonBytes(chunk);
|
|
1056
|
+
let entries = 0;
|
|
1057
|
+
for (const list of CHUNKED_LISTS)
|
|
1058
|
+
for (const entry of reads[list] ?? []) {
|
|
1059
|
+
const bytes = jsonBytes(entry) + 1;
|
|
1060
|
+
// One entry bigger than a chunk goes in a chunk of its own, the same
|
|
1061
|
+
// bytes whatever else the reads hold: Dev then has it by its hash after
|
|
1062
|
+
// the first upload, and a later request sends it no more (hub-ee, 8 Nov:
|
|
1063
|
+
// the same library main once per set).
|
|
1064
|
+
if (bytes > limit) {
|
|
1065
|
+
alone.push({ figmaVersion, nodes: [], [list]: [entry] });
|
|
1066
|
+
continue;
|
|
1067
|
+
}
|
|
1068
|
+
if (entries > 0 && used + bytes > limit) {
|
|
1069
|
+
chunks.push(chunk);
|
|
1070
|
+
chunk = { figmaVersion, nodes: [] };
|
|
1071
|
+
used = jsonBytes(chunk);
|
|
1072
|
+
entries = 0;
|
|
1073
|
+
}
|
|
1074
|
+
(chunk[list] ??= []).push(entry);
|
|
1075
|
+
used += bytes;
|
|
1076
|
+
entries += 1;
|
|
1077
|
+
}
|
|
1078
|
+
chunks.push(chunk);
|
|
1079
|
+
return [...chunks, ...alone];
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
// One part of a chunk that one read makes bigger than a chunk: about this many
|
|
1083
|
+
// of the chunk's bytes, base64 encoded, under Dev's 16 MB request cap.
|
|
1084
|
+
export const LANE_READS_PART_BYTES = 6 * 1024 * 1024;
|
|
1085
|
+
|
|
1086
|
+
/**
|
|
1087
|
+
* A chunk's JSON split by bytes into parts, each with the whole chunk's hash,
|
|
1088
|
+
* its index and the count, as POST /design/change-sets/:id/reads/parts takes
|
|
1089
|
+
* them (hub-310, hub-ee 8 Nov: the App Frame main alone is a 34.3 MB read).
|
|
1090
|
+
*/
|
|
1091
|
+
export function laneReadsParts(chunk, size = LANE_READS_PART_BYTES) {
|
|
1092
|
+
const bytes = Buffer.from(JSON.stringify(chunk));
|
|
1093
|
+
const sha256 = createHash("sha256").update(bytes).digest("hex");
|
|
1094
|
+
const count = Math.max(1, Math.ceil(bytes.length / size));
|
|
1095
|
+
return Array.from({ length: count }, (_, index) => ({
|
|
1096
|
+
sha256, index, count, data: bytes.subarray(index * size, (index + 1) * size).toString("base64"),
|
|
1097
|
+
}));
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
/**
|
|
1101
|
+
* What a submit, re-submit or dry run sends for the lane's reads: inline when
|
|
1102
|
+
* they fit in one chunk, else uploaded chunk by chunk to the set and named by
|
|
1103
|
+
* `readIds`. A chunk that one read makes bigger than a chunk goes up in parts,
|
|
1104
|
+
* by bytes, and Dev puts it back together. Dev keeps a chunk by its content,
|
|
1105
|
+
* and a part by the chunk's hash and its index, so one sent again is the same
|
|
1106
|
+
* one: an upload that hits a gateway timeout or a dropped connection is sent
|
|
1107
|
+
* again, and a rerun after a failure sends only what it must.
|
|
1108
|
+
*/
|
|
1109
|
+
export async function laneReadsBody(id, laneReads, { request = devRequest, progress = stderrLine, limit = LANE_READS_CHUNK_BYTES, partBytes = LANE_READS_PART_BYTES, wait = delay, attempts = 4 } = {}) {
|
|
1110
|
+
if (!laneReads) return {};
|
|
1111
|
+
if (jsonBytes(laneReads) <= limit) return { laneReads };
|
|
1112
|
+
const chunks = laneReadsChunks(laneReads, limit);
|
|
1113
|
+
const path = `/api/v1/design/change-sets/${encode(id)}/reads`;
|
|
1114
|
+
const send = async (at, body) => {
|
|
1115
|
+
for (let attempt = 1; ; attempt += 1) {
|
|
1116
|
+
try {
|
|
1117
|
+
return await request("POST", at, body);
|
|
1118
|
+
} catch (error) {
|
|
1119
|
+
if (!TRANSIENT.has(error?.code) || attempt >= attempts) throw laneReadsUploadRefusal(error, id);
|
|
1120
|
+
await wait(attempt * 2_000);
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
};
|
|
1124
|
+
// The parts in order; Dev answers the chunk on the last one, or names the
|
|
1125
|
+
// parts it still needs, which go again. A chunk Dev already has from these
|
|
1126
|
+
// parts is answered on the first, and the rest aren't sent.
|
|
1127
|
+
const sendParts = async (chunk) => {
|
|
1128
|
+
const parts = laneReadsParts(chunk, partBytes);
|
|
1129
|
+
let todo = parts.map((_, i) => i);
|
|
1130
|
+
for (let round = 1; ; round += 1) {
|
|
1131
|
+
let answer;
|
|
1132
|
+
for (const i of todo) {
|
|
1133
|
+
answer = (await send(`${path}/parts`, parts[i])).data;
|
|
1134
|
+
if (answer?.chunk) return answer.chunk.id;
|
|
1135
|
+
}
|
|
1136
|
+
if (!answer?.missing?.length || round >= attempts)
|
|
1137
|
+
throw new CliError("LANE_READS_UPLOAD_INCOMPLETE", `Dev didn't put the ${parts.length} parts of one lane-reads chunk together for ${id}; run the command again (sent parts are kept).`, 1, answer);
|
|
1138
|
+
todo = answer.missing;
|
|
1139
|
+
}
|
|
1140
|
+
};
|
|
1141
|
+
const readIds = [];
|
|
1142
|
+
for (const [index, chunk] of chunks.entries()) {
|
|
1143
|
+
readIds.push(jsonBytes(chunk) > limit ? await sendParts(chunk) : (await send(path, chunk)).data.id);
|
|
1144
|
+
progress(`lane reads: ${index + 1} of ${chunks.length} chunks uploaded to ${id}`);
|
|
1145
|
+
}
|
|
1146
|
+
return { readIds };
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
function laneReadsUploadRefusal(error, id) {
|
|
1150
|
+
if (error?.code === "LANE_READS_TOO_LARGE")
|
|
1151
|
+
return new CliError(error.code, `${error.message}
|
|
1152
|
+
The lane-reads chunk is larger than Dev takes, even in parts; tell the Steward (hub-310).`, error.exitCode ?? 1, error.details);
|
|
1153
|
+
if (["HTTP_404", "NOT_FOUND", "ROUTE_NOT_FOUND"].includes(error?.code))
|
|
1154
|
+
return new CliError(error.code, `Dev doesn't take lane reads in chunks yet (POST /design/change-sets/${id}/reads): this nodii-dev needs Dev with the lane-reads upload (hub-310) deployed.`, error.exitCode ?? 1, error.details);
|
|
1155
|
+
return error;
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1030
1158
|
// MW1-57.11: the lane reads Figma through the MCP in its own session, and sends
|
|
1031
1159
|
// what it read. Dev runs the same gates on that, with no job and no Figma call.
|
|
1032
1160
|
export async function readLaneReads(path, { read = readFile } = {}) {
|