opfs-worker 0.3.3 → 0.5.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 +238 -865
- package/dist/assets/worker-3SMz_DAt.js.map +1 -0
- package/dist/helpers-Bm2TWyPQ.js +1224 -0
- package/dist/helpers-Bm2TWyPQ.js.map +1 -0
- package/dist/helpers-BoLdVbGk.cjs +4 -0
- package/dist/helpers-BoLdVbGk.cjs.map +1 -0
- package/dist/index.cjs +1428 -506
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1465 -537
- package/dist/index.js.map +1 -1
- package/dist/raw.cjs +1 -1
- package/dist/raw.cjs.map +1 -1
- package/dist/raw.js +133 -188
- package/dist/raw.js.map +1 -1
- package/dist/types.d.ts +20 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/errors.d.ts +9 -9
- package/dist/utils/errors.d.ts.map +1 -1
- package/dist/utils/helpers.d.ts +34 -2
- package/dist/utils/helpers.d.ts.map +1 -1
- package/dist/worker.d.ts +29 -21
- package/dist/worker.d.ts.map +1 -1
- package/package.json +5 -2
- package/dist/assets/worker-CLK22qZk.js.map +0 -1
- package/dist/helpers-B87wz5kv.cjs +0 -2
- package/dist/helpers-B87wz5kv.cjs.map +0 -1
- package/dist/helpers-DxFcNkZe.js +0 -222
- package/dist/helpers-DxFcNkZe.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,77 +1,77 @@
|
|
|
1
1
|
import { wrap as i } from "comlink";
|
|
2
|
-
import { D as
|
|
3
|
-
const
|
|
2
|
+
import { D as p, F as f, O as d, b as u, a as g, P as m, c as w, S as y, T as b, e as v, q as S, p as x, d as E, t as P, k as A, x as F, f as O, v as C, h as T, i as R, j as $, m as _, g as D, n as I, l as M, u as j, r as N, s as k, w as L, o as U } from "./helpers-Bm2TWyPQ.js";
|
|
3
|
+
const r = `/**
|
|
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(
|
|
11
|
-
const { port1: t, port2:
|
|
12
|
-
return
|
|
8
|
+
const ht = Symbol("Comlink.proxy"), Dt = Symbol("Comlink.endpoint"), Ot = Symbol("Comlink.releaseProxy"), U = Symbol("Comlink.finalizer"), L = Symbol("Comlink.thrown"), ut = (s) => typeof s == "object" && s !== null || typeof s == "function", Nt = {
|
|
9
|
+
canHandle: (s) => ut(s) && s[ht],
|
|
10
|
+
serialize(s) {
|
|
11
|
+
const { port1: t, port2: e } = new MessageChannel();
|
|
12
|
+
return Y(s, t), [e, [e]];
|
|
13
13
|
},
|
|
14
|
-
deserialize(
|
|
15
|
-
return
|
|
14
|
+
deserialize(s) {
|
|
15
|
+
return s.start(), $t(s);
|
|
16
16
|
}
|
|
17
|
-
},
|
|
18
|
-
canHandle: (
|
|
19
|
-
serialize({ value:
|
|
17
|
+
}, Ft = {
|
|
18
|
+
canHandle: (s) => ut(s) && L in s,
|
|
19
|
+
serialize({ value: s }) {
|
|
20
20
|
let t;
|
|
21
|
-
return
|
|
21
|
+
return s instanceof Error ? t = {
|
|
22
22
|
isError: !0,
|
|
23
23
|
value: {
|
|
24
|
-
message:
|
|
25
|
-
name:
|
|
26
|
-
stack:
|
|
24
|
+
message: s.message,
|
|
25
|
+
name: s.name,
|
|
26
|
+
stack: s.stack
|
|
27
27
|
}
|
|
28
|
-
} : t = { isError: !1, value:
|
|
28
|
+
} : t = { isError: !1, value: s }, [t, []];
|
|
29
29
|
},
|
|
30
|
-
deserialize(
|
|
31
|
-
throw
|
|
30
|
+
deserialize(s) {
|
|
31
|
+
throw s.isError ? Object.assign(new Error(s.value.message), s.value) : s.value;
|
|
32
32
|
}
|
|
33
|
-
},
|
|
34
|
-
["proxy",
|
|
35
|
-
["throw",
|
|
33
|
+
}, ft = /* @__PURE__ */ new Map([
|
|
34
|
+
["proxy", Nt],
|
|
35
|
+
["throw", Ft]
|
|
36
36
|
]);
|
|
37
|
-
function
|
|
38
|
-
for (const
|
|
39
|
-
if (t ===
|
|
37
|
+
function Tt(s, t) {
|
|
38
|
+
for (const e of s)
|
|
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 i
|
|
45
|
-
if (!
|
|
43
|
+
function Y(s, t = globalThis, e = ["*"]) {
|
|
44
|
+
t.addEventListener("message", function n(i) {
|
|
45
|
+
if (!i || !i.data)
|
|
46
46
|
return;
|
|
47
|
-
if (!
|
|
48
|
-
console.warn(\`Invalid origin '\${
|
|
47
|
+
if (!Tt(e, i.origin)) {
|
|
48
|
+
console.warn(\`Invalid origin '\${i.origin}' for comlink proxy\`);
|
|
49
49
|
return;
|
|
50
50
|
}
|
|
51
|
-
const { id:
|
|
51
|
+
const { id: r, type: o, path: a } = Object.assign({ path: [] }, i.data), l = (i.data.argumentList || []).map(C);
|
|
52
52
|
let h;
|
|
53
53
|
try {
|
|
54
|
-
const
|
|
55
|
-
switch (
|
|
54
|
+
const c = a.slice(0, -1).reduce((u, d) => u[d], s), f = a.reduce((u, d) => u[d], s);
|
|
55
|
+
switch (o) {
|
|
56
56
|
case "GET":
|
|
57
|
-
h =
|
|
57
|
+
h = f;
|
|
58
58
|
break;
|
|
59
59
|
case "SET":
|
|
60
|
-
|
|
60
|
+
c[a.slice(-1)[0]] = C(i.data.value), h = !0;
|
|
61
61
|
break;
|
|
62
62
|
case "APPLY":
|
|
63
|
-
h =
|
|
63
|
+
h = f.apply(c, l);
|
|
64
64
|
break;
|
|
65
65
|
case "CONSTRUCT":
|
|
66
66
|
{
|
|
67
|
-
const
|
|
68
|
-
h =
|
|
67
|
+
const u = new f(...l);
|
|
68
|
+
h = It(u);
|
|
69
69
|
}
|
|
70
70
|
break;
|
|
71
71
|
case "ENDPOINT":
|
|
72
72
|
{
|
|
73
|
-
const { port1:
|
|
74
|
-
|
|
73
|
+
const { port1: u, port2: d } = new MessageChannel();
|
|
74
|
+
Y(s, d), h = Lt(u, [u]);
|
|
75
75
|
}
|
|
76
76
|
break;
|
|
77
77
|
case "RELEASE":
|
|
@@ -80,360 +80,1334 @@ function x(e, t = globalThis, r = ["*"]) {
|
|
|
80
80
|
default:
|
|
81
81
|
return;
|
|
82
82
|
}
|
|
83
|
-
} catch (
|
|
84
|
-
h = { value:
|
|
83
|
+
} catch (c) {
|
|
84
|
+
h = { value: c, [L]: 0 };
|
|
85
85
|
}
|
|
86
|
-
Promise.resolve(h).catch((
|
|
87
|
-
const [
|
|
88
|
-
t.postMessage(Object.assign(Object.assign({},
|
|
89
|
-
}).catch((
|
|
90
|
-
const [
|
|
86
|
+
Promise.resolve(h).catch((c) => ({ value: c, [L]: 0 })).then((c) => {
|
|
87
|
+
const [f, u] = H(c);
|
|
88
|
+
t.postMessage(Object.assign(Object.assign({}, f), { id: r }), u), o === "RELEASE" && (t.removeEventListener("message", n), dt(t), U in s && typeof s[U] == "function" && s[U]());
|
|
89
|
+
}).catch((c) => {
|
|
90
|
+
const [f, u] = H({
|
|
91
91
|
value: new TypeError("Unserializable return value"),
|
|
92
|
-
[
|
|
92
|
+
[L]: 0
|
|
93
93
|
});
|
|
94
|
-
t.postMessage(Object.assign(Object.assign({},
|
|
94
|
+
t.postMessage(Object.assign(Object.assign({}, f), { id: r }), u);
|
|
95
95
|
});
|
|
96
96
|
}), t.start && t.start();
|
|
97
97
|
}
|
|
98
|
-
function
|
|
99
|
-
return
|
|
98
|
+
function Mt(s) {
|
|
99
|
+
return s.constructor.name === "MessagePort";
|
|
100
100
|
}
|
|
101
|
-
function
|
|
102
|
-
|
|
101
|
+
function dt(s) {
|
|
102
|
+
Mt(s) && s.close();
|
|
103
103
|
}
|
|
104
|
-
function
|
|
105
|
-
const
|
|
106
|
-
return
|
|
107
|
-
const { data:
|
|
108
|
-
if (!
|
|
104
|
+
function $t(s, t) {
|
|
105
|
+
const e = /* @__PURE__ */ new Map();
|
|
106
|
+
return s.addEventListener("message", function(i) {
|
|
107
|
+
const { data: r } = i;
|
|
108
|
+
if (!r || !r.id)
|
|
109
109
|
return;
|
|
110
|
-
const
|
|
111
|
-
if (
|
|
110
|
+
const o = e.get(r.id);
|
|
111
|
+
if (o)
|
|
112
112
|
try {
|
|
113
|
-
|
|
113
|
+
o(r);
|
|
114
114
|
} finally {
|
|
115
|
-
|
|
115
|
+
e.delete(r.id);
|
|
116
116
|
}
|
|
117
|
-
}),
|
|
117
|
+
}), V(s, e, [], t);
|
|
118
118
|
}
|
|
119
|
-
function
|
|
120
|
-
if (
|
|
119
|
+
function R(s) {
|
|
120
|
+
if (s)
|
|
121
121
|
throw new Error("Proxy has been released and is not useable");
|
|
122
122
|
}
|
|
123
|
-
function
|
|
124
|
-
return
|
|
123
|
+
function pt(s) {
|
|
124
|
+
return D(s, /* @__PURE__ */ new Map(), {
|
|
125
125
|
type: "RELEASE"
|
|
126
126
|
}).then(() => {
|
|
127
|
-
|
|
127
|
+
dt(s);
|
|
128
128
|
});
|
|
129
129
|
}
|
|
130
|
-
const
|
|
131
|
-
const t = (
|
|
132
|
-
|
|
130
|
+
const I = /* @__PURE__ */ new WeakMap(), z = "FinalizationRegistry" in globalThis && new FinalizationRegistry((s) => {
|
|
131
|
+
const t = (I.get(s) || 0) - 1;
|
|
132
|
+
I.set(s, t), t === 0 && pt(s);
|
|
133
133
|
});
|
|
134
|
-
function
|
|
135
|
-
const
|
|
136
|
-
|
|
134
|
+
function Pt(s, t) {
|
|
135
|
+
const e = (I.get(t) || 0) + 1;
|
|
136
|
+
I.set(t, e), z && z.register(s, t, s);
|
|
137
137
|
}
|
|
138
|
-
function
|
|
139
|
-
|
|
138
|
+
function Rt(s) {
|
|
139
|
+
z && z.unregister(s);
|
|
140
140
|
}
|
|
141
|
-
function
|
|
141
|
+
function V(s, t, e = [], n = function() {
|
|
142
142
|
}) {
|
|
143
|
-
let
|
|
144
|
-
const
|
|
145
|
-
get(
|
|
146
|
-
if (
|
|
143
|
+
let i = !1;
|
|
144
|
+
const r = new Proxy(n, {
|
|
145
|
+
get(o, a) {
|
|
146
|
+
if (R(i), a === Ot)
|
|
147
147
|
return () => {
|
|
148
|
-
|
|
148
|
+
Rt(r), pt(s), t.clear(), i = !0;
|
|
149
149
|
};
|
|
150
|
-
if (
|
|
151
|
-
if (
|
|
152
|
-
return { then: () =>
|
|
153
|
-
const l =
|
|
150
|
+
if (a === "then") {
|
|
151
|
+
if (e.length === 0)
|
|
152
|
+
return { then: () => r };
|
|
153
|
+
const l = D(s, t, {
|
|
154
154
|
type: "GET",
|
|
155
|
-
path:
|
|
156
|
-
}).then(
|
|
155
|
+
path: e.map((h) => h.toString())
|
|
156
|
+
}).then(C);
|
|
157
157
|
return l.then.bind(l);
|
|
158
158
|
}
|
|
159
|
-
return
|
|
159
|
+
return V(s, t, [...e, a]);
|
|
160
160
|
},
|
|
161
|
-
set(
|
|
162
|
-
|
|
163
|
-
const [h,
|
|
164
|
-
return
|
|
161
|
+
set(o, a, l) {
|
|
162
|
+
R(i);
|
|
163
|
+
const [h, c] = H(l);
|
|
164
|
+
return D(s, t, {
|
|
165
165
|
type: "SET",
|
|
166
|
-
path: [...
|
|
166
|
+
path: [...e, a].map((f) => f.toString()),
|
|
167
167
|
value: h
|
|
168
|
-
},
|
|
168
|
+
}, c).then(C);
|
|
169
169
|
},
|
|
170
|
-
apply(
|
|
171
|
-
|
|
172
|
-
const h =
|
|
173
|
-
if (h ===
|
|
174
|
-
return
|
|
170
|
+
apply(o, a, l) {
|
|
171
|
+
R(i);
|
|
172
|
+
const h = e[e.length - 1];
|
|
173
|
+
if (h === Dt)
|
|
174
|
+
return D(s, t, {
|
|
175
175
|
type: "ENDPOINT"
|
|
176
|
-
}).then(
|
|
176
|
+
}).then(C);
|
|
177
177
|
if (h === "bind")
|
|
178
|
-
return
|
|
179
|
-
const [
|
|
180
|
-
return
|
|
178
|
+
return V(s, t, e.slice(0, -1));
|
|
179
|
+
const [c, f] = et(l);
|
|
180
|
+
return D(s, t, {
|
|
181
181
|
type: "APPLY",
|
|
182
|
-
path:
|
|
183
|
-
argumentList:
|
|
184
|
-
},
|
|
182
|
+
path: e.map((u) => u.toString()),
|
|
183
|
+
argumentList: c
|
|
184
|
+
}, f).then(C);
|
|
185
185
|
},
|
|
186
|
-
construct(
|
|
187
|
-
|
|
188
|
-
const [l, h] =
|
|
189
|
-
return
|
|
186
|
+
construct(o, a) {
|
|
187
|
+
R(i);
|
|
188
|
+
const [l, h] = et(a);
|
|
189
|
+
return D(s, t, {
|
|
190
190
|
type: "CONSTRUCT",
|
|
191
|
-
path:
|
|
191
|
+
path: e.map((c) => c.toString()),
|
|
192
192
|
argumentList: l
|
|
193
|
-
}, h).then(
|
|
193
|
+
}, h).then(C);
|
|
194
194
|
}
|
|
195
195
|
});
|
|
196
|
-
return
|
|
196
|
+
return Pt(r, s), r;
|
|
197
197
|
}
|
|
198
|
-
function
|
|
199
|
-
return Array.prototype.concat.apply([],
|
|
198
|
+
function kt(s) {
|
|
199
|
+
return Array.prototype.concat.apply([], s);
|
|
200
200
|
}
|
|
201
|
-
function
|
|
202
|
-
const t =
|
|
203
|
-
return [t.map((
|
|
201
|
+
function et(s) {
|
|
202
|
+
const t = s.map(H);
|
|
203
|
+
return [t.map((e) => e[0]), kt(t.map((e) => e[1]))];
|
|
204
204
|
}
|
|
205
|
-
const
|
|
206
|
-
function
|
|
207
|
-
return
|
|
205
|
+
const gt = /* @__PURE__ */ new WeakMap();
|
|
206
|
+
function Lt(s, t) {
|
|
207
|
+
return gt.set(s, t), s;
|
|
208
208
|
}
|
|
209
|
-
function
|
|
210
|
-
return Object.assign(
|
|
209
|
+
function It(s) {
|
|
210
|
+
return Object.assign(s, { [ht]: !0 });
|
|
211
211
|
}
|
|
212
|
-
function
|
|
213
|
-
for (const [t,
|
|
214
|
-
if (
|
|
215
|
-
const [
|
|
212
|
+
function H(s) {
|
|
213
|
+
for (const [t, e] of ft)
|
|
214
|
+
if (e.canHandle(s)) {
|
|
215
|
+
const [n, i] = e.serialize(s);
|
|
216
216
|
return [
|
|
217
217
|
{
|
|
218
218
|
type: "HANDLER",
|
|
219
219
|
name: t,
|
|
220
|
-
value:
|
|
220
|
+
value: n
|
|
221
221
|
},
|
|
222
|
-
|
|
222
|
+
i
|
|
223
223
|
];
|
|
224
224
|
}
|
|
225
225
|
return [
|
|
226
226
|
{
|
|
227
227
|
type: "RAW",
|
|
228
|
-
value:
|
|
228
|
+
value: s
|
|
229
229
|
},
|
|
230
|
-
|
|
230
|
+
gt.get(s) || []
|
|
231
231
|
];
|
|
232
232
|
}
|
|
233
|
-
function
|
|
234
|
-
switch (
|
|
233
|
+
function C(s) {
|
|
234
|
+
switch (s.type) {
|
|
235
235
|
case "HANDLER":
|
|
236
|
-
return
|
|
236
|
+
return ft.get(s.name).deserialize(s.value);
|
|
237
237
|
case "RAW":
|
|
238
|
-
return
|
|
238
|
+
return s.value;
|
|
239
239
|
}
|
|
240
240
|
}
|
|
241
|
-
function
|
|
242
|
-
return new Promise((
|
|
243
|
-
const
|
|
244
|
-
t.set(
|
|
241
|
+
function D(s, t, e, n) {
|
|
242
|
+
return new Promise((i) => {
|
|
243
|
+
const r = zt();
|
|
244
|
+
t.set(r, i), s.start && s.start(), s.postMessage(Object.assign({ id: r }, e), n);
|
|
245
245
|
});
|
|
246
246
|
}
|
|
247
|
-
function
|
|
247
|
+
function zt() {
|
|
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,
|
|
252
|
-
super(t), this.code =
|
|
250
|
+
class g extends Error {
|
|
251
|
+
constructor(t, e, n, i) {
|
|
252
|
+
super(t, { cause: i }), this.code = e, this.path = n, this.name = "OPFSError";
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
|
-
class
|
|
256
|
-
constructor() {
|
|
257
|
-
super("OPFS is not supported in this browser", "OPFS_NOT_SUPPORTED");
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
class b extends c {
|
|
261
|
-
constructor() {
|
|
262
|
-
super("OPFS is not mounted", "OPFS_NOT_MOUNTED");
|
|
255
|
+
class Ht extends g {
|
|
256
|
+
constructor(t) {
|
|
257
|
+
super("OPFS is not supported in this browser", "OPFS_NOT_SUPPORTED", void 0, t);
|
|
263
258
|
}
|
|
264
259
|
}
|
|
265
|
-
class
|
|
266
|
-
constructor(t,
|
|
267
|
-
super(t, "INVALID_PATH",
|
|
260
|
+
class Wt extends g {
|
|
261
|
+
constructor(t, e, n) {
|
|
262
|
+
super(t, "INVALID_PATH", e, n);
|
|
268
263
|
}
|
|
269
264
|
}
|
|
270
|
-
class
|
|
271
|
-
constructor(t) {
|
|
272
|
-
super(\`File not found: \${t}\`, "FILE_NOT_FOUND", t);
|
|
265
|
+
class _ extends g {
|
|
266
|
+
constructor(t, e) {
|
|
267
|
+
super(\`File not found: \${t}\`, "FILE_NOT_FOUND", t, e);
|
|
273
268
|
}
|
|
274
269
|
}
|
|
275
|
-
function
|
|
270
|
+
function jt(s, t = "utf-8") {
|
|
276
271
|
switch (t) {
|
|
277
272
|
case "utf8":
|
|
278
273
|
case "utf-8":
|
|
279
|
-
return new TextEncoder().encode(
|
|
274
|
+
return new TextEncoder().encode(s);
|
|
280
275
|
case "utf16le":
|
|
281
276
|
case "ucs2":
|
|
282
277
|
case "ucs-2":
|
|
283
|
-
return
|
|
278
|
+
return _t(s);
|
|
284
279
|
case "ascii":
|
|
285
|
-
return
|
|
280
|
+
return qt(s);
|
|
286
281
|
case "latin1":
|
|
287
|
-
return
|
|
282
|
+
return Gt(s);
|
|
288
283
|
case "binary":
|
|
289
|
-
return Uint8Array.from(
|
|
284
|
+
return Uint8Array.from(s, (e) => e.charCodeAt(0));
|
|
290
285
|
case "base64":
|
|
291
|
-
return Uint8Array.from(atob(
|
|
286
|
+
return Uint8Array.from(atob(s), (e) => e.charCodeAt(0));
|
|
292
287
|
case "hex":
|
|
293
|
-
if (!/^[\\da-f]+$/i.test(
|
|
294
|
-
throw new
|
|
295
|
-
return Uint8Array.from(
|
|
288
|
+
if (!/^[\\da-f]+$/i.test(s) || s.length % 2 !== 0)
|
|
289
|
+
throw new g("Invalid hex string", "INVALID_HEX_FORMAT");
|
|
290
|
+
return Uint8Array.from(s.match(/.{1,2}/g).map((e) => parseInt(e, 16)));
|
|
296
291
|
default:
|
|
297
|
-
return console.warn("Encoding not supported, falling back to UTF-8"), new TextEncoder().encode(
|
|
292
|
+
return console.warn("Encoding not supported, falling back to UTF-8"), new TextEncoder().encode(s);
|
|
298
293
|
}
|
|
299
294
|
}
|
|
300
|
-
function
|
|
295
|
+
function Ut(s, t = "utf-8") {
|
|
301
296
|
switch (t) {
|
|
302
297
|
case "utf8":
|
|
303
298
|
case "utf-8":
|
|
304
|
-
return new TextDecoder().decode(
|
|
299
|
+
return new TextDecoder().decode(s);
|
|
305
300
|
case "utf16le":
|
|
306
301
|
case "ucs2":
|
|
307
302
|
case "ucs-2":
|
|
308
|
-
return
|
|
303
|
+
return Bt(s);
|
|
309
304
|
case "latin1":
|
|
310
|
-
return String.fromCharCode(...
|
|
305
|
+
return String.fromCharCode(...s);
|
|
311
306
|
case "binary":
|
|
312
|
-
return String.fromCharCode(...
|
|
307
|
+
return String.fromCharCode(...s);
|
|
313
308
|
case "ascii":
|
|
314
|
-
return String.fromCharCode(...
|
|
309
|
+
return String.fromCharCode(...s.map((e) => e & 127));
|
|
315
310
|
case "base64":
|
|
316
|
-
return btoa(String.fromCharCode(...
|
|
311
|
+
return btoa(String.fromCharCode(...s));
|
|
317
312
|
case "hex":
|
|
318
|
-
return Array.from(
|
|
313
|
+
return Array.from(s).map((e) => e.toString(16).padStart(2, "0")).join("");
|
|
319
314
|
default:
|
|
320
|
-
return console.warn("Unsupported encoding, falling back to UTF-8"), new TextDecoder().decode(
|
|
315
|
+
return console.warn("Unsupported encoding, falling back to UTF-8"), new TextDecoder().decode(s);
|
|
321
316
|
}
|
|
322
317
|
}
|
|
323
|
-
function
|
|
324
|
-
const t = new Uint8Array(
|
|
325
|
-
for (let
|
|
326
|
-
const
|
|
327
|
-
t[
|
|
318
|
+
function _t(s) {
|
|
319
|
+
const t = new Uint8Array(s.length * 2);
|
|
320
|
+
for (let e = 0; e < s.length; e++) {
|
|
321
|
+
const n = s.charCodeAt(e);
|
|
322
|
+
t[e * 2] = n & 255, t[e * 2 + 1] = n >> 8;
|
|
328
323
|
}
|
|
329
324
|
return t;
|
|
330
325
|
}
|
|
331
|
-
function
|
|
332
|
-
|
|
333
|
-
const t = new Uint16Array(
|
|
326
|
+
function Bt(s) {
|
|
327
|
+
s.length % 2 !== 0 && (console.warn("Invalid UTF-16LE buffer length, truncating last byte"), s = s.slice(0, s.length - 1));
|
|
328
|
+
const t = new Uint16Array(s.buffer, s.byteOffset, s.byteLength / 2);
|
|
334
329
|
return String.fromCharCode(...t);
|
|
335
330
|
}
|
|
336
|
-
function
|
|
337
|
-
const t = new Uint8Array(
|
|
338
|
-
for (let
|
|
339
|
-
t[
|
|
331
|
+
function Gt(s) {
|
|
332
|
+
const t = new Uint8Array(s.length);
|
|
333
|
+
for (let e = 0; e < s.length; e++)
|
|
334
|
+
t[e] = s.charCodeAt(e) & 255;
|
|
340
335
|
return t;
|
|
341
336
|
}
|
|
342
|
-
function
|
|
343
|
-
const t = new Uint8Array(
|
|
344
|
-
for (let
|
|
345
|
-
t[
|
|
337
|
+
function qt(s) {
|
|
338
|
+
const t = new Uint8Array(s.length);
|
|
339
|
+
for (let e = 0; e < s.length; e++)
|
|
340
|
+
t[e] = s.charCodeAt(e) & 127;
|
|
346
341
|
return t;
|
|
347
342
|
}
|
|
348
|
-
|
|
343
|
+
const mt = (s, t, e) => {
|
|
344
|
+
const n = s instanceof RegExp ? st(s, e) : s, i = t instanceof RegExp ? st(t, e) : t, r = n !== null && i != null && Vt(n, i, e);
|
|
345
|
+
return r && {
|
|
346
|
+
start: r[0],
|
|
347
|
+
end: r[1],
|
|
348
|
+
pre: e.slice(0, r[0]),
|
|
349
|
+
body: e.slice(r[0] + n.length, r[1]),
|
|
350
|
+
post: e.slice(r[1] + i.length)
|
|
351
|
+
};
|
|
352
|
+
}, st = (s, t) => {
|
|
353
|
+
const e = t.match(s);
|
|
354
|
+
return e ? e[0] : null;
|
|
355
|
+
}, Vt = (s, t, e) => {
|
|
356
|
+
let n, i, r, o, a, l = e.indexOf(s), h = e.indexOf(t, l + 1), c = l;
|
|
357
|
+
if (l >= 0 && h > 0) {
|
|
358
|
+
if (s === t)
|
|
359
|
+
return [l, h];
|
|
360
|
+
for (n = [], r = e.length; c >= 0 && !a; ) {
|
|
361
|
+
if (c === l)
|
|
362
|
+
n.push(c), l = e.indexOf(s, c + 1);
|
|
363
|
+
else if (n.length === 1) {
|
|
364
|
+
const f = n.pop();
|
|
365
|
+
f !== void 0 && (a = [f, h]);
|
|
366
|
+
} else
|
|
367
|
+
i = n.pop(), i !== void 0 && i < r && (r = i, o = h), h = e.indexOf(t, c + 1);
|
|
368
|
+
c = l < h && l >= 0 ? l : h;
|
|
369
|
+
}
|
|
370
|
+
n.length && o !== void 0 && (a = [r, o]);
|
|
371
|
+
}
|
|
372
|
+
return a;
|
|
373
|
+
}, wt = "\\0SLASH" + Math.random() + "\\0", yt = "\\0OPEN" + Math.random() + "\\0", J = "\\0CLOSE" + Math.random() + "\\0", Et = "\\0COMMA" + Math.random() + "\\0", St = "\\0PERIOD" + Math.random() + "\\0", Zt = new RegExp(wt, "g"), Xt = new RegExp(yt, "g"), Yt = new RegExp(J, "g"), Jt = new RegExp(Et, "g"), Kt = new RegExp(St, "g"), Qt = /\\\\\\\\/g, te = /\\\\{/g, ee = /\\\\}/g, se = /\\\\,/g, ne = /\\\\./g;
|
|
374
|
+
function B(s) {
|
|
375
|
+
return isNaN(s) ? s.charCodeAt(0) : parseInt(s, 10);
|
|
376
|
+
}
|
|
377
|
+
function ie(s) {
|
|
378
|
+
return s.replace(Qt, wt).replace(te, yt).replace(ee, J).replace(se, Et).replace(ne, St);
|
|
379
|
+
}
|
|
380
|
+
function re(s) {
|
|
381
|
+
return s.replace(Zt, "\\\\").replace(Xt, "{").replace(Yt, "}").replace(Jt, ",").replace(Kt, ".");
|
|
382
|
+
}
|
|
383
|
+
function xt(s) {
|
|
384
|
+
if (!s)
|
|
385
|
+
return [""];
|
|
386
|
+
const t = [], e = mt("{", "}", s);
|
|
387
|
+
if (!e)
|
|
388
|
+
return s.split(",");
|
|
389
|
+
const { pre: n, body: i, post: r } = e, o = n.split(",");
|
|
390
|
+
o[o.length - 1] += "{" + i + "}";
|
|
391
|
+
const a = xt(r);
|
|
392
|
+
return r.length && (o[o.length - 1] += a.shift(), o.push.apply(o, a)), t.push.apply(t, o), t;
|
|
393
|
+
}
|
|
394
|
+
function oe(s) {
|
|
395
|
+
return s ? (s.slice(0, 2) === "{}" && (s = "\\\\{\\\\}" + s.slice(2)), M(ie(s), !0).map(re)) : [];
|
|
396
|
+
}
|
|
397
|
+
function ae(s) {
|
|
398
|
+
return "{" + s + "}";
|
|
399
|
+
}
|
|
400
|
+
function ce(s) {
|
|
401
|
+
return /^-?0\\d/.test(s);
|
|
402
|
+
}
|
|
403
|
+
function le(s, t) {
|
|
404
|
+
return s <= t;
|
|
405
|
+
}
|
|
406
|
+
function he(s, t) {
|
|
407
|
+
return s >= t;
|
|
408
|
+
}
|
|
409
|
+
function M(s, t) {
|
|
410
|
+
const e = [], n = mt("{", "}", s);
|
|
411
|
+
if (!n)
|
|
412
|
+
return [s];
|
|
413
|
+
const i = n.pre, r = n.post.length ? M(n.post, !1) : [""];
|
|
414
|
+
if (/\\$$/.test(n.pre))
|
|
415
|
+
for (let o = 0; o < r.length; o++) {
|
|
416
|
+
const a = i + "{" + n.body + "}" + r[o];
|
|
417
|
+
e.push(a);
|
|
418
|
+
}
|
|
419
|
+
else {
|
|
420
|
+
const o = /^-?\\d+\\.\\.-?\\d+(?:\\.\\.-?\\d+)?$/.test(n.body), a = /^[a-zA-Z]\\.\\.[a-zA-Z](?:\\.\\.-?\\d+)?$/.test(n.body), l = o || a, h = n.body.indexOf(",") >= 0;
|
|
421
|
+
if (!l && !h)
|
|
422
|
+
return n.post.match(/,(?!,).*\\}/) ? (s = n.pre + "{" + n.body + J + n.post, M(s)) : [s];
|
|
423
|
+
let c;
|
|
424
|
+
if (l)
|
|
425
|
+
c = n.body.split(/\\.\\./);
|
|
426
|
+
else if (c = xt(n.body), c.length === 1 && c[0] !== void 0 && (c = M(c[0], !1).map(ae), c.length === 1))
|
|
427
|
+
return r.map((u) => n.pre + c[0] + u);
|
|
428
|
+
let f;
|
|
429
|
+
if (l && c[0] !== void 0 && c[1] !== void 0) {
|
|
430
|
+
const u = B(c[0]), d = B(c[1]), m = Math.max(c[0].length, c[1].length);
|
|
431
|
+
let p = c.length === 3 && c[2] !== void 0 ? Math.abs(B(c[2])) : 1, S = le;
|
|
432
|
+
d < u && (p *= -1, S = he);
|
|
433
|
+
const N = c.some(ce);
|
|
434
|
+
f = [];
|
|
435
|
+
for (let x = u; S(x, d); x += p) {
|
|
436
|
+
let w;
|
|
437
|
+
if (a)
|
|
438
|
+
w = String.fromCharCode(x), w === "\\\\" && (w = "");
|
|
439
|
+
else if (w = String(x), N) {
|
|
440
|
+
const F = m - w.length;
|
|
441
|
+
if (F > 0) {
|
|
442
|
+
const P = new Array(F + 1).join("0");
|
|
443
|
+
x < 0 ? w = "-" + P + w.slice(1) : w = P + w;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
f.push(w);
|
|
447
|
+
}
|
|
448
|
+
} else {
|
|
449
|
+
f = [];
|
|
450
|
+
for (let u = 0; u < c.length; u++)
|
|
451
|
+
f.push.apply(f, M(c[u], !1));
|
|
452
|
+
}
|
|
453
|
+
for (let u = 0; u < f.length; u++)
|
|
454
|
+
for (let d = 0; d < r.length; d++) {
|
|
455
|
+
const m = i + f[u] + r[d];
|
|
456
|
+
(!t || l || m) && e.push(m);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
return e;
|
|
460
|
+
}
|
|
461
|
+
const ue = 1024 * 64, W = (s) => {
|
|
462
|
+
if (typeof s != "string")
|
|
463
|
+
throw new TypeError("invalid pattern");
|
|
464
|
+
if (s.length > ue)
|
|
465
|
+
throw new TypeError("pattern is too long");
|
|
466
|
+
}, fe = {
|
|
467
|
+
"[:alnum:]": ["\\\\p{L}\\\\p{Nl}\\\\p{Nd}", !0],
|
|
468
|
+
"[:alpha:]": ["\\\\p{L}\\\\p{Nl}", !0],
|
|
469
|
+
"[:ascii:]": ["\\\\x00-\\\\x7f", !1],
|
|
470
|
+
"[:blank:]": ["\\\\p{Zs}\\\\t", !0],
|
|
471
|
+
"[:cntrl:]": ["\\\\p{Cc}", !0],
|
|
472
|
+
"[:digit:]": ["\\\\p{Nd}", !0],
|
|
473
|
+
"[:graph:]": ["\\\\p{Z}\\\\p{C}", !0, !0],
|
|
474
|
+
"[:lower:]": ["\\\\p{Ll}", !0],
|
|
475
|
+
"[:print:]": ["\\\\p{C}", !0],
|
|
476
|
+
"[:punct:]": ["\\\\p{P}", !0],
|
|
477
|
+
"[:space:]": ["\\\\p{Z}\\\\t\\\\r\\\\n\\\\v\\\\f", !0],
|
|
478
|
+
"[:upper:]": ["\\\\p{Lu}", !0],
|
|
479
|
+
"[:word:]": ["\\\\p{L}\\\\p{Nl}\\\\p{Nd}\\\\p{Pc}", !0],
|
|
480
|
+
"[:xdigit:]": ["A-Fa-f0-9", !1]
|
|
481
|
+
}, T = (s) => s.replace(/[[\\]\\\\-]/g, "\\\\$&"), de = (s) => s.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, "\\\\$&"), nt = (s) => s.join(""), pe = (s, t) => {
|
|
482
|
+
const e = t;
|
|
483
|
+
if (s.charAt(e) !== "[")
|
|
484
|
+
throw new Error("not in a brace expression");
|
|
485
|
+
const n = [], i = [];
|
|
486
|
+
let r = e + 1, o = !1, a = !1, l = !1, h = !1, c = e, f = "";
|
|
487
|
+
t: for (; r < s.length; ) {
|
|
488
|
+
const p = s.charAt(r);
|
|
489
|
+
if ((p === "!" || p === "^") && r === e + 1) {
|
|
490
|
+
h = !0, r++;
|
|
491
|
+
continue;
|
|
492
|
+
}
|
|
493
|
+
if (p === "]" && o && !l) {
|
|
494
|
+
c = r + 1;
|
|
495
|
+
break;
|
|
496
|
+
}
|
|
497
|
+
if (o = !0, p === "\\\\" && !l) {
|
|
498
|
+
l = !0, r++;
|
|
499
|
+
continue;
|
|
500
|
+
}
|
|
501
|
+
if (p === "[" && !l) {
|
|
502
|
+
for (const [S, [v, N, x]] of Object.entries(fe))
|
|
503
|
+
if (s.startsWith(S, r)) {
|
|
504
|
+
if (f)
|
|
505
|
+
return ["$.", !1, s.length - e, !0];
|
|
506
|
+
r += S.length, x ? i.push(v) : n.push(v), a = a || N;
|
|
507
|
+
continue t;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
if (l = !1, f) {
|
|
511
|
+
p > f ? n.push(T(f) + "-" + T(p)) : p === f && n.push(T(p)), f = "", r++;
|
|
512
|
+
continue;
|
|
513
|
+
}
|
|
514
|
+
if (s.startsWith("-]", r + 1)) {
|
|
515
|
+
n.push(T(p + "-")), r += 2;
|
|
516
|
+
continue;
|
|
517
|
+
}
|
|
518
|
+
if (s.startsWith("-", r + 1)) {
|
|
519
|
+
f = p, r += 2;
|
|
520
|
+
continue;
|
|
521
|
+
}
|
|
522
|
+
n.push(T(p)), r++;
|
|
523
|
+
}
|
|
524
|
+
if (c < r)
|
|
525
|
+
return ["", !1, 0, !1];
|
|
526
|
+
if (!n.length && !i.length)
|
|
527
|
+
return ["$.", !1, s.length - e, !0];
|
|
528
|
+
if (i.length === 0 && n.length === 1 && /^\\\\?.$/.test(n[0]) && !h) {
|
|
529
|
+
const p = n[0].length === 2 ? n[0].slice(-1) : n[0];
|
|
530
|
+
return [de(p), !1, c - e, !1];
|
|
531
|
+
}
|
|
532
|
+
const u = "[" + (h ? "^" : "") + nt(n) + "]", d = "[" + (h ? "" : "^") + nt(i) + "]";
|
|
533
|
+
return [n.length && i.length ? "(" + u + "|" + d + ")" : n.length ? u : d, a, c - e, !0];
|
|
534
|
+
}, $ = (s, { windowsPathsNoEscape: t = !1 } = {}) => t ? s.replace(/\\[([^\\/\\\\])\\]/g, "$1") : s.replace(/((?!\\\\).|^)\\[([^\\/\\\\])\\]/g, "$1$2").replace(/\\\\([^\\/])/g, "$1"), ge = /* @__PURE__ */ new Set(["!", "?", "+", "*", "@"]), it = (s) => ge.has(s), me = "(?!(?:^|/)\\\\.\\\\.?(?:$|/))", k = "(?!\\\\.)", we = /* @__PURE__ */ new Set(["[", "."]), ye = /* @__PURE__ */ new Set(["..", "."]), Ee = new Set("().*{}+?[]^$\\\\!"), Se = (s) => s.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, "\\\\$&"), K = "[^/]", rt = K + "*?", ot = K + "+?";
|
|
535
|
+
class E {
|
|
536
|
+
type;
|
|
537
|
+
#s;
|
|
538
|
+
#n;
|
|
539
|
+
#r = !1;
|
|
540
|
+
#t = [];
|
|
541
|
+
#e;
|
|
542
|
+
#o;
|
|
543
|
+
#c;
|
|
544
|
+
#a = !1;
|
|
545
|
+
#i;
|
|
546
|
+
#l;
|
|
547
|
+
// set to true if it's an extglob with no children
|
|
548
|
+
// (which really means one child of '')
|
|
549
|
+
#u = !1;
|
|
550
|
+
constructor(t, e, n = {}) {
|
|
551
|
+
this.type = t, t && (this.#n = !0), this.#e = e, this.#s = this.#e ? this.#e.#s : this, this.#i = this.#s === this ? n : this.#s.#i, this.#c = this.#s === this ? [] : this.#s.#c, t === "!" && !this.#s.#a && this.#c.push(this), this.#o = this.#e ? this.#e.#t.length : 0;
|
|
552
|
+
}
|
|
553
|
+
get hasMagic() {
|
|
554
|
+
if (this.#n !== void 0)
|
|
555
|
+
return this.#n;
|
|
556
|
+
for (const t of this.#t)
|
|
557
|
+
if (typeof t != "string" && (t.type || t.hasMagic))
|
|
558
|
+
return this.#n = !0;
|
|
559
|
+
return this.#n;
|
|
560
|
+
}
|
|
561
|
+
// reconstructs the pattern
|
|
562
|
+
toString() {
|
|
563
|
+
return this.#l !== void 0 ? this.#l : this.type ? this.#l = this.type + "(" + this.#t.map((t) => String(t)).join("|") + ")" : this.#l = this.#t.map((t) => String(t)).join("");
|
|
564
|
+
}
|
|
565
|
+
#d() {
|
|
566
|
+
if (this !== this.#s)
|
|
567
|
+
throw new Error("should only call on root");
|
|
568
|
+
if (this.#a)
|
|
569
|
+
return this;
|
|
570
|
+
this.toString(), this.#a = !0;
|
|
571
|
+
let t;
|
|
572
|
+
for (; t = this.#c.pop(); ) {
|
|
573
|
+
if (t.type !== "!")
|
|
574
|
+
continue;
|
|
575
|
+
let e = t, n = e.#e;
|
|
576
|
+
for (; n; ) {
|
|
577
|
+
for (let i = e.#o + 1; !n.type && i < n.#t.length; i++)
|
|
578
|
+
for (const r of t.#t) {
|
|
579
|
+
if (typeof r == "string")
|
|
580
|
+
throw new Error("string part in extglob AST??");
|
|
581
|
+
r.copyIn(n.#t[i]);
|
|
582
|
+
}
|
|
583
|
+
e = n, n = e.#e;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
return this;
|
|
587
|
+
}
|
|
588
|
+
push(...t) {
|
|
589
|
+
for (const e of t)
|
|
590
|
+
if (e !== "") {
|
|
591
|
+
if (typeof e != "string" && !(e instanceof E && e.#e === this))
|
|
592
|
+
throw new Error("invalid part: " + e);
|
|
593
|
+
this.#t.push(e);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
toJSON() {
|
|
597
|
+
const t = this.type === null ? this.#t.slice().map((e) => typeof e == "string" ? e : e.toJSON()) : [this.type, ...this.#t.map((e) => e.toJSON())];
|
|
598
|
+
return this.isStart() && !this.type && t.unshift([]), this.isEnd() && (this === this.#s || this.#s.#a && this.#e?.type === "!") && t.push({}), t;
|
|
599
|
+
}
|
|
600
|
+
isStart() {
|
|
601
|
+
if (this.#s === this)
|
|
602
|
+
return !0;
|
|
603
|
+
if (!this.#e?.isStart())
|
|
604
|
+
return !1;
|
|
605
|
+
if (this.#o === 0)
|
|
606
|
+
return !0;
|
|
607
|
+
const t = this.#e;
|
|
608
|
+
for (let e = 0; e < this.#o; e++) {
|
|
609
|
+
const n = t.#t[e];
|
|
610
|
+
if (!(n instanceof E && n.type === "!"))
|
|
611
|
+
return !1;
|
|
612
|
+
}
|
|
613
|
+
return !0;
|
|
614
|
+
}
|
|
615
|
+
isEnd() {
|
|
616
|
+
if (this.#s === this || this.#e?.type === "!")
|
|
617
|
+
return !0;
|
|
618
|
+
if (!this.#e?.isEnd())
|
|
619
|
+
return !1;
|
|
620
|
+
if (!this.type)
|
|
621
|
+
return this.#e?.isEnd();
|
|
622
|
+
const t = this.#e ? this.#e.#t.length : 0;
|
|
623
|
+
return this.#o === t - 1;
|
|
624
|
+
}
|
|
625
|
+
copyIn(t) {
|
|
626
|
+
typeof t == "string" ? this.push(t) : this.push(t.clone(this));
|
|
627
|
+
}
|
|
628
|
+
clone(t) {
|
|
629
|
+
const e = new E(this.type, t);
|
|
630
|
+
for (const n of this.#t)
|
|
631
|
+
e.copyIn(n);
|
|
632
|
+
return e;
|
|
633
|
+
}
|
|
634
|
+
static #h(t, e, n, i) {
|
|
635
|
+
let r = !1, o = !1, a = -1, l = !1;
|
|
636
|
+
if (e.type === null) {
|
|
637
|
+
let d = n, m = "";
|
|
638
|
+
for (; d < t.length; ) {
|
|
639
|
+
const p = t.charAt(d++);
|
|
640
|
+
if (r || p === "\\\\") {
|
|
641
|
+
r = !r, m += p;
|
|
642
|
+
continue;
|
|
643
|
+
}
|
|
644
|
+
if (o) {
|
|
645
|
+
d === a + 1 ? (p === "^" || p === "!") && (l = !0) : p === "]" && !(d === a + 2 && l) && (o = !1), m += p;
|
|
646
|
+
continue;
|
|
647
|
+
} else if (p === "[") {
|
|
648
|
+
o = !0, a = d, l = !1, m += p;
|
|
649
|
+
continue;
|
|
650
|
+
}
|
|
651
|
+
if (!i.noext && it(p) && t.charAt(d) === "(") {
|
|
652
|
+
e.push(m), m = "";
|
|
653
|
+
const S = new E(p, e);
|
|
654
|
+
d = E.#h(t, S, d, i), e.push(S);
|
|
655
|
+
continue;
|
|
656
|
+
}
|
|
657
|
+
m += p;
|
|
658
|
+
}
|
|
659
|
+
return e.push(m), d;
|
|
660
|
+
}
|
|
661
|
+
let h = n + 1, c = new E(null, e);
|
|
662
|
+
const f = [];
|
|
663
|
+
let u = "";
|
|
664
|
+
for (; h < t.length; ) {
|
|
665
|
+
const d = t.charAt(h++);
|
|
666
|
+
if (r || d === "\\\\") {
|
|
667
|
+
r = !r, u += d;
|
|
668
|
+
continue;
|
|
669
|
+
}
|
|
670
|
+
if (o) {
|
|
671
|
+
h === a + 1 ? (d === "^" || d === "!") && (l = !0) : d === "]" && !(h === a + 2 && l) && (o = !1), u += d;
|
|
672
|
+
continue;
|
|
673
|
+
} else if (d === "[") {
|
|
674
|
+
o = !0, a = h, l = !1, u += d;
|
|
675
|
+
continue;
|
|
676
|
+
}
|
|
677
|
+
if (it(d) && t.charAt(h) === "(") {
|
|
678
|
+
c.push(u), u = "";
|
|
679
|
+
const m = new E(d, c);
|
|
680
|
+
c.push(m), h = E.#h(t, m, h, i);
|
|
681
|
+
continue;
|
|
682
|
+
}
|
|
683
|
+
if (d === "|") {
|
|
684
|
+
c.push(u), u = "", f.push(c), c = new E(null, e);
|
|
685
|
+
continue;
|
|
686
|
+
}
|
|
687
|
+
if (d === ")")
|
|
688
|
+
return u === "" && e.#t.length === 0 && (e.#u = !0), c.push(u), u = "", e.push(...f, c), h;
|
|
689
|
+
u += d;
|
|
690
|
+
}
|
|
691
|
+
return e.type = null, e.#n = void 0, e.#t = [t.substring(n - 1)], h;
|
|
692
|
+
}
|
|
693
|
+
static fromGlob(t, e = {}) {
|
|
694
|
+
const n = new E(null, void 0, e);
|
|
695
|
+
return E.#h(t, n, 0, e), n;
|
|
696
|
+
}
|
|
697
|
+
// returns the regular expression if there's magic, or the unescaped
|
|
698
|
+
// string if not.
|
|
699
|
+
toMMPattern() {
|
|
700
|
+
if (this !== this.#s)
|
|
701
|
+
return this.#s.toMMPattern();
|
|
702
|
+
const t = this.toString(), [e, n, i, r] = this.toRegExpSource();
|
|
703
|
+
if (!(i || this.#n || this.#i.nocase && !this.#i.nocaseMagicOnly && t.toUpperCase() !== t.toLowerCase()))
|
|
704
|
+
return n;
|
|
705
|
+
const a = (this.#i.nocase ? "i" : "") + (r ? "u" : "");
|
|
706
|
+
return Object.assign(new RegExp(\`^\${e}$\`, a), {
|
|
707
|
+
_src: e,
|
|
708
|
+
_glob: t
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
get options() {
|
|
712
|
+
return this.#i;
|
|
713
|
+
}
|
|
714
|
+
// returns the string match, the regexp source, whether there's magic
|
|
715
|
+
// in the regexp (so a regular expression is required) and whether or
|
|
716
|
+
// not the uflag is needed for the regular expression (for posix classes)
|
|
717
|
+
// TODO: instead of injecting the start/end at this point, just return
|
|
718
|
+
// the BODY of the regexp, along with the start/end portions suitable
|
|
719
|
+
// for binding the start/end in either a joined full-path makeRe context
|
|
720
|
+
// (where we bind to (^|/), or a standalone matchPart context (where
|
|
721
|
+
// we bind to ^, and not /). Otherwise slashes get duped!
|
|
722
|
+
//
|
|
723
|
+
// In part-matching mode, the start is:
|
|
724
|
+
// - if not isStart: nothing
|
|
725
|
+
// - if traversal possible, but not allowed: ^(?!\\.\\.?$)
|
|
726
|
+
// - if dots allowed or not possible: ^
|
|
727
|
+
// - if dots possible and not allowed: ^(?!\\.)
|
|
728
|
+
// end is:
|
|
729
|
+
// - if not isEnd(): nothing
|
|
730
|
+
// - else: $
|
|
731
|
+
//
|
|
732
|
+
// In full-path matching mode, we put the slash at the START of the
|
|
733
|
+
// pattern, so start is:
|
|
734
|
+
// - if first pattern: same as part-matching mode
|
|
735
|
+
// - if not isStart(): nothing
|
|
736
|
+
// - if traversal possible, but not allowed: /(?!\\.\\.?(?:$|/))
|
|
737
|
+
// - if dots allowed or not possible: /
|
|
738
|
+
// - if dots possible and not allowed: /(?!\\.)
|
|
739
|
+
// end is:
|
|
740
|
+
// - if last pattern, same as part-matching mode
|
|
741
|
+
// - else nothing
|
|
742
|
+
//
|
|
743
|
+
// Always put the (?:$|/) on negated tails, though, because that has to be
|
|
744
|
+
// there to bind the end of the negated pattern portion, and it's easier to
|
|
745
|
+
// just stick it in now rather than try to inject it later in the middle of
|
|
746
|
+
// the pattern.
|
|
747
|
+
//
|
|
748
|
+
// We can just always return the same end, and leave it up to the caller
|
|
749
|
+
// to know whether it's going to be used joined or in parts.
|
|
750
|
+
// And, if the start is adjusted slightly, can do the same there:
|
|
751
|
+
// - if not isStart: nothing
|
|
752
|
+
// - if traversal possible, but not allowed: (?:/|^)(?!\\.\\.?$)
|
|
753
|
+
// - if dots allowed or not possible: (?:/|^)
|
|
754
|
+
// - if dots possible and not allowed: (?:/|^)(?!\\.)
|
|
755
|
+
//
|
|
756
|
+
// But it's better to have a simpler binding without a conditional, for
|
|
757
|
+
// performance, so probably better to return both start options.
|
|
758
|
+
//
|
|
759
|
+
// Then the caller just ignores the end if it's not the first pattern,
|
|
760
|
+
// and the start always gets applied.
|
|
761
|
+
//
|
|
762
|
+
// But that's always going to be $ if it's the ending pattern, or nothing,
|
|
763
|
+
// so the caller can just attach $ at the end of the pattern when building.
|
|
764
|
+
//
|
|
765
|
+
// So the todo is:
|
|
766
|
+
// - better detect what kind of start is needed
|
|
767
|
+
// - return both flavors of starting pattern
|
|
768
|
+
// - attach $ at the end of the pattern when creating the actual RegExp
|
|
769
|
+
//
|
|
770
|
+
// Ah, but wait, no, that all only applies to the root when the first pattern
|
|
771
|
+
// is not an extglob. If the first pattern IS an extglob, then we need all
|
|
772
|
+
// that dot prevention biz to live in the extglob portions, because eg
|
|
773
|
+
// +(*|.x*) can match .xy but not .yx.
|
|
774
|
+
//
|
|
775
|
+
// So, return the two flavors if it's #root and the first child is not an
|
|
776
|
+
// AST, otherwise leave it to the child AST to handle it, and there,
|
|
777
|
+
// use the (?:^|/) style of start binding.
|
|
778
|
+
//
|
|
779
|
+
// Even simplified further:
|
|
780
|
+
// - Since the start for a join is eg /(?!\\.) and the start for a part
|
|
781
|
+
// is ^(?!\\.), we can just prepend (?!\\.) to the pattern (either root
|
|
782
|
+
// or start or whatever) and prepend ^ or / at the Regexp construction.
|
|
783
|
+
toRegExpSource(t) {
|
|
784
|
+
const e = t ?? !!this.#i.dot;
|
|
785
|
+
if (this.#s === this && this.#d(), !this.type) {
|
|
786
|
+
const l = this.isStart() && this.isEnd(), h = this.#t.map((d) => {
|
|
787
|
+
const [m, p, S, v] = typeof d == "string" ? E.#p(d, this.#n, l) : d.toRegExpSource(t);
|
|
788
|
+
return this.#n = this.#n || S, this.#r = this.#r || v, m;
|
|
789
|
+
}).join("");
|
|
790
|
+
let c = "";
|
|
791
|
+
if (this.isStart() && typeof this.#t[0] == "string" && !(this.#t.length === 1 && ye.has(this.#t[0]))) {
|
|
792
|
+
const m = we, p = (
|
|
793
|
+
// dots are allowed, and the pattern starts with [ or .
|
|
794
|
+
e && m.has(h.charAt(0)) || // the pattern starts with \\., and then [ or .
|
|
795
|
+
h.startsWith("\\\\.") && m.has(h.charAt(2)) || // the pattern starts with \\.\\., and then [ or .
|
|
796
|
+
h.startsWith("\\\\.\\\\.") && m.has(h.charAt(4))
|
|
797
|
+
), S = !e && !t && m.has(h.charAt(0));
|
|
798
|
+
c = p ? me : S ? k : "";
|
|
799
|
+
}
|
|
800
|
+
let f = "";
|
|
801
|
+
return this.isEnd() && this.#s.#a && this.#e?.type === "!" && (f = "(?:$|\\\\/)"), [
|
|
802
|
+
c + h + f,
|
|
803
|
+
$(h),
|
|
804
|
+
this.#n = !!this.#n,
|
|
805
|
+
this.#r
|
|
806
|
+
];
|
|
807
|
+
}
|
|
808
|
+
const n = this.type === "*" || this.type === "+", i = this.type === "!" ? "(?:(?!(?:" : "(?:";
|
|
809
|
+
let r = this.#f(e);
|
|
810
|
+
if (this.isStart() && this.isEnd() && !r && this.type !== "!") {
|
|
811
|
+
const l = this.toString();
|
|
812
|
+
return this.#t = [l], this.type = null, this.#n = void 0, [l, $(this.toString()), !1, !1];
|
|
813
|
+
}
|
|
814
|
+
let o = !n || t || e || !k ? "" : this.#f(!0);
|
|
815
|
+
o === r && (o = ""), o && (r = \`(?:\${r})(?:\${o})*?\`);
|
|
816
|
+
let a = "";
|
|
817
|
+
if (this.type === "!" && this.#u)
|
|
818
|
+
a = (this.isStart() && !e ? k : "") + ot;
|
|
819
|
+
else {
|
|
820
|
+
const l = this.type === "!" ? (
|
|
821
|
+
// !() must match something,but !(x) can match ''
|
|
822
|
+
"))" + (this.isStart() && !e && !t ? k : "") + rt + ")"
|
|
823
|
+
) : this.type === "@" ? ")" : this.type === "?" ? ")?" : this.type === "+" && o ? ")" : this.type === "*" && o ? ")?" : \`)\${this.type}\`;
|
|
824
|
+
a = i + r + l;
|
|
825
|
+
}
|
|
826
|
+
return [
|
|
827
|
+
a,
|
|
828
|
+
$(r),
|
|
829
|
+
this.#n = !!this.#n,
|
|
830
|
+
this.#r
|
|
831
|
+
];
|
|
832
|
+
}
|
|
833
|
+
#f(t) {
|
|
834
|
+
return this.#t.map((e) => {
|
|
835
|
+
if (typeof e == "string")
|
|
836
|
+
throw new Error("string type in extglob ast??");
|
|
837
|
+
const [n, i, r, o] = e.toRegExpSource(t);
|
|
838
|
+
return this.#r = this.#r || o, n;
|
|
839
|
+
}).filter((e) => !(this.isStart() && this.isEnd()) || !!e).join("|");
|
|
840
|
+
}
|
|
841
|
+
static #p(t, e, n = !1) {
|
|
842
|
+
let i = !1, r = "", o = !1;
|
|
843
|
+
for (let a = 0; a < t.length; a++) {
|
|
844
|
+
const l = t.charAt(a);
|
|
845
|
+
if (i) {
|
|
846
|
+
i = !1, r += (Ee.has(l) ? "\\\\" : "") + l;
|
|
847
|
+
continue;
|
|
848
|
+
}
|
|
849
|
+
if (l === "\\\\") {
|
|
850
|
+
a === t.length - 1 ? r += "\\\\\\\\" : i = !0;
|
|
851
|
+
continue;
|
|
852
|
+
}
|
|
853
|
+
if (l === "[") {
|
|
854
|
+
const [h, c, f, u] = pe(t, a);
|
|
855
|
+
if (f) {
|
|
856
|
+
r += h, o = o || c, a += f - 1, e = e || u;
|
|
857
|
+
continue;
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
if (l === "*") {
|
|
861
|
+
n && t === "*" ? r += ot : r += rt, e = !0;
|
|
862
|
+
continue;
|
|
863
|
+
}
|
|
864
|
+
if (l === "?") {
|
|
865
|
+
r += K, e = !0;
|
|
866
|
+
continue;
|
|
867
|
+
}
|
|
868
|
+
r += Se(l);
|
|
869
|
+
}
|
|
870
|
+
return [r, $(t), !!e, o];
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
const xe = (s, { windowsPathsNoEscape: t = !1 } = {}) => t ? s.replace(/[?*()[\\]]/g, "[$&]") : s.replace(/[?*()[\\]\\\\]/g, "\\\\$&"), y = (s, t, e = {}) => (W(t), !e.nocomment && t.charAt(0) === "#" ? !1 : new j(t, e).match(s)), be = /^\\*+([^+@!?\\*\\[\\(]*)$/, Ae = (s) => (t) => !t.startsWith(".") && t.endsWith(s), ve = (s) => (t) => t.endsWith(s), Ce = (s) => (s = s.toLowerCase(), (t) => !t.startsWith(".") && t.toLowerCase().endsWith(s)), De = (s) => (s = s.toLowerCase(), (t) => t.toLowerCase().endsWith(s)), Oe = /^\\*+\\.\\*+$/, Ne = (s) => !s.startsWith(".") && s.includes("."), Fe = (s) => s !== "." && s !== ".." && s.includes("."), Te = /^\\.\\*+$/, Me = (s) => s !== "." && s !== ".." && s.startsWith("."), $e = /^\\*+$/, Pe = (s) => s.length !== 0 && !s.startsWith("."), Re = (s) => s.length !== 0 && s !== "." && s !== "..", ke = /^\\?+([^+@!?\\*\\[\\(]*)?$/, Le = ([s, t = ""]) => {
|
|
874
|
+
const e = bt([s]);
|
|
875
|
+
return t ? (t = t.toLowerCase(), (n) => e(n) && n.toLowerCase().endsWith(t)) : e;
|
|
876
|
+
}, Ie = ([s, t = ""]) => {
|
|
877
|
+
const e = At([s]);
|
|
878
|
+
return t ? (t = t.toLowerCase(), (n) => e(n) && n.toLowerCase().endsWith(t)) : e;
|
|
879
|
+
}, ze = ([s, t = ""]) => {
|
|
880
|
+
const e = At([s]);
|
|
881
|
+
return t ? (n) => e(n) && n.endsWith(t) : e;
|
|
882
|
+
}, He = ([s, t = ""]) => {
|
|
883
|
+
const e = bt([s]);
|
|
884
|
+
return t ? (n) => e(n) && n.endsWith(t) : e;
|
|
885
|
+
}, bt = ([s]) => {
|
|
886
|
+
const t = s.length;
|
|
887
|
+
return (e) => e.length === t && !e.startsWith(".");
|
|
888
|
+
}, At = ([s]) => {
|
|
889
|
+
const t = s.length;
|
|
890
|
+
return (e) => e.length === t && e !== "." && e !== "..";
|
|
891
|
+
}, vt = typeof process == "object" && process ? typeof process.env == "object" && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix", at = {
|
|
892
|
+
win32: { sep: "\\\\" },
|
|
893
|
+
posix: { sep: "/" }
|
|
894
|
+
}, We = vt === "win32" ? at.win32.sep : at.posix.sep;
|
|
895
|
+
y.sep = We;
|
|
896
|
+
const A = Symbol("globstar **");
|
|
897
|
+
y.GLOBSTAR = A;
|
|
898
|
+
const je = "[^/]", Ue = je + "*?", _e = "(?:(?!(?:\\\\/|^)(?:\\\\.{1,2})($|\\\\/)).)*?", Be = "(?:(?!(?:\\\\/|^)\\\\.).)*?", Ge = (s, t = {}) => (e) => y(e, s, t);
|
|
899
|
+
y.filter = Ge;
|
|
900
|
+
const b = (s, t = {}) => Object.assign({}, s, t), qe = (s) => {
|
|
901
|
+
if (!s || typeof s != "object" || !Object.keys(s).length)
|
|
902
|
+
return y;
|
|
903
|
+
const t = y;
|
|
904
|
+
return Object.assign((n, i, r = {}) => t(n, i, b(s, r)), {
|
|
905
|
+
Minimatch: class extends t.Minimatch {
|
|
906
|
+
constructor(i, r = {}) {
|
|
907
|
+
super(i, b(s, r));
|
|
908
|
+
}
|
|
909
|
+
static defaults(i) {
|
|
910
|
+
return t.defaults(b(s, i)).Minimatch;
|
|
911
|
+
}
|
|
912
|
+
},
|
|
913
|
+
AST: class extends t.AST {
|
|
914
|
+
/* c8 ignore start */
|
|
915
|
+
constructor(i, r, o = {}) {
|
|
916
|
+
super(i, r, b(s, o));
|
|
917
|
+
}
|
|
918
|
+
/* c8 ignore stop */
|
|
919
|
+
static fromGlob(i, r = {}) {
|
|
920
|
+
return t.AST.fromGlob(i, b(s, r));
|
|
921
|
+
}
|
|
922
|
+
},
|
|
923
|
+
unescape: (n, i = {}) => t.unescape(n, b(s, i)),
|
|
924
|
+
escape: (n, i = {}) => t.escape(n, b(s, i)),
|
|
925
|
+
filter: (n, i = {}) => t.filter(n, b(s, i)),
|
|
926
|
+
defaults: (n) => t.defaults(b(s, n)),
|
|
927
|
+
makeRe: (n, i = {}) => t.makeRe(n, b(s, i)),
|
|
928
|
+
braceExpand: (n, i = {}) => t.braceExpand(n, b(s, i)),
|
|
929
|
+
match: (n, i, r = {}) => t.match(n, i, b(s, r)),
|
|
930
|
+
sep: t.sep,
|
|
931
|
+
GLOBSTAR: A
|
|
932
|
+
});
|
|
933
|
+
};
|
|
934
|
+
y.defaults = qe;
|
|
935
|
+
const Ct = (s, t = {}) => (W(s), t.nobrace || !/\\{(?:(?!\\{).)*\\}/.test(s) ? [s] : oe(s));
|
|
936
|
+
y.braceExpand = Ct;
|
|
937
|
+
const Ve = (s, t = {}) => new j(s, t).makeRe();
|
|
938
|
+
y.makeRe = Ve;
|
|
939
|
+
const Ze = (s, t, e = {}) => {
|
|
940
|
+
const n = new j(t, e);
|
|
941
|
+
return s = s.filter((i) => n.match(i)), n.options.nonull && !s.length && s.push(t), s;
|
|
942
|
+
};
|
|
943
|
+
y.match = Ze;
|
|
944
|
+
const ct = /[?*]|[+@!]\\(.*?\\)|\\[|\\]/, Xe = (s) => s.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, "\\\\$&");
|
|
945
|
+
class j {
|
|
946
|
+
options;
|
|
947
|
+
set;
|
|
948
|
+
pattern;
|
|
949
|
+
windowsPathsNoEscape;
|
|
950
|
+
nonegate;
|
|
951
|
+
negate;
|
|
952
|
+
comment;
|
|
953
|
+
empty;
|
|
954
|
+
preserveMultipleSlashes;
|
|
955
|
+
partial;
|
|
956
|
+
globSet;
|
|
957
|
+
globParts;
|
|
958
|
+
nocase;
|
|
959
|
+
isWindows;
|
|
960
|
+
platform;
|
|
961
|
+
windowsNoMagicRoot;
|
|
962
|
+
regexp;
|
|
963
|
+
constructor(t, e = {}) {
|
|
964
|
+
W(t), e = e || {}, this.options = e, this.pattern = t, this.platform = e.platform || vt, 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();
|
|
965
|
+
}
|
|
966
|
+
hasMagic() {
|
|
967
|
+
if (this.options.magicalBraces && this.set.length > 1)
|
|
968
|
+
return !0;
|
|
969
|
+
for (const t of this.set)
|
|
970
|
+
for (const e of t)
|
|
971
|
+
if (typeof e != "string")
|
|
972
|
+
return !0;
|
|
973
|
+
return !1;
|
|
974
|
+
}
|
|
975
|
+
debug(...t) {
|
|
976
|
+
}
|
|
977
|
+
make() {
|
|
978
|
+
const t = this.pattern, e = this.options;
|
|
979
|
+
if (!e.nocomment && t.charAt(0) === "#") {
|
|
980
|
+
this.comment = !0;
|
|
981
|
+
return;
|
|
982
|
+
}
|
|
983
|
+
if (!t) {
|
|
984
|
+
this.empty = !0;
|
|
985
|
+
return;
|
|
986
|
+
}
|
|
987
|
+
this.parseNegate(), this.globSet = [...new Set(this.braceExpand())], e.debug && (this.debug = (...r) => console.error(...r)), this.debug(this.pattern, this.globSet);
|
|
988
|
+
const n = this.globSet.map((r) => this.slashSplit(r));
|
|
989
|
+
this.globParts = this.preprocess(n), this.debug(this.pattern, this.globParts);
|
|
990
|
+
let i = this.globParts.map((r, o, a) => {
|
|
991
|
+
if (this.isWindows && this.windowsNoMagicRoot) {
|
|
992
|
+
const l = r[0] === "" && r[1] === "" && (r[2] === "?" || !ct.test(r[2])) && !ct.test(r[3]), h = /^[a-z]:/i.test(r[0]);
|
|
993
|
+
if (l)
|
|
994
|
+
return [...r.slice(0, 4), ...r.slice(4).map((c) => this.parse(c))];
|
|
995
|
+
if (h)
|
|
996
|
+
return [r[0], ...r.slice(1).map((c) => this.parse(c))];
|
|
997
|
+
}
|
|
998
|
+
return r.map((l) => this.parse(l));
|
|
999
|
+
});
|
|
1000
|
+
if (this.debug(this.pattern, i), this.set = i.filter((r) => r.indexOf(!1) === -1), this.isWindows)
|
|
1001
|
+
for (let r = 0; r < this.set.length; r++) {
|
|
1002
|
+
const o = this.set[r];
|
|
1003
|
+
o[0] === "" && o[1] === "" && this.globParts[r][2] === "?" && typeof o[3] == "string" && /^[a-z]:$/i.test(o[3]) && (o[2] = "?");
|
|
1004
|
+
}
|
|
1005
|
+
this.debug(this.pattern, this.set);
|
|
1006
|
+
}
|
|
1007
|
+
// various transforms to equivalent pattern sets that are
|
|
1008
|
+
// faster to process in a filesystem walk. The goal is to
|
|
1009
|
+
// eliminate what we can, and push all ** patterns as far
|
|
1010
|
+
// to the right as possible, even if it increases the number
|
|
1011
|
+
// of patterns that we have to process.
|
|
1012
|
+
preprocess(t) {
|
|
1013
|
+
if (this.options.noglobstar)
|
|
1014
|
+
for (let n = 0; n < t.length; n++)
|
|
1015
|
+
for (let i = 0; i < t[n].length; i++)
|
|
1016
|
+
t[n][i] === "**" && (t[n][i] = "*");
|
|
1017
|
+
const { optimizationLevel: e = 1 } = this.options;
|
|
1018
|
+
return e >= 2 ? (t = this.firstPhasePreProcess(t), t = this.secondPhasePreProcess(t)) : e >= 1 ? t = this.levelOneOptimize(t) : t = this.adjascentGlobstarOptimize(t), t;
|
|
1019
|
+
}
|
|
1020
|
+
// just get rid of adjascent ** portions
|
|
1021
|
+
adjascentGlobstarOptimize(t) {
|
|
1022
|
+
return t.map((e) => {
|
|
1023
|
+
let n = -1;
|
|
1024
|
+
for (; (n = e.indexOf("**", n + 1)) !== -1; ) {
|
|
1025
|
+
let i = n;
|
|
1026
|
+
for (; e[i + 1] === "**"; )
|
|
1027
|
+
i++;
|
|
1028
|
+
i !== n && e.splice(n, i - n);
|
|
1029
|
+
}
|
|
1030
|
+
return e;
|
|
1031
|
+
});
|
|
1032
|
+
}
|
|
1033
|
+
// get rid of adjascent ** and resolve .. portions
|
|
1034
|
+
levelOneOptimize(t) {
|
|
1035
|
+
return t.map((e) => (e = e.reduce((n, i) => {
|
|
1036
|
+
const r = n[n.length - 1];
|
|
1037
|
+
return i === "**" && r === "**" ? n : i === ".." && r && r !== ".." && r !== "." && r !== "**" ? (n.pop(), n) : (n.push(i), n);
|
|
1038
|
+
}, []), e.length === 0 ? [""] : e));
|
|
1039
|
+
}
|
|
1040
|
+
levelTwoFileOptimize(t) {
|
|
1041
|
+
Array.isArray(t) || (t = this.slashSplit(t));
|
|
1042
|
+
let e = !1;
|
|
1043
|
+
do {
|
|
1044
|
+
if (e = !1, !this.preserveMultipleSlashes) {
|
|
1045
|
+
for (let i = 1; i < t.length - 1; i++) {
|
|
1046
|
+
const r = t[i];
|
|
1047
|
+
i === 1 && r === "" && t[0] === "" || (r === "." || r === "") && (e = !0, t.splice(i, 1), i--);
|
|
1048
|
+
}
|
|
1049
|
+
t[0] === "." && t.length === 2 && (t[1] === "." || t[1] === "") && (e = !0, t.pop());
|
|
1050
|
+
}
|
|
1051
|
+
let n = 0;
|
|
1052
|
+
for (; (n = t.indexOf("..", n + 1)) !== -1; ) {
|
|
1053
|
+
const i = t[n - 1];
|
|
1054
|
+
i && i !== "." && i !== ".." && i !== "**" && (e = !0, t.splice(n - 1, 2), n -= 2);
|
|
1055
|
+
}
|
|
1056
|
+
} while (e);
|
|
1057
|
+
return t.length === 0 ? [""] : t;
|
|
1058
|
+
}
|
|
1059
|
+
// First phase: single-pattern processing
|
|
1060
|
+
// <pre> is 1 or more portions
|
|
1061
|
+
// <rest> is 1 or more portions
|
|
1062
|
+
// <p> is any portion other than ., .., '', or **
|
|
1063
|
+
// <e> is . or ''
|
|
1064
|
+
//
|
|
1065
|
+
// **/.. is *brutal* for filesystem walking performance, because
|
|
1066
|
+
// it effectively resets the recursive walk each time it occurs,
|
|
1067
|
+
// and ** cannot be reduced out by a .. pattern part like a regexp
|
|
1068
|
+
// or most strings (other than .., ., and '') can be.
|
|
1069
|
+
//
|
|
1070
|
+
// <pre>/**/../<p>/<p>/<rest> -> {<pre>/../<p>/<p>/<rest>,<pre>/**/<p>/<p>/<rest>}
|
|
1071
|
+
// <pre>/<e>/<rest> -> <pre>/<rest>
|
|
1072
|
+
// <pre>/<p>/../<rest> -> <pre>/<rest>
|
|
1073
|
+
// **/**/<rest> -> **/<rest>
|
|
1074
|
+
//
|
|
1075
|
+
// **/*/<rest> -> */**/<rest> <== not valid because ** doesn't follow
|
|
1076
|
+
// this WOULD be allowed if ** did follow symlinks, or * didn't
|
|
1077
|
+
firstPhasePreProcess(t) {
|
|
1078
|
+
let e = !1;
|
|
1079
|
+
do {
|
|
1080
|
+
e = !1;
|
|
1081
|
+
for (let n of t) {
|
|
1082
|
+
let i = -1;
|
|
1083
|
+
for (; (i = n.indexOf("**", i + 1)) !== -1; ) {
|
|
1084
|
+
let o = i;
|
|
1085
|
+
for (; n[o + 1] === "**"; )
|
|
1086
|
+
o++;
|
|
1087
|
+
o > i && n.splice(i + 1, o - i);
|
|
1088
|
+
let a = n[i + 1];
|
|
1089
|
+
const l = n[i + 2], h = n[i + 3];
|
|
1090
|
+
if (a !== ".." || !l || l === "." || l === ".." || !h || h === "." || h === "..")
|
|
1091
|
+
continue;
|
|
1092
|
+
e = !0, n.splice(i, 1);
|
|
1093
|
+
const c = n.slice(0);
|
|
1094
|
+
c[i] = "**", t.push(c), i--;
|
|
1095
|
+
}
|
|
1096
|
+
if (!this.preserveMultipleSlashes) {
|
|
1097
|
+
for (let o = 1; o < n.length - 1; o++) {
|
|
1098
|
+
const a = n[o];
|
|
1099
|
+
o === 1 && a === "" && n[0] === "" || (a === "." || a === "") && (e = !0, n.splice(o, 1), o--);
|
|
1100
|
+
}
|
|
1101
|
+
n[0] === "." && n.length === 2 && (n[1] === "." || n[1] === "") && (e = !0, n.pop());
|
|
1102
|
+
}
|
|
1103
|
+
let r = 0;
|
|
1104
|
+
for (; (r = n.indexOf("..", r + 1)) !== -1; ) {
|
|
1105
|
+
const o = n[r - 1];
|
|
1106
|
+
if (o && o !== "." && o !== ".." && o !== "**") {
|
|
1107
|
+
e = !0;
|
|
1108
|
+
const l = r === 1 && n[r + 1] === "**" ? ["."] : [];
|
|
1109
|
+
n.splice(r - 1, 2, ...l), n.length === 0 && n.push(""), r -= 2;
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
} while (e);
|
|
1114
|
+
return t;
|
|
1115
|
+
}
|
|
1116
|
+
// second phase: multi-pattern dedupes
|
|
1117
|
+
// {<pre>/*/<rest>,<pre>/<p>/<rest>} -> <pre>/*/<rest>
|
|
1118
|
+
// {<pre>/<rest>,<pre>/<rest>} -> <pre>/<rest>
|
|
1119
|
+
// {<pre>/**/<rest>,<pre>/<rest>} -> <pre>/**/<rest>
|
|
1120
|
+
//
|
|
1121
|
+
// {<pre>/**/<rest>,<pre>/**/<p>/<rest>} -> <pre>/**/<rest>
|
|
1122
|
+
// ^-- not valid because ** doens't follow symlinks
|
|
1123
|
+
secondPhasePreProcess(t) {
|
|
1124
|
+
for (let e = 0; e < t.length - 1; e++)
|
|
1125
|
+
for (let n = e + 1; n < t.length; n++) {
|
|
1126
|
+
const i = this.partsMatch(t[e], t[n], !this.preserveMultipleSlashes);
|
|
1127
|
+
if (i) {
|
|
1128
|
+
t[e] = [], t[n] = i;
|
|
1129
|
+
break;
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
return t.filter((e) => e.length);
|
|
1133
|
+
}
|
|
1134
|
+
partsMatch(t, e, n = !1) {
|
|
1135
|
+
let i = 0, r = 0, o = [], a = "";
|
|
1136
|
+
for (; i < t.length && r < e.length; )
|
|
1137
|
+
if (t[i] === e[r])
|
|
1138
|
+
o.push(a === "b" ? e[r] : t[i]), i++, r++;
|
|
1139
|
+
else if (n && t[i] === "**" && e[r] === t[i + 1])
|
|
1140
|
+
o.push(t[i]), i++;
|
|
1141
|
+
else if (n && e[r] === "**" && t[i] === e[r + 1])
|
|
1142
|
+
o.push(e[r]), r++;
|
|
1143
|
+
else if (t[i] === "*" && e[r] && (this.options.dot || !e[r].startsWith(".")) && e[r] !== "**") {
|
|
1144
|
+
if (a === "b")
|
|
1145
|
+
return !1;
|
|
1146
|
+
a = "a", o.push(t[i]), i++, r++;
|
|
1147
|
+
} else if (e[r] === "*" && t[i] && (this.options.dot || !t[i].startsWith(".")) && t[i] !== "**") {
|
|
1148
|
+
if (a === "a")
|
|
1149
|
+
return !1;
|
|
1150
|
+
a = "b", o.push(e[r]), i++, r++;
|
|
1151
|
+
} else
|
|
1152
|
+
return !1;
|
|
1153
|
+
return t.length === e.length && o;
|
|
1154
|
+
}
|
|
1155
|
+
parseNegate() {
|
|
1156
|
+
if (this.nonegate)
|
|
1157
|
+
return;
|
|
1158
|
+
const t = this.pattern;
|
|
1159
|
+
let e = !1, n = 0;
|
|
1160
|
+
for (let i = 0; i < t.length && t.charAt(i) === "!"; i++)
|
|
1161
|
+
e = !e, n++;
|
|
1162
|
+
n && (this.pattern = t.slice(n)), this.negate = e;
|
|
1163
|
+
}
|
|
1164
|
+
// set partial to true to test if, for example,
|
|
1165
|
+
// "/a/b" matches the start of "/*/b/*/d"
|
|
1166
|
+
// Partial means, if you run out of file before you run
|
|
1167
|
+
// out of pattern, then that's fine, as long as all
|
|
1168
|
+
// the parts match.
|
|
1169
|
+
matchOne(t, e, n = !1) {
|
|
1170
|
+
const i = this.options;
|
|
1171
|
+
if (this.isWindows) {
|
|
1172
|
+
const p = typeof t[0] == "string" && /^[a-z]:$/i.test(t[0]), S = !p && t[0] === "" && t[1] === "" && t[2] === "?" && /^[a-z]:$/i.test(t[3]), v = typeof e[0] == "string" && /^[a-z]:$/i.test(e[0]), N = !v && e[0] === "" && e[1] === "" && e[2] === "?" && typeof e[3] == "string" && /^[a-z]:$/i.test(e[3]), x = S ? 3 : p ? 0 : void 0, w = N ? 3 : v ? 0 : void 0;
|
|
1173
|
+
if (typeof x == "number" && typeof w == "number") {
|
|
1174
|
+
const [F, P] = [t[x], e[w]];
|
|
1175
|
+
F.toLowerCase() === P.toLowerCase() && (e[w] = F, w > x ? e = e.slice(w) : x > w && (t = t.slice(x)));
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
const { optimizationLevel: r = 1 } = this.options;
|
|
1179
|
+
r >= 2 && (t = this.levelTwoFileOptimize(t)), this.debug("matchOne", this, { file: t, pattern: e }), this.debug("matchOne", t.length, e.length);
|
|
1180
|
+
for (var o = 0, a = 0, l = t.length, h = e.length; o < l && a < h; o++, a++) {
|
|
1181
|
+
this.debug("matchOne loop");
|
|
1182
|
+
var c = e[a], f = t[o];
|
|
1183
|
+
if (this.debug(e, c, f), c === !1)
|
|
1184
|
+
return !1;
|
|
1185
|
+
if (c === A) {
|
|
1186
|
+
this.debug("GLOBSTAR", [e, c, f]);
|
|
1187
|
+
var u = o, d = a + 1;
|
|
1188
|
+
if (d === h) {
|
|
1189
|
+
for (this.debug("** at the end"); o < l; o++)
|
|
1190
|
+
if (t[o] === "." || t[o] === ".." || !i.dot && t[o].charAt(0) === ".")
|
|
1191
|
+
return !1;
|
|
1192
|
+
return !0;
|
|
1193
|
+
}
|
|
1194
|
+
for (; u < l; ) {
|
|
1195
|
+
var m = t[u];
|
|
1196
|
+
if (this.debug(\`
|
|
1197
|
+
globstar while\`, t, u, e, d, m), this.matchOne(t.slice(u), e.slice(d), n))
|
|
1198
|
+
return this.debug("globstar found match!", u, l, m), !0;
|
|
1199
|
+
if (m === "." || m === ".." || !i.dot && m.charAt(0) === ".") {
|
|
1200
|
+
this.debug("dot detected!", t, u, e, d);
|
|
1201
|
+
break;
|
|
1202
|
+
}
|
|
1203
|
+
this.debug("globstar swallow a segment, and continue"), u++;
|
|
1204
|
+
}
|
|
1205
|
+
return !!(n && (this.debug(\`
|
|
1206
|
+
>>> no match, partial?\`, t, u, e, d), u === l));
|
|
1207
|
+
}
|
|
1208
|
+
let p;
|
|
1209
|
+
if (typeof c == "string" ? (p = f === c, this.debug("string match", c, f, p)) : (p = c.test(f), this.debug("pattern match", c, f, p)), !p)
|
|
1210
|
+
return !1;
|
|
1211
|
+
}
|
|
1212
|
+
if (o === l && a === h)
|
|
1213
|
+
return !0;
|
|
1214
|
+
if (o === l)
|
|
1215
|
+
return n;
|
|
1216
|
+
if (a === h)
|
|
1217
|
+
return o === l - 1 && t[o] === "";
|
|
1218
|
+
throw new Error("wtf?");
|
|
1219
|
+
}
|
|
1220
|
+
braceExpand() {
|
|
1221
|
+
return Ct(this.pattern, this.options);
|
|
1222
|
+
}
|
|
1223
|
+
parse(t) {
|
|
1224
|
+
W(t);
|
|
1225
|
+
const e = this.options;
|
|
1226
|
+
if (t === "**")
|
|
1227
|
+
return A;
|
|
1228
|
+
if (t === "")
|
|
1229
|
+
return "";
|
|
1230
|
+
let n, i = null;
|
|
1231
|
+
(n = t.match($e)) ? i = e.dot ? Re : Pe : (n = t.match(be)) ? i = (e.nocase ? e.dot ? De : Ce : e.dot ? ve : Ae)(n[1]) : (n = t.match(ke)) ? i = (e.nocase ? e.dot ? Ie : Le : e.dot ? ze : He)(n) : (n = t.match(Oe)) ? i = e.dot ? Fe : Ne : (n = t.match(Te)) && (i = Me);
|
|
1232
|
+
const r = E.fromGlob(t, this.options).toMMPattern();
|
|
1233
|
+
return i && typeof r == "object" && Reflect.defineProperty(r, "test", { value: i }), r;
|
|
1234
|
+
}
|
|
1235
|
+
makeRe() {
|
|
1236
|
+
if (this.regexp || this.regexp === !1)
|
|
1237
|
+
return this.regexp;
|
|
1238
|
+
const t = this.set;
|
|
1239
|
+
if (!t.length)
|
|
1240
|
+
return this.regexp = !1, this.regexp;
|
|
1241
|
+
const e = this.options, n = e.noglobstar ? Ue : e.dot ? _e : Be, i = new Set(e.nocase ? ["i"] : []);
|
|
1242
|
+
let r = t.map((l) => {
|
|
1243
|
+
const h = l.map((c) => {
|
|
1244
|
+
if (c instanceof RegExp)
|
|
1245
|
+
for (const f of c.flags.split(""))
|
|
1246
|
+
i.add(f);
|
|
1247
|
+
return typeof c == "string" ? Xe(c) : c === A ? A : c._src;
|
|
1248
|
+
});
|
|
1249
|
+
return h.forEach((c, f) => {
|
|
1250
|
+
const u = h[f + 1], d = h[f - 1];
|
|
1251
|
+
c !== A || d === A || (d === void 0 ? u !== void 0 && u !== A ? h[f + 1] = "(?:\\\\/|" + n + "\\\\/)?" + u : h[f] = n : u === void 0 ? h[f - 1] = d + "(?:\\\\/|" + n + ")?" : u !== A && (h[f - 1] = d + "(?:\\\\/|\\\\/" + n + "\\\\/)" + u, h[f + 1] = A));
|
|
1252
|
+
}), h.filter((c) => c !== A).join("/");
|
|
1253
|
+
}).join("|");
|
|
1254
|
+
const [o, a] = t.length > 1 ? ["(?:", ")"] : ["", ""];
|
|
1255
|
+
r = "^" + o + r + a + "$", this.negate && (r = "^(?!" + r + ").+$");
|
|
1256
|
+
try {
|
|
1257
|
+
this.regexp = new RegExp(r, [...i].join(""));
|
|
1258
|
+
} catch {
|
|
1259
|
+
this.regexp = !1;
|
|
1260
|
+
}
|
|
1261
|
+
return this.regexp;
|
|
1262
|
+
}
|
|
1263
|
+
slashSplit(t) {
|
|
1264
|
+
return this.preserveMultipleSlashes ? t.split("/") : this.isWindows && /^\\/\\/[^\\/]+/.test(t) ? ["", ...t.split(/\\/+/)] : t.split(/\\/+/);
|
|
1265
|
+
}
|
|
1266
|
+
match(t, e = this.partial) {
|
|
1267
|
+
if (this.debug("match", t, this.pattern), this.comment)
|
|
1268
|
+
return !1;
|
|
1269
|
+
if (this.empty)
|
|
1270
|
+
return t === "";
|
|
1271
|
+
if (t === "/" && e)
|
|
1272
|
+
return !0;
|
|
1273
|
+
const n = this.options;
|
|
1274
|
+
this.isWindows && (t = t.split("\\\\").join("/"));
|
|
1275
|
+
const i = this.slashSplit(t);
|
|
1276
|
+
this.debug(this.pattern, "split", i);
|
|
1277
|
+
const r = this.set;
|
|
1278
|
+
this.debug(this.pattern, "set", r);
|
|
1279
|
+
let o = i[i.length - 1];
|
|
1280
|
+
if (!o)
|
|
1281
|
+
for (let a = i.length - 2; !o && a >= 0; a--)
|
|
1282
|
+
o = i[a];
|
|
1283
|
+
for (let a = 0; a < r.length; a++) {
|
|
1284
|
+
const l = r[a];
|
|
1285
|
+
let h = i;
|
|
1286
|
+
if (n.matchBase && l.length === 1 && (h = [o]), this.matchOne(h, l, e))
|
|
1287
|
+
return n.flipNegate ? !0 : !this.negate;
|
|
1288
|
+
}
|
|
1289
|
+
return n.flipNegate ? !1 : this.negate;
|
|
1290
|
+
}
|
|
1291
|
+
static defaults(t) {
|
|
1292
|
+
return y.defaults(t).Minimatch;
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
y.AST = E;
|
|
1296
|
+
y.Minimatch = j;
|
|
1297
|
+
y.escape = xe;
|
|
1298
|
+
y.unescape = $;
|
|
1299
|
+
function Ye() {
|
|
349
1300
|
if (!("storage" in navigator) || !("getDirectory" in navigator.storage))
|
|
350
|
-
throw new
|
|
1301
|
+
throw new Ht();
|
|
1302
|
+
}
|
|
1303
|
+
async function Q(s, t, e) {
|
|
1304
|
+
return typeof navigator < "u" && navigator.locks?.request ? navigator.locks.request(\`opfs:\${s.replace(/\\/+/g, "/").toLowerCase()}\`, { mode: t }, e) : e();
|
|
351
1305
|
}
|
|
352
|
-
function
|
|
353
|
-
return Array.isArray(
|
|
1306
|
+
function O(s) {
|
|
1307
|
+
return Array.isArray(s) ? s : (s.startsWith("~/") ? s.slice(2) : s).split("/").filter(Boolean);
|
|
354
1308
|
}
|
|
355
|
-
function
|
|
356
|
-
return typeof
|
|
1309
|
+
function tt(s) {
|
|
1310
|
+
return typeof s == "string" ? s ?? "/" : \`/\${s.join("/")}\`;
|
|
357
1311
|
}
|
|
358
|
-
function
|
|
359
|
-
const t =
|
|
1312
|
+
function Z(s) {
|
|
1313
|
+
const t = O(s);
|
|
360
1314
|
return t[t.length - 1] || "";
|
|
361
1315
|
}
|
|
362
|
-
function
|
|
363
|
-
const t =
|
|
364
|
-
return t.pop(),
|
|
1316
|
+
function G(s) {
|
|
1317
|
+
const t = O(s);
|
|
1318
|
+
return t.pop(), tt(t);
|
|
1319
|
+
}
|
|
1320
|
+
function X(s) {
|
|
1321
|
+
return !s || s === "/" ? "/" : s.startsWith("~/") ? \`/\${s.slice(2)}\` : s.startsWith("/") ? s : \`/\${s}\`;
|
|
365
1322
|
}
|
|
366
|
-
function
|
|
367
|
-
return
|
|
1323
|
+
function Je(s, t = !1) {
|
|
1324
|
+
return s = s.replace(/\\/$/, ""), t && !s.includes("*") ? \`\${s}/**\` : s;
|
|
368
1325
|
}
|
|
369
|
-
function
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
1326
|
+
function q(s, t) {
|
|
1327
|
+
return y(s, t, {
|
|
1328
|
+
dot: !0,
|
|
1329
|
+
matchBase: !0
|
|
1330
|
+
});
|
|
1331
|
+
}
|
|
1332
|
+
function Ke(s) {
|
|
1333
|
+
const t = X(s), e = O(t), n = [];
|
|
1334
|
+
for (const i of e)
|
|
1335
|
+
if (!(i === "." || i === ""))
|
|
1336
|
+
if (i === "..") {
|
|
1337
|
+
if (n.length === 0)
|
|
375
1338
|
continue;
|
|
376
|
-
|
|
1339
|
+
n.pop();
|
|
377
1340
|
} else
|
|
378
|
-
|
|
379
|
-
return
|
|
1341
|
+
n.push(i);
|
|
1342
|
+
return tt(n);
|
|
380
1343
|
}
|
|
381
|
-
function
|
|
382
|
-
return typeof
|
|
1344
|
+
function Qe(s, t = "utf-8") {
|
|
1345
|
+
return typeof s == "string" ? jt(s, t) : s instanceof Uint8Array ? s : new Uint8Array(s);
|
|
383
1346
|
}
|
|
384
|
-
async function
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
} finally {
|
|
390
|
-
t.close();
|
|
391
|
-
}
|
|
1347
|
+
async function ts(s, t) {
|
|
1348
|
+
return Q(t, "shared", async () => {
|
|
1349
|
+
const n = await (await s.getFile()).arrayBuffer();
|
|
1350
|
+
return new Uint8Array(n);
|
|
1351
|
+
});
|
|
392
1352
|
}
|
|
393
|
-
async function
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
n =
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
1353
|
+
async function lt(s, t, e, n = {}, i) {
|
|
1354
|
+
const r = async () => {
|
|
1355
|
+
let o = null;
|
|
1356
|
+
const a = n.append || !1, l = !a && (n.truncate ?? !0);
|
|
1357
|
+
try {
|
|
1358
|
+
o = await s.createSyncAccessHandle();
|
|
1359
|
+
const h = Qe(t, e), c = a ? o.getSize() : 0;
|
|
1360
|
+
o.write(h, { at: c }), l && o.truncate(h.byteLength), o.flush();
|
|
1361
|
+
} catch (h) {
|
|
1362
|
+
console.error(h);
|
|
1363
|
+
const c = a ? "append" : "write";
|
|
1364
|
+
throw new g(\`Failed to \${c} file\`, \`\${c.toUpperCase()}_FAILED\`, void 0, h);
|
|
1365
|
+
} finally {
|
|
405
1366
|
try {
|
|
406
|
-
|
|
1367
|
+
o?.close();
|
|
407
1368
|
} catch {
|
|
408
1369
|
}
|
|
409
|
-
|
|
1370
|
+
}
|
|
1371
|
+
};
|
|
1372
|
+
return i ? Q(i, "exclusive", r) : r();
|
|
410
1373
|
}
|
|
411
|
-
async function
|
|
412
|
-
if (
|
|
413
|
-
throw new Error(\`File size \${
|
|
414
|
-
const
|
|
415
|
-
return Array.from(new Uint8Array(
|
|
1374
|
+
async function es(s, t = "SHA-1", e = 50 * 1024 * 1024) {
|
|
1375
|
+
if (s instanceof File && (s = await s.arrayBuffer()), s.byteLength > e)
|
|
1376
|
+
throw new Error(\`File size \${s.byteLength} bytes exceeds maximum allowed size \${e} bytes\`);
|
|
1377
|
+
const n = new Uint8Array(s), i = await crypto.subtle.digest(t, n);
|
|
1378
|
+
return Array.from(new Uint8Array(i)).map((o) => o.toString(16).padStart(2, "0")).join("");
|
|
416
1379
|
}
|
|
417
|
-
async function
|
|
418
|
-
const t = await
|
|
1380
|
+
async function ss(s) {
|
|
1381
|
+
const t = await s.arrayBuffer();
|
|
419
1382
|
return new Uint8Array(t);
|
|
420
1383
|
}
|
|
421
|
-
|
|
1384
|
+
async function ns(s, t, e = {}) {
|
|
1385
|
+
const n = Z(t);
|
|
1386
|
+
return Q(t, "exclusive", async () => {
|
|
1387
|
+
const i = e.recursive ?? !1, r = e.force ?? !1;
|
|
1388
|
+
try {
|
|
1389
|
+
await s.removeEntry(n, { recursive: i });
|
|
1390
|
+
} catch (o) {
|
|
1391
|
+
if (o.name === "NotFoundError") {
|
|
1392
|
+
if (!r)
|
|
1393
|
+
throw new g(\`No such file or directory: \${t}\`, "ENOENT", void 0, o);
|
|
1394
|
+
} else throw o.name === "InvalidModificationError" ? new g(\`Directory not empty: \${t}. Use recursive option to force removal.\`, "ENOTEMPTY", void 0, o) : o.name === "TypeMismatchError" && !i ? new g(\`Cannot remove directory without recursive option: \${t}\`, "EISDIR", void 0, o) : new g(\`Failed to remove entry: \${t}\`, "RM_FAILED", void 0, o);
|
|
1395
|
+
}
|
|
1396
|
+
});
|
|
1397
|
+
}
|
|
1398
|
+
class is {
|
|
422
1399
|
/** Root directory handle for the file system */
|
|
423
1400
|
root = null;
|
|
424
|
-
/** Map of watched paths
|
|
1401
|
+
/** Map of watched paths and options */
|
|
425
1402
|
watchers = /* @__PURE__ */ new Map();
|
|
426
|
-
/** Interval handle for polling watched paths */
|
|
427
|
-
watchTimer = null;
|
|
428
|
-
/** Flag to avoid concurrent scans */
|
|
429
|
-
scanning = !1;
|
|
430
1403
|
/** Promise to prevent concurrent mount operations */
|
|
431
1404
|
mountingPromise = null;
|
|
432
1405
|
/** BroadcastChannel instance for sending events */
|
|
433
1406
|
broadcastChannel = null;
|
|
434
1407
|
/** Configuration options */
|
|
435
1408
|
options = {
|
|
436
|
-
|
|
1409
|
+
root: "/",
|
|
1410
|
+
namespace: "",
|
|
437
1411
|
maxFileSize: 50 * 1024 * 1024,
|
|
438
1412
|
hashAlgorithm: null,
|
|
439
1413
|
broadcastChannel: "opfs-worker"
|
|
@@ -450,38 +1424,40 @@ class wt {
|
|
|
450
1424
|
async notifyChange(t) {
|
|
451
1425
|
if (!this.options.broadcastChannel)
|
|
452
1426
|
return;
|
|
453
|
-
|
|
454
|
-
if (this.
|
|
1427
|
+
const e = t.path;
|
|
1428
|
+
if (![...this.watchers.values()].some((r) => q(e, r.pattern) && r.include.some((o) => o && q(e, o)) && !r.exclude.some((o) => o && q(e, o))))
|
|
1429
|
+
return;
|
|
1430
|
+
let i;
|
|
1431
|
+
if (this.options.hashAlgorithm)
|
|
455
1432
|
try {
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
} catch (i) {
|
|
459
|
-
console.warn(\`Failed to calculate hash for \${t.path}:\`, i);
|
|
1433
|
+
i = (await this.stat(e)).hash;
|
|
1434
|
+
} catch {
|
|
460
1435
|
}
|
|
461
1436
|
try {
|
|
462
1437
|
this.broadcastChannel || (this.broadcastChannel = new BroadcastChannel(this.options.broadcastChannel));
|
|
463
|
-
const
|
|
464
|
-
|
|
1438
|
+
const r = {
|
|
1439
|
+
namespace: this.options.namespace,
|
|
465
1440
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
466
1441
|
...t,
|
|
467
|
-
...
|
|
1442
|
+
...i && { hash: i }
|
|
468
1443
|
};
|
|
469
|
-
this.broadcastChannel.postMessage(
|
|
470
|
-
} catch (
|
|
471
|
-
console.warn("Failed to send event via BroadcastChannel:",
|
|
1444
|
+
this.broadcastChannel.postMessage(r);
|
|
1445
|
+
} catch (r) {
|
|
1446
|
+
console.warn("Failed to send event via BroadcastChannel:", r);
|
|
472
1447
|
}
|
|
473
1448
|
}
|
|
474
1449
|
/**
|
|
475
1450
|
* Creates a new OPFSFileSystem instance
|
|
476
1451
|
*
|
|
477
1452
|
* @param options - Optional configuration options
|
|
1453
|
+
* @param options.root - Root path for the file system (default: '/')
|
|
478
1454
|
* @param options.watchInterval - Polling interval in milliseconds for file watching
|
|
479
1455
|
* @param options.hashAlgorithm - Hash algorithm for file hashing
|
|
480
1456
|
* @param options.maxFileSize - Maximum file size for hashing in bytes (default: 50MB)
|
|
481
1457
|
* @throws {OPFSError} If OPFS is not supported in the current browser
|
|
482
1458
|
*/
|
|
483
1459
|
constructor(t) {
|
|
484
|
-
|
|
1460
|
+
Ye(), t && this.setOptions(t);
|
|
485
1461
|
}
|
|
486
1462
|
/**
|
|
487
1463
|
* Initialize the file system within a given directory
|
|
@@ -504,14 +1480,13 @@ class wt {
|
|
|
504
1480
|
* await fs.mount('/my-app');
|
|
505
1481
|
* \`\`\`
|
|
506
1482
|
*/
|
|
507
|
-
async mount(t =
|
|
508
|
-
return this.mountingPromise && await this.mountingPromise, this.mountingPromise = new Promise(async (
|
|
509
|
-
this.root = null;
|
|
1483
|
+
async mount(t = this.options.root) {
|
|
1484
|
+
return this.mountingPromise && await this.mountingPromise, t = X(t), this.mountingPromise = new Promise(async (e, n) => {
|
|
510
1485
|
try {
|
|
511
|
-
const
|
|
512
|
-
t === "/" ? this.root =
|
|
513
|
-
} catch
|
|
514
|
-
|
|
1486
|
+
const i = await navigator.storage.getDirectory();
|
|
1487
|
+
t === "/" ? this.root = i : this.root = await this.getDirectoryHandle(t, !0, i), e(!0);
|
|
1488
|
+
} catch {
|
|
1489
|
+
n(new g("Failed to initialize OPFS", "INIT_FAILED"));
|
|
515
1490
|
} finally {
|
|
516
1491
|
this.mountingPromise = null;
|
|
517
1492
|
}
|
|
@@ -521,31 +1496,14 @@ class wt {
|
|
|
521
1496
|
* Update configuration options
|
|
522
1497
|
*
|
|
523
1498
|
* @param options - Configuration options to update
|
|
1499
|
+
* @param options.root - Root path for the file system
|
|
524
1500
|
* @param options.watchInterval - Polling interval in milliseconds for file watching
|
|
525
1501
|
* @param options.hashAlgorithm - Hash algorithm for file hashing
|
|
526
1502
|
* @param options.maxFileSize - Maximum file size for hashing in bytes
|
|
527
1503
|
* @param options.broadcastChannel - Custom name for the broadcast channel
|
|
528
1504
|
*/
|
|
529
|
-
setOptions(t) {
|
|
530
|
-
t.
|
|
531
|
-
}
|
|
532
|
-
/**
|
|
533
|
-
* Automatically mount the OPFS root if not already mounted
|
|
534
|
-
*
|
|
535
|
-
* This method is called internally when file operations are performed
|
|
536
|
-
* without explicitly mounting first.
|
|
537
|
-
*
|
|
538
|
-
* @returns Promise that resolves when auto-mount is complete
|
|
539
|
-
* @throws {OPFSError} If auto-mount fails
|
|
540
|
-
*/
|
|
541
|
-
async ensureMounted() {
|
|
542
|
-
if (!this.root) {
|
|
543
|
-
if (this.mountingPromise) {
|
|
544
|
-
await this.mountingPromise;
|
|
545
|
-
return;
|
|
546
|
-
}
|
|
547
|
-
throw new c("OPFS not mounted", "NOT_MOUNTED");
|
|
548
|
-
}
|
|
1505
|
+
async setOptions(t) {
|
|
1506
|
+
t.hashAlgorithm !== void 0 && (this.options.hashAlgorithm = t.hashAlgorithm), t.maxFileSize !== void 0 && (this.options.maxFileSize = t.maxFileSize), t.broadcastChannel !== void 0 && (this.broadcastChannel && this.options.broadcastChannel !== t.broadcastChannel && (this.broadcastChannel.close(), this.broadcastChannel = null), this.options.broadcastChannel = t.broadcastChannel), t.namespace && (this.options.namespace = t.namespace), t.root !== void 0 && (this.options.root = t.root, this.options.namespace || (this.options.namespace = \`opfs-worker:\${this.options.root}\`), await this.mount(this.options.root));
|
|
549
1507
|
}
|
|
550
1508
|
/**
|
|
551
1509
|
* Get a directory handle from a path
|
|
@@ -565,14 +1523,12 @@ class wt {
|
|
|
565
1523
|
* const docsDir2 = await fs.getDirectoryHandle(['users', 'john', 'documents'], true);
|
|
566
1524
|
* \`\`\`
|
|
567
1525
|
*/
|
|
568
|
-
async getDirectoryHandle(t,
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
a = await a.getDirectoryHandle(s, { create: r });
|
|
575
|
-
return a;
|
|
1526
|
+
async getDirectoryHandle(t, e = !1, n = this.root) {
|
|
1527
|
+
const i = Array.isArray(t) ? t : O(t);
|
|
1528
|
+
let r = n;
|
|
1529
|
+
for (const o of i)
|
|
1530
|
+
r = await r.getDirectoryHandle(o, { create: e });
|
|
1531
|
+
return r;
|
|
576
1532
|
}
|
|
577
1533
|
/**
|
|
578
1534
|
* Get a file handle from a path
|
|
@@ -593,14 +1549,12 @@ class wt {
|
|
|
593
1549
|
* const fileHandle2 = await fs.getFileHandle(['config', 'settings.json'], true);
|
|
594
1550
|
* \`\`\`
|
|
595
1551
|
*/
|
|
596
|
-
async getFileHandle(t,
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
const a = n.pop();
|
|
603
|
-
return (await this.getDirectoryHandle(n, r, i)).getFileHandle(a, { create: r });
|
|
1552
|
+
async getFileHandle(t, e = !1, n = this.root) {
|
|
1553
|
+
const i = O(t);
|
|
1554
|
+
if (i.length === 0)
|
|
1555
|
+
throw new Wt("Path must not be empty", Array.isArray(t) ? t.join("/") : t);
|
|
1556
|
+
const r = i.pop();
|
|
1557
|
+
return (await this.getDirectoryHandle(i, e, n)).getFileHandle(r, { create: e });
|
|
604
1558
|
}
|
|
605
1559
|
/**
|
|
606
1560
|
* Get a complete index of all files and directories in the file system
|
|
@@ -622,15 +1576,15 @@ class wt {
|
|
|
622
1576
|
* \`\`\`
|
|
623
1577
|
*/
|
|
624
1578
|
async index() {
|
|
625
|
-
const t = /* @__PURE__ */ new Map(),
|
|
626
|
-
const
|
|
627
|
-
for (const
|
|
628
|
-
const
|
|
1579
|
+
const t = /* @__PURE__ */ new Map(), e = async (n) => {
|
|
1580
|
+
const i = await this.readDir(n);
|
|
1581
|
+
for (const r of i) {
|
|
1582
|
+
const o = \`\${n === "/" ? "" : n}/\${r.name}\`;
|
|
629
1583
|
try {
|
|
630
|
-
const
|
|
631
|
-
t.set(
|
|
632
|
-
} catch (
|
|
633
|
-
console.warn(\`Skipping broken entry: \${
|
|
1584
|
+
const a = await this.stat(o);
|
|
1585
|
+
t.set(o, a), a.isDirectory && await e(o);
|
|
1586
|
+
} catch (a) {
|
|
1587
|
+
console.warn(\`Skipping broken entry: \${o}\`, a);
|
|
634
1588
|
}
|
|
635
1589
|
}
|
|
636
1590
|
};
|
|
@@ -641,15 +1595,15 @@ class wt {
|
|
|
641
1595
|
ctime: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
642
1596
|
isFile: !1,
|
|
643
1597
|
isDirectory: !0
|
|
644
|
-
}), await
|
|
1598
|
+
}), await e("/"), t;
|
|
645
1599
|
}
|
|
646
|
-
async readFile(t,
|
|
647
|
-
await this.
|
|
1600
|
+
async readFile(t, e = "utf-8") {
|
|
1601
|
+
await this.mount();
|
|
648
1602
|
try {
|
|
649
|
-
const
|
|
650
|
-
return
|
|
651
|
-
} catch (
|
|
652
|
-
throw
|
|
1603
|
+
const n = await this.getFileHandle(t, !1), i = await ts(n, t);
|
|
1604
|
+
return e === "binary" ? i : Ut(i, e);
|
|
1605
|
+
} catch (n) {
|
|
1606
|
+
throw new _(t, n);
|
|
653
1607
|
}
|
|
654
1608
|
}
|
|
655
1609
|
/**
|
|
@@ -677,10 +1631,10 @@ class wt {
|
|
|
677
1631
|
* await fs.writeFile('/data/utf16.txt', 'Hello World', 'utf-16le');
|
|
678
1632
|
* \`\`\`
|
|
679
1633
|
*/
|
|
680
|
-
async writeFile(t,
|
|
681
|
-
await this.
|
|
682
|
-
const
|
|
683
|
-
await
|
|
1634
|
+
async writeFile(t, e, n) {
|
|
1635
|
+
await this.mount();
|
|
1636
|
+
const i = await this.exists(t), r = await this.getFileHandle(t, !0);
|
|
1637
|
+
await lt(r, e, n, {}, t), i ? await this.notifyChange({ path: t, type: "changed", isDirectory: !1 }) : await this.notifyChange({ path: t, type: "added", isDirectory: !1 });
|
|
684
1638
|
}
|
|
685
1639
|
/**
|
|
686
1640
|
* Append data to a file
|
|
@@ -704,10 +1658,10 @@ class wt {
|
|
|
704
1658
|
* await fs.appendFile('/data/binary.dat', additionalData);
|
|
705
1659
|
* \`\`\`
|
|
706
1660
|
*/
|
|
707
|
-
async appendFile(t,
|
|
708
|
-
await this.
|
|
709
|
-
const
|
|
710
|
-
await
|
|
1661
|
+
async appendFile(t, e, n) {
|
|
1662
|
+
await this.mount();
|
|
1663
|
+
const i = await this.getFileHandle(t, !0);
|
|
1664
|
+
await lt(i, e, n, { append: !0 }, t), await this.notifyChange({ path: t, type: "changed", isDirectory: !1 });
|
|
711
1665
|
}
|
|
712
1666
|
/**
|
|
713
1667
|
* Create a directory
|
|
@@ -730,20 +1684,21 @@ class wt {
|
|
|
730
1684
|
* await fs.mkdir('/users/john/documents/projects', { recursive: true });
|
|
731
1685
|
* \`\`\`
|
|
732
1686
|
*/
|
|
733
|
-
async mkdir(t,
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
let
|
|
738
|
-
|
|
739
|
-
const o = n[s];
|
|
1687
|
+
async mkdir(t, e) {
|
|
1688
|
+
await this.mount();
|
|
1689
|
+
const n = e?.recursive ?? !1, i = O(t);
|
|
1690
|
+
let r = this.root;
|
|
1691
|
+
for (let o = 0; o < i.length; o++) {
|
|
1692
|
+
const a = i[o];
|
|
740
1693
|
try {
|
|
741
|
-
|
|
1694
|
+
r = await r.getDirectoryHandle(a, { create: n || o === i.length - 1 });
|
|
742
1695
|
} catch (l) {
|
|
743
|
-
throw l.name === "NotFoundError" ? new
|
|
744
|
-
\`Parent directory does not exist: \${
|
|
745
|
-
"ENOENT"
|
|
746
|
-
|
|
1696
|
+
throw l.name === "NotFoundError" ? new g(
|
|
1697
|
+
\`Parent directory does not exist: \${tt(i.slice(0, o + 1))}\`,
|
|
1698
|
+
"ENOENT",
|
|
1699
|
+
void 0,
|
|
1700
|
+
l
|
|
1701
|
+
) : l.name === "TypeMismatchError" ? new g(\`Path segment is not a directory: \${a}\`, "ENOTDIR", void 0, l) : new g("Failed to create directory", "MKDIR_FAILED", void 0, l);
|
|
747
1702
|
}
|
|
748
1703
|
}
|
|
749
1704
|
await this.notifyChange({ path: t, type: "added", isDirectory: !0 });
|
|
@@ -771,7 +1726,7 @@ class wt {
|
|
|
771
1726
|
* \`\`\`
|
|
772
1727
|
*/
|
|
773
1728
|
async stat(t) {
|
|
774
|
-
if (await this.
|
|
1729
|
+
if (await this.mount(), t === "/")
|
|
775
1730
|
return {
|
|
776
1731
|
kind: "directory",
|
|
777
1732
|
size: 0,
|
|
@@ -780,30 +1735,30 @@ class wt {
|
|
|
780
1735
|
isFile: !1,
|
|
781
1736
|
isDirectory: !0
|
|
782
1737
|
};
|
|
783
|
-
const
|
|
1738
|
+
const e = Z(t), n = await this.getDirectoryHandle(G(t), !1), i = this.options.hashAlgorithm !== null;
|
|
784
1739
|
try {
|
|
785
|
-
const
|
|
1740
|
+
const o = await (await n.getFileHandle(e, { create: !1 })).getFile(), a = {
|
|
786
1741
|
kind: "file",
|
|
787
|
-
size:
|
|
788
|
-
mtime: new Date(
|
|
789
|
-
ctime: new Date(
|
|
1742
|
+
size: o.size,
|
|
1743
|
+
mtime: new Date(o.lastModified).toISOString(),
|
|
1744
|
+
ctime: new Date(o.lastModified).toISOString(),
|
|
790
1745
|
isFile: !0,
|
|
791
1746
|
isDirectory: !1
|
|
792
1747
|
};
|
|
793
|
-
if (
|
|
1748
|
+
if (i && this.options.hashAlgorithm)
|
|
794
1749
|
try {
|
|
795
|
-
const l = await
|
|
796
|
-
|
|
1750
|
+
const l = await es(o, this.options.hashAlgorithm, this.options.maxFileSize);
|
|
1751
|
+
a.hash = l;
|
|
797
1752
|
} catch (l) {
|
|
798
1753
|
console.warn(\`Failed to calculate hash for \${t}:\`, l);
|
|
799
1754
|
}
|
|
800
|
-
return
|
|
801
|
-
} catch (
|
|
802
|
-
if (
|
|
803
|
-
throw new
|
|
1755
|
+
return a;
|
|
1756
|
+
} catch (r) {
|
|
1757
|
+
if (r.name !== "TypeMismatchError" && r.name !== "NotFoundError")
|
|
1758
|
+
throw new g("Failed to stat (file)", "STAT_FAILED", void 0, r);
|
|
804
1759
|
}
|
|
805
1760
|
try {
|
|
806
|
-
return await
|
|
1761
|
+
return await n.getDirectoryHandle(e, { create: !1 }), {
|
|
807
1762
|
kind: "directory",
|
|
808
1763
|
size: 0,
|
|
809
1764
|
mtime: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
@@ -811,8 +1766,8 @@ class wt {
|
|
|
811
1766
|
isFile: !1,
|
|
812
1767
|
isDirectory: !0
|
|
813
1768
|
};
|
|
814
|
-
} catch (
|
|
815
|
-
throw
|
|
1769
|
+
} catch (r) {
|
|
1770
|
+
throw r.name === "NotFoundError" ? new g(\`No such file or directory: \${t}\`, "ENOENT", void 0, r) : new g("Failed to stat (directory)", "STAT_FAILED", void 0, r);
|
|
816
1771
|
}
|
|
817
1772
|
}
|
|
818
1773
|
/**
|
|
@@ -834,18 +1789,18 @@ class wt {
|
|
|
834
1789
|
* \`\`\`
|
|
835
1790
|
*/
|
|
836
1791
|
async readDir(t) {
|
|
837
|
-
await this.
|
|
838
|
-
const
|
|
839
|
-
for await (const [
|
|
840
|
-
const
|
|
841
|
-
|
|
842
|
-
name:
|
|
843
|
-
kind:
|
|
844
|
-
isFile:
|
|
845
|
-
isDirectory: !
|
|
1792
|
+
await this.mount();
|
|
1793
|
+
const e = await this.getDirectoryHandle(t, !1), n = [];
|
|
1794
|
+
for await (const [i, r] of e.entries()) {
|
|
1795
|
+
const o = r.kind === "file";
|
|
1796
|
+
n.push({
|
|
1797
|
+
name: i,
|
|
1798
|
+
kind: r.kind,
|
|
1799
|
+
isFile: o,
|
|
1800
|
+
isDirectory: !o
|
|
846
1801
|
});
|
|
847
1802
|
}
|
|
848
|
-
return
|
|
1803
|
+
return n;
|
|
849
1804
|
}
|
|
850
1805
|
/**
|
|
851
1806
|
* Check if a file or directory exists
|
|
@@ -862,30 +1817,30 @@ class wt {
|
|
|
862
1817
|
* \`\`\`
|
|
863
1818
|
*/
|
|
864
1819
|
async exists(t) {
|
|
865
|
-
if (await this.
|
|
1820
|
+
if (await this.mount(), t === "/")
|
|
866
1821
|
return !0;
|
|
867
|
-
const
|
|
868
|
-
let
|
|
1822
|
+
const e = Z(t);
|
|
1823
|
+
let n = null;
|
|
869
1824
|
try {
|
|
870
|
-
|
|
871
|
-
} catch (
|
|
872
|
-
throw (
|
|
1825
|
+
n = await this.getDirectoryHandle(G(t), !1);
|
|
1826
|
+
} catch (i) {
|
|
1827
|
+
throw (i.name === "NotFoundError" || i.name === "TypeMismatchError") && (n = null), i;
|
|
873
1828
|
}
|
|
874
|
-
if (!
|
|
1829
|
+
if (!n || !e)
|
|
875
1830
|
return !1;
|
|
876
1831
|
try {
|
|
877
|
-
return await
|
|
878
|
-
} catch (
|
|
879
|
-
if (
|
|
880
|
-
throw
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
1832
|
+
return await n.getFileHandle(e, { create: !1 }), !0;
|
|
1833
|
+
} catch (i) {
|
|
1834
|
+
if (i.name !== "NotFoundError" && i.name !== "TypeMismatchError")
|
|
1835
|
+
throw i;
|
|
1836
|
+
try {
|
|
1837
|
+
return await n.getDirectoryHandle(e, { create: !1 }), !0;
|
|
1838
|
+
} catch (r) {
|
|
1839
|
+
if (r.name !== "NotFoundError" && r.name !== "TypeMismatchError")
|
|
1840
|
+
throw r;
|
|
1841
|
+
return !1;
|
|
1842
|
+
}
|
|
887
1843
|
}
|
|
888
|
-
return !1;
|
|
889
1844
|
}
|
|
890
1845
|
/**
|
|
891
1846
|
* Clear all contents of a directory without removing the directory itself
|
|
@@ -907,16 +1862,16 @@ class wt {
|
|
|
907
1862
|
* \`\`\`
|
|
908
1863
|
*/
|
|
909
1864
|
async clear(t = "/") {
|
|
910
|
-
await this.
|
|
1865
|
+
await this.mount();
|
|
911
1866
|
try {
|
|
912
|
-
const
|
|
913
|
-
for (const
|
|
914
|
-
const
|
|
915
|
-
await this.remove(
|
|
1867
|
+
const e = await this.readDir(t);
|
|
1868
|
+
for (const n of e) {
|
|
1869
|
+
const i = \`\${t === "/" ? "" : t}/\${n.name}\`;
|
|
1870
|
+
await this.remove(i, { recursive: !0 });
|
|
916
1871
|
}
|
|
917
1872
|
await this.notifyChange({ path: t, type: "changed", isDirectory: !0 });
|
|
918
|
-
} catch (
|
|
919
|
-
throw
|
|
1873
|
+
} catch (e) {
|
|
1874
|
+
throw e instanceof g ? e : new g(\`Failed to clear directory: \${t}\`, "CLEAR_FAILED", void 0, e);
|
|
920
1875
|
}
|
|
921
1876
|
}
|
|
922
1877
|
/**
|
|
@@ -943,24 +1898,11 @@ class wt {
|
|
|
943
1898
|
* await fs.rm('/maybe/exists', { force: true });
|
|
944
1899
|
* \`\`\`
|
|
945
1900
|
*/
|
|
946
|
-
async remove(t,
|
|
947
|
-
await this.
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
const a = O(t);
|
|
952
|
-
if (!a)
|
|
953
|
-
throw new N("Invalid path", t);
|
|
954
|
-
const s = await this.getDirectoryHandle(P(t), !1);
|
|
955
|
-
try {
|
|
956
|
-
await s.removeEntry(a, { recursive: i });
|
|
957
|
-
} catch (o) {
|
|
958
|
-
if (o.name === "NotFoundError") {
|
|
959
|
-
if (!n)
|
|
960
|
-
throw new c(\`No such file or directory: \${t}\`, "ENOENT");
|
|
961
|
-
} else throw o.name === "InvalidModificationError" ? new c(\`Directory not empty: \${t}. Use recursive option to force removal.\`, "ENOTEMPTY") : o.name === "TypeMismatchError" && !i ? new c(\`Cannot remove directory without recursive option: \${t}\`, "EISDIR") : new c(\`Failed to remove path: \${t}\`, "RM_FAILED");
|
|
962
|
-
}
|
|
963
|
-
await this.notifyChange({ path: t, type: "removed", isDirectory: !1 });
|
|
1901
|
+
async remove(t, e) {
|
|
1902
|
+
if (await this.mount(), t === "/")
|
|
1903
|
+
throw new g("Cannot remove root directory", "EROOT");
|
|
1904
|
+
const n = await this.getDirectoryHandle(G(t), !1);
|
|
1905
|
+
await ns(n, t, e), await this.notifyChange({ path: t, type: "removed", isDirectory: !1 });
|
|
964
1906
|
}
|
|
965
1907
|
/**
|
|
966
1908
|
* Resolve a path to an absolute path
|
|
@@ -981,14 +1923,14 @@ class wt {
|
|
|
981
1923
|
* \`\`\`
|
|
982
1924
|
*/
|
|
983
1925
|
async realpath(t) {
|
|
984
|
-
await this.
|
|
1926
|
+
await this.mount();
|
|
985
1927
|
try {
|
|
986
|
-
const
|
|
987
|
-
if (!await this.exists(
|
|
988
|
-
throw new
|
|
989
|
-
return
|
|
990
|
-
} catch (
|
|
991
|
-
throw
|
|
1928
|
+
const e = Ke(t);
|
|
1929
|
+
if (!await this.exists(e))
|
|
1930
|
+
throw new _(e);
|
|
1931
|
+
return e;
|
|
1932
|
+
} catch (e) {
|
|
1933
|
+
throw e instanceof g ? e : new g(\`Failed to resolve path: \${t}\`, "REALPATH_FAILED", void 0, e);
|
|
992
1934
|
}
|
|
993
1935
|
}
|
|
994
1936
|
/**
|
|
@@ -1007,14 +1949,14 @@ class wt {
|
|
|
1007
1949
|
* await fs.rename('/old/path/file.txt', '/new/path/renamed.txt');
|
|
1008
1950
|
* \`\`\`
|
|
1009
1951
|
*/
|
|
1010
|
-
async rename(t,
|
|
1011
|
-
await this.
|
|
1952
|
+
async rename(t, e) {
|
|
1953
|
+
await this.mount();
|
|
1012
1954
|
try {
|
|
1013
1955
|
if (!await this.exists(t))
|
|
1014
|
-
throw new
|
|
1015
|
-
await this.copy(t,
|
|
1016
|
-
} catch (
|
|
1017
|
-
throw
|
|
1956
|
+
throw new _(t);
|
|
1957
|
+
await this.copy(t, e, { recursive: !0 }), await this.remove(t, { recursive: !0 }), await this.notifyChange({ path: t, type: "removed", isDirectory: !1 }), await this.notifyChange({ path: e, type: "added", isDirectory: !1 });
|
|
1958
|
+
} catch (n) {
|
|
1959
|
+
throw n instanceof g ? n : new g(\`Failed to rename from \${t} to \${e}\`, "RENAME_FAILED", void 0, n);
|
|
1018
1960
|
}
|
|
1019
1961
|
}
|
|
1020
1962
|
/**
|
|
@@ -1042,48 +1984,71 @@ class wt {
|
|
|
1042
1984
|
* await fs.copy('/source', '/dest', { recursive: true, force: false });
|
|
1043
1985
|
* \`\`\`
|
|
1044
1986
|
*/
|
|
1045
|
-
async copy(t,
|
|
1046
|
-
await this.
|
|
1987
|
+
async copy(t, e, n) {
|
|
1988
|
+
await this.mount();
|
|
1047
1989
|
try {
|
|
1048
|
-
const
|
|
1990
|
+
const i = n?.recursive ?? !1, r = n?.force ?? !0;
|
|
1049
1991
|
if (!await this.exists(t))
|
|
1050
|
-
throw new
|
|
1051
|
-
if (await this.exists(
|
|
1052
|
-
throw new
|
|
1992
|
+
throw new g(\`Source does not exist: \${t}\`, "ENOENT", void 0);
|
|
1993
|
+
if (await this.exists(e) && !r)
|
|
1994
|
+
throw new g(\`Destination already exists: \${e}\`, "EEXIST", void 0);
|
|
1053
1995
|
if ((await this.stat(t)).isFile) {
|
|
1054
1996
|
const h = await this.readFile(t, "binary");
|
|
1055
|
-
await this.writeFile(
|
|
1997
|
+
await this.writeFile(e, h);
|
|
1056
1998
|
} else {
|
|
1057
|
-
if (!
|
|
1058
|
-
throw new
|
|
1059
|
-
await this.mkdir(
|
|
1999
|
+
if (!i)
|
|
2000
|
+
throw new g(\`Cannot copy directory without recursive option: \${t}\`, "EISDIR", void 0);
|
|
2001
|
+
await this.mkdir(e, { recursive: !0 });
|
|
1060
2002
|
const h = await this.readDir(t);
|
|
1061
|
-
for (const
|
|
1062
|
-
const
|
|
1063
|
-
await this.copy(
|
|
2003
|
+
for (const c of h) {
|
|
2004
|
+
const f = \`\${t}/\${c.name}\`, u = \`\${e}/\${c.name}\`;
|
|
2005
|
+
await this.copy(f, u, { recursive: !0, force: r });
|
|
1064
2006
|
}
|
|
1065
2007
|
}
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
throw n instanceof c ? n : new c(\`Failed to copy from \${t} to \${r}\`, "CP_FAILED");
|
|
2008
|
+
} catch (i) {
|
|
2009
|
+
throw i instanceof g ? i : new g(\`Failed to copy from \${t} to \${e}\`, "CP_FAILED", void 0, i);
|
|
1069
2010
|
}
|
|
1070
2011
|
}
|
|
1071
2012
|
/**
|
|
1072
2013
|
* Start watching a file or directory for changes
|
|
2014
|
+
*
|
|
2015
|
+
* @param path - The path to watch (minimatch syntax allowed)
|
|
2016
|
+
* @param options - Watch options
|
|
2017
|
+
* @param options.recursive - Whether to watch recursively (default: true)
|
|
2018
|
+
* @param options.exclude - Glob pattern(s) to exclude (minimatch).
|
|
2019
|
+
* @returns Promise that resolves when watching starts
|
|
2020
|
+
*
|
|
2021
|
+
* @example
|
|
2022
|
+
* \`\`\`typescript
|
|
2023
|
+
* // Watch entire directory tree recursively (default)
|
|
2024
|
+
* await fs.watch('/data');
|
|
2025
|
+
*
|
|
2026
|
+
* // Watch only immediate children (shallow)
|
|
2027
|
+
* await fs.watch('/data', { recursive: false });
|
|
2028
|
+
*
|
|
2029
|
+
* // Watch a single file
|
|
2030
|
+
* await fs.watch('/config.json', { recursive: false });
|
|
2031
|
+
*
|
|
2032
|
+
* // Watch all json files but not in dist directory
|
|
2033
|
+
* await fs.watch('/**\\/*.json', { recursive: false, exclude: ['dist/**'] });
|
|
2034
|
+
*
|
|
2035
|
+
* \`\`\`
|
|
1073
2036
|
*/
|
|
1074
|
-
async watch(t) {
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
2037
|
+
async watch(t, e) {
|
|
2038
|
+
if (!this.options.broadcastChannel)
|
|
2039
|
+
throw new g("This instance is not configured to send events. Please specify options.broadcastChannel to enable watching.", "ENOENT");
|
|
2040
|
+
const n = {
|
|
2041
|
+
pattern: Je(t, e?.recursive ?? !0),
|
|
2042
|
+
include: Array.isArray(e?.include) ? e.include : [e?.include ?? "**"],
|
|
2043
|
+
exclude: Array.isArray(e?.exclude) ? e.exclude : [e?.exclude ?? ""]
|
|
2044
|
+
};
|
|
2045
|
+
this.watchers.set(t, n);
|
|
1080
2046
|
}
|
|
1081
2047
|
/**
|
|
1082
2048
|
* Stop watching a previously watched path
|
|
1083
2049
|
*/
|
|
1084
2050
|
unwatch(t) {
|
|
1085
|
-
|
|
1086
|
-
this.watchers.delete(r), this.watchers.size === 0 && this.watchTimer && (clearInterval(this.watchTimer), this.watchTimer = null);
|
|
2051
|
+
this.watchers.delete(t);
|
|
1087
2052
|
}
|
|
1088
2053
|
/**
|
|
1089
2054
|
* Dispose of resources and clean up the file system instance
|
|
@@ -1092,49 +2057,7 @@ class wt {
|
|
|
1092
2057
|
* to properly clean up resources like the broadcast channel and watch timers.
|
|
1093
2058
|
*/
|
|
1094
2059
|
dispose() {
|
|
1095
|
-
this.broadcastChannel && (this.broadcastChannel.close(), this.broadcastChannel = null), this.
|
|
1096
|
-
}
|
|
1097
|
-
async buildSnapshot(t) {
|
|
1098
|
-
const r = /* @__PURE__ */ new Map(), i = async (n) => {
|
|
1099
|
-
const a = await this.stat(n);
|
|
1100
|
-
if (r.set(n, a), a.isDirectory) {
|
|
1101
|
-
const s = await this.readDir(n);
|
|
1102
|
-
for (const o of s) {
|
|
1103
|
-
const l = \`\${n === "/" ? "" : n}/\${o.name}\`;
|
|
1104
|
-
await i(l);
|
|
1105
|
-
}
|
|
1106
|
-
}
|
|
1107
|
-
};
|
|
1108
|
-
return await i(t), r;
|
|
1109
|
-
}
|
|
1110
|
-
async scanWatches() {
|
|
1111
|
-
if (!this.scanning) {
|
|
1112
|
-
this.scanning = !0;
|
|
1113
|
-
try {
|
|
1114
|
-
await Promise.all(
|
|
1115
|
-
[...this.watchers.entries()].map(async ([t, r]) => {
|
|
1116
|
-
let i;
|
|
1117
|
-
try {
|
|
1118
|
-
i = await this.buildSnapshot(t);
|
|
1119
|
-
} catch {
|
|
1120
|
-
i = /* @__PURE__ */ new Map();
|
|
1121
|
-
}
|
|
1122
|
-
for (const [n, a] of i) {
|
|
1123
|
-
const s = r.get(n);
|
|
1124
|
-
s ? (s.mtime !== a.mtime || s.size !== a.size) && await this.notifyChange({ path: n, type: "changed", isDirectory: a.isDirectory }) : await this.notifyChange({ path: n, type: "added", isDirectory: a.isDirectory });
|
|
1125
|
-
}
|
|
1126
|
-
for (const n of r.keys())
|
|
1127
|
-
if (!i.has(n)) {
|
|
1128
|
-
const a = r.get(n);
|
|
1129
|
-
await this.notifyChange({ path: n, type: "removed", isDirectory: a?.isDirectory ?? !1 });
|
|
1130
|
-
}
|
|
1131
|
-
this.watchers.set(t, i);
|
|
1132
|
-
})
|
|
1133
|
-
);
|
|
1134
|
-
} finally {
|
|
1135
|
-
this.scanning = !1;
|
|
1136
|
-
}
|
|
1137
|
-
}
|
|
2060
|
+
this.broadcastChannel && (this.broadcastChannel.close(), this.broadcastChannel = null), this.watchers.clear();
|
|
1138
2061
|
}
|
|
1139
2062
|
/**
|
|
1140
2063
|
* Synchronize the file system with external data
|
|
@@ -1164,74 +2087,79 @@ class wt {
|
|
|
1164
2087
|
* await fs.sync(entries, { cleanBefore: true });
|
|
1165
2088
|
* \`\`\`
|
|
1166
2089
|
*/
|
|
1167
|
-
async sync(t,
|
|
1168
|
-
await this.
|
|
2090
|
+
async sync(t, e) {
|
|
2091
|
+
await this.mount();
|
|
1169
2092
|
try {
|
|
1170
|
-
(
|
|
1171
|
-
for (const [
|
|
1172
|
-
const
|
|
1173
|
-
let
|
|
1174
|
-
|
|
2093
|
+
(e?.cleanBefore ?? !1) && await this.clear("/");
|
|
2094
|
+
for (const [i, r] of t) {
|
|
2095
|
+
const o = X(i);
|
|
2096
|
+
let a;
|
|
2097
|
+
r instanceof Blob ? a = await ss(r) : a = r, await this.writeFile(o, a);
|
|
1175
2098
|
}
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
throw i instanceof c ? i : new c("Failed to sync file system", "SYNC_FAILED");
|
|
2099
|
+
} catch (n) {
|
|
2100
|
+
throw n instanceof g ? n : new g("Failed to sync file system", "SYNC_FAILED", void 0, n);
|
|
1179
2101
|
}
|
|
1180
2102
|
}
|
|
1181
2103
|
}
|
|
1182
|
-
typeof
|
|
1183
|
-
//# sourceMappingURL=worker-
|
|
1184
|
-
`,
|
|
1185
|
-
function o(
|
|
1186
|
-
let
|
|
2104
|
+
typeof globalThis < "u" && globalThis.constructor.name === "DedicatedWorkerGlobalScope" && Y(new is());
|
|
2105
|
+
//# sourceMappingURL=worker-3SMz_DAt.js.map
|
|
2106
|
+
`, s = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", r], { type: "text/javascript;charset=utf-8" });
|
|
2107
|
+
function o(n) {
|
|
2108
|
+
let t;
|
|
1187
2109
|
try {
|
|
1188
|
-
if (
|
|
1189
|
-
const e = new Worker(
|
|
2110
|
+
if (t = s && (self.URL || self.webkitURL).createObjectURL(s), !t) throw "";
|
|
2111
|
+
const e = new Worker(t, {
|
|
1190
2112
|
type: "module",
|
|
1191
|
-
name:
|
|
2113
|
+
name: n?.name
|
|
1192
2114
|
});
|
|
1193
2115
|
return e.addEventListener("error", () => {
|
|
1194
|
-
(self.URL || self.webkitURL).revokeObjectURL(
|
|
2116
|
+
(self.URL || self.webkitURL).revokeObjectURL(t);
|
|
1195
2117
|
}), e;
|
|
1196
2118
|
} catch {
|
|
1197
2119
|
return new Worker(
|
|
1198
|
-
"data:text/javascript;charset=utf-8," + encodeURIComponent(
|
|
2120
|
+
"data:text/javascript;charset=utf-8," + encodeURIComponent(r),
|
|
1199
2121
|
{
|
|
1200
2122
|
type: "module",
|
|
1201
|
-
name:
|
|
2123
|
+
name: n?.name
|
|
1202
2124
|
}
|
|
1203
2125
|
);
|
|
1204
2126
|
}
|
|
1205
2127
|
}
|
|
1206
|
-
function
|
|
1207
|
-
const
|
|
1208
|
-
return
|
|
2128
|
+
async function h(n) {
|
|
2129
|
+
const t = i(new o());
|
|
2130
|
+
return n && (n.broadcastChannel && n.broadcastChannel instanceof BroadcastChannel && (n.broadcastChannel = n.broadcastChannel.name), await t.setOptions(n)), t;
|
|
1209
2131
|
}
|
|
1210
2132
|
export {
|
|
1211
|
-
|
|
2133
|
+
p as DirectoryNotFoundError,
|
|
1212
2134
|
f as FileNotFoundError,
|
|
1213
|
-
|
|
2135
|
+
d as OPFSError,
|
|
1214
2136
|
u as OPFSNotMountedError,
|
|
1215
|
-
|
|
2137
|
+
g as OPFSNotSupportedError,
|
|
1216
2138
|
m as PathError,
|
|
1217
2139
|
w as PermissionError,
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
P as
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
2140
|
+
y as StorageError,
|
|
2141
|
+
b as TimeoutError,
|
|
2142
|
+
v as basename,
|
|
2143
|
+
S as buffersEqual,
|
|
2144
|
+
x as calculateFileHash,
|
|
2145
|
+
E as checkOPFSSupport,
|
|
2146
|
+
P as convertBlobToUint8Array,
|
|
2147
|
+
A as createBuffer,
|
|
2148
|
+
h as createWorker,
|
|
2149
|
+
F as decodeBuffer,
|
|
2150
|
+
O as dirname,
|
|
1228
2151
|
C as encodeString,
|
|
1229
2152
|
T as extname,
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
_ as
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
2153
|
+
R as isPathExcluded,
|
|
2154
|
+
$ as joinPath,
|
|
2155
|
+
_ as matchMinimatch,
|
|
2156
|
+
D as normalizeMinimatch,
|
|
2157
|
+
I as normalizePath,
|
|
2158
|
+
M as readFileData,
|
|
2159
|
+
j as removeEntry,
|
|
2160
|
+
N as resolvePath,
|
|
2161
|
+
k as splitPath,
|
|
2162
|
+
L as withLock,
|
|
2163
|
+
U as writeFileData
|
|
1236
2164
|
};
|
|
1237
2165
|
//# sourceMappingURL=index.js.map
|