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

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.
Files changed (38) hide show
  1. package/esm/{3ec3463a197b5c4bac1e.wasm → fe3ccd485f4eb7cd1a1e.wasm} +0 -0
  2. package/esm/forkedProject.d.ts +2 -1
  3. package/esm/forkedProject.js +5 -0
  4. package/esm/internalProject.d.ts +3 -3
  5. package/esm/internalProject.js +33 -20
  6. package/esm/loaderWorker.js +1 -1
  7. package/esm/project.d.ts +2 -1
  8. package/esm/project.js +6 -1
  9. package/esm/sabcom.d.ts +6 -0
  10. package/esm/sabcom.js +53 -5
  11. package/esm/serviceWorker.js +1 -0
  12. package/esm/type.d.ts +38 -0
  13. package/esm/type.js +44 -0
  14. package/esm/utoo/index.d.ts +27 -24
  15. package/esm/utoo/index.js +97 -95
  16. package/esm/utoo/index_bg.wasm +0 -0
  17. package/esm/webpackLoaders/{worker/cjs.js → cjs.js} +71 -64
  18. package/esm/webpackLoaders/loaderWorkerPool.d.ts +2 -0
  19. package/esm/{loaderWorkerPool.js → webpackLoaders/loaderWorkerPool.js} +30 -18
  20. package/esm/webpackLoaders/polyfills/fsPolyfill.d.ts +78 -0
  21. package/esm/webpackLoaders/polyfills/fsPolyfill.js +279 -0
  22. package/esm/webpackLoaders/polyfills/fsPromisesPolyfill.d.ts +26 -0
  23. package/esm/webpackLoaders/polyfills/fsPromisesPolyfill.js +112 -0
  24. package/esm/webpackLoaders/{worker/type.d.ts → type.d.ts} +1 -0
  25. package/esm/webpackLoaders/{worker/index.js → worker.js} +8 -3
  26. package/package.json +4 -3
  27. package/esm/loaderWorkerPool.d.ts +0 -3
  28. package/esm/webpackLoaders/worker/polyfills/fsPolyfill.d.ts +0 -244
  29. package/esm/webpackLoaders/worker/polyfills/fsPolyfill.js +0 -369
  30. package/esm/webpackLoaders/worker/polyfills/fsPromisesPolyfill.d.ts +0 -9
  31. package/esm/webpackLoaders/worker/polyfills/fsPromisesPolyfill.js +0 -9
  32. /package/esm/webpackLoaders/{worker/cjs.d.ts → cjs.d.ts} +0 -0
  33. /package/esm/webpackLoaders/{worker/polyfills → polyfills}/nodePolyFills.d.ts +0 -0
  34. /package/esm/webpackLoaders/{worker/polyfills → polyfills}/nodePolyFills.js +0 -0
  35. /package/esm/webpackLoaders/{worker/polyfills → polyfills}/workerThreadsPolyfill.d.ts +0 -0
  36. /package/esm/webpackLoaders/{worker/polyfills → polyfills}/workerThreadsPolyfill.js +0 -0
  37. /package/esm/webpackLoaders/{worker/type.js → type.js} +0 -0
  38. /package/esm/webpackLoaders/{worker/index.d.ts → worker.d.ts} +0 -0
@@ -1,8 +1,8 @@
1
- import * as sabcom from "./sabcom";
2
- import initWasm, { registerWorkerScheduler, workerCreated, } from "./utoo";
1
+ import * as sabcom from "../sabcom";
2
+ import initWasm, { Project as ProjectInternal, registerWorkerScheduler, workerCreated, } from "../utoo";
3
3
  let nextWorkerId = 0;
4
4
  const loaderWorkers = {};
