figma-lupa 0.2.0 → 0.2.1

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/server.js CHANGED
@@ -42436,7 +42436,7 @@ var import_websocket_server = __toESM(require_websocket_server(), 1);
42436
42436
  // package.json
42437
42437
  var package_default = {
42438
42438
  name: "figma-lupa",
42439
- version: "0.2.0",
42439
+ version: "0.2.1",
42440
42440
  description: "Read-only Figma CLI, MCP server and plugin for pixel-faithful design-to-code with a small context footprint.",
42441
42441
  type: "module",
42442
42442
  license: "GPL-3.0-or-later",
@@ -42544,12 +42544,23 @@ var Bridge = class {
42544
42544
  waiters = /* @__PURE__ */ new Set();
42545
42545
  want;
42546
42546
  activeAt = Date.now();
42547
+ onStopRequest;
42548
+ version;
42549
+ /** Peer: the hub's version and whether it stops on request. */
42550
+ hubVersion;
42551
+ hubCanStop = false;
42547
42552
  constructor(opts = {}) {
42548
42553
  this.port = opts.port ?? Number(process.env.LUPA_PORT ?? DEFAULT_PORT);
42549
42554
  this.host = opts.host ?? "127.0.0.1";
42550
42555
  this.log = opts.log ?? (() => {
42551
42556
  });
42552
42557
  this.want = opts.role ?? "auto";
42558
+ this.onStopRequest = opts.onStopRequest;
42559
+ this.version = opts.version ?? SERVER_VERSION;
42560
+ }
42561
+ /** Peer: ask the hub to stop. Only `lupa serve` hubs (hubCanStop) do. */
42562
+ askHubToStop() {
42563
+ if (this.hubSocket?.readyState === import_websocket.default.OPEN) this.hubSocket.send(JSON.stringify({ t: "stop" }));
42553
42564
  }
42554
42565
  /** Milliseconds since this process last handled or forwarded a request. */
42555
42566
  get idleMs() {
@@ -42702,7 +42713,7 @@ var Bridge = class {
42702
42713
  ws.terminate();
42703
42714
  finish(false);
42704
42715
  }, 2e3);
42705
- ws.on("open", () => ws.send(JSON.stringify({ t: "hello", role: "peer", protocol: PROTOCOL_VERSION })));
42716
+ ws.on("open", () => ws.send(JSON.stringify({ t: "hello", role: "peer", protocol: PROTOCOL_VERSION, version: this.version })));
42706
42717
  ws.on("message", (data) => {
42707
42718
  let msg;
42708
42719
  try {
@@ -42712,6 +42723,8 @@ var Bridge = class {
42712
42723
  }
42713
42724
  if (msg.t === "welcome") {
42714
42725
  this.hubSocket = ws;
42726
+ this.hubVersion = msg.serverVersion;
42727
+ this.hubCanStop = msg.canStop === true;
42715
42728
  this.role = "peer";
42716
42729
  this.log("connected to hub as peer");
42717
42730
  finish(true);
@@ -42796,7 +42809,7 @@ var Bridge = class {
42796
42809
  } else {
42797
42810
  this.peers.add(ws);
42798
42811
  }
42799
- ws.send(JSON.stringify({ t: "welcome", role: msg.role, conn, serverVersion: SERVER_VERSION }));
42812
+ ws.send(JSON.stringify({ t: "welcome", role: msg.role, conn, serverVersion: this.version, canStop: !!this.onStopRequest }));
42800
42813
  if (msg.role === "peer") ws.send(JSON.stringify({ t: "plugins", plugins: this.list() }));
42801
42814
  return;
42802
42815
  }
@@ -42826,7 +42839,10 @@ var Bridge = class {
42826
42839
  }
42827
42840
  return;
42828
42841
  }
42829
- if (msg.t === "list") {
42842
+ if (msg.t === "stop") {
42843
+ this.log(this.onStopRequest ? "a newer Lupa asked this hub to stop" : "ignored a stop request (not a lupa serve hub)");
42844
+ this.onStopRequest?.();
42845
+ } else if (msg.t === "list") {
42830
42846
  ws.send(JSON.stringify({ t: "plugins", plugins: this.list() }));
42831
42847
  } else if (msg.t === "req") {
42832
42848
  let target;
@@ -44480,12 +44496,16 @@ function cachedChromiums() {
44480
44496
  }
44481
44497
  async function launch(chromium) {
44482
44498
  const attempts = [];
44483
- if (process.env.LUPA_BROWSER) attempts.push({ executablePath: process.env.LUPA_BROWSER });
44484
- attempts.push({}, ...cachedChromiums().map((p) => ({ executablePath: p })), { channel: "chrome" });
44499
+ if (process.env.LUPA_BROWSER) attempts.push({ executablePath: process.env.LUPA_BROWSER, label: `LUPA_BROWSER (${process.env.LUPA_BROWSER})` });
44500
+ attempts.push(
44501
+ { label: "Playwright's Chromium" },
44502
+ ...cachedChromiums().map((p) => ({ executablePath: p, label: `Playwright's Chromium (${p})` })),
44503
+ { channel: "chrome", label: "Google Chrome" }
44504
+ );
44485
44505
  const errors = [];
44486
- for (const a of attempts) {
44506
+ for (const { label, ...a } of attempts) {
44487
44507
  try {
44488
- return await chromium.launch({ ...a, headless: true });
44508
+ return { browser: await chromium.launch({ ...a, headless: true }), label };
44489
44509
  } catch (e) {
44490
44510
  errors.push(`${a.executablePath ?? a.channel ?? "bundled"}: ${String(e.message).split("\n")[0]}`);
44491
44511
  }
@@ -44550,7 +44570,7 @@ async function serveFile(url2) {
44550
44570
  async function renderUrl(opts) {
44551
44571
  const served = opts.url.startsWith("file:") ? await serveFile(opts.url) : void 0;
44552
44572
  try {
44553
- const browser = await launch(await loadChromium());
44573
+ const { browser } = await launch(await loadChromium());
44554
44574
  try {
44555
44575
  const page = await browser.newPage({
44556
44576
  viewport: { width: Math.round(opts.width), height: opts.height ?? 900 },
@@ -44582,7 +44602,7 @@ async function renderSvg(svg, o) {
44582
44602
  const file2 = path.join(dir, `render-${process.pid}-${Date.now()}.svg`);
44583
44603
  await writeFile(file2, svg);
44584
44604
  try {
44585
- const browser = await launch(await loadChromium());
44605
+ const { browser } = await launch(await loadChromium());
44586
44606
  try {
44587
44607
  const page = await browser.newPage({
44588
44608
  viewport: { width: Math.ceil(o.width), height: Math.ceil(o.height) },
@@ -44603,7 +44623,7 @@ function formatStatus(plugins, role, port) {
44603
44623
  if (!plugins.length) {
44604
44624
  return [
44605
44625
  `Lupa ${role} on port ${port}. No Figma file connected.`,
44606
- "In Figma: open the file \u2192 Plugins \u2192 Development \u2192 Lupa (import plugin/manifest.json once). Keep the plugin window open."
44626
+ "In Figma: open the file \u2192 Plugins \u2192 Development \u2192 Lupa. Keep the plugin window open. Not in the list yet? lupa setup shows the manifest to import once."
44607
44627
  ].join("\n");
44608
44628
  }
44609
44629
  const lines = [`Lupa ${role} on port ${port}. Connected files (most recently active first):`];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "figma-lupa",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Read-only Figma CLI, MCP server and plugin for pixel-faithful design-to-code with a small context footprint.",
5
5
  "type": "module",
6
6
  "license": "GPL-3.0-or-later",
@@ -1118,7 +1118,7 @@
1118
1118
  t: "hello",
1119
1119
  role: "plugin",
1120
1120
  protocol: PROTOCOL_VERSION,
1121
- pluginVersion: "0.2.0",
1121
+ pluginVersion: "0.2.1",
1122
1122
  fileKey: fileKey(),
1123
1123
  editorType: figma.editorType
1124
1124
  }, state());
@@ -7,8 +7,9 @@ description: Implement a Figma frame or component faithfully in code with the `l
7
7
 
8
8
  `lupa` reads the live Figma file through the Lupa plugin, and it is read-only. If the first command fails:
9
9
 
10
- - **"command not found":** ask the user to run `npm link` in the Lupa folder.
10
+ - **"command not found":** ask the user to install Lupa with `npm install -g figma-lupa && lupa setup`.
11
11
  - **No file connected:** ask the user to open the file in Figma, run *Plugins → Development → Lupa*, and keep the plugin window open.
12
+ - **A line starting with `lupa:`** (a newer Lupa, or a plugin on another version): pass it on to the user when you report back. Don't update Lupa yourself.
12
13
 
13
14
  The target is a Figma URL (in quotes, because it contains `&`), node ids like `12:34`, or nothing for the current selection. When a session also has the Lupa MCP tools (`get_design`, …), they take the same options.
14
15