@atlaspack/fs 2.12.1-canary.3354

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/lib/index.js ADDED
@@ -0,0 +1,2278 @@
1
+ var $dlC2Z$path = require("path");
2
+ var $dlC2Z$stream = require("stream");
3
+ var $dlC2Z$util = require("util");
4
+ var $dlC2Z$fs = require("fs");
5
+ var $dlC2Z$os = require("os");
6
+ var $dlC2Z$atlaspackcore = require("@atlaspack/core");
7
+ var $dlC2Z$atlaspackutils = require("@atlaspack/utils");
8
+ var $dlC2Z$atlaspackfeatureflags = require("@atlaspack/feature-flags");
9
+ var $dlC2Z$parcelwatcher = require("@parcel/watcher");
10
+ var $dlC2Z$atlaspackrust = require("@atlaspack/rust");
11
+ var $dlC2Z$assert = require("assert");
12
+ var $dlC2Z$constants = require("constants");
13
+ var $dlC2Z$atlaspackworkers = require("@atlaspack/workers");
14
+ var $dlC2Z$events = require("events");
15
+
16
+
17
+ function $atlaspack$interopDefault(a) {
18
+ return a && a.__esModule ? a.default : a;
19
+ }
20
+
21
+ function $atlaspack$exportWildcard(dest, source) {
22
+ Object.keys(source).forEach(function(key) {
23
+ if (key === 'default' || key === '__esModule' || Object.prototype.hasOwnProperty.call(dest, key)) {
24
+ return;
25
+ }
26
+
27
+ Object.defineProperty(dest, key, {
28
+ enumerable: true,
29
+ get: function get() {
30
+ return source[key];
31
+ }
32
+ });
33
+ });
34
+
35
+ return dest;
36
+ }
37
+
38
+ function $atlaspack$export(e, n, v, s) {
39
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
40
+ }
41
+
42
+ var $atlaspack$global = globalThis;
43
+
44
+ $atlaspack$export(module.exports, "ncp", () => $4256a6714e3958a6$export$d3a8044e3fef7335);
45
+
46
+
47
+
48
+ var $fd5eb542960b5f45$exports = {};
49
+
50
+ $atlaspack$export($fd5eb542960b5f45$exports, "NodeFS", () => $fd5eb542960b5f45$export$c4e0ef2ab73c21e7);
51
+ var $1b674202ab68c176$exports = {};
52
+
53
+ var $62dc3839f187e943$exports = {};
54
+
55
+ var $62dc3839f187e943$var$origCwd = process.cwd;
56
+ var $62dc3839f187e943$var$cwd = null;
57
+ var $62dc3839f187e943$var$platform = process.env.GRACEFUL_FS_PLATFORM || process.platform;
58
+ process.cwd = function() {
59
+ if (!$62dc3839f187e943$var$cwd) $62dc3839f187e943$var$cwd = $62dc3839f187e943$var$origCwd.call(process);
60
+ return $62dc3839f187e943$var$cwd;
61
+ };
62
+ try {
63
+ process.cwd();
64
+ } catch (er) {}
65
+ // This check is needed until node.js 12 is required
66
+ if (typeof process.chdir === 'function') {
67
+ var $62dc3839f187e943$var$chdir = process.chdir;
68
+ process.chdir = function(d) {
69
+ $62dc3839f187e943$var$cwd = null;
70
+ $62dc3839f187e943$var$chdir.call(process, d);
71
+ };
72
+ if (Object.setPrototypeOf) Object.setPrototypeOf(process.chdir, $62dc3839f187e943$var$chdir);
73
+ }
74
+ $62dc3839f187e943$exports = $62dc3839f187e943$var$patch;
75
+ function $62dc3839f187e943$var$patch(fs) {
76
+ // (re-)implement some things that are known busted or missing.
77
+ // lchmod, broken prior to 0.6.2
78
+ // back-port the fix here.
79
+ if ($dlC2Z$constants.hasOwnProperty('O_SYMLINK') && process.version.match(/^v0\.6\.[0-2]|^v0\.5\./)) patchLchmod(fs);
80
+ // lutimes implementation, or no-op
81
+ if (!fs.lutimes) patchLutimes(fs);
82
+ // https://github.com/isaacs/node-graceful-fs/issues/4
83
+ // Chown should not fail on einval or eperm if non-root.
84
+ // It should not fail on enosys ever, as this just indicates
85
+ // that a fs doesn't support the intended operation.
86
+ fs.chown = chownFix(fs.chown);
87
+ fs.fchown = chownFix(fs.fchown);
88
+ fs.lchown = chownFix(fs.lchown);
89
+ fs.chmod = chmodFix(fs.chmod);
90
+ fs.fchmod = chmodFix(fs.fchmod);
91
+ fs.lchmod = chmodFix(fs.lchmod);
92
+ fs.chownSync = chownFixSync(fs.chownSync);
93
+ fs.fchownSync = chownFixSync(fs.fchownSync);
94
+ fs.lchownSync = chownFixSync(fs.lchownSync);
95
+ fs.chmodSync = chmodFixSync(fs.chmodSync);
96
+ fs.fchmodSync = chmodFixSync(fs.fchmodSync);
97
+ fs.lchmodSync = chmodFixSync(fs.lchmodSync);
98
+ fs.stat = statFix(fs.stat);
99
+ fs.fstat = statFix(fs.fstat);
100
+ fs.lstat = statFix(fs.lstat);
101
+ fs.statSync = statFixSync(fs.statSync);
102
+ fs.fstatSync = statFixSync(fs.fstatSync);
103
+ fs.lstatSync = statFixSync(fs.lstatSync);
104
+ // if lchmod/lchown do not exist, then make them no-ops
105
+ if (fs.chmod && !fs.lchmod) {
106
+ fs.lchmod = function(path, mode, cb) {
107
+ if (cb) process.nextTick(cb);
108
+ };
109
+ fs.lchmodSync = function() {};
110
+ }
111
+ if (fs.chown && !fs.lchown) {
112
+ fs.lchown = function(path, uid, gid, cb) {
113
+ if (cb) process.nextTick(cb);
114
+ };
115
+ fs.lchownSync = function() {};
116
+ }
117
+ // on Windows, A/V software can lock the directory, causing this
118
+ // to fail with an EACCES or EPERM if the directory contains newly
119
+ // created files. Try again on failure, for up to 60 seconds.
120
+ // Set the timeout this long because some Windows Anti-Virus, such as Parity
121
+ // bit9, may lock files for up to a minute, causing npm package install
122
+ // failures. Also, take care to yield the scheduler. Windows scheduling gives
123
+ // CPU to a busy looping process, which can cause the program causing the lock
124
+ // contention to be starved of CPU by node, so the contention doesn't resolve.
125
+ if ($62dc3839f187e943$var$platform === "win32") fs.rename = typeof fs.rename !== 'function' ? fs.rename : function(fs$rename) {
126
+ function rename(from, to, cb) {
127
+ var start = Date.now();
128
+ var backoff = 0;
129
+ fs$rename(from, to, function CB(er) {
130
+ if (er && (er.code === "EACCES" || er.code === "EPERM" || er.code === "EBUSY") && Date.now() - start < 60000) {
131
+ setTimeout(function() {
132
+ fs.stat(to, function(stater, st) {
133
+ if (stater && stater.code === "ENOENT") fs$rename(from, to, CB);
134
+ else cb(er);
135
+ });
136
+ }, backoff);
137
+ if (backoff < 100) backoff += 10;
138
+ return;
139
+ }
140
+ if (cb) cb(er);
141
+ });
142
+ }
143
+ if (Object.setPrototypeOf) Object.setPrototypeOf(rename, fs$rename);
144
+ return rename;
145
+ }(fs.rename);
146
+ // if read() returns EAGAIN, then just try it again.
147
+ fs.read = typeof fs.read !== 'function' ? fs.read : function(fs$read) {
148
+ function read(fd, buffer, offset, length, position, callback_) {
149
+ var callback;
150
+ if (callback_ && typeof callback_ === 'function') {
151
+ var eagCounter = 0;
152
+ callback = function(er, _, __) {
153
+ if (er && er.code === 'EAGAIN' && eagCounter < 10) {
154
+ eagCounter++;
155
+ return fs$read.call(fs, fd, buffer, offset, length, position, callback);
156
+ }
157
+ callback_.apply(this, arguments);
158
+ };
159
+ }
160
+ return fs$read.call(fs, fd, buffer, offset, length, position, callback);
161
+ }
162
+ // This ensures `util.promisify` works as it does for native `fs.read`.
163
+ if (Object.setPrototypeOf) Object.setPrototypeOf(read, fs$read);
164
+ return read;
165
+ }(fs.read);
166
+ fs.readSync = typeof fs.readSync !== 'function' ? fs.readSync : function(fs$readSync) {
167
+ return function(fd, buffer, offset, length, position) {
168
+ var eagCounter = 0;
169
+ while(true)try {
170
+ return fs$readSync.call(fs, fd, buffer, offset, length, position);
171
+ } catch (er) {
172
+ if (er.code === 'EAGAIN' && eagCounter < 10) {
173
+ eagCounter++;
174
+ continue;
175
+ }
176
+ throw er;
177
+ }
178
+ };
179
+ }(fs.readSync);
180
+ function patchLchmod(fs) {
181
+ fs.lchmod = function(path, mode, callback) {
182
+ fs.open(path, $dlC2Z$constants.O_WRONLY | $dlC2Z$constants.O_SYMLINK, mode, function(err, fd) {
183
+ if (err) {
184
+ if (callback) callback(err);
185
+ return;
186
+ }
187
+ // prefer to return the chmod error, if one occurs,
188
+ // but still try to close, and report closing errors if they occur.
189
+ fs.fchmod(fd, mode, function(err) {
190
+ fs.close(fd, function(err2) {
191
+ if (callback) callback(err || err2);
192
+ });
193
+ });
194
+ });
195
+ };
196
+ fs.lchmodSync = function(path, mode) {
197
+ var fd = fs.openSync(path, $dlC2Z$constants.O_WRONLY | $dlC2Z$constants.O_SYMLINK, mode);
198
+ // prefer to return the chmod error, if one occurs,
199
+ // but still try to close, and report closing errors if they occur.
200
+ var threw = true;
201
+ var ret;
202
+ try {
203
+ ret = fs.fchmodSync(fd, mode);
204
+ threw = false;
205
+ } finally{
206
+ if (threw) try {
207
+ fs.closeSync(fd);
208
+ } catch (er) {}
209
+ else fs.closeSync(fd);
210
+ }
211
+ return ret;
212
+ };
213
+ }
214
+ function patchLutimes(fs) {
215
+ if ($dlC2Z$constants.hasOwnProperty("O_SYMLINK") && fs.futimes) {
216
+ fs.lutimes = function(path, at, mt, cb) {
217
+ fs.open(path, $dlC2Z$constants.O_SYMLINK, function(er, fd) {
218
+ if (er) {
219
+ if (cb) cb(er);
220
+ return;
221
+ }
222
+ fs.futimes(fd, at, mt, function(er) {
223
+ fs.close(fd, function(er2) {
224
+ if (cb) cb(er || er2);
225
+ });
226
+ });
227
+ });
228
+ };
229
+ fs.lutimesSync = function(path, at, mt) {
230
+ var fd = fs.openSync(path, $dlC2Z$constants.O_SYMLINK);
231
+ var ret;
232
+ var threw = true;
233
+ try {
234
+ ret = fs.futimesSync(fd, at, mt);
235
+ threw = false;
236
+ } finally{
237
+ if (threw) try {
238
+ fs.closeSync(fd);
239
+ } catch (er) {}
240
+ else fs.closeSync(fd);
241
+ }
242
+ return ret;
243
+ };
244
+ } else if (fs.futimes) {
245
+ fs.lutimes = function(_a, _b, _c, cb) {
246
+ if (cb) process.nextTick(cb);
247
+ };
248
+ fs.lutimesSync = function() {};
249
+ }
250
+ }
251
+ function chmodFix(orig) {
252
+ if (!orig) return orig;
253
+ return function(target, mode, cb) {
254
+ return orig.call(fs, target, mode, function(er) {
255
+ if (chownErOk(er)) er = null;
256
+ if (cb) cb.apply(this, arguments);
257
+ });
258
+ };
259
+ }
260
+ function chmodFixSync(orig) {
261
+ if (!orig) return orig;
262
+ return function(target, mode) {
263
+ try {
264
+ return orig.call(fs, target, mode);
265
+ } catch (er) {
266
+ if (!chownErOk(er)) throw er;
267
+ }
268
+ };
269
+ }
270
+ function chownFix(orig) {
271
+ if (!orig) return orig;
272
+ return function(target, uid, gid, cb) {
273
+ return orig.call(fs, target, uid, gid, function(er) {
274
+ if (chownErOk(er)) er = null;
275
+ if (cb) cb.apply(this, arguments);
276
+ });
277
+ };
278
+ }
279
+ function chownFixSync(orig) {
280
+ if (!orig) return orig;
281
+ return function(target, uid, gid) {
282
+ try {
283
+ return orig.call(fs, target, uid, gid);
284
+ } catch (er) {
285
+ if (!chownErOk(er)) throw er;
286
+ }
287
+ };
288
+ }
289
+ function statFix(orig) {
290
+ if (!orig) return orig;
291
+ // Older versions of Node erroneously returned signed integers for
292
+ // uid + gid.
293
+ return function(target, options, cb) {
294
+ if (typeof options === 'function') {
295
+ cb = options;
296
+ options = null;
297
+ }
298
+ function callback(er, stats) {
299
+ if (stats) {
300
+ if (stats.uid < 0) stats.uid += 0x100000000;
301
+ if (stats.gid < 0) stats.gid += 0x100000000;
302
+ }
303
+ if (cb) cb.apply(this, arguments);
304
+ }
305
+ return options ? orig.call(fs, target, options, callback) : orig.call(fs, target, callback);
306
+ };
307
+ }
308
+ function statFixSync(orig) {
309
+ if (!orig) return orig;
310
+ // Older versions of Node erroneously returned signed integers for
311
+ // uid + gid.
312
+ return function(target, options) {
313
+ var stats = options ? orig.call(fs, target, options) : orig.call(fs, target);
314
+ if (stats) {
315
+ if (stats.uid < 0) stats.uid += 0x100000000;
316
+ if (stats.gid < 0) stats.gid += 0x100000000;
317
+ }
318
+ return stats;
319
+ };
320
+ }
321
+ // ENOSYS means that the fs doesn't support the op. Just ignore
322
+ // that, because it doesn't matter.
323
+ //
324
+ // if there's no getuid, or if getuid() is something other
325
+ // than 0, and the error is EINVAL or EPERM, then just ignore
326
+ // it.
327
+ //
328
+ // This specific case is a silent failure in cp, install, tar,
329
+ // and most other unix tools that manage permissions.
330
+ //
331
+ // When running as root, or if other types of errors are
332
+ // encountered, then it's strict.
333
+ function chownErOk(er) {
334
+ if (!er) return true;
335
+ if (er.code === "ENOSYS") return true;
336
+ var nonroot = !process.getuid || process.getuid() !== 0;
337
+ if (nonroot) {
338
+ if (er.code === "EINVAL" || er.code === "EPERM") return true;
339
+ }
340
+ return false;
341
+ }
342
+ }
343
+
344
+
345
+ var $dd8f2c33a06f99ca$exports = {};
346
+
347
+ var $dd8f2c33a06f99ca$require$Stream = $dlC2Z$stream.Stream;
348
+ $dd8f2c33a06f99ca$exports = $dd8f2c33a06f99ca$var$legacy;
349
+ function $dd8f2c33a06f99ca$var$legacy(fs) {
350
+ return {
351
+ ReadStream: ReadStream,
352
+ WriteStream: WriteStream
353
+ };
354
+ function ReadStream(path, options) {
355
+ if (!(this instanceof ReadStream)) return new ReadStream(path, options);
356
+ $dd8f2c33a06f99ca$require$Stream.call(this);
357
+ var self = this;
358
+ this.path = path;
359
+ this.fd = null;
360
+ this.readable = true;
361
+ this.paused = false;
362
+ this.flags = 'r';
363
+ this.mode = 438; /*=0666*/
364
+ this.bufferSize = 65536;
365
+ options = options || {};
366
+ // Mixin options into this
367
+ var keys = Object.keys(options);
368
+ for(var index = 0, length = keys.length; index < length; index++){
369
+ var key = keys[index];
370
+ this[key] = options[key];
371
+ }
372
+ if (this.encoding) this.setEncoding(this.encoding);
373
+ if (this.start !== undefined) {
374
+ if ('number' !== typeof this.start) throw TypeError('start must be a Number');
375
+ if (this.end === undefined) this.end = Infinity;
376
+ else if ('number' !== typeof this.end) throw TypeError('end must be a Number');
377
+ if (this.start > this.end) throw new Error('start must be <= end');
378
+ this.pos = this.start;
379
+ }
380
+ if (this.fd !== null) {
381
+ process.nextTick(function() {
382
+ self._read();
383
+ });
384
+ return;
385
+ }
386
+ fs.open(this.path, this.flags, this.mode, function(err, fd) {
387
+ if (err) {
388
+ self.emit('error', err);
389
+ self.readable = false;
390
+ return;
391
+ }
392
+ self.fd = fd;
393
+ self.emit('open', fd);
394
+ self._read();
395
+ });
396
+ }
397
+ function WriteStream(path, options) {
398
+ if (!(this instanceof WriteStream)) return new WriteStream(path, options);
399
+ $dd8f2c33a06f99ca$require$Stream.call(this);
400
+ this.path = path;
401
+ this.fd = null;
402
+ this.writable = true;
403
+ this.flags = 'w';
404
+ this.encoding = 'binary';
405
+ this.mode = 438; /*=0666*/
406
+ this.bytesWritten = 0;
407
+ options = options || {};
408
+ // Mixin options into this
409
+ var keys = Object.keys(options);
410
+ for(var index = 0, length = keys.length; index < length; index++){
411
+ var key = keys[index];
412
+ this[key] = options[key];
413
+ }
414
+ if (this.start !== undefined) {
415
+ if ('number' !== typeof this.start) throw TypeError('start must be a Number');
416
+ if (this.start < 0) throw new Error('start must be >= zero');
417
+ this.pos = this.start;
418
+ }
419
+ this.busy = false;
420
+ this._queue = [];
421
+ if (this.fd === null) {
422
+ this._open = fs.open;
423
+ this._queue.push([
424
+ this._open,
425
+ this.path,
426
+ this.flags,
427
+ this.mode,
428
+ undefined
429
+ ]);
430
+ this.flush();
431
+ }
432
+ }
433
+ }
434
+
435
+
436
+ var $3c4b7a3d3568cdcd$exports = {};
437
+ 'use strict';
438
+ $3c4b7a3d3568cdcd$exports = $3c4b7a3d3568cdcd$var$clone;
439
+ var $3c4b7a3d3568cdcd$var$getPrototypeOf = Object.getPrototypeOf || function(obj) {
440
+ return obj.__proto__;
441
+ };
442
+ function $3c4b7a3d3568cdcd$var$clone(obj) {
443
+ if (obj === null || typeof obj !== 'object') return obj;
444
+ if (obj instanceof Object) var copy = {
445
+ __proto__: $3c4b7a3d3568cdcd$var$getPrototypeOf(obj)
446
+ };
447
+ else var copy = Object.create(null);
448
+ Object.getOwnPropertyNames(obj).forEach(function(key) {
449
+ Object.defineProperty(copy, key, Object.getOwnPropertyDescriptor(obj, key));
450
+ });
451
+ return copy;
452
+ }
453
+
454
+
455
+
456
+ /* istanbul ignore next - node 0.x polyfill */ var $1b674202ab68c176$var$gracefulQueue;
457
+ var $1b674202ab68c176$var$previousSymbol;
458
+ /* istanbul ignore else - node 0.x polyfill */ if (typeof Symbol === 'function' && typeof Symbol.for === 'function') {
459
+ $1b674202ab68c176$var$gracefulQueue = Symbol.for('graceful-fs.queue');
460
+ // This is used in testing by future versions
461
+ $1b674202ab68c176$var$previousSymbol = Symbol.for('graceful-fs.previous');
462
+ } else {
463
+ $1b674202ab68c176$var$gracefulQueue = '___graceful-fs.queue';
464
+ $1b674202ab68c176$var$previousSymbol = '___graceful-fs.previous';
465
+ }
466
+ function $1b674202ab68c176$var$noop() {}
467
+ function $1b674202ab68c176$var$publishQueue(context, queue) {
468
+ Object.defineProperty(context, $1b674202ab68c176$var$gracefulQueue, {
469
+ get: function() {
470
+ return queue;
471
+ }
472
+ });
473
+ }
474
+ var $1b674202ab68c176$var$debug = $1b674202ab68c176$var$noop;
475
+ if ($dlC2Z$util.debuglog) $1b674202ab68c176$var$debug = $dlC2Z$util.debuglog('gfs4');
476
+ else if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || '')) $1b674202ab68c176$var$debug = function() {
477
+ var m = $dlC2Z$util.format.apply($dlC2Z$util, arguments);
478
+ m = 'GFS4: ' + m.split(/\n/).join('\nGFS4: ');
479
+ console.error(m);
480
+ };
481
+
482
+ // Once time initialization
483
+ if (!$dlC2Z$fs[$1b674202ab68c176$var$gracefulQueue]) {
484
+ // This queue can be shared by multiple loaded instances
485
+ var $1b674202ab68c176$var$queue = $atlaspack$global[$1b674202ab68c176$var$gracefulQueue] || [];
486
+ $1b674202ab68c176$var$publishQueue($dlC2Z$fs, $1b674202ab68c176$var$queue);
487
+ // Patch fs.close/closeSync to shared queue version, because we need
488
+ // to retry() whenever a close happens *anywhere* in the program.
489
+ // This is essential when multiple graceful-fs instances are
490
+ // in play at the same time.
491
+ $dlC2Z$fs.close = function(fs$close) {
492
+ function close(fd, cb) {
493
+ return fs$close.call($dlC2Z$fs, fd, function(err) {
494
+ // This function uses the graceful-fs shared queue
495
+ if (!err) $1b674202ab68c176$var$resetQueue();
496
+ if (typeof cb === 'function') cb.apply(this, arguments);
497
+ });
498
+ }
499
+ Object.defineProperty(close, $1b674202ab68c176$var$previousSymbol, {
500
+ value: fs$close
501
+ });
502
+ return close;
503
+ }($dlC2Z$fs.close);
504
+ $dlC2Z$fs.closeSync = function(fs$closeSync) {
505
+ function closeSync(fd) {
506
+ // This function uses the graceful-fs shared queue
507
+ fs$closeSync.apply($dlC2Z$fs, arguments);
508
+ $1b674202ab68c176$var$resetQueue();
509
+ }
510
+ Object.defineProperty(closeSync, $1b674202ab68c176$var$previousSymbol, {
511
+ value: fs$closeSync
512
+ });
513
+ return closeSync;
514
+ }($dlC2Z$fs.closeSync);
515
+ if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || '')) process.on('exit', function() {
516
+ $1b674202ab68c176$var$debug($dlC2Z$fs[$1b674202ab68c176$var$gracefulQueue]);
517
+ $dlC2Z$assert.equal($dlC2Z$fs[$1b674202ab68c176$var$gracefulQueue].length, 0);
518
+ });
519
+ }
520
+ if (!$atlaspack$global[$1b674202ab68c176$var$gracefulQueue]) $1b674202ab68c176$var$publishQueue($atlaspack$global, $dlC2Z$fs[$1b674202ab68c176$var$gracefulQueue]);
521
+ $1b674202ab68c176$exports = $1b674202ab68c176$var$patch($3c4b7a3d3568cdcd$exports($dlC2Z$fs));
522
+ if (process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH && !$dlC2Z$fs.__patched) {
523
+ $1b674202ab68c176$exports = $1b674202ab68c176$var$patch($dlC2Z$fs);
524
+ $dlC2Z$fs.__patched = true;
525
+ }
526
+ function $1b674202ab68c176$var$patch(fs) {
527
+ // Everything that references the open() function needs to be in here
528
+ $62dc3839f187e943$exports(fs);
529
+ fs.gracefulify = $1b674202ab68c176$var$patch;
530
+ fs.createReadStream = createReadStream;
531
+ fs.createWriteStream = createWriteStream;
532
+ var fs$readFile = fs.readFile;
533
+ fs.readFile = readFile;
534
+ function readFile(path, options, cb) {
535
+ if (typeof options === 'function') cb = options, options = null;
536
+ return go$readFile(path, options, cb);
537
+ function go$readFile(path, options, cb, startTime) {
538
+ return fs$readFile(path, options, function(err) {
539
+ if (err && (err.code === 'EMFILE' || err.code === 'ENFILE')) $1b674202ab68c176$var$enqueue([
540
+ go$readFile,
541
+ [
542
+ path,
543
+ options,
544
+ cb
545
+ ],
546
+ err,
547
+ startTime || Date.now(),
548
+ Date.now()
549
+ ]);
550
+ else if (typeof cb === 'function') cb.apply(this, arguments);
551
+ });
552
+ }
553
+ }
554
+ var fs$writeFile = fs.writeFile;
555
+ fs.writeFile = writeFile;
556
+ function writeFile(path, data, options, cb) {
557
+ if (typeof options === 'function') cb = options, options = null;
558
+ return go$writeFile(path, data, options, cb);
559
+ function go$writeFile(path, data, options, cb, startTime) {
560
+ return fs$writeFile(path, data, options, function(err) {
561
+ if (err && (err.code === 'EMFILE' || err.code === 'ENFILE')) $1b674202ab68c176$var$enqueue([
562
+ go$writeFile,
563
+ [
564
+ path,
565
+ data,
566
+ options,
567
+ cb
568
+ ],
569
+ err,
570
+ startTime || Date.now(),
571
+ Date.now()
572
+ ]);
573
+ else if (typeof cb === 'function') cb.apply(this, arguments);
574
+ });
575
+ }
576
+ }
577
+ var fs$appendFile = fs.appendFile;
578
+ if (fs$appendFile) fs.appendFile = appendFile;
579
+ function appendFile(path, data, options, cb) {
580
+ if (typeof options === 'function') cb = options, options = null;
581
+ return go$appendFile(path, data, options, cb);
582
+ function go$appendFile(path, data, options, cb, startTime) {
583
+ return fs$appendFile(path, data, options, function(err) {
584
+ if (err && (err.code === 'EMFILE' || err.code === 'ENFILE')) $1b674202ab68c176$var$enqueue([
585
+ go$appendFile,
586
+ [
587
+ path,
588
+ data,
589
+ options,
590
+ cb
591
+ ],
592
+ err,
593
+ startTime || Date.now(),
594
+ Date.now()
595
+ ]);
596
+ else if (typeof cb === 'function') cb.apply(this, arguments);
597
+ });
598
+ }
599
+ }
600
+ var fs$copyFile = fs.copyFile;
601
+ if (fs$copyFile) fs.copyFile = copyFile;
602
+ function copyFile(src, dest, flags, cb) {
603
+ if (typeof flags === 'function') {
604
+ cb = flags;
605
+ flags = 0;
606
+ }
607
+ return go$copyFile(src, dest, flags, cb);
608
+ function go$copyFile(src, dest, flags, cb, startTime) {
609
+ return fs$copyFile(src, dest, flags, function(err) {
610
+ if (err && (err.code === 'EMFILE' || err.code === 'ENFILE')) $1b674202ab68c176$var$enqueue([
611
+ go$copyFile,
612
+ [
613
+ src,
614
+ dest,
615
+ flags,
616
+ cb
617
+ ],
618
+ err,
619
+ startTime || Date.now(),
620
+ Date.now()
621
+ ]);
622
+ else if (typeof cb === 'function') cb.apply(this, arguments);
623
+ });
624
+ }
625
+ }
626
+ var fs$readdir = fs.readdir;
627
+ fs.readdir = readdir;
628
+ var noReaddirOptionVersions = /^v[0-5]\./;
629
+ function readdir(path, options, cb) {
630
+ if (typeof options === 'function') cb = options, options = null;
631
+ var go$readdir = noReaddirOptionVersions.test(process.version) ? function go$readdir(path, options, cb, startTime) {
632
+ return fs$readdir(path, fs$readdirCallback(path, options, cb, startTime));
633
+ } : function go$readdir(path, options, cb, startTime) {
634
+ return fs$readdir(path, options, fs$readdirCallback(path, options, cb, startTime));
635
+ };
636
+ return go$readdir(path, options, cb);
637
+ function fs$readdirCallback(path, options, cb, startTime) {
638
+ return function(err, files) {
639
+ if (err && (err.code === 'EMFILE' || err.code === 'ENFILE')) $1b674202ab68c176$var$enqueue([
640
+ go$readdir,
641
+ [
642
+ path,
643
+ options,
644
+ cb
645
+ ],
646
+ err,
647
+ startTime || Date.now(),
648
+ Date.now()
649
+ ]);
650
+ else {
651
+ if (files && files.sort) files.sort();
652
+ if (typeof cb === 'function') cb.call(this, err, files);
653
+ }
654
+ };
655
+ }
656
+ }
657
+ if (process.version.substr(0, 4) === 'v0.8') {
658
+ var legStreams = $dd8f2c33a06f99ca$exports(fs);
659
+ ReadStream = legStreams.ReadStream;
660
+ WriteStream = legStreams.WriteStream;
661
+ }
662
+ var fs$ReadStream = fs.ReadStream;
663
+ if (fs$ReadStream) {
664
+ ReadStream.prototype = Object.create(fs$ReadStream.prototype);
665
+ ReadStream.prototype.open = ReadStream$open;
666
+ }
667
+ var fs$WriteStream = fs.WriteStream;
668
+ if (fs$WriteStream) {
669
+ WriteStream.prototype = Object.create(fs$WriteStream.prototype);
670
+ WriteStream.prototype.open = WriteStream$open;
671
+ }
672
+ Object.defineProperty(fs, 'ReadStream', {
673
+ get: function() {
674
+ return ReadStream;
675
+ },
676
+ set: function(val) {
677
+ ReadStream = val;
678
+ },
679
+ enumerable: true,
680
+ configurable: true
681
+ });
682
+ Object.defineProperty(fs, 'WriteStream', {
683
+ get: function() {
684
+ return WriteStream;
685
+ },
686
+ set: function(val) {
687
+ WriteStream = val;
688
+ },
689
+ enumerable: true,
690
+ configurable: true
691
+ });
692
+ // legacy names
693
+ var FileReadStream = ReadStream;
694
+ Object.defineProperty(fs, 'FileReadStream', {
695
+ get: function() {
696
+ return FileReadStream;
697
+ },
698
+ set: function(val) {
699
+ FileReadStream = val;
700
+ },
701
+ enumerable: true,
702
+ configurable: true
703
+ });
704
+ var FileWriteStream = WriteStream;
705
+ Object.defineProperty(fs, 'FileWriteStream', {
706
+ get: function() {
707
+ return FileWriteStream;
708
+ },
709
+ set: function(val) {
710
+ FileWriteStream = val;
711
+ },
712
+ enumerable: true,
713
+ configurable: true
714
+ });
715
+ function ReadStream(path, options) {
716
+ if (this instanceof ReadStream) return fs$ReadStream.apply(this, arguments), this;
717
+ else return ReadStream.apply(Object.create(ReadStream.prototype), arguments);
718
+ }
719
+ function ReadStream$open() {
720
+ var that = this;
721
+ open(that.path, that.flags, that.mode, function(err, fd) {
722
+ if (err) {
723
+ if (that.autoClose) that.destroy();
724
+ that.emit('error', err);
725
+ } else {
726
+ that.fd = fd;
727
+ that.emit('open', fd);
728
+ that.read();
729
+ }
730
+ });
731
+ }
732
+ function WriteStream(path, options) {
733
+ if (this instanceof WriteStream) return fs$WriteStream.apply(this, arguments), this;
734
+ else return WriteStream.apply(Object.create(WriteStream.prototype), arguments);
735
+ }
736
+ function WriteStream$open() {
737
+ var that = this;
738
+ open(that.path, that.flags, that.mode, function(err, fd) {
739
+ if (err) {
740
+ that.destroy();
741
+ that.emit('error', err);
742
+ } else {
743
+ that.fd = fd;
744
+ that.emit('open', fd);
745
+ }
746
+ });
747
+ }
748
+ function createReadStream(path, options) {
749
+ return new fs.ReadStream(path, options);
750
+ }
751
+ function createWriteStream(path, options) {
752
+ return new fs.WriteStream(path, options);
753
+ }
754
+ var fs$open = fs.open;
755
+ fs.open = open;
756
+ function open(path, flags, mode, cb) {
757
+ if (typeof mode === 'function') cb = mode, mode = null;
758
+ return go$open(path, flags, mode, cb);
759
+ function go$open(path, flags, mode, cb, startTime) {
760
+ return fs$open(path, flags, mode, function(err, fd) {
761
+ if (err && (err.code === 'EMFILE' || err.code === 'ENFILE')) $1b674202ab68c176$var$enqueue([
762
+ go$open,
763
+ [
764
+ path,
765
+ flags,
766
+ mode,
767
+ cb
768
+ ],
769
+ err,
770
+ startTime || Date.now(),
771
+ Date.now()
772
+ ]);
773
+ else if (typeof cb === 'function') cb.apply(this, arguments);
774
+ });
775
+ }
776
+ }
777
+ return fs;
778
+ }
779
+ function $1b674202ab68c176$var$enqueue(elem) {
780
+ $1b674202ab68c176$var$debug('ENQUEUE', elem[0].name, elem[1]);
781
+ $dlC2Z$fs[$1b674202ab68c176$var$gracefulQueue].push(elem);
782
+ $1b674202ab68c176$var$retry();
783
+ }
784
+ // keep track of the timeout between retry() calls
785
+ var $1b674202ab68c176$var$retryTimer;
786
+ // reset the startTime and lastTime to now
787
+ // this resets the start of the 60 second overall timeout as well as the
788
+ // delay between attempts so that we'll retry these jobs sooner
789
+ function $1b674202ab68c176$var$resetQueue() {
790
+ var now = Date.now();
791
+ for(var i = 0; i < $dlC2Z$fs[$1b674202ab68c176$var$gracefulQueue].length; ++i)// entries that are only a length of 2 are from an older version, don't
792
+ // bother modifying those since they'll be retried anyway.
793
+ if ($dlC2Z$fs[$1b674202ab68c176$var$gracefulQueue][i].length > 2) {
794
+ $dlC2Z$fs[$1b674202ab68c176$var$gracefulQueue][i][3] = now // startTime
795
+ ;
796
+ $dlC2Z$fs[$1b674202ab68c176$var$gracefulQueue][i][4] = now // lastTime
797
+ ;
798
+ }
799
+ // call retry to make sure we're actively processing the queue
800
+ $1b674202ab68c176$var$retry();
801
+ }
802
+ function $1b674202ab68c176$var$retry() {
803
+ // clear the timer and remove it to help prevent unintended concurrency
804
+ clearTimeout($1b674202ab68c176$var$retryTimer);
805
+ $1b674202ab68c176$var$retryTimer = undefined;
806
+ if ($dlC2Z$fs[$1b674202ab68c176$var$gracefulQueue].length === 0) return;
807
+ var elem = $dlC2Z$fs[$1b674202ab68c176$var$gracefulQueue].shift();
808
+ var fn = elem[0];
809
+ var args = elem[1];
810
+ // these items may be unset if they were added by an older graceful-fs
811
+ var err = elem[2];
812
+ var startTime = elem[3];
813
+ var lastTime = elem[4];
814
+ // if we don't have a startTime we have no way of knowing if we've waited
815
+ // long enough, so go ahead and retry this item now
816
+ if (startTime === undefined) {
817
+ $1b674202ab68c176$var$debug('RETRY', fn.name, args);
818
+ fn.apply(null, args);
819
+ } else if (Date.now() - startTime >= 60000) {
820
+ // it's been more than 60 seconds total, bail now
821
+ $1b674202ab68c176$var$debug('TIMEOUT', fn.name, args);
822
+ var cb = args.pop();
823
+ if (typeof cb === 'function') cb.call(null, err);
824
+ } else {
825
+ // the amount of time between the last attempt and right now
826
+ var sinceAttempt = Date.now() - lastTime;
827
+ // the amount of time between when we first tried, and when we last tried
828
+ // rounded up to at least 1
829
+ var sinceStart = Math.max(lastTime - startTime, 1);
830
+ // backoff. wait longer than the total time we've been retrying, but only
831
+ // up to a maximum of 100ms
832
+ var desiredDelay = Math.min(sinceStart * 1.2, 100);
833
+ // it's been long enough since the last retry, do it again
834
+ if (sinceAttempt >= desiredDelay) {
835
+ $1b674202ab68c176$var$debug('RETRY', fn.name, args);
836
+ fn.apply(null, args.concat([
837
+ startTime
838
+ ]));
839
+ } else // if we can't do this job yet, push it to the end of the queue
840
+ // and let the next iteration check again
841
+ $dlC2Z$fs[$1b674202ab68c176$var$gracefulQueue].push(elem);
842
+ }
843
+ // schedule our next run if one isn't already scheduled
844
+ if ($1b674202ab68c176$var$retryTimer === undefined) $1b674202ab68c176$var$retryTimer = setTimeout($1b674202ab68c176$var$retry, 0);
845
+ }
846
+
847
+
848
+
849
+ var $c023d554c0890ceb$exports = {};
850
+
851
+
852
+ $c023d554c0890ceb$exports = $c023d554c0890ceb$var$ncp;
853
+ $c023d554c0890ceb$var$ncp.ncp = $c023d554c0890ceb$var$ncp;
854
+ function $c023d554c0890ceb$var$ncp(source, dest, options, callback) {
855
+ var cback = callback;
856
+ if (!callback) {
857
+ cback = options;
858
+ options = {};
859
+ }
860
+ var basePath = process.cwd(), currentPath = $dlC2Z$path.resolve(basePath, source), targetPath = $dlC2Z$path.resolve(basePath, dest), filter = options.filter, rename = options.rename, transform = options.transform, clobber = options.clobber !== false, modified = options.modified, dereference = options.dereference, errs = null, started = 0, finished = 0, running = 0, limit = options.limit || $c023d554c0890ceb$var$ncp.limit || 16;
861
+ limit = limit < 1 ? 1 : limit > 512 ? 512 : limit;
862
+ startCopy(currentPath);
863
+ function startCopy(source) {
864
+ started++;
865
+ if (filter) {
866
+ if (filter instanceof RegExp) {
867
+ if (!filter.test(source)) return cb(true);
868
+ } else if (typeof filter === 'function') {
869
+ if (!filter(source)) return cb(true);
870
+ }
871
+ }
872
+ return getStats(source);
873
+ }
874
+ function getStats(source) {
875
+ var stat = dereference ? $dlC2Z$fs.stat : $dlC2Z$fs.lstat;
876
+ if (running >= limit) return setImmediate(function() {
877
+ getStats(source);
878
+ });
879
+ running++;
880
+ stat(source, function(err, stats) {
881
+ var item = {};
882
+ if (err) return onError(err);
883
+ // We need to get the mode from the stats object and preserve it.
884
+ item.name = source;
885
+ item.mode = stats.mode;
886
+ item.mtime = stats.mtime; //modified time
887
+ item.atime = stats.atime; //access time
888
+ if (stats.isDirectory()) return onDir(item);
889
+ else if (stats.isFile()) return onFile(item);
890
+ else if (stats.isSymbolicLink()) // Symlinks don't really need to know about the mode.
891
+ return onLink(source);
892
+ });
893
+ }
894
+ function onFile(file) {
895
+ var target = file.name.replace(currentPath, targetPath);
896
+ if (rename) target = rename(target);
897
+ isWritable(target, function(writable) {
898
+ if (writable) return copyFile(file, target);
899
+ if (clobber) rmFile(target, function() {
900
+ copyFile(file, target);
901
+ });
902
+ if (modified) {
903
+ var stat = dereference ? $dlC2Z$fs.stat : $dlC2Z$fs.lstat;
904
+ stat(target, function(err, stats) {
905
+ //if souce modified time greater to target modified time copy file
906
+ if (file.mtime.getTime() > stats.mtime.getTime()) copyFile(file, target);
907
+ else return cb();
908
+ });
909
+ } else return cb();
910
+ });
911
+ }
912
+ function copyFile(file, target) {
913
+ var readStream = $dlC2Z$fs.createReadStream(file.name), writeStream = $dlC2Z$fs.createWriteStream(target, {
914
+ mode: file.mode
915
+ });
916
+ readStream.on('error', onError);
917
+ writeStream.on('error', onError);
918
+ if (transform) transform(readStream, writeStream, file);
919
+ else writeStream.on('open', function() {
920
+ readStream.pipe(writeStream);
921
+ });
922
+ writeStream.once('finish', function() {
923
+ if (modified) {
924
+ //target file modified date sync.
925
+ $dlC2Z$fs.utimesSync(target, file.atime, file.mtime);
926
+ cb();
927
+ } else cb();
928
+ });
929
+ }
930
+ function rmFile(file, done) {
931
+ $dlC2Z$fs.unlink(file, function(err) {
932
+ if (err) return onError(err);
933
+ return done();
934
+ });
935
+ }
936
+ function onDir(dir) {
937
+ var target = dir.name.replace(currentPath, targetPath);
938
+ isWritable(target, function(writable) {
939
+ if (writable) return mkDir(dir, target);
940
+ copyDir(dir.name);
941
+ });
942
+ }
943
+ function mkDir(dir, target) {
944
+ $dlC2Z$fs.mkdir(target, dir.mode, function(err) {
945
+ if (err) return onError(err);
946
+ copyDir(dir.name);
947
+ });
948
+ }
949
+ function copyDir(dir) {
950
+ $dlC2Z$fs.readdir(dir, function(err, items) {
951
+ if (err) return onError(err);
952
+ items.forEach(function(item) {
953
+ startCopy($dlC2Z$path.join(dir, item));
954
+ });
955
+ return cb();
956
+ });
957
+ }
958
+ function onLink(link) {
959
+ var target = link.replace(currentPath, targetPath);
960
+ $dlC2Z$fs.readlink(link, function(err, resolvedPath) {
961
+ if (err) return onError(err);
962
+ checkLink(resolvedPath, target);
963
+ });
964
+ }
965
+ function checkLink(resolvedPath, target) {
966
+ if (dereference) resolvedPath = $dlC2Z$path.resolve(basePath, resolvedPath);
967
+ isWritable(target, function(writable) {
968
+ if (writable) return makeLink(resolvedPath, target);
969
+ $dlC2Z$fs.readlink(target, function(err, targetDest) {
970
+ if (err) return onError(err);
971
+ if (dereference) targetDest = $dlC2Z$path.resolve(basePath, targetDest);
972
+ if (targetDest === resolvedPath) return cb();
973
+ return rmFile(target, function() {
974
+ makeLink(resolvedPath, target);
975
+ });
976
+ });
977
+ });
978
+ }
979
+ function makeLink(linkPath, target) {
980
+ $dlC2Z$fs.symlink(linkPath, target, function(err) {
981
+ if (err) return onError(err);
982
+ return cb();
983
+ });
984
+ }
985
+ function isWritable(path, done) {
986
+ $dlC2Z$fs.lstat(path, function(err) {
987
+ if (err) {
988
+ if (err.code === 'ENOENT') return done(true);
989
+ return done(false);
990
+ }
991
+ return done(false);
992
+ });
993
+ }
994
+ function onError(err) {
995
+ if (options.stopOnError) return cback(err);
996
+ else if (!errs && options.errs) errs = $dlC2Z$fs.createWriteStream(options.errs);
997
+ else if (!errs) errs = [];
998
+ if (typeof errs.write === 'undefined') errs.push(err);
999
+ else errs.write(err.stack + '\n\n');
1000
+ return cb();
1001
+ }
1002
+ function cb(skipped) {
1003
+ if (!skipped) running--;
1004
+ finished++;
1005
+ if (started === finished && running === 0) {
1006
+ if (cback !== undefined) return errs ? cback(errs) : cback(null);
1007
+ }
1008
+ }
1009
+ }
1010
+
1011
+
1012
+
1013
+
1014
+
1015
+
1016
+
1017
+
1018
+
1019
+ var $eebb6ebf9f6069d2$exports = {};
1020
+ $eebb6ebf9f6069d2$exports = JSON.parse("{\"name\":\"@atlaspack/fs\",\"version\":\"2.12.1-canary.3354+7bb54d46a\",\"description\":\"Blazing fast, zero configuration web application bundler\",\"license\":\"MIT\",\"publishConfig\":{\"access\":\"public\"},\"repository\":{\"type\":\"git\",\"url\":\"https://github.com/atlassian-labs/atlaspack.git\"},\"main\":\"lib/index.js\",\"source\":\"src/index.js\",\"types\":\"index.d.ts\",\"engines\":{\"node\":\">= 16.0.0\"},\"targets\":{\"types\":false,\"main\":{\"includeNodeModules\":{\"@atlaspack/core\":false,\"@atlaspack/feature-flags\":false,\"@atlaspack/rust\":false,\"@atlaspack/types-internal\":false,\"@atlaspack/utils\":false,\"@atlaspack/watcher-watchman-js\":false,\"@parcel/watcher\":false,\"@atlaspack/workers\":false}},\"browser\":{\"includeNodeModules\":{\"@atlaspack/core\":false,\"@atlaspack/feature-flags\":false,\"@atlaspack/rust\":false,\"@atlaspack/types-internal\":false,\"@atlaspack/utils\":false,\"@atlaspack/watcher-watchman-js\":false,\"@parcel/watcher\":false,\"@atlaspack/workers\":false}}},\"scripts\":{\"build-ts\":\"mkdir -p lib && flow-to-ts src/types.js > lib/types.d.ts\",\"check-ts\":\"tsc --noEmit index.d.ts\"},\"dependencies\":{\"@atlaspack/feature-flags\":\"2.12.1-canary.3354+7bb54d46a\",\"@atlaspack/rust\":\"2.12.1-canary.3354+7bb54d46a\",\"@atlaspack/types-internal\":\"2.12.1-canary.3354+7bb54d46a\",\"@atlaspack/utils\":\"2.12.1-canary.3354+7bb54d46a\",\"@atlaspack/workers\":\"2.12.1-canary.3354+7bb54d46a\",\"@parcel/watcher\":\"^2.0.7\"},\"devDependencies\":{\"@atlaspack/watcher-watchman-js\":\"2.12.1-canary.3354+7bb54d46a\",\"graceful-fs\":\"^4.2.4\",\"ncp\":\"^2.0.0\",\"nullthrows\":\"^1.1.1\",\"utility-types\":\"^3.10.0\"},\"peerDependencies\":{\"@atlaspack/core\":\"2.12.1-canary.3354+7bb54d46a\"},\"browser\":{\"@atlaspack/fs\":\"./lib/browser.js\",\"./src/NodeFS.js\":\"./src/NodeFS.browser.js\"},\"gitHead\":\"7bb54d46a00c5ba9cdbc2ee426dcbe82c8d79a3e\"}");
1021
+
1022
+
1023
+
1024
+
1025
+ function $c5a03bd108f66311$export$4c6d088a7d7f9947(fs, moduleName, dir) {
1026
+ let { root: root } = (0, ($atlaspack$interopDefault($dlC2Z$path))).parse(dir);
1027
+ while(dir !== root){
1028
+ // Skip node_modules directories
1029
+ if ((0, ($atlaspack$interopDefault($dlC2Z$path))).basename(dir) === 'node_modules') dir = (0, ($atlaspack$interopDefault($dlC2Z$path))).dirname(dir);
1030
+ try {
1031
+ let moduleDir = (0, ($atlaspack$interopDefault($dlC2Z$path))).join(dir, 'node_modules', moduleName);
1032
+ let stats = fs.statSync(moduleDir);
1033
+ if (stats.isDirectory()) return moduleDir;
1034
+ } catch (err) {
1035
+ // ignore
1036
+ }
1037
+ // Move up a directory
1038
+ dir = (0, ($atlaspack$interopDefault($dlC2Z$path))).dirname(dir);
1039
+ }
1040
+ return null;
1041
+ }
1042
+ function $c5a03bd108f66311$export$d51a93c758976388(fs, fileNames, dir, root) {
1043
+ let { root: pathRoot } = (0, ($atlaspack$interopDefault($dlC2Z$path))).parse(dir);
1044
+ // eslint-disable-next-line no-constant-condition
1045
+ while(true){
1046
+ if ((0, ($atlaspack$interopDefault($dlC2Z$path))).basename(dir) === 'node_modules') return null;
1047
+ for (const fileName of fileNames){
1048
+ let filePath = (0, ($atlaspack$interopDefault($dlC2Z$path))).join(dir, fileName);
1049
+ try {
1050
+ if (fs.statSync(filePath).isFile()) return filePath;
1051
+ } catch (err) {
1052
+ // ignore
1053
+ }
1054
+ }
1055
+ if (dir === root || dir === pathRoot) break;
1056
+ dir = (0, ($atlaspack$interopDefault($dlC2Z$path))).dirname(dir);
1057
+ }
1058
+ return null;
1059
+ }
1060
+ function $c5a03bd108f66311$export$64df6e3182fd5b2d(fs, filePaths) {
1061
+ for (let filePath of filePaths)try {
1062
+ if (fs.statSync(filePath).isFile()) return filePath;
1063
+ } catch (err) {
1064
+ // ignore
1065
+ }
1066
+ }
1067
+
1068
+
1069
+ // Most of this can go away once we only support Node 10+, which includes
1070
+ // require('fs').promises
1071
+ const $fd5eb542960b5f45$var$realpath = (0, $dlC2Z$util.promisify)(process.platform === 'win32' ? (0, (/*@__PURE__*/$atlaspack$interopDefault($1b674202ab68c176$exports))).realpath : (0, (/*@__PURE__*/$atlaspack$interopDefault($1b674202ab68c176$exports))).realpath.native);
1072
+ const $fd5eb542960b5f45$var$isPnP = process.versions.pnp != null;
1073
+ function $fd5eb542960b5f45$var$getWatchmanWatcher() {
1074
+ // This is here to trick atlaspack into ignoring this require...
1075
+ const packageName = [
1076
+ '@atlaspack',
1077
+ 'watcher-watchman-js'
1078
+ ].join('/');
1079
+ // $FlowFixMe
1080
+ return require(packageName);
1081
+ }
1082
+ class $fd5eb542960b5f45$export$c4e0ef2ab73c21e7 {
1083
+ readFile = (0, $dlC2Z$util.promisify)((0, (/*@__PURE__*/$atlaspack$interopDefault($1b674202ab68c176$exports))).readFile);
1084
+ copyFile = (0, $dlC2Z$util.promisify)((0, (/*@__PURE__*/$atlaspack$interopDefault($1b674202ab68c176$exports))).copyFile);
1085
+ stat = (0, $dlC2Z$util.promisify)((0, (/*@__PURE__*/$atlaspack$interopDefault($1b674202ab68c176$exports))).stat);
1086
+ readdir = (0, $dlC2Z$util.promisify)((0, (/*@__PURE__*/$atlaspack$interopDefault($1b674202ab68c176$exports))).readdir);
1087
+ symlink = (0, $dlC2Z$util.promisify)((0, (/*@__PURE__*/$atlaspack$interopDefault($1b674202ab68c176$exports))).symlink);
1088
+ unlink = (0, $dlC2Z$util.promisify)((0, (/*@__PURE__*/$atlaspack$interopDefault($1b674202ab68c176$exports))).unlink);
1089
+ utimes = (0, $dlC2Z$util.promisify)((0, (/*@__PURE__*/$atlaspack$interopDefault($1b674202ab68c176$exports))).utimes);
1090
+ ncp = (0, $dlC2Z$util.promisify)((0, (/*@__PURE__*/$atlaspack$interopDefault($c023d554c0890ceb$exports))));
1091
+ createReadStream = (0, (/*@__PURE__*/$atlaspack$interopDefault($1b674202ab68c176$exports))).createReadStream;
1092
+ cwd = ()=>process.cwd();
1093
+ chdir = (directory)=>process.chdir(directory);
1094
+ statSync = (path)=>(0, (/*@__PURE__*/$atlaspack$interopDefault($1b674202ab68c176$exports))).statSync(path);
1095
+ realpathSync = process.platform === 'win32' ? (0, (/*@__PURE__*/$atlaspack$interopDefault($1b674202ab68c176$exports))).realpathSync : (0, (/*@__PURE__*/$atlaspack$interopDefault($1b674202ab68c176$exports))).realpathSync.native;
1096
+ existsSync = (0, (/*@__PURE__*/$atlaspack$interopDefault($1b674202ab68c176$exports))).existsSync;
1097
+ readdirSync = (0, (/*@__PURE__*/$atlaspack$interopDefault($1b674202ab68c176$exports))).readdirSync;
1098
+ findAncestorFile = $fd5eb542960b5f45$var$isPnP ? (...args)=>$c5a03bd108f66311$export$d51a93c758976388(this, ...args) : $dlC2Z$atlaspackrust.findAncestorFile;
1099
+ findNodeModule = $fd5eb542960b5f45$var$isPnP ? (...args)=>$c5a03bd108f66311$export$4c6d088a7d7f9947(this, ...args) : $dlC2Z$atlaspackrust.findNodeModule;
1100
+ findFirstFile = $fd5eb542960b5f45$var$isPnP ? (...args)=>$c5a03bd108f66311$export$64df6e3182fd5b2d(this, ...args) : $dlC2Z$atlaspackrust.findFirstFile;
1101
+ watcher() {
1102
+ return (0, $dlC2Z$atlaspackfeatureflags.getFeatureFlag)('useWatchmanWatcher') ? $fd5eb542960b5f45$var$getWatchmanWatcher() : (0, ($atlaspack$interopDefault($dlC2Z$parcelwatcher)));
1103
+ }
1104
+ createWriteStream(filePath, options) {
1105
+ // Make createWriteStream atomic
1106
+ let tmpFilePath = $fd5eb542960b5f45$var$getTempFilePath(filePath);
1107
+ let failed = false;
1108
+ const move = async ()=>{
1109
+ if (!failed) try {
1110
+ await (0, (/*@__PURE__*/$atlaspack$interopDefault($1b674202ab68c176$exports))).promises.rename(tmpFilePath, filePath);
1111
+ } catch (e) {
1112
+ // This is adapted from fs-write-stream-atomic. Apparently
1113
+ // Windows doesn't like renaming when the target already exists.
1114
+ if (process.platform === 'win32' && e.syscall && e.syscall === 'rename' && e.code && e.code === 'EPERM') {
1115
+ let [hashTmp, hashTarget] = await Promise.all([
1116
+ (0, $dlC2Z$atlaspackutils.hashFile)(this, tmpFilePath),
1117
+ (0, $dlC2Z$atlaspackutils.hashFile)(this, filePath)
1118
+ ]);
1119
+ await this.unlink(tmpFilePath);
1120
+ if (hashTmp != hashTarget) throw e;
1121
+ }
1122
+ }
1123
+ };
1124
+ let writeStream = (0, (/*@__PURE__*/$atlaspack$interopDefault($1b674202ab68c176$exports))).createWriteStream(tmpFilePath, {
1125
+ ...options,
1126
+ fs: {
1127
+ ...(0, (/*@__PURE__*/$atlaspack$interopDefault($1b674202ab68c176$exports))),
1128
+ close: (fd, cb)=>{
1129
+ (0, (/*@__PURE__*/$atlaspack$interopDefault($1b674202ab68c176$exports))).close(fd, (err)=>{
1130
+ if (err) cb(err);
1131
+ else move().then(()=>cb(), (err)=>cb(err));
1132
+ });
1133
+ }
1134
+ }
1135
+ });
1136
+ writeStream.once('error', ()=>{
1137
+ failed = true;
1138
+ (0, (/*@__PURE__*/$atlaspack$interopDefault($1b674202ab68c176$exports))).unlinkSync(tmpFilePath);
1139
+ });
1140
+ return writeStream;
1141
+ }
1142
+ async writeFile(filePath, contents, options) {
1143
+ let tmpFilePath = $fd5eb542960b5f45$var$getTempFilePath(filePath);
1144
+ await (0, (/*@__PURE__*/$atlaspack$interopDefault($1b674202ab68c176$exports))).promises.writeFile(tmpFilePath, contents, options);
1145
+ await (0, (/*@__PURE__*/$atlaspack$interopDefault($1b674202ab68c176$exports))).promises.rename(tmpFilePath, filePath);
1146
+ }
1147
+ readFileSync(filePath, encoding) {
1148
+ if (encoding != null) return (0, (/*@__PURE__*/$atlaspack$interopDefault($1b674202ab68c176$exports))).readFileSync(filePath, encoding);
1149
+ return (0, (/*@__PURE__*/$atlaspack$interopDefault($1b674202ab68c176$exports))).readFileSync(filePath);
1150
+ }
1151
+ async realpath(originalPath) {
1152
+ try {
1153
+ return await $fd5eb542960b5f45$var$realpath(originalPath, 'utf8');
1154
+ } catch (e) {
1155
+ // do nothing
1156
+ }
1157
+ return originalPath;
1158
+ }
1159
+ exists(filePath) {
1160
+ return new Promise((resolve)=>{
1161
+ (0, (/*@__PURE__*/$atlaspack$interopDefault($1b674202ab68c176$exports))).exists(filePath, resolve);
1162
+ });
1163
+ }
1164
+ watch(dir, fn, opts) {
1165
+ return this.watcher().subscribe(dir, fn, opts);
1166
+ }
1167
+ getEventsSince(dir, snapshot, opts) {
1168
+ return this.watcher().getEventsSince(dir, snapshot, opts);
1169
+ }
1170
+ async writeSnapshot(dir, snapshot, opts) {
1171
+ await this.watcher().writeSnapshot(dir, snapshot, opts);
1172
+ }
1173
+ static deserialize() {
1174
+ return new $fd5eb542960b5f45$export$c4e0ef2ab73c21e7();
1175
+ }
1176
+ serialize() {
1177
+ return null;
1178
+ }
1179
+ async mkdirp(filePath) {
1180
+ await (0, ($atlaspack$interopDefault($dlC2Z$fs))).promises.mkdir(filePath, {
1181
+ recursive: true
1182
+ });
1183
+ }
1184
+ async rimraf(filePath) {
1185
+ if ((0, (/*@__PURE__*/$atlaspack$interopDefault($1b674202ab68c176$exports))).promises.rm) {
1186
+ await (0, (/*@__PURE__*/$atlaspack$interopDefault($1b674202ab68c176$exports))).promises.rm(filePath, {
1187
+ recursive: true,
1188
+ force: true
1189
+ });
1190
+ return;
1191
+ }
1192
+ // fs.promises.rm is not supported in node 12...
1193
+ let stat;
1194
+ try {
1195
+ stat = await this.stat(filePath);
1196
+ } catch (err) {
1197
+ return;
1198
+ }
1199
+ if (stat.isDirectory()) // $FlowFixMe
1200
+ await (0, ($atlaspack$interopDefault($dlC2Z$fs))).promises.rmdir(filePath, {
1201
+ recursive: true
1202
+ });
1203
+ else await (0, ($atlaspack$interopDefault($dlC2Z$fs))).promises.unlink(filePath);
1204
+ }
1205
+ }
1206
+ (0, $dlC2Z$atlaspackcore.registerSerializableClass)(`${(0, (/*@__PURE__*/$atlaspack$interopDefault($eebb6ebf9f6069d2$exports))).version}:NodeFS`, $fd5eb542960b5f45$export$c4e0ef2ab73c21e7);
1207
+ let $fd5eb542960b5f45$var$writeStreamCalls = 0;
1208
+ let $fd5eb542960b5f45$var$threadId;
1209
+
1210
+ try {
1211
+ ({ threadId: $fd5eb542960b5f45$var$threadId } = $fd5eb542960b5f45$import$9c2ae04019a9b9e3);
1212
+ } catch {
1213
+ //
1214
+ }
1215
+ let $fd5eb542960b5f45$var$useOsTmpDir;
1216
+ function $fd5eb542960b5f45$var$shouldUseOsTmpDir(filePath) {
1217
+ if ($fd5eb542960b5f45$var$useOsTmpDir != null) return $fd5eb542960b5f45$var$useOsTmpDir;
1218
+ try {
1219
+ const tmpDir = (0, $dlC2Z$os.tmpdir)();
1220
+ (0, ($atlaspack$interopDefault($dlC2Z$fs))).accessSync(tmpDir, (0, ($atlaspack$interopDefault($dlC2Z$fs))).constants.R_OK | (0, ($atlaspack$interopDefault($dlC2Z$fs))).constants.W_OK);
1221
+ const tmpDirStats = (0, ($atlaspack$interopDefault($dlC2Z$fs))).statSync(tmpDir);
1222
+ const filePathStats = (0, ($atlaspack$interopDefault($dlC2Z$fs))).statSync(filePath);
1223
+ // Check the tmpdir is on the same partition as the target directory.
1224
+ // This is required to ensure renaming is an atomic operation.
1225
+ $fd5eb542960b5f45$var$useOsTmpDir = tmpDirStats.dev === filePathStats.dev;
1226
+ } catch (e) {
1227
+ // We don't have read/write access to the OS tmp directory
1228
+ $fd5eb542960b5f45$var$useOsTmpDir = false;
1229
+ }
1230
+ return $fd5eb542960b5f45$var$useOsTmpDir;
1231
+ }
1232
+ // Generate a temporary file path used for atomic writing of files.
1233
+ function $fd5eb542960b5f45$var$getTempFilePath(filePath) {
1234
+ $fd5eb542960b5f45$var$writeStreamCalls = $fd5eb542960b5f45$var$writeStreamCalls % Number.MAX_SAFE_INTEGER;
1235
+ let tmpFilePath = filePath;
1236
+ // If possible, write the tmp file to the OS tmp directory
1237
+ // This reduces the amount of FS events the watcher needs to process during the build
1238
+ if ($fd5eb542960b5f45$var$shouldUseOsTmpDir(filePath)) tmpFilePath = (0, ($atlaspack$interopDefault($dlC2Z$path))).join((0, $dlC2Z$os.tmpdir)(), (0, ($atlaspack$interopDefault($dlC2Z$path))).basename(filePath));
1239
+ return tmpFilePath + '.' + process.pid + ($fd5eb542960b5f45$var$threadId != null ? '.' + $fd5eb542960b5f45$var$threadId : '') + '.' + ($fd5eb542960b5f45$var$writeStreamCalls++).toString(36);
1240
+ }
1241
+
1242
+
1243
+ var $7b991d7841c5927f$exports = {};
1244
+
1245
+ $atlaspack$export($7b991d7841c5927f$exports, "MemoryFS", () => $7b991d7841c5927f$export$3048eb7ec07c2c4e);
1246
+ $atlaspack$export($7b991d7841c5927f$exports, "FSError", () => $7b991d7841c5927f$export$d414276624ebf134);
1247
+ $atlaspack$export($7b991d7841c5927f$exports, "makeShared", () => $7b991d7841c5927f$export$df9eb3e75aa27a22);
1248
+ $atlaspack$export($7b991d7841c5927f$exports, "File", () => $7b991d7841c5927f$export$b6afa8811b7e644e);
1249
+
1250
+
1251
+
1252
+
1253
+
1254
+
1255
+ var $1acbdc46f00ee4fb$exports = {};
1256
+ 'use strict';
1257
+ function $1acbdc46f00ee4fb$var$nullthrows(x, message) {
1258
+ if (x != null) return x;
1259
+ var error = new Error(message !== undefined ? message : 'Got unexpected ' + x);
1260
+ error.framesToPop = 1; // Skip nullthrows's own stack frame.
1261
+ throw error;
1262
+ }
1263
+ $1acbdc46f00ee4fb$exports = $1acbdc46f00ee4fb$var$nullthrows;
1264
+ $1acbdc46f00ee4fb$exports.default = $1acbdc46f00ee4fb$var$nullthrows;
1265
+ Object.defineProperty($1acbdc46f00ee4fb$exports, '__esModule', {
1266
+ value: true
1267
+ });
1268
+
1269
+
1270
+
1271
+
1272
+ const $7b991d7841c5927f$var$instances = new Map();
1273
+ let $7b991d7841c5927f$var$id = 0;
1274
+ class $7b991d7841c5927f$export$3048eb7ec07c2c4e {
1275
+ _numWorkerInstances = 0;
1276
+ _workerRegisterResolves = [];
1277
+ _emitter = new (0, ($atlaspack$interopDefault($dlC2Z$events)))();
1278
+ constructor(workerFarm){
1279
+ this.farm = workerFarm;
1280
+ this._cwd = (0, ($atlaspack$interopDefault($dlC2Z$path))).resolve((0, ($atlaspack$interopDefault($dlC2Z$path))).sep);
1281
+ this.dirs = new Map([
1282
+ [
1283
+ this._cwd,
1284
+ new $7b991d7841c5927f$var$Directory()
1285
+ ]
1286
+ ]);
1287
+ this.files = new Map();
1288
+ this.symlinks = new Map();
1289
+ this.watchers = new Map();
1290
+ this.events = [];
1291
+ this.id = $7b991d7841c5927f$var$id++;
1292
+ this._workerHandles = [];
1293
+ this._eventQueue = [];
1294
+ $7b991d7841c5927f$var$instances.set(this.id, this);
1295
+ this._emitter.on('allWorkersRegistered', ()=>{
1296
+ for (let resolve of this._workerRegisterResolves)resolve();
1297
+ this._workerRegisterResolves = [];
1298
+ });
1299
+ }
1300
+ static deserialize(opts) {
1301
+ let existing = $7b991d7841c5927f$var$instances.get(opts.id);
1302
+ if (existing != null) {
1303
+ // Correct the count of worker instances since serialization assumes a new instance is created
1304
+ (0, ($atlaspack$interopDefault($dlC2Z$atlaspackworkers))).getWorkerApi().runHandle(opts.handle, [
1305
+ 'decrementWorkerInstance',
1306
+ []
1307
+ ]);
1308
+ return existing;
1309
+ }
1310
+ let fs = new $7b991d7841c5927f$var$WorkerFS(opts.id, (0, (/*@__PURE__*/$atlaspack$interopDefault($1acbdc46f00ee4fb$exports)))(opts.handle));
1311
+ fs.dirs = opts.dirs;
1312
+ fs.files = opts.files;
1313
+ fs.symlinks = opts.symlinks;
1314
+ return fs;
1315
+ }
1316
+ serialize() {
1317
+ if (!this.handle) this.handle = this.farm.createReverseHandle((fn, args)=>{
1318
+ // $FlowFixMe
1319
+ return this[fn](...args);
1320
+ });
1321
+ // If a worker instance already exists, it will decrement this number
1322
+ this._numWorkerInstances++;
1323
+ return {
1324
+ $$raw: false,
1325
+ id: this.id,
1326
+ handle: this.handle,
1327
+ dirs: this.dirs,
1328
+ files: this.files,
1329
+ symlinks: this.symlinks
1330
+ };
1331
+ }
1332
+ decrementWorkerInstance() {
1333
+ this._numWorkerInstances--;
1334
+ if (this._numWorkerInstances === this._workerHandles.length) this._emitter.emit('allWorkersRegistered');
1335
+ }
1336
+ cwd() {
1337
+ return this._cwd;
1338
+ }
1339
+ chdir(dir) {
1340
+ this._cwd = dir;
1341
+ }
1342
+ _normalizePath(filePath, realpath = true) {
1343
+ filePath = (0, ($atlaspack$interopDefault($dlC2Z$path))).normalize(filePath);
1344
+ if (!filePath.startsWith(this.cwd())) filePath = (0, ($atlaspack$interopDefault($dlC2Z$path))).resolve(this.cwd(), filePath);
1345
+ // get realpath by following symlinks
1346
+ if (realpath) {
1347
+ let { root: root, dir: dir, base: base } = (0, ($atlaspack$interopDefault($dlC2Z$path))).parse(filePath);
1348
+ let parts = dir.slice(root.length).split((0, ($atlaspack$interopDefault($dlC2Z$path))).sep).concat(base);
1349
+ let res = root;
1350
+ for (let part of parts){
1351
+ res = (0, ($atlaspack$interopDefault($dlC2Z$path))).join(res, part);
1352
+ let symlink = this.symlinks.get(res);
1353
+ if (symlink) res = symlink;
1354
+ }
1355
+ return res;
1356
+ }
1357
+ return filePath;
1358
+ }
1359
+ async writeFile(filePath, contents, options) {
1360
+ filePath = this._normalizePath(filePath);
1361
+ if (this.dirs.has(filePath)) throw new $7b991d7841c5927f$export$d414276624ebf134('EISDIR', filePath, 'is a directory');
1362
+ let dir = (0, ($atlaspack$interopDefault($dlC2Z$path))).dirname(filePath);
1363
+ if (!this.dirs.has(dir)) throw new $7b991d7841c5927f$export$d414276624ebf134('ENOENT', dir, 'does not exist');
1364
+ let buffer = $7b991d7841c5927f$export$df9eb3e75aa27a22(contents);
1365
+ let file = this.files.get(filePath);
1366
+ let mode = options && options.mode || 438;
1367
+ if (file) {
1368
+ file.write(buffer, mode);
1369
+ this.files.set(filePath, file);
1370
+ } else this.files.set(filePath, new $7b991d7841c5927f$export$b6afa8811b7e644e(buffer, mode));
1371
+ await this._sendWorkerEvent({
1372
+ type: 'writeFile',
1373
+ path: filePath,
1374
+ entry: this.files.get(filePath)
1375
+ });
1376
+ this._triggerEvent({
1377
+ type: file ? 'update' : 'create',
1378
+ path: filePath
1379
+ });
1380
+ }
1381
+ // eslint-disable-next-line require-await
1382
+ async readFile(filePath, encoding) {
1383
+ return this.readFileSync(filePath, encoding);
1384
+ }
1385
+ readFileSync(filePath, encoding) {
1386
+ filePath = this._normalizePath(filePath);
1387
+ let file = this.files.get(filePath);
1388
+ if (file == null) throw new $7b991d7841c5927f$export$d414276624ebf134('ENOENT', filePath, 'does not exist');
1389
+ let buffer = file.read();
1390
+ if (encoding) return buffer.toString(encoding);
1391
+ return buffer;
1392
+ }
1393
+ async copyFile(source, destination) {
1394
+ let contents = await this.readFile(source);
1395
+ await this.writeFile(destination, contents);
1396
+ }
1397
+ statSync(filePath) {
1398
+ filePath = this._normalizePath(filePath);
1399
+ let dir = this.dirs.get(filePath);
1400
+ if (dir) return dir.stat();
1401
+ let file = this.files.get(filePath);
1402
+ if (file == null) throw new $7b991d7841c5927f$export$d414276624ebf134('ENOENT', filePath, 'does not exist');
1403
+ return file.stat();
1404
+ }
1405
+ // eslint-disable-next-line require-await
1406
+ async stat(filePath) {
1407
+ return this.statSync(filePath);
1408
+ }
1409
+ readdirSync(dir, opts) {
1410
+ dir = this._normalizePath(dir);
1411
+ if (!this.dirs.has(dir)) throw new $7b991d7841c5927f$export$d414276624ebf134('ENOENT', dir, 'does not exist');
1412
+ if (!dir.endsWith((0, ($atlaspack$interopDefault($dlC2Z$path))).sep)) dir += (0, ($atlaspack$interopDefault($dlC2Z$path))).sep;
1413
+ let res = [];
1414
+ for (let [filePath, entry] of this.dirs){
1415
+ if (filePath === dir) continue;
1416
+ if (filePath.startsWith(dir) && filePath.indexOf((0, ($atlaspack$interopDefault($dlC2Z$path))).sep, dir.length) === -1) {
1417
+ let name = filePath.slice(dir.length);
1418
+ if (opts?.withFileTypes) res.push(new $7b991d7841c5927f$var$Dirent(name, entry));
1419
+ else res.push(name);
1420
+ }
1421
+ }
1422
+ for (let [filePath, entry] of this.files)if (filePath.startsWith(dir) && filePath.indexOf((0, ($atlaspack$interopDefault($dlC2Z$path))).sep, dir.length) === -1) {
1423
+ let name = filePath.slice(dir.length);
1424
+ if (opts?.withFileTypes) res.push(new $7b991d7841c5927f$var$Dirent(name, entry));
1425
+ else res.push(name);
1426
+ }
1427
+ for (let [from] of this.symlinks)if (from.startsWith(dir) && from.indexOf((0, ($atlaspack$interopDefault($dlC2Z$path))).sep, dir.length) === -1) {
1428
+ let name = from.slice(dir.length);
1429
+ if (opts?.withFileTypes) res.push(new $7b991d7841c5927f$var$Dirent(name, {
1430
+ mode: $7b991d7841c5927f$var$S_IFLNK
1431
+ }));
1432
+ else res.push(name);
1433
+ }
1434
+ return res;
1435
+ }
1436
+ // eslint-disable-next-line require-await
1437
+ async readdir(dir, opts) {
1438
+ return this.readdirSync(dir, opts);
1439
+ }
1440
+ async unlink(filePath) {
1441
+ filePath = this._normalizePath(filePath);
1442
+ if (!this.files.has(filePath) && !this.dirs.has(filePath)) throw new $7b991d7841c5927f$export$d414276624ebf134('ENOENT', filePath, 'does not exist');
1443
+ this.files.delete(filePath);
1444
+ this.dirs.delete(filePath);
1445
+ this.watchers.delete(filePath);
1446
+ await this._sendWorkerEvent({
1447
+ type: 'unlink',
1448
+ path: filePath
1449
+ });
1450
+ this._triggerEvent({
1451
+ type: 'delete',
1452
+ path: filePath
1453
+ });
1454
+ return Promise.resolve();
1455
+ }
1456
+ async mkdirp(dir) {
1457
+ dir = this._normalizePath(dir);
1458
+ if (this.dirs.has(dir)) return Promise.resolve();
1459
+ if (this.files.has(dir)) throw new $7b991d7841c5927f$export$d414276624ebf134('ENOENT', dir, 'is not a directory');
1460
+ let root = (0, ($atlaspack$interopDefault($dlC2Z$path))).parse(dir).root;
1461
+ while(dir !== root){
1462
+ if (this.dirs.has(dir)) break;
1463
+ this.dirs.set(dir, new $7b991d7841c5927f$var$Directory());
1464
+ await this._sendWorkerEvent({
1465
+ type: 'mkdir',
1466
+ path: dir
1467
+ });
1468
+ this._triggerEvent({
1469
+ type: 'create',
1470
+ path: dir
1471
+ });
1472
+ dir = (0, ($atlaspack$interopDefault($dlC2Z$path))).dirname(dir);
1473
+ }
1474
+ return Promise.resolve();
1475
+ }
1476
+ async rimraf(filePath) {
1477
+ filePath = this._normalizePath(filePath);
1478
+ if (this.dirs.has(filePath)) {
1479
+ let dir = filePath + (0, ($atlaspack$interopDefault($dlC2Z$path))).sep;
1480
+ for (let filePath of this.files.keys())if (filePath.startsWith(dir)) {
1481
+ this.files.delete(filePath);
1482
+ await this._sendWorkerEvent({
1483
+ type: 'unlink',
1484
+ path: filePath
1485
+ });
1486
+ this._triggerEvent({
1487
+ type: 'delete',
1488
+ path: filePath
1489
+ });
1490
+ }
1491
+ for (let dirPath of this.dirs.keys())if (dirPath.startsWith(dir)) {
1492
+ this.dirs.delete(dirPath);
1493
+ this.watchers.delete(dirPath);
1494
+ await this._sendWorkerEvent({
1495
+ type: 'unlink',
1496
+ path: filePath
1497
+ });
1498
+ this._triggerEvent({
1499
+ type: 'delete',
1500
+ path: dirPath
1501
+ });
1502
+ }
1503
+ for (let filePath of this.symlinks.keys())if (filePath.startsWith(dir)) {
1504
+ this.symlinks.delete(filePath);
1505
+ await this._sendWorkerEvent({
1506
+ type: 'unlink',
1507
+ path: filePath
1508
+ });
1509
+ }
1510
+ this.dirs.delete(filePath);
1511
+ await this._sendWorkerEvent({
1512
+ type: 'unlink',
1513
+ path: filePath
1514
+ });
1515
+ this._triggerEvent({
1516
+ type: 'delete',
1517
+ path: filePath
1518
+ });
1519
+ } else if (this.files.has(filePath)) {
1520
+ this.files.delete(filePath);
1521
+ await this._sendWorkerEvent({
1522
+ type: 'unlink',
1523
+ path: filePath
1524
+ });
1525
+ this._triggerEvent({
1526
+ type: 'delete',
1527
+ path: filePath
1528
+ });
1529
+ }
1530
+ return Promise.resolve();
1531
+ }
1532
+ async ncp(source, destination) {
1533
+ source = this._normalizePath(source);
1534
+ if (this.dirs.has(source)) {
1535
+ if (!this.dirs.has(destination)) {
1536
+ this.dirs.set(destination, new $7b991d7841c5927f$var$Directory());
1537
+ await this._sendWorkerEvent({
1538
+ type: 'mkdir',
1539
+ path: destination
1540
+ });
1541
+ this._triggerEvent({
1542
+ type: 'create',
1543
+ path: destination
1544
+ });
1545
+ }
1546
+ let dir = source + (0, ($atlaspack$interopDefault($dlC2Z$path))).sep;
1547
+ for (let dirPath of this.dirs.keys())if (dirPath.startsWith(dir)) {
1548
+ let destName = (0, ($atlaspack$interopDefault($dlC2Z$path))).join(destination, dirPath.slice(dir.length));
1549
+ if (!this.dirs.has(destName)) {
1550
+ this.dirs.set(destName, new $7b991d7841c5927f$var$Directory());
1551
+ await this._sendWorkerEvent({
1552
+ type: 'mkdir',
1553
+ path: destination
1554
+ });
1555
+ this._triggerEvent({
1556
+ type: 'create',
1557
+ path: destName
1558
+ });
1559
+ }
1560
+ }
1561
+ for (let [filePath, file] of this.files)if (filePath.startsWith(dir)) {
1562
+ let destName = (0, ($atlaspack$interopDefault($dlC2Z$path))).join(destination, filePath.slice(dir.length));
1563
+ let exists = this.files.has(destName);
1564
+ this.files.set(destName, file);
1565
+ await this._sendWorkerEvent({
1566
+ type: 'writeFile',
1567
+ path: destName,
1568
+ entry: file
1569
+ });
1570
+ this._triggerEvent({
1571
+ type: exists ? 'update' : 'create',
1572
+ path: destName
1573
+ });
1574
+ }
1575
+ } else await this.copyFile(source, destination);
1576
+ }
1577
+ createReadStream(filePath) {
1578
+ return new $7b991d7841c5927f$var$ReadStream(this, filePath);
1579
+ }
1580
+ createWriteStream(filePath, options) {
1581
+ return new $7b991d7841c5927f$var$WriteStream(this, filePath, options);
1582
+ }
1583
+ realpathSync(filePath) {
1584
+ return this._normalizePath(filePath);
1585
+ }
1586
+ // eslint-disable-next-line require-await
1587
+ async realpath(filePath) {
1588
+ return this.realpathSync(filePath);
1589
+ }
1590
+ async symlink(target, path) {
1591
+ target = this._normalizePath(target);
1592
+ path = this._normalizePath(path);
1593
+ this.symlinks.set(path, target);
1594
+ await this._sendWorkerEvent({
1595
+ type: 'symlink',
1596
+ path: path,
1597
+ target: target
1598
+ });
1599
+ }
1600
+ existsSync(filePath) {
1601
+ filePath = this._normalizePath(filePath);
1602
+ return this.files.has(filePath) || this.dirs.has(filePath);
1603
+ }
1604
+ // eslint-disable-next-line require-await
1605
+ async exists(filePath) {
1606
+ return this.existsSync(filePath);
1607
+ }
1608
+ _triggerEvent(event) {
1609
+ this.events.push(event);
1610
+ if (this.watchers.size === 0) return;
1611
+ // Batch events
1612
+ this._eventQueue.push(event);
1613
+ clearTimeout(this._watcherTimer);
1614
+ this._watcherTimer = setTimeout(()=>{
1615
+ let events = this._eventQueue;
1616
+ this._eventQueue = [];
1617
+ for (let [dir, watchers] of this.watchers){
1618
+ if (!dir.endsWith((0, ($atlaspack$interopDefault($dlC2Z$path))).sep)) dir += (0, ($atlaspack$interopDefault($dlC2Z$path))).sep;
1619
+ if (event.path.startsWith(dir)) for (let watcher of watchers)watcher.trigger(events);
1620
+ }
1621
+ }, 50);
1622
+ }
1623
+ _registerWorker(handle) {
1624
+ this._workerHandles.push(handle);
1625
+ if (this._numWorkerInstances === this._workerHandles.length) this._emitter.emit('allWorkersRegistered');
1626
+ }
1627
+ async _sendWorkerEvent(event) {
1628
+ // Wait for worker instances to register their handles
1629
+ while(this._workerHandles.length < this._numWorkerInstances)await new Promise((resolve)=>this._workerRegisterResolves.push(resolve));
1630
+ await Promise.all(this._workerHandles.map((workerHandle)=>this.farm.workerApi.runHandle(workerHandle, [
1631
+ event
1632
+ ])));
1633
+ }
1634
+ watch(dir, fn, opts) {
1635
+ dir = this._normalizePath(dir);
1636
+ let watcher = new $7b991d7841c5927f$var$Watcher(fn, opts);
1637
+ let watchers = this.watchers.get(dir);
1638
+ if (!watchers) {
1639
+ watchers = new Set();
1640
+ this.watchers.set(dir, watchers);
1641
+ }
1642
+ watchers.add(watcher);
1643
+ return Promise.resolve({
1644
+ unsubscribe: ()=>{
1645
+ watchers = (0, (/*@__PURE__*/$atlaspack$interopDefault($1acbdc46f00ee4fb$exports)))(watchers);
1646
+ watchers.delete(watcher);
1647
+ if (watchers.size === 0) this.watchers.delete(dir);
1648
+ return Promise.resolve();
1649
+ }
1650
+ });
1651
+ }
1652
+ async getEventsSince(dir, snapshot, opts) {
1653
+ let contents = await this.readFile(snapshot, 'utf8');
1654
+ let len = Number(contents);
1655
+ let events = this.events.slice(len);
1656
+ let ignore = opts.ignore;
1657
+ if (ignore) events = events.filter((event)=>!ignore.some((i)=>event.path.startsWith(i + (0, ($atlaspack$interopDefault($dlC2Z$path))).sep)));
1658
+ return events;
1659
+ }
1660
+ async writeSnapshot(dir, snapshot) {
1661
+ await this.writeFile(snapshot, '' + this.events.length);
1662
+ }
1663
+ findAncestorFile(fileNames, fromDir, root) {
1664
+ return (0, $c5a03bd108f66311$export$d51a93c758976388)(this, fileNames, fromDir, root);
1665
+ }
1666
+ findNodeModule(moduleName, fromDir) {
1667
+ return (0, $c5a03bd108f66311$export$4c6d088a7d7f9947)(this, moduleName, fromDir);
1668
+ }
1669
+ findFirstFile(filePaths) {
1670
+ return (0, $c5a03bd108f66311$export$64df6e3182fd5b2d)(this, filePaths);
1671
+ }
1672
+ }
1673
+ class $7b991d7841c5927f$var$Watcher {
1674
+ constructor(fn, options){
1675
+ this.fn = fn;
1676
+ this.options = options;
1677
+ }
1678
+ trigger(events) {
1679
+ let ignore = this.options.ignore;
1680
+ if (ignore) events = events.filter((event)=>!ignore.some((i)=>event.path.startsWith(i + (0, ($atlaspack$interopDefault($dlC2Z$path))).sep)));
1681
+ if (events.length > 0) this.fn(null, events);
1682
+ }
1683
+ }
1684
+ class $7b991d7841c5927f$export$d414276624ebf134 extends Error {
1685
+ constructor(code, path, message){
1686
+ super(`${code}: ${path} ${message}`);
1687
+ this.name = 'FSError';
1688
+ this.code = code;
1689
+ this.path = path;
1690
+ Error.captureStackTrace?.(this, this.constructor);
1691
+ }
1692
+ }
1693
+ class $7b991d7841c5927f$var$ReadStream extends (0, $dlC2Z$stream.Readable) {
1694
+ constructor(fs, filePath){
1695
+ super();
1696
+ this.fs = fs;
1697
+ this.filePath = filePath;
1698
+ this.reading = false;
1699
+ this.bytesRead = 0;
1700
+ }
1701
+ _read() {
1702
+ if (this.reading) return;
1703
+ this.reading = true;
1704
+ this.fs.readFile(this.filePath).then((res)=>{
1705
+ this.bytesRead += res.byteLength;
1706
+ this.push(res);
1707
+ this.push(null);
1708
+ }, (err)=>{
1709
+ this.emit('error', err);
1710
+ });
1711
+ }
1712
+ }
1713
+ class $7b991d7841c5927f$var$WriteStream extends (0, $dlC2Z$stream.Writable) {
1714
+ constructor(fs, filePath, options){
1715
+ super({
1716
+ emitClose: true,
1717
+ autoDestroy: true
1718
+ });
1719
+ this.fs = fs;
1720
+ this.filePath = filePath;
1721
+ this.options = options;
1722
+ this.buffer = Buffer.alloc(0);
1723
+ }
1724
+ _write(chunk, encoding, callback) {
1725
+ let c = typeof chunk === 'string' ? Buffer.from(chunk, encoding) : chunk;
1726
+ this.buffer = Buffer.concat([
1727
+ this.buffer,
1728
+ c
1729
+ ]);
1730
+ callback();
1731
+ }
1732
+ _final(callback) {
1733
+ this.fs.writeFile(this.filePath, this.buffer, this.options).then(callback).catch(callback);
1734
+ }
1735
+ }
1736
+ const $7b991d7841c5927f$var$S_IFREG = 32768;
1737
+ const $7b991d7841c5927f$var$S_IFDIR = 16384;
1738
+ const $7b991d7841c5927f$var$S_IFLNK = 40960;
1739
+ const $7b991d7841c5927f$var$S_IFMT = 61440;
1740
+ class $7b991d7841c5927f$var$Entry {
1741
+ constructor(mode){
1742
+ this.mode = mode;
1743
+ let now = Date.now();
1744
+ this.atime = now;
1745
+ this.mtime = now;
1746
+ this.ctime = now;
1747
+ this.birthtime = now;
1748
+ }
1749
+ access() {
1750
+ let now = Date.now();
1751
+ this.atime = now;
1752
+ this.ctime = now;
1753
+ }
1754
+ modify(mode) {
1755
+ let now = Date.now();
1756
+ this.mtime = now;
1757
+ this.ctime = now;
1758
+ this.mode = mode;
1759
+ }
1760
+ getSize() {
1761
+ return 0;
1762
+ }
1763
+ stat() {
1764
+ return new $7b991d7841c5927f$var$Stat(this);
1765
+ }
1766
+ }
1767
+ class $7b991d7841c5927f$var$Stat {
1768
+ dev = 0;
1769
+ ino = 0;
1770
+ nlink = 0;
1771
+ uid = 0;
1772
+ gid = 0;
1773
+ rdev = 0;
1774
+ blksize = 0;
1775
+ blocks = 0;
1776
+ constructor(entry){
1777
+ this.mode = entry.mode;
1778
+ this.size = entry.getSize();
1779
+ this.atimeMs = entry.atime;
1780
+ this.mtimeMs = entry.mtime;
1781
+ this.ctimeMs = entry.ctime;
1782
+ this.birthtimeMs = entry.birthtime;
1783
+ this.atime = new Date(entry.atime);
1784
+ this.mtime = new Date(entry.mtime);
1785
+ this.ctime = new Date(entry.ctime);
1786
+ this.birthtime = new Date(entry.birthtime);
1787
+ }
1788
+ isFile() {
1789
+ return Boolean(this.mode & $7b991d7841c5927f$var$S_IFREG);
1790
+ }
1791
+ isDirectory() {
1792
+ return Boolean(this.mode & $7b991d7841c5927f$var$S_IFDIR);
1793
+ }
1794
+ isBlockDevice() {
1795
+ return false;
1796
+ }
1797
+ isCharacterDevice() {
1798
+ return false;
1799
+ }
1800
+ isSymbolicLink() {
1801
+ return false;
1802
+ }
1803
+ isFIFO() {
1804
+ return false;
1805
+ }
1806
+ isSocket() {
1807
+ return false;
1808
+ }
1809
+ }
1810
+ class $7b991d7841c5927f$var$Dirent {
1811
+ #mode;
1812
+ constructor(name, entry){
1813
+ this.name = name;
1814
+ this.#mode = entry.mode;
1815
+ }
1816
+ isFile() {
1817
+ return (this.#mode & $7b991d7841c5927f$var$S_IFMT) === $7b991d7841c5927f$var$S_IFREG;
1818
+ }
1819
+ isDirectory() {
1820
+ return (this.#mode & $7b991d7841c5927f$var$S_IFMT) === $7b991d7841c5927f$var$S_IFDIR;
1821
+ }
1822
+ isBlockDevice() {
1823
+ return false;
1824
+ }
1825
+ isCharacterDevice() {
1826
+ return false;
1827
+ }
1828
+ isSymbolicLink() {
1829
+ return (this.#mode & $7b991d7841c5927f$var$S_IFMT) === $7b991d7841c5927f$var$S_IFLNK;
1830
+ }
1831
+ isFIFO() {
1832
+ return false;
1833
+ }
1834
+ isSocket() {
1835
+ return false;
1836
+ }
1837
+ }
1838
+ class $7b991d7841c5927f$export$b6afa8811b7e644e extends $7b991d7841c5927f$var$Entry {
1839
+ constructor(buffer, mode){
1840
+ super($7b991d7841c5927f$var$S_IFREG | mode);
1841
+ this.buffer = buffer;
1842
+ }
1843
+ read() {
1844
+ super.access();
1845
+ return Buffer.from(this.buffer);
1846
+ }
1847
+ write(buffer, mode) {
1848
+ super.modify($7b991d7841c5927f$var$S_IFREG | mode);
1849
+ this.buffer = buffer;
1850
+ }
1851
+ getSize() {
1852
+ return this.buffer.byteLength;
1853
+ }
1854
+ }
1855
+ class $7b991d7841c5927f$var$Directory extends $7b991d7841c5927f$var$Entry {
1856
+ constructor(){
1857
+ super($7b991d7841c5927f$var$S_IFDIR);
1858
+ }
1859
+ }
1860
+ function $7b991d7841c5927f$export$df9eb3e75aa27a22(contents) {
1861
+ if (typeof contents !== 'string' && contents.buffer instanceof (0, $dlC2Z$atlaspackutils.SharedBuffer)) return contents;
1862
+ let contentsBuffer = contents;
1863
+ // $FlowFixMe
1864
+ if (process.browser) // For the polyfilled buffer module, it's faster to always convert once so that the subsequent
1865
+ // operations are fast (.byteLength and using .set instead of .write)
1866
+ contentsBuffer = contentsBuffer instanceof Buffer ? contentsBuffer : Buffer.from(contentsBuffer);
1867
+ let length = Buffer.byteLength(contentsBuffer);
1868
+ let shared = new (0, $dlC2Z$atlaspackutils.SharedBuffer)(length);
1869
+ let buffer = Buffer.from(shared);
1870
+ if (length > 0) {
1871
+ if (typeof contentsBuffer === 'string') buffer.write(contentsBuffer);
1872
+ else buffer.set(contentsBuffer);
1873
+ }
1874
+ return buffer;
1875
+ }
1876
+ class $7b991d7841c5927f$var$WorkerFS extends $7b991d7841c5927f$export$3048eb7ec07c2c4e {
1877
+ constructor(id, handle){
1878
+ // TODO Make this not a subclass
1879
+ // $FlowFixMe
1880
+ super();
1881
+ this.id = id;
1882
+ this.handleFn = (methodName, args)=>(0, ($atlaspack$interopDefault($dlC2Z$atlaspackworkers))).getWorkerApi().runHandle(handle, [
1883
+ methodName,
1884
+ args
1885
+ ]);
1886
+ this.handleFn('_registerWorker', [
1887
+ (0, ($atlaspack$interopDefault($dlC2Z$atlaspackworkers))).getWorkerApi().createReverseHandle((event)=>{
1888
+ switch(event.type){
1889
+ case 'writeFile':
1890
+ this.files.set(event.path, event.entry);
1891
+ break;
1892
+ case 'unlink':
1893
+ this.files.delete(event.path);
1894
+ this.dirs.delete(event.path);
1895
+ this.symlinks.delete(event.path);
1896
+ break;
1897
+ case 'mkdir':
1898
+ this.dirs.set(event.path, new $7b991d7841c5927f$var$Directory());
1899
+ break;
1900
+ case 'symlink':
1901
+ this.symlinks.set(event.path, event.target);
1902
+ break;
1903
+ }
1904
+ })
1905
+ ]);
1906
+ }
1907
+ static deserialize(opts) {
1908
+ return (0, (/*@__PURE__*/$atlaspack$interopDefault($1acbdc46f00ee4fb$exports)))($7b991d7841c5927f$var$instances.get(opts.id));
1909
+ }
1910
+ serialize() {
1911
+ // $FlowFixMe
1912
+ return {
1913
+ id: this.id
1914
+ };
1915
+ }
1916
+ writeFile(filePath, contents, options) {
1917
+ super.writeFile(filePath, contents, options);
1918
+ let buffer = $7b991d7841c5927f$export$df9eb3e75aa27a22(contents);
1919
+ return this.handleFn('writeFile', [
1920
+ filePath,
1921
+ buffer,
1922
+ options
1923
+ ]);
1924
+ }
1925
+ unlink(filePath) {
1926
+ super.unlink(filePath);
1927
+ return this.handleFn('unlink', [
1928
+ filePath
1929
+ ]);
1930
+ }
1931
+ mkdirp(dir) {
1932
+ super.mkdirp(dir);
1933
+ return this.handleFn('mkdirp', [
1934
+ dir
1935
+ ]);
1936
+ }
1937
+ rimraf(filePath) {
1938
+ super.rimraf(filePath);
1939
+ return this.handleFn('rimraf', [
1940
+ filePath
1941
+ ]);
1942
+ }
1943
+ ncp(source, destination) {
1944
+ super.ncp(source, destination);
1945
+ return this.handleFn('ncp', [
1946
+ source,
1947
+ destination
1948
+ ]);
1949
+ }
1950
+ symlink(target, path) {
1951
+ super.symlink(target, path);
1952
+ return this.handleFn('symlink', [
1953
+ target,
1954
+ path
1955
+ ]);
1956
+ }
1957
+ }
1958
+ (0, $dlC2Z$atlaspackcore.registerSerializableClass)(`${(0, (/*@__PURE__*/$atlaspack$interopDefault($eebb6ebf9f6069d2$exports))).version}:MemoryFS`, $7b991d7841c5927f$export$3048eb7ec07c2c4e);
1959
+ (0, $dlC2Z$atlaspackcore.registerSerializableClass)(`${(0, (/*@__PURE__*/$atlaspack$interopDefault($eebb6ebf9f6069d2$exports))).version}:WorkerFS`, $7b991d7841c5927f$var$WorkerFS);
1960
+ (0, $dlC2Z$atlaspackcore.registerSerializableClass)(`${(0, (/*@__PURE__*/$atlaspack$interopDefault($eebb6ebf9f6069d2$exports))).version}:Stat`, $7b991d7841c5927f$var$Stat);
1961
+ (0, $dlC2Z$atlaspackcore.registerSerializableClass)(`${(0, (/*@__PURE__*/$atlaspack$interopDefault($eebb6ebf9f6069d2$exports))).version}:File`, $7b991d7841c5927f$export$b6afa8811b7e644e);
1962
+ (0, $dlC2Z$atlaspackcore.registerSerializableClass)(`${(0, (/*@__PURE__*/$atlaspack$interopDefault($eebb6ebf9f6069d2$exports))).version}:Directory`, $7b991d7841c5927f$var$Directory);
1963
+
1964
+
1965
+ var $994c93c6792b2070$exports = {};
1966
+
1967
+ $atlaspack$export($994c93c6792b2070$exports, "OverlayFS", () => $994c93c6792b2070$export$5963299e2424ca1c);
1968
+
1969
+
1970
+
1971
+
1972
+
1973
+
1974
+
1975
+ class $994c93c6792b2070$export$5963299e2424ca1c {
1976
+ deleted = new Set();
1977
+ constructor(workerFarmOrFS, readable){
1978
+ if (workerFarmOrFS instanceof (0, ($atlaspack$interopDefault($dlC2Z$atlaspackworkers)))) this.writable = new (0, $7b991d7841c5927f$export$3048eb7ec07c2c4e)(workerFarmOrFS);
1979
+ else this.writable = workerFarmOrFS;
1980
+ this.readable = readable;
1981
+ this._cwd = readable.cwd();
1982
+ }
1983
+ static deserialize(opts) {
1984
+ let fs = new $994c93c6792b2070$export$5963299e2424ca1c(opts.writable, opts.readable);
1985
+ if (opts.deleted != null) fs.deleted = opts.deleted;
1986
+ return fs;
1987
+ }
1988
+ serialize() {
1989
+ return {
1990
+ $$raw: false,
1991
+ writable: this.writable,
1992
+ readable: this.readable,
1993
+ deleted: this.deleted
1994
+ };
1995
+ }
1996
+ _deletedThrows(filePath) {
1997
+ filePath = this._normalizePath(filePath);
1998
+ if (this.deleted.has(filePath)) throw new $994c93c6792b2070$var$FSError('ENOENT', filePath, 'does not exist');
1999
+ return filePath;
2000
+ }
2001
+ _checkExists(filePath) {
2002
+ filePath = this._deletedThrows(filePath);
2003
+ if (!this.existsSync(filePath)) throw new $994c93c6792b2070$var$FSError('ENOENT', filePath, 'does not exist');
2004
+ return filePath;
2005
+ }
2006
+ _isSymlink(filePath) {
2007
+ filePath = this._normalizePath(filePath);
2008
+ // Check the parts of the path to see if any are symlinks.
2009
+ let { root: root, dir: dir, base: base } = (0, ($atlaspack$interopDefault($dlC2Z$path))).parse(filePath);
2010
+ let segments = dir.slice(root.length).split((0, ($atlaspack$interopDefault($dlC2Z$path))).sep).concat(base);
2011
+ while(segments.length){
2012
+ filePath = (0, ($atlaspack$interopDefault($dlC2Z$path))).join(root, ...segments);
2013
+ let name = segments.pop();
2014
+ if (this.deleted.has(filePath)) return false;
2015
+ else if (this.writable instanceof (0, $7b991d7841c5927f$export$3048eb7ec07c2c4e) && this.writable.symlinks.has(filePath)) return true;
2016
+ else {
2017
+ // HACK: Atlaspack fs does not provide `lstatSync`,
2018
+ // so we use `readdirSync` to check if the path is a symlink.
2019
+ let parent = (0, ($atlaspack$interopDefault($dlC2Z$path))).resolve(filePath, '..');
2020
+ if (parent === filePath) return false;
2021
+ try {
2022
+ for (let dirent of this.readdirSync(parent, {
2023
+ withFileTypes: true
2024
+ })){
2025
+ if (typeof dirent === 'string') break; // {withFileTypes: true} not supported
2026
+ else if (dirent.name === name) {
2027
+ if (dirent.isSymbolicLink()) return true;
2028
+ }
2029
+ }
2030
+ } catch (e) {
2031
+ if (e.code === 'ENOENT') return false;
2032
+ throw e;
2033
+ }
2034
+ }
2035
+ }
2036
+ return false;
2037
+ }
2038
+ async _copyPathForWrite(filePath) {
2039
+ filePath = await this._normalizePath(filePath);
2040
+ let dirPath = (0, ($atlaspack$interopDefault($dlC2Z$path))).dirname(filePath);
2041
+ if (this.existsSync(dirPath) && !this.writable.existsSync(dirPath)) await this.writable.mkdirp(dirPath);
2042
+ return filePath;
2043
+ }
2044
+ _normalizePath(filePath) {
2045
+ return (0, ($atlaspack$interopDefault($dlC2Z$path))).resolve(this.cwd(), filePath);
2046
+ }
2047
+ // eslint-disable-next-line require-await
2048
+ async readFile(filePath, encoding) {
2049
+ return this.readFileSync(filePath, encoding);
2050
+ }
2051
+ async writeFile(filePath, contents, options) {
2052
+ filePath = await this._copyPathForWrite(filePath);
2053
+ await this.writable.writeFile(filePath, contents, options);
2054
+ this.deleted.delete(filePath);
2055
+ }
2056
+ async copyFile(source, destination) {
2057
+ source = this._normalizePath(source);
2058
+ destination = await this._copyPathForWrite(destination);
2059
+ if (await this.writable.exists(source)) await this.writable.writeFile(destination, await this.writable.readFile(source));
2060
+ else await this.writable.writeFile(destination, await this.readable.readFile(source));
2061
+ this.deleted.delete(destination);
2062
+ }
2063
+ // eslint-disable-next-line require-await
2064
+ async stat(filePath) {
2065
+ return this.statSync(filePath);
2066
+ }
2067
+ async symlink(target, filePath) {
2068
+ target = this._normalizePath(target);
2069
+ filePath = this._normalizePath(filePath);
2070
+ await this.writable.symlink(target, filePath);
2071
+ this.deleted.delete(filePath);
2072
+ }
2073
+ async unlink(filePath) {
2074
+ filePath = this._normalizePath(filePath);
2075
+ let toDelete = [
2076
+ filePath
2077
+ ];
2078
+ if (this.writable instanceof (0, $7b991d7841c5927f$export$3048eb7ec07c2c4e) && this._isSymlink(filePath)) this.writable.symlinks.delete(filePath);
2079
+ else if (this.statSync(filePath).isDirectory()) {
2080
+ let stack = [
2081
+ filePath
2082
+ ];
2083
+ // Recursively add every descendant path to deleted.
2084
+ while(stack.length){
2085
+ let root = (0, (/*@__PURE__*/$atlaspack$interopDefault($1acbdc46f00ee4fb$exports)))(stack.pop());
2086
+ for (let ent of this.readdirSync(root, {
2087
+ withFileTypes: true
2088
+ }))if (typeof ent === 'string') {
2089
+ let childPath = (0, ($atlaspack$interopDefault($dlC2Z$path))).join(root, ent);
2090
+ toDelete.push(childPath);
2091
+ if (this.statSync(childPath).isDirectory()) stack.push(childPath);
2092
+ } else {
2093
+ let childPath = (0, ($atlaspack$interopDefault($dlC2Z$path))).join(root, ent.name);
2094
+ toDelete.push(childPath);
2095
+ if (ent.isDirectory()) stack.push(childPath);
2096
+ }
2097
+ }
2098
+ }
2099
+ try {
2100
+ await this.writable.unlink(filePath);
2101
+ } catch (e) {
2102
+ if (e.code === 'ENOENT' && !this.readable.existsSync(filePath)) throw e;
2103
+ }
2104
+ for (let pathToDelete of toDelete)this.deleted.add(pathToDelete);
2105
+ }
2106
+ async mkdirp(dir) {
2107
+ dir = this._normalizePath(dir);
2108
+ await this.writable.mkdirp(dir);
2109
+ if (this.deleted != null) {
2110
+ let root = (0, ($atlaspack$interopDefault($dlC2Z$path))).parse(dir).root;
2111
+ while(dir !== root){
2112
+ this.deleted.delete(dir);
2113
+ dir = (0, ($atlaspack$interopDefault($dlC2Z$path))).dirname(dir);
2114
+ }
2115
+ }
2116
+ }
2117
+ async rimraf(filePath) {
2118
+ try {
2119
+ await this.unlink(filePath);
2120
+ } catch (e) {
2121
+ // noop
2122
+ }
2123
+ }
2124
+ // eslint-disable-next-line require-await
2125
+ async ncp(source, destination) {
2126
+ // TODO: Implement this correctly.
2127
+ return this.writable.ncp(source, destination);
2128
+ }
2129
+ createReadStream(filePath, opts) {
2130
+ filePath = this._deletedThrows(filePath);
2131
+ if (this.writable.existsSync(filePath)) return this.writable.createReadStream(filePath, opts);
2132
+ return this.readable.createReadStream(filePath, opts);
2133
+ }
2134
+ createWriteStream(path, opts) {
2135
+ path = this._normalizePath(path);
2136
+ this.deleted.delete(path);
2137
+ return this.writable.createWriteStream(path, opts);
2138
+ }
2139
+ cwd() {
2140
+ return this._cwd;
2141
+ }
2142
+ chdir(path) {
2143
+ this._cwd = this._checkExists(path);
2144
+ }
2145
+ // eslint-disable-next-line require-await
2146
+ async realpath(filePath) {
2147
+ return this.realpathSync(filePath);
2148
+ }
2149
+ readFileSync(filePath, encoding) {
2150
+ filePath = this.realpathSync(filePath);
2151
+ try {
2152
+ // $FlowFixMe[incompatible-call]
2153
+ return this.writable.readFileSync(filePath, encoding);
2154
+ } catch (err) {
2155
+ // $FlowFixMe[incompatible-call]
2156
+ return this.readable.readFileSync(filePath, encoding);
2157
+ }
2158
+ }
2159
+ statSync(filePath) {
2160
+ filePath = this._normalizePath(filePath);
2161
+ try {
2162
+ return this.writable.statSync(filePath);
2163
+ } catch (e) {
2164
+ if (e.code === 'ENOENT' && this.existsSync(filePath)) return this.readable.statSync(filePath);
2165
+ throw e;
2166
+ }
2167
+ }
2168
+ realpathSync(filePath) {
2169
+ filePath = this._deletedThrows(filePath);
2170
+ filePath = this._deletedThrows(this.writable.realpathSync(filePath));
2171
+ if (!this.writable.existsSync(filePath)) return this.readable.realpathSync(filePath);
2172
+ return filePath;
2173
+ }
2174
+ // eslint-disable-next-line require-await
2175
+ async exists(filePath) {
2176
+ return this.existsSync(filePath);
2177
+ }
2178
+ existsSync(filePath) {
2179
+ filePath = this._normalizePath(filePath);
2180
+ if (this.deleted.has(filePath)) return false;
2181
+ try {
2182
+ filePath = this.realpathSync(filePath);
2183
+ } catch (err) {
2184
+ if (err.code !== 'ENOENT') throw err;
2185
+ }
2186
+ if (this.deleted.has(filePath)) return false;
2187
+ return this.writable.existsSync(filePath) || this.readable.existsSync(filePath);
2188
+ }
2189
+ // eslint-disable-next-line require-await
2190
+ async readdir(path, opts) {
2191
+ return this.readdirSync(path, opts);
2192
+ }
2193
+ readdirSync(dir, opts) {
2194
+ dir = this.realpathSync(dir);
2195
+ // Read from both filesystems and merge the results
2196
+ let entries = new Map();
2197
+ try {
2198
+ for (let entry of this.writable.readdirSync(dir, opts)){
2199
+ let filePath = (0, ($atlaspack$interopDefault($dlC2Z$path))).join(dir, entry.name ?? entry);
2200
+ if (this.deleted.has(filePath)) continue;
2201
+ entries.set(filePath, entry);
2202
+ }
2203
+ } catch {
2204
+ // noop
2205
+ }
2206
+ try {
2207
+ for (let entry of this.readable.readdirSync(dir, opts)){
2208
+ let filePath = (0, ($atlaspack$interopDefault($dlC2Z$path))).join(dir, entry.name ?? entry);
2209
+ if (this.deleted.has(filePath)) continue;
2210
+ if (entries.has(filePath)) continue;
2211
+ entries.set(filePath, entry);
2212
+ }
2213
+ } catch {
2214
+ // noop
2215
+ }
2216
+ return Array.from(entries.values());
2217
+ }
2218
+ async watch(dir, fn, opts) {
2219
+ let writableSubscription = await this.writable.watch(dir, fn, opts);
2220
+ let readableSubscription = await this.readable.watch(dir, fn, opts);
2221
+ return {
2222
+ unsubscribe: async ()=>{
2223
+ await writableSubscription.unsubscribe();
2224
+ await readableSubscription.unsubscribe();
2225
+ }
2226
+ };
2227
+ }
2228
+ async getEventsSince(dir, snapshot, opts) {
2229
+ let writableEvents = await this.writable.getEventsSince(dir, snapshot, opts);
2230
+ let readableEvents = await this.readable.getEventsSince(dir, snapshot, opts);
2231
+ return [
2232
+ ...writableEvents,
2233
+ ...readableEvents
2234
+ ];
2235
+ }
2236
+ async writeSnapshot(dir, snapshot, opts) {
2237
+ await this.writable.writeSnapshot(dir, snapshot, opts);
2238
+ }
2239
+ findAncestorFile(fileNames, fromDir, root) {
2240
+ return (0, $c5a03bd108f66311$export$d51a93c758976388)(this, fileNames, fromDir, root);
2241
+ }
2242
+ findNodeModule(moduleName, fromDir) {
2243
+ return (0, $c5a03bd108f66311$export$4c6d088a7d7f9947)(this, moduleName, fromDir);
2244
+ }
2245
+ findFirstFile(filePaths) {
2246
+ return (0, $c5a03bd108f66311$export$64df6e3182fd5b2d)(this, filePaths);
2247
+ }
2248
+ }
2249
+ class $994c93c6792b2070$var$FSError extends Error {
2250
+ constructor(code, path, message){
2251
+ super(`${code}: ${path} ${message}`);
2252
+ this.name = 'FSError';
2253
+ this.code = code;
2254
+ this.path = path;
2255
+ Error.captureStackTrace?.(this, this.constructor);
2256
+ }
2257
+ }
2258
+ (0, $dlC2Z$atlaspackcore.registerSerializableClass)(`${(0, (/*@__PURE__*/$atlaspack$interopDefault($eebb6ebf9f6069d2$exports))).version}:OverlayFS`, $994c93c6792b2070$export$5963299e2424ca1c);
2259
+
2260
+
2261
+ const $4256a6714e3958a6$var$pipeline = (0, $dlC2Z$util.promisify)((0, ($atlaspack$interopDefault($dlC2Z$stream))).pipeline);
2262
+ async function $4256a6714e3958a6$export$d3a8044e3fef7335(sourceFS, source, destinationFS, destination) {
2263
+ await destinationFS.mkdirp(destination);
2264
+ let files = await sourceFS.readdir(source);
2265
+ for (let file of files){
2266
+ let sourcePath = (0, ($atlaspack$interopDefault($dlC2Z$path))).join(source, file);
2267
+ let destPath = (0, ($atlaspack$interopDefault($dlC2Z$path))).join(destination, file);
2268
+ let stats = await sourceFS.stat(sourcePath);
2269
+ if (stats.isFile()) await $4256a6714e3958a6$var$pipeline(sourceFS.createReadStream(sourcePath), destinationFS.createWriteStream(destPath));
2270
+ else if (stats.isDirectory()) await $4256a6714e3958a6$export$d3a8044e3fef7335(sourceFS, sourcePath, destinationFS, destPath);
2271
+ }
2272
+ }
2273
+ $atlaspack$exportWildcard(module.exports, $fd5eb542960b5f45$exports);
2274
+ $atlaspack$exportWildcard(module.exports, $7b991d7841c5927f$exports);
2275
+ $atlaspack$exportWildcard(module.exports, $994c93c6792b2070$exports);
2276
+
2277
+
2278
+ //# sourceMappingURL=index.js.map