5
- export const runLoaderWorkerPool = async (binding, projectCwd, projectInternal, loaderWorkerUrl, loadersImportMap) => {
5
+ export const runLoaderWorkerPool = async (binding, projectCwd, loaderWorkerUrl, loadersImportMap) => {
6
6
  registerWorkerScheduler(async (creation) => {
7
7
  const { options: { filename, cwd }, } = creation;
8
8
  nextWorkerId += 1;
@@ -13,15 +13,15 @@ export const runLoaderWorkerPool = async (binding, projectCwd, projectInternal,
13
13
  worker.onmessage = async (event) => {
14
14
  if (event.data === "sab_request") {
15
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),
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
25
  });
26
26
  }
27
27
  };
@@ -29,15 +29,26 @@ export const runLoaderWorkerPool = async (binding, projectCwd, projectInternal,
29
29
  let finalFilename = filename;
30
30
  if (projectCwd) {
31
31
  const sep = "/";
32
- const pCwd = projectCwd.endsWith(sep)
32
+ let pCwd = projectCwd.endsWith(sep)
33
33
  ? projectCwd.slice(0, -1)
34
34
  : projectCwd;
35
- let cCwd = cwd.startsWith(sep) ? cwd.slice(1) : cwd;
36
- if (cCwd === "." || cCwd === "./") {
37
- cCwd = "";
35
+ if (!pCwd.startsWith(sep)) {
36
+ pCwd = sep + pCwd;
38
37
  }
39
- finalCwd = cCwd ? `${pCwd}${sep}${cCwd}` : pCwd;
40
- if (!filename.startsWith("/")) {
38
+ if (cwd.startsWith(sep)) {
39
+ finalCwd = cwd;
40
+ }
41
+ else {
42
+ let cCwd = cwd;
43
+ if (cCwd === "." || cCwd === "./") {
44
+ cCwd = "";
45
+ }
46
+ finalCwd = cCwd ? `${pCwd}${sep}${cCwd}` : pCwd;
47
+ }
48
+ if (filename.startsWith(sep)) {
49
+ finalFilename = filename;
50
+ }
51
+ else {
41
52
  let fName = filename;
42
53
  if (fName.startsWith("./"))
43
54
  fName = fName.slice(2);
@@ -51,6 +62,7 @@ export const runLoaderWorkerPool = async (binding, projectCwd, projectInternal,
51
62
  {
52
63
  workerData: {
53
64
  cwd: finalCwd,
65
+ projectRoot: projectCwd,
54
66
  workerId: workerId,
55
67
  },
56
68
  loaderAssets: {
@@ -0,0 +1,78 @@
1
+ import { Buffer } from "buffer";
2
+ import { Stats } from "../../type";
3
+ import { promises } from "./fsPromisesPolyfill";
4
+ export declare function readFileSync(path: string, options: any): string | Buffer<any>;
5
+ export declare function readdirSync(path: string, options?: any): any;
6
+ export declare function writeFileSync(path: string, data: string | Uint8Array, options?: any): void;
7
+ export declare function mkdirSync(path: string, options?: any): void;
8
+ export declare function rmSync(path: string, options?: any): void;
9
+ export declare function rmdirSync(path: string, options?: any): void;
10
+ export declare function copyFileSync(src: string, dst: string): void;
11
+ export declare function statSync(p: string): Stats;
12
+ export declare function lstatSync(p: string): Stats;
13
+ export declare function realpathSync(p: string): string;
14
+ export declare function accessSync(path: string, mode?: number): void;
15
+ export declare function existsSync(path: string): boolean;
16
+ export declare function readFile(path: string, options: any, cb: Function): void;
17
+ export declare function readdir(path: string, options: any, cb: Function): void;
18
+ export declare function writeFile(path: string, data: string | Uint8Array, options: any, cb: Function): void;
19
+ export declare function mkdir(path: string, options: any, cb: Function): void;
20
+ export declare function rm(path: string, options: any, cb: Function): void;
21
+ export declare function rmdir(path: string, options: any, cb: Function): void;
22
+ export declare function copyFile(src: string, dst: string, cb: Function): void;
23
+ export declare function stat(p: string, cb: Function): void;
24
+ export declare function lstat(p: string, cb: Function): void;
25
+ export declare function realpath(p: string, cb: Function): void;
26
+ export declare function access(p: string, mode: number | Function, cb?: Function): void;
27
+ export declare const constants: {
28
+ F_OK: number;
29
+ R_OK: number;
30
+ W_OK: number;
31
+ X_OK: number;
32
+ };
33
+ declare const _default: {
34
+ readFile: typeof readFile;
35
+ readFileSync: typeof readFileSync;
36
+ readdir: typeof readdir;
37
+ readdirSync: typeof readdirSync;
38
+ writeFile: typeof writeFile;
39
+ writeFileSync: typeof writeFileSync;
40
+ mkdir: typeof mkdir;
41
+ mkdirSync: typeof mkdirSync;
42
+ rm: typeof rm;
43
+ rmSync: typeof rmSync;
44
+ rmdir: typeof rmdir;
45
+ rmdirSync: typeof rmdirSync;
46
+ copyFile: typeof copyFile;
47
+ copyFileSync: typeof copyFileSync;
48
+ stat: typeof stat;
49
+ statSync: typeof statSync;
50
+ lstat: typeof lstat;
51
+ lstatSync: typeof lstatSync;
52
+ realpath: typeof realpath;
53
+ realpathSync: typeof realpathSync;
54
+ access: typeof access;
55
+ accessSync: typeof accessSync;
56
+ existsSync: typeof existsSync;
57
+ promises: {
58
+ readFile: (p: string, options?: any) => Promise<any>;
59
+ writeFile: (p: string, data: string | Uint8Array, options?: any) => Promise<void>;
60
+ readdir: (p: string, options?: any) => Promise<any>;
61
+ mkdir: (p: string, options?: any) => Promise<void>;
62
+ rm: (p: string, options?: any) => Promise<void>;
63
+ rmdir: (p: string, options?: any) => Promise<any>;
64
+ copyFile: (src: string, dst: string) => Promise<any>;
65
+ stat: (p: string) => Promise<Stats>;
66
+ lstat: (p: string) => Promise<Stats>;
67
+ realpath: (p: string) => Promise<string>;
68
+ access: (p: string, mode?: number) => Promise<void>;
69
+ };
70
+ constants: {
71
+ F_OK: number;
72
+ R_OK: number;
73
+ W_OK: number;
74
+ X_OK: number;
75
+ };
76
+ };
77
+ export default _default;
78
+ export { promises };
@@ -0,0 +1,279 @@
1
+ import { Buffer } from "buffer";
2
+ import path from "path";
3
+ import * as sabcom from "../../sabcom";
4
+ import { Stats } from "../../type";
5
+ import { promises } from "./fsPromisesPolyfill";
6
+ function resolvePath(p) {
7
+ var _a, _b, _c;
8
+ // @ts-ignore
9
+ 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) || "/";
10
+ return path.resolve(cwd, p);
11
+ }
12
+ function getSabClient() {
13
+ // @ts-ignore
14
+ const client = self.workerData.sabClient;
15
+ if (!client) {
16
+ throw new Error("Sync fs not supported (no sabClient)");
17
+ }
18
+ return client;
19
+ }
20
+ function getFs() {
21
+ // @ts-ignore
22
+ const fs = self.workerData.fs;
23
+ if (!fs) {
24
+ throw new Error("FS not initialized");
25
+ }
26
+ return fs;
27
+ }
28
+ // --- Synchronous API (via sabcom) ---
29
+ export function readFileSync(path, options) {
30
+ const client = getSabClient();
31
+ const result = client.call(sabcom.SAB_OP_READ_FILE, resolvePath(path));
32
+ if (options === "utf8" ||
33
+ options === "utf-8" ||
34
+ (options && (options.encoding === "utf8" || options.encoding === "utf-8"))) {
35
+ return new TextDecoder().decode(result);
36
+ }
37
+ return Buffer.from(result);
38
+ }
39
+ export function readdirSync(path, options) {
40
+ const client = getSabClient();
41
+ const result = client.call(sabcom.SAB_OP_READ_DIR, resolvePath(path));
42
+ const json = new TextDecoder().decode(result);
43
+ const entries = JSON.parse(json);
44
+ if (options === null || options === void 0 ? void 0 : options.withFileTypes) {
45
+ return entries.map((e) => ({
46
+ name: e.name,
47
+ isFile: () => e.type === "file",
48
+ isDirectory: () => e.type === "directory",
49
+ isSymbolicLink: () => false,
50
+ }));
51
+ }
52
+ return entries.map((e) => e.name);
53
+ }
54
+ export function writeFileSync(path, data, options) {
55
+ const client = getSabClient();
56
+ // TODO: handle binary data properly
57
+ const content = typeof data === "string" ? data : new TextDecoder().decode(data);
58
+ const payload = JSON.stringify({ path: resolvePath(path), data: content });
59
+ client.call(sabcom.SAB_OP_WRITE_FILE, payload);
60
+ }
61
+ export function mkdirSync(path, options) {
62
+ const client = getSabClient();
63
+ const recursive = (options === null || options === void 0 ? void 0 : options.recursive) || false;
64
+ const payload = JSON.stringify({ path: resolvePath(path), recursive });
65
+ client.call(sabcom.SAB_OP_MKDIR, payload);
66
+ }
67
+ export function rmSync(path, options) {
68
+ const client = getSabClient();
69
+ const recursive = (options === null || options === void 0 ? void 0 : options.recursive) || false;
70
+ const payload = JSON.stringify({ path: resolvePath(path), recursive });
71
+ client.call(sabcom.SAB_OP_RM, payload);
72
+ }
73
+ export function rmdirSync(path, options) {
74
+ const client = getSabClient();
75
+ const recursive = (options === null || options === void 0 ? void 0 : options.recursive) || false;
76
+ const payload = JSON.stringify({ path: resolvePath(path), recursive });
77
+ client.call(sabcom.SAB_OP_RMDIR, payload);
78
+ }
79
+ export function copyFileSync(src, dst) {
80
+ const client = getSabClient();
81
+ const payload = JSON.stringify({
82
+ src: resolvePath(src),
83
+ dst: resolvePath(dst),
84
+ });
85
+ client.call(sabcom.SAB_OP_COPY_FILE, payload);
86
+ }
87
+ export function statSync(p) {
88
+ const client = getSabClient();
89
+ const struct = client.callStat(resolvePath(p));
90
+ return new Stats({
91
+ type: struct.type === sabcom.STAT_TYPE_DIR ? "directory" : "file",
92
+ size: Number(struct.size),
93
+ atimeMs: struct.atimeMs,
94
+ mtimeMs: struct.mtimeMs,
95
+ ctimeMs: struct.ctimeMs,
96
+ birthtimeMs: struct.birthtimeMs,
97
+ });
98
+ }
99
+ export function lstatSync(p) {
100
+ return statSync(p);
101
+ }
102
+ export function realpathSync(p) {
103
+ return p;
104
+ }
105
+ export function accessSync(path, mode) {
106
+ statSync(path);
107
+ }
108
+ export function existsSync(path) {
109
+ try {
110
+ statSync(path);
111
+ return true;
112
+ }
113
+ catch (e) {
114
+ return false;
115
+ }
116
+ }
117
+ // --- Asynchronous API (via WASM Project) ---
118
+ export function readFile(path, options, cb) {
119
+ if (typeof options === "function") {
120
+ cb = options;
121
+ options = {};
122
+ }
123
+ const encoding = options === "utf8" ||
124
+ options === "utf-8" ||
125
+ (options === null || options === void 0 ? void 0 : options.encoding) === "utf8" ||
126
+ (options === null || options === void 0 ? void 0 : options.encoding) === "utf-8"
127
+ ? "utf8"
128
+ : undefined;
129
+ const p = resolvePath(path);
130
+ const fs = getFs();
131
+ const promise = encoding ? fs.readToString(p) : fs.read(p);
132
+ promise
133
+ .then((data) => {
134
+ cb(null, encoding ? data : Buffer.from(data));
135
+ })
136
+ .catch((e) => cb(e));
137
+ }
138
+ export function readdir(path, options, cb) {
139
+ if (typeof options === "function") {
140
+ cb = options;
141
+ options = {};
142
+ }
143
+ getFs()
144
+ .readDir(resolvePath(path))
145
+ .then((entries) => {
146
+ const result = entries.map((e) => {
147
+ const json = e.toJSON();
148
+ if (options === null || options === void 0 ? void 0 : options.withFileTypes) {
149
+ return {
150
+ name: json.name,
151
+ isFile: () => json.type === "file",
152
+ isDirectory: () => json.type === "directory",
153
+ isSymbolicLink: () => false,
154
+ };
155
+ }
156
+ return json.name;
157
+ });
158
+ cb(null, result);
159
+ })
160
+ .catch((e) => cb(e));
161
+ }
162
+ export function writeFile(path, data, options, cb) {
163
+ if (typeof options === "function") {
164
+ cb = options;
165
+ options = {};
166
+ }
167
+ const p = resolvePath(path);
168
+ const fs = getFs();
169
+ const promise = typeof data === "string" ? fs.writeString(p, data) : fs.write(p, data);
170
+ promise.then(() => cb(null)).catch((e) => cb(e));
171
+ }
172
+ export function mkdir(path, options, cb) {
173
+ if (typeof options === "function") {
174
+ cb = options;
175
+ options = {};
176
+ }
177
+ const p = resolvePath(path);
178
+ const fs = getFs();
179
+ const promise = (options === null || options === void 0 ? void 0 : options.recursive) ? fs.createDirAll(p) : fs.createDir(p);
180
+ promise.then(() => cb(null)).catch((e) => cb(e));
181
+ }
182
+ export function rm(path, options, cb) {
183
+ if (typeof options === "function") {
184
+ cb = options;
185
+ options = {};
186
+ }
187
+ const p = resolvePath(path);
188
+ const fs = getFs();
189
+ fs.metadata(p)
190
+ .then((metadata) => {
191
+ const type = metadata.toJSON().type;
192
+ if (type === "file") {
193
+ return fs.removeFile(p);
194
+ }
195
+ else {
196
+ return fs.removeDir(p, !!(options === null || options === void 0 ? void 0 : options.recursive));
197
+ }
198
+ })
199
+ .then(() => cb(null))
200
+ .catch((e) => cb(e));
201
+ }
202
+ export function rmdir(path, options, cb) {
203
+ if (typeof options === "function") {
204
+ cb = options;
205
+ options = {};
206
+ }
207
+ getFs()
208
+ .removeDir(resolvePath(path), !!(options === null || options === void 0 ? void 0 : options.recursive))
209
+ .then(() => cb(null))
210
+ .catch((e) => cb(e));
211
+ }
212
+ export function copyFile(src, dst, cb) {
213
+ getFs()
214
+ .copyFile(resolvePath(src), resolvePath(dst))
215
+ .then(() => cb(null))
216
+ .catch((e) => cb(e));
217
+ }
218
+ export function stat(p, cb) {
219
+ getFs()
220
+ .metadata(resolvePath(p))
221
+ .then((metadata) => {
222
+ const json = metadata.toJSON();
223
+ cb(null, new Stats({
224
+ type: json.type,
225
+ size: Number(json.file_size || 0),
226
+ }));
227
+ })
228
+ .catch((e) => cb(e));
229
+ }
230
+ export function lstat(p, cb) {
231
+ stat(p, cb);
232
+ }
233
+ export function realpath(p, cb) {
234
+ cb(null, p);
235
+ }
236
+ export function access(p, mode, cb) {
237
+ if (typeof mode === "function") {
238
+ cb = mode;
239
+ mode = 0;
240
+ }
241
+ stat(p, (err) => {
242
+ if (cb)
243
+ cb(err);
244
+ });
245
+ }
246
+ export const constants = {
247
+ F_OK: 0,
248
+ R_OK: 4,
249
+ W_OK: 2,
250
+ X_OK: 1,
251
+ };
252
+ export default {
253
+ readFile,
254
+ readFileSync,
255
+ readdir,
256
+ readdirSync,
257
+ writeFile,
258
+ writeFileSync,
259
+ mkdir,
260
+ mkdirSync,
261
+ rm,
262
+ rmSync,
263
+ rmdir,
264
+ rmdirSync,
265
+ copyFile,
266
+ copyFileSync,
267
+ stat,
268
+ statSync,
269
+ lstat,
270
+ lstatSync,
271
+ realpath,
272
+ realpathSync,
273
+ access,
274
+ accessSync,
275
+ existsSync,
276
+ promises,
277
+ constants,
278
+ };
279
+ export { promises };
@@ -0,0 +1,26 @@
1
+ import { Stats } from "../../type";
2
+ export declare const promises: {
3
+ readFile: (p: string, options?: any) => Promise<any>;
4
+ writeFile: (p: string, data: string | Uint8Array, options?: any) => Promise<void>;
5
+ readdir: (p: string, options?: any) => Promise<any>;
6
+ mkdir: (p: string, options?: any) => Promise<void>;
7
+ rm: (p: string, options?: any) => Promise<void>;
8
+ rmdir: (p: string, options?: any) => Promise<any>;
9
+ copyFile: (src: string, dst: string) => Promise<any>;
10
+ stat: (p: string) => Promise<Stats>;
11
+ lstat: (p: string) => Promise<Stats>;
12
+ realpath: (p: string) => Promise<string>;
13
+ access: (p: string, mode?: number) => Promise<void>;
14
+ };
15
+ export declare const readFile: (p: string, options?: any) => Promise<any>;
16
+ export declare const writeFile: (p: string, data: string | Uint8Array, options?: any) => Promise<void>;
17
+ export declare const readdir: (p: string, options?: any) => Promise<any>;
18
+ export declare const mkdir: (p: string, options?: any) => Promise<void>;
19
+ export declare const rm: (p: string, options?: any) => Promise<void>;
20
+ export declare const rmdir: (p: string, options?: any) => Promise<any>;
21
+ export declare const copyFile: (src: string, dst: string) => Promise<any>;
22
+ export declare const stat: (p: string) => Promise<Stats>;
23
+ export declare const lstat: (p: string) => Promise<Stats>;
24
+ export declare const realpath: (p: string) => Promise<string>;
25
+ export declare const access: (p: string, mode?: number) => Promise<void>;
26
+ export default promises;
@@ -0,0 +1,112 @@
1
+ import { Buffer } from "buffer";
2
+ import path from "path";
3
+ import { Stats } from "../../type";
4
+ function resolvePath(p) {
5
+ var _a, _b, _c;
6
+ // @ts-ignore
7
+ 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) || "/";
8
+ return path.resolve(cwd, p);
9
+ }
10
+ function getFs() {
11
+ // @ts-ignore
12
+ const fs = self.workerData.fs;
13
+ if (!fs) {
14
+ throw new Error("FS not initialized");
15
+ }
16
+ return fs;
17
+ }
18
+ export const promises = {
19
+ readFile: async (p, options) => {
20
+ const encoding = options === "utf8" ||
21
+ options === "utf-8" ||
22
+ (options === null || options === void 0 ? void 0 : options.encoding) === "utf8" ||
23
+ (options === null || options === void 0 ? void 0 : options.encoding) === "utf-8"
24
+ ? "utf8"
25
+ : undefined;
26
+ const fs = getFs();
27
+ const path = resolvePath(p);
28
+ const data = await (encoding ? fs.readToString(path) : fs.read(path));
29
+ return encoding ? data : Buffer.from(data);
30
+ },
31
+ writeFile: async (p, data, options) => {
32
+ const fs = getFs();
33
+ const path = resolvePath(p);
34
+ if (typeof data === "string") {
35
+ await fs.writeString(path, data);
36
+ }
37
+ else {
38
+ await fs.write(path, data);
39
+ }
40
+ },
41
+ readdir: async (p, options) => {
42
+ const entries = await getFs().readDir(resolvePath(p));
43
+ return entries.map((e) => {
44
+ const json = e.toJSON();
45
+ if (options === null || options === void 0 ? void 0 : options.withFileTypes) {
46
+ return {
47
+ name: json.name,
48
+ isFile: () => json.type === "file",
49
+ isDirectory: () => json.type === "directory",
50
+ isSymbolicLink: () => false,
51
+ };
52
+ }
53
+ return json.name;
54
+ });
55
+ },
56
+ mkdir: async (p, options) => {
57
+ const fs = getFs();
58
+ const path = resolvePath(p);
59
+ if (options === null || options === void 0 ? void 0 : options.recursive) {
60
+ await fs.createDirAll(path);
61
+ }
62
+ else {
63
+ await fs.createDir(path);
64
+ }
65
+ },
66
+ rm: async (p, options) => {
67
+ const fs = getFs();
68
+ const path = resolvePath(p);
69
+ const metadata = await fs.metadata(path);
70
+ const type = metadata.toJSON().type;
71
+ if (type === "file") {
72
+ await fs.removeFile(path);
73
+ }
74
+ else {
75
+ await fs.removeDir(path, !!(options === null || options === void 0 ? void 0 : options.recursive));
76
+ }
77
+ },
78
+ rmdir: async (p, options) => getFs().removeDir(resolvePath(p), !!(options === null || options === void 0 ? void 0 : options.recursive)),
79
+ copyFile: async (src, dst) => getFs().copyFile(resolvePath(src), resolvePath(dst)),
80
+ stat: async (p) => {
81
+ const metadata = await getFs().metadata(resolvePath(p));
82
+ const json = metadata.toJSON();
83
+ return new Stats({
84
+ type: json.type,
85
+ size: Number(json.file_size || 0),
86
+ });
87
+ },
88
+ lstat: async (p) => {
89
+ const metadata = await getFs().metadata(resolvePath(p));
90
+ const json = metadata.toJSON();
91
+ return new Stats({
92
+ type: json.type,
93
+ size: Number(json.file_size || 0),
94
+ });
95
+ },
96
+ realpath: async (p) => p,
97
+ access: async (p, mode) => {
98
+ await getFs().metadata(resolvePath(p));
99
+ },
100
+ };
101
+ export const readFile = promises.readFile;
102
+ export const writeFile = promises.writeFile;
103
+ export const readdir = promises.readdir;
104
+ export const mkdir = promises.mkdir;
105
+ export const rm = promises.rm;
106
+ export const rmdir = promises.rmdir;
107
+ export const copyFile = promises.copyFile;
108
+ export const stat = promises.stat;
109
+ export const lstat = promises.lstat;
110
+ export const realpath = promises.realpath;
111
+ export const access = promises.access;
112
+ export default promises;
@@ -2,6 +2,7 @@ export interface LoaderRunnerMeta {
2
2
  workerData: {
3
3
  workerId: number;
4
4
  cwd: string;
5
+ projectRoot: string;
5
6
  };
6
7
  loaderAssets: {
7
8
  importMaps: Record<string, string>;
@@ -1,5 +1,5 @@
1
- import { SabComClient } from "../../sabcom";
2
- import initWasm, { recvTaskMessageInWorker, sendTaskMessage, workerCreated, } from "../../utoo";
1
+ import { SabComClient } from "../sabcom";
2
+ import initWasm, { Project, recvTaskMessageInWorker, sendTaskMessage, workerCreated, } from "../utoo";
3
3
  import { cjs } from "./cjs";
4
4
  const binding = {
5
5
  recvTaskMessageInWorker,
@@ -18,17 +18,22 @@ export function startLoaderWorker() {
18
18
  self.postMessage("sab_request");
19
19
  })
20
20
  : undefined;
21
+ // Initialize the thread-local state (tokio runtime).
22
+ // We don't need to pass threadWorkerUrl here because it's already stored in a global static in Rust.
23
+ Project.init("");
24
+ Project.setCwd(meta.workerData.cwd);
21
25
  self.workerData = {
22
26
  workerId: meta.workerData.workerId,
23
27
  cwd: meta.workerData.cwd,
28
+ projectRoot: meta.workerData.projectRoot,
24
29
  binding,
25
30
  sabClient,
31
+ fs: Project,
26
32
  };
27
33
  self.process = {
28
34
  env: {},
29
35
  cwd: () => self.workerData.cwd,
30
36
  };
31
- console.log("Worker CWD:", self.process.cwd());
32
37
  cjs(meta.loaderAssets.entrypoint, meta.loaderAssets.importMaps);
33
38
  };
34
39
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@utoo/web",
3
- "version": "1.2.0-rc.4",
3
+ "version": "1.2.0-rc.6",
4
4
  "module": "esm/index.js",
5
5
  "types": "esm/index.d.ts",
6
6
  "files": [
@@ -15,16 +15,17 @@
15
15
  "bindgen-build:local": "wasm-bindgen ../../target/wasm32-unknown-unknown/release-local/utoo_wasm.wasm --out-dir src/utoo --out-name index --target web",
16
16
  "pretsc": "npm run build --workspace @utoo/pack-shared",
17
17
  "tsc": "rm -rf esm && tsc -p ./tsconfig.json",
18
- "dev": "npm run build-wasm -- --profile wasm-dev && npm run bindgen-dev && npm run tsc && cp src/utoo/index_bg.wasm esm/utoo",
18
+ "dev": "npm run build-wasm -- --profile wasm-dev && npm run bindgen-dev && npm run tsc && npm run build-loaderWorker && cp src/utoo/index_bg.wasm esm/utoo",
19
19
  "dev:pm": "npm run build-wasm:pm -- --profile wasm-dev && npm run bindgen-dev && npm run tsc && cp src/utoo/index_bg.wasm esm/utoo",
20
20
  "wasm-opt": "wasm-opt src/utoo/index_bg.wasm -o esm/utoo/index_bg.wasm --enable-threads --enable-bulk-memory --enable-nontrapping-float-to-int -Oz",
21
21
  "build": "npm run build-wasm -- --release && npm run bindgen-build && npm run tsc && npm run build-loaderWorker && npm run wasm-opt",
22
22
  "build:local": "npm run build-wasm -- --profile release-local && npm run bindgen-build:local && npm run tsc && npm run build-loaderWorker && cp src/utoo/index_bg.wasm esm/utoo",
23
- "build-loaderWorker": "node cli/umd.js -e ./src/webpackLoaders/worker/index.ts -o ./esm/loaderWorker.js -t webworker",
23
+ "build-loaderWorker": "node cli/umd.js -e ./src/webpackLoaders/worker.ts -o ./esm/loaderWorker.js -t webworker",
24
24
  "prepublishOnly": "npm run build"
25
25
  },
26
26
  "dependencies": {
27
27
  "@utoo/pack-shared": "^0.0.7",
28
+ "buffer-backed-object": "^1.0.1",
28
29
  "comlink": "^4.4.2",
29
30
  "micromatch": "^4.0.8",
30
31
  "systemjs": "^6.15.1"
@@ -1,3 +0,0 @@
1
- import { Binding } from "./type";
2
- import { Project as ProjectInternal } from "./utoo";
3
- export declare const runLoaderWorkerPool: (binding: Binding, projectCwd: string, projectInternal: ProjectInternal, loaderWorkerUrl: string, loadersImportMap?: Record<string, string>) => Promise<void>;