reg-cli 0.19.0-rc0 → 0.19.0-rc1

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/LICENSE CHANGED
File without changes
package/README.md CHANGED
File without changes
package/dist/cli.cjs CHANGED
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env node
2
- require("./rolldown-runtime-D_mwlA32.cjs");
3
2
  const require_index = require("./index.cjs");
4
- const require_ximgdiff = require("./ximgdiff-wmW1BH1H.cjs");
3
+ const require_ximgdiff = require("./ximgdiff-B16oe7EL.cjs");
5
4
  let node_fs_promises = require("node:fs/promises");
6
5
  let node_path = require("node:path");
7
6
  let node_module = require("node:module");
package/dist/cli.d.cts CHANGED
File without changes
package/dist/cli.d.mts CHANGED
File without changes
package/dist/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as writeXimgdiffAssets } from "./ximgdiff-DzkRRnkW.mjs";
2
+ import { t as writeXimgdiffAssets } from "./ximgdiff-D8GAJaxA.mjs";
3
3
  import { dir, run } from "./index.mjs";
4
4
  import { createRequire } from "node:module";
5
5
  import { copyFile, mkdir } from "node:fs/promises";
package/dist/index.cjs CHANGED
@@ -1,8 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_rolldown_runtime = require("./rolldown-runtime-D_mwlA32.cjs");
3
- const require_tracing = require("./tracing-DlLL541f.cjs");
2
+ const require_tracing = require("./tracing-Cf9TNPXQ.cjs");
4
3
  let node_events = require("node:events");
5
- node_events = require_rolldown_runtime.__toESM(node_events, 1);
4
+ node_events = require_tracing.__toESM(node_events, 1);
6
5
  let node_worker_threads = require("node:worker_threads");
7
6
  let url = require("url");
8
7
  let node_path = require("node:path");
@@ -36,79 +35,80 @@ const runInternal = async (argv, emitter) => {
36
35
  }
37
36
  const traceContext = require_tracing.isTracingEnabled() ? require_tracing.startRootSpan("reg-cli") : null;
38
37
  const t_new_entry = Date.now();
39
- const worker = new node_worker_threads.Worker((0, node_path.join)(dir(), `./entry.${require_tracing.resolveExtention()}`), { workerData: { argv } });
38
+ const worker = new node_worker_threads.Worker((0, node_path.join)(dir(), `./runner.${require_tracing.resolveExtention()}`), { workerData: {
39
+ argv,
40
+ mode: "entry"
41
+ } });
40
42
  recordMainSpan("main.new_entry_worker", t_new_entry);
41
43
  let nextTid = 1;
42
44
  const workers = [worker];
43
45
  const threadWorkerSpans = [];
