@senad-d/drawme 0.1.9 → 0.1.10
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/CHANGELOG.md +9 -1
- package/package.json +2 -2
- package/src/drawio.ts +78 -18
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,13 @@ All notable changes to this project are documented here. The format is based on
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.1.10] - 2026-10-27
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- Headless Linux exports size the Xvfb screen to the requested raster (floor 1280x1024, cap 8192) instead of a fixed 1280x1024: a final PNG wider than the screen made draw.io fail with `UnknownVizError` and hang until the timeout.
|
|
14
|
+
- A timed-out export now ends its whole process tree (xvfb-run, Xvfb, draw.io) instead of leaving orphans, and the failure message keeps draw.io's stderr next to the timeout reason.
|
|
15
|
+
|
|
9
16
|
## [0.1.9] - 2026-10-11
|
|
10
17
|
|
|
11
18
|
### Fixed
|
|
@@ -135,6 +142,7 @@ Initial release: DrawMe as a native Pi extension for authoring, validating, and
|
|
|
135
142
|
- Tooling: ESLint flat config, custom `format:check`, `check:golden` asset-integrity check, Vitest suite
|
|
136
143
|
with real-CLI integration tests, CI, SonarCloud, and release workflows.
|
|
137
144
|
|
|
138
|
-
[Unreleased]: https://github.com/senad-d/DrawMe/compare/v0.1.
|
|
145
|
+
[Unreleased]: https://github.com/senad-d/DrawMe/compare/v0.1.10...HEAD
|
|
146
|
+
[0.1.10]: https://github.com/senad-d/DrawMe/compare/v0.1.9...v0.1.10
|
|
139
147
|
[0.1.9]: https://github.com/senad-d/DrawMe/compare/v0.0.1...v0.1.9
|
|
140
148
|
[0.0.1]: https://github.com/senad-d/DrawMe/releases/tag/v0.0.1
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@senad-d/drawme",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"description": "Pi extension for authoring, validating, and exporting editable draw.io diagrams from natural-language descriptions.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"@vitest/coverage-v8": "^5.0.0",
|
|
80
80
|
"eslint": "^10.8.0",
|
|
81
81
|
"globals": "^17.8.0",
|
|
82
|
-
"typebox": "1.3
|
|
82
|
+
"typebox": "1.4.3",
|
|
83
83
|
"typescript": "~6.0.3",
|
|
84
84
|
"typescript-eslint": "^8.10.0",
|
|
85
85
|
"vitest": "^5.0.0"
|
package/src/drawio.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* `-e` PNG IEND repair, page indexing, and headless-Linux handling so callers never
|
|
5
5
|
* hand-build a draw.io command line.
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
7
|
+
import { spawn } from "node:child_process";
|
|
8
8
|
import { existsSync, realpathSync } from "node:fs";
|
|
9
9
|
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
10
10
|
import { basename, dirname, extname, join, resolve } from "node:path";
|
|
@@ -72,20 +72,57 @@ const CANDIDATES = [
|
|
|
72
72
|
"/mnt/c/Program Files/draw.io/draw.io.exe", // WSL2
|
|
73
73
|
];
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Run a command and collect its output. Off Windows the child leads its own process
|
|
77
|
+
* group, so a timeout ends the whole tree (xvfb-run, Xvfb, Electron), not only the
|
|
78
|
+
* direct child: SIGTERM first so xvfb-run can clean up, SIGKILL after a grace period.
|
|
79
|
+
*/
|
|
80
|
+
export function run(bin: string, args: string[], timeout = 120_000): Promise<{ stdout: string; stderr: string }> {
|
|
76
81
|
return new Promise((resolve, reject) => {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
const group = platform() !== "win32";
|
|
83
|
+
const child = spawn(bin, args, { detached: group, stdio: ["ignore", "pipe", "pipe"] });
|
|
84
|
+
let stdout = "";
|
|
85
|
+
let stderr = "";
|
|
86
|
+
let timedOut = false;
|
|
87
|
+
let killTimer: NodeJS.Timeout | undefined;
|
|
88
|
+
child.stdout.on("data", (chunk: Buffer) => (stdout += chunk.toString()));
|
|
89
|
+
child.stderr.on("data", (chunk: Buffer) => (stderr += chunk.toString()));
|
|
90
|
+
const timer = setTimeout(() => {
|
|
91
|
+
timedOut = true;
|
|
92
|
+
killTree(child.pid, group, "SIGTERM");
|
|
93
|
+
killTimer = setTimeout(() => killTree(child.pid, group, "SIGKILL"), 5_000);
|
|
94
|
+
}, timeout);
|
|
95
|
+
child.on("error", (err) => {
|
|
96
|
+
clearTimeout(timer);
|
|
97
|
+
reject(Object.assign(err, { stderr }));
|
|
98
|
+
});
|
|
99
|
+
child.on("close", (code, signal) => {
|
|
100
|
+
clearTimeout(timer);
|
|
101
|
+
if (timedOut) {
|
|
102
|
+
// Reap anything in the group that ignored SIGTERM.
|
|
103
|
+
clearTimeout(killTimer);
|
|
104
|
+
killTree(child.pid, group, "SIGKILL");
|
|
105
|
+
}
|
|
106
|
+
if (code === 0 && !timedOut) {
|
|
107
|
+
resolve({ stdout, stderr });
|
|
108
|
+
return;
|
|
84
109
|
}
|
|
110
|
+
const exitReason = signal ?? `code ${code}`;
|
|
111
|
+
const why = timedOut ? `timed out after ${timeout / 1000}s` : `exited with ${exitReason}`;
|
|
112
|
+
reject(Object.assign(new Error(`${bin} ${why}`), { code, signal, stderr }));
|
|
85
113
|
});
|
|
86
114
|
});
|
|
87
115
|
}
|
|
88
116
|
|
|
117
|
+
function killTree(pid: number | undefined, group: boolean, signal: NodeJS.Signals): void {
|
|
118
|
+
if (pid === undefined) return;
|
|
119
|
+
try {
|
|
120
|
+
process.kill(group ? -pid : pid, signal);
|
|
121
|
+
} catch {
|
|
122
|
+
// already gone
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
89
126
|
function parseMajor(version: string): number {
|
|
90
127
|
const m = /(\d+)/.exec(version);
|
|
91
128
|
return m ? Number.parseInt(m[1], 10) : 0;
|
|
@@ -354,12 +391,30 @@ function isRootUser(): boolean {
|
|
|
354
391
|
return typeof getuid === "function" && getuid() === 0;
|
|
355
392
|
}
|
|
356
393
|
|
|
394
|
+
/**
|
|
395
|
+
* Xvfb screen for an export: draw.io fails (UnknownVizError, then hangs) when the
|
|
396
|
+
* requested raster is wider than the virtual screen. The height is unknown when only
|
|
397
|
+
* a width is requested, so the larger requested side sizes both, plus a margin,
|
|
398
|
+
* floored at 1280x1024 and capped at 8192.
|
|
399
|
+
*/
|
|
400
|
+
export function xvfbScreen(args: string[]): string {
|
|
401
|
+
const want = Math.max(flagNumber(args, "--width"), flagNumber(args, "--height"));
|
|
402
|
+
const side = want > 0 ? Math.min(8192, want + 256) : 0;
|
|
403
|
+
return `${Math.max(1280, side)}x${Math.max(1024, side)}x24`;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
function flagNumber(args: string[], flag: string): number {
|
|
407
|
+
const i = args.indexOf(flag);
|
|
408
|
+
return i >= 0 ? Number(args[i + 1]) || 0 : 0;
|
|
409
|
+
}
|
|
410
|
+
|
|
357
411
|
/** Run the export, wrapping in `xvfb-run` on headless Linux and falling back to a direct call if it's absent. */
|
|
358
412
|
async function invoke(binary: string, fullArgs: string[]): Promise<string> {
|
|
359
413
|
if (platform() === "linux" && !process.env.DISPLAY) {
|
|
414
|
+
const screen = `-screen 0 ${xvfbScreen(fullArgs)}`;
|
|
360
415
|
try {
|
|
361
|
-
await run("xvfb-run", ["-a",
|
|
362
|
-
return `xvfb-run -a --server-args="
|
|
416
|
+
await run("xvfb-run", ["-a", `--server-args=${screen}`, binary, ...fullArgs]);
|
|
417
|
+
return `xvfb-run -a --server-args="${screen}" ${binary} ${fullArgs.join(" ")}`;
|
|
363
418
|
} catch (e) {
|
|
364
419
|
if ((e as NodeJS.ErrnoException).code !== "ENOENT") throw e;
|
|
365
420
|
// xvfb-run not installed — fall through to a direct call
|
|
@@ -379,6 +434,17 @@ export async function exportDiagram(opts: ExportOptions): Promise<ExportResult>
|
|
|
379
434
|
return withSourceExportQueue(opts.input, () => exportDiagramQueued(opts));
|
|
380
435
|
}
|
|
381
436
|
|
|
437
|
+
async function invokeExport(binary: string, args: string[]): Promise<string> {
|
|
438
|
+
try {
|
|
439
|
+
return await invoke(binary, args);
|
|
440
|
+
} catch (e) {
|
|
441
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
442
|
+
const stderr = (e as { stderr?: string }).stderr?.trim();
|
|
443
|
+
const detail = stderr ? `${message}\n${stderr}` : message;
|
|
444
|
+
throw new Error(`draw.io export failed: ${detail}`, { cause: e });
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
382
448
|
async function exportDiagramQueued(opts: ExportOptions): Promise<ExportResult> {
|
|
383
449
|
const info = await resolveBinary(opts.binary);
|
|
384
450
|
if (!info.available || !info.binary) {
|
|
@@ -391,13 +457,7 @@ async function exportDiagramQueued(opts: ExportOptions): Promise<ExportResult> {
|
|
|
391
457
|
const plan = planExport(opts, platform(), isRootUser(), await pageContentWidth(opts.input, opts.pageIndex ?? 1));
|
|
392
458
|
const fullArgs = [...plan.args, plan.input, ...plan.linuxExtra];
|
|
393
459
|
|
|
394
|
-
|
|
395
|
-
try {
|
|
396
|
-
command = await invoke(info.binary, fullArgs);
|
|
397
|
-
} catch (e) {
|
|
398
|
-
const detail = ((e as { stderr?: string }).stderr || (e as Error).message || String(e)).trim();
|
|
399
|
-
throw new Error(`draw.io export failed: ${detail}`, { cause: e });
|
|
400
|
-
}
|
|
460
|
+
const command = await invokeExport(info.binary, fullArgs);
|
|
401
461
|
if (!existsSync(plan.output)) {
|
|
402
462
|
throw new Error(`draw.io reported no error but the output was not created: ${plan.output}`);
|
|
403
463
|
}
|