@nodii/dev 0.6.67 → 0.6.68

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/figma.js CHANGED
@@ -663,9 +663,49 @@ export function isChangeSetId(value) {
663
663
  return true;
664
664
  }
665
665
 
666
- export async function figmaPublishPlan(value, { request = devRequest } = {}) {
666
+ // The plan reads the design file for minutes on a large library, so Dev works it
667
+ // out as a job (DESIGN-SYSTEM-PARITY-153): the POST answers 202, here it's polled
668
+ // until it ends. Dev's job stops itself after an hour; stop a little later.
669
+ const PLAN_JOB_WAIT_MS = 65 * 60_000;
670
+ const planJobPath = (key, id) => `/api/v1/design/files/${encode(key)}/publish-plan/jobs/${encode(id)}`;
671
+
672
+ /** A finished plan job as the plan itself: the plan, or the refusal Dev ended it with. */
673
+ export function planJobOutcome(job) {
674
+ if (job.state === "succeeded") return { data: job.result };
675
+ const e = job.error ?? {};
676
+ if (e.code === "PUBLISH_PLAN_JOB_LOST") throw new CliError(e.code, `${e.message ?? "Dev lost this job"} (job ${job.id} on ${job.fileKey}). Run the same command again.`, 1, e.details);
677
+ throw new CliError(!e.code || GATEWAY.has(e.code) ? "PUBLISH_PLAN_JOB_FAILED" : e.code, e.message ?? `Dev's publish plan job ${job.id} failed with HTTP ${job.httpStatus}`, 1, e.details);
678
+ }
679
+
680
+ /** Starts or joins the file's plan job (startDesignPublishPlan) and polls it until it ends, printing progress. */
681
+ export async function figmaPublishPlan(value, { request = devRequest, sleep = delay, progress = stderrLine, now = Date.now } = {}) {
667
682
  const key = figmaFileKey(value);
668
- return fileCall(key, request)("GET", `/api/v1/design/files/${encode(key)}/publish-plan`);
683
+ const call = fileCall(key, request);
684
+ let job = (await call("POST", `/api/v1/design/files/${encode(key)}/publish-plan`, {})).data;
685
+ const start = now();
686
+ let printed = start;
687
+ let misses = 0;
688
+ for (let n = 0; !DONE.has(job.state); n++) {
689
+ if (now() - start > PLAN_JOB_WAIT_MS)
690
+ throw new CliError("PUBLISH_PLAN_JOB_TIMEOUT", `Dev's publish plan job ${job.id} on ${key} is still running after ${Math.round(PLAN_JOB_WAIT_MS / 60_000)} minutes. Run the same command again to join it.`, 1);
691
+ await sleep(JOB_POLL_MS[Math.min(n, JOB_POLL_MS.length - 1)]);
692
+ try {
693
+ job = (await call("GET", planJobPath(key, job.id))).data;
694
+ misses = 0;
695
+ } catch (error) {
696
+ if (!TRANSIENT.has(error?.code)) throw error;
697
+ // A poll that hit the edge's gateway or a blip retries; the job runs on in Dev.
698
+ if (++misses > 5) throw new CliError("PUBLISH_PLAN_JOB_UNREACHABLE", `Lost touch with Dev (${error.code}) while its publish plan job ${job.id} on ${key} runs. Run the same command again to join it.`, 1);
699
+ progress(`polling ${job.id} again (${error.code})`);
700
+ continue;
701
+ }
702
+ if (!DONE.has(job.state) && now() - printed >= JOB_PROGRESS_MS) {
703
+ printed = now();
704
+ const done = job.progress ? `, ${job.progress.compared} of ${job.progress.total} components compared` : "";
705
+ progress(`${key}: publish plan job ${job.id} still running (${Math.round((printed - start) / 1000)} s${done})`);
706
+ }
707
+ }
708
+ return planJobOutcome(job);
669
709
  }
670
710
 
671
711
  const planLine = (x) => ` ${x.nodeId ?? (x.kind ? scopeText(x) : "(no node)")} ${x.name ?? ""} (${x.changeSetId} ${x.state}${x.title ? `: ${x.title}` : ""})`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodii/dev",
3
- "version": "0.6.67",
3
+ "version": "0.6.68",
4
4
  "description": "Agent CLI for Nodii Dev, reached through the platform edge",
5
5
  "type": "module",
6
6
  "bin": {