@utoo/web 1.2.8 → 1.3.0-rc.2

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,10 +1,13 @@
1
- import { DepsOptions, InstallOptions, PackFile, ProjectEndpoint, Stats } from "../types";
1
+ import { DepsOptions, InstallOptions, PackFile, ProjectEndpoint, Stats, UpdateMessage } from "../types";
2
2
  export declare class ForkedProject implements ProjectEndpoint {
3
3
  private endpoint;
4
4
  constructor(port: MessagePort);
5
5
  deps(options?: DepsOptions): Promise<string>;
6
6
  install(packageLock: string, options?: InstallOptions): Promise<void>;
7
7
  build(): Promise<import("..").BuildOutput>;
8
+ dev(onUpdate?: (result: any) => void): void;
9
+ hmrSubscribe(identifier: string, callback: (update: unknown) => void): Promise<void>;
10
+ updateInfoSubscribe(aggregationMs: number, callback: (message: UpdateMessage) => void): void;
8
11
  readFile(path: string, encoding?: "utf8"): Promise<any>;
9
12
  writeFile(path: string, content: string | Uint8Array, encoding?: "utf8"): Promise<void>;
10
13
  copyFile(src: string, dst: string): Promise<void>;
@@ -6,14 +6,29 @@ export class ForkedProject {
6
6
  (_a = this.endpoint) !== null && _a !== void 0 ? _a : (this.endpoint = comlink.wrap(port));
7
7
  }
8
8
  async deps(options) {
9
- return await this.endpoint.deps(options);
9
+ var _a, _b;
10
+ return await this.endpoint.deps({
11
+ registry: (_a = options === null || options === void 0 ? void 0 : options.registry) !== null && _a !== void 0 ? _a : undefined,
12
+ concurrency: (_b = options === null || options === void 0 ? void 0 : options.concurrency) !== null && _b !== void 0 ? _b : undefined,
13
+ });
10
14
  }
11
15
  async install(packageLock, options) {
12
- return await this.endpoint.install(packageLock, options);
16
+ return await this.endpoint.install(packageLock, {
17
+ maxConcurrentDownloads: options === null || options === void 0 ? void 0 : options.maxConcurrentDownloads,
18
+ });
13
19
  }
14
20
  async build() {
15
21
  return await this.endpoint.build();
16
22
  }
23
+ dev(onUpdate) {
24
+ this.endpoint.dev(onUpdate ? comlink.proxy(onUpdate) : undefined);
25
+ }
26
+ async hmrSubscribe(identifier, callback) {
27
+ await this.endpoint.hmrSubscribe(identifier, comlink.proxy(callback));
28
+ }
29
+ updateInfoSubscribe(aggregationMs, callback) {
30
+ this.endpoint.updateInfoSubscribe(aggregationMs, comlink.proxy(callback));
31
+ }
17
32
  async readFile(path, encoding) {
18
33
  return (await this.endpoint.readFile(path, encoding));
19
34
  }
@@ -1,13 +1,17 @@
1
+ import { type UpdateMessage } from "@utoo/pack-shared";
1
2
  import { DepsOptions, InstallOptions, PackFile, ProjectEndpoint, ProjectOptions, Stats } from "../types";
2
3
  import initWasm from "../utoo";
3
4
  declare class InternalEndpoint implements ProjectEndpoint {
4
5
  wasmInit?: ReturnType<typeof initWasm>;
5
6
  options?: Omit<ProjectOptions, "workerUrl" | "serviceWorker">;
6
7
  loaderWorkerPoolInitialized: boolean;
8
+ private rootTask?;
9
+ private hmrRootTasks;
7
10
  mount(opt: Omit<ProjectOptions, "workerUrl" | "serviceWorker">): Promise<void>;
8
11
  deps(options?: DepsOptions): Promise<string>;
9
12
  install(packageLock: string, options?: InstallOptions): Promise<void>;
10
13
  build(): Promise<any>;
14
+ dev(onUpdate?: (result: any) => void): Promise<void>;
11
15
  readFile(path: string, encoding?: "utf8"): Promise<any>;
12
16
  writeFile(path: string, content: string | Uint8Array, _encoding?: "utf8"): Promise<void>;
13
17
  copyFile(src: string, dst: string): Promise<void>;
@@ -26,6 +30,8 @@ declare class InternalEndpoint implements ProjectEndpoint {
26
30
  }): Promise<void>;
27
31
  gzip(files: PackFile[]): Promise<Uint8Array<ArrayBufferLike>>;
28
32
  sigMd5(content: Uint8Array): Promise<string>;
33
+ hmrSubscribe(identifier: string, callback: (update: unknown) => void): Promise<void>;
34
+ updateInfoSubscribe(aggregationMs: number, callback: (message: UpdateMessage) => void): void;
29
35
  }
