@nodii/dev 0.6.212 → 0.6.213

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 CHANGED
@@ -1794,10 +1794,10 @@ export async function main(argv = process.argv.slice(2)) {
1794
1794
  return emit(await figmaFilePublished(rest[0], await publishedBody(f)).catch((error) => { throw laneReadsRefusal(error); }), json, (p) => figmaFilePublishedText(p.data));
1795
1795
  // --dry-run runs Dev's dry run of the submit gate (design check --change-set)
1796
1796
  // on the same body, and never writes (CLI-18).
1797
- const dryRun = async (id, text, file, { split = false } = {}) => {
1797
+ const dryRun = async (id, text, file, { split = false, command } = {}) => {
1798
1798
  const laneReads = f["lane-reads"] ? await readLaneReads(f["lane-reads"]) : undefined;
1799
1799
  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 } : {}) },
1800
- { read: async () => text, split, ...(laneReads ? { laneReads } : {}), ...(f["code-pr"] !== undefined ? { codePr: f["code-pr"] } : {}) }).catch((error) => { throw laneReadsRefusal(error); });
1800
+ { read: async () => text, split, command, ...(laneReads ? { laneReads } : {}), ...(f["code-pr"] !== undefined ? { codePr: f["code-pr"] } : {}) }).catch((error) => { throw laneReadsRefusal(error); });
1801
1801
  emit(result.payload, json, result.human);
