@atlaspack/fs 2.14.5-dev.14 → 2.14.5-dev.55

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