@layoutdesign/context 0.2.3 → 0.2.4

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.
@@ -1 +1 @@
1
- {"version":3,"file":"ensure.d.ts","sourceRoot":"","sources":["../../../src/preview/ensure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAIrE,iEAAiE;AACjE,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,aAAa,CAAC,CAIlE;AAED,qEAAqE;AACrE,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CAE5D"}
1
+ {"version":3,"file":"ensure.d.ts","sourceRoot":"","sources":["../../../src/preview/ensure.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAiCrE,iEAAiE;AACjE,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,aAAa,CAAC,CAkBlE;AAED,qEAAqE;AACrE,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CAE5D"}
@@ -1,10 +1,52 @@
1
+ import { PREVIEW_PORT } from "../kit/types.js";
1
2
  import { startPreviewServer } from "./server.js";
2
3
  let previewServer = null;
4
+ /**
5
+ * Check if an existing preview server is responding on the port.
6
+ * Returns a stub PreviewServer if reachable, null otherwise.
7
+ */
8
+ async function probeExistingServer() {
9
+ const http = await import("node:http");
10
+ const url = `http://localhost:${PREVIEW_PORT}`;
11
+ return new Promise((resolve) => {
12
+ const req = http.default.get(url, { timeout: 2000 }, (res) => {
13
+ res.resume(); // drain response
14
+ if (res.statusCode === 200) {
15
+ resolve({
16
+ url,
17
+ broadcast: () => { },
18
+ close: () => { },
19
+ });
20
+ }
21
+ else {
22
+ resolve(null);
23
+ }
24
+ });
25
+ req.on("error", () => resolve(null));
26
+ req.on("timeout", () => {
27
+ req.destroy();
28
+ resolve(null);
29
+ });
30
+ });
31
+ }
3
32
  /** Ensure the preview server is running. Starts it if needed. */
4
33
  export async function ensurePreviewServer() {
5
34
  if (previewServer)
6
35
  return previewServer;
7
- previewServer = await startPreviewServer(undefined, { openBrowser: false });
36
+ try {
37
+ previewServer = await startPreviewServer(undefined, { openBrowser: false });
38
+ }
39
+ catch (err) {
40
+ // Port already in use — check if there's a working server there
41
+ if (err instanceof Error && err.message.includes("already in use")) {
42
+ const existing = await probeExistingServer();
43
+ if (existing) {
44
+ previewServer = existing;
45
+ return previewServer;
46
+ }
47
+ }
48
+ throw err;
49
+ }
8
50
  return previewServer;
9
51
  }
10
52
  /** Called from MCP server startup to store the initial reference. */
@@ -1 +1 @@
1
- {"version":3,"file":"ensure.js","sourceRoot":"","sources":["../../../src/preview/ensure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAsB,MAAM,aAAa,CAAC;AAErE,IAAI,aAAa,GAAyB,IAAI,CAAC;AAE/C,iEAAiE;AACjE,MAAM,CAAC,KAAK,UAAU,mBAAmB;IACvC,IAAI,aAAa;QAAE,OAAO,aAAa,CAAC;IACxC,aAAa,GAAG,MAAM,kBAAkB,CAAC,SAAS,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,CAAC;IAC5E,OAAO,aAAa,CAAC;AACvB,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,gBAAgB,CAAC,MAAqB;IACpD,aAAa,GAAG,MAAM,CAAC;AACzB,CAAC"}
1
+ {"version":3,"file":"ensure.js","sourceRoot":"","sources":["../../../src/preview/ensure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAsB,MAAM,aAAa,CAAC;AAErE,IAAI,aAAa,GAAyB,IAAI,CAAC;AAE/C;;;GAGG;AACH,KAAK,UAAU,mBAAmB;IAChC,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,CAAC;IACvC,MAAM,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AM,mBAAmB,EAAE,CAAC;YAC7C,IAAI,QAAQ,EAAE,CAAC;gBACb,aAAa,GAAG,QAAQ,CAAC;gBACzB,OAAO,aAAa,CAAC;YACvB,CAAC;QACH,CAAC;QACD,MAAM,GAAG,CAAC;IACZ,CAAC;IAED,OAAO,aAAa,CAAC;AACvB,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,gBAAgB,CAAC,MAAqB;IACpD,aAAa,GAAG,MAAM,CAAC;AACzB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@layoutdesign/context",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "Design system context for AI coding agents — MCP server + CLI + live preview",
5
5
  "license": "MIT",
6
6
  "type": "module",