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