@danielsimonjr/sciengjs 0.3.0 → 0.3.2
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/README.md +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worker/run.d.ts +19 -1
- package/dist/worker/run.js +60 -4
- package/dist/worker/run.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ sciengjs turns diagram source into images on your own machine. It sends no sourc
|
|
|
10
10
|
|
|
11
11
|
## What this release does
|
|
12
12
|
|
|
13
|
-
Release 0.3.
|
|
13
|
+
Release 0.3.2 holds three input types: **Graphviz DOT**, **Mermaid** (every diagram type) and **HTML** (to PNG and PDF). The browser stage draws the Mermaid types other than class, state and sequence, and every PDF.
|
|
14
14
|
|
|
15
15
|
| Input | Output | Engine |
|
|
16
16
|
|---|---|---|
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const ENGINE_VERSION = "0.3.
|
|
1
|
+
export declare const ENGINE_VERSION = "0.3.2";
|
package/dist/version.js
CHANGED
package/dist/worker/run.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Worker } from "node:worker_threads";
|
|
1
|
+
import { Worker, type WorkerOptions } from "node:worker_threads";
|
|
2
2
|
import type { BackendOutput, WorkerJob } from "./protocol.ts";
|
|
3
3
|
/** The exit of one worker. The exit code is the code that `Worker.terminate` reports. */
|
|
4
4
|
export interface WorkerExit {
|
|
@@ -20,6 +20,24 @@ export interface WorkerLimits {
|
|
|
20
20
|
/** Creates the worker. Tests replace it with a double. */
|
|
21
21
|
createWorker?: (entry: URL, data: WorkerJob, maxMemoryMb: number) => Worker;
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* The function returns the parent's execArgv without the flags that describe input or mode.
|
|
25
|
+
* Node gives a worker the parent's execArgv by default. If you start the parent with
|
|
26
|
+
* `--input-type`, the worker can not load its entry. The other flags pass to the worker
|
|
27
|
+
* in the same order, with no change.
|
|
28
|
+
*/
|
|
29
|
+
export declare function workerExecArgv(parentArgv: readonly string[]): string[];
|
|
30
|
+
/**
|
|
31
|
+
* Creates a worker with the parent flags that a worker can take. The parent execArgv can hold flags
|
|
32
|
+
* that a worker rejects, such as the expanded defaults of `node --test` and `--stack-trace-limit`.
|
|
33
|
+
* Rules:
|
|
34
|
+
* 1. When workerExecArgv removes no flag, the worker gets no execArgv key. Node then inherits the parent flags.
|
|
35
|
+
* 2. When it removes a flag, the worker gets the filtered list.
|
|
36
|
+
* 3. When the constructor throws `ERR_WORKER_INVALID_EXEC_ARGV`, the worker is constructed again with an empty list.
|
|
37
|
+
* The empty list drops every parent flag, also `--conditions`, `--import` and `--require`. The built worker entry needs none of them.
|
|
38
|
+
* Other errors pass through. `ctor` receives the options and returns the worker. Tests pass a double.
|
|
39
|
+
*/
|
|
40
|
+
export declare function constructWorker(ctor: (options: WorkerOptions) => Worker, base: WorkerOptions, parentArgv: readonly string[]): Worker;
|
|
23
41
|
/**
|
|
24
42
|
* Runs one render in a fresh worker. The worker ends at the first of: its message, its error,
|
|
25
43
|
* its exit, or the time limit. The promise settles only after the worker has exited.
|
package/dist/worker/run.js
CHANGED
|
@@ -4,11 +4,67 @@ import { fileURLToPath } from "node:url";
|
|
|
4
4
|
import { RenderError } from "../errors.js";
|
|
5
5
|
/** The default longest wait for a worker to stop. It is the only place where this value is set. */
|
|
6
6
|
const DEFAULT_TERMINATE_WAIT_MS = 5000;
|
|
7
|
+
/** Node flags that take their value from the next token, such as `-e <code>`. */
|
|
8
|
+
const VALUE_FLAGS = new Set(["-e", "--eval", "-p", "--print", "--input-type"]);
|
|
9
|
+
/** Node flags that change how the entry loads or runs. They take no value. */
|
|
10
|
+
const MODE_FLAGS = new Set(["-i", "--interactive", "-c", "--check"]);
|
|
11
|
+
/** A group of single-letter short flags, such as `-pe`. Only letters of the loader flags match. */
|
|
12
|
+
const SHORT_GROUP = /^-[epic]{2,}$/;
|
|
13
|
+
/**
|
|
14
|
+
* The function returns the parent's execArgv without the flags that describe input or mode.
|
|
15
|
+
* Node gives a worker the parent's execArgv by default. If you start the parent with
|
|
16
|
+
* `--input-type`, the worker can not load its entry. The other flags pass to the worker
|
|
17
|
+
* in the same order, with no change.
|
|
18
|
+
*/
|
|
19
|
+
export function workerExecArgv(parentArgv) {
|
|
20
|
+
const kept = [];
|
|
21
|
+
for (let i = 0; i < parentArgv.length; i++) {
|
|
22
|
+
const token = parentArgv[i];
|
|
23
|
+
if (MODE_FLAGS.has(token))
|
|
24
|
+
continue;
|
|
25
|
+
if (SHORT_GROUP.test(token)) {
|
|
26
|
+
if (/[ep]/.test(token))
|
|
27
|
+
i++;
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const eq = token.indexOf("=");
|
|
31
|
+
const name = eq === -1 ? token : token.slice(0, eq);
|
|
32
|
+
if (VALUE_FLAGS.has(name)) {
|
|
33
|
+
if (eq === -1)
|
|
34
|
+
i++;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
kept.push(token);
|
|
38
|
+
}
|
|
39
|
+
return kept;
|
|
40
|
+
}
|
|
41
|
+
/** The error code that Node throws when a worker rejects the execArgv it receives. */
|
|
42
|
+
const INVALID_EXEC_ARGV = "ERR_WORKER_INVALID_EXEC_ARGV";
|
|
43
|
+
/**
|
|
44
|
+
* Creates a worker with the parent flags that a worker can take. The parent execArgv can hold flags
|
|
45
|
+
* that a worker rejects, such as the expanded defaults of `node --test` and `--stack-trace-limit`.
|
|
46
|
+
* Rules:
|
|
47
|
+
* 1. When workerExecArgv removes no flag, the worker gets no execArgv key. Node then inherits the parent flags.
|
|
48
|
+
* 2. When it removes a flag, the worker gets the filtered list.
|
|
49
|
+
* 3. When the constructor throws `ERR_WORKER_INVALID_EXEC_ARGV`, the worker is constructed again with an empty list.
|
|
50
|
+
* The empty list drops every parent flag, also `--conditions`, `--import` and `--require`. The built worker entry needs none of them.
|
|
51
|
+
* Other errors pass through. `ctor` receives the options and returns the worker. Tests pass a double.
|
|
52
|
+
*/
|
|
53
|
+
export function constructWorker(ctor, base, parentArgv) {
|
|
54
|
+
const kept = workerExecArgv(parentArgv);
|
|
55
|
+
const removedAny = kept.length !== parentArgv.length;
|
|
56
|
+
try {
|
|
57
|
+
return ctor(removedAny ? { ...base, execArgv: kept } : { ...base });
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
if (err?.code === INVALID_EXEC_ARGV) {
|
|
61
|
+
return ctor({ ...base, execArgv: [] });
|
|
62
|
+
}
|
|
63
|
+
throw err;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
7
66
|
function createDefaultWorker(entry, data, maxMemoryMb) {
|
|
8
|
-
return new Worker(entry, {
|
|
9
|
-
workerData: data,
|
|
10
|
-
resourceLimits: { maxOldGenerationSizeMb: maxMemoryMb },
|
|
11
|
-
});
|
|
67
|
+
return constructWorker((options) => new Worker(entry, options), { workerData: data, resourceLimits: { maxOldGenerationSizeMb: maxMemoryMb } }, process.execArgv);
|
|
12
68
|
}
|
|
13
69
|
/** Terminates the worker. It rejects when terminate throws, rejects or does not resolve within the wait. */
|
|
14
70
|
function stopWorker(worker, waitMs) {
|
package/dist/worker/run.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.js","sourceRoot":"","sources":["../../src/worker/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"run.js","sourceRoot":"","sources":["../../src/worker/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAsB,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAyB3C,mGAAmG;AACnG,MAAM,yBAAyB,GAAG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AAC,CAAC;gBACrF,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QACH,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,GAA8B,EAAE,EAAE;YACtD,MAAM,CAAC,GAAG,EAAE;gBACV,IAAI,GAAG,CAAC,IAAI,KAAK,0BAA0B,EAAE,CAAC;oBAC5C,MAAM,CAAC,IAAI,WAAW,CAAC,SAAS,EAAE,qCAAqC,MAAM,CAAC,WAAW,KAAK,CAAC,CAAC,CAAC;gBACnG,CAAC;qBAAM,CAAC;oBACN,MAAM,CAAC,IAAI,WAAW,CAAC,YAAY,EAAE,yBAAyB,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;gBAChF,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QACH,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,IAAY,EAAE,EAAE;YACnC,MAAM,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,WAAW,CAAC,YAAY,EAAE,kCAAkC,IAAI,qBAAqB,CAAC,CAAC,CAAC,CAAC;QACnH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@danielsimonjr/sciengjs",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A local rendering engine for science and engineering diagrams, documents and models",
|
|
6
6
|
"license": "MIT",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"test": "bun test",
|
|
45
45
|
"smoke": "node test/smoke/smoke.mjs",
|
|
46
46
|
"clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
47
|
-
"test:node": "node --test test/node/worker.node.mjs"
|
|
47
|
+
"test:node": "node --test test/node/worker.node.mjs test/node/eval-render.node.mjs test/node/worker-execargv.node.mjs"
|
|
48
48
|
},
|
|
49
49
|
"keywords": [
|
|
50
50
|
"graphviz",
|