30
36
  declare const internalEndpoint: InternalEndpoint;
31
37
  export { internalEndpoint };
@@ -3,6 +3,8 @@ import { runLoaderWorkerPool } from "../webpackLoaders/loaderWorkerPool";
3
3
  class InternalEndpoint {
4
4
  constructor() {
5
5
  this.loaderWorkerPoolInitialized = false;
6
+ // Keep HMR root tasks alive (keyed by identifier)
7
+ this.hmrRootTasks = new Map();
6
8
  }
7
9
  // This should be called only once
8
10
  async mount(opt) {
@@ -23,11 +25,16 @@ class InternalEndpoint {
23
25
  async deps(options) {
24
26
  var _a, _b;
25
27
  await this.wasmInit;
26
- return await ProjectInternal.deps((_a = options === null || options === void 0 ? void 0 : options.registry) !== null && _a !== void 0 ? _a : undefined, (_b = options === null || options === void 0 ? void 0 : options.concurrency) !== null && _b !== void 0 ? _b : undefined);
28
+ // Ensure we pass undefined (not null) for missing values
29
+ const registry = (_a = options === null || options === void 0 ? void 0 : options.registry) !== null && _a !== void 0 ? _a : undefined;
30
+ const concurrency = (_b = options === null || options === void 0 ? void 0 : options.concurrency) !== null && _b !== void 0 ? _b : undefined;
31
+ return await ProjectInternal.deps(registry, concurrency);
27
32
  }
28
33
  async install(packageLock, options) {
34
+ var _a;
29
35
  await this.wasmInit;
30
- await ProjectInternal.install(packageLock, options === null || options === void 0 ? void 0 : options.maxConcurrentDownloads);
36
+ const concurrency = (_a = options === null || options === void 0 ? void 0 : options.maxConcurrentDownloads) !== null && _a !== void 0 ? _a : undefined;
37
+ await ProjectInternal.install(packageLock, concurrency);
31
38
  return;
32
39
  }
33
40
  async build() {
@@ -39,6 +46,16 @@ class InternalEndpoint {
39
46
  }
40
47
  return await ProjectInternal.build();
41
48
  }
49
+ async dev(onUpdate) {
50
+ var _a, _b;
51
+ if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.loaderWorkerUrl) && !this.loaderWorkerPoolInitialized) {
52
+ runLoaderWorkerPool(this.options.cwd, this.options.loaderWorkerUrl, (_b = this.options) === null || _b === void 0 ? void 0 : _b.loadersImportMap);
53
+ this.loaderWorkerPoolInitialized = true;
54
+ }
55
+ this.rootTask = await ProjectInternal.entrypointsSubscribe((result) => {
56
+ onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate(result);
57
+ });
58
+ }
42
59
  async readFile(path, encoding) {
43
60
  await this.wasmInit;
44
61
  let ret;
@@ -124,6 +141,13 @@ class InternalEndpoint {
124
141
  await this.wasmInit;
125
142
  return await ProjectInternal.sigMd5(content);
126
143
  }
144
+ async hmrSubscribe(identifier, callback) {
145
+ const rootTask = await ProjectInternal.hmrEvents(identifier, callback);
146
+ this.hmrRootTasks.set(identifier, rootTask);
147
+ }
148
+ updateInfoSubscribe(aggregationMs, callback) {
149
+ ProjectInternal.updateInfoSubscribe(aggregationMs, callback);
150
+ }
127
151
  }
128
152
  const internalEndpoint = new InternalEndpoint();
129
153
  export { internalEndpoint };
@@ -1,9 +1,13 @@
1
+ import { type UpdateMessage } from "@utoo/pack-shared";
2
+ import { HmrClient } from "../hmr";
1
3
  import { BuildOutput, DepsOptions, Dirent, InstallOptions, PackFile, ProjectEndpoint, ProjectOptions, ServiceWorkerOptions, Stats } from "../types";
2
4
  export declare class Project implements ProjectEndpoint {
3
5
  #private;
4
6
  private options;
5
7
  readonly cwd: string;
6
8
  readonly serviceWorkerOptions?: ServiceWorkerOptions;
9
+ /** HMR server for managing hot module replacement with preview iframes */
10
+ private hmrServer?;
7
11
  private remote;
8
12
  constructor(options: ProjectOptions);
9
13
  private connectWorker;
@@ -12,6 +16,9 @@ export declare class Project implements ProjectEndpoint {
12
16
  deps(options?: DepsOptions): Promise<string>;
13
17
  install(packageLock: string, options?: InstallOptions): Promise<void>;
14
18
  build(): Promise<BuildOutput>;
19
+ dev(onUpdate?: (result: BuildOutput) => void): void;
20
+ hmrSubscribe(identifier: string, callback: (update: unknown) => void): Promise<void>;
21
+ updateInfoSubscribe(aggregationMs: number, callback: (message: UpdateMessage) => void): void;
15
22
  readFile(path: string, encoding?: "utf8"): Promise<any>;
16
23
  writeFile(path: string, content: string | Uint8Array, encoding?: "utf8"): Promise<void>;
17
24
  copyFile(src: string, dst: string): Promise<void>;
@@ -30,5 +37,14 @@ export declare class Project implements ProjectEndpoint {
30
37
  stat(path: string): Promise<Stats>;
31
38
  gzip(files: PackFile[]): Promise<Uint8Array>;
32
39
  sigMd5(content: Uint8Array): Promise<string>;
40
+ /**
41
+ * Connect an iframe to the HMR server for hot module replacement.
42
+ * Only works after dev() has been called.
43
+ *
44
+ * @param iframe The iframe element to connect
45
+ * @param origin Optional origin for postMessage (default: "*")
46
+ * @returns The HMR client instance, or null if connection failed or dev() not called
47
+ */
48
+ connectHmrIframe(iframe: HTMLIFrameElement, origin?: string): HmrClient | null;
33
49
  static fork(channel: MessageChannel, eventSource?: Client | DedicatedWorkerGlobalScope): ProjectEndpoint;
34
50
  }
@@ -12,6 +12,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
12
12
  var _Project_mount;
13
13
  import { handleIssues } from "@utoo/pack-shared";
14
14
  import * as comlink from "comlink";
15
+ import { HmrServer } from "../hmr";
15
16
  import { WorkerMessageType } from "../message";
16
17
  import { installServiceWorker } from "../serviceWorker/install";
17
18
  import { Dirent, Stats, } from "../types";
@@ -79,6 +80,30 @@ export class Project {
79
80
  handleIssues(res.issues, false, false);
80
81
  return res;
81
82
  }
83
+ dev(onUpdate) {
84
+ // Create HmrServer lazily on first dev() call
85
+ if (!this.hmrServer) {
86
+ this.hmrServer = new HmrServer({
87
+ onSubscribe: async (path, client) => {
88
+ await this.hmrSubscribe(path, (update) => {
89
+ this.hmrServer.sendUpdate(path, update);
90
+ });
91
+ },
92
+ });
93
+ }
94
+ this.remote.dev(onUpdate
95
+ ? comlink.proxy((result) => {
96
+ handleIssues(result.issues, false, false);
97
+ onUpdate(result);
98
+ })
99
+ : undefined);
100
+ }
101
+ async hmrSubscribe(identifier, callback) {
102
+ await this.remote.hmrSubscribe(identifier, comlink.proxy(callback));
103
+ }
104
+ updateInfoSubscribe(aggregationMs, callback) {
105
+ this.remote.updateInfoSubscribe(aggregationMs, comlink.proxy(callback));
106
+ }
82
107
  async readFile(path, encoding) {
83
108
  await __classPrivateFieldGet(this, _Project_mount, "f");
84
109
  return (await this.remote.readFile(path, encoding));
@@ -124,6 +149,20 @@ export class Project {
124
149
  await __classPrivateFieldGet(this, _Project_mount, "f");
125
150
  return await this.remote.sigMd5(content);
126
151
  }
152
+ /**
153
+ * Connect an iframe to the HMR server for hot module replacement.
154
+ * Only works after dev() has been called.
155
+ *
156
+ * @param iframe The iframe element to connect
157
+ * @param origin Optional origin for postMessage (default: "*")
158
+ * @returns The HMR client instance, or null if connection failed or dev() not called
159
+ */
160
+ connectHmrIframe(iframe, origin) {
161
+ if (!this.hmrServer) {
162
+ return null;
163
+ }
164
+ return this.hmrServer.connectIframe(iframe, origin);
165
+ }
127
166
  static fork(channel, eventSource) {
128
167
  (eventSource || self).postMessage(WorkerMessageType.RequestFork, {
129
168
  transfer: [channel.port2],
package/esm/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { Issue } from "@utoo/pack-shared";
1
+ import { Issue, type UpdateMessage } from "@utoo/pack-shared";
2
2
  import initWasm, { DirEntryType } from "./utoo";
3
+ export { type UpdateMessage } from "@utoo/pack-shared";
3
4
  export interface RawDirent {
4
5
  name: string;
5
6
  type: DirEntryType;
@@ -69,6 +70,17 @@ export interface ProjectEndpoint {
69
70
  deps: (options?: DepsOptions) => Promise<string>;
70
71
  install: (packageLock: string, options?: InstallOptions) => Promise<void>;
71
72
  build: () => Promise<BuildOutput>;
73
+ /** Start dev mode with file watching. onUpdate is called on each rebuild. */
74
+ dev: (onUpdate?: (result: BuildOutput) => void) => void;
75
+ /**
76
+ * Subscribe to HMR events for a specific identifier.
77
+ * Returns a Promise that resolves when the subscription is set up.
78
+ * Matches NAPI signature: project_hmr_events(project, identifier, func) -> RootTask
79
+ * Callback receives: { result: ClientUpdateInstruction, issues: Issue[], diagnostics: Diagnostic[] }
80
+ */
81
+ hmrSubscribe: (identifier: string, callback: (update: unknown) => void) => void | Promise<void>;
82
+ /** Subscribe to compilation lifecycle events (start/end). */
83
+ updateInfoSubscribe: (aggregationMs: number, callback: (message: UpdateMessage) => void) => void;
72
84
  readFile(path: string): Promise<Uint8Array>;
73
85
  readFile(path: string, encoding?: "utf8"): Promise<string>;
74
86
  writeFile(path: string, content: string | Uint8Array, encoding?: "utf8"): Promise<void>;
@@ -212,24 +212,33 @@ export class Project {
212
212
  static get cwd(): string;
213
213
  /**
214
214
  * Generate package-lock.json by resolving dependencies.
215
- *
216
- * # Arguments
217
- * * `registry` - Optional registry URL. If None, uses npmmirror.
218
- * - "https://registry.npmmirror.com" - supports semver queries (faster)
219
- * - "https://registry.npmjs.org" - official npm registry (slower, fetches full manifest)
220
- * * `concurrency` - Optional concurrency limit (defaults to 20)
221
215
  * @param {string | null} [registry]
222
216
  * @param {number | null} [concurrency]
223
217
  * @returns {Promise<string>}
224
218
  */
225
219
  static deps(registry?: string | null, concurrency?: number | null): Promise<string>;
220
+ /**
221
+ * Subscribe to entrypoints changes with HMR support.
222
+ * This will watch for file changes and automatically rebuild.
223
+ * Returns a RootTask that must be held by JS to keep the subscription active.
224
+ * @param {Function} callback
225
+ * @returns {Promise<RootTask>}
226
+ */
227
+ static entrypointsSubscribe(callback: Function): Promise<RootTask>;
226
228
  /**
227
229
  * Create a tar.gz archive and return bytes (no file I/O)
228
- * This is useful for main thread execution without OPFS access
229
230
  * @param {any} files
230
231
  * @returns {Promise<Uint8Array>}
231
232
  */
232
233
  static gzip(files: any): Promise<Uint8Array>;
234
+ /**
235
+ * Subscribe to HMR events for a specific identifier.
236
+ * Returns a RootTask that must be held by JS to keep the subscription active.
237
+ * @param {string} identifier
238
+ * @param {Function} callback
239
+ * @returns {Promise<RootTask>}
240
+ */
241
+ static hmrEvents(identifier: string, callback: Function): Promise<RootTask>;
233
242
  /**
234
243
  * @param {string} thread_url
235
244
  */
@@ -251,6 +260,28 @@ export class Project {
251
260
  * @returns {Promise<string>}
252
261
  */
253
262
  static sigMd5(content: Uint8Array): Promise<string>;
263
+ /**
264
+ * Subscribe to compilation lifecycle events.
265
+ * Emits "start" when computation begins, "end" when idle for aggregation_ms.
266
+ * @param {number} aggregation_ms
267
+ * @param {Function} callback
268
+ */
269
+ static updateInfoSubscribe(aggregation_ms: number, callback: Function): void;
270
+ /**
271
+ * Write all entrypoints to disk.
272
+ * @param {Function} callback
273
+ */
274
+ static writeAllToDisk(callback: Function): void;
275
+ __destroy_into_raw(): number | undefined;
276
+ __wbg_ptr: number | undefined;
277
+ free(): void;
278
+ }
279
+ /**
280
+ * A root task handle that keeps the turbo-tasks subscription alive.
281
+ * This must be held by JS to keep the subscription active.
282
+ */
283
+ export class RootTask {
284
+ static __wrap(ptr: any): any;
254
285
  __destroy_into_raw(): number | undefined;
255
286
  __wbg_ptr: number | undefined;
256
287
  free(): void;
package/esm/utoo/index.js CHANGED
@@ -507,12 +507,6 @@ export class Project {
507
507
  }
508
508
  /**
509
509
  * Generate package-lock.json by resolving dependencies.
510
- *
511
- * # Arguments
512
- * * `registry` - Optional registry URL. If None, uses npmmirror.
513
- * - "https://registry.npmmirror.com" - supports semver queries (faster)
514
- * - "https://registry.npmjs.org" - official npm registry (slower, fetches full manifest)
515
- * * `concurrency` - Optional concurrency limit (defaults to 20)
516
510
  * @param {string | null} [registry]
517
511
  * @param {number | null} [concurrency]
518
512
  * @returns {Promise<string>}
@@ -523,9 +517,19 @@ export class Project {
523
517
  const ret = wasm.project_deps(ptr0, len0, isLikeNone(concurrency) ? 0x100000001 : (concurrency) >>> 0);
524
518
  return takeObject(ret);
525
519
  }
520
+ /**
521
+ * Subscribe to entrypoints changes with HMR support.
522
+ * This will watch for file changes and automatically rebuild.
523
+ * Returns a RootTask that must be held by JS to keep the subscription active.
524
+ * @param {Function} callback
525
+ * @returns {Promise<RootTask>}
526
+ */
527
+ static entrypointsSubscribe(callback) {
528
+ const ret = wasm.project_entrypointsSubscribe(addHeapObject(callback));
529
+ return takeObject(ret);
530
+ }
526
531
  /**
527
532
  * Create a tar.gz archive and return bytes (no file I/O)
528
- * This is useful for main thread execution without OPFS access
529
533
  * @param {any} files
530
534
  * @returns {Promise<Uint8Array>}
531
535
  */
@@ -533,6 +537,19 @@ export class Project {
533
537
  const ret = wasm.project_gzip(addHeapObject(files));
534
538
  return takeObject(ret);
535
539
  }
540
+ /**
541
+ * Subscribe to HMR events for a specific identifier.
542
+ * Returns a RootTask that must be held by JS to keep the subscription active.
543
+ * @param {string} identifier
544
+ * @param {Function} callback
545
+ * @returns {Promise<RootTask>}
546
+ */
547
+ static hmrEvents(identifier, callback) {
548
+ const ptr0 = passStringToWasm0(identifier, wasm.__wbindgen_export, wasm.__wbindgen_export2);
549
+ const len0 = WASM_VECTOR_LEN;
550
+ const ret = wasm.project_hmrEvents(ptr0, len0, addHeapObject(callback));
551
+ return takeObject(ret);
552
+ }
536
553
  /**
537
554
  * @param {string} thread_url
538
555
  */
@@ -570,9 +587,50 @@ export class Project {
570
587
  const ret = wasm.project_sigMd5(addHeapObject(content));
571
588
  return takeObject(ret);
572
589
  }
590
+ /**
591
+ * Subscribe to compilation lifecycle events.
592
+ * Emits "start" when computation begins, "end" when idle for aggregation_ms.
593
+ * @param {number} aggregation_ms
594
+ * @param {Function} callback
595
+ */
596
+ static updateInfoSubscribe(aggregation_ms, callback) {
597
+ wasm.project_updateInfoSubscribe(aggregation_ms, addHeapObject(callback));
598
+ }
599
+ /**
600
+ * Write all entrypoints to disk.
601
+ * @param {Function} callback
602
+ */
603
+ static writeAllToDisk(callback) {
604
+ wasm.project_writeAllToDisk(addHeapObject(callback));
605
+ }
573
606
  }
574
607
  if (Symbol.dispose)
575
608
  Project.prototype[Symbol.dispose] = Project.prototype.free;
609
+ /**
610
+ * A root task handle that keeps the turbo-tasks subscription alive.
611
+ * This must be held by JS to keep the subscription active.
612
+ */
613
+ export class RootTask {
614
+ static __wrap(ptr) {
615
+ ptr = ptr >>> 0;
616
+ const obj = Object.create(RootTask.prototype);
617
+ obj.__wbg_ptr = ptr;
618
+ RootTaskFinalization.register(obj, obj.__wbg_ptr, obj);
619
+ return obj;
620
+ }
621
+ __destroy_into_raw() {
622
+ const ptr = this.__wbg_ptr;
623
+ this.__wbg_ptr = 0;
624
+ RootTaskFinalization.unregister(this);
625
+ return ptr;
626
+ }
627
+ free() {
628
+ const ptr = this.__destroy_into_raw();
629
+ wasm.__wbg_roottask_free(ptr, 0);
630
+ }
631
+ }
632
+ if (Symbol.dispose)
633
+ RootTask.prototype[Symbol.dispose] = RootTask.prototype.free;
576
634
  export class WasmTaskMessage {
577
635
  static __wrap(ptr) {
578
636
  ptr = ptr >>> 0;
@@ -844,13 +902,6 @@ function __wbg_get_imports(memory) {
844
902
  const ret = Error(getStringFromWasm0(arg0, arg1));
845
903
  return addHeapObject(ret);
846
904
  },
847
- __wbg_String_8f0eb39a4a4c2f66: function (arg0, arg1) {
848
- const ret = String(getObject(arg1));
849
- const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
850
- const len1 = WASM_VECTOR_LEN;
851
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
852
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
853
- },
854
905
  __wbg___wbindgen_debug_string_0bc8482c6e3508ae: function (arg0, arg1) {
855
906
  const ret = debugString(getObject(arg1));
856
907
  const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
@@ -867,10 +918,6 @@ function __wbg_get_imports(memory) {
867
918
  const ret = typeof (val) === 'object' && val !== null;
868
919
  return ret;
869
920
  },
870
- __wbg___wbindgen_is_string_cd444516edc5b180: function (arg0) {
871
- const ret = typeof (getObject(arg0)) === 'string';
872
- return ret;
873
- },
874
921
  __wbg___wbindgen_is_undefined_9e4d92534c42d778: function (arg0) {
875
922
  const ret = getObject(arg0) === undefined;
876
923
  return ret;
@@ -1227,7 +1274,7 @@ function __wbg_get_imports(memory) {
1227
1274
  const a = state0.a;
1228
1275
  state0.a = 0;
1229
1276
  try {
1230
- return __wasm_bindgen_func_elem_3447(a, state0.b, arg0, arg1);
1277
+ return __wasm_bindgen_func_elem_3247(a, state0.b, arg0, arg1);
1231
1278
  }
1232
1279
  finally {
1233
1280
  state0.a = a;
@@ -1250,10 +1297,6 @@ function __wbg_get_imports(memory) {
1250
1297
  const ret = new FileSystemObserver(getObject(arg0));
1251
1298
  return addHeapObject(ret);
1252
1299
  },
1253
- __wbg_new_dca287b076112a51: function () {
1254
- const ret = new Map();
1255
- return addHeapObject(ret);
1256
- },
1257
1300
  __wbg_new_dd2b680c8bf6ae29: function (arg0) {
1258
1301
  const ret = new Uint8Array(getObject(arg0));
1259
1302
  return addHeapObject(ret);
@@ -1320,6 +1363,12 @@ function __wbg_get_imports(memory) {
1320
1363
  const ret = Array.of(getObject(arg0), getObject(arg1), getObject(arg2));
1321
1364
  return addHeapObject(ret);
1322
1365
  },
1366
+ __wbg_parse_708461a1feddfb38: function () {
1367
+ return handleError(function (arg0, arg1) {
1368
+ const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
1369
+ return addHeapObject(ret);
1370
+ }, arguments);
1371
+ },
1323
1372
  __wbg_performance_6adc3b899e448a23: function (arg0) {
1324
1373
  const ret = getObject(arg0).performance;
1325
1374
  return addHeapObject(ret);
@@ -1368,6 +1417,10 @@ function __wbg_get_imports(memory) {
1368
1417
  const ret = getObject(arg0).root;
1369
1418
  return addHeapObject(ret);
1370
1419
  },
1420
+ __wbg_roottask_new: function (arg0) {
1421
+ const ret = RootTask.__wrap(arg0);
1422
+ return addHeapObject(ret);
1423
+ },
1371
1424
  __wbg_setTimeout_63008613644b07af: function () {
1372
1425
  return handleError(function (arg0, arg1, arg2) {
1373
1426
  const ret = getObject(arg0).setTimeout(getObject(arg1), arg2);
@@ -1378,13 +1431,6 @@ function __wbg_get_imports(memory) {
1378
1431
  const ret = setTimeout(getObject(arg0), arg1);
1379
1432
  return addHeapObject(ret);
1380
1433
  },
1381
- __wbg_set_1eb0999cf5d27fc8: function (arg0, arg1, arg2) {
1382
- const ret = getObject(arg0).set(getObject(arg1), getObject(arg2));
1383
- return addHeapObject(ret);
1384
- },
1385
- __wbg_set_3f1d0b984ed272ed: function (arg0, arg1, arg2) {
1386
- getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
1387
- },
1388
1434
  __wbg_set_body_9a7e00afe3cfe244: function (arg0, arg1) {
1389
1435
  getObject(arg0).body = getObject(arg1);
1390
1436
  },
@@ -1548,33 +1594,33 @@ function __wbg_get_imports(memory) {
1548
1594
  return addHeapObject(ret);
1549
1595
  },
1550
1596
  __wbindgen_cast_0000000000000001: function (arg0, arg1) {
1551
- // Cast intrinsic for `Closure(Closure { dtor_idx: 1878, function: Function { arguments: [Externref], shim_idx: 7388, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1552
- const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_22681, __wasm_bindgen_func_elem_83554);
1597
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 1845, function: Function { arguments: [Externref], shim_idx: 7400, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1598
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_22596, __wasm_bindgen_func_elem_83828);
1553
1599
  return addHeapObject(ret);
1554
1600
  },
1555
1601
  __wbindgen_cast_0000000000000002: function (arg0, arg1) {
1556
- // Cast intrinsic for `Closure(Closure { dtor_idx: 1878, function: Function { arguments: [NamedExternref("Array<any>")], shim_idx: 7381, ret: Unit, inner_ret: Some(Unit) }, mutable: false }) -> Externref`.
1557
- const ret = makeClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_22681, __wasm_bindgen_func_elem_83231);
1602
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 1845, function: Function { arguments: [NamedExternref("Array<any>")], shim_idx: 7384, ret: Unit, inner_ret: Some(Unit) }, mutable: false }) -> Externref`.
1603
+ const ret = makeClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_22596, __wasm_bindgen_func_elem_83390);
1558
1604
  return addHeapObject(ret);
1559
1605
  },
1560
1606
  __wbindgen_cast_0000000000000003: function (arg0, arg1) {
1561
- // Cast intrinsic for `Closure(Closure { dtor_idx: 1878, function: Function { arguments: [NamedExternref("MessageEvent")], shim_idx: 7388, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1562
- const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_22681, __wasm_bindgen_func_elem_83554);
1607
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 1845, function: Function { arguments: [NamedExternref("MessageEvent")], shim_idx: 7400, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1608
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_22596, __wasm_bindgen_func_elem_83828);
1563
1609
  return addHeapObject(ret);
1564
1610
  },
1565
1611
  __wbindgen_cast_0000000000000004: function (arg0, arg1) {
1566
- // Cast intrinsic for `Closure(Closure { dtor_idx: 1878, function: Function { arguments: [], shim_idx: 1879, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1567
- const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_22681, __wasm_bindgen_func_elem_22682);
1612
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 1845, function: Function { arguments: [], shim_idx: 1846, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1613
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_22596, __wasm_bindgen_func_elem_22597);
1568
1614
  return addHeapObject(ret);
1569
1615
  },
1570
1616
  __wbindgen_cast_0000000000000005: function (arg0, arg1) {
1571
- // Cast intrinsic for `Closure(Closure { dtor_idx: 7392, function: Function { arguments: [Ref(NamedExternref("MessageEvent"))], shim_idx: 7393, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1572
- const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_83606, __wasm_bindgen_func_elem_83607);
1617
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 7404, function: Function { arguments: [Ref(NamedExternref("MessageEvent"))], shim_idx: 7405, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1618
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_83880, __wasm_bindgen_func_elem_83881);
1573
1619
  return addHeapObject(ret);
1574
1620
  },
1575
1621
  __wbindgen_cast_0000000000000006: function (arg0, arg1) {
1576
- // Cast intrinsic for `Closure(Closure { dtor_idx: 7392, function: Function { arguments: [], shim_idx: 1879, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1577
- const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_83606, __wasm_bindgen_func_elem_22682);
1622
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 7404, function: Function { arguments: [], shim_idx: 1846, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1623
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_83880, __wasm_bindgen_func_elem_22597);
1578
1624
  return addHeapObject(ret);
1579
1625
  },
1580
1626
  __wbindgen_cast_0000000000000007: function (arg0) {
@@ -1582,22 +1628,12 @@ function __wbg_get_imports(memory) {
1582
1628
  const ret = arg0;
1583
1629
  return addHeapObject(ret);
1584
1630
  },
1585
- __wbindgen_cast_0000000000000008: function (arg0) {
1586
- // Cast intrinsic for `I64 -> Externref`.
1587
- const ret = arg0;
1588
- return addHeapObject(ret);
1589
- },
1590
- __wbindgen_cast_0000000000000009: function (arg0, arg1) {
1631
+ __wbindgen_cast_0000000000000008: function (arg0, arg1) {
1591
1632
  // Cast intrinsic for `Ref(String) -> Externref`.
1592
1633
  const ret = getStringFromWasm0(arg0, arg1);
1593
1634
  return addHeapObject(ret);
1594
1635
  },
1595
- __wbindgen_cast_000000000000000a: function (arg0) {
1596
- // Cast intrinsic for `U64 -> Externref`.
1597
- const ret = BigInt.asUintN(64, arg0);
1598
- return addHeapObject(ret);
1599
- },
1600
- __wbindgen_cast_000000000000000b: function (arg0, arg1) {
1636
+ __wbindgen_cast_0000000000000009: function (arg0, arg1) {
1601
1637
  var v0 = getArrayJsValueFromWasm0(arg0, arg1).slice();
1602
1638
  wasm.__wbindgen_export4(arg0, arg1 * 4, 4);
1603
1639
  // Cast intrinsic for `Vector(NamedExternref("DirEntry")) -> Externref`.
@@ -1632,25 +1668,25 @@ function __wbg_get_imports(memory) {
1632
1668
  "./index_bg.js": import0,
1633
1669
  };
1634
1670
  }
1635
- function __wasm_bindgen_func_elem_22682(arg0, arg1) {
1636
- wasm.__wasm_bindgen_func_elem_22682(arg0, arg1);
1671
+ function __wasm_bindgen_func_elem_22597(arg0, arg1) {
1672
+ wasm.__wasm_bindgen_func_elem_22597(arg0, arg1);
1637
1673
  }
1638
- function __wasm_bindgen_func_elem_83554(arg0, arg1, arg2) {
1639
- wasm.__wasm_bindgen_func_elem_83554(arg0, arg1, addHeapObject(arg2));
1674
+ function __wasm_bindgen_func_elem_83828(arg0, arg1, arg2) {
1675
+ wasm.__wasm_bindgen_func_elem_83828(arg0, arg1, addHeapObject(arg2));
1640
1676
  }
1641
- function __wasm_bindgen_func_elem_83231(arg0, arg1, arg2) {
1642
- wasm.__wasm_bindgen_func_elem_83231(arg0, arg1, addHeapObject(arg2));
1677
+ function __wasm_bindgen_func_elem_83390(arg0, arg1, arg2) {
1678
+ wasm.__wasm_bindgen_func_elem_83390(arg0, arg1, addHeapObject(arg2));
1643
1679
  }
1644
- function __wasm_bindgen_func_elem_83607(arg0, arg1, arg2) {
1680
+ function __wasm_bindgen_func_elem_83881(arg0, arg1, arg2) {
1645
1681
  try {
1646
- wasm.__wasm_bindgen_func_elem_83607(arg0, arg1, addBorrowedObject(arg2));
1682
+ wasm.__wasm_bindgen_func_elem_83881(arg0, arg1, addBorrowedObject(arg2));
1647
1683
  }
1648
1684
  finally {
1649
1685
  heap[stack_pointer++] = undefined;
1650
1686
  }
1651
1687
  }
1652
- function __wasm_bindgen_func_elem_3447(arg0, arg1, arg2, arg3) {
1653
- wasm.__wasm_bindgen_func_elem_3447(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
1688
+ function __wasm_bindgen_func_elem_3247(arg0, arg1, arg2, arg3) {
1689
+ wasm.__wasm_bindgen_func_elem_3247(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
1654
1690
  }
1655
1691
  const __wbindgen_enum_DirEntryType = ["file", "directory"];
1656
1692
  const __wbindgen_enum_FileSystemChangeRecordType = ["appeared", "disappeared", "errored", "modified", "moved", "unknown"];
@@ -1674,6 +1710,9 @@ const MetadataFinalization = (typeof FinalizationRegistry === 'undefined')
1674
1710
  const ProjectFinalization = (typeof FinalizationRegistry === 'undefined')
1675
1711
  ? { register: () => { }, unregister: () => { } }
1676
1712
  : new FinalizationRegistry(ptr => wasm.__wbg_project_free(ptr >>> 0, 1));
1713
+ const RootTaskFinalization = (typeof FinalizationRegistry === 'undefined')
1714
+ ? { register: () => { }, unregister: () => { } }
1715
+ : new FinalizationRegistry(ptr => wasm.__wbg_roottask_free(ptr >>> 0, 1));
1677
1716
  const WasmTaskMessageFinalization = (typeof FinalizationRegistry === 'undefined')
1678
1717
  ? { register: () => { }, unregister: () => { } }
1679
1718
  : new FinalizationRegistry(ptr => wasm.__wbg_wasmtaskmessage_free(ptr >>> 0, 1));
Binary file
@@ -1,4 +1,4 @@
1
- import initWasm, { Fs, recvTaskMessageInWorker, sendTaskMessage, workerCreated, } from "../utoo";
1
+ import { Fs, initSync, recvTaskMessageInWorker, sendTaskMessage, workerCreated, } from "../utoo";
2
2
  import { cjs } from "./cjs";
3
3
  const binding = {
4
4
  recvTaskMessageInWorker,
@@ -6,12 +6,15 @@ const binding = {
6
6
  workerCreated,
7
7
  };
8
8
  export function startLoaderWorker() {
9
- self.onmessage = async (event) => {
9
+ self.onmessage = (event) => {
10
10
  let [module, memory, meta] = event.data;
11
- await initWasm(module, memory).catch((err) => {
12
- console.log(err);
11
+ try {
12
+ initSync({ module, memory });
13
+ }
14
+ catch (err) {
15
+ console.error(err);
13
16
  throw err;
14
- });
17
+ }
15
18
  self.workerData = {
16
19
  threadId: meta.workerData.threadId,
17
20
  cwd: meta.workerData.cwd,