@utoo/web 1.2.0-rc.1 → 1.2.0-rc.11

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 (58) hide show
  1. package/README.md +55 -0
  2. package/esm/{aa0ad15d2a587c43406f.wasm → 7a09b7ab69b3abceced7.wasm} +0 -0
  3. package/esm/index.d.ts +3 -2
  4. package/esm/index.js +3 -2
  5. package/esm/loaderWorker.js +1 -1
  6. package/esm/loaderWorker.js.LICENSE.txt +0 -21
  7. package/esm/{forkedProject.d.ts → project/ForkedProject.d.ts} +5 -3
  8. package/esm/{forkedProject.js → project/ForkedProject.js} +8 -0
  9. package/esm/{internalProject.d.ts → project/InternalProject.d.ts} +5 -4
  10. package/esm/project/InternalProject.js +134 -0
  11. package/esm/{project.d.ts → project/Project.d.ts} +3 -1
  12. package/esm/{project.js → project/Project.js} +19 -6
  13. package/esm/serviceWorker.js +4 -3
  14. package/esm/{type.d.ts → types.d.ts} +43 -0
  15. package/esm/types.js +56 -0
  16. package/esm/utils/sabcom.d.ts +61 -0
  17. package/esm/utils/sabcom.js +203 -0
  18. package/esm/utoo/index.d.ts +73 -38
  19. package/esm/utoo/index.js +167 -143
  20. package/esm/utoo/index_bg.wasm +0 -0
  21. package/esm/webpackLoaders/{worker/cjs.js → cjs.js} +65 -41
  22. package/esm/webpackLoaders/loaderWorkerPool.d.ts +2 -0
  23. package/esm/webpackLoaders/loaderWorkerPool.js +90 -0
  24. package/esm/webpackLoaders/polyfills/fsPolyfill.d.ts +78 -0
  25. package/esm/webpackLoaders/{worker/polyfills → polyfills}/fsPolyfill.js +154 -191
  26. package/esm/webpackLoaders/polyfills/fsPromisesPolyfill.d.ts +26 -0
  27. package/esm/webpackLoaders/polyfills/fsPromisesPolyfill.js +112 -0
  28. package/esm/webpackLoaders/{worker/polyfills → polyfills}/nodePolyFills.d.ts +0 -2
  29. package/esm/webpackLoaders/{worker/polyfills → polyfills}/nodePolyFills.js +4 -3
  30. package/esm/webpackLoaders/{worker/type.d.ts → types.d.ts} +1 -0
  31. package/esm/webpackLoaders/{worker/index.js → worker.js} +8 -3
  32. package/esm/worker.js +2 -2
  33. package/package.json +14 -13
  34. package/esm/internalProject.js +0 -110
  35. package/esm/loaderWorkerPool.d.ts +0 -3
  36. package/esm/loaderWorkerPool.js +0 -125
  37. package/esm/sabcom.d.ts +0 -31
  38. package/esm/sabcom.js +0 -71
  39. package/esm/type.js +0 -12
  40. package/esm/webpackLoaders/loaders/less-loader/index.d.ts +0 -3
  41. package/esm/webpackLoaders/loaders/less-loader/index.js +0 -103
  42. package/esm/webpackLoaders/loaders/less-loader/options.json +0 -67
  43. package/esm/webpackLoaders/loaders/less-loader/utils.d.ts +0 -14
  44. package/esm/webpackLoaders/loaders/less-loader/utils.js +0 -217
  45. package/esm/webpackLoaders/worker/polyfills/fastGlobPolyfill.d.ts +0 -2
  46. package/esm/webpackLoaders/worker/polyfills/fastGlobPolyfill.js +0 -48
  47. package/esm/webpackLoaders/worker/polyfills/fsPolyfill.d.ts +0 -124
  48. package/esm/webpackLoaders/worker/polyfills/fsPromisesPolyfill.d.ts +0 -9
  49. package/esm/webpackLoaders/worker/polyfills/fsPromisesPolyfill.js +0 -9
  50. /package/esm/{installServiceWorker.d.ts → utils/installServiceWorker.d.ts} +0 -0
  51. /package/esm/{installServiceWorker.js → utils/installServiceWorker.js} +0 -0
  52. /package/esm/{message.d.ts → utils/message.d.ts} +0 -0
  53. /package/esm/{message.js → utils/message.js} +0 -0
  54. /package/esm/webpackLoaders/{worker/cjs.d.ts → cjs.d.ts} +0 -0
  55. /package/esm/webpackLoaders/{worker/polyfills → polyfills}/workerThreadsPolyfill.d.ts +0 -0
  56. /package/esm/webpackLoaders/{worker/polyfills → polyfills}/workerThreadsPolyfill.js +0 -0
  57. /package/esm/webpackLoaders/{worker/type.js → types.js} +0 -0
  58. /package/esm/webpackLoaders/{worker/index.d.ts → worker.d.ts} +0 -0
