@remix_labs/machine-starter 2.11935.0-dev → 2.11939.0-dev

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/common.js CHANGED
@@ -117,7 +117,7 @@ globalThis.MixSetMask = (m => {
117
117
  }
118
118
  });
119
119
 
120
- function StartWASM(hub, baseURL, org, workspace, vmID, user, token, noOutputViaMQTT, getWorker) {
120
+ function StartWASM(hub, baseURL, org, workspace, vmID, user, token, noOutputViaMQTT) {
121
121
  return StartWASM2(hub, {
122
122
  baseURL: baseURL,
123
123
  org: org,
@@ -125,17 +125,17 @@ function StartWASM(hub, baseURL, org, workspace, vmID, user, token, noOutputViaM
125
125
  token: token,
126
126
  noOutputViaMQTT: noOutputViaMQTT,
127
127
  machType: "WASM"
128
- }, getWorker)
128
+ })
129
129
  }
130
130
 
131
- async function StartWASM2(hub, config, getWorker) {
131
+ async function StartWASM2(hub, config) {
132
132
  if (!last_hub) {
133
133
  console.log("[machine-starter] Call MixExplain() for explaining debug levels, and MixSetMask(m) for changing these")
134
134
  };
135
135
  last_hub = hub;
136
136
  let channel = await hub.newChannel();
137
137
  // injected by either index.js or node.js
138
- let worker = getWorker();
138
+ let worker = globalThis.GetMachineWASMWorker();
139
139
  if (workers[config.vmID] || ffiLoops[config.vmID])
140
140
  throw new Error("Cannot start VM, the ID is used: " + config.vmID);
141
141
  workers[config.vmID] = worker;
@@ -163,7 +163,7 @@ async function StartWASM2(hub, config, getWorker) {
163
163
  };
164
164
  let vm_kind = { isRaw:false, canFail:false, useJsonDecoder:false};
165
165
  starterFFIkind["$vm_start"] = vm_kind;
166
- starterFFIfuns["$vm_start"] = (conn, args) => ffi_vm_start(conn, args, getWorker);
166
+ starterFFIfuns["$vm_start"] = ffi_vm_start;
167
167
  starterFFIkind["$vm_stop"] = vm_kind;
168
168
  starterFFIfuns["$vm_stop"] = ffi_vm_stop;
169
169
  let mixrtCode = config.mixrtCode;
@@ -218,7 +218,7 @@ async function mixcoreStarterFFIs(mixcore) {
218
218
  return ffis;
219
219
  }
220
220
 
221
- async function ffi_vm_start(conn, args, getWorker) {
221
+ async function ffi_vm_start(conn, args) {
222
222
  let vm_id = "embedded." + nanoid();
223
223
  console.log("[machine-starter] starting VM: ", vm_id);
224
224
  let config = {};
@@ -234,7 +234,7 @@ async function ffi_vm_start(conn, args, getWorker) {
234
234
  config["interceptFFI"] = arg_config.interceptFFI;
235
235
  if (arg_config.interceptDynloadFFI !== undefined)
236
236
  config["interceptDynloadFFI"] = arg_config.interceptDynloadFFI;
237
- let worker = await StartWASM2(conn.hub, config, getWorker);
237
+ let worker = await StartWASM2(conn.hub, config);
238
238
  return vm_id;
239
239
  }
240
240
 
@@ -1,2 +1,2 @@
1
- var GROOVEBOX_BUILD = "11935";
1
+ var GROOVEBOX_BUILD = "11939";
2
2
  export { GROOVEBOX_BUILD }
package/index.js CHANGED
@@ -1 +1,12 @@
1
+ import MachineWASMWorker from './machine-wasm.worker.mjs'
2
+
3
+ const blob = new Blob([MachineWASMWorker], {type: 'application/javascript'});
4
+ const url = URL.createObjectURL(blob);
5
+
6
+ function GetMachineWASMWorker() {
7
+ return new Worker(url);
8
+ }
9
+
10
+ globalThis.GetMachineWASMWorker = GetMachineWASMWorker;
11
+
1
12
  export * from './common.js';
package/node.js CHANGED
@@ -5,6 +5,26 @@ globalThis.console = new Console.Console({stdout: process.stderr, stderr: proces
5
5
  // redirect stdout to stderr to avoid that log messages appear in the wrong
6
6
  // order
7
7
 
8
+ // NB: The only way I've made this work in node+webpack is if:
9
+ //
10
+ // * we use Worker from worker_threads directly
11
+ // * we build each worker's module with webpack as an ESM .mjs bundle
12
+ // * we put all the bundles in one directory
13
+ // * we load the worker with a URL('./foo.mjs')
14
+ //
15
+ // Other ways to package/load might work, but definitely seems like
16
+ // using worker_threads.Worker directly is needed (rather than through,
17
+ // say, the web-worker packages that wraps either worker_threads.Worker
18
+ // or the browser Worker to give the same interface). Webpack says ESM
19
+ // is necessary but I'm not sure if this is true for either the main
20
+ // script or the workers.
21
+ import { Worker } from "worker_threads";
22
+
23
+ function GetMachineWASMWorker() {
24
+ return new Worker(new URL("./machine-wasm.node.mjs", import.meta.url));
25
+ }
26
+ globalThis.GetMachineWASMWorker = GetMachineWASMWorker;
27
+
8
28
  // Can't just `export *` because we need hub-client below in common.js
9
29
  import * as Hub from "@remix_labs/hub-client";
10
30
  export { Hub };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remix_labs/machine-starter",
3
- "version": "2.11935.0-dev",
3
+ "version": "2.11939.0-dev",
4
4
  "description": "start the groove",
5
5
  "main": "node.js",
6
6
  "browser": "index.js",
@@ -11,7 +11,7 @@
11
11
  "author": "Remixlabs staff",
12
12
  "license": "ISC",
13
13
  "dependencies": {
14
- "@remix_labs/hub-client": "2.11935.0-dev",
14
+ "@remix_labs/hub-client": "2.11939.0-dev",
15
15
  "nanoid": "^5.0.2",
16
16
  "web-worker": "^1.2.0"
17
17
  },
package/start.js CHANGED
@@ -1,8 +1,6 @@
1
1
  import Process from "process";
2
- import { Worker } from "worker_threads";
3
2
  import { StartWASM2, Hub } from "./node.js";
4
3
  import { mixcoreWasmBase64, mixcoreJsBase64 } from './mixcore-wasm-inmem.js';
5
- import MachineWASMWorkerString from './machine-wasm.worker.mjs'
6
4
 
7
5
  if (Process.stdout._handle)
8
6
  Process.stdout._handle.setBlocking(true);
@@ -50,25 +48,6 @@ let mixcore = {
50
48
  dbName: "compiler-testing",
51
49
  createDbs: ["compiler-testing"],
52
50
  };
53
-
54
- // comment from start.js (before https://github.com/remixlabs/mix-rs/pull/1129):
55
- //
56
- // NB: The only way I've made this work in node+webpack is if:
57
- //
58
- // * we use Worker from worker_threads directly
59
- // * we build each worker's module with webpack as an ESM .mjs bundle
60
- // * we put all the bundles in one directory
61
- // * we load the worker with a URL('./foo.mjs')
62
- //
63
- // Other ways to package/load might work, but definitely seems like
64
- // using worker_threads.Worker directly is needed (rather than through,
65
- // say, the web-worker packages that wraps either worker_threads.Worker
66
- // or the browser Worker to give the same interface). Webpack says ESM
67
- // is necessary but I'm not sure if this is true for either the main
68
- // script or the workers.
69
- let workerUrl = "data:text/javascript," + encodeURIComponent(MachineWASMWorkerString);
70
- let getMachineWorker = () => new Worker(workerUrl);
71
-
72
51
  w.configure({wsURL: mqttURL, user:mqttUser, token:mqttToken}).then(resp => {
73
52
  if (variant == "BYTE") variant = "QCODE";
74
53
  switch(variant) {
@@ -88,7 +67,7 @@ w.configure({wsURL: mqttURL, user:mqttUser, token:mqttToken}).then(resp => {
88
67
  machType: variant,
89
68
  localFFIs: {},
90
69
  mixcore,
91
- }, getMachineWorker);
70
+ });
92
71
  });
93
72
  if (globalThis.EnableAndStartMixCompiler) {
94
73
  EnableAndStartMixCompiler(w).then(startVM);