@utoo/web 1.3.0 → 1.3.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.
- package/esm/loaderWorker.js +1 -1
- package/esm/utoo/index_bg.wasm +0 -0
- package/esm/webpackLoaders/polyfills/{fsPromisesPolyfill.d.ts → fsPolyfill/promises.d.ts} +1 -1
- package/esm/webpackLoaders/polyfills/fsPolyfill/promises.js +159 -0
- package/esm/webpackLoaders/polyfills/{fsPolyfill.d.ts → fsPolyfill/sync.d.ts} +3 -3
- package/esm/webpackLoaders/polyfills/fsPolyfill/sync.js +384 -0
- package/esm/webpackLoaders/polyfills/fsPolyfill/utils.d.ts +3 -0
- package/esm/webpackLoaders/polyfills/fsPolyfill/utils.js +28 -0
- package/esm/webpackLoaders/polyfills/nodePolyFills.d.ts +1 -1
- package/esm/webpackLoaders/polyfills/nodePolyFills.js +1 -1
- package/package.json +1 -1
- package/esm/webpackLoaders/polyfills/fsPolyfill.js +0 -291
- package/esm/webpackLoaders/polyfills/fsPromisesPolyfill.js +0 -113
|
@@ -1,291 +0,0 @@
|
|
|
1
|
-
import { Buffer } from "buffer";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import { Stats } from "../../types";
|
|
4
|
-
import { promises } from "./fsPromisesPolyfill";
|
|
5
|
-
import { workerData } from "./workerThreadsPolyfill";
|
|
6
|
-
function resolvePath(p) {
|
|
7
|
-
var _a, _b;
|
|
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)) || (workerData === null || workerData === void 0 ? void 0 : workerData.cwd) || "/";
|
|
10
|
-
return path.resolve(cwd, p);
|
|
11
|
-
}
|
|
12
|
-
function getFs() {
|
|
13
|
-
// @ts-ignore
|
|
14
|
-
const fs = workerData.fs;
|
|
15
|
-
if (!fs) {
|
|
16
|
-
throw new Error("FS not initialized");
|
|
17
|
-
}
|
|
18
|
-
return fs;
|
|
19
|
-
}
|
|
20
|
-
// --- Synchronous API (via WASM Project Sync APIs) ---
|
|
21
|
-
const textDecoder = new TextDecoder();
|
|
22
|
-
export function readFileSync(path, options) {
|
|
23
|
-
const fs = getFs();
|
|
24
|
-
const result = fs.readSync(resolvePath(path));
|
|
25
|
-
if (options === "utf8" ||
|
|
26
|
-
options === "utf-8" ||
|
|
27
|
-
(options && (options.encoding === "utf8" || options.encoding === "utf-8"))) {
|
|
28
|
-
return textDecoder.decode(result);
|
|
29
|
-
}
|
|
30
|
-
return Buffer.from(result);
|
|
31
|
-
}
|
|
32
|
-
export function readdirSync(path, options) {
|
|
33
|
-
const fs = getFs();
|
|
34
|
-
const entries = fs.readDirSync(resolvePath(path));
|
|
35
|
-
if (options === null || options === void 0 ? void 0 : options.withFileTypes) {
|
|
36
|
-
return entries.map((e) => ({
|
|
37
|
-
name: e.name,
|
|
38
|
-
isFile: () => e.type === "file",
|
|
39
|
-
isDirectory: () => e.type === "directory",
|
|
40
|
-
isSymbolicLink: () => false,
|
|
41
|
-
}));
|
|
42
|
-
}
|
|
43
|
-
return entries.map((e) => e.name);
|
|
44
|
-
}
|
|
45
|
-
export function writeFileSync(path, data, options) {
|
|
46
|
-
const fs = getFs();
|
|
47
|
-
let content;
|
|
48
|
-
if (typeof data === "string") {
|
|
49
|
-
content = new TextEncoder().encode(data);
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
content = data;
|
|
53
|
-
}
|
|
54
|
-
fs.writeSync(resolvePath(path), content);
|
|
55
|
-
}
|
|
56
|
-
export function mkdirSync(path, options) {
|
|
57
|
-
const fs = getFs();
|
|
58
|
-
const recursive = (options === null || options === void 0 ? void 0 : options.recursive) || false;
|
|
59
|
-
if (recursive) {
|
|
60
|
-
fs.createDirAllSync(resolvePath(path));
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
fs.createDirSync(resolvePath(path));
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
export function rmSync(path, options) {
|
|
67
|
-
const fs = getFs();
|
|
68
|
-
const recursive = (options === null || options === void 0 ? void 0 : options.recursive) || false;
|
|
69
|
-
if (recursive) {
|
|
70
|
-
fs.removeDirSync(resolvePath(path), true);
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
fs.removeFileSync(resolvePath(path));
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
export function rmdirSync(path, options) {
|
|
77
|
-
const fs = getFs();
|
|
78
|
-
const recursive = (options === null || options === void 0 ? void 0 : options.recursive) || false;
|
|
79
|
-
fs.removeDirSync(resolvePath(path), recursive);
|
|
80
|
-
}
|
|
81
|
-
export function copyFileSync(src, dst) {
|
|
82
|
-
const fs = getFs();
|
|
83
|
-
fs.copyFileSync(resolvePath(src), resolvePath(dst));
|
|
84
|
-
}
|
|
85
|
-
export function statSync(p) {
|
|
86
|
-
const fs = getFs();
|
|
87
|
-
const metadata = fs.metadataSync(resolvePath(p));
|
|
88
|
-
let type, size;
|
|
89
|
-
// @ts-ignore
|
|
90
|
-
if (typeof metadata.toJSON === "function") {
|
|
91
|
-
// @ts-ignore
|
|
92
|
-
const json = metadata.toJSON();
|
|
93
|
-
type = json.type;
|
|
94
|
-
size = json.file_size;
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
// @ts-ignore
|
|
98
|
-
type = metadata.type;
|
|
99
|
-
// @ts-ignore
|
|
100
|
-
size = metadata.file_size;
|
|
101
|
-
}
|
|
102
|
-
return new Stats({
|
|
103
|
-
type: type === "directory" ? "directory" : "file",
|
|
104
|
-
size: Number(size || 0),
|
|
105
|
-
atimeMs: Date.now(),
|
|
106
|
-
mtimeMs: Date.now(),
|
|
107
|
-
ctimeMs: Date.now(),
|
|
108
|
-
birthtimeMs: Date.now(),
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
export function lstatSync(p) {
|
|
112
|
-
return statSync(p);
|
|
113
|
-
}
|
|
114
|
-
export function realpathSync(p) {
|
|
115
|
-
return p;
|
|
116
|
-
}
|
|
117
|
-
export function accessSync(path, mode) {
|
|
118
|
-
statSync(path);
|
|
119
|
-
}
|
|
120
|
-
export function existsSync(path) {
|
|
121
|
-
try {
|
|
122
|
-
statSync(path);
|
|
123
|
-
return true;
|
|
124
|
-
}
|
|
125
|
-
catch (e) {
|
|
126
|
-
return false;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
// --- Asynchronous API (via WASM Project) ---
|
|
130
|
-
export function readFile(path, options, cb) {
|
|
131
|
-
if (typeof options === "function") {
|
|
132
|
-
cb = options;
|
|
133
|
-
options = {};
|
|
134
|
-
}
|
|
135
|
-
const encoding = options === "utf8" ||
|
|
136
|
-
options === "utf-8" ||
|
|
137
|
-
(options === null || options === void 0 ? void 0 : options.encoding) === "utf8" ||
|
|
138
|
-
(options === null || options === void 0 ? void 0 : options.encoding) === "utf-8"
|
|
139
|
-
? "utf8"
|
|
140
|
-
: undefined;
|
|
141
|
-
const p = resolvePath(path);
|
|
142
|
-
const fs = getFs();
|
|
143
|
-
const promise = encoding ? fs.readToString(p) : fs.read(p);
|
|
144
|
-
promise
|
|
145
|
-
.then((data) => {
|
|
146
|
-
cb(null, encoding ? data : Buffer.from(data));
|
|
147
|
-
})
|
|
148
|
-
.catch((e) => cb(e));
|
|
149
|
-
}
|
|
150
|
-
export function readdir(path, options, cb) {
|
|
151
|
-
if (typeof options === "function") {
|
|
152
|
-
cb = options;
|
|
153
|
-
options = {};
|
|
154
|
-
}
|
|
155
|
-
getFs()
|
|
156
|
-
.readDir(resolvePath(path))
|
|
157
|
-
.then((entries) => {
|
|
158
|
-
const result = entries.map((e) => {
|
|
159
|
-
const json = e.toJSON();
|
|
160
|
-
if (options === null || options === void 0 ? void 0 : options.withFileTypes) {
|
|
161
|
-
return {
|
|
162
|
-
name: json.name,
|
|
163
|
-
isFile: () => json.type === "file",
|
|
164
|
-
isDirectory: () => json.type === "directory",
|
|
165
|
-
isSymbolicLink: () => false,
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
return json.name;
|
|
169
|
-
});
|
|
170
|
-
cb(null, result);
|
|
171
|
-
})
|
|
172
|
-
.catch((e) => cb(e));
|
|
173
|
-
}
|
|
174
|
-
export function writeFile(path, data, options, cb) {
|
|
175
|
-
if (typeof options === "function") {
|
|
176
|
-
cb = options;
|
|
177
|
-
options = {};
|
|
178
|
-
}
|
|
179
|
-
const p = resolvePath(path);
|
|
180
|
-
const fs = getFs();
|
|
181
|
-
const promise = typeof data === "string" ? fs.writeString(p, data) : fs.write(p, data);
|
|
182
|
-
promise.then(() => cb(null)).catch((e) => cb(e));
|
|
183
|
-
}
|
|
184
|
-
export function mkdir(path, options, cb) {
|
|
185
|
-
if (typeof options === "function") {
|
|
186
|
-
cb = options;
|
|
187
|
-
options = {};
|
|
188
|
-
}
|
|
189
|
-
const p = resolvePath(path);
|
|
190
|
-
const fs = getFs();
|
|
191
|
-
const promise = (options === null || options === void 0 ? void 0 : options.recursive) ? fs.createDirAll(p) : fs.createDir(p);
|
|
192
|
-
promise.then(() => cb(null)).catch((e) => cb(e));
|
|
193
|
-
}
|
|
194
|
-
export function rm(path, options, cb) {
|
|
195
|
-
if (typeof options === "function") {
|
|
196
|
-
cb = options;
|
|
197
|
-
options = {};
|
|
198
|
-
}
|
|
199
|
-
const p = resolvePath(path);
|
|
200
|
-
const fs = getFs();
|
|
201
|
-
fs.metadata(p)
|
|
202
|
-
.then((metadata) => {
|
|
203
|
-
const type = metadata.toJSON().type;
|
|
204
|
-
if (type === "file") {
|
|
205
|
-
return fs.removeFile(p);
|
|
206
|
-
}
|
|
207
|
-
else {
|
|
208
|
-
return fs.removeDir(p, !!(options === null || options === void 0 ? void 0 : options.recursive));
|
|
209
|
-
}
|
|
210
|
-
})
|
|
211
|
-
.then(() => cb(null))
|
|
212
|
-
.catch((e) => cb(e));
|
|
213
|
-
}
|
|
214
|
-
export function rmdir(path, options, cb) {
|
|
215
|
-
if (typeof options === "function") {
|
|
216
|
-
cb = options;
|
|
217
|
-
options = {};
|
|
218
|
-
}
|
|
219
|
-
getFs()
|
|
220
|
-
.removeDir(resolvePath(path), !!(options === null || options === void 0 ? void 0 : options.recursive))
|
|
221
|
-
.then(() => cb(null))
|
|
222
|
-
.catch((e) => cb(e));
|
|
223
|
-
}
|
|
224
|
-
export function copyFile(src, dst, cb) {
|
|
225
|
-
getFs()
|
|
226
|
-
.copyFile(resolvePath(src), resolvePath(dst))
|
|
227
|
-
.then(() => cb(null))
|
|
228
|
-
.catch((e) => cb(e));
|
|
229
|
-
}
|
|
230
|
-
export function stat(p, cb) {
|
|
231
|
-
getFs()
|
|
232
|
-
.metadata(resolvePath(p))
|
|
233
|
-
.then((metadata) => {
|
|
234
|
-
const json = metadata.toJSON();
|
|
235
|
-
cb(null, new Stats({
|
|
236
|
-
type: json.type,
|
|
237
|
-
size: Number(json.file_size || 0),
|
|
238
|
-
}));
|
|
239
|
-
})
|
|
240
|
-
.catch((e) => cb(e));
|
|
241
|
-
}
|
|
242
|
-
export function lstat(p, cb) {
|
|
243
|
-
stat(p, cb);
|
|
244
|
-
}
|
|
245
|
-
export function realpath(p, cb) {
|
|
246
|
-
cb(null, p);
|
|
247
|
-
}
|
|
248
|
-
export function access(p, mode, cb) {
|
|
249
|
-
if (typeof mode === "function") {
|
|
250
|
-
cb = mode;
|
|
251
|
-
mode = 0;
|
|
252
|
-
}
|
|
253
|
-
stat(p, (err) => {
|
|
254
|
-
if (cb)
|
|
255
|
-
cb(err);
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
export const constants = {
|
|
259
|
-
F_OK: 0,
|
|
260
|
-
R_OK: 4,
|
|
261
|
-
W_OK: 2,
|
|
262
|
-
X_OK: 1,
|
|
263
|
-
};
|
|
264
|
-
export default {
|
|
265
|
-
readFile,
|
|
266
|
-
readFileSync,
|
|
267
|
-
readdir,
|
|
268
|
-
readdirSync,
|
|
269
|
-
writeFile,
|
|
270
|
-
writeFileSync,
|
|
271
|
-
mkdir,
|
|
272
|
-
mkdirSync,
|
|
273
|
-
rm,
|
|
274
|
-
rmSync,
|
|
275
|
-
rmdir,
|
|
276
|
-
rmdirSync,
|
|
277
|
-
copyFile,
|
|
278
|
-
copyFileSync,
|
|
279
|
-
stat,
|
|
280
|
-
statSync,
|
|
281
|
-
lstat,
|
|
282
|
-
lstatSync,
|
|
283
|
-
realpath,
|
|
284
|
-
realpathSync,
|
|
285
|
-
access,
|
|
286
|
-
accessSync,
|
|
287
|
-
existsSync,
|
|
288
|
-
promises,
|
|
289
|
-
constants,
|
|
290
|
-
};
|
|
291
|
-
export { promises };
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { Buffer } from "buffer";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import { Stats } from "../../types";
|
|
4
|
-
import { workerData } from "./workerThreadsPolyfill";
|
|
5
|
-
function resolvePath(p) {
|
|
6
|
-
var _a, _b;
|
|
7
|
-
// @ts-ignore
|
|
8
|
-
const cwd = ((_b = (_a = self.process) === null || _a === void 0 ? void 0 : _a.cwd) === null || _b === void 0 ? void 0 : _b.call(_a)) || (workerData === null || workerData === void 0 ? void 0 : workerData.cwd) || "/";
|
|
9
|
-
return path.resolve(cwd, p);
|
|
10
|
-
}
|
|
11
|
-
function getFs() {
|
|
12
|
-
// @ts-ignore
|
|
13
|
-
const fs = workerData.fs;
|
|
14
|
-
if (!fs) {
|
|
15
|
-
throw new Error("FS not initialized");
|
|
16
|
-
}
|
|
17
|
-
return fs;
|
|
18
|
-
}
|
|
19
|
-
export const promises = {
|
|
20
|
-
readFile: async (p, options) => {
|
|
21
|
-
const encoding = options === "utf8" ||
|
|
22
|
-
options === "utf-8" ||
|
|
23
|
-
(options === null || options === void 0 ? void 0 : options.encoding) === "utf8" ||
|
|
24
|
-
(options === null || options === void 0 ? void 0 : options.encoding) === "utf-8"
|
|
25
|
-
? "utf8"
|
|
26
|
-
: undefined;
|
|
27
|
-
const fs = getFs();
|
|
28
|
-
const path = resolvePath(p);
|
|
29
|
-
const data = await (encoding ? fs.readToString(path) : fs.read(path));
|
|
30
|
-
return encoding ? data : Buffer.from(data);
|
|
31
|
-
},
|
|
32
|
-
writeFile: async (p, data, options) => {
|
|
33
|
-
const fs = getFs();
|
|
34
|
-
const path = resolvePath(p);
|
|
35
|
-
if (typeof data === "string") {
|
|
36
|
-
await fs.writeString(path, data);
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
await fs.write(path, data);
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
readdir: async (p, options) => {
|
|
43
|
-
const entries = await getFs().readDir(resolvePath(p));
|
|
44
|
-
return entries.map((e) => {
|
|
45
|
-
const json = e.toJSON();
|
|
46
|
-
if (options === null || options === void 0 ? void 0 : options.withFileTypes) {
|
|
47
|
-
return {
|
|
48
|
-
name: json.name,
|
|
49
|
-
isFile: () => json.type === "file",
|
|
50
|
-
isDirectory: () => json.type === "directory",
|
|
51
|
-
isSymbolicLink: () => false,
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
return json.name;
|
|
55
|
-
});
|
|
56
|
-
},
|
|
57
|
-
mkdir: async (p, options) => {
|
|
58
|
-
const fs = getFs();
|
|
59
|
-
const path = resolvePath(p);
|
|
60
|
-
if (options === null || options === void 0 ? void 0 : options.recursive) {
|
|
61
|
-
await fs.createDirAll(path);
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
await fs.createDir(path);
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
rm: async (p, options) => {
|
|
68
|
-
const fs = getFs();
|
|
69
|
-
const path = resolvePath(p);
|
|
70
|
-
const metadata = await fs.metadata(path);
|
|
71
|
-
const type = metadata.toJSON().type;
|
|
72
|
-
if (type === "file") {
|
|
73
|
-
await fs.removeFile(path);
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
await fs.removeDir(path, !!(options === null || options === void 0 ? void 0 : options.recursive));
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
rmdir: async (p, options) => getFs().removeDir(resolvePath(p), !!(options === null || options === void 0 ? void 0 : options.recursive)),
|
|
80
|
-
copyFile: async (src, dst) => getFs().copyFile(resolvePath(src), resolvePath(dst)),
|
|
81
|
-
stat: async (p) => {
|
|
82
|
-
const metadata = await getFs().metadata(resolvePath(p));
|
|
83
|
-
const json = metadata.toJSON();
|
|
84
|
-
return new Stats({
|
|
85
|
-
type: json.type,
|
|
86
|
-
size: Number(json.file_size || 0),
|
|
87
|
-
});
|
|
88
|
-
},
|
|
89
|
-
lstat: async (p) => {
|
|
90
|
-
const metadata = await getFs().metadata(resolvePath(p));
|
|
91
|
-
const json = metadata.toJSON();
|
|
92
|
-
return new Stats({
|
|
93
|
-
type: json.type,
|
|
94
|
-
size: Number(json.file_size || 0),
|
|
95
|
-
});
|
|
96
|
-
},
|
|
97
|
-
realpath: async (p) => p,
|
|
98
|
-
access: async (p, mode) => {
|
|
99
|
-
await getFs().metadata(resolvePath(p));
|
|
100
|
-
},
|
|
101
|
-
};
|
|
102
|
-
export const readFile = promises.readFile;
|
|
103
|
-
export const writeFile = promises.writeFile;
|
|
104
|
-
export const readdir = promises.readdir;
|
|
105
|
-
export const mkdir = promises.mkdir;
|
|
106
|
-
export const rm = promises.rm;
|
|
107
|
-
export const rmdir = promises.rmdir;
|
|
108
|
-
export const copyFile = promises.copyFile;
|
|
109
|
-
export const stat = promises.stat;
|
|
110
|
-
export const lstat = promises.lstat;
|
|
111
|
-
export const realpath = promises.realpath;
|
|
112
|
-
export const access = promises.access;
|
|
113
|
-
export default promises;
|