@utoo/web 1.2.0-rc.3 → 1.2.0-rc.4

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.
@@ -1,3 +1,3 @@
1
1
  import { Binding } from "./type";
2
2
  import { Project as ProjectInternal } from "./utoo";
3
- export declare const runLoaderWorkerPool: (binding: Binding, projectCwd: string, projectInternal: ProjectInternal, workerUrl: string, loadersImportMap?: Record<string, string>) => Promise<void>;
3
+ export declare const runLoaderWorkerPool: (binding: Binding, projectCwd: string, projectInternal: ProjectInternal, loaderWorkerUrl: string, loadersImportMap?: Record<string, string>) => Promise<void>;
@@ -1,75 +1,28 @@
1
- import { SAB_OP_COPY_FILE, SAB_OP_MKDIR, SAB_OP_READ_DIR, SAB_OP_READ_FILE, SAB_OP_RM, SAB_OP_RMDIR, SAB_OP_WRITE_FILE, SabComHost, } from "./sabcom";
1
+ import * as sabcom from "./sabcom";
2
2
  import initWasm, { registerWorkerScheduler, workerCreated, } from "./utoo";
3
3
  let nextWorkerId = 0;
4
4
  const loaderWorkers = {};
5
- export const runLoaderWorkerPool = async (binding, projectCwd, projectInternal, workerUrl, loadersImportMap) => {
5
+ export const runLoaderWorkerPool = async (binding, projectCwd, projectInternal, loaderWorkerUrl, loadersImportMap) => {
6
6
  registerWorkerScheduler(async (creation) => {
7
7
  const { options: { filename, cwd }, } = creation;
8
8
  nextWorkerId += 1;
9
9
  const workerId = nextWorkerId;
10
10
  const sab = new SharedArrayBuffer(1024 * 1024 * 10); // 10MB
11
- const sabHost = new SabComHost(sab);
12
- const worker = new Worker(workerUrl, { name: filename });
11
+ const sabHost = new sabcom.SabComHost(sab);
12
+ const worker = new Worker(loaderWorkerUrl, { name: filename });
13
13
  worker.onmessage = async (event) => {
14
14
  if (event.data === "sab_request") {
15
- const { op, data: path } = sabHost.readRequest();
16
- try {
17
- if (op === SAB_OP_READ_FILE) {
18
- const bytes = await projectInternal.read(path);
19
- sabHost.writeResponse(bytes);
20
- }
21
- else if (op === SAB_OP_READ_DIR) {
22
- const entries = await projectInternal.readDir(path);
23
- sabHost.writeResponse(JSON.stringify(entries.map((e) => e.toJSON())));
24
- }
25
- else if (op === SAB_OP_WRITE_FILE) {
26
- const { content, encoding } = JSON.parse(path);
27
- const filePath = content.path;
28
- const fileContent = content.data;
29
- // TODO: handle binary content (base64?)
30
- await projectInternal.writeString(filePath, fileContent);
31
- sabHost.writeResponse("ok");
32
- }
33
- else if (op === SAB_OP_MKDIR) {
34
- const { path: dirPath, recursive } = JSON.parse(path);
35
- if (recursive) {
36
- await projectInternal.createDirAll(dirPath);
37
- }
38
- else {
39
- await projectInternal.createDir(dirPath);
40
- }
41
- sabHost.writeResponse("ok");
42
- }
43
- else if (op === SAB_OP_RM) {
44
- const { path: rmPath, recursive } = JSON.parse(path);
45
- // Mimic internalProject.rm logic
46
- const metadata = await projectInternal.metadata(rmPath);
47
- const type = metadata.toJSON().type;
48
- if (type === "file") {
49
- await projectInternal.removeFile(rmPath);
50
- }
51
- else if (type === "directory") {
52
- await projectInternal.removeDir(rmPath, !!recursive);
53
- }
54
- sabHost.writeResponse("ok");
55
- }
56
- else if (op === SAB_OP_RMDIR) {
57
- const { path: rmPath, recursive } = JSON.parse(path);
58
- await projectInternal.removeDir(rmPath, !!recursive);
59
- sabHost.writeResponse("ok");
60
- }
61
- else if (op === SAB_OP_COPY_FILE) {
62
- const { src, dst } = JSON.parse(path);
63
- await projectInternal.copyFile(src, dst);
64
- sabHost.writeResponse("ok");
65
- }
66
- else {
67
- sabHost.writeError("Unknown op");
68
- }
69
- }
70
- catch (e) {
71
- sabHost.writeError(e.message);
72
- }
15
+ await sabcom.handleSabRequest(sabHost, {
16
+ read: (path) => projectInternal.read(path),
17
+ readDir: (path) => projectInternal.readDir(path),
18
+ writeString: (path, content) => projectInternal.writeString(path, content),
19
+ createDirAll: (path) => projectInternal.createDirAll(path),
20
+ createDir: (path) => projectInternal.createDir(path),
21
+ metadata: (path) => projectInternal.metadata(path),
22
+ removeFile: (path) => projectInternal.removeFile(path),
23
+ removeDir: (path, recursive) => projectInternal.removeDir(path, recursive),
24
+ copyFile: (src, dst) => projectInternal.copyFile(src, dst),
25
+ });
73
26
  }
74
27
  };
75
28
  let finalCwd = cwd;
package/esm/sabcom.d.ts CHANGED
@@ -9,6 +9,7 @@ export declare const SAB_OP_MKDIR = 4;
9
9
  export declare const SAB_OP_RM = 5;
10
10
  export declare const SAB_OP_RMDIR = 6;
11
11
  export declare const SAB_OP_COPY_FILE = 7;
12
+ export declare const SAB_OP_STAT = 8;
12
13
  export declare class SabComHost {
13
14
  private sab;
14
15
  private int32;
@@ -29,3 +30,15 @@ export declare class SabComClient {
29
30
  constructor(sab: SharedArrayBuffer, notifyHost: () => void);
30
31
  call(op: number, data: string): Uint8Array<ArrayBuffer>;
31
32
  }
33
+ export interface SabFileSystem {
34
+ read(path: string): Promise<Uint8Array>;
35
+ readDir(path: string): Promise<any[]>;
36
+ writeString(path: string, content: string): Promise<void>;
37
+ createDirAll(path: string): Promise<void>;
38
+ createDir(path: string): Promise<void>;
39
+ metadata(path: string): Promise<any>;
40
+ removeFile(path: string): Promise<void>;
41
+ removeDir(path: string, recursive: boolean): Promise<void>;
42
+ copyFile(src: string, dst: string): Promise<void>;
43
+ }
44
+ export declare const handleSabRequest: (sabHost: SabComHost, fs: SabFileSystem) => Promise<void>;
package/esm/sabcom.js CHANGED
@@ -9,6 +9,7 @@ export const SAB_OP_MKDIR = 4;
9
9
  export const SAB_OP_RM = 5;
10
10
  export const SAB_OP_RMDIR = 6;
11
11
  export const SAB_OP_COPY_FILE = 7;
12
+ export const SAB_OP_STAT = 8;
12
13
  // Layout:
13
14
  // 0: State (Int32)
14
15
  // 1: Op (Int32)
@@ -69,3 +70,67 @@ export class SabComClient {
69
70
  return this.uint8.slice(12, 12 + len);
70
71
  }
71
72
  }
73
+ export const handleSabRequest = async (sabHost, fs) => {
74
+ const { op, data: path } = sabHost.readRequest();
75
+ try {
76
+ if (op === SAB_OP_READ_FILE) {
77
+ const bytes = await fs.read(path);
78
+ sabHost.writeResponse(bytes);
79
+ }
80
+ else if (op === SAB_OP_READ_DIR) {
81
+ const entries = await fs.readDir(path);
82
+ sabHost.writeResponse(JSON.stringify(entries.map((e) => e.toJSON())));
83
+ }
84
+ else if (op === SAB_OP_WRITE_FILE) {
85
+ const { content, encoding } = JSON.parse(path);
86
+ const filePath = content.path;
87
+ const fileContent = content.data;
88
+ // TODO: handle binary content (base64?)
89
+ await fs.writeString(filePath, fileContent);
90
+ sabHost.writeResponse("ok");
91
+ }
92
+ else if (op === SAB_OP_MKDIR) {
93
+ const { path: dirPath, recursive } = JSON.parse(path);
94
+ if (recursive) {
95
+ await fs.createDirAll(dirPath);
96
+ }
97
+ else {
98
+ await fs.createDir(dirPath);
99
+ }
100
+ sabHost.writeResponse("ok");
101
+ }
102
+ else if (op === SAB_OP_RM) {
103
+ const { path: rmPath, recursive } = JSON.parse(path);
104
+ // Mimic internalProject.rm logic
105
+ const metadata = await fs.metadata(rmPath);
106
+ const type = metadata.toJSON().type;
107
+ if (type === "file") {
108
+ await fs.removeFile(rmPath);
109
+ }
110
+ else if (type === "directory") {
111
+ await fs.removeDir(rmPath, !!recursive);
112
+ }
113
+ sabHost.writeResponse("ok");
114
+ }
115
+ else if (op === SAB_OP_RMDIR) {
116
+ const { path: rmPath, recursive } = JSON.parse(path);
117
+ await fs.removeDir(rmPath, !!recursive);
118
+ sabHost.writeResponse("ok");
119
+ }
120
+ else if (op === SAB_OP_COPY_FILE) {
121
+ const { src, dst } = JSON.parse(path);
122
+ await fs.copyFile(src, dst);
123
+ sabHost.writeResponse("ok");
124
+ }
125
+ else if (op === SAB_OP_STAT) {
126
+ const metadata = await fs.metadata(path);
127
+ sabHost.writeResponse(JSON.stringify(metadata));
128
+ }
129
+ else {
130
+ sabHost.writeError("Unknown op");
131
+ }
132
+ }
133
+ catch (e) {
134
+ sabHost.writeError(e.message);
135
+ }
136
+ };
@@ -54,7 +54,7 @@ async function readFileFromProject(projectPath) {
54
54
  headers: {
55
55
  "Content-Type": mimeType,
56
56
  ...(mimeType === "text/html"
57
- ? { "Cross-Origin-Embedder-Policy": "require-corp" }
57
+ ? { "Cross-Origin-Embedder-Policy": "credentialless" }
58
58
  : {}),
59
59
  },
60
60
  });
@@ -62,11 +62,30 @@ export class DirEntry {
62
62
  }
63
63
  export class Metadata {
64
64
  static __wrap(ptr: any): any;
65
- toJSON(): {};
65
+ toJSON(): {
66
+ type: DirEntryType;
67
+ file_size: bigint;
68
+ };
66
69
  toString(): string;
67
70
  __destroy_into_raw(): number | undefined;
68
71
  __wbg_ptr: number | undefined;
69
72
  free(): void;
73
+ /**
74
+ * @param {DirEntryType} arg0
75
+ */
76
+ set type(arg0: DirEntryType);
77
+ /**
78
+ * @returns {DirEntryType}
79
+ */
80
+ get type(): DirEntryType;
81
+ /**
82
+ * @param {bigint} arg0
83
+ */
84
+ set file_size(arg0: bigint);
85
+ /**
86
+ * @returns {bigint}
87
+ */
88
+ get file_size(): bigint;
70
89
  }
71
90
  export class Project {
72
91
  /**
package/esm/utoo/index.js CHANGED
@@ -182,63 +182,63 @@ const CLOSURE_DTORS = (typeof FinalizationRegistry === 'undefined')
182
182
  : new FinalizationRegistry(state => {
183
183
  wasm.__wbindgen_export_5.get(state.dtor)(state.a, state.b);
184
184
  });
185
- function makeMutClosure(arg0, arg1, dtor, f) {
185
+ function makeClosure(arg0, arg1, dtor, f) {
186
186
  const state = { a: arg0, b: arg1, cnt: 1, dtor };
187
187
  const real = (...args) => {
188
188
  // First up with a closure we increment the internal reference
189
189
  // count. This ensures that the Rust closure environment won't
190
190
  // be deallocated while we're invoking it.
191
191
  state.cnt++;
192
- const a = state.a;
193
- state.a = 0;
194
192
  try {
195
- return f(a, state.b, ...args);
193
+ return f(state.a, state.b, ...args);
196
194
  }
197
195
  finally {
198
196
  if (--state.cnt === 0) {
199
- wasm.__wbindgen_export_5.get(state.dtor)(a, state.b);
197
+ wasm.__wbindgen_export_5.get(state.dtor)(state.a, state.b);
198
+ state.a = 0;
200
199
  CLOSURE_DTORS.unregister(state);
201
200
  }
202
- else {
203
- state.a = a;
204
- }
205
201
  }
206
202
  };
207
203
  real.original = state;
208
204
  CLOSURE_DTORS.register(real, state, state);
209
205
  return real;
210
206
  }
211
- function getArrayJsValueFromWasm0(ptr, len) {
212
- ptr = ptr >>> 0;
213
- const mem = getDataViewMemory0();
214
- const result = [];
215
- for (let i = ptr; i < ptr + 4 * len; i += 4) {
216
- result.push(takeObject(mem.getUint32(i, true)));
217
- }
218
- return result;
219
- }
220
- function makeClosure(arg0, arg1, dtor, f) {
207
+ function makeMutClosure(arg0, arg1, dtor, f) {
221
208
  const state = { a: arg0, b: arg1, cnt: 1, dtor };
222
209
  const real = (...args) => {
223
210
  // First up with a closure we increment the internal reference
224
211
  // count. This ensures that the Rust closure environment won't
225
212
  // be deallocated while we're invoking it.
226
213
  state.cnt++;
214
+ const a = state.a;
215
+ state.a = 0;
227
216
  try {
228
- return f(state.a, state.b, ...args);
217
+ return f(a, state.b, ...args);
229
218
  }
230
219
  finally {
231
220
  if (--state.cnt === 0) {
232
- wasm.__wbindgen_export_5.get(state.dtor)(state.a, state.b);
233
- state.a = 0;
221
+ wasm.__wbindgen_export_5.get(state.dtor)(a, state.b);
234
222
  CLOSURE_DTORS.unregister(state);
235
223
  }
224
+ else {
225
+ state.a = a;
226
+ }
236
227
  }
237
228
  };
238
229
  real.original = state;
239
230
  CLOSURE_DTORS.register(real, state, state);
240
231
  return real;
241
232
  }
233
+ function getArrayJsValueFromWasm0(ptr, len) {
234
+ ptr = ptr >>> 0;
235
+ const mem = getDataViewMemory0();
236
+ const result = [];
237
+ for (let i = ptr; i < ptr + 4 * len; i += 4) {
238
+ result.push(takeObject(mem.getUint32(i, true)));
239
+ }
240
+ return result;
241
+ }
242
242
  function _assertClass(instance, klass) {
243
243
  if (!(instance instanceof klass)) {
244
244
  throw new Error(`expected instance of ${klass.name}`);
@@ -271,12 +271,6 @@ export function init_log_filter(filter) {
271
271
  const len0 = WASM_VECTOR_LEN;
272
272
  wasm.init_log_filter(ptr0, len0);
273
273
  }
274
- function passArray8ToWasm0(arg, malloc) {
275
- const ptr = malloc(arg.length * 1, 1) >>> 0;
276
- getUint8ArrayMemory0().set(arg, ptr / 1);
277
- WASM_VECTOR_LEN = arg.length;
278
- return ptr;
279
- }
280
274
  /**
281
275
  * @param {number} worker_id
282
276
  */
@@ -290,6 +284,12 @@ export function workerCreated(worker_id) {
290
284
  export function registerWorkerScheduler(creator, terminator) {
291
285
  wasm.registerWorkerScheduler(addHeapObject(creator), addHeapObject(terminator));
292
286
  }
287
+ function passArray8ToWasm0(arg, malloc) {
288
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
289
+ getUint8ArrayMemory0().set(arg, ptr / 1);
290
+ WASM_VECTOR_LEN = arg.length;
291
+ return ptr;
292
+ }
293
293
  /**
294
294
  * Entry point for web workers
295
295
  * @param {number} ptr
@@ -297,13 +297,13 @@ export function registerWorkerScheduler(creator, terminator) {
297
297
  export function wasm_thread_entry_point(ptr) {
298
298
  wasm.wasm_thread_entry_point(ptr);
299
299
  }
300
- function __wbg_adapter_4(arg0, arg1, arg2) {
300
+ function __wbg_adapter_6(arg0, arg1, arg2) {
301
301
  wasm.__wbindgen_export_6(arg0, arg1, addHeapObject(arg2));
302
302
  }
303
- function __wbg_adapter_13(arg0, arg1) {
303
+ function __wbg_adapter_15(arg0, arg1) {
304
304
  wasm.__wbindgen_export_7(arg0, arg1);
305
305
  }
306
- function __wbg_adapter_26(arg0, arg1, arg2) {
306
+ function __wbg_adapter_18(arg0, arg1, arg2) {
307
307
  wasm.__wbindgen_export_8(arg0, arg1, addHeapObject(arg2));
308
308
  }
309
309
  let stack_pointer = 128;
@@ -441,7 +441,10 @@ export class Metadata {
441
441
  return obj;
442
442
  }
443
443
  toJSON() {
444
- return {};
444
+ return {
445
+ type: this.type,
446
+ file_size: this.file_size,
447
+ };
445
448
  }
446
449
  toString() {
447
450
  return JSON.stringify(this);
@@ -456,6 +459,32 @@ export class Metadata {
456
459
  const ptr = this.__destroy_into_raw();
457
460
  wasm.__wbg_metadata_free(ptr, 0);
458
461
  }
462
+ /**
463
+ * @returns {DirEntryType}
464
+ */
465
+ get type() {
466
+ const ret = wasm.__wbg_get_metadata_type(this.__wbg_ptr);
467
+ return __wbindgen_enum_DirEntryType[ret];
468
+ }
469
+ /**
470
+ * @param {DirEntryType} arg0
471
+ */
472
+ set type(arg0) {
473
+ wasm.__wbg_set_metadata_type(this.__wbg_ptr, (__wbindgen_enum_DirEntryType.indexOf(arg0) + 1 || 3) - 1);
474
+ }
475
+ /**
476
+ * @returns {bigint}
477
+ */
478
+ get file_size() {
479
+ const ret = wasm.__wbg_get_metadata_file_size(this.__wbg_ptr);
480
+ return BigInt.asUintN(64, ret);
481
+ }
482
+ /**
483
+ * @param {bigint} arg0
484
+ */
485
+ set file_size(arg0) {
486
+ wasm.__wbg_set_metadata_file_size(this.__wbg_ptr, arg0);
487
+ }
459
488
  }
460
489
  if (Symbol.dispose)
461
490
  Metadata.prototype[Symbol.dispose] = Metadata.prototype.free;
@@ -1712,9 +1741,9 @@ function __wbg_get_imports() {
1712
1741
  return ret;
1713
1742
  }, arguments);
1714
1743
  };
1715
- imports.wbg.__wbindgen_cast_1113a938f979d88a = function (arg0, arg1) {
1716
- // Cast intrinsic for `Closure(Closure { dtor_idx: 603, function: Function { arguments: [], shim_idx: 604, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1717
- const ret = makeMutClosure(arg0, arg1, 603, __wbg_adapter_13);
1744
+ imports.wbg.__wbindgen_cast_147f62ca53704375 = function (arg0, arg1) {
1745
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 8608, function: Function { arguments: [NamedExternref("Array<any>")], shim_idx: 8609, ret: Unit, inner_ret: Some(Unit) }, mutable: false }) -> Externref`.
1746
+ const ret = makeClosure(arg0, arg1, 8608, __wbg_adapter_18);
1718
1747
  return addHeapObject(ret);
1719
1748
  };
1720
1749
  imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function (arg0, arg1) {
@@ -1722,14 +1751,19 @@ function __wbg_get_imports() {
1722
1751
  const ret = getStringFromWasm0(arg0, arg1);
1723
1752
  return addHeapObject(ret);
1724
1753
  };
1754
+ imports.wbg.__wbindgen_cast_320e55bca3a693f6 = function (arg0, arg1) {
1755
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 8608, function: Function { arguments: [Ref(NamedExternref("MessageEvent"))], shim_idx: 8631, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1756
+ const ret = makeMutClosure(arg0, arg1, 8608, __wbg_adapter_29);
1757
+ return addHeapObject(ret);
1758
+ };
1725
1759
  imports.wbg.__wbindgen_cast_4625c577ab2ec9ee = function (arg0) {
1726
1760
  // Cast intrinsic for `U64 -> Externref`.
1727
1761
  const ret = BigInt.asUintN(64, arg0);
1728
1762
  return addHeapObject(ret);
1729
1763
  };
1730
- imports.wbg.__wbindgen_cast_59550fe77af0bf03 = function (arg0, arg1) {
1731
- // Cast intrinsic for `Closure(Closure { dtor_idx: 8609, function: Function { arguments: [Ref(NamedExternref("MessageEvent"))], shim_idx: 8630, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1732
- const ret = makeMutClosure(arg0, arg1, 8609, __wbg_adapter_29);
1764
+ imports.wbg.__wbindgen_cast_6c005a14a1fbf1c5 = function (arg0, arg1) {
1765
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 595, function: Function { arguments: [], shim_idx: 596, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1766
+ const ret = makeMutClosure(arg0, arg1, 595, __wbg_adapter_15);
1733
1767
  return addHeapObject(ret);
1734
1768
  };
1735
1769
  imports.wbg.__wbindgen_cast_76322aab70622876 = function (arg0, arg1) {
@@ -1739,11 +1773,6 @@ function __wbg_get_imports() {
1739
1773
  const ret = v0;
1740
1774
  return addHeapObject(ret);
1741
1775
  };
1742
- imports.wbg.__wbindgen_cast_77984da3a91be2e9 = function (arg0, arg1) {
1743
- // Cast intrinsic for `Closure(Closure { dtor_idx: 8625, function: Function { arguments: [Externref], shim_idx: 8626, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1744
- const ret = makeMutClosure(arg0, arg1, 8625, __wbg_adapter_4);
1745
- return addHeapObject(ret);
1746
- };
1747
1776
  imports.wbg.__wbindgen_cast_77bc3e92745e9a35 = function (arg0, arg1) {
1748
1777
  var v0 = getArrayU8FromWasm0(arg0, arg1).slice();
1749
1778
  wasm.__wbindgen_export_4(arg0, arg1 * 1, 1);
@@ -1751,9 +1780,14 @@ function __wbg_get_imports() {
1751
1780
  const ret = v0;
1752
1781
  return addHeapObject(ret);
1753
1782
  };
1754
- imports.wbg.__wbindgen_cast_8ecade4ce8b126db = function (arg0, arg1) {
1755
- // Cast intrinsic for `Closure(Closure { dtor_idx: 8625, function: Function { arguments: [], shim_idx: 604, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1756
- const ret = makeMutClosure(arg0, arg1, 8625, __wbg_adapter_13);
1783
+ imports.wbg.__wbindgen_cast_7b3678bd8e0fb80b = function (arg0, arg1) {
1784
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 8626, function: Function { arguments: [NamedExternref("MessageEvent")], shim_idx: 8627, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1785
+ const ret = makeMutClosure(arg0, arg1, 8626, __wbg_adapter_6);
1786
+ return addHeapObject(ret);
1787
+ };
1788
+ imports.wbg.__wbindgen_cast_884165a22f3e9702 = function (arg0, arg1) {
1789
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 8626, function: Function { arguments: [Externref], shim_idx: 8627, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1790
+ const ret = makeMutClosure(arg0, arg1, 8626, __wbg_adapter_6);
1757
1791
  return addHeapObject(ret);
1758
1792
  };
1759
1793
  imports.wbg.__wbindgen_cast_9ae0607507abb057 = function (arg0) {
@@ -1761,14 +1795,9 @@ function __wbg_get_imports() {
1761
1795
  const ret = arg0;
1762
1796
  return addHeapObject(ret);
1763
1797
  };
1764
- imports.wbg.__wbindgen_cast_bb0fb35a7180d55b = function (arg0, arg1) {
1765
- // Cast intrinsic for `Closure(Closure { dtor_idx: 8625, function: Function { arguments: [NamedExternref("MessageEvent")], shim_idx: 8626, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1766
- const ret = makeMutClosure(arg0, arg1, 8625, __wbg_adapter_4);
1767
- return addHeapObject(ret);
1768
- };
1769
- imports.wbg.__wbindgen_cast_cdaa362fcf12456c = function (arg0, arg1) {
1770
- // Cast intrinsic for `Closure(Closure { dtor_idx: 8609, function: Function { arguments: [NamedExternref("Array<any>")], shim_idx: 8610, ret: Unit, inner_ret: Some(Unit) }, mutable: false }) -> Externref`.
1771
- const ret = makeClosure(arg0, arg1, 8609, __wbg_adapter_26);
1798
+ imports.wbg.__wbindgen_cast_c112ec0eb88c0f62 = function (arg0, arg1) {
1799
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 8626, function: Function { arguments: [], shim_idx: 596, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1800
+ const ret = makeMutClosure(arg0, arg1, 8626, __wbg_adapter_15);
1772
1801
  return addHeapObject(ret);
1773
1802
  };
1774
1803
  imports.wbg.__wbindgen_cast_d6cd19b81560fd6e = function (arg0) {
Binary file
@@ -89,7 +89,7 @@ const executeModule = (moduleCode, moduleId, id, importMaps, entrypoint) => {
89
89
  return finalExports;
90
90
  };
91
91
  const loadModule = (id, context, importMaps, entrypoint) => {
92
- var _a, _b, _c, _d, _e, _f;
92
+ var _a, _b, _c;
93
93
  const cacheKey = `${context}:${id}`;
94
94
  if (resolutionCache[cacheKey]) {
95
95
  const cachedId = resolutionCache[cacheKey];
@@ -136,13 +136,6 @@ const loadModule = (id, context, importMaps, entrypoint) => {
136
136
  let searchPaths = searchPathsCache[context];
137
137
  if (!searchPaths) {
138
138
  searchPaths = [];
139
- // @ts-ignore
140
- const cwd = ((_b = (_a = self.process) === null || _a === void 0 ? void 0 : _a.cwd) === null || _b === void 0 ? void 0 : _b.call(_a)) || ((_c = self.workerData) === null || _c === void 0 ? void 0 : _c.cwd) || "/";
141
- const isInsideNodeModules = context.includes("/node_modules/") ||
142
- context.includes("\\node_modules\\");
143
- if (isInsideNodeModules) {
144
- searchPaths.push(path.join(cwd, "node_modules"));
145
- }
146
139
  let currentDir = context;
147
140
  while (true) {
148
141
  if (path.basename(currentDir) !== "node_modules") {
@@ -182,25 +175,35 @@ const loadModule = (id, context, importMaps, entrypoint) => {
182
175
  ];
183
176
  for (const candidate of candidates) {
184
177
  if (existsSync(candidate) && !statSync(candidate).isDirectory()) {
185
- resolvedId = candidate;
186
- moduleCode = fs.readFileSync(candidate, "utf8");
187
- moduleId = candidate;
188
- break;
178
+ try {
179
+ resolvedId = candidate;
180
+ moduleCode = fs.readFileSync(candidate, "utf8");
181
+ moduleId = candidate;
182
+ break;
183
+ }
184
+ catch (e) {
185
+ // ignore
186
+ }
189
187
  }
190
188
  }
191
189
  }
192
190
  }
193
- catch (_g) { }
191
+ catch (_d) { }
194
192
  }
195
193
  if (!moduleCode) {
196
194
  const extensions = ["", ".js", ".json", "/index.js"];
197
195
  for (const ext of extensions) {
198
196
  const p = nodeModulesPath + ext;
199
197
  if (existsSync(p) && !statSync(p).isDirectory()) {
200
- resolvedId = p;
201
- moduleCode = fs.readFileSync(p, "utf8");
202
- moduleId = p;
203
- break;
198
+ try {
199
+ resolvedId = p;
200
+ moduleCode = fs.readFileSync(p, "utf8");
201
+ moduleId = p;
202
+ break;
203
+ }
204
+ catch (e) {
205
+ // ignore
206
+ }
204
207
  }
205
208
  }
206
209
  }
@@ -211,7 +214,7 @@ const loadModule = (id, context, importMaps, entrypoint) => {
211
214
  // Fallback: Try resolving absolute path (handling CWD stripping)
212
215
  if (!moduleCode && id.startsWith("/")) {
213
216
  // @ts-ignore
214
- const cwd = ((_e = (_d = self.process) === null || _d === void 0 ? void 0 : _d.cwd) === null || _e === void 0 ? void 0 : _e.call(_d)) || ((_f = self.workerData) === null || _f === void 0 ? void 0 : _f.cwd) || "/";
217
+ const cwd = ((_b = (_a = self.process) === null || _a === void 0 ? void 0 : _a.cwd) === null || _b === void 0 ? void 0 : _b.call(_a)) || ((_c = self.workerData) === null || _c === void 0 ? void 0 : _c.cwd) || "/";
215
218
  let relativeId = id;
216
219
  if (id.startsWith(cwd)) {
217
220
  relativeId = id.slice(cwd.length);
@@ -222,10 +225,15 @@ const loadModule = (id, context, importMaps, entrypoint) => {
222
225
  for (const ext of extensions) {
223
226
  const p = relativeId + ext;
224
227
  if (existsSync(p) && !statSync(p).isDirectory()) {
225
- resolvedId = p; // Use relative path for FS ops
226
- moduleCode = fs.readFileSync(p, "utf8");
227
- moduleId = id; // Keep original absolute path as module ID
228
- break;
228
+ try {
229
+ resolvedId = p; // Use relative path for FS ops
230
+ moduleCode = fs.readFileSync(p, "utf8");
231
+ moduleId = id; // Keep original absolute path as module ID
232
+ break;
233
+ }
234
+ catch (e) {
235
+ // ignore
236
+ }
229
237
  }
230
238
  }
231
239
  }
@@ -235,10 +243,16 @@ const loadModule = (id, context, importMaps, entrypoint) => {
235
243
  for (const ext of extensions) {
236
244
  const p = resolvedId + ext;
237
245
  if (existsSync(p) && !statSync(p).isDirectory()) {
238
- resolvedId = p;
239
- moduleCode = fs.readFileSync(p, "utf8");
240
- moduleId = p;
241
- break;
246
+ try {
247
+ resolvedId = p;
248
+ moduleCode = fs.readFileSync(p, "utf8");
249
+ moduleId = p;
250
+ break;
251
+ }
252
+ catch (e) {
253
+ console.error(`[Debug] Failed to read file ${p}:`, e);
254
+ // ignore
255
+ }
242
256
  }
243
257
  }
244
258
  }
@@ -247,7 +261,7 @@ const loadModule = (id, context, importMaps, entrypoint) => {
247
261
  resolutionCache[cacheKey] = moduleId;
248
262
  return executeModule(moduleCode, moduleId, id, importMaps, entrypoint);
249
263
  }
250
- console.error(`Worker: Dependency ${id} (resolved: ${resolvedId}) not found.`);
264
+ console.error(`Worker: Dependency ${id} (resolved: ${resolvedId}) not found. Context: ${context}`);
251
265
  return {};
252
266
  };
253
267
  export async function cjs(entrypoint, importMaps) {