@utoo/web 1.2.0-rc.5 → 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/{8df7dc7828270e8a8ece.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 +104 -102
  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 +3 -2
  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
@@ -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.5",
3
+ "version": "1.2.0-rc.6",
4
4
  "module": "esm/index.js",
5
5
  "types": "esm/index.d.ts",
6
6
  "files": [
@@ -20,11 +20,12 @@
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>;
@@ -1,244 +0,0 @@
1
- import { Buffer } from "buffer";
2
- export declare function readFile(path: string, options: any, cb: Function): void;
3
- export declare function readFileSync(path: string, options: any): string | Buffer<any>;
4
- export declare function readdirSync(path: string, options?: any): any;
5
- export declare function readdir(path: string, options: any, cb: Function): void;
6
- export declare function writeFileSync(path: string, data: string | Uint8Array, options?: any): void;
7
- export declare function writeFile(path: string, data: string | Uint8Array, options: any, cb: Function): void;
8
- export declare function mkdirSync(path: string, options?: any): void;
9
- export declare function mkdir(path: string, options: any, cb: Function): void;
10
- export declare function rmSync(path: string, options?: any): void;
11
- export declare function rm(path: string, options: any, cb: Function): void;
12
- export declare function rmdirSync(path: string, options?: any): void;
13
- export declare function rmdir(path: string, options: any, cb: Function): void;
14
- export declare function copyFileSync(src: string, dst: string): void;
15
- export declare function copyFile(src: string, dst: string, cb: Function): void;
16
- export declare function statSync(p: string): {
17
- dev: number;
18
- ino: number;
19
- mode: number;
20
- nlink: number;
21
- uid: number;
22
- gid: number;
23
- rdev: number;
24
- size: number;
25
- blksize: number;
26
- blocks: number;
27
- atimeMs: number;
28
- mtimeMs: number;
29
- ctimeMs: number;
30
- birthtimeMs: number;
31
- atime: Date;
32
- mtime: Date;
33
- ctime: Date;
34
- birthtime: Date;
35
- isDirectory: () => any;
36
- isFile: () => any;
37
- isSymbolicLink: () => any;
38
- isBlockDevice: () => boolean;
39
- isCharacterDevice: () => boolean;
40
- isFIFO: () => boolean;
41
- isSocket: () => boolean;
42
- };
43
- export declare function lstatSync(p: string): {
44
- dev: number;
45
- ino: number;
46
- mode: number;
47
- nlink: number;
48
- uid: number;
49
- gid: number;
50
- rdev: number;
51
- size: number;
52
- blksize: number;
53
- blocks: number;
54
- atimeMs: number;
55
- mtimeMs: number;
56
- ctimeMs: number;
57
- birthtimeMs: number;
58
- atime: Date;
59
- mtime: Date;
60
- ctime: Date;
61
- birthtime: Date;
62
- isDirectory: () => any;
63
- isFile: () => any;
64
- isSymbolicLink: () => any;
65
- isBlockDevice: () => boolean;
66
- isCharacterDevice: () => boolean;
67
- isFIFO: () => boolean;
68
- isSocket: () => boolean;
69
- };
70
- export declare function stat(path: string, cb: Function): void;
71
- export declare function lstat(path: string, cb: Function): void;
72
- export declare function realpathSync(p: string): string;
73
- export declare function realpath(p: string, cb: Function): void;
74
- export declare function accessSync(path: string, mode?: number): void;
75
- export declare function access(path: string, mode: number | Function, cb?: Function): void;
76
- export declare function existsSync(path: string): boolean;
77
- export declare const promises: {
78
- readFile: (path: string, options?: any) => Promise<string | Buffer<any>>;
79
- writeFile: (path: string, data: string | Uint8Array, options?: any) => Promise<void>;
80
- readdir: (path: string, options?: any) => Promise<any>;
81
- mkdir: (path: string, options?: any) => Promise<void>;
82
- rm: (path: string, options?: any) => Promise<void>;
83
- rmdir: (path: string, options?: any) => Promise<void>;
84
- copyFile: (src: string, dst: string) => Promise<void>;
85
- stat: (p: string) => Promise<{
86
- dev: number;
87
- ino: number;
88
- mode: number;
89
- nlink: number;
90
- uid: number;
91
- gid: number;
92
- rdev: number;
93
- size: number;
94
- blksize: number;
95
- blocks: number;
96
- atimeMs: number;
97
- mtimeMs: number;
98
- ctimeMs: number;
99
- birthtimeMs: number;
100
- atime: Date;
101
- mtime: Date;
102
- ctime: Date;
103
- birthtime: Date;
104
- isDirectory: () => any;
105
- isFile: () => any;
106
- isSymbolicLink: () => any;
107
- isBlockDevice: () => boolean;
108
- isCharacterDevice: () => boolean;
109
- isFIFO: () => boolean;
110
- isSocket: () => boolean;
111
- }>;
112
- lstat: (p: string) => Promise<{
113
- dev: number;
114
- ino: number;
115
- mode: number;
116
- nlink: number;
117
- uid: number;
118
- gid: number;
119
- rdev: number;
120
- size: number;
121
- blksize: number;
122
- blocks: number;
123
- atimeMs: number;
124
- mtimeMs: number;
125
- ctimeMs: number;
126
- birthtimeMs: number;
127
- atime: Date;
128
- mtime: Date;
129
- ctime: Date;
130
- birthtime: Date;
131
- isDirectory: () => any;
132
- isFile: () => any;
133
- isSymbolicLink: () => any;
134
- isBlockDevice: () => boolean;
135
- isCharacterDevice: () => boolean;
136
- isFIFO: () => boolean;
137
- isSocket: () => boolean;
138
- }>;
139
- realpath: (p: string) => Promise<string>;
140
- access: (path: string, mode?: number) => Promise<void>;
141
- };
142
- export declare const constants: {
143
- F_OK: number;
144
- R_OK: number;
145
- W_OK: number;
146
- X_OK: number;
147
- };
148
- declare const _default: {
149
- readFile: typeof readFile;
150
- readFileSync: typeof readFileSync;
151
- readdir: typeof readdir;
152
- readdirSync: typeof readdirSync;
153
- writeFile: typeof writeFile;
154
- writeFileSync: typeof writeFileSync;
155
- mkdir: typeof mkdir;
156
- mkdirSync: typeof mkdirSync;
157
- rm: typeof rm;
158
- rmSync: typeof rmSync;
159
- rmdir: typeof rmdir;
160
- rmdirSync: typeof rmdirSync;
161
- copyFile: typeof copyFile;
162
- copyFileSync: typeof copyFileSync;
163
- stat: typeof stat;
164
- statSync: typeof statSync;
165
- lstat: typeof lstat;
166
- lstatSync: typeof lstatSync;
167
- realpath: typeof realpath;
168
- realpathSync: typeof realpathSync;
169
- access: typeof access;
170
- accessSync: typeof accessSync;
171
- existsSync: typeof existsSync;
172
- promises: {
173
- readFile: (path: string, options?: any) => Promise<string | Buffer<any>>;
174
- writeFile: (path: string, data: string | Uint8Array, options?: any) => Promise<void>;
175
- readdir: (path: string, options?: any) => Promise<any>;
176
- mkdir: (path: string, options?: any) => Promise<void>;
177
- rm: (path: string, options?: any) => Promise<void>;
178
- rmdir: (path: string, options?: any) => Promise<void>;
179
- copyFile: (src: string, dst: string) => Promise<void>;
180
- stat: (p: string) => Promise<{
181
- dev: number;
182
- ino: number;
183
- mode: number;
184
- nlink: number;
185
- uid: number;
186
- gid: number;
187
- rdev: number;
188
- size: number;
189
- blksize: number;
190
- blocks: number;
191
- atimeMs: number;
192
- mtimeMs: number;
193
- ctimeMs: number;
194
- birthtimeMs: number;
195
- atime: Date;
196
- mtime: Date;
197
- ctime: Date;
198
- birthtime: Date;
199
- isDirectory: () => any;
200
- isFile: () => any;
201
- isSymbolicLink: () => any;
202
- isBlockDevice: () => boolean;
203
- isCharacterDevice: () => boolean;
204
- isFIFO: () => boolean;
205
- isSocket: () => boolean;
206
- }>;
207
- lstat: (p: string) => Promise<{
208
- dev: number;
209
- ino: number;
210
- mode: number;
211
- nlink: number;
212
- uid: number;
213
- gid: number;
214
- rdev: number;
215
- size: number;
216
- blksize: number;
217
- blocks: number;
218
- atimeMs: number;
219
- mtimeMs: number;
220
- ctimeMs: number;
221
- birthtimeMs: number;
222
- atime: Date;
223
- mtime: Date;
224
- ctime: Date;
225
- birthtime: Date;
226
- isDirectory: () => any;
227
- isFile: () => any;
228
- isSymbolicLink: () => any;
229
- isBlockDevice: () => boolean;
230
- isCharacterDevice: () => boolean;
231
- isFIFO: () => boolean;
232
- isSocket: () => boolean;
233
- }>;
234
- realpath: (p: string) => Promise<string>;
235
- access: (path: string, mode?: number) => Promise<void>;
236
- };
237
- constants: {
238
- F_OK: number;
239
- R_OK: number;
240
- W_OK: number;
241
- X_OK: number;
242
- };
243
- };
244
- export default _default;