opfs-worker 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -6
- package/dist/assets/worker-CLvhwwfc.js.map +1 -0
- package/dist/facade.d.ts +141 -0
- package/dist/facade.d.ts.map +1 -0
- package/dist/{helpers-DS5dyURe.js → helpers-CkNHswLp.js} +547 -573
- package/dist/helpers-CkNHswLp.js.map +1 -0
- package/dist/helpers-TAynP0fb.cjs +4 -0
- package/dist/helpers-TAynP0fb.cjs.map +1 -0
- package/dist/index.cjs +753 -878
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +998 -932
- package/dist/index.js.map +1 -1
- package/dist/raw.cjs +1 -1
- package/dist/raw.cjs.map +1 -1
- package/dist/raw.d.ts +13 -0
- package/dist/raw.d.ts.map +1 -0
- package/dist/raw.js +187 -148
- package/dist/raw.js.map +1 -1
- package/dist/types.d.ts +3 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/encoder.d.ts +1 -2
- package/dist/utils/encoder.d.ts.map +1 -1
- package/dist/utils/helpers.d.ts +2 -22
- package/dist/utils/helpers.d.ts.map +1 -1
- package/dist/worker.d.ts +22 -32
- package/dist/worker.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/assets/worker-CvILLJKw.js.map +0 -1
- package/dist/helpers-CKqaiMjI.cjs +0 -4
- package/dist/helpers-CKqaiMjI.cjs.map +0 -1
- package/dist/helpers-DS5dyURe.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,63 +1,64 @@
|
|
|
1
|
-
import { wrap as
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { wrap as d } from "comlink";
|
|
2
|
+
import { i as h, d as c, e as a } from "./helpers-CkNHswLp.js";
|
|
3
|
+
import { E, D as x, F as S, O as F, b as P, a as O, P as A, c as T, S as I, T as $, h as R, v as C, u as _, B as N, g as D, x as k, t as M, f as L, C as j, k as W, q as z, p as U, j as H, m as B, o as G, l as q, n as V, y as Y, r as X, A as Z, s as J, z as K, w as Q } from "./helpers-CkNHswLp.js";
|
|
4
|
+
const p = `/**
|
|
4
5
|
* @license
|
|
5
6
|
* Copyright 2019 Google LLC
|
|
6
7
|
* SPDX-License-Identifier: Apache-2.0
|
|
7
8
|
*/
|
|
8
|
-
const
|
|
9
|
-
canHandle: (
|
|
10
|
-
serialize(
|
|
9
|
+
const pt = Symbol("Comlink.proxy"), Ct = Symbol("Comlink.endpoint"), Tt = Symbol("Comlink.releaseProxy"), q = Symbol("Comlink.finalizer"), z = Symbol("Comlink.thrown"), gt = (s) => typeof s == "object" && s !== null || typeof s == "function", Mt = {
|
|
10
|
+
canHandle: (s) => gt(s) && s[pt],
|
|
11
|
+
serialize(s) {
|
|
11
12
|
const { port1: t, port2: e } = new MessageChannel();
|
|
12
|
-
return
|
|
13
|
+
return K(s, t), [e, [e]];
|
|
13
14
|
},
|
|
14
|
-
deserialize(
|
|
15
|
-
return
|
|
15
|
+
deserialize(s) {
|
|
16
|
+
return s.start(), Rt(s);
|
|
16
17
|
}
|
|
17
|
-
},
|
|
18
|
-
canHandle: (
|
|
19
|
-
serialize({ value:
|
|
18
|
+
}, Pt = {
|
|
19
|
+
canHandle: (s) => gt(s) && z in s,
|
|
20
|
+
serialize({ value: s }) {
|
|
20
21
|
let t;
|
|
21
|
-
return
|
|
22
|
+
return s instanceof Error ? t = {
|
|
22
23
|
isError: !0,
|
|
23
24
|
value: {
|
|
24
|
-
message:
|
|
25
|
-
name:
|
|
26
|
-
stack:
|
|
25
|
+
message: s.message,
|
|
26
|
+
name: s.name,
|
|
27
|
+
stack: s.stack
|
|
27
28
|
}
|
|
28
|
-
} : t = { isError: !1, value:
|
|
29
|
+
} : t = { isError: !1, value: s }, [t, []];
|
|
29
30
|
},
|
|
30
|
-
deserialize(
|
|
31
|
-
throw
|
|
31
|
+
deserialize(s) {
|
|
32
|
+
throw s.isError ? Object.assign(new Error(s.value.message), s.value) : s.value;
|
|
32
33
|
}
|
|
33
|
-
},
|
|
34
|
-
["proxy",
|
|
35
|
-
["throw",
|
|
34
|
+
}, wt = /* @__PURE__ */ new Map([
|
|
35
|
+
["proxy", Mt],
|
|
36
|
+
["throw", Pt]
|
|
36
37
|
]);
|
|
37
|
-
function
|
|
38
|
-
for (const e of
|
|
38
|
+
function It(s, t) {
|
|
39
|
+
for (const e of s)
|
|
39
40
|
if (t === e || e === "*" || e instanceof RegExp && e.test(t))
|
|
40
41
|
return !0;
|
|
41
42
|
return !1;
|
|
42
43
|
}
|
|
43
|
-
function
|
|
44
|
-
t.addEventListener("message", function
|
|
45
|
-
if (!
|
|
44
|
+
function K(s, t = globalThis, e = ["*"]) {
|
|
45
|
+
t.addEventListener("message", function n(i) {
|
|
46
|
+
if (!i || !i.data)
|
|
46
47
|
return;
|
|
47
|
-
if (!
|
|
48
|
-
console.warn(\`Invalid origin '\${
|
|
48
|
+
if (!It(e, i.origin)) {
|
|
49
|
+
console.warn(\`Invalid origin '\${i.origin}' for comlink proxy\`);
|
|
49
50
|
return;
|
|
50
51
|
}
|
|
51
|
-
const { id:
|
|
52
|
+
const { id: r, type: o, path: a } = Object.assign({ path: [] }, i.data), l = (i.data.argumentList || []).map(F);
|
|
52
53
|
let h;
|
|
53
54
|
try {
|
|
54
|
-
const c = a.slice(0, -1).reduce((u, d) => u[d],
|
|
55
|
+
const c = a.slice(0, -1).reduce((u, d) => u[d], s), f = a.reduce((u, d) => u[d], s);
|
|
55
56
|
switch (o) {
|
|
56
57
|
case "GET":
|
|
57
58
|
h = f;
|
|
58
59
|
break;
|
|
59
60
|
case "SET":
|
|
60
|
-
c[a.slice(-1)[0]] = F(
|
|
61
|
+
c[a.slice(-1)[0]] = F(i.data.value), h = !0;
|
|
61
62
|
break;
|
|
62
63
|
case "APPLY":
|
|
63
64
|
h = f.apply(c, l);
|
|
@@ -65,13 +66,13 @@ function tt(n, t = globalThis, e = ["*"]) {
|
|
|
65
66
|
case "CONSTRUCT":
|
|
66
67
|
{
|
|
67
68
|
const u = new f(...l);
|
|
68
|
-
h =
|
|
69
|
+
h = Wt(u);
|
|
69
70
|
}
|
|
70
71
|
break;
|
|
71
72
|
case "ENDPOINT":
|
|
72
73
|
{
|
|
73
74
|
const { port1: u, port2: d } = new MessageChannel();
|
|
74
|
-
|
|
75
|
+
K(s, d), h = H(u, [u]);
|
|
75
76
|
}
|
|
76
77
|
break;
|
|
77
78
|
case "RELEASE":
|
|
@@ -81,462 +82,326 @@ function tt(n, t = globalThis, e = ["*"]) {
|
|
|
81
82
|
return;
|
|
82
83
|
}
|
|
83
84
|
} catch (c) {
|
|
84
|
-
h = { value: c, [
|
|
85
|
+
h = { value: c, [z]: 0 };
|
|
85
86
|
}
|
|
86
|
-
Promise.resolve(h).catch((c) => ({ value: c, [
|
|
87
|
-
const [f, u] =
|
|
88
|
-
t.postMessage(Object.assign(Object.assign({}, f), { id:
|
|
87
|
+
Promise.resolve(h).catch((c) => ({ value: c, [z]: 0 })).then((c) => {
|
|
88
|
+
const [f, u] = B(c);
|
|
89
|
+
t.postMessage(Object.assign(Object.assign({}, f), { id: r }), u), o === "RELEASE" && (t.removeEventListener("message", n), yt(t), q in s && typeof s[q] == "function" && s[q]());
|
|
89
90
|
}).catch((c) => {
|
|
90
|
-
const [f, u] =
|
|
91
|
+
const [f, u] = B({
|
|
91
92
|
value: new TypeError("Unserializable return value"),
|
|
92
|
-
[
|
|
93
|
+
[z]: 0
|
|
93
94
|
});
|
|
94
|
-
t.postMessage(Object.assign(Object.assign({}, f), { id:
|
|
95
|
+
t.postMessage(Object.assign(Object.assign({}, f), { id: r }), u);
|
|
95
96
|
});
|
|
96
97
|
}), t.start && t.start();
|
|
97
98
|
}
|
|
98
|
-
function
|
|
99
|
-
return
|
|
99
|
+
function kt(s) {
|
|
100
|
+
return s.constructor.name === "MessagePort";
|
|
100
101
|
}
|
|
101
|
-
function
|
|
102
|
-
|
|
102
|
+
function yt(s) {
|
|
103
|
+
kt(s) && s.close();
|
|
103
104
|
}
|
|
104
|
-
function
|
|
105
|
+
function Rt(s, t) {
|
|
105
106
|
const e = /* @__PURE__ */ new Map();
|
|
106
|
-
return
|
|
107
|
-
const { data:
|
|
108
|
-
if (!
|
|
107
|
+
return s.addEventListener("message", function(i) {
|
|
108
|
+
const { data: r } = i;
|
|
109
|
+
if (!r || !r.id)
|
|
109
110
|
return;
|
|
110
|
-
const o = e.get(
|
|
111
|
+
const o = e.get(r.id);
|
|
111
112
|
if (o)
|
|
112
113
|
try {
|
|
113
|
-
o(
|
|
114
|
+
o(r);
|
|
114
115
|
} finally {
|
|
115
|
-
e.delete(
|
|
116
|
+
e.delete(r.id);
|
|
116
117
|
}
|
|
117
|
-
}),
|
|
118
|
+
}), Z(s, e, [], t);
|
|
118
119
|
}
|
|
119
|
-
function
|
|
120
|
-
if (
|
|
120
|
+
function k(s) {
|
|
121
|
+
if (s)
|
|
121
122
|
throw new Error("Proxy has been released and is not useable");
|
|
122
123
|
}
|
|
123
|
-
function
|
|
124
|
-
return N(
|
|
124
|
+
function mt(s) {
|
|
125
|
+
return N(s, /* @__PURE__ */ new Map(), {
|
|
125
126
|
type: "RELEASE"
|
|
126
127
|
}).then(() => {
|
|
127
|
-
|
|
128
|
+
yt(s);
|
|
128
129
|
});
|
|
129
130
|
}
|
|
130
|
-
const
|
|
131
|
-
const t = (
|
|
132
|
-
|
|
131
|
+
const _ = /* @__PURE__ */ new WeakMap(), j = "FinalizationRegistry" in globalThis && new FinalizationRegistry((s) => {
|
|
132
|
+
const t = (_.get(s) || 0) - 1;
|
|
133
|
+
_.set(s, t), t === 0 && mt(s);
|
|
133
134
|
});
|
|
134
|
-
function
|
|
135
|
-
const e = (
|
|
136
|
-
|
|
135
|
+
function Lt(s, t) {
|
|
136
|
+
const e = (_.get(t) || 0) + 1;
|
|
137
|
+
_.set(t, e), j && j.register(s, t, s);
|
|
137
138
|
}
|
|
138
|
-
function
|
|
139
|
-
|
|
139
|
+
function zt(s) {
|
|
140
|
+
j && j.unregister(s);
|
|
140
141
|
}
|
|
141
|
-
function
|
|
142
|
+
function Z(s, t, e = [], n = function() {
|
|
142
143
|
}) {
|
|
143
|
-
let
|
|
144
|
-
const
|
|
144
|
+
let i = !1;
|
|
145
|
+
const r = new Proxy(n, {
|
|
145
146
|
get(o, a) {
|
|
146
|
-
if (
|
|
147
|
+
if (k(i), a === Tt)
|
|
147
148
|
return () => {
|
|
148
|
-
|
|
149
|
+
zt(r), mt(s), t.clear(), i = !0;
|
|
149
150
|
};
|
|
150
151
|
if (a === "then") {
|
|
151
152
|
if (e.length === 0)
|
|
152
|
-
return { then: () =>
|
|
153
|
-
const l = N(
|
|
153
|
+
return { then: () => r };
|
|
154
|
+
const l = N(s, t, {
|
|
154
155
|
type: "GET",
|
|
155
156
|
path: e.map((h) => h.toString())
|
|
156
157
|
}).then(F);
|
|
157
158
|
return l.then.bind(l);
|
|
158
159
|
}
|
|
159
|
-
return
|
|
160
|
+
return Z(s, t, [...e, a]);
|
|
160
161
|
},
|
|
161
162
|
set(o, a, l) {
|
|
162
|
-
|
|
163
|
-
const [h, c] =
|
|
164
|
-
return N(
|
|
163
|
+
k(i);
|
|
164
|
+
const [h, c] = B(l);
|
|
165
|
+
return N(s, t, {
|
|
165
166
|
type: "SET",
|
|
166
167
|
path: [...e, a].map((f) => f.toString()),
|
|
167
168
|
value: h
|
|
168
169
|
}, c).then(F);
|
|
169
170
|
},
|
|
170
171
|
apply(o, a, l) {
|
|
171
|
-
|
|
172
|
+
k(i);
|
|
172
173
|
const h = e[e.length - 1];
|
|
173
|
-
if (h ===
|
|
174
|
-
return N(
|
|
174
|
+
if (h === Ct)
|
|
175
|
+
return N(s, t, {
|
|
175
176
|
type: "ENDPOINT"
|
|
176
177
|
}).then(F);
|
|
177
178
|
if (h === "bind")
|
|
178
|
-
return
|
|
179
|
-
const [c, f] =
|
|
180
|
-
return N(
|
|
179
|
+
return Z(s, t, e.slice(0, -1));
|
|
180
|
+
const [c, f] = st(l);
|
|
181
|
+
return N(s, t, {
|
|
181
182
|
type: "APPLY",
|
|
182
183
|
path: e.map((u) => u.toString()),
|
|
183
184
|
argumentList: c
|
|
184
185
|
}, f).then(F);
|
|
185
186
|
},
|
|
186
187
|
construct(o, a) {
|
|
187
|
-
|
|
188
|
-
const [l, h] =
|
|
189
|
-
return N(
|
|
188
|
+
k(i);
|
|
189
|
+
const [l, h] = st(a);
|
|
190
|
+
return N(s, t, {
|
|
190
191
|
type: "CONSTRUCT",
|
|
191
192
|
path: e.map((c) => c.toString()),
|
|
192
193
|
argumentList: l
|
|
193
194
|
}, h).then(F);
|
|
194
195
|
}
|
|
195
196
|
});
|
|
196
|
-
return
|
|
197
|
+
return Lt(r, s), r;
|
|
197
198
|
}
|
|
198
|
-
function
|
|
199
|
-
return Array.prototype.concat.apply([],
|
|
199
|
+
function Ht(s) {
|
|
200
|
+
return Array.prototype.concat.apply([], s);
|
|
200
201
|
}
|
|
201
|
-
function
|
|
202
|
-
const t =
|
|
203
|
-
return [t.map((e) => e[0]),
|
|
202
|
+
function st(s) {
|
|
203
|
+
const t = s.map(B);
|
|
204
|
+
return [t.map((e) => e[0]), Ht(t.map((e) => e[1]))];
|
|
204
205
|
}
|
|
205
|
-
const
|
|
206
|
-
function
|
|
207
|
-
return
|
|
206
|
+
const Et = /* @__PURE__ */ new WeakMap();
|
|
207
|
+
function H(s, t) {
|
|
208
|
+
return Et.set(s, t), s;
|
|
208
209
|
}
|
|
209
|
-
function
|
|
210
|
-
return Object.assign(
|
|
210
|
+
function Wt(s) {
|
|
211
|
+
return Object.assign(s, { [pt]: !0 });
|
|
211
212
|
}
|
|
212
|
-
function
|
|
213
|
-
for (const [t, e] of
|
|
214
|
-
if (e.canHandle(
|
|
215
|
-
const [
|
|
213
|
+
function B(s) {
|
|
214
|
+
for (const [t, e] of wt)
|
|
215
|
+
if (e.canHandle(s)) {
|
|
216
|
+
const [n, i] = e.serialize(s);
|
|
216
217
|
return [
|
|
217
218
|
{
|
|
218
219
|
type: "HANDLER",
|
|
219
220
|
name: t,
|
|
220
|
-
value:
|
|
221
|
+
value: n
|
|
221
222
|
},
|
|
222
|
-
|
|
223
|
+
i
|
|
223
224
|
];
|
|
224
225
|
}
|
|
225
226
|
return [
|
|
226
227
|
{
|
|
227
228
|
type: "RAW",
|
|
228
|
-
value:
|
|
229
|
+
value: s
|
|
229
230
|
},
|
|
230
|
-
|
|
231
|
+
Et.get(s) || []
|
|
231
232
|
];
|
|
232
233
|
}
|
|
233
|
-
function F(
|
|
234
|
-
switch (
|
|
234
|
+
function F(s) {
|
|
235
|
+
switch (s.type) {
|
|
235
236
|
case "HANDLER":
|
|
236
|
-
return
|
|
237
|
+
return wt.get(s.name).deserialize(s.value);
|
|
237
238
|
case "RAW":
|
|
238
|
-
return
|
|
239
|
+
return s.value;
|
|
239
240
|
}
|
|
240
241
|
}
|
|
241
|
-
function N(
|
|
242
|
-
return new Promise((
|
|
243
|
-
const
|
|
244
|
-
t.set(
|
|
242
|
+
function N(s, t, e, n) {
|
|
243
|
+
return new Promise((i) => {
|
|
244
|
+
const r = _t();
|
|
245
|
+
t.set(r, i), s.start && s.start(), s.postMessage(Object.assign({ id: r }, e), n);
|
|
245
246
|
});
|
|
246
247
|
}
|
|
247
|
-
function
|
|
248
|
+
function _t() {
|
|
248
249
|
return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
|
|
249
250
|
}
|
|
250
251
|
class p extends Error {
|
|
251
|
-
constructor(t, e,
|
|
252
|
-
super(t, { cause:
|
|
252
|
+
constructor(t, e, n, i) {
|
|
253
|
+
super(t, { cause: i }), this.code = e, this.path = n, this.name = "OPFSError";
|
|
253
254
|
}
|
|
254
255
|
}
|
|
255
|
-
class
|
|
256
|
+
class jt extends p {
|
|
256
257
|
constructor(t) {
|
|
257
258
|
super("OPFS is not supported in this browser", "OPFS_NOT_SUPPORTED", void 0, t);
|
|
258
259
|
}
|
|
259
260
|
}
|
|
260
|
-
class
|
|
261
|
-
constructor(t, e,
|
|
262
|
-
super(t, "INVALID_PATH", e,
|
|
261
|
+
class Bt extends p {
|
|
262
|
+
constructor(t, e, n) {
|
|
263
|
+
super(t, "INVALID_PATH", e, n);
|
|
263
264
|
}
|
|
264
265
|
}
|
|
265
|
-
class
|
|
266
|
+
class nt extends p {
|
|
266
267
|
constructor(t, e) {
|
|
267
268
|
super(\`File not found: \${t}\`, "FILE_NOT_FOUND", t, e);
|
|
268
269
|
}
|
|
269
270
|
}
|
|
270
|
-
function
|
|
271
|
-
const
|
|
272
|
-
return new p(\`Failed to \${
|
|
271
|
+
function R(s, t, e, n) {
|
|
272
|
+
const i = \`\${s.toUpperCase()}_FAILED\`;
|
|
273
|
+
return new p(\`Failed to \${s} file descriptor: \${t}\`, i, e, n);
|
|
273
274
|
}
|
|
274
|
-
function
|
|
275
|
+
function Ut(s, t) {
|
|
275
276
|
const e = t?.path;
|
|
276
|
-
switch (
|
|
277
|
+
switch (s.name) {
|
|
277
278
|
case "InvalidStateError":
|
|
278
|
-
return new p(\`File is busy: \${e || "unknown"}\`, "EBUSY", e,
|
|
279
|
+
return new p(\`File is busy: \${e || "unknown"}\`, "EBUSY", e, s);
|
|
279
280
|
case "QuotaExceededError":
|
|
280
|
-
return new p(\`No space left on device: \${e || "unknown"}\`, "ENOSPC", e,
|
|
281
|
+
return new p(\`No space left on device: \${e || "unknown"}\`, "ENOSPC", e, s);
|
|
281
282
|
case "NotFoundError":
|
|
282
|
-
return new p(\`No such file or directory: \${e || "unknown"}\`, "ENOENT", e,
|
|
283
|
+
return new p(\`No such file or directory: \${e || "unknown"}\`, "ENOENT", e, s);
|
|
283
284
|
case "TypeMismatchError":
|
|
284
|
-
return new p(\`Is a directory: \${e || "unknown"}\`, "EISDIR", e,
|
|
285
|
+
return new p(\`Is a directory: \${e || "unknown"}\`, "EISDIR", e, s);
|
|
285
286
|
case "NotAllowedError":
|
|
286
287
|
case "SecurityError":
|
|
287
|
-
return new p(\`Permission denied: \${e || "unknown"}\`, "EACCES", e,
|
|
288
|
+
return new p(\`Permission denied: \${e || "unknown"}\`, "EACCES", e, s);
|
|
288
289
|
case "InvalidModificationError":
|
|
289
|
-
return new p(\`Invalid modification: \${e || "unknown"}\`, "EINVAL", e,
|
|
290
|
+
return new p(\`Invalid modification: \${e || "unknown"}\`, "EINVAL", e, s);
|
|
290
291
|
case "AbortError":
|
|
291
|
-
return new p(\`Operation aborted: \${e || "unknown"}\`, "EINTR", e,
|
|
292
|
+
return new p(\`Operation aborted: \${e || "unknown"}\`, "EINTR", e, s);
|
|
292
293
|
case "OperationError":
|
|
293
|
-
return new p(\`Operation failed: \${e || "unknown"}\`, "EIO", e,
|
|
294
|
+
return new p(\`Operation failed: \${e || "unknown"}\`, "EIO", e, s);
|
|
294
295
|
case "TypeError":
|
|
295
|
-
return new p(\`Operation not supported: \${e || "unknown"}\`, "ENOTSUP", e,
|
|
296
|
+
return new p(\`Operation not supported: \${e || "unknown"}\`, "ENOTSUP", e, s);
|
|
296
297
|
default:
|
|
297
|
-
return new p(\`I/O error: \${e || "unknown"}\`, "EIO", e,
|
|
298
|
+
return new p(\`I/O error: \${e || "unknown"}\`, "EIO", e, s);
|
|
298
299
|
}
|
|
299
300
|
}
|
|
300
|
-
const
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
".ico",
|
|
309
|
-
".tiff",
|
|
310
|
-
".tga",
|
|
311
|
-
// Audio
|
|
312
|
-
".mp3",
|
|
313
|
-
".wav",
|
|
314
|
-
".ogg",
|
|
315
|
-
".flac",
|
|
316
|
-
".aac",
|
|
317
|
-
".wma",
|
|
318
|
-
".m4a",
|
|
319
|
-
// Video
|
|
320
|
-
".mp4",
|
|
321
|
-
".avi",
|
|
322
|
-
".mov",
|
|
323
|
-
".wmv",
|
|
324
|
-
".flv",
|
|
325
|
-
".webm",
|
|
326
|
-
".mkv",
|
|
327
|
-
".m4v",
|
|
328
|
-
// Documents
|
|
329
|
-
".pdf",
|
|
330
|
-
".doc",
|
|
331
|
-
".docx",
|
|
332
|
-
".xls",
|
|
333
|
-
".xlsx",
|
|
334
|
-
".ppt",
|
|
335
|
-
".pptx",
|
|
336
|
-
// Archives
|
|
337
|
-
".zip",
|
|
338
|
-
".rar",
|
|
339
|
-
".7z",
|
|
340
|
-
".tar",
|
|
341
|
-
".gz",
|
|
342
|
-
".bz2",
|
|
343
|
-
// Executables
|
|
344
|
-
".exe",
|
|
345
|
-
".dll",
|
|
346
|
-
".so",
|
|
347
|
-
".dylib",
|
|
348
|
-
// Other binary formats
|
|
349
|
-
".dat",
|
|
350
|
-
".db",
|
|
351
|
-
".sqlite",
|
|
352
|
-
".bin",
|
|
353
|
-
".obj",
|
|
354
|
-
".fbx",
|
|
355
|
-
".3ds"
|
|
356
|
-
];
|
|
357
|
-
function V(n) {
|
|
358
|
-
const t = n.lastIndexOf(".");
|
|
359
|
-
if (t <= 0)
|
|
360
|
-
return !0;
|
|
361
|
-
const e = n.slice(t).toLowerCase();
|
|
362
|
-
return Xt.includes(e);
|
|
363
|
-
}
|
|
364
|
-
function Yt(n, t = "utf-8") {
|
|
365
|
-
switch (t) {
|
|
366
|
-
case "utf8":
|
|
367
|
-
case "utf-8":
|
|
368
|
-
return new TextEncoder().encode(n);
|
|
369
|
-
case "utf16le":
|
|
370
|
-
case "ucs2":
|
|
371
|
-
case "ucs-2":
|
|
372
|
-
return Jt(n);
|
|
373
|
-
case "ascii":
|
|
374
|
-
return te(n);
|
|
375
|
-
case "latin1":
|
|
376
|
-
return Qt(n);
|
|
377
|
-
case "binary":
|
|
378
|
-
return Uint8Array.from(n, (e) => e.charCodeAt(0));
|
|
379
|
-
case "base64":
|
|
380
|
-
return Uint8Array.from(atob(n), (e) => e.charCodeAt(0));
|
|
381
|
-
case "hex":
|
|
382
|
-
if (!/^[\\da-f]+$/i.test(n) || n.length % 2 !== 0)
|
|
383
|
-
throw new p("Invalid hex string", "INVALID_HEX_FORMAT");
|
|
384
|
-
return Uint8Array.from(n.match(/.{1,2}/g).map((e) => parseInt(e, 16)));
|
|
385
|
-
default:
|
|
386
|
-
return console.warn("Encoding not supported, falling back to UTF-8"), new TextEncoder().encode(n);
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
function Zt(n, t = "utf-8") {
|
|
390
|
-
switch (t) {
|
|
391
|
-
case "utf8":
|
|
392
|
-
case "utf-8":
|
|
393
|
-
return new TextDecoder().decode(n);
|
|
394
|
-
case "utf16le":
|
|
395
|
-
case "utf-16le":
|
|
396
|
-
case "ucs2":
|
|
397
|
-
case "ucs-2":
|
|
398
|
-
return Kt(n);
|
|
399
|
-
case "latin1":
|
|
400
|
-
return String.fromCharCode(...n);
|
|
401
|
-
case "ascii":
|
|
402
|
-
return String.fromCharCode(...n.map((e) => e & 127));
|
|
403
|
-
case "base64":
|
|
404
|
-
return btoa(String.fromCharCode(...n));
|
|
405
|
-
case "hex":
|
|
406
|
-
return Array.from(n).map((e) => e.toString(16).padStart(2, "0")).join("");
|
|
407
|
-
default:
|
|
408
|
-
return console.warn("Unsupported encoding, falling back to UTF-8"), new TextDecoder().decode(n);
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
function Jt(n) {
|
|
412
|
-
const t = new Uint8Array(n.length * 2);
|
|
413
|
-
for (let e = 0; e < n.length; e++) {
|
|
414
|
-
const s = n.charCodeAt(e);
|
|
415
|
-
t[e * 2] = s & 255, t[e * 2 + 1] = s >> 8;
|
|
416
|
-
}
|
|
417
|
-
return t;
|
|
418
|
-
}
|
|
419
|
-
function Kt(n) {
|
|
420
|
-
n.length % 2 !== 0 && (console.warn("Invalid UTF-16LE buffer length, truncating last byte"), n = n.slice(0, n.length - 1));
|
|
421
|
-
const t = new Uint16Array(n.buffer, n.byteOffset, n.byteLength / 2);
|
|
422
|
-
return String.fromCharCode(...t);
|
|
423
|
-
}
|
|
424
|
-
function Qt(n) {
|
|
425
|
-
const t = new Uint8Array(n.length);
|
|
426
|
-
for (let e = 0; e < n.length; e++)
|
|
427
|
-
t[e] = n.charCodeAt(e) & 255;
|
|
428
|
-
return t;
|
|
429
|
-
}
|
|
430
|
-
function te(n) {
|
|
431
|
-
const t = new Uint8Array(n.length);
|
|
432
|
-
for (let e = 0; e < n.length; e++)
|
|
433
|
-
t[e] = n.charCodeAt(e) & 127;
|
|
434
|
-
return t;
|
|
435
|
-
}
|
|
436
|
-
const bt = (n, t, e) => {
|
|
437
|
-
const s = n instanceof RegExp ? it(n, e) : n, r = t instanceof RegExp ? it(t, e) : t, i = s !== null && r != null && ee(s, r, e);
|
|
438
|
-
return i && {
|
|
439
|
-
start: i[0],
|
|
440
|
-
end: i[1],
|
|
441
|
-
pre: e.slice(0, i[0]),
|
|
442
|
-
body: e.slice(i[0] + s.length, i[1]),
|
|
443
|
-
post: e.slice(i[1] + r.length)
|
|
301
|
+
const St = (s, t, e) => {
|
|
302
|
+
const n = s instanceof RegExp ? it(s, e) : s, i = t instanceof RegExp ? it(t, e) : t, r = n !== null && i != null && Gt(n, i, e);
|
|
303
|
+
return r && {
|
|
304
|
+
start: r[0],
|
|
305
|
+
end: r[1],
|
|
306
|
+
pre: e.slice(0, r[0]),
|
|
307
|
+
body: e.slice(r[0] + n.length, r[1]),
|
|
308
|
+
post: e.slice(r[1] + i.length)
|
|
444
309
|
};
|
|
445
|
-
}, it = (
|
|
446
|
-
const e = t.match(
|
|
310
|
+
}, it = (s, t) => {
|
|
311
|
+
const e = t.match(s);
|
|
447
312
|
return e ? e[0] : null;
|
|
448
|
-
},
|
|
449
|
-
let
|
|
313
|
+
}, Gt = (s, t, e) => {
|
|
314
|
+
let n, i, r, o, a, l = e.indexOf(s), h = e.indexOf(t, l + 1), c = l;
|
|
450
315
|
if (l >= 0 && h > 0) {
|
|
451
|
-
if (
|
|
316
|
+
if (s === t)
|
|
452
317
|
return [l, h];
|
|
453
|
-
for (
|
|
318
|
+
for (n = [], r = e.length; c >= 0 && !a; ) {
|
|
454
319
|
if (c === l)
|
|
455
|
-
|
|
456
|
-
else if (
|
|
457
|
-
const f =
|
|
320
|
+
n.push(c), l = e.indexOf(s, c + 1);
|
|
321
|
+
else if (n.length === 1) {
|
|
322
|
+
const f = n.pop();
|
|
458
323
|
f !== void 0 && (a = [f, h]);
|
|
459
324
|
} else
|
|
460
|
-
|
|
325
|
+
i = n.pop(), i !== void 0 && i < r && (r = i, o = h), h = e.indexOf(t, c + 1);
|
|
461
326
|
c = l < h && l >= 0 ? l : h;
|
|
462
327
|
}
|
|
463
|
-
|
|
328
|
+
n.length && o !== void 0 && (a = [r, o]);
|
|
464
329
|
}
|
|
465
330
|
return a;
|
|
466
|
-
},
|
|
467
|
-
function
|
|
468
|
-
return isNaN(
|
|
331
|
+
}, xt = "\\0SLASH" + Math.random() + "\\0", bt = "\\0OPEN" + Math.random() + "\\0", Q = "\\0CLOSE" + Math.random() + "\\0", vt = "\\0COMMA" + Math.random() + "\\0", At = "\\0PERIOD" + Math.random() + "\\0", qt = new RegExp(xt, "g"), Vt = new RegExp(bt, "g"), Xt = new RegExp(Q, "g"), Yt = new RegExp(vt, "g"), Zt = new RegExp(At, "g"), Jt = /\\\\\\\\/g, Kt = /\\\\{/g, Qt = /\\\\}/g, te = /\\\\,/g, ee = /\\\\./g;
|
|
332
|
+
function V(s) {
|
|
333
|
+
return isNaN(s) ? s.charCodeAt(0) : parseInt(s, 10);
|
|
469
334
|
}
|
|
470
|
-
function
|
|
471
|
-
return
|
|
335
|
+
function se(s) {
|
|
336
|
+
return s.replace(Jt, xt).replace(Kt, bt).replace(Qt, Q).replace(te, vt).replace(ee, At);
|
|
472
337
|
}
|
|
473
|
-
function
|
|
474
|
-
return
|
|
338
|
+
function ne(s) {
|
|
339
|
+
return s.replace(qt, "\\\\").replace(Vt, "{").replace(Xt, "}").replace(Yt, ",").replace(Zt, ".");
|
|
475
340
|
}
|
|
476
|
-
function
|
|
477
|
-
if (!
|
|
341
|
+
function Ft(s) {
|
|
342
|
+
if (!s)
|
|
478
343
|
return [""];
|
|
479
|
-
const t = [], e =
|
|
344
|
+
const t = [], e = St("{", "}", s);
|
|
480
345
|
if (!e)
|
|
481
|
-
return
|
|
482
|
-
const { pre:
|
|
483
|
-
o[o.length - 1] += "{" +
|
|
484
|
-
const a =
|
|
485
|
-
return
|
|
346
|
+
return s.split(",");
|
|
347
|
+
const { pre: n, body: i, post: r } = e, o = n.split(",");
|
|
348
|
+
o[o.length - 1] += "{" + i + "}";
|
|
349
|
+
const a = Ft(r);
|
|
350
|
+
return r.length && (o[o.length - 1] += a.shift(), o.push.apply(o, a)), t.push.apply(t, o), t;
|
|
486
351
|
}
|
|
487
|
-
function
|
|
488
|
-
return
|
|
352
|
+
function ie(s) {
|
|
353
|
+
return s ? (s.slice(0, 2) === "{}" && (s = "\\\\{\\\\}" + s.slice(2)), T(se(s), !0).map(ne)) : [];
|
|
489
354
|
}
|
|
490
|
-
function
|
|
491
|
-
return "{" +
|
|
355
|
+
function re(s) {
|
|
356
|
+
return "{" + s + "}";
|
|
492
357
|
}
|
|
493
|
-
function
|
|
494
|
-
return /^-?0\\d/.test(
|
|
358
|
+
function oe(s) {
|
|
359
|
+
return /^-?0\\d/.test(s);
|
|
495
360
|
}
|
|
496
|
-
function
|
|
497
|
-
return
|
|
361
|
+
function ae(s, t) {
|
|
362
|
+
return s <= t;
|
|
498
363
|
}
|
|
499
|
-
function
|
|
500
|
-
return
|
|
364
|
+
function ce(s, t) {
|
|
365
|
+
return s >= t;
|
|
501
366
|
}
|
|
502
|
-
function T(
|
|
503
|
-
const e = [],
|
|
504
|
-
if (!
|
|
505
|
-
return [
|
|
506
|
-
const
|
|
507
|
-
if (/\\$$/.test(
|
|
508
|
-
for (let o = 0; o <
|
|
509
|
-
const a =
|
|
367
|
+
function T(s, t) {
|
|
368
|
+
const e = [], n = St("{", "}", s);
|
|
369
|
+
if (!n)
|
|
370
|
+
return [s];
|
|
371
|
+
const i = n.pre, r = n.post.length ? T(n.post, !1) : [""];
|
|
372
|
+
if (/\\$$/.test(n.pre))
|
|
373
|
+
for (let o = 0; o < r.length; o++) {
|
|
374
|
+
const a = i + "{" + n.body + "}" + r[o];
|
|
510
375
|
e.push(a);
|
|
511
376
|
}
|
|
512
377
|
else {
|
|
513
|
-
const o = /^-?\\d+\\.\\.-?\\d+(?:\\.\\.-?\\d+)?$/.test(
|
|
378
|
+
const o = /^-?\\d+\\.\\.-?\\d+(?:\\.\\.-?\\d+)?$/.test(n.body), a = /^[a-zA-Z]\\.\\.[a-zA-Z](?:\\.\\.-?\\d+)?$/.test(n.body), l = o || a, h = n.body.indexOf(",") >= 0;
|
|
514
379
|
if (!l && !h)
|
|
515
|
-
return
|
|
380
|
+
return n.post.match(/,(?!,).*\\}/) ? (s = n.pre + "{" + n.body + Q + n.post, T(s)) : [s];
|
|
516
381
|
let c;
|
|
517
382
|
if (l)
|
|
518
|
-
c =
|
|
519
|
-
else if (c =
|
|
520
|
-
return
|
|
383
|
+
c = n.body.split(/\\.\\./);
|
|
384
|
+
else if (c = Ft(n.body), c.length === 1 && c[0] !== void 0 && (c = T(c[0], !1).map(re), c.length === 1))
|
|
385
|
+
return r.map((u) => n.pre + c[0] + u);
|
|
521
386
|
let f;
|
|
522
387
|
if (l && c[0] !== void 0 && c[1] !== void 0) {
|
|
523
|
-
const u =
|
|
524
|
-
let g = c.length === 3 && c[2] !== void 0 ? Math.abs(
|
|
525
|
-
d < u && (g *= -1, S =
|
|
526
|
-
const
|
|
388
|
+
const u = V(c[0]), d = V(c[1]), w = Math.max(c[0].length, c[1].length);
|
|
389
|
+
let g = c.length === 3 && c[2] !== void 0 ? Math.abs(V(c[2])) : 1, S = ae;
|
|
390
|
+
d < u && (g *= -1, S = ce);
|
|
391
|
+
const O = c.some(oe);
|
|
527
392
|
f = [];
|
|
528
393
|
for (let x = u; S(x, d); x += g) {
|
|
529
|
-
let
|
|
394
|
+
let y;
|
|
530
395
|
if (a)
|
|
531
|
-
|
|
532
|
-
else if (
|
|
533
|
-
const
|
|
534
|
-
if (
|
|
535
|
-
const
|
|
536
|
-
x < 0 ?
|
|
396
|
+
y = String.fromCharCode(x), y === "\\\\" && (y = "");
|
|
397
|
+
else if (y = String(x), O) {
|
|
398
|
+
const $ = w - y.length;
|
|
399
|
+
if ($ > 0) {
|
|
400
|
+
const I = new Array($ + 1).join("0");
|
|
401
|
+
x < 0 ? y = "-" + I + y.slice(1) : y = I + y;
|
|
537
402
|
}
|
|
538
403
|
}
|
|
539
|
-
f.push(
|
|
404
|
+
f.push(y);
|
|
540
405
|
}
|
|
541
406
|
} else {
|
|
542
407
|
f = [];
|
|
@@ -544,19 +409,19 @@ function T(n, t) {
|
|
|
544
409
|
f.push.apply(f, T(c[u], !1));
|
|
545
410
|
}
|
|
546
411
|
for (let u = 0; u < f.length; u++)
|
|
547
|
-
for (let d = 0; d <
|
|
548
|
-
const w =
|
|
412
|
+
for (let d = 0; d < r.length; d++) {
|
|
413
|
+
const w = i + f[u] + r[d];
|
|
549
414
|
(!t || l || w) && e.push(w);
|
|
550
415
|
}
|
|
551
416
|
}
|
|
552
417
|
return e;
|
|
553
418
|
}
|
|
554
|
-
const
|
|
555
|
-
if (typeof
|
|
419
|
+
const le = 1024 * 64, U = (s) => {
|
|
420
|
+
if (typeof s != "string")
|
|
556
421
|
throw new TypeError("invalid pattern");
|
|
557
|
-
if (
|
|
422
|
+
if (s.length > le)
|
|
558
423
|
throw new TypeError("pattern is too long");
|
|
559
|
-
},
|
|
424
|
+
}, he = {
|
|
560
425
|
"[:alnum:]": ["\\\\p{L}\\\\p{Nl}\\\\p{Nd}", !0],
|
|
561
426
|
"[:alpha:]": ["\\\\p{L}\\\\p{Nl}", !0],
|
|
562
427
|
"[:ascii:]": ["\\\\x00-\\\\x7f", !1],
|
|
@@ -571,92 +436,92 @@ const Ee = 1024 * 64, j = (n) => {
|
|
|
571
436
|
"[:upper:]": ["\\\\p{Lu}", !0],
|
|
572
437
|
"[:word:]": ["\\\\p{L}\\\\p{Nl}\\\\p{Nd}\\\\p{Pc}", !0],
|
|
573
438
|
"[:xdigit:]": ["A-Fa-f0-9", !1]
|
|
574
|
-
},
|
|
439
|
+
}, C = (s) => s.replace(/[[\\]\\\\-]/g, "\\\\$&"), ue = (s) => s.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, "\\\\$&"), rt = (s) => s.join(""), fe = (s, t) => {
|
|
575
440
|
const e = t;
|
|
576
|
-
if (
|
|
441
|
+
if (s.charAt(e) !== "[")
|
|
577
442
|
throw new Error("not in a brace expression");
|
|
578
|
-
const
|
|
579
|
-
let
|
|
580
|
-
t: for (;
|
|
581
|
-
const g =
|
|
582
|
-
if ((g === "!" || g === "^") &&
|
|
583
|
-
h = !0,
|
|
443
|
+
const n = [], i = [];
|
|
444
|
+
let r = e + 1, o = !1, a = !1, l = !1, h = !1, c = e, f = "";
|
|
445
|
+
t: for (; r < s.length; ) {
|
|
446
|
+
const g = s.charAt(r);
|
|
447
|
+
if ((g === "!" || g === "^") && r === e + 1) {
|
|
448
|
+
h = !0, r++;
|
|
584
449
|
continue;
|
|
585
450
|
}
|
|
586
451
|
if (g === "]" && o && !l) {
|
|
587
|
-
c =
|
|
452
|
+
c = r + 1;
|
|
588
453
|
break;
|
|
589
454
|
}
|
|
590
455
|
if (o = !0, g === "\\\\" && !l) {
|
|
591
|
-
l = !0,
|
|
456
|
+
l = !0, r++;
|
|
592
457
|
continue;
|
|
593
458
|
}
|
|
594
459
|
if (g === "[" && !l) {
|
|
595
|
-
for (const [S, [A,
|
|
596
|
-
if (
|
|
460
|
+
for (const [S, [A, O, x]] of Object.entries(he))
|
|
461
|
+
if (s.startsWith(S, r)) {
|
|
597
462
|
if (f)
|
|
598
|
-
return ["$.", !1,
|
|
599
|
-
|
|
463
|
+
return ["$.", !1, s.length - e, !0];
|
|
464
|
+
r += S.length, x ? i.push(A) : n.push(A), a = a || O;
|
|
600
465
|
continue t;
|
|
601
466
|
}
|
|
602
467
|
}
|
|
603
468
|
if (l = !1, f) {
|
|
604
|
-
g > f ?
|
|
469
|
+
g > f ? n.push(C(f) + "-" + C(g)) : g === f && n.push(C(g)), f = "", r++;
|
|
605
470
|
continue;
|
|
606
471
|
}
|
|
607
|
-
if (
|
|
608
|
-
|
|
472
|
+
if (s.startsWith("-]", r + 1)) {
|
|
473
|
+
n.push(C(g + "-")), r += 2;
|
|
609
474
|
continue;
|
|
610
475
|
}
|
|
611
|
-
if (
|
|
612
|
-
f = g,
|
|
476
|
+
if (s.startsWith("-", r + 1)) {
|
|
477
|
+
f = g, r += 2;
|
|
613
478
|
continue;
|
|
614
479
|
}
|
|
615
|
-
|
|
480
|
+
n.push(C(g)), r++;
|
|
616
481
|
}
|
|
617
|
-
if (c <
|
|
482
|
+
if (c < r)
|
|
618
483
|
return ["", !1, 0, !1];
|
|
619
|
-
if (!
|
|
620
|
-
return ["$.", !1,
|
|
621
|
-
if (
|
|
622
|
-
const g =
|
|
623
|
-
return [
|
|
624
|
-
}
|
|
625
|
-
const u = "[" + (h ? "^" : "") +
|
|
626
|
-
return [
|
|
627
|
-
},
|
|
484
|
+
if (!n.length && !i.length)
|
|
485
|
+
return ["$.", !1, s.length - e, !0];
|
|
486
|
+
if (i.length === 0 && n.length === 1 && /^\\\\?.$/.test(n[0]) && !h) {
|
|
487
|
+
const g = n[0].length === 2 ? n[0].slice(-1) : n[0];
|
|
488
|
+
return [ue(g), !1, c - e, !1];
|
|
489
|
+
}
|
|
490
|
+
const u = "[" + (h ? "^" : "") + rt(n) + "]", d = "[" + (h ? "" : "^") + rt(i) + "]";
|
|
491
|
+
return [n.length && i.length ? "(" + u + "|" + d + ")" : n.length ? u : d, a, c - e, !0];
|
|
492
|
+
}, M = (s, { windowsPathsNoEscape: t = !1 } = {}) => t ? s.replace(/\\[([^\\/\\\\])\\]/g, "$1") : s.replace(/((?!\\\\).|^)\\[([^\\/\\\\])\\]/g, "$1$2").replace(/\\\\([^\\/])/g, "$1"), de = /* @__PURE__ */ new Set(["!", "?", "+", "*", "@"]), ot = (s) => de.has(s), pe = "(?!(?:^|/)\\\\.\\\\.?(?:$|/))", L = "(?!\\\\.)", ge = /* @__PURE__ */ new Set(["[", "."]), we = /* @__PURE__ */ new Set(["..", "."]), ye = new Set("().*{}+?[]^$\\\\!"), me = (s) => s.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, "\\\\$&"), tt = "[^/]", at = tt + "*?", ct = tt + "+?";
|
|
628
493
|
class E {
|
|
629
494
|
type;
|
|
630
|
-
#n;
|
|
631
495
|
#s;
|
|
632
|
-
#
|
|
496
|
+
#n;
|
|
497
|
+
#r = !1;
|
|
633
498
|
#t = [];
|
|
634
499
|
#e;
|
|
635
500
|
#o;
|
|
636
501
|
#c;
|
|
637
502
|
#a = !1;
|
|
638
|
-
#
|
|
503
|
+
#i;
|
|
639
504
|
#l;
|
|
640
505
|
// set to true if it's an extglob with no children
|
|
641
506
|
// (which really means one child of '')
|
|
642
507
|
#u = !1;
|
|
643
|
-
constructor(t, e,
|
|
644
|
-
this.type = t, t && (this.#
|
|
508
|
+
constructor(t, e, n = {}) {
|
|
509
|
+
this.type = t, t && (this.#n = !0), this.#e = e, this.#s = this.#e ? this.#e.#s : this, this.#i = this.#s === this ? n : this.#s.#i, this.#c = this.#s === this ? [] : this.#s.#c, t === "!" && !this.#s.#a && this.#c.push(this), this.#o = this.#e ? this.#e.#t.length : 0;
|
|
645
510
|
}
|
|
646
511
|
get hasMagic() {
|
|
647
|
-
if (this.#
|
|
648
|
-
return this.#
|
|
512
|
+
if (this.#n !== void 0)
|
|
513
|
+
return this.#n;
|
|
649
514
|
for (const t of this.#t)
|
|
650
515
|
if (typeof t != "string" && (t.type || t.hasMagic))
|
|
651
|
-
return this.#
|
|
652
|
-
return this.#
|
|
516
|
+
return this.#n = !0;
|
|
517
|
+
return this.#n;
|
|
653
518
|
}
|
|
654
519
|
// reconstructs the pattern
|
|
655
520
|
toString() {
|
|
656
521
|
return this.#l !== void 0 ? this.#l : this.type ? this.#l = this.type + "(" + this.#t.map((t) => String(t)).join("|") + ")" : this.#l = this.#t.map((t) => String(t)).join("");
|
|
657
522
|
}
|
|
658
523
|
#d() {
|
|
659
|
-
if (this !== this.#
|
|
524
|
+
if (this !== this.#s)
|
|
660
525
|
throw new Error("should only call on root");
|
|
661
526
|
if (this.#a)
|
|
662
527
|
return this;
|
|
@@ -665,15 +530,15 @@ class E {
|
|
|
665
530
|
for (; t = this.#c.pop(); ) {
|
|
666
531
|
if (t.type !== "!")
|
|
667
532
|
continue;
|
|
668
|
-
let e = t,
|
|
669
|
-
for (;
|
|
670
|
-
for (let
|
|
671
|
-
for (const
|
|
672
|
-
if (typeof
|
|
533
|
+
let e = t, n = e.#e;
|
|
534
|
+
for (; n; ) {
|
|
535
|
+
for (let i = e.#o + 1; !n.type && i < n.#t.length; i++)
|
|
536
|
+
for (const r of t.#t) {
|
|
537
|
+
if (typeof r == "string")
|
|
673
538
|
throw new Error("string part in extglob AST??");
|
|
674
|
-
|
|
539
|
+
r.copyIn(n.#t[i]);
|
|
675
540
|
}
|
|
676
|
-
e =
|
|
541
|
+
e = n, n = e.#e;
|
|
677
542
|
}
|
|
678
543
|
}
|
|
679
544
|
return this;
|
|
@@ -688,10 +553,10 @@ class E {
|
|
|
688
553
|
}
|
|
689
554
|
toJSON() {
|
|
690
555
|
const t = this.type === null ? this.#t.slice().map((e) => typeof e == "string" ? e : e.toJSON()) : [this.type, ...this.#t.map((e) => e.toJSON())];
|
|
691
|
-
return this.isStart() && !this.type && t.unshift([]), this.isEnd() && (this === this.#
|
|
556
|
+
return this.isStart() && !this.type && t.unshift([]), this.isEnd() && (this === this.#s || this.#s.#a && this.#e?.type === "!") && t.push({}), t;
|
|
692
557
|
}
|
|
693
558
|
isStart() {
|
|
694
|
-
if (this.#
|
|
559
|
+
if (this.#s === this)
|
|
695
560
|
return !0;
|
|
696
561
|
if (!this.#e?.isStart())
|
|
697
562
|
return !1;
|
|
@@ -699,14 +564,14 @@ class E {
|
|
|
699
564
|
return !0;
|
|
700
565
|
const t = this.#e;
|
|
701
566
|
for (let e = 0; e < this.#o; e++) {
|
|
702
|
-
const
|
|
703
|
-
if (!(
|
|
567
|
+
const n = t.#t[e];
|
|
568
|
+
if (!(n instanceof E && n.type === "!"))
|
|
704
569
|
return !1;
|
|
705
570
|
}
|
|
706
571
|
return !0;
|
|
707
572
|
}
|
|
708
573
|
isEnd() {
|
|
709
|
-
if (this.#
|
|
574
|
+
if (this.#s === this || this.#e?.type === "!")
|
|
710
575
|
return !0;
|
|
711
576
|
if (!this.#e?.isEnd())
|
|
712
577
|
return !1;
|
|
@@ -720,18 +585,18 @@ class E {
|
|
|
720
585
|
}
|
|
721
586
|
clone(t) {
|
|
722
587
|
const e = new E(this.type, t);
|
|
723
|
-
for (const
|
|
724
|
-
e.copyIn(
|
|
588
|
+
for (const n of this.#t)
|
|
589
|
+
e.copyIn(n);
|
|
725
590
|
return e;
|
|
726
591
|
}
|
|
727
|
-
static #h(t, e,
|
|
728
|
-
let
|
|
592
|
+
static #h(t, e, n, i) {
|
|
593
|
+
let r = !1, o = !1, a = -1, l = !1;
|
|
729
594
|
if (e.type === null) {
|
|
730
|
-
let d =
|
|
595
|
+
let d = n, w = "";
|
|
731
596
|
for (; d < t.length; ) {
|
|
732
597
|
const g = t.charAt(d++);
|
|
733
|
-
if (
|
|
734
|
-
|
|
598
|
+
if (r || g === "\\\\") {
|
|
599
|
+
r = !r, w += g;
|
|
735
600
|
continue;
|
|
736
601
|
}
|
|
737
602
|
if (o) {
|
|
@@ -741,23 +606,23 @@ class E {
|
|
|
741
606
|
o = !0, a = d, l = !1, w += g;
|
|
742
607
|
continue;
|
|
743
608
|
}
|
|
744
|
-
if (!
|
|
609
|
+
if (!i.noext && ot(g) && t.charAt(d) === "(") {
|
|
745
610
|
e.push(w), w = "";
|
|
746
611
|
const S = new E(g, e);
|
|
747
|
-
d = E.#h(t, S, d,
|
|
612
|
+
d = E.#h(t, S, d, i), e.push(S);
|
|
748
613
|
continue;
|
|
749
614
|
}
|
|
750
615
|
w += g;
|
|
751
616
|
}
|
|
752
617
|
return e.push(w), d;
|
|
753
618
|
}
|
|
754
|
-
let h =
|
|
619
|
+
let h = n + 1, c = new E(null, e);
|
|
755
620
|
const f = [];
|
|
756
621
|
let u = "";
|
|
757
622
|
for (; h < t.length; ) {
|
|
758
623
|
const d = t.charAt(h++);
|
|
759
|
-
if (
|
|
760
|
-
|
|
624
|
+
if (r || d === "\\\\") {
|
|
625
|
+
r = !r, u += d;
|
|
761
626
|
continue;
|
|
762
627
|
}
|
|
763
628
|
if (o) {
|
|
@@ -767,10 +632,10 @@ class E {
|
|
|
767
632
|
o = !0, a = h, l = !1, u += d;
|
|
768
633
|
continue;
|
|
769
634
|
}
|
|
770
|
-
if (
|
|
635
|
+
if (ot(d) && t.charAt(h) === "(") {
|
|
771
636
|
c.push(u), u = "";
|
|
772
637
|
const w = new E(d, c);
|
|
773
|
-
c.push(w), h = E.#h(t, w, h,
|
|
638
|
+
c.push(w), h = E.#h(t, w, h, i);
|
|
774
639
|
continue;
|
|
775
640
|
}
|
|
776
641
|
if (d === "|") {
|
|
@@ -781,28 +646,28 @@ class E {
|
|
|
781
646
|
return u === "" && e.#t.length === 0 && (e.#u = !0), c.push(u), u = "", e.push(...f, c), h;
|
|
782
647
|
u += d;
|
|
783
648
|
}
|
|
784
|
-
return e.type = null, e.#
|
|
649
|
+
return e.type = null, e.#n = void 0, e.#t = [t.substring(n - 1)], h;
|
|
785
650
|
}
|
|
786
651
|
static fromGlob(t, e = {}) {
|
|
787
|
-
const
|
|
788
|
-
return E.#h(t,
|
|
652
|
+
const n = new E(null, void 0, e);
|
|
653
|
+
return E.#h(t, n, 0, e), n;
|
|
789
654
|
}
|
|
790
655
|
// returns the regular expression if there's magic, or the unescaped
|
|
791
656
|
// string if not.
|
|
792
657
|
toMMPattern() {
|
|
793
|
-
if (this !== this.#
|
|
794
|
-
return this.#
|
|
795
|
-
const t = this.toString(), [e,
|
|
796
|
-
if (!(
|
|
797
|
-
return
|
|
798
|
-
const a = (this.#
|
|
658
|
+
if (this !== this.#s)
|
|
659
|
+
return this.#s.toMMPattern();
|
|
660
|
+
const t = this.toString(), [e, n, i, r] = this.toRegExpSource();
|
|
661
|
+
if (!(i || this.#n || this.#i.nocase && !this.#i.nocaseMagicOnly && t.toUpperCase() !== t.toLowerCase()))
|
|
662
|
+
return n;
|
|
663
|
+
const a = (this.#i.nocase ? "i" : "") + (r ? "u" : "");
|
|
799
664
|
return Object.assign(new RegExp(\`^\${e}$\`, a), {
|
|
800
665
|
_src: e,
|
|
801
666
|
_glob: t
|
|
802
667
|
});
|
|
803
668
|
}
|
|
804
669
|
get options() {
|
|
805
|
-
return this.#
|
|
670
|
+
return this.#i;
|
|
806
671
|
}
|
|
807
672
|
// returns the string match, the regexp source, whether there's magic
|
|
808
673
|
// in the regexp (so a regular expression is required) and whether or
|
|
@@ -874,168 +739,168 @@ class E {
|
|
|
874
739
|
// is ^(?!\\.), we can just prepend (?!\\.) to the pattern (either root
|
|
875
740
|
// or start or whatever) and prepend ^ or / at the Regexp construction.
|
|
876
741
|
toRegExpSource(t) {
|
|
877
|
-
const e = t ?? !!this.#
|
|
878
|
-
if (this.#
|
|
742
|
+
const e = t ?? !!this.#i.dot;
|
|
743
|
+
if (this.#s === this && this.#d(), !this.type) {
|
|
879
744
|
const l = this.isStart() && this.isEnd(), h = this.#t.map((d) => {
|
|
880
|
-
const [w, g, S, A] = typeof d == "string" ? E.#p(d, this.#
|
|
881
|
-
return this.#
|
|
745
|
+
const [w, g, S, A] = typeof d == "string" ? E.#p(d, this.#n, l) : d.toRegExpSource(t);
|
|
746
|
+
return this.#n = this.#n || S, this.#r = this.#r || A, w;
|
|
882
747
|
}).join("");
|
|
883
748
|
let c = "";
|
|
884
|
-
if (this.isStart() && typeof this.#t[0] == "string" && !(this.#t.length === 1 &&
|
|
885
|
-
const w =
|
|
749
|
+
if (this.isStart() && typeof this.#t[0] == "string" && !(this.#t.length === 1 && we.has(this.#t[0]))) {
|
|
750
|
+
const w = ge, g = (
|
|
886
751
|
// dots are allowed, and the pattern starts with [ or .
|
|
887
752
|
e && w.has(h.charAt(0)) || // the pattern starts with \\., and then [ or .
|
|
888
753
|
h.startsWith("\\\\.") && w.has(h.charAt(2)) || // the pattern starts with \\.\\., and then [ or .
|
|
889
754
|
h.startsWith("\\\\.\\\\.") && w.has(h.charAt(4))
|
|
890
755
|
), S = !e && !t && w.has(h.charAt(0));
|
|
891
|
-
c = g ?
|
|
756
|
+
c = g ? pe : S ? L : "";
|
|
892
757
|
}
|
|
893
758
|
let f = "";
|
|
894
|
-
return this.isEnd() && this.#
|
|
759
|
+
return this.isEnd() && this.#s.#a && this.#e?.type === "!" && (f = "(?:$|\\\\/)"), [
|
|
895
760
|
c + h + f,
|
|
896
|
-
|
|
897
|
-
this.#
|
|
898
|
-
this.#
|
|
761
|
+
M(h),
|
|
762
|
+
this.#n = !!this.#n,
|
|
763
|
+
this.#r
|
|
899
764
|
];
|
|
900
765
|
}
|
|
901
|
-
const
|
|
902
|
-
let
|
|
903
|
-
if (this.isStart() && this.isEnd() && !
|
|
766
|
+
const n = this.type === "*" || this.type === "+", i = this.type === "!" ? "(?:(?!(?:" : "(?:";
|
|
767
|
+
let r = this.#f(e);
|
|
768
|
+
if (this.isStart() && this.isEnd() && !r && this.type !== "!") {
|
|
904
769
|
const l = this.toString();
|
|
905
|
-
return this.#t = [l], this.type = null, this.#
|
|
770
|
+
return this.#t = [l], this.type = null, this.#n = void 0, [l, M(this.toString()), !1, !1];
|
|
906
771
|
}
|
|
907
|
-
let o = !
|
|
908
|
-
o ===
|
|
772
|
+
let o = !n || t || e || !L ? "" : this.#f(!0);
|
|
773
|
+
o === r && (o = ""), o && (r = \`(?:\${r})(?:\${o})*?\`);
|
|
909
774
|
let a = "";
|
|
910
775
|
if (this.type === "!" && this.#u)
|
|
911
|
-
a = (this.isStart() && !e ?
|
|
776
|
+
a = (this.isStart() && !e ? L : "") + ct;
|
|
912
777
|
else {
|
|
913
778
|
const l = this.type === "!" ? (
|
|
914
779
|
// !() must match something,but !(x) can match ''
|
|
915
|
-
"))" + (this.isStart() && !e && !t ?
|
|
780
|
+
"))" + (this.isStart() && !e && !t ? L : "") + at + ")"
|
|
916
781
|
) : this.type === "@" ? ")" : this.type === "?" ? ")?" : this.type === "+" && o ? ")" : this.type === "*" && o ? ")?" : \`)\${this.type}\`;
|
|
917
|
-
a =
|
|
782
|
+
a = i + r + l;
|
|
918
783
|
}
|
|
919
784
|
return [
|
|
920
785
|
a,
|
|
921
|
-
|
|
922
|
-
this.#
|
|
923
|
-
this.#
|
|
786
|
+
M(r),
|
|
787
|
+
this.#n = !!this.#n,
|
|
788
|
+
this.#r
|
|
924
789
|
];
|
|
925
790
|
}
|
|
926
791
|
#f(t) {
|
|
927
792
|
return this.#t.map((e) => {
|
|
928
793
|
if (typeof e == "string")
|
|
929
794
|
throw new Error("string type in extglob ast??");
|
|
930
|
-
const [
|
|
931
|
-
return this.#
|
|
795
|
+
const [n, i, r, o] = e.toRegExpSource(t);
|
|
796
|
+
return this.#r = this.#r || o, n;
|
|
932
797
|
}).filter((e) => !(this.isStart() && this.isEnd()) || !!e).join("|");
|
|
933
798
|
}
|
|
934
|
-
static #p(t, e,
|
|
935
|
-
let
|
|
799
|
+
static #p(t, e, n = !1) {
|
|
800
|
+
let i = !1, r = "", o = !1;
|
|
936
801
|
for (let a = 0; a < t.length; a++) {
|
|
937
802
|
const l = t.charAt(a);
|
|
938
|
-
if (
|
|
939
|
-
|
|
803
|
+
if (i) {
|
|
804
|
+
i = !1, r += (ye.has(l) ? "\\\\" : "") + l;
|
|
940
805
|
continue;
|
|
941
806
|
}
|
|
942
807
|
if (l === "\\\\") {
|
|
943
|
-
a === t.length - 1 ?
|
|
808
|
+
a === t.length - 1 ? r += "\\\\\\\\" : i = !0;
|
|
944
809
|
continue;
|
|
945
810
|
}
|
|
946
811
|
if (l === "[") {
|
|
947
|
-
const [h, c, f, u] =
|
|
812
|
+
const [h, c, f, u] = fe(t, a);
|
|
948
813
|
if (f) {
|
|
949
|
-
|
|
814
|
+
r += h, o = o || c, a += f - 1, e = e || u;
|
|
950
815
|
continue;
|
|
951
816
|
}
|
|
952
817
|
}
|
|
953
818
|
if (l === "*") {
|
|
954
|
-
|
|
819
|
+
n && t === "*" ? r += ct : r += at, e = !0;
|
|
955
820
|
continue;
|
|
956
821
|
}
|
|
957
822
|
if (l === "?") {
|
|
958
|
-
|
|
823
|
+
r += tt, e = !0;
|
|
959
824
|
continue;
|
|
960
825
|
}
|
|
961
|
-
|
|
826
|
+
r += me(l);
|
|
962
827
|
}
|
|
963
|
-
return [
|
|
964
|
-
}
|
|
965
|
-
}
|
|
966
|
-
const
|
|
967
|
-
const e =
|
|
968
|
-
return t ? (t = t.toLowerCase(), (
|
|
969
|
-
},
|
|
970
|
-
const e =
|
|
971
|
-
return t ? (t = t.toLowerCase(), (
|
|
972
|
-
},
|
|
973
|
-
const e =
|
|
974
|
-
return t ? (
|
|
975
|
-
},
|
|
976
|
-
const e =
|
|
977
|
-
return t ? (
|
|
978
|
-
},
|
|
979
|
-
const t =
|
|
828
|
+
return [r, M(t), !!e, o];
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
const Ee = (s, { windowsPathsNoEscape: t = !1 } = {}) => t ? s.replace(/[?*()[\\]]/g, "[$&]") : s.replace(/[?*()[\\]\\\\]/g, "\\\\$&"), m = (s, t, e = {}) => (U(t), !e.nocomment && t.charAt(0) === "#" ? !1 : new G(t, e).match(s)), Se = /^\\*+([^+@!?\\*\\[\\(]*)$/, xe = (s) => (t) => !t.startsWith(".") && t.endsWith(s), be = (s) => (t) => t.endsWith(s), ve = (s) => (s = s.toLowerCase(), (t) => !t.startsWith(".") && t.toLowerCase().endsWith(s)), Ae = (s) => (s = s.toLowerCase(), (t) => t.toLowerCase().endsWith(s)), Fe = /^\\*+\\.\\*+$/, Ne = (s) => !s.startsWith(".") && s.includes("."), De = (s) => s !== "." && s !== ".." && s.includes("."), Oe = /^\\.\\*+$/, $e = (s) => s !== "." && s !== ".." && s.startsWith("."), Ce = /^\\*+$/, Te = (s) => s.length !== 0 && !s.startsWith("."), Me = (s) => s.length !== 0 && s !== "." && s !== "..", Pe = /^\\?+([^+@!?\\*\\[\\(]*)?$/, Ie = ([s, t = ""]) => {
|
|
832
|
+
const e = Nt([s]);
|
|
833
|
+
return t ? (t = t.toLowerCase(), (n) => e(n) && n.toLowerCase().endsWith(t)) : e;
|
|
834
|
+
}, ke = ([s, t = ""]) => {
|
|
835
|
+
const e = Dt([s]);
|
|
836
|
+
return t ? (t = t.toLowerCase(), (n) => e(n) && n.toLowerCase().endsWith(t)) : e;
|
|
837
|
+
}, Re = ([s, t = ""]) => {
|
|
838
|
+
const e = Dt([s]);
|
|
839
|
+
return t ? (n) => e(n) && n.endsWith(t) : e;
|
|
840
|
+
}, Le = ([s, t = ""]) => {
|
|
841
|
+
const e = Nt([s]);
|
|
842
|
+
return t ? (n) => e(n) && n.endsWith(t) : e;
|
|
843
|
+
}, Nt = ([s]) => {
|
|
844
|
+
const t = s.length;
|
|
980
845
|
return (e) => e.length === t && !e.startsWith(".");
|
|
981
|
-
},
|
|
982
|
-
const t =
|
|
846
|
+
}, Dt = ([s]) => {
|
|
847
|
+
const t = s.length;
|
|
983
848
|
return (e) => e.length === t && e !== "." && e !== "..";
|
|
984
|
-
},
|
|
849
|
+
}, Ot = typeof process == "object" && process ? typeof process.env == "object" && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix", lt = {
|
|
985
850
|
win32: { sep: "\\\\" },
|
|
986
851
|
posix: { sep: "/" }
|
|
987
|
-
},
|
|
988
|
-
|
|
852
|
+
}, ze = Ot === "win32" ? lt.win32.sep : lt.posix.sep;
|
|
853
|
+
m.sep = ze;
|
|
989
854
|
const v = Symbol("globstar **");
|
|
990
|
-
|
|
991
|
-
const
|
|
992
|
-
|
|
993
|
-
const b = (
|
|
994
|
-
if (!
|
|
995
|
-
return
|
|
996
|
-
const t =
|
|
997
|
-
return Object.assign((
|
|
855
|
+
m.GLOBSTAR = v;
|
|
856
|
+
const He = "[^/]", We = He + "*?", _e = "(?:(?!(?:\\\\/|^)(?:\\\\.{1,2})($|\\\\/)).)*?", je = "(?:(?!(?:\\\\/|^)\\\\.).)*?", Be = (s, t = {}) => (e) => m(e, s, t);
|
|
857
|
+
m.filter = Be;
|
|
858
|
+
const b = (s, t = {}) => Object.assign({}, s, t), Ue = (s) => {
|
|
859
|
+
if (!s || typeof s != "object" || !Object.keys(s).length)
|
|
860
|
+
return m;
|
|
861
|
+
const t = m;
|
|
862
|
+
return Object.assign((n, i, r = {}) => t(n, i, b(s, r)), {
|
|
998
863
|
Minimatch: class extends t.Minimatch {
|
|
999
|
-
constructor(
|
|
1000
|
-
super(
|
|
864
|
+
constructor(i, r = {}) {
|
|
865
|
+
super(i, b(s, r));
|
|
1001
866
|
}
|
|
1002
|
-
static defaults(
|
|
1003
|
-
return t.defaults(b(
|
|
867
|
+
static defaults(i) {
|
|
868
|
+
return t.defaults(b(s, i)).Minimatch;
|
|
1004
869
|
}
|
|
1005
870
|
},
|
|
1006
871
|
AST: class extends t.AST {
|
|
1007
872
|
/* c8 ignore start */
|
|
1008
|
-
constructor(
|
|
1009
|
-
super(
|
|
873
|
+
constructor(i, r, o = {}) {
|
|
874
|
+
super(i, r, b(s, o));
|
|
1010
875
|
}
|
|
1011
876
|
/* c8 ignore stop */
|
|
1012
|
-
static fromGlob(
|
|
1013
|
-
return t.AST.fromGlob(
|
|
877
|
+
static fromGlob(i, r = {}) {
|
|
878
|
+
return t.AST.fromGlob(i, b(s, r));
|
|
1014
879
|
}
|
|
1015
880
|
},
|
|
1016
|
-
unescape: (
|
|
1017
|
-
escape: (
|
|
1018
|
-
filter: (
|
|
1019
|
-
defaults: (
|
|
1020
|
-
makeRe: (
|
|
1021
|
-
braceExpand: (
|
|
1022
|
-
match: (
|
|
881
|
+
unescape: (n, i = {}) => t.unescape(n, b(s, i)),
|
|
882
|
+
escape: (n, i = {}) => t.escape(n, b(s, i)),
|
|
883
|
+
filter: (n, i = {}) => t.filter(n, b(s, i)),
|
|
884
|
+
defaults: (n) => t.defaults(b(s, n)),
|
|
885
|
+
makeRe: (n, i = {}) => t.makeRe(n, b(s, i)),
|
|
886
|
+
braceExpand: (n, i = {}) => t.braceExpand(n, b(s, i)),
|
|
887
|
+
match: (n, i, r = {}) => t.match(n, i, b(s, r)),
|
|
1023
888
|
sep: t.sep,
|
|
1024
889
|
GLOBSTAR: v
|
|
1025
890
|
});
|
|
1026
891
|
};
|
|
1027
|
-
|
|
1028
|
-
const
|
|
1029
|
-
|
|
1030
|
-
const
|
|
1031
|
-
|
|
1032
|
-
const
|
|
1033
|
-
const
|
|
1034
|
-
return
|
|
892
|
+
m.defaults = Ue;
|
|
893
|
+
const $t = (s, t = {}) => (U(s), t.nobrace || !/\\{(?:(?!\\{).)*\\}/.test(s) ? [s] : ie(s));
|
|
894
|
+
m.braceExpand = $t;
|
|
895
|
+
const Ge = (s, t = {}) => new G(s, t).makeRe();
|
|
896
|
+
m.makeRe = Ge;
|
|
897
|
+
const qe = (s, t, e = {}) => {
|
|
898
|
+
const n = new G(t, e);
|
|
899
|
+
return s = s.filter((i) => n.match(i)), n.options.nonull && !s.length && s.push(t), s;
|
|
1035
900
|
};
|
|
1036
|
-
|
|
1037
|
-
const
|
|
1038
|
-
class
|
|
901
|
+
m.match = qe;
|
|
902
|
+
const ht = /[?*]|[+@!]\\(.*?\\)|\\[|\\]/, Ve = (s) => s.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, "\\\\$&");
|
|
903
|
+
class G {
|
|
1039
904
|
options;
|
|
1040
905
|
set;
|
|
1041
906
|
pattern;
|
|
@@ -1054,7 +919,7 @@ class U {
|
|
|
1054
919
|
windowsNoMagicRoot;
|
|
1055
920
|
regexp;
|
|
1056
921
|
constructor(t, e = {}) {
|
|
1057
|
-
|
|
922
|
+
U(t), e = e || {}, this.options = e, this.pattern = t, this.platform = e.platform || Ot, this.isWindows = this.platform === "win32", this.windowsPathsNoEscape = !!e.windowsPathsNoEscape || e.allowWindowsEscape === !1, this.windowsPathsNoEscape && (this.pattern = this.pattern.replace(/\\\\/g, "/")), this.preserveMultipleSlashes = !!e.preserveMultipleSlashes, this.regexp = null, this.negate = !1, this.nonegate = !!e.nonegate, this.comment = !1, this.empty = !1, this.partial = !!e.partial, this.nocase = !!this.options.nocase, this.windowsNoMagicRoot = e.windowsNoMagicRoot !== void 0 ? e.windowsNoMagicRoot : !!(this.isWindows && this.nocase), this.globSet = [], this.globParts = [], this.set = [], this.make();
|
|
1058
923
|
}
|
|
1059
924
|
hasMagic() {
|
|
1060
925
|
if (this.options.magicalBraces && this.set.length > 1)
|
|
@@ -1077,23 +942,23 @@ class U {
|
|
|
1077
942
|
this.empty = !0;
|
|
1078
943
|
return;
|
|
1079
944
|
}
|
|
1080
|
-
this.parseNegate(), this.globSet = [...new Set(this.braceExpand())], e.debug && (this.debug = (...
|
|
1081
|
-
const
|
|
1082
|
-
this.globParts = this.preprocess(
|
|
1083
|
-
let
|
|
945
|
+
this.parseNegate(), this.globSet = [...new Set(this.braceExpand())], e.debug && (this.debug = (...r) => console.error(...r)), this.debug(this.pattern, this.globSet);
|
|
946
|
+
const n = this.globSet.map((r) => this.slashSplit(r));
|
|
947
|
+
this.globParts = this.preprocess(n), this.debug(this.pattern, this.globParts);
|
|
948
|
+
let i = this.globParts.map((r, o, a) => {
|
|
1084
949
|
if (this.isWindows && this.windowsNoMagicRoot) {
|
|
1085
|
-
const l =
|
|
950
|
+
const l = r[0] === "" && r[1] === "" && (r[2] === "?" || !ht.test(r[2])) && !ht.test(r[3]), h = /^[a-z]:/i.test(r[0]);
|
|
1086
951
|
if (l)
|
|
1087
|
-
return [...
|
|
952
|
+
return [...r.slice(0, 4), ...r.slice(4).map((c) => this.parse(c))];
|
|
1088
953
|
if (h)
|
|
1089
|
-
return [
|
|
954
|
+
return [r[0], ...r.slice(1).map((c) => this.parse(c))];
|
|
1090
955
|
}
|
|
1091
|
-
return
|
|
956
|
+
return r.map((l) => this.parse(l));
|
|
1092
957
|
});
|
|
1093
|
-
if (this.debug(this.pattern,
|
|
1094
|
-
for (let
|
|
1095
|
-
const o = this.set[
|
|
1096
|
-
o[0] === "" && o[1] === "" && this.globParts[
|
|
958
|
+
if (this.debug(this.pattern, i), this.set = i.filter((r) => r.indexOf(!1) === -1), this.isWindows)
|
|
959
|
+
for (let r = 0; r < this.set.length; r++) {
|
|
960
|
+
const o = this.set[r];
|
|
961
|
+
o[0] === "" && o[1] === "" && this.globParts[r][2] === "?" && typeof o[3] == "string" && /^[a-z]:$/i.test(o[3]) && (o[2] = "?");
|
|
1097
962
|
}
|
|
1098
963
|
this.debug(this.pattern, this.set);
|
|
1099
964
|
}
|
|
@@ -1104,30 +969,30 @@ class U {
|
|
|
1104
969
|
// of patterns that we have to process.
|
|
1105
970
|
preprocess(t) {
|
|
1106
971
|
if (this.options.noglobstar)
|
|
1107
|
-
for (let
|
|
1108
|
-
for (let
|
|
1109
|
-
t[
|
|
972
|
+
for (let n = 0; n < t.length; n++)
|
|
973
|
+
for (let i = 0; i < t[n].length; i++)
|
|
974
|
+
t[n][i] === "**" && (t[n][i] = "*");
|
|
1110
975
|
const { optimizationLevel: e = 1 } = this.options;
|
|
1111
976
|
return e >= 2 ? (t = this.firstPhasePreProcess(t), t = this.secondPhasePreProcess(t)) : e >= 1 ? t = this.levelOneOptimize(t) : t = this.adjascentGlobstarOptimize(t), t;
|
|
1112
977
|
}
|
|
1113
978
|
// just get rid of adjascent ** portions
|
|
1114
979
|
adjascentGlobstarOptimize(t) {
|
|
1115
980
|
return t.map((e) => {
|
|
1116
|
-
let
|
|
1117
|
-
for (; (
|
|
1118
|
-
let
|
|
1119
|
-
for (; e[
|
|
1120
|
-
|
|
1121
|
-
|
|
981
|
+
let n = -1;
|
|
982
|
+
for (; (n = e.indexOf("**", n + 1)) !== -1; ) {
|
|
983
|
+
let i = n;
|
|
984
|
+
for (; e[i + 1] === "**"; )
|
|
985
|
+
i++;
|
|
986
|
+
i !== n && e.splice(n, i - n);
|
|
1122
987
|
}
|
|
1123
988
|
return e;
|
|
1124
989
|
});
|
|
1125
990
|
}
|
|
1126
991
|
// get rid of adjascent ** and resolve .. portions
|
|
1127
992
|
levelOneOptimize(t) {
|
|
1128
|
-
return t.map((e) => (e = e.reduce((
|
|
1129
|
-
const
|
|
1130
|
-
return
|
|
993
|
+
return t.map((e) => (e = e.reduce((n, i) => {
|
|
994
|
+
const r = n[n.length - 1];
|
|
995
|
+
return i === "**" && r === "**" ? n : i === ".." && r && r !== ".." && r !== "." && r !== "**" ? (n.pop(), n) : (n.push(i), n);
|
|
1131
996
|
}, []), e.length === 0 ? [""] : e));
|
|
1132
997
|
}
|
|
1133
998
|
levelTwoFileOptimize(t) {
|
|
@@ -1135,16 +1000,16 @@ class U {
|
|
|
1135
1000
|
let e = !1;
|
|
1136
1001
|
do {
|
|
1137
1002
|
if (e = !1, !this.preserveMultipleSlashes) {
|
|
1138
|
-
for (let
|
|
1139
|
-
const
|
|
1140
|
-
|
|
1003
|
+
for (let i = 1; i < t.length - 1; i++) {
|
|
1004
|
+
const r = t[i];
|
|
1005
|
+
i === 1 && r === "" && t[0] === "" || (r === "." || r === "") && (e = !0, t.splice(i, 1), i--);
|
|
1141
1006
|
}
|
|
1142
1007
|
t[0] === "." && t.length === 2 && (t[1] === "." || t[1] === "") && (e = !0, t.pop());
|
|
1143
1008
|
}
|
|
1144
|
-
let
|
|
1145
|
-
for (; (
|
|
1146
|
-
const
|
|
1147
|
-
|
|
1009
|
+
let n = 0;
|
|
1010
|
+
for (; (n = t.indexOf("..", n + 1)) !== -1; ) {
|
|
1011
|
+
const i = t[n - 1];
|
|
1012
|
+
i && i !== "." && i !== ".." && i !== "**" && (e = !0, t.splice(n - 1, 2), n -= 2);
|
|
1148
1013
|
}
|
|
1149
1014
|
} while (e);
|
|
1150
1015
|
return t.length === 0 ? [""] : t;
|
|
@@ -1171,35 +1036,35 @@ class U {
|
|
|
1171
1036
|
let e = !1;
|
|
1172
1037
|
do {
|
|
1173
1038
|
e = !1;
|
|
1174
|
-
for (let
|
|
1175
|
-
let
|
|
1176
|
-
for (; (
|
|
1177
|
-
let o =
|
|
1178
|
-
for (;
|
|
1039
|
+
for (let n of t) {
|
|
1040
|
+
let i = -1;
|
|
1041
|
+
for (; (i = n.indexOf("**", i + 1)) !== -1; ) {
|
|
1042
|
+
let o = i;
|
|
1043
|
+
for (; n[o + 1] === "**"; )
|
|
1179
1044
|
o++;
|
|
1180
|
-
o >
|
|
1181
|
-
let a =
|
|
1182
|
-
const l =
|
|
1045
|
+
o > i && n.splice(i + 1, o - i);
|
|
1046
|
+
let a = n[i + 1];
|
|
1047
|
+
const l = n[i + 2], h = n[i + 3];
|
|
1183
1048
|
if (a !== ".." || !l || l === "." || l === ".." || !h || h === "." || h === "..")
|
|
1184
1049
|
continue;
|
|
1185
|
-
e = !0,
|
|
1186
|
-
const c =
|
|
1187
|
-
c[
|
|
1050
|
+
e = !0, n.splice(i, 1);
|
|
1051
|
+
const c = n.slice(0);
|
|
1052
|
+
c[i] = "**", t.push(c), i--;
|
|
1188
1053
|
}
|
|
1189
1054
|
if (!this.preserveMultipleSlashes) {
|
|
1190
|
-
for (let o = 1; o <
|
|
1191
|
-
const a =
|
|
1192
|
-
o === 1 && a === "" &&
|
|
1055
|
+
for (let o = 1; o < n.length - 1; o++) {
|
|
1056
|
+
const a = n[o];
|
|
1057
|
+
o === 1 && a === "" && n[0] === "" || (a === "." || a === "") && (e = !0, n.splice(o, 1), o--);
|
|
1193
1058
|
}
|
|
1194
|
-
|
|
1059
|
+
n[0] === "." && n.length === 2 && (n[1] === "." || n[1] === "") && (e = !0, n.pop());
|
|
1195
1060
|
}
|
|
1196
|
-
let
|
|
1197
|
-
for (; (
|
|
1198
|
-
const o =
|
|
1061
|
+
let r = 0;
|
|
1062
|
+
for (; (r = n.indexOf("..", r + 1)) !== -1; ) {
|
|
1063
|
+
const o = n[r - 1];
|
|
1199
1064
|
if (o && o !== "." && o !== ".." && o !== "**") {
|
|
1200
1065
|
e = !0;
|
|
1201
|
-
const l =
|
|
1202
|
-
|
|
1066
|
+
const l = r === 1 && n[r + 1] === "**" ? ["."] : [];
|
|
1067
|
+
n.splice(r - 1, 2, ...l), n.length === 0 && n.push(""), r -= 2;
|
|
1203
1068
|
}
|
|
1204
1069
|
}
|
|
1205
1070
|
}
|
|
@@ -1215,32 +1080,32 @@ class U {
|
|
|
1215
1080
|
// ^-- not valid because ** doens't follow symlinks
|
|
1216
1081
|
secondPhasePreProcess(t) {
|
|
1217
1082
|
for (let e = 0; e < t.length - 1; e++)
|
|
1218
|
-
for (let
|
|
1219
|
-
const
|
|
1220
|
-
if (
|
|
1221
|
-
t[e] = [], t[
|
|
1083
|
+
for (let n = e + 1; n < t.length; n++) {
|
|
1084
|
+
const i = this.partsMatch(t[e], t[n], !this.preserveMultipleSlashes);
|
|
1085
|
+
if (i) {
|
|
1086
|
+
t[e] = [], t[n] = i;
|
|
1222
1087
|
break;
|
|
1223
1088
|
}
|
|
1224
1089
|
}
|
|
1225
1090
|
return t.filter((e) => e.length);
|
|
1226
1091
|
}
|
|
1227
|
-
partsMatch(t, e,
|
|
1228
|
-
let
|
|
1229
|
-
for (;
|
|
1230
|
-
if (t[
|
|
1231
|
-
o.push(a === "b" ? e[
|
|
1232
|
-
else if (
|
|
1233
|
-
o.push(t[
|
|
1234
|
-
else if (
|
|
1235
|
-
o.push(e[
|
|
1236
|
-
else if (t[
|
|
1092
|
+
partsMatch(t, e, n = !1) {
|
|
1093
|
+
let i = 0, r = 0, o = [], a = "";
|
|
1094
|
+
for (; i < t.length && r < e.length; )
|
|
1095
|
+
if (t[i] === e[r])
|
|
1096
|
+
o.push(a === "b" ? e[r] : t[i]), i++, r++;
|
|
1097
|
+
else if (n && t[i] === "**" && e[r] === t[i + 1])
|
|
1098
|
+
o.push(t[i]), i++;
|
|
1099
|
+
else if (n && e[r] === "**" && t[i] === e[r + 1])
|
|
1100
|
+
o.push(e[r]), r++;
|
|
1101
|
+
else if (t[i] === "*" && e[r] && (this.options.dot || !e[r].startsWith(".")) && e[r] !== "**") {
|
|
1237
1102
|
if (a === "b")
|
|
1238
1103
|
return !1;
|
|
1239
|
-
a = "a", o.push(t[
|
|
1240
|
-
} else if (e[
|
|
1104
|
+
a = "a", o.push(t[i]), i++, r++;
|
|
1105
|
+
} else if (e[r] === "*" && t[i] && (this.options.dot || !t[i].startsWith(".")) && t[i] !== "**") {
|
|
1241
1106
|
if (a === "a")
|
|
1242
1107
|
return !1;
|
|
1243
|
-
a = "b", o.push(e[
|
|
1108
|
+
a = "b", o.push(e[r]), i++, r++;
|
|
1244
1109
|
} else
|
|
1245
1110
|
return !1;
|
|
1246
1111
|
return t.length === e.length && o;
|
|
@@ -1249,27 +1114,27 @@ class U {
|
|
|
1249
1114
|
if (this.nonegate)
|
|
1250
1115
|
return;
|
|
1251
1116
|
const t = this.pattern;
|
|
1252
|
-
let e = !1,
|
|
1253
|
-
for (let
|
|
1254
|
-
e = !e,
|
|
1255
|
-
|
|
1117
|
+
let e = !1, n = 0;
|
|
1118
|
+
for (let i = 0; i < t.length && t.charAt(i) === "!"; i++)
|
|
1119
|
+
e = !e, n++;
|
|
1120
|
+
n && (this.pattern = t.slice(n)), this.negate = e;
|
|
1256
1121
|
}
|
|
1257
1122
|
// set partial to true to test if, for example,
|
|
1258
1123
|
// "/a/b" matches the start of "/*/b/*/d"
|
|
1259
1124
|
// Partial means, if you run out of file before you run
|
|
1260
1125
|
// out of pattern, then that's fine, as long as all
|
|
1261
1126
|
// the parts match.
|
|
1262
|
-
matchOne(t, e,
|
|
1263
|
-
const
|
|
1127
|
+
matchOne(t, e, n = !1) {
|
|
1128
|
+
const i = this.options;
|
|
1264
1129
|
if (this.isWindows) {
|
|
1265
|
-
const g = typeof t[0] == "string" && /^[a-z]:$/i.test(t[0]), S = !g && t[0] === "" && t[1] === "" && t[2] === "?" && /^[a-z]:$/i.test(t[3]), A = typeof e[0] == "string" && /^[a-z]:$/i.test(e[0]),
|
|
1266
|
-
if (typeof x == "number" && typeof
|
|
1267
|
-
const [
|
|
1268
|
-
|
|
1130
|
+
const g = typeof t[0] == "string" && /^[a-z]:$/i.test(t[0]), S = !g && t[0] === "" && t[1] === "" && t[2] === "?" && /^[a-z]:$/i.test(t[3]), A = typeof e[0] == "string" && /^[a-z]:$/i.test(e[0]), O = !A && e[0] === "" && e[1] === "" && e[2] === "?" && typeof e[3] == "string" && /^[a-z]:$/i.test(e[3]), x = S ? 3 : g ? 0 : void 0, y = O ? 3 : A ? 0 : void 0;
|
|
1131
|
+
if (typeof x == "number" && typeof y == "number") {
|
|
1132
|
+
const [$, I] = [t[x], e[y]];
|
|
1133
|
+
$.toLowerCase() === I.toLowerCase() && (e[y] = $, y > x ? e = e.slice(y) : x > y && (t = t.slice(x)));
|
|
1269
1134
|
}
|
|
1270
1135
|
}
|
|
1271
|
-
const { optimizationLevel:
|
|
1272
|
-
|
|
1136
|
+
const { optimizationLevel: r = 1 } = this.options;
|
|
1137
|
+
r >= 2 && (t = this.levelTwoFileOptimize(t)), this.debug("matchOne", this, { file: t, pattern: e }), this.debug("matchOne", t.length, e.length);
|
|
1273
1138
|
for (var o = 0, a = 0, l = t.length, h = e.length; o < l && a < h; o++, a++) {
|
|
1274
1139
|
this.debug("matchOne loop");
|
|
1275
1140
|
var c = e[a], f = t[o];
|
|
@@ -1280,22 +1145,22 @@ class U {
|
|
|
1280
1145
|
var u = o, d = a + 1;
|
|
1281
1146
|
if (d === h) {
|
|
1282
1147
|
for (this.debug("** at the end"); o < l; o++)
|
|
1283
|
-
if (t[o] === "." || t[o] === ".." || !
|
|
1148
|
+
if (t[o] === "." || t[o] === ".." || !i.dot && t[o].charAt(0) === ".")
|
|
1284
1149
|
return !1;
|
|
1285
1150
|
return !0;
|
|
1286
1151
|
}
|
|
1287
1152
|
for (; u < l; ) {
|
|
1288
1153
|
var w = t[u];
|
|
1289
1154
|
if (this.debug(\`
|
|
1290
|
-
globstar while\`, t, u, e, d, w), this.matchOne(t.slice(u), e.slice(d),
|
|
1155
|
+
globstar while\`, t, u, e, d, w), this.matchOne(t.slice(u), e.slice(d), n))
|
|
1291
1156
|
return this.debug("globstar found match!", u, l, w), !0;
|
|
1292
|
-
if (w === "." || w === ".." || !
|
|
1157
|
+
if (w === "." || w === ".." || !i.dot && w.charAt(0) === ".") {
|
|
1293
1158
|
this.debug("dot detected!", t, u, e, d);
|
|
1294
1159
|
break;
|
|
1295
1160
|
}
|
|
1296
1161
|
this.debug("globstar swallow a segment, and continue"), u++;
|
|
1297
1162
|
}
|
|
1298
|
-
return !!(
|
|
1163
|
+
return !!(n && (this.debug(\`
|
|
1299
1164
|
>>> no match, partial?\`, t, u, e, d), u === l));
|
|
1300
1165
|
}
|
|
1301
1166
|
let g;
|
|
@@ -1305,25 +1170,25 @@ globstar while\`, t, u, e, d, w), this.matchOne(t.slice(u), e.slice(d), s))
|
|
|
1305
1170
|
if (o === l && a === h)
|
|
1306
1171
|
return !0;
|
|
1307
1172
|
if (o === l)
|
|
1308
|
-
return
|
|
1173
|
+
return n;
|
|
1309
1174
|
if (a === h)
|
|
1310
1175
|
return o === l - 1 && t[o] === "";
|
|
1311
1176
|
throw new Error("wtf?");
|
|
1312
1177
|
}
|
|
1313
1178
|
braceExpand() {
|
|
1314
|
-
return
|
|
1179
|
+
return $t(this.pattern, this.options);
|
|
1315
1180
|
}
|
|
1316
1181
|
parse(t) {
|
|
1317
|
-
|
|
1182
|
+
U(t);
|
|
1318
1183
|
const e = this.options;
|
|
1319
1184
|
if (t === "**")
|
|
1320
1185
|
return v;
|
|
1321
1186
|
if (t === "")
|
|
1322
1187
|
return "";
|
|
1323
|
-
let
|
|
1324
|
-
(
|
|
1325
|
-
const
|
|
1326
|
-
return
|
|
1188
|
+
let n, i = null;
|
|
1189
|
+
(n = t.match(Ce)) ? i = e.dot ? Me : Te : (n = t.match(Se)) ? i = (e.nocase ? e.dot ? Ae : ve : e.dot ? be : xe)(n[1]) : (n = t.match(Pe)) ? i = (e.nocase ? e.dot ? ke : Ie : e.dot ? Re : Le)(n) : (n = t.match(Fe)) ? i = e.dot ? De : Ne : (n = t.match(Oe)) && (i = $e);
|
|
1190
|
+
const r = E.fromGlob(t, this.options).toMMPattern();
|
|
1191
|
+
return i && typeof r == "object" && Reflect.defineProperty(r, "test", { value: i }), r;
|
|
1327
1192
|
}
|
|
1328
1193
|
makeRe() {
|
|
1329
1194
|
if (this.regexp || this.regexp === !1)
|
|
@@ -1331,23 +1196,23 @@ globstar while\`, t, u, e, d, w), this.matchOne(t.slice(u), e.slice(d), s))
|
|
|
1331
1196
|
const t = this.set;
|
|
1332
1197
|
if (!t.length)
|
|
1333
1198
|
return this.regexp = !1, this.regexp;
|
|
1334
|
-
const e = this.options,
|
|
1335
|
-
let
|
|
1199
|
+
const e = this.options, n = e.noglobstar ? We : e.dot ? _e : je, i = new Set(e.nocase ? ["i"] : []);
|
|
1200
|
+
let r = t.map((l) => {
|
|
1336
1201
|
const h = l.map((c) => {
|
|
1337
1202
|
if (c instanceof RegExp)
|
|
1338
1203
|
for (const f of c.flags.split(""))
|
|
1339
|
-
|
|
1340
|
-
return typeof c == "string" ?
|
|
1204
|
+
i.add(f);
|
|
1205
|
+
return typeof c == "string" ? Ve(c) : c === v ? v : c._src;
|
|
1341
1206
|
});
|
|
1342
1207
|
return h.forEach((c, f) => {
|
|
1343
1208
|
const u = h[f + 1], d = h[f - 1];
|
|
1344
|
-
c !== v || d === v || (d === void 0 ? u !== void 0 && u !== v ? h[f + 1] = "(?:\\\\/|" +
|
|
1209
|
+
c !== v || d === v || (d === void 0 ? u !== void 0 && u !== v ? h[f + 1] = "(?:\\\\/|" + n + "\\\\/)?" + u : h[f] = n : u === void 0 ? h[f - 1] = d + "(?:\\\\/|" + n + ")?" : u !== v && (h[f - 1] = d + "(?:\\\\/|\\\\/" + n + "\\\\/)" + u, h[f + 1] = v));
|
|
1345
1210
|
}), h.filter((c) => c !== v).join("/");
|
|
1346
1211
|
}).join("|");
|
|
1347
1212
|
const [o, a] = t.length > 1 ? ["(?:", ")"] : ["", ""];
|
|
1348
|
-
|
|
1213
|
+
r = "^" + o + r + a + "$", this.negate && (r = "^(?!" + r + ").+$");
|
|
1349
1214
|
try {
|
|
1350
|
-
this.regexp = new RegExp(
|
|
1215
|
+
this.regexp = new RegExp(r, [...i].join(""));
|
|
1351
1216
|
} catch {
|
|
1352
1217
|
this.regexp = !1;
|
|
1353
1218
|
}
|
|
@@ -1363,161 +1228,133 @@ globstar while\`, t, u, e, d, w), this.matchOne(t.slice(u), e.slice(d), s))
|
|
|
1363
1228
|
return t === "";
|
|
1364
1229
|
if (t === "/" && e)
|
|
1365
1230
|
return !0;
|
|
1366
|
-
const
|
|
1231
|
+
const n = this.options;
|
|
1367
1232
|
this.isWindows && (t = t.split("\\\\").join("/"));
|
|
1368
|
-
const
|
|
1369
|
-
this.debug(this.pattern, "split",
|
|
1370
|
-
const
|
|
1371
|
-
this.debug(this.pattern, "set",
|
|
1372
|
-
let o =
|
|
1233
|
+
const i = this.slashSplit(t);
|
|
1234
|
+
this.debug(this.pattern, "split", i);
|
|
1235
|
+
const r = this.set;
|
|
1236
|
+
this.debug(this.pattern, "set", r);
|
|
1237
|
+
let o = i[i.length - 1];
|
|
1373
1238
|
if (!o)
|
|
1374
|
-
for (let a =
|
|
1375
|
-
o =
|
|
1376
|
-
for (let a = 0; a <
|
|
1377
|
-
const l =
|
|
1378
|
-
let h =
|
|
1379
|
-
if (
|
|
1380
|
-
return
|
|
1239
|
+
for (let a = i.length - 2; !o && a >= 0; a--)
|
|
1240
|
+
o = i[a];
|
|
1241
|
+
for (let a = 0; a < r.length; a++) {
|
|
1242
|
+
const l = r[a];
|
|
1243
|
+
let h = i;
|
|
1244
|
+
if (n.matchBase && l.length === 1 && (h = [o]), this.matchOne(h, l, e))
|
|
1245
|
+
return n.flipNegate ? !0 : !this.negate;
|
|
1381
1246
|
}
|
|
1382
|
-
return
|
|
1247
|
+
return n.flipNegate ? !1 : this.negate;
|
|
1383
1248
|
}
|
|
1384
1249
|
static defaults(t) {
|
|
1385
|
-
return
|
|
1250
|
+
return m.defaults(t).Minimatch;
|
|
1386
1251
|
}
|
|
1387
1252
|
}
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
function
|
|
1253
|
+
m.AST = E;
|
|
1254
|
+
m.Minimatch = G;
|
|
1255
|
+
m.escape = Ee;
|
|
1256
|
+
m.unescape = M;
|
|
1257
|
+
function Xe() {
|
|
1393
1258
|
if (!("storage" in navigator) || !("getDirectory" in navigator.storage))
|
|
1394
|
-
throw new
|
|
1259
|
+
throw new jt();
|
|
1395
1260
|
}
|
|
1396
|
-
async function
|
|
1397
|
-
return typeof navigator < "u" && navigator.locks?.request ? navigator.locks.request(\`opfs:\${
|
|
1261
|
+
async function P(s, t, e) {
|
|
1262
|
+
return typeof navigator < "u" && navigator.locks?.request ? navigator.locks.request(\`opfs:\${s.replace(/\\/+/g, "/")}\`, { mode: t }, e) : e();
|
|
1398
1263
|
}
|
|
1399
|
-
function
|
|
1400
|
-
return Array.isArray(
|
|
1264
|
+
function D(s) {
|
|
1265
|
+
return Array.isArray(s) ? s : (s.startsWith("~/") ? s.slice(2) : s).split("/").filter(Boolean);
|
|
1401
1266
|
}
|
|
1402
|
-
function
|
|
1403
|
-
return typeof
|
|
1267
|
+
function et(s) {
|
|
1268
|
+
return typeof s == "string" ? s ?? "/" : \`/\${s.join("/")}\`;
|
|
1404
1269
|
}
|
|
1405
|
-
function
|
|
1406
|
-
const t =
|
|
1270
|
+
function J(s) {
|
|
1271
|
+
const t = D(s);
|
|
1407
1272
|
return t[t.length - 1] || "";
|
|
1408
1273
|
}
|
|
1409
|
-
function
|
|
1410
|
-
const t =
|
|
1411
|
-
return t.pop(),
|
|
1274
|
+
function X(s) {
|
|
1275
|
+
const t = D(s);
|
|
1276
|
+
return t.pop(), et(t);
|
|
1412
1277
|
}
|
|
1413
|
-
function
|
|
1414
|
-
return !
|
|
1278
|
+
function W(s) {
|
|
1279
|
+
return !s || s === "/" ? "/" : s.startsWith("~/") ? \`/\${s.slice(2)}\` : s.startsWith("/") ? s : \`/\${s}\`;
|
|
1415
1280
|
}
|
|
1416
|
-
function
|
|
1417
|
-
return
|
|
1281
|
+
function Ye(s, t = !1) {
|
|
1282
|
+
return s = s.replace(/\\/$/, ""), t && !s.includes("*") ? \`\${s}/**\` : s;
|
|
1418
1283
|
}
|
|
1419
|
-
function
|
|
1420
|
-
return
|
|
1284
|
+
function Y(s, t) {
|
|
1285
|
+
return m(s, t, {
|
|
1421
1286
|
dot: !0,
|
|
1422
1287
|
matchBase: !0
|
|
1423
1288
|
});
|
|
1424
1289
|
}
|
|
1425
|
-
function
|
|
1426
|
-
const t =
|
|
1427
|
-
for (const
|
|
1428
|
-
if (!(
|
|
1429
|
-
if (
|
|
1430
|
-
if (
|
|
1290
|
+
function ut(s) {
|
|
1291
|
+
const t = W(s), e = D(t), n = [];
|
|
1292
|
+
for (const i of e)
|
|
1293
|
+
if (!(i === "." || i === ""))
|
|
1294
|
+
if (i === "..") {
|
|
1295
|
+
if (n.length === 0)
|
|
1431
1296
|
continue;
|
|
1432
|
-
|
|
1297
|
+
n.pop();
|
|
1433
1298
|
} else
|
|
1434
|
-
|
|
1435
|
-
return
|
|
1436
|
-
}
|
|
1437
|
-
function an(n, t = "utf-8") {
|
|
1438
|
-
return typeof n == "string" ? Yt(n, t) : n instanceof Uint8Array ? n : new Uint8Array(n);
|
|
1439
|
-
}
|
|
1440
|
-
async function cn(n, t) {
|
|
1441
|
-
return B(t, "shared", async () => {
|
|
1442
|
-
const s = await (await n.getFile()).arrayBuffer();
|
|
1443
|
-
return new Uint8Array(s);
|
|
1444
|
-
});
|
|
1299
|
+
n.push(i);
|
|
1300
|
+
return et(n);
|
|
1445
1301
|
}
|
|
1446
|
-
async function
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
l.write(h, { at: c }), a && l.truncate(h.byteLength), l.flush();
|
|
1452
|
-
} catch (h) {
|
|
1453
|
-
console.error(h);
|
|
1454
|
-
const c = o ? "append" : "write";
|
|
1455
|
-
throw new p(\`Failed to \${c} file\`, \`\${c.toUpperCase()}_FAILED\`, void 0, h);
|
|
1456
|
-
} finally {
|
|
1457
|
-
try {
|
|
1458
|
-
l?.close();
|
|
1459
|
-
} catch {
|
|
1460
|
-
}
|
|
1461
|
-
}
|
|
1462
|
-
};
|
|
1463
|
-
return s ? B(s, "exclusive", i) : i();
|
|
1302
|
+
async function Ze(s, t = "SHA-1", e = 50 * 1024 * 1024) {
|
|
1303
|
+
if (s instanceof File && (s = await s.arrayBuffer()), s.byteLength > e)
|
|
1304
|
+
throw new Error(\`File size \${s.byteLength} bytes exceeds maximum allowed size \${e} bytes\`);
|
|
1305
|
+
const n = new Uint8Array(s), i = await crypto.subtle.digest(t, n);
|
|
1306
|
+
return Array.from(new Uint8Array(i)).map((o) => o.toString(16).padStart(2, "0")).join("");
|
|
1464
1307
|
}
|
|
1465
|
-
async function
|
|
1466
|
-
|
|
1467
|
-
throw new Error(\`File size \${n.byteLength} bytes exceeds maximum allowed size \${e} bytes\`);
|
|
1468
|
-
const s = new Uint8Array(n), r = await crypto.subtle.digest(t, s);
|
|
1469
|
-
return Array.from(new Uint8Array(r)).map((o) => o.toString(16).padStart(2, "0")).join("");
|
|
1470
|
-
}
|
|
1471
|
-
async function hn(n) {
|
|
1472
|
-
const t = await n.arrayBuffer();
|
|
1308
|
+
async function Je(s) {
|
|
1309
|
+
const t = await s.arrayBuffer();
|
|
1473
1310
|
return new Uint8Array(t);
|
|
1474
1311
|
}
|
|
1475
|
-
async function
|
|
1476
|
-
const
|
|
1477
|
-
return
|
|
1478
|
-
const
|
|
1312
|
+
async function Ke(s, t, e = {}) {
|
|
1313
|
+
const n = J(t);
|
|
1314
|
+
return P(t, "exclusive", async () => {
|
|
1315
|
+
const i = e.recursive ?? !1, r = e.force ?? !1;
|
|
1479
1316
|
e.useTrash;
|
|
1480
1317
|
try {
|
|
1481
|
-
await
|
|
1318
|
+
await s.removeEntry(n, { recursive: i });
|
|
1482
1319
|
} catch (o) {
|
|
1483
1320
|
if (o.name === "NotFoundError") {
|
|
1484
|
-
if (!
|
|
1321
|
+
if (!r)
|
|
1485
1322
|
throw new p(\`No such file or directory: \${t}\`, "ENOENT", void 0, o);
|
|
1486
|
-
} else throw o.name === "InvalidModificationError" ? new p(\`Directory not empty: \${t}. Use recursive option to force removal.\`, "ENOTEMPTY", void 0, o) : o.name === "TypeMismatchError" && !
|
|
1323
|
+
} else throw o.name === "InvalidModificationError" ? new p(\`Directory not empty: \${t}. Use recursive option to force removal.\`, "ENOTEMPTY", void 0, o) : o.name === "TypeMismatchError" && !i ? new p(\`Cannot remove directory without recursive option: \${t}\`, "EISDIR", void 0, o) : new p(\`Failed to remove entry: \${t}\`, "RM_FAILED", void 0, o);
|
|
1487
1324
|
}
|
|
1488
1325
|
});
|
|
1489
1326
|
}
|
|
1490
|
-
function
|
|
1327
|
+
function ft(s, t, e, n) {
|
|
1491
1328
|
if (!Number.isInteger(t) || !Number.isInteger(e))
|
|
1492
1329
|
throw new p("Invalid offset or length", "EINVAL");
|
|
1493
1330
|
if (t < 0 || e < 0)
|
|
1494
1331
|
throw new p("Negative offset or length not allowed", "EINVAL");
|
|
1495
|
-
if (t + e >
|
|
1332
|
+
if (t + e > s)
|
|
1496
1333
|
throw new p("Operation would overflow buffer", "ERANGE");
|
|
1497
|
-
if (
|
|
1334
|
+
if (n != null && (!Number.isInteger(n) || n < 0))
|
|
1498
1335
|
throw new p("Invalid position", "EINVAL");
|
|
1499
1336
|
}
|
|
1500
|
-
function
|
|
1337
|
+
function dt(s, t, e) {
|
|
1501
1338
|
try {
|
|
1502
1339
|
t.flush(), t.close();
|
|
1503
|
-
} catch (
|
|
1504
|
-
console.warn(\`Warning: Failed to properly close file descriptor \${
|
|
1340
|
+
} catch (n) {
|
|
1341
|
+
console.warn(\`Warning: Failed to properly close file descriptor \${s} (\${e}):\`, n);
|
|
1505
1342
|
}
|
|
1506
1343
|
}
|
|
1507
|
-
function
|
|
1508
|
-
if (
|
|
1344
|
+
function Qe(s, t, e) {
|
|
1345
|
+
if (s >= e)
|
|
1509
1346
|
return { isEOF: !0, actualLength: 0 };
|
|
1510
|
-
const
|
|
1511
|
-
return
|
|
1347
|
+
const n = Math.min(t, e - s);
|
|
1348
|
+
return n <= 0 ? { isEOF: !0, actualLength: 0 } : { isEOF: !1, actualLength: n };
|
|
1512
1349
|
}
|
|
1513
|
-
async function
|
|
1350
|
+
async function ts(s, t) {
|
|
1514
1351
|
try {
|
|
1515
|
-
return await
|
|
1352
|
+
return await s.createSyncAccessHandle();
|
|
1516
1353
|
} catch (e) {
|
|
1517
|
-
throw
|
|
1354
|
+
throw Ut(e, { path: t });
|
|
1518
1355
|
}
|
|
1519
1356
|
}
|
|
1520
|
-
class
|
|
1357
|
+
class es {
|
|
1521
1358
|
/** Root directory handle for the file system */
|
|
1522
1359
|
root;
|
|
1523
1360
|
/** Map of watched paths and options */
|
|
@@ -1531,7 +1368,7 @@ class dn {
|
|
|
1531
1368
|
root: "/",
|
|
1532
1369
|
namespace: "",
|
|
1533
1370
|
maxFileSize: 50 * 1024 * 1024,
|
|
1534
|
-
hashAlgorithm:
|
|
1371
|
+
hashAlgorithm: !1,
|
|
1535
1372
|
broadcastChannel: "opfs-worker"
|
|
1536
1373
|
};
|
|
1537
1374
|
/** Map of open file descriptors to their metadata */
|
|
@@ -1561,25 +1398,25 @@ class dn {
|
|
|
1561
1398
|
if (!this.options.broadcastChannel)
|
|
1562
1399
|
return;
|
|
1563
1400
|
const e = t.path;
|
|
1564
|
-
if (![...this.watchers.values()].some((
|
|
1401
|
+
if (![...this.watchers.values()].some((r) => Y(e, r.pattern) && r.include.some((o) => o && Y(e, o)) && !r.exclude.some((o) => o && Y(e, o))))
|
|
1565
1402
|
return;
|
|
1566
|
-
let
|
|
1403
|
+
let i;
|
|
1567
1404
|
if (this.options.hashAlgorithm)
|
|
1568
1405
|
try {
|
|
1569
|
-
|
|
1406
|
+
i = (await this.stat(e)).hash;
|
|
1570
1407
|
} catch {
|
|
1571
1408
|
}
|
|
1572
1409
|
try {
|
|
1573
1410
|
this.broadcastChannel || (this.broadcastChannel = new BroadcastChannel(this.options.broadcastChannel));
|
|
1574
|
-
const
|
|
1411
|
+
const r = {
|
|
1575
1412
|
namespace: this.options.namespace,
|
|
1576
1413
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1577
1414
|
...t,
|
|
1578
|
-
...
|
|
1415
|
+
...i && { hash: i }
|
|
1579
1416
|
};
|
|
1580
|
-
this.broadcastChannel.postMessage(
|
|
1581
|
-
} catch (
|
|
1582
|
-
console.warn("Failed to send event via BroadcastChannel:",
|
|
1417
|
+
this.broadcastChannel.postMessage(r);
|
|
1418
|
+
} catch (r) {
|
|
1419
|
+
console.warn("Failed to send event via BroadcastChannel:", r);
|
|
1583
1420
|
}
|
|
1584
1421
|
}
|
|
1585
1422
|
/**
|
|
@@ -1593,7 +1430,7 @@ class dn {
|
|
|
1593
1430
|
* @throws {OPFSError} If OPFS is not supported in the current browser
|
|
1594
1431
|
*/
|
|
1595
1432
|
constructor(t) {
|
|
1596
|
-
|
|
1433
|
+
Xe(), t && this.setOptions(t);
|
|
1597
1434
|
}
|
|
1598
1435
|
/**
|
|
1599
1436
|
* Initialize the file system within a given directory
|
|
@@ -1618,12 +1455,12 @@ class dn {
|
|
|
1618
1455
|
*/
|
|
1619
1456
|
async mount() {
|
|
1620
1457
|
const t = this.options.root;
|
|
1621
|
-
return this.mountingPromise && await this.mountingPromise, this.mountingPromise = new Promise(async (e,
|
|
1458
|
+
return this.mountingPromise && await this.mountingPromise, this.mountingPromise = new Promise(async (e, n) => {
|
|
1622
1459
|
try {
|
|
1623
|
-
const
|
|
1624
|
-
this.root = t === "/" ?
|
|
1625
|
-
} catch (
|
|
1626
|
-
|
|
1460
|
+
const i = await navigator.storage.getDirectory();
|
|
1461
|
+
this.root = t === "/" ? i : await this.getDirectoryHandle(t, !0, i), e(!0);
|
|
1462
|
+
} catch (i) {
|
|
1463
|
+
n(new p("Failed to initialize OPFS", "INIT_FAILED", t, i));
|
|
1627
1464
|
} finally {
|
|
1628
1465
|
this.mountingPromise = null;
|
|
1629
1466
|
}
|
|
@@ -1640,7 +1477,7 @@ class dn {
|
|
|
1640
1477
|
* @param options.broadcastChannel - Custom name for the broadcast channel
|
|
1641
1478
|
*/
|
|
1642
1479
|
async setOptions(t) {
|
|
1643
|
-
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 =
|
|
1480
|
+
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 = W(t.root), this.options.namespace || (this.options.namespace = \`opfs-worker:\${this.options.root}\`), await this.mount());
|
|
1644
1481
|
}
|
|
1645
1482
|
/**
|
|
1646
1483
|
* Get a directory handle from a path
|
|
@@ -1660,12 +1497,12 @@ class dn {
|
|
|
1660
1497
|
* const docsDir2 = await fs.getDirectoryHandle(['users', 'john', 'documents'], true);
|
|
1661
1498
|
* \`\`\`
|
|
1662
1499
|
*/
|
|
1663
|
-
async getDirectoryHandle(t, e = !1,
|
|
1664
|
-
const
|
|
1665
|
-
let
|
|
1666
|
-
for (const o of
|
|
1667
|
-
|
|
1668
|
-
return
|
|
1500
|
+
async getDirectoryHandle(t, e = !1, n = this.root) {
|
|
1501
|
+
const i = Array.isArray(t) ? t : D(t);
|
|
1502
|
+
let r = n;
|
|
1503
|
+
for (const o of i)
|
|
1504
|
+
r = await r.getDirectoryHandle(o, { create: e });
|
|
1505
|
+
return r;
|
|
1669
1506
|
}
|
|
1670
1507
|
/**
|
|
1671
1508
|
* Get a file handle from a path
|
|
@@ -1686,12 +1523,12 @@ class dn {
|
|
|
1686
1523
|
* const fileHandle2 = await fs.getFileHandle(['config', 'settings.json'], true);
|
|
1687
1524
|
* \`\`\`
|
|
1688
1525
|
*/
|
|
1689
|
-
async getFileHandle(t, e = !1,
|
|
1690
|
-
const
|
|
1691
|
-
if (
|
|
1692
|
-
throw new
|
|
1693
|
-
const
|
|
1694
|
-
return (await this.getDirectoryHandle(
|
|
1526
|
+
async getFileHandle(t, e = !1, n = this.root) {
|
|
1527
|
+
const i = D(t);
|
|
1528
|
+
if (i.length === 0)
|
|
1529
|
+
throw new Bt("Path must not be empty", Array.isArray(t) ? t.join("/") : t);
|
|
1530
|
+
const r = i.pop();
|
|
1531
|
+
return (await this.getDirectoryHandle(i, e, n)).getFileHandle(r, { create: e });
|
|
1695
1532
|
}
|
|
1696
1533
|
/**
|
|
1697
1534
|
* Get a complete index of all files and directories in the file system
|
|
@@ -1713,10 +1550,10 @@ class dn {
|
|
|
1713
1550
|
* \`\`\`
|
|
1714
1551
|
*/
|
|
1715
1552
|
async index() {
|
|
1716
|
-
const t = /* @__PURE__ */ new Map(), e = async (
|
|
1717
|
-
const
|
|
1718
|
-
for (const
|
|
1719
|
-
const o = \`\${
|
|
1553
|
+
const t = /* @__PURE__ */ new Map(), e = async (n) => {
|
|
1554
|
+
const i = await this.readDir(n);
|
|
1555
|
+
for (const r of i) {
|
|
1556
|
+
const o = \`\${n === "/" ? "" : n}/\${r.name}\`;
|
|
1720
1557
|
try {
|
|
1721
1558
|
const a = await this.stat(o);
|
|
1722
1559
|
t.set(o, a), a.isDirectory && await e(o);
|
|
@@ -1734,71 +1571,111 @@ class dn {
|
|
|
1734
1571
|
isDirectory: !0
|
|
1735
1572
|
}), await e("/"), t;
|
|
1736
1573
|
}
|
|
1737
|
-
|
|
1738
|
-
|
|
1574
|
+
/**
|
|
1575
|
+
* Read a file from the file system
|
|
1576
|
+
*
|
|
1577
|
+
* Reads the contents of a file and returns it as binary data.
|
|
1578
|
+
*
|
|
1579
|
+
* @param path - The path to the file to read
|
|
1580
|
+
* @returns Promise that resolves to the file contents as Uint8Array
|
|
1581
|
+
* @throws {FileNotFoundError} If the file does not exist
|
|
1582
|
+
* @throws {OPFSError} If reading the file fails
|
|
1583
|
+
*
|
|
1584
|
+
* @example
|
|
1585
|
+
* \`\`\`typescript
|
|
1586
|
+
* // Read as binary data
|
|
1587
|
+
* const content = await fs.readFile('/config/settings.json');
|
|
1588
|
+
*
|
|
1589
|
+
* // Read binary file
|
|
1590
|
+
* const binaryData = await fs.readFile('/images/logo.png');
|
|
1591
|
+
* \`\`\`
|
|
1592
|
+
*/
|
|
1593
|
+
async readFile(t) {
|
|
1594
|
+
await this.mount();
|
|
1739
1595
|
try {
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1596
|
+
return await P(t, "shared", async () => {
|
|
1597
|
+
const e = await this.open(t);
|
|
1598
|
+
try {
|
|
1599
|
+
const { size: n } = await this.fstat(e), i = new Uint8Array(n);
|
|
1600
|
+
return n > 0 && await this.read(e, i, 0, n, 0), H(i, [i.buffer]);
|
|
1601
|
+
} finally {
|
|
1602
|
+
await this.close(e);
|
|
1603
|
+
}
|
|
1604
|
+
});
|
|
1605
|
+
} catch (e) {
|
|
1606
|
+
throw new nt(t, e);
|
|
1744
1607
|
}
|
|
1745
1608
|
}
|
|
1746
1609
|
/**
|
|
1747
1610
|
* Write data to a file
|
|
1748
1611
|
*
|
|
1749
|
-
* Creates or overwrites a file with the specified data. If the file already
|
|
1612
|
+
* Creates or overwrites a file with the specified binary data. If the file already
|
|
1750
1613
|
* exists, it will be truncated before writing.
|
|
1751
1614
|
*
|
|
1752
1615
|
* @param path - The path to the file to write
|
|
1753
|
-
* @param data - The data to write to the file (
|
|
1754
|
-
* @param encoding - The encoding to use when writing string data (default: 'utf-8')
|
|
1616
|
+
* @param data - The binary data to write to the file (Uint8Array or ArrayBuffer)
|
|
1755
1617
|
* @returns Promise that resolves when the write operation is complete
|
|
1756
1618
|
* @throws {OPFSError} If writing the file fails
|
|
1757
1619
|
*
|
|
1758
1620
|
* @example
|
|
1759
1621
|
* \`\`\`typescript
|
|
1760
|
-
* // Write text data
|
|
1761
|
-
* await fs.writeFile('/config/settings.json', JSON.stringify({ theme: 'dark' }));
|
|
1762
|
-
*
|
|
1763
1622
|
* // Write binary data
|
|
1764
1623
|
* const binaryData = new Uint8Array([1, 2, 3, 4, 5]);
|
|
1765
1624
|
* await fs.writeFile('/data/binary.dat', binaryData);
|
|
1766
1625
|
*
|
|
1767
|
-
* // Write
|
|
1768
|
-
*
|
|
1626
|
+
* // Write from ArrayBuffer
|
|
1627
|
+
* const arrayBuffer = new ArrayBuffer(10);
|
|
1628
|
+
* await fs.writeFile('/data/buffer.dat', arrayBuffer);
|
|
1769
1629
|
* \`\`\`
|
|
1770
1630
|
*/
|
|
1771
|
-
async writeFile(t, e
|
|
1631
|
+
async writeFile(t, e) {
|
|
1772
1632
|
await this.mount();
|
|
1773
|
-
const
|
|
1774
|
-
|
|
1633
|
+
const n = e instanceof Uint8Array ? e : new Uint8Array(e);
|
|
1634
|
+
await P(t, "exclusive", async () => {
|
|
1635
|
+
const i = await this.exists(t), r = await this.open(t, { create: !0, truncate: !0 });
|
|
1636
|
+
try {
|
|
1637
|
+
await this.write(r, n, 0, n.length, null, !1), await this.fsync(r);
|
|
1638
|
+
} finally {
|
|
1639
|
+
await this.close(r);
|
|
1640
|
+
}
|
|
1641
|
+
await this.notifyChange({ path: t, type: i ? "changed" : "added", isDirectory: !1 });
|
|
1642
|
+
});
|
|
1775
1643
|
}
|
|
1776
1644
|
/**
|
|
1777
1645
|
* Append data to a file
|
|
1778
1646
|
*
|
|
1779
|
-
* Adds data to the end of an existing file. If the file doesn't exist,
|
|
1647
|
+
* Adds binary data to the end of an existing file. If the file doesn't exist,
|
|
1780
1648
|
* it will be created.
|
|
1781
1649
|
*
|
|
1782
1650
|
* @param path - The path to the file to append to
|
|
1783
|
-
* @param data - The data to append to the file (
|
|
1784
|
-
* @param encoding - The encoding to use when appending string data (default: 'utf-8')
|
|
1651
|
+
* @param data - The binary data to append to the file (Uint8Array or ArrayBuffer)
|
|
1785
1652
|
* @returns Promise that resolves when the append operation is complete
|
|
1786
1653
|
* @throws {OPFSError} If appending to the file fails
|
|
1787
1654
|
*
|
|
1788
1655
|
* @example
|
|
1789
1656
|
* \`\`\`typescript
|
|
1790
|
-
* // Append text to a log file
|
|
1791
|
-
* await fs.appendFile('/logs/app.log', \`[\${new Date().toISOString()}] User logged in\\n\`);
|
|
1792
|
-
*
|
|
1793
1657
|
* // Append binary data
|
|
1794
1658
|
* const additionalData = new Uint8Array([6, 7, 8]);
|
|
1795
1659
|
* await fs.appendFile('/data/binary.dat', additionalData);
|
|
1660
|
+
*
|
|
1661
|
+
* // Append from ArrayBuffer
|
|
1662
|
+
* const arrayBuffer = new ArrayBuffer(5);
|
|
1663
|
+
* await fs.appendFile('/data/buffer.dat', arrayBuffer);
|
|
1796
1664
|
* \`\`\`
|
|
1797
1665
|
*/
|
|
1798
|
-
async appendFile(t, e
|
|
1666
|
+
async appendFile(t, e) {
|
|
1799
1667
|
await this.mount();
|
|
1800
|
-
const
|
|
1801
|
-
|
|
1668
|
+
const n = e instanceof Uint8Array ? e : new Uint8Array(e);
|
|
1669
|
+
await P(t, "exclusive", async () => {
|
|
1670
|
+
const i = await this.open(t, { create: !0 });
|
|
1671
|
+
try {
|
|
1672
|
+
const { size: r } = await this.fstat(i);
|
|
1673
|
+
await this.write(i, n, 0, n.length, r, !1), await this.fsync(i);
|
|
1674
|
+
} finally {
|
|
1675
|
+
await this.close(i);
|
|
1676
|
+
}
|
|
1677
|
+
await this.notifyChange({ path: t, type: "changed", isDirectory: !1 });
|
|
1678
|
+
});
|
|
1802
1679
|
}
|
|
1803
1680
|
/**
|
|
1804
1681
|
* Create a directory
|
|
@@ -1823,15 +1700,15 @@ class dn {
|
|
|
1823
1700
|
*/
|
|
1824
1701
|
async mkdir(t, e) {
|
|
1825
1702
|
await this.mount();
|
|
1826
|
-
const
|
|
1827
|
-
let
|
|
1828
|
-
for (let o = 0; o <
|
|
1829
|
-
const a =
|
|
1703
|
+
const n = e?.recursive ?? !1, i = D(t);
|
|
1704
|
+
let r = this.root;
|
|
1705
|
+
for (let o = 0; o < i.length; o++) {
|
|
1706
|
+
const a = i[o];
|
|
1830
1707
|
try {
|
|
1831
|
-
|
|
1708
|
+
r = await r.getDirectoryHandle(a, { create: n || o === i.length - 1 });
|
|
1832
1709
|
} catch (l) {
|
|
1833
1710
|
throw l.name === "NotFoundError" ? new p(
|
|
1834
|
-
\`Parent directory does not exist: \${
|
|
1711
|
+
\`Parent directory does not exist: \${et(i.slice(0, o + 1))}\`,
|
|
1835
1712
|
"ENOENT",
|
|
1836
1713
|
void 0,
|
|
1837
1714
|
l
|
|
@@ -1872,9 +1749,9 @@ class dn {
|
|
|
1872
1749
|
isFile: !1,
|
|
1873
1750
|
isDirectory: !0
|
|
1874
1751
|
};
|
|
1875
|
-
const e =
|
|
1752
|
+
const e = J(t), n = await this.getDirectoryHandle(X(t), !1), i = this.options.hashAlgorithm !== null;
|
|
1876
1753
|
try {
|
|
1877
|
-
const o = await (await
|
|
1754
|
+
const o = await (await n.getFileHandle(e, { create: !1 })).getFile(), a = {
|
|
1878
1755
|
kind: "file",
|
|
1879
1756
|
size: o.size,
|
|
1880
1757
|
mtime: new Date(o.lastModified).toISOString(),
|
|
@@ -1882,20 +1759,20 @@ class dn {
|
|
|
1882
1759
|
isFile: !0,
|
|
1883
1760
|
isDirectory: !1
|
|
1884
1761
|
};
|
|
1885
|
-
if (
|
|
1762
|
+
if (i && this.options.hashAlgorithm)
|
|
1886
1763
|
try {
|
|
1887
|
-
const l = await
|
|
1764
|
+
const l = await Ze(o, this.options.hashAlgorithm, this.options.maxFileSize);
|
|
1888
1765
|
a.hash = l;
|
|
1889
1766
|
} catch (l) {
|
|
1890
1767
|
console.warn(\`Failed to calculate hash for \${t}:\`, l);
|
|
1891
1768
|
}
|
|
1892
1769
|
return a;
|
|
1893
|
-
} catch (
|
|
1894
|
-
if (
|
|
1895
|
-
throw new p("Failed to stat (file)", "STAT_FAILED", void 0,
|
|
1770
|
+
} catch (r) {
|
|
1771
|
+
if (r.name !== "TypeMismatchError" && r.name !== "NotFoundError")
|
|
1772
|
+
throw new p("Failed to stat (file)", "STAT_FAILED", void 0, r);
|
|
1896
1773
|
}
|
|
1897
1774
|
try {
|
|
1898
|
-
return await
|
|
1775
|
+
return await n.getDirectoryHandle(e, { create: !1 }), {
|
|
1899
1776
|
kind: "directory",
|
|
1900
1777
|
size: 0,
|
|
1901
1778
|
mtime: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
@@ -1903,8 +1780,8 @@ class dn {
|
|
|
1903
1780
|
isFile: !1,
|
|
1904
1781
|
isDirectory: !0
|
|
1905
1782
|
};
|
|
1906
|
-
} catch (
|
|
1907
|
-
throw
|
|
1783
|
+
} catch (r) {
|
|
1784
|
+
throw r.name === "NotFoundError" ? new p(\`No such file or directory: \${t}\`, "ENOENT", void 0, r) : new p("Failed to stat (directory)", "STAT_FAILED", void 0, r);
|
|
1908
1785
|
}
|
|
1909
1786
|
}
|
|
1910
1787
|
/**
|
|
@@ -1927,17 +1804,17 @@ class dn {
|
|
|
1927
1804
|
*/
|
|
1928
1805
|
async readDir(t) {
|
|
1929
1806
|
await this.mount();
|
|
1930
|
-
const e = await this.getDirectoryHandle(t, !1),
|
|
1931
|
-
for await (const [
|
|
1932
|
-
const o =
|
|
1933
|
-
|
|
1934
|
-
name:
|
|
1935
|
-
kind:
|
|
1807
|
+
const e = await this.getDirectoryHandle(t, !1), n = [];
|
|
1808
|
+
for await (const [i, r] of e.entries()) {
|
|
1809
|
+
const o = r.kind === "file";
|
|
1810
|
+
n.push({
|
|
1811
|
+
name: i,
|
|
1812
|
+
kind: r.kind,
|
|
1936
1813
|
isFile: o,
|
|
1937
1814
|
isDirectory: !o
|
|
1938
1815
|
});
|
|
1939
1816
|
}
|
|
1940
|
-
return
|
|
1817
|
+
return n;
|
|
1941
1818
|
}
|
|
1942
1819
|
/**
|
|
1943
1820
|
* Check if a file or directory exists
|
|
@@ -1956,26 +1833,26 @@ class dn {
|
|
|
1956
1833
|
async exists(t) {
|
|
1957
1834
|
if (await this.mount(), t === "/")
|
|
1958
1835
|
return !0;
|
|
1959
|
-
const e =
|
|
1960
|
-
let
|
|
1836
|
+
const e = J(t);
|
|
1837
|
+
let n = null;
|
|
1961
1838
|
try {
|
|
1962
|
-
|
|
1963
|
-
} catch (
|
|
1964
|
-
if (
|
|
1965
|
-
throw
|
|
1839
|
+
n = await this.getDirectoryHandle(X(t), !1);
|
|
1840
|
+
} catch (i) {
|
|
1841
|
+
if (n = null, i.name !== "NotFoundError" && i.name !== "TypeMismatchError")
|
|
1842
|
+
throw i;
|
|
1966
1843
|
}
|
|
1967
|
-
if (!
|
|
1844
|
+
if (!n || !e)
|
|
1968
1845
|
return !1;
|
|
1969
1846
|
try {
|
|
1970
|
-
return await
|
|
1971
|
-
} catch (
|
|
1972
|
-
if (
|
|
1973
|
-
throw
|
|
1847
|
+
return await n.getFileHandle(e, { create: !1 }), !0;
|
|
1848
|
+
} catch (i) {
|
|
1849
|
+
if (i.name !== "NotFoundError" && i.name !== "TypeMismatchError")
|
|
1850
|
+
throw i;
|
|
1974
1851
|
try {
|
|
1975
|
-
return await
|
|
1976
|
-
} catch (
|
|
1977
|
-
if (
|
|
1978
|
-
throw
|
|
1852
|
+
return await n.getDirectoryHandle(e, { create: !1 }), !0;
|
|
1853
|
+
} catch (r) {
|
|
1854
|
+
if (r.name !== "NotFoundError" && r.name !== "TypeMismatchError")
|
|
1855
|
+
throw r;
|
|
1979
1856
|
return !1;
|
|
1980
1857
|
}
|
|
1981
1858
|
}
|
|
@@ -2003,9 +1880,9 @@ class dn {
|
|
|
2003
1880
|
await this.mount();
|
|
2004
1881
|
try {
|
|
2005
1882
|
const e = await this.readDir(t);
|
|
2006
|
-
for (const
|
|
2007
|
-
const
|
|
2008
|
-
await this.remove(
|
|
1883
|
+
for (const n of e) {
|
|
1884
|
+
const i = \`\${t === "/" ? "" : t}/\${n.name}\`;
|
|
1885
|
+
await this.remove(i, { recursive: !0 });
|
|
2009
1886
|
}
|
|
2010
1887
|
await this.notifyChange({ path: t, type: "changed", isDirectory: !0 });
|
|
2011
1888
|
} catch (e) {
|
|
@@ -2039,8 +1916,8 @@ class dn {
|
|
|
2039
1916
|
async remove(t, e) {
|
|
2040
1917
|
if (await this.mount(), t === "/")
|
|
2041
1918
|
throw new p("Cannot remove root directory", "EROOT");
|
|
2042
|
-
const { recursive:
|
|
2043
|
-
await
|
|
1919
|
+
const { recursive: n = !1, force: i = !1 } = e || {}, r = await this.getDirectoryHandle(X(t), !1), o = await this.stat(t);
|
|
1920
|
+
await Ke(r, t, { recursive: n, force: i }), await this.notifyChange({ path: t, type: "removed", isDirectory: o.isDirectory });
|
|
2044
1921
|
}
|
|
2045
1922
|
/**
|
|
2046
1923
|
* Resolve a path to an absolute path
|
|
@@ -2063,9 +1940,9 @@ class dn {
|
|
|
2063
1940
|
async realpath(t) {
|
|
2064
1941
|
await this.mount();
|
|
2065
1942
|
try {
|
|
2066
|
-
const e =
|
|
1943
|
+
const e = ut(t);
|
|
2067
1944
|
if (!await this.exists(e))
|
|
2068
|
-
throw new
|
|
1945
|
+
throw new nt(e);
|
|
2069
1946
|
return e;
|
|
2070
1947
|
} catch (e) {
|
|
2071
1948
|
throw e instanceof p ? e : new p(\`Failed to resolve path: \${t}\`, "REALPATH_FAILED", void 0, e);
|
|
@@ -2093,17 +1970,15 @@ class dn {
|
|
|
2093
1970
|
* await fs.rename('/old/path/file.txt', '/new/path/renamed.txt', { overwrite: true });
|
|
2094
1971
|
* \`\`\`
|
|
2095
1972
|
*/
|
|
2096
|
-
async rename(t, e,
|
|
1973
|
+
async rename(t, e, n) {
|
|
2097
1974
|
await this.mount();
|
|
2098
1975
|
try {
|
|
2099
|
-
const
|
|
2100
|
-
if (
|
|
2101
|
-
throw new q(t);
|
|
2102
|
-
if (await this.exists(e) && !r)
|
|
1976
|
+
const i = n?.overwrite ?? !1, r = await this.stat(t);
|
|
1977
|
+
if (await this.exists(e) && !i)
|
|
2103
1978
|
throw new p(\`Destination already exists: \${e}\`, "EEXIST", void 0);
|
|
2104
|
-
await this.copy(t, e, { recursive: !0, overwrite:
|
|
2105
|
-
} catch (
|
|
2106
|
-
throw
|
|
1979
|
+
await this.copy(t, e, { recursive: !0, overwrite: i }), await this.remove(t, { recursive: !0 }), await this.notifyChange({ path: t, type: "removed", isDirectory: r.isDirectory }), await this.notifyChange({ path: e, type: "added", isDirectory: r.isDirectory });
|
|
1980
|
+
} catch (i) {
|
|
1981
|
+
throw i instanceof p ? i : new p(\`Failed to rename from \${t} to \${e}\`, "RENAME_FAILED", void 0, i);
|
|
2107
1982
|
}
|
|
2108
1983
|
}
|
|
2109
1984
|
/**
|
|
@@ -2131,29 +2006,29 @@ class dn {
|
|
|
2131
2006
|
* await fs.copy('/source', '/dest', { recursive: true, overwrite: false });
|
|
2132
2007
|
* \`\`\`
|
|
2133
2008
|
*/
|
|
2134
|
-
async copy(t, e,
|
|
2009
|
+
async copy(t, e, n) {
|
|
2135
2010
|
await this.mount();
|
|
2136
2011
|
try {
|
|
2137
|
-
const
|
|
2012
|
+
const i = n?.recursive ?? !1, r = n?.overwrite ?? !0;
|
|
2138
2013
|
if (!await this.exists(t))
|
|
2139
2014
|
throw new p(\`Source does not exist: \${t}\`, "ENOENT", void 0);
|
|
2140
|
-
if (await this.exists(e) && !
|
|
2015
|
+
if (await this.exists(e) && !r)
|
|
2141
2016
|
throw new p(\`Destination already exists: \${e}\`, "EEXIST", void 0);
|
|
2142
2017
|
if ((await this.stat(t)).isFile) {
|
|
2143
|
-
const h = await this.readFile(t
|
|
2018
|
+
const h = await this.readFile(t);
|
|
2144
2019
|
await this.writeFile(e, h);
|
|
2145
2020
|
} else {
|
|
2146
|
-
if (!
|
|
2021
|
+
if (!i)
|
|
2147
2022
|
throw new p(\`Cannot copy directory without recursive option: \${t}\`, "EISDIR", void 0);
|
|
2148
2023
|
await this.mkdir(e, { recursive: !0 });
|
|
2149
2024
|
const h = await this.readDir(t);
|
|
2150
2025
|
for (const c of h) {
|
|
2151
2026
|
const f = \`\${t}/\${c.name}\`, u = \`\${e}/\${c.name}\`;
|
|
2152
|
-
await this.copy(f, u, { recursive: !0, overwrite:
|
|
2027
|
+
await this.copy(f, u, { recursive: !0, overwrite: r });
|
|
2153
2028
|
}
|
|
2154
2029
|
}
|
|
2155
|
-
} catch (
|
|
2156
|
-
throw
|
|
2030
|
+
} catch (i) {
|
|
2031
|
+
throw i instanceof p ? i : new p(\`Failed to copy from \${t} to \${e}\`, "CP_FAILED", void 0, i);
|
|
2157
2032
|
}
|
|
2158
2033
|
}
|
|
2159
2034
|
/**
|
|
@@ -2184,12 +2059,12 @@ class dn {
|
|
|
2184
2059
|
async watch(t, e) {
|
|
2185
2060
|
if (!this.options.broadcastChannel)
|
|
2186
2061
|
throw new p("This instance is not configured to send events. Please specify options.broadcastChannel to enable watching.", "ENOENT");
|
|
2187
|
-
const
|
|
2188
|
-
pattern:
|
|
2062
|
+
const n = {
|
|
2063
|
+
pattern: Ye(t, e?.recursive ?? !0),
|
|
2189
2064
|
include: Array.isArray(e?.include) ? e.include : [e?.include ?? "**"],
|
|
2190
2065
|
exclude: Array.isArray(e?.exclude) ? e.exclude : [e?.exclude ?? ""]
|
|
2191
2066
|
};
|
|
2192
|
-
this.watchers.set(t,
|
|
2067
|
+
this.watchers.set(t, n);
|
|
2193
2068
|
}
|
|
2194
2069
|
/**
|
|
2195
2070
|
* Stop watching a previously watched path
|
|
@@ -2226,13 +2101,13 @@ class dn {
|
|
|
2226
2101
|
*/
|
|
2227
2102
|
async open(t, e) {
|
|
2228
2103
|
await this.mount();
|
|
2229
|
-
const { create:
|
|
2104
|
+
const { create: n = !1, exclusive: i = !1, truncate: r = !1 } = e || {}, o = W(ut(t));
|
|
2230
2105
|
try {
|
|
2231
|
-
return
|
|
2106
|
+
return n && i ? await P(o, "exclusive", async () => {
|
|
2232
2107
|
if (await this.exists(o))
|
|
2233
2108
|
throw new p(\`File already exists: \${o}\`, "EEXIST", o);
|
|
2234
|
-
return this._openFile(o,
|
|
2235
|
-
}) : await this._openFile(o,
|
|
2109
|
+
return this._openFile(o, n, r);
|
|
2110
|
+
}) : await this._openFile(o, n, r);
|
|
2236
2111
|
} catch (a) {
|
|
2237
2112
|
throw a instanceof p ? a : new p(\`Failed to open file: \${o}\`, "OPEN_FAILED", o, a);
|
|
2238
2113
|
}
|
|
@@ -2241,20 +2116,20 @@ class dn {
|
|
|
2241
2116
|
* Internal method to open a file (without locking)
|
|
2242
2117
|
* @private
|
|
2243
2118
|
*/
|
|
2244
|
-
async _openFile(t, e,
|
|
2245
|
-
const
|
|
2119
|
+
async _openFile(t, e, n) {
|
|
2120
|
+
const i = await this.getFileHandle(t, e);
|
|
2246
2121
|
try {
|
|
2247
|
-
await
|
|
2122
|
+
await i.getFile();
|
|
2248
2123
|
} catch (a) {
|
|
2249
2124
|
throw a.name === "TypeMismatchError" ? new p(\`Is a directory: \${t}\`, "EISDIR", t) : a;
|
|
2250
2125
|
}
|
|
2251
|
-
const
|
|
2252
|
-
|
|
2126
|
+
const r = await ts(i, t);
|
|
2127
|
+
n && (r.truncate(0), r.flush());
|
|
2253
2128
|
const o = this.nextFd++;
|
|
2254
2129
|
return this.openFiles.set(o, {
|
|
2255
2130
|
path: t,
|
|
2256
|
-
fileHandle:
|
|
2257
|
-
syncHandle:
|
|
2131
|
+
fileHandle: i,
|
|
2132
|
+
syncHandle: r,
|
|
2258
2133
|
position: 0
|
|
2259
2134
|
}), o;
|
|
2260
2135
|
}
|
|
@@ -2274,7 +2149,7 @@ class dn {
|
|
|
2274
2149
|
*/
|
|
2275
2150
|
async close(t) {
|
|
2276
2151
|
const e = this._getFileDescriptor(t);
|
|
2277
|
-
|
|
2152
|
+
dt(t, e.syncHandle, e.path), this.openFiles.delete(t);
|
|
2278
2153
|
}
|
|
2279
2154
|
/**
|
|
2280
2155
|
* Read data from a file descriptor
|
|
@@ -2300,17 +2175,17 @@ class dn {
|
|
|
2300
2175
|
* await fs.close(fd);
|
|
2301
2176
|
* \`\`\`
|
|
2302
2177
|
*/
|
|
2303
|
-
async read(t, e,
|
|
2178
|
+
async read(t, e, n, i, r) {
|
|
2304
2179
|
const o = this._getFileDescriptor(t);
|
|
2305
|
-
|
|
2180
|
+
ft(e.length, n, i, r);
|
|
2306
2181
|
try {
|
|
2307
|
-
const a =
|
|
2182
|
+
const a = r ?? o.position, l = o.syncHandle.getSize(), { isEOF: h, actualLength: c } = Qe(a, i, l);
|
|
2308
2183
|
if (h)
|
|
2309
|
-
return
|
|
2310
|
-
const f = e.subarray(
|
|
2311
|
-
return
|
|
2184
|
+
return H({ bytesRead: 0, buffer: e }, [e.buffer]);
|
|
2185
|
+
const f = e.subarray(n, n + c), u = o.syncHandle.read(f, { at: a });
|
|
2186
|
+
return r == null && (o.position = a + u), H({ bytesRead: u, buffer: e }, [e.buffer]);
|
|
2312
2187
|
} catch (a) {
|
|
2313
|
-
throw
|
|
2188
|
+
throw R("read", t, o.path, a);
|
|
2314
2189
|
}
|
|
2315
2190
|
}
|
|
2316
2191
|
/**
|
|
@@ -2321,9 +2196,10 @@ class dn {
|
|
|
2321
2196
|
* @param offset - The offset in the buffer to start reading from (default: 0)
|
|
2322
2197
|
* @param length - The number of bytes to write (default: entire buffer)
|
|
2323
2198
|
* @param position - The position in the file to write to (null/undefined for current position)
|
|
2199
|
+
* @param emitEvent - Whether to emit a change event (default: true)
|
|
2324
2200
|
* @returns Promise that resolves to the number of bytes written
|
|
2325
2201
|
* @throws {OPFSError} If the file descriptor is invalid or writing fails
|
|
2326
|
-
*
|
|
2202
|
+
*
|
|
2327
2203
|
* @example
|
|
2328
2204
|
* \`\`\`typescript
|
|
2329
2205
|
* const fd = await fs.open('/data/file.txt', { create: true });
|
|
@@ -2333,14 +2209,14 @@ class dn {
|
|
|
2333
2209
|
* await fs.close(fd);
|
|
2334
2210
|
* \`\`\`
|
|
2335
2211
|
*/
|
|
2336
|
-
async write(t, e,
|
|
2337
|
-
const
|
|
2338
|
-
|
|
2212
|
+
async write(t, e, n = 0, i, r, o = !0) {
|
|
2213
|
+
const a = this._getFileDescriptor(t), l = i ?? e.length - n;
|
|
2214
|
+
ft(e.length, n, l, r);
|
|
2339
2215
|
try {
|
|
2340
|
-
const
|
|
2341
|
-
return (
|
|
2342
|
-
} catch (
|
|
2343
|
-
throw
|
|
2216
|
+
const h = r ?? a.position, c = e.subarray(n, n + l), f = a.syncHandle.write(c, { at: h });
|
|
2217
|
+
return (r == null || r === a.position) && (a.position = h + f), o && await this.notifyChange({ path: a.path, type: "changed", isDirectory: !1 }), f;
|
|
2218
|
+
} catch (h) {
|
|
2219
|
+
throw R("write", t, a.path, h);
|
|
2344
2220
|
}
|
|
2345
2221
|
}
|
|
2346
2222
|
/**
|
|
@@ -2382,13 +2258,13 @@ class dn {
|
|
|
2382
2258
|
* \`\`\`
|
|
2383
2259
|
*/
|
|
2384
2260
|
async ftruncate(t, e = 0) {
|
|
2385
|
-
const
|
|
2261
|
+
const n = this._getFileDescriptor(t);
|
|
2386
2262
|
if (e < 0 || !Number.isInteger(e))
|
|
2387
2263
|
throw new p("Invalid size", "EINVAL");
|
|
2388
2264
|
try {
|
|
2389
|
-
|
|
2390
|
-
} catch (
|
|
2391
|
-
throw
|
|
2265
|
+
n.syncHandle.truncate(e), n.syncHandle.flush(), n.position > e && (n.position = e), await this.notifyChange({ path: n.path, type: "changed", isDirectory: !1 });
|
|
2266
|
+
} catch (i) {
|
|
2267
|
+
throw R("truncate", t, n.path, i);
|
|
2392
2268
|
}
|
|
2393
2269
|
}
|
|
2394
2270
|
/**
|
|
@@ -2409,8 +2285,8 @@ class dn {
|
|
|
2409
2285
|
const e = this._getFileDescriptor(t);
|
|
2410
2286
|
try {
|
|
2411
2287
|
e.syncHandle.flush();
|
|
2412
|
-
} catch (
|
|
2413
|
-
throw
|
|
2288
|
+
} catch (n) {
|
|
2289
|
+
throw R("sync", t, e.path, n);
|
|
2414
2290
|
}
|
|
2415
2291
|
}
|
|
2416
2292
|
/**
|
|
@@ -2422,7 +2298,7 @@ class dn {
|
|
|
2422
2298
|
dispose() {
|
|
2423
2299
|
this.broadcastChannel && (this.broadcastChannel.close(), this.broadcastChannel = null), this.watchers.clear();
|
|
2424
2300
|
for (const [t, e] of this.openFiles)
|
|
2425
|
-
|
|
2301
|
+
dt(t, e.syncHandle, e.path);
|
|
2426
2302
|
this.openFiles.clear(), this.nextFd = 1;
|
|
2427
2303
|
}
|
|
2428
2304
|
/**
|
|
@@ -2457,83 +2333,273 @@ class dn {
|
|
|
2457
2333
|
await this.mount();
|
|
2458
2334
|
try {
|
|
2459
2335
|
(e?.cleanBefore ?? !1) && await this.clear("/");
|
|
2460
|
-
for (const [
|
|
2461
|
-
const o =
|
|
2336
|
+
for (const [i, r] of t) {
|
|
2337
|
+
const o = W(i);
|
|
2462
2338
|
let a;
|
|
2463
|
-
|
|
2339
|
+
r instanceof Blob ? a = await Je(r) : typeof r == "string" ? a = new TextEncoder().encode(r) : a = r, await this.writeFile(o, a);
|
|
2464
2340
|
}
|
|
2465
|
-
} catch (
|
|
2466
|
-
throw
|
|
2341
|
+
} catch (n) {
|
|
2342
|
+
throw n instanceof p ? n : new p("Failed to sync file system", "SYNC_FAILED", void 0, n);
|
|
2467
2343
|
}
|
|
2468
2344
|
}
|
|
2469
2345
|
}
|
|
2470
|
-
typeof globalThis < "u" && globalThis.constructor.name === "DedicatedWorkerGlobalScope" &&
|
|
2471
|
-
//# sourceMappingURL=worker-
|
|
2472
|
-
`,
|
|
2473
|
-
function
|
|
2474
|
-
let
|
|
2346
|
+
typeof globalThis < "u" && globalThis.constructor.name === "DedicatedWorkerGlobalScope" && K(new es());
|
|
2347
|
+
//# sourceMappingURL=worker-CLvhwwfc.js.map
|
|
2348
|
+
`, l = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", p], { type: "text/javascript;charset=utf-8" });
|
|
2349
|
+
function u(s) {
|
|
2350
|
+
let n;
|
|
2475
2351
|
try {
|
|
2476
|
-
if (
|
|
2477
|
-
const
|
|
2352
|
+
if (n = l && (self.URL || self.webkitURL).createObjectURL(l), !n) throw "";
|
|
2353
|
+
const t = new Worker(n, {
|
|
2478
2354
|
type: "module",
|
|
2479
|
-
name:
|
|
2355
|
+
name: s?.name
|
|
2480
2356
|
});
|
|
2481
|
-
return
|
|
2482
|
-
(self.URL || self.webkitURL).revokeObjectURL(
|
|
2483
|
-
}),
|
|
2357
|
+
return t.addEventListener("error", () => {
|
|
2358
|
+
(self.URL || self.webkitURL).revokeObjectURL(n);
|
|
2359
|
+
}), t;
|
|
2484
2360
|
} catch {
|
|
2485
2361
|
return new Worker(
|
|
2486
|
-
"data:text/javascript;charset=utf-8," + encodeURIComponent(
|
|
2362
|
+
"data:text/javascript;charset=utf-8," + encodeURIComponent(p),
|
|
2487
2363
|
{
|
|
2488
2364
|
type: "module",
|
|
2489
|
-
name:
|
|
2365
|
+
name: s?.name
|
|
2490
2366
|
}
|
|
2491
2367
|
);
|
|
2492
2368
|
}
|
|
2493
2369
|
}
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2370
|
+
class w {
|
|
2371
|
+
#n;
|
|
2372
|
+
constructor(n) {
|
|
2373
|
+
const t = d(new u());
|
|
2374
|
+
this.#n = t, n && (n.broadcastChannel && n.broadcastChannel instanceof BroadcastChannel && (n.broadcastChannel = n.broadcastChannel.name), this.setOptions(n));
|
|
2375
|
+
}
|
|
2376
|
+
/**
|
|
2377
|
+
* Update configuration options
|
|
2378
|
+
*/
|
|
2379
|
+
async setOptions(n) {
|
|
2380
|
+
return this.#n.setOptions(n);
|
|
2381
|
+
}
|
|
2382
|
+
/**
|
|
2383
|
+
* Get a complete index of all files and directories in the file system
|
|
2384
|
+
*/
|
|
2385
|
+
async index() {
|
|
2386
|
+
return this.#n.index();
|
|
2387
|
+
}
|
|
2388
|
+
async readFile(n, t) {
|
|
2389
|
+
const e = await this.#n.readFile(n);
|
|
2390
|
+
return t || (t = h(n) ? "binary" : "utf-8"), t === "binary" ? e : c(e, t);
|
|
2391
|
+
}
|
|
2392
|
+
/**
|
|
2393
|
+
* Write data to a file
|
|
2394
|
+
*/
|
|
2395
|
+
async writeFile(n, t, e) {
|
|
2396
|
+
e || (e = typeof t != "string" || h(n) ? "binary" : "utf-8");
|
|
2397
|
+
const r = typeof t == "string" ? a(t, e) : t instanceof Uint8Array ? t : new Uint8Array(t);
|
|
2398
|
+
return this.#n.writeFile(n, r);
|
|
2399
|
+
}
|
|
2400
|
+
/**
|
|
2401
|
+
* Append data to a file
|
|
2402
|
+
*/
|
|
2403
|
+
async appendFile(n, t, e) {
|
|
2404
|
+
e || (e = typeof t != "string" || h(n) ? "binary" : "utf-8");
|
|
2405
|
+
const r = typeof t == "string" ? a(t, e) : t instanceof Uint8Array ? t : new Uint8Array(t);
|
|
2406
|
+
return this.#n.appendFile(n, r);
|
|
2407
|
+
}
|
|
2408
|
+
/**
|
|
2409
|
+
* Create a directory
|
|
2410
|
+
*/
|
|
2411
|
+
async mkdir(n, t) {
|
|
2412
|
+
return this.#n.mkdir(n, t);
|
|
2413
|
+
}
|
|
2414
|
+
/**
|
|
2415
|
+
* Get file or directory statistics
|
|
2416
|
+
*/
|
|
2417
|
+
async stat(n) {
|
|
2418
|
+
return this.#n.stat(n);
|
|
2419
|
+
}
|
|
2420
|
+
/**
|
|
2421
|
+
* Read a directory's contents
|
|
2422
|
+
*/
|
|
2423
|
+
async readDir(n) {
|
|
2424
|
+
return this.#n.readDir(n);
|
|
2425
|
+
}
|
|
2426
|
+
/**
|
|
2427
|
+
* Check if a file or directory exists
|
|
2428
|
+
*/
|
|
2429
|
+
async exists(n) {
|
|
2430
|
+
return this.#n.exists(n);
|
|
2431
|
+
}
|
|
2432
|
+
/**
|
|
2433
|
+
* Clear all contents of a directory without removing the directory itself
|
|
2434
|
+
*/
|
|
2435
|
+
async clear(n) {
|
|
2436
|
+
return this.#n.clear(n);
|
|
2437
|
+
}
|
|
2438
|
+
/**
|
|
2439
|
+
* Remove files and directories
|
|
2440
|
+
*/
|
|
2441
|
+
async remove(n, t) {
|
|
2442
|
+
return this.#n.remove(n, t);
|
|
2443
|
+
}
|
|
2444
|
+
/**
|
|
2445
|
+
* Resolve a path to an absolute path
|
|
2446
|
+
*/
|
|
2447
|
+
async realpath(n) {
|
|
2448
|
+
return this.#n.realpath(n);
|
|
2449
|
+
}
|
|
2450
|
+
/**
|
|
2451
|
+
* Rename a file or directory
|
|
2452
|
+
*/
|
|
2453
|
+
async rename(n, t, e) {
|
|
2454
|
+
return this.#n.rename(n, t, e);
|
|
2455
|
+
}
|
|
2456
|
+
/**
|
|
2457
|
+
* Copy files and directories
|
|
2458
|
+
*/
|
|
2459
|
+
async copy(n, t, e) {
|
|
2460
|
+
return this.#n.copy(n, t, e);
|
|
2461
|
+
}
|
|
2462
|
+
/**
|
|
2463
|
+
* Start watching a file or directory for changes
|
|
2464
|
+
*/
|
|
2465
|
+
watch(n, t) {
|
|
2466
|
+
return this.#n.watch(n, t), () => this.unwatch(n);
|
|
2467
|
+
}
|
|
2468
|
+
/**
|
|
2469
|
+
* Stop watching a previously watched path
|
|
2470
|
+
*/
|
|
2471
|
+
unwatch(n) {
|
|
2472
|
+
this.#n.unwatch(n);
|
|
2473
|
+
}
|
|
2474
|
+
/**
|
|
2475
|
+
* Open a file and return a file descriptor
|
|
2476
|
+
*/
|
|
2477
|
+
async open(n, t) {
|
|
2478
|
+
return this.#n.open(n, t);
|
|
2479
|
+
}
|
|
2480
|
+
/**
|
|
2481
|
+
* Close a file descriptor
|
|
2482
|
+
*/
|
|
2483
|
+
async close(n) {
|
|
2484
|
+
return this.#n.close(n);
|
|
2485
|
+
}
|
|
2486
|
+
/**
|
|
2487
|
+
* Read data from a file descriptor
|
|
2488
|
+
*
|
|
2489
|
+
* This method requires special handling due to Comlink transfer requirements.
|
|
2490
|
+
* The buffer is transferred to the worker and back, so the original buffer
|
|
2491
|
+
* becomes unusable after the call.
|
|
2492
|
+
*/
|
|
2493
|
+
async read(n, t, e, r, o) {
|
|
2494
|
+
const { bytesRead: i, buffer: f } = await this.#n.read(
|
|
2495
|
+
n,
|
|
2496
|
+
// Temp buffer to preserve the original buffer
|
|
2497
|
+
new Uint8Array(r),
|
|
2498
|
+
0,
|
|
2499
|
+
r,
|
|
2500
|
+
o
|
|
2501
|
+
);
|
|
2502
|
+
return i > 0 && t.set(f.subarray(0, i), e), { bytesRead: i, buffer: t };
|
|
2503
|
+
}
|
|
2504
|
+
/**
|
|
2505
|
+
* Write data to a file descriptor
|
|
2506
|
+
*/
|
|
2507
|
+
async write(n, t, e, r, o, i) {
|
|
2508
|
+
return this.#n.write(n, t, e, r, o, i);
|
|
2509
|
+
}
|
|
2510
|
+
/**
|
|
2511
|
+
* Get file status information by file descriptor
|
|
2512
|
+
*/
|
|
2513
|
+
async fstat(n) {
|
|
2514
|
+
return this.#n.fstat(n);
|
|
2515
|
+
}
|
|
2516
|
+
/**
|
|
2517
|
+
* Truncate file to specified size
|
|
2518
|
+
*/
|
|
2519
|
+
async ftruncate(n, t) {
|
|
2520
|
+
return this.#n.ftruncate(n, t);
|
|
2521
|
+
}
|
|
2522
|
+
/**
|
|
2523
|
+
* Synchronize file data to storage (fsync equivalent)
|
|
2524
|
+
*/
|
|
2525
|
+
async fsync(n) {
|
|
2526
|
+
return this.#n.fsync(n);
|
|
2527
|
+
}
|
|
2528
|
+
/**
|
|
2529
|
+
* Dispose of resources and clean up the file system instance
|
|
2530
|
+
*/
|
|
2531
|
+
dispose() {
|
|
2532
|
+
this.#n.dispose();
|
|
2533
|
+
}
|
|
2534
|
+
/**
|
|
2535
|
+
* Synchronize the file system with external data
|
|
2536
|
+
*/
|
|
2537
|
+
async sync(n, t) {
|
|
2538
|
+
return this.#n.sync(n, t);
|
|
2539
|
+
}
|
|
2540
|
+
/**
|
|
2541
|
+
* Read a file as text with automatic encoding detection
|
|
2542
|
+
*/
|
|
2543
|
+
async readText(n, t = "utf-8") {
|
|
2544
|
+
const e = await this.#n.readFile(n);
|
|
2545
|
+
return c(e, t);
|
|
2546
|
+
}
|
|
2547
|
+
/**
|
|
2548
|
+
* Write text to a file with specified encoding
|
|
2549
|
+
*/
|
|
2550
|
+
async writeText(n, t, e = "utf-8") {
|
|
2551
|
+
const r = a(t, e);
|
|
2552
|
+
return this.#n.writeFile(n, r);
|
|
2553
|
+
}
|
|
2554
|
+
/**
|
|
2555
|
+
* Append text to a file with specified encoding
|
|
2556
|
+
*/
|
|
2557
|
+
async appendText(n, t, e = "utf-8") {
|
|
2558
|
+
const r = a(t, e);
|
|
2559
|
+
return this.#n.appendFile(n, r);
|
|
2560
|
+
}
|
|
2561
|
+
}
|
|
2562
|
+
function g(s) {
|
|
2563
|
+
return new w(s);
|
|
2497
2564
|
}
|
|
2498
2565
|
export {
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
X as writeFileData
|
|
2566
|
+
E as BINARY_FILE_EXTENSIONS,
|
|
2567
|
+
x as DirectoryNotFoundError,
|
|
2568
|
+
S as FileNotFoundError,
|
|
2569
|
+
F as OPFSError,
|
|
2570
|
+
w as OPFSFileSystem,
|
|
2571
|
+
P as OPFSNotMountedError,
|
|
2572
|
+
O as OPFSNotSupportedError,
|
|
2573
|
+
A as PathError,
|
|
2574
|
+
T as PermissionError,
|
|
2575
|
+
I as StorageError,
|
|
2576
|
+
$ as TimeoutError,
|
|
2577
|
+
R as basename,
|
|
2578
|
+
C as buffersEqual,
|
|
2579
|
+
_ as calculateFileHash,
|
|
2580
|
+
N as calculateReadLength,
|
|
2581
|
+
D as checkOPFSSupport,
|
|
2582
|
+
k as convertBlobToUint8Array,
|
|
2583
|
+
M as createBuffer,
|
|
2584
|
+
L as createFDError,
|
|
2585
|
+
j as createSyncHandleSafe,
|
|
2586
|
+
g as createWorker,
|
|
2587
|
+
c as decodeBuffer,
|
|
2588
|
+
W as dirname,
|
|
2589
|
+
a as encodeString,
|
|
2590
|
+
z as extname,
|
|
2591
|
+
h as isBinaryFileExtension,
|
|
2592
|
+
U as isPathExcluded,
|
|
2593
|
+
H as joinPath,
|
|
2594
|
+
B as mapDomError,
|
|
2595
|
+
G as matchMinimatch,
|
|
2596
|
+
q as normalizeMinimatch,
|
|
2597
|
+
V as normalizePath,
|
|
2598
|
+
Y as removeEntry,
|
|
2599
|
+
X as resolvePath,
|
|
2600
|
+
Z as safeCloseSyncHandle,
|
|
2601
|
+
J as splitPath,
|
|
2602
|
+
K as validateReadWriteArgs,
|
|
2603
|
+
Q as withLock
|
|
2538
2604
|
};
|
|
2539
2605
|
//# sourceMappingURL=index.js.map
|