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