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