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