@utoo/web 1.1.0 → 1.2.0-rc.10

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 (56) hide show
  1. package/README.md +55 -0
  2. package/esm/a0a815481b4ff49f8961.wasm +0 -0
  3. package/esm/index.d.ts +3 -2
  4. package/esm/index.js +3 -2
  5. package/esm/loaderWorker.js +2 -0
  6. package/esm/loaderWorker.js.LICENSE.txt +23 -0
  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 -3
  10. package/esm/project/InternalProject.js +132 -0
  11. package/esm/{project.d.ts → project/Project.d.ts} +4 -1
  12. package/esm/{project.js → project/Project.js} +21 -6
  13. package/esm/serviceWorker.js +4 -3
  14. package/esm/{type.d.ts → types.d.ts} +44 -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 +126 -66
  19. package/esm/utoo/index.js +351 -235
  20. package/esm/utoo/index_bg.wasm +0 -0
  21. package/esm/webpackLoaders/cjs.js +299 -0
  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/polyfills/fsPolyfill.js +279 -0
  26. package/esm/webpackLoaders/polyfills/fsPromisesPolyfill.d.ts +26 -0
  27. package/esm/webpackLoaders/polyfills/fsPromisesPolyfill.js +112 -0
  28. package/esm/webpackLoaders/polyfills/nodePolyFills.d.ts +92 -0
  29. package/esm/webpackLoaders/polyfills/nodePolyFills.js +230 -0
  30. package/esm/webpackLoaders/polyfills/workerThreadsPolyfill.d.ts +7 -0
  31. package/esm/webpackLoaders/polyfills/workerThreadsPolyfill.js +16 -0
  32. package/esm/webpackLoaders/{worker/type.d.ts → types.d.ts} +2 -1
  33. package/esm/webpackLoaders/worker.d.ts +2 -0
  34. package/esm/webpackLoaders/worker.js +46 -0
  35. package/esm/worker.js +2 -2
  36. package/package.json +19 -18
  37. package/esm/internalProject.js +0 -185
  38. package/esm/type.js +0 -12
  39. package/esm/webpackLoaders/loaders/less-loader/index.d.ts +0 -3
  40. package/esm/webpackLoaders/loaders/less-loader/index.js +0 -103
  41. package/esm/webpackLoaders/loaders/less-loader/options.json +0 -67
  42. package/esm/webpackLoaders/loaders/less-loader/utils.d.ts +0 -14
  43. package/esm/webpackLoaders/loaders/less-loader/utils.js +0 -217
  44. package/esm/webpackLoaders/worker/cjs.js +0 -80
  45. package/esm/webpackLoaders/worker/index.d.ts +0 -2
  46. package/esm/webpackLoaders/worker/index.js +0 -31
  47. package/esm/webpackLoaders/worker/nodePolyFills.d.ts +0 -14
  48. package/esm/webpackLoaders/worker/nodePolyFills.js +0 -24
  49. package/esm/webpackLoaders/workerContent.d.ts +0 -2
  50. package/esm/webpackLoaders/workerContent.js +0 -1
  51. /package/esm/{installServiceWorker.d.ts → utils/installServiceWorker.d.ts} +0 -0
  52. /package/esm/{installServiceWorker.js → utils/installServiceWorker.js} +0 -0
  53. /package/esm/{message.d.ts → utils/message.d.ts} +0 -0
  54. /package/esm/{message.js → utils/message.js} +0 -0
  55. /package/esm/webpackLoaders/{worker/cjs.d.ts → cjs.d.ts} +0 -0
  56. /package/esm/webpackLoaders/{worker/type.js → types.js} +0 -0
@@ -0,0 +1,279 @@
1
+ import { Buffer } from "buffer";
2
+ import path from "path";
3
+ import { Stats } from "../../types";
4
+ import * as sabcom from "../../utils/sabcom";
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 "../../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;
@@ -0,0 +1,92 @@
1
+ import * as fs from "./fsPolyfill";
2
+ declare const _default: {
3
+ readonly assert: any;
4
+ readonly "node:assert": any;
5
+ buffer: any;
6
+ "node:buffer": any;
7
+ readonly child_process: any;
8
+ readonly "node:child_process": any;
9
+ readonly cluster: any;
10
+ readonly "node:cluster": any;
11
+ readonly console: any;
12
+ readonly "node:console": any;
13
+ readonly constants: any;
14
+ readonly "node:constants": any;
15
+ readonly crypto: any;
16
+ readonly "node:crypto": any;
17
+ readonly dgram: any;
18
+ readonly "node:dgram": any;
19
+ readonly dns: any;
20
+ readonly "node:dns": any;
21
+ readonly domain: any;
22
+ readonly "node:domain": any;
23
+ readonly events: any;
24
+ readonly "node:events": any;
25
+ readonly http: any;
26
+ readonly "node:http": any;
27
+ readonly http2: any;
28
+ readonly "node:http2": any;
29
+ readonly https: any;
30
+ readonly "node:https": any;
31
+ readonly module: any;
32
+ readonly "node:module": any;
33
+ readonly net: any;
34
+ readonly "node:net": any;
35
+ readonly os: any;
36
+ readonly "node:os": any;
37
+ readonly punycode: any;
38
+ readonly "node:punycode": any;
39
+ readonly querystring: any;
40
+ readonly "node:querystring": any;
41
+ readonly readline: any;
42
+ readonly "node:readline": any;
43
+ readonly repl: any;
44
+ readonly "node:repl": any;
45
+ readonly stream: any;
46
+ readonly "node:stream": any;
47
+ readonly string_decoder: any;
48
+ readonly "node:string_decoder": any;
49
+ readonly sys: any;
50
+ readonly "node:sys": any;
51
+ readonly timers: any;
52
+ readonly "node:timers": any;
53
+ readonly tls: any;
54
+ readonly "node:tls": any;
55
+ readonly tty: any;
56
+ readonly "node:tty": any;
57
+ readonly vm: any;
58
+ readonly "node:vm": any;
59
+ readonly zlib: any;
60
+ readonly "node:zlib": any;
61
+ fs: typeof fs;
62
+ "node:fs": typeof fs;
63
+ path: any;
64
+ "node:path": any;
65
+ process: any;
66
+ "node:process": any;
67
+ readonly url: any;
68
+ readonly "node:url": any;
69
+ readonly util: any;
70
+ readonly "node:util": any;
71
+ worker_threads: {
72
+ workerData: any;
73
+ threadId: any;
74
+ isMainThread: false;
75
+ parentPort: {
76
+ postMessage: (message: any) => void;
77
+ on: (event: string, listener: (...args: any[]) => void) => void;
78
+ off: (event: string, listener: (...args: any[]) => void) => void;
79
+ };
80
+ };
81
+ "node:worker_threads": {
82
+ workerData: any;
83
+ threadId: any;
84
+ isMainThread: false;
85
+ parentPort: {
86
+ postMessage: (message: any) => void;
87
+ on: (event: string, listener: (...args: any[]) => void) => void;
88
+ off: (event: string, listener: (...args: any[]) => void) => void;
89
+ };
90
+ };
91
+ };
92
+ export default _default;