opfs-worker 1.3.2 → 2.1.0
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/README.md +64 -458
- package/dist/BaseOPFS-BPw9AIQ-.cjs +4 -0
- package/dist/BaseOPFS-BPw9AIQ-.cjs.map +1 -0
- package/dist/BaseOPFS-Cylz6ijk.js +2036 -0
- package/dist/BaseOPFS-Cylz6ijk.js.map +1 -0
- package/dist/OPFSAsync-BKSAJJeh.js +124 -0
- package/dist/OPFSAsync-BKSAJJeh.js.map +1 -0
- package/dist/OPFSAsync-s2P7y3sw.cjs +2 -0
- package/dist/OPFSAsync-s2P7y3sw.cjs.map +1 -0
- package/dist/OPFSFacade-DePnNRgt.cjs +2 -0
- package/dist/OPFSFacade-DePnNRgt.cjs.map +1 -0
- package/dist/OPFSFacade-XohWlHuu.js +281 -0
- package/dist/OPFSFacade-XohWlHuu.js.map +1 -0
- package/dist/OPFSSync-C7KBepe_.cjs +2 -0
- package/dist/OPFSSync-C7KBepe_.cjs.map +1 -0
- package/dist/OPFSSync-CsSQkpk5.js +208 -0
- package/dist/OPFSSync-CsSQkpk5.js.map +1 -0
- package/dist/assets/dedicated.worker-nY3tK4zi.js.map +1 -0
- package/dist/{worker.d.ts → core/BaseOPFS.d.ts} +34 -300
- package/dist/core/BaseOPFS.d.ts.map +1 -0
- package/dist/core/OPFSAsync.d.ts +55 -0
- package/dist/core/OPFSAsync.d.ts.map +1 -0
- package/dist/core/OPFSSync.d.ts +54 -0
- package/dist/core/OPFSSync.d.ts.map +1 -0
- package/dist/createOPFSAsync-BwKDmHsy.cjs +2 -0
- package/dist/createOPFSAsync-BwKDmHsy.cjs.map +1 -0
- package/dist/createOPFSAsync-Y4Mg6qte.js +10 -0
- package/dist/createOPFSAsync-Y4Mg6qte.js.map +1 -0
- package/dist/createOPFSDedicated-CsnV6MLP.js +2333 -0
- package/dist/createOPFSDedicated-CsnV6MLP.js.map +1 -0
- package/dist/createOPFSDedicated-pKTRWLdz.cjs +2283 -0
- package/dist/createOPFSDedicated-pKTRWLdz.cjs.map +1 -0
- package/dist/createOPFSShared-CGdd__PH.js +23 -0
- package/dist/createOPFSShared-CGdd__PH.js.map +1 -0
- package/dist/createOPFSShared-CskROt7U.cjs +2 -0
- package/dist/createOPFSShared-CskROt7U.cjs.map +1 -0
- package/dist/dedicated.worker.js +2281 -0
- package/dist/dedicated.worker.js.map +1 -0
- package/dist/{facade.d.ts → facade/OPFSFacade.d.ts} +35 -10
- package/dist/facade/OPFSFacade.d.ts.map +1 -0
- package/dist/facade/createOPFSAsync.d.ts +16 -0
- package/dist/facade/createOPFSAsync.d.ts.map +1 -0
- package/dist/facade/createOPFSDedicated.d.ts +17 -0
- package/dist/facade/createOPFSDedicated.d.ts.map +1 -0
- package/dist/facade/createOPFSShared.d.ts +24 -0
- package/dist/facade/createOPFSShared.d.ts.map +1 -0
- package/dist/index.async.cjs +2 -0
- package/dist/index.async.cjs.map +1 -0
- package/dist/index.async.d.ts +10 -0
- package/dist/index.async.d.ts.map +1 -0
- package/dist/index.async.js +55 -0
- package/dist/index.async.js.map +1 -0
- package/dist/index.cjs +1 -2466
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +15 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +61 -2799
- package/dist/index.js.map +1 -1
- package/dist/index.pure.cjs +2 -0
- package/dist/index.pure.cjs.map +1 -0
- package/dist/index.pure.d.ts +8 -0
- package/dist/index.pure.d.ts.map +1 -0
- package/dist/index.pure.js +53 -0
- package/dist/index.pure.js.map +1 -0
- package/dist/index.sharedworker.cjs +2 -0
- package/dist/index.sharedworker.cjs.map +1 -0
- package/dist/index.sharedworker.d.ts +11 -0
- package/dist/index.sharedworker.d.ts.map +1 -0
- package/dist/index.sharedworker.js +55 -0
- package/dist/index.sharedworker.js.map +1 -0
- package/dist/index.sync.cjs +2 -0
- package/dist/index.sync.cjs.map +1 -0
- package/dist/index.sync.d.ts +11 -0
- package/dist/index.sync.d.ts.map +1 -0
- package/dist/index.sync.js +55 -0
- package/dist/index.sync.js.map +1 -0
- package/dist/shared.worker.js +2166 -0
- package/dist/shared.worker.js.map +1 -0
- package/dist/types.d.ts +9 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/helpers.d.ts +11 -1
- package/dist/utils/helpers.d.ts.map +1 -1
- package/dist/worker/createDedicatedWorker.d.ts +30 -0
- package/dist/worker/createDedicatedWorker.d.ts.map +1 -0
- package/dist/worker/createSharedWorker.d.ts +37 -0
- package/dist/worker/createSharedWorker.d.ts.map +1 -0
- package/dist/worker/dedicated.worker.d.ts +2 -0
- package/dist/worker/dedicated.worker.d.ts.map +1 -0
- package/dist/worker/shared.worker.d.ts +2 -0
- package/dist/worker/shared.worker.d.ts.map +1 -0
- package/docs/README.md +30 -0
- package/docs/api/backend.md +36 -0
- package/docs/api/create.md +82 -0
- package/docs/api/facade.md +52 -0
- package/docs/choosing-a-mode.md +41 -0
- package/docs/file-descriptors.md +695 -0
- package/docs/guides/async.md +36 -0
- package/docs/guides/dedicated.md +76 -0
- package/docs/guides/hashing.md +34 -0
- package/docs/guides/pure.md +46 -0
- package/docs/guides/sharedworker.md +57 -0
- package/docs/guides/streaming.md +51 -0
- package/docs/guides/watching.md +35 -0
- package/docs/migration.md +41 -0
- package/docs/types.md +246 -0
- package/package.json +55 -10
- package/src/core/BaseOPFS.ts +951 -0
- package/src/core/OPFSAsync.ts +248 -0
- package/src/core/OPFSSync.ts +460 -0
- package/src/facade/OPFSFacade.ts +489 -0
- package/src/facade/createOPFSAsync.ts +22 -0
- package/src/facade/createOPFSDedicated.ts +23 -0
- package/src/facade/createOPFSShared.ts +30 -0
- package/src/index.async.ts +11 -0
- package/src/index.pure.ts +8 -0
- package/src/index.sharedworker.ts +12 -0
- package/src/index.sync.ts +12 -0
- package/src/index.ts +44 -0
- package/src/types.ts +103 -0
- package/src/utils/encoder.ts +205 -0
- package/src/utils/errors.ts +297 -0
- package/src/utils/helpers.ts +465 -0
- package/src/worker/createDedicatedWorker.ts +74 -0
- package/src/worker/createSharedWorker.ts +67 -0
- package/src/worker/dedicated.worker.ts +13 -0
- package/src/worker/shared.worker.ts +17 -0
- package/dist/assets/worker-1Wh1cr7P.js.map +0 -1
- package/dist/assets/worker-BeJaVyBV.js.map +0 -1
- package/dist/assets/worker-DYYLzR1Y.js.map +0 -1
- package/dist/facade.d.ts.map +0 -1
- package/dist/helpers-BuGfPAg0.js +0 -1439
- package/dist/helpers-BuGfPAg0.js.map +0 -1
- package/dist/helpers-CF7A2WQG.cjs +0 -4
- package/dist/helpers-CF7A2WQG.cjs.map +0 -1
- package/dist/helpers-CIiblZ8d.cjs +0 -4
- package/dist/helpers-CIiblZ8d.cjs.map +0 -1
- package/dist/helpers-CKOebsbw.js +0 -1423
- package/dist/helpers-CKOebsbw.js.map +0 -1
- package/dist/helpers-Ca2c767K.js +0 -1427
- package/dist/helpers-Ca2c767K.js.map +0 -1
- package/dist/helpers-Dwc92hv9.cjs +0 -4
- package/dist/helpers-Dwc92hv9.cjs.map +0 -1
- package/dist/raw.cjs +0 -2
- package/dist/raw.cjs.map +0 -1
- package/dist/raw.d.ts +0 -13
- package/dist/raw.d.ts.map +0 -1
- package/dist/raw.js +0 -1001
- package/dist/raw.js.map +0 -1
- package/dist/worker.d.ts.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,2467 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2019 Google LLC
|
|
4
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
*/
|
|
6
|
-
const bt = Symbol("Comlink.proxy"), Ht = Symbol("Comlink.endpoint"), Wt = Symbol("Comlink.releaseProxy"), X = Symbol("Comlink.finalizer"), _ = Symbol("Comlink.thrown"), Ot = (s) => typeof s == "object" && s !== null || typeof s == "function", jt = {
|
|
7
|
-
canHandle: (s) => Ot(s) && s[bt],
|
|
8
|
-
serialize(s) {
|
|
9
|
-
const { port1: t, port2: e } = new MessageChannel();
|
|
10
|
-
return ot(s, t), [e, [e]];
|
|
11
|
-
},
|
|
12
|
-
deserialize(s) {
|
|
13
|
-
return s.start(), Gt(s);
|
|
14
|
-
}
|
|
15
|
-
}, _t = {
|
|
16
|
-
canHandle: (s) => Ot(s) && _ in s,
|
|
17
|
-
serialize({ value: s }) {
|
|
18
|
-
let t;
|
|
19
|
-
return s instanceof Error ? t = {
|
|
20
|
-
isError: !0,
|
|
21
|
-
value: {
|
|
22
|
-
message: s.message,
|
|
23
|
-
name: s.name,
|
|
24
|
-
stack: s.stack
|
|
25
|
-
}
|
|
26
|
-
} : t = { isError: !1, value: s }, [t, []];
|
|
27
|
-
},
|
|
28
|
-
deserialize(s) {
|
|
29
|
-
throw s.isError ? Object.assign(new Error(s.value.message), s.value) : s.value;
|
|
30
|
-
}
|
|
31
|
-
}, Dt = /* @__PURE__ */ new Map([
|
|
32
|
-
["proxy", jt],
|
|
33
|
-
["throw", _t]
|
|
34
|
-
]);
|
|
35
|
-
function Ut(s, t) {
|
|
36
|
-
for (const e of s)
|
|
37
|
-
if (t === e || e === "*" || e instanceof RegExp && e.test(t))
|
|
38
|
-
return !0;
|
|
39
|
-
return !1;
|
|
40
|
-
}
|
|
41
|
-
function ot(s, t = globalThis, e = ["*"]) {
|
|
42
|
-
t.addEventListener("message", function n(r) {
|
|
43
|
-
if (!r || !r.data)
|
|
44
|
-
return;
|
|
45
|
-
if (!Ut(e, r.origin)) {
|
|
46
|
-
console.warn(\`Invalid origin '\${r.origin}' for comlink proxy\`);
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
const { id: i, type: o, path: a } = Object.assign({ path: [] }, r.data), l = (r.data.argumentList || []).map(C);
|
|
50
|
-
let h;
|
|
51
|
-
try {
|
|
52
|
-
const c = a.slice(0, -1).reduce((u, d) => u[d], s), f = a.reduce((u, d) => u[d], s);
|
|
53
|
-
switch (o) {
|
|
54
|
-
case "GET":
|
|
55
|
-
h = f;
|
|
56
|
-
break;
|
|
57
|
-
case "SET":
|
|
58
|
-
c[a.slice(-1)[0]] = C(r.data.value), h = !0;
|
|
59
|
-
break;
|
|
60
|
-
case "APPLY":
|
|
61
|
-
h = f.apply(c, l);
|
|
62
|
-
break;
|
|
63
|
-
case "CONSTRUCT":
|
|
64
|
-
{
|
|
65
|
-
const u = new f(...l);
|
|
66
|
-
h = Zt(u);
|
|
67
|
-
}
|
|
68
|
-
break;
|
|
69
|
-
case "ENDPOINT":
|
|
70
|
-
{
|
|
71
|
-
const { port1: u, port2: d } = new MessageChannel();
|
|
72
|
-
ot(s, d), h = U(u, [u]);
|
|
73
|
-
}
|
|
74
|
-
break;
|
|
75
|
-
case "RELEASE":
|
|
76
|
-
h = void 0;
|
|
77
|
-
break;
|
|
78
|
-
default:
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
} catch (c) {
|
|
82
|
-
h = { value: c, [_]: 0 };
|
|
83
|
-
}
|
|
84
|
-
Promise.resolve(h).catch((c) => ({ value: c, [_]: 0 })).then((c) => {
|
|
85
|
-
const [f, u] = V(c);
|
|
86
|
-
t.postMessage(Object.assign(Object.assign({}, f), { id: i }), u), o === "RELEASE" && (t.removeEventListener("message", n), vt(t), X in s && typeof s[X] == "function" && s[X]());
|
|
87
|
-
}).catch((c) => {
|
|
88
|
-
const [f, u] = V({
|
|
89
|
-
value: new TypeError("Unserializable return value"),
|
|
90
|
-
[_]: 0
|
|
91
|
-
});
|
|
92
|
-
t.postMessage(Object.assign(Object.assign({}, f), { id: i }), u);
|
|
93
|
-
});
|
|
94
|
-
}), t.start && t.start();
|
|
95
|
-
}
|
|
96
|
-
function Bt(s) {
|
|
97
|
-
return s.constructor.name === "MessagePort";
|
|
98
|
-
}
|
|
99
|
-
function vt(s) {
|
|
100
|
-
Bt(s) && s.close();
|
|
101
|
-
}
|
|
102
|
-
function Gt(s, t) {
|
|
103
|
-
const e = /* @__PURE__ */ new Map();
|
|
104
|
-
return s.addEventListener("message", function(r) {
|
|
105
|
-
const { data: i } = r;
|
|
106
|
-
if (!i || !i.id)
|
|
107
|
-
return;
|
|
108
|
-
const o = e.get(i.id);
|
|
109
|
-
if (o)
|
|
110
|
-
try {
|
|
111
|
-
o(i);
|
|
112
|
-
} finally {
|
|
113
|
-
e.delete(i.id);
|
|
114
|
-
}
|
|
115
|
-
}), st(s, e, [], t);
|
|
116
|
-
}
|
|
117
|
-
function H(s) {
|
|
118
|
-
if (s)
|
|
119
|
-
throw new Error("Proxy has been released and is not useable");
|
|
120
|
-
}
|
|
121
|
-
function At(s) {
|
|
122
|
-
return F(s, /* @__PURE__ */ new Map(), {
|
|
123
|
-
type: "RELEASE"
|
|
124
|
-
}).then(() => {
|
|
125
|
-
vt(s);
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
const G = /* @__PURE__ */ new WeakMap(), q = "FinalizationRegistry" in globalThis && new FinalizationRegistry((s) => {
|
|
129
|
-
const t = (G.get(s) || 0) - 1;
|
|
130
|
-
G.set(s, t), t === 0 && At(s);
|
|
131
|
-
});
|
|
132
|
-
function qt(s, t) {
|
|
133
|
-
const e = (G.get(t) || 0) + 1;
|
|
134
|
-
G.set(t, e), q && q.register(s, t, s);
|
|
135
|
-
}
|
|
136
|
-
function Vt(s) {
|
|
137
|
-
q && q.unregister(s);
|
|
138
|
-
}
|
|
139
|
-
function st(s, t, e = [], n = function() {
|
|
140
|
-
}) {
|
|
141
|
-
let r = !1;
|
|
142
|
-
const i = new Proxy(n, {
|
|
143
|
-
get(o, a) {
|
|
144
|
-
if (H(r), a === Wt)
|
|
145
|
-
return () => {
|
|
146
|
-
Vt(i), At(s), t.clear(), r = !0;
|
|
147
|
-
};
|
|
148
|
-
if (a === "then") {
|
|
149
|
-
if (e.length === 0)
|
|
150
|
-
return { then: () => i };
|
|
151
|
-
const l = F(s, t, {
|
|
152
|
-
type: "GET",
|
|
153
|
-
path: e.map((h) => h.toString())
|
|
154
|
-
}).then(C);
|
|
155
|
-
return l.then.bind(l);
|
|
156
|
-
}
|
|
157
|
-
return st(s, t, [...e, a]);
|
|
158
|
-
},
|
|
159
|
-
set(o, a, l) {
|
|
160
|
-
H(r);
|
|
161
|
-
const [h, c] = V(l);
|
|
162
|
-
return F(s, t, {
|
|
163
|
-
type: "SET",
|
|
164
|
-
path: [...e, a].map((f) => f.toString()),
|
|
165
|
-
value: h
|
|
166
|
-
}, c).then(C);
|
|
167
|
-
},
|
|
168
|
-
apply(o, a, l) {
|
|
169
|
-
H(r);
|
|
170
|
-
const h = e[e.length - 1];
|
|
171
|
-
if (h === Ht)
|
|
172
|
-
return F(s, t, {
|
|
173
|
-
type: "ENDPOINT"
|
|
174
|
-
}).then(C);
|
|
175
|
-
if (h === "bind")
|
|
176
|
-
return st(s, t, e.slice(0, -1));
|
|
177
|
-
const [c, f] = ht(l);
|
|
178
|
-
return F(s, t, {
|
|
179
|
-
type: "APPLY",
|
|
180
|
-
path: e.map((u) => u.toString()),
|
|
181
|
-
argumentList: c
|
|
182
|
-
}, f).then(C);
|
|
183
|
-
},
|
|
184
|
-
construct(o, a) {
|
|
185
|
-
H(r);
|
|
186
|
-
const [l, h] = ht(a);
|
|
187
|
-
return F(s, t, {
|
|
188
|
-
type: "CONSTRUCT",
|
|
189
|
-
path: e.map((c) => c.toString()),
|
|
190
|
-
argumentList: l
|
|
191
|
-
}, h).then(C);
|
|
192
|
-
}
|
|
193
|
-
});
|
|
194
|
-
return qt(i, s), i;
|
|
195
|
-
}
|
|
196
|
-
function Yt(s) {
|
|
197
|
-
return Array.prototype.concat.apply([], s);
|
|
198
|
-
}
|
|
199
|
-
function ht(s) {
|
|
200
|
-
const t = s.map(V);
|
|
201
|
-
return [t.map((e) => e[0]), Yt(t.map((e) => e[1]))];
|
|
202
|
-
}
|
|
203
|
-
const Nt = /* @__PURE__ */ new WeakMap();
|
|
204
|
-
function U(s, t) {
|
|
205
|
-
return Nt.set(s, t), s;
|
|
206
|
-
}
|
|
207
|
-
function Zt(s) {
|
|
208
|
-
return Object.assign(s, { [bt]: !0 });
|
|
209
|
-
}
|
|
210
|
-
function V(s) {
|
|
211
|
-
for (const [t, e] of Dt)
|
|
212
|
-
if (e.canHandle(s)) {
|
|
213
|
-
const [n, r] = e.serialize(s);
|
|
214
|
-
return [
|
|
215
|
-
{
|
|
216
|
-
type: "HANDLER",
|
|
217
|
-
name: t,
|
|
218
|
-
value: n
|
|
219
|
-
},
|
|
220
|
-
r
|
|
221
|
-
];
|
|
222
|
-
}
|
|
223
|
-
return [
|
|
224
|
-
{
|
|
225
|
-
type: "RAW",
|
|
226
|
-
value: s
|
|
227
|
-
},
|
|
228
|
-
Nt.get(s) || []
|
|
229
|
-
];
|
|
230
|
-
}
|
|
231
|
-
function C(s) {
|
|
232
|
-
switch (s.type) {
|
|
233
|
-
case "HANDLER":
|
|
234
|
-
return Dt.get(s.name).deserialize(s.value);
|
|
235
|
-
case "RAW":
|
|
236
|
-
return s.value;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
function F(s, t, e, n) {
|
|
240
|
-
return new Promise((r) => {
|
|
241
|
-
const i = Xt();
|
|
242
|
-
t.set(i, r), s.start && s.start(), s.postMessage(Object.assign({ id: i }, e), n);
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
function Xt() {
|
|
246
|
-
return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
|
|
247
|
-
}
|
|
248
|
-
var D = /* @__PURE__ */ ((s) => (s.Added = "added", s.Changed = "changed", s.Removed = "removed", s))(D || {});
|
|
249
|
-
const Jt = {
|
|
250
|
-
ENOENT: -2,
|
|
251
|
-
// No such file or directory
|
|
252
|
-
EISDIR: -21,
|
|
253
|
-
// Is a directory
|
|
254
|
-
ENOTDIR: -20,
|
|
255
|
-
// Not a directory
|
|
256
|
-
EACCES: -13,
|
|
257
|
-
// Permission denied
|
|
258
|
-
EEXIST: -17,
|
|
259
|
-
// File exists
|
|
260
|
-
ENOTEMPTY: -39,
|
|
261
|
-
// Directory not empty
|
|
262
|
-
EINVAL: -22,
|
|
263
|
-
// Invalid argument
|
|
264
|
-
EIO: -5,
|
|
265
|
-
// I/O error
|
|
266
|
-
ENOSPC: -28,
|
|
267
|
-
// No space left on device
|
|
268
|
-
EBUSY: -16,
|
|
269
|
-
// Device or resource busy
|
|
270
|
-
EINTR: -4,
|
|
271
|
-
// Interrupted system call
|
|
272
|
-
ENOTSUP: -95,
|
|
273
|
-
// Operation not supported
|
|
274
|
-
ERANGE: -34,
|
|
275
|
-
// Result too large
|
|
276
|
-
EBADF: -9,
|
|
277
|
-
// Bad file descriptor
|
|
278
|
-
EROOT: -1
|
|
279
|
-
// Custom: Cannot remove root directory
|
|
280
|
-
};
|
|
281
|
-
class w extends Error {
|
|
282
|
-
errno;
|
|
283
|
-
syscall;
|
|
284
|
-
path;
|
|
285
|
-
constructor(t, e, n, r, i) {
|
|
286
|
-
super(t, { cause: i }), this.name = e, this.errno = Jt[e] || -1, this.path = n, this.syscall = r;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
class Qt extends w {
|
|
290
|
-
constructor(t) {
|
|
291
|
-
super("OPFS is not supported in this browser", "ENOTSUP", void 0, void 0, t);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
class Kt extends w {
|
|
295
|
-
constructor(t, e, n) {
|
|
296
|
-
super(t, "INVALID_PATH", e, "access", n);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
class R extends w {
|
|
300
|
-
constructor(t, e, n) {
|
|
301
|
-
const r = {
|
|
302
|
-
file: \`File not found: \${e}\`,
|
|
303
|
-
directory: \`Directory not found: \${e}\`,
|
|
304
|
-
source: \`Source does not exist: \${e}\`
|
|
305
|
-
};
|
|
306
|
-
super(r[t], "ENOENT", e, "access", n);
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
class te extends w {
|
|
310
|
-
constructor(t, e, n) {
|
|
311
|
-
super(\`Permission denied for \${e} on: \${t}\`, "EACCES", t, e, n);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
class ee extends w {
|
|
315
|
-
constructor(t, e, n) {
|
|
316
|
-
super(t, "ENOSPC", e, "write", n);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
class se extends w {
|
|
320
|
-
constructor(t, e) {
|
|
321
|
-
super(\`File is busy: \${t}\`, "EBUSY", t, "open", e);
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
class nt extends w {
|
|
325
|
-
constructor(t, e, n) {
|
|
326
|
-
const r = t === "directory" ? \`Is a directory: \${e}\` : \`Not a directory: \${e}\`, i = t === "directory" ? "EISDIR" : "ENOTDIR";
|
|
327
|
-
super(r, i, e, "access", n);
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
class N extends w {
|
|
331
|
-
constructor(t, e, n, r) {
|
|
332
|
-
const i = {
|
|
333
|
-
argument: "EINVAL",
|
|
334
|
-
format: "INVALID_FORMAT",
|
|
335
|
-
descriptor: "EBADF",
|
|
336
|
-
overflow: "ERANGE"
|
|
337
|
-
};
|
|
338
|
-
super(e, i[t], n, "validate", r);
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
class ne extends w {
|
|
342
|
-
constructor(t, e) {
|
|
343
|
-
super(\`Operation aborted: \${t}\`, "EINTR", t, "interrupt", e);
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
class ut extends w {
|
|
347
|
-
constructor(t, e, n) {
|
|
348
|
-
super(t, "EIO", e, "io", n);
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
class Ct extends w {
|
|
352
|
-
constructor(t, e) {
|
|
353
|
-
super(\`Operation not supported: \${t}\`, "ENOTSUP", t, "operation", e);
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
class rt extends w {
|
|
357
|
-
constructor(t, e, n) {
|
|
358
|
-
const r = {
|
|
359
|
-
RM_FAILED: \`Failed to remove entry: \${e}\`,
|
|
360
|
-
ENOTEMPTY: \`Directory not empty: \${e}. Use recursive option to force removal.\`,
|
|
361
|
-
EROOT: "Cannot remove root directory"
|
|
362
|
-
};
|
|
363
|
-
super(r[t] || \`Directory operation failed: \${e}\`, t, e, "unlink", n);
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
class re extends w {
|
|
367
|
-
constructor(t, e) {
|
|
368
|
-
super("Failed to initialize OPFS", "INIT_FAILED", t, "init", e);
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
class J extends w {
|
|
372
|
-
constructor(t, e, n) {
|
|
373
|
-
super(\`Failed to \${t}: \${e}\`, \`\${t.toUpperCase()}_FAILED\`, e, t, n);
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
class Q extends w {
|
|
377
|
-
constructor(t, e) {
|
|
378
|
-
super(\`Destination already exists: \${t}\`, "EEXIST", t, "open", e);
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
function W(s, t, e, n) {
|
|
382
|
-
const r = \`\${s.toUpperCase()}_FAILED\`;
|
|
383
|
-
return new w(\`Failed to \${s} file descriptor: \${t}\`, r, e, s, n);
|
|
384
|
-
}
|
|
385
|
-
function v(s, t) {
|
|
386
|
-
const e = t?.path, n = t?.isDirectory, r = t?.existenceType ?? "file", i = t?.operation;
|
|
387
|
-
switch (s.name) {
|
|
388
|
-
case "InvalidStateError":
|
|
389
|
-
return new se(e || "unknown", s);
|
|
390
|
-
case "QuotaExceededError":
|
|
391
|
-
return new ee(\`No space left on device: \${e || "unknown"}\`, e, s);
|
|
392
|
-
case "NotFoundError":
|
|
393
|
-
return new R(r, e, s);
|
|
394
|
-
case "TypeMismatchError":
|
|
395
|
-
return n !== void 0 ? n ? new nt("directory", e || "unknown", s) : new nt("file", e || "unknown", s) : new N("argument", \`Type mismatch: \${e || "unknown"}\`, e, s);
|
|
396
|
-
case "NotAllowedError":
|
|
397
|
-
case "SecurityError":
|
|
398
|
-
return new te(e, "unknown", s);
|
|
399
|
-
case "InvalidModificationError":
|
|
400
|
-
return i === "remove" ? new rt("ENOTEMPTY", e, s) : new N("argument", \`Invalid modification: \${e || "unknown"}\`, e, s);
|
|
401
|
-
case "AbortError":
|
|
402
|
-
return new ne(e || "unknown", s);
|
|
403
|
-
case "OperationError":
|
|
404
|
-
return new ut(\`Operation failed: \${e || "unknown"}\`, e, s);
|
|
405
|
-
case "TypeError":
|
|
406
|
-
return new Ct(e || "unknown", s);
|
|
407
|
-
default:
|
|
408
|
-
return i === "remove" ? new rt("RM_FAILED", e, s) : new ut(\`I/O error: \${e || "unknown"}\`, e, s);
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
const Ft = (s, t, e) => {
|
|
412
|
-
const n = s instanceof RegExp ? ft(s, e) : s, r = t instanceof RegExp ? ft(t, e) : t, i = n !== null && r != null && ie(n, r, e);
|
|
413
|
-
return i && {
|
|
414
|
-
start: i[0],
|
|
415
|
-
end: i[1],
|
|
416
|
-
pre: e.slice(0, i[0]),
|
|
417
|
-
body: e.slice(i[0] + n.length, i[1]),
|
|
418
|
-
post: e.slice(i[1] + r.length)
|
|
419
|
-
};
|
|
420
|
-
}, ft = (s, t) => {
|
|
421
|
-
const e = t.match(s);
|
|
422
|
-
return e ? e[0] : null;
|
|
423
|
-
}, ie = (s, t, e) => {
|
|
424
|
-
let n, r, i, o, a, l = e.indexOf(s), h = e.indexOf(t, l + 1), c = l;
|
|
425
|
-
if (l >= 0 && h > 0) {
|
|
426
|
-
if (s === t)
|
|
427
|
-
return [l, h];
|
|
428
|
-
for (n = [], i = e.length; c >= 0 && !a; ) {
|
|
429
|
-
if (c === l)
|
|
430
|
-
n.push(c), l = e.indexOf(s, c + 1);
|
|
431
|
-
else if (n.length === 1) {
|
|
432
|
-
const f = n.pop();
|
|
433
|
-
f !== void 0 && (a = [f, h]);
|
|
434
|
-
} else
|
|
435
|
-
r = n.pop(), r !== void 0 && r < i && (i = r, o = h), h = e.indexOf(t, c + 1);
|
|
436
|
-
c = l < h && l >= 0 ? l : h;
|
|
437
|
-
}
|
|
438
|
-
n.length && o !== void 0 && (a = [i, o]);
|
|
439
|
-
}
|
|
440
|
-
return a;
|
|
441
|
-
}, $t = "\\0SLASH" + Math.random() + "\\0", Mt = "\\0OPEN" + Math.random() + "\\0", at = "\\0CLOSE" + Math.random() + "\\0", Tt = "\\0COMMA" + Math.random() + "\\0", Pt = "\\0PERIOD" + Math.random() + "\\0", oe = new RegExp($t, "g"), ae = new RegExp(Mt, "g"), ce = new RegExp(at, "g"), le = new RegExp(Tt, "g"), he = new RegExp(Pt, "g"), ue = /\\\\\\\\/g, fe = /\\\\{/g, de = /\\\\}/g, pe = /\\\\,/g, ge = /\\\\./g;
|
|
442
|
-
function K(s) {
|
|
443
|
-
return isNaN(s) ? s.charCodeAt(0) : parseInt(s, 10);
|
|
444
|
-
}
|
|
445
|
-
function we(s) {
|
|
446
|
-
return s.replace(ue, $t).replace(fe, Mt).replace(de, at).replace(pe, Tt).replace(ge, Pt);
|
|
447
|
-
}
|
|
448
|
-
function me(s) {
|
|
449
|
-
return s.replace(oe, "\\\\").replace(ae, "{").replace(ce, "}").replace(le, ",").replace(he, ".");
|
|
450
|
-
}
|
|
451
|
-
function Rt(s) {
|
|
452
|
-
if (!s)
|
|
453
|
-
return [""];
|
|
454
|
-
const t = [], e = Ft("{", "}", s);
|
|
455
|
-
if (!e)
|
|
456
|
-
return s.split(",");
|
|
457
|
-
const { pre: n, body: r, post: i } = e, o = n.split(",");
|
|
458
|
-
o[o.length - 1] += "{" + r + "}";
|
|
459
|
-
const a = Rt(i);
|
|
460
|
-
return i.length && (o[o.length - 1] += a.shift(), o.push.apply(o, a)), t.push.apply(t, o), t;
|
|
461
|
-
}
|
|
462
|
-
function ye(s) {
|
|
463
|
-
return s ? (s.slice(0, 2) === "{}" && (s = "\\\\{\\\\}" + s.slice(2)), k(we(s), !0).map(me)) : [];
|
|
464
|
-
}
|
|
465
|
-
function Ee(s) {
|
|
466
|
-
return "{" + s + "}";
|
|
467
|
-
}
|
|
468
|
-
function Se(s) {
|
|
469
|
-
return /^-?0\\d/.test(s);
|
|
470
|
-
}
|
|
471
|
-
function xe(s, t) {
|
|
472
|
-
return s <= t;
|
|
473
|
-
}
|
|
474
|
-
function be(s, t) {
|
|
475
|
-
return s >= t;
|
|
476
|
-
}
|
|
477
|
-
function k(s, t) {
|
|
478
|
-
const e = [], n = Ft("{", "}", s);
|
|
479
|
-
if (!n)
|
|
480
|
-
return [s];
|
|
481
|
-
const r = n.pre, i = n.post.length ? k(n.post, !1) : [""];
|
|
482
|
-
if (/\\$$/.test(n.pre))
|
|
483
|
-
for (let o = 0; o < i.length; o++) {
|
|
484
|
-
const a = r + "{" + n.body + "}" + i[o];
|
|
485
|
-
e.push(a);
|
|
486
|
-
}
|
|
487
|
-
else {
|
|
488
|
-
const o = /^-?\\d+\\.\\.-?\\d+(?:\\.\\.-?\\d+)?$/.test(n.body), a = /^[a-zA-Z]\\.\\.[a-zA-Z](?:\\.\\.-?\\d+)?$/.test(n.body), l = o || a, h = n.body.indexOf(",") >= 0;
|
|
489
|
-
if (!l && !h)
|
|
490
|
-
return n.post.match(/,(?!,).*\\}/) ? (s = n.pre + "{" + n.body + at + n.post, k(s)) : [s];
|
|
491
|
-
let c;
|
|
492
|
-
if (l)
|
|
493
|
-
c = n.body.split(/\\.\\./);
|
|
494
|
-
else if (c = Rt(n.body), c.length === 1 && c[0] !== void 0 && (c = k(c[0], !1).map(Ee), c.length === 1))
|
|
495
|
-
return i.map((u) => n.pre + c[0] + u);
|
|
496
|
-
let f;
|
|
497
|
-
if (l && c[0] !== void 0 && c[1] !== void 0) {
|
|
498
|
-
const u = K(c[0]), d = K(c[1]), g = Math.max(c[0].length, c[1].length);
|
|
499
|
-
let p = c.length === 3 && c[2] !== void 0 ? Math.abs(K(c[2])) : 1, S = xe;
|
|
500
|
-
d < u && (p *= -1, S = be);
|
|
501
|
-
const M = c.some(Se);
|
|
502
|
-
f = [];
|
|
503
|
-
for (let x = u; S(x, d); x += p) {
|
|
504
|
-
let m;
|
|
505
|
-
if (a)
|
|
506
|
-
m = String.fromCharCode(x), m === "\\\\" && (m = "");
|
|
507
|
-
else if (m = String(x), M) {
|
|
508
|
-
const T = g - m.length;
|
|
509
|
-
if (T > 0) {
|
|
510
|
-
const z = new Array(T + 1).join("0");
|
|
511
|
-
x < 0 ? m = "-" + z + m.slice(1) : m = z + m;
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
f.push(m);
|
|
515
|
-
}
|
|
516
|
-
} else {
|
|
517
|
-
f = [];
|
|
518
|
-
for (let u = 0; u < c.length; u++)
|
|
519
|
-
f.push.apply(f, k(c[u], !1));
|
|
520
|
-
}
|
|
521
|
-
for (let u = 0; u < f.length; u++)
|
|
522
|
-
for (let d = 0; d < i.length; d++) {
|
|
523
|
-
const g = r + f[u] + i[d];
|
|
524
|
-
(!t || l || g) && e.push(g);
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
return e;
|
|
528
|
-
}
|
|
529
|
-
const Oe = 1024 * 64, Y = (s) => {
|
|
530
|
-
if (typeof s != "string")
|
|
531
|
-
throw new TypeError("invalid pattern");
|
|
532
|
-
if (s.length > Oe)
|
|
533
|
-
throw new TypeError("pattern is too long");
|
|
534
|
-
}, De = {
|
|
535
|
-
"[:alnum:]": ["\\\\p{L}\\\\p{Nl}\\\\p{Nd}", !0],
|
|
536
|
-
"[:alpha:]": ["\\\\p{L}\\\\p{Nl}", !0],
|
|
537
|
-
"[:ascii:]": ["\\\\x00-\\\\x7f", !1],
|
|
538
|
-
"[:blank:]": ["\\\\p{Zs}\\\\t", !0],
|
|
539
|
-
"[:cntrl:]": ["\\\\p{Cc}", !0],
|
|
540
|
-
"[:digit:]": ["\\\\p{Nd}", !0],
|
|
541
|
-
"[:graph:]": ["\\\\p{Z}\\\\p{C}", !0, !0],
|
|
542
|
-
"[:lower:]": ["\\\\p{Ll}", !0],
|
|
543
|
-
"[:print:]": ["\\\\p{C}", !0],
|
|
544
|
-
"[:punct:]": ["\\\\p{P}", !0],
|
|
545
|
-
"[:space:]": ["\\\\p{Z}\\\\t\\\\r\\\\n\\\\v\\\\f", !0],
|
|
546
|
-
"[:upper:]": ["\\\\p{Lu}", !0],
|
|
547
|
-
"[:word:]": ["\\\\p{L}\\\\p{Nl}\\\\p{Nd}\\\\p{Pc}", !0],
|
|
548
|
-
"[:xdigit:]": ["A-Fa-f0-9", !1]
|
|
549
|
-
}, P = (s) => s.replace(/[[\\]\\\\-]/g, "\\\\$&"), ve = (s) => s.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, "\\\\$&"), dt = (s) => s.join(""), Ae = (s, t) => {
|
|
550
|
-
const e = t;
|
|
551
|
-
if (s.charAt(e) !== "[")
|
|
552
|
-
throw new Error("not in a brace expression");
|
|
553
|
-
const n = [], r = [];
|
|
554
|
-
let i = e + 1, o = !1, a = !1, l = !1, h = !1, c = e, f = "";
|
|
555
|
-
t: for (; i < s.length; ) {
|
|
556
|
-
const p = s.charAt(i);
|
|
557
|
-
if ((p === "!" || p === "^") && i === e + 1) {
|
|
558
|
-
h = !0, i++;
|
|
559
|
-
continue;
|
|
560
|
-
}
|
|
561
|
-
if (p === "]" && o && !l) {
|
|
562
|
-
c = i + 1;
|
|
563
|
-
break;
|
|
564
|
-
}
|
|
565
|
-
if (o = !0, p === "\\\\" && !l) {
|
|
566
|
-
l = !0, i++;
|
|
567
|
-
continue;
|
|
568
|
-
}
|
|
569
|
-
if (p === "[" && !l) {
|
|
570
|
-
for (const [S, [A, M, x]] of Object.entries(De))
|
|
571
|
-
if (s.startsWith(S, i)) {
|
|
572
|
-
if (f)
|
|
573
|
-
return ["$.", !1, s.length - e, !0];
|
|
574
|
-
i += S.length, x ? r.push(A) : n.push(A), a = a || M;
|
|
575
|
-
continue t;
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
if (l = !1, f) {
|
|
579
|
-
p > f ? n.push(P(f) + "-" + P(p)) : p === f && n.push(P(p)), f = "", i++;
|
|
580
|
-
continue;
|
|
581
|
-
}
|
|
582
|
-
if (s.startsWith("-]", i + 1)) {
|
|
583
|
-
n.push(P(p + "-")), i += 2;
|
|
584
|
-
continue;
|
|
585
|
-
}
|
|
586
|
-
if (s.startsWith("-", i + 1)) {
|
|
587
|
-
f = p, i += 2;
|
|
588
|
-
continue;
|
|
589
|
-
}
|
|
590
|
-
n.push(P(p)), i++;
|
|
591
|
-
}
|
|
592
|
-
if (c < i)
|
|
593
|
-
return ["", !1, 0, !1];
|
|
594
|
-
if (!n.length && !r.length)
|
|
595
|
-
return ["$.", !1, s.length - e, !0];
|
|
596
|
-
if (r.length === 0 && n.length === 1 && /^\\\\?.$/.test(n[0]) && !h) {
|
|
597
|
-
const p = n[0].length === 2 ? n[0].slice(-1) : n[0];
|
|
598
|
-
return [ve(p), !1, c - e, !1];
|
|
599
|
-
}
|
|
600
|
-
const u = "[" + (h ? "^" : "") + dt(n) + "]", d = "[" + (h ? "" : "^") + dt(r) + "]";
|
|
601
|
-
return [n.length && r.length ? "(" + u + "|" + d + ")" : n.length ? u : d, a, c - e, !0];
|
|
602
|
-
}, I = (s, { windowsPathsNoEscape: t = !1 } = {}) => t ? s.replace(/\\[([^\\/\\\\])\\]/g, "$1") : s.replace(/((?!\\\\).|^)\\[([^\\/\\\\])\\]/g, "$1$2").replace(/\\\\([^\\/])/g, "$1"), Ne = /* @__PURE__ */ new Set(["!", "?", "+", "*", "@"]), pt = (s) => Ne.has(s), Ce = "(?!(?:^|/)\\\\.\\\\.?(?:$|/))", j = "(?!\\\\.)", Fe = /* @__PURE__ */ new Set(["[", "."]), $e = /* @__PURE__ */ new Set(["..", "."]), Me = new Set("().*{}+?[]^$\\\\!"), Te = (s) => s.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, "\\\\$&"), ct = "[^/]", gt = ct + "*?", wt = ct + "+?";
|
|
603
|
-
class E {
|
|
604
|
-
type;
|
|
605
|
-
#s;
|
|
606
|
-
#n;
|
|
607
|
-
#i = !1;
|
|
608
|
-
#t = [];
|
|
609
|
-
#e;
|
|
610
|
-
#o;
|
|
611
|
-
#c;
|
|
612
|
-
#a = !1;
|
|
613
|
-
#r;
|
|
614
|
-
#l;
|
|
615
|
-
// set to true if it's an extglob with no children
|
|
616
|
-
// (which really means one child of '')
|
|
617
|
-
#u = !1;
|
|
618
|
-
constructor(t, e, n = {}) {
|
|
619
|
-
this.type = t, t && (this.#n = !0), this.#e = e, this.#s = this.#e ? this.#e.#s : this, this.#r = this.#s === this ? n : this.#s.#r, this.#c = this.#s === this ? [] : this.#s.#c, t === "!" && !this.#s.#a && this.#c.push(this), this.#o = this.#e ? this.#e.#t.length : 0;
|
|
620
|
-
}
|
|
621
|
-
get hasMagic() {
|
|
622
|
-
if (this.#n !== void 0)
|
|
623
|
-
return this.#n;
|
|
624
|
-
for (const t of this.#t)
|
|
625
|
-
if (typeof t != "string" && (t.type || t.hasMagic))
|
|
626
|
-
return this.#n = !0;
|
|
627
|
-
return this.#n;
|
|
628
|
-
}
|
|
629
|
-
// reconstructs the pattern
|
|
630
|
-
toString() {
|
|
631
|
-
return this.#l !== void 0 ? this.#l : this.type ? this.#l = this.type + "(" + this.#t.map((t) => String(t)).join("|") + ")" : this.#l = this.#t.map((t) => String(t)).join("");
|
|
632
|
-
}
|
|
633
|
-
#d() {
|
|
634
|
-
if (this !== this.#s)
|
|
635
|
-
throw new Error("should only call on root");
|
|
636
|
-
if (this.#a)
|
|
637
|
-
return this;
|
|
638
|
-
this.toString(), this.#a = !0;
|
|
639
|
-
let t;
|
|
640
|
-
for (; t = this.#c.pop(); ) {
|
|
641
|
-
if (t.type !== "!")
|
|
642
|
-
continue;
|
|
643
|
-
let e = t, n = e.#e;
|
|
644
|
-
for (; n; ) {
|
|
645
|
-
for (let r = e.#o + 1; !n.type && r < n.#t.length; r++)
|
|
646
|
-
for (const i of t.#t) {
|
|
647
|
-
if (typeof i == "string")
|
|
648
|
-
throw new Error("string part in extglob AST??");
|
|
649
|
-
i.copyIn(n.#t[r]);
|
|
650
|
-
}
|
|
651
|
-
e = n, n = e.#e;
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
return this;
|
|
655
|
-
}
|
|
656
|
-
push(...t) {
|
|
657
|
-
for (const e of t)
|
|
658
|
-
if (e !== "") {
|
|
659
|
-
if (typeof e != "string" && !(e instanceof E && e.#e === this))
|
|
660
|
-
throw new Error("invalid part: " + e);
|
|
661
|
-
this.#t.push(e);
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
toJSON() {
|
|
665
|
-
const t = this.type === null ? this.#t.slice().map((e) => typeof e == "string" ? e : e.toJSON()) : [this.type, ...this.#t.map((e) => e.toJSON())];
|
|
666
|
-
return this.isStart() && !this.type && t.unshift([]), this.isEnd() && (this === this.#s || this.#s.#a && this.#e?.type === "!") && t.push({}), t;
|
|
667
|
-
}
|
|
668
|
-
isStart() {
|
|
669
|
-
if (this.#s === this)
|
|
670
|
-
return !0;
|
|
671
|
-
if (!this.#e?.isStart())
|
|
672
|
-
return !1;
|
|
673
|
-
if (this.#o === 0)
|
|
674
|
-
return !0;
|
|
675
|
-
const t = this.#e;
|
|
676
|
-
for (let e = 0; e < this.#o; e++) {
|
|
677
|
-
const n = t.#t[e];
|
|
678
|
-
if (!(n instanceof E && n.type === "!"))
|
|
679
|
-
return !1;
|
|
680
|
-
}
|
|
681
|
-
return !0;
|
|
682
|
-
}
|
|
683
|
-
isEnd() {
|
|
684
|
-
if (this.#s === this || this.#e?.type === "!")
|
|
685
|
-
return !0;
|
|
686
|
-
if (!this.#e?.isEnd())
|
|
687
|
-
return !1;
|
|
688
|
-
if (!this.type)
|
|
689
|
-
return this.#e?.isEnd();
|
|
690
|
-
const t = this.#e ? this.#e.#t.length : 0;
|
|
691
|
-
return this.#o === t - 1;
|
|
692
|
-
}
|
|
693
|
-
copyIn(t) {
|
|
694
|
-
typeof t == "string" ? this.push(t) : this.push(t.clone(this));
|
|
695
|
-
}
|
|
696
|
-
clone(t) {
|
|
697
|
-
const e = new E(this.type, t);
|
|
698
|
-
for (const n of this.#t)
|
|
699
|
-
e.copyIn(n);
|
|
700
|
-
return e;
|
|
701
|
-
}
|
|
702
|
-
static #h(t, e, n, r) {
|
|
703
|
-
let i = !1, o = !1, a = -1, l = !1;
|
|
704
|
-
if (e.type === null) {
|
|
705
|
-
let d = n, g = "";
|
|
706
|
-
for (; d < t.length; ) {
|
|
707
|
-
const p = t.charAt(d++);
|
|
708
|
-
if (i || p === "\\\\") {
|
|
709
|
-
i = !i, g += p;
|
|
710
|
-
continue;
|
|
711
|
-
}
|
|
712
|
-
if (o) {
|
|
713
|
-
d === a + 1 ? (p === "^" || p === "!") && (l = !0) : p === "]" && !(d === a + 2 && l) && (o = !1), g += p;
|
|
714
|
-
continue;
|
|
715
|
-
} else if (p === "[") {
|
|
716
|
-
o = !0, a = d, l = !1, g += p;
|
|
717
|
-
continue;
|
|
718
|
-
}
|
|
719
|
-
if (!r.noext && pt(p) && t.charAt(d) === "(") {
|
|
720
|
-
e.push(g), g = "";
|
|
721
|
-
const S = new E(p, e);
|
|
722
|
-
d = E.#h(t, S, d, r), e.push(S);
|
|
723
|
-
continue;
|
|
724
|
-
}
|
|
725
|
-
g += p;
|
|
726
|
-
}
|
|
727
|
-
return e.push(g), d;
|
|
728
|
-
}
|
|
729
|
-
let h = n + 1, c = new E(null, e);
|
|
730
|
-
const f = [];
|
|
731
|
-
let u = "";
|
|
732
|
-
for (; h < t.length; ) {
|
|
733
|
-
const d = t.charAt(h++);
|
|
734
|
-
if (i || d === "\\\\") {
|
|
735
|
-
i = !i, u += d;
|
|
736
|
-
continue;
|
|
737
|
-
}
|
|
738
|
-
if (o) {
|
|
739
|
-
h === a + 1 ? (d === "^" || d === "!") && (l = !0) : d === "]" && !(h === a + 2 && l) && (o = !1), u += d;
|
|
740
|
-
continue;
|
|
741
|
-
} else if (d === "[") {
|
|
742
|
-
o = !0, a = h, l = !1, u += d;
|
|
743
|
-
continue;
|
|
744
|
-
}
|
|
745
|
-
if (pt(d) && t.charAt(h) === "(") {
|
|
746
|
-
c.push(u), u = "";
|
|
747
|
-
const g = new E(d, c);
|
|
748
|
-
c.push(g), h = E.#h(t, g, h, r);
|
|
749
|
-
continue;
|
|
750
|
-
}
|
|
751
|
-
if (d === "|") {
|
|
752
|
-
c.push(u), u = "", f.push(c), c = new E(null, e);
|
|
753
|
-
continue;
|
|
754
|
-
}
|
|
755
|
-
if (d === ")")
|
|
756
|
-
return u === "" && e.#t.length === 0 && (e.#u = !0), c.push(u), u = "", e.push(...f, c), h;
|
|
757
|
-
u += d;
|
|
758
|
-
}
|
|
759
|
-
return e.type = null, e.#n = void 0, e.#t = [t.substring(n - 1)], h;
|
|
760
|
-
}
|
|
761
|
-
static fromGlob(t, e = {}) {
|
|
762
|
-
const n = new E(null, void 0, e);
|
|
763
|
-
return E.#h(t, n, 0, e), n;
|
|
764
|
-
}
|
|
765
|
-
// returns the regular expression if there's magic, or the unescaped
|
|
766
|
-
// string if not.
|
|
767
|
-
toMMPattern() {
|
|
768
|
-
if (this !== this.#s)
|
|
769
|
-
return this.#s.toMMPattern();
|
|
770
|
-
const t = this.toString(), [e, n, r, i] = this.toRegExpSource();
|
|
771
|
-
if (!(r || this.#n || this.#r.nocase && !this.#r.nocaseMagicOnly && t.toUpperCase() !== t.toLowerCase()))
|
|
772
|
-
return n;
|
|
773
|
-
const a = (this.#r.nocase ? "i" : "") + (i ? "u" : "");
|
|
774
|
-
return Object.assign(new RegExp(\`^\${e}$\`, a), {
|
|
775
|
-
_src: e,
|
|
776
|
-
_glob: t
|
|
777
|
-
});
|
|
778
|
-
}
|
|
779
|
-
get options() {
|
|
780
|
-
return this.#r;
|
|
781
|
-
}
|
|
782
|
-
// returns the string match, the regexp source, whether there's magic
|
|
783
|
-
// in the regexp (so a regular expression is required) and whether or
|
|
784
|
-
// not the uflag is needed for the regular expression (for posix classes)
|
|
785
|
-
// TODO: instead of injecting the start/end at this point, just return
|
|
786
|
-
// the BODY of the regexp, along with the start/end portions suitable
|
|
787
|
-
// for binding the start/end in either a joined full-path makeRe context
|
|
788
|
-
// (where we bind to (^|/), or a standalone matchPart context (where
|
|
789
|
-
// we bind to ^, and not /). Otherwise slashes get duped!
|
|
790
|
-
//
|
|
791
|
-
// In part-matching mode, the start is:
|
|
792
|
-
// - if not isStart: nothing
|
|
793
|
-
// - if traversal possible, but not allowed: ^(?!\\.\\.?$)
|
|
794
|
-
// - if dots allowed or not possible: ^
|
|
795
|
-
// - if dots possible and not allowed: ^(?!\\.)
|
|
796
|
-
// end is:
|
|
797
|
-
// - if not isEnd(): nothing
|
|
798
|
-
// - else: $
|
|
799
|
-
//
|
|
800
|
-
// In full-path matching mode, we put the slash at the START of the
|
|
801
|
-
// pattern, so start is:
|
|
802
|
-
// - if first pattern: same as part-matching mode
|
|
803
|
-
// - if not isStart(): nothing
|
|
804
|
-
// - if traversal possible, but not allowed: /(?!\\.\\.?(?:$|/))
|
|
805
|
-
// - if dots allowed or not possible: /
|
|
806
|
-
// - if dots possible and not allowed: /(?!\\.)
|
|
807
|
-
// end is:
|
|
808
|
-
// - if last pattern, same as part-matching mode
|
|
809
|
-
// - else nothing
|
|
810
|
-
//
|
|
811
|
-
// Always put the (?:$|/) on negated tails, though, because that has to be
|
|
812
|
-
// there to bind the end of the negated pattern portion, and it's easier to
|
|
813
|
-
// just stick it in now rather than try to inject it later in the middle of
|
|
814
|
-
// the pattern.
|
|
815
|
-
//
|
|
816
|
-
// We can just always return the same end, and leave it up to the caller
|
|
817
|
-
// to know whether it's going to be used joined or in parts.
|
|
818
|
-
// And, if the start is adjusted slightly, can do the same there:
|
|
819
|
-
// - if not isStart: nothing
|
|
820
|
-
// - if traversal possible, but not allowed: (?:/|^)(?!\\.\\.?$)
|
|
821
|
-
// - if dots allowed or not possible: (?:/|^)
|
|
822
|
-
// - if dots possible and not allowed: (?:/|^)(?!\\.)
|
|
823
|
-
//
|
|
824
|
-
// But it's better to have a simpler binding without a conditional, for
|
|
825
|
-
// performance, so probably better to return both start options.
|
|
826
|
-
//
|
|
827
|
-
// Then the caller just ignores the end if it's not the first pattern,
|
|
828
|
-
// and the start always gets applied.
|
|
829
|
-
//
|
|
830
|
-
// But that's always going to be $ if it's the ending pattern, or nothing,
|
|
831
|
-
// so the caller can just attach $ at the end of the pattern when building.
|
|
832
|
-
//
|
|
833
|
-
// So the todo is:
|
|
834
|
-
// - better detect what kind of start is needed
|
|
835
|
-
// - return both flavors of starting pattern
|
|
836
|
-
// - attach $ at the end of the pattern when creating the actual RegExp
|
|
837
|
-
//
|
|
838
|
-
// Ah, but wait, no, that all only applies to the root when the first pattern
|
|
839
|
-
// is not an extglob. If the first pattern IS an extglob, then we need all
|
|
840
|
-
// that dot prevention biz to live in the extglob portions, because eg
|
|
841
|
-
// +(*|.x*) can match .xy but not .yx.
|
|
842
|
-
//
|
|
843
|
-
// So, return the two flavors if it's #root and the first child is not an
|
|
844
|
-
// AST, otherwise leave it to the child AST to handle it, and there,
|
|
845
|
-
// use the (?:^|/) style of start binding.
|
|
846
|
-
//
|
|
847
|
-
// Even simplified further:
|
|
848
|
-
// - Since the start for a join is eg /(?!\\.) and the start for a part
|
|
849
|
-
// is ^(?!\\.), we can just prepend (?!\\.) to the pattern (either root
|
|
850
|
-
// or start or whatever) and prepend ^ or / at the Regexp construction.
|
|
851
|
-
toRegExpSource(t) {
|
|
852
|
-
const e = t ?? !!this.#r.dot;
|
|
853
|
-
if (this.#s === this && this.#d(), !this.type) {
|
|
854
|
-
const l = this.isStart() && this.isEnd(), h = this.#t.map((d) => {
|
|
855
|
-
const [g, p, S, A] = typeof d == "string" ? E.#p(d, this.#n, l) : d.toRegExpSource(t);
|
|
856
|
-
return this.#n = this.#n || S, this.#i = this.#i || A, g;
|
|
857
|
-
}).join("");
|
|
858
|
-
let c = "";
|
|
859
|
-
if (this.isStart() && typeof this.#t[0] == "string" && !(this.#t.length === 1 && $e.has(this.#t[0]))) {
|
|
860
|
-
const g = Fe, p = (
|
|
861
|
-
// dots are allowed, and the pattern starts with [ or .
|
|
862
|
-
e && g.has(h.charAt(0)) || // the pattern starts with \\., and then [ or .
|
|
863
|
-
h.startsWith("\\\\.") && g.has(h.charAt(2)) || // the pattern starts with \\.\\., and then [ or .
|
|
864
|
-
h.startsWith("\\\\.\\\\.") && g.has(h.charAt(4))
|
|
865
|
-
), S = !e && !t && g.has(h.charAt(0));
|
|
866
|
-
c = p ? Ce : S ? j : "";
|
|
867
|
-
}
|
|
868
|
-
let f = "";
|
|
869
|
-
return this.isEnd() && this.#s.#a && this.#e?.type === "!" && (f = "(?:$|\\\\/)"), [
|
|
870
|
-
c + h + f,
|
|
871
|
-
I(h),
|
|
872
|
-
this.#n = !!this.#n,
|
|
873
|
-
this.#i
|
|
874
|
-
];
|
|
875
|
-
}
|
|
876
|
-
const n = this.type === "*" || this.type === "+", r = this.type === "!" ? "(?:(?!(?:" : "(?:";
|
|
877
|
-
let i = this.#f(e);
|
|
878
|
-
if (this.isStart() && this.isEnd() && !i && this.type !== "!") {
|
|
879
|
-
const l = this.toString();
|
|
880
|
-
return this.#t = [l], this.type = null, this.#n = void 0, [l, I(this.toString()), !1, !1];
|
|
881
|
-
}
|
|
882
|
-
let o = !n || t || e || !j ? "" : this.#f(!0);
|
|
883
|
-
o === i && (o = ""), o && (i = \`(?:\${i})(?:\${o})*?\`);
|
|
884
|
-
let a = "";
|
|
885
|
-
if (this.type === "!" && this.#u)
|
|
886
|
-
a = (this.isStart() && !e ? j : "") + wt;
|
|
887
|
-
else {
|
|
888
|
-
const l = this.type === "!" ? (
|
|
889
|
-
// !() must match something,but !(x) can match ''
|
|
890
|
-
"))" + (this.isStart() && !e && !t ? j : "") + gt + ")"
|
|
891
|
-
) : this.type === "@" ? ")" : this.type === "?" ? ")?" : this.type === "+" && o ? ")" : this.type === "*" && o ? ")?" : \`)\${this.type}\`;
|
|
892
|
-
a = r + i + l;
|
|
893
|
-
}
|
|
894
|
-
return [
|
|
895
|
-
a,
|
|
896
|
-
I(i),
|
|
897
|
-
this.#n = !!this.#n,
|
|
898
|
-
this.#i
|
|
899
|
-
];
|
|
900
|
-
}
|
|
901
|
-
#f(t) {
|
|
902
|
-
return this.#t.map((e) => {
|
|
903
|
-
if (typeof e == "string")
|
|
904
|
-
throw new Error("string type in extglob ast??");
|
|
905
|
-
const [n, r, i, o] = e.toRegExpSource(t);
|
|
906
|
-
return this.#i = this.#i || o, n;
|
|
907
|
-
}).filter((e) => !(this.isStart() && this.isEnd()) || !!e).join("|");
|
|
908
|
-
}
|
|
909
|
-
static #p(t, e, n = !1) {
|
|
910
|
-
let r = !1, i = "", o = !1;
|
|
911
|
-
for (let a = 0; a < t.length; a++) {
|
|
912
|
-
const l = t.charAt(a);
|
|
913
|
-
if (r) {
|
|
914
|
-
r = !1, i += (Me.has(l) ? "\\\\" : "") + l;
|
|
915
|
-
continue;
|
|
916
|
-
}
|
|
917
|
-
if (l === "\\\\") {
|
|
918
|
-
a === t.length - 1 ? i += "\\\\\\\\" : r = !0;
|
|
919
|
-
continue;
|
|
920
|
-
}
|
|
921
|
-
if (l === "[") {
|
|
922
|
-
const [h, c, f, u] = Ae(t, a);
|
|
923
|
-
if (f) {
|
|
924
|
-
i += h, o = o || c, a += f - 1, e = e || u;
|
|
925
|
-
continue;
|
|
926
|
-
}
|
|
927
|
-
}
|
|
928
|
-
if (l === "*") {
|
|
929
|
-
n && t === "*" ? i += wt : i += gt, e = !0;
|
|
930
|
-
continue;
|
|
931
|
-
}
|
|
932
|
-
if (l === "?") {
|
|
933
|
-
i += ct, e = !0;
|
|
934
|
-
continue;
|
|
935
|
-
}
|
|
936
|
-
i += Te(l);
|
|
937
|
-
}
|
|
938
|
-
return [i, I(t), !!e, o];
|
|
939
|
-
}
|
|
940
|
-
}
|
|
941
|
-
const Pe = (s, { windowsPathsNoEscape: t = !1 } = {}) => t ? s.replace(/[?*()[\\]]/g, "[$&]") : s.replace(/[?*()[\\]\\\\]/g, "\\\\$&"), y = (s, t, e = {}) => (Y(t), !e.nocomment && t.charAt(0) === "#" ? !1 : new Z(t, e).match(s)), Re = /^\\*+([^+@!?\\*\\[\\(]*)$/, ke = (s) => (t) => !t.startsWith(".") && t.endsWith(s), Ie = (s) => (t) => t.endsWith(s), Le = (s) => (s = s.toLowerCase(), (t) => !t.startsWith(".") && t.toLowerCase().endsWith(s)), ze = (s) => (s = s.toLowerCase(), (t) => t.toLowerCase().endsWith(s)), He = /^\\*+\\.\\*+$/, We = (s) => !s.startsWith(".") && s.includes("."), je = (s) => s !== "." && s !== ".." && s.includes("."), _e = /^\\.\\*+$/, Ue = (s) => s !== "." && s !== ".." && s.startsWith("."), Be = /^\\*+$/, Ge = (s) => s.length !== 0 && !s.startsWith("."), qe = (s) => s.length !== 0 && s !== "." && s !== "..", Ve = /^\\?+([^+@!?\\*\\[\\(]*)?$/, Ye = ([s, t = ""]) => {
|
|
942
|
-
const e = kt([s]);
|
|
943
|
-
return t ? (t = t.toLowerCase(), (n) => e(n) && n.toLowerCase().endsWith(t)) : e;
|
|
944
|
-
}, Ze = ([s, t = ""]) => {
|
|
945
|
-
const e = It([s]);
|
|
946
|
-
return t ? (t = t.toLowerCase(), (n) => e(n) && n.toLowerCase().endsWith(t)) : e;
|
|
947
|
-
}, Xe = ([s, t = ""]) => {
|
|
948
|
-
const e = It([s]);
|
|
949
|
-
return t ? (n) => e(n) && n.endsWith(t) : e;
|
|
950
|
-
}, Je = ([s, t = ""]) => {
|
|
951
|
-
const e = kt([s]);
|
|
952
|
-
return t ? (n) => e(n) && n.endsWith(t) : e;
|
|
953
|
-
}, kt = ([s]) => {
|
|
954
|
-
const t = s.length;
|
|
955
|
-
return (e) => e.length === t && !e.startsWith(".");
|
|
956
|
-
}, It = ([s]) => {
|
|
957
|
-
const t = s.length;
|
|
958
|
-
return (e) => e.length === t && e !== "." && e !== "..";
|
|
959
|
-
}, Lt = typeof process == "object" && process ? typeof process.env == "object" && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix", mt = {
|
|
960
|
-
win32: { sep: "\\\\" },
|
|
961
|
-
posix: { sep: "/" }
|
|
962
|
-
}, Qe = Lt === "win32" ? mt.win32.sep : mt.posix.sep;
|
|
963
|
-
y.sep = Qe;
|
|
964
|
-
const O = Symbol("globstar **");
|
|
965
|
-
y.GLOBSTAR = O;
|
|
966
|
-
const Ke = "[^/]", ts = Ke + "*?", es = "(?:(?!(?:\\\\/|^)(?:\\\\.{1,2})($|\\\\/)).)*?", ss = "(?:(?!(?:\\\\/|^)\\\\.).)*?", ns = (s, t = {}) => (e) => y(e, s, t);
|
|
967
|
-
y.filter = ns;
|
|
968
|
-
const b = (s, t = {}) => Object.assign({}, s, t), rs = (s) => {
|
|
969
|
-
if (!s || typeof s != "object" || !Object.keys(s).length)
|
|
970
|
-
return y;
|
|
971
|
-
const t = y;
|
|
972
|
-
return Object.assign((n, r, i = {}) => t(n, r, b(s, i)), {
|
|
973
|
-
Minimatch: class extends t.Minimatch {
|
|
974
|
-
constructor(r, i = {}) {
|
|
975
|
-
super(r, b(s, i));
|
|
976
|
-
}
|
|
977
|
-
static defaults(r) {
|
|
978
|
-
return t.defaults(b(s, r)).Minimatch;
|
|
979
|
-
}
|
|
980
|
-
},
|
|
981
|
-
AST: class extends t.AST {
|
|
982
|
-
/* c8 ignore start */
|
|
983
|
-
constructor(r, i, o = {}) {
|
|
984
|
-
super(r, i, b(s, o));
|
|
985
|
-
}
|
|
986
|
-
/* c8 ignore stop */
|
|
987
|
-
static fromGlob(r, i = {}) {
|
|
988
|
-
return t.AST.fromGlob(r, b(s, i));
|
|
989
|
-
}
|
|
990
|
-
},
|
|
991
|
-
unescape: (n, r = {}) => t.unescape(n, b(s, r)),
|
|
992
|
-
escape: (n, r = {}) => t.escape(n, b(s, r)),
|
|
993
|
-
filter: (n, r = {}) => t.filter(n, b(s, r)),
|
|
994
|
-
defaults: (n) => t.defaults(b(s, n)),
|
|
995
|
-
makeRe: (n, r = {}) => t.makeRe(n, b(s, r)),
|
|
996
|
-
braceExpand: (n, r = {}) => t.braceExpand(n, b(s, r)),
|
|
997
|
-
match: (n, r, i = {}) => t.match(n, r, b(s, i)),
|
|
998
|
-
sep: t.sep,
|
|
999
|
-
GLOBSTAR: O
|
|
1000
|
-
});
|
|
1001
|
-
};
|
|
1002
|
-
y.defaults = rs;
|
|
1003
|
-
const zt = (s, t = {}) => (Y(s), t.nobrace || !/\\{(?:(?!\\{).)*\\}/.test(s) ? [s] : ye(s));
|
|
1004
|
-
y.braceExpand = zt;
|
|
1005
|
-
const is = (s, t = {}) => new Z(s, t).makeRe();
|
|
1006
|
-
y.makeRe = is;
|
|
1007
|
-
const os = (s, t, e = {}) => {
|
|
1008
|
-
const n = new Z(t, e);
|
|
1009
|
-
return s = s.filter((r) => n.match(r)), n.options.nonull && !s.length && s.push(t), s;
|
|
1010
|
-
};
|
|
1011
|
-
y.match = os;
|
|
1012
|
-
const yt = /[?*]|[+@!]\\(.*?\\)|\\[|\\]/, as = (s) => s.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, "\\\\$&");
|
|
1013
|
-
class Z {
|
|
1014
|
-
options;
|
|
1015
|
-
set;
|
|
1016
|
-
pattern;
|
|
1017
|
-
windowsPathsNoEscape;
|
|
1018
|
-
nonegate;
|
|
1019
|
-
negate;
|
|
1020
|
-
comment;
|
|
1021
|
-
empty;
|
|
1022
|
-
preserveMultipleSlashes;
|
|
1023
|
-
partial;
|
|
1024
|
-
globSet;
|
|
1025
|
-
globParts;
|
|
1026
|
-
nocase;
|
|
1027
|
-
isWindows;
|
|
1028
|
-
platform;
|
|
1029
|
-
windowsNoMagicRoot;
|
|
1030
|
-
regexp;
|
|
1031
|
-
constructor(t, e = {}) {
|
|
1032
|
-
Y(t), e = e || {}, this.options = e, this.pattern = t, this.platform = e.platform || Lt, this.isWindows = this.platform === "win32", this.windowsPathsNoEscape = !!e.windowsPathsNoEscape || e.allowWindowsEscape === !1, this.windowsPathsNoEscape && (this.pattern = this.pattern.replace(/\\\\/g, "/")), this.preserveMultipleSlashes = !!e.preserveMultipleSlashes, this.regexp = null, this.negate = !1, this.nonegate = !!e.nonegate, this.comment = !1, this.empty = !1, this.partial = !!e.partial, this.nocase = !!this.options.nocase, this.windowsNoMagicRoot = e.windowsNoMagicRoot !== void 0 ? e.windowsNoMagicRoot : !!(this.isWindows && this.nocase), this.globSet = [], this.globParts = [], this.set = [], this.make();
|
|
1033
|
-
}
|
|
1034
|
-
hasMagic() {
|
|
1035
|
-
if (this.options.magicalBraces && this.set.length > 1)
|
|
1036
|
-
return !0;
|
|
1037
|
-
for (const t of this.set)
|
|
1038
|
-
for (const e of t)
|
|
1039
|
-
if (typeof e != "string")
|
|
1040
|
-
return !0;
|
|
1041
|
-
return !1;
|
|
1042
|
-
}
|
|
1043
|
-
debug(...t) {
|
|
1044
|
-
}
|
|
1045
|
-
make() {
|
|
1046
|
-
const t = this.pattern, e = this.options;
|
|
1047
|
-
if (!e.nocomment && t.charAt(0) === "#") {
|
|
1048
|
-
this.comment = !0;
|
|
1049
|
-
return;
|
|
1050
|
-
}
|
|
1051
|
-
if (!t) {
|
|
1052
|
-
this.empty = !0;
|
|
1053
|
-
return;
|
|
1054
|
-
}
|
|
1055
|
-
this.parseNegate(), this.globSet = [...new Set(this.braceExpand())], e.debug && (this.debug = (...i) => console.error(...i)), this.debug(this.pattern, this.globSet);
|
|
1056
|
-
const n = this.globSet.map((i) => this.slashSplit(i));
|
|
1057
|
-
this.globParts = this.preprocess(n), this.debug(this.pattern, this.globParts);
|
|
1058
|
-
let r = this.globParts.map((i, o, a) => {
|
|
1059
|
-
if (this.isWindows && this.windowsNoMagicRoot) {
|
|
1060
|
-
const l = i[0] === "" && i[1] === "" && (i[2] === "?" || !yt.test(i[2])) && !yt.test(i[3]), h = /^[a-z]:/i.test(i[0]);
|
|
1061
|
-
if (l)
|
|
1062
|
-
return [...i.slice(0, 4), ...i.slice(4).map((c) => this.parse(c))];
|
|
1063
|
-
if (h)
|
|
1064
|
-
return [i[0], ...i.slice(1).map((c) => this.parse(c))];
|
|
1065
|
-
}
|
|
1066
|
-
return i.map((l) => this.parse(l));
|
|
1067
|
-
});
|
|
1068
|
-
if (this.debug(this.pattern, r), this.set = r.filter((i) => i.indexOf(!1) === -1), this.isWindows)
|
|
1069
|
-
for (let i = 0; i < this.set.length; i++) {
|
|
1070
|
-
const o = this.set[i];
|
|
1071
|
-
o[0] === "" && o[1] === "" && this.globParts[i][2] === "?" && typeof o[3] == "string" && /^[a-z]:$/i.test(o[3]) && (o[2] = "?");
|
|
1072
|
-
}
|
|
1073
|
-
this.debug(this.pattern, this.set);
|
|
1074
|
-
}
|
|
1075
|
-
// various transforms to equivalent pattern sets that are
|
|
1076
|
-
// faster to process in a filesystem walk. The goal is to
|
|
1077
|
-
// eliminate what we can, and push all ** patterns as far
|
|
1078
|
-
// to the right as possible, even if it increases the number
|
|
1079
|
-
// of patterns that we have to process.
|
|
1080
|
-
preprocess(t) {
|
|
1081
|
-
if (this.options.noglobstar)
|
|
1082
|
-
for (let n = 0; n < t.length; n++)
|
|
1083
|
-
for (let r = 0; r < t[n].length; r++)
|
|
1084
|
-
t[n][r] === "**" && (t[n][r] = "*");
|
|
1085
|
-
const { optimizationLevel: e = 1 } = this.options;
|
|
1086
|
-
return e >= 2 ? (t = this.firstPhasePreProcess(t), t = this.secondPhasePreProcess(t)) : e >= 1 ? t = this.levelOneOptimize(t) : t = this.adjascentGlobstarOptimize(t), t;
|
|
1087
|
-
}
|
|
1088
|
-
// just get rid of adjascent ** portions
|
|
1089
|
-
adjascentGlobstarOptimize(t) {
|
|
1090
|
-
return t.map((e) => {
|
|
1091
|
-
let n = -1;
|
|
1092
|
-
for (; (n = e.indexOf("**", n + 1)) !== -1; ) {
|
|
1093
|
-
let r = n;
|
|
1094
|
-
for (; e[r + 1] === "**"; )
|
|
1095
|
-
r++;
|
|
1096
|
-
r !== n && e.splice(n, r - n);
|
|
1097
|
-
}
|
|
1098
|
-
return e;
|
|
1099
|
-
});
|
|
1100
|
-
}
|
|
1101
|
-
// get rid of adjascent ** and resolve .. portions
|
|
1102
|
-
levelOneOptimize(t) {
|
|
1103
|
-
return t.map((e) => (e = e.reduce((n, r) => {
|
|
1104
|
-
const i = n[n.length - 1];
|
|
1105
|
-
return r === "**" && i === "**" ? n : r === ".." && i && i !== ".." && i !== "." && i !== "**" ? (n.pop(), n) : (n.push(r), n);
|
|
1106
|
-
}, []), e.length === 0 ? [""] : e));
|
|
1107
|
-
}
|
|
1108
|
-
levelTwoFileOptimize(t) {
|
|
1109
|
-
Array.isArray(t) || (t = this.slashSplit(t));
|
|
1110
|
-
let e = !1;
|
|
1111
|
-
do {
|
|
1112
|
-
if (e = !1, !this.preserveMultipleSlashes) {
|
|
1113
|
-
for (let r = 1; r < t.length - 1; r++) {
|
|
1114
|
-
const i = t[r];
|
|
1115
|
-
r === 1 && i === "" && t[0] === "" || (i === "." || i === "") && (e = !0, t.splice(r, 1), r--);
|
|
1116
|
-
}
|
|
1117
|
-
t[0] === "." && t.length === 2 && (t[1] === "." || t[1] === "") && (e = !0, t.pop());
|
|
1118
|
-
}
|
|
1119
|
-
let n = 0;
|
|
1120
|
-
for (; (n = t.indexOf("..", n + 1)) !== -1; ) {
|
|
1121
|
-
const r = t[n - 1];
|
|
1122
|
-
r && r !== "." && r !== ".." && r !== "**" && (e = !0, t.splice(n - 1, 2), n -= 2);
|
|
1123
|
-
}
|
|
1124
|
-
} while (e);
|
|
1125
|
-
return t.length === 0 ? [""] : t;
|
|
1126
|
-
}
|
|
1127
|
-
// First phase: single-pattern processing
|
|
1128
|
-
// <pre> is 1 or more portions
|
|
1129
|
-
// <rest> is 1 or more portions
|
|
1130
|
-
// <p> is any portion other than ., .., '', or **
|
|
1131
|
-
// <e> is . or ''
|
|
1132
|
-
//
|
|
1133
|
-
// **/.. is *brutal* for filesystem walking performance, because
|
|
1134
|
-
// it effectively resets the recursive walk each time it occurs,
|
|
1135
|
-
// and ** cannot be reduced out by a .. pattern part like a regexp
|
|
1136
|
-
// or most strings (other than .., ., and '') can be.
|
|
1137
|
-
//
|
|
1138
|
-
// <pre>/**/../<p>/<p>/<rest> -> {<pre>/../<p>/<p>/<rest>,<pre>/**/<p>/<p>/<rest>}
|
|
1139
|
-
// <pre>/<e>/<rest> -> <pre>/<rest>
|
|
1140
|
-
// <pre>/<p>/../<rest> -> <pre>/<rest>
|
|
1141
|
-
// **/**/<rest> -> **/<rest>
|
|
1142
|
-
//
|
|
1143
|
-
// **/*/<rest> -> */**/<rest> <== not valid because ** doesn't follow
|
|
1144
|
-
// this WOULD be allowed if ** did follow symlinks, or * didn't
|
|
1145
|
-
firstPhasePreProcess(t) {
|
|
1146
|
-
let e = !1;
|
|
1147
|
-
do {
|
|
1148
|
-
e = !1;
|
|
1149
|
-
for (let n of t) {
|
|
1150
|
-
let r = -1;
|
|
1151
|
-
for (; (r = n.indexOf("**", r + 1)) !== -1; ) {
|
|
1152
|
-
let o = r;
|
|
1153
|
-
for (; n[o + 1] === "**"; )
|
|
1154
|
-
o++;
|
|
1155
|
-
o > r && n.splice(r + 1, o - r);
|
|
1156
|
-
let a = n[r + 1];
|
|
1157
|
-
const l = n[r + 2], h = n[r + 3];
|
|
1158
|
-
if (a !== ".." || !l || l === "." || l === ".." || !h || h === "." || h === "..")
|
|
1159
|
-
continue;
|
|
1160
|
-
e = !0, n.splice(r, 1);
|
|
1161
|
-
const c = n.slice(0);
|
|
1162
|
-
c[r] = "**", t.push(c), r--;
|
|
1163
|
-
}
|
|
1164
|
-
if (!this.preserveMultipleSlashes) {
|
|
1165
|
-
for (let o = 1; o < n.length - 1; o++) {
|
|
1166
|
-
const a = n[o];
|
|
1167
|
-
o === 1 && a === "" && n[0] === "" || (a === "." || a === "") && (e = !0, n.splice(o, 1), o--);
|
|
1168
|
-
}
|
|
1169
|
-
n[0] === "." && n.length === 2 && (n[1] === "." || n[1] === "") && (e = !0, n.pop());
|
|
1170
|
-
}
|
|
1171
|
-
let i = 0;
|
|
1172
|
-
for (; (i = n.indexOf("..", i + 1)) !== -1; ) {
|
|
1173
|
-
const o = n[i - 1];
|
|
1174
|
-
if (o && o !== "." && o !== ".." && o !== "**") {
|
|
1175
|
-
e = !0;
|
|
1176
|
-
const l = i === 1 && n[i + 1] === "**" ? ["."] : [];
|
|
1177
|
-
n.splice(i - 1, 2, ...l), n.length === 0 && n.push(""), i -= 2;
|
|
1178
|
-
}
|
|
1179
|
-
}
|
|
1180
|
-
}
|
|
1181
|
-
} while (e);
|
|
1182
|
-
return t;
|
|
1183
|
-
}
|
|
1184
|
-
// second phase: multi-pattern dedupes
|
|
1185
|
-
// {<pre>/*/<rest>,<pre>/<p>/<rest>} -> <pre>/*/<rest>
|
|
1186
|
-
// {<pre>/<rest>,<pre>/<rest>} -> <pre>/<rest>
|
|
1187
|
-
// {<pre>/**/<rest>,<pre>/<rest>} -> <pre>/**/<rest>
|
|
1188
|
-
//
|
|
1189
|
-
// {<pre>/**/<rest>,<pre>/**/<p>/<rest>} -> <pre>/**/<rest>
|
|
1190
|
-
// ^-- not valid because ** doens't follow symlinks
|
|
1191
|
-
secondPhasePreProcess(t) {
|
|
1192
|
-
for (let e = 0; e < t.length - 1; e++)
|
|
1193
|
-
for (let n = e + 1; n < t.length; n++) {
|
|
1194
|
-
const r = this.partsMatch(t[e], t[n], !this.preserveMultipleSlashes);
|
|
1195
|
-
if (r) {
|
|
1196
|
-
t[e] = [], t[n] = r;
|
|
1197
|
-
break;
|
|
1198
|
-
}
|
|
1199
|
-
}
|
|
1200
|
-
return t.filter((e) => e.length);
|
|
1201
|
-
}
|
|
1202
|
-
partsMatch(t, e, n = !1) {
|
|
1203
|
-
let r = 0, i = 0, o = [], a = "";
|
|
1204
|
-
for (; r < t.length && i < e.length; )
|
|
1205
|
-
if (t[r] === e[i])
|
|
1206
|
-
o.push(a === "b" ? e[i] : t[r]), r++, i++;
|
|
1207
|
-
else if (n && t[r] === "**" && e[i] === t[r + 1])
|
|
1208
|
-
o.push(t[r]), r++;
|
|
1209
|
-
else if (n && e[i] === "**" && t[r] === e[i + 1])
|
|
1210
|
-
o.push(e[i]), i++;
|
|
1211
|
-
else if (t[r] === "*" && e[i] && (this.options.dot || !e[i].startsWith(".")) && e[i] !== "**") {
|
|
1212
|
-
if (a === "b")
|
|
1213
|
-
return !1;
|
|
1214
|
-
a = "a", o.push(t[r]), r++, i++;
|
|
1215
|
-
} else if (e[i] === "*" && t[r] && (this.options.dot || !t[r].startsWith(".")) && t[r] !== "**") {
|
|
1216
|
-
if (a === "a")
|
|
1217
|
-
return !1;
|
|
1218
|
-
a = "b", o.push(e[i]), r++, i++;
|
|
1219
|
-
} else
|
|
1220
|
-
return !1;
|
|
1221
|
-
return t.length === e.length && o;
|
|
1222
|
-
}
|
|
1223
|
-
parseNegate() {
|
|
1224
|
-
if (this.nonegate)
|
|
1225
|
-
return;
|
|
1226
|
-
const t = this.pattern;
|
|
1227
|
-
let e = !1, n = 0;
|
|
1228
|
-
for (let r = 0; r < t.length && t.charAt(r) === "!"; r++)
|
|
1229
|
-
e = !e, n++;
|
|
1230
|
-
n && (this.pattern = t.slice(n)), this.negate = e;
|
|
1231
|
-
}
|
|
1232
|
-
// set partial to true to test if, for example,
|
|
1233
|
-
// "/a/b" matches the start of "/*/b/*/d"
|
|
1234
|
-
// Partial means, if you run out of file before you run
|
|
1235
|
-
// out of pattern, then that's fine, as long as all
|
|
1236
|
-
// the parts match.
|
|
1237
|
-
matchOne(t, e, n = !1) {
|
|
1238
|
-
const r = this.options;
|
|
1239
|
-
if (this.isWindows) {
|
|
1240
|
-
const p = typeof t[0] == "string" && /^[a-z]:$/i.test(t[0]), S = !p && t[0] === "" && t[1] === "" && t[2] === "?" && /^[a-z]:$/i.test(t[3]), A = typeof e[0] == "string" && /^[a-z]:$/i.test(e[0]), M = !A && e[0] === "" && e[1] === "" && e[2] === "?" && typeof e[3] == "string" && /^[a-z]:$/i.test(e[3]), x = S ? 3 : p ? 0 : void 0, m = M ? 3 : A ? 0 : void 0;
|
|
1241
|
-
if (typeof x == "number" && typeof m == "number") {
|
|
1242
|
-
const [T, z] = [t[x], e[m]];
|
|
1243
|
-
T.toLowerCase() === z.toLowerCase() && (e[m] = T, m > x ? e = e.slice(m) : x > m && (t = t.slice(x)));
|
|
1244
|
-
}
|
|
1245
|
-
}
|
|
1246
|
-
const { optimizationLevel: i = 1 } = this.options;
|
|
1247
|
-
i >= 2 && (t = this.levelTwoFileOptimize(t)), this.debug("matchOne", this, { file: t, pattern: e }), this.debug("matchOne", t.length, e.length);
|
|
1248
|
-
for (var o = 0, a = 0, l = t.length, h = e.length; o < l && a < h; o++, a++) {
|
|
1249
|
-
this.debug("matchOne loop");
|
|
1250
|
-
var c = e[a], f = t[o];
|
|
1251
|
-
if (this.debug(e, c, f), c === !1)
|
|
1252
|
-
return !1;
|
|
1253
|
-
if (c === O) {
|
|
1254
|
-
this.debug("GLOBSTAR", [e, c, f]);
|
|
1255
|
-
var u = o, d = a + 1;
|
|
1256
|
-
if (d === h) {
|
|
1257
|
-
for (this.debug("** at the end"); o < l; o++)
|
|
1258
|
-
if (t[o] === "." || t[o] === ".." || !r.dot && t[o].charAt(0) === ".")
|
|
1259
|
-
return !1;
|
|
1260
|
-
return !0;
|
|
1261
|
-
}
|
|
1262
|
-
for (; u < l; ) {
|
|
1263
|
-
var g = t[u];
|
|
1264
|
-
if (this.debug(\`
|
|
1265
|
-
globstar while\`, t, u, e, d, g), this.matchOne(t.slice(u), e.slice(d), n))
|
|
1266
|
-
return this.debug("globstar found match!", u, l, g), !0;
|
|
1267
|
-
if (g === "." || g === ".." || !r.dot && g.charAt(0) === ".") {
|
|
1268
|
-
this.debug("dot detected!", t, u, e, d);
|
|
1269
|
-
break;
|
|
1270
|
-
}
|
|
1271
|
-
this.debug("globstar swallow a segment, and continue"), u++;
|
|
1272
|
-
}
|
|
1273
|
-
return !!(n && (this.debug(\`
|
|
1274
|
-
>>> no match, partial?\`, t, u, e, d), u === l));
|
|
1275
|
-
}
|
|
1276
|
-
let p;
|
|
1277
|
-
if (typeof c == "string" ? (p = f === c, this.debug("string match", c, f, p)) : (p = c.test(f), this.debug("pattern match", c, f, p)), !p)
|
|
1278
|
-
return !1;
|
|
1279
|
-
}
|
|
1280
|
-
if (o === l && a === h)
|
|
1281
|
-
return !0;
|
|
1282
|
-
if (o === l)
|
|
1283
|
-
return n;
|
|
1284
|
-
if (a === h)
|
|
1285
|
-
return o === l - 1 && t[o] === "";
|
|
1286
|
-
throw new Error("wtf?");
|
|
1287
|
-
}
|
|
1288
|
-
braceExpand() {
|
|
1289
|
-
return zt(this.pattern, this.options);
|
|
1290
|
-
}
|
|
1291
|
-
parse(t) {
|
|
1292
|
-
Y(t);
|
|
1293
|
-
const e = this.options;
|
|
1294
|
-
if (t === "**")
|
|
1295
|
-
return O;
|
|
1296
|
-
if (t === "")
|
|
1297
|
-
return "";
|
|
1298
|
-
let n, r = null;
|
|
1299
|
-
(n = t.match(Be)) ? r = e.dot ? qe : Ge : (n = t.match(Re)) ? r = (e.nocase ? e.dot ? ze : Le : e.dot ? Ie : ke)(n[1]) : (n = t.match(Ve)) ? r = (e.nocase ? e.dot ? Ze : Ye : e.dot ? Xe : Je)(n) : (n = t.match(He)) ? r = e.dot ? je : We : (n = t.match(_e)) && (r = Ue);
|
|
1300
|
-
const i = E.fromGlob(t, this.options).toMMPattern();
|
|
1301
|
-
return r && typeof i == "object" && Reflect.defineProperty(i, "test", { value: r }), i;
|
|
1302
|
-
}
|
|
1303
|
-
makeRe() {
|
|
1304
|
-
if (this.regexp || this.regexp === !1)
|
|
1305
|
-
return this.regexp;
|
|
1306
|
-
const t = this.set;
|
|
1307
|
-
if (!t.length)
|
|
1308
|
-
return this.regexp = !1, this.regexp;
|
|
1309
|
-
const e = this.options, n = e.noglobstar ? ts : e.dot ? es : ss, r = new Set(e.nocase ? ["i"] : []);
|
|
1310
|
-
let i = t.map((l) => {
|
|
1311
|
-
const h = l.map((c) => {
|
|
1312
|
-
if (c instanceof RegExp)
|
|
1313
|
-
for (const f of c.flags.split(""))
|
|
1314
|
-
r.add(f);
|
|
1315
|
-
return typeof c == "string" ? as(c) : c === O ? O : c._src;
|
|
1316
|
-
});
|
|
1317
|
-
return h.forEach((c, f) => {
|
|
1318
|
-
const u = h[f + 1], d = h[f - 1];
|
|
1319
|
-
c !== O || d === O || (d === void 0 ? u !== void 0 && u !== O ? h[f + 1] = "(?:\\\\/|" + n + "\\\\/)?" + u : h[f] = n : u === void 0 ? h[f - 1] = d + "(?:\\\\/|" + n + ")?" : u !== O && (h[f - 1] = d + "(?:\\\\/|\\\\/" + n + "\\\\/)" + u, h[f + 1] = O));
|
|
1320
|
-
}), h.filter((c) => c !== O).join("/");
|
|
1321
|
-
}).join("|");
|
|
1322
|
-
const [o, a] = t.length > 1 ? ["(?:", ")"] : ["", ""];
|
|
1323
|
-
i = "^" + o + i + a + "$", this.negate && (i = "^(?!" + i + ").+$");
|
|
1324
|
-
try {
|
|
1325
|
-
this.regexp = new RegExp(i, [...r].join(""));
|
|
1326
|
-
} catch {
|
|
1327
|
-
this.regexp = !1;
|
|
1328
|
-
}
|
|
1329
|
-
return this.regexp;
|
|
1330
|
-
}
|
|
1331
|
-
slashSplit(t) {
|
|
1332
|
-
return this.preserveMultipleSlashes ? t.split("/") : this.isWindows && /^\\/\\/[^\\/]+/.test(t) ? ["", ...t.split(/\\/+/)] : t.split(/\\/+/);
|
|
1333
|
-
}
|
|
1334
|
-
match(t, e = this.partial) {
|
|
1335
|
-
if (this.debug("match", t, this.pattern), this.comment)
|
|
1336
|
-
return !1;
|
|
1337
|
-
if (this.empty)
|
|
1338
|
-
return t === "";
|
|
1339
|
-
if (t === "/" && e)
|
|
1340
|
-
return !0;
|
|
1341
|
-
const n = this.options;
|
|
1342
|
-
this.isWindows && (t = t.split("\\\\").join("/"));
|
|
1343
|
-
const r = this.slashSplit(t);
|
|
1344
|
-
this.debug(this.pattern, "split", r);
|
|
1345
|
-
const i = this.set;
|
|
1346
|
-
this.debug(this.pattern, "set", i);
|
|
1347
|
-
let o = r[r.length - 1];
|
|
1348
|
-
if (!o)
|
|
1349
|
-
for (let a = r.length - 2; !o && a >= 0; a--)
|
|
1350
|
-
o = r[a];
|
|
1351
|
-
for (let a = 0; a < i.length; a++) {
|
|
1352
|
-
const l = i[a];
|
|
1353
|
-
let h = r;
|
|
1354
|
-
if (n.matchBase && l.length === 1 && (h = [o]), this.matchOne(h, l, e))
|
|
1355
|
-
return n.flipNegate ? !0 : !this.negate;
|
|
1356
|
-
}
|
|
1357
|
-
return n.flipNegate ? !1 : this.negate;
|
|
1358
|
-
}
|
|
1359
|
-
static defaults(t) {
|
|
1360
|
-
return y.defaults(t).Minimatch;
|
|
1361
|
-
}
|
|
1362
|
-
}
|
|
1363
|
-
y.AST = E;
|
|
1364
|
-
y.Minimatch = Z;
|
|
1365
|
-
y.escape = Pe;
|
|
1366
|
-
y.unescape = I;
|
|
1367
|
-
function cs() {
|
|
1368
|
-
if (!("storage" in navigator) || !("getDirectory" in navigator.storage))
|
|
1369
|
-
throw new Qt();
|
|
1370
|
-
}
|
|
1371
|
-
async function L(s, t, e) {
|
|
1372
|
-
return typeof navigator < "u" && navigator.locks?.request ? navigator.locks.request(\`opfs:\${s.replace(/\\/+/g, "/")}\`, { mode: t }, e) : e();
|
|
1373
|
-
}
|
|
1374
|
-
function $(s) {
|
|
1375
|
-
return Array.isArray(s) ? s : (s.startsWith("~/") ? s.slice(2) : s).split("/").filter(Boolean);
|
|
1376
|
-
}
|
|
1377
|
-
function lt(s) {
|
|
1378
|
-
return typeof s == "string" ? s ?? "/" : \`/\${s.join("/")}\`;
|
|
1379
|
-
}
|
|
1380
|
-
function it(s) {
|
|
1381
|
-
const t = $(s);
|
|
1382
|
-
return t[t.length - 1] || "";
|
|
1383
|
-
}
|
|
1384
|
-
function tt(s) {
|
|
1385
|
-
const t = $(s);
|
|
1386
|
-
return t.pop(), lt(t);
|
|
1387
|
-
}
|
|
1388
|
-
function B(s) {
|
|
1389
|
-
return !s || s === "/" ? "/" : s.startsWith("~/") ? \`/\${s.slice(2)}\` : s.startsWith("/") ? s : \`/\${s}\`;
|
|
1390
|
-
}
|
|
1391
|
-
function ls(s, t = !1) {
|
|
1392
|
-
return s = s.replace(/\\/$/, ""), t && !s.includes("*") ? \`\${s}/**\` : s;
|
|
1393
|
-
}
|
|
1394
|
-
function et(s, t) {
|
|
1395
|
-
return y(s, t, {
|
|
1396
|
-
dot: !0,
|
|
1397
|
-
matchBase: !0
|
|
1398
|
-
});
|
|
1399
|
-
}
|
|
1400
|
-
function Et(s) {
|
|
1401
|
-
const t = B(s), e = $(t), n = [];
|
|
1402
|
-
for (const r of e)
|
|
1403
|
-
if (!(r === "." || r === ""))
|
|
1404
|
-
if (r === "..") {
|
|
1405
|
-
if (n.length === 0)
|
|
1406
|
-
continue;
|
|
1407
|
-
n.pop();
|
|
1408
|
-
} else
|
|
1409
|
-
n.push(r);
|
|
1410
|
-
return lt(n);
|
|
1411
|
-
}
|
|
1412
|
-
async function hs(s, t = "SHA-1", e = 50 * 1024 * 1024) {
|
|
1413
|
-
if (s instanceof File && (s = await s.arrayBuffer()), s.byteLength > e)
|
|
1414
|
-
throw new Error(\`File size \${s.byteLength} bytes exceeds maximum allowed size \${e} bytes\`);
|
|
1415
|
-
const n = new Uint8Array(s), r = await crypto.subtle.digest(t, n);
|
|
1416
|
-
return Array.from(new Uint8Array(r)).map((o) => o.toString(16).padStart(2, "0")).join("");
|
|
1417
|
-
}
|
|
1418
|
-
async function us(s) {
|
|
1419
|
-
const t = await s.arrayBuffer();
|
|
1420
|
-
return new Uint8Array(t);
|
|
1421
|
-
}
|
|
1422
|
-
async function fs(s, t, e = {}) {
|
|
1423
|
-
const n = it(t);
|
|
1424
|
-
return L(t, "exclusive", async () => {
|
|
1425
|
-
const r = e.recursive ?? !1, i = e.force ?? !1;
|
|
1426
|
-
try {
|
|
1427
|
-
await s.removeEntry(n, { recursive: r });
|
|
1428
|
-
} catch (o) {
|
|
1429
|
-
if (o.name === "NotFoundError" && i)
|
|
1430
|
-
return;
|
|
1431
|
-
const a = o.name === "TypeMismatchError" && !r;
|
|
1432
|
-
throw v(o, {
|
|
1433
|
-
path: t,
|
|
1434
|
-
operation: "remove",
|
|
1435
|
-
isDirectory: a
|
|
1436
|
-
});
|
|
1437
|
-
}
|
|
1438
|
-
});
|
|
1439
|
-
}
|
|
1440
|
-
function St(s, t, e, n) {
|
|
1441
|
-
if (!Number.isInteger(t) || !Number.isInteger(e))
|
|
1442
|
-
throw new N("argument", "Invalid offset or length");
|
|
1443
|
-
if (t < 0 || e < 0)
|
|
1444
|
-
throw new N("argument", "Negative offset or length not allowed");
|
|
1445
|
-
if (t + e > s)
|
|
1446
|
-
throw new N("overflow", "Operation would overflow buffer");
|
|
1447
|
-
if (n != null && (!Number.isInteger(n) || n < 0))
|
|
1448
|
-
throw new N("argument", "Invalid position");
|
|
1449
|
-
}
|
|
1450
|
-
function xt(s, t, e) {
|
|
1451
|
-
try {
|
|
1452
|
-
t.flush(), t.close();
|
|
1453
|
-
} catch (n) {
|
|
1454
|
-
console.warn(\`Warning: Failed to properly close file descriptor \${s} (\${e}):\`, n);
|
|
1455
|
-
}
|
|
1456
|
-
}
|
|
1457
|
-
function ds(s, t, e) {
|
|
1458
|
-
if (s >= e)
|
|
1459
|
-
return { isEOF: !0, actualLength: 0 };
|
|
1460
|
-
const n = Math.min(t, e - s);
|
|
1461
|
-
return n <= 0 ? { isEOF: !0, actualLength: 0 } : { isEOF: !1, actualLength: n };
|
|
1462
|
-
}
|
|
1463
|
-
async function ps(s, t) {
|
|
1464
|
-
try {
|
|
1465
|
-
return await s.createSyncAccessHandle();
|
|
1466
|
-
} catch (e) {
|
|
1467
|
-
throw v(e, { path: t, isDirectory: !1 });
|
|
1468
|
-
}
|
|
1469
|
-
}
|
|
1470
|
-
class gs {
|
|
1471
|
-
/** Root directory handle for the file system */
|
|
1472
|
-
root;
|
|
1473
|
-
/** Map of watched paths and options */
|
|
1474
|
-
watchers = /* @__PURE__ */ new Map();
|
|
1475
|
-
/** Promise to prevent concurrent mount operations */
|
|
1476
|
-
mountingPromise = null;
|
|
1477
|
-
/** BroadcastChannel instance for sending events */
|
|
1478
|
-
broadcastChannel = null;
|
|
1479
|
-
/** Configuration options */
|
|
1480
|
-
options = {
|
|
1481
|
-
root: "/",
|
|
1482
|
-
namespace: "",
|
|
1483
|
-
maxFileSize: 50 * 1024 * 1024,
|
|
1484
|
-
hashAlgorithm: "etag",
|
|
1485
|
-
broadcastChannel: "opfs-worker"
|
|
1486
|
-
};
|
|
1487
|
-
/** Map of open file descriptors to their metadata */
|
|
1488
|
-
openFiles = /* @__PURE__ */ new Map();
|
|
1489
|
-
/** Next available file descriptor number */
|
|
1490
|
-
nextFd = 1;
|
|
1491
|
-
/**
|
|
1492
|
-
* Get file info by descriptor with validation
|
|
1493
|
-
* @private
|
|
1494
|
-
*/
|
|
1495
|
-
_getFileDescriptor(t) {
|
|
1496
|
-
const e = this.openFiles.get(t);
|
|
1497
|
-
if (!e)
|
|
1498
|
-
throw new N("descriptor", \`Invalid file descriptor: \${t}\`);
|
|
1499
|
-
return e;
|
|
1500
|
-
}
|
|
1501
|
-
/**
|
|
1502
|
-
* Notify about internal changes to the file system
|
|
1503
|
-
*
|
|
1504
|
-
* This method is called by internal operations to notify clients about
|
|
1505
|
-
* changes, even when no specific paths are being watched.
|
|
1506
|
-
*
|
|
1507
|
-
* @param event - The event describing the change
|
|
1508
|
-
*/
|
|
1509
|
-
async notifyChange(t) {
|
|
1510
|
-
if (!this.options.broadcastChannel)
|
|
1511
|
-
return;
|
|
1512
|
-
const e = t.path;
|
|
1513
|
-
if (![...this.watchers.values()].some((i) => et(e, i.pattern) && i.include.some((o) => o && et(e, o)) && !i.exclude.some((o) => o && et(e, o))))
|
|
1514
|
-
return;
|
|
1515
|
-
let r;
|
|
1516
|
-
if (this.options.hashAlgorithm)
|
|
1517
|
-
try {
|
|
1518
|
-
r = (await this.stat(e)).hash;
|
|
1519
|
-
} catch {
|
|
1520
|
-
}
|
|
1521
|
-
try {
|
|
1522
|
-
this.broadcastChannel || (this.broadcastChannel = new BroadcastChannel(this.options.broadcastChannel));
|
|
1523
|
-
const i = {
|
|
1524
|
-
namespace: this.options.namespace,
|
|
1525
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1526
|
-
...t,
|
|
1527
|
-
...r && { hash: r }
|
|
1528
|
-
};
|
|
1529
|
-
this.broadcastChannel.postMessage(i);
|
|
1530
|
-
} catch (i) {
|
|
1531
|
-
console.warn("Failed to send event via BroadcastChannel:", i);
|
|
1532
|
-
}
|
|
1533
|
-
}
|
|
1534
|
-
/**
|
|
1535
|
-
* Creates a new OPFSFileSystem instance
|
|
1536
|
-
*
|
|
1537
|
-
* @param options - Optional configuration options
|
|
1538
|
-
* @param options.root - Root path for the file system (default: '/')
|
|
1539
|
-
* @param options.watchInterval - Polling interval in milliseconds for file watching
|
|
1540
|
-
* @param options.hashAlgorithm - Hash algorithm for file hashing
|
|
1541
|
-
* @param options.maxFileSize - Maximum file size for hashing in bytes (default: 50MB)
|
|
1542
|
-
* @throws {OPFSError} If OPFS is not supported in the current browser
|
|
1543
|
-
*/
|
|
1544
|
-
constructor(t) {
|
|
1545
|
-
cs(), t && this.setOptions(t);
|
|
1546
|
-
}
|
|
1547
|
-
/**
|
|
1548
|
-
* Initialize the file system within a given directory
|
|
1549
|
-
*
|
|
1550
|
-
* This method sets up the root directory for all subsequent operations.
|
|
1551
|
-
* If no root is specified, it will use the OPFS root directory.
|
|
1552
|
-
*
|
|
1553
|
-
* @returns Promise that resolves to true if initialization was successful
|
|
1554
|
-
* @throws {OPFSError} If initialization fails
|
|
1555
|
-
*
|
|
1556
|
-
* @example
|
|
1557
|
-
* \`\`\`typescript
|
|
1558
|
-
* const fs = new OPFSFileSystem();
|
|
1559
|
-
*
|
|
1560
|
-
* // Use OPFS root (default)
|
|
1561
|
-
* await fs.mount();
|
|
1562
|
-
*
|
|
1563
|
-
* // Use custom directory
|
|
1564
|
-
* await fs.mount('/my-app');
|
|
1565
|
-
* \`\`\`
|
|
1566
|
-
*/
|
|
1567
|
-
async mount() {
|
|
1568
|
-
const t = this.options.root;
|
|
1569
|
-
return this.mountingPromise && await this.mountingPromise, this.mountingPromise = new Promise(async (e, n) => {
|
|
1570
|
-
try {
|
|
1571
|
-
const r = await navigator.storage.getDirectory();
|
|
1572
|
-
this.root = t === "/" ? r : await this.getDirectoryHandle(t, !0, r), e(!0);
|
|
1573
|
-
} catch (r) {
|
|
1574
|
-
n(new re(t, r));
|
|
1575
|
-
} finally {
|
|
1576
|
-
this.mountingPromise = null;
|
|
1577
|
-
}
|
|
1578
|
-
}), this.mountingPromise;
|
|
1579
|
-
}
|
|
1580
|
-
/**
|
|
1581
|
-
* Update configuration options
|
|
1582
|
-
*
|
|
1583
|
-
* @param options - Configuration options to update
|
|
1584
|
-
* @param options.root - Root path for the file system
|
|
1585
|
-
* @param options.watchInterval - Polling interval in milliseconds for file watching
|
|
1586
|
-
* @param options.hashAlgorithm - Hash algorithm for file hashing
|
|
1587
|
-
* @param options.maxFileSize - Maximum file size for hashing in bytes
|
|
1588
|
-
* @param options.broadcastChannel - Custom name for the broadcast channel
|
|
1589
|
-
*/
|
|
1590
|
-
async setOptions(t) {
|
|
1591
|
-
t.hashAlgorithm !== void 0 && (this.options.hashAlgorithm = t.hashAlgorithm), t.maxFileSize !== void 0 && (this.options.maxFileSize = t.maxFileSize), t.broadcastChannel !== void 0 && (this.broadcastChannel && this.options.broadcastChannel !== t.broadcastChannel && (this.broadcastChannel.close(), this.broadcastChannel = null), this.options.broadcastChannel = t.broadcastChannel), t.namespace && (this.options.namespace = t.namespace), t.root !== void 0 && (this.options.root = B(t.root), this.options.namespace || (this.options.namespace = \`opfs-worker:\${this.options.root}\`), await this.mount());
|
|
1592
|
-
}
|
|
1593
|
-
/**
|
|
1594
|
-
* Get a directory handle from a path
|
|
1595
|
-
*
|
|
1596
|
-
* Navigates through the directory structure to find or create a directory
|
|
1597
|
-
* at the specified path.
|
|
1598
|
-
*
|
|
1599
|
-
* @param path - The path to the directory (string or array of segments)
|
|
1600
|
-
* @param create - Whether to create the directory if it doesn't exist (default: false)
|
|
1601
|
-
* @param from - The directory to start from (default: root directory)
|
|
1602
|
-
* @returns Promise that resolves to the directory handle
|
|
1603
|
-
* @throws {OPFSError} If the directory cannot be accessed or created
|
|
1604
|
-
*
|
|
1605
|
-
* @example
|
|
1606
|
-
* \`\`\`typescript
|
|
1607
|
-
* const docsDir = await fs.getDirectoryHandle('/users/john/documents', true);
|
|
1608
|
-
* const docsDir2 = await fs.getDirectoryHandle(['users', 'john', 'documents'], true);
|
|
1609
|
-
* \`\`\`
|
|
1610
|
-
*/
|
|
1611
|
-
async getDirectoryHandle(t, e = !1, n = this.root) {
|
|
1612
|
-
const r = Array.isArray(t) ? t : $(t);
|
|
1613
|
-
let i = n;
|
|
1614
|
-
for (const o of r)
|
|
1615
|
-
i = await i.getDirectoryHandle(o, { create: e });
|
|
1616
|
-
return i;
|
|
1617
|
-
}
|
|
1618
|
-
/**
|
|
1619
|
-
* Get a file handle from a path
|
|
1620
|
-
*
|
|
1621
|
-
* Navigates to the parent directory and retrieves or creates a file handle
|
|
1622
|
-
* for the specified file path.
|
|
1623
|
-
*
|
|
1624
|
-
* @param path - The path to the file (string or array of segments)
|
|
1625
|
-
* @param create - Whether to create the file if it doesn't exist (default: false)
|
|
1626
|
-
* @param _from - The directory to start from (default: root directory)
|
|
1627
|
-
* @returns Promise that resolves to the file handle
|
|
1628
|
-
* @throws {PathError} If the path is empty
|
|
1629
|
-
* @throws {OPFSError} If the file cannot be accessed or created
|
|
1630
|
-
*
|
|
1631
|
-
* @example
|
|
1632
|
-
* \`\`\`typescript
|
|
1633
|
-
* const fileHandle = await fs.getFileHandle('/config/settings.json', true);
|
|
1634
|
-
* const fileHandle2 = await fs.getFileHandle(['config', 'settings.json'], true);
|
|
1635
|
-
* \`\`\`
|
|
1636
|
-
*/
|
|
1637
|
-
async getFileHandle(t, e = !1, n = this.root) {
|
|
1638
|
-
const r = $(t);
|
|
1639
|
-
if (r.length === 0)
|
|
1640
|
-
throw new Kt("Path must not be empty", Array.isArray(t) ? t.join("/") : t);
|
|
1641
|
-
const i = r.pop();
|
|
1642
|
-
return (await this.getDirectoryHandle(r, e, n)).getFileHandle(i, { create: e });
|
|
1643
|
-
}
|
|
1644
|
-
/**
|
|
1645
|
-
* Get a complete index of all files and directories in the file system
|
|
1646
|
-
*
|
|
1647
|
-
* This method recursively traverses the entire file system and returns
|
|
1648
|
-
* a Map containing FileStat objects for every file and directory.
|
|
1649
|
-
*
|
|
1650
|
-
* @returns Promise that resolves to a Map of paths to FileStat objects
|
|
1651
|
-
* @throws {OPFSError} If the file system is not mounted
|
|
1652
|
-
*
|
|
1653
|
-
* @example
|
|
1654
|
-
* \`\`\`typescript
|
|
1655
|
-
* const index = await fs.index();
|
|
1656
|
-
* const fileStats = index.get('/data/config.json');
|
|
1657
|
-
* if (fileStats) {
|
|
1658
|
-
* console.log(\`File size: \${fileStats.size} bytes\`);
|
|
1659
|
-
* if (fileStats.hash) console.log(\`Hash: \${fileStats.hash}\`);
|
|
1660
|
-
* }
|
|
1661
|
-
* \`\`\`
|
|
1662
|
-
*/
|
|
1663
|
-
async index() {
|
|
1664
|
-
const t = /* @__PURE__ */ new Map(), e = async (n) => {
|
|
1665
|
-
const r = await this.readDir(n);
|
|
1666
|
-
for (const i of r) {
|
|
1667
|
-
const o = \`\${n === "/" ? "" : n}/\${i.name}\`;
|
|
1668
|
-
try {
|
|
1669
|
-
const a = await this.stat(o);
|
|
1670
|
-
t.set(o, a), a.isDirectory && await e(o);
|
|
1671
|
-
} catch (a) {
|
|
1672
|
-
console.warn(\`Skipping broken entry: \${o}\`, a);
|
|
1673
|
-
}
|
|
1674
|
-
}
|
|
1675
|
-
};
|
|
1676
|
-
return t.set("/", {
|
|
1677
|
-
kind: "directory",
|
|
1678
|
-
size: 0,
|
|
1679
|
-
mtime: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
1680
|
-
ctime: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
1681
|
-
isFile: !1,
|
|
1682
|
-
isDirectory: !0
|
|
1683
|
-
}), await e("/"), t;
|
|
1684
|
-
}
|
|
1685
|
-
/**
|
|
1686
|
-
* Read a file from the file system
|
|
1687
|
-
*
|
|
1688
|
-
* Reads the contents of a file and returns it as binary data.
|
|
1689
|
-
*
|
|
1690
|
-
* @param path - The path to the file to read
|
|
1691
|
-
* @returns Promise that resolves to the file contents as Uint8Array
|
|
1692
|
-
* @throws {FileNotFoundError} If the file does not exist
|
|
1693
|
-
* @throws {OPFSError} If reading the file fails
|
|
1694
|
-
*
|
|
1695
|
-
* @example
|
|
1696
|
-
* \`\`\`typescript
|
|
1697
|
-
* // Read as binary data
|
|
1698
|
-
* const content = await fs.readFile('/config/settings.json');
|
|
1699
|
-
*
|
|
1700
|
-
* // Read binary file
|
|
1701
|
-
* const binaryData = await fs.readFile('/images/logo.png');
|
|
1702
|
-
* \`\`\`
|
|
1703
|
-
*/
|
|
1704
|
-
async readFile(t) {
|
|
1705
|
-
await this.mount();
|
|
1706
|
-
try {
|
|
1707
|
-
return await L(t, "shared", async () => {
|
|
1708
|
-
const e = await this.open(t);
|
|
1709
|
-
try {
|
|
1710
|
-
const { size: n } = await this.fstat(e), r = new Uint8Array(n);
|
|
1711
|
-
return n > 0 && await this.read(e, r, 0, n, 0), U(r, [r.buffer]);
|
|
1712
|
-
} finally {
|
|
1713
|
-
await this.close(e);
|
|
1714
|
-
}
|
|
1715
|
-
});
|
|
1716
|
-
} catch (e) {
|
|
1717
|
-
throw new R("file", t, e);
|
|
1718
|
-
}
|
|
1719
|
-
}
|
|
1720
|
-
/**
|
|
1721
|
-
* Write data to a file
|
|
1722
|
-
*
|
|
1723
|
-
* Creates or overwrites a file with the specified binary data. If the file already
|
|
1724
|
-
* exists, it will be truncated before writing.
|
|
1725
|
-
*
|
|
1726
|
-
* @param path - The path to the file to write
|
|
1727
|
-
* @param data - The binary data to write to the file (Uint8Array or ArrayBuffer)
|
|
1728
|
-
* @returns Promise that resolves when the write operation is complete
|
|
1729
|
-
* @throws {OPFSError} If writing the file fails
|
|
1730
|
-
*
|
|
1731
|
-
* @example
|
|
1732
|
-
* \`\`\`typescript
|
|
1733
|
-
* // Write binary data
|
|
1734
|
-
* const binaryData = new Uint8Array([1, 2, 3, 4, 5]);
|
|
1735
|
-
* await fs.writeFile('/data/binary.dat', binaryData);
|
|
1736
|
-
*
|
|
1737
|
-
* // Write from ArrayBuffer
|
|
1738
|
-
* const arrayBuffer = new ArrayBuffer(10);
|
|
1739
|
-
* await fs.writeFile('/data/buffer.dat', arrayBuffer);
|
|
1740
|
-
* \`\`\`
|
|
1741
|
-
*/
|
|
1742
|
-
async writeFile(t, e) {
|
|
1743
|
-
await this.mount();
|
|
1744
|
-
const n = e instanceof Uint8Array ? e : new Uint8Array(e);
|
|
1745
|
-
await L(t, "exclusive", async () => {
|
|
1746
|
-
const r = await this.exists(t), i = await this.open(t, { create: !0, truncate: !0 });
|
|
1747
|
-
try {
|
|
1748
|
-
await this.write(i, n, 0, n.length, null, !1), await this.fsync(i);
|
|
1749
|
-
} finally {
|
|
1750
|
-
await this.close(i);
|
|
1751
|
-
}
|
|
1752
|
-
await this.notifyChange({ path: t, type: r ? D.Changed : D.Added, isDirectory: !1 });
|
|
1753
|
-
});
|
|
1754
|
-
}
|
|
1755
|
-
/**
|
|
1756
|
-
* Append data to a file
|
|
1757
|
-
*
|
|
1758
|
-
* Adds binary data to the end of an existing file. If the file doesn't exist,
|
|
1759
|
-
* it will be created.
|
|
1760
|
-
*
|
|
1761
|
-
* @param path - The path to the file to append to
|
|
1762
|
-
* @param data - The binary data to append to the file (Uint8Array or ArrayBuffer)
|
|
1763
|
-
* @returns Promise that resolves when the append operation is complete
|
|
1764
|
-
* @throws {OPFSError} If appending to the file fails
|
|
1765
|
-
*
|
|
1766
|
-
* @example
|
|
1767
|
-
* \`\`\`typescript
|
|
1768
|
-
* // Append binary data
|
|
1769
|
-
* const additionalData = new Uint8Array([6, 7, 8]);
|
|
1770
|
-
* await fs.appendFile('/data/binary.dat', additionalData);
|
|
1771
|
-
*
|
|
1772
|
-
* // Append from ArrayBuffer
|
|
1773
|
-
* const arrayBuffer = new ArrayBuffer(5);
|
|
1774
|
-
* await fs.appendFile('/data/buffer.dat', arrayBuffer);
|
|
1775
|
-
* \`\`\`
|
|
1776
|
-
*/
|
|
1777
|
-
async appendFile(t, e) {
|
|
1778
|
-
await this.mount();
|
|
1779
|
-
const n = e instanceof Uint8Array ? e : new Uint8Array(e);
|
|
1780
|
-
await L(t, "exclusive", async () => {
|
|
1781
|
-
const r = await this.open(t, { create: !0 });
|
|
1782
|
-
try {
|
|
1783
|
-
const { size: i } = await this.fstat(r);
|
|
1784
|
-
await this.write(r, n, 0, n.length, i, !1), await this.fsync(r);
|
|
1785
|
-
} finally {
|
|
1786
|
-
await this.close(r);
|
|
1787
|
-
}
|
|
1788
|
-
await this.notifyChange({ path: t, type: D.Changed, isDirectory: !1 });
|
|
1789
|
-
});
|
|
1790
|
-
}
|
|
1791
|
-
/**
|
|
1792
|
-
* Create a directory
|
|
1793
|
-
*
|
|
1794
|
-
* Creates a new directory at the specified path. If the recursive option
|
|
1795
|
-
* is enabled, parent directories will be created as needed.
|
|
1796
|
-
*
|
|
1797
|
-
* @param path - The path where the directory should be created
|
|
1798
|
-
* @param options - Options for directory creation
|
|
1799
|
-
* @param options.recursive - Whether to create parent directories if they don't exist (default: false)
|
|
1800
|
-
* @returns Promise that resolves when the directory is created
|
|
1801
|
-
* @throws {OPFSError} If the directory cannot be created
|
|
1802
|
-
*
|
|
1803
|
-
* @example
|
|
1804
|
-
* \`\`\`typescript
|
|
1805
|
-
* // Create a single directory
|
|
1806
|
-
* await fs.mkdir('/users/john');
|
|
1807
|
-
*
|
|
1808
|
-
* // Create nested directories
|
|
1809
|
-
* await fs.mkdir('/users/john/documents/projects', { recursive: true });
|
|
1810
|
-
* \`\`\`
|
|
1811
|
-
*/
|
|
1812
|
-
async mkdir(t, e) {
|
|
1813
|
-
await this.mount();
|
|
1814
|
-
const n = e?.recursive ?? !1, r = $(t);
|
|
1815
|
-
let i = this.root;
|
|
1816
|
-
for (let o = 0; o < r.length; o++) {
|
|
1817
|
-
const a = r[o];
|
|
1818
|
-
try {
|
|
1819
|
-
i = await i.getDirectoryHandle(a, { create: n || o === r.length - 1 });
|
|
1820
|
-
} catch (l) {
|
|
1821
|
-
throw l.name === "NotFoundError" ? v(l, {
|
|
1822
|
-
path: lt(r.slice(0, o + 1)),
|
|
1823
|
-
existenceType: "directory"
|
|
1824
|
-
}) : l.name === "TypeMismatchError" ? v(l, { path: a, isDirectory: !1 }) : new J("create directory", a, l);
|
|
1825
|
-
}
|
|
1826
|
-
}
|
|
1827
|
-
await this.notifyChange({ path: t, type: D.Added, isDirectory: !0 });
|
|
1828
|
-
}
|
|
1829
|
-
/**
|
|
1830
|
-
* Get file or directory statistics
|
|
1831
|
-
*
|
|
1832
|
-
* Returns detailed information about a file or directory, including
|
|
1833
|
-
* size, modification time, and optionally a hash of the file content.
|
|
1834
|
-
*
|
|
1835
|
-
* @param path - The path to the file or directory
|
|
1836
|
-
* @returns Promise that resolves to FileStat object
|
|
1837
|
-
* @throws {OPFSError} If the path does not exist or cannot be accessed
|
|
1838
|
-
*
|
|
1839
|
-
* @example
|
|
1840
|
-
* \`\`\`typescript
|
|
1841
|
-
* const stats = await fs.stat('/data/config.json');
|
|
1842
|
-
* console.log(\`File size: \${stats.size} bytes\`);
|
|
1843
|
-
* console.log(\`Last modified: \${stats.mtime}\`);
|
|
1844
|
-
*
|
|
1845
|
-
* // If hashing is enabled, hash will be included
|
|
1846
|
-
* if (stats.hash) {
|
|
1847
|
-
* console.log(\`Hash: \${stats.hash}\`);
|
|
1848
|
-
* }
|
|
1849
|
-
* \`\`\`
|
|
1850
|
-
*/
|
|
1851
|
-
async stat(t) {
|
|
1852
|
-
if (await this.mount(), t === "/")
|
|
1853
|
-
return {
|
|
1854
|
-
kind: "directory",
|
|
1855
|
-
size: 0,
|
|
1856
|
-
mtime: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
1857
|
-
ctime: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
1858
|
-
isFile: !1,
|
|
1859
|
-
isDirectory: !0
|
|
1860
|
-
};
|
|
1861
|
-
const e = it(t);
|
|
1862
|
-
let n;
|
|
1863
|
-
try {
|
|
1864
|
-
n = await this.getDirectoryHandle(tt(t), !1);
|
|
1865
|
-
const r = this.options.hashAlgorithm, o = await (await n.getFileHandle(e, { create: !1 })).getFile(), a = {
|
|
1866
|
-
kind: "file",
|
|
1867
|
-
size: o.size,
|
|
1868
|
-
mtime: new Date(o.lastModified).toISOString(),
|
|
1869
|
-
ctime: new Date(o.lastModified).toISOString(),
|
|
1870
|
-
isFile: !0,
|
|
1871
|
-
isDirectory: !1
|
|
1872
|
-
};
|
|
1873
|
-
if (r === "etag")
|
|
1874
|
-
a.hash = \`\${o.lastModified.toString(36)}-\${o.size.toString(36)}\`;
|
|
1875
|
-
else if (typeof r == "string")
|
|
1876
|
-
try {
|
|
1877
|
-
const l = await hs(o, r, this.options.maxFileSize);
|
|
1878
|
-
a.hash = l;
|
|
1879
|
-
} catch (l) {
|
|
1880
|
-
console.warn(\`Failed to calculate hash for \${t}:\`, l);
|
|
1881
|
-
}
|
|
1882
|
-
return a;
|
|
1883
|
-
} catch (r) {
|
|
1884
|
-
if (r.name === "NotFoundError")
|
|
1885
|
-
throw new R("file", t, r);
|
|
1886
|
-
if (r.name !== "TypeMismatchError")
|
|
1887
|
-
throw new J("stat", t, r);
|
|
1888
|
-
}
|
|
1889
|
-
try {
|
|
1890
|
-
return await n.getDirectoryHandle(e, { create: !1 }), {
|
|
1891
|
-
kind: "directory",
|
|
1892
|
-
size: 0,
|
|
1893
|
-
mtime: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
1894
|
-
ctime: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
1895
|
-
isFile: !1,
|
|
1896
|
-
isDirectory: !0
|
|
1897
|
-
};
|
|
1898
|
-
} catch (r) {
|
|
1899
|
-
throw new J("stat", t, r);
|
|
1900
|
-
}
|
|
1901
|
-
}
|
|
1902
|
-
/**
|
|
1903
|
-
* Read a directory's contents
|
|
1904
|
-
*
|
|
1905
|
-
* Lists all files and subdirectories within the specified directory.
|
|
1906
|
-
*
|
|
1907
|
-
* @param path - The path to the directory to read
|
|
1908
|
-
* @returns Promise that resolves to an array of detailed file/directory information
|
|
1909
|
-
* @throws {OPFSError} If the directory does not exist or cannot be accessed
|
|
1910
|
-
*
|
|
1911
|
-
* @example
|
|
1912
|
-
* \`\`\`typescript
|
|
1913
|
-
* // Get detailed information about files and directories
|
|
1914
|
-
* const detailed = await fs.readDir('/users/john/documents');
|
|
1915
|
-
* detailed.forEach(item => {
|
|
1916
|
-
* console.log(\`\${item.name} - \${item.isFile ? 'file' : 'directory'}\`);
|
|
1917
|
-
* });
|
|
1918
|
-
* \`\`\`
|
|
1919
|
-
*/
|
|
1920
|
-
async readDir(t) {
|
|
1921
|
-
await this.mount();
|
|
1922
|
-
const e = await this.getDirectoryHandle(t, !1), n = [];
|
|
1923
|
-
for await (const [r, i] of e.entries()) {
|
|
1924
|
-
const o = i.kind === "file";
|
|
1925
|
-
n.push({
|
|
1926
|
-
name: r,
|
|
1927
|
-
kind: i.kind,
|
|
1928
|
-
isFile: o,
|
|
1929
|
-
isDirectory: !o
|
|
1930
|
-
});
|
|
1931
|
-
}
|
|
1932
|
-
return n;
|
|
1933
|
-
}
|
|
1934
|
-
/**
|
|
1935
|
-
* Check if a file or directory exists
|
|
1936
|
-
*
|
|
1937
|
-
* Verifies if a file or directory exists at the specified path.
|
|
1938
|
-
*
|
|
1939
|
-
* @param path - The path to check
|
|
1940
|
-
* @returns Promise that resolves to true if the file or directory exists, false otherwise
|
|
1941
|
-
*
|
|
1942
|
-
* @example
|
|
1943
|
-
* \`\`\`typescript
|
|
1944
|
-
* const exists = await fs.exists('/config/settings.json');
|
|
1945
|
-
* console.log(\`File exists: \${exists}\`);
|
|
1946
|
-
* \`\`\`
|
|
1947
|
-
*/
|
|
1948
|
-
async exists(t) {
|
|
1949
|
-
if (await this.mount(), t === "/")
|
|
1950
|
-
return !0;
|
|
1951
|
-
const e = it(t);
|
|
1952
|
-
let n = null;
|
|
1953
|
-
try {
|
|
1954
|
-
n = await this.getDirectoryHandle(tt(t), !1);
|
|
1955
|
-
} catch (r) {
|
|
1956
|
-
if (n = null, r.name !== "NotFoundError" && r.name !== "TypeMismatchError")
|
|
1957
|
-
throw r;
|
|
1958
|
-
}
|
|
1959
|
-
if (!n || !e)
|
|
1960
|
-
return !1;
|
|
1961
|
-
try {
|
|
1962
|
-
return await n.getFileHandle(e, { create: !1 }), !0;
|
|
1963
|
-
} catch (r) {
|
|
1964
|
-
if (r.name !== "NotFoundError" && r.name !== "TypeMismatchError")
|
|
1965
|
-
throw r;
|
|
1966
|
-
try {
|
|
1967
|
-
return await n.getDirectoryHandle(e, { create: !1 }), !0;
|
|
1968
|
-
} catch (i) {
|
|
1969
|
-
if (i.name !== "NotFoundError" && i.name !== "TypeMismatchError")
|
|
1970
|
-
throw i;
|
|
1971
|
-
return !1;
|
|
1972
|
-
}
|
|
1973
|
-
}
|
|
1974
|
-
}
|
|
1975
|
-
/**
|
|
1976
|
-
* Clear all contents of a directory without removing the directory itself
|
|
1977
|
-
*
|
|
1978
|
-
* Removes all files and subdirectories within the specified directory,
|
|
1979
|
-
* but keeps the directory itself.
|
|
1980
|
-
*
|
|
1981
|
-
* @param path - The path to the directory to clear (default: '/')
|
|
1982
|
-
* @returns Promise that resolves when all contents are removed
|
|
1983
|
-
* @throws {OPFSError} If the operation fails
|
|
1984
|
-
*
|
|
1985
|
-
* @example
|
|
1986
|
-
* \`\`\`typescript
|
|
1987
|
-
* // Clear root directory contents
|
|
1988
|
-
* await fs.clear('/');
|
|
1989
|
-
*
|
|
1990
|
-
* // Clear specific directory contents
|
|
1991
|
-
* await fs.clear('/data');
|
|
1992
|
-
* \`\`\`
|
|
1993
|
-
*/
|
|
1994
|
-
async clear(t = "/") {
|
|
1995
|
-
await this.mount();
|
|
1996
|
-
try {
|
|
1997
|
-
const e = await this.readDir(t);
|
|
1998
|
-
for (const n of e) {
|
|
1999
|
-
const r = \`\${t === "/" ? "" : t}/\${n.name}\`;
|
|
2000
|
-
await this.remove(r, { recursive: !0 });
|
|
2001
|
-
}
|
|
2002
|
-
await this.notifyChange({ path: t, type: D.Changed, isDirectory: !0 });
|
|
2003
|
-
} catch (e) {
|
|
2004
|
-
throw e instanceof w ? e : v(e, { path: t, isDirectory: !0 });
|
|
2005
|
-
}
|
|
2006
|
-
}
|
|
2007
|
-
/**
|
|
2008
|
-
* Remove files and directories
|
|
2009
|
-
*
|
|
2010
|
-
* Removes files and directories. Similar to Node.js fs.rm().
|
|
2011
|
-
*
|
|
2012
|
-
* @param path - The path to remove
|
|
2013
|
-
* @param options - Options for removal
|
|
2014
|
-
* @param options.recursive - Whether to remove directories and their contents recursively (default: false)
|
|
2015
|
-
* @param options.force - Whether to ignore errors if the path doesn't exist (default: false)
|
|
2016
|
-
* @returns Promise that resolves when the removal is complete
|
|
2017
|
-
* @throws {OPFSError} If the removal fails
|
|
2018
|
-
*
|
|
2019
|
-
* @example
|
|
2020
|
-
* \`\`\`typescript
|
|
2021
|
-
* // Remove a file
|
|
2022
|
-
* await fs.rm('/path/to/file.txt');
|
|
2023
|
-
*
|
|
2024
|
-
* // Remove a directory and all its contents
|
|
2025
|
-
* await fs.rm('/path/to/directory', { recursive: true });
|
|
2026
|
-
*
|
|
2027
|
-
* // Remove with force (ignore if doesn't exist)
|
|
2028
|
-
* await fs.rm('/maybe/exists', { force: true });
|
|
2029
|
-
* \`\`\`
|
|
2030
|
-
*/
|
|
2031
|
-
async remove(t, e) {
|
|
2032
|
-
if (await this.mount(), t === "/")
|
|
2033
|
-
throw new rt("EROOT", t);
|
|
2034
|
-
const { recursive: n = !1, force: r = !1 } = e || {}, i = await this.getDirectoryHandle(tt(t), !1), o = await this.stat(t);
|
|
2035
|
-
await fs(i, t, { recursive: n, force: r }), await this.notifyChange({ path: t, type: D.Removed, isDirectory: o.isDirectory });
|
|
2036
|
-
}
|
|
2037
|
-
/**
|
|
2038
|
-
* Resolve a path to an absolute path
|
|
2039
|
-
*
|
|
2040
|
-
* Resolves relative paths and normalizes path segments (like '..' and '.').
|
|
2041
|
-
* Similar to Node.js fs.realpath() but without symlink resolution since OPFS doesn't support symlinks.
|
|
2042
|
-
*
|
|
2043
|
-
* @param path - The path to resolve
|
|
2044
|
-
* @returns Promise that resolves to the absolute normalized path
|
|
2045
|
-
* @throws {FileNotFoundError} If the path does not exist
|
|
2046
|
-
* @throws {OPFSError} If path resolution fails
|
|
2047
|
-
*
|
|
2048
|
-
* @example
|
|
2049
|
-
* \`\`\`typescript
|
|
2050
|
-
* // Resolve relative path
|
|
2051
|
-
* const absolute = await fs.realpath('./config/../data/file.txt');
|
|
2052
|
-
* console.log(absolute); // '/data/file.txt'
|
|
2053
|
-
* \`\`\`
|
|
2054
|
-
*/
|
|
2055
|
-
async realpath(t) {
|
|
2056
|
-
await this.mount();
|
|
2057
|
-
try {
|
|
2058
|
-
const e = Et(t);
|
|
2059
|
-
if (!await this.exists(e))
|
|
2060
|
-
throw new R("file", e);
|
|
2061
|
-
return e;
|
|
2062
|
-
} catch (e) {
|
|
2063
|
-
throw e instanceof w ? e : v(e, { path: t });
|
|
2064
|
-
}
|
|
2065
|
-
}
|
|
2066
|
-
/**
|
|
2067
|
-
* Rename a file or directory
|
|
2068
|
-
*
|
|
2069
|
-
* Changes the name of a file or directory. If the target path already exists,
|
|
2070
|
-
* it will be replaced only if overwrite option is enabled.
|
|
2071
|
-
*
|
|
2072
|
-
* @param oldPath - The current path of the file or directory
|
|
2073
|
-
* @param newPath - The new path for the file or directory
|
|
2074
|
-
* @param options - Options for renaming
|
|
2075
|
-
* @param options.overwrite - Whether to overwrite existing files (default: false)
|
|
2076
|
-
* @returns Promise that resolves when the rename operation is complete
|
|
2077
|
-
* @throws {OPFSError} If the rename operation fails
|
|
2078
|
-
*
|
|
2079
|
-
* @example
|
|
2080
|
-
* \`\`\`typescript
|
|
2081
|
-
* // Basic rename (fails if target exists)
|
|
2082
|
-
* await fs.rename('/old/path/file.txt', '/new/path/renamed.txt');
|
|
2083
|
-
*
|
|
2084
|
-
* // Rename with overwrite
|
|
2085
|
-
* await fs.rename('/old/path/file.txt', '/new/path/renamed.txt', { overwrite: true });
|
|
2086
|
-
* \`\`\`
|
|
2087
|
-
*/
|
|
2088
|
-
async rename(t, e, n) {
|
|
2089
|
-
await this.mount();
|
|
2090
|
-
try {
|
|
2091
|
-
const r = n?.overwrite ?? !1, i = await this.stat(t);
|
|
2092
|
-
if (await this.exists(e) && !r)
|
|
2093
|
-
throw new Q(e);
|
|
2094
|
-
await this.copy(t, e, { recursive: !0, overwrite: r }), await this.remove(t, { recursive: !0 }), await this.notifyChange({ path: t, type: D.Removed, isDirectory: i.isDirectory }), await this.notifyChange({ path: e, type: D.Added, isDirectory: i.isDirectory });
|
|
2095
|
-
} catch (r) {
|
|
2096
|
-
throw r instanceof w ? r : v(r, { path: t });
|
|
2097
|
-
}
|
|
2098
|
-
}
|
|
2099
|
-
/**
|
|
2100
|
-
* Copy files and directories
|
|
2101
|
-
*
|
|
2102
|
-
* Copies files and directories. Similar to Node.js fs.cp().
|
|
2103
|
-
*
|
|
2104
|
-
* @param source - The source path to copy from
|
|
2105
|
-
* @param destination - The destination path to copy to
|
|
2106
|
-
* @param options - Options for copying
|
|
2107
|
-
* @param options.recursive - Whether to copy directories recursively (default: false)
|
|
2108
|
-
* @param options.overwrite - Whether to overwrite existing files (default: true)
|
|
2109
|
-
* @returns Promise that resolves when the copy operation is complete
|
|
2110
|
-
* @throws {OPFSError} If the copy operation fails
|
|
2111
|
-
*
|
|
2112
|
-
* @example
|
|
2113
|
-
* \`\`\`typescript
|
|
2114
|
-
* // Copy a file
|
|
2115
|
-
* await fs.copy('/source/file.txt', '/dest/file.txt');
|
|
2116
|
-
*
|
|
2117
|
-
* // Copy a directory and all its contents
|
|
2118
|
-
* await fs.copy('/source/dir', '/dest/dir', { recursive: true });
|
|
2119
|
-
*
|
|
2120
|
-
* // Copy without overwriting existing files
|
|
2121
|
-
* await fs.copy('/source', '/dest', { recursive: true, overwrite: false });
|
|
2122
|
-
* \`\`\`
|
|
2123
|
-
*/
|
|
2124
|
-
async copy(t, e, n) {
|
|
2125
|
-
await this.mount();
|
|
2126
|
-
try {
|
|
2127
|
-
const r = n?.recursive ?? !1, i = n?.overwrite ?? !0;
|
|
2128
|
-
if (!await this.exists(t))
|
|
2129
|
-
throw new R("source", t);
|
|
2130
|
-
if (await this.exists(e) && !i)
|
|
2131
|
-
throw new Q(e);
|
|
2132
|
-
if ((await this.stat(t)).isFile) {
|
|
2133
|
-
const h = await this.readFile(t);
|
|
2134
|
-
await this.writeFile(e, h);
|
|
2135
|
-
} else {
|
|
2136
|
-
if (!r)
|
|
2137
|
-
throw new nt("directory", t);
|
|
2138
|
-
await this.mkdir(e, { recursive: !0 });
|
|
2139
|
-
const h = await this.readDir(t);
|
|
2140
|
-
for (const c of h) {
|
|
2141
|
-
const f = \`\${t}/\${c.name}\`, u = \`\${e}/\${c.name}\`;
|
|
2142
|
-
await this.copy(f, u, { recursive: !0, overwrite: i });
|
|
2143
|
-
}
|
|
2144
|
-
}
|
|
2145
|
-
} catch (r) {
|
|
2146
|
-
throw r instanceof w ? r : v(r, { path: t });
|
|
2147
|
-
}
|
|
2148
|
-
}
|
|
2149
|
-
/**
|
|
2150
|
-
* Start watching a file or directory for changes
|
|
2151
|
-
*
|
|
2152
|
-
* @param path - The path to watch (minimatch syntax allowed)
|
|
2153
|
-
* @param options - Watch options
|
|
2154
|
-
* @param options.recursive - Whether to watch recursively (default: true)
|
|
2155
|
-
* @param options.exclude - Glob pattern(s) to exclude (minimatch).
|
|
2156
|
-
* @returns Promise that resolves when watching starts
|
|
2157
|
-
*
|
|
2158
|
-
* @example
|
|
2159
|
-
* \`\`\`typescript
|
|
2160
|
-
* // Watch entire directory tree recursively (default)
|
|
2161
|
-
* await fs.watch('/data');
|
|
2162
|
-
*
|
|
2163
|
-
* // Watch only immediate children (shallow)
|
|
2164
|
-
* await fs.watch('/data', { recursive: false });
|
|
2165
|
-
*
|
|
2166
|
-
* // Watch a single file
|
|
2167
|
-
* await fs.watch('/config.json', { recursive: false });
|
|
2168
|
-
*
|
|
2169
|
-
* // Watch all json files but not in dist directory
|
|
2170
|
-
* await fs.watch('/**\\/*.json', { recursive: false, exclude: ['dist/**'] });
|
|
2171
|
-
*
|
|
2172
|
-
* \`\`\`
|
|
2173
|
-
*/
|
|
2174
|
-
async watch(t, e) {
|
|
2175
|
-
if (!this.options.broadcastChannel)
|
|
2176
|
-
throw new Ct("This instance is not configured to send events. Please specify options.broadcastChannel to enable watching.");
|
|
2177
|
-
const n = {
|
|
2178
|
-
pattern: ls(t, e?.recursive ?? !0),
|
|
2179
|
-
include: Array.isArray(e?.include) ? e.include : [e?.include ?? "**"],
|
|
2180
|
-
exclude: Array.isArray(e?.exclude) ? e.exclude : [e?.exclude ?? ""]
|
|
2181
|
-
};
|
|
2182
|
-
this.watchers.set(t, n);
|
|
2183
|
-
}
|
|
2184
|
-
/**
|
|
2185
|
-
* Stop watching a previously watched path
|
|
2186
|
-
*/
|
|
2187
|
-
unwatch(t) {
|
|
2188
|
-
this.watchers.delete(t);
|
|
2189
|
-
}
|
|
2190
|
-
/**
|
|
2191
|
-
* Open a file and return a file descriptor
|
|
2192
|
-
*
|
|
2193
|
-
* @param path - The path to the file to open
|
|
2194
|
-
* @param options - Options for opening the file
|
|
2195
|
-
* @param options.create - Whether to create the file if it doesn't exist (default: false)
|
|
2196
|
-
* @param options.exclusive - If true and create is true, fails if file already exists (default: false)
|
|
2197
|
-
* Note: This is best-effort in OPFS, not fully atomic due to browser limitations
|
|
2198
|
-
* @param options.truncate - Whether to truncate the file to zero length (default: false)
|
|
2199
|
-
* @returns Promise that resolves to a file descriptor number
|
|
2200
|
-
* @throws {OPFSError} If opening the file fails
|
|
2201
|
-
*
|
|
2202
|
-
* @example
|
|
2203
|
-
* \`\`\`typescript
|
|
2204
|
-
* // Open existing file for reading
|
|
2205
|
-
* const fd = await fs.open('/data/config.json');
|
|
2206
|
-
*
|
|
2207
|
-
* // Create new file for writing
|
|
2208
|
-
* const fd = await fs.open('/data/new.txt', { create: true });
|
|
2209
|
-
*
|
|
2210
|
-
* // Create file exclusively (fails if exists)
|
|
2211
|
-
* const fd = await fs.open('/data/unique.txt', { create: true, exclusive: true });
|
|
2212
|
-
*
|
|
2213
|
-
* // Open and truncate file
|
|
2214
|
-
* const fd = await fs.open('/data/log.txt', { create: true, truncate: true });
|
|
2215
|
-
* \`\`\`
|
|
2216
|
-
*/
|
|
2217
|
-
async open(t, e) {
|
|
2218
|
-
await this.mount();
|
|
2219
|
-
const { create: n = !1, exclusive: r = !1, truncate: i = !1 } = e || {}, o = B(Et(t));
|
|
2220
|
-
try {
|
|
2221
|
-
return n && r ? await L(o, "exclusive", async () => {
|
|
2222
|
-
if (await this.exists(o))
|
|
2223
|
-
throw new Q(o);
|
|
2224
|
-
return this._openFile(o, n, i);
|
|
2225
|
-
}) : await this._openFile(o, n, i);
|
|
2226
|
-
} catch (a) {
|
|
2227
|
-
if (a instanceof w)
|
|
2228
|
-
throw a;
|
|
2229
|
-
const l = a && a.name === "TypeMismatchError";
|
|
2230
|
-
throw v(a, {
|
|
2231
|
-
path: o,
|
|
2232
|
-
isDirectory: !!l
|
|
2233
|
-
});
|
|
2234
|
-
}
|
|
2235
|
-
}
|
|
2236
|
-
/**
|
|
2237
|
-
* Internal method to open a file (without locking)
|
|
2238
|
-
* @private
|
|
2239
|
-
*/
|
|
2240
|
-
async _openFile(t, e, n) {
|
|
2241
|
-
const r = await this.getFileHandle(t, e);
|
|
2242
|
-
try {
|
|
2243
|
-
await r.getFile();
|
|
2244
|
-
} catch (a) {
|
|
2245
|
-
throw v(a, { path: t, isDirectory: !0 });
|
|
2246
|
-
}
|
|
2247
|
-
const i = await ps(r, t);
|
|
2248
|
-
n && (i.truncate(0), i.flush());
|
|
2249
|
-
const o = this.nextFd++;
|
|
2250
|
-
return this.openFiles.set(o, {
|
|
2251
|
-
path: t,
|
|
2252
|
-
fileHandle: r,
|
|
2253
|
-
syncHandle: i,
|
|
2254
|
-
position: 0
|
|
2255
|
-
}), o;
|
|
2256
|
-
}
|
|
2257
|
-
/**
|
|
2258
|
-
* Close a file descriptor
|
|
2259
|
-
*
|
|
2260
|
-
* @param fd - The file descriptor to close
|
|
2261
|
-
* @returns Promise that resolves when the file descriptor is closed
|
|
2262
|
-
* @throws {OPFSError} If the file descriptor is invalid or closing fails
|
|
2263
|
-
*
|
|
2264
|
-
* @example
|
|
2265
|
-
* \`\`\`typescript
|
|
2266
|
-
* const fd = await fs.open('/data/file.txt');
|
|
2267
|
-
* // ... use the file descriptor ...
|
|
2268
|
-
* await fs.close(fd);
|
|
2269
|
-
* \`\`\`
|
|
2270
|
-
*/
|
|
2271
|
-
async close(t) {
|
|
2272
|
-
const e = this._getFileDescriptor(t);
|
|
2273
|
-
xt(t, e.syncHandle, e.path), this.openFiles.delete(t);
|
|
2274
|
-
}
|
|
2275
|
-
/**
|
|
2276
|
-
* Read data from a file descriptor
|
|
2277
|
-
*
|
|
2278
|
-
* @param fd - The file descriptor to read from
|
|
2279
|
-
* @param buffer - The buffer to read data into
|
|
2280
|
-
* @param offset - The offset in the buffer to start writing at
|
|
2281
|
-
* @param length - The number of bytes to read
|
|
2282
|
-
* @param position - The position in the file to read from (null for current position)
|
|
2283
|
-
* @returns Promise that resolves to the number of bytes read and the modified buffer
|
|
2284
|
-
* @throws {OPFSError} If the file descriptor is invalid or reading fails
|
|
2285
|
-
*
|
|
2286
|
-
* @note This method uses Comlink.transfer() to efficiently pass the buffer as a Transferable Object,
|
|
2287
|
-
* ensuring zero-copy performance across Web Worker boundaries.
|
|
2288
|
-
*
|
|
2289
|
-
* @example
|
|
2290
|
-
* \`\`\`typescript
|
|
2291
|
-
* const fd = await fs.open('/data/file.txt');
|
|
2292
|
-
* const buffer = new Uint8Array(1024);
|
|
2293
|
-
* const { bytesRead, buffer: modifiedBuffer } = await fs.read(fd, buffer, 0, 1024, null);
|
|
2294
|
-
* console.log(\`Read \${bytesRead} bytes\`);
|
|
2295
|
-
* // Use modifiedBuffer which contains the actual data
|
|
2296
|
-
* await fs.close(fd);
|
|
2297
|
-
* \`\`\`
|
|
2298
|
-
*/
|
|
2299
|
-
async read(t, e, n, r, i) {
|
|
2300
|
-
const o = this._getFileDescriptor(t);
|
|
2301
|
-
St(e.length, n, r, i);
|
|
2302
|
-
try {
|
|
2303
|
-
const a = i ?? o.position, l = o.syncHandle.getSize(), { isEOF: h, actualLength: c } = ds(a, r, l);
|
|
2304
|
-
if (h)
|
|
2305
|
-
return U({ bytesRead: 0, buffer: e }, [e.buffer]);
|
|
2306
|
-
const f = e.subarray(n, n + c), u = o.syncHandle.read(f, { at: a });
|
|
2307
|
-
return i == null && (o.position = a + u), U({ bytesRead: u, buffer: e }, [e.buffer]);
|
|
2308
|
-
} catch (a) {
|
|
2309
|
-
throw W("read", t, o.path, a);
|
|
2310
|
-
}
|
|
2311
|
-
}
|
|
2312
|
-
/**
|
|
2313
|
-
* Write data to a file descriptor
|
|
2314
|
-
*
|
|
2315
|
-
* @param fd - The file descriptor to write to
|
|
2316
|
-
* @param buffer - The buffer containing data to write
|
|
2317
|
-
* @param offset - The offset in the buffer to start reading from (default: 0)
|
|
2318
|
-
* @param length - The number of bytes to write (default: entire buffer)
|
|
2319
|
-
* @param position - The position in the file to write to (null/undefined for current position)
|
|
2320
|
-
* @param emitEvent - Whether to emit a change event (default: true)
|
|
2321
|
-
* @returns Promise that resolves to the number of bytes written
|
|
2322
|
-
* @throws {OPFSError} If the file descriptor is invalid or writing fails
|
|
2323
|
-
*
|
|
2324
|
-
* @example
|
|
2325
|
-
* \`\`\`typescript
|
|
2326
|
-
* const fd = await fs.open('/data/file.txt', { create: true });
|
|
2327
|
-
* const data = new TextEncoder().encode('Hello, World!');
|
|
2328
|
-
* const bytesWritten = await fs.write(fd, data, 0, data.length, null);
|
|
2329
|
-
* console.log(\`Wrote \${bytesWritten} bytes\`);
|
|
2330
|
-
* await fs.close(fd);
|
|
2331
|
-
* \`\`\`
|
|
2332
|
-
*/
|
|
2333
|
-
async write(t, e, n = 0, r, i, o = !0) {
|
|
2334
|
-
const a = this._getFileDescriptor(t), l = r ?? e.length - n;
|
|
2335
|
-
St(e.length, n, l, i);
|
|
2336
|
-
try {
|
|
2337
|
-
const h = i ?? a.position, c = e.subarray(n, n + l), f = a.syncHandle.write(c, { at: h });
|
|
2338
|
-
return (i == null || i === a.position) && (a.position = h + f), o && await this.notifyChange({ path: a.path, type: D.Changed, isDirectory: !1 }), f;
|
|
2339
|
-
} catch (h) {
|
|
2340
|
-
throw W("write", t, a.path, h);
|
|
2341
|
-
}
|
|
2342
|
-
}
|
|
2343
|
-
/**
|
|
2344
|
-
* Get file status information by file descriptor
|
|
2345
|
-
*
|
|
2346
|
-
* @param fd - The file descriptor
|
|
2347
|
-
* @returns Promise that resolves to FileStat object
|
|
2348
|
-
* @throws {OPFSError} If the file descriptor is invalid
|
|
2349
|
-
*
|
|
2350
|
-
* @example
|
|
2351
|
-
* \`\`\`typescript
|
|
2352
|
-
* const fd = await fs.open('/data/file.txt');
|
|
2353
|
-
* const stats = await fs.fstat(fd);
|
|
2354
|
-
* console.log(\`File size: \${stats.size} bytes\`);
|
|
2355
|
-
* console.log(\`Last modified: \${stats.mtime}\`);
|
|
2356
|
-
*
|
|
2357
|
-
* // If hashing is enabled, hash will be included
|
|
2358
|
-
* if (stats.hash) {
|
|
2359
|
-
* console.log(\`Hash: \${stats.hash}\`);
|
|
2360
|
-
* }
|
|
2361
|
-
* \`\`\`
|
|
2362
|
-
*/
|
|
2363
|
-
async fstat(t) {
|
|
2364
|
-
const e = this._getFileDescriptor(t);
|
|
2365
|
-
return this.stat(e.path);
|
|
2366
|
-
}
|
|
2367
|
-
/**
|
|
2368
|
-
* Truncate file to specified size
|
|
2369
|
-
*
|
|
2370
|
-
* @param fd - The file descriptor
|
|
2371
|
-
* @param size - The new size of the file (default: 0)
|
|
2372
|
-
* @returns Promise that resolves when truncation is complete
|
|
2373
|
-
* @throws {OPFSError} If the file descriptor is invalid or truncation fails
|
|
2374
|
-
*
|
|
2375
|
-
* @example
|
|
2376
|
-
* \`\`\`typescript
|
|
2377
|
-
* const fd = await fs.open('/data/file.txt', { create: true });
|
|
2378
|
-
* await fs.truncate(fd, 100); // Truncate to 100 bytes
|
|
2379
|
-
* \`\`\`
|
|
2380
|
-
*/
|
|
2381
|
-
async ftruncate(t, e = 0) {
|
|
2382
|
-
const n = this._getFileDescriptor(t);
|
|
2383
|
-
if (e < 0 || !Number.isInteger(e))
|
|
2384
|
-
throw new N("argument", "Invalid size");
|
|
2385
|
-
try {
|
|
2386
|
-
n.syncHandle.truncate(e), n.syncHandle.flush(), n.position > e && (n.position = e), await this.notifyChange({ path: n.path, type: D.Changed, isDirectory: !1 });
|
|
2387
|
-
} catch (r) {
|
|
2388
|
-
throw W("truncate", t, n.path, r);
|
|
2389
|
-
}
|
|
2390
|
-
}
|
|
2391
|
-
/**
|
|
2392
|
-
* Synchronize file data to storage (fsync equivalent)
|
|
2393
|
-
*
|
|
2394
|
-
* @param fd - The file descriptor
|
|
2395
|
-
* @returns Promise that resolves when synchronization is complete
|
|
2396
|
-
* @throws {OPFSError} If the file descriptor is invalid or sync fails
|
|
2397
|
-
*
|
|
2398
|
-
* @example
|
|
2399
|
-
* \`\`\`typescript
|
|
2400
|
-
* const fd = await fs.open('/data/file.txt', { create: true });
|
|
2401
|
-
* await fs.write(fd, data);
|
|
2402
|
-
* await fs.fsync(fd); // Ensure data is written to storage
|
|
2403
|
-
* \`\`\`
|
|
2404
|
-
*/
|
|
2405
|
-
async fsync(t) {
|
|
2406
|
-
const e = this._getFileDescriptor(t);
|
|
2407
|
-
try {
|
|
2408
|
-
e.syncHandle.flush();
|
|
2409
|
-
} catch (n) {
|
|
2410
|
-
throw W("sync", t, e.path, n);
|
|
2411
|
-
}
|
|
2412
|
-
}
|
|
2413
|
-
/**
|
|
2414
|
-
* Dispose of resources and clean up the file system instance
|
|
2415
|
-
*
|
|
2416
|
-
* This method should be called when the file system instance is no longer needed
|
|
2417
|
-
* to properly clean up resources like the broadcast channel and watch timers.
|
|
2418
|
-
*/
|
|
2419
|
-
dispose() {
|
|
2420
|
-
this.broadcastChannel && (this.broadcastChannel.close(), this.broadcastChannel = null), this.watchers.clear();
|
|
2421
|
-
for (const [t, e] of this.openFiles)
|
|
2422
|
-
xt(t, e.syncHandle, e.path);
|
|
2423
|
-
this.openFiles.clear(), this.nextFd = 1;
|
|
2424
|
-
}
|
|
2425
|
-
/**
|
|
2426
|
-
* Synchronize the file system with external data
|
|
2427
|
-
*
|
|
2428
|
-
* Syncs the file system with an array of entries containing paths and data.
|
|
2429
|
-
* This is useful for importing data from external sources or syncing with remote data.
|
|
2430
|
-
*
|
|
2431
|
-
* @param entries - Array of [path, data] tuples to sync
|
|
2432
|
-
* @returns Promise that resolves when synchronization is complete
|
|
2433
|
-
* @throws {OPFSError} If the synchronization fails
|
|
2434
|
-
*
|
|
2435
|
-
* @example
|
|
2436
|
-
* \`\`\`typescript
|
|
2437
|
-
* // Sync with external data
|
|
2438
|
-
* const entries: [string, string | Uint8Array | Blob][] = [
|
|
2439
|
-
* ['/config.json', JSON.stringify({ theme: 'dark' })],
|
|
2440
|
-
* ['/data/binary.dat', new Uint8Array([1, 2, 3, 4])],
|
|
2441
|
-
* ['/upload.txt', new Blob(['file content'], { type: 'text/plain' })]
|
|
2442
|
-
* ];
|
|
2443
|
-
*
|
|
2444
|
-
* // Sync without clearing existing files
|
|
2445
|
-
* await fs.sync(entries);
|
|
2446
|
-
*
|
|
2447
|
-
* // Clean file system and then sync
|
|
2448
|
-
* await fs.sync(entries, { cleanBefore: true });
|
|
2449
|
-
* \`\`\`
|
|
2450
|
-
*/
|
|
2451
|
-
async createIndex(t) {
|
|
2452
|
-
await this.mount();
|
|
2453
|
-
try {
|
|
2454
|
-
for (const [e, n] of t) {
|
|
2455
|
-
const r = B(e);
|
|
2456
|
-
let i;
|
|
2457
|
-
n instanceof Blob ? i = await us(n) : typeof n == "string" ? i = new TextEncoder().encode(n) : i = n, await this.writeFile(r, i);
|
|
2458
|
-
}
|
|
2459
|
-
} catch (e) {
|
|
2460
|
-
throw e instanceof w ? e : v(e);
|
|
2461
|
-
}
|
|
2462
|
-
}
|
|
2463
|
-
}
|
|
2464
|
-
typeof globalThis < "u" && globalThis.constructor.name === "DedicatedWorkerGlobalScope" && ot(new gs());
|
|
2465
|
-
//# sourceMappingURL=worker-DYYLzR1Y.js.map
|
|
2466
|
-
`,h=typeof self<"u"&&self.Blob&&new Blob(["URL.revokeObjectURL(import.meta.url);",l],{type:"text/javascript;charset=utf-8"});function u(o){let n;try{if(n=h&&(self.URL||self.webkitURL).createObjectURL(h),!n)throw"";const t=new Worker(n,{type:"module",name:o?.name});return t.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(n)}),t}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(l),{type:"module",name:o?.name})}}function a(o){return o instanceof URL?o.pathname:o}class p{#n;#t;promises=this;constructor(n){this.#t=new u,this.#n=d.wrap(this.#t),n&&(n.broadcastChannel&&n.broadcastChannel instanceof BroadcastChannel&&(n.broadcastChannel=n.broadcastChannel.name),this.setOptions(n))}watch(n,t){const r=a(n);return this.#n.watch(r,t),()=>this.unwatch(r)}unwatch(n){const t=a(n);this.#n.unwatch(t)}async setOptions(n){return this.#n.setOptions(n)}async index(){return this.#n.index()}async readFile(n,t){const r=a(n);let s;typeof t=="string"?s=t:t&&typeof t=="object"&&(s=t.encoding);const i=await this.#n.readFile(r);return s||(s=e.isBinaryFileExtension(r)?"binary":"utf-8"),s==="binary"?i:e.decodeBuffer(i,s)}async writeFile(n,t,r){const s=a(n);let i;typeof r=="string"?i=r:r&&typeof r=="object"&&(i=r.encoding),i||(i=typeof t!="string"||e.isBinaryFileExtension(s)?"binary":"utf-8");const c=typeof t=="string"?e.encodeString(t,i):t instanceof Uint8Array?t:new Uint8Array(t);return this.#n.writeFile(s,c)}async appendFile(n,t,r){const s=a(n);r||(r=typeof t!="string"||e.isBinaryFileExtension(s)?"binary":"utf-8");const i=typeof t=="string"?e.encodeString(t,r):t instanceof Uint8Array?t:new Uint8Array(t);return this.#n.appendFile(s,i)}async mkdir(n,t){const r=a(n);let s;return typeof t=="number"?s={recursive:!1}:s=t,this.#n.mkdir(r,s)}async stat(n){const t=a(n);return this.#n.stat(t)}async readDir(n){const t=a(n);return this.#n.readDir(t)}async exists(n){const t=a(n);return this.#n.exists(t)}async clear(n){const t=n?a(n):void 0;return this.#n.clear(t)}async remove(n,t){const r=a(n);return this.#n.remove(r,t)}async unlink(n){return this.remove(n)}async rm(n,t){return this.remove(n,t)}async rmdir(n){return this.remove(n)}async readdir(n,t){return this.readDir(n)}async lstat(n){return this.stat(n)}async chmod(n,t){return Promise.resolve()}async realpath(n){const t=a(n);return this.#n.realpath(t)}async rename(n,t,r){const s=a(n),i=a(t);return this.#n.rename(s,i,r)}async copy(n,t,r){const s=a(n),i=a(t);return this.#n.copy(s,i,r)}async open(n,t){const r=a(n);return this.#n.open(r,t)}async close(n){return this.#n.close(n)}async read(n,t,r,s,i){const{bytesRead:c,buffer:f}=await this.#n.read(n,new Uint8Array(s),0,s,i);return c>0&&t.set(f.subarray(0,c),r),{bytesRead:c,buffer:t}}async write(n,t,r,s,i,c){return this.#n.write(n,t,r,s,i,c)}async fstat(n){return this.#n.fstat(n)}async ftruncate(n,t){return this.#n.ftruncate(n,t)}async fsync(n){return this.#n.fsync(n)}async createIndex(n){const t=n.map(([r,s])=>[a(r),s]);return this.#n.createIndex(t)}async readText(n,t="utf-8"){const r=a(n),s=await this.#n.readFile(r);return e.decodeBuffer(s,t)}async writeText(n,t,r="utf-8"){const s=a(n),i=e.encodeString(t,r);return this.#n.writeFile(s,i)}async appendText(n,t,r="utf-8"){const s=a(n),i=e.encodeString(t,r);return this.#n.appendFile(s,i)}dispose(){const n=this.#n,t=this.#t;(async()=>{try{await n.dispose()}finally{t.terminate()}})()}}function m(o){return new p(o)}exports.AlreadyExistsError=e.AlreadyExistsError;exports.BINARY_FILE_EXTENSIONS=e.BINARY_FILE_EXTENSIONS;exports.DirectoryOperationError=e.DirectoryOperationError;exports.ExistenceError=e.ExistenceError;exports.FileBusyError=e.FileBusyError;exports.FileSystemOperationError=e.FileSystemOperationError;exports.FileTypeError=e.FileTypeError;exports.IOError=e.IOError;exports.InitializationFailedError=e.InitializationFailedError;exports.OPFSError=e.OPFSError;exports.OPFSNotSupportedError=e.OPFSNotSupportedError;exports.OperationAbortedError=e.OperationAbortedError;exports.OperationNotSupportedError=e.OperationNotSupportedError;exports.PathError=e.PathError;exports.PermissionError=e.PermissionError;exports.StorageError=e.StorageError;exports.ValidationError=e.ValidationError;exports.WatchEventType=e.WatchEventType;exports.basename=e.basename;exports.buffersEqual=e.buffersEqual;exports.calculateFileHash=e.calculateFileHash;exports.calculateReadLength=e.calculateReadLength;exports.checkOPFSSupport=e.checkOPFSSupport;exports.convertBlobToUint8Array=e.convertBlobToUint8Array;exports.createBuffer=e.createBuffer;exports.createFDError=e.createFDError;exports.createSyncHandleSafe=e.createSyncHandleSafe;exports.decodeBuffer=e.decodeBuffer;exports.dirname=e.dirname;exports.encodeString=e.encodeString;exports.extname=e.extname;exports.isBinaryFileExtension=e.isBinaryFileExtension;exports.isPathExcluded=e.isPathExcluded;exports.joinPath=e.joinPath;exports.mapDomError=e.mapDomError;exports.matchMinimatch=e.matchMinimatch;exports.normalizeMinimatch=e.normalizeMinimatch;exports.normalizePath=e.normalizePath;exports.removeEntry=e.removeEntry;exports.resolvePath=e.resolvePath;exports.safeCloseSyncHandle=e.safeCloseSyncHandle;exports.splitPath=e.splitPath;exports.validateReadWriteArgs=e.validateReadWriteArgs;exports.withLock=e.withLock;exports.OPFSFileSystem=p;exports.createWorker=m;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./BaseOPFS-BPw9AIQ-.cjs"),t=require("./OPFSSync-C7KBepe_.cjs"),a=require("./OPFSFacade-DePnNRgt.cjs"),e=require("./createOPFSDedicated-pKTRWLdz.cjs"),o=require("./OPFSAsync-s2P7y3sw.cjs"),i=require("./createOPFSAsync-BwKDmHsy.cjs"),c=require("./createOPFSShared-CskROt7U.cjs");exports.AlreadyExistsError=r.AlreadyExistsError;exports.BINARY_FILE_EXTENSIONS=r.BINARY_FILE_EXTENSIONS;exports.BaseOPFS=r.BaseOPFS;exports.DirectoryOperationError=r.DirectoryOperationError;exports.ExistenceError=r.ExistenceError;exports.FileBusyError=r.FileBusyError;exports.FileSystemOperationError=r.FileSystemOperationError;exports.FileTypeError=r.FileTypeError;exports.IOError=r.IOError;exports.InitializationFailedError=r.InitializationFailedError;exports.OPFSError=r.OPFSError;exports.OPFSNotSupportedError=r.OPFSNotSupportedError;exports.OperationAbortedError=r.OperationAbortedError;exports.OperationNotSupportedError=r.OperationNotSupportedError;exports.PathError=r.PathError;exports.PermissionError=r.PermissionError;exports.StorageError=r.StorageError;exports.ValidationError=r.ValidationError;exports.WatchEventType=r.WatchEventType;exports.basename=r.basename;exports.buffersEqual=r.buffersEqual;exports.calculateFileHash=r.calculateFileHash;exports.calculateReadLength=r.calculateReadLength;exports.checkOPFSSupport=r.checkOPFSSupport;exports.convertBlobToUint8Array=r.convertBlobToUint8Array;exports.createBuffer=r.createBuffer;exports.createFDError=r.createFDError;exports.createSyncHandleSafe=r.createSyncHandleSafe;exports.decodeBuffer=r.decodeBuffer;exports.dirname=r.dirname;exports.encodeString=r.encodeString;exports.extname=r.extname;exports.isBinaryFileExtension=r.isBinaryFileExtension;exports.isPathExcluded=r.isPathExcluded;exports.joinPath=r.joinPath;exports.mapDomError=r.mapDomError;exports.matchMinimatch=r.matchMinimatch;exports.normalizeMinimatch=r.normalizeMinimatch;exports.normalizePath=r.normalizePath;exports.removeEntry=r.removeEntry;exports.resolvePath=r.resolvePath;exports.safeCloseSyncHandle=r.safeCloseSyncHandle;exports.splitPath=r.splitPath;exports.validateReadWriteArgs=r.validateReadWriteArgs;exports.withLock=r.withLock;exports.OPFSSync=t.OPFSSync;exports.OPFSFacade=a.OPFSFacade;exports.OPFSFileSystem=a.OPFSFacade;exports.createOPFS=e.createOPFSDedicated;exports.createOPFSDedicated=e.createOPFSDedicated;exports.createWorker=e.createOPFSDedicated;exports.OPFSAsync=o.OPFSAsync;exports.createOPFSAsync=i.createOPFSAsync;exports.createOPFSShared=c.createOPFSShared;
|
|
2467
2
|
//# sourceMappingURL=index.cjs.map
|