1802
1802
  if (result.exitCode) {
1803
1803
  if (!json) console.error(`DS_CONFORMANCE_FAILED: ${result.payload.data.findings.length} finding(s)`);
@@ -1809,13 +1809,13 @@ export async function main(argv = process.argv.slice(2)) {
1809
1809
  // The same body checks as the real submit, which needs --file.
1810
1810
  const text = f.file ? await readFile(f.file, "utf8") : null;
1811
1811
  checkSubmitPayload(text ? JSON.parse(text) : { figmaVersion: f["figma-version"] }, f.file || "the submit (no --file)");
1812
- return dryRun(rest[0], text, f.file, { split: true });
1812
+ return dryRun(rest[0], text, f.file, { split: true, command: "submit" });
1813
1813
  }
1814
1814
  if (action === "resubmit" && f["dry-run"]) {
1815
1815
  if (!rest[0] || !rest[1]) throw new CliError("USAGE", "figma resubmit CHANGE_SET PAYLOAD.json --dry-run", 2);
1816
1816
  const text = await readFile(rest[1], "utf8");
1817
1817
  assertContext(resubmitPayload(text, rest[1]), { resubmit: true, file: rest[1] });
1818
- return dryRun(rest[0], text, rest[1]);
1818
+ return dryRun(rest[0], text, rest[1], { command: "resubmit" });
1819
1819
  }
1820
1820
  if (action === "submit") {
1821
1821
  const payload = f.file ? JSON.parse(await readFile(f.file, "utf8")) : { figmaVersion: requireFlag(f, "figma-version") };
package/dist/core.js CHANGED
@@ -4,7 +4,7 @@ import { chmod, lstat, mkdir, readFile, rename, rm, writeFile } from "node:fs/pr
4
4
  import { homedir, platform } from "node:os";
5
5
  import { basename, dirname, join } from "node:path";
6
6
 
7
- export const VERSION = "0.6.212";
7
+ export const VERSION = "0.6.213";
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
@@ -149,6 +149,20 @@ const PUBLISH_LABEL = "Components published";
149
149
  const VERSION_PAGES = 5;
150
150
  const KEY_LOOKUPS_AT_ONCE = 3;
151
151
 
152
+ async function versionHistoryReads(figmaGet, path) {
153
+ const reads = [];
154
+ let at = `/${path}?page_size=100`;
155
+ for (let page = 0; page < VERSION_PAGES && at; page++) {
156
+ const body = await figmaGet(at);
157
+ reads.push({ path: at.slice(1), body });
158
+ const older = body?.pagination?.prev_page;
159
+ if (typeof older !== "string" || !older.startsWith(`${FIGMA_API}/${path}`)) break;
160
+ const next = new URL(older);
161
+ at = next.origin === new URL(FIGMA_API).origin && next.pathname === `/v1/${path}` ? `${next.pathname.slice(3)}${next.search}` : null;
162
+ }
163
+ return reads;
164
+ }
165
+
152
166
  /**
153
167
  * A library's newest "Components published" version (DEC-0047): what a
154
168
  * consuming file can have. Null when none is in its recent history; its
@@ -468,7 +482,7 @@ function mergedReports(reports) {
468
482
  * plus the submit-time guards against the set's items: IMAGE_NOT_TRUECOLOR
469
483
  * refuses; STALE_FIGMA_VERSION is a warning. Changes no state.
470
484
  */
471
- export async function designCheckChangeSet(target, flags, { request = devRequest, send, progress, read = (f) => readFile(f, "utf8"), laneReads, split = false, codePr } = {}) {
485
+ export async function designCheckChangeSet(target, flags, { request = devRequest, send, progress, read = (f) => readFile(f, "utf8"), laneReads, split = false, codePr, command, env = process.env, figmaGet, laneReadsLimit } = {}) {
472
486
  const id = flags["change-set"];
473
487
  // On the lane's reads too Dev runs the dry run as a job (hub-448); --sync sends the plain call.
474
488
  const sync = submitMode(flags);
@@ -488,22 +502,44 @@ export async function designCheckChangeSet(target, flags, { request = devRequest
488
502
  if (!body || typeof body !== "object" || Array.isArray(body)) throw new CliError("USAGE", `${flags.file}: expected the submit body, a JSON object`, 2);
489
503
  }
490
504
  if (flags["figma-version"]) body = { ...body, figmaVersion: String(flags["figma-version"]) };
505
+ if (command) body = { ...body, command };
491
506
  // hub-558: images go up one by one and the body names them; --code-pr rides in the body.
492
507
  body = withCodePr(body, codePr, { ...(progress ? { progress } : {}) });
493
508
  body = await uploadSubmitImages(id, body, { request, ...(progress ? { progress } : {}) });
494
- // hub-310: large reads go up once, in chunks, and every run names them.
495
- if (laneReads) body = { ...body, ...(await laneReadsBody(id, laneReads, { request, ...(progress ? { progress } : {}) })) };
496
- // A submit body past the dry run's node limit runs in parts, each under it;
497
- // a re-submit's can't be split, since it must name every rejected item.
498
- const groups = split && Array.isArray(body.items) ? dryRunGroups(body.items) : [];
509
+ // Upload a large read corpus once. A versions negotiation below keeps its
510
+ // readIds and adds only one small inline REST supplement.
511
+ const storedReads = laneReads
512
+ ? await laneReadsBody(id, laneReads, { request, ...(progress ? { progress } : {}), ...(laneReadsLimit ? { limit: laneReadsLimit } : {}) })
513
+ : {};
514
+ let versionReads = [];
515
+ const withReads = () => {
516
+ if (!versionReads.length) return { ...body, ...storedReads };
517
+ if (storedReads.laneReads)
518
+ return { ...body, laneReads: { ...storedReads.laneReads, rest: [...(storedReads.laneReads.rest ?? []).filter((entry) => !versionReads.some((read) => read.path === entry.path)), ...versionReads] } };
519
+ return { ...body, ...storedReads, laneReads: { figmaVersion: laneReads.figmaVersion, nodes: [], rest: versionReads } };
520
+ };
499
521
  let p;
500
522
  try {
501
- const run = (b) => figmaConformance(id, b, { request, sync, ...(send ? { send } : {}), ...(progress ? { progress } : {}) });
502
- if (groups.length > 1) {
523
+ const run = (sent) => figmaConformance(id, sent, { request, sync, ...(send ? { send } : {}), ...(progress ? { progress } : {}) });
524
+ const runAll = async () => {
525
+ const sent = withReads();
526
+ // A submit body past the dry run's node limit runs in parts, each under it;
527
+ // a re-submit's can't be split, since it must name every rejected item.
528
+ const groups = split && Array.isArray(sent.items) ? dryRunGroups(sent.items) : [];
529
+ if (groups.length <= 1) return run(sent);
503
530
  const reports = [];
504
- for (const items of groups) reports.push((await run({ ...body, items })).data ?? {});
505
- p = { data: mergedReports(reports) };
506
- } else p = await run(body);
531
+ for (const items of groups) reports.push((await run({ ...sent, items })).data ?? {});
532
+ return { data: mergedReports(reports) };
533
+ };
534
+ try {
535
+ p = await runAll();
536
+ } catch (error) {
537
+ const path = String(error?.details?.path ?? "").replace(/^\/+/, "");
538
+ if (!laneReads || error?.code !== "FIGMA_READS_NEEDED" || !/^files\/[^/]+\/versions$/.test(path)) throw error;
539
+ const get = figmaGet ?? figmaClient(figmaToken(env));
540
+ versionReads = await versionHistoryReads(get, path);
541
+ p = await runAll();
542
+ }
507
543
  } catch (error) {
508
544
  // A cold run reads every root and main from Figma and can outlast the
509
545
  // edge's gateway (504, an HTML page). Dev keeps the mains it read for 5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodii/dev",
3
- "version": "0.6.212",
3
+ "version": "0.6.213",
4
4
  "description": "Agent CLI for Nodii Dev, reached through the platform edge",
5
5
  "type": "module",
6
6
  "bin": {