reg-cli 0.0.0-experimental-wasm0

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/cli.cjs ADDED
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ const index = require('./index.cjs');
4
+ require('node:events');
5
+ require('node:worker_threads');
6
+ require('./shared/reg-cli.566a78e6.cjs');
7
+ require('path');
8
+ require('url');
9
+ require('node:fs/promises');
10
+ require('node:path');
11
+
12
+ const emitter = index.run(process.argv.slice(2));
13
+ emitter.on("complete", (data) => {
14
+ console.log(data);
15
+ });
package/dist/cli.d.cts ADDED
@@ -0,0 +1,2 @@
1
+
2
+ export { }
package/dist/cli.d.mts ADDED
@@ -0,0 +1,2 @@
1
+
2
+ export { }
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+
2
+ export { }
package/dist/cli.mjs ADDED
@@ -0,0 +1,13 @@
1
+ import { run } from './index.mjs';
2
+ import 'node:events';
3
+ import 'node:worker_threads';
4
+ import './shared/reg-cli.2f9d9b15.mjs';
5
+ import 'path';
6
+ import 'url';
7
+ import 'node:fs/promises';
8
+ import 'node:path';
9
+
10
+ const emitter = run(process.argv.slice(2));
11
+ emitter.on("complete", (data) => {
12
+ console.log(data);
13
+ });
package/dist/entry.cjs ADDED
@@ -0,0 +1,67 @@
1
+ 'use strict';
2
+
3
+ const fs = require('node:fs');
4
+ const wasmUtil = require('@tybys/wasm-util');
5
+ const node_process = require('node:process');
6
+ const node_worker_threads = require('node:worker_threads');
7
+ const utils = require('./shared/reg-cli.566a78e6.cjs');
8
+ require('path');
9
+ require('url');
10
+ require('node:fs/promises');
11
+ require('node:path');
12
+
13
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
14
+
15
+ const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
16
+
17
+ const wasi = new wasmUtil.WASI({
18
+ version: "preview1",
19
+ args: node_worker_threads.workerData.argv,
20
+ env: node_process.env,
21
+ returnOnExit: true,
22
+ preopens: { "./": "./" },
23
+ fs: fs__default
24
+ });
25
+ const imports = wasi.getImportObject();
26
+ const file = utils.readWasm();
27
+ (async () => {
28
+ try {
29
+ const wasm = await WebAssembly.compile(await file);
30
+ const opts = { initial: 256, maximum: 16384, shared: true };
31
+ const memory = new WebAssembly.Memory(opts);
32
+ let instance = await WebAssembly.instantiate(wasm, {
33
+ ...imports,
34
+ wasi: {
35
+ "thread-spawn": (startArg) => {
36
+ const threadIdBuffer = new SharedArrayBuffer(4);
37
+ const id = new Int32Array(threadIdBuffer);
38
+ Atomics.store(id, 0, -1);
39
+ node_worker_threads.parentPort?.postMessage({
40
+ cmd: "thread-spawn",
41
+ startArg,
42
+ threadId: id,
43
+ memory
44
+ });
45
+ Atomics.wait(id, 0, -1);
46
+ const tid = Atomics.load(id, 0);
47
+ return tid;
48
+ }
49
+ },
50
+ env: { memory }
51
+ });
52
+ wasi.start(instance);
53
+ const m = instance.exports.wasm_main();
54
+ const view = new DataView(memory.buffer, m);
55
+ const len = view.getUint32(0, true);
56
+ const bufPtr = view.getUint32(4, true);
57
+ const stringData = new Uint8Array(memory.buffer, bufPtr, len);
58
+ const decoder = new TextDecoder("utf-8");
59
+ const string = decoder.decode(stringData);
60
+ instance.exports.free_wasm_output(m);
61
+ const report = JSON.parse(string);
62
+ console.log(report);
63
+ node_worker_threads.parentPort?.postMessage({ cmd: "complete", data: report });
64
+ } catch (e) {
65
+ throw e;
66
+ }
67
+ })();
@@ -0,0 +1,14 @@
1
+ type CompareOutput = {
2
+ failedItems: string[];
3
+ newItems: string[];
4
+ deletedItems: string[];
5
+ passedItems: string[];
6
+ expectedItems: string[];
7
+ actualItems: string[];
8
+ diffItems: string[];
9
+ actualDir: string;
10
+ expectedDir: string;
11
+ diffDir: string;
12
+ };
13
+
14
+ export type { CompareOutput };
@@ -0,0 +1,14 @@
1
+ type CompareOutput = {
2
+ failedItems: string[];
3
+ newItems: string[];
4
+ deletedItems: string[];
5
+ passedItems: string[];
6
+ expectedItems: string[];
7
+ actualItems: string[];
8
+ diffItems: string[];
9
+ actualDir: string;
10
+ expectedDir: string;
11
+ diffDir: string;
12
+ };
13
+
14
+ export type { CompareOutput };
@@ -0,0 +1,14 @@
1
+ type CompareOutput = {
2
+ failedItems: string[];
3
+ newItems: string[];
4
+ deletedItems: string[];
5
+ passedItems: string[];
6
+ expectedItems: string[];
7
+ actualItems: string[];
8
+ diffItems: string[];
9
+ actualDir: string;
10
+ expectedDir: string;
11
+ diffDir: string;
12
+ };
13
+
14
+ export type { CompareOutput };
package/dist/entry.mjs ADDED
@@ -0,0 +1,61 @@
1
+ import fs from 'node:fs';
2
+ import { WASI } from '@tybys/wasm-util';
3
+ import { env } from 'node:process';
4
+ import { workerData, parentPort } from 'node:worker_threads';
5
+ import { a as readWasm } from './shared/reg-cli.2f9d9b15.mjs';
6
+ import 'path';
7
+ import 'url';
8
+ import 'node:fs/promises';
9
+ import 'node:path';
10
+
11
+ const wasi = new WASI({
12
+ version: "preview1",
13
+ args: workerData.argv,
14
+ env,
15
+ returnOnExit: true,
16
+ preopens: { "./": "./" },
17
+ fs
18
+ });
19
+ const imports = wasi.getImportObject();
20
+ const file = readWasm();
21
+ (async () => {
22
+ try {
23
+ const wasm = await WebAssembly.compile(await file);
24
+ const opts = { initial: 256, maximum: 16384, shared: true };
25
+ const memory = new WebAssembly.Memory(opts);
26
+ let instance = await WebAssembly.instantiate(wasm, {
27
+ ...imports,
28
+ wasi: {
29
+ "thread-spawn": (startArg) => {
30
+ const threadIdBuffer = new SharedArrayBuffer(4);
31
+ const id = new Int32Array(threadIdBuffer);
32
+ Atomics.store(id, 0, -1);
33
+ parentPort?.postMessage({
34
+ cmd: "thread-spawn",
35
+ startArg,
36
+ threadId: id,
37
+ memory
38
+ });
39
+ Atomics.wait(id, 0, -1);
40
+ const tid = Atomics.load(id, 0);
41
+ return tid;
42
+ }
43
+ },
44
+ env: { memory }
45
+ });
46
+ wasi.start(instance);
47
+ const m = instance.exports.wasm_main();
48
+ const view = new DataView(memory.buffer, m);
49
+ const len = view.getUint32(0, true);
50
+ const bufPtr = view.getUint32(4, true);
51
+ const stringData = new Uint8Array(memory.buffer, bufPtr, len);
52
+ const decoder = new TextDecoder("utf-8");
53
+ const string = decoder.decode(stringData);
54
+ instance.exports.free_wasm_output(m);
55
+ const report = JSON.parse(string);
56
+ console.log(report);
57
+ parentPort?.postMessage({ cmd: "complete", data: report });
58
+ } catch (e) {
59
+ throw e;
60
+ }
61
+ })();
package/dist/index.cjs ADDED
@@ -0,0 +1,71 @@
1
+ 'use strict';
2
+
3
+ const EventEmitter = require('node:events');
4
+ const node_worker_threads = require('node:worker_threads');
5
+ const utils = require('./shared/reg-cli.566a78e6.cjs');
6
+ require('path');
7
+ require('url');
8
+ require('node:fs/promises');
9
+ require('node:path');
10
+
11
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
12
+
13
+ const EventEmitter__default = /*#__PURE__*/_interopDefaultCompat(EventEmitter);
14
+
15
+ const run = (argv) => {
16
+ const emitter = new EventEmitter__default();
17
+ const worker = new node_worker_threads.Worker(`./entry.${utils.resolveExtention()}`, { workerData: { argv } });
18
+ let nextTid = 1;
19
+ const workers = [worker];
20
+ const spawn = (startArg, threadId, memory) => {
21
+ const worker2 = new node_worker_threads.Worker(`./worker.${utils.resolveExtention()}`);
22
+ workers.push(worker2);
23
+ worker2.on("message", ({ cmd, startArg: startArg2, threadId: threadId2, memory: memory2 }) => {
24
+ if (cmd === "loaded") {
25
+ if (typeof worker2.unref === "function") {
26
+ worker2.unref();
27
+ }
28
+ } else if (cmd === "thread-spawn") {
29
+ spawn(startArg2, threadId2, memory2);
30
+ }
31
+ });
32
+ worker2.on("error", (e) => {
33
+ workers.forEach((w) => w.terminate());
34
+ throw new Error(e.message);
35
+ });
36
+ const tid = nextTid++;
37
+ if (threadId) {
38
+ Atomics.store(threadId, 0, tid);
39
+ Atomics.notify(threadId, 0);
40
+ }
41
+ worker2.postMessage({ startArg, tid, memory });
42
+ return tid;
43
+ };
44
+ worker.on("message", ({ cmd, startArg, threadId, memory, data }) => {
45
+ if (cmd === "complete") {
46
+ workers.forEach((w) => w.terminate());
47
+ emitter.emit("complete", data);
48
+ }
49
+ if (cmd === "loaded") {
50
+ if (typeof worker.unref === "function") {
51
+ worker.unref();
52
+ }
53
+ return;
54
+ }
55
+ if (cmd === "thread-spawn") {
56
+ spawn(startArg, threadId, memory);
57
+ }
58
+ });
59
+ worker.on("error", (err) => {
60
+ workers.forEach((w) => w.terminate());
61
+ throw new Error(err.message);
62
+ });
63
+ return emitter;
64
+ };
65
+ const compare = (input) => {
66
+ const args = Object.entries(input).flatMap(([k, v]) => [k, String(v)]);
67
+ return run(args);
68
+ };
69
+
70
+ exports.compare = compare;
71
+ exports.run = run;
@@ -0,0 +1,36 @@
1
+ import EventEmitter from 'node:events';
2
+
3
+ declare const run: (argv: string[]) => EventEmitter;
4
+ type CompareInput = {
5
+ actualDir: string;
6
+ expectedDir: string;
7
+ diffDir: string;
8
+ report?: string;
9
+ junitReport?: string;
10
+ json?: string;
11
+ update?: boolean;
12
+ extendedErrors?: boolean;
13
+ urlPrefix?: string;
14
+ matchingThreshold?: number;
15
+ threshold?: number;
16
+ thresholdRate?: number;
17
+ thresholdPixel?: number;
18
+ concurrency?: number;
19
+ enableAntialias?: boolean;
20
+ enableClientAdditionalDetection?: boolean;
21
+ };
22
+ type CompareOutput = {
23
+ failedItems: string[];
24
+ newItems: string[];
25
+ deletedItems: string[];
26
+ passedItems: string[];
27
+ expectedItems: string[];
28
+ actualItems: string[];
29
+ diffItems: string[];
30
+ actualDir: string;
31
+ expectedDir: string;
32
+ diffDir: string;
33
+ };
34
+ declare const compare: (input: CompareInput) => EventEmitter;
35
+
36
+ export { type CompareInput, type CompareOutput, compare, run };
@@ -0,0 +1,36 @@
1
+ import EventEmitter from 'node:events';
2
+
3
+ declare const run: (argv: string[]) => EventEmitter;
4
+ type CompareInput = {
5
+ actualDir: string;
6
+ expectedDir: string;
7
+ diffDir: string;
8
+ report?: string;
9
+ junitReport?: string;
10
+ json?: string;
11
+ update?: boolean;
12
+ extendedErrors?: boolean;
13
+ urlPrefix?: string;
14
+ matchingThreshold?: number;
15
+ threshold?: number;
16
+ thresholdRate?: number;
17
+ thresholdPixel?: number;
18
+ concurrency?: number;
19
+ enableAntialias?: boolean;
20
+ enableClientAdditionalDetection?: boolean;
21
+ };
22
+ type CompareOutput = {
23
+ failedItems: string[];
24
+ newItems: string[];
25
+ deletedItems: string[];
26
+ passedItems: string[];
27
+ expectedItems: string[];
28
+ actualItems: string[];
29
+ diffItems: string[];
30
+ actualDir: string;
31
+ expectedDir: string;
32
+ diffDir: string;
33
+ };
34
+ declare const compare: (input: CompareInput) => EventEmitter;
35
+
36
+ export { type CompareInput, type CompareOutput, compare, run };
@@ -0,0 +1,36 @@
1
+ import EventEmitter from 'node:events';
2
+
3
+ declare const run: (argv: string[]) => EventEmitter;
4
+ type CompareInput = {
5
+ actualDir: string;
6
+ expectedDir: string;
7
+ diffDir: string;
8
+ report?: string;
9
+ junitReport?: string;
10
+ json?: string;
11
+ update?: boolean;
12
+ extendedErrors?: boolean;
13
+ urlPrefix?: string;
14
+ matchingThreshold?: number;
15
+ threshold?: number;
16
+ thresholdRate?: number;
17
+ thresholdPixel?: number;
18
+ concurrency?: number;
19
+ enableAntialias?: boolean;
20
+ enableClientAdditionalDetection?: boolean;
21
+ };
22
+ type CompareOutput = {
23
+ failedItems: string[];
24
+ newItems: string[];
25
+ deletedItems: string[];
26
+ passedItems: string[];
27
+ expectedItems: string[];
28
+ actualItems: string[];
29
+ diffItems: string[];
30
+ actualDir: string;
31
+ expectedDir: string;
32
+ diffDir: string;
33
+ };
34
+ declare const compare: (input: CompareInput) => EventEmitter;
35
+
36
+ export { type CompareInput, type CompareOutput, compare, run };
package/dist/index.mjs ADDED
@@ -0,0 +1,64 @@
1
+ import EventEmitter from 'node:events';
2
+ import { Worker } from 'node:worker_threads';
3
+ import { r as resolveExtention } from './shared/reg-cli.2f9d9b15.mjs';
4
+ import 'path';
5
+ import 'url';
6
+ import 'node:fs/promises';
7
+ import 'node:path';
8
+
9
+ const run = (argv) => {
10
+ const emitter = new EventEmitter();
11
+ const worker = new Worker(`./entry.${resolveExtention()}`, { workerData: { argv } });
12
+ let nextTid = 1;
13
+ const workers = [worker];
14
+ const spawn = (startArg, threadId, memory) => {
15
+ const worker2 = new Worker(`./worker.${resolveExtention()}`);
16
+ workers.push(worker2);
17
+ worker2.on("message", ({ cmd, startArg: startArg2, threadId: threadId2, memory: memory2 }) => {
18
+ if (cmd === "loaded") {
19
+ if (typeof worker2.unref === "function") {
20
+ worker2.unref();
21
+ }
22
+ } else if (cmd === "thread-spawn") {
23
+ spawn(startArg2, threadId2, memory2);
24
+ }
25
+ });
26
+ worker2.on("error", (e) => {
27
+ workers.forEach((w) => w.terminate());
28
+ throw new Error(e.message);
29
+ });
30
+ const tid = nextTid++;
31
+ if (threadId) {
32
+ Atomics.store(threadId, 0, tid);
33
+ Atomics.notify(threadId, 0);
34
+ }
35
+ worker2.postMessage({ startArg, tid, memory });
36
+ return tid;
37
+ };
38
+ worker.on("message", ({ cmd, startArg, threadId, memory, data }) => {
39
+ if (cmd === "complete") {
40
+ workers.forEach((w) => w.terminate());
41
+ emitter.emit("complete", data);
42
+ }
43
+ if (cmd === "loaded") {
44
+ if (typeof worker.unref === "function") {
45
+ worker.unref();
46
+ }
47
+ return;
48
+ }
49
+ if (cmd === "thread-spawn") {
50
+ spawn(startArg, threadId, memory);
51
+ }
52
+ });
53
+ worker.on("error", (err) => {
54
+ workers.forEach((w) => w.terminate());
55
+ throw new Error(err.message);
56
+ });
57
+ return emitter;
58
+ };
59
+ const compare = (input) => {
60
+ const args = Object.entries(input).flatMap(([k, v]) => [k, String(v)]);
61
+ return run(args);
62
+ };
63
+
64
+ export { compare, run };
@@ -0,0 +1,16 @@
1
+ import path from 'path';
2
+ import { fileURLToPath } from 'url';
3
+ import { readFile } from 'node:fs/promises';
4
+ import { join } from 'node:path';
5
+
6
+ const isESM = typeof import.meta !== "undefined";
7
+ const readWasm = () => {
8
+ const dir = isESM ? path.dirname(fileURLToPath(import.meta.url)) : __dirname;
9
+ const file = readFile(join(dir, "./reg.wasm"));
10
+ return file;
11
+ };
12
+ const resolveExtention = () => {
13
+ return isESM ? "mjs" : "cjs";
14
+ };
15
+
16
+ export { readWasm as a, resolveExtention as r };
@@ -0,0 +1,24 @@
1
+ 'use strict';
2
+
3
+ const path = require('path');
4
+ const url = require('url');
5
+ const promises = require('node:fs/promises');
6
+ const node_path = require('node:path');
7
+
8
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
9
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
10
+
11
+ const path__default = /*#__PURE__*/_interopDefaultCompat(path);
12
+
13
+ const isESM = typeof ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/reg-cli.566a78e6.cjs', document.baseURI).href)) }) !== "undefined";
14
+ const readWasm = () => {
15
+ const dir = isESM ? path__default.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/reg-cli.566a78e6.cjs', document.baseURI).href)))) : __dirname;
16
+ const file = promises.readFile(node_path.join(dir, "./reg.wasm"));
17
+ return file;
18
+ };
19
+ const resolveExtention = () => {
20
+ return isESM ? "mjs" : "cjs";
21
+ };
22
+
23
+ exports.readWasm = readWasm;
24
+ exports.resolveExtention = resolveExtention;
Binary file
@@ -0,0 +1,119 @@
1
+ 'use strict';
2
+
3
+ const node_worker_threads = require('node:worker_threads');
4
+ const fs = require('node:fs');
5
+ const wasmUtil = require('@tybys/wasm-util');
6
+ const node_process = require('node:process');
7
+ const utils = require('./shared/reg-cli.566a78e6.cjs');
8
+ require('path');
9
+ require('url');
10
+ require('node:fs/promises');
11
+ require('node:path');
12
+
13
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
14
+
15
+ const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
16
+
17
+ const kIsProxy = Symbol("kIsProxy");
18
+ const createInstanceProxy = (instance, memory) => {
19
+ if (instance[kIsProxy])
20
+ return instance;
21
+ const originalExports = instance.exports;
22
+ const createHandler = function(target) {
23
+ const handlers = [
24
+ "apply",
25
+ "construct",
26
+ "defineProperty",
27
+ "deleteProperty",
28
+ "get",
29
+ "getOwnPropertyDescriptor",
30
+ "getPrototypeOf",
31
+ "has",
32
+ "isExtensible",
33
+ "ownKeys",
34
+ "preventExtensions",
35
+ "set",
36
+ "setPrototypeOf"
37
+ ];
38
+ const handler2 = {};
39
+ for (let i = 0; i < handlers.length; i++) {
40
+ const name = handlers[i];
41
+ handler2[name] = function() {
42
+ const args = Array.prototype.slice.call(arguments, 1);
43
+ args.unshift(target);
44
+ return Reflect[name].apply(Reflect, args);
45
+ };
46
+ }
47
+ return handler2;
48
+ };
49
+ const handler = createHandler(originalExports);
50
+ const _initialize = () => {
51
+ };
52
+ const _start = () => 0;
53
+ handler.get = function(_target, p, receiver) {
54
+ if (p === "memory") {
55
+ return (typeof memory === "function" ? memory() : memory) ?? Reflect.get(originalExports, p, receiver);
56
+ }
57
+ if (p === "_initialize") {
58
+ return p in originalExports ? _initialize : void 0;
59
+ }
60
+ if (p === "_start") {
61
+ return p in originalExports ? _start : void 0;
62
+ }
63
+ return Reflect.get(originalExports, p, receiver);
64
+ };
65
+ handler.has = function(_target, p) {
66
+ if (p === "memory")
67
+ return true;
68
+ return Reflect.has(originalExports, p);
69
+ };
70
+ const exportsProxy = new Proxy(/* @__PURE__ */ Object.create(null), handler);
71
+ return new Proxy(instance, {
72
+ get(target, p, receiver) {
73
+ if (p === "exports") {
74
+ return exportsProxy;
75
+ }
76
+ if (p === kIsProxy) {
77
+ return true;
78
+ }
79
+ return Reflect.get(target, p, receiver);
80
+ }
81
+ });
82
+ };
83
+
84
+ const wasi = new wasmUtil.WASI({
85
+ version: "preview1",
86
+ args: node_process.argv,
87
+ env: node_process.env,
88
+ returnOnExit: true,
89
+ preopens: { "./": "./" },
90
+ fs: fs__default
91
+ });
92
+ const imports = wasi.getImportObject();
93
+ const file = utils.readWasm();
94
+ const handler = async ({ startArg, tid, memory }) => {
95
+ try {
96
+ const wasm = await WebAssembly.compile(await file);
97
+ let instance = await WebAssembly.instantiate(wasm, {
98
+ ...imports,
99
+ wasi: {
100
+ "thread-spawn": (startArg2) => {
101
+ const threadIdBuffer = new SharedArrayBuffer(4);
102
+ const id = new Int32Array(threadIdBuffer);
103
+ Atomics.store(id, 0, -1);
104
+ postMessage({ cmd: "thread-spawn", startArg: startArg2, threadId: id, memory });
105
+ Atomics.wait(id, 0, -1);
106
+ const tid2 = Atomics.load(id, 0);
107
+ return tid2;
108
+ }
109
+ },
110
+ env: { memory }
111
+ });
112
+ instance = createInstanceProxy(instance, memory);
113
+ wasi.start(instance);
114
+ instance.exports.wasi_thread_start(tid, startArg);
115
+ } catch (e) {
116
+ throw e;
117
+ }
118
+ };
119
+ node_worker_threads.parentPort?.addListener("message", handler);
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -0,0 +1,113 @@
1
+ import { parentPort } from 'node:worker_threads';
2
+ import fs from 'node:fs';
3
+ import { WASI } from '@tybys/wasm-util';
4
+ import { argv, env } from 'node:process';
5
+ import { a as readWasm } from './shared/reg-cli.2f9d9b15.mjs';
6
+ import 'path';
7
+ import 'url';
8
+ import 'node:fs/promises';
9
+ import 'node:path';
10
+
11
+ const kIsProxy = Symbol("kIsProxy");
12
+ const createInstanceProxy = (instance, memory) => {
13
+ if (instance[kIsProxy])
14
+ return instance;
15
+ const originalExports = instance.exports;
16
+ const createHandler = function(target) {
17
+ const handlers = [
18
+ "apply",
19
+ "construct",
20
+ "defineProperty",
21
+ "deleteProperty",
22
+ "get",
23
+ "getOwnPropertyDescriptor",
24
+ "getPrototypeOf",
25
+ "has",
26
+ "isExtensible",
27
+ "ownKeys",
28
+ "preventExtensions",
29
+ "set",
30
+ "setPrototypeOf"
31
+ ];
32
+ const handler2 = {};
33
+ for (let i = 0; i < handlers.length; i++) {
34
+ const name = handlers[i];
35
+ handler2[name] = function() {
36
+ const args = Array.prototype.slice.call(arguments, 1);
37
+ args.unshift(target);
38
+ return Reflect[name].apply(Reflect, args);
39
+ };
40
+ }
41
+ return handler2;
42
+ };
43
+ const handler = createHandler(originalExports);
44
+ const _initialize = () => {
45
+ };
46
+ const _start = () => 0;
47
+ handler.get = function(_target, p, receiver) {
48
+ if (p === "memory") {
49
+ return (typeof memory === "function" ? memory() : memory) ?? Reflect.get(originalExports, p, receiver);
50
+ }
51
+ if (p === "_initialize") {
52
+ return p in originalExports ? _initialize : void 0;
53
+ }
54
+ if (p === "_start") {
55
+ return p in originalExports ? _start : void 0;
56
+ }
57
+ return Reflect.get(originalExports, p, receiver);
58
+ };
59
+ handler.has = function(_target, p) {
60
+ if (p === "memory")
61
+ return true;
62
+ return Reflect.has(originalExports, p);
63
+ };
64
+ const exportsProxy = new Proxy(/* @__PURE__ */ Object.create(null), handler);
65
+ return new Proxy(instance, {
66
+ get(target, p, receiver) {
67
+ if (p === "exports") {
68
+ return exportsProxy;
69
+ }
70
+ if (p === kIsProxy) {
71
+ return true;
72
+ }
73
+ return Reflect.get(target, p, receiver);
74
+ }
75
+ });
76
+ };
77
+
78
+ const wasi = new WASI({
79
+ version: "preview1",
80
+ args: argv,
81
+ env,
82
+ returnOnExit: true,
83
+ preopens: { "./": "./" },
84
+ fs
85
+ });
86
+ const imports = wasi.getImportObject();
87
+ const file = readWasm();
88
+ const handler = async ({ startArg, tid, memory }) => {
89
+ try {
90
+ const wasm = await WebAssembly.compile(await file);
91
+ let instance = await WebAssembly.instantiate(wasm, {
92
+ ...imports,
93
+ wasi: {
94
+ "thread-spawn": (startArg2) => {
95
+ const threadIdBuffer = new SharedArrayBuffer(4);
96
+ const id = new Int32Array(threadIdBuffer);
97
+ Atomics.store(id, 0, -1);
98
+ postMessage({ cmd: "thread-spawn", startArg: startArg2, threadId: id, memory });
99
+ Atomics.wait(id, 0, -1);
100
+ const tid2 = Atomics.load(id, 0);
101
+ return tid2;
102
+ }
103
+ },
104
+ env: { memory }
105
+ });
106
+ instance = createInstanceProxy(instance, memory);
107
+ wasi.start(instance);
108
+ instance.exports.wasi_thread_start(tid, startArg);
109
+ } catch (e) {
110
+ throw e;
111
+ }
112
+ };
113
+ parentPort?.addListener("message", handler);
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "reg-cli",
3
+ "version": "0.0.0-experimental-wasm0",
4
+ "description": "",
5
+ "type": "module",
6
+ "start": "node ./dist/cli.mjs",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.mjs",
11
+ "require": "./dist/index.cjs"
12
+ }
13
+ },
14
+ "engines": {
15
+ "node": ">=18"
16
+ },
17
+ "main": "./dist/index.cjs",
18
+ "module": "./dist/index.mjs",
19
+ "types": "./dist/index.d.ts",
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "bin": {
24
+ "reg-cli": "./dist/cli.mjs"
25
+ },
26
+ "scripts": {
27
+ "build": "unbuild && cp reg.wasm ./dist/shared/reg.wasm"
28
+ },
29
+ "keywords": [],
30
+ "author": "bokuweb",
31
+ "license": "MIT",
32
+ "dependencies": {
33
+ "@tybys/wasm-util": "^0.9.0"
34
+ },
35
+ "devDependencies": {
36
+ "@types/node": "^22.5.5",
37
+ "unbuild": "^2.0.0"
38
+ }
39
+ }