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