@atlaspack/fs 2.14.5-dev.95 → 2.14.5-dev.97

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 CHANGED
@@ -1,2418 +1,99 @@
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");
1
+ "use strict";
16
2
 
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);
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _exportNames = {
7
+ ncp: true
481
8
  };
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
- });
9
+ exports.ncp = ncp;
10
+ function _path() {
11
+ const data = _interopRequireDefault(require("path"));
12
+ _path = function () {
13
+ return data;
14
+ };
15
+ return data;
16
+ }
17
+ function _stream() {
18
+ const data = _interopRequireDefault(require("stream"));
19
+ _stream = function () {
20
+ return data;
21
+ };
22
+ return data;
23
+ }
24
+ function _util() {
25
+ const data = require("util");
26
+ _util = function () {
27
+ return data;
28
+ };
29
+ return data;
30
+ }
31
+ var _NodeFS = require("./NodeFS");
32
+ Object.keys(_NodeFS).forEach(function (key) {
33
+ if (key === "default" || key === "__esModule") return;
34
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
35
+ if (key in exports && exports[key] === _NodeFS[key]) return;
36
+ Object.defineProperty(exports, key, {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _NodeFS[key];
894
40
  }
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.5-dev.95+d8e35a83e\",\"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-dev.163+d8e35a83e\",\"@atlaspack/feature-flags\":\"2.14.1-dev.163+d8e35a83e\",\"@atlaspack/logger\":\"2.14.5-dev.95+d8e35a83e\",\"@atlaspack/rust\":\"3.2.1-dev.95+d8e35a83e\",\"@atlaspack/types-internal\":\"2.14.1-dev.163+d8e35a83e\",\"@atlaspack/utils\":\"2.14.5-dev.95+d8e35a83e\",\"@atlaspack/workers\":\"2.14.5-dev.95+d8e35a83e\",\"@parcel/watcher\":\"^2.0.7\"},\"devDependencies\":{\"@atlaspack/watcher-watchman-js\":\"2.14.5-dev.95+d8e35a83e\",\"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\":\"d8e35a83e480e0811b63a319e88ffe9a2cd509e6\"}");
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
- try {
1140
- (0, (/*@__PURE__*/$parcel$interopDefault($243d4fdf6bcaa749$exports))).unlinkSync(tmpFilePath);
1141
- } catch (_err) {
1142
- // ignore
1143
- }
1144
- });
1145
- return writeStream;
1146
- }
1147
- async writeFile(filePath, contents, options) {
1148
- let tmpFilePath = $94eb45ad74bb764d$var$getTempFilePath(filePath);
1149
- await (0, (/*@__PURE__*/$parcel$interopDefault($243d4fdf6bcaa749$exports))).promises.writeFile(tmpFilePath, contents, options);
1150
- await (0, (/*@__PURE__*/$parcel$interopDefault($243d4fdf6bcaa749$exports))).promises.rename(tmpFilePath, filePath);
1151
- }
1152
- readFileSync(filePath, encoding) {
1153
- if (encoding != null) return (0, (/*@__PURE__*/$parcel$interopDefault($243d4fdf6bcaa749$exports))).readFileSync(filePath, encoding);
1154
- return (0, (/*@__PURE__*/$parcel$interopDefault($243d4fdf6bcaa749$exports))).readFileSync(filePath);
1155
- }
1156
- async realpath(originalPath) {
1157
- try {
1158
- return await $94eb45ad74bb764d$var$realpath(originalPath, 'utf8');
1159
- } catch (e) {
1160
- // do nothing
1161
- }
1162
- return originalPath;
1163
- }
1164
- exists(filePath) {
1165
- return new Promise((resolve)=>{
1166
- (0, (/*@__PURE__*/$parcel$interopDefault($243d4fdf6bcaa749$exports))).exists(filePath, resolve);
1167
- });
1168
- }
1169
- watch(dir, fn, opts) {
1170
- return this.watcher().subscribe(dir, fn, opts);
1171
- }
1172
- getEventsSince(dir, snapshot, opts) {
1173
- return this.watcher().getEventsSince(dir, snapshot, opts);
1174
- }
1175
- async writeSnapshot(dir, snapshot, opts) {
1176
- await this.mkdirp((0, ($parcel$interopDefault($2V2hx$path))).dirname(snapshot));
1177
- await this.watcher().writeSnapshot(dir, snapshot, opts);
1178
- }
1179
- static deserialize() {
1180
- return new $94eb45ad74bb764d$export$c4e0ef2ab73c21e7();
1181
- }
1182
- serialize() {
1183
- return null;
1184
- }
1185
- async mkdirp(filePath) {
1186
- await (0, ($parcel$interopDefault($2V2hx$fs))).promises.mkdir(filePath, {
1187
- recursive: true
1188
- });
1189
- }
1190
- async rimraf(filePath) {
1191
- if ((0, (/*@__PURE__*/$parcel$interopDefault($243d4fdf6bcaa749$exports))).promises.rm) {
1192
- await (0, (/*@__PURE__*/$parcel$interopDefault($243d4fdf6bcaa749$exports))).promises.rm(filePath, {
1193
- recursive: true,
1194
- force: true
1195
- });
1196
- return;
1197
- }
1198
- // fs.promises.rm is not supported in node 12...
1199
- let stat;
1200
- try {
1201
- stat = await this.stat(filePath);
1202
- } catch (err) {
1203
- return;
1204
- }
1205
- if (stat.isDirectory()) // $FlowFixMe
1206
- await (0, ($parcel$interopDefault($2V2hx$fs))).promises.rmdir(filePath, {
1207
- recursive: true
1208
- });
1209
- else await (0, ($parcel$interopDefault($2V2hx$fs))).promises.unlink(filePath);
1210
- }
1211
- }
1212
- (0, $2V2hx$atlaspackbuildcache.registerSerializableClass)(`${(0, (/*@__PURE__*/$parcel$interopDefault($d7f6ae9f917393f7$exports))).version}:NodeFS`, $94eb45ad74bb764d$export$c4e0ef2ab73c21e7);
1213
- let $94eb45ad74bb764d$var$writeStreamCalls = 0;
1214
- let $94eb45ad74bb764d$var$threadId;
1215
-
1216
- try {
1217
- ({ threadId: $94eb45ad74bb764d$var$threadId } = $94eb45ad74bb764d$import$9c2ae04019a9b9e3);
1218
- } catch {
1219
- //
1220
- }
1221
- let $94eb45ad74bb764d$var$useOsTmpDir;
1222
- function $94eb45ad74bb764d$var$shouldUseOsTmpDir(filePath) {
1223
- if ($94eb45ad74bb764d$var$useOsTmpDir != null) return $94eb45ad74bb764d$var$useOsTmpDir;
1224
- try {
1225
- const tmpDir = (0, $2V2hx$os.tmpdir)();
1226
- (0, ($parcel$interopDefault($2V2hx$fs))).accessSync(tmpDir, (0, ($parcel$interopDefault($2V2hx$fs))).constants.R_OK | (0, ($parcel$interopDefault($2V2hx$fs))).constants.W_OK);
1227
- const tmpDirStats = (0, ($parcel$interopDefault($2V2hx$fs))).statSync(tmpDir);
1228
- const filePathStats = (0, ($parcel$interopDefault($2V2hx$fs))).statSync(filePath);
1229
- // Check the tmpdir is on the same partition as the target directory.
1230
- // This is required to ensure renaming is an atomic operation.
1231
- $94eb45ad74bb764d$var$useOsTmpDir = tmpDirStats.dev === filePathStats.dev;
1232
- } catch (e) {
1233
- // We don't have read/write access to the OS tmp directory
1234
- $94eb45ad74bb764d$var$useOsTmpDir = false;
1235
- }
1236
- return $94eb45ad74bb764d$var$useOsTmpDir;
1237
- }
1238
- // Generate a temporary file path used for atomic writing of files.
1239
- function $94eb45ad74bb764d$var$getTempFilePath(filePath) {
1240
- $94eb45ad74bb764d$var$writeStreamCalls = $94eb45ad74bb764d$var$writeStreamCalls % Number.MAX_SAFE_INTEGER;
1241
- let tmpFilePath = filePath;
1242
- // If possible, write the tmp file to the OS tmp directory
1243
- // This reduces the amount of FS events the watcher needs to process during the build
1244
- if ($94eb45ad74bb764d$var$shouldUseOsTmpDir(filePath)) tmpFilePath = (0, ($parcel$interopDefault($2V2hx$path))).join((0, $2V2hx$os.tmpdir)(), (0, ($parcel$interopDefault($2V2hx$path))).basename(filePath));
1245
- return tmpFilePath + '.' + process.pid + ($94eb45ad74bb764d$var$threadId != null ? '.' + $94eb45ad74bb764d$var$threadId : '') + '.' + ($94eb45ad74bb764d$var$writeStreamCalls++).toString(36);
1246
- }
1247
-
1248
-
1249
- var $0846bf1c7ee89e90$exports = {};
1250
-
1251
- $parcel$export($0846bf1c7ee89e90$exports, "MemoryFS", () => $0846bf1c7ee89e90$export$3048eb7ec07c2c4e);
1252
- $parcel$export($0846bf1c7ee89e90$exports, "FSError", () => $0846bf1c7ee89e90$export$d414276624ebf134);
1253
- $parcel$export($0846bf1c7ee89e90$exports, "makeShared", () => $0846bf1c7ee89e90$export$df9eb3e75aa27a22);
1254
- $parcel$export($0846bf1c7ee89e90$exports, "File", () => $0846bf1c7ee89e90$export$b6afa8811b7e644e);
1255
-
1256
-
1257
-
1258
-
1259
-
1260
-
1261
- var $20532aab86e1ce9f$exports = {};
1262
- 'use strict';
1263
- function $20532aab86e1ce9f$var$nullthrows(x, message) {
1264
- if (x != null) return x;
1265
- var error = new Error(message !== undefined ? message : 'Got unexpected ' + x);
1266
- error.framesToPop = 1; // Skip nullthrows's own stack frame.
1267
- throw error;
1268
- }
1269
- $20532aab86e1ce9f$exports = $20532aab86e1ce9f$var$nullthrows;
1270
- $20532aab86e1ce9f$exports.default = $20532aab86e1ce9f$var$nullthrows;
1271
- Object.defineProperty($20532aab86e1ce9f$exports, '__esModule', {
1272
- value: true
41
+ });
1273
42
  });
