@uipath/api-workflow-tool 1.201.0-preview.133 → 1.202.0-preview.134

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.
@@ -1,1795 +0,0 @@
1
- import {
2
- BrowserContextStorage,
3
- ConsoleTelemetryProvider,
4
- ProjectPackager,
5
- TelemetryService,
6
- ToolLogger,
7
- setGlobalLogHandler
8
- } from "./packager-tool-21day5ep.js";
9
- import {
10
- translate
11
- } from "./packager-tool-h1tyrbff.js";
12
- import"./packager-tool-wckvcay0.js";
13
-
14
- // ../filesystem/dist/index.browser.js
15
- var __create = Object.create;
16
- var __getProtoOf = Object.getPrototypeOf;
17
- var __defProp = Object.defineProperty;
18
- var __getOwnPropNames = Object.getOwnPropertyNames;
19
- var __hasOwnProp = Object.prototype.hasOwnProperty;
20
- function __accessProp(key) {
21
- return this[key];
22
- }
23
- var __toESMCache_node;
24
- var __toESMCache_esm;
25
- var __toESM = (mod, isNodeMode, target) => {
26
- var canCache = mod != null && typeof mod === "object";
27
- if (canCache) {
28
- var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
29
- var cached = cache.get(mod);
30
- if (cached)
31
- return cached;
32
- }
33
- target = mod != null ? __create(__getProtoOf(mod)) : {};
34
- const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
35
- for (let key of __getOwnPropNames(mod))
36
- if (!__hasOwnProp.call(to, key))
37
- __defProp(to, key, {
38
- get: __accessProp.bind(mod, key),
39
- enumerable: true
40
- });
41
- if (canCache)
42
- cache.set(mod, to);
43
- return to;
44
- };
45
- var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
46
- var require_just_once = __commonJS((exports, module) => {
47
- module.exports = once;
48
- function once(fn) {
49
- var called, value;
50
- if (typeof fn !== "function") {
51
- throw new Error("expected a function but got " + fn);
52
- }
53
- return function wrap() {
54
- if (called) {
55
- return value;
56
- }
57
- called = true;
58
- value = fn.apply(this, arguments);
59
- return value;
60
- };
61
- }
62
- });
63
- var require_text_min = __commonJS((exports) => {
64
- (function(scope) {
65
- function B(r, e) {
66
- var f;
67
- return r instanceof Buffer ? f = r : f = Buffer.from(r.buffer, r.byteOffset, r.byteLength), f.toString(e);
68
- }
69
- var w = function(r) {
70
- return Buffer.from(r);
71
- };
72
- function h(r) {
73
- for (var e = 0, f = Math.min(256 * 256, r.length + 1), n = new Uint16Array(f), i = [], o = 0;; ) {
74
- var t = e < r.length;
75
- if (!t || o >= f - 1) {
76
- var s = n.subarray(0, o), m = s;
77
- if (i.push(String.fromCharCode.apply(null, m)), !t)
78
- return i.join("");
79
- r = r.subarray(e), e = 0, o = 0;
80
- }
81
- var a = r[e++];
82
- if ((a & 128) === 0)
83
- n[o++] = a;
84
- else if ((a & 224) === 192) {
85
- var d = r[e++] & 63;
86
- n[o++] = (a & 31) << 6 | d;
87
- } else if ((a & 240) === 224) {
88
- var d = r[e++] & 63, l = r[e++] & 63;
89
- n[o++] = (a & 31) << 12 | d << 6 | l;
90
- } else if ((a & 248) === 240) {
91
- var d = r[e++] & 63, l = r[e++] & 63, R = r[e++] & 63, c = (a & 7) << 18 | d << 12 | l << 6 | R;
92
- c > 65535 && (c -= 65536, n[o++] = c >>> 10 & 1023 | 55296, c = 56320 | c & 1023), n[o++] = c;
93
- }
94
- }
95
- }
96
- function F(r) {
97
- for (var e = 0, f = r.length, n = 0, i = Math.max(32, f + (f >>> 1) + 7), o = new Uint8Array(i >>> 3 << 3);e < f; ) {
98
- var t = r.charCodeAt(e++);
99
- if (t >= 55296 && t <= 56319) {
100
- if (e < f) {
101
- var s = r.charCodeAt(e);
102
- (s & 64512) === 56320 && (++e, t = ((t & 1023) << 10) + (s & 1023) + 65536);
103
- }
104
- if (t >= 55296 && t <= 56319)
105
- continue;
106
- }
107
- if (n + 4 > o.length) {
108
- i += 8, i *= 1 + e / r.length * 2, i = i >>> 3 << 3;
109
- var m = new Uint8Array(i);
110
- m.set(o), o = m;
111
- }
112
- if ((t & 4294967168) === 0) {
113
- o[n++] = t;
114
- continue;
115
- } else if ((t & 4294965248) === 0)
116
- o[n++] = t >>> 6 & 31 | 192;
117
- else if ((t & 4294901760) === 0)
118
- o[n++] = t >>> 12 & 15 | 224, o[n++] = t >>> 6 & 63 | 128;
119
- else if ((t & 4292870144) === 0)
120
- o[n++] = t >>> 18 & 7 | 240, o[n++] = t >>> 12 & 63 | 128, o[n++] = t >>> 6 & 63 | 128;
121
- else
122
- continue;
123
- o[n++] = t & 63 | 128;
124
- }
125
- return o.slice ? o.slice(0, n) : o.subarray(0, n);
126
- }
127
- var u = "Failed to ", p = function(r, e, f) {
128
- if (r)
129
- throw new Error("".concat(u).concat(e, ": the '").concat(f, "' option is unsupported."));
130
- };
131
- var x = typeof Buffer == "function" && Buffer.from;
132
- var A = x ? w : F;
133
- function v() {
134
- this.encoding = "utf-8";
135
- }
136
- v.prototype.encode = function(r, e) {
137
- return p(e && e.stream, "encode", "stream"), A(r);
138
- };
139
- function U(r) {
140
- var e;
141
- try {
142
- var f = new Blob([r], { type: "text/plain;charset=UTF-8" });
143
- e = URL.createObjectURL(f);
144
- var n = new XMLHttpRequest;
145
- return n.open("GET", e, false), n.send(), n.responseText;
146
- } finally {
147
- e && URL.revokeObjectURL(e);
148
- }
149
- }
150
- var O = !x && typeof Blob == "function" && typeof URL == "function" && typeof URL.createObjectURL == "function", S = ["utf-8", "utf8", "unicode-1-1-utf-8"], T = h;
151
- x ? T = B : O && (T = function(r) {
152
- try {
153
- return U(r);
154
- } catch (e) {
155
- return h(r);
156
- }
157
- });
158
- var y = "construct 'TextDecoder'", E = "".concat(u, " ").concat(y, ": the ");
159
- function g(r, e) {
160
- p(e && e.fatal, y, "fatal"), r = r || "utf-8";
161
- var f;
162
- if (x ? f = Buffer.isEncoding(r) : f = S.indexOf(r.toLowerCase()) !== -1, !f)
163
- throw new RangeError("".concat(E, " encoding label provided ('").concat(r, "') is invalid."));
164
- this.encoding = r, this.fatal = false, this.ignoreBOM = false;
165
- }
166
- g.prototype.decode = function(r, e) {
167
- p(e && e.stream, "decode", "stream");
168
- var f;
169
- return r instanceof Uint8Array ? f = r : r.buffer instanceof ArrayBuffer ? f = new Uint8Array(r.buffer) : f = new Uint8Array(r), T(f, this.encoding);
170
- };
171
- scope.TextEncoder = scope.TextEncoder || v;
172
- scope.TextDecoder = scope.TextDecoder || g;
173
- })(typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : exports);
174
- });
175
- var require_browser = __commonJS((exports, module) => {
176
- require_text_min();
177
- module.exports = {
178
- encode: (string) => new TextEncoder().encode(string),
179
- decode: (buffer) => new TextDecoder().decode(buffer)
180
- };
181
- });
182
- var require_just_debounce_it = __commonJS((exports, module) => {
183
- module.exports = debounce;
184
- function debounce(fn, wait, callFirst) {
185
- var timeout;
186
- return function() {
187
- if (!wait) {
188
- return fn.apply(this, arguments);
189
- }
190
- var context = this;
191
- var args = arguments;
192
- var callNow = callFirst && !timeout;
193
- clearTimeout(timeout);
194
- timeout = setTimeout(function() {
195
- timeout = null;
196
- if (!callNow) {
197
- return fn.apply(context, args);
198
- }
199
- }, wait);
200
- if (callNow) {
201
- return fn.apply(this, arguments);
202
- }
203
- };
204
- }
205
- });
206
- var require_path = __commonJS((exports, module) => {
207
- function normalizePath(path) {
208
- if (path.length === 0) {
209
- return ".";
210
- }
211
- let parts = splitPath(path);
212
- parts = parts.reduce(reducer, []);
213
- return joinPath(...parts);
214
- }
215
- function resolvePath(...paths) {
216
- let result = "";
217
- for (let path of paths) {
218
- if (path.startsWith("/")) {
219
- result = path;
220
- } else {
221
- result = normalizePath(joinPath(result, path));
222
- }
223
- }
224
- return result;
225
- }
226
- function joinPath(...parts) {
227
- if (parts.length === 0)
228
- return "";
229
- let path = parts.join("/");
230
- path = path.replace(/\/{2,}/g, "/");
231
- return path;
232
- }
233
- function splitPath(path) {
234
- if (path.length === 0)
235
- return [];
236
- if (path === "/")
237
- return ["/"];
238
- let parts = path.split("/");
239
- if (parts[parts.length - 1] === "") {
240
- parts.pop();
241
- }
242
- if (path[0] === "/") {
243
- parts[0] = "/";
244
- } else {
245
- if (parts[0] !== ".") {
246
- parts.unshift(".");
247
- }
248
- }
249
- return parts;
250
- }
251
- function dirname(path) {
252
- const last = path.lastIndexOf("/");
253
- if (last === -1)
254
- throw new Error(`Cannot get dirname of "${path}"`);
255
- if (last === 0)
256
- return "/";
257
- return path.slice(0, last);
258
- }
259
- function basename(path) {
260
- if (path === "/")
261
- throw new Error(`Cannot get basename of "${path}"`);
262
- const last = path.lastIndexOf("/");
263
- if (last === -1)
264
- return path;
265
- return path.slice(last + 1);
266
- }
267
- function reducer(ancestors, current) {
268
- if (ancestors.length === 0) {
269
- ancestors.push(current);
270
- return ancestors;
271
- }
272
- if (current === ".")
273
- return ancestors;
274
- if (current === "..") {
275
- if (ancestors.length === 1) {
276
- if (ancestors[0] === "/") {
277
- throw new Error("Unable to normalize path - traverses above root directory");
278
- }
279
- if (ancestors[0] === ".") {
280
- ancestors.push(current);
281
- return ancestors;
282
- }
283
- }
284
- if (ancestors[ancestors.length - 1] === "..") {
285
- ancestors.push("..");
286
- return ancestors;
287
- } else {
288
- ancestors.pop();
289
- return ancestors;
290
- }
291
- }
292
- ancestors.push(current);
293
- return ancestors;
294
- }
295
- module.exports = {
296
- join: joinPath,
297
- normalize: normalizePath,
298
- split: splitPath,
299
- basename,
300
- dirname,
301
- resolve: resolvePath
302
- };
303
- });
304
- var require_errors = __commonJS((exports, module) => {
305
- function Err(name) {
306
- return class extends Error {
307
- constructor(...args) {
308
- super(...args);
309
- this.code = name;
310
- if (this.message) {
311
- this.message = name + ": " + this.message;
312
- } else {
313
- this.message = name;
314
- }
315
- }
316
- };
317
- }
318
- var EEXIST = Err("EEXIST");
319
- var ENOENT = Err("ENOENT");
320
- var ENOTDIR = Err("ENOTDIR");
321
- var ENOTEMPTY = Err("ENOTEMPTY");
322
- var ETIMEDOUT = Err("ETIMEDOUT");
323
- var EISDIR = Err("EISDIR");
324
- module.exports = { EEXIST, ENOENT, ENOTDIR, ENOTEMPTY, ETIMEDOUT, EISDIR };
325
- });
326
- var require_CacheFS = __commonJS((exports, module) => {
327
- var path = require_path();
328
- var { EEXIST, ENOENT, ENOTDIR, ENOTEMPTY, EISDIR } = require_errors();
329
- var STAT = 0;
330
- module.exports = class CacheFS {
331
- constructor() {}
332
- _makeRoot(root = new Map) {
333
- root.set(STAT, { mode: 511, type: "dir", size: 0, ino: 0, mtimeMs: Date.now() });
334
- return root;
335
- }
336
- activate(superblock = null) {
337
- if (superblock === null) {
338
- this._root = new Map([["/", this._makeRoot()]]);
339
- } else if (typeof superblock === "string") {
340
- this._root = new Map([["/", this._makeRoot(this.parse(superblock))]]);
341
- } else {
342
- this._root = superblock;
343
- }
344
- }
345
- get activated() {
346
- return !!this._root;
347
- }
348
- deactivate() {
349
- this._root = undefined;
350
- }
351
- size() {
352
- return this._countInodes(this._root.get("/")) - 1;
353
- }
354
- _countInodes(map) {
355
- let count = 1;
356
- for (let [key, val] of map) {
357
- if (key === STAT)
358
- continue;
359
- count += this._countInodes(val);
360
- }
361
- return count;
362
- }
363
- autoinc() {
364
- let val = this._maxInode(this._root.get("/")) + 1;
365
- return val;
366
- }
367
- _maxInode(map) {
368
- let max = map.get(STAT).ino;
369
- for (let [key, val] of map) {
370
- if (key === STAT)
371
- continue;
372
- max = Math.max(max, this._maxInode(val));
373
- }
374
- return max;
375
- }
376
- print(root = this._root.get("/")) {
377
- let str = "";
378
- const printTree = (root2, indent) => {
379
- for (let [file, node] of root2) {
380
- if (file === 0)
381
- continue;
382
- let stat = node.get(STAT);
383
- let mode = stat.mode.toString(8);
384
- str += `${"\t".repeat(indent)}${file} ${mode}`;
385
- if (stat.type === "file") {
386
- str += ` ${stat.size} ${stat.mtimeMs}
387
- `;
388
- } else {
389
- str += `
390
- `;
391
- printTree(node, indent + 1);
392
- }
393
- }
394
- };
395
- printTree(root, 0);
396
- return str;
397
- }
398
- parse(print) {
399
- let autoinc = 0;
400
- function mk(stat) {
401
- const ino = ++autoinc;
402
- const type = stat.length === 1 ? "dir" : "file";
403
- let [mode, size, mtimeMs] = stat;
404
- mode = parseInt(mode, 8);
405
- size = size ? parseInt(size) : 0;
406
- mtimeMs = mtimeMs ? parseInt(mtimeMs) : Date.now();
407
- return new Map([[STAT, { mode, type, size, mtimeMs, ino }]]);
408
- }
409
- let lines = print.trim().split(`
410
- `);
411
- let _root = this._makeRoot();
412
- let stack = [
413
- { indent: -1, node: _root },
414
- { indent: 0, node: null }
415
- ];
416
- for (let line of lines) {
417
- let prefix = line.match(/^\t*/)[0];
418
- let indent = prefix.length;
419
- line = line.slice(indent);
420
- let [filename, ...stat] = line.split("\t");
421
- let node = mk(stat);
422
- if (indent <= stack[stack.length - 1].indent) {
423
- while (indent <= stack[stack.length - 1].indent) {
424
- stack.pop();
425
- }
426
- }
427
- stack.push({ indent, node });
428
- let cd = stack[stack.length - 2].node;
429
- cd.set(filename, node);
430
- }
431
- return _root;
432
- }
433
- _lookup(filepath, follow = true) {
434
- let dir = this._root;
435
- let partialPath = "/";
436
- let parts = path.split(filepath);
437
- for (let i = 0;i < parts.length; ++i) {
438
- let part = parts[i];
439
- dir = dir.get(part);
440
- if (!dir)
441
- throw new ENOENT(filepath);
442
- if (follow || i < parts.length - 1) {
443
- const stat = dir.get(STAT);
444
- if (stat.type === "symlink") {
445
- let target = path.resolve(partialPath, stat.target);
446
- dir = this._lookup(target);
447
- }
448
- if (!partialPath) {
449
- partialPath = part;
450
- } else {
451
- partialPath = path.join(partialPath, part);
452
- }
453
- }
454
- }
455
- return dir;
456
- }
457
- mkdir(filepath, { mode }) {
458
- if (filepath === "/")
459
- throw new EEXIST;
460
- let dir = this._lookup(path.dirname(filepath));
461
- let basename = path.basename(filepath);
462
- if (dir.has(basename)) {
463
- throw new EEXIST;
464
- }
465
- let entry = new Map;
466
- let stat = {
467
- mode,
468
- type: "dir",
469
- size: 0,
470
- mtimeMs: Date.now(),
471
- ino: this.autoinc()
472
- };
473
- entry.set(STAT, stat);
474
- dir.set(basename, entry);
475
- }
476
- rmdir(filepath) {
477
- let dir = this._lookup(filepath);
478
- if (dir.get(STAT).type !== "dir")
479
- throw new ENOTDIR;
480
- if (dir.size > 1)
481
- throw new ENOTEMPTY;
482
- let parent = this._lookup(path.dirname(filepath));
483
- let basename = path.basename(filepath);
484
- parent.delete(basename);
485
- }
486
- readdir(filepath) {
487
- let dir = this._lookup(filepath);
488
- if (dir.get(STAT).type !== "dir")
489
- throw new ENOTDIR;
490
- return [...dir.keys()].filter((key) => typeof key === "string");
491
- }
492
- writeStat(filepath, size, { mode }) {
493
- let ino;
494
- let oldStat;
495
- try {
496
- oldStat = this.stat(filepath);
497
- } catch (err) {}
498
- if (oldStat !== undefined) {
499
- if (oldStat.type === "dir") {
500
- throw new EISDIR;
501
- }
502
- if (mode == null) {
503
- mode = oldStat.mode;
504
- }
505
- ino = oldStat.ino;
506
- }
507
- if (mode == null) {
508
- mode = 438;
509
- }
510
- if (ino == null) {
511
- ino = this.autoinc();
512
- }
513
- let dir = this._lookup(path.dirname(filepath));
514
- let basename = path.basename(filepath);
515
- let stat = {
516
- mode,
517
- type: "file",
518
- size,
519
- mtimeMs: Date.now(),
520
- ino
521
- };
522
- let entry = new Map;
523
- entry.set(STAT, stat);
524
- dir.set(basename, entry);
525
- return stat;
526
- }
527
- unlink(filepath) {
528
- let parent = this._lookup(path.dirname(filepath));
529
- let basename = path.basename(filepath);
530
- parent.delete(basename);
531
- }
532
- rename(oldFilepath, newFilepath) {
533
- let basename = path.basename(newFilepath);
534
- let entry = this._lookup(oldFilepath);
535
- let destDir = this._lookup(path.dirname(newFilepath));
536
- destDir.set(basename, entry);
537
- this.unlink(oldFilepath);
538
- }
539
- stat(filepath) {
540
- return this._lookup(filepath).get(STAT);
541
- }
542
- lstat(filepath) {
543
- return this._lookup(filepath, false).get(STAT);
544
- }
545
- readlink(filepath) {
546
- return this._lookup(filepath, false).get(STAT).target;
547
- }
548
- symlink(target, filepath) {
549
- let ino, mode;
550
- try {
551
- let oldStat = this.stat(filepath);
552
- if (mode === null) {
553
- mode = oldStat.mode;
554
- }
555
- ino = oldStat.ino;
556
- } catch (err) {}
557
- if (mode == null) {
558
- mode = 40960;
559
- }
560
- if (ino == null) {
561
- ino = this.autoinc();
562
- }
563
- let dir = this._lookup(path.dirname(filepath));
564
- let basename = path.basename(filepath);
565
- let stat = {
566
- mode,
567
- type: "symlink",
568
- target,
569
- size: 0,
570
- mtimeMs: Date.now(),
571
- ino
572
- };
573
- let entry = new Map;
574
- entry.set(STAT, stat);
575
- dir.set(basename, entry);
576
- return stat;
577
- }
578
- _du(dir) {
579
- let size = 0;
580
- for (const [name, entry] of dir.entries()) {
581
- if (name === STAT) {
582
- size += entry.size;
583
- } else {
584
- size += this._du(entry);
585
- }
586
- }
587
- return size;
588
- }
589
- du(filepath) {
590
- let dir = this._lookup(filepath);
591
- return this._du(dir);
592
- }
593
- };
594
- });
595
- var require_idb_keyval_cjs = __commonJS((exports) => {
596
- Object.defineProperty(exports, "__esModule", { value: true });
597
-
598
- class Store {
599
- constructor(dbName = "keyval-store", storeName = "keyval") {
600
- this.storeName = storeName;
601
- this._dbName = dbName;
602
- this._storeName = storeName;
603
- this._init();
604
- }
605
- _init() {
606
- if (this._dbp) {
607
- return;
608
- }
609
- this._dbp = new Promise((resolve, reject) => {
610
- const openreq = indexedDB.open(this._dbName);
611
- openreq.onerror = () => reject(openreq.error);
612
- openreq.onsuccess = () => resolve(openreq.result);
613
- openreq.onupgradeneeded = () => {
614
- openreq.result.createObjectStore(this._storeName);
615
- };
616
- });
617
- }
618
- _withIDBStore(type, callback) {
619
- this._init();
620
- return this._dbp.then((db) => new Promise((resolve, reject) => {
621
- const transaction = db.transaction(this.storeName, type);
622
- transaction.oncomplete = () => resolve();
623
- transaction.onabort = transaction.onerror = () => reject(transaction.error);
624
- callback(transaction.objectStore(this.storeName));
625
- }));
626
- }
627
- _close() {
628
- this._init();
629
- return this._dbp.then((db) => {
630
- db.close();
631
- this._dbp = undefined;
632
- });
633
- }
634
- }
635
- var store;
636
- function getDefaultStore() {
637
- if (!store)
638
- store = new Store;
639
- return store;
640
- }
641
- function get(key, store2 = getDefaultStore()) {
642
- let req;
643
- return store2._withIDBStore("readwrite", (store3) => {
644
- req = store3.get(key);
645
- }).then(() => req.result);
646
- }
647
- function set(key, value, store2 = getDefaultStore()) {
648
- return store2._withIDBStore("readwrite", (store3) => {
649
- store3.put(value, key);
650
- });
651
- }
652
- function update(key, updater, store2 = getDefaultStore()) {
653
- return store2._withIDBStore("readwrite", (store3) => {
654
- const req = store3.get(key);
655
- req.onsuccess = () => {
656
- store3.put(updater(req.result), key);
657
- };
658
- });
659
- }
660
- function del(key, store2 = getDefaultStore()) {
661
- return store2._withIDBStore("readwrite", (store3) => {
662
- store3.delete(key);
663
- });
664
- }
665
- function clear(store2 = getDefaultStore()) {
666
- return store2._withIDBStore("readwrite", (store3) => {
667
- store3.clear();
668
- });
669
- }
670
- function keys(store2 = getDefaultStore()) {
671
- const keys2 = [];
672
- return store2._withIDBStore("readwrite", (store3) => {
673
- (store3.openKeyCursor || store3.openCursor).call(store3).onsuccess = function() {
674
- if (!this.result)
675
- return;
676
- keys2.push(this.result.key);
677
- this.result.continue();
678
- };
679
- }).then(() => keys2);
680
- }
681
- function close(store2 = getDefaultStore()) {
682
- return store2._close();
683
- }
684
- exports.Store = Store;
685
- exports.get = get;
686
- exports.set = set;
687
- exports.update = update;
688
- exports.del = del;
689
- exports.clear = clear;
690
- exports.keys = keys;
691
- exports.close = close;
692
- });
693
- var require_IdbBackend = __commonJS((exports, module) => {
694
- var idb = require_idb_keyval_cjs();
695
- module.exports = class IdbBackend {
696
- constructor(dbname, storename) {
697
- this._database = dbname;
698
- this._storename = storename;
699
- this._store = new idb.Store(this._database, this._storename);
700
- }
701
- saveSuperblock(superblock) {
702
- return idb.set("!root", superblock, this._store);
703
- }
704
- loadSuperblock() {
705
- return idb.get("!root", this._store);
706
- }
707
- readFile(inode) {
708
- return idb.get(inode, this._store);
709
- }
710
- writeFile(inode, data) {
711
- return idb.set(inode, data, this._store);
712
- }
713
- unlink(inode) {
714
- return idb.del(inode, this._store);
715
- }
716
- wipe() {
717
- return idb.clear(this._store);
718
- }
719
- close() {
720
- return idb.close(this._store);
721
- }
722
- };
723
- });
724
- var require_HttpBackend = __commonJS((exports, module) => {
725
- module.exports = class HttpBackend {
726
- constructor(url) {
727
- this._url = url;
728
- }
729
- loadSuperblock() {
730
- return fetch(this._url + "/.superblock.txt").then((res) => res.ok ? res.text() : null);
731
- }
732
- async readFile(filepath) {
733
- const res = await fetch(this._url + filepath);
734
- if (res.status === 200) {
735
- return res.arrayBuffer();
736
- } else {
737
- throw new Error("ENOENT");
738
- }
739
- }
740
- async sizeFile(filepath) {
741
- const res = await fetch(this._url + filepath, { method: "HEAD" });
742
- if (res.status === 200) {
743
- return res.headers.get("content-length");
744
- } else {
745
- throw new Error("ENOENT");
746
- }
747
- }
748
- };
749
- });
750
- var require_Mutex = __commonJS((exports, module) => {
751
- var idb = require_idb_keyval_cjs();
752
- var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
753
- module.exports = class Mutex {
754
- constructor(dbname, storename) {
755
- this._id = Math.random();
756
- this._database = dbname;
757
- this._storename = storename;
758
- this._store = new idb.Store(this._database, this._storename);
759
- this._lock = null;
760
- }
761
- async has({ margin = 2000 } = {}) {
762
- if (this._lock && this._lock.holder === this._id) {
763
- const now = Date.now();
764
- if (this._lock.expires > now + margin) {
765
- return true;
766
- } else {
767
- return await this.renew();
768
- }
769
- } else {
770
- return false;
771
- }
772
- }
773
- async renew({ ttl = 5000 } = {}) {
774
- let success;
775
- await idb.update("lock", (current) => {
776
- const now = Date.now();
777
- const expires = now + ttl;
778
- success = current && current.holder === this._id;
779
- this._lock = success ? { holder: this._id, expires } : current;
780
- return this._lock;
781
- }, this._store);
782
- return success;
783
- }
784
- async acquire({ ttl = 5000 } = {}) {
785
- let success;
786
- let expired;
787
- let doubleLock;
788
- await idb.update("lock", (current) => {
789
- const now = Date.now();
790
- const expires = now + ttl;
791
- expired = current && current.expires < now;
792
- success = current === undefined || expired;
793
- doubleLock = current && current.holder === this._id;
794
- this._lock = success ? { holder: this._id, expires } : current;
795
- return this._lock;
796
- }, this._store);
797
- if (doubleLock) {
798
- throw new Error("Mutex double-locked");
799
- }
800
- return success;
801
- }
802
- async wait({ interval = 100, limit = 6000, ttl } = {}) {
803
- while (limit--) {
804
- if (await this.acquire({ ttl }))
805
- return true;
806
- await sleep(interval);
807
- }
808
- throw new Error("Mutex timeout");
809
- }
810
- async release({ force = false } = {}) {
811
- let success;
812
- let doubleFree;
813
- let someoneElseHasIt;
814
- await idb.update("lock", (current) => {
815
- success = force || current && current.holder === this._id;
816
- doubleFree = current === undefined;
817
- someoneElseHasIt = current && current.holder !== this._id;
818
- this._lock = success ? undefined : current;
819
- return this._lock;
820
- }, this._store);
821
- await idb.close(this._store);
822
- if (!success && !force) {
823
- if (doubleFree)
824
- throw new Error("Mutex double-freed");
825
- if (someoneElseHasIt)
826
- throw new Error("Mutex lost ownership");
827
- }
828
- return success;
829
- }
830
- };
831
- });
832
- var require_Mutex2 = __commonJS((exports, module) => {
833
- module.exports = class Mutex {
834
- constructor(name) {
835
- this._id = Math.random();
836
- this._database = name;
837
- this._has = false;
838
- this._release = null;
839
- }
840
- async has() {
841
- return this._has;
842
- }
843
- async acquire() {
844
- return new Promise((resolve) => {
845
- navigator.locks.request(this._database + "_lock", { ifAvailable: true }, (lock) => {
846
- this._has = !!lock;
847
- resolve(!!lock);
848
- return new Promise((resolve2) => {
849
- this._release = resolve2;
850
- });
851
- });
852
- });
853
- }
854
- async wait({ timeout = 600000 } = {}) {
855
- return new Promise((resolve, reject) => {
856
- const controller = new AbortController;
857
- setTimeout(() => {
858
- controller.abort();
859
- reject(new Error("Mutex timeout"));
860
- }, timeout);
861
- navigator.locks.request(this._database + "_lock", { signal: controller.signal }, (lock) => {
862
- this._has = !!lock;
863
- resolve(!!lock);
864
- return new Promise((resolve2) => {
865
- this._release = resolve2;
866
- });
867
- });
868
- });
869
- }
870
- async release({ force = false } = {}) {
871
- this._has = false;
872
- if (this._release) {
873
- this._release();
874
- } else if (force) {
875
- navigator.locks.request(this._database + "_lock", { steal: true }, (lock) => true);
876
- }
877
- }
878
- };
879
- });
880
- var require_DefaultBackend = __commonJS((exports, module) => {
881
- var { encode, decode } = require_browser();
882
- var debounce = require_just_debounce_it();
883
- var CacheFS = require_CacheFS();
884
- var { ENOENT, ENOTEMPTY, ETIMEDOUT } = require_errors();
885
- var IdbBackend = require_IdbBackend();
886
- var HttpBackend = require_HttpBackend();
887
- var Mutex = require_Mutex();
888
- var Mutex2 = require_Mutex2();
889
- var path = require_path();
890
- module.exports = class DefaultBackend {
891
- constructor() {
892
- this.saveSuperblock = debounce(() => {
893
- this.flush();
894
- }, 500);
895
- }
896
- async init(name, {
897
- wipe,
898
- url,
899
- urlauto,
900
- fileDbName = name,
901
- db = null,
902
- fileStoreName = name + "_files",
903
- lockDbName = name + "_lock",
904
- lockStoreName = name + "_lock"
905
- } = {}) {
906
- this._name = name;
907
- this._idb = db || new IdbBackend(fileDbName, fileStoreName);
908
- this._mutex = navigator.locks ? new Mutex2(name) : new Mutex(lockDbName, lockStoreName);
909
- this._cache = new CacheFS(name);
910
- this._opts = { wipe, url };
911
- this._needsWipe = !!wipe;
912
- if (url) {
913
- this._http = new HttpBackend(url);
914
- this._urlauto = !!urlauto;
915
- }
916
- }
917
- async activate() {
918
- if (this._cache.activated)
919
- return;
920
- if (this._needsWipe) {
921
- this._needsWipe = false;
922
- await this._idb.wipe();
923
- await this._mutex.release({ force: true });
924
- }
925
- if (!await this._mutex.has())
926
- await this._mutex.wait();
927
- const root = await this._idb.loadSuperblock();
928
- if (root) {
929
- this._cache.activate(root);
930
- } else if (this._http) {
931
- const text = await this._http.loadSuperblock();
932
- this._cache.activate(text);
933
- await this._saveSuperblock();
934
- } else {
935
- this._cache.activate();
936
- }
937
- if (await this._mutex.has()) {
938
- return;
939
- } else {
940
- throw new ETIMEDOUT;
941
- }
942
- }
943
- async deactivate() {
944
- if (await this._mutex.has()) {
945
- await this._saveSuperblock();
946
- }
947
- this._cache.deactivate();
948
- try {
949
- await this._mutex.release();
950
- } catch (e) {
951
- console.log(e);
952
- }
953
- await this._idb.close();
954
- }
955
- async _saveSuperblock() {
956
- if (this._cache.activated) {
957
- this._lastSavedAt = Date.now();
958
- await this._idb.saveSuperblock(this._cache._root);
959
- }
960
- }
961
- _writeStat(filepath, size, opts) {
962
- let dirparts = path.split(path.dirname(filepath));
963
- let dir = dirparts.shift();
964
- for (let dirpart of dirparts) {
965
- dir = path.join(dir, dirpart);
966
- try {
967
- this._cache.mkdir(dir, { mode: 511 });
968
- } catch (e) {}
969
- }
970
- return this._cache.writeStat(filepath, size, opts);
971
- }
972
- async readFile(filepath, opts) {
973
- const encoding = typeof opts === "string" ? opts : opts && opts.encoding;
974
- if (encoding && encoding !== "utf8")
975
- throw new Error('Only "utf8" encoding is supported in readFile');
976
- let data = null, stat = null;
977
- try {
978
- stat = this._cache.stat(filepath);
979
- data = await this._idb.readFile(stat.ino);
980
- } catch (e) {
981
- if (!this._urlauto)
982
- throw e;
983
- }
984
- if (!data && this._http) {
985
- let lstat = this._cache.lstat(filepath);
986
- while (lstat.type === "symlink") {
987
- filepath = path.resolve(path.dirname(filepath), lstat.target);
988
- lstat = this._cache.lstat(filepath);
989
- }
990
- data = await this._http.readFile(filepath);
991
- }
992
- if (data) {
993
- if (!stat || stat.size != data.byteLength) {
994
- stat = await this._writeStat(filepath, data.byteLength, { mode: stat ? stat.mode : 438 });
995
- this.saveSuperblock();
996
- }
997
- if (encoding === "utf8") {
998
- data = decode(data);
999
- } else {
1000
- data.toString = () => decode(data);
1001
- }
1002
- }
1003
- if (!stat)
1004
- throw new ENOENT(filepath);
1005
- return data;
1006
- }
1007
- async writeFile(filepath, data, opts) {
1008
- const { mode, encoding = "utf8" } = opts;
1009
- if (typeof data === "string") {
1010
- if (encoding !== "utf8") {
1011
- throw new Error('Only "utf8" encoding is supported in writeFile');
1012
- }
1013
- data = encode(data);
1014
- }
1015
- const stat = await this._cache.writeStat(filepath, data.byteLength, { mode });
1016
- await this._idb.writeFile(stat.ino, data);
1017
- }
1018
- async unlink(filepath, opts) {
1019
- const stat = this._cache.lstat(filepath);
1020
- this._cache.unlink(filepath);
1021
- if (stat.type !== "symlink") {
1022
- await this._idb.unlink(stat.ino);
1023
- }
1024
- }
1025
- readdir(filepath, opts) {
1026
- return this._cache.readdir(filepath);
1027
- }
1028
- mkdir(filepath, opts) {
1029
- const { mode = 511 } = opts;
1030
- this._cache.mkdir(filepath, { mode });
1031
- }
1032
- rmdir(filepath, opts) {
1033
- if (filepath === "/") {
1034
- throw new ENOTEMPTY;
1035
- }
1036
- this._cache.rmdir(filepath);
1037
- }
1038
- rename(oldFilepath, newFilepath) {
1039
- this._cache.rename(oldFilepath, newFilepath);
1040
- }
1041
- stat(filepath, opts) {
1042
- return this._cache.stat(filepath);
1043
- }
1044
- lstat(filepath, opts) {
1045
- return this._cache.lstat(filepath);
1046
- }
1047
- readlink(filepath, opts) {
1048
- return this._cache.readlink(filepath);
1049
- }
1050
- symlink(target, filepath) {
1051
- this._cache.symlink(target, filepath);
1052
- }
1053
- async backFile(filepath, opts) {
1054
- let size = await this._http.sizeFile(filepath);
1055
- await this._writeStat(filepath, size, opts);
1056
- }
1057
- du(filepath) {
1058
- return this._cache.du(filepath);
1059
- }
1060
- flush() {
1061
- return this._saveSuperblock();
1062
- }
1063
- };
1064
- });
1065
- var require_Stat = __commonJS((exports, module) => {
1066
- module.exports = class Stat {
1067
- constructor(stats) {
1068
- this.type = stats.type;
1069
- this.mode = stats.mode;
1070
- this.size = stats.size;
1071
- this.ino = stats.ino;
1072
- this.mtimeMs = stats.mtimeMs;
1073
- this.ctimeMs = stats.ctimeMs || stats.mtimeMs;
1074
- this.uid = 1;
1075
- this.gid = 1;
1076
- this.dev = 1;
1077
- }
1078
- isFile() {
1079
- return this.type === "file";
1080
- }
1081
- isDirectory() {
1082
- return this.type === "dir";
1083
- }
1084
- isSymbolicLink() {
1085
- return this.type === "symlink";
1086
- }
1087
- };
1088
- });
1089
- var require_PromisifiedFS = __commonJS((exports, module) => {
1090
- var DefaultBackend = require_DefaultBackend();
1091
- var Stat = require_Stat();
1092
- var path = require_path();
1093
- function cleanParamsFilepathOpts(filepath, opts, ...rest) {
1094
- filepath = path.normalize(filepath);
1095
- if (typeof opts === "undefined" || typeof opts === "function") {
1096
- opts = {};
1097
- }
1098
- if (typeof opts === "string") {
1099
- opts = {
1100
- encoding: opts
1101
- };
1102
- }
1103
- return [filepath, opts, ...rest];
1104
- }
1105
- function cleanParamsFilepathDataOpts(filepath, data, opts, ...rest) {
1106
- filepath = path.normalize(filepath);
1107
- if (typeof opts === "undefined" || typeof opts === "function") {
1108
- opts = {};
1109
- }
1110
- if (typeof opts === "string") {
1111
- opts = {
1112
- encoding: opts
1113
- };
1114
- }
1115
- return [filepath, data, opts, ...rest];
1116
- }
1117
- function cleanParamsFilepathFilepath(oldFilepath, newFilepath, ...rest) {
1118
- return [path.normalize(oldFilepath), path.normalize(newFilepath), ...rest];
1119
- }
1120
- module.exports = class PromisifiedFS {
1121
- constructor(name, options = {}) {
1122
- this.init = this.init.bind(this);
1123
- this.readFile = this._wrap(this.readFile, cleanParamsFilepathOpts, false);
1124
- this.writeFile = this._wrap(this.writeFile, cleanParamsFilepathDataOpts, true);
1125
- this.unlink = this._wrap(this.unlink, cleanParamsFilepathOpts, true);
1126
- this.readdir = this._wrap(this.readdir, cleanParamsFilepathOpts, false);
1127
- this.mkdir = this._wrap(this.mkdir, cleanParamsFilepathOpts, true);
1128
- this.rmdir = this._wrap(this.rmdir, cleanParamsFilepathOpts, true);
1129
- this.rename = this._wrap(this.rename, cleanParamsFilepathFilepath, true);
1130
- this.stat = this._wrap(this.stat, cleanParamsFilepathOpts, false);
1131
- this.lstat = this._wrap(this.lstat, cleanParamsFilepathOpts, false);
1132
- this.readlink = this._wrap(this.readlink, cleanParamsFilepathOpts, false);
1133
- this.symlink = this._wrap(this.symlink, cleanParamsFilepathFilepath, true);
1134
- this.backFile = this._wrap(this.backFile, cleanParamsFilepathOpts, true);
1135
- this.du = this._wrap(this.du, cleanParamsFilepathOpts, false);
1136
- this._deactivationPromise = null;
1137
- this._deactivationTimeout = null;
1138
- this._activationPromise = null;
1139
- this._operations = new Set;
1140
- if (name) {
1141
- this.init(name, options);
1142
- }
1143
- }
1144
- async init(...args) {
1145
- if (this._initPromiseResolve)
1146
- await this._initPromise;
1147
- this._initPromise = this._init(...args);
1148
- return this._initPromise;
1149
- }
1150
- async _init(name, options = {}) {
1151
- await this._gracefulShutdown();
1152
- if (this._activationPromise)
1153
- await this._deactivate();
1154
- if (this._backend && this._backend.destroy) {
1155
- await this._backend.destroy();
1156
- }
1157
- this._backend = options.backend || new DefaultBackend;
1158
- if (this._backend.init) {
1159
- await this._backend.init(name, options);
1160
- }
1161
- if (this._initPromiseResolve) {
1162
- this._initPromiseResolve();
1163
- this._initPromiseResolve = null;
1164
- }
1165
- if (!options.defer) {
1166
- this.stat("/");
1167
- }
1168
- }
1169
- async _gracefulShutdown() {
1170
- if (this._operations.size > 0) {
1171
- this._isShuttingDown = true;
1172
- await new Promise((resolve) => this._gracefulShutdownResolve = resolve);
1173
- this._isShuttingDown = false;
1174
- this._gracefulShutdownResolve = null;
1175
- }
1176
- }
1177
- _wrap(fn, paramCleaner, mutating) {
1178
- return async (...args) => {
1179
- args = paramCleaner(...args);
1180
- let op = {
1181
- name: fn.name,
1182
- args
1183
- };
1184
- this._operations.add(op);
1185
- try {
1186
- await this._activate();
1187
- return await fn.apply(this, args);
1188
- } finally {
1189
- this._operations.delete(op);
1190
- if (mutating)
1191
- this._backend.saveSuperblock();
1192
- if (this._operations.size === 0) {
1193
- if (!this._deactivationTimeout)
1194
- clearTimeout(this._deactivationTimeout);
1195
- this._deactivationTimeout = setTimeout(this._deactivate.bind(this), 500);
1196
- }
1197
- }
1198
- };
1199
- }
1200
- async _activate() {
1201
- if (!this._initPromise)
1202
- console.warn(new Error(`Attempted to use LightningFS ${this._name} before it was initialized.`));
1203
- await this._initPromise;
1204
- if (this._deactivationTimeout) {
1205
- clearTimeout(this._deactivationTimeout);
1206
- this._deactivationTimeout = null;
1207
- }
1208
- if (this._deactivationPromise)
1209
- await this._deactivationPromise;
1210
- this._deactivationPromise = null;
1211
- if (!this._activationPromise) {
1212
- this._activationPromise = this._backend.activate ? this._backend.activate() : Promise.resolve();
1213
- }
1214
- await this._activationPromise;
1215
- }
1216
- async _deactivate() {
1217
- if (this._activationPromise)
1218
- await this._activationPromise;
1219
- if (!this._deactivationPromise) {
1220
- this._deactivationPromise = this._backend.deactivate ? this._backend.deactivate() : Promise.resolve();
1221
- }
1222
- this._activationPromise = null;
1223
- if (this._gracefulShutdownResolve)
1224
- this._gracefulShutdownResolve();
1225
- return this._deactivationPromise;
1226
- }
1227
- async readFile(filepath, opts) {
1228
- return this._backend.readFile(filepath, opts);
1229
- }
1230
- async writeFile(filepath, data, opts) {
1231
- await this._backend.writeFile(filepath, data, opts);
1232
- return null;
1233
- }
1234
- async unlink(filepath, opts) {
1235
- await this._backend.unlink(filepath, opts);
1236
- return null;
1237
- }
1238
- async readdir(filepath, opts) {
1239
- return this._backend.readdir(filepath, opts);
1240
- }
1241
- async mkdir(filepath, opts) {
1242
- await this._backend.mkdir(filepath, opts);
1243
- return null;
1244
- }
1245
- async rmdir(filepath, opts) {
1246
- await this._backend.rmdir(filepath, opts);
1247
- return null;
1248
- }
1249
- async rename(oldFilepath, newFilepath) {
1250
- await this._backend.rename(oldFilepath, newFilepath);
1251
- return null;
1252
- }
1253
- async stat(filepath, opts) {
1254
- const data = await this._backend.stat(filepath, opts);
1255
- return new Stat(data);
1256
- }
1257
- async lstat(filepath, opts) {
1258
- const data = await this._backend.lstat(filepath, opts);
1259
- return new Stat(data);
1260
- }
1261
- async readlink(filepath, opts) {
1262
- return this._backend.readlink(filepath, opts);
1263
- }
1264
- async symlink(target, filepath) {
1265
- await this._backend.symlink(target, filepath);
1266
- return null;
1267
- }
1268
- async backFile(filepath, opts) {
1269
- await this._backend.backFile(filepath, opts);
1270
- return null;
1271
- }
1272
- async du(filepath) {
1273
- return this._backend.du(filepath);
1274
- }
1275
- async flush() {
1276
- return this._backend.flush();
1277
- }
1278
- };
1279
- });
1280
- var require_src = __commonJS((exports, module) => {
1281
- var once = require_just_once();
1282
- var PromisifiedFS = require_PromisifiedFS();
1283
- function wrapCallback(opts, cb) {
1284
- if (typeof opts === "function") {
1285
- cb = opts;
1286
- }
1287
- cb = once(cb);
1288
- const resolve = (...args) => cb(null, ...args);
1289
- return [resolve, cb];
1290
- }
1291
- module.exports = class FS {
1292
- constructor(...args) {
1293
- this.promises = new PromisifiedFS(...args);
1294
- this.init = this.init.bind(this);
1295
- this.readFile = this.readFile.bind(this);
1296
- this.writeFile = this.writeFile.bind(this);
1297
- this.unlink = this.unlink.bind(this);
1298
- this.readdir = this.readdir.bind(this);
1299
- this.mkdir = this.mkdir.bind(this);
1300
- this.rmdir = this.rmdir.bind(this);
1301
- this.rename = this.rename.bind(this);
1302
- this.stat = this.stat.bind(this);
1303
- this.lstat = this.lstat.bind(this);
1304
- this.readlink = this.readlink.bind(this);
1305
- this.symlink = this.symlink.bind(this);
1306
- this.backFile = this.backFile.bind(this);
1307
- this.du = this.du.bind(this);
1308
- this.flush = this.flush.bind(this);
1309
- }
1310
- init(name, options) {
1311
- return this.promises.init(name, options);
1312
- }
1313
- readFile(filepath, opts, cb) {
1314
- const [resolve, reject] = wrapCallback(opts, cb);
1315
- this.promises.readFile(filepath, opts).then(resolve).catch(reject);
1316
- }
1317
- writeFile(filepath, data, opts, cb) {
1318
- const [resolve, reject] = wrapCallback(opts, cb);
1319
- this.promises.writeFile(filepath, data, opts).then(resolve).catch(reject);
1320
- }
1321
- unlink(filepath, opts, cb) {
1322
- const [resolve, reject] = wrapCallback(opts, cb);
1323
- this.promises.unlink(filepath, opts).then(resolve).catch(reject);
1324
- }
1325
- readdir(filepath, opts, cb) {
1326
- const [resolve, reject] = wrapCallback(opts, cb);
1327
- this.promises.readdir(filepath, opts).then(resolve).catch(reject);
1328
- }
1329
- mkdir(filepath, opts, cb) {
1330
- const [resolve, reject] = wrapCallback(opts, cb);
1331
- this.promises.mkdir(filepath, opts).then(resolve).catch(reject);
1332
- }
1333
- rmdir(filepath, opts, cb) {
1334
- const [resolve, reject] = wrapCallback(opts, cb);
1335
- this.promises.rmdir(filepath, opts).then(resolve).catch(reject);
1336
- }
1337
- rename(oldFilepath, newFilepath, cb) {
1338
- const [resolve, reject] = wrapCallback(cb);
1339
- this.promises.rename(oldFilepath, newFilepath).then(resolve).catch(reject);
1340
- }
1341
- stat(filepath, opts, cb) {
1342
- const [resolve, reject] = wrapCallback(opts, cb);
1343
- this.promises.stat(filepath).then(resolve).catch(reject);
1344
- }
1345
- lstat(filepath, opts, cb) {
1346
- const [resolve, reject] = wrapCallback(opts, cb);
1347
- this.promises.lstat(filepath).then(resolve).catch(reject);
1348
- }
1349
- readlink(filepath, opts, cb) {
1350
- const [resolve, reject] = wrapCallback(opts, cb);
1351
- this.promises.readlink(filepath).then(resolve).catch(reject);
1352
- }
1353
- symlink(target, filepath, cb) {
1354
- const [resolve, reject] = wrapCallback(cb);
1355
- this.promises.symlink(target, filepath).then(resolve).catch(reject);
1356
- }
1357
- backFile(filepath, opts, cb) {
1358
- const [resolve, reject] = wrapCallback(opts, cb);
1359
- this.promises.backFile(filepath, opts).then(resolve).catch(reject);
1360
- }
1361
- du(filepath, cb) {
1362
- const [resolve, reject] = wrapCallback(cb);
1363
- this.promises.du(filepath).then(resolve).catch(reject);
1364
- }
1365
- flush(cb) {
1366
- const [resolve, reject] = wrapCallback(cb);
1367
- this.promises.flush().then(resolve).catch(reject);
1368
- }
1369
- };
1370
- });
1371
- var import_lightning_fs = __toESM(require_src(), 1);
1372
- var LOCK_MAX_WAIT_MS = 20000;
1373
- var IN_MEMORY_LOCK_TAILS_KEY = Symbol.for("@uipath/filesystem/lock-tails");
1374
- var getInMemoryLockTails = () => {
1375
- const globalsHost = globalThis;
1376
- const existing = globalsHost[IN_MEMORY_LOCK_TAILS_KEY];
1377
- if (existing && typeof existing.get === "function" && typeof existing.set === "function" && typeof existing.delete === "function") {
1378
- return existing;
1379
- }
1380
- const created = new Map;
1381
- globalsHost[IN_MEMORY_LOCK_TAILS_KEY] = created;
1382
- return created;
1383
- };
1384
- var getWebLocks = () => {
1385
- if (typeof navigator === "undefined")
1386
- return;
1387
- return navigator.locks;
1388
- };
1389
-
1390
- class BrowserFileSystem {
1391
- initialized = false;
1392
- fsInstance = null;
1393
- async init() {
1394
- if (this.initialized)
1395
- return;
1396
- this.fsInstance = new import_lightning_fs.default("uipcli-fs");
1397
- this.initialized = true;
1398
- }
1399
- normalizePath(p) {
1400
- const isAbs = p.startsWith("/");
1401
- const segments = p.split("/");
1402
- const normalized = [];
1403
- for (const seg of segments) {
1404
- if (seg === "." || seg === "")
1405
- continue;
1406
- if (seg === "..") {
1407
- normalized.pop();
1408
- } else {
1409
- normalized.push(seg);
1410
- }
1411
- }
1412
- return (isAbs ? "/" : "") + normalized.join("/");
1413
- }
1414
- path = {
1415
- join: (...paths) => {
1416
- const joined = paths.filter(Boolean).join("/");
1417
- return this.normalizePath(joined);
1418
- },
1419
- resolve: (...paths) => {
1420
- let resolved = "";
1421
- for (let i = paths.length - 1;i >= 0; i--) {
1422
- const p = paths[i];
1423
- if (!p)
1424
- continue;
1425
- resolved = resolved ? `${p}/${resolved}` : p;
1426
- if (p.startsWith("/"))
1427
- break;
1428
- }
1429
- if (!resolved.startsWith("/")) {
1430
- resolved = `/${resolved}`;
1431
- }
1432
- return this.normalizePath(resolved);
1433
- },
1434
- relative: (from, to) => {
1435
- const fromParts = this.normalizePath(from).split("/").filter(Boolean);
1436
- const toParts = this.normalizePath(to).split("/").filter(Boolean);
1437
- let common = 0;
1438
- while (common < fromParts.length && common < toParts.length && fromParts[common] === toParts[common]) {
1439
- common++;
1440
- }
1441
- const ups = Array(fromParts.length - common).fill("..");
1442
- const downs = toParts.slice(common);
1443
- return [...ups, ...downs].join("/") || ".";
1444
- },
1445
- dirname: (p) => {
1446
- const parts = p.split("/").filter(Boolean);
1447
- parts.pop();
1448
- return `/${parts.join("/")}`;
1449
- },
1450
- isAbsolute: (p) => p.startsWith("/"),
1451
- basename: (p, ext) => {
1452
- const parts = p.split("/").filter(Boolean);
1453
- const base = parts[parts.length - 1] || "";
1454
- if (ext && base.endsWith(ext))
1455
- return base.slice(0, -ext.length);
1456
- return base;
1457
- }
1458
- };
1459
- env = {
1460
- cwd: () => "/",
1461
- homedir: () => "/home",
1462
- tmpdir: () => "/tmp",
1463
- getenv: (_key) => {
1464
- return;
1465
- }
1466
- };
1467
- utils = {
1468
- open: async (url) => {
1469
- if (typeof window !== "undefined") {
1470
- window.open(url, "_blank");
1471
- }
1472
- }
1473
- };
1474
- async prepare() {
1475
- await this.init();
1476
- }
1477
- getFs() {
1478
- if (!this.fsInstance) {
1479
- throw new Error("Browser filesystem is not initialized.");
1480
- }
1481
- return this.fsInstance;
1482
- }
1483
- async readFile(path, options) {
1484
- try {
1485
- await this.init();
1486
- const fs = this.getFs();
1487
- if (options) {
1488
- return await fs.promises.readFile(path, "utf8");
1489
- }
1490
- const content = await fs.promises.readFile(path);
1491
- return new Uint8Array(content);
1492
- } catch (error) {
1493
- if (this.isEnoent(error))
1494
- return null;
1495
- throw error;
1496
- }
1497
- }
1498
- async writeFile(filePath, data) {
1499
- await this.init();
1500
- const fs = this.getFs();
1501
- const dir = this.path.dirname(filePath);
1502
- if (dir && dir !== "/") {
1503
- await this.mkdir(dir);
1504
- }
1505
- await fs.promises.writeFile(filePath, data);
1506
- }
1507
- async appendFile(filePath, data) {
1508
- await this.init();
1509
- const fs = this.getFs();
1510
- const dir = this.path.dirname(filePath);
1511
- if (dir && dir !== "/") {
1512
- await this.mkdir(dir);
1513
- }
1514
- const existing = await this.readFile(filePath, "utf-8");
1515
- const head = existing ?? "";
1516
- const tail = typeof data === "string" ? data : new TextDecoder().decode(data);
1517
- await fs.promises.writeFile(filePath, head + tail);
1518
- }
1519
- async readdir(path) {
1520
- try {
1521
- await this.init();
1522
- const fs = this.getFs();
1523
- return await fs.promises.readdir(path);
1524
- } catch (error) {
1525
- if (this.isEnoent(error))
1526
- return [];
1527
- throw error;
1528
- }
1529
- }
1530
- async stat(path) {
1531
- try {
1532
- await this.init();
1533
- const fs = this.getFs();
1534
- const stats = await fs.promises.stat(path);
1535
- return {
1536
- isFile: () => stats.isFile(),
1537
- isDirectory: () => stats.isDirectory(),
1538
- size: stats.size,
1539
- mtimeMs: stats.mtimeMs
1540
- };
1541
- } catch (error) {
1542
- if (this.isEnoent(error))
1543
- return null;
1544
- throw error;
1545
- }
1546
- }
1547
- async exists(path) {
1548
- return await this.stat(path) !== null;
1549
- }
1550
- async mkdir(path) {
1551
- await this.init();
1552
- const fs = this.getFs();
1553
- const normalizedPath = this.normalizePath(path);
1554
- if (normalizedPath === "/" || normalizedPath === "") {
1555
- return;
1556
- }
1557
- const parentDir = this.path.dirname(normalizedPath);
1558
- if (parentDir !== normalizedPath && parentDir !== "/") {
1559
- await this.mkdir(parentDir);
1560
- } else if (parentDir === "/") {
1561
- await this.checkRootDirectory();
1562
- }
1563
- try {
1564
- await fs.promises.mkdir(normalizedPath);
1565
- } catch (error) {
1566
- if (this.isEexist(error))
1567
- return;
1568
- throw error;
1569
- }
1570
- }
1571
- async acquireLock(lockPath) {
1572
- const canonical = this.normalizePath(this.path.isAbsolute(lockPath) ? lockPath : `/${lockPath}`);
1573
- const name = `@uipath/filesystem:lock:${canonical}`;
1574
- const webLocks = getWebLocks();
1575
- if (webLocks) {
1576
- return await this.acquireWebLock(webLocks, name);
1577
- }
1578
- return this.acquireInMemoryLock(name);
1579
- }
1580
- async acquireWebLock(webLocks, name) {
1581
- const abortController = new AbortController;
1582
- const timeoutHandle = setTimeout(() => {
1583
- abortController.abort();
1584
- }, LOCK_MAX_WAIT_MS);
1585
- return await new Promise((resolveAcquire, rejectAcquire) => {
1586
- let releaseHeld;
1587
- const requested = webLocks.request(name, { signal: abortController.signal }, () => new Promise((resolveHeld) => {
1588
- clearTimeout(timeoutHandle);
1589
- releaseHeld = resolveHeld;
1590
- resolveAcquire(async () => {
1591
- resolveHeld();
1592
- });
1593
- }));
1594
- requested.catch((error) => {
1595
- clearTimeout(timeoutHandle);
1596
- if (releaseHeld) {
1597
- return;
1598
- }
1599
- if (error?.name === "AbortError") {
1600
- rejectAcquire(new Error(`ELOCKED: timed out waiting for lock on ${name}`));
1601
- return;
1602
- }
1603
- rejectAcquire(error);
1604
- });
1605
- });
1606
- }
1607
- acquireInMemoryLock(name) {
1608
- const tails = getInMemoryLockTails();
1609
- const prior = tails.get(name) ?? Promise.resolve();
1610
- let releaseHeld;
1611
- const held = new Promise((resolve) => {
1612
- releaseHeld = resolve;
1613
- });
1614
- const chained = prior.then(() => held);
1615
- tails.set(name, chained);
1616
- chained.then(() => {
1617
- if (tails.get(name) === chained) {
1618
- tails.delete(name);
1619
- }
1620
- });
1621
- return new Promise((resolveAcquire, rejectAcquire) => {
1622
- const timer = setTimeout(() => {
1623
- releaseHeld();
1624
- rejectAcquire(new Error(`ELOCKED: timed out waiting for lock on ${name}`));
1625
- }, LOCK_MAX_WAIT_MS);
1626
- prior.then(() => {
1627
- clearTimeout(timer);
1628
- resolveAcquire(async () => {
1629
- releaseHeld();
1630
- });
1631
- });
1632
- });
1633
- }
1634
- async rm(path) {
1635
- await this.init();
1636
- const fs = this.getFs();
1637
- const stats = await this.stat(path);
1638
- if (!stats) {
1639
- return;
1640
- }
1641
- if (stats.isDirectory()) {
1642
- const entries = await this.readdir(path);
1643
- for (const entry of entries) {
1644
- await this.rm(this.path.join(path, entry));
1645
- }
1646
- try {
1647
- await fs.promises.rmdir(path);
1648
- } catch (error) {
1649
- if (this.isEnoent(error))
1650
- return;
1651
- throw error;
1652
- }
1653
- return;
1654
- }
1655
- try {
1656
- await fs.promises.unlink(path);
1657
- } catch (error) {
1658
- if (this.isEnoent(error))
1659
- return;
1660
- throw error;
1661
- }
1662
- }
1663
- async rename(oldPath, newPath) {
1664
- await this.init();
1665
- const fs = this.getFs();
1666
- await fs.promises.rename(oldPath, newPath);
1667
- }
1668
- async realpath(filePath) {
1669
- return filePath;
1670
- }
1671
- async getTempDir() {
1672
- const dir = `/tmp/uipath-fs-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
1673
- await this.mkdir(dir);
1674
- return dir;
1675
- }
1676
- async copyDirectory(sourcePath, destPath) {
1677
- const sourceStats = await this.stat(sourcePath);
1678
- if (!sourceStats) {
1679
- throw new Error(`Source directory does not exist: ${sourcePath}`);
1680
- }
1681
- if (!sourceStats.isDirectory()) {
1682
- throw new Error(`Source path is not a directory: ${sourcePath}`);
1683
- }
1684
- await this.mkdir(destPath);
1685
- const entries = await this.readdir(sourcePath);
1686
- for (const entry of entries) {
1687
- const srcEntry = this.path.join(sourcePath, entry);
1688
- const destEntry = this.path.join(destPath, entry);
1689
- const entryStats = await this.stat(srcEntry);
1690
- if (!entryStats)
1691
- continue;
1692
- if (entryStats.isDirectory()) {
1693
- await this.copyDirectory(srcEntry, destEntry);
1694
- } else if (entryStats.isFile()) {
1695
- const content = await this.readFile(srcEntry);
1696
- if (content !== null) {
1697
- await this.writeFile(destEntry, content);
1698
- }
1699
- }
1700
- }
1701
- }
1702
- isEnoent(error) {
1703
- return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
1704
- }
1705
- isEexist(error) {
1706
- return typeof error === "object" && error !== null && "code" in error && error.code === "EEXIST";
1707
- }
1708
- async checkRootDirectory() {
1709
- try {
1710
- const fs = this.getFs();
1711
- await fs.promises.stat("/");
1712
- } catch (error) {
1713
- if (this.isEnoent(error)) {
1714
- const fs = this.getFs();
1715
- await fs.promises.mkdir("/");
1716
- return;
1717
- }
1718
- throw error;
1719
- }
1720
- }
1721
- }
1722
- var defaultFs = new BrowserFileSystem;
1723
- var initPromise = defaultFs.init();
1724
-
1725
- // ../packager/project-packager/src/base-browser-packager-factory.ts
1726
- var sharedFileSystem = null;
1727
- var GLOBAL_FS_KEY = "__uipath_sharedFileSystem";
1728
-
1729
- class BaseBrowserPackagerFactory {
1730
- async getOrCreateFileSystem(config) {
1731
- if (config?.fileSystem) {
1732
- return config.fileSystem;
1733
- }
1734
- const globalRecord = globalThis;
1735
- if (!sharedFileSystem) {
1736
- sharedFileSystem = globalRecord[GLOBAL_FS_KEY] ?? null;
1737
- }
1738
- if (!sharedFileSystem) {
1739
- const fs = new BrowserFileSystem;
1740
- try {
1741
- await fs.init();
1742
- } catch (error) {
1743
- if (error instanceof Error && error.message.includes("Mount point is already in use")) {
1744
- fs.initialized = true;
1745
- } else {
1746
- throw error;
1747
- }
1748
- }
1749
- sharedFileSystem = fs;
1750
- globalRecord[GLOBAL_FS_KEY] = fs;
1751
- }
1752
- return sharedFileSystem;
1753
- }
1754
- getOrCreateTelemetryService(config) {
1755
- if (config?.telemetryService) {
1756
- return config.telemetryService;
1757
- }
1758
- const provider = new ConsoleTelemetryProvider;
1759
- const contextStorage = new BrowserContextStorage;
1760
- return new TelemetryService(provider, contextStorage);
1761
- }
1762
- configureLogHandler(config) {
1763
- if (config?.logHandler) {
1764
- setGlobalLogHandler(config.logHandler);
1765
- }
1766
- }
1767
- configureLanguage(config) {
1768
- const language = config?.language ?? "en";
1769
- translate.setLocale(language);
1770
- }
1771
- }
1772
- // ../packager/project-packager/src/browser-project-packager-factory.ts
1773
- class BrowserProjectPackagerFactory extends BaseBrowserPackagerFactory {
1774
- async createAsync(config) {
1775
- const logger = new ToolLogger("ProjectPackagerFactory", "Create");
1776
- this.configureLanguage(config);
1777
- this.configureLogHandler(config);
1778
- logger.info("Creating ProjectPackager instance...");
1779
- const fileSystem = await this.getOrCreateFileSystem(config);
1780
- const telemetryService = this.getOrCreateTelemetryService(config);
1781
- const projectPackager = new ProjectPackager(fileSystem, telemetryService);
1782
- logger.info("ProjectPackager created successfully.");
1783
- return projectPackager;
1784
- }
1785
- }
1786
- async function createBrowserProjectPackager(options) {
1787
- const factory = new BrowserProjectPackagerFactory;
1788
- return factory.createAsync(options);
1789
- }
1790
- export {
1791
- createBrowserProjectPackager,
1792
- BaseBrowserPackagerFactory
1793
- };
1794
-
1795
- //# debugId=BEA0DF616EA4E56964756E2164756E21