@utoo/web 1.2.0-rc.9 → 1.2.1

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,7 +1,8 @@
1
- import { PackFile, ProjectEndpoint, Stats } from "../types";
1
+ import { DepsOptions, PackFile, ProjectEndpoint, Stats } from "../types";
2
2
  export declare class ForkedProject implements ProjectEndpoint {
3
3
  private endpoint;
4
4
  constructor(port: MessagePort);
5
+ deps(options?: DepsOptions): Promise<string>;
5
6
  install(packageLock: string, maxConcurrentDownloads?: number): Promise<void>;
6
7
  build(): Promise<import("..").BuildOutput>;
7
8
  readFile(path: string, encoding?: "utf8"): Promise<any>;
@@ -1,10 +1,13 @@
1
1
  import * as comlink from "comlink";
2
- import { Stats } from "../types";
2
+ import { Stats, } from "../types";
3
3
  export class ForkedProject {
4
4
  constructor(port) {
5
5
  var _a;
6
6
  (_a = this.endpoint) !== null && _a !== void 0 ? _a : (this.endpoint = comlink.wrap(port));
7
7
  }
8
+ async deps(options) {
9
+ return await this.endpoint.deps(options);
10
+ }
8
11
  async install(packageLock, maxConcurrentDownloads) {
9
12
  return await this.endpoint.install(packageLock, maxConcurrentDownloads);
10
13
  }
@@ -1,10 +1,11 @@
1
- import { PackFile, ProjectEndpoint, ProjectOptions, Stats } from "../types";
1
+ import { DepsOptions, PackFile, ProjectEndpoint, ProjectOptions, Stats } from "../types";
2
2
  import initWasm from "../utoo";
3
3
  declare class InternalEndpoint implements ProjectEndpoint {
4
4
  wasmInit?: ReturnType<typeof initWasm>;
5
5
  options?: Omit<ProjectOptions, "workerUrl" | "serviceWorker">;
6
6
  loaderWorkerPoolInitialized: boolean;
7
7
  mount(opt: Omit<ProjectOptions, "workerUrl" | "serviceWorker">): Promise<void>;
8
+ deps(options?: DepsOptions): Promise<string>;
8
9
  install(packageLock: string, maxConcurrentDownloads?: number): Promise<void>;
9
10
  build(): Promise<any>;
10
11
  readFile(path: string, encoding?: "utf8"): Promise<any>;
@@ -1,5 +1,4 @@
1
- import * as comlink from "comlink";
2
- import initWasm, { init_log_filter, Project as ProjectInternal, } from "../utoo";
1
+ import initWasm, { initLogFilter, Project as ProjectInternal, } from "../utoo";
3
2
  import { runLoaderWorkerPool } from "../webpackLoaders/loaderWorkerPool";
4
3
  class InternalEndpoint {
5
4
  constructor() {
@@ -13,13 +12,19 @@ class InternalEndpoint {
13
12
  (_a = this.wasmInit) !== null && _a !== void 0 ? _a : (this.wasmInit = initWasm(wasmUrl));
14
13
  await this.wasmInit;
15
14
  // Initialize log filter after wasm init
16
- const filter = logFilter || "pack_core=info,pack_api=info,utoo_wasm=info";
17
- init_log_filter(filter);
15
+ const filter = logFilter ||
16
+ "pack_core=info,pack_api=info,utoo_wasm=info,utoo_ruborist=info";
17
+ initLogFilter(filter);
18
18
  const absoluteCwd = cwd.startsWith("/") ? cwd : "/" + cwd;
19
19
  ProjectInternal.init(threadWorkerUrl || "");
20
20
  ProjectInternal.setCwd(absoluteCwd);
21
21
  return;
22
22
  }
23
+ async deps(options) {
24
+ var _a, _b;
25
+ 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);
27
+ }
23
28
  async install(packageLock, maxConcurrentDownloads) {
24
29
  await this.wasmInit;
25
30
  await ProjectInternal.install(packageLock, maxConcurrentDownloads);
@@ -41,8 +46,7 @@ class InternalEndpoint {
41
46
  ret = await ProjectInternal.readToString(path);
42
47
  }
43
48
  else {
44
- ret = await ProjectInternal.read(path);
45
- return comlink.transfer(ret, [ret.buffer]);
49
+ return await ProjectInternal.read(path);
46
50
  }
47
51
  return ret;
48
52
  }
@@ -114,8 +118,7 @@ class InternalEndpoint {
114
118
  }
115
119
  async gzip(files) {
116
120
  await this.wasmInit;
117
- const ret = await ProjectInternal.gzip(files);
118
- return comlink.transfer(ret, [ret.buffer]);
121
+ return await ProjectInternal.gzip(files);
119
122
  }
120
123
  async sigMd5(content) {
121
124
  await this.wasmInit;
@@ -1,4 +1,4 @@
1
- import { BuildOutput, Dirent, PackFile, ProjectEndpoint, ProjectOptions, ServiceWorkerOptions, Stats } from "../types";
1
+ import { BuildOutput, DepsOptions, Dirent, PackFile, ProjectEndpoint, ProjectOptions, ServiceWorkerOptions, Stats } from "../types";
2
2
  export declare class Project implements ProjectEndpoint {
3
3
  #private;
4
4
  private options;
@@ -9,6 +9,7 @@ export declare class Project implements ProjectEndpoint {
9
9
  private connectWorker;
10
10
  installServiceWorker(): Promise<void>;
11
11
  mount(): Promise<void>;
12
+ deps(options?: DepsOptions): Promise<string>;
12
13
  install(packageLock: string, maxConcurrentDownloads?: number): Promise<void>;
13
14
  build(): Promise<BuildOutput>;
14
15
  readFile(path: string, encoding?: "utf8"): Promise<any>;
@@ -65,6 +65,10 @@ export class Project {
65
65
  async mount() {
66
66
  return await __classPrivateFieldGet(this, _Project_mount, "f");
67
67
  }
68
+ async deps(options) {
69
+ await __classPrivateFieldGet(this, _Project_mount, "f");
70
+ return await this.remote.deps(options);
71
+ }
68
72
  async install(packageLock, maxConcurrentDownloads) {
69
73
  await __classPrivateFieldGet(this, _Project_mount, "f");
70
74
  return await this.remote.install(packageLock, maxConcurrentDownloads);
@@ -82,7 +86,7 @@ export class Project {
82
86
  async writeFile(path, content, encoding) {
83
87
  await __classPrivateFieldGet(this, _Project_mount, "f");
84
88
  if (content instanceof Uint8Array) {
85
- return await this.remote.writeFile(path, comlink.transfer(content, [content.buffer]), encoding);
89
+ return await this.remote.writeFile(path, content, encoding);
86
90
  }
87
91
  return await this.remote.writeFile(path, content, encoding);
88
92
  }
@@ -114,12 +118,11 @@ export class Project {
114
118
  }
115
119
  async gzip(files) {
116
120
  await __classPrivateFieldGet(this, _Project_mount, "f");
117
- const buffers = files.map((f) => f.content.buffer);
118
- return await this.remote.gzip(comlink.transfer(files, buffers));
121
+ return await this.remote.gzip(files);
119
122
  }
120
123
  async sigMd5(content) {
121
124
  await __classPrivateFieldGet(this, _Project_mount, "f");
122
- return await this.remote.sigMd5(comlink.transfer(content, [content.buffer]));
125
+ return await this.remote.sigMd5(content);
123
126
  }
124
127
  static fork(channel, eventSource) {
125
128
  (eventSource || self).postMessage(Fork, {
package/esm/types.d.ts CHANGED
@@ -55,7 +55,12 @@ export interface PackFile {
55
55
  path: string;
56
56
  content: Uint8Array;
57
57
  }
58
+ export interface DepsOptions {
59
+ registry?: string | null;
60
+ concurrency?: number | null;
61
+ }
58
62
  export interface ProjectEndpoint {
63
+ deps: (options?: DepsOptions) => Promise<string>;
59
64
  install: (packageLock: string, maxConcurrentDownloads?: number) => Promise<void>;
60
65
  build: () => Promise<BuildOutput>;
61
66
  readFile(path: string): Promise<Uint8Array>;
@@ -1,32 +1,32 @@
1
- /**
2
- * @param {number} worker_id
3
- * @returns {Promise<WasmTaskMessage>}
4
- */
5
- export function recvTaskMessageInWorker(worker_id: number): Promise<WasmTaskMessage>;
6
- /**
7
- * @param {any} message
8
- * @returns {Promise<void>}
9
- */
10
- export function sendTaskMessage(message: any): Promise<void>;
11
1
  /**
12
2
  * @param {string} filter
13
3
  */
14
- export function init_log_filter(filter: string): void;
4
+ export function initLogFilter(filter: string): void;
15
5
  export function init_pack(): void;
16
6
  /**
17
7
  * @param {number} worker_id
8
+ * @returns {Promise<WasmTaskMessage>}
18
9
  */
19
- export function workerCreated(worker_id: number): void;
10
+ export function recvTaskMessageInWorker(worker_id: number): Promise<WasmTaskMessage>;
20
11
  /**
21
12
  * @param {Function} creator
22
13
  * @param {Function} terminator
23
14
  */
24
15
  export function registerWorkerScheduler(creator: Function, terminator: Function): void;
16
+ /**
17
+ * @param {any} message
18
+ * @returns {Promise<void>}
19
+ */
20
+ export function sendTaskMessage(message: any): Promise<void>;
25
21
  /**
26
22
  * Entry point for web workers
27
23
  * @param {number} ptr
28
24
  */
29
25
  export function wasm_thread_entry_point(ptr: number): void;
26
+ /**
27
+ * @param {number} worker_id
28
+ */
29
+ export function workerCreated(worker_id: number): void;
30
30
  export class CreateSyncAccessHandleOptions {
31
31
  static __wrap(ptr: any): any;
32
32
  __destroy_into_raw(): number | undefined;
@@ -99,6 +99,11 @@ export class Project {
99
99
  * @returns {Promise<void>}
100
100
  */
101
101
  static removeDir(path: string, recursive: boolean): Promise<void>;
102
+ /**
103
+ * @param {string} path
104
+ * @param {Uint8Array} content
105
+ */
106
+ static writeSync(path: string, content: Uint8Array): void;
102
107
  /**
103
108
  * @param {string} path
104
109
  * @returns {Promise<void>}
@@ -110,6 +115,21 @@ export class Project {
110
115
  * @returns {Promise<void>}
111
116
  */
112
117
  static writeString(path: string, content: string): Promise<void>;
118
+ /**
119
+ * @param {string} path
120
+ * @returns {Metadata}
121
+ */
122
+ static metadataSync(path: string): Metadata;
123
+ /**
124
+ * @param {string} path
125
+ * @returns {DirEntry[]}
126
+ */
127
+ static readDirSync(path: string): DirEntry[];
128
+ /**
129
+ * @param {string} src
130
+ * @param {string} dst
131
+ */
132
+ static copyFileSync(src: string, dst: string): void;
113
133
  /**
114
134
  * @param {string} path
115
135
  * @returns {Promise<void>}
@@ -120,17 +140,47 @@ export class Project {
120
140
  * @returns {Promise<string>}
121
141
  */
122
142
  static readToString(path: string): Promise<string>;
143
+ /**
144
+ * @param {string} path
145
+ */
146
+ static createDirSync(path: string): void;
147
+ /**
148
+ * @param {string} path
149
+ * @param {boolean} recursive
150
+ */
151
+ static removeDirSync(path: string, recursive: boolean): void;
152
+ /**
153
+ * @param {string} path
154
+ */
155
+ static removeFileSync(path: string): void;
156
+ /**
157
+ * @param {string} path
158
+ */
159
+ static createDirAllSync(path: string): void;
123
160
  /**
124
161
  * @returns {string}
125
162
  */
126
163
  static get cwd(): string;
164
+ /**
165
+ * Generate package-lock.json by resolving dependencies.
166
+ *
167
+ * # Arguments
168
+ * * `registry` - Optional registry URL. If None, uses npmmirror.
169
+ * - "https://registry.npmmirror.com" - supports semver queries (faster)
170
+ * - "https://registry.npmjs.org" - official npm registry (slower, fetches full manifest)
171
+ * * `concurrency` - Optional concurrency limit (defaults to 20)
172
+ * @param {string | null} [registry]
173
+ * @param {number | null} [concurrency]
174
+ * @returns {Promise<string>}
175
+ */
176
+ static deps(registry?: string | null, concurrency?: number | null): Promise<string>;
127
177
  /**
128
178
  * Create a tar.gz archive and return bytes (no file I/O)
129
179
  * This is useful for main thread execution without OPFS access
130
180
  * @param {any} files
131
- * @returns {Uint8Array}
181
+ * @returns {Promise<Uint8Array>}
132
182
  */
133
- static gzip(files: any): Uint8Array;
183
+ static gzip(files: any): Promise<Uint8Array>;
134
184
  /**
135
185
  * @param {string} thread_url
136
186
  */
@@ -161,11 +211,11 @@ export class Project {
161
211
  */
162
212
  static setCwd(path: string): void;
163
213
  /**
164
- * Calculate MD5 hash of byte content
214
+ * Calculate MD5 hash of byte content (async for better thread scheduling)
165
215
  * @param {Uint8Array} content
166
- * @returns {string}
216
+ * @returns {Promise<string>}
167
217
  */
168
- static sigMd5(content: Uint8Array): string;
218
+ static sigMd5(content: Uint8Array): Promise<string>;
169
219
  /**
170
220
  * @param {string} path
171
221
  * @returns {Promise<Metadata>}
@@ -182,6 +232,11 @@ export class Project {
182
232
  * @returns {Promise<void>}
183
233
  */
184
234
  static copyFile(src: string, dst: string): Promise<void>;
235
+ /**
236
+ * @param {string} path
237
+ * @returns {Uint8Array}
238
+ */
239
+ static readSync(path: string): Uint8Array;
185
240
  __destroy_into_raw(): number | undefined;
186
241
  __wbg_ptr: number | undefined;
187
242
  free(): void;
@@ -191,6 +246,10 @@ export class WasmTaskMessage {
191
246
  __destroy_into_raw(): number | undefined;
192
247
  __wbg_ptr: number | undefined;
193
248
  free(): void;
249
+ /**
250
+ * @returns {Uint8Array}
251
+ */
252
+ get data(): Uint8Array;
194
253
  /**
195
254
  * @param {number} arg0
196
255
  */
@@ -199,14 +258,6 @@ export class WasmTaskMessage {
199
258
  * @returns {number}
200
259
  */
201
260
  get taskId(): number;
202
- /**
203
- * @param {string} arg0
204
- */
205
- set data(arg0: string);
206
- /**
207
- * @returns {string}
208
- */
209
- get data(): string;
210
261
  }
211
262
  export class WebWorkerCreation {
212
263
  static __wrap(ptr: any): any;