@@ -1,29 +1,13 @@
1
1
  import { Buffer } from "buffer";
2
2
  import path from "path";
3
- 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, } from "../../../sabcom";
3
+ import { Stats } from "../../types";
4
+ import * as sabcom from "../../utils/sabcom";
5
+ import { promises } from "./fsPromisesPolyfill";
4
6
  function resolvePath(p) {
5
7
  var _a, _b, _c;
6
8
  // @ts-ignore
7
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) || "/";
8
- if (cwd === "/") {
9
- if (p.startsWith("/")) {
10
- return p.slice(1);
11
- }
12
- return p;
13
- }
14
- if (p.startsWith(cwd)) {
15
- // Check if it's an exact match or followed by separator
16
- if (p.length === cwd.length) {
17
- return ".";
18
- }
19
- if (p[cwd.length] === path.sep || p[cwd.length] === "/") {
20
- let relative = p.slice(cwd.length);
21
- if (relative.startsWith("/"))
22
- relative = relative.slice(1);
23
- return relative || ".";
24
- }
25
- }
26
- return p;
10
+ return path.resolve(cwd, p);
27
11
  }
28
12
  function getSabClient() {
29
13
  // @ts-ignore
@@ -33,22 +17,18 @@ function getSabClient() {
33
17
  }
34
18
  return client;
35
19
  }
