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