opfs-worker 0.4.2 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +204 -880
- package/dist/assets/worker-DYhMhDRt.js.map +1 -0
- package/dist/helpers-BfBe8lFJ.cjs +4 -0
- package/dist/helpers-BfBe8lFJ.cjs.map +1 -0
- package/dist/{helpers-BgMlBRWa.js → helpers-DcIl7KL0.js} +341 -237
- package/dist/helpers-DcIl7KL0.js.map +1 -0
- package/dist/index.cjs +608 -592
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +649 -626
- package/dist/index.js.map +1 -1
- package/dist/raw.cjs +1 -1
- package/dist/raw.cjs.map +1 -1
- package/dist/raw.js +104 -166
- package/dist/raw.js.map +1 -1
- package/dist/types.d.ts +14 -7
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/errors.d.ts +9 -9
- package/dist/utils/errors.d.ts.map +1 -1
- package/dist/utils/helpers.d.ts +44 -2
- package/dist/utils/helpers.d.ts.map +1 -1
- package/dist/worker.d.ts +7 -9
- package/dist/worker.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/assets/worker-Bra0Mewp.js.map +0 -1
- package/dist/helpers-BgMlBRWa.js.map +0 -1
- package/dist/helpers-DuJbWewc.cjs +0 -4
- package/dist/helpers-DuJbWewc.cjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { wrap as i } from "comlink";
|
|
2
|
-
import {
|
|
2
|
+
import { B as p, D as f, F as d, O as u, b as g, a as m, P as w, c as y, S as b, T as v, e as x, t as S, q as E, d as A, u as P, l as F, y as O, f as C, x as T, k as R, i as $, h as _, j as D, m as I, g as j, n as N, o as M, v as k, r as L, s as z, w as U, p as W } from "./helpers-DcIl7KL0.js";
|
|
3
3
|
const r = `/**
|
|
4
4
|
* @license
|
|
5
5
|
* Copyright 2019 Google LLC
|
|
6
6
|
* SPDX-License-Identifier: Apache-2.0
|
|
7
7
|
*/
|
|
8
|
-
const ut = Symbol("Comlink.proxy"),
|
|
8
|
+
const ut = Symbol("Comlink.proxy"), Dt = Symbol("Comlink.endpoint"), Nt = Symbol("Comlink.releaseProxy"), U = Symbol("Comlink.finalizer"), L = Symbol("Comlink.thrown"), ft = (s) => typeof s == "object" && s !== null || typeof s == "function", Ft = {
|
|
9
9
|
canHandle: (s) => ft(s) && s[ut],
|
|
10
10
|
serialize(s) {
|
|
11
11
|
const { port1: t, port2: e } = new MessageChannel();
|
|
12
12
|
return J(s, t), [e, [e]];
|
|
13
13
|
},
|
|
14
14
|
deserialize(s) {
|
|
15
|
-
return s.start(),
|
|
15
|
+
return s.start(), Pt(s);
|
|
16
16
|
}
|
|
17
|
-
},
|
|
18
|
-
canHandle: (s) => ft(s) &&
|
|
17
|
+
}, Tt = {
|
|
18
|
+
canHandle: (s) => ft(s) && L in s,
|
|
19
19
|
serialize({ value: s }) {
|
|
20
20
|
let t;
|
|
21
21
|
return s instanceof Error ? t = {
|
|
@@ -31,10 +31,10 @@ const ut = Symbol("Comlink.proxy"), Tt = Symbol("Comlink.endpoint"), Ft = Symbol
|
|
|
31
31
|
throw s.isError ? Object.assign(new Error(s.value.message), s.value) : s.value;
|
|
32
32
|
}
|
|
33
33
|
}, dt = /* @__PURE__ */ new Map([
|
|
34
|
-
["proxy",
|
|
35
|
-
["throw",
|
|
34
|
+
["proxy", Ft],
|
|
35
|
+
["throw", Tt]
|
|
36
36
|
]);
|
|
37
|
-
function
|
|
37
|
+
function Mt(s, t) {
|
|
38
38
|
for (const e of s)
|
|
39
39
|
if (t === e || e === "*" || e instanceof RegExp && e.test(t))
|
|
40
40
|
return !0;
|
|
@@ -44,64 +44,64 @@ function J(s, t = globalThis, e = ["*"]) {
|
|
|
44
44
|
t.addEventListener("message", function n(i) {
|
|
45
45
|
if (!i || !i.data)
|
|
46
46
|
return;
|
|
47
|
-
if (!
|
|
47
|
+
if (!Mt(e, i.origin)) {
|
|
48
48
|
console.warn(\`Invalid origin '\${i.origin}' for comlink proxy\`);
|
|
49
49
|
return;
|
|
50
50
|
}
|
|
51
|
-
const { id: r, type: o, path: a } = Object.assign({ path: [] }, i.data),
|
|
52
|
-
let
|
|
51
|
+
const { id: r, type: o, path: a } = Object.assign({ path: [] }, i.data), l = (i.data.argumentList || []).map(C);
|
|
52
|
+
let h;
|
|
53
53
|
try {
|
|
54
|
-
const
|
|
54
|
+
const c = a.slice(0, -1).reduce((u, d) => u[d], s), f = a.reduce((u, d) => u[d], s);
|
|
55
55
|
switch (o) {
|
|
56
56
|
case "GET":
|
|
57
|
-
|
|
57
|
+
h = f;
|
|
58
58
|
break;
|
|
59
59
|
case "SET":
|
|
60
|
-
|
|
60
|
+
c[a.slice(-1)[0]] = C(i.data.value), h = !0;
|
|
61
61
|
break;
|
|
62
62
|
case "APPLY":
|
|
63
|
-
|
|
63
|
+
h = f.apply(c, l);
|
|
64
64
|
break;
|
|
65
65
|
case "CONSTRUCT":
|
|
66
66
|
{
|
|
67
|
-
const u = new f(...
|
|
68
|
-
|
|
67
|
+
const u = new f(...l);
|
|
68
|
+
h = zt(u);
|
|
69
69
|
}
|
|
70
70
|
break;
|
|
71
71
|
case "ENDPOINT":
|
|
72
72
|
{
|
|
73
73
|
const { port1: u, port2: d } = new MessageChannel();
|
|
74
|
-
J(s, d),
|
|
74
|
+
J(s, d), h = It(u, [u]);
|
|
75
75
|
}
|
|
76
76
|
break;
|
|
77
77
|
case "RELEASE":
|
|
78
|
-
|
|
78
|
+
h = void 0;
|
|
79
79
|
break;
|
|
80
80
|
default:
|
|
81
81
|
return;
|
|
82
82
|
}
|
|
83
|
-
} catch (
|
|
84
|
-
|
|
83
|
+
} catch (c) {
|
|
84
|
+
h = { value: c, [L]: 0 };
|
|
85
85
|
}
|
|
86
|
-
Promise.resolve(
|
|
87
|
-
const [f, u] =
|
|
88
|
-
t.postMessage(Object.assign(Object.assign({}, f), { id: r }), u), o === "RELEASE" && (t.removeEventListener("message", n), pt(t),
|
|
89
|
-
}).catch((
|
|
90
|
-
const [f, u] =
|
|
86
|
+
Promise.resolve(h).catch((c) => ({ value: c, [L]: 0 })).then((c) => {
|
|
87
|
+
const [f, u] = H(c);
|
|
88
|
+
t.postMessage(Object.assign(Object.assign({}, f), { id: r }), u), o === "RELEASE" && (t.removeEventListener("message", n), pt(t), U in s && typeof s[U] == "function" && s[U]());
|
|
89
|
+
}).catch((c) => {
|
|
90
|
+
const [f, u] = H({
|
|
91
91
|
value: new TypeError("Unserializable return value"),
|
|
92
|
-
[
|
|
92
|
+
[L]: 0
|
|
93
93
|
});
|
|
94
94
|
t.postMessage(Object.assign(Object.assign({}, f), { id: r }), u);
|
|
95
95
|
});
|
|
96
96
|
}), t.start && t.start();
|
|
97
97
|
}
|
|
98
|
-
function
|
|
98
|
+
function $t(s) {
|
|
99
99
|
return s.constructor.name === "MessagePort";
|
|
100
100
|
}
|
|
101
101
|
function pt(s) {
|
|
102
|
-
|
|
102
|
+
$t(s) && s.close();
|
|
103
103
|
}
|
|
104
|
-
function
|
|
104
|
+
function Pt(s, t) {
|
|
105
105
|
const e = /* @__PURE__ */ new Map();
|
|
106
106
|
return s.addEventListener("message", function(i) {
|
|
107
107
|
const { data: r } = i;
|
|
@@ -114,9 +114,9 @@ function $t(s, t) {
|
|
|
114
114
|
} finally {
|
|
115
115
|
e.delete(r.id);
|
|
116
116
|
}
|
|
117
|
-
}),
|
|
117
|
+
}), X(s, e, [], t);
|
|
118
118
|
}
|
|
119
|
-
function
|
|
119
|
+
function R(s) {
|
|
120
120
|
if (s)
|
|
121
121
|
throw new Error("Proxy has been released and is not useable");
|
|
122
122
|
}
|
|
@@ -127,89 +127,89 @@ function gt(s) {
|
|
|
127
127
|
pt(s);
|
|
128
128
|
});
|
|
129
129
|
}
|
|
130
|
-
const
|
|
131
|
-
const t = (
|
|
132
|
-
|
|
130
|
+
const I = /* @__PURE__ */ new WeakMap(), z = "FinalizationRegistry" in globalThis && new FinalizationRegistry((s) => {
|
|
131
|
+
const t = (I.get(s) || 0) - 1;
|
|
132
|
+
I.set(s, t), t === 0 && gt(s);
|
|
133
133
|
});
|
|
134
134
|
function Rt(s, t) {
|
|
135
|
-
const e = (
|
|
136
|
-
|
|
135
|
+
const e = (I.get(t) || 0) + 1;
|
|
136
|
+
I.set(t, e), z && z.register(s, t, s);
|
|
137
137
|
}
|
|
138
|
-
function
|
|
139
|
-
|
|
138
|
+
function kt(s) {
|
|
139
|
+
z && z.unregister(s);
|
|
140
140
|
}
|
|
141
|
-
function
|
|
141
|
+
function X(s, t, e = [], n = function() {
|
|
142
142
|
}) {
|
|
143
143
|
let i = !1;
|
|
144
144
|
const r = new Proxy(n, {
|
|
145
145
|
get(o, a) {
|
|
146
|
-
if (
|
|
146
|
+
if (R(i), a === Nt)
|
|
147
147
|
return () => {
|
|
148
|
-
|
|
148
|
+
kt(r), gt(s), t.clear(), i = !0;
|
|
149
149
|
};
|
|
150
150
|
if (a === "then") {
|
|
151
151
|
if (e.length === 0)
|
|
152
152
|
return { then: () => r };
|
|
153
|
-
const
|
|
153
|
+
const l = O(s, t, {
|
|
154
154
|
type: "GET",
|
|
155
|
-
path: e.map((
|
|
155
|
+
path: e.map((h) => h.toString())
|
|
156
156
|
}).then(C);
|
|
157
|
-
return
|
|
157
|
+
return l.then.bind(l);
|
|
158
158
|
}
|
|
159
|
-
return
|
|
159
|
+
return X(s, t, [...e, a]);
|
|
160
160
|
},
|
|
161
|
-
set(o, a,
|
|
162
|
-
|
|
163
|
-
const [
|
|
161
|
+
set(o, a, l) {
|
|
162
|
+
R(i);
|
|
163
|
+
const [h, c] = H(l);
|
|
164
164
|
return O(s, t, {
|
|
165
165
|
type: "SET",
|
|
166
166
|
path: [...e, a].map((f) => f.toString()),
|
|
167
|
-
value:
|
|
168
|
-
},
|
|
167
|
+
value: h
|
|
168
|
+
}, c).then(C);
|
|
169
169
|
},
|
|
170
|
-
apply(o, a,
|
|
171
|
-
|
|
172
|
-
const
|
|
173
|
-
if (
|
|
170
|
+
apply(o, a, l) {
|
|
171
|
+
R(i);
|
|
172
|
+
const h = e[e.length - 1];
|
|
173
|
+
if (h === Dt)
|
|
174
174
|
return O(s, t, {
|
|
175
175
|
type: "ENDPOINT"
|
|
176
176
|
}).then(C);
|
|
177
|
-
if (
|
|
178
|
-
return
|
|
179
|
-
const [
|
|
177
|
+
if (h === "bind")
|
|
178
|
+
return X(s, t, e.slice(0, -1));
|
|
179
|
+
const [c, f] = st(l);
|
|
180
180
|
return O(s, t, {
|
|
181
181
|
type: "APPLY",
|
|
182
182
|
path: e.map((u) => u.toString()),
|
|
183
|
-
argumentList:
|
|
183
|
+
argumentList: c
|
|
184
184
|
}, f).then(C);
|
|
185
185
|
},
|
|
186
186
|
construct(o, a) {
|
|
187
|
-
|
|
188
|
-
const [
|
|
187
|
+
R(i);
|
|
188
|
+
const [l, h] = st(a);
|
|
189
189
|
return O(s, t, {
|
|
190
190
|
type: "CONSTRUCT",
|
|
191
|
-
path: e.map((
|
|
192
|
-
argumentList:
|
|
193
|
-
},
|
|
191
|
+
path: e.map((c) => c.toString()),
|
|
192
|
+
argumentList: l
|
|
193
|
+
}, h).then(C);
|
|
194
194
|
}
|
|
195
195
|
});
|
|
196
196
|
return Rt(r, s), r;
|
|
197
197
|
}
|
|
198
|
-
function
|
|
198
|
+
function Lt(s) {
|
|
199
199
|
return Array.prototype.concat.apply([], s);
|
|
200
200
|
}
|
|
201
|
-
function
|
|
202
|
-
const t = s.map(
|
|
203
|
-
return [t.map((e) => e[0]),
|
|
201
|
+
function st(s) {
|
|
202
|
+
const t = s.map(H);
|
|
203
|
+
return [t.map((e) => e[0]), Lt(t.map((e) => e[1]))];
|
|
204
204
|
}
|
|
205
|
-
const
|
|
206
|
-
function
|
|
207
|
-
return
|
|
205
|
+
const mt = /* @__PURE__ */ new WeakMap();
|
|
206
|
+
function It(s, t) {
|
|
207
|
+
return mt.set(s, t), s;
|
|
208
208
|
}
|
|
209
209
|
function zt(s) {
|
|
210
210
|
return Object.assign(s, { [ut]: !0 });
|
|
211
211
|
}
|
|
212
|
-
function
|
|
212
|
+
function H(s) {
|
|
213
213
|
for (const [t, e] of dt)
|
|
214
214
|
if (e.canHandle(s)) {
|
|
215
215
|
const [n, i] = e.serialize(s);
|
|
@@ -227,7 +227,7 @@ function j(s) {
|
|
|
227
227
|
type: "RAW",
|
|
228
228
|
value: s
|
|
229
229
|
},
|
|
230
|
-
|
|
230
|
+
mt.get(s) || []
|
|
231
231
|
];
|
|
232
232
|
}
|
|
233
233
|
function C(s) {
|
|
@@ -240,15 +240,108 @@ function C(s) {
|
|
|
240
240
|
}
|
|
241
241
|
function O(s, t, e, n) {
|
|
242
242
|
return new Promise((i) => {
|
|
243
|
-
const r =
|
|
243
|
+
const r = Ht();
|
|
244
244
|
t.set(r, i), s.start && s.start(), s.postMessage(Object.assign({ id: r }, e), n);
|
|
245
245
|
});
|
|
246
246
|
}
|
|
247
|
-
function
|
|
247
|
+
function Ht() {
|
|
248
248
|
return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
|
|
249
249
|
}
|
|
250
|
-
|
|
251
|
-
|
|
250
|
+
class g extends Error {
|
|
251
|
+
constructor(t, e, n, i) {
|
|
252
|
+
super(t, { cause: i }), this.code = e, this.path = n, this.name = "OPFSError";
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
class Wt extends g {
|
|
256
|
+
constructor(t) {
|
|
257
|
+
super("OPFS is not supported in this browser", "OPFS_NOT_SUPPORTED", void 0, t);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
class jt extends g {
|
|
261
|
+
constructor(t, e, n) {
|
|
262
|
+
super(t, "INVALID_PATH", e, n);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
class _ extends g {
|
|
266
|
+
constructor(t, e) {
|
|
267
|
+
super(\`File not found: \${t}\`, "FILE_NOT_FOUND", t, e);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
function Ut(s, t = "utf-8") {
|
|
271
|
+
switch (t) {
|
|
272
|
+
case "utf8":
|
|
273
|
+
case "utf-8":
|
|
274
|
+
return new TextEncoder().encode(s);
|
|
275
|
+
case "utf16le":
|
|
276
|
+
case "ucs2":
|
|
277
|
+
case "ucs-2":
|
|
278
|
+
return Bt(s);
|
|
279
|
+
case "ascii":
|
|
280
|
+
return Vt(s);
|
|
281
|
+
case "latin1":
|
|
282
|
+
return qt(s);
|
|
283
|
+
case "binary":
|
|
284
|
+
return Uint8Array.from(s, (e) => e.charCodeAt(0));
|
|
285
|
+
case "base64":
|
|
286
|
+
return Uint8Array.from(atob(s), (e) => e.charCodeAt(0));
|
|
287
|
+
case "hex":
|
|
288
|
+
if (!/^[\\da-f]+$/i.test(s) || s.length % 2 !== 0)
|
|
289
|
+
throw new g("Invalid hex string", "INVALID_HEX_FORMAT");
|
|
290
|
+
return Uint8Array.from(s.match(/.{1,2}/g).map((e) => parseInt(e, 16)));
|
|
291
|
+
default:
|
|
292
|
+
return console.warn("Encoding not supported, falling back to UTF-8"), new TextEncoder().encode(s);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
function _t(s, t = "utf-8") {
|
|
296
|
+
switch (t) {
|
|
297
|
+
case "utf8":
|
|
298
|
+
case "utf-8":
|
|
299
|
+
return new TextDecoder().decode(s);
|
|
300
|
+
case "utf16le":
|
|
301
|
+
case "ucs2":
|
|
302
|
+
case "ucs-2":
|
|
303
|
+
return Gt(s);
|
|
304
|
+
case "latin1":
|
|
305
|
+
return String.fromCharCode(...s);
|
|
306
|
+
case "binary":
|
|
307
|
+
return String.fromCharCode(...s);
|
|
308
|
+
case "ascii":
|
|
309
|
+
return String.fromCharCode(...s.map((e) => e & 127));
|
|
310
|
+
case "base64":
|
|
311
|
+
return btoa(String.fromCharCode(...s));
|
|
312
|
+
case "hex":
|
|
313
|
+
return Array.from(s).map((e) => e.toString(16).padStart(2, "0")).join("");
|
|
314
|
+
default:
|
|
315
|
+
return console.warn("Unsupported encoding, falling back to UTF-8"), new TextDecoder().decode(s);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
function Bt(s) {
|
|
319
|
+
const t = new Uint8Array(s.length * 2);
|
|
320
|
+
for (let e = 0; e < s.length; e++) {
|
|
321
|
+
const n = s.charCodeAt(e);
|
|
322
|
+
t[e * 2] = n & 255, t[e * 2 + 1] = n >> 8;
|
|
323
|
+
}
|
|
324
|
+
return t;
|
|
325
|
+
}
|
|
326
|
+
function Gt(s) {
|
|
327
|
+
s.length % 2 !== 0 && (console.warn("Invalid UTF-16LE buffer length, truncating last byte"), s = s.slice(0, s.length - 1));
|
|
328
|
+
const t = new Uint16Array(s.buffer, s.byteOffset, s.byteLength / 2);
|
|
329
|
+
return String.fromCharCode(...t);
|
|
330
|
+
}
|
|
331
|
+
function qt(s) {
|
|
332
|
+
const t = new Uint8Array(s.length);
|
|
333
|
+
for (let e = 0; e < s.length; e++)
|
|
334
|
+
t[e] = s.charCodeAt(e) & 255;
|
|
335
|
+
return t;
|
|
336
|
+
}
|
|
337
|
+
function Vt(s) {
|
|
338
|
+
const t = new Uint8Array(s.length);
|
|
339
|
+
for (let e = 0; e < s.length; e++)
|
|
340
|
+
t[e] = s.charCodeAt(e) & 127;
|
|
341
|
+
return t;
|
|
342
|
+
}
|
|
343
|
+
const wt = (s, t, e) => {
|
|
344
|
+
const n = s instanceof RegExp ? nt(s, e) : s, i = t instanceof RegExp ? nt(t, e) : t, r = n !== null && i != null && Xt(n, i, e);
|
|
252
345
|
return r && {
|
|
253
346
|
start: r[0],
|
|
254
347
|
end: r[1],
|
|
@@ -256,65 +349,65 @@ const mt = (s, t, e) => {
|
|
|
256
349
|
body: e.slice(r[0] + n.length, r[1]),
|
|
257
350
|
post: e.slice(r[1] + i.length)
|
|
258
351
|
};
|
|
259
|
-
},
|
|
352
|
+
}, nt = (s, t) => {
|
|
260
353
|
const e = t.match(s);
|
|
261
354
|
return e ? e[0] : null;
|
|
262
|
-
},
|
|
263
|
-
let n, i, r, o, a,
|
|
264
|
-
if (
|
|
355
|
+
}, Xt = (s, t, e) => {
|
|
356
|
+
let n, i, r, o, a, l = e.indexOf(s), h = e.indexOf(t, l + 1), c = l;
|
|
357
|
+
if (l >= 0 && h > 0) {
|
|
265
358
|
if (s === t)
|
|
266
|
-
return [
|
|
267
|
-
for (n = [], r = e.length;
|
|
268
|
-
if (
|
|
269
|
-
n.push(
|
|
359
|
+
return [l, h];
|
|
360
|
+
for (n = [], r = e.length; c >= 0 && !a; ) {
|
|
361
|
+
if (c === l)
|
|
362
|
+
n.push(c), l = e.indexOf(s, c + 1);
|
|
270
363
|
else if (n.length === 1) {
|
|
271
364
|
const f = n.pop();
|
|
272
|
-
f !== void 0 && (a = [f,
|
|
365
|
+
f !== void 0 && (a = [f, h]);
|
|
273
366
|
} else
|
|
274
|
-
i = n.pop(), i !== void 0 && i < r && (r = i, o =
|
|
275
|
-
|
|
367
|
+
i = n.pop(), i !== void 0 && i < r && (r = i, o = h), h = e.indexOf(t, c + 1);
|
|
368
|
+
c = l < h && l >= 0 ? l : h;
|
|
276
369
|
}
|
|
277
370
|
n.length && o !== void 0 && (a = [r, o]);
|
|
278
371
|
}
|
|
279
372
|
return a;
|
|
280
|
-
}, yt = "\\0SLASH" + Math.random() + "\\0", Et = "\\0OPEN" + Math.random() + "\\0", K = "\\0CLOSE" + Math.random() + "\\0", St = "\\0COMMA" + Math.random() + "\\0",
|
|
281
|
-
function
|
|
373
|
+
}, yt = "\\0SLASH" + Math.random() + "\\0", Et = "\\0OPEN" + Math.random() + "\\0", K = "\\0CLOSE" + Math.random() + "\\0", St = "\\0COMMA" + Math.random() + "\\0", bt = "\\0PERIOD" + Math.random() + "\\0", Yt = new RegExp(yt, "g"), Zt = new RegExp(Et, "g"), Jt = new RegExp(K, "g"), Kt = new RegExp(St, "g"), Qt = new RegExp(bt, "g"), te = /\\\\\\\\/g, ee = /\\\\{/g, se = /\\\\}/g, ne = /\\\\,/g, ie = /\\\\./g;
|
|
374
|
+
function B(s) {
|
|
282
375
|
return isNaN(s) ? s.charCodeAt(0) : parseInt(s, 10);
|
|
283
376
|
}
|
|
284
|
-
function
|
|
285
|
-
return s.replace(
|
|
377
|
+
function re(s) {
|
|
378
|
+
return s.replace(te, yt).replace(ee, Et).replace(se, K).replace(ne, St).replace(ie, bt);
|
|
286
379
|
}
|
|
287
|
-
function
|
|
288
|
-
return s.replace(
|
|
380
|
+
function oe(s) {
|
|
381
|
+
return s.replace(Yt, "\\\\").replace(Zt, "{").replace(Jt, "}").replace(Kt, ",").replace(Qt, ".");
|
|
289
382
|
}
|
|
290
|
-
function
|
|
383
|
+
function xt(s) {
|
|
291
384
|
if (!s)
|
|
292
385
|
return [""];
|
|
293
|
-
const t = [], e =
|
|
386
|
+
const t = [], e = wt("{", "}", s);
|
|
294
387
|
if (!e)
|
|
295
388
|
return s.split(",");
|
|
296
389
|
const { pre: n, body: i, post: r } = e, o = n.split(",");
|
|
297
390
|
o[o.length - 1] += "{" + i + "}";
|
|
298
|
-
const a =
|
|
391
|
+
const a = xt(r);
|
|
299
392
|
return r.length && (o[o.length - 1] += a.shift(), o.push.apply(o, a)), t.push.apply(t, o), t;
|
|
300
393
|
}
|
|
301
|
-
function
|
|
302
|
-
return s ? (s.slice(0, 2) === "{}" && (s = "\\\\{\\\\}" + s.slice(2)), M(
|
|
394
|
+
function ae(s) {
|
|
395
|
+
return s ? (s.slice(0, 2) === "{}" && (s = "\\\\{\\\\}" + s.slice(2)), M(re(s), !0).map(oe)) : [];
|
|
303
396
|
}
|
|
304
|
-
function
|
|
397
|
+
function ce(s) {
|
|
305
398
|
return "{" + s + "}";
|
|
306
399
|
}
|
|
307
|
-
function
|
|
400
|
+
function le(s) {
|
|
308
401
|
return /^-?0\\d/.test(s);
|
|
309
402
|
}
|
|
310
|
-
function
|
|
403
|
+
function he(s, t) {
|
|
311
404
|
return s <= t;
|
|
312
405
|
}
|
|
313
|
-
function
|
|
406
|
+
function ue(s, t) {
|
|
314
407
|
return s >= t;
|
|
315
408
|
}
|
|
316
409
|
function M(s, t) {
|
|
317
|
-
const e = [], n =
|
|
410
|
+
const e = [], n = wt("{", "}", s);
|
|
318
411
|
if (!n)
|
|
319
412
|
return [s];
|
|
320
413
|
const i = n.pre, r = n.post.length ? M(n.post, !1) : [""];
|
|
@@ -324,53 +417,53 @@ function M(s, t) {
|
|
|
324
417
|
e.push(a);
|
|
325
418
|
}
|
|
326
419
|
else {
|
|
327
|
-
const o = /^-?\\d+\\.\\.-?\\d+(?:\\.\\.-?\\d+)?$/.test(n.body), a = /^[a-zA-Z]\\.\\.[a-zA-Z](?:\\.\\.-?\\d+)?$/.test(n.body),
|
|
328
|
-
if (!
|
|
420
|
+
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;
|
|
421
|
+
if (!l && !h)
|
|
329
422
|
return n.post.match(/,(?!,).*\\}/) ? (s = n.pre + "{" + n.body + K + n.post, M(s)) : [s];
|
|
330
|
-
let
|
|
331
|
-
if (
|
|
332
|
-
|
|
333
|
-
else if (
|
|
334
|
-
return r.map((u) => n.pre +
|
|
423
|
+
let c;
|
|
424
|
+
if (l)
|
|
425
|
+
c = n.body.split(/\\.\\./);
|
|
426
|
+
else if (c = xt(n.body), c.length === 1 && c[0] !== void 0 && (c = M(c[0], !1).map(ce), c.length === 1))
|
|
427
|
+
return r.map((u) => n.pre + c[0] + u);
|
|
335
428
|
let f;
|
|
336
|
-
if (
|
|
337
|
-
const u =
|
|
338
|
-
let p =
|
|
339
|
-
d < u && (p *= -1, S =
|
|
340
|
-
const N =
|
|
429
|
+
if (l && c[0] !== void 0 && c[1] !== void 0) {
|
|
430
|
+
const u = B(c[0]), d = B(c[1]), m = Math.max(c[0].length, c[1].length);
|
|
431
|
+
let p = c.length === 3 && c[2] !== void 0 ? Math.abs(B(c[2])) : 1, S = he;
|
|
432
|
+
d < u && (p *= -1, S = ue);
|
|
433
|
+
const N = c.some(le);
|
|
341
434
|
f = [];
|
|
342
|
-
for (let
|
|
343
|
-
let
|
|
435
|
+
for (let b = u; S(b, d); b += p) {
|
|
436
|
+
let w;
|
|
344
437
|
if (a)
|
|
345
|
-
|
|
346
|
-
else if (
|
|
347
|
-
const
|
|
348
|
-
if (
|
|
349
|
-
const
|
|
350
|
-
|
|
438
|
+
w = String.fromCharCode(b), w === "\\\\" && (w = "");
|
|
439
|
+
else if (w = String(b), N) {
|
|
440
|
+
const F = m - w.length;
|
|
441
|
+
if (F > 0) {
|
|
442
|
+
const P = new Array(F + 1).join("0");
|
|
443
|
+
b < 0 ? w = "-" + P + w.slice(1) : w = P + w;
|
|
351
444
|
}
|
|
352
445
|
}
|
|
353
|
-
f.push(
|
|
446
|
+
f.push(w);
|
|
354
447
|
}
|
|
355
448
|
} else {
|
|
356
449
|
f = [];
|
|
357
|
-
for (let u = 0; u <
|
|
358
|
-
f.push.apply(f, M(
|
|
450
|
+
for (let u = 0; u < c.length; u++)
|
|
451
|
+
f.push.apply(f, M(c[u], !1));
|
|
359
452
|
}
|
|
360
453
|
for (let u = 0; u < f.length; u++)
|
|
361
454
|
for (let d = 0; d < r.length; d++) {
|
|
362
|
-
const
|
|
363
|
-
(!t ||
|
|
455
|
+
const m = i + f[u] + r[d];
|
|
456
|
+
(!t || l || m) && e.push(m);
|
|
364
457
|
}
|
|
365
458
|
}
|
|
366
459
|
return e;
|
|
367
460
|
}
|
|
368
|
-
const
|
|
461
|
+
const fe = 1024 * 64, W = (s) => {
|
|
369
462
|
if (typeof s != "string")
|
|
370
463
|
throw new TypeError("invalid pattern");
|
|
371
|
-
if (s.length >
|
|
464
|
+
if (s.length > fe)
|
|
372
465
|
throw new TypeError("pattern is too long");
|
|
373
|
-
},
|
|
466
|
+
}, de = {
|
|
374
467
|
"[:alnum:]": ["\\\\p{L}\\\\p{Nl}\\\\p{Nd}", !0],
|
|
375
468
|
"[:alpha:]": ["\\\\p{L}\\\\p{Nl}", !0],
|
|
376
469
|
"[:ascii:]": ["\\\\x00-\\\\x7f", !1],
|
|
@@ -385,60 +478,60 @@ const ie = 1024 * 64, U = (s) => {
|
|
|
385
478
|
"[:upper:]": ["\\\\p{Lu}", !0],
|
|
386
479
|
"[:word:]": ["\\\\p{L}\\\\p{Nl}\\\\p{Nd}\\\\p{Pc}", !0],
|
|
387
480
|
"[:xdigit:]": ["A-Fa-f0-9", !1]
|
|
388
|
-
},
|
|
481
|
+
}, T = (s) => s.replace(/[[\\]\\\\-]/g, "\\\\$&"), pe = (s) => s.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, "\\\\$&"), it = (s) => s.join(""), ge = (s, t) => {
|
|
389
482
|
const e = t;
|
|
390
483
|
if (s.charAt(e) !== "[")
|
|
391
484
|
throw new Error("not in a brace expression");
|
|
392
485
|
const n = [], i = [];
|
|
393
|
-
let r = e + 1, o = !1, a = !1,
|
|
486
|
+
let r = e + 1, o = !1, a = !1, l = !1, h = !1, c = e, f = "";
|
|
394
487
|
t: for (; r < s.length; ) {
|
|
395
488
|
const p = s.charAt(r);
|
|
396
489
|
if ((p === "!" || p === "^") && r === e + 1) {
|
|
397
|
-
|
|
490
|
+
h = !0, r++;
|
|
398
491
|
continue;
|
|
399
492
|
}
|
|
400
|
-
if (p === "]" && o && !
|
|
401
|
-
|
|
493
|
+
if (p === "]" && o && !l) {
|
|
494
|
+
c = r + 1;
|
|
402
495
|
break;
|
|
403
496
|
}
|
|
404
|
-
if (o = !0, p === "\\\\" && !
|
|
405
|
-
|
|
497
|
+
if (o = !0, p === "\\\\" && !l) {
|
|
498
|
+
l = !0, r++;
|
|
406
499
|
continue;
|
|
407
500
|
}
|
|
408
|
-
if (p === "[" && !
|
|
409
|
-
for (const [S, [
|
|
501
|
+
if (p === "[" && !l) {
|
|
502
|
+
for (const [S, [v, N, b]] of Object.entries(de))
|
|
410
503
|
if (s.startsWith(S, r)) {
|
|
411
504
|
if (f)
|
|
412
505
|
return ["$.", !1, s.length - e, !0];
|
|
413
|
-
r += S.length,
|
|
506
|
+
r += S.length, b ? i.push(v) : n.push(v), a = a || N;
|
|
414
507
|
continue t;
|
|
415
508
|
}
|
|
416
509
|
}
|
|
417
|
-
if (
|
|
418
|
-
p > f ? n.push(
|
|
510
|
+
if (l = !1, f) {
|
|
511
|
+
p > f ? n.push(T(f) + "-" + T(p)) : p === f && n.push(T(p)), f = "", r++;
|
|
419
512
|
continue;
|
|
420
513
|
}
|
|
421
514
|
if (s.startsWith("-]", r + 1)) {
|
|
422
|
-
n.push(
|
|
515
|
+
n.push(T(p + "-")), r += 2;
|
|
423
516
|
continue;
|
|
424
517
|
}
|
|
425
518
|
if (s.startsWith("-", r + 1)) {
|
|
426
519
|
f = p, r += 2;
|
|
427
520
|
continue;
|
|
428
521
|
}
|
|
429
|
-
n.push(
|
|
522
|
+
n.push(T(p)), r++;
|
|
430
523
|
}
|
|
431
|
-
if (
|
|
524
|
+
if (c < r)
|
|
432
525
|
return ["", !1, 0, !1];
|
|
433
526
|
if (!n.length && !i.length)
|
|
434
527
|
return ["$.", !1, s.length - e, !0];
|
|
435
|
-
if (i.length === 0 && n.length === 1 && /^\\\\?.$/.test(n[0]) && !
|
|
528
|
+
if (i.length === 0 && n.length === 1 && /^\\\\?.$/.test(n[0]) && !h) {
|
|
436
529
|
const p = n[0].length === 2 ? n[0].slice(-1) : n[0];
|
|
437
|
-
return [
|
|
530
|
+
return [pe(p), !1, c - e, !1];
|
|
438
531
|
}
|
|
439
|
-
const u = "[" + (
|
|
440
|
-
return [n.length && i.length ? "(" + u + "|" + d + ")" : n.length ? u : d, a,
|
|
441
|
-
}, $ = (s, { windowsPathsNoEscape: t = !1 } = {}) => t ? s.replace(/\\[([^\\/\\\\])\\]/g, "$1") : s.replace(/((?!\\\\).|^)\\[([^\\/\\\\])\\]/g, "$1$2").replace(/\\\\([^\\/])/g, "$1"),
|
|
532
|
+
const u = "[" + (h ? "^" : "") + it(n) + "]", d = "[" + (h ? "" : "^") + it(i) + "]";
|
|
533
|
+
return [n.length && i.length ? "(" + u + "|" + d + ")" : n.length ? u : d, a, c - e, !0];
|
|
534
|
+
}, $ = (s, { windowsPathsNoEscape: t = !1 } = {}) => t ? s.replace(/\\[([^\\/\\\\])\\]/g, "$1") : s.replace(/((?!\\\\).|^)\\[([^\\/\\\\])\\]/g, "$1$2").replace(/\\\\([^\\/])/g, "$1"), me = /* @__PURE__ */ new Set(["!", "?", "+", "*", "@"]), rt = (s) => me.has(s), we = "(?!(?:^|/)\\\\.\\\\.?(?:$|/))", k = "(?!\\\\.)", ye = /* @__PURE__ */ new Set(["[", "."]), Ee = /* @__PURE__ */ new Set(["..", "."]), Se = new Set("().*{}+?[]^$\\\\!"), be = (s) => s.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, "\\\\$&"), Q = "[^/]", ot = Q + "*?", at = Q + "+?";
|
|
442
535
|
class E {
|
|
443
536
|
type;
|
|
444
537
|
#s;
|
|
@@ -450,7 +543,7 @@ class E {
|
|
|
450
543
|
#c;
|
|
451
544
|
#a = !1;
|
|
452
545
|
#i;
|
|
453
|
-
#
|
|
546
|
+
#l;
|
|
454
547
|
// set to true if it's an extglob with no children
|
|
455
548
|
// (which really means one child of '')
|
|
456
549
|
#u = !1;
|
|
@@ -467,7 +560,7 @@ class E {
|
|
|
467
560
|
}
|
|
468
561
|
// reconstructs the pattern
|
|
469
562
|
toString() {
|
|
470
|
-
return this.#
|
|
563
|
+
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("");
|
|
471
564
|
}
|
|
472
565
|
#d() {
|
|
473
566
|
if (this !== this.#s)
|
|
@@ -538,68 +631,68 @@ class E {
|
|
|
538
631
|
e.copyIn(n);
|
|
539
632
|
return e;
|
|
540
633
|
}
|
|
541
|
-
static #
|
|
542
|
-
let r = !1, o = !1, a = -1,
|
|
634
|
+
static #h(t, e, n, i) {
|
|
635
|
+
let r = !1, o = !1, a = -1, l = !1;
|
|
543
636
|
if (e.type === null) {
|
|
544
|
-
let d = n,
|
|
637
|
+
let d = n, m = "";
|
|
545
638
|
for (; d < t.length; ) {
|
|
546
639
|
const p = t.charAt(d++);
|
|
547
640
|
if (r || p === "\\\\") {
|
|
548
|
-
r = !r,
|
|
641
|
+
r = !r, m += p;
|
|
549
642
|
continue;
|
|
550
643
|
}
|
|
551
644
|
if (o) {
|
|
552
|
-
d === a + 1 ? (p === "^" || p === "!") && (
|
|
645
|
+
d === a + 1 ? (p === "^" || p === "!") && (l = !0) : p === "]" && !(d === a + 2 && l) && (o = !1), m += p;
|
|
553
646
|
continue;
|
|
554
647
|
} else if (p === "[") {
|
|
555
|
-
o = !0, a = d,
|
|
648
|
+
o = !0, a = d, l = !1, m += p;
|
|
556
649
|
continue;
|
|
557
650
|
}
|
|
558
|
-
if (!i.noext &&
|
|
559
|
-
e.push(
|
|
651
|
+
if (!i.noext && rt(p) && t.charAt(d) === "(") {
|
|
652
|
+
e.push(m), m = "";
|
|
560
653
|
const S = new E(p, e);
|
|
561
|
-
d = E.#
|
|
654
|
+
d = E.#h(t, S, d, i), e.push(S);
|
|
562
655
|
continue;
|
|
563
656
|
}
|
|
564
|
-
|
|
657
|
+
m += p;
|
|
565
658
|
}
|
|
566
|
-
return e.push(
|
|
659
|
+
return e.push(m), d;
|
|
567
660
|
}
|
|
568
|
-
let
|
|
661
|
+
let h = n + 1, c = new E(null, e);
|
|
569
662
|
const f = [];
|
|
570
663
|
let u = "";
|
|
571
|
-
for (;
|
|
572
|
-
const d = t.charAt(
|
|
664
|
+
for (; h < t.length; ) {
|
|
665
|
+
const d = t.charAt(h++);
|
|
573
666
|
if (r || d === "\\\\") {
|
|
574
667
|
r = !r, u += d;
|
|
575
668
|
continue;
|
|
576
669
|
}
|
|
577
670
|
if (o) {
|
|
578
|
-
|
|
671
|
+
h === a + 1 ? (d === "^" || d === "!") && (l = !0) : d === "]" && !(h === a + 2 && l) && (o = !1), u += d;
|
|
579
672
|
continue;
|
|
580
673
|
} else if (d === "[") {
|
|
581
|
-
o = !0, a =
|
|
674
|
+
o = !0, a = h, l = !1, u += d;
|
|
582
675
|
continue;
|
|
583
676
|
}
|
|
584
|
-
if (
|
|
585
|
-
|
|
586
|
-
const
|
|
587
|
-
|
|
677
|
+
if (rt(d) && t.charAt(h) === "(") {
|
|
678
|
+
c.push(u), u = "";
|
|
679
|
+
const m = new E(d, c);
|
|
680
|
+
c.push(m), h = E.#h(t, m, h, i);
|
|
588
681
|
continue;
|
|
589
682
|
}
|
|
590
683
|
if (d === "|") {
|
|
591
|
-
|
|
684
|
+
c.push(u), u = "", f.push(c), c = new E(null, e);
|
|
592
685
|
continue;
|
|
593
686
|
}
|
|
594
687
|
if (d === ")")
|
|
595
|
-
return u === "" && e.#t.length === 0 && (e.#u = !0),
|
|
688
|
+
return u === "" && e.#t.length === 0 && (e.#u = !0), c.push(u), u = "", e.push(...f, c), h;
|
|
596
689
|
u += d;
|
|
597
690
|
}
|
|
598
|
-
return e.type = null, e.#n = void 0, e.#t = [t.substring(n - 1)],
|
|
691
|
+
return e.type = null, e.#n = void 0, e.#t = [t.substring(n - 1)], h;
|
|
599
692
|
}
|
|
600
693
|
static fromGlob(t, e = {}) {
|
|
601
694
|
const n = new E(null, void 0, e);
|
|
602
|
-
return E.#
|
|
695
|
+
return E.#h(t, n, 0, e), n;
|
|
603
696
|
}
|
|
604
697
|
// returns the regular expression if there's magic, or the unescaped
|
|
605
698
|
// string if not.
|
|
@@ -690,24 +783,24 @@ class E {
|
|
|
690
783
|
toRegExpSource(t) {
|
|
691
784
|
const e = t ?? !!this.#i.dot;
|
|
692
785
|
if (this.#s === this && this.#d(), !this.type) {
|
|
693
|
-
const
|
|
694
|
-
const [
|
|
695
|
-
return this.#n = this.#n || S, this.#r = this.#r ||
|
|
786
|
+
const l = this.isStart() && this.isEnd(), h = this.#t.map((d) => {
|
|
787
|
+
const [m, p, S, v] = typeof d == "string" ? E.#p(d, this.#n, l) : d.toRegExpSource(t);
|
|
788
|
+
return this.#n = this.#n || S, this.#r = this.#r || v, m;
|
|
696
789
|
}).join("");
|
|
697
|
-
let
|
|
698
|
-
if (this.isStart() && typeof this.#t[0] == "string" && !(this.#t.length === 1 &&
|
|
699
|
-
const
|
|
790
|
+
let c = "";
|
|
791
|
+
if (this.isStart() && typeof this.#t[0] == "string" && !(this.#t.length === 1 && Ee.has(this.#t[0]))) {
|
|
792
|
+
const m = ye, p = (
|
|
700
793
|
// dots are allowed, and the pattern starts with [ or .
|
|
701
|
-
e &&
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
), S = !e && !t &&
|
|
705
|
-
|
|
794
|
+
e && m.has(h.charAt(0)) || // the pattern starts with \\., and then [ or .
|
|
795
|
+
h.startsWith("\\\\.") && m.has(h.charAt(2)) || // the pattern starts with \\.\\., and then [ or .
|
|
796
|
+
h.startsWith("\\\\.\\\\.") && m.has(h.charAt(4))
|
|
797
|
+
), S = !e && !t && m.has(h.charAt(0));
|
|
798
|
+
c = p ? we : S ? k : "";
|
|
706
799
|
}
|
|
707
800
|
let f = "";
|
|
708
801
|
return this.isEnd() && this.#s.#a && this.#e?.type === "!" && (f = "(?:$|\\\\/)"), [
|
|
709
|
-
|
|
710
|
-
$(
|
|
802
|
+
c + h + f,
|
|
803
|
+
$(h),
|
|
711
804
|
this.#n = !!this.#n,
|
|
712
805
|
this.#r
|
|
713
806
|
];
|
|
@@ -715,20 +808,20 @@ class E {
|
|
|
715
808
|
const n = this.type === "*" || this.type === "+", i = this.type === "!" ? "(?:(?!(?:" : "(?:";
|
|
716
809
|
let r = this.#f(e);
|
|
717
810
|
if (this.isStart() && this.isEnd() && !r && this.type !== "!") {
|
|
718
|
-
const
|
|
719
|
-
return this.#t = [
|
|
811
|
+
const l = this.toString();
|
|
812
|
+
return this.#t = [l], this.type = null, this.#n = void 0, [l, $(this.toString()), !1, !1];
|
|
720
813
|
}
|
|
721
814
|
let o = !n || t || e || !k ? "" : this.#f(!0);
|
|
722
815
|
o === r && (o = ""), o && (r = \`(?:\${r})(?:\${o})*?\`);
|
|
723
816
|
let a = "";
|
|
724
817
|
if (this.type === "!" && this.#u)
|
|
725
|
-
a = (this.isStart() && !e ? k : "") +
|
|
818
|
+
a = (this.isStart() && !e ? k : "") + at;
|
|
726
819
|
else {
|
|
727
|
-
const
|
|
820
|
+
const l = this.type === "!" ? (
|
|
728
821
|
// !() must match something,but !(x) can match ''
|
|
729
|
-
"))" + (this.isStart() && !e && !t ? k : "") +
|
|
822
|
+
"))" + (this.isStart() && !e && !t ? k : "") + ot + ")"
|
|
730
823
|
) : this.type === "@" ? ")" : this.type === "?" ? ")?" : this.type === "+" && o ? ")" : this.type === "*" && o ? ")?" : \`)\${this.type}\`;
|
|
731
|
-
a = i + r +
|
|
824
|
+
a = i + r + l;
|
|
732
825
|
}
|
|
733
826
|
return [
|
|
734
827
|
a,
|
|
@@ -748,108 +841,108 @@ class E {
|
|
|
748
841
|
static #p(t, e, n = !1) {
|
|
749
842
|
let i = !1, r = "", o = !1;
|
|
750
843
|
for (let a = 0; a < t.length; a++) {
|
|
751
|
-
const
|
|
844
|
+
const l = t.charAt(a);
|
|
752
845
|
if (i) {
|
|
753
|
-
i = !1, r += (
|
|
846
|
+
i = !1, r += (Se.has(l) ? "\\\\" : "") + l;
|
|
754
847
|
continue;
|
|
755
848
|
}
|
|
756
|
-
if (
|
|
849
|
+
if (l === "\\\\") {
|
|
757
850
|
a === t.length - 1 ? r += "\\\\\\\\" : i = !0;
|
|
758
851
|
continue;
|
|
759
852
|
}
|
|
760
|
-
if (
|
|
761
|
-
const [
|
|
853
|
+
if (l === "[") {
|
|
854
|
+
const [h, c, f, u] = ge(t, a);
|
|
762
855
|
if (f) {
|
|
763
|
-
r +=
|
|
856
|
+
r += h, o = o || c, a += f - 1, e = e || u;
|
|
764
857
|
continue;
|
|
765
858
|
}
|
|
766
859
|
}
|
|
767
|
-
if (
|
|
768
|
-
n && t === "*" ? r +=
|
|
860
|
+
if (l === "*") {
|
|
861
|
+
n && t === "*" ? r += at : r += ot, e = !0;
|
|
769
862
|
continue;
|
|
770
863
|
}
|
|
771
|
-
if (
|
|
864
|
+
if (l === "?") {
|
|
772
865
|
r += Q, e = !0;
|
|
773
866
|
continue;
|
|
774
867
|
}
|
|
775
|
-
r +=
|
|
868
|
+
r += be(l);
|
|
776
869
|
}
|
|
777
870
|
return [r, $(t), !!e, o];
|
|
778
871
|
}
|
|
779
872
|
}
|
|
780
|
-
const
|
|
873
|
+
const xe = (s, { windowsPathsNoEscape: t = !1 } = {}) => t ? s.replace(/[?*()[\\]]/g, "[$&]") : s.replace(/[?*()[\\]\\\\]/g, "\\\\$&"), y = (s, t, e = {}) => (W(t), !e.nocomment && t.charAt(0) === "#" ? !1 : new j(t, e).match(s)), Ae = /^\\*+([^+@!?\\*\\[\\(]*)$/, ve = (s) => (t) => !t.startsWith(".") && t.endsWith(s), Ce = (s) => (t) => t.endsWith(s), Oe = (s) => (s = s.toLowerCase(), (t) => !t.startsWith(".") && t.toLowerCase().endsWith(s)), De = (s) => (s = s.toLowerCase(), (t) => t.toLowerCase().endsWith(s)), Ne = /^\\*+\\.\\*+$/, Fe = (s) => !s.startsWith(".") && s.includes("."), Te = (s) => s !== "." && s !== ".." && s.includes("."), Me = /^\\.\\*+$/, $e = (s) => s !== "." && s !== ".." && s.startsWith("."), Pe = /^\\*+$/, Re = (s) => s.length !== 0 && !s.startsWith("."), ke = (s) => s.length !== 0 && s !== "." && s !== "..", Le = /^\\?+([^+@!?\\*\\[\\(]*)?$/, Ie = ([s, t = ""]) => {
|
|
781
874
|
const e = At([s]);
|
|
782
875
|
return t ? (t = t.toLowerCase(), (n) => e(n) && n.toLowerCase().endsWith(t)) : e;
|
|
783
|
-
},
|
|
784
|
-
const e =
|
|
876
|
+
}, ze = ([s, t = ""]) => {
|
|
877
|
+
const e = vt([s]);
|
|
785
878
|
return t ? (t = t.toLowerCase(), (n) => e(n) && n.toLowerCase().endsWith(t)) : e;
|
|
786
|
-
},
|
|
787
|
-
const e =
|
|
879
|
+
}, He = ([s, t = ""]) => {
|
|
880
|
+
const e = vt([s]);
|
|
788
881
|
return t ? (n) => e(n) && n.endsWith(t) : e;
|
|
789
|
-
},
|
|
882
|
+
}, We = ([s, t = ""]) => {
|
|
790
883
|
const e = At([s]);
|
|
791
884
|
return t ? (n) => e(n) && n.endsWith(t) : e;
|
|
792
885
|
}, At = ([s]) => {
|
|
793
886
|
const t = s.length;
|
|
794
887
|
return (e) => e.length === t && !e.startsWith(".");
|
|
795
|
-
},
|
|
888
|
+
}, vt = ([s]) => {
|
|
796
889
|
const t = s.length;
|
|
797
890
|
return (e) => e.length === t && e !== "." && e !== "..";
|
|
798
|
-
}, Ct = typeof process == "object" && process ? typeof process.env == "object" && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix",
|
|
891
|
+
}, Ct = typeof process == "object" && process ? typeof process.env == "object" && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix", ct = {
|
|
799
892
|
win32: { sep: "\\\\" },
|
|
800
893
|
posix: { sep: "/" }
|
|
801
|
-
},
|
|
802
|
-
y.sep =
|
|
894
|
+
}, je = Ct === "win32" ? ct.win32.sep : ct.posix.sep;
|
|
895
|
+
y.sep = je;
|
|
803
896
|
const A = Symbol("globstar **");
|
|
804
897
|
y.GLOBSTAR = A;
|
|
805
|
-
const
|
|
806
|
-
y.filter =
|
|
807
|
-
const
|
|
898
|
+
const Ue = "[^/]", _e = Ue + "*?", Be = "(?:(?!(?:\\\\/|^)(?:\\\\.{1,2})($|\\\\/)).)*?", Ge = "(?:(?!(?:\\\\/|^)\\\\.).)*?", qe = (s, t = {}) => (e) => y(e, s, t);
|
|
899
|
+
y.filter = qe;
|
|
900
|
+
const x = (s, t = {}) => Object.assign({}, s, t), Ve = (s) => {
|
|
808
901
|
if (!s || typeof s != "object" || !Object.keys(s).length)
|
|
809
902
|
return y;
|
|
810
903
|
const t = y;
|
|
811
|
-
return Object.assign((n, i, r = {}) => t(n, i,
|
|
904
|
+
return Object.assign((n, i, r = {}) => t(n, i, x(s, r)), {
|
|
812
905
|
Minimatch: class extends t.Minimatch {
|
|
813
906
|
constructor(i, r = {}) {
|
|
814
|
-
super(i,
|
|
907
|
+
super(i, x(s, r));
|
|
815
908
|
}
|
|
816
909
|
static defaults(i) {
|
|
817
|
-
return t.defaults(
|
|
910
|
+
return t.defaults(x(s, i)).Minimatch;
|
|
818
911
|
}
|
|
819
912
|
},
|
|
820
913
|
AST: class extends t.AST {
|
|
821
914
|
/* c8 ignore start */
|
|
822
915
|
constructor(i, r, o = {}) {
|
|
823
|
-
super(i, r,
|
|
916
|
+
super(i, r, x(s, o));
|
|
824
917
|
}
|
|
825
918
|
/* c8 ignore stop */
|
|
826
919
|
static fromGlob(i, r = {}) {
|
|
827
|
-
return t.AST.fromGlob(i,
|
|
920
|
+
return t.AST.fromGlob(i, x(s, r));
|
|
828
921
|
}
|
|
829
922
|
},
|
|
830
|
-
unescape: (n, i = {}) => t.unescape(n,
|
|
831
|
-
escape: (n, i = {}) => t.escape(n,
|
|
832
|
-
filter: (n, i = {}) => t.filter(n,
|
|
833
|
-
defaults: (n) => t.defaults(
|
|
834
|
-
makeRe: (n, i = {}) => t.makeRe(n,
|
|
835
|
-
braceExpand: (n, i = {}) => t.braceExpand(n,
|
|
836
|
-
match: (n, i, r = {}) => t.match(n, i,
|
|
923
|
+
unescape: (n, i = {}) => t.unescape(n, x(s, i)),
|
|
924
|
+
escape: (n, i = {}) => t.escape(n, x(s, i)),
|
|
925
|
+
filter: (n, i = {}) => t.filter(n, x(s, i)),
|
|
926
|
+
defaults: (n) => t.defaults(x(s, n)),
|
|
927
|
+
makeRe: (n, i = {}) => t.makeRe(n, x(s, i)),
|
|
928
|
+
braceExpand: (n, i = {}) => t.braceExpand(n, x(s, i)),
|
|
929
|
+
match: (n, i, r = {}) => t.match(n, i, x(s, r)),
|
|
837
930
|
sep: t.sep,
|
|
838
931
|
GLOBSTAR: A
|
|
839
932
|
});
|
|
840
933
|
};
|
|
841
|
-
y.defaults =
|
|
842
|
-
const Ot = (s, t = {}) => (
|
|
934
|
+
y.defaults = Ve;
|
|
935
|
+
const Ot = (s, t = {}) => (W(s), t.nobrace || !/\\{(?:(?!\\{).)*\\}/.test(s) ? [s] : ae(s));
|
|
843
936
|
y.braceExpand = Ot;
|
|
844
|
-
const
|
|
845
|
-
y.makeRe =
|
|
846
|
-
const
|
|
847
|
-
const n = new
|
|
937
|
+
const Xe = (s, t = {}) => new j(s, t).makeRe();
|
|
938
|
+
y.makeRe = Xe;
|
|
939
|
+
const Ye = (s, t, e = {}) => {
|
|
940
|
+
const n = new j(t, e);
|
|
848
941
|
return s = s.filter((i) => n.match(i)), n.options.nonull && !s.length && s.push(t), s;
|
|
849
942
|
};
|
|
850
|
-
y.match =
|
|
851
|
-
const
|
|
852
|
-
class
|
|
943
|
+
y.match = Ye;
|
|
944
|
+
const lt = /[?*]|[+@!]\\(.*?\\)|\\[|\\]/, Ze = (s) => s.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, "\\\\$&");
|
|
945
|
+
class j {
|
|
853
946
|
options;
|
|
854
947
|
set;
|
|
855
948
|
pattern;
|
|
@@ -868,7 +961,7 @@ class _ {
|
|
|
868
961
|
windowsNoMagicRoot;
|
|
869
962
|
regexp;
|
|
870
963
|
constructor(t, e = {}) {
|
|
871
|
-
|
|
964
|
+
W(t), e = e || {}, this.options = e, this.pattern = t, this.platform = e.platform || Ct, 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();
|
|
872
965
|
}
|
|
873
966
|
hasMagic() {
|
|
874
967
|
if (this.options.magicalBraces && this.set.length > 1)
|
|
@@ -896,13 +989,13 @@ class _ {
|
|
|
896
989
|
this.globParts = this.preprocess(n), this.debug(this.pattern, this.globParts);
|
|
897
990
|
let i = this.globParts.map((r, o, a) => {
|
|
898
991
|
if (this.isWindows && this.windowsNoMagicRoot) {
|
|
899
|
-
const
|
|
900
|
-
if (c)
|
|
901
|
-
return [...r.slice(0, 4), ...r.slice(4).map((h) => this.parse(h))];
|
|
992
|
+
const l = r[0] === "" && r[1] === "" && (r[2] === "?" || !lt.test(r[2])) && !lt.test(r[3]), h = /^[a-z]:/i.test(r[0]);
|
|
902
993
|
if (l)
|
|
903
|
-
return [r
|
|
994
|
+
return [...r.slice(0, 4), ...r.slice(4).map((c) => this.parse(c))];
|
|
995
|
+
if (h)
|
|
996
|
+
return [r[0], ...r.slice(1).map((c) => this.parse(c))];
|
|
904
997
|
}
|
|
905
|
-
return r.map((
|
|
998
|
+
return r.map((l) => this.parse(l));
|
|
906
999
|
});
|
|
907
1000
|
if (this.debug(this.pattern, i), this.set = i.filter((r) => r.indexOf(!1) === -1), this.isWindows)
|
|
908
1001
|
for (let r = 0; r < this.set.length; r++) {
|
|
@@ -993,12 +1086,12 @@ class _ {
|
|
|
993
1086
|
o++;
|
|
994
1087
|
o > i && n.splice(i + 1, o - i);
|
|
995
1088
|
let a = n[i + 1];
|
|
996
|
-
const
|
|
997
|
-
if (a !== ".." || !
|
|
1089
|
+
const l = n[i + 2], h = n[i + 3];
|
|
1090
|
+
if (a !== ".." || !l || l === "." || l === ".." || !h || h === "." || h === "..")
|
|
998
1091
|
continue;
|
|
999
1092
|
e = !0, n.splice(i, 1);
|
|
1000
|
-
const
|
|
1001
|
-
|
|
1093
|
+
const c = n.slice(0);
|
|
1094
|
+
c[i] = "**", t.push(c), i--;
|
|
1002
1095
|
}
|
|
1003
1096
|
if (!this.preserveMultipleSlashes) {
|
|
1004
1097
|
for (let o = 1; o < n.length - 1; o++) {
|
|
@@ -1012,8 +1105,8 @@ class _ {
|
|
|
1012
1105
|
const o = n[r - 1];
|
|
1013
1106
|
if (o && o !== "." && o !== ".." && o !== "**") {
|
|
1014
1107
|
e = !0;
|
|
1015
|
-
const
|
|
1016
|
-
n.splice(r - 1, 2, ...
|
|
1108
|
+
const l = r === 1 && n[r + 1] === "**" ? ["."] : [];
|
|
1109
|
+
n.splice(r - 1, 2, ...l), n.length === 0 && n.push(""), r -= 2;
|
|
1017
1110
|
}
|
|
1018
1111
|
}
|
|
1019
1112
|
}
|
|
@@ -1076,66 +1169,66 @@ class _ {
|
|
|
1076
1169
|
matchOne(t, e, n = !1) {
|
|
1077
1170
|
const i = this.options;
|
|
1078
1171
|
if (this.isWindows) {
|
|
1079
|
-
const p = typeof t[0] == "string" && /^[a-z]:$/i.test(t[0]), S = !p && t[0] === "" && t[1] === "" && t[2] === "?" && /^[a-z]:$/i.test(t[3]),
|
|
1080
|
-
if (typeof
|
|
1081
|
-
const [
|
|
1082
|
-
|
|
1172
|
+
const p = typeof t[0] == "string" && /^[a-z]:$/i.test(t[0]), S = !p && t[0] === "" && t[1] === "" && t[2] === "?" && /^[a-z]:$/i.test(t[3]), v = typeof e[0] == "string" && /^[a-z]:$/i.test(e[0]), N = !v && e[0] === "" && e[1] === "" && e[2] === "?" && typeof e[3] == "string" && /^[a-z]:$/i.test(e[3]), b = S ? 3 : p ? 0 : void 0, w = N ? 3 : v ? 0 : void 0;
|
|
1173
|
+
if (typeof b == "number" && typeof w == "number") {
|
|
1174
|
+
const [F, P] = [t[b], e[w]];
|
|
1175
|
+
F.toLowerCase() === P.toLowerCase() && (e[w] = F, w > b ? e = e.slice(w) : b > w && (t = t.slice(b)));
|
|
1083
1176
|
}
|
|
1084
1177
|
}
|
|
1085
1178
|
const { optimizationLevel: r = 1 } = this.options;
|
|
1086
1179
|
r >= 2 && (t = this.levelTwoFileOptimize(t)), this.debug("matchOne", this, { file: t, pattern: e }), this.debug("matchOne", t.length, e.length);
|
|
1087
|
-
for (var o = 0, a = 0,
|
|
1180
|
+
for (var o = 0, a = 0, l = t.length, h = e.length; o < l && a < h; o++, a++) {
|
|
1088
1181
|
this.debug("matchOne loop");
|
|
1089
|
-
var
|
|
1090
|
-
if (this.debug(e,
|
|
1182
|
+
var c = e[a], f = t[o];
|
|
1183
|
+
if (this.debug(e, c, f), c === !1)
|
|
1091
1184
|
return !1;
|
|
1092
|
-
if (
|
|
1093
|
-
this.debug("GLOBSTAR", [e,
|
|
1185
|
+
if (c === A) {
|
|
1186
|
+
this.debug("GLOBSTAR", [e, c, f]);
|
|
1094
1187
|
var u = o, d = a + 1;
|
|
1095
|
-
if (d ===
|
|
1096
|
-
for (this.debug("** at the end"); o <
|
|
1188
|
+
if (d === h) {
|
|
1189
|
+
for (this.debug("** at the end"); o < l; o++)
|
|
1097
1190
|
if (t[o] === "." || t[o] === ".." || !i.dot && t[o].charAt(0) === ".")
|
|
1098
1191
|
return !1;
|
|
1099
1192
|
return !0;
|
|
1100
1193
|
}
|
|
1101
|
-
for (; u <
|
|
1102
|
-
var
|
|
1194
|
+
for (; u < l; ) {
|
|
1195
|
+
var m = t[u];
|
|
1103
1196
|
if (this.debug(\`
|
|
1104
|
-
globstar while\`, t, u, e, d,
|
|
1105
|
-
return this.debug("globstar found match!", u,
|
|
1106
|
-
if (
|
|
1197
|
+
globstar while\`, t, u, e, d, m), this.matchOne(t.slice(u), e.slice(d), n))
|
|
1198
|
+
return this.debug("globstar found match!", u, l, m), !0;
|
|
1199
|
+
if (m === "." || m === ".." || !i.dot && m.charAt(0) === ".") {
|
|
1107
1200
|
this.debug("dot detected!", t, u, e, d);
|
|
1108
1201
|
break;
|
|
1109
1202
|
}
|
|
1110
1203
|
this.debug("globstar swallow a segment, and continue"), u++;
|
|
1111
1204
|
}
|
|
1112
1205
|
return !!(n && (this.debug(\`
|
|
1113
|
-
>>> no match, partial?\`, t, u, e, d), u ===
|
|
1206
|
+
>>> no match, partial?\`, t, u, e, d), u === l));
|
|
1114
1207
|
}
|
|
1115
1208
|
let p;
|
|
1116
|
-
if (typeof
|
|
1209
|
+
if (typeof c == "string" ? (p = f === c, this.debug("string match", c, f, p)) : (p = c.test(f), this.debug("pattern match", c, f, p)), !p)
|
|
1117
1210
|
return !1;
|
|
1118
1211
|
}
|
|
1119
|
-
if (o ===
|
|
1212
|
+
if (o === l && a === h)
|
|
1120
1213
|
return !0;
|
|
1121
|
-
if (o ===
|
|
1214
|
+
if (o === l)
|
|
1122
1215
|
return n;
|
|
1123
|
-
if (a ===
|
|
1124
|
-
return o ===
|
|
1216
|
+
if (a === h)
|
|
1217
|
+
return o === l - 1 && t[o] === "";
|
|
1125
1218
|
throw new Error("wtf?");
|
|
1126
1219
|
}
|
|
1127
1220
|
braceExpand() {
|
|
1128
1221
|
return Ot(this.pattern, this.options);
|
|
1129
1222
|
}
|
|
1130
1223
|
parse(t) {
|
|
1131
|
-
|
|
1224
|
+
W(t);
|
|
1132
1225
|
const e = this.options;
|
|
1133
1226
|
if (t === "**")
|
|
1134
1227
|
return A;
|
|
1135
1228
|
if (t === "")
|
|
1136
1229
|
return "";
|
|
1137
1230
|
let n, i = null;
|
|
1138
|
-
(n = t.match(
|
|
1231
|
+
(n = t.match(Pe)) ? i = e.dot ? ke : Re : (n = t.match(Ae)) ? i = (e.nocase ? e.dot ? De : Oe : e.dot ? Ce : ve)(n[1]) : (n = t.match(Le)) ? i = (e.nocase ? e.dot ? ze : Ie : e.dot ? He : We)(n) : (n = t.match(Ne)) ? i = e.dot ? Te : Fe : (n = t.match(Me)) && (i = $e);
|
|
1139
1232
|
const r = E.fromGlob(t, this.options).toMMPattern();
|
|
1140
1233
|
return i && typeof r == "object" && Reflect.defineProperty(r, "test", { value: i }), r;
|
|
1141
1234
|
}
|
|
@@ -1145,18 +1238,18 @@ globstar while\`, t, u, e, d, w), this.matchOne(t.slice(u), e.slice(d), n))
|
|
|
1145
1238
|
const t = this.set;
|
|
1146
1239
|
if (!t.length)
|
|
1147
1240
|
return this.regexp = !1, this.regexp;
|
|
1148
|
-
const e = this.options, n = e.noglobstar ?
|
|
1149
|
-
let r = t.map((
|
|
1150
|
-
const
|
|
1151
|
-
if (
|
|
1152
|
-
for (const f of
|
|
1241
|
+
const e = this.options, n = e.noglobstar ? _e : e.dot ? Be : Ge, i = new Set(e.nocase ? ["i"] : []);
|
|
1242
|
+
let r = t.map((l) => {
|
|
1243
|
+
const h = l.map((c) => {
|
|
1244
|
+
if (c instanceof RegExp)
|
|
1245
|
+
for (const f of c.flags.split(""))
|
|
1153
1246
|
i.add(f);
|
|
1154
|
-
return typeof
|
|
1247
|
+
return typeof c == "string" ? Ze(c) : c === A ? A : c._src;
|
|
1155
1248
|
});
|
|
1156
|
-
return
|
|
1157
|
-
const u =
|
|
1158
|
-
|
|
1159
|
-
}),
|
|
1249
|
+
return h.forEach((c, f) => {
|
|
1250
|
+
const u = h[f + 1], d = h[f - 1];
|
|
1251
|
+
c !== A || d === A || (d === void 0 ? u !== void 0 && u !== A ? h[f + 1] = "(?:\\\\/|" + n + "\\\\/)?" + u : h[f] = n : u === void 0 ? h[f - 1] = d + "(?:\\\\/|" + n + ")?" : u !== A && (h[f - 1] = d + "(?:\\\\/|\\\\/" + n + "\\\\/)" + u, h[f + 1] = A));
|
|
1252
|
+
}), h.filter((c) => c !== A).join("/");
|
|
1160
1253
|
}).join("|");
|
|
1161
1254
|
const [o, a] = t.length > 1 ? ["(?:", ")"] : ["", ""];
|
|
1162
1255
|
r = "^" + o + r + a + "$", this.negate && (r = "^(?!" + r + ").+$");
|
|
@@ -1188,9 +1281,9 @@ globstar while\`, t, u, e, d, w), this.matchOne(t.slice(u), e.slice(d), n))
|
|
|
1188
1281
|
for (let a = i.length - 2; !o && a >= 0; a--)
|
|
1189
1282
|
o = i[a];
|
|
1190
1283
|
for (let a = 0; a < r.length; a++) {
|
|
1191
|
-
const
|
|
1192
|
-
let
|
|
1193
|
-
if (n.matchBase &&
|
|
1284
|
+
const l = r[a];
|
|
1285
|
+
let h = i;
|
|
1286
|
+
if (n.matchBase && l.length === 1 && (h = [o]), this.matchOne(h, l, e))
|
|
1194
1287
|
return n.flipNegate ? !0 : !this.negate;
|
|
1195
1288
|
}
|
|
1196
1289
|
return n.flipNegate ? !1 : this.negate;
|
|
@@ -1200,136 +1293,107 @@ globstar while\`, t, u, e, d, w), this.matchOne(t.slice(u), e.slice(d), n))
|
|
|
1200
1293
|
}
|
|
1201
1294
|
}
|
|
1202
1295
|
y.AST = E;
|
|
1203
|
-
y.Minimatch =
|
|
1204
|
-
y.escape =
|
|
1296
|
+
y.Minimatch = j;
|
|
1297
|
+
y.escape = xe;
|
|
1205
1298
|
y.unescape = $;
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
return String.fromCharCode(...s);
|
|
1269
|
-
case "ascii":
|
|
1270
|
-
return String.fromCharCode(...s.map((e) => e & 127));
|
|
1271
|
-
case "base64":
|
|
1272
|
-
return btoa(String.fromCharCode(...s));
|
|
1273
|
-
case "hex":
|
|
1274
|
-
return Array.from(s).map((e) => e.toString(16).padStart(2, "0")).join("");
|
|
1275
|
-
default:
|
|
1276
|
-
return console.warn("Unsupported encoding, falling back to UTF-8"), new TextDecoder().decode(s);
|
|
1277
|
-
}
|
|
1278
|
-
}
|
|
1279
|
-
function qe(s) {
|
|
1280
|
-
const t = new Uint8Array(s.length * 2);
|
|
1281
|
-
for (let e = 0; e < s.length; e++) {
|
|
1282
|
-
const n = s.charCodeAt(e);
|
|
1283
|
-
t[e * 2] = n & 255, t[e * 2 + 1] = n >> 8;
|
|
1284
|
-
}
|
|
1285
|
-
return t;
|
|
1286
|
-
}
|
|
1287
|
-
function Ve(s) {
|
|
1288
|
-
s.length % 2 !== 0 && (console.warn("Invalid UTF-16LE buffer length, truncating last byte"), s = s.slice(0, s.length - 1));
|
|
1289
|
-
const t = new Uint16Array(s.buffer, s.byteOffset, s.byteLength / 2);
|
|
1290
|
-
return String.fromCharCode(...t);
|
|
1291
|
-
}
|
|
1292
|
-
function Ze(s) {
|
|
1293
|
-
const t = new Uint8Array(s.length);
|
|
1294
|
-
for (let e = 0; e < s.length; e++)
|
|
1295
|
-
t[e] = s.charCodeAt(e) & 255;
|
|
1296
|
-
return t;
|
|
1297
|
-
}
|
|
1298
|
-
function Xe(s) {
|
|
1299
|
-
const t = new Uint8Array(s.length);
|
|
1300
|
-
for (let e = 0; e < s.length; e++)
|
|
1301
|
-
t[e] = s.charCodeAt(e) & 127;
|
|
1302
|
-
return t;
|
|
1299
|
+
const Je = [
|
|
1300
|
+
// Images
|
|
1301
|
+
".jpg",
|
|
1302
|
+
".jpeg",
|
|
1303
|
+
".png",
|
|
1304
|
+
".gif",
|
|
1305
|
+
".bmp",
|
|
1306
|
+
".webp",
|
|
1307
|
+
".svg",
|
|
1308
|
+
".ico",
|
|
1309
|
+
".tiff",
|
|
1310
|
+
".tga",
|
|
1311
|
+
// Audio
|
|
1312
|
+
".mp3",
|
|
1313
|
+
".wav",
|
|
1314
|
+
".ogg",
|
|
1315
|
+
".flac",
|
|
1316
|
+
".aac",
|
|
1317
|
+
".wma",
|
|
1318
|
+
".m4a",
|
|
1319
|
+
// Video
|
|
1320
|
+
".mp4",
|
|
1321
|
+
".avi",
|
|
1322
|
+
".mov",
|
|
1323
|
+
".wmv",
|
|
1324
|
+
".flv",
|
|
1325
|
+
".webm",
|
|
1326
|
+
".mkv",
|
|
1327
|
+
".m4v",
|
|
1328
|
+
// Documents
|
|
1329
|
+
".pdf",
|
|
1330
|
+
".doc",
|
|
1331
|
+
".docx",
|
|
1332
|
+
".xls",
|
|
1333
|
+
".xlsx",
|
|
1334
|
+
".ppt",
|
|
1335
|
+
".pptx",
|
|
1336
|
+
// Archives
|
|
1337
|
+
".zip",
|
|
1338
|
+
".rar",
|
|
1339
|
+
".7z",
|
|
1340
|
+
".tar",
|
|
1341
|
+
".gz",
|
|
1342
|
+
".bz2",
|
|
1343
|
+
// Executables
|
|
1344
|
+
".exe",
|
|
1345
|
+
".dll",
|
|
1346
|
+
".so",
|
|
1347
|
+
".dylib",
|
|
1348
|
+
".bin",
|
|
1349
|
+
// Other binary formats
|
|
1350
|
+
".dat",
|
|
1351
|
+
".db",
|
|
1352
|
+
".sqlite",
|
|
1353
|
+
".bin",
|
|
1354
|
+
".obj",
|
|
1355
|
+
".fbx",
|
|
1356
|
+
".3ds"
|
|
1357
|
+
];
|
|
1358
|
+
function G(s) {
|
|
1359
|
+
const t = s.toLowerCase().substring(s.lastIndexOf("."));
|
|
1360
|
+
return Je.includes(t);
|
|
1303
1361
|
}
|
|
1304
|
-
function
|
|
1362
|
+
function Ke() {
|
|
1305
1363
|
if (!("storage" in navigator) || !("getDirectory" in navigator.storage))
|
|
1306
|
-
throw new
|
|
1364
|
+
throw new Wt();
|
|
1307
1365
|
}
|
|
1308
|
-
function
|
|
1366
|
+
async function tt(s, t, e) {
|
|
1367
|
+
return typeof navigator < "u" && navigator.locks?.request ? navigator.locks.request(\`opfs:\${s.replace(/\\/+/g, "/").toLowerCase()}\`, { mode: t }, e) : e();
|
|
1368
|
+
}
|
|
1369
|
+
function D(s) {
|
|
1309
1370
|
return Array.isArray(s) ? s : (s.startsWith("~/") ? s.slice(2) : s).split("/").filter(Boolean);
|
|
1310
1371
|
}
|
|
1311
|
-
function
|
|
1372
|
+
function et(s) {
|
|
1312
1373
|
return typeof s == "string" ? s ?? "/" : \`/\${s.join("/")}\`;
|
|
1313
1374
|
}
|
|
1314
|
-
function
|
|
1315
|
-
const t =
|
|
1375
|
+
function Y(s) {
|
|
1376
|
+
const t = D(s);
|
|
1316
1377
|
return t[t.length - 1] || "";
|
|
1317
1378
|
}
|
|
1318
|
-
function
|
|
1319
|
-
const t =
|
|
1320
|
-
return t.pop(),
|
|
1379
|
+
function q(s) {
|
|
1380
|
+
const t = D(s);
|
|
1381
|
+
return t.pop(), et(t);
|
|
1321
1382
|
}
|
|
1322
|
-
function
|
|
1383
|
+
function Z(s) {
|
|
1323
1384
|
return !s || s === "/" ? "/" : s.startsWith("~/") ? \`/\${s.slice(2)}\` : s.startsWith("/") ? s : \`/\${s}\`;
|
|
1324
1385
|
}
|
|
1325
|
-
function
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
return
|
|
1386
|
+
function Qe(s, t = !1) {
|
|
1387
|
+
return s = s.replace(/\\/$/, ""), t && !s.includes("*") ? \`\${s}/**\` : s;
|
|
1388
|
+
}
|
|
1389
|
+
function V(s, t) {
|
|
1390
|
+
return y(s, t, {
|
|
1391
|
+
dot: !0,
|
|
1392
|
+
matchBase: !0
|
|
1393
|
+
});
|
|
1330
1394
|
}
|
|
1331
|
-
function
|
|
1332
|
-
const t =
|
|
1395
|
+
function ts(s) {
|
|
1396
|
+
const t = Z(s), e = D(t), n = [];
|
|
1333
1397
|
for (const i of e)
|
|
1334
1398
|
if (!(i === "." || i === ""))
|
|
1335
1399
|
if (i === "..") {
|
|
@@ -1338,57 +1402,67 @@ function Je(s) {
|
|
|
1338
1402
|
n.pop();
|
|
1339
1403
|
} else
|
|
1340
1404
|
n.push(i);
|
|
1341
|
-
return
|
|
1405
|
+
return et(n);
|
|
1342
1406
|
}
|
|
1343
|
-
function
|
|
1344
|
-
return typeof s == "string" ?
|
|
1407
|
+
function es(s, t = "utf-8") {
|
|
1408
|
+
return typeof s == "string" ? Ut(s, t) : s instanceof Uint8Array ? s : new Uint8Array(s);
|
|
1345
1409
|
}
|
|
1346
|
-
async function
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
} finally {
|
|
1352
|
-
t.close();
|
|
1353
|
-
}
|
|
1410
|
+
async function ss(s, t) {
|
|
1411
|
+
return tt(t, "shared", async () => {
|
|
1412
|
+
const n = await (await s.getFile()).arrayBuffer();
|
|
1413
|
+
return new Uint8Array(n);
|
|
1414
|
+
});
|
|
1354
1415
|
}
|
|
1355
|
-
async function
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
i =
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1416
|
+
async function ht(s, t, e, n, i = {}) {
|
|
1417
|
+
const r = async () => {
|
|
1418
|
+
let o = null;
|
|
1419
|
+
const a = i.append || !1, l = !a && (i.truncate ?? !0);
|
|
1420
|
+
try {
|
|
1421
|
+
o = await s.createSyncAccessHandle();
|
|
1422
|
+
const h = es(t, e), c = a ? o.getSize() : 0;
|
|
1423
|
+
o.write(h, { at: c }), l && o.truncate(h.byteLength), o.flush();
|
|
1424
|
+
} catch (h) {
|
|
1425
|
+
console.error(h);
|
|
1426
|
+
const c = a ? "append" : "write";
|
|
1427
|
+
throw new g(\`Failed to \${c} file\`, \`\${c.toUpperCase()}_FAILED\`, void 0, h);
|
|
1428
|
+
} finally {
|
|
1367
1429
|
try {
|
|
1368
|
-
|
|
1430
|
+
o?.close();
|
|
1369
1431
|
} catch {
|
|
1370
1432
|
}
|
|
1371
|
-
|
|
1433
|
+
}
|
|
1434
|
+
};
|
|
1435
|
+
return n ? tt(n, "exclusive", r) : r();
|
|
1372
1436
|
}
|
|
1373
|
-
async function
|
|
1437
|
+
async function ns(s, t = "SHA-1", e = 50 * 1024 * 1024) {
|
|
1374
1438
|
if (s instanceof File && (s = await s.arrayBuffer()), s.byteLength > e)
|
|
1375
1439
|
throw new Error(\`File size \${s.byteLength} bytes exceeds maximum allowed size \${e} bytes\`);
|
|
1376
1440
|
const n = new Uint8Array(s), i = await crypto.subtle.digest(t, n);
|
|
1377
1441
|
return Array.from(new Uint8Array(i)).map((o) => o.toString(16).padStart(2, "0")).join("");
|
|
1378
1442
|
}
|
|
1379
|
-
async function
|
|
1443
|
+
async function is(s) {
|
|
1380
1444
|
const t = await s.arrayBuffer();
|
|
1381
1445
|
return new Uint8Array(t);
|
|
1382
1446
|
}
|
|
1383
|
-
|
|
1447
|
+
async function rs(s, t, e = {}) {
|
|
1448
|
+
const n = Y(t);
|
|
1449
|
+
return tt(t, "exclusive", async () => {
|
|
1450
|
+
const i = e.recursive ?? !1, r = e.force ?? !1;
|
|
1451
|
+
try {
|
|
1452
|
+
await s.removeEntry(n, { recursive: i });
|
|
1453
|
+
} catch (o) {
|
|
1454
|
+
if (o.name === "NotFoundError") {
|
|
1455
|
+
if (!r)
|
|
1456
|
+
throw new g(\`No such file or directory: \${t}\`, "ENOENT", void 0, o);
|
|
1457
|
+
} else throw o.name === "InvalidModificationError" ? new g(\`Directory not empty: \${t}. Use recursive option to force removal.\`, "ENOTEMPTY", void 0, o) : o.name === "TypeMismatchError" && !i ? new g(\`Cannot remove directory without recursive option: \${t}\`, "EISDIR", void 0, o) : new g(\`Failed to remove entry: \${t}\`, "RM_FAILED", void 0, o);
|
|
1458
|
+
}
|
|
1459
|
+
});
|
|
1460
|
+
}
|
|
1461
|
+
class os {
|
|
1384
1462
|
/** Root directory handle for the file system */
|
|
1385
1463
|
root = null;
|
|
1386
|
-
/** Map of watched paths
|
|
1464
|
+
/** Map of watched paths and options */
|
|
1387
1465
|
watchers = /* @__PURE__ */ new Map();
|
|
1388
|
-
/** Interval handle for polling watched paths */
|
|
1389
|
-
watchTimer = null;
|
|
1390
|
-
/** Flag to avoid concurrent scans */
|
|
1391
|
-
scanning = !1;
|
|
1392
1466
|
/** Promise to prevent concurrent mount operations */
|
|
1393
1467
|
mountingPromise = null;
|
|
1394
1468
|
/** BroadcastChannel instance for sending events */
|
|
@@ -1396,7 +1470,7 @@ class ss {
|
|
|
1396
1470
|
/** Configuration options */
|
|
1397
1471
|
options = {
|
|
1398
1472
|
root: "/",
|
|
1399
|
-
|
|
1473
|
+
namespace: "",
|
|
1400
1474
|
maxFileSize: 50 * 1024 * 1024,
|
|
1401
1475
|
hashAlgorithm: null,
|
|
1402
1476
|
broadcastChannel: "opfs-worker"
|
|
@@ -1413,25 +1487,26 @@ class ss {
|
|
|
1413
1487
|
async notifyChange(t) {
|
|
1414
1488
|
if (!this.options.broadcastChannel)
|
|
1415
1489
|
return;
|
|
1416
|
-
|
|
1417
|
-
if (this.
|
|
1490
|
+
const e = t.path;
|
|
1491
|
+
if (![...this.watchers.values()].some((r) => V(e, r.pattern) && r.include.some((o) => o && V(e, o)) && !r.exclude.some((o) => o && V(e, o))))
|
|
1492
|
+
return;
|
|
1493
|
+
let i;
|
|
1494
|
+
if (this.options.hashAlgorithm)
|
|
1418
1495
|
try {
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
} catch (n) {
|
|
1422
|
-
console.warn(\`Failed to calculate hash for \${t.path}:\`, n);
|
|
1496
|
+
i = (await this.stat(e)).hash;
|
|
1497
|
+
} catch {
|
|
1423
1498
|
}
|
|
1424
1499
|
try {
|
|
1425
1500
|
this.broadcastChannel || (this.broadcastChannel = new BroadcastChannel(this.options.broadcastChannel));
|
|
1426
|
-
const
|
|
1427
|
-
|
|
1501
|
+
const r = {
|
|
1502
|
+
namespace: this.options.namespace,
|
|
1428
1503
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1429
1504
|
...t,
|
|
1430
|
-
...
|
|
1505
|
+
...i && { hash: i }
|
|
1431
1506
|
};
|
|
1432
|
-
this.broadcastChannel.postMessage(
|
|
1433
|
-
} catch (
|
|
1434
|
-
console.warn("Failed to send event via BroadcastChannel:",
|
|
1507
|
+
this.broadcastChannel.postMessage(r);
|
|
1508
|
+
} catch (r) {
|
|
1509
|
+
console.warn("Failed to send event via BroadcastChannel:", r);
|
|
1435
1510
|
}
|
|
1436
1511
|
}
|
|
1437
1512
|
/**
|
|
@@ -1445,7 +1520,7 @@ class ss {
|
|
|
1445
1520
|
* @throws {OPFSError} If OPFS is not supported in the current browser
|
|
1446
1521
|
*/
|
|
1447
1522
|
constructor(t) {
|
|
1448
|
-
|
|
1523
|
+
Ke(), t && this.setOptions(t);
|
|
1449
1524
|
}
|
|
1450
1525
|
/**
|
|
1451
1526
|
* Initialize the file system within a given directory
|
|
@@ -1469,13 +1544,12 @@ class ss {
|
|
|
1469
1544
|
* \`\`\`
|
|
1470
1545
|
*/
|
|
1471
1546
|
async mount(t = this.options.root) {
|
|
1472
|
-
return this.mountingPromise && await this.mountingPromise, t =
|
|
1473
|
-
this.root = null;
|
|
1547
|
+
return this.mountingPromise && await this.mountingPromise, t = Z(t), this.mountingPromise = new Promise(async (e, n) => {
|
|
1474
1548
|
try {
|
|
1475
1549
|
const i = await navigator.storage.getDirectory();
|
|
1476
1550
|
t === "/" ? this.root = i : this.root = await this.getDirectoryHandle(t, !0, i), e(!0);
|
|
1477
|
-
} catch
|
|
1478
|
-
|
|
1551
|
+
} catch {
|
|
1552
|
+
n(new g("Failed to initialize OPFS", "INIT_FAILED"));
|
|
1479
1553
|
} finally {
|
|
1480
1554
|
this.mountingPromise = null;
|
|
1481
1555
|
}
|
|
@@ -1492,7 +1566,7 @@ class ss {
|
|
|
1492
1566
|
* @param options.broadcastChannel - Custom name for the broadcast channel
|
|
1493
1567
|
*/
|
|
1494
1568
|
async setOptions(t) {
|
|
1495
|
-
t.
|
|
1569
|
+
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 = t.root, this.options.namespace || (this.options.namespace = \`opfs-worker:\${this.options.root}\`), await this.mount(this.options.root));
|
|
1496
1570
|
}
|
|
1497
1571
|
/**
|
|
1498
1572
|
* Get a directory handle from a path
|
|
@@ -1513,9 +1587,7 @@ class ss {
|
|
|
1513
1587
|
* \`\`\`
|
|
1514
1588
|
*/
|
|
1515
1589
|
async getDirectoryHandle(t, e = !1, n = this.root) {
|
|
1516
|
-
|
|
1517
|
-
throw new q();
|
|
1518
|
-
const i = Array.isArray(t) ? t : F(t);
|
|
1590
|
+
const i = Array.isArray(t) ? t : D(t);
|
|
1519
1591
|
let r = n;
|
|
1520
1592
|
for (const o of i)
|
|
1521
1593
|
r = await r.getDirectoryHandle(o, { create: e });
|
|
@@ -1541,11 +1613,9 @@ class ss {
|
|
|
1541
1613
|
* \`\`\`
|
|
1542
1614
|
*/
|
|
1543
1615
|
async getFileHandle(t, e = !1, n = this.root) {
|
|
1544
|
-
|
|
1545
|
-
throw new q();
|
|
1546
|
-
const i = F(t);
|
|
1616
|
+
const i = D(t);
|
|
1547
1617
|
if (i.length === 0)
|
|
1548
|
-
throw new
|
|
1618
|
+
throw new jt("Path must not be empty", Array.isArray(t) ? t.join("/") : t);
|
|
1549
1619
|
const r = i.pop();
|
|
1550
1620
|
return (await this.getDirectoryHandle(i, e, n)).getFileHandle(r, { create: e });
|
|
1551
1621
|
}
|
|
@@ -1590,13 +1660,13 @@ class ss {
|
|
|
1590
1660
|
isDirectory: !0
|
|
1591
1661
|
}), await e("/"), t;
|
|
1592
1662
|
}
|
|
1593
|
-
async readFile(t, e
|
|
1594
|
-
await this.mount();
|
|
1663
|
+
async readFile(t, e) {
|
|
1664
|
+
await this.mount(), e || (e = G(t) ? "binary" : "utf-8");
|
|
1595
1665
|
try {
|
|
1596
|
-
const n = await this.getFileHandle(t, !1), i = await
|
|
1597
|
-
return e === "binary" ? i :
|
|
1666
|
+
const n = await this.getFileHandle(t, !1), i = await ss(n, t);
|
|
1667
|
+
return e === "binary" ? i : _t(i, e);
|
|
1598
1668
|
} catch (n) {
|
|
1599
|
-
throw
|
|
1669
|
+
throw new _(t, n);
|
|
1600
1670
|
}
|
|
1601
1671
|
}
|
|
1602
1672
|
/**
|
|
@@ -1626,8 +1696,8 @@ class ss {
|
|
|
1626
1696
|
*/
|
|
1627
1697
|
async writeFile(t, e, n) {
|
|
1628
1698
|
await this.mount();
|
|
1629
|
-
const i = await this.getFileHandle(t, !0);
|
|
1630
|
-
await
|
|
1699
|
+
const i = await this.exists(t), r = await this.getFileHandle(t, !0);
|
|
1700
|
+
n || (n = typeof e != "string" || G(t) ? "binary" : "utf-8"), await ht(r, e, n, t), i ? await this.notifyChange({ path: t, type: "changed", isDirectory: !1 }) : await this.notifyChange({ path: t, type: "added", isDirectory: !1 });
|
|
1631
1701
|
}
|
|
1632
1702
|
/**
|
|
1633
1703
|
* Append data to a file
|
|
@@ -1654,7 +1724,7 @@ class ss {
|
|
|
1654
1724
|
async appendFile(t, e, n) {
|
|
1655
1725
|
await this.mount();
|
|
1656
1726
|
const i = await this.getFileHandle(t, !0);
|
|
1657
|
-
await
|
|
1727
|
+
n || (n = typeof e != "string" || G(t) ? "binary" : "utf-8"), await ht(i, e, n, t, { append: !0 }), await this.notifyChange({ path: t, type: "changed", isDirectory: !1 });
|
|
1658
1728
|
}
|
|
1659
1729
|
/**
|
|
1660
1730
|
* Create a directory
|
|
@@ -1678,19 +1748,20 @@ class ss {
|
|
|
1678
1748
|
* \`\`\`
|
|
1679
1749
|
*/
|
|
1680
1750
|
async mkdir(t, e) {
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
const n = e?.recursive ?? !1, i = F(t);
|
|
1751
|
+
await this.mount();
|
|
1752
|
+
const n = e?.recursive ?? !1, i = D(t);
|
|
1684
1753
|
let r = this.root;
|
|
1685
1754
|
for (let o = 0; o < i.length; o++) {
|
|
1686
1755
|
const a = i[o];
|
|
1687
1756
|
try {
|
|
1688
1757
|
r = await r.getDirectoryHandle(a, { create: n || o === i.length - 1 });
|
|
1689
|
-
} catch (
|
|
1690
|
-
throw
|
|
1691
|
-
\`Parent directory does not exist: \${
|
|
1692
|
-
"ENOENT"
|
|
1693
|
-
|
|
1758
|
+
} catch (l) {
|
|
1759
|
+
throw l.name === "NotFoundError" ? new g(
|
|
1760
|
+
\`Parent directory does not exist: \${et(i.slice(0, o + 1))}\`,
|
|
1761
|
+
"ENOENT",
|
|
1762
|
+
void 0,
|
|
1763
|
+
l
|
|
1764
|
+
) : l.name === "TypeMismatchError" ? new g(\`Path segment is not a directory: \${a}\`, "ENOTDIR", void 0, l) : new g("Failed to create directory", "MKDIR_FAILED", void 0, l);
|
|
1694
1765
|
}
|
|
1695
1766
|
}
|
|
1696
1767
|
await this.notifyChange({ path: t, type: "added", isDirectory: !0 });
|
|
@@ -1727,7 +1798,7 @@ class ss {
|
|
|
1727
1798
|
isFile: !1,
|
|
1728
1799
|
isDirectory: !0
|
|
1729
1800
|
};
|
|
1730
|
-
const e =
|
|
1801
|
+
const e = Y(t), n = await this.getDirectoryHandle(q(t), !1), i = this.options.hashAlgorithm !== null;
|
|
1731
1802
|
try {
|
|
1732
1803
|
const o = await (await n.getFileHandle(e, { create: !1 })).getFile(), a = {
|
|
1733
1804
|
kind: "file",
|
|
@@ -1739,15 +1810,15 @@ class ss {
|
|
|
1739
1810
|
};
|
|
1740
1811
|
if (i && this.options.hashAlgorithm)
|
|
1741
1812
|
try {
|
|
1742
|
-
const
|
|
1743
|
-
a.hash =
|
|
1744
|
-
} catch (
|
|
1745
|
-
console.warn(\`Failed to calculate hash for \${t}:\`,
|
|
1813
|
+
const l = await ns(o, this.options.hashAlgorithm, this.options.maxFileSize);
|
|
1814
|
+
a.hash = l;
|
|
1815
|
+
} catch (l) {
|
|
1816
|
+
console.warn(\`Failed to calculate hash for \${t}:\`, l);
|
|
1746
1817
|
}
|
|
1747
1818
|
return a;
|
|
1748
1819
|
} catch (r) {
|
|
1749
1820
|
if (r.name !== "TypeMismatchError" && r.name !== "NotFoundError")
|
|
1750
|
-
throw new g("Failed to stat (file)", "STAT_FAILED");
|
|
1821
|
+
throw new g("Failed to stat (file)", "STAT_FAILED", void 0, r);
|
|
1751
1822
|
}
|
|
1752
1823
|
try {
|
|
1753
1824
|
return await n.getDirectoryHandle(e, { create: !1 }), {
|
|
@@ -1759,7 +1830,7 @@ class ss {
|
|
|
1759
1830
|
isDirectory: !0
|
|
1760
1831
|
};
|
|
1761
1832
|
} catch (r) {
|
|
1762
|
-
throw r.name === "NotFoundError" ? new g(\`No such file or directory: \${t}\`, "ENOENT") : new g("Failed to stat (directory)", "STAT_FAILED");
|
|
1833
|
+
throw r.name === "NotFoundError" ? new g(\`No such file or directory: \${t}\`, "ENOENT", void 0, r) : new g("Failed to stat (directory)", "STAT_FAILED", void 0, r);
|
|
1763
1834
|
}
|
|
1764
1835
|
}
|
|
1765
1836
|
/**
|
|
@@ -1811,10 +1882,10 @@ class ss {
|
|
|
1811
1882
|
async exists(t) {
|
|
1812
1883
|
if (await this.mount(), t === "/")
|
|
1813
1884
|
return !0;
|
|
1814
|
-
const e =
|
|
1885
|
+
const e = Y(t);
|
|
1815
1886
|
let n = null;
|
|
1816
1887
|
try {
|
|
1817
|
-
n = await this.getDirectoryHandle(
|
|
1888
|
+
n = await this.getDirectoryHandle(q(t), !1);
|
|
1818
1889
|
} catch (i) {
|
|
1819
1890
|
throw (i.name === "NotFoundError" || i.name === "TypeMismatchError") && (n = null), i;
|
|
1820
1891
|
}
|
|
@@ -1825,14 +1896,14 @@ class ss {
|
|
|
1825
1896
|
} catch (i) {
|
|
1826
1897
|
if (i.name !== "NotFoundError" && i.name !== "TypeMismatchError")
|
|
1827
1898
|
throw i;
|
|
1899
|
+
try {
|
|
1900
|
+
return await n.getDirectoryHandle(e, { create: !1 }), !0;
|
|
1901
|
+
} catch (r) {
|
|
1902
|
+
if (r.name !== "NotFoundError" && r.name !== "TypeMismatchError")
|
|
1903
|
+
throw r;
|
|
1904
|
+
return !1;
|
|
1905
|
+
}
|
|
1828
1906
|
}
|
|
1829
|
-
try {
|
|
1830
|
-
return await n.getDirectoryHandle(e, { create: !1 }), !0;
|
|
1831
|
-
} catch (i) {
|
|
1832
|
-
if (i.name !== "NotFoundError" && i.name !== "TypeMismatchError")
|
|
1833
|
-
throw i;
|
|
1834
|
-
}
|
|
1835
|
-
return !1;
|
|
1836
1907
|
}
|
|
1837
1908
|
/**
|
|
1838
1909
|
* Clear all contents of a directory without removing the directory itself
|
|
@@ -1863,7 +1934,7 @@ class ss {
|
|
|
1863
1934
|
}
|
|
1864
1935
|
await this.notifyChange({ path: t, type: "changed", isDirectory: !0 });
|
|
1865
1936
|
} catch (e) {
|
|
1866
|
-
throw e instanceof g ? e : new g(\`Failed to clear directory: \${t}\`, "CLEAR_FAILED");
|
|
1937
|
+
throw e instanceof g ? e : new g(\`Failed to clear directory: \${t}\`, "CLEAR_FAILED", void 0, e);
|
|
1867
1938
|
}
|
|
1868
1939
|
}
|
|
1869
1940
|
/**
|
|
@@ -1891,23 +1962,10 @@ class ss {
|
|
|
1891
1962
|
* \`\`\`
|
|
1892
1963
|
*/
|
|
1893
1964
|
async remove(t, e) {
|
|
1894
|
-
await this.mount()
|
|
1895
|
-
const n = e?.recursive ?? !1, i = e?.force ?? !1;
|
|
1896
|
-
if (t === "/")
|
|
1965
|
+
if (await this.mount(), t === "/")
|
|
1897
1966
|
throw new g("Cannot remove root directory", "EROOT");
|
|
1898
|
-
const
|
|
1899
|
-
|
|
1900
|
-
throw new ht("Invalid path", t);
|
|
1901
|
-
const o = await this.getDirectoryHandle(X(t), !1);
|
|
1902
|
-
try {
|
|
1903
|
-
await o.removeEntry(r, { recursive: n });
|
|
1904
|
-
} catch (a) {
|
|
1905
|
-
if (a.name === "NotFoundError") {
|
|
1906
|
-
if (!i)
|
|
1907
|
-
throw new g(\`No such file or directory: \${t}\`, "ENOENT");
|
|
1908
|
-
} else throw a.name === "InvalidModificationError" ? new g(\`Directory not empty: \${t}. Use recursive option to force removal.\`, "ENOTEMPTY") : a.name === "TypeMismatchError" && !n ? new g(\`Cannot remove directory without recursive option: \${t}\`, "EISDIR") : new g(\`Failed to remove path: \${t}\`, "RM_FAILED");
|
|
1909
|
-
}
|
|
1910
|
-
await this.notifyChange({ path: t, type: "removed", isDirectory: !1 });
|
|
1967
|
+
const n = await this.getDirectoryHandle(q(t), !1);
|
|
1968
|
+
await rs(n, t, e), await this.notifyChange({ path: t, type: "removed", isDirectory: !1 });
|
|
1911
1969
|
}
|
|
1912
1970
|
/**
|
|
1913
1971
|
* Resolve a path to an absolute path
|
|
@@ -1930,12 +1988,12 @@ class ss {
|
|
|
1930
1988
|
async realpath(t) {
|
|
1931
1989
|
await this.mount();
|
|
1932
1990
|
try {
|
|
1933
|
-
const e =
|
|
1991
|
+
const e = ts(t);
|
|
1934
1992
|
if (!await this.exists(e))
|
|
1935
|
-
throw new
|
|
1993
|
+
throw new _(e);
|
|
1936
1994
|
return e;
|
|
1937
1995
|
} catch (e) {
|
|
1938
|
-
throw e instanceof g ? e : new g(\`Failed to resolve path: \${t}\`, "REALPATH_FAILED");
|
|
1996
|
+
throw e instanceof g ? e : new g(\`Failed to resolve path: \${t}\`, "REALPATH_FAILED", void 0, e);
|
|
1939
1997
|
}
|
|
1940
1998
|
}
|
|
1941
1999
|
/**
|
|
@@ -1958,10 +2016,10 @@ class ss {
|
|
|
1958
2016
|
await this.mount();
|
|
1959
2017
|
try {
|
|
1960
2018
|
if (!await this.exists(t))
|
|
1961
|
-
throw new
|
|
2019
|
+
throw new _(t);
|
|
1962
2020
|
await this.copy(t, e, { recursive: !0 }), await this.remove(t, { recursive: !0 }), await this.notifyChange({ path: t, type: "removed", isDirectory: !1 }), await this.notifyChange({ path: e, type: "added", isDirectory: !1 });
|
|
1963
2021
|
} catch (n) {
|
|
1964
|
-
throw n instanceof g ? n : new g(\`Failed to rename from \${t} to \${e}\`, "RENAME_FAILED");
|
|
2022
|
+
throw n instanceof g ? n : new g(\`Failed to rename from \${t} to \${e}\`, "RENAME_FAILED", void 0, n);
|
|
1965
2023
|
}
|
|
1966
2024
|
}
|
|
1967
2025
|
/**
|
|
@@ -1994,34 +2052,33 @@ class ss {
|
|
|
1994
2052
|
try {
|
|
1995
2053
|
const i = n?.recursive ?? !1, r = n?.force ?? !0;
|
|
1996
2054
|
if (!await this.exists(t))
|
|
1997
|
-
throw new g(\`Source does not exist: \${t}\`, "ENOENT");
|
|
2055
|
+
throw new g(\`Source does not exist: \${t}\`, "ENOENT", void 0);
|
|
1998
2056
|
if (await this.exists(e) && !r)
|
|
1999
|
-
throw new g(\`Destination already exists: \${e}\`, "EEXIST");
|
|
2057
|
+
throw new g(\`Destination already exists: \${e}\`, "EEXIST", void 0);
|
|
2000
2058
|
if ((await this.stat(t)).isFile) {
|
|
2001
|
-
const
|
|
2002
|
-
await this.writeFile(e,
|
|
2059
|
+
const h = await this.readFile(t, "binary");
|
|
2060
|
+
await this.writeFile(e, h);
|
|
2003
2061
|
} else {
|
|
2004
2062
|
if (!i)
|
|
2005
|
-
throw new g(\`Cannot copy directory without recursive option: \${t}\`, "EISDIR");
|
|
2063
|
+
throw new g(\`Cannot copy directory without recursive option: \${t}\`, "EISDIR", void 0);
|
|
2006
2064
|
await this.mkdir(e, { recursive: !0 });
|
|
2007
|
-
const
|
|
2008
|
-
for (const
|
|
2009
|
-
const f = \`\${t}/\${
|
|
2065
|
+
const h = await this.readDir(t);
|
|
2066
|
+
for (const c of h) {
|
|
2067
|
+
const f = \`\${t}/\${c.name}\`, u = \`\${e}/\${c.name}\`;
|
|
2010
2068
|
await this.copy(f, u, { recursive: !0, force: r });
|
|
2011
2069
|
}
|
|
2012
2070
|
}
|
|
2013
|
-
await this.notifyChange({ path: e, type: "added", isDirectory: !1 });
|
|
2014
2071
|
} catch (i) {
|
|
2015
|
-
throw i instanceof g ? i : new g(\`Failed to copy from \${t} to \${e}\`, "CP_FAILED");
|
|
2072
|
+
throw i instanceof g ? i : new g(\`Failed to copy from \${t} to \${e}\`, "CP_FAILED", void 0, i);
|
|
2016
2073
|
}
|
|
2017
2074
|
}
|
|
2018
2075
|
/**
|
|
2019
2076
|
* Start watching a file or directory for changes
|
|
2020
2077
|
*
|
|
2021
|
-
* @param path - The path to watch
|
|
2078
|
+
* @param path - The path to watch (minimatch syntax allowed)
|
|
2022
2079
|
* @param options - Watch options
|
|
2023
2080
|
* @param options.recursive - Whether to watch recursively (default: true)
|
|
2024
|
-
* @param options.
|
|
2081
|
+
* @param options.exclude - Glob pattern(s) to exclude (minimatch).
|
|
2025
2082
|
* @returns Promise that resolves when watching starts
|
|
2026
2083
|
*
|
|
2027
2084
|
* @example
|
|
@@ -2034,21 +2091,27 @@ class ss {
|
|
|
2034
2091
|
*
|
|
2035
2092
|
* // Watch a single file
|
|
2036
2093
|
* await fs.watch('/config.json', { recursive: false });
|
|
2094
|
+
*
|
|
2095
|
+
* // Watch all json files but not in dist directory
|
|
2096
|
+
* await fs.watch('/**\\/*.json', { recursive: false, exclude: ['dist/**'] });
|
|
2097
|
+
*
|
|
2037
2098
|
* \`\`\`
|
|
2038
2099
|
*/
|
|
2039
2100
|
async watch(t, e) {
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2101
|
+
if (!this.options.broadcastChannel)
|
|
2102
|
+
throw new g("This instance is not configured to send events. Please specify options.broadcastChannel to enable watching.", "ENOENT");
|
|
2103
|
+
const n = {
|
|
2104
|
+
pattern: Qe(t, e?.recursive ?? !0),
|
|
2105
|
+
include: Array.isArray(e?.include) ? e.include : [e?.include ?? "**"],
|
|
2106
|
+
exclude: Array.isArray(e?.exclude) ? e.exclude : [e?.exclude ?? ""]
|
|
2107
|
+
};
|
|
2108
|
+
this.watchers.set(t, n);
|
|
2045
2109
|
}
|
|
2046
2110
|
/**
|
|
2047
2111
|
* Stop watching a previously watched path
|
|
2048
2112
|
*/
|
|
2049
2113
|
unwatch(t) {
|
|
2050
|
-
|
|
2051
|
-
this.watchers.delete(e), this.watchers.size === 0 && this.watchTimer && (clearInterval(this.watchTimer), this.watchTimer = null);
|
|
2114
|
+
this.watchers.delete(t);
|
|
2052
2115
|
}
|
|
2053
2116
|
/**
|
|
2054
2117
|
* Dispose of resources and clean up the file system instance
|
|
@@ -2057,53 +2120,7 @@ class ss {
|
|
|
2057
2120
|
* to properly clean up resources like the broadcast channel and watch timers.
|
|
2058
2121
|
*/
|
|
2059
2122
|
dispose() {
|
|
2060
|
-
this.broadcastChannel && (this.broadcastChannel.close(), this.broadcastChannel = null), this.
|
|
2061
|
-
}
|
|
2062
|
-
async buildSnapshot(t, e) {
|
|
2063
|
-
const n = /* @__PURE__ */ new Map(), i = e?.recursive ?? !0, r = e?.excludes, o = async (c) => {
|
|
2064
|
-
const l = await this.stat(c);
|
|
2065
|
-
return n.set(c, l), l;
|
|
2066
|
-
}, a = async (c) => {
|
|
2067
|
-
if (L(c, r))
|
|
2068
|
-
return;
|
|
2069
|
-
if ((await o(c)).isDirectory) {
|
|
2070
|
-
const h = await this.readDir(c);
|
|
2071
|
-
for (const f of h) {
|
|
2072
|
-
const u = \`\${c === "/" ? "" : c}/\${f.name}\`;
|
|
2073
|
-
i ? await a(u) : L(u, r) || await o(u);
|
|
2074
|
-
}
|
|
2075
|
-
}
|
|
2076
|
-
};
|
|
2077
|
-
return await a(t), n;
|
|
2078
|
-
}
|
|
2079
|
-
async scanWatches() {
|
|
2080
|
-
if (!this.scanning) {
|
|
2081
|
-
this.scanning = !0;
|
|
2082
|
-
try {
|
|
2083
|
-
await Promise.all(
|
|
2084
|
-
[...this.watchers.entries()].map(async ([t, { snapshot: e, options: n }]) => {
|
|
2085
|
-
let i;
|
|
2086
|
-
try {
|
|
2087
|
-
i = await this.buildSnapshot(t, n);
|
|
2088
|
-
} catch {
|
|
2089
|
-
i = /* @__PURE__ */ new Map();
|
|
2090
|
-
}
|
|
2091
|
-
for (const [r, o] of i) {
|
|
2092
|
-
const a = e.get(r);
|
|
2093
|
-
L(r, n.excludes) || (a ? (a.mtime !== o.mtime || a.size !== o.size) && await this.notifyChange({ path: r, type: "changed", isDirectory: o.isDirectory }) : await this.notifyChange({ path: r, type: "added", isDirectory: o.isDirectory }));
|
|
2094
|
-
}
|
|
2095
|
-
for (const r of e.keys())
|
|
2096
|
-
if (!L(r, n.excludes) && !i.has(r)) {
|
|
2097
|
-
const o = e.get(r);
|
|
2098
|
-
await this.notifyChange({ path: r, type: "removed", isDirectory: o?.isDirectory ?? !1 });
|
|
2099
|
-
}
|
|
2100
|
-
this.watchers.set(t, { snapshot: i, options: n });
|
|
2101
|
-
})
|
|
2102
|
-
);
|
|
2103
|
-
} finally {
|
|
2104
|
-
this.scanning = !1;
|
|
2105
|
-
}
|
|
2106
|
-
}
|
|
2123
|
+
this.broadcastChannel && (this.broadcastChannel.close(), this.broadcastChannel = null), this.watchers.clear();
|
|
2107
2124
|
}
|
|
2108
2125
|
/**
|
|
2109
2126
|
* Synchronize the file system with external data
|
|
@@ -2138,70 +2155,76 @@ class ss {
|
|
|
2138
2155
|
try {
|
|
2139
2156
|
(e?.cleanBefore ?? !1) && await this.clear("/");
|
|
2140
2157
|
for (const [i, r] of t) {
|
|
2141
|
-
const o =
|
|
2158
|
+
const o = Z(i);
|
|
2142
2159
|
let a;
|
|
2143
|
-
r instanceof Blob ? a = await
|
|
2160
|
+
r instanceof Blob ? a = await is(r) : a = r, await this.writeFile(o, a);
|
|
2144
2161
|
}
|
|
2145
|
-
await this.notifyChange({ path: "/", type: "changed", isDirectory: !0 });
|
|
2146
2162
|
} catch (n) {
|
|
2147
|
-
throw n instanceof g ? n : new g("Failed to sync file system", "SYNC_FAILED");
|
|
2163
|
+
throw n instanceof g ? n : new g("Failed to sync file system", "SYNC_FAILED", void 0, n);
|
|
2148
2164
|
}
|
|
2149
2165
|
}
|
|
2150
2166
|
}
|
|
2151
|
-
typeof
|
|
2152
|
-
//# sourceMappingURL=worker-
|
|
2167
|
+
typeof globalThis < "u" && globalThis.constructor.name === "DedicatedWorkerGlobalScope" && J(new os());
|
|
2168
|
+
//# sourceMappingURL=worker-DYhMhDRt.js.map
|
|
2153
2169
|
`, s = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", r], { type: "text/javascript;charset=utf-8" });
|
|
2154
|
-
function o(
|
|
2155
|
-
let
|
|
2170
|
+
function o(n) {
|
|
2171
|
+
let t;
|
|
2156
2172
|
try {
|
|
2157
|
-
if (
|
|
2158
|
-
const e = new Worker(
|
|
2173
|
+
if (t = s && (self.URL || self.webkitURL).createObjectURL(s), !t) throw "";
|
|
2174
|
+
const e = new Worker(t, {
|
|
2159
2175
|
type: "module",
|
|
2160
|
-
name:
|
|
2176
|
+
name: n?.name
|
|
2161
2177
|
});
|
|
2162
2178
|
return e.addEventListener("error", () => {
|
|
2163
|
-
(self.URL || self.webkitURL).revokeObjectURL(
|
|
2179
|
+
(self.URL || self.webkitURL).revokeObjectURL(t);
|
|
2164
2180
|
}), e;
|
|
2165
2181
|
} catch {
|
|
2166
2182
|
return new Worker(
|
|
2167
2183
|
"data:text/javascript;charset=utf-8," + encodeURIComponent(r),
|
|
2168
2184
|
{
|
|
2169
2185
|
type: "module",
|
|
2170
|
-
name:
|
|
2186
|
+
name: n?.name
|
|
2171
2187
|
}
|
|
2172
2188
|
);
|
|
2173
2189
|
}
|
|
2174
2190
|
}
|
|
2175
|
-
function h(
|
|
2176
|
-
const
|
|
2177
|
-
return
|
|
2191
|
+
async function h(n) {
|
|
2192
|
+
const t = i(new o());
|
|
2193
|
+
return n && (n.broadcastChannel && n.broadcastChannel instanceof BroadcastChannel && (n.broadcastChannel = n.broadcastChannel.name), await t.setOptions(n)), t;
|
|
2178
2194
|
}
|
|
2179
2195
|
export {
|
|
2180
|
-
p as
|
|
2181
|
-
f as
|
|
2182
|
-
d as
|
|
2183
|
-
u as
|
|
2184
|
-
g as
|
|
2185
|
-
m as
|
|
2186
|
-
w as
|
|
2187
|
-
y as
|
|
2188
|
-
b as
|
|
2189
|
-
v as
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2196
|
+
p as BINARY_FILE_EXTENSIONS,
|
|
2197
|
+
f as DirectoryNotFoundError,
|
|
2198
|
+
d as FileNotFoundError,
|
|
2199
|
+
u as OPFSError,
|
|
2200
|
+
g as OPFSNotMountedError,
|
|
2201
|
+
m as OPFSNotSupportedError,
|
|
2202
|
+
w as PathError,
|
|
2203
|
+
y as PermissionError,
|
|
2204
|
+
b as StorageError,
|
|
2205
|
+
v as TimeoutError,
|
|
2206
|
+
x as basename,
|
|
2207
|
+
S as buffersEqual,
|
|
2208
|
+
E as calculateFileHash,
|
|
2209
|
+
A as checkOPFSSupport,
|
|
2210
|
+
P as convertBlobToUint8Array,
|
|
2211
|
+
F as createBuffer,
|
|
2194
2212
|
h as createWorker,
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
_ as
|
|
2201
|
-
D as
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
M as
|
|
2213
|
+
O as decodeBuffer,
|
|
2214
|
+
C as dirname,
|
|
2215
|
+
T as encodeString,
|
|
2216
|
+
R as extname,
|
|
2217
|
+
$ as isBinaryFileExtension,
|
|
2218
|
+
_ as isPathExcluded,
|
|
2219
|
+
D as joinPath,
|
|
2220
|
+
I as matchMinimatch,
|
|
2221
|
+
j as normalizeMinimatch,
|
|
2222
|
+
N as normalizePath,
|
|
2223
|
+
M as readFileData,
|
|
2224
|
+
k as removeEntry,
|
|
2225
|
+
L as resolvePath,
|
|
2226
|
+
z as splitPath,
|
|
2227
|
+
U as withLock,
|
|
2228
|
+
W as writeFileData
|
|
2206
2229
|
};
|
|
2207
2230
|
//# sourceMappingURL=index.js.map
|