36
- export function readFile(path, options, cb) {
37
- if (typeof options === "function") {
38
- cb = options;
39
- options = {};
40
- }
41
- try {
42
- const data = readFileSync(path, options);
43
- cb(null, data);
44
- }
45
- catch (e) {
46
- cb(e);
20
+ function getFs() {
21
+ // @ts-ignore
22
+ const fs = self.workerData.fs;
23
+ if (!fs) {
24
+ throw new Error("FS not initialized");
47
25
  }
26
+ return fs;
48
27
  }
28
+ // --- Synchronous API (via sabcom) ---
49
29
  export function readFileSync(path, options) {
50
30
  const client = getSabClient();
51
- const result = client.call(SAB_OP_READ_FILE, resolvePath(path));
31
+ const result = client.call(sabcom.SAB_OP_READ_FILE, resolvePath(path));
52
32
  if (options === "utf8" ||
53
33
  options === "utf-8" ||
54
34
  (options && (options.encoding === "utf8" || options.encoding === "utf-8"))) {
@@ -58,7 +38,7 @@ export function readFileSync(path, options) {
58
38
  }
59
39
  export function readdirSync(path, options) {
60
40
  const client = getSabClient();
61
- const result = client.call(SAB_OP_READ_DIR, resolvePath(path));
41
+ const result = client.call(sabcom.SAB_OP_READ_DIR, resolvePath(path));
62
42
  const json = new TextDecoder().decode(result);
63
43
  const entries = JSON.parse(json);
64
44
  if (options === null || options === void 0 ? void 0 : options.withFileTypes) {
@@ -71,95 +51,30 @@ export function readdirSync(path, options) {
71
51
  }
72
52
  return entries.map((e) => e.name);
73
53
  }
74
- export function readdir(path, options, cb) {
75
- if (typeof options === "function") {
76
- cb = options;
77
- options = {};
78
- }
79
- try {
80
- const files = readdirSync(path, options);
81
- cb(null, files);
82
- }
83
- catch (e) {
84
- cb(e);
85
- }
86
- }
87
54
  export function writeFileSync(path, data, options) {
88
55
  const client = getSabClient();
89
56
  // TODO: handle binary data properly
90
57
  const content = typeof data === "string" ? data : new TextDecoder().decode(data);
91
58
  const payload = JSON.stringify({ path: resolvePath(path), data: content });
92
- client.call(SAB_OP_WRITE_FILE, payload);
93
- }
94
- export function writeFile(path, data, options, cb) {
95
- if (typeof options === "function") {
96
- cb = options;
97
- options = {};
98
- }
99
- try {
100
- writeFileSync(path, data, options);
101
- cb(null);
102
- }
103
- catch (e) {
104
- cb(e);
105
- }
59
+ client.call(sabcom.SAB_OP_WRITE_FILE, payload);
106
60
  }
107
61
  export function mkdirSync(path, options) {
108
62
  const client = getSabClient();
109
63
  const recursive = (options === null || options === void 0 ? void 0 : options.recursive) || false;
110
64
  const payload = JSON.stringify({ path: resolvePath(path), recursive });
111
- client.call(SAB_OP_MKDIR, payload);
112
- }
113
- export function mkdir(path, options, cb) {
114
- if (typeof options === "function") {
115
- cb = options;
116
- options = {};
117
- }
118
- try {
119
- mkdirSync(path, options);
120
- cb(null);
121
- }
122
- catch (e) {
123
- cb(e);
124
- }
65
+ client.call(sabcom.SAB_OP_MKDIR, payload);
125
66
  }
126
67
  export function rmSync(path, options) {
127
68
  const client = getSabClient();
128
69
  const recursive = (options === null || options === void 0 ? void 0 : options.recursive) || false;
129
70
  const payload = JSON.stringify({ path: resolvePath(path), recursive });
130
- client.call(SAB_OP_RM, payload);
131
- }
132
- export function rm(path, options, cb) {
133
- if (typeof options === "function") {
134
- cb = options;
135
- options = {};
136
- }
137
- try {
138
- rmSync(path, options);
139
- cb(null);
140
- }
141
- catch (e) {
142
- cb(e);
143
- }
71
+ client.call(sabcom.SAB_OP_RM, payload);
144
72
  }
145
73
  export function rmdirSync(path, options) {
146
74
  const client = getSabClient();
147
75
  const recursive = (options === null || options === void 0 ? void 0 : options.recursive) || false;
148
76
  const payload = JSON.stringify({ path: resolvePath(path), recursive });
149
- client.call(SAB_OP_RMDIR, payload);
150
- }
151
- export function rmdir(path, options, cb) {
152
- if (typeof options === "function") {
153
- cb = options;
154
- options = {};
155
- }
156
- try {
157
- rmdirSync(path, options);
158
- cb(null);
159
- }
160
- catch (e) {
161
- cb(e);
162
- }
77
+ client.call(sabcom.SAB_OP_RMDIR, payload);
163
78
  }
164
79
  export function copyFileSync(src, dst) {
165
80
  const client = getSabClient();
@@ -167,120 +82,167 @@ export function copyFileSync(src, dst) {
167
82
  src: resolvePath(src),
168
83
  dst: resolvePath(dst),
169
84
  });
170
- client.call(SAB_OP_COPY_FILE, payload);
171
- }
172
- export function copyFile(src, dst, cb) {
173
- try {
174
- copyFileSync(src, dst);
175
- cb(null);
176
- }
177
- catch (e) {
178
- cb(e);
179
- }
85
+ client.call(sabcom.SAB_OP_COPY_FILE, payload);
180
86
  }
181
87
  export function statSync(p) {
182
- const parent = path.dirname(p);
183
- const name = path.basename(p);
184
- // Root check
185
- if (p === "/" || p === ".") {
186
- return {
187
- isDirectory: () => true,
188
- isFile: () => false,
189
- isSymbolicLink: () => false,
190
- size: 0,
191
- mtime: new Date(),
192
- };
193
- }
194
- try {
195
- const entries = readdirSync(parent, { withFileTypes: true });
196
- const entry = entries.find((e) => e.name === name);
197
- if (!entry) {
198
- throw new Error(`ENOENT: no such file or directory, stat '${p}'`);
199
- }
200
- return {
201
- isDirectory: () => entry.isDirectory(),
202
- isFile: () => entry.isFile(),
203
- isSymbolicLink: () => entry.isSymbolicLink(),
204
- size: 0,
205
- mtime: new Date(),
206
- };
207
- }
208
- catch (e) {
209
- throw e;
210
- }
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
+ });
211
98
  }
212
99
  export function lstatSync(p) {
213
100
  return statSync(p);
214
101
  }
215
- export function stat(path, cb) {
102
+ export function realpathSync(p) {
103
+ return p;
104
+ }
105
+ export function accessSync(path, mode) {
106
+ statSync(path);
107
+ }
108
+ export function existsSync(path) {
216
109
  try {
217
- const stats = statSync(path);
218
- cb(null, stats);
110
+ statSync(path);
111
+ return true;
219
112
  }
220
113
  catch (e) {
221
- cb(e);
114
+ return false;
222
115
  }
223
116
  }
224
- export function lstat(path, cb) {
225
- try {
226
- const stats = lstatSync(path);
227
- cb(null, stats);
117
+ // --- Asynchronous API (via WASM Project) ---
118
+ export function readFile(path, options, cb) {
119
+ if (typeof options === "function") {
120
+ cb = options;
121
+ options = {};
228
122
  }
229
- catch (e) {
230
- cb(e);
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 = {};
231
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));
232
161
  }
233
- export function realpathSync(p) {
234
- return p;
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));
235
171
  }
236
- export function realpath(p, cb) {
237
- cb(null, p);
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));
238
181
  }
