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