44
- const spawn = (startArg, threadId, memory) => {
45
- const t_new_worker = Date.now();
46
- const worker = new node_worker_threads.Worker((0, node_path.join)(dir(), `./worker.${require_tracing.resolveExtention()}`), { workerData: { argv } });
47
- const tid = nextTid++;
48
- recordMainSpan("main.new_thread_worker", t_new_worker, { tid });
49
- workers.push(worker);
50
- worker.on("message", (msg) => {
51
- const { cmd } = msg;
52
- if (cmd === "loaded") {
53
- if (typeof worker.unref === "function") worker.unref();
54
- } else if (cmd === "thread-spawn") spawn(msg.startArg, msg.threadId, msg.memory);
55
- else if (cmd === "worker-spans") {
56
- if (Array.isArray(msg.workerSpans)) threadWorkerSpans.push(...msg.workerSpans);
57
- } else if (cmd === "compare-event") {
58
- if (msg.event) emitter.emit("compare", msg.event);
46
+ const attachCommonHandlers = (w) => {
47
+ w.on("message", (msg) => {
48
+ switch (msg.cmd) {
49
+ case "compare-event":
50
+ if (msg.event) emitter.emit("compare", msg.event);
51
+ return;
52
+ case "thread-spawn":
53
+ spawn(msg.startArg, msg.threadId, msg.memory);
54
+ return;
55
+ case "worker-spans":
56
+ if (Array.isArray(msg.workerSpans)) threadWorkerSpans.push(...msg.workerSpans);
57
+ return;
58
+ case "loaded":
59
+ if (typeof w.unref === "function") w.unref();
60
+ return;
59
61
  }
60
62
  });
61
- worker.on("error", (e) => {
62
- workers.forEach((w) => w.terminate());
63
+ w.on("error", (e) => {
64
+ if (traceContext) require_tracing.endRootSpan(false);
65
+ workers.forEach((x) => x.terminate());
63
66
  emitter.emit("error", e);
64
67
  });
68
+ };
69
+ const spawn = (startArg, threadId, memory) => {
70
+ const t_new_worker = Date.now();
71
+ const w = new node_worker_threads.Worker((0, node_path.join)(dir(), `./runner.${require_tracing.resolveExtention()}`), { workerData: {
72
+ argv,
73
+ mode: "thread"
74
+ } });
75
+ const tid = nextTid++;
76
+ recordMainSpan("main.new_thread_worker", t_new_worker, { tid });
77
+ workers.push(w);
78
+ attachCommonHandlers(w);
65
79
  if (threadId) {
66
80
  Atomics.store(threadId, 0, tid);
67
81
  Atomics.notify(threadId, 0);
68
82
  }
69
- worker.postMessage({
83
+ w.postMessage({
70
84
  startArg,
71
85
  tid,
72
86
  memory
73
87
  });
74
88
  return tid;
75
89
  };
76
- worker.on("message", async ({ cmd, startArg, threadId, memory, data, traceData, workerSpans, event }) => {
77
- if (cmd === "compare-event") {
78
- if (event) emitter.emit("compare", event);
79
- return;
80
- }
81
- if (cmd === "complete") {
82
- const t_post_complete = Date.now();
83
- if (require_tracing.isTracingEnabled()) {
84
- if (Array.isArray(workerSpans)) require_tracing.processWorkerSpans(workerSpans, "entry");
85
- if (threadWorkerSpans.length) require_tracing.processWorkerSpans(threadWorkerSpans, "thread");
86
- if (traceData) require_tracing.processRustTraceData(traceData);
87
- recordMainSpan("main.process_trace_and_spans", t_post_complete);
88
- mainSpans.push({
89
- name: "main.run_total",
90
- start_ms: run_start_ms,
91
- end_ms: Date.now(),
92
- worker_label: "main"
93
- });
94
- require_tracing.processWorkerSpans(mainSpans, "main");
95
- require_tracing.endRootSpan(true);
96
- await require_tracing.shutdownTracing();
97
- }
98
- workers.forEach((w) => w.terminate());
99
- emitter.emit("complete", data);
100
- return;
101
- }
102
- if (cmd === "loaded") {
103
- if (typeof worker.unref === "function") worker.unref();
104
- return;
90
+ attachCommonHandlers(worker);
91
+ worker.on("message", async (msg) => {
92
+ if (msg.cmd !== "complete") return;
93
+ const { data, traceData, workerSpans } = msg;
94
+ const t_post_complete = Date.now();
95
+ if (require_tracing.isTracingEnabled()) {
96
+ if (Array.isArray(workerSpans)) require_tracing.processWorkerSpans(workerSpans, "entry");
97
+ if (threadWorkerSpans.length) require_tracing.processWorkerSpans(threadWorkerSpans, "thread");
98
+ if (traceData) require_tracing.processRustTraceData(traceData);
99
+ recordMainSpan("main.process_trace_and_spans", t_post_complete);
100
+ mainSpans.push({
101
+ name: "main.run_total",
102
+ start_ms: run_start_ms,
103
+ end_ms: Date.now(),
104
+ worker_label: "main"
105
+ });
106
+ require_tracing.processWorkerSpans(mainSpans, "main");
107
+ require_tracing.endRootSpan(true);
108
+ await require_tracing.shutdownTracing();
105
109
  }
106
- if (cmd === "thread-spawn") spawn(startArg, threadId, memory);
107
- });
108
- worker.on("error", (err) => {
109
- if (traceContext) require_tracing.endRootSpan(false);
110
110
  workers.forEach((w) => w.terminate());
111
- emitter.emit("error", err);
111
+ emitter.emit("complete", data);
112
112
  });
113
113
  };
114
114
  /** Flags that `compare()` handles itself in JS; they are NOT forwarded to
@@ -163,7 +163,7 @@ const compare = (input) => {
163
163
  inner.on("complete", async (data) => {
164
164
  try {
165
165
  if (restAny.additionalDetection === "client" && typeof input.report === "string") {
166
- const { writeXimgdiffAssets } = await Promise.resolve().then(() => require("./ximgdiff-wmW1BH1H.cjs")).then((n) => n.ximgdiff_exports);
166
+ const { writeXimgdiffAssets } = await Promise.resolve().then(() => require("./ximgdiff-B16oe7EL.cjs")).then((n) => n.ximgdiff_exports);
167
167
  await writeXimgdiffAssets({
168
168
  reportPath: input.report,
169
169
  urlPrefix: typeof input.urlPrefix === "string" ? input.urlPrefix : "",
package/dist/index.d.cts CHANGED
File without changes
package/dist/index.d.mts CHANGED
File without changes
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as processWorkerSpans, d as resolveExtention, i as processRustTraceData, l as isCJS, n as initTracing, o as shutdownTracing, r as isTracingEnabled, s as startRootSpan, t as endRootSpan } from "./tracing-7HO8hac9.mjs";
1
+ import { a as processWorkerSpans, i as processRustTraceData, n as initTracing, o as shutdownTracing, p as resolveExtention, r as isTracingEnabled, s as startRootSpan, t as endRootSpan, u as isCJS } from "./tracing-Bo38b9aR.mjs";
2
2
  import EventEmitter from "node:events";
3
3
  import { Worker } from "node:worker_threads";
4
4
  import { fileURLToPath } from "url";
@@ -33,79 +33,80 @@ const runInternal = async (argv, emitter) => {
33
33
  }
34
34
  const traceContext = isTracingEnabled() ? startRootSpan("reg-cli") : null;
35
35
  const t_new_entry = Date.now();
36
- const worker = new Worker(join(dir(), `./entry.${resolveExtention()}`), { workerData: { argv } });
36
+ const worker = new Worker(join(dir(), `./runner.${resolveExtention()}`), { workerData: {
37
+ argv,
38
+ mode: "entry"
39
+ } });
37
40
  recordMainSpan("main.new_entry_worker", t_new_entry);
38
41
  let nextTid = 1;
39
42
  const workers = [worker];
40
43
  const threadWorkerSpans = [];
41
- const spawn = (startArg, threadId, memory) => {
42
- const t_new_worker = Date.now();
43
- const worker = new Worker(join(dir(), `./worker.${resolveExtention()}`), { workerData: { argv } });
44
- const tid = nextTid++;
45
- recordMainSpan("main.new_thread_worker", t_new_worker, { tid });
46
- workers.push(worker);
47
- worker.on("message", (msg) => {
48
- const { cmd } = msg;
49
- if (cmd === "loaded") {
50
- if (typeof worker.unref === "function") worker.unref();
51
- } else if (cmd === "thread-spawn") spawn(msg.startArg, msg.threadId, msg.memory);
52
- else if (cmd === "worker-spans") {
53
- if (Array.isArray(msg.workerSpans)) threadWorkerSpans.push(...msg.workerSpans);
54
- } else if (cmd === "compare-event") {
55
- if (msg.event) emitter.emit("compare", msg.event);
44
+ const attachCommonHandlers = (w) => {
45
+ w.on("message", (msg) => {
46
+ switch (msg.cmd) {
47
+ case "compare-event":
48
+ if (msg.event) emitter.emit("compare", msg.event);
49
+ return;
50
+ case "thread-spawn":
51
+ spawn(msg.startArg, msg.threadId, msg.memory);
52
+ return;
53
+ case "worker-spans":
54
+ if (Array.isArray(msg.workerSpans)) threadWorkerSpans.push(...msg.workerSpans);
55
+ return;
56
+ case "loaded":
57
+ if (typeof w.unref === "function") w.unref();
58
+ return;
56
59
  }
57
60
  });
58
- worker.on("error", (e) => {
59
- workers.forEach((w) => w.terminate());
61
+ w.on("error", (e) => {
62
+ if (traceContext) endRootSpan(false);
63
+ workers.forEach((x) => x.terminate());
60
64
  emitter.emit("error", e);
61
65
  });
66
+ };
67
+ const spawn = (startArg, threadId, memory) => {
68
+ const t_new_worker = Date.now();
69
+ const w = new Worker(join(dir(), `./runner.${resolveExtention()}`), { workerData: {
70
+ argv,
71
+ mode: "thread"
72
+ } });
73
+ const tid = nextTid++;
74
+ recordMainSpan("main.new_thread_worker", t_new_worker, { tid });
75
+ workers.push(w);
76
+ attachCommonHandlers(w);
62
77
  if (threadId) {
63
78
  Atomics.store(threadId, 0, tid);
64
79
  Atomics.notify(threadId, 0);
65
80
  }
66
- worker.postMessage({
81
+ w.postMessage({
67
82
  startArg,
68
83
  tid,
69
84
  memory
70
85
  });
71
86
  return tid;
72
87
  };
73
- worker.on("message", async ({ cmd, startArg, threadId, memory, data, traceData, workerSpans, event }) => {
74
- if (cmd === "compare-event") {
75
- if (event) emitter.emit("compare", event);
76
- return;
77
- }
78
- if (cmd === "complete") {
79
- const t_post_complete = Date.now();
80
- if (isTracingEnabled()) {
81
- if (Array.isArray(workerSpans)) processWorkerSpans(workerSpans, "entry");
82
- if (threadWorkerSpans.length) processWorkerSpans(threadWorkerSpans, "thread");
83
- if (traceData) processRustTraceData(traceData);
84
- recordMainSpan("main.process_trace_and_spans", t_post_complete);
85
- mainSpans.push({
86
- name: "main.run_total",
87
- start_ms: run_start_ms,
88
- end_ms: Date.now(),
89
- worker_label: "main"
90
- });
91
- processWorkerSpans(mainSpans, "main");
92
- endRootSpan(true);
93
- await shutdownTracing();
94
- }
95
- workers.forEach((w) => w.terminate());
96
- emitter.emit("complete", data);
97
- return;
98
- }
99
- if (cmd === "loaded") {
100
- if (typeof worker.unref === "function") worker.unref();
101
- return;
88
+ attachCommonHandlers(worker);
89
+ worker.on("message", async (msg) => {
90
+ if (msg.cmd !== "complete") return;
91
+ const { data, traceData, workerSpans } = msg;
92
+ const t_post_complete = Date.now();
93
+ if (isTracingEnabled()) {
94
+ if (Array.isArray(workerSpans)) processWorkerSpans(workerSpans, "entry");
95
+ if (threadWorkerSpans.length) processWorkerSpans(threadWorkerSpans, "thread");
96
+ if (traceData) processRustTraceData(traceData);
97
+ recordMainSpan("main.process_trace_and_spans", t_post_complete);
98
+ mainSpans.push({
99
+ name: "main.run_total",
100
+ start_ms: run_start_ms,
101
+ end_ms: Date.now(),
102
+ worker_label: "main"
103
+ });
104
+ processWorkerSpans(mainSpans, "main");
105
+ endRootSpan(true);
106
+ await shutdownTracing();
102
107
  }
103
- if (cmd === "thread-spawn") spawn(startArg, threadId, memory);
104
- });
105
- worker.on("error", (err) => {
106
- if (traceContext) endRootSpan(false);
107
108
  workers.forEach((w) => w.terminate());
108
- emitter.emit("error", err);
109
+ emitter.emit("complete", data);
109
110
  });
110
111
  };
111
112
  /** Flags that `compare()` handles itself in JS; they are NOT forwarded to
@@ -160,7 +161,7 @@ const compare = (input) => {
160
161
  inner.on("complete", async (data) => {
161
162
  try {
162
163
  if (restAny.additionalDetection === "client" && typeof input.report === "string") {
163
- const { writeXimgdiffAssets } = await import("./ximgdiff-DzkRRnkW.mjs").then((n) => n.n);
164
+ const { writeXimgdiffAssets } = await import("./ximgdiff-D8GAJaxA.mjs").then((n) => n.n);
164
165
  await writeXimgdiffAssets({
165
166
  reportPath: input.report,
166
167
  urlPrefix: typeof input.urlPrefix === "string" ? input.urlPrefix : "",
package/dist/reg.wasm CHANGED
Binary file
@@ -0,0 +1,228 @@
1
+ const require_tracing = require("./tracing-Cf9TNPXQ.cjs");
2
+ let node_worker_threads = require("node:worker_threads");
3
+ let node_process = require("node:process");
4
+ let node_fs = require("node:fs");
5
+ node_fs = require_tracing.__toESM(node_fs, 1);
6
+ let _tybys_wasm_util = require("@tybys/wasm-util");
7
+ //#region src/proxy.ts
8
+ const kIsProxy = Symbol("kIsProxy");
9
+ const createInstanceProxy = (instance, memory) => {
10
+ if (instance[kIsProxy]) return instance;
11
+ const originalExports = instance.exports;
12
+ const createHandler = function(target) {
13
+ const handlers = [
14
+ "apply",
15
+ "construct",
16
+ "defineProperty",
17
+ "deleteProperty",
18
+ "get",
19
+ "getOwnPropertyDescriptor",
20
+ "getPrototypeOf",
21
+ "has",
22
+ "isExtensible",
23
+ "ownKeys",
24
+ "preventExtensions",
25
+ "set",
26
+ "setPrototypeOf"
27
+ ];
28
+ const handler = {};
29
+ for (let i = 0; i < handlers.length; i++) {
30
+ const name = handlers[i];
31
+ handler[name] = function() {
32
+ const args = Array.prototype.slice.call(arguments, 1);
33
+ args.unshift(target);
34
+ return Reflect[name].apply(Reflect, args);
35
+ };
36
+ }
37
+ return handler;
38
+ };
39
+ const handler = createHandler(originalExports);
40
+ const _initialize = () => {};
41
+ const _start = () => 0;
42
+ handler.get = function(_target, p, receiver) {
43
+ if (p === "memory") return (typeof memory === "function" ? memory() : memory) ?? Reflect.get(originalExports, p, receiver);
44
+ if (p === "_initialize") return p in originalExports ? _initialize : void 0;
45
+ if (p === "_start") return p in originalExports ? _start : void 0;
46
+ return Reflect.get(originalExports, p, receiver);
47
+ };
48
+ handler.has = function(_target, p) {
49
+ if (p === "memory") return true;
50
+ return Reflect.has(originalExports, p);
51
+ };
52
+ const exportsProxy = new Proxy(Object.create(null), handler);
53
+ return new Proxy(instance, { get(target, p, receiver) {
54
+ if (p === "exports") return exportsProxy;
55
+ if (p === kIsProxy) return true;
56
+ return Reflect.get(target, p, receiver);
57
+ } });
58
+ };
59
+ //#endregion
60
+ //#region src/progress.ts
61
+ const MARKER = "__REG_CLI_EVT__ ";
62
+ /**
63
+ * Build a WASI `printErr` hook that forwards progress events to `onEvent`
64
+ * and everything else to `fallback` (defaults to `console.error`).
65
+ *
66
+ * `@tybys/wasm-util`'s `StandardOutput.write` already buffers until a
67
+ * newline and invokes the callback with one stripped line per call
68
+ * (see the `StandardOutput` class in
69
+ * `node_modules/@tybys/wasm-util/dist/wasm-util.esm-bundler.js`). So
70
+ * we can treat each invocation as a single complete line.
71
+ */
72
+ const createPrintErrHook = (onEvent, fallback = (s) => console.error(s)) => {
73
+ return (line) => {
74
+ if (line.startsWith(MARKER)) {
75
+ const json = line.slice(16);
76
+ try {
77
+ const ev = JSON.parse(json);
78
+ if (ev && typeof ev.type === "string" && typeof ev.path === "string") {
79
+ onEvent(ev);
80
+ return;
81
+ }
82
+ } catch {}
83
+ }
84
+ fallback(line);
85
+ };
86
+ };
87
+ //#endregion
88
+ //#region src/runner.ts
89
+ const mode = node_worker_threads.workerData.mode;
90
+ const isTracingEnabled = () => node_process.env.OTEL_ENABLED === "true" || node_process.env.JAEGER_ENABLED === "true";
91
+ const argv = require_tracing.normalizeWasiArgv(node_worker_threads.workerData.argv);
92
+ const sandbox = require_tracing.computeWasiSandbox(argv);
93
+ const printErr = createPrintErrHook((ev) => {
94
+ node_worker_threads.parentPort?.postMessage({
95
+ cmd: "compare-event",
96
+ event: ev
97
+ });
98
+ });
99
+ const wasi = new _tybys_wasm_util.WASI({
100
+ version: "preview1",
101
+ args: argv,
102
+ env: sandbox.env,
103
+ returnOnExit: true,
104
+ preopens: sandbox.preopens,
105
+ fs: node_fs.default,
106
+ printErr
107
+ });
108
+ const wasmFile = require_tracing.readWasm();
109
+ const readWasmString = (exports, memory, outputPtr) => {
110
+ const view = new DataView(memory.buffer, outputPtr);
111
+ const len = view.getUint32(0, true);
112
+ const bufPtr = view.getUint32(4, true);
113
+ const bytes = new Uint8Array(memory.buffer, bufPtr, len);
114
+ const s = new TextDecoder("utf-8").decode(bytes);
115
+ exports.free_wasm_output(outputPtr);
116
+ return s;
117
+ };
118
+ const makeSpanRecorder = (workerLabel) => {
119
+ const workerSpans = [];
120
+ const tSpan = async (name, fn, attributes) => {
121
+ if (!isTracingEnabled()) return fn();
122
+ const start_ms = Date.now();
123
+ const r = await fn();
124
+ workerSpans.push({
125
+ name,
126
+ start_ms,
127
+ end_ms: Date.now(),
128
+ attributes,
129
+ worker_label: workerLabel
130
+ });
131
+ return r;
132
+ };
133
+ return {
134
+ workerSpans,
135
+ tSpan
136
+ };
137
+ };
138
+ const makeThreadSpawnImport = (memory) => (startArg) => {
139
+ const buf = new SharedArrayBuffer(4);
140
+ const id = new Int32Array(buf);
141
+ Atomics.store(id, 0, -1);
142
+ node_worker_threads.parentPort?.postMessage({
143
+ cmd: "thread-spawn",
144
+ startArg,
145
+ threadId: id,
146
+ memory
147
+ });
148
+ Atomics.wait(id, 0, -1);
149
+ return Atomics.load(id, 0);
150
+ };
151
+ const compileAndInstantiate = async (memory, tSpan, prefix) => {
152
+ const wasm = await tSpan(`${prefix}.wasm_compile`, async () => WebAssembly.compile(await wasmFile));
153
+ const wasi_snapshot_preview1 = require_tracing.filterWasiImports(wasm, wasi.getImportObject().wasi_snapshot_preview1);
154
+ return tSpan(`${prefix}.wasm_instantiate`, async () => WebAssembly.instantiate(wasm, {
155
+ wasi_snapshot_preview1,
156
+ wasi: { "thread-spawn": makeThreadSpawnImport(memory) },
157
+ env: { memory }
158
+ }));
159
+ };
160
+ if (mode === "entry") (async () => {
161
+ const entry_start_ms = Date.now();
162
+ const { workerSpans, tSpan } = makeSpanRecorder("entry");
163
+ const memory = new WebAssembly.Memory({
164
+ initial: 256,
165
+ maximum: 16384,
166
+ shared: true
167
+ });
168
+ const instance = await compileAndInstantiate(memory, tSpan, "entry");
169
+ const exports = instance.exports;
170
+ await tSpan("entry.wasi_start", async () => {
171
+ wasi.start(instance);
172
+ });
173
+ if (isTracingEnabled() && typeof exports.init_tracing === "function") await tSpan("entry.init_tracing_rust", async () => {
174
+ exports.init_tracing();
175
+ });
176
+ const m = await tSpan("entry.wasm_main", async () => exports.wasm_main());
177
+ const reportString = await tSpan("entry.read_report_string", async () => readWasmString(exports, memory, m));
178
+ const report = JSON.parse(reportString);
179
+ let traceData = null;
180
+ if (isTracingEnabled() && typeof exports.get_trace_data === "function") await tSpan("entry.collect_rust_traces", async () => {
181
+ const traceJson = readWasmString(exports, memory, exports.get_trace_data());
182
+ try {
183
+ traceData = JSON.parse(traceJson);
184
+ } catch (e) {
185
+ console.error("[Tracing] Failed to parse trace data:", e);
186
+ }
187
+ if (typeof exports.clear_trace_data === "function") exports.clear_trace_data();
188
+ });
189
+ if (isTracingEnabled()) workerSpans.push({
190
+ name: "entry.worker_total",
191
+ start_ms: entry_start_ms,
192
+ end_ms: Date.now(),
193
+ worker_label: "entry"
194
+ });
195
+ node_worker_threads.parentPort?.postMessage({
196
+ cmd: "complete",
197
+ data: report,
198
+ traceData,
199
+ workerSpans
200
+ });
201
+ })();
202
+ else node_worker_threads.parentPort?.addListener("message", async ({ startArg, tid, memory }) => {
203
+ const workerLabel = `thread-${tid}`;
204
+ const handler_start_ms = Date.now();
205
+ const { workerSpans, tSpan } = makeSpanRecorder(workerLabel);
206
+ let instance = await compileAndInstantiate(memory, tSpan, "worker");
207
+ instance = createInstanceProxy(instance, memory);
208
+ await tSpan("worker.wasi_start", async () => {
209
+ wasi.start(instance);
210
+ });
211
+ await tSpan("worker.wasi_thread_start", async () => {
212
+ instance.exports.wasi_thread_start(tid, startArg);
213
+ }, { tid });
214
+ if (isTracingEnabled()) {
215
+ workerSpans.push({
216
+ name: "worker.thread_total",
217
+ start_ms: handler_start_ms,
218
+ end_ms: Date.now(),
219
+ worker_label: workerLabel,
220
+ attributes: { tid }
221
+ });
222
+ node_worker_threads.parentPort?.postMessage({
223
+ cmd: "worker-spans",
224
+ workerSpans
225
+ });
226
+ }
227
+ });
228
+ //#endregion
File without changes
File without changes