239
- export function accessSync(path, mode) {
240
- try {
241
- statSync(path);
182
+ export function rm(path, options, cb) {
183
+ if (typeof options === "function") {
184
+ cb = options;
185
+ options = {};
242
186
  }
243
- catch (e) {
244
- throw e;
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 = {};
245
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);
246
232
  }
247
- export function access(path, mode, cb) {
233
+ export function realpath(p, cb) {
234
+ cb(null, p);
235
+ }
236
+ export function access(p, mode, cb) {
248
237
  if (typeof mode === "function") {
249
238
  cb = mode;
250
239
  mode = 0;
251
240
  }
252
- try {
253
- accessSync(path, mode);
254
- if (cb)
255
- cb(null);
256
- }
257
- catch (e) {
241
+ stat(p, (err) => {
258
242
  if (cb)
259
- cb(e);
260
- }
261
- }
262
- export function existsSync(path) {
263
- try {
264
- statSync(path);
265
- return true;
266
- }
267
- catch (e) {
268
- return false;
269
- }
243
+ cb(err);
244
+ });
270
245
  }
271
- export const promises = {
272
- readFile: async (path, options) => readFileSync(path, options),
273
- writeFile: async (path, data, options) => writeFileSync(path, data, options),
274
- readdir: async (path, options) => readdirSync(path, options),
275
- mkdir: async (path, options) => mkdirSync(path, options),
276
- rm: async (path, options) => rmSync(path, options),
277
- rmdir: async (path, options) => rmdirSync(path, options),
278
- copyFile: async (src, dst) => copyFileSync(src, dst),
279
- stat: async (p) => statSync(p),
280
- lstat: async (p) => lstatSync(p),
281
- realpath: async (p) => realpathSync(p),
282
- access: async (path, mode) => accessSync(path, mode),
283
- };
284
246
  export const constants = {
285
247
  F_OK: 0,
286
248
  R_OK: 4,
@@ -314,3 +276,4 @@ export default {
314
276
  promises,
315
277
  constants,
316
278
  };
279
+ export { promises };
@@ -0,0 +1,26 @@
1
+ import { Stats } from "../../types";
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 "../../types";
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;
@@ -22,7 +22,6 @@ declare const _default: {
22
22
  readonly "node:domain": any;
23
23
  readonly events: any;
24
24
  readonly "node:events": any;
25
- "fast-glob": any;
26
25
  readonly http: any;
27
26
  readonly "node:http": any;
28
27
  readonly http2: any;
@@ -61,7 +60,6 @@ declare const _default: {
61
60
  readonly "node:zlib": any;
62
61
  fs: typeof fs;
63
62
  "node:fs": typeof fs;
64
- "graceful-fs": typeof fs;
65
63
  path: any;
66
64
  "node:path": any;
67
65
  process: any;
@@ -7,6 +7,10 @@ process.cwd = () => {
7
7
  // @ts-ignore
8
8
  return ((_a = self.workerData) === null || _a === void 0 ? void 0 : _a.cwd) || (originalCwd === null || originalCwd === void 0 ? void 0 : originalCwd()) || "/";
9
9
  };
10
+ if (!process.versions)
11
+ process.versions = {};
12
+ if (!process.versions.node)
13
+ process.versions.node = "24.0.0";
10
14
  self.process = process;
11
15
  self.global = self;
12
16
  const path = require("path");
@@ -17,7 +21,6 @@ path.resolve = (...args) => {
17
21
  const cwd = ((_a = self.workerData) === null || _a === void 0 ? void 0 : _a.cwd) || "/";
18
22
  return originalResolve(cwd, ...args);
19
23
  };
20
- import fastGlob from "./fastGlobPolyfill";
21
24
  import * as fs from "./fsPolyfill";
22
25
  import * as workerThreads from "./workerThreadsPolyfill";
23
26
  const workerThreadsWithLiveWorkerData = {
@@ -96,7 +99,6 @@ export default {
96
99
  get "node:events"() {
97
100
  return require("events");
98
101
  },
99
- "fast-glob": fastGlob,
100
102
  get http() {
101
103
  return require("http");
102
104
  },
@@ -207,7 +209,6 @@ export default {
207
209
  },
208
210
  fs,
209
211
  "node:fs": fs,
210
- "graceful-fs": fs,
211
212
  path,
212
213
  "node:path": path,
213
214
  process,
@@ -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 "../utils/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/esm/worker.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as comlink from "comlink";
2
- import { internalEndpoint } from "./internalProject";
3
- import { HandShake } from "./message";
2
+ import { internalEndpoint } from "./project/InternalProject";
3
+ import { HandShake } from "./utils/message";
4
4
  const ConnectedPorts = new Set();
5
5
  self.addEventListener("message", (e) => {
6
6
  const port = e.ports[0];