opfs-worker 0.5.0 → 1.0.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/dist/assets/worker-XHCzp1qX.js.map +1 -0
- package/dist/{helpers-Bm2TWyPQ.js → helpers-CTCvNFs1.js} +215 -150
- package/dist/{helpers-Bm2TWyPQ.js.map → helpers-CTCvNFs1.js.map} +1 -1
- package/dist/helpers-Cvjm0f_r.cjs +4 -0
- package/dist/{helpers-BoLdVbGk.cjs.map → helpers-Cvjm0f_r.cjs.map} +1 -1
- package/dist/index.cjs +302 -229
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +330 -255
- package/dist/index.js.map +1 -1
- package/dist/raw.cjs +1 -1
- package/dist/raw.cjs.map +1 -1
- package/dist/raw.js +110 -100
- 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 +2 -1
- package/dist/utils/encoder.d.ts.map +1 -1
- package/dist/utils/helpers.d.ts +22 -3
- package/dist/utils/helpers.d.ts.map +1 -1
- package/dist/worker.d.ts +14 -7
- package/dist/worker.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/assets/worker-3SMz_DAt.js.map +0 -1
- package/dist/helpers-BoLdVbGk.cjs +0 -4
package/dist/index.cjs
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
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-Cvjm0f_r.cjs"),i=`/**
|
|
2
2
|
* @license
|
|
3
3
|
* Copyright 2019 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
const
|
|
7
|
-
canHandle: (s) =>
|
|
6
|
+
const ut = Symbol("Comlink.proxy"), Dt = Symbol("Comlink.endpoint"), Nt = Symbol("Comlink.releaseProxy"), U = Symbol("Comlink.finalizer"), L = Symbol("Comlink.thrown"), ft = (s) => typeof s == "object" && s !== null || typeof s == "function", Tt = {
|
|
7
|
+
canHandle: (s) => ft(s) && s[ut],
|
|
8
8
|
serialize(s) {
|
|
9
9
|
const { port1: t, port2: e } = new MessageChannel();
|
|
10
|
-
return
|
|
10
|
+
return J(s, t), [e, [e]];
|
|
11
11
|
},
|
|
12
12
|
deserialize(s) {
|
|
13
|
-
return s.start(),
|
|
13
|
+
return s.start(), Pt(s);
|
|
14
14
|
}
|
|
15
15
|
}, Ft = {
|
|
16
|
-
canHandle: (s) =>
|
|
16
|
+
canHandle: (s) => ft(s) && L in s,
|
|
17
17
|
serialize({ value: s }) {
|
|
18
18
|
let t;
|
|
19
19
|
return s instanceof Error ? t = {
|
|
@@ -28,21 +28,21 @@ const ht = Symbol("Comlink.proxy"), Dt = Symbol("Comlink.endpoint"), Ot = Symbol
|
|
|
28
28
|
deserialize(s) {
|
|
29
29
|
throw s.isError ? Object.assign(new Error(s.value.message), s.value) : s.value;
|
|
30
30
|
}
|
|
31
|
-
},
|
|
32
|
-
["proxy",
|
|
31
|
+
}, dt = /* @__PURE__ */ new Map([
|
|
32
|
+
["proxy", Tt],
|
|
33
33
|
["throw", Ft]
|
|
34
34
|
]);
|
|
35
|
-
function
|
|
35
|
+
function Mt(s, t) {
|
|
36
36
|
for (const e of s)
|
|
37
37
|
if (t === e || e === "*" || e instanceof RegExp && e.test(t))
|
|
38
38
|
return !0;
|
|
39
39
|
return !1;
|
|
40
40
|
}
|
|
41
|
-
function
|
|
41
|
+
function J(s, t = globalThis, e = ["*"]) {
|
|
42
42
|
t.addEventListener("message", function n(i) {
|
|
43
43
|
if (!i || !i.data)
|
|
44
44
|
return;
|
|
45
|
-
if (!
|
|
45
|
+
if (!Mt(e, i.origin)) {
|
|
46
46
|
console.warn(\`Invalid origin '\${i.origin}' for comlink proxy\`);
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
@@ -63,13 +63,13 @@ function Y(s, t = globalThis, e = ["*"]) {
|
|
|
63
63
|
case "CONSTRUCT":
|
|
64
64
|
{
|
|
65
65
|
const u = new f(...l);
|
|
66
|
-
h =
|
|
66
|
+
h = zt(u);
|
|
67
67
|
}
|
|
68
68
|
break;
|
|
69
69
|
case "ENDPOINT":
|
|
70
70
|
{
|
|
71
71
|
const { port1: u, port2: d } = new MessageChannel();
|
|
72
|
-
|
|
72
|
+
J(s, d), h = It(u, [u]);
|
|
73
73
|
}
|
|
74
74
|
break;
|
|
75
75
|
case "RELEASE":
|
|
@@ -83,7 +83,7 @@ function Y(s, t = globalThis, e = ["*"]) {
|
|
|
83
83
|
}
|
|
84
84
|
Promise.resolve(h).catch((c) => ({ value: c, [L]: 0 })).then((c) => {
|
|
85
85
|
const [f, u] = H(c);
|
|
86
|
-
t.postMessage(Object.assign(Object.assign({}, f), { id: r }), u), o === "RELEASE" && (t.removeEventListener("message", n),
|
|
86
|
+
t.postMessage(Object.assign(Object.assign({}, f), { id: r }), u), o === "RELEASE" && (t.removeEventListener("message", n), pt(t), U in s && typeof s[U] == "function" && s[U]());
|
|
87
87
|
}).catch((c) => {
|
|
88
88
|
const [f, u] = H({
|
|
89
89
|
value: new TypeError("Unserializable return value"),
|
|
@@ -93,13 +93,13 @@ function Y(s, t = globalThis, e = ["*"]) {
|
|
|
93
93
|
});
|
|
94
94
|
}), t.start && t.start();
|
|
95
95
|
}
|
|
96
|
-
function
|
|
96
|
+
function $t(s) {
|
|
97
97
|
return s.constructor.name === "MessagePort";
|
|
98
98
|
}
|
|
99
|
-
function
|
|
100
|
-
|
|
99
|
+
function pt(s) {
|
|
100
|
+
$t(s) && s.close();
|
|
101
101
|
}
|
|
102
|
-
function
|
|
102
|
+
function Pt(s, t) {
|
|
103
103
|
const e = /* @__PURE__ */ new Map();
|
|
104
104
|
return s.addEventListener("message", function(i) {
|
|
105
105
|
const { data: r } = i;
|
|
@@ -112,54 +112,54 @@ function $t(s, t) {
|
|
|
112
112
|
} finally {
|
|
113
113
|
e.delete(r.id);
|
|
114
114
|
}
|
|
115
|
-
}),
|
|
115
|
+
}), X(s, e, [], t);
|
|
116
116
|
}
|
|
117
117
|
function R(s) {
|
|
118
118
|
if (s)
|
|
119
119
|
throw new Error("Proxy has been released and is not useable");
|
|
120
120
|
}
|
|
121
|
-
function
|
|
122
|
-
return
|
|
121
|
+
function gt(s) {
|
|
122
|
+
return O(s, /* @__PURE__ */ new Map(), {
|
|
123
123
|
type: "RELEASE"
|
|
124
124
|
}).then(() => {
|
|
125
|
-
|
|
125
|
+
pt(s);
|
|
126
126
|
});
|
|
127
127
|
}
|
|
128
128
|
const I = /* @__PURE__ */ new WeakMap(), z = "FinalizationRegistry" in globalThis && new FinalizationRegistry((s) => {
|
|
129
129
|
const t = (I.get(s) || 0) - 1;
|
|
130
|
-
I.set(s, t), t === 0 &&
|
|
130
|
+
I.set(s, t), t === 0 && gt(s);
|
|
131
131
|
});
|
|
132
|
-
function
|
|
132
|
+
function Rt(s, t) {
|
|
133
133
|
const e = (I.get(t) || 0) + 1;
|
|
134
134
|
I.set(t, e), z && z.register(s, t, s);
|
|
135
135
|
}
|
|
136
|
-
function
|
|
136
|
+
function kt(s) {
|
|
137
137
|
z && z.unregister(s);
|
|
138
138
|
}
|
|
139
|
-
function
|
|
139
|
+
function X(s, t, e = [], n = function() {
|
|
140
140
|
}) {
|
|
141
141
|
let i = !1;
|
|
142
142
|
const r = new Proxy(n, {
|
|
143
143
|
get(o, a) {
|
|
144
|
-
if (R(i), a ===
|
|
144
|
+
if (R(i), a === Nt)
|
|
145
145
|
return () => {
|
|
146
|
-
|
|
146
|
+
kt(r), gt(s), t.clear(), i = !0;
|
|
147
147
|
};
|
|
148
148
|
if (a === "then") {
|
|
149
149
|
if (e.length === 0)
|
|
150
150
|
return { then: () => r };
|
|
151
|
-
const l =
|
|
151
|
+
const l = O(s, t, {
|
|
152
152
|
type: "GET",
|
|
153
153
|
path: e.map((h) => h.toString())
|
|
154
154
|
}).then(C);
|
|
155
155
|
return l.then.bind(l);
|
|
156
156
|
}
|
|
157
|
-
return
|
|
157
|
+
return X(s, t, [...e, a]);
|
|
158
158
|
},
|
|
159
159
|
set(o, a, l) {
|
|
160
160
|
R(i);
|
|
161
161
|
const [h, c] = H(l);
|
|
162
|
-
return
|
|
162
|
+
return O(s, t, {
|
|
163
163
|
type: "SET",
|
|
164
164
|
path: [...e, a].map((f) => f.toString()),
|
|
165
165
|
value: h
|
|
@@ -169,13 +169,13 @@ function V(s, t, e = [], n = function() {
|
|
|
169
169
|
R(i);
|
|
170
170
|
const h = e[e.length - 1];
|
|
171
171
|
if (h === Dt)
|
|
172
|
-
return
|
|
172
|
+
return O(s, t, {
|
|
173
173
|
type: "ENDPOINT"
|
|
174
174
|
}).then(C);
|
|
175
175
|
if (h === "bind")
|
|
176
|
-
return
|
|
177
|
-
const [c, f] =
|
|
178
|
-
return
|
|
176
|
+
return X(s, t, e.slice(0, -1));
|
|
177
|
+
const [c, f] = st(l);
|
|
178
|
+
return O(s, t, {
|
|
179
179
|
type: "APPLY",
|
|
180
180
|
path: e.map((u) => u.toString()),
|
|
181
181
|
argumentList: c
|
|
@@ -183,32 +183,32 @@ function V(s, t, e = [], n = function() {
|
|
|
183
183
|
},
|
|
184
184
|
construct(o, a) {
|
|
185
185
|
R(i);
|
|
186
|
-
const [l, h] =
|
|
187
|
-
return
|
|
186
|
+
const [l, h] = st(a);
|
|
187
|
+
return O(s, t, {
|
|
188
188
|
type: "CONSTRUCT",
|
|
189
189
|
path: e.map((c) => c.toString()),
|
|
190
190
|
argumentList: l
|
|
191
191
|
}, h).then(C);
|
|
192
192
|
}
|
|
193
193
|
});
|
|
194
|
-
return
|
|
194
|
+
return Rt(r, s), r;
|
|
195
195
|
}
|
|
196
|
-
function
|
|
196
|
+
function Lt(s) {
|
|
197
197
|
return Array.prototype.concat.apply([], s);
|
|
198
198
|
}
|
|
199
|
-
function
|
|
199
|
+
function st(s) {
|
|
200
200
|
const t = s.map(H);
|
|
201
|
-
return [t.map((e) => e[0]),
|
|
201
|
+
return [t.map((e) => e[0]), Lt(t.map((e) => e[1]))];
|
|
202
202
|
}
|
|
203
|
-
const
|
|
204
|
-
function
|
|
205
|
-
return
|
|
203
|
+
const mt = /* @__PURE__ */ new WeakMap();
|
|
204
|
+
function It(s, t) {
|
|
205
|
+
return mt.set(s, t), s;
|
|
206
206
|
}
|
|
207
|
-
function
|
|
208
|
-
return Object.assign(s, { [
|
|
207
|
+
function zt(s) {
|
|
208
|
+
return Object.assign(s, { [ut]: !0 });
|
|
209
209
|
}
|
|
210
210
|
function H(s) {
|
|
211
|
-
for (const [t, e] of
|
|
211
|
+
for (const [t, e] of dt)
|
|
212
212
|
if (e.canHandle(s)) {
|
|
213
213
|
const [n, i] = e.serialize(s);
|
|
214
214
|
return [
|
|
@@ -225,24 +225,24 @@ function H(s) {
|
|
|
225
225
|
type: "RAW",
|
|
226
226
|
value: s
|
|
227
227
|
},
|
|
228
|
-
|
|
228
|
+
mt.get(s) || []
|
|
229
229
|
];
|
|
230
230
|
}
|
|
231
231
|
function C(s) {
|
|
232
232
|
switch (s.type) {
|
|
233
233
|
case "HANDLER":
|
|
234
|
-
return
|
|
234
|
+
return dt.get(s.name).deserialize(s.value);
|
|
235
235
|
case "RAW":
|
|
236
236
|
return s.value;
|
|
237
237
|
}
|
|
238
238
|
}
|
|
239
|
-
function
|
|
239
|
+
function O(s, t, e, n) {
|
|
240
240
|
return new Promise((i) => {
|
|
241
|
-
const r =
|
|
241
|
+
const r = Ht();
|
|
242
242
|
t.set(r, i), s.start && s.start(), s.postMessage(Object.assign({ id: r }, e), n);
|
|
243
243
|
});
|
|
244
244
|
}
|
|
245
|
-
function
|
|
245
|
+
function Ht() {
|
|
246
246
|
return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
|
|
247
247
|
}
|
|
248
248
|
class g extends Error {
|
|
@@ -250,12 +250,12 @@ class g extends Error {
|
|
|
250
250
|
super(t, { cause: i }), this.code = e, this.path = n, this.name = "OPFSError";
|
|
251
251
|
}
|
|
252
252
|
}
|
|
253
|
-
class
|
|
253
|
+
class Wt extends g {
|
|
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
|
|
258
|
+
class jt extends g {
|
|
259
259
|
constructor(t, e, n) {
|
|
260
260
|
super(t, "INVALID_PATH", e, n);
|
|
261
261
|
}
|
|
@@ -265,7 +265,7 @@ class _ extends g {
|
|
|
265
265
|
super(\`File not found: \${t}\`, "FILE_NOT_FOUND", t, e);
|
|
266
266
|
}
|
|
267
267
|
}
|
|
268
|
-
function
|
|
268
|
+
function Ut(s, t = "utf-8") {
|
|
269
269
|
switch (t) {
|
|
270
270
|
case "utf8":
|
|
271
271
|
case "utf-8":
|
|
@@ -273,11 +273,11 @@ function jt(s, t = "utf-8") {
|
|
|
273
273
|
case "utf16le":
|
|
274
274
|
case "ucs2":
|
|
275
275
|
case "ucs-2":
|
|
276
|
-
return
|
|
276
|
+
return Bt(s);
|
|
277
277
|
case "ascii":
|
|
278
|
-
return
|
|
278
|
+
return Vt(s);
|
|
279
279
|
case "latin1":
|
|
280
|
-
return
|
|
280
|
+
return qt(s);
|
|
281
281
|
case "binary":
|
|
282
282
|
return Uint8Array.from(s, (e) => e.charCodeAt(0));
|
|
283
283
|
case "base64":
|
|
@@ -290,19 +290,18 @@ function jt(s, t = "utf-8") {
|
|
|
290
290
|
return console.warn("Encoding not supported, falling back to UTF-8"), new TextEncoder().encode(s);
|
|
291
291
|
}
|
|
292
292
|
}
|
|
293
|
-
function
|
|
293
|
+
function _t(s, t = "utf-8") {
|
|
294
294
|
switch (t) {
|
|
295
295
|
case "utf8":
|
|
296
296
|
case "utf-8":
|
|
297
297
|
return new TextDecoder().decode(s);
|
|
298
298
|
case "utf16le":
|
|
299
|
+
case "utf-16le":
|
|
299
300
|
case "ucs2":
|
|
300
301
|
case "ucs-2":
|
|
301
|
-
return
|
|
302
|
+
return Gt(s);
|
|
302
303
|
case "latin1":
|
|
303
304
|
return String.fromCharCode(...s);
|
|
304
|
-
case "binary":
|
|
305
|
-
return String.fromCharCode(...s);
|
|
306
305
|
case "ascii":
|
|
307
306
|
return String.fromCharCode(...s.map((e) => e & 127));
|
|
308
307
|
case "base64":
|
|
@@ -313,7 +312,7 @@ function Ut(s, t = "utf-8") {
|
|
|
313
312
|
return console.warn("Unsupported encoding, falling back to UTF-8"), new TextDecoder().decode(s);
|
|
314
313
|
}
|
|
315
314
|
}
|
|
316
|
-
function
|
|
315
|
+
function Bt(s) {
|
|
317
316
|
const t = new Uint8Array(s.length * 2);
|
|
318
317
|
for (let e = 0; e < s.length; e++) {
|
|
319
318
|
const n = s.charCodeAt(e);
|
|
@@ -321,25 +320,25 @@ function _t(s) {
|
|
|
321
320
|
}
|
|
322
321
|
return t;
|
|
323
322
|
}
|
|
324
|
-
function
|
|
323
|
+
function Gt(s) {
|
|
325
324
|
s.length % 2 !== 0 && (console.warn("Invalid UTF-16LE buffer length, truncating last byte"), s = s.slice(0, s.length - 1));
|
|
326
325
|
const t = new Uint16Array(s.buffer, s.byteOffset, s.byteLength / 2);
|
|
327
326
|
return String.fromCharCode(...t);
|
|
328
327
|
}
|
|
329
|
-
function
|
|
328
|
+
function qt(s) {
|
|
330
329
|
const t = new Uint8Array(s.length);
|
|
331
330
|
for (let e = 0; e < s.length; e++)
|
|
332
331
|
t[e] = s.charCodeAt(e) & 255;
|
|
333
332
|
return t;
|
|
334
333
|
}
|
|
335
|
-
function
|
|
334
|
+
function Vt(s) {
|
|
336
335
|
const t = new Uint8Array(s.length);
|
|
337
336
|
for (let e = 0; e < s.length; e++)
|
|
338
337
|
t[e] = s.charCodeAt(e) & 127;
|
|
339
338
|
return t;
|
|
340
339
|
}
|
|
341
|
-
const
|
|
342
|
-
const n = s instanceof RegExp ?
|
|
340
|
+
const wt = (s, t, e) => {
|
|
341
|
+
const n = s instanceof RegExp ? nt(s, e) : s, i = t instanceof RegExp ? nt(t, e) : t, r = n !== null && i != null && Xt(n, i, e);
|
|
343
342
|
return r && {
|
|
344
343
|
start: r[0],
|
|
345
344
|
end: r[1],
|
|
@@ -347,10 +346,10 @@ const mt = (s, t, e) => {
|
|
|
347
346
|
body: e.slice(r[0] + n.length, r[1]),
|
|
348
347
|
post: e.slice(r[1] + i.length)
|
|
349
348
|
};
|
|
350
|
-
},
|
|
349
|
+
}, nt = (s, t) => {
|
|
351
350
|
const e = t.match(s);
|
|
352
351
|
return e ? e[0] : null;
|
|
353
|
-
},
|
|
352
|
+
}, Xt = (s, t, e) => {
|
|
354
353
|
let n, i, r, o, a, l = e.indexOf(s), h = e.indexOf(t, l + 1), c = l;
|
|
355
354
|
if (l >= 0 && h > 0) {
|
|
356
355
|
if (s === t)
|
|
@@ -368,44 +367,44 @@ const mt = (s, t, e) => {
|
|
|
368
367
|
n.length && o !== void 0 && (a = [r, o]);
|
|
369
368
|
}
|
|
370
369
|
return a;
|
|
371
|
-
},
|
|
370
|
+
}, yt = "\\0SLASH" + Math.random() + "\\0", Et = "\\0OPEN" + Math.random() + "\\0", K = "\\0CLOSE" + Math.random() + "\\0", St = "\\0COMMA" + Math.random() + "\\0", xt = "\\0PERIOD" + Math.random() + "\\0", Yt = new RegExp(yt, "g"), Zt = new RegExp(Et, "g"), Jt = new RegExp(K, "g"), Kt = new RegExp(St, "g"), Qt = new RegExp(xt, "g"), te = /\\\\\\\\/g, ee = /\\\\{/g, se = /\\\\}/g, ne = /\\\\,/g, ie = /\\\\./g;
|
|
372
371
|
function B(s) {
|
|
373
372
|
return isNaN(s) ? s.charCodeAt(0) : parseInt(s, 10);
|
|
374
373
|
}
|
|
375
|
-
function ie(s) {
|
|
376
|
-
return s.replace(Qt, wt).replace(te, yt).replace(ee, J).replace(se, Et).replace(ne, St);
|
|
377
|
-
}
|
|
378
374
|
function re(s) {
|
|
379
|
-
return s.replace(
|
|
375
|
+
return s.replace(te, yt).replace(ee, Et).replace(se, K).replace(ne, St).replace(ie, xt);
|
|
380
376
|
}
|
|
381
|
-
function
|
|
377
|
+
function oe(s) {
|
|
378
|
+
return s.replace(Yt, "\\\\").replace(Zt, "{").replace(Jt, "}").replace(Kt, ",").replace(Qt, ".");
|
|
379
|
+
}
|
|
380
|
+
function bt(s) {
|
|
382
381
|
if (!s)
|
|
383
382
|
return [""];
|
|
384
|
-
const t = [], e =
|
|
383
|
+
const t = [], e = wt("{", "}", s);
|
|
385
384
|
if (!e)
|
|
386
385
|
return s.split(",");
|
|
387
386
|
const { pre: n, body: i, post: r } = e, o = n.split(",");
|
|
388
387
|
o[o.length - 1] += "{" + i + "}";
|
|
389
|
-
const a =
|
|
388
|
+
const a = bt(r);
|
|
390
389
|
return r.length && (o[o.length - 1] += a.shift(), o.push.apply(o, a)), t.push.apply(t, o), t;
|
|
391
390
|
}
|
|
392
|
-
function oe(s) {
|
|
393
|
-
return s ? (s.slice(0, 2) === "{}" && (s = "\\\\{\\\\}" + s.slice(2)), M(ie(s), !0).map(re)) : [];
|
|
394
|
-
}
|
|
395
391
|
function ae(s) {
|
|
396
|
-
return "{"
|
|
392
|
+
return s ? (s.slice(0, 2) === "{}" && (s = "\\\\{\\\\}" + s.slice(2)), M(re(s), !0).map(oe)) : [];
|
|
397
393
|
}
|
|
398
394
|
function ce(s) {
|
|
395
|
+
return "{" + s + "}";
|
|
396
|
+
}
|
|
397
|
+
function le(s) {
|
|
399
398
|
return /^-?0\\d/.test(s);
|
|
400
399
|
}
|
|
401
|
-
function
|
|
400
|
+
function he(s, t) {
|
|
402
401
|
return s <= t;
|
|
403
402
|
}
|
|
404
|
-
function
|
|
403
|
+
function ue(s, t) {
|
|
405
404
|
return s >= t;
|
|
406
405
|
}
|
|
407
406
|
function M(s, t) {
|
|
408
|
-
const e = [], n =
|
|
407
|
+
const e = [], n = wt("{", "}", s);
|
|
409
408
|
if (!n)
|
|
410
409
|
return [s];
|
|
411
410
|
const i = n.pre, r = n.post.length ? M(n.post, !1) : [""];
|
|
@@ -417,27 +416,27 @@ function M(s, t) {
|
|
|
417
416
|
else {
|
|
418
417
|
const o = /^-?\\d+\\.\\.-?\\d+(?:\\.\\.-?\\d+)?$/.test(n.body), a = /^[a-zA-Z]\\.\\.[a-zA-Z](?:\\.\\.-?\\d+)?$/.test(n.body), l = o || a, h = n.body.indexOf(",") >= 0;
|
|
419
418
|
if (!l && !h)
|
|
420
|
-
return n.post.match(/,(?!,).*\\}/) ? (s = n.pre + "{" + n.body +
|
|
419
|
+
return n.post.match(/,(?!,).*\\}/) ? (s = n.pre + "{" + n.body + K + n.post, M(s)) : [s];
|
|
421
420
|
let c;
|
|
422
421
|
if (l)
|
|
423
422
|
c = n.body.split(/\\.\\./);
|
|
424
|
-
else if (c =
|
|
423
|
+
else if (c = bt(n.body), c.length === 1 && c[0] !== void 0 && (c = M(c[0], !1).map(ce), c.length === 1))
|
|
425
424
|
return r.map((u) => n.pre + c[0] + u);
|
|
426
425
|
let f;
|
|
427
426
|
if (l && c[0] !== void 0 && c[1] !== void 0) {
|
|
428
427
|
const u = B(c[0]), d = B(c[1]), m = Math.max(c[0].length, c[1].length);
|
|
429
|
-
let p = c.length === 3 && c[2] !== void 0 ? Math.abs(B(c[2])) : 1, S =
|
|
430
|
-
d < u && (p *= -1, S =
|
|
431
|
-
const N = c.some(
|
|
428
|
+
let p = c.length === 3 && c[2] !== void 0 ? Math.abs(B(c[2])) : 1, S = he;
|
|
429
|
+
d < u && (p *= -1, S = ue);
|
|
430
|
+
const N = c.some(le);
|
|
432
431
|
f = [];
|
|
433
432
|
for (let x = u; S(x, d); x += p) {
|
|
434
433
|
let w;
|
|
435
434
|
if (a)
|
|
436
435
|
w = String.fromCharCode(x), w === "\\\\" && (w = "");
|
|
437
436
|
else if (w = String(x), N) {
|
|
438
|
-
const
|
|
439
|
-
if (
|
|
440
|
-
const P = new Array(
|
|
437
|
+
const T = m - w.length;
|
|
438
|
+
if (T > 0) {
|
|
439
|
+
const P = new Array(T + 1).join("0");
|
|
441
440
|
x < 0 ? w = "-" + P + w.slice(1) : w = P + w;
|
|
442
441
|
}
|
|
443
442
|
}
|
|
@@ -456,12 +455,12 @@ function M(s, t) {
|
|
|
456
455
|
}
|
|
457
456
|
return e;
|
|
458
457
|
}
|
|
459
|
-
const
|
|
458
|
+
const fe = 1024 * 64, W = (s) => {
|
|
460
459
|
if (typeof s != "string")
|
|
461
460
|
throw new TypeError("invalid pattern");
|
|
462
|
-
if (s.length >
|
|
461
|
+
if (s.length > fe)
|
|
463
462
|
throw new TypeError("pattern is too long");
|
|
464
|
-
},
|
|
463
|
+
}, de = {
|
|
465
464
|
"[:alnum:]": ["\\\\p{L}\\\\p{Nl}\\\\p{Nd}", !0],
|
|
466
465
|
"[:alpha:]": ["\\\\p{L}\\\\p{Nl}", !0],
|
|
467
466
|
"[:ascii:]": ["\\\\x00-\\\\x7f", !1],
|
|
@@ -476,7 +475,7 @@ const ue = 1024 * 64, W = (s) => {
|
|
|
476
475
|
"[:upper:]": ["\\\\p{Lu}", !0],
|
|
477
476
|
"[:word:]": ["\\\\p{L}\\\\p{Nl}\\\\p{Nd}\\\\p{Pc}", !0],
|
|
478
477
|
"[:xdigit:]": ["A-Fa-f0-9", !1]
|
|
479
|
-
},
|
|
478
|
+
}, F = (s) => s.replace(/[[\\]\\\\-]/g, "\\\\$&"), pe = (s) => s.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, "\\\\$&"), it = (s) => s.join(""), ge = (s, t) => {
|
|
480
479
|
const e = t;
|
|
481
480
|
if (s.charAt(e) !== "[")
|
|
482
481
|
throw new Error("not in a brace expression");
|
|
@@ -497,27 +496,27 @@ const ue = 1024 * 64, W = (s) => {
|
|
|
497
496
|
continue;
|
|
498
497
|
}
|
|
499
498
|
if (p === "[" && !l) {
|
|
500
|
-
for (const [S, [
|
|
499
|
+
for (const [S, [A, N, x]] of Object.entries(de))
|
|
501
500
|
if (s.startsWith(S, r)) {
|
|
502
501
|
if (f)
|
|
503
502
|
return ["$.", !1, s.length - e, !0];
|
|
504
|
-
r += S.length, x ? i.push(
|
|
503
|
+
r += S.length, x ? i.push(A) : n.push(A), a = a || N;
|
|
505
504
|
continue t;
|
|
506
505
|
}
|
|
507
506
|
}
|
|
508
507
|
if (l = !1, f) {
|
|
509
|
-
p > f ? n.push(
|
|
508
|
+
p > f ? n.push(F(f) + "-" + F(p)) : p === f && n.push(F(p)), f = "", r++;
|
|
510
509
|
continue;
|
|
511
510
|
}
|
|
512
511
|
if (s.startsWith("-]", r + 1)) {
|
|
513
|
-
n.push(
|
|
512
|
+
n.push(F(p + "-")), r += 2;
|
|
514
513
|
continue;
|
|
515
514
|
}
|
|
516
515
|
if (s.startsWith("-", r + 1)) {
|
|
517
516
|
f = p, r += 2;
|
|
518
517
|
continue;
|
|
519
518
|
}
|
|
520
|
-
n.push(
|
|
519
|
+
n.push(F(p)), r++;
|
|
521
520
|
}
|
|
522
521
|
if (c < r)
|
|
523
522
|
return ["", !1, 0, !1];
|
|
@@ -525,11 +524,11 @@ const ue = 1024 * 64, W = (s) => {
|
|
|
525
524
|
return ["$.", !1, s.length - e, !0];
|
|
526
525
|
if (i.length === 0 && n.length === 1 && /^\\\\?.$/.test(n[0]) && !h) {
|
|
527
526
|
const p = n[0].length === 2 ? n[0].slice(-1) : n[0];
|
|
528
|
-
return [
|
|
527
|
+
return [pe(p), !1, c - e, !1];
|
|
529
528
|
}
|
|
530
|
-
const u = "[" + (h ? "^" : "") +
|
|
529
|
+
const u = "[" + (h ? "^" : "") + it(n) + "]", d = "[" + (h ? "" : "^") + it(i) + "]";
|
|
531
530
|
return [n.length && i.length ? "(" + u + "|" + d + ")" : n.length ? u : d, a, c - e, !0];
|
|
532
|
-
}, $ = (s, { windowsPathsNoEscape: t = !1 } = {}) => t ? s.replace(/\\[([^\\/\\\\])\\]/g, "$1") : s.replace(/((?!\\\\).|^)\\[([^\\/\\\\])\\]/g, "$1$2").replace(/\\\\([^\\/])/g, "$1"),
|
|
531
|
+
}, $ = (s, { windowsPathsNoEscape: t = !1 } = {}) => t ? s.replace(/\\[([^\\/\\\\])\\]/g, "$1") : s.replace(/((?!\\\\).|^)\\[([^\\/\\\\])\\]/g, "$1$2").replace(/\\\\([^\\/])/g, "$1"), me = /* @__PURE__ */ new Set(["!", "?", "+", "*", "@"]), rt = (s) => me.has(s), we = "(?!(?:^|/)\\\\.\\\\.?(?:$|/))", k = "(?!\\\\.)", ye = /* @__PURE__ */ new Set(["[", "."]), Ee = /* @__PURE__ */ new Set(["..", "."]), Se = new Set("().*{}+?[]^$\\\\!"), xe = (s) => s.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, "\\\\$&"), Q = "[^/]", ot = Q + "*?", at = Q + "+?";
|
|
533
532
|
class E {
|
|
534
533
|
type;
|
|
535
534
|
#s;
|
|
@@ -646,7 +645,7 @@ class E {
|
|
|
646
645
|
o = !0, a = d, l = !1, m += p;
|
|
647
646
|
continue;
|
|
648
647
|
}
|
|
649
|
-
if (!i.noext &&
|
|
648
|
+
if (!i.noext && rt(p) && t.charAt(d) === "(") {
|
|
650
649
|
e.push(m), m = "";
|
|
651
650
|
const S = new E(p, e);
|
|
652
651
|
d = E.#h(t, S, d, i), e.push(S);
|
|
@@ -672,7 +671,7 @@ class E {
|
|
|
672
671
|
o = !0, a = h, l = !1, u += d;
|
|
673
672
|
continue;
|
|
674
673
|
}
|
|
675
|
-
if (
|
|
674
|
+
if (rt(d) && t.charAt(h) === "(") {
|
|
676
675
|
c.push(u), u = "";
|
|
677
676
|
const m = new E(d, c);
|
|
678
677
|
c.push(m), h = E.#h(t, m, h, i);
|
|
@@ -782,18 +781,18 @@ class E {
|
|
|
782
781
|
const e = t ?? !!this.#i.dot;
|
|
783
782
|
if (this.#s === this && this.#d(), !this.type) {
|
|
784
783
|
const l = this.isStart() && this.isEnd(), h = this.#t.map((d) => {
|
|
785
|
-
const [m, p, S,
|
|
786
|
-
return this.#n = this.#n || S, this.#r = this.#r ||
|
|
784
|
+
const [m, p, S, A] = typeof d == "string" ? E.#p(d, this.#n, l) : d.toRegExpSource(t);
|
|
785
|
+
return this.#n = this.#n || S, this.#r = this.#r || A, m;
|
|
787
786
|
}).join("");
|
|
788
787
|
let c = "";
|
|
789
|
-
if (this.isStart() && typeof this.#t[0] == "string" && !(this.#t.length === 1 &&
|
|
790
|
-
const m =
|
|
788
|
+
if (this.isStart() && typeof this.#t[0] == "string" && !(this.#t.length === 1 && Ee.has(this.#t[0]))) {
|
|
789
|
+
const m = ye, p = (
|
|
791
790
|
// dots are allowed, and the pattern starts with [ or .
|
|
792
791
|
e && m.has(h.charAt(0)) || // the pattern starts with \\., and then [ or .
|
|
793
792
|
h.startsWith("\\\\.") && m.has(h.charAt(2)) || // the pattern starts with \\.\\., and then [ or .
|
|
794
793
|
h.startsWith("\\\\.\\\\.") && m.has(h.charAt(4))
|
|
795
794
|
), S = !e && !t && m.has(h.charAt(0));
|
|
796
|
-
c = p ?
|
|
795
|
+
c = p ? we : S ? k : "";
|
|
797
796
|
}
|
|
798
797
|
let f = "";
|
|
799
798
|
return this.isEnd() && this.#s.#a && this.#e?.type === "!" && (f = "(?:$|\\\\/)"), [
|
|
@@ -813,11 +812,11 @@ class E {
|
|
|
813
812
|
o === r && (o = ""), o && (r = \`(?:\${r})(?:\${o})*?\`);
|
|
814
813
|
let a = "";
|
|
815
814
|
if (this.type === "!" && this.#u)
|
|
816
|
-
a = (this.isStart() && !e ? k : "") +
|
|
815
|
+
a = (this.isStart() && !e ? k : "") + at;
|
|
817
816
|
else {
|
|
818
817
|
const l = this.type === "!" ? (
|
|
819
818
|
// !() must match something,but !(x) can match ''
|
|
820
|
-
"))" + (this.isStart() && !e && !t ? k : "") +
|
|
819
|
+
"))" + (this.isStart() && !e && !t ? k : "") + ot + ")"
|
|
821
820
|
) : this.type === "@" ? ")" : this.type === "?" ? ")?" : this.type === "+" && o ? ")" : this.type === "*" && o ? ")?" : \`)\${this.type}\`;
|
|
822
821
|
a = i + r + l;
|
|
823
822
|
}
|
|
@@ -841,7 +840,7 @@ class E {
|
|
|
841
840
|
for (let a = 0; a < t.length; a++) {
|
|
842
841
|
const l = t.charAt(a);
|
|
843
842
|
if (i) {
|
|
844
|
-
i = !1, r += (
|
|
843
|
+
i = !1, r += (Se.has(l) ? "\\\\" : "") + l;
|
|
845
844
|
continue;
|
|
846
845
|
}
|
|
847
846
|
if (l === "\\\\") {
|
|
@@ -849,53 +848,53 @@ class E {
|
|
|
849
848
|
continue;
|
|
850
849
|
}
|
|
851
850
|
if (l === "[") {
|
|
852
|
-
const [h, c, f, u] =
|
|
851
|
+
const [h, c, f, u] = ge(t, a);
|
|
853
852
|
if (f) {
|
|
854
853
|
r += h, o = o || c, a += f - 1, e = e || u;
|
|
855
854
|
continue;
|
|
856
855
|
}
|
|
857
856
|
}
|
|
858
857
|
if (l === "*") {
|
|
859
|
-
n && t === "*" ? r +=
|
|
858
|
+
n && t === "*" ? r += at : r += ot, e = !0;
|
|
860
859
|
continue;
|
|
861
860
|
}
|
|
862
861
|
if (l === "?") {
|
|
863
|
-
r +=
|
|
862
|
+
r += Q, e = !0;
|
|
864
863
|
continue;
|
|
865
864
|
}
|
|
866
|
-
r +=
|
|
865
|
+
r += xe(l);
|
|
867
866
|
}
|
|
868
867
|
return [r, $(t), !!e, o];
|
|
869
868
|
}
|
|
870
869
|
}
|
|
871
|
-
const
|
|
872
|
-
const e =
|
|
870
|
+
const be = (s, { windowsPathsNoEscape: t = !1 } = {}) => t ? s.replace(/[?*()[\\]]/g, "[$&]") : s.replace(/[?*()[\\]\\\\]/g, "\\\\$&"), y = (s, t, e = {}) => (W(t), !e.nocomment && t.charAt(0) === "#" ? !1 : new j(t, e).match(s)), ve = /^\\*+([^+@!?\\*\\[\\(]*)$/, Ae = (s) => (t) => !t.startsWith(".") && t.endsWith(s), Ce = (s) => (t) => t.endsWith(s), Oe = (s) => (s = s.toLowerCase(), (t) => !t.startsWith(".") && t.toLowerCase().endsWith(s)), De = (s) => (s = s.toLowerCase(), (t) => t.toLowerCase().endsWith(s)), Ne = /^\\*+\\.\\*+$/, Te = (s) => !s.startsWith(".") && s.includes("."), Fe = (s) => s !== "." && s !== ".." && s.includes("."), Me = /^\\.\\*+$/, $e = (s) => s !== "." && s !== ".." && s.startsWith("."), Pe = /^\\*+$/, Re = (s) => s.length !== 0 && !s.startsWith("."), ke = (s) => s.length !== 0 && s !== "." && s !== "..", Le = /^\\?+([^+@!?\\*\\[\\(]*)?$/, Ie = ([s, t = ""]) => {
|
|
871
|
+
const e = vt([s]);
|
|
873
872
|
return t ? (t = t.toLowerCase(), (n) => e(n) && n.toLowerCase().endsWith(t)) : e;
|
|
874
|
-
},
|
|
873
|
+
}, ze = ([s, t = ""]) => {
|
|
875
874
|
const e = At([s]);
|
|
876
875
|
return t ? (t = t.toLowerCase(), (n) => e(n) && n.toLowerCase().endsWith(t)) : e;
|
|
877
|
-
},
|
|
876
|
+
}, He = ([s, t = ""]) => {
|
|
878
877
|
const e = At([s]);
|
|
879
878
|
return t ? (n) => e(n) && n.endsWith(t) : e;
|
|
880
|
-
},
|
|
881
|
-
const e =
|
|
879
|
+
}, We = ([s, t = ""]) => {
|
|
880
|
+
const e = vt([s]);
|
|
882
881
|
return t ? (n) => e(n) && n.endsWith(t) : e;
|
|
883
|
-
},
|
|
882
|
+
}, vt = ([s]) => {
|
|
884
883
|
const t = s.length;
|
|
885
884
|
return (e) => e.length === t && !e.startsWith(".");
|
|
886
885
|
}, At = ([s]) => {
|
|
887
886
|
const t = s.length;
|
|
888
887
|
return (e) => e.length === t && e !== "." && e !== "..";
|
|
889
|
-
},
|
|
888
|
+
}, Ct = typeof process == "object" && process ? typeof process.env == "object" && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix", ct = {
|
|
890
889
|
win32: { sep: "\\\\" },
|
|
891
890
|
posix: { sep: "/" }
|
|
892
|
-
},
|
|
893
|
-
y.sep =
|
|
894
|
-
const
|
|
895
|
-
y.GLOBSTAR =
|
|
896
|
-
const
|
|
897
|
-
y.filter =
|
|
898
|
-
const b = (s, t = {}) => Object.assign({}, s, t),
|
|
891
|
+
}, je = Ct === "win32" ? ct.win32.sep : ct.posix.sep;
|
|
892
|
+
y.sep = je;
|
|
893
|
+
const v = Symbol("globstar **");
|
|
894
|
+
y.GLOBSTAR = v;
|
|
895
|
+
const Ue = "[^/]", _e = Ue + "*?", Be = "(?:(?!(?:\\\\/|^)(?:\\\\.{1,2})($|\\\\/)).)*?", Ge = "(?:(?!(?:\\\\/|^)\\\\.).)*?", qe = (s, t = {}) => (e) => y(e, s, t);
|
|
896
|
+
y.filter = qe;
|
|
897
|
+
const b = (s, t = {}) => Object.assign({}, s, t), Ve = (s) => {
|
|
899
898
|
if (!s || typeof s != "object" || !Object.keys(s).length)
|
|
900
899
|
return y;
|
|
901
900
|
const t = y;
|
|
@@ -926,20 +925,20 @@ const b = (s, t = {}) => Object.assign({}, s, t), qe = (s) => {
|
|
|
926
925
|
braceExpand: (n, i = {}) => t.braceExpand(n, b(s, i)),
|
|
927
926
|
match: (n, i, r = {}) => t.match(n, i, b(s, r)),
|
|
928
927
|
sep: t.sep,
|
|
929
|
-
GLOBSTAR:
|
|
928
|
+
GLOBSTAR: v
|
|
930
929
|
});
|
|
931
930
|
};
|
|
932
|
-
y.defaults =
|
|
933
|
-
const
|
|
934
|
-
y.braceExpand =
|
|
935
|
-
const
|
|
936
|
-
y.makeRe =
|
|
937
|
-
const
|
|
931
|
+
y.defaults = Ve;
|
|
932
|
+
const Ot = (s, t = {}) => (W(s), t.nobrace || !/\\{(?:(?!\\{).)*\\}/.test(s) ? [s] : ae(s));
|
|
933
|
+
y.braceExpand = Ot;
|
|
934
|
+
const Xe = (s, t = {}) => new j(s, t).makeRe();
|
|
935
|
+
y.makeRe = Xe;
|
|
936
|
+
const Ye = (s, t, e = {}) => {
|
|
938
937
|
const n = new j(t, e);
|
|
939
938
|
return s = s.filter((i) => n.match(i)), n.options.nonull && !s.length && s.push(t), s;
|
|
940
939
|
};
|
|
941
|
-
y.match =
|
|
942
|
-
const
|
|
940
|
+
y.match = Ye;
|
|
941
|
+
const lt = /[?*]|[+@!]\\(.*?\\)|\\[|\\]/, Ze = (s) => s.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, "\\\\$&");
|
|
943
942
|
class j {
|
|
944
943
|
options;
|
|
945
944
|
set;
|
|
@@ -959,7 +958,7 @@ class j {
|
|
|
959
958
|
windowsNoMagicRoot;
|
|
960
959
|
regexp;
|
|
961
960
|
constructor(t, e = {}) {
|
|
962
|
-
W(t), e = e || {}, this.options = e, this.pattern = t, this.platform = e.platform ||
|
|
961
|
+
W(t), e = e || {}, this.options = e, this.pattern = t, this.platform = e.platform || Ct, this.isWindows = this.platform === "win32", this.windowsPathsNoEscape = !!e.windowsPathsNoEscape || e.allowWindowsEscape === !1, this.windowsPathsNoEscape && (this.pattern = this.pattern.replace(/\\\\/g, "/")), this.preserveMultipleSlashes = !!e.preserveMultipleSlashes, this.regexp = null, this.negate = !1, this.nonegate = !!e.nonegate, this.comment = !1, this.empty = !1, this.partial = !!e.partial, this.nocase = !!this.options.nocase, this.windowsNoMagicRoot = e.windowsNoMagicRoot !== void 0 ? e.windowsNoMagicRoot : !!(this.isWindows && this.nocase), this.globSet = [], this.globParts = [], this.set = [], this.make();
|
|
963
962
|
}
|
|
964
963
|
hasMagic() {
|
|
965
964
|
if (this.options.magicalBraces && this.set.length > 1)
|
|
@@ -987,7 +986,7 @@ class j {
|
|
|
987
986
|
this.globParts = this.preprocess(n), this.debug(this.pattern, this.globParts);
|
|
988
987
|
let i = this.globParts.map((r, o, a) => {
|
|
989
988
|
if (this.isWindows && this.windowsNoMagicRoot) {
|
|
990
|
-
const l = r[0] === "" && r[1] === "" && (r[2] === "?" || !
|
|
989
|
+
const l = r[0] === "" && r[1] === "" && (r[2] === "?" || !lt.test(r[2])) && !lt.test(r[3]), h = /^[a-z]:/i.test(r[0]);
|
|
991
990
|
if (l)
|
|
992
991
|
return [...r.slice(0, 4), ...r.slice(4).map((c) => this.parse(c))];
|
|
993
992
|
if (h)
|
|
@@ -1167,10 +1166,10 @@ class j {
|
|
|
1167
1166
|
matchOne(t, e, n = !1) {
|
|
1168
1167
|
const i = this.options;
|
|
1169
1168
|
if (this.isWindows) {
|
|
1170
|
-
const p = typeof t[0] == "string" && /^[a-z]:$/i.test(t[0]), S = !p && t[0] === "" && t[1] === "" && t[2] === "?" && /^[a-z]:$/i.test(t[3]),
|
|
1169
|
+
const p = typeof t[0] == "string" && /^[a-z]:$/i.test(t[0]), S = !p && t[0] === "" && t[1] === "" && t[2] === "?" && /^[a-z]:$/i.test(t[3]), A = typeof e[0] == "string" && /^[a-z]:$/i.test(e[0]), N = !A && e[0] === "" && e[1] === "" && e[2] === "?" && typeof e[3] == "string" && /^[a-z]:$/i.test(e[3]), x = S ? 3 : p ? 0 : void 0, w = N ? 3 : A ? 0 : void 0;
|
|
1171
1170
|
if (typeof x == "number" && typeof w == "number") {
|
|
1172
|
-
const [
|
|
1173
|
-
|
|
1171
|
+
const [T, P] = [t[x], e[w]];
|
|
1172
|
+
T.toLowerCase() === P.toLowerCase() && (e[w] = T, w > x ? e = e.slice(w) : x > w && (t = t.slice(x)));
|
|
1174
1173
|
}
|
|
1175
1174
|
}
|
|
1176
1175
|
const { optimizationLevel: r = 1 } = this.options;
|
|
@@ -1180,7 +1179,7 @@ class j {
|
|
|
1180
1179
|
var c = e[a], f = t[o];
|
|
1181
1180
|
if (this.debug(e, c, f), c === !1)
|
|
1182
1181
|
return !1;
|
|
1183
|
-
if (c ===
|
|
1182
|
+
if (c === v) {
|
|
1184
1183
|
this.debug("GLOBSTAR", [e, c, f]);
|
|
1185
1184
|
var u = o, d = a + 1;
|
|
1186
1185
|
if (d === h) {
|
|
@@ -1216,17 +1215,17 @@ globstar while\`, t, u, e, d, m), this.matchOne(t.slice(u), e.slice(d), n))
|
|
|
1216
1215
|
throw new Error("wtf?");
|
|
1217
1216
|
}
|
|
1218
1217
|
braceExpand() {
|
|
1219
|
-
return
|
|
1218
|
+
return Ot(this.pattern, this.options);
|
|
1220
1219
|
}
|
|
1221
1220
|
parse(t) {
|
|
1222
1221
|
W(t);
|
|
1223
1222
|
const e = this.options;
|
|
1224
1223
|
if (t === "**")
|
|
1225
|
-
return
|
|
1224
|
+
return v;
|
|
1226
1225
|
if (t === "")
|
|
1227
1226
|
return "";
|
|
1228
1227
|
let n, i = null;
|
|
1229
|
-
(n = t.match(
|
|
1228
|
+
(n = t.match(Pe)) ? i = e.dot ? ke : Re : (n = t.match(ve)) ? i = (e.nocase ? e.dot ? De : Oe : e.dot ? Ce : Ae)(n[1]) : (n = t.match(Le)) ? i = (e.nocase ? e.dot ? ze : Ie : e.dot ? He : We)(n) : (n = t.match(Ne)) ? i = e.dot ? Fe : Te : (n = t.match(Me)) && (i = $e);
|
|
1230
1229
|
const r = E.fromGlob(t, this.options).toMMPattern();
|
|
1231
1230
|
return i && typeof r == "object" && Reflect.defineProperty(r, "test", { value: i }), r;
|
|
1232
1231
|
}
|
|
@@ -1236,18 +1235,18 @@ globstar while\`, t, u, e, d, m), this.matchOne(t.slice(u), e.slice(d), n))
|
|
|
1236
1235
|
const t = this.set;
|
|
1237
1236
|
if (!t.length)
|
|
1238
1237
|
return this.regexp = !1, this.regexp;
|
|
1239
|
-
const e = this.options, n = e.noglobstar ?
|
|
1238
|
+
const e = this.options, n = e.noglobstar ? _e : e.dot ? Be : Ge, i = new Set(e.nocase ? ["i"] : []);
|
|
1240
1239
|
let r = t.map((l) => {
|
|
1241
1240
|
const h = l.map((c) => {
|
|
1242
1241
|
if (c instanceof RegExp)
|
|
1243
1242
|
for (const f of c.flags.split(""))
|
|
1244
1243
|
i.add(f);
|
|
1245
|
-
return typeof c == "string" ?
|
|
1244
|
+
return typeof c == "string" ? Ze(c) : c === v ? v : c._src;
|
|
1246
1245
|
});
|
|
1247
1246
|
return h.forEach((c, f) => {
|
|
1248
1247
|
const u = h[f + 1], d = h[f - 1];
|
|
1249
|
-
c !==
|
|
1250
|
-
}), h.filter((c) => c !==
|
|
1248
|
+
c !== v || d === v || (d === void 0 ? u !== void 0 && u !== v ? h[f + 1] = "(?:\\\\/|" + n + "\\\\/)?" + u : h[f] = n : u === void 0 ? h[f - 1] = d + "(?:\\\\/|" + n + ")?" : u !== v && (h[f - 1] = d + "(?:\\\\/|\\\\/" + n + "\\\\/)" + u, h[f + 1] = v));
|
|
1249
|
+
}), h.filter((c) => c !== v).join("/");
|
|
1251
1250
|
}).join("|");
|
|
1252
1251
|
const [o, a] = t.length > 1 ? ["(?:", ")"] : ["", ""];
|
|
1253
1252
|
r = "^" + o + r + a + "$", this.negate && (r = "^(?!" + r + ").+$");
|
|
@@ -1292,43 +1291,106 @@ globstar while\`, t, u, e, d, m), this.matchOne(t.slice(u), e.slice(d), n))
|
|
|
1292
1291
|
}
|
|
1293
1292
|
y.AST = E;
|
|
1294
1293
|
y.Minimatch = j;
|
|
1295
|
-
y.escape =
|
|
1294
|
+
y.escape = be;
|
|
1296
1295
|
y.unescape = $;
|
|
1297
|
-
|
|
1296
|
+
const Je = [
|
|
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() {
|
|
1298
1360
|
if (!("storage" in navigator) || !("getDirectory" in navigator.storage))
|
|
1299
|
-
throw new
|
|
1361
|
+
throw new Wt();
|
|
1300
1362
|
}
|
|
1301
|
-
async function
|
|
1363
|
+
async function tt(s, t, e) {
|
|
1302
1364
|
return typeof navigator < "u" && navigator.locks?.request ? navigator.locks.request(\`opfs:\${s.replace(/\\/+/g, "/").toLowerCase()}\`, { mode: t }, e) : e();
|
|
1303
1365
|
}
|
|
1304
|
-
function
|
|
1366
|
+
function D(s) {
|
|
1305
1367
|
return Array.isArray(s) ? s : (s.startsWith("~/") ? s.slice(2) : s).split("/").filter(Boolean);
|
|
1306
1368
|
}
|
|
1307
|
-
function
|
|
1369
|
+
function et(s) {
|
|
1308
1370
|
return typeof s == "string" ? s ?? "/" : \`/\${s.join("/")}\`;
|
|
1309
1371
|
}
|
|
1310
|
-
function
|
|
1311
|
-
const t =
|
|
1372
|
+
function Y(s) {
|
|
1373
|
+
const t = D(s);
|
|
1312
1374
|
return t[t.length - 1] || "";
|
|
1313
1375
|
}
|
|
1314
|
-
function
|
|
1315
|
-
const t =
|
|
1316
|
-
return t.pop(),
|
|
1376
|
+
function q(s) {
|
|
1377
|
+
const t = D(s);
|
|
1378
|
+
return t.pop(), et(t);
|
|
1317
1379
|
}
|
|
1318
|
-
function
|
|
1380
|
+
function Z(s) {
|
|
1319
1381
|
return !s || s === "/" ? "/" : s.startsWith("~/") ? \`/\${s.slice(2)}\` : s.startsWith("/") ? s : \`/\${s}\`;
|
|
1320
1382
|
}
|
|
1321
|
-
function
|
|
1383
|
+
function Qe(s, t = !1) {
|
|
1322
1384
|
return s = s.replace(/\\/$/, ""), t && !s.includes("*") ? \`\${s}/**\` : s;
|
|
1323
1385
|
}
|
|
1324
|
-
function
|
|
1386
|
+
function V(s, t) {
|
|
1325
1387
|
return y(s, t, {
|
|
1326
1388
|
dot: !0,
|
|
1327
1389
|
matchBase: !0
|
|
1328
1390
|
});
|
|
1329
1391
|
}
|
|
1330
|
-
function
|
|
1331
|
-
const t =
|
|
1392
|
+
function ts(s) {
|
|
1393
|
+
const t = Z(s), e = D(t), n = [];
|
|
1332
1394
|
for (const i of e)
|
|
1333
1395
|
if (!(i === "." || i === ""))
|
|
1334
1396
|
if (i === "..") {
|
|
@@ -1337,24 +1399,24 @@ function Ke(s) {
|
|
|
1337
1399
|
n.pop();
|
|
1338
1400
|
} else
|
|
1339
1401
|
n.push(i);
|
|
1340
|
-
return
|
|
1402
|
+
return et(n);
|
|
1341
1403
|
}
|
|
1342
|
-
function
|
|
1343
|
-
return typeof s == "string" ?
|
|
1404
|
+
function es(s, t = "utf-8") {
|
|
1405
|
+
return typeof s == "string" ? Ut(s, t) : s instanceof Uint8Array ? s : new Uint8Array(s);
|
|
1344
1406
|
}
|
|
1345
|
-
async function
|
|
1346
|
-
return
|
|
1407
|
+
async function ss(s, t) {
|
|
1408
|
+
return tt(t, "shared", async () => {
|
|
1347
1409
|
const n = await (await s.getFile()).arrayBuffer();
|
|
1348
1410
|
return new Uint8Array(n);
|
|
1349
1411
|
});
|
|
1350
1412
|
}
|
|
1351
|
-
async function
|
|
1413
|
+
async function ht(s, t, e, n, i = {}) {
|
|
1352
1414
|
const r = async () => {
|
|
1353
1415
|
let o = null;
|
|
1354
|
-
const a =
|
|
1416
|
+
const a = i.append || !1, l = !a && (i.truncate ?? !0);
|
|
1355
1417
|
try {
|
|
1356
1418
|
o = await s.createSyncAccessHandle();
|
|
1357
|
-
const h =
|
|
1419
|
+
const h = es(t, e), c = a ? o.getSize() : 0;
|
|
1358
1420
|
o.write(h, { at: c }), l && o.truncate(h.byteLength), o.flush();
|
|
1359
1421
|
} catch (h) {
|
|
1360
1422
|
console.error(h);
|
|
@@ -1367,22 +1429,23 @@ async function lt(s, t, e, n = {}, i) {
|
|
|
1367
1429
|
}
|
|
1368
1430
|
}
|
|
1369
1431
|
};
|
|
1370
|
-
return
|
|
1432
|
+
return n ? tt(n, "exclusive", r) : r();
|
|
1371
1433
|
}
|
|
1372
|
-
async function
|
|
1434
|
+
async function ns(s, t = "SHA-1", e = 50 * 1024 * 1024) {
|
|
1373
1435
|
if (s instanceof File && (s = await s.arrayBuffer()), s.byteLength > e)
|
|
1374
1436
|
throw new Error(\`File size \${s.byteLength} bytes exceeds maximum allowed size \${e} bytes\`);
|
|
1375
1437
|
const n = new Uint8Array(s), i = await crypto.subtle.digest(t, n);
|
|
1376
1438
|
return Array.from(new Uint8Array(i)).map((o) => o.toString(16).padStart(2, "0")).join("");
|
|
1377
1439
|
}
|
|
1378
|
-
async function
|
|
1440
|
+
async function is(s) {
|
|
1379
1441
|
const t = await s.arrayBuffer();
|
|
1380
1442
|
return new Uint8Array(t);
|
|
1381
1443
|
}
|
|
1382
|
-
async function
|
|
1383
|
-
const n =
|
|
1384
|
-
return
|
|
1444
|
+
async function rs(s, t, e = {}) {
|
|
1445
|
+
const n = Y(t);
|
|
1446
|
+
return tt(t, "exclusive", async () => {
|
|
1385
1447
|
const i = e.recursive ?? !1, r = e.force ?? !1;
|
|
1448
|
+
e.useTrash;
|
|
1386
1449
|
try {
|
|
1387
1450
|
await s.removeEntry(n, { recursive: i });
|
|
1388
1451
|
} catch (o) {
|
|
@@ -1393,9 +1456,9 @@ async function ns(s, t, e = {}) {
|
|
|
1393
1456
|
}
|
|
1394
1457
|
});
|
|
1395
1458
|
}
|
|
1396
|
-
class
|
|
1459
|
+
class os {
|
|
1397
1460
|
/** Root directory handle for the file system */
|
|
1398
|
-
root
|
|
1461
|
+
root;
|
|
1399
1462
|
/** Map of watched paths and options */
|
|
1400
1463
|
watchers = /* @__PURE__ */ new Map();
|
|
1401
1464
|
/** Promise to prevent concurrent mount operations */
|
|
@@ -1423,7 +1486,7 @@ class is {
|
|
|
1423
1486
|
if (!this.options.broadcastChannel)
|
|
1424
1487
|
return;
|
|
1425
1488
|
const e = t.path;
|
|
1426
|
-
if (![...this.watchers.values()].some((r) =>
|
|
1489
|
+
if (![...this.watchers.values()].some((r) => V(e, r.pattern) && r.include.some((o) => o && V(e, o)) && !r.exclude.some((o) => o && V(e, o))))
|
|
1427
1490
|
return;
|
|
1428
1491
|
let i;
|
|
1429
1492
|
if (this.options.hashAlgorithm)
|
|
@@ -1455,7 +1518,7 @@ class is {
|
|
|
1455
1518
|
* @throws {OPFSError} If OPFS is not supported in the current browser
|
|
1456
1519
|
*/
|
|
1457
1520
|
constructor(t) {
|
|
1458
|
-
|
|
1521
|
+
Ke(), t && this.setOptions(t);
|
|
1459
1522
|
}
|
|
1460
1523
|
/**
|
|
1461
1524
|
* Initialize the file system within a given directory
|
|
@@ -1478,13 +1541,14 @@ class is {
|
|
|
1478
1541
|
* await fs.mount('/my-app');
|
|
1479
1542
|
* \`\`\`
|
|
1480
1543
|
*/
|
|
1481
|
-
async mount(
|
|
1482
|
-
|
|
1544
|
+
async mount() {
|
|
1545
|
+
const t = this.options.root;
|
|
1546
|
+
return this.mountingPromise && await this.mountingPromise, this.mountingPromise = new Promise(async (e, n) => {
|
|
1483
1547
|
try {
|
|
1484
1548
|
const i = await navigator.storage.getDirectory();
|
|
1485
|
-
t === "/" ?
|
|
1486
|
-
} catch {
|
|
1487
|
-
n(new g("Failed to initialize OPFS", "INIT_FAILED"));
|
|
1549
|
+
this.root = t === "/" ? i : await this.getDirectoryHandle(t, !0, i), e(!0);
|
|
1550
|
+
} catch (i) {
|
|
1551
|
+
n(new g("Failed to initialize OPFS", "INIT_FAILED", t, i));
|
|
1488
1552
|
} finally {
|
|
1489
1553
|
this.mountingPromise = null;
|
|
1490
1554
|
}
|
|
@@ -1501,7 +1565,7 @@ class is {
|
|
|
1501
1565
|
* @param options.broadcastChannel - Custom name for the broadcast channel
|
|
1502
1566
|
*/
|
|
1503
1567
|
async setOptions(t) {
|
|
1504
|
-
t.hashAlgorithm !== void 0 && (this.options.hashAlgorithm = t.hashAlgorithm), t.maxFileSize !== void 0 && (this.options.maxFileSize = t.maxFileSize), t.broadcastChannel !== void 0 && (this.broadcastChannel && this.options.broadcastChannel !== t.broadcastChannel && (this.broadcastChannel.close(), this.broadcastChannel = null), this.options.broadcastChannel = t.broadcastChannel), t.namespace && (this.options.namespace = t.namespace), t.root !== void 0 && (this.options.root = t.root, this.options.namespace || (this.options.namespace = \`opfs-worker:\${this.options.root}\`), await this.mount(
|
|
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 = Z(t.root), this.options.namespace || (this.options.namespace = \`opfs-worker:\${this.options.root}\`), await this.mount());
|
|
1505
1569
|
}
|
|
1506
1570
|
/**
|
|
1507
1571
|
* Get a directory handle from a path
|
|
@@ -1522,7 +1586,7 @@ class is {
|
|
|
1522
1586
|
* \`\`\`
|
|
1523
1587
|
*/
|
|
1524
1588
|
async getDirectoryHandle(t, e = !1, n = this.root) {
|
|
1525
|
-
const i = Array.isArray(t) ? t :
|
|
1589
|
+
const i = Array.isArray(t) ? t : D(t);
|
|
1526
1590
|
let r = n;
|
|
1527
1591
|
for (const o of i)
|
|
1528
1592
|
r = await r.getDirectoryHandle(o, { create: e });
|
|
@@ -1548,9 +1612,9 @@ class is {
|
|
|
1548
1612
|
* \`\`\`
|
|
1549
1613
|
*/
|
|
1550
1614
|
async getFileHandle(t, e = !1, n = this.root) {
|
|
1551
|
-
const i =
|
|
1615
|
+
const i = D(t);
|
|
1552
1616
|
if (i.length === 0)
|
|
1553
|
-
throw new
|
|
1617
|
+
throw new jt("Path must not be empty", Array.isArray(t) ? t.join("/") : t);
|
|
1554
1618
|
const r = i.pop();
|
|
1555
1619
|
return (await this.getDirectoryHandle(i, e, n)).getFileHandle(r, { create: e });
|
|
1556
1620
|
}
|
|
@@ -1595,11 +1659,11 @@ class is {
|
|
|
1595
1659
|
isDirectory: !0
|
|
1596
1660
|
}), await e("/"), t;
|
|
1597
1661
|
}
|
|
1598
|
-
async readFile(t, e
|
|
1599
|
-
await this.mount();
|
|
1662
|
+
async readFile(t, e) {
|
|
1663
|
+
await this.mount(), e || (e = G(t) ? "binary" : "utf-8");
|
|
1600
1664
|
try {
|
|
1601
|
-
const n = await this.getFileHandle(t, !1), i = await
|
|
1602
|
-
return e === "binary" ? i :
|
|
1665
|
+
const n = await this.getFileHandle(t, !1, this.root), i = await ss(n, t);
|
|
1666
|
+
return e === "binary" ? i : _t(i, e);
|
|
1603
1667
|
} catch (n) {
|
|
1604
1668
|
throw new _(t, n);
|
|
1605
1669
|
}
|
|
@@ -1632,7 +1696,7 @@ class is {
|
|
|
1632
1696
|
async writeFile(t, e, n) {
|
|
1633
1697
|
await this.mount();
|
|
1634
1698
|
const i = await this.exists(t), r = await this.getFileHandle(t, !0);
|
|
1635
|
-
await
|
|
1699
|
+
n || (n = typeof e != "string" || G(t) ? "binary" : "utf-8"), await ht(r, e, n, t), i ? await this.notifyChange({ path: t, type: "changed", isDirectory: !1 }) : await this.notifyChange({ path: t, type: "added", isDirectory: !1 });
|
|
1636
1700
|
}
|
|
1637
1701
|
/**
|
|
1638
1702
|
* Append data to a file
|
|
@@ -1659,7 +1723,7 @@ class is {
|
|
|
1659
1723
|
async appendFile(t, e, n) {
|
|
1660
1724
|
await this.mount();
|
|
1661
1725
|
const i = await this.getFileHandle(t, !0);
|
|
1662
|
-
await
|
|
1726
|
+
n || (n = typeof e != "string" || G(t) ? "binary" : "utf-8"), await ht(i, e, n, t, { append: !0 }), await this.notifyChange({ path: t, type: "changed", isDirectory: !1 });
|
|
1663
1727
|
}
|
|
1664
1728
|
/**
|
|
1665
1729
|
* Create a directory
|
|
@@ -1684,7 +1748,7 @@ class is {
|
|
|
1684
1748
|
*/
|
|
1685
1749
|
async mkdir(t, e) {
|
|
1686
1750
|
await this.mount();
|
|
1687
|
-
const n = e?.recursive ?? !1, i =
|
|
1751
|
+
const n = e?.recursive ?? !1, i = D(t);
|
|
1688
1752
|
let r = this.root;
|
|
1689
1753
|
for (let o = 0; o < i.length; o++) {
|
|
1690
1754
|
const a = i[o];
|
|
@@ -1692,7 +1756,7 @@ class is {
|
|
|
1692
1756
|
r = await r.getDirectoryHandle(a, { create: n || o === i.length - 1 });
|
|
1693
1757
|
} catch (l) {
|
|
1694
1758
|
throw l.name === "NotFoundError" ? new g(
|
|
1695
|
-
\`Parent directory does not exist: \${
|
|
1759
|
+
\`Parent directory does not exist: \${et(i.slice(0, o + 1))}\`,
|
|
1696
1760
|
"ENOENT",
|
|
1697
1761
|
void 0,
|
|
1698
1762
|
l
|
|
@@ -1733,7 +1797,7 @@ class is {
|
|
|
1733
1797
|
isFile: !1,
|
|
1734
1798
|
isDirectory: !0
|
|
1735
1799
|
};
|
|
1736
|
-
const e =
|
|
1800
|
+
const e = Y(t), n = await this.getDirectoryHandle(q(t), !1), i = this.options.hashAlgorithm !== null;
|
|
1737
1801
|
try {
|
|
1738
1802
|
const o = await (await n.getFileHandle(e, { create: !1 })).getFile(), a = {
|
|
1739
1803
|
kind: "file",
|
|
@@ -1745,7 +1809,7 @@ class is {
|
|
|
1745
1809
|
};
|
|
1746
1810
|
if (i && this.options.hashAlgorithm)
|
|
1747
1811
|
try {
|
|
1748
|
-
const l = await
|
|
1812
|
+
const l = await ns(o, this.options.hashAlgorithm, this.options.maxFileSize);
|
|
1749
1813
|
a.hash = l;
|
|
1750
1814
|
} catch (l) {
|
|
1751
1815
|
console.warn(\`Failed to calculate hash for \${t}:\`, l);
|
|
@@ -1817,10 +1881,10 @@ class is {
|
|
|
1817
1881
|
async exists(t) {
|
|
1818
1882
|
if (await this.mount(), t === "/")
|
|
1819
1883
|
return !0;
|
|
1820
|
-
const e =
|
|
1884
|
+
const e = Y(t);
|
|
1821
1885
|
let n = null;
|
|
1822
1886
|
try {
|
|
1823
|
-
n = await this.getDirectoryHandle(
|
|
1887
|
+
n = await this.getDirectoryHandle(q(t), !1);
|
|
1824
1888
|
} catch (i) {
|
|
1825
1889
|
throw (i.name === "NotFoundError" || i.name === "TypeMismatchError") && (n = null), i;
|
|
1826
1890
|
}
|
|
@@ -1899,8 +1963,8 @@ class is {
|
|
|
1899
1963
|
async remove(t, e) {
|
|
1900
1964
|
if (await this.mount(), t === "/")
|
|
1901
1965
|
throw new g("Cannot remove root directory", "EROOT");
|
|
1902
|
-
const n = await this.getDirectoryHandle(
|
|
1903
|
-
await
|
|
1966
|
+
const { recursive: n = !1, force: i = !1 } = e || {}, r = await this.getDirectoryHandle(q(t), !1);
|
|
1967
|
+
await rs(r, t, { recursive: n, force: i }), await this.notifyChange({ path: t, type: "removed", isDirectory: !1 });
|
|
1904
1968
|
}
|
|
1905
1969
|
/**
|
|
1906
1970
|
* Resolve a path to an absolute path
|
|
@@ -1923,7 +1987,7 @@ class is {
|
|
|
1923
1987
|
async realpath(t) {
|
|
1924
1988
|
await this.mount();
|
|
1925
1989
|
try {
|
|
1926
|
-
const e =
|
|
1990
|
+
const e = ts(t);
|
|
1927
1991
|
if (!await this.exists(e))
|
|
1928
1992
|
throw new _(e);
|
|
1929
1993
|
return e;
|
|
@@ -1935,26 +1999,35 @@ class is {
|
|
|
1935
1999
|
* Rename a file or directory
|
|
1936
2000
|
*
|
|
1937
2001
|
* Changes the name of a file or directory. If the target path already exists,
|
|
1938
|
-
* it will be replaced.
|
|
2002
|
+
* it will be replaced only if overwrite option is enabled.
|
|
1939
2003
|
*
|
|
1940
2004
|
* @param oldPath - The current path of the file or directory
|
|
1941
2005
|
* @param newPath - The new path for the file or directory
|
|
2006
|
+
* @param options - Options for renaming
|
|
2007
|
+
* @param options.overwrite - Whether to overwrite existing files (default: false)
|
|
1942
2008
|
* @returns Promise that resolves when the rename operation is complete
|
|
1943
2009
|
* @throws {OPFSError} If the rename operation fails
|
|
1944
2010
|
*
|
|
1945
2011
|
* @example
|
|
1946
2012
|
* \`\`\`typescript
|
|
2013
|
+
* // Basic rename (fails if target exists)
|
|
1947
2014
|
* await fs.rename('/old/path/file.txt', '/new/path/renamed.txt');
|
|
2015
|
+
*
|
|
2016
|
+
* // Rename with overwrite
|
|
2017
|
+
* await fs.rename('/old/path/file.txt', '/new/path/renamed.txt', { overwrite: true });
|
|
1948
2018
|
* \`\`\`
|
|
1949
2019
|
*/
|
|
1950
|
-
async rename(t, e) {
|
|
2020
|
+
async rename(t, e, n) {
|
|
1951
2021
|
await this.mount();
|
|
1952
2022
|
try {
|
|
2023
|
+
const i = n?.overwrite ?? !1;
|
|
1953
2024
|
if (!await this.exists(t))
|
|
1954
2025
|
throw new _(t);
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
2026
|
+
if (await this.exists(e) && !i)
|
|
2027
|
+
throw new g(\`Destination already exists: \${e}\`, "EEXIST", void 0);
|
|
2028
|
+
await this.copy(t, e, { recursive: !0, overwrite: i }), await this.remove(t, { recursive: !0 }), await this.notifyChange({ path: t, type: "removed", isDirectory: !1 }), await this.notifyChange({ path: e, type: "added", isDirectory: !1 });
|
|
2029
|
+
} catch (i) {
|
|
2030
|
+
throw i instanceof g ? i : new g(\`Failed to rename from \${t} to \${e}\`, "RENAME_FAILED", void 0, i);
|
|
1958
2031
|
}
|
|
1959
2032
|
}
|
|
1960
2033
|
/**
|
|
@@ -1966,7 +2039,7 @@ class is {
|
|
|
1966
2039
|
* @param destination - The destination path to copy to
|
|
1967
2040
|
* @param options - Options for copying
|
|
1968
2041
|
* @param options.recursive - Whether to copy directories recursively (default: false)
|
|
1969
|
-
* @param options.
|
|
2042
|
+
* @param options.overwrite - Whether to overwrite existing files (default: true)
|
|
1970
2043
|
* @returns Promise that resolves when the copy operation is complete
|
|
1971
2044
|
* @throws {OPFSError} If the copy operation fails
|
|
1972
2045
|
*
|
|
@@ -1979,13 +2052,13 @@ class is {
|
|
|
1979
2052
|
* await fs.copy('/source/dir', '/dest/dir', { recursive: true });
|
|
1980
2053
|
*
|
|
1981
2054
|
* // Copy without overwriting existing files
|
|
1982
|
-
* await fs.copy('/source', '/dest', { recursive: true,
|
|
2055
|
+
* await fs.copy('/source', '/dest', { recursive: true, overwrite: false });
|
|
1983
2056
|
* \`\`\`
|
|
1984
2057
|
*/
|
|
1985
2058
|
async copy(t, e, n) {
|
|
1986
2059
|
await this.mount();
|
|
1987
2060
|
try {
|
|
1988
|
-
const i = n?.recursive ?? !1, r = n?.
|
|
2061
|
+
const i = n?.recursive ?? !1, r = n?.overwrite ?? !0;
|
|
1989
2062
|
if (!await this.exists(t))
|
|
1990
2063
|
throw new g(\`Source does not exist: \${t}\`, "ENOENT", void 0);
|
|
1991
2064
|
if (await this.exists(e) && !r)
|
|
@@ -2000,7 +2073,7 @@ class is {
|
|
|
2000
2073
|
const h = await this.readDir(t);
|
|
2001
2074
|
for (const c of h) {
|
|
2002
2075
|
const f = \`\${t}/\${c.name}\`, u = \`\${e}/\${c.name}\`;
|
|
2003
|
-
await this.copy(f, u, { recursive: !0,
|
|
2076
|
+
await this.copy(f, u, { recursive: !0, overwrite: r });
|
|
2004
2077
|
}
|
|
2005
2078
|
}
|
|
2006
2079
|
} catch (i) {
|
|
@@ -2036,7 +2109,7 @@ class is {
|
|
|
2036
2109
|
if (!this.options.broadcastChannel)
|
|
2037
2110
|
throw new g("This instance is not configured to send events. Please specify options.broadcastChannel to enable watching.", "ENOENT");
|
|
2038
2111
|
const n = {
|
|
2039
|
-
pattern:
|
|
2112
|
+
pattern: Qe(t, e?.recursive ?? !0),
|
|
2040
2113
|
include: Array.isArray(e?.include) ? e.include : [e?.include ?? "**"],
|
|
2041
2114
|
exclude: Array.isArray(e?.exclude) ? e.exclude : [e?.exclude ?? ""]
|
|
2042
2115
|
};
|
|
@@ -2090,16 +2163,16 @@ class is {
|
|
|
2090
2163
|
try {
|
|
2091
2164
|
(e?.cleanBefore ?? !1) && await this.clear("/");
|
|
2092
2165
|
for (const [i, r] of t) {
|
|
2093
|
-
const o =
|
|
2166
|
+
const o = Z(i);
|
|
2094
2167
|
let a;
|
|
2095
|
-
r instanceof Blob ? a = await
|
|
2168
|
+
r instanceof Blob ? a = await is(r) : a = r, await this.writeFile(o, a);
|
|
2096
2169
|
}
|
|
2097
2170
|
} catch (n) {
|
|
2098
2171
|
throw n instanceof g ? n : new g("Failed to sync file system", "SYNC_FAILED", void 0, n);
|
|
2099
2172
|
}
|
|
2100
2173
|
}
|
|
2101
2174
|
}
|
|
2102
|
-
typeof globalThis < "u" && globalThis.constructor.name === "DedicatedWorkerGlobalScope" &&
|
|
2103
|
-
//# sourceMappingURL=worker-
|
|
2104
|
-
`,r=typeof self<"u"&&self.Blob&&new Blob(["URL.revokeObjectURL(import.meta.url);",i],{type:"text/javascript;charset=utf-8"});function a(t){let e;try{if(e=r&&(self.URL||self.webkitURL).createObjectURL(r),!e)throw"";const s=new Worker(e,{type:"module",name:t?.name});return s.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(e)}),s}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(i),{type:"module",name:t?.name})}}async function h(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.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.checkOPFSSupport=n.checkOPFSSupport;exports.convertBlobToUint8Array=n.convertBlobToUint8Array;exports.createBuffer=n.createBuffer;exports.decodeBuffer=n.decodeBuffer;exports.dirname=n.dirname;exports.encodeString=n.encodeString;exports.extname=n.extname;exports.isPathExcluded=n.isPathExcluded;exports.joinPath=n.joinPath;exports.matchMinimatch=n.matchMinimatch;exports.normalizeMinimatch=n.normalizeMinimatch;exports.normalizePath=n.normalizePath;exports.readFileData=n.readFileData;exports.removeEntry=n.removeEntry;exports.resolvePath=n.resolvePath;exports.splitPath=n.splitPath;exports.withLock=n.withLock;exports.writeFileData=n.writeFileData;exports.createWorker=h;
|
|
2175
|
+
typeof globalThis < "u" && globalThis.constructor.name === "DedicatedWorkerGlobalScope" && J(new os());
|
|
2176
|
+
//# sourceMappingURL=worker-XHCzp1qX.js.map
|
|
2177
|
+
`,r=typeof self<"u"&&self.Blob&&new Blob(["URL.revokeObjectURL(import.meta.url);",i],{type:"text/javascript;charset=utf-8"});function a(t){let e;try{if(e=r&&(self.URL||self.webkitURL).createObjectURL(r),!e)throw"";const s=new Worker(e,{type:"module",name:t?.name});return s.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(e)}),s}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(i),{type:"module",name:t?.name})}}async function h(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.checkOPFSSupport=n.checkOPFSSupport;exports.convertBlobToUint8Array=n.convertBlobToUint8Array;exports.createBuffer=n.createBuffer;exports.decodeBuffer=n.decodeBuffer;exports.dirname=n.dirname;exports.encodeString=n.encodeString;exports.extname=n.extname;exports.isBinaryFileExtension=n.isBinaryFileExtension;exports.isPathExcluded=n.isPathExcluded;exports.joinPath=n.joinPath;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.splitPath=n.splitPath;exports.withLock=n.withLock;exports.writeFileData=n.writeFileData;exports.createWorker=h;
|
|
2105
2178
|
//# sourceMappingURL=index.cjs.map
|