@aethervtt/shard-physics 0.1.0 → 0.2.0

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.
@@ -0,0 +1,11 @@
1
+ import type { TrackWorkerLike } from './client.js';
2
+ /**
3
+ * Runs the TypeScript worker entry at `entry` in a worker thread, through the web Worker interface
4
+ * the track client expects. Needs `tsx` installed.
5
+ *
6
+ * The thread registers tsx itself before it imports the entry. `--import tsx` in `execArgv` is not
7
+ * enough: tsx registers its hooks in a worker thread only on Node 22.22.3 and later (where it can
8
+ * tell a worker from Node's own loader thread). On earlier 22.x it skips them, and Node's built-in
9
+ * type stripping then loads the entry and fails on its extensionless imports.
10
+ */
11
+ export declare function nodeTrackWorker(entry: URL): TrackWorkerLike;
@@ -0,0 +1,26 @@
1
+ import { Worker } from "node:worker_threads";
2
+ function nodeTrackWorker(entry) {
3
+ const tsx = JSON.stringify(import.meta.resolve("tsx/esm/api"));
4
+ const worker = new Worker(
5
+ `import(${tsx}).then((tsx) => { tsx.register(); return import(${JSON.stringify(entry.href)}) })`,
6
+ { eval: true }
7
+ );
8
+ const listeners = {
9
+ message: [],
10
+ error: [],
11
+ messageerror: []
12
+ };
13
+ const emit = (type, event) => {
14
+ for (const listener of listeners[type]) listener(event);
15
+ };
16
+ worker.on("message", (data) => emit("message", { data }));
17
+ worker.on("error", (err) => emit("error", { type: "error", message: err.message }));
18
+ return {
19
+ postMessage: (message, transfer) => worker.postMessage(message, transfer),
20
+ addEventListener: (type, listener) => void listeners[type].push(listener),
21
+ terminate: () => void worker.terminate()
22
+ };
23
+ }
24
+ export {
25
+ nodeTrackWorker
26
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aethervtt/shard-physics",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -20,6 +20,10 @@
20
20
  "./worker": {
21
21
  "types": "./dist/worker/index.d.ts",
22
22
  "default": "./dist/worker/index.js"
23
+ },
24
+ "./worker/testing": {
25
+ "types": "./dist/worker/testing.d.ts",
26
+ "default": "./dist/worker/testing.js"
23
27
  }
24
28
  },
25
29
  "files": [
@@ -28,12 +32,12 @@
28
32
  "README.md"
29
33
  ],
30
34
  "dependencies": {
31
- "@aethervtt/shard-assets": "0.1.0",
32
- "@aethervtt/shard-core": "0.1.0",
33
- "@aethervtt/shard-mesh": "0.1.0",
34
- "@aethervtt/shard-render": "0.1.0",
35
- "@aethervtt/shard-runtime": "0.1.0",
36
- "@aethervtt/shard-transform": "0.1.0",
35
+ "@aethervtt/shard-assets": "0.2.0",
36
+ "@aethervtt/shard-core": "0.2.0",
37
+ "@aethervtt/shard-mesh": "0.2.0",
38
+ "@aethervtt/shard-render": "0.2.0",
39
+ "@aethervtt/shard-runtime": "0.2.0",
40
+ "@aethervtt/shard-transform": "0.2.0",
37
41
  "@dimforge/rapier2d-compat": "0.20.0",
38
42
  "@dimforge/rapier2d-deterministic-compat": "0.20.0",
39
43
  "@dimforge/rapier3d-compat": "0.20.0",
@@ -49,6 +53,6 @@
49
53
  "provenance": true
50
54
  },
51
55
  "shard": {
52
- "buildSha": "8e14c9896f82a3554b156f1ffdd68f2cc3e7d78a"
56
+ "buildSha": "32c22a3944ed23f5d1baa90bf7cc9fae724f5fd8"
53
57
  }
54
58
  }