1274
-
1275
-
1276
-
1277
-
1278
- const $0846bf1c7ee89e90$var$instances = new Map();
1279
- let $0846bf1c7ee89e90$var$id = 0;
1280
- class $0846bf1c7ee89e90$export$3048eb7ec07c2c4e {
1281
- _numWorkerInstances = 0;
1282
- _workerRegisterResolves = [];
1283
- _emitter = new (0, ($parcel$interopDefault($2V2hx$events)))();
1284
- constructor(workerFarm){
1285
- this.farm = workerFarm;
1286
- this._cwd = (0, ($parcel$interopDefault($2V2hx$path))).resolve((0, ($parcel$interopDefault($2V2hx$path))).sep);
1287
- this.dirs = new Map([
1288
- [
1289
- this._cwd,
1290
- new $0846bf1c7ee89e90$var$Directory()
1291
- ]
1292
- ]);
1293
- this.files = new Map();
1294
- this.symlinks = new Map();
1295
- this.watchers = new Map();
1296
- this.events = [];
1297
- this.id = $0846bf1c7ee89e90$var$id++;
1298
- this._workerHandles = [];
1299
- this._eventQueue = [];
1300
- $0846bf1c7ee89e90$var$instances.set(this.id, this);
1301
- this._emitter.on('allWorkersRegistered', ()=>{
1302
- for (let resolve of this._workerRegisterResolves)resolve();
1303
- this._workerRegisterResolves = [];
1304
- });
1305
- }
1306
- static deserialize(opts) {
1307
- let existing = $0846bf1c7ee89e90$var$instances.get(opts.id);
1308
- if (existing != null) {
1309
- // Correct the count of worker instances since serialization assumes a new instance is created
1310
- (0, ($parcel$interopDefault($2V2hx$atlaspackworkers))).getWorkerApi().runHandle(opts.handle, [
1311
- 'decrementWorkerInstance',
1312
- []
1313
- ]);
1314
- return existing;
1315
- }
1316
- let fs = new $0846bf1c7ee89e90$var$WorkerFS(opts.id, (0, (/*@__PURE__*/$parcel$interopDefault($20532aab86e1ce9f$exports)))(opts.handle));
1317
- fs.dirs = opts.dirs;
1318
- fs.files = opts.files;
1319
- fs.symlinks = opts.symlinks;
1320
- return fs;
1321
- }
1322
- serialize() {
1323
- if (!this.handle) this.handle = this.farm.createReverseHandle((fn, args)=>{
1324
- // $FlowFixMe
1325
- return this[fn](...args);
1326
- });
1327
- // If a worker instance already exists, it will decrement this number
1328
- this._numWorkerInstances++;
1329
- return {
1330
- $$raw: false,
1331
- id: this.id,
1332
- handle: this.handle,
1333
- dirs: this.dirs,
1334
- files: this.files,
1335
- symlinks: this.symlinks
1336
- };
1337
- }
1338
- decrementWorkerInstance() {
1339
- this._numWorkerInstances--;
1340
- if (this._numWorkerInstances === this._workerHandles.length) this._emitter.emit('allWorkersRegistered');
1341
- }
1342
- cwd() {
1343
- return this._cwd;
1344
- }
1345
- chdir(dir) {
1346
- this._cwd = dir;
1347
- }
1348
- _normalizePath(filePath, realpath = true) {
1349
- filePath = (0, ($parcel$interopDefault($2V2hx$path))).normalize(filePath);
1350
- if (!filePath.startsWith(this.cwd())) filePath = (0, ($parcel$interopDefault($2V2hx$path))).resolve(this.cwd(), filePath);
1351
- // get realpath by following symlinks
1352
- if (realpath) {
1353
- let { root: root, dir: dir, base: base } = (0, ($parcel$interopDefault($2V2hx$path))).parse(filePath);
1354
- let parts = dir.slice(root.length).split((0, ($parcel$interopDefault($2V2hx$path))).sep).concat(base);
1355
- let res = root;
1356
- for (let part of parts){
1357
- res = (0, ($parcel$interopDefault($2V2hx$path))).join(res, part);
1358
- let symlink = this.symlinks.get(res);
1359
- if (symlink) res = symlink;
1360
- }
1361
- return res;
1362
- }
1363
- return filePath;
1364
- }
1365
- async writeFile(filePath, contents, options) {
1366
- filePath = this._normalizePath(filePath);
1367
- if (this.dirs.has(filePath)) throw new $0846bf1c7ee89e90$export$d414276624ebf134('EISDIR', filePath, 'is a directory');
1368
- let dir = (0, ($parcel$interopDefault($2V2hx$path))).dirname(filePath);
1369
- if (!this.dirs.has(dir)) throw new $0846bf1c7ee89e90$export$d414276624ebf134('ENOENT', dir, 'does not exist');
1370
- let buffer = $0846bf1c7ee89e90$export$df9eb3e75aa27a22(contents);
1371
- let file = this.files.get(filePath);
1372
- let mode = options && options.mode || 438;
1373
- if (file) {
1374
- file.write(buffer, mode);
1375
- this.files.set(filePath, file);
1376
- } else this.files.set(filePath, new $0846bf1c7ee89e90$export$b6afa8811b7e644e(buffer, mode));
1377
- await this._sendWorkerEvent({
1378
- type: 'writeFile',
1379
- path: filePath,
1380
- entry: this.files.get(filePath)
1381
- });
1382
- this._triggerEvent({
1383
- type: file ? 'update' : 'create',
1384
- path: filePath
1385
- });
1386
- }
1387
- // eslint-disable-next-line require-await
1388
- async readFile(filePath, encoding) {
1389
- return this.readFileSync(filePath, encoding);
1390
- }
1391
- readFileSync(filePath, encoding) {
1392
- filePath = this._normalizePath(filePath);
1393
- let file = this.files.get(filePath);
1394
- if (file == null) throw new $0846bf1c7ee89e90$export$d414276624ebf134('ENOENT', filePath, 'does not exist');
1395
- let buffer = file.read();
1396
- if (encoding) return buffer.toString(encoding);
1397
- return buffer;
43
+ var _MemoryFS = require("./MemoryFS");
44
+ Object.keys(_MemoryFS).forEach(function (key) {
45
+ if (key === "default" || key === "__esModule") return;
46
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
47
+ if (key in exports && exports[key] === _MemoryFS[key]) return;
48
+ Object.defineProperty(exports, key, {
49
+ enumerable: true,
50
+ get: function () {
51
+ return _MemoryFS[key];
1398
52
  }
1399
- async copyFile(source, destination) {
1400
- let contents = await this.readFile(source);
1401
- await this.writeFile(destination, contents);
1402
- }
1403
- statSync(filePath) {
1404
- filePath = this._normalizePath(filePath);
1405
- let dir = this.dirs.get(filePath);
1406
- if (dir) return dir.stat();
1407
- let file = this.files.get(filePath);
1408
- if (file == null) throw new $0846bf1c7ee89e90$export$d414276624ebf134('ENOENT', filePath, 'does not exist');
1409
- return file.stat();
1410
- }
1411
- // eslint-disable-next-line require-await
1412
- async stat(filePath) {
1413
- return this.statSync(filePath);
1414
- }
1415
- readdirSync(dir, opts) {
1416
- dir = this._normalizePath(dir);
1417
- if (!this.dirs.has(dir)) throw new $0846bf1c7ee89e90$export$d414276624ebf134('ENOENT', dir, 'does not exist');
1418
- if (!dir.endsWith((0, ($parcel$interopDefault($2V2hx$path))).sep)) dir += (0, ($parcel$interopDefault($2V2hx$path))).sep;
1419
- let res = [];
1420
- for (let [filePath, entry] of this.dirs){
1421
- if (filePath === dir) continue;
1422
- if (filePath.startsWith(dir) && filePath.indexOf((0, ($parcel$interopDefault($2V2hx$path))).sep, dir.length) === -1) {
1423
- let name = filePath.slice(dir.length);
1424
- if (opts?.withFileTypes) res.push(new $0846bf1c7ee89e90$var$Dirent(name, entry));
1425
- else res.push(name);
1426
- }
1427
- }
1428
- for (let [filePath, entry] of this.files)if (filePath.startsWith(dir) && filePath.indexOf((0, ($parcel$interopDefault($2V2hx$path))).sep, dir.length) === -1) {
1429
- let name = filePath.slice(dir.length);
1430
- if (opts?.withFileTypes) res.push(new $0846bf1c7ee89e90$var$Dirent(name, entry));
1431
- else res.push(name);
1432
- }
1433
- for (let [from] of this.symlinks)if (from.startsWith(dir) && from.indexOf((0, ($parcel$interopDefault($2V2hx$path))).sep, dir.length) === -1) {
1434
- let name = from.slice(dir.length);
1435
- if (opts?.withFileTypes) res.push(new $0846bf1c7ee89e90$var$Dirent(name, {
1436
- mode: $0846bf1c7ee89e90$var$S_IFLNK
1437
- }));
1438
- else res.push(name);
1439
- }
1440
- return res;
1441
- }
1442
- // eslint-disable-next-line require-await
1443
- async readdir(dir, opts) {
1444
- return this.readdirSync(dir, opts);
1445
- }
1446
- async unlink(filePath) {
1447
- filePath = this._normalizePath(filePath);
1448
- if (!this.files.has(filePath) && !this.dirs.has(filePath)) throw new $0846bf1c7ee89e90$export$d414276624ebf134('ENOENT', filePath, 'does not exist');
1449
- this.files.delete(filePath);
1450
- this.dirs.delete(filePath);
1451
- this.watchers.delete(filePath);
1452
- await this._sendWorkerEvent({
1453
- type: 'unlink',
1454
- path: filePath
1455
- });
1456
- this._triggerEvent({
1457
- type: 'delete',
1458
- path: filePath
1459
- });
1460
- return Promise.resolve();
1461
- }
1462
- async mkdirp(dir) {
1463
- dir = this._normalizePath(dir);
1464
- if (this.dirs.has(dir)) return Promise.resolve();
1465
- if (this.files.has(dir)) throw new $0846bf1c7ee89e90$export$d414276624ebf134('ENOENT', dir, 'is not a directory');
1466
- let root = (0, ($parcel$interopDefault($2V2hx$path))).parse(dir).root;
1467
- while(dir !== root){
1468
- if (this.dirs.has(dir)) break;
1469
- this.dirs.set(dir, new $0846bf1c7ee89e90$var$Directory());
1470
- await this._sendWorkerEvent({
1471
- type: 'mkdir',
1472
- path: dir
1473
- });
1474
- this._triggerEvent({
1475
- type: 'create',
1476
- path: dir
1477
- });
1478
- dir = (0, ($parcel$interopDefault($2V2hx$path))).dirname(dir);
1479
- }
1480
- return Promise.resolve();
1481
- }
1482
- async rimraf(filePath) {
1483
- filePath = this._normalizePath(filePath);
1484
- if (this.dirs.has(filePath)) {
1485
- let dir = filePath + (0, ($parcel$interopDefault($2V2hx$path))).sep;
1486
- for (let filePath of this.files.keys())if (filePath.startsWith(dir)) {
1487
- this.files.delete(filePath);
1488
- await this._sendWorkerEvent({
1489
- type: 'unlink',
1490
- path: filePath
1491
- });
1492
- this._triggerEvent({
1493
- type: 'delete',
1494
- path: filePath
1495
- });
1496
- }
1497
- for (let dirPath of this.dirs.keys())if (dirPath.startsWith(dir)) {
1498
- this.dirs.delete(dirPath);
1499
- this.watchers.delete(dirPath);
1500
- await this._sendWorkerEvent({
1501
- type: 'unlink',
1502
- path: filePath
1503
- });
1504
- this._triggerEvent({
1505
- type: 'delete',
1506
- path: dirPath
1507
- });
1508
- }
1509
- for (let filePath of this.symlinks.keys())if (filePath.startsWith(dir)) {
1510
- this.symlinks.delete(filePath);
1511
- await this._sendWorkerEvent({
1512
- type: 'unlink',
1513
- path: filePath
1514
- });
1515
- }
1516
- this.dirs.delete(filePath);
1517
- await this._sendWorkerEvent({
1518
- type: 'unlink',
1519
- path: filePath
1520
- });
1521
- this._triggerEvent({
1522
- type: 'delete',
1523
- path: filePath
1524
- });
1525
- } else if (this.files.has(filePath)) {
1526
- this.files.delete(filePath);
1527
- await this._sendWorkerEvent({
1528
- type: 'unlink',
1529
- path: filePath
1530
- });
1531
- this._triggerEvent({
1532
- type: 'delete',
1533
- path: filePath
1534
- });
1535
- }
1536
- return Promise.resolve();
1537
- }
1538
- async ncp(source, destination) {
1539
- source = this._normalizePath(source);
1540
- if (this.dirs.has(source)) {
1541
- if (!this.dirs.has(destination)) {
1542
- this.dirs.set(destination, new $0846bf1c7ee89e90$var$Directory());
1543
- await this._sendWorkerEvent({
1544
- type: 'mkdir',
1545
- path: destination
1546
- });
1547
- this._triggerEvent({
1548
- type: 'create',
1549
- path: destination
1550
- });
1551
- }
1552
- let dir = source + (0, ($parcel$interopDefault($2V2hx$path))).sep;
1553
- for (let dirPath of this.dirs.keys())if (dirPath.startsWith(dir)) {
1554
- let destName = (0, ($parcel$interopDefault($2V2hx$path))).join(destination, dirPath.slice(dir.length));
1555
- if (!this.dirs.has(destName)) {
1556
- this.dirs.set(destName, new $0846bf1c7ee89e90$var$Directory());
1557
- await this._sendWorkerEvent({
1558
- type: 'mkdir',
1559
- path: destination
1560
- });
1561
- this._triggerEvent({
1562
- type: 'create',
1563
- path: destName
1564
- });
1565
- }
1566
- }
1567
- for (let [filePath, file] of this.files)if (filePath.startsWith(dir)) {
1568
- let destName = (0, ($parcel$interopDefault($2V2hx$path))).join(destination, filePath.slice(dir.length));
1569
- let exists = this.files.has(destName);
1570
- this.files.set(destName, file);
1571
- await this._sendWorkerEvent({
1572
- type: 'writeFile',
1573
- path: destName,
1574
- entry: file
1575
- });
1576
- this._triggerEvent({
1577
- type: exists ? 'update' : 'create',
1578
- path: destName
1579
- });
1580
- }
1581
- } else await this.copyFile(source, destination);
1582
- }
1583
- createReadStream(filePath) {
1584
- return new $0846bf1c7ee89e90$var$ReadStream(this, filePath);
1585
- }
1586
- createWriteStream(filePath, options) {
1587
- this.mkdirp((0, ($parcel$interopDefault($2V2hx$path))).dirname(filePath));
1588
- return new $0846bf1c7ee89e90$var$WriteStream(this, filePath, options);
1589
- }
1590
- realpathSync(filePath) {
1591
- return this._normalizePath(filePath);
1592
- }
1593
- // eslint-disable-next-line require-await
1594
- async realpath(filePath) {
1595
- return this.realpathSync(filePath);
1596
- }
1597
- async symlink(target, path) {
1598
- target = this._normalizePath(target);
1599
- path = this._normalizePath(path);
1600
- this.symlinks.set(path, target);
1601
- await this._sendWorkerEvent({
1602
- type: 'symlink',
1603
- path: path,
1604
- target: target
1605
- });
1606
- }
1607
- existsSync(filePath) {
1608
- filePath = this._normalizePath(filePath);
1609
- return this.files.has(filePath) || this.dirs.has(filePath);
1610
- }
1611
- // eslint-disable-next-line require-await
1612
- async exists(filePath) {
1613
- return this.existsSync(filePath);
1614
- }
1615
- _triggerEvent(event) {
1616
- this.events.push(event);
1617
- if (this.watchers.size === 0) return;
1618
- // Batch events
1619
- this._eventQueue.push(event);
1620
- clearTimeout(this._watcherTimer);
1621
- this._watcherTimer = setTimeout(()=>{
1622
- let events = this._eventQueue;
1623
- this._eventQueue = [];
1624
- for (let [dir, watchers] of this.watchers){
1625
- if (!dir.endsWith((0, ($parcel$interopDefault($2V2hx$path))).sep)) dir += (0, ($parcel$interopDefault($2V2hx$path))).sep;
1626
- const relevantEvents = events.filter((event)=>event.path.startsWith(dir));
1627
- if (relevantEvents.length > 0) for (let watcher of watchers)watcher.trigger(relevantEvents);
1628
- }
1629
- }, 50);
1630
- }
1631
- _registerWorker(handle) {
1632
- this._workerHandles.push(handle);
1633
- if (this._numWorkerInstances === this._workerHandles.length) this._emitter.emit('allWorkersRegistered');
1634
- }
1635
- async _sendWorkerEvent(event) {
1636
- // Wait for worker instances to register their handles
1637
- while(this._workerHandles.length < this._numWorkerInstances)await new Promise((resolve)=>this._workerRegisterResolves.push(resolve));
1638
- await Promise.all(this._workerHandles.map((workerHandle)=>this.farm.workerApi.runHandle(workerHandle, [
1639
- event
1640
- ])));
1641
- }
1642
- watch(dir, fn, opts) {
1643
- dir = this._normalizePath(dir);
1644
- let watcher = new $0846bf1c7ee89e90$var$Watcher(fn, opts);
1645
- let watchers = this.watchers.get(dir);
1646
- if (!watchers) {
1647
- watchers = new Set();
1648
- this.watchers.set(dir, watchers);
1649
- }
1650
- watchers.add(watcher);
1651
- return Promise.resolve({
1652
- unsubscribe: ()=>{
1653
- watchers = (0, (/*@__PURE__*/$parcel$interopDefault($20532aab86e1ce9f$exports)))(watchers);
1654
- watchers.delete(watcher);
1655
- if (watchers.size === 0) this.watchers.delete(dir);
1656
- return Promise.resolve();
1657
- }
1658
- });
1659
- }
1660
- async getEventsSince(dir, snapshot, opts) {
1661
- let contents = await this.readFile(snapshot, 'utf8');
1662
- let len = Number(contents);
1663
- let events = this.events.slice(len);
1664
- let ignore = opts.ignore;
1665
- if (ignore) events = events.filter((event)=>!ignore.some((i)=>event.path.startsWith(i + (0, ($parcel$interopDefault($2V2hx$path))).sep)));
1666
- return events;
1667
- }
1668
- async writeSnapshot(dir, snapshot) {
1669
- await this.mkdirp((0, ($parcel$interopDefault($2V2hx$path))).dirname(snapshot));
1670
- await this.writeFile(snapshot, '' + this.events.length);
1671
- }
1672
- findAncestorFile(fileNames, fromDir, root) {
1673
- return (0, $782db929ace769f6$export$d51a93c758976388)(this, fileNames, fromDir, root);
1674
- }
1675
- findNodeModule(moduleName, fromDir) {
1676
- return (0, $782db929ace769f6$export$4c6d088a7d7f9947)(this, moduleName, fromDir);
1677
- }
1678
- findFirstFile(filePaths) {
1679
- return (0, $782db929ace769f6$export$64df6e3182fd5b2d)(this, filePaths);
1680
- }
1681
- }
1682
- class $0846bf1c7ee89e90$var$Watcher {
1683
- constructor(fn, options){
1684
- this.fn = fn;
1685
- this.options = options;
1686
- }
1687
- trigger(events) {
1688
- let ignore = this.options.ignore;
1689
- if (ignore) events = events.filter((event)=>!ignore.some((i)=>event.path.startsWith(i + (0, ($parcel$interopDefault($2V2hx$path))).sep)));
1690
- if (events.length > 0) this.fn(null, events);
1691
- }
1692
- }
1693
- class $0846bf1c7ee89e90$export$d414276624ebf134 extends Error {
1694
- constructor(code, path, message){
1695
- super(`${code}: ${path} ${message}`);
1696
- this.name = 'FSError';
1697
- this.code = code;
1698
- this.path = path;
1699
- Error.captureStackTrace?.(this, this.constructor);
1700
- }
1701
- }
1702
- class $0846bf1c7ee89e90$var$ReadStream extends (0, $2V2hx$stream.Readable) {
1703
- constructor(fs, filePath){
1704
- super();
1705
- this.fs = fs;
1706
- this.filePath = filePath;
1707
- this.reading = false;
1708
- this.bytesRead = 0;
1709
- }
1710
- _read() {
1711
- if (this.reading) return;
1712
- this.reading = true;
1713
- this.fs.readFile(this.filePath).then((res)=>{
1714
- this.bytesRead += res.byteLength;
1715
- this.push(res);
1716
- this.push(null);
1717
- }, (err)=>{
1718
- this.emit('error', err);
1719
- });
1720
- }
1721
- }
1722
- class $0846bf1c7ee89e90$var$WriteStream extends (0, $2V2hx$stream.Writable) {
1723
- constructor(fs, filePath, options){
1724
- super({
1725
- emitClose: true,
1726
- autoDestroy: true
1727
- });
1728
- this.fs = fs;
1729
- this.filePath = filePath;
1730
- this.options = options;
1731
- this.buffer = Buffer.alloc(0);
1732
- }
1733
- _write(chunk, encoding, callback) {
1734
- let c = typeof chunk === 'string' ? Buffer.from(chunk, encoding) : chunk;
1735
- this.buffer = Buffer.concat([
1736
- this.buffer,
1737
- c
1738
- ]);
1739
- callback();
1740
- }
1741
- _final(callback) {
1742
- this.fs.writeFile(this.filePath, this.buffer, this.options).then(callback).catch(callback);
1743
- }
1744
- }
1745
- const $0846bf1c7ee89e90$var$S_IFREG = 32768;
1746
- const $0846bf1c7ee89e90$var$S_IFDIR = 16384;
1747
- const $0846bf1c7ee89e90$var$S_IFLNK = 40960;
1748
- const $0846bf1c7ee89e90$var$S_IFMT = 61440;
1749
- class $0846bf1c7ee89e90$var$Entry {
1750
- constructor(mode){
1751
- this.mode = mode;
1752
- let now = Date.now();
1753
- this.atime = now;
1754
- this.mtime = now;
1755
- this.ctime = now;
1756
- this.birthtime = now;
1757
- }
1758
- access() {
1759
- let now = Date.now();
1760
- this.atime = now;
1761
- this.ctime = now;
1762
- }
1763
- modify(mode) {
1764
- let now = Date.now();
1765
- this.mtime = now;
1766
- this.ctime = now;
1767
- this.mode = mode;
1768
- }
1769
- getSize() {
1770
- return 0;
1771
- }
1772
- stat() {
1773
- return new $0846bf1c7ee89e90$var$Stat(this);
1774
- }
1775
- }
1776
- class $0846bf1c7ee89e90$var$Stat {
1777
- dev = 0;
1778
- ino = 0;
1779
- nlink = 0;
1780
- uid = 0;
1781
- gid = 0;
1782
- rdev = 0;
1783
- blksize = 0;
1784
- blocks = 0;
1785
- constructor(entry){
1786
- this.mode = entry.mode;
1787
- this.size = entry.getSize();
1788
- this.atimeMs = entry.atime;
1789
- this.mtimeMs = entry.mtime;
1790
- this.ctimeMs = entry.ctime;
1791
- this.birthtimeMs = entry.birthtime;
1792
- this.atime = new Date(entry.atime);
1793
- this.mtime = new Date(entry.mtime);
1794
- this.ctime = new Date(entry.ctime);
1795
- this.birthtime = new Date(entry.birthtime);
1796
- }
1797
- isFile() {
1798
- return Boolean(this.mode & $0846bf1c7ee89e90$var$S_IFREG);
1799
- }
1800
- isDirectory() {
1801
- return Boolean(this.mode & $0846bf1c7ee89e90$var$S_IFDIR);
1802
- }
1803
- isBlockDevice() {
1804
- return false;
1805
- }
1806
- isCharacterDevice() {
1807
- return false;
1808
- }
1809
- isSymbolicLink() {
1810
- return false;
1811
- }
1812
- isFIFO() {
1813
- return false;
1814
- }
1815
- isSocket() {
1816
- return false;
1817
- }
1818
- }
1819
- class $0846bf1c7ee89e90$var$Dirent {
1820
- #mode;
1821
- constructor(name, entry){
1822
- this.name = name;
1823
- this.#mode = entry.mode;
1824
- }
1825
- isFile() {
1826
- return (this.#mode & $0846bf1c7ee89e90$var$S_IFMT) === $0846bf1c7ee89e90$var$S_IFREG;
1827
- }
1828
- isDirectory() {
1829
- return (this.#mode & $0846bf1c7ee89e90$var$S_IFMT) === $0846bf1c7ee89e90$var$S_IFDIR;
1830
- }
1831
- isBlockDevice() {
1832
- return false;
1833
- }
1834
- isCharacterDevice() {
1835
- return false;
1836
- }
1837
- isSymbolicLink() {
1838
- return (this.#mode & $0846bf1c7ee89e90$var$S_IFMT) === $0846bf1c7ee89e90$var$S_IFLNK;
1839
- }
1840
- isFIFO() {
1841
- return false;
1842
- }
1843
- isSocket() {
1844
- return false;
1845
- }
1846
- }
1847
- class $0846bf1c7ee89e90$export$b6afa8811b7e644e extends $0846bf1c7ee89e90$var$Entry {
1848
- constructor(buffer, mode){
1849
- super($0846bf1c7ee89e90$var$S_IFREG | mode);
1850
- this.buffer = buffer;
1851
- }
1852
- read() {
1853
- super.access();
1854
- return Buffer.from(this.buffer);
1855
- }
1856
- write(buffer, mode) {
1857
- super.modify($0846bf1c7ee89e90$var$S_IFREG | mode);
1858
- this.buffer = buffer;
1859
- }
1860
- getSize() {
1861
- return this.buffer.byteLength;
1862
- }
1863
- }
1864
- class $0846bf1c7ee89e90$var$Directory extends $0846bf1c7ee89e90$var$Entry {
1865
- constructor(){
1866
- super($0846bf1c7ee89e90$var$S_IFDIR);
1867
- }
1868
- }
1869
- function $0846bf1c7ee89e90$export$df9eb3e75aa27a22(contents) {
1870
- if (typeof contents !== 'string' && contents.buffer instanceof (0, $2V2hx$atlaspackutils.SharedBuffer)) return contents;
1871
- let contentsBuffer = contents;
1872
- // $FlowFixMe
1873
- if (process.browser) // For the polyfilled buffer module, it's faster to always convert once so that the subsequent
1874
- // operations are fast (.byteLength and using .set instead of .write)
1875
- contentsBuffer = contentsBuffer instanceof Buffer ? contentsBuffer : Buffer.from(contentsBuffer);
1876
- let length = Buffer.byteLength(contentsBuffer);
1877
- let shared = new (0, $2V2hx$atlaspackutils.SharedBuffer)(length);
1878
- let buffer = Buffer.from(shared);
1879
- if (length > 0) {
1880
- if (typeof contentsBuffer === 'string') buffer.write(contentsBuffer);
1881
- else buffer.set(contentsBuffer);
1882
- }
1883
- return buffer;
1884
- }
1885
- class $0846bf1c7ee89e90$var$WorkerFS extends $0846bf1c7ee89e90$export$3048eb7ec07c2c4e {
1886
- constructor(id, handle){
1887
- // TODO Make this not a subclass
1888
- // $FlowFixMe
1889
- super();
1890
- this.id = id;
1891
- this.handleFn = (methodName, args)=>(0, ($parcel$interopDefault($2V2hx$atlaspackworkers))).getWorkerApi().runHandle(handle, [
1892
- methodName,
1893
- args
1894
- ]);
1895
- this.handleFn('_registerWorker', [
1896
- (0, ($parcel$interopDefault($2V2hx$atlaspackworkers))).getWorkerApi().createReverseHandle((event)=>{
1897
- switch(event.type){
1898
- case 'writeFile':
1899
- this.files.set(event.path, event.entry);
1900
- break;
1901
- case 'unlink':
1902
- this.files.delete(event.path);
1903
- this.dirs.delete(event.path);
1904
- this.symlinks.delete(event.path);
1905
- break;
1906
- case 'mkdir':
1907
- this.dirs.set(event.path, new $0846bf1c7ee89e90$var$Directory());
1908
- break;
1909
- case 'symlink':
1910
- this.symlinks.set(event.path, event.target);
1911
- break;
1912
- }
1913
- })
1914
- ]);
1915
- }
1916
- static deserialize(opts) {
1917
- return (0, (/*@__PURE__*/$parcel$interopDefault($20532aab86e1ce9f$exports)))($0846bf1c7ee89e90$var$instances.get(opts.id));
1918
- }
1919
- serialize() {
1920
- // $FlowFixMe
1921
- return {
1922
- id: this.id
1923
- };
1924
- }
1925
- writeFile(filePath, contents, options) {
1926
- super.writeFile(filePath, contents, options);
1927
- let buffer = $0846bf1c7ee89e90$export$df9eb3e75aa27a22(contents);
1928
- return this.handleFn('writeFile', [
1929
- filePath,
1930
- buffer,
1931
- options
1932
- ]);
1933
- }
1934
- unlink(filePath) {
1935
- super.unlink(filePath);
1936
- return this.handleFn('unlink', [
1937
- filePath
1938
- ]);
1939
- }
1940
- mkdirp(dir) {
1941
- super.mkdirp(dir);
1942
- return this.handleFn('mkdirp', [
1943
- dir
1944
- ]);
1945
- }
1946
- rimraf(filePath) {
1947
- super.rimraf(filePath);
1948
- return this.handleFn('rimraf', [
1949
- filePath
1950
- ]);
1951
- }
1952
- ncp(source, destination) {
1953
- super.ncp(source, destination);
1954
- return this.handleFn('ncp', [
1955
- source,
1956
- destination
1957
- ]);
1958
- }
1959
- symlink(target, path) {
1960
- super.symlink(target, path);
1961
- return this.handleFn('symlink', [
1962
- target,
1963
- path
1964
- ]);
1965
- }
1966
- }
1967
- (0, $2V2hx$atlaspackbuildcache.registerSerializableClass)(`${(0, (/*@__PURE__*/$parcel$interopDefault($d7f6ae9f917393f7$exports))).version}:MemoryFS`, $0846bf1c7ee89e90$export$3048eb7ec07c2c4e);
1968
- (0, $2V2hx$atlaspackbuildcache.registerSerializableClass)(`${(0, (/*@__PURE__*/$parcel$interopDefault($d7f6ae9f917393f7$exports))).version}:WorkerFS`, $0846bf1c7ee89e90$var$WorkerFS);
1969
- (0, $2V2hx$atlaspackbuildcache.registerSerializableClass)(`${(0, (/*@__PURE__*/$parcel$interopDefault($d7f6ae9f917393f7$exports))).version}:Stat`, $0846bf1c7ee89e90$var$Stat);
1970
- (0, $2V2hx$atlaspackbuildcache.registerSerializableClass)(`${(0, (/*@__PURE__*/$parcel$interopDefault($d7f6ae9f917393f7$exports))).version}:File`, $0846bf1c7ee89e90$export$b6afa8811b7e644e);
1971
- (0, $2V2hx$atlaspackbuildcache.registerSerializableClass)(`${(0, (/*@__PURE__*/$parcel$interopDefault($d7f6ae9f917393f7$exports))).version}:Directory`, $0846bf1c7ee89e90$var$Directory);
1972
-
1973
-
1974
- var $74907c54eb766352$exports = {};
1975
-
1976
- $parcel$export($74907c54eb766352$exports, "OverlayFS", () => $74907c54eb766352$export$5963299e2424ca1c);
1977
-
1978
-
1979
-
1980
-
1981
-
1982
-
1983
-
1984
- class $74907c54eb766352$export$5963299e2424ca1c {
1985
- deleted = new Set();
1986
- constructor(workerFarmOrFS, readable){
1987
- if (workerFarmOrFS instanceof (0, ($parcel$interopDefault($2V2hx$atlaspackworkers)))) this.writable = new (0, $0846bf1c7ee89e90$export$3048eb7ec07c2c4e)(workerFarmOrFS);
1988
- else this.writable = workerFarmOrFS;
1989
- this.readable = readable;
1990
- this._cwd = readable.cwd();
1991
- }
1992
- static deserialize(opts) {
1993
- let fs = new $74907c54eb766352$export$5963299e2424ca1c(opts.writable, opts.readable);
1994
- if (opts.deleted != null) fs.deleted = opts.deleted;
1995
- return fs;
1996
- }
1997
- serialize() {
1998
- return {
1999
- $$raw: false,
2000
- writable: this.writable,
2001
- readable: this.readable,
2002
- deleted: this.deleted
2003
- };
2004
- }
2005
- _deletedThrows(filePath) {
2006
- filePath = this._normalizePath(filePath);
2007
- if (this.deleted.has(filePath)) throw new $74907c54eb766352$var$FSError('ENOENT', filePath, 'does not exist');
2008
- return filePath;
2009
- }
2010
- _checkExists(filePath) {
2011
- filePath = this._deletedThrows(filePath);
2012
- if (!this.existsSync(filePath)) throw new $74907c54eb766352$var$FSError('ENOENT', filePath, 'does not exist');
2013
- return filePath;
2014
- }
2015
- _isSymlink(filePath) {
2016
- filePath = this._normalizePath(filePath);
2017
- // Check the parts of the path to see if any are symlinks.
2018
- let { root: root, dir: dir, base: base } = (0, ($parcel$interopDefault($2V2hx$path))).parse(filePath);
2019
- let segments = dir.slice(root.length).split((0, ($parcel$interopDefault($2V2hx$path))).sep).concat(base);
2020
- while(segments.length){
2021
- filePath = (0, ($parcel$interopDefault($2V2hx$path))).join(root, ...segments);
2022
- let name = segments.pop();
2023
- if (this.deleted.has(filePath)) return false;
2024
- else if (this.writable instanceof (0, $0846bf1c7ee89e90$export$3048eb7ec07c2c4e) && this.writable.symlinks.has(filePath)) return true;
2025
- else {
2026
- // HACK: Atlaspack fs does not provide `lstatSync`,
2027
- // so we use `readdirSync` to check if the path is a symlink.
2028
- let parent = (0, ($parcel$interopDefault($2V2hx$path))).resolve(filePath, '..');
2029
- if (parent === filePath) return false;
2030
- try {
2031
- for (let dirent of this.readdirSync(parent, {
2032
- withFileTypes: true
2033
- })){
2034
- if (typeof dirent === 'string') break; // {withFileTypes: true} not supported
2035
- else if (dirent.name === name) {
2036
- if (dirent.isSymbolicLink()) return true;
2037
- }
2038
- }
2039
- } catch (e) {
2040
- if (e.code === 'ENOENT') return false;
2041
- throw e;
2042
- }
2043
- }
2044
- }
2045
- return false;
2046
- }
2047
- async _copyPathForWrite(filePath) {
2048
- filePath = await this._normalizePath(filePath);
2049
- let dirPath = (0, ($parcel$interopDefault($2V2hx$path))).dirname(filePath);
2050
- if (this.existsSync(dirPath) && !this.writable.existsSync(dirPath)) await this.writable.mkdirp(dirPath);
2051
- return filePath;
2052
- }
2053
- _normalizePath(filePath) {
2054
- return (0, ($parcel$interopDefault($2V2hx$path))).resolve(this.cwd(), filePath);
2055
- }
2056
- // eslint-disable-next-line require-await
2057
- async readFile(filePath, encoding) {
2058
- return this.readFileSync(filePath, encoding);
2059
- }
2060
- async writeFile(filePath, contents, options) {
2061
- filePath = await this._copyPathForWrite(filePath);
2062
- await this.writable.writeFile(filePath, contents, options);
2063
- this.deleted.delete(filePath);
2064
- }
2065
- async copyFile(source, destination) {
2066
- source = this._normalizePath(source);
2067
- destination = await this._copyPathForWrite(destination);
2068
- if (await this.writable.exists(source)) await this.writable.writeFile(destination, await this.writable.readFile(source));
2069
- else await this.writable.writeFile(destination, await this.readable.readFile(source));
2070
- this.deleted.delete(destination);
2071
- }
2072
- // eslint-disable-next-line require-await
2073
- async stat(filePath) {
2074
- return this.statSync(filePath);
2075
- }
2076
- async symlink(target, filePath) {
2077
- target = this._normalizePath(target);
2078
- filePath = this._normalizePath(filePath);
2079
- await this.writable.symlink(target, filePath);
2080
- this.deleted.delete(filePath);
2081
- }
2082
- async unlink(filePath) {
2083
- filePath = this._normalizePath(filePath);
2084
- let toDelete = [
2085
- filePath
2086
- ];
2087
- if (this.writable instanceof (0, $0846bf1c7ee89e90$export$3048eb7ec07c2c4e) && this._isSymlink(filePath)) this.writable.symlinks.delete(filePath);
2088
- else if (this.statSync(filePath).isDirectory()) {
2089
- let stack = [
2090
- filePath
2091
- ];
2092
- // Recursively add every descendant path to deleted.
2093
- while(stack.length){
2094
- let root = (0, (/*@__PURE__*/$parcel$interopDefault($20532aab86e1ce9f$exports)))(stack.pop());
2095
- for (let ent of this.readdirSync(root, {
2096
- withFileTypes: true
2097
- }))if (typeof ent === 'string') {
2098
- let childPath = (0, ($parcel$interopDefault($2V2hx$path))).join(root, ent);
2099
- toDelete.push(childPath);
2100
- if (this.statSync(childPath).isDirectory()) stack.push(childPath);
2101
- } else {
2102
- let childPath = (0, ($parcel$interopDefault($2V2hx$path))).join(root, ent.name);
2103
- toDelete.push(childPath);
2104
- if (ent.isDirectory()) stack.push(childPath);
2105
- }
2106
- }
2107
- }
2108
- try {
2109
- await this.writable.unlink(filePath);
2110
- } catch (e) {
2111
- if (e.code === 'ENOENT' && !this.readable.existsSync(filePath)) throw e;
2112
- }
2113
- for (let pathToDelete of toDelete)this.deleted.add(pathToDelete);
2114
- }
2115
- async mkdirp(dir) {
2116
- dir = this._normalizePath(dir);
2117
- await this.writable.mkdirp(dir);
2118
- if (this.deleted != null) {
2119
- let root = (0, ($parcel$interopDefault($2V2hx$path))).parse(dir).root;
2120
- while(dir !== root){
2121
- this.deleted.delete(dir);
2122
- dir = (0, ($parcel$interopDefault($2V2hx$path))).dirname(dir);
2123
- }
2124
- }
2125
- }
2126
- async rimraf(filePath) {
2127
- try {
2128
- await this.unlink(filePath);
2129
- } catch (e) {
2130
- // noop
2131
- }
2132
- }
2133
- // eslint-disable-next-line require-await
2134
- async ncp(source, destination) {
2135
- // TODO: Implement this correctly.
2136
- return this.writable.ncp(source, destination);
2137
- }
2138
- createReadStream(filePath, opts) {
2139
- filePath = this._deletedThrows(filePath);
2140
- if (this.writable.existsSync(filePath)) return this.writable.createReadStream(filePath, opts);
2141
- return this.readable.createReadStream(filePath, opts);
2142
- }
2143
- createWriteStream(path, opts) {
2144
- path = this._normalizePath(path);
2145
- this.deleted.delete(path);
2146
- return this.writable.createWriteStream(path, opts);
2147
- }
2148
- cwd() {
2149
- return this._cwd;
2150
- }
2151
- chdir(path) {
2152
- this._cwd = this._checkExists(path);
2153
- }
2154
- // eslint-disable-next-line require-await
2155
- async realpath(filePath) {
2156
- return this.realpathSync(filePath);
2157
- }
2158
- readFileSync(filePath, encoding) {
2159
- filePath = this.realpathSync(filePath);
2160
- try {
2161
- // $FlowFixMe[incompatible-call]
2162
- return this.writable.readFileSync(filePath, encoding);
2163
- } catch (err) {
2164
- // $FlowFixMe[incompatible-call]
2165
- return this.readable.readFileSync(filePath, encoding);
2166
- }
2167
- }
2168
- statSync(filePath) {
2169
- filePath = this._normalizePath(filePath);
2170
- try {
2171
- return this.writable.statSync(filePath);
2172
- } catch (e) {
2173
- if (e.code === 'ENOENT' && this.existsSync(filePath)) return this.readable.statSync(filePath);
2174
- throw e;
2175
- }
2176
- }
2177
- realpathSync(filePath) {
2178
- filePath = this._deletedThrows(filePath);
2179
- filePath = this._deletedThrows(this.writable.realpathSync(filePath));
2180
- if (!this.writable.existsSync(filePath)) return this.readable.realpathSync(filePath);
2181
- return filePath;
2182
- }
2183
- // eslint-disable-next-line require-await
2184
- async exists(filePath) {
2185
- return this.existsSync(filePath);
2186
- }
2187
- existsSync(filePath) {
2188
- filePath = this._normalizePath(filePath);
2189
- if (this.deleted.has(filePath)) return false;
2190
- try {
2191
- filePath = this.realpathSync(filePath);
2192
- } catch (err) {
2193
- if (err.code !== 'ENOENT') throw err;
2194
- }
2195
- if (this.deleted.has(filePath)) return false;
2196
- return this.writable.existsSync(filePath) || this.readable.existsSync(filePath);
2197
- }
2198
- // eslint-disable-next-line require-await
2199
- async readdir(path, opts) {
2200
- return this.readdirSync(path, opts);
2201
- }
2202
- readdirSync(dir, opts) {
2203
- dir = this.realpathSync(dir);
2204
- // Read from both filesystems and merge the results
2205
- let entries = new Map();
2206
- try {
2207
- for (let entry of this.writable.readdirSync(dir, opts)){
2208
- let filePath = (0, ($parcel$interopDefault($2V2hx$path))).join(dir, entry.name ?? entry);
2209
- if (this.deleted.has(filePath)) continue;
2210
- entries.set(filePath, entry);
2211
- }
2212
- } catch {
2213
- // noop
2214
- }
2215
- try {
2216
- for (let entry of this.readable.readdirSync(dir, opts)){
2217
- let filePath = (0, ($parcel$interopDefault($2V2hx$path))).join(dir, entry.name ?? entry);
2218
- if (this.deleted.has(filePath)) continue;
2219
- if (entries.has(filePath)) continue;
2220
- entries.set(filePath, entry);
2221
- }
2222
- } catch {
2223
- // noop
2224
- }
2225
- return Array.from(entries.values());
2226
- }
2227
- async watch(dir, fn, opts) {
2228
- let writableSubscription = await this.writable.watch(dir, fn, opts);
2229
- let readableSubscription = await this.readable.watch(dir, fn, opts);
2230
- return {
2231
- unsubscribe: async ()=>{
2232
- await writableSubscription.unsubscribe();
2233
- await readableSubscription.unsubscribe();
2234
- }
2235
- };
2236
- }
2237
- async getEventsSince(dir, snapshot, opts) {
2238
- let writableEvents = await this.writable.getEventsSince(dir, snapshot, opts);
2239
- let readableEvents = await this.readable.getEventsSince(dir, snapshot, opts);
2240
- return [
2241
- ...writableEvents,
2242
- ...readableEvents
2243
- ];
2244
- }
2245
- async writeSnapshot(dir, snapshot, opts) {
2246
- await this.writable.writeSnapshot(dir, snapshot, opts);
2247
- }
2248
- findAncestorFile(fileNames, fromDir, root) {
2249
- return (0, $782db929ace769f6$export$d51a93c758976388)(this, fileNames, fromDir, root);
2250
- }
2251
- findNodeModule(moduleName, fromDir) {
2252
- return (0, $782db929ace769f6$export$4c6d088a7d7f9947)(this, moduleName, fromDir);
2253
- }
2254
- findFirstFile(filePaths) {
2255
- return (0, $782db929ace769f6$export$64df6e3182fd5b2d)(this, filePaths);
2256
- }
2257
- }
2258
- class $74907c54eb766352$var$FSError extends Error {
2259
- constructor(code, path, message){
2260
- super(`${code}: ${path} ${message}`);
2261
- this.name = 'FSError';
2262
- this.code = code;
2263
- this.path = path;
2264
- Error.captureStackTrace?.(this, this.constructor);
2265
- }
2266
- }
2267
- (0, $2V2hx$atlaspackbuildcache.registerSerializableClass)(`${(0, (/*@__PURE__*/$parcel$interopDefault($d7f6ae9f917393f7$exports))).version}:OverlayFS`, $74907c54eb766352$export$5963299e2424ca1c);
2268
-
2269
-
2270
- var $907e69a4d4f6f904$exports = {};
2271
-
2272
- $parcel$export($907e69a4d4f6f904$exports, "NodeVCSAwareFS", () => $907e69a4d4f6f904$export$80de92554c03942a);
2273
-
2274
-
2275
-
2276
-
2277
-
2278
-
2279
-
2280
- class $907e69a4d4f6f904$export$80de92554c03942a extends (0, $94eb45ad74bb764d$export$c4e0ef2ab73c21e7) {
2281
- /**
2282
- * These files are excluded from 'dirty file' tracking even if they are
2283
- * modified.
2284
- */ #excludePatterns;
2285
- /**
2286
- * Logging function for the diff between watcher events and vcs events.
2287
- */ #logEventDiff;
2288
- /**
2289
- * The path of the git repository containing the project root. Null if the
2290
- * project is not a git repository.
2291
- */ #gitRepoPath;
2292
- constructor(options){
2293
- super();
2294
- this.#excludePatterns = options.excludePatterns;
2295
- this.#logEventDiff = options.logEventDiff;
2296
- this.#gitRepoPath = options.gitRepoPath;
2297
- }
2298
- // $FlowFixMe[incompatible-extend] the serialization API is not happy with inheritance
2299
- static deserialize(data) {
2300
- const fs = new $907e69a4d4f6f904$export$80de92554c03942a({
2301
- excludePatterns: data.excludePatterns,
2302
- logEventDiff: null,
2303
- gitRepoPath: data.gitRepoPath
2304
- });
2305
- return fs;
2306
- }
2307
- // $FlowFixMe[incompatible-extend] the serialization API is not happy with inheritance
2308
- serialize() {
2309
- return {
2310
- excludePatterns: this.#excludePatterns,
2311
- logEventDiff: null,
2312
- gitRepoPath: this.#gitRepoPath
2313
- };
2314
- }
2315
- setGitRepoPath(gitRepoPath) {
2316
- this.#gitRepoPath = gitRepoPath;
2317
- }
2318
- async getEventsSince(dir, snapshot, opts) {
2319
- const gitRepoPath = this.#gitRepoPath;
2320
- if (gitRepoPath == null) return this.watcher().getEventsSince(dir, snapshot, opts);
2321
- const { nativeSnapshotPath: nativeSnapshotPath, vcsState: vcsState } = await (0, $2V2hx$atlaspacklogger.instrumentAsync)('NodeVCSAwareFS.readSnapshot', async ()=>{
2322
- // Note: can't use toString() directly, or it won't resolve the promise
2323
- const snapshotFile = await this.readFile(snapshot);
2324
- const snapshotFileContent = snapshotFile.toString();
2325
- return JSON.parse(snapshotFileContent);
2326
- });
2327
- let watcherEventsSince = [];
2328
- const vcsEventsSince = vcsState != null ? (await (0, $2V2hx$atlaspacklogger.instrumentAsync)('NodeVCSAwareFS::rust.getEventsSince', ()=>(0, $2V2hx$atlaspackrust.getEventsSince)(gitRepoPath, vcsState, null))).map((e)=>({
2329
- path: e.path,
2330
- type: e.changeType
2331
- })) : null;
2332
- if ((0, $2V2hx$atlaspackfeatureflags.getFeatureFlagValue)('vcsMode') !== 'NEW' && vcsEventsSince != null) {
2333
- watcherEventsSince = await (0, $2V2hx$atlaspacklogger.instrumentAsync)('NodeVCSAwareFS::watchman.getEventsSince', ()=>this.watcher().getEventsSince(dir, nativeSnapshotPath, opts));
2334
- this.#logEventDiff?.(watcherEventsSince, vcsEventsSince);
2335
- }
2336
- if ([
2337
- 'NEW_AND_CHECK',
2338
- 'NEW'
2339
- ].includes((0, $2V2hx$atlaspackfeatureflags.getFeatureFlagValue)('vcsMode'))) {
2340
- if (vcsEventsSince == null) {
2341
- (0, ($parcel$interopDefault($2V2hx$atlaspacklogger))).error({
2342
- origin: '@atlaspack/fs',
2343
- message: 'Missing VCS state. There was an error when writing the snapshot. Please clear your cache.',
2344
- meta: {
2345
- trackableEvent: 'vcs_state_snapshot_read_failed'
2346
- }
2347
- });
2348
- return [];
2349
- }
2350
- return vcsEventsSince;
2351
- }
2352
- return watcherEventsSince;
2353
- }
2354
- async writeSnapshot(dir, snapshot, opts) {
2355
- const gitRepoPath = this.#gitRepoPath;
2356
- if (gitRepoPath == null) {
2357
- await this.watcher().writeSnapshot(dir, snapshot, opts);
2358
- return;
2359
- }
2360
- const snapshotDirectory = (0, ($parcel$interopDefault($2V2hx$path))).dirname(snapshot);
2361
- await this.mkdirp(snapshotDirectory);
2362
- const filename = (0, ($parcel$interopDefault($2V2hx$path))).basename(snapshot, '.txt');
2363
- const nativeSnapshotPath = (0, ($parcel$interopDefault($2V2hx$path))).join(snapshotDirectory, `${filename}.native-snapshot.txt`);
2364
- if ((0, $2V2hx$atlaspackfeatureflags.getFeatureFlagValue)('vcsMode') !== 'NEW') await (0, $2V2hx$atlaspacklogger.instrumentAsync)('NodeVCSAwareFS::watchman.writeSnapshot', async ()=>{
2365
- await this.watcher().writeSnapshot(dir, nativeSnapshotPath, opts);
2366
- });
2367
- let vcsState = null;
2368
- try {
2369
- vcsState = await (0, $2V2hx$atlaspacklogger.instrumentAsync)('NodeVCSAwareFS::getVcsStateSnapshot', ()=>(0, $2V2hx$atlaspackrust.getVcsStateSnapshot)(gitRepoPath, this.#excludePatterns));
2370
- (0, ($parcel$interopDefault($2V2hx$atlaspacklogger))).verbose({
2371
- origin: '@atlaspack/fs',
2372
- message: 'Expose VCS timing metrics',
2373
- meta: {
2374
- trackableEvent: 'vcs_timing_metrics',
2375
- dirtyFilesExecutionTime: vcsState?.dirtyFilesExecutionTime,
2376
- yarnStatesExecutionTime: vcsState?.yarnStatesExecutionTime
2377
- }
2378
- });
2379
- } catch (err) {
2380
- (0, ($parcel$interopDefault($2V2hx$atlaspacklogger))).error({
2381
- origin: '@atlaspack/fs',
2382
- message: `Failed to get VCS state snapshot: ${err.message}`,
2383
- meta: {
2384
- trackableEvent: 'vcs_state_snapshot_failed',
2385
- error: err
2386
- }
2387
- });
2388
- }
2389
- const snapshotContents = {
2390
- vcsState: vcsState,
2391
- nativeSnapshotPath: nativeSnapshotPath
2392
- };
2393
- await this.writeFile(snapshot, JSON.stringify(snapshotContents));
53
+ });
54
+ });
55
+ var _OverlayFS = require("./OverlayFS");
56
+ Object.keys(_OverlayFS).forEach(function (key) {
57
+ if (key === "default" || key === "__esModule") return;
58
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
59
+ if (key in exports && exports[key] === _OverlayFS[key]) return;
60
+ Object.defineProperty(exports, key, {
61
+ enumerable: true,
62
+ get: function () {
63
+ return _OverlayFS[key];
2394
64
  }
2395
- }
2396
- (0, $2V2hx$atlaspackbuildcache.registerSerializableClass)(`${(0, (/*@__PURE__*/$parcel$interopDefault($d7f6ae9f917393f7$exports))).version}:NodeVCSAwareFS`, $907e69a4d4f6f904$export$80de92554c03942a);
2397
-
2398
-
2399
- const $5acbc033ab4ad011$var$pipeline = (0, $2V2hx$util.promisify)((0, ($parcel$interopDefault($2V2hx$stream))).pipeline);
2400
- async function $5acbc033ab4ad011$export$d3a8044e3fef7335(sourceFS, source, destinationFS, destination, filter) {
2401
- await destinationFS.mkdirp(destination);
2402
- let files = await sourceFS.readdir(source);
2403
- for (let file of files){
2404
- if (filter && !filter(file)) continue;
2405
- let sourcePath = (0, ($parcel$interopDefault($2V2hx$path))).join(source, file);
2406
- let destPath = (0, ($parcel$interopDefault($2V2hx$path))).join(destination, file);
2407
- let stats = await sourceFS.stat(sourcePath);
2408
- if (stats.isFile()) await $5acbc033ab4ad011$var$pipeline(sourceFS.createReadStream(sourcePath), destinationFS.createWriteStream(destPath));
2409
- else if (stats.isDirectory()) await $5acbc033ab4ad011$export$d3a8044e3fef7335(sourceFS, sourcePath, destinationFS, destPath, filter);
65
+ });
66
+ });
67
+ var _NodeVCSAwareFS = require("./NodeVCSAwareFS");
68
+ Object.keys(_NodeVCSAwareFS).forEach(function (key) {
69
+ if (key === "default" || key === "__esModule") return;
70
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
71
+ if (key in exports && exports[key] === _NodeVCSAwareFS[key]) return;
72
+ Object.defineProperty(exports, key, {
73
+ enumerable: true,
74
+ get: function () {
75
+ return _NodeVCSAwareFS[key];
2410
76
  }
2411
- }
2412
- $parcel$exportWildcard(module.exports, $94eb45ad74bb764d$exports);
2413
- $parcel$exportWildcard(module.exports, $0846bf1c7ee89e90$exports);
2414
- $parcel$exportWildcard(module.exports, $74907c54eb766352$exports);
2415
- $parcel$exportWildcard(module.exports, $907e69a4d4f6f904$exports);
2416
-
2417
-
2418
- //# sourceMappingURL=index.js.map
77
+ });
78
+ });
79
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
80
+ const pipeline = (0, _util().promisify)(_stream().default.pipeline);
81
+
82
+ // Recursively copies a directory from the sourceFS to the destinationFS
83
+ async function ncp(sourceFS, source, destinationFS, destination, filter) {
84
+ await destinationFS.mkdirp(destination);
85
+ let files = await sourceFS.readdir(source);
86
+ for (let file of files) {
87
+ if (filter && !filter(file)) {
88
+ continue;
89
+ }
90
+ let sourcePath = _path().default.join(source, file);
91
+ let destPath = _path().default.join(destination, file);
92
+ let stats = await sourceFS.stat(sourcePath);
93
+ if (stats.isFile()) {
94
+ await pipeline(sourceFS.createReadStream(sourcePath), destinationFS.createWriteStream(destPath));
95
+ } else if (stats.isDirectory()) {
96
+ await ncp(sourceFS, sourcePath, destinationFS, destPath, filter);
97
+ }
98
+ }
99
+ }