@atlaspack/fs 2.14.0 → 2.14.1-canary.6

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