rspkify 0.0.0-beta.0

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.
@@ -0,0 +1,2560 @@
1
+ import { f as commonjsGlobal, g as getDefaultExportFromCjs } from './index.mjs';
2
+ import require$$0$2 from 'fs';
3
+ import require$$0 from 'constants';
4
+ import require$$0$1 from 'stream';
5
+ import require$$4 from 'util';
6
+ import require$$5 from 'assert';
7
+ import require$$1 from 'path';
8
+
9
+ function _mergeNamespaces(n, m) {
10
+ m.forEach(function (e) {
11
+ e && typeof e !== 'string' && !Array.isArray(e) && Object.keys(e).forEach(function (k) {
12
+ if (k !== 'default' && !(k in n)) {
13
+ var d = Object.getOwnPropertyDescriptor(e, k);
14
+ Object.defineProperty(n, k, d.get ? d : {
15
+ enumerable: true,
16
+ get: function () { return e[k]; }
17
+ });
18
+ }
19
+ });
20
+ });
21
+ return Object.freeze(n);
22
+ }
23
+
24
+ var fs$h = {};
25
+
26
+ var universalify$1 = {};
27
+
28
+ universalify$1.fromCallback = function (fn) {
29
+ return Object.defineProperty(function (...args) {
30
+ if (typeof args[args.length - 1] === 'function') fn.apply(this, args);
31
+ else {
32
+ return new Promise((resolve, reject) => {
33
+ args.push((err, res) => (err != null) ? reject(err) : resolve(res));
34
+ fn.apply(this, args);
35
+ })
36
+ }
37
+ }, 'name', { value: fn.name })
38
+ };
39
+
40
+ universalify$1.fromPromise = function (fn) {
41
+ return Object.defineProperty(function (...args) {
42
+ const cb = args[args.length - 1];
43
+ if (typeof cb !== 'function') return fn.apply(this, args)
44
+ else {
45
+ args.pop();
46
+ fn.apply(this, args).then(r => cb(null, r), cb);
47
+ }
48
+ }, 'name', { value: fn.name })
49
+ };
50
+
51
+ var constants = require$$0;
52
+
53
+ var origCwd = process.cwd;
54
+ var cwd = null;
55
+
56
+ var platform = process.env.GRACEFUL_FS_PLATFORM || process.platform;
57
+
58
+ process.cwd = function() {
59
+ if (!cwd)
60
+ cwd = origCwd.call(process);
61
+ return cwd
62
+ };
63
+ try {
64
+ process.cwd();
65
+ } catch (er) {}
66
+
67
+ // This check is needed until node.js 12 is required
68
+ if (typeof process.chdir === 'function') {
69
+ var chdir = process.chdir;
70
+ process.chdir = function (d) {
71
+ cwd = null;
72
+ chdir.call(process, d);
73
+ };
74
+ if (Object.setPrototypeOf) Object.setPrototypeOf(process.chdir, chdir);
75
+ }
76
+
77
+ var polyfills$1 = patch$1;
78
+
79
+ function patch$1 (fs) {
80
+ // (re-)implement some things that are known busted or missing.
81
+
82
+ // lchmod, broken prior to 0.6.2
83
+ // back-port the fix here.
84
+ if (constants.hasOwnProperty('O_SYMLINK') &&
85
+ process.version.match(/^v0\.6\.[0-2]|^v0\.5\./)) {
86
+ patchLchmod(fs);
87
+ }
88
+
89
+ // lutimes implementation, or no-op
90
+ if (!fs.lutimes) {
91
+ patchLutimes(fs);
92
+ }
93
+
94
+ // https://github.com/isaacs/node-graceful-fs/issues/4
95
+ // Chown should not fail on einval or eperm if non-root.
96
+ // It should not fail on enosys ever, as this just indicates
97
+ // that a fs doesn't support the intended operation.
98
+
99
+ fs.chown = chownFix(fs.chown);
100
+ fs.fchown = chownFix(fs.fchown);
101
+ fs.lchown = chownFix(fs.lchown);
102
+
103
+ fs.chmod = chmodFix(fs.chmod);
104
+ fs.fchmod = chmodFix(fs.fchmod);
105
+ fs.lchmod = chmodFix(fs.lchmod);
106
+
107
+ fs.chownSync = chownFixSync(fs.chownSync);
108
+ fs.fchownSync = chownFixSync(fs.fchownSync);
109
+ fs.lchownSync = chownFixSync(fs.lchownSync);
110
+
111
+ fs.chmodSync = chmodFixSync(fs.chmodSync);
112
+ fs.fchmodSync = chmodFixSync(fs.fchmodSync);
113
+ fs.lchmodSync = chmodFixSync(fs.lchmodSync);
114
+
115
+ fs.stat = statFix(fs.stat);
116
+ fs.fstat = statFix(fs.fstat);
117
+ fs.lstat = statFix(fs.lstat);
118
+
119
+ fs.statSync = statFixSync(fs.statSync);
120
+ fs.fstatSync = statFixSync(fs.fstatSync);
121
+ fs.lstatSync = statFixSync(fs.lstatSync);
122
+
123
+ // if lchmod/lchown do not exist, then make them no-ops
124
+ if (fs.chmod && !fs.lchmod) {
125
+ fs.lchmod = function (path, mode, cb) {
126
+ if (cb) process.nextTick(cb);
127
+ };
128
+ fs.lchmodSync = function () {};
129
+ }
130
+ if (fs.chown && !fs.lchown) {
131
+ fs.lchown = function (path, uid, gid, cb) {
132
+ if (cb) process.nextTick(cb);
133
+ };
134
+ fs.lchownSync = function () {};
135
+ }
136
+
137
+ // on Windows, A/V software can lock the directory, causing this
138
+ // to fail with an EACCES or EPERM if the directory contains newly
139
+ // created files. Try again on failure, for up to 60 seconds.
140
+
141
+ // Set the timeout this long because some Windows Anti-Virus, such as Parity
142
+ // bit9, may lock files for up to a minute, causing npm package install
143
+ // failures. Also, take care to yield the scheduler. Windows scheduling gives
144
+ // CPU to a busy looping process, which can cause the program causing the lock
145
+ // contention to be starved of CPU by node, so the contention doesn't resolve.
146
+ if (platform === "win32") {
147
+ fs.rename = typeof fs.rename !== 'function' ? fs.rename
148
+ : (function (fs$rename) {
149
+ function rename (from, to, cb) {
150
+ var start = Date.now();
151
+ var backoff = 0;
152
+ fs$rename(from, to, function CB (er) {
153
+ if (er
154
+ && (er.code === "EACCES" || er.code === "EPERM" || er.code === "EBUSY")
155
+ && Date.now() - start < 60000) {
156
+ setTimeout(function() {
157
+ fs.stat(to, function (stater, st) {
158
+ if (stater && stater.code === "ENOENT")
159
+ fs$rename(from, to, CB);
160
+ else
161
+ cb(er);
162
+ });
163
+ }, backoff);
164
+ if (backoff < 100)
165
+ backoff += 10;
166
+ return;
167
+ }
168
+ if (cb) cb(er);
169
+ });
170
+ }
171
+ if (Object.setPrototypeOf) Object.setPrototypeOf(rename, fs$rename);
172
+ return rename
173
+ })(fs.rename);
174
+ }
175
+
176
+ // if read() returns EAGAIN, then just try it again.
177
+ fs.read = typeof fs.read !== 'function' ? fs.read
178
+ : (function (fs$read) {
179
+ function read (fd, buffer, offset, length, position, callback_) {
180
+ var callback;
181
+ if (callback_ && typeof callback_ === 'function') {
182
+ var eagCounter = 0;
183
+ callback = function (er, _, __) {
184
+ if (er && er.code === 'EAGAIN' && eagCounter < 10) {
185
+ eagCounter ++;
186
+ return fs$read.call(fs, fd, buffer, offset, length, position, callback)
187
+ }
188
+ callback_.apply(this, arguments);
189
+ };
190
+ }
191
+ return fs$read.call(fs, fd, buffer, offset, length, position, callback)
192
+ }
193
+
194
+ // This ensures `util.promisify` works as it does for native `fs.read`.
195
+ if (Object.setPrototypeOf) Object.setPrototypeOf(read, fs$read);
196
+ return read
197
+ })(fs.read);
198
+
199
+ fs.readSync = typeof fs.readSync !== 'function' ? fs.readSync
200
+ : (function (fs$readSync) { return function (fd, buffer, offset, length, position) {
201
+ var eagCounter = 0;
202
+ while (true) {
203
+ try {
204
+ return fs$readSync.call(fs, fd, buffer, offset, length, position)
205
+ } catch (er) {
206
+ if (er.code === 'EAGAIN' && eagCounter < 10) {
207
+ eagCounter ++;
208
+ continue
209
+ }
210
+ throw er
211
+ }
212
+ }
213
+ }})(fs.readSync);
214
+
215
+ function patchLchmod (fs) {
216
+ fs.lchmod = function (path, mode, callback) {
217
+ fs.open( path
218
+ , constants.O_WRONLY | constants.O_SYMLINK
219
+ , mode
220
+ , function (err, fd) {
221
+ if (err) {
222
+ if (callback) callback(err);
223
+ return
224
+ }
225
+ // prefer to return the chmod error, if one occurs,
226
+ // but still try to close, and report closing errors if they occur.
227
+ fs.fchmod(fd, mode, function (err) {
228
+ fs.close(fd, function(err2) {
229
+ if (callback) callback(err || err2);
230
+ });
231
+ });
232
+ });
233
+ };
234
+
235
+ fs.lchmodSync = function (path, mode) {
236
+ var fd = fs.openSync(path, constants.O_WRONLY | constants.O_SYMLINK, mode);
237
+
238
+ // prefer to return the chmod error, if one occurs,
239
+ // but still try to close, and report closing errors if they occur.
240
+ var threw = true;
241
+ var ret;
242
+ try {
243
+ ret = fs.fchmodSync(fd, mode);
244
+ threw = false;
245
+ } finally {
246
+ if (threw) {
247
+ try {
248
+ fs.closeSync(fd);
249
+ } catch (er) {}
250
+ } else {
251
+ fs.closeSync(fd);
252
+ }
253
+ }
254
+ return ret
255
+ };
256
+ }
257
+
258
+ function patchLutimes (fs) {
259
+ if (constants.hasOwnProperty("O_SYMLINK") && fs.futimes) {
260
+ fs.lutimes = function (path, at, mt, cb) {
261
+ fs.open(path, constants.O_SYMLINK, function (er, fd) {
262
+ if (er) {
263
+ if (cb) cb(er);
264
+ return
265
+ }
266
+ fs.futimes(fd, at, mt, function (er) {
267
+ fs.close(fd, function (er2) {
268
+ if (cb) cb(er || er2);
269
+ });
270
+ });
271
+ });
272
+ };
273
+
274
+ fs.lutimesSync = function (path, at, mt) {
275
+ var fd = fs.openSync(path, constants.O_SYMLINK);
276
+ var ret;
277
+ var threw = true;
278
+ try {
279
+ ret = fs.futimesSync(fd, at, mt);
280
+ threw = false;
281
+ } finally {
282
+ if (threw) {
283
+ try {
284
+ fs.closeSync(fd);
285
+ } catch (er) {}
286
+ } else {
287
+ fs.closeSync(fd);
288
+ }
289
+ }
290
+ return ret
291
+ };
292
+
293
+ } else if (fs.futimes) {
294
+ fs.lutimes = function (_a, _b, _c, cb) { if (cb) process.nextTick(cb); };
295
+ fs.lutimesSync = function () {};
296
+ }
297
+ }
298
+
299
+ function chmodFix (orig) {
300
+ if (!orig) return orig
301
+ return function (target, mode, cb) {
302
+ return orig.call(fs, target, mode, function (er) {
303
+ if (chownErOk(er)) er = null;
304
+ if (cb) cb.apply(this, arguments);
305
+ })
306
+ }
307
+ }
308
+
309
+ function chmodFixSync (orig) {
310
+ if (!orig) return orig
311
+ return function (target, mode) {
312
+ try {
313
+ return orig.call(fs, target, mode)
314
+ } catch (er) {
315
+ if (!chownErOk(er)) throw er
316
+ }
317
+ }
318
+ }
319
+
320
+
321
+ function chownFix (orig) {
322
+ if (!orig) return orig
323
+ return function (target, uid, gid, cb) {
324
+ return orig.call(fs, target, uid, gid, function (er) {
325
+ if (chownErOk(er)) er = null;
326
+ if (cb) cb.apply(this, arguments);
327
+ })
328
+ }
329
+ }
330
+
331
+ function chownFixSync (orig) {
332
+ if (!orig) return orig
333
+ return function (target, uid, gid) {
334
+ try {
335
+ return orig.call(fs, target, uid, gid)
336
+ } catch (er) {
337
+ if (!chownErOk(er)) throw er
338
+ }
339
+ }
340
+ }
341
+
342
+ function statFix (orig) {
343
+ if (!orig) return orig
344
+ // Older versions of Node erroneously returned signed integers for
345
+ // uid + gid.
346
+ return function (target, options, cb) {
347
+ if (typeof options === 'function') {
348
+ cb = options;
349
+ options = null;
350
+ }
351
+ function callback (er, stats) {
352
+ if (stats) {
353
+ if (stats.uid < 0) stats.uid += 0x100000000;
354
+ if (stats.gid < 0) stats.gid += 0x100000000;
355
+ }
356
+ if (cb) cb.apply(this, arguments);
357
+ }
358
+ return options ? orig.call(fs, target, options, callback)
359
+ : orig.call(fs, target, callback)
360
+ }
361
+ }
362
+
363
+ function statFixSync (orig) {
364
+ if (!orig) return orig
365
+ // Older versions of Node erroneously returned signed integers for
366
+ // uid + gid.
367
+ return function (target, options) {
368
+ var stats = options ? orig.call(fs, target, options)
369
+ : orig.call(fs, target);
370
+ if (stats) {
371
+ if (stats.uid < 0) stats.uid += 0x100000000;
372
+ if (stats.gid < 0) stats.gid += 0x100000000;
373
+ }
374
+ return stats;
375
+ }
376
+ }
377
+
378
+ // ENOSYS means that the fs doesn't support the op. Just ignore
379
+ // that, because it doesn't matter.
380
+ //
381
+ // if there's no getuid, or if getuid() is something other
382
+ // than 0, and the error is EINVAL or EPERM, then just ignore
383
+ // it.
384
+ //
385
+ // This specific case is a silent failure in cp, install, tar,
386
+ // and most other unix tools that manage permissions.
387
+ //
388
+ // When running as root, or if other types of errors are
389
+ // encountered, then it's strict.
390
+ function chownErOk (er) {
391
+ if (!er)
392
+ return true
393
+
394
+ if (er.code === "ENOSYS")
395
+ return true
396
+
397
+ var nonroot = !process.getuid || process.getuid() !== 0;
398
+ if (nonroot) {
399
+ if (er.code === "EINVAL" || er.code === "EPERM")
400
+ return true
401
+ }
402
+
403
+ return false
404
+ }
405
+ }
406
+
407
+ var Stream = require$$0$1.Stream;
408
+
409
+ var legacyStreams = legacy$1;
410
+
411
+ function legacy$1 (fs) {
412
+ return {
413
+ ReadStream: ReadStream,
414
+ WriteStream: WriteStream
415
+ }
416
+
417
+ function ReadStream (path, options) {
418
+ if (!(this instanceof ReadStream)) return new ReadStream(path, options);
419
+
420
+ Stream.call(this);
421
+
422
+ var self = this;
423
+
424
+ this.path = path;
425
+ this.fd = null;
426
+ this.readable = true;
427
+ this.paused = false;
428
+
429
+ this.flags = 'r';
430
+ this.mode = 438; /*=0666*/
431
+ this.bufferSize = 64 * 1024;
432
+
433
+ options = options || {};
434
+
435
+ // Mixin options into this
436
+ var keys = Object.keys(options);
437
+ for (var index = 0, length = keys.length; index < length; index++) {
438
+ var key = keys[index];
439
+ this[key] = options[key];
440
+ }
441
+
442
+ if (this.encoding) this.setEncoding(this.encoding);
443
+
444
+ if (this.start !== undefined) {
445
+ if ('number' !== typeof this.start) {
446
+ throw TypeError('start must be a Number');
447
+ }
448
+ if (this.end === undefined) {
449
+ this.end = Infinity;
450
+ } else if ('number' !== typeof this.end) {
451
+ throw TypeError('end must be a Number');
452
+ }
453
+
454
+ if (this.start > this.end) {
455
+ throw new Error('start must be <= end');
456
+ }
457
+
458
+ this.pos = this.start;
459
+ }
460
+
461
+ if (this.fd !== null) {
462
+ process.nextTick(function() {
463
+ self._read();
464
+ });
465
+ return;
466
+ }
467
+
468
+ fs.open(this.path, this.flags, this.mode, function (err, fd) {
469
+ if (err) {
470
+ self.emit('error', err);
471
+ self.readable = false;
472
+ return;
473
+ }
474
+
475
+ self.fd = fd;
476
+ self.emit('open', fd);
477
+ self._read();
478
+ });
479
+ }
480
+
481
+ function WriteStream (path, options) {
482
+ if (!(this instanceof WriteStream)) return new WriteStream(path, options);
483
+
484
+ Stream.call(this);
485
+
486
+ this.path = path;
487
+ this.fd = null;
488
+ this.writable = true;
489
+
490
+ this.flags = 'w';
491
+ this.encoding = 'binary';
492
+ this.mode = 438; /*=0666*/
493
+ this.bytesWritten = 0;
494
+
495
+ options = options || {};
496
+
497
+ // Mixin options into this
498
+ var keys = Object.keys(options);
499
+ for (var index = 0, length = keys.length; index < length; index++) {
500
+ var key = keys[index];
501
+ this[key] = options[key];
502
+ }
503
+
504
+ if (this.start !== undefined) {
505
+ if ('number' !== typeof this.start) {
506
+ throw TypeError('start must be a Number');
507
+ }
508
+ if (this.start < 0) {
509
+ throw new Error('start must be >= zero');
510
+ }
511
+
512
+ this.pos = this.start;
513
+ }
514
+
515
+ this.busy = false;
516
+ this._queue = [];
517
+
518
+ if (this.fd === null) {
519
+ this._open = fs.open;
520
+ this._queue.push([this._open, this.path, this.flags, this.mode, undefined]);
521
+ this.flush();
522
+ }
523
+ }
524
+ }
525
+
526
+ var clone_1 = clone$1;
527
+
528
+ var getPrototypeOf = Object.getPrototypeOf || function (obj) {
529
+ return obj.__proto__
530
+ };
531
+
532
+ function clone$1 (obj) {
533
+ if (obj === null || typeof obj !== 'object')
534
+ return obj
535
+
536
+ if (obj instanceof Object)
537
+ var copy = { __proto__: getPrototypeOf(obj) };
538
+ else
539
+ var copy = Object.create(null);
540
+
541
+ Object.getOwnPropertyNames(obj).forEach(function (key) {
542
+ Object.defineProperty(copy, key, Object.getOwnPropertyDescriptor(obj, key));
543
+ });
544
+
545
+ return copy
546
+ }
547
+
548
+ var fs$g = require$$0$2;
549
+ var polyfills = polyfills$1;
550
+ var legacy = legacyStreams;
551
+ var clone = clone_1;
552
+
553
+ var util$1 = require$$4;
554
+
555
+ /* istanbul ignore next - node 0.x polyfill */
556
+ var gracefulQueue;
557
+ var previousSymbol;
558
+
559
+ /* istanbul ignore else - node 0.x polyfill */
560
+ if (typeof Symbol === 'function' && typeof Symbol.for === 'function') {
561
+ gracefulQueue = Symbol.for('graceful-fs.queue');
562
+ // This is used in testing by future versions
563
+ previousSymbol = Symbol.for('graceful-fs.previous');
564
+ } else {
565
+ gracefulQueue = '___graceful-fs.queue';
566
+ previousSymbol = '___graceful-fs.previous';
567
+ }
568
+
569
+ function noop () {}
570
+
571
+ function publishQueue(context, queue) {
572
+ Object.defineProperty(context, gracefulQueue, {
573
+ get: function() {
574
+ return queue
575
+ }
576
+ });
577
+ }
578
+
579
+ var debug = noop;
580
+ if (util$1.debuglog)
581
+ debug = util$1.debuglog('gfs4');
582
+ else if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || ''))
583
+ debug = function() {
584
+ var m = util$1.format.apply(util$1, arguments);
585
+ m = 'GFS4: ' + m.split(/\n/).join('\nGFS4: ');
586
+ console.error(m);
587
+ };
588
+
589
+ // Once time initialization
590
+ if (!fs$g[gracefulQueue]) {
591
+ // This queue can be shared by multiple loaded instances
592
+ var queue = commonjsGlobal[gracefulQueue] || [];
593
+ publishQueue(fs$g, queue);
594
+
595
+ // Patch fs.close/closeSync to shared queue version, because we need
596
+ // to retry() whenever a close happens *anywhere* in the program.
597
+ // This is essential when multiple graceful-fs instances are
598
+ // in play at the same time.
599
+ fs$g.close = (function (fs$close) {
600
+ function close (fd, cb) {
601
+ return fs$close.call(fs$g, fd, function (err) {
602
+ // This function uses the graceful-fs shared queue
603
+ if (!err) {
604
+ resetQueue();
605
+ }
606
+
607
+ if (typeof cb === 'function')
608
+ cb.apply(this, arguments);
609
+ })
610
+ }
611
+
612
+ Object.defineProperty(close, previousSymbol, {
613
+ value: fs$close
614
+ });
615
+ return close
616
+ })(fs$g.close);
617
+
618
+ fs$g.closeSync = (function (fs$closeSync) {
619
+ function closeSync (fd) {
620
+ // This function uses the graceful-fs shared queue
621
+ fs$closeSync.apply(fs$g, arguments);
622
+ resetQueue();
623
+ }
624
+
625
+ Object.defineProperty(closeSync, previousSymbol, {
626
+ value: fs$closeSync
627
+ });
628
+ return closeSync
629
+ })(fs$g.closeSync);
630
+
631
+ if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || '')) {
632
+ process.on('exit', function() {
633
+ debug(fs$g[gracefulQueue]);
634
+ require$$5.equal(fs$g[gracefulQueue].length, 0);
635
+ });
636
+ }
637
+ }
638
+
639
+ if (!commonjsGlobal[gracefulQueue]) {
640
+ publishQueue(commonjsGlobal, fs$g[gracefulQueue]);
641
+ }
642
+
643
+ var gracefulFs = patch(clone(fs$g));
644
+ if (process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH && !fs$g.__patched) {
645
+ gracefulFs = patch(fs$g);
646
+ fs$g.__patched = true;
647
+ }
648
+
649
+ function patch (fs) {
650
+ // Everything that references the open() function needs to be in here
651
+ polyfills(fs);
652
+ fs.gracefulify = patch;
653
+
654
+ fs.createReadStream = createReadStream;
655
+ fs.createWriteStream = createWriteStream;
656
+ var fs$readFile = fs.readFile;
657
+ fs.readFile = readFile;
658
+ function readFile (path, options, cb) {
659
+ if (typeof options === 'function')
660
+ cb = options, options = null;
661
+
662
+ return go$readFile(path, options, cb)
663
+
664
+ function go$readFile (path, options, cb, startTime) {
665
+ return fs$readFile(path, options, function (err) {
666
+ if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
667
+ enqueue([go$readFile, [path, options, cb], err, startTime || Date.now(), Date.now()]);
668
+ else {
669
+ if (typeof cb === 'function')
670
+ cb.apply(this, arguments);
671
+ }
672
+ })
673
+ }
674
+ }
675
+
676
+ var fs$writeFile = fs.writeFile;
677
+ fs.writeFile = writeFile;
678
+ function writeFile (path, data, options, cb) {
679
+ if (typeof options === 'function')
680
+ cb = options, options = null;
681
+
682
+ return go$writeFile(path, data, options, cb)
683
+
684
+ function go$writeFile (path, data, options, cb, startTime) {
685
+ return fs$writeFile(path, data, options, function (err) {
686
+ if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
687
+ enqueue([go$writeFile, [path, data, options, cb], err, startTime || Date.now(), Date.now()]);
688
+ else {
689
+ if (typeof cb === 'function')
690
+ cb.apply(this, arguments);
691
+ }
692
+ })
693
+ }
694
+ }
695
+
696
+ var fs$appendFile = fs.appendFile;
697
+ if (fs$appendFile)
698
+ fs.appendFile = appendFile;
699
+ function appendFile (path, data, options, cb) {
700
+ if (typeof options === 'function')
701
+ cb = options, options = null;
702
+
703
+ return go$appendFile(path, data, options, cb)
704
+
705
+ function go$appendFile (path, data, options, cb, startTime) {
706
+ return fs$appendFile(path, data, options, function (err) {
707
+ if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
708
+ enqueue([go$appendFile, [path, data, options, cb], err, startTime || Date.now(), Date.now()]);
709
+ else {
710
+ if (typeof cb === 'function')
711
+ cb.apply(this, arguments);
712
+ }
713
+ })
714
+ }
715
+ }
716
+
717
+ var fs$copyFile = fs.copyFile;
718
+ if (fs$copyFile)
719
+ fs.copyFile = copyFile;
720
+ function copyFile (src, dest, flags, cb) {
721
+ if (typeof flags === 'function') {
722
+ cb = flags;
723
+ flags = 0;
724
+ }
725
+ return go$copyFile(src, dest, flags, cb)
726
+
727
+ function go$copyFile (src, dest, flags, cb, startTime) {
728
+ return fs$copyFile(src, dest, flags, function (err) {
729
+ if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
730
+ enqueue([go$copyFile, [src, dest, flags, cb], err, startTime || Date.now(), Date.now()]);
731
+ else {
732
+ if (typeof cb === 'function')
733
+ cb.apply(this, arguments);
734
+ }
735
+ })
736
+ }
737
+ }
738
+
739
+ var fs$readdir = fs.readdir;
740
+ fs.readdir = readdir;
741
+ var noReaddirOptionVersions = /^v[0-5]\./;
742
+ function readdir (path, options, cb) {
743
+ if (typeof options === 'function')
744
+ cb = options, options = null;
745
+
746
+ var go$readdir = noReaddirOptionVersions.test(process.version)
747
+ ? function go$readdir (path, options, cb, startTime) {
748
+ return fs$readdir(path, fs$readdirCallback(
749
+ path, options, cb, startTime
750
+ ))
751
+ }
752
+ : function go$readdir (path, options, cb, startTime) {
753
+ return fs$readdir(path, options, fs$readdirCallback(
754
+ path, options, cb, startTime
755
+ ))
756
+ };
757
+
758
+ return go$readdir(path, options, cb)
759
+
760
+ function fs$readdirCallback (path, options, cb, startTime) {
761
+ return function (err, files) {
762
+ if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
763
+ enqueue([
764
+ go$readdir,
765
+ [path, options, cb],
766
+ err,
767
+ startTime || Date.now(),
768
+ Date.now()
769
+ ]);
770
+ else {
771
+ if (files && files.sort)
772
+ files.sort();
773
+
774
+ if (typeof cb === 'function')
775
+ cb.call(this, err, files);
776
+ }
777
+ }
778
+ }
779
+ }
780
+
781
+ if (process.version.substr(0, 4) === 'v0.8') {
782
+ var legStreams = legacy(fs);
783
+ ReadStream = legStreams.ReadStream;
784
+ WriteStream = legStreams.WriteStream;
785
+ }
786
+
787
+ var fs$ReadStream = fs.ReadStream;
788
+ if (fs$ReadStream) {
789
+ ReadStream.prototype = Object.create(fs$ReadStream.prototype);
790
+ ReadStream.prototype.open = ReadStream$open;
791
+ }
792
+
793
+ var fs$WriteStream = fs.WriteStream;
794
+ if (fs$WriteStream) {
795
+ WriteStream.prototype = Object.create(fs$WriteStream.prototype);
796
+ WriteStream.prototype.open = WriteStream$open;
797
+ }
798
+
799
+ Object.defineProperty(fs, 'ReadStream', {
800
+ get: function () {
801
+ return ReadStream
802
+ },
803
+ set: function (val) {
804
+ ReadStream = val;
805
+ },
806
+ enumerable: true,
807
+ configurable: true
808
+ });
809
+ Object.defineProperty(fs, 'WriteStream', {
810
+ get: function () {
811
+ return WriteStream
812
+ },
813
+ set: function (val) {
814
+ WriteStream = val;
815
+ },
816
+ enumerable: true,
817
+ configurable: true
818
+ });
819
+
820
+ // legacy names
821
+ var FileReadStream = ReadStream;
822
+ Object.defineProperty(fs, 'FileReadStream', {
823
+ get: function () {
824
+ return FileReadStream
825
+ },
826
+ set: function (val) {
827
+ FileReadStream = val;
828
+ },
829
+ enumerable: true,
830
+ configurable: true
831
+ });
832
+ var FileWriteStream = WriteStream;
833
+ Object.defineProperty(fs, 'FileWriteStream', {
834
+ get: function () {
835
+ return FileWriteStream
836
+ },
837
+ set: function (val) {
838
+ FileWriteStream = val;
839
+ },
840
+ enumerable: true,
841
+ configurable: true
842
+ });
843
+
844
+ function ReadStream (path, options) {
845
+ if (this instanceof ReadStream)
846
+ return fs$ReadStream.apply(this, arguments), this
847
+ else
848
+ return ReadStream.apply(Object.create(ReadStream.prototype), arguments)
849
+ }
850
+
851
+ function ReadStream$open () {
852
+ var that = this;
853
+ open(that.path, that.flags, that.mode, function (err, fd) {
854
+ if (err) {
855
+ if (that.autoClose)
856
+ that.destroy();
857
+
858
+ that.emit('error', err);
859
+ } else {
860
+ that.fd = fd;
861
+ that.emit('open', fd);
862
+ that.read();
863
+ }
864
+ });
865
+ }
866
+
867
+ function WriteStream (path, options) {
868
+ if (this instanceof WriteStream)
869
+ return fs$WriteStream.apply(this, arguments), this
870
+ else
871
+ return WriteStream.apply(Object.create(WriteStream.prototype), arguments)
872
+ }
873
+
874
+ function WriteStream$open () {
875
+ var that = this;
876
+ open(that.path, that.flags, that.mode, function (err, fd) {
877
+ if (err) {
878
+ that.destroy();
879
+ that.emit('error', err);
880
+ } else {
881
+ that.fd = fd;
882
+ that.emit('open', fd);
883
+ }
884
+ });
885
+ }
886
+
887
+ function createReadStream (path, options) {
888
+ return new fs.ReadStream(path, options)
889
+ }
890
+
891
+ function createWriteStream (path, options) {
892
+ return new fs.WriteStream(path, options)
893
+ }
894
+
895
+ var fs$open = fs.open;
896
+ fs.open = open;
897
+ function open (path, flags, mode, cb) {
898
+ if (typeof mode === 'function')
899
+ cb = mode, mode = null;
900
+
901
+ return go$open(path, flags, mode, cb)
902
+
903
+ function go$open (path, flags, mode, cb, startTime) {
904
+ return fs$open(path, flags, mode, function (err, fd) {
905
+ if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
906
+ enqueue([go$open, [path, flags, mode, cb], err, startTime || Date.now(), Date.now()]);
907
+ else {
908
+ if (typeof cb === 'function')
909
+ cb.apply(this, arguments);
910
+ }
911
+ })
912
+ }
913
+ }
914
+
915
+ return fs
916
+ }
917
+
918
+ function enqueue (elem) {
919
+ debug('ENQUEUE', elem[0].name, elem[1]);
920
+ fs$g[gracefulQueue].push(elem);
921
+ retry();
922
+ }
923
+
924
+ // keep track of the timeout between retry() calls
925
+ var retryTimer;
926
+
927
+ // reset the startTime and lastTime to now
928
+ // this resets the start of the 60 second overall timeout as well as the
929
+ // delay between attempts so that we'll retry these jobs sooner
930
+ function resetQueue () {
931
+ var now = Date.now();
932
+ for (var i = 0; i < fs$g[gracefulQueue].length; ++i) {
933
+ // entries that are only a length of 2 are from an older version, don't
934
+ // bother modifying those since they'll be retried anyway.
935
+ if (fs$g[gracefulQueue][i].length > 2) {
936
+ fs$g[gracefulQueue][i][3] = now; // startTime
937
+ fs$g[gracefulQueue][i][4] = now; // lastTime
938
+ }
939
+ }
940
+ // call retry to make sure we're actively processing the queue
941
+ retry();
942
+ }
943
+
944
+ function retry () {
945
+ // clear the timer and remove it to help prevent unintended concurrency
946
+ clearTimeout(retryTimer);
947
+ retryTimer = undefined;
948
+
949
+ if (fs$g[gracefulQueue].length === 0)
950
+ return
951
+
952
+ var elem = fs$g[gracefulQueue].shift();
953
+ var fn = elem[0];
954
+ var args = elem[1];
955
+ // these items may be unset if they were added by an older graceful-fs
956
+ var err = elem[2];
957
+ var startTime = elem[3];
958
+ var lastTime = elem[4];
959
+
960
+ // if we don't have a startTime we have no way of knowing if we've waited
961
+ // long enough, so go ahead and retry this item now
962
+ if (startTime === undefined) {
963
+ debug('RETRY', fn.name, args);
964
+ fn.apply(null, args);
965
+ } else if (Date.now() - startTime >= 60000) {
966
+ // it's been more than 60 seconds total, bail now
967
+ debug('TIMEOUT', fn.name, args);
968
+ var cb = args.pop();
969
+ if (typeof cb === 'function')
970
+ cb.call(null, err);
971
+ } else {
972
+ // the amount of time between the last attempt and right now
973
+ var sinceAttempt = Date.now() - lastTime;
974
+ // the amount of time between when we first tried, and when we last tried
975
+ // rounded up to at least 1
976
+ var sinceStart = Math.max(lastTime - startTime, 1);
977
+ // backoff. wait longer than the total time we've been retrying, but only
978
+ // up to a maximum of 100ms
979
+ var desiredDelay = Math.min(sinceStart * 1.2, 100);
980
+ // it's been long enough since the last retry, do it again
981
+ if (sinceAttempt >= desiredDelay) {
982
+ debug('RETRY', fn.name, args);
983
+ fn.apply(null, args.concat([startTime]));
984
+ } else {
985
+ // if we can't do this job yet, push it to the end of the queue
986
+ // and let the next iteration check again
987
+ fs$g[gracefulQueue].push(elem);
988
+ }
989
+ }
990
+
991
+ // schedule our next run if one isn't already scheduled
992
+ if (retryTimer === undefined) {
993
+ retryTimer = setTimeout(retry, 0);
994
+ }
995
+ }
996
+
997
+ (function (exports$1) {
998
+ // This is adapted from https://github.com/normalize/mz
999
+ // Copyright (c) 2014-2016 Jonathan Ong me@jongleberry.com and Contributors
1000
+ const u = universalify$1.fromCallback;
1001
+ const fs = gracefulFs;
1002
+
1003
+ const api = [
1004
+ 'access',
1005
+ 'appendFile',
1006
+ 'chmod',
1007
+ 'chown',
1008
+ 'close',
1009
+ 'copyFile',
1010
+ 'fchmod',
1011
+ 'fchown',
1012
+ 'fdatasync',
1013
+ 'fstat',
1014
+ 'fsync',
1015
+ 'ftruncate',
1016
+ 'futimes',
1017
+ 'lchmod',
1018
+ 'lchown',
1019
+ 'link',
1020
+ 'lstat',
1021
+ 'mkdir',
1022
+ 'mkdtemp',
1023
+ 'open',
1024
+ 'opendir',
1025
+ 'readdir',
1026
+ 'readFile',
1027
+ 'readlink',
1028
+ 'realpath',
1029
+ 'rename',
1030
+ 'rm',
1031
+ 'rmdir',
1032
+ 'stat',
1033
+ 'symlink',
1034
+ 'truncate',
1035
+ 'unlink',
1036
+ 'utimes',
1037
+ 'writeFile'
1038
+ ].filter(key => {
1039
+ // Some commands are not available on some systems. Ex:
1040
+ // fs.cp was added in Node.js v16.7.0
1041
+ // fs.lchown is not available on at least some Linux
1042
+ return typeof fs[key] === 'function'
1043
+ });
1044
+
1045
+ // Export cloned fs:
1046
+ Object.assign(exports$1, fs);
1047
+
1048
+ // Universalify async methods:
1049
+ api.forEach(method => {
1050
+ exports$1[method] = u(fs[method]);
1051
+ });
1052
+
1053
+ // We differ from mz/fs in that we still ship the old, broken, fs.exists()
1054
+ // since we are a drop-in replacement for the native module
1055
+ exports$1.exists = function (filename, callback) {
1056
+ if (typeof callback === 'function') {
1057
+ return fs.exists(filename, callback)
1058
+ }
1059
+ return new Promise(resolve => {
1060
+ return fs.exists(filename, resolve)
1061
+ })
1062
+ };
1063
+
1064
+ // fs.read(), fs.write(), fs.readv(), & fs.writev() need special treatment due to multiple callback args
1065
+
1066
+ exports$1.read = function (fd, buffer, offset, length, position, callback) {
1067
+ if (typeof callback === 'function') {
1068
+ return fs.read(fd, buffer, offset, length, position, callback)
1069
+ }
1070
+ return new Promise((resolve, reject) => {
1071
+ fs.read(fd, buffer, offset, length, position, (err, bytesRead, buffer) => {
1072
+ if (err) return reject(err)
1073
+ resolve({ bytesRead, buffer });
1074
+ });
1075
+ })
1076
+ };
1077
+
1078
+ // Function signature can be
1079
+ // fs.write(fd, buffer[, offset[, length[, position]]], callback)
1080
+ // OR
1081
+ // fs.write(fd, string[, position[, encoding]], callback)
1082
+ // We need to handle both cases, so we use ...args
1083
+ exports$1.write = function (fd, buffer, ...args) {
1084
+ if (typeof args[args.length - 1] === 'function') {
1085
+ return fs.write(fd, buffer, ...args)
1086
+ }
1087
+
1088
+ return new Promise((resolve, reject) => {
1089
+ fs.write(fd, buffer, ...args, (err, bytesWritten, buffer) => {
1090
+ if (err) return reject(err)
1091
+ resolve({ bytesWritten, buffer });
1092
+ });
1093
+ })
1094
+ };
1095
+
1096
+ // Function signature is
1097
+ // s.readv(fd, buffers[, position], callback)
1098
+ // We need to handle the optional arg, so we use ...args
1099
+ exports$1.readv = function (fd, buffers, ...args) {
1100
+ if (typeof args[args.length - 1] === 'function') {
1101
+ return fs.readv(fd, buffers, ...args)
1102
+ }
1103
+
1104
+ return new Promise((resolve, reject) => {
1105
+ fs.readv(fd, buffers, ...args, (err, bytesRead, buffers) => {
1106
+ if (err) return reject(err)
1107
+ resolve({ bytesRead, buffers });
1108
+ });
1109
+ })
1110
+ };
1111
+
1112
+ // Function signature is
1113
+ // s.writev(fd, buffers[, position], callback)
1114
+ // We need to handle the optional arg, so we use ...args
1115
+ exports$1.writev = function (fd, buffers, ...args) {
1116
+ if (typeof args[args.length - 1] === 'function') {
1117
+ return fs.writev(fd, buffers, ...args)
1118
+ }
1119
+
1120
+ return new Promise((resolve, reject) => {
1121
+ fs.writev(fd, buffers, ...args, (err, bytesWritten, buffers) => {
1122
+ if (err) return reject(err)
1123
+ resolve({ bytesWritten, buffers });
1124
+ });
1125
+ })
1126
+ };
1127
+
1128
+ // fs.realpath.native sometimes not available if fs is monkey-patched
1129
+ if (typeof fs.realpath.native === 'function') {
1130
+ exports$1.realpath.native = u(fs.realpath.native);
1131
+ } else {
1132
+ process.emitWarning(
1133
+ 'fs.realpath.native is not a function. Is fs being monkey-patched?',
1134
+ 'Warning', 'fs-extra-WARN0003'
1135
+ );
1136
+ }
1137
+ } (fs$h));
1138
+
1139
+ var makeDir$1 = {};
1140
+
1141
+ var utils$1 = {};
1142
+
1143
+ const path$b = require$$1;
1144
+
1145
+ // https://github.com/nodejs/node/issues/8987
1146
+ // https://github.com/libuv/libuv/pull/1088
1147
+ utils$1.checkPath = function checkPath (pth) {
1148
+ if (process.platform === 'win32') {
1149
+ const pathHasInvalidWinCharacters = /[<>:"|?*]/.test(pth.replace(path$b.parse(pth).root, ''));
1150
+
1151
+ if (pathHasInvalidWinCharacters) {
1152
+ const error = new Error(`Path contains invalid characters: ${pth}`);
1153
+ error.code = 'EINVAL';
1154
+ throw error
1155
+ }
1156
+ }
1157
+ };
1158
+
1159
+ const fs$f = fs$h;
1160
+ const { checkPath } = utils$1;
1161
+
1162
+ const getMode = options => {
1163
+ const defaults = { mode: 0o777 };
1164
+ if (typeof options === 'number') return options
1165
+ return ({ ...defaults, ...options }).mode
1166
+ };
1167
+
1168
+ makeDir$1.makeDir = async (dir, options) => {
1169
+ checkPath(dir);
1170
+
1171
+ return fs$f.mkdir(dir, {
1172
+ mode: getMode(options),
1173
+ recursive: true
1174
+ })
1175
+ };
1176
+
1177
+ makeDir$1.makeDirSync = (dir, options) => {
1178
+ checkPath(dir);
1179
+
1180
+ return fs$f.mkdirSync(dir, {
1181
+ mode: getMode(options),
1182
+ recursive: true
1183
+ })
1184
+ };
1185
+
1186
+ const u$a = universalify$1.fromPromise;
1187
+ const { makeDir: _makeDir, makeDirSync } = makeDir$1;
1188
+ const makeDir = u$a(_makeDir);
1189
+
1190
+ var mkdirs$2 = {
1191
+ mkdirs: makeDir,
1192
+ mkdirsSync: makeDirSync,
1193
+ // alias
1194
+ mkdirp: makeDir,
1195
+ mkdirpSync: makeDirSync,
1196
+ ensureDir: makeDir,
1197
+ ensureDirSync: makeDirSync
1198
+ };
1199
+
1200
+ const u$9 = universalify$1.fromPromise;
1201
+ const fs$e = fs$h;
1202
+
1203
+ function pathExists$6 (path) {
1204
+ return fs$e.access(path).then(() => true).catch(() => false)
1205
+ }
1206
+
1207
+ var pathExists_1 = {
1208
+ pathExists: u$9(pathExists$6),
1209
+ pathExistsSync: fs$e.existsSync
1210
+ };
1211
+
1212
+ const fs$d = gracefulFs;
1213
+
1214
+ function utimesMillis$1 (path, atime, mtime, callback) {
1215
+ // if (!HAS_MILLIS_RES) return fs.utimes(path, atime, mtime, callback)
1216
+ fs$d.open(path, 'r+', (err, fd) => {
1217
+ if (err) return callback(err)
1218
+ fs$d.futimes(fd, atime, mtime, futimesErr => {
1219
+ fs$d.close(fd, closeErr => {
1220
+ if (callback) callback(futimesErr || closeErr);
1221
+ });
1222
+ });
1223
+ });
1224
+ }
1225
+
1226
+ function utimesMillisSync$1 (path, atime, mtime) {
1227
+ const fd = fs$d.openSync(path, 'r+');
1228
+ fs$d.futimesSync(fd, atime, mtime);
1229
+ return fs$d.closeSync(fd)
1230
+ }
1231
+
1232
+ var utimes = {
1233
+ utimesMillis: utimesMillis$1,
1234
+ utimesMillisSync: utimesMillisSync$1
1235
+ };
1236
+
1237
+ const fs$c = fs$h;
1238
+ const path$a = require$$1;
1239
+ const util = require$$4;
1240
+
1241
+ function getStats$2 (src, dest, opts) {
1242
+ const statFunc = opts.dereference
1243
+ ? (file) => fs$c.stat(file, { bigint: true })
1244
+ : (file) => fs$c.lstat(file, { bigint: true });
1245
+ return Promise.all([
1246
+ statFunc(src),
1247
+ statFunc(dest).catch(err => {
1248
+ if (err.code === 'ENOENT') return null
1249
+ throw err
1250
+ })
1251
+ ]).then(([srcStat, destStat]) => ({ srcStat, destStat }))
1252
+ }
1253
+
1254
+ function getStatsSync (src, dest, opts) {
1255
+ let destStat;
1256
+ const statFunc = opts.dereference
1257
+ ? (file) => fs$c.statSync(file, { bigint: true })
1258
+ : (file) => fs$c.lstatSync(file, { bigint: true });
1259
+ const srcStat = statFunc(src);
1260
+ try {
1261
+ destStat = statFunc(dest);
1262
+ } catch (err) {
1263
+ if (err.code === 'ENOENT') return { srcStat, destStat: null }
1264
+ throw err
1265
+ }
1266
+ return { srcStat, destStat }
1267
+ }
1268
+
1269
+ function checkPaths (src, dest, funcName, opts, cb) {
1270
+ util.callbackify(getStats$2)(src, dest, opts, (err, stats) => {
1271
+ if (err) return cb(err)
1272
+ const { srcStat, destStat } = stats;
1273
+
1274
+ if (destStat) {
1275
+ if (areIdentical$2(srcStat, destStat)) {
1276
+ const srcBaseName = path$a.basename(src);
1277
+ const destBaseName = path$a.basename(dest);
1278
+ if (funcName === 'move' &&
1279
+ srcBaseName !== destBaseName &&
1280
+ srcBaseName.toLowerCase() === destBaseName.toLowerCase()) {
1281
+ return cb(null, { srcStat, destStat, isChangingCase: true })
1282
+ }
1283
+ return cb(new Error('Source and destination must not be the same.'))
1284
+ }
1285
+ if (srcStat.isDirectory() && !destStat.isDirectory()) {
1286
+ return cb(new Error(`Cannot overwrite non-directory '${dest}' with directory '${src}'.`))
1287
+ }
1288
+ if (!srcStat.isDirectory() && destStat.isDirectory()) {
1289
+ return cb(new Error(`Cannot overwrite directory '${dest}' with non-directory '${src}'.`))
1290
+ }
1291
+ }
1292
+
1293
+ if (srcStat.isDirectory() && isSrcSubdir(src, dest)) {
1294
+ return cb(new Error(errMsg(src, dest, funcName)))
1295
+ }
1296
+ return cb(null, { srcStat, destStat })
1297
+ });
1298
+ }
1299
+
1300
+ function checkPathsSync (src, dest, funcName, opts) {
1301
+ const { srcStat, destStat } = getStatsSync(src, dest, opts);
1302
+
1303
+ if (destStat) {
1304
+ if (areIdentical$2(srcStat, destStat)) {
1305
+ const srcBaseName = path$a.basename(src);
1306
+ const destBaseName = path$a.basename(dest);
1307
+ if (funcName === 'move' &&
1308
+ srcBaseName !== destBaseName &&
1309
+ srcBaseName.toLowerCase() === destBaseName.toLowerCase()) {
1310
+ return { srcStat, destStat, isChangingCase: true }
1311
+ }
1312
+ throw new Error('Source and destination must not be the same.')
1313
+ }
1314
+ if (srcStat.isDirectory() && !destStat.isDirectory()) {
1315
+ throw new Error(`Cannot overwrite non-directory '${dest}' with directory '${src}'.`)
1316
+ }
1317
+ if (!srcStat.isDirectory() && destStat.isDirectory()) {
1318
+ throw new Error(`Cannot overwrite directory '${dest}' with non-directory '${src}'.`)
1319
+ }
1320
+ }
1321
+
1322
+ if (srcStat.isDirectory() && isSrcSubdir(src, dest)) {
1323
+ throw new Error(errMsg(src, dest, funcName))
1324
+ }
1325
+ return { srcStat, destStat }
1326
+ }
1327
+
1328
+ // recursively check if dest parent is a subdirectory of src.
1329
+ // It works for all file types including symlinks since it
1330
+ // checks the src and dest inodes. It starts from the deepest
1331
+ // parent and stops once it reaches the src parent or the root path.
1332
+ function checkParentPaths (src, srcStat, dest, funcName, cb) {
1333
+ const srcParent = path$a.resolve(path$a.dirname(src));
1334
+ const destParent = path$a.resolve(path$a.dirname(dest));
1335
+ if (destParent === srcParent || destParent === path$a.parse(destParent).root) return cb()
1336
+ fs$c.stat(destParent, { bigint: true }, (err, destStat) => {
1337
+ if (err) {
1338
+ if (err.code === 'ENOENT') return cb()
1339
+ return cb(err)
1340
+ }
1341
+ if (areIdentical$2(srcStat, destStat)) {
1342
+ return cb(new Error(errMsg(src, dest, funcName)))
1343
+ }
1344
+ return checkParentPaths(src, srcStat, destParent, funcName, cb)
1345
+ });
1346
+ }
1347
+
1348
+ function checkParentPathsSync (src, srcStat, dest, funcName) {
1349
+ const srcParent = path$a.resolve(path$a.dirname(src));
1350
+ const destParent = path$a.resolve(path$a.dirname(dest));
1351
+ if (destParent === srcParent || destParent === path$a.parse(destParent).root) return
1352
+ let destStat;
1353
+ try {
1354
+ destStat = fs$c.statSync(destParent, { bigint: true });
1355
+ } catch (err) {
1356
+ if (err.code === 'ENOENT') return
1357
+ throw err
1358
+ }
1359
+ if (areIdentical$2(srcStat, destStat)) {
1360
+ throw new Error(errMsg(src, dest, funcName))
1361
+ }
1362
+ return checkParentPathsSync(src, srcStat, destParent, funcName)
1363
+ }
1364
+
1365
+ function areIdentical$2 (srcStat, destStat) {
1366
+ return destStat.ino && destStat.dev && destStat.ino === srcStat.ino && destStat.dev === srcStat.dev
1367
+ }
1368
+
1369
+ // return true if dest is a subdir of src, otherwise false.
1370
+ // It only checks the path strings.
1371
+ function isSrcSubdir (src, dest) {
1372
+ const srcArr = path$a.resolve(src).split(path$a.sep).filter(i => i);
1373
+ const destArr = path$a.resolve(dest).split(path$a.sep).filter(i => i);
1374
+ return srcArr.reduce((acc, cur, i) => acc && destArr[i] === cur, true)
1375
+ }
1376
+
1377
+ function errMsg (src, dest, funcName) {
1378
+ return `Cannot ${funcName} '${src}' to a subdirectory of itself, '${dest}'.`
1379
+ }
1380
+
1381
+ var stat$4 = {
1382
+ checkPaths,
1383
+ checkPathsSync,
1384
+ checkParentPaths,
1385
+ checkParentPathsSync,
1386
+ isSrcSubdir,
1387
+ areIdentical: areIdentical$2
1388
+ };
1389
+
1390
+ const fs$b = gracefulFs;
1391
+ const path$9 = require$$1;
1392
+ const mkdirs$1 = mkdirs$2.mkdirs;
1393
+ const pathExists$5 = pathExists_1.pathExists;
1394
+ const utimesMillis = utimes.utimesMillis;
1395
+ const stat$3 = stat$4;
1396
+
1397
+ function copy$2 (src, dest, opts, cb) {
1398
+ if (typeof opts === 'function' && !cb) {
1399
+ cb = opts;
1400
+ opts = {};
1401
+ } else if (typeof opts === 'function') {
1402
+ opts = { filter: opts };
1403
+ }
1404
+
1405
+ cb = cb || function () {};
1406
+ opts = opts || {};
1407
+
1408
+ opts.clobber = 'clobber' in opts ? !!opts.clobber : true; // default to true for now
1409
+ opts.overwrite = 'overwrite' in opts ? !!opts.overwrite : opts.clobber; // overwrite falls back to clobber
1410
+
1411
+ // Warn about using preserveTimestamps on 32-bit node
1412
+ if (opts.preserveTimestamps && process.arch === 'ia32') {
1413
+ process.emitWarning(
1414
+ 'Using the preserveTimestamps option in 32-bit node is not recommended;\n\n' +
1415
+ '\tsee https://github.com/jprichardson/node-fs-extra/issues/269',
1416
+ 'Warning', 'fs-extra-WARN0001'
1417
+ );
1418
+ }
1419
+
1420
+ stat$3.checkPaths(src, dest, 'copy', opts, (err, stats) => {
1421
+ if (err) return cb(err)
1422
+ const { srcStat, destStat } = stats;
1423
+ stat$3.checkParentPaths(src, srcStat, dest, 'copy', err => {
1424
+ if (err) return cb(err)
1425
+ runFilter(src, dest, opts, (err, include) => {
1426
+ if (err) return cb(err)
1427
+ if (!include) return cb()
1428
+
1429
+ checkParentDir(destStat, src, dest, opts, cb);
1430
+ });
1431
+ });
1432
+ });
1433
+ }
1434
+
1435
+ function checkParentDir (destStat, src, dest, opts, cb) {
1436
+ const destParent = path$9.dirname(dest);
1437
+ pathExists$5(destParent, (err, dirExists) => {
1438
+ if (err) return cb(err)
1439
+ if (dirExists) return getStats$1(destStat, src, dest, opts, cb)
1440
+ mkdirs$1(destParent, err => {
1441
+ if (err) return cb(err)
1442
+ return getStats$1(destStat, src, dest, opts, cb)
1443
+ });
1444
+ });
1445
+ }
1446
+
1447
+ function runFilter (src, dest, opts, cb) {
1448
+ if (!opts.filter) return cb(null, true)
1449
+ Promise.resolve(opts.filter(src, dest))
1450
+ .then(include => cb(null, include), error => cb(error));
1451
+ }
1452
+
1453
+ function getStats$1 (destStat, src, dest, opts, cb) {
1454
+ const stat = opts.dereference ? fs$b.stat : fs$b.lstat;
1455
+ stat(src, (err, srcStat) => {
1456
+ if (err) return cb(err)
1457
+
1458
+ if (srcStat.isDirectory()) return onDir$1(srcStat, destStat, src, dest, opts, cb)
1459
+ else if (srcStat.isFile() ||
1460
+ srcStat.isCharacterDevice() ||
1461
+ srcStat.isBlockDevice()) return onFile$1(srcStat, destStat, src, dest, opts, cb)
1462
+ else if (srcStat.isSymbolicLink()) return onLink$1(destStat, src, dest, opts, cb)
1463
+ else if (srcStat.isSocket()) return cb(new Error(`Cannot copy a socket file: ${src}`))
1464
+ else if (srcStat.isFIFO()) return cb(new Error(`Cannot copy a FIFO pipe: ${src}`))
1465
+ return cb(new Error(`Unknown file: ${src}`))
1466
+ });
1467
+ }
1468
+
1469
+ function onFile$1 (srcStat, destStat, src, dest, opts, cb) {
1470
+ if (!destStat) return copyFile$1(srcStat, src, dest, opts, cb)
1471
+ return mayCopyFile$1(srcStat, src, dest, opts, cb)
1472
+ }
1473
+
1474
+ function mayCopyFile$1 (srcStat, src, dest, opts, cb) {
1475
+ if (opts.overwrite) {
1476
+ fs$b.unlink(dest, err => {
1477
+ if (err) return cb(err)
1478
+ return copyFile$1(srcStat, src, dest, opts, cb)
1479
+ });
1480
+ } else if (opts.errorOnExist) {
1481
+ return cb(new Error(`'${dest}' already exists`))
1482
+ } else return cb()
1483
+ }
1484
+
1485
+ function copyFile$1 (srcStat, src, dest, opts, cb) {
1486
+ fs$b.copyFile(src, dest, err => {
1487
+ if (err) return cb(err)
1488
+ if (opts.preserveTimestamps) return handleTimestampsAndMode(srcStat.mode, src, dest, cb)
1489
+ return setDestMode$1(dest, srcStat.mode, cb)
1490
+ });
1491
+ }
1492
+
1493
+ function handleTimestampsAndMode (srcMode, src, dest, cb) {
1494
+ // Make sure the file is writable before setting the timestamp
1495
+ // otherwise open fails with EPERM when invoked with 'r+'
1496
+ // (through utimes call)
1497
+ if (fileIsNotWritable$1(srcMode)) {
1498
+ return makeFileWritable$1(dest, srcMode, err => {
1499
+ if (err) return cb(err)
1500
+ return setDestTimestampsAndMode(srcMode, src, dest, cb)
1501
+ })
1502
+ }
1503
+ return setDestTimestampsAndMode(srcMode, src, dest, cb)
1504
+ }
1505
+
1506
+ function fileIsNotWritable$1 (srcMode) {
1507
+ return (srcMode & 0o200) === 0
1508
+ }
1509
+
1510
+ function makeFileWritable$1 (dest, srcMode, cb) {
1511
+ return setDestMode$1(dest, srcMode | 0o200, cb)
1512
+ }
1513
+
1514
+ function setDestTimestampsAndMode (srcMode, src, dest, cb) {
1515
+ setDestTimestamps$1(src, dest, err => {
1516
+ if (err) return cb(err)
1517
+ return setDestMode$1(dest, srcMode, cb)
1518
+ });
1519
+ }
1520
+
1521
+ function setDestMode$1 (dest, srcMode, cb) {
1522
+ return fs$b.chmod(dest, srcMode, cb)
1523
+ }
1524
+
1525
+ function setDestTimestamps$1 (src, dest, cb) {
1526
+ // The initial srcStat.atime cannot be trusted
1527
+ // because it is modified by the read(2) system call
1528
+ // (See https://nodejs.org/api/fs.html#fs_stat_time_values)
1529
+ fs$b.stat(src, (err, updatedSrcStat) => {
1530
+ if (err) return cb(err)
1531
+ return utimesMillis(dest, updatedSrcStat.atime, updatedSrcStat.mtime, cb)
1532
+ });
1533
+ }
1534
+
1535
+ function onDir$1 (srcStat, destStat, src, dest, opts, cb) {
1536
+ if (!destStat) return mkDirAndCopy$1(srcStat.mode, src, dest, opts, cb)
1537
+ return copyDir$1(src, dest, opts, cb)
1538
+ }
1539
+
1540
+ function mkDirAndCopy$1 (srcMode, src, dest, opts, cb) {
1541
+ fs$b.mkdir(dest, err => {
1542
+ if (err) return cb(err)
1543
+ copyDir$1(src, dest, opts, err => {
1544
+ if (err) return cb(err)
1545
+ return setDestMode$1(dest, srcMode, cb)
1546
+ });
1547
+ });
1548
+ }
1549
+
1550
+ function copyDir$1 (src, dest, opts, cb) {
1551
+ fs$b.readdir(src, (err, items) => {
1552
+ if (err) return cb(err)
1553
+ return copyDirItems(items, src, dest, opts, cb)
1554
+ });
1555
+ }
1556
+
1557
+ function copyDirItems (items, src, dest, opts, cb) {
1558
+ const item = items.pop();
1559
+ if (!item) return cb()
1560
+ return copyDirItem$1(items, item, src, dest, opts, cb)
1561
+ }
1562
+
1563
+ function copyDirItem$1 (items, item, src, dest, opts, cb) {
1564
+ const srcItem = path$9.join(src, item);
1565
+ const destItem = path$9.join(dest, item);
1566
+ runFilter(srcItem, destItem, opts, (err, include) => {
1567
+ if (err) return cb(err)
1568
+ if (!include) return copyDirItems(items, src, dest, opts, cb)
1569
+
1570
+ stat$3.checkPaths(srcItem, destItem, 'copy', opts, (err, stats) => {
1571
+ if (err) return cb(err)
1572
+ const { destStat } = stats;
1573
+ getStats$1(destStat, srcItem, destItem, opts, err => {
1574
+ if (err) return cb(err)
1575
+ return copyDirItems(items, src, dest, opts, cb)
1576
+ });
1577
+ });
1578
+ });
1579
+ }
1580
+
1581
+ function onLink$1 (destStat, src, dest, opts, cb) {
1582
+ fs$b.readlink(src, (err, resolvedSrc) => {
1583
+ if (err) return cb(err)
1584
+ if (opts.dereference) {
1585
+ resolvedSrc = path$9.resolve(process.cwd(), resolvedSrc);
1586
+ }
1587
+
1588
+ if (!destStat) {
1589
+ return fs$b.symlink(resolvedSrc, dest, cb)
1590
+ } else {
1591
+ fs$b.readlink(dest, (err, resolvedDest) => {
1592
+ if (err) {
1593
+ // dest exists and is a regular file or directory,
1594
+ // Windows may throw UNKNOWN error. If dest already exists,
1595
+ // fs throws error anyway, so no need to guard against it here.
1596
+ if (err.code === 'EINVAL' || err.code === 'UNKNOWN') return fs$b.symlink(resolvedSrc, dest, cb)
1597
+ return cb(err)
1598
+ }
1599
+ if (opts.dereference) {
1600
+ resolvedDest = path$9.resolve(process.cwd(), resolvedDest);
1601
+ }
1602
+ if (stat$3.isSrcSubdir(resolvedSrc, resolvedDest)) {
1603
+ return cb(new Error(`Cannot copy '${resolvedSrc}' to a subdirectory of itself, '${resolvedDest}'.`))
1604
+ }
1605
+
1606
+ // do not copy if src is a subdir of dest since unlinking
1607
+ // dest in this case would result in removing src contents
1608
+ // and therefore a broken symlink would be created.
1609
+ if (stat$3.isSrcSubdir(resolvedDest, resolvedSrc)) {
1610
+ return cb(new Error(`Cannot overwrite '${resolvedDest}' with '${resolvedSrc}'.`))
1611
+ }
1612
+ return copyLink$1(resolvedSrc, dest, cb)
1613
+ });
1614
+ }
1615
+ });
1616
+ }
1617
+
1618
+ function copyLink$1 (resolvedSrc, dest, cb) {
1619
+ fs$b.unlink(dest, err => {
1620
+ if (err) return cb(err)
1621
+ return fs$b.symlink(resolvedSrc, dest, cb)
1622
+ });
1623
+ }
1624
+
1625
+ var copy_1 = copy$2;
1626
+
1627
+ const fs$a = gracefulFs;
1628
+ const path$8 = require$$1;
1629
+ const mkdirsSync$1 = mkdirs$2.mkdirsSync;
1630
+ const utimesMillisSync = utimes.utimesMillisSync;
1631
+ const stat$2 = stat$4;
1632
+
1633
+ function copySync$1 (src, dest, opts) {
1634
+ if (typeof opts === 'function') {
1635
+ opts = { filter: opts };
1636
+ }
1637
+
1638
+ opts = opts || {};
1639
+ opts.clobber = 'clobber' in opts ? !!opts.clobber : true; // default to true for now
1640
+ opts.overwrite = 'overwrite' in opts ? !!opts.overwrite : opts.clobber; // overwrite falls back to clobber
1641
+
1642
+ // Warn about using preserveTimestamps on 32-bit node
1643
+ if (opts.preserveTimestamps && process.arch === 'ia32') {
1644
+ process.emitWarning(
1645
+ 'Using the preserveTimestamps option in 32-bit node is not recommended;\n\n' +
1646
+ '\tsee https://github.com/jprichardson/node-fs-extra/issues/269',
1647
+ 'Warning', 'fs-extra-WARN0002'
1648
+ );
1649
+ }
1650
+
1651
+ const { srcStat, destStat } = stat$2.checkPathsSync(src, dest, 'copy', opts);
1652
+ stat$2.checkParentPathsSync(src, srcStat, dest, 'copy');
1653
+ if (opts.filter && !opts.filter(src, dest)) return
1654
+ const destParent = path$8.dirname(dest);
1655
+ if (!fs$a.existsSync(destParent)) mkdirsSync$1(destParent);
1656
+ return getStats(destStat, src, dest, opts)
1657
+ }
1658
+
1659
+ function getStats (destStat, src, dest, opts) {
1660
+ const statSync = opts.dereference ? fs$a.statSync : fs$a.lstatSync;
1661
+ const srcStat = statSync(src);
1662
+
1663
+ if (srcStat.isDirectory()) return onDir(srcStat, destStat, src, dest, opts)
1664
+ else if (srcStat.isFile() ||
1665
+ srcStat.isCharacterDevice() ||
1666
+ srcStat.isBlockDevice()) return onFile(srcStat, destStat, src, dest, opts)
1667
+ else if (srcStat.isSymbolicLink()) return onLink(destStat, src, dest, opts)
1668
+ else if (srcStat.isSocket()) throw new Error(`Cannot copy a socket file: ${src}`)
1669
+ else if (srcStat.isFIFO()) throw new Error(`Cannot copy a FIFO pipe: ${src}`)
1670
+ throw new Error(`Unknown file: ${src}`)
1671
+ }
1672
+
1673
+ function onFile (srcStat, destStat, src, dest, opts) {
1674
+ if (!destStat) return copyFile(srcStat, src, dest, opts)
1675
+ return mayCopyFile(srcStat, src, dest, opts)
1676
+ }
1677
+
1678
+ function mayCopyFile (srcStat, src, dest, opts) {
1679
+ if (opts.overwrite) {
1680
+ fs$a.unlinkSync(dest);
1681
+ return copyFile(srcStat, src, dest, opts)
1682
+ } else if (opts.errorOnExist) {
1683
+ throw new Error(`'${dest}' already exists`)
1684
+ }
1685
+ }
1686
+
1687
+ function copyFile (srcStat, src, dest, opts) {
1688
+ fs$a.copyFileSync(src, dest);
1689
+ if (opts.preserveTimestamps) handleTimestamps(srcStat.mode, src, dest);
1690
+ return setDestMode(dest, srcStat.mode)
1691
+ }
1692
+
1693
+ function handleTimestamps (srcMode, src, dest) {
1694
+ // Make sure the file is writable before setting the timestamp
1695
+ // otherwise open fails with EPERM when invoked with 'r+'
1696
+ // (through utimes call)
1697
+ if (fileIsNotWritable(srcMode)) makeFileWritable(dest, srcMode);
1698
+ return setDestTimestamps(src, dest)
1699
+ }
1700
+
1701
+ function fileIsNotWritable (srcMode) {
1702
+ return (srcMode & 0o200) === 0
1703
+ }
1704
+
1705
+ function makeFileWritable (dest, srcMode) {
1706
+ return setDestMode(dest, srcMode | 0o200)
1707
+ }
1708
+
1709
+ function setDestMode (dest, srcMode) {
1710
+ return fs$a.chmodSync(dest, srcMode)
1711
+ }
1712
+
1713
+ function setDestTimestamps (src, dest) {
1714
+ // The initial srcStat.atime cannot be trusted
1715
+ // because it is modified by the read(2) system call
1716
+ // (See https://nodejs.org/api/fs.html#fs_stat_time_values)
1717
+ const updatedSrcStat = fs$a.statSync(src);
1718
+ return utimesMillisSync(dest, updatedSrcStat.atime, updatedSrcStat.mtime)
1719
+ }
1720
+
1721
+ function onDir (srcStat, destStat, src, dest, opts) {
1722
+ if (!destStat) return mkDirAndCopy(srcStat.mode, src, dest, opts)
1723
+ return copyDir(src, dest, opts)
1724
+ }
1725
+
1726
+ function mkDirAndCopy (srcMode, src, dest, opts) {
1727
+ fs$a.mkdirSync(dest);
1728
+ copyDir(src, dest, opts);
1729
+ return setDestMode(dest, srcMode)
1730
+ }
1731
+
1732
+ function copyDir (src, dest, opts) {
1733
+ fs$a.readdirSync(src).forEach(item => copyDirItem(item, src, dest, opts));
1734
+ }
1735
+
1736
+ function copyDirItem (item, src, dest, opts) {
1737
+ const srcItem = path$8.join(src, item);
1738
+ const destItem = path$8.join(dest, item);
1739
+ if (opts.filter && !opts.filter(srcItem, destItem)) return
1740
+ const { destStat } = stat$2.checkPathsSync(srcItem, destItem, 'copy', opts);
1741
+ return getStats(destStat, srcItem, destItem, opts)
1742
+ }
1743
+
1744
+ function onLink (destStat, src, dest, opts) {
1745
+ let resolvedSrc = fs$a.readlinkSync(src);
1746
+ if (opts.dereference) {
1747
+ resolvedSrc = path$8.resolve(process.cwd(), resolvedSrc);
1748
+ }
1749
+
1750
+ if (!destStat) {
1751
+ return fs$a.symlinkSync(resolvedSrc, dest)
1752
+ } else {
1753
+ let resolvedDest;
1754
+ try {
1755
+ resolvedDest = fs$a.readlinkSync(dest);
1756
+ } catch (err) {
1757
+ // dest exists and is a regular file or directory,
1758
+ // Windows may throw UNKNOWN error. If dest already exists,
1759
+ // fs throws error anyway, so no need to guard against it here.
1760
+ if (err.code === 'EINVAL' || err.code === 'UNKNOWN') return fs$a.symlinkSync(resolvedSrc, dest)
1761
+ throw err
1762
+ }
1763
+ if (opts.dereference) {
1764
+ resolvedDest = path$8.resolve(process.cwd(), resolvedDest);
1765
+ }
1766
+ if (stat$2.isSrcSubdir(resolvedSrc, resolvedDest)) {
1767
+ throw new Error(`Cannot copy '${resolvedSrc}' to a subdirectory of itself, '${resolvedDest}'.`)
1768
+ }
1769
+
1770
+ // prevent copy if src is a subdir of dest since unlinking
1771
+ // dest in this case would result in removing src contents
1772
+ // and therefore a broken symlink would be created.
1773
+ if (stat$2.isSrcSubdir(resolvedDest, resolvedSrc)) {
1774
+ throw new Error(`Cannot overwrite '${resolvedDest}' with '${resolvedSrc}'.`)
1775
+ }
1776
+ return copyLink(resolvedSrc, dest)
1777
+ }
1778
+ }
1779
+
1780
+ function copyLink (resolvedSrc, dest) {
1781
+ fs$a.unlinkSync(dest);
1782
+ return fs$a.symlinkSync(resolvedSrc, dest)
1783
+ }
1784
+
1785
+ var copySync_1 = copySync$1;
1786
+
1787
+ const u$8 = universalify$1.fromCallback;
1788
+ var copy$1 = {
1789
+ copy: u$8(copy_1),
1790
+ copySync: copySync_1
1791
+ };
1792
+
1793
+ const fs$9 = gracefulFs;
1794
+ const u$7 = universalify$1.fromCallback;
1795
+
1796
+ function remove$2 (path, callback) {
1797
+ fs$9.rm(path, { recursive: true, force: true }, callback);
1798
+ }
1799
+
1800
+ function removeSync$1 (path) {
1801
+ fs$9.rmSync(path, { recursive: true, force: true });
1802
+ }
1803
+
1804
+ var remove_1 = {
1805
+ remove: u$7(remove$2),
1806
+ removeSync: removeSync$1
1807
+ };
1808
+
1809
+ const u$6 = universalify$1.fromPromise;
1810
+ const fs$8 = fs$h;
1811
+ const path$7 = require$$1;
1812
+ const mkdir$3 = mkdirs$2;
1813
+ const remove$1 = remove_1;
1814
+
1815
+ const emptyDir = u$6(async function emptyDir (dir) {
1816
+ let items;
1817
+ try {
1818
+ items = await fs$8.readdir(dir);
1819
+ } catch {
1820
+ return mkdir$3.mkdirs(dir)
1821
+ }
1822
+
1823
+ return Promise.all(items.map(item => remove$1.remove(path$7.join(dir, item))))
1824
+ });
1825
+
1826
+ function emptyDirSync (dir) {
1827
+ let items;
1828
+ try {
1829
+ items = fs$8.readdirSync(dir);
1830
+ } catch {
1831
+ return mkdir$3.mkdirsSync(dir)
1832
+ }
1833
+
1834
+ items.forEach(item => {
1835
+ item = path$7.join(dir, item);
1836
+ remove$1.removeSync(item);
1837
+ });
1838
+ }
1839
+
1840
+ var empty = {
1841
+ emptyDirSync,
1842
+ emptydirSync: emptyDirSync,
1843
+ emptyDir,
1844
+ emptydir: emptyDir
1845
+ };
1846
+
1847
+ const u$5 = universalify$1.fromCallback;
1848
+ const path$6 = require$$1;
1849
+ const fs$7 = gracefulFs;
1850
+ const mkdir$2 = mkdirs$2;
1851
+
1852
+ function createFile$1 (file, callback) {
1853
+ function makeFile () {
1854
+ fs$7.writeFile(file, '', err => {
1855
+ if (err) return callback(err)
1856
+ callback();
1857
+ });
1858
+ }
1859
+
1860
+ fs$7.stat(file, (err, stats) => { // eslint-disable-line handle-callback-err
1861
+ if (!err && stats.isFile()) return callback()
1862
+ const dir = path$6.dirname(file);
1863
+ fs$7.stat(dir, (err, stats) => {
1864
+ if (err) {
1865
+ // if the directory doesn't exist, make it
1866
+ if (err.code === 'ENOENT') {
1867
+ return mkdir$2.mkdirs(dir, err => {
1868
+ if (err) return callback(err)
1869
+ makeFile();
1870
+ })
1871
+ }
1872
+ return callback(err)
1873
+ }
1874
+
1875
+ if (stats.isDirectory()) makeFile();
1876
+ else {
1877
+ // parent is not a directory
1878
+ // This is just to cause an internal ENOTDIR error to be thrown
1879
+ fs$7.readdir(dir, err => {
1880
+ if (err) return callback(err)
1881
+ });
1882
+ }
1883
+ });
1884
+ });
1885
+ }
1886
+
1887
+ function createFileSync$1 (file) {
1888
+ let stats;
1889
+ try {
1890
+ stats = fs$7.statSync(file);
1891
+ } catch {}
1892
+ if (stats && stats.isFile()) return
1893
+
1894
+ const dir = path$6.dirname(file);
1895
+ try {
1896
+ if (!fs$7.statSync(dir).isDirectory()) {
1897
+ // parent is not a directory
1898
+ // This is just to cause an internal ENOTDIR error to be thrown
1899
+ fs$7.readdirSync(dir);
1900
+ }
1901
+ } catch (err) {
1902
+ // If the stat call above failed because the directory doesn't exist, create it
1903
+ if (err && err.code === 'ENOENT') mkdir$2.mkdirsSync(dir);
1904
+ else throw err
1905
+ }
1906
+
1907
+ fs$7.writeFileSync(file, '');
1908
+ }
1909
+
1910
+ var file = {
1911
+ createFile: u$5(createFile$1),
1912
+ createFileSync: createFileSync$1
1913
+ };
1914
+
1915
+ const u$4 = universalify$1.fromCallback;
1916
+ const path$5 = require$$1;
1917
+ const fs$6 = gracefulFs;
1918
+ const mkdir$1 = mkdirs$2;
1919
+ const pathExists$4 = pathExists_1.pathExists;
1920
+ const { areIdentical: areIdentical$1 } = stat$4;
1921
+
1922
+ function createLink$1 (srcpath, dstpath, callback) {
1923
+ function makeLink (srcpath, dstpath) {
1924
+ fs$6.link(srcpath, dstpath, err => {
1925
+ if (err) return callback(err)
1926
+ callback(null);
1927
+ });
1928
+ }
1929
+
1930
+ fs$6.lstat(dstpath, (_, dstStat) => {
1931
+ fs$6.lstat(srcpath, (err, srcStat) => {
1932
+ if (err) {
1933
+ err.message = err.message.replace('lstat', 'ensureLink');
1934
+ return callback(err)
1935
+ }
1936
+ if (dstStat && areIdentical$1(srcStat, dstStat)) return callback(null)
1937
+
1938
+ const dir = path$5.dirname(dstpath);
1939
+ pathExists$4(dir, (err, dirExists) => {
1940
+ if (err) return callback(err)
1941
+ if (dirExists) return makeLink(srcpath, dstpath)
1942
+ mkdir$1.mkdirs(dir, err => {
1943
+ if (err) return callback(err)
1944
+ makeLink(srcpath, dstpath);
1945
+ });
1946
+ });
1947
+ });
1948
+ });
1949
+ }
1950
+
1951
+ function createLinkSync$1 (srcpath, dstpath) {
1952
+ let dstStat;
1953
+ try {
1954
+ dstStat = fs$6.lstatSync(dstpath);
1955
+ } catch {}
1956
+
1957
+ try {
1958
+ const srcStat = fs$6.lstatSync(srcpath);
1959
+ if (dstStat && areIdentical$1(srcStat, dstStat)) return
1960
+ } catch (err) {
1961
+ err.message = err.message.replace('lstat', 'ensureLink');
1962
+ throw err
1963
+ }
1964
+
1965
+ const dir = path$5.dirname(dstpath);
1966
+ const dirExists = fs$6.existsSync(dir);
1967
+ if (dirExists) return fs$6.linkSync(srcpath, dstpath)
1968
+ mkdir$1.mkdirsSync(dir);
1969
+
1970
+ return fs$6.linkSync(srcpath, dstpath)
1971
+ }
1972
+
1973
+ var link = {
1974
+ createLink: u$4(createLink$1),
1975
+ createLinkSync: createLinkSync$1
1976
+ };
1977
+
1978
+ const path$4 = require$$1;
1979
+ const fs$5 = gracefulFs;
1980
+ const pathExists$3 = pathExists_1.pathExists;
1981
+
1982
+ /**
1983
+ * Function that returns two types of paths, one relative to symlink, and one
1984
+ * relative to the current working directory. Checks if path is absolute or
1985
+ * relative. If the path is relative, this function checks if the path is
1986
+ * relative to symlink or relative to current working directory. This is an
1987
+ * initiative to find a smarter `srcpath` to supply when building symlinks.
1988
+ * This allows you to determine which path to use out of one of three possible
1989
+ * types of source paths. The first is an absolute path. This is detected by
1990
+ * `path.isAbsolute()`. When an absolute path is provided, it is checked to
1991
+ * see if it exists. If it does it's used, if not an error is returned
1992
+ * (callback)/ thrown (sync). The other two options for `srcpath` are a
1993
+ * relative url. By default Node's `fs.symlink` works by creating a symlink
1994
+ * using `dstpath` and expects the `srcpath` to be relative to the newly
1995
+ * created symlink. If you provide a `srcpath` that does not exist on the file
1996
+ * system it results in a broken symlink. To minimize this, the function
1997
+ * checks to see if the 'relative to symlink' source file exists, and if it
1998
+ * does it will use it. If it does not, it checks if there's a file that
1999
+ * exists that is relative to the current working directory, if does its used.
2000
+ * This preserves the expectations of the original fs.symlink spec and adds
2001
+ * the ability to pass in `relative to current working direcotry` paths.
2002
+ */
2003
+
2004
+ function symlinkPaths$1 (srcpath, dstpath, callback) {
2005
+ if (path$4.isAbsolute(srcpath)) {
2006
+ return fs$5.lstat(srcpath, (err) => {
2007
+ if (err) {
2008
+ err.message = err.message.replace('lstat', 'ensureSymlink');
2009
+ return callback(err)
2010
+ }
2011
+ return callback(null, {
2012
+ toCwd: srcpath,
2013
+ toDst: srcpath
2014
+ })
2015
+ })
2016
+ } else {
2017
+ const dstdir = path$4.dirname(dstpath);
2018
+ const relativeToDst = path$4.join(dstdir, srcpath);
2019
+ return pathExists$3(relativeToDst, (err, exists) => {
2020
+ if (err) return callback(err)
2021
+ if (exists) {
2022
+ return callback(null, {
2023
+ toCwd: relativeToDst,
2024
+ toDst: srcpath
2025
+ })
2026
+ } else {
2027
+ return fs$5.lstat(srcpath, (err) => {
2028
+ if (err) {
2029
+ err.message = err.message.replace('lstat', 'ensureSymlink');
2030
+ return callback(err)
2031
+ }
2032
+ return callback(null, {
2033
+ toCwd: srcpath,
2034
+ toDst: path$4.relative(dstdir, srcpath)
2035
+ })
2036
+ })
2037
+ }
2038
+ })
2039
+ }
2040
+ }
2041
+
2042
+ function symlinkPathsSync$1 (srcpath, dstpath) {
2043
+ let exists;
2044
+ if (path$4.isAbsolute(srcpath)) {
2045
+ exists = fs$5.existsSync(srcpath);
2046
+ if (!exists) throw new Error('absolute srcpath does not exist')
2047
+ return {
2048
+ toCwd: srcpath,
2049
+ toDst: srcpath
2050
+ }
2051
+ } else {
2052
+ const dstdir = path$4.dirname(dstpath);
2053
+ const relativeToDst = path$4.join(dstdir, srcpath);
2054
+ exists = fs$5.existsSync(relativeToDst);
2055
+ if (exists) {
2056
+ return {
2057
+ toCwd: relativeToDst,
2058
+ toDst: srcpath
2059
+ }
2060
+ } else {
2061
+ exists = fs$5.existsSync(srcpath);
2062
+ if (!exists) throw new Error('relative srcpath does not exist')
2063
+ return {
2064
+ toCwd: srcpath,
2065
+ toDst: path$4.relative(dstdir, srcpath)
2066
+ }
2067
+ }
2068
+ }
2069
+ }
2070
+
2071
+ var symlinkPaths_1 = {
2072
+ symlinkPaths: symlinkPaths$1,
2073
+ symlinkPathsSync: symlinkPathsSync$1
2074
+ };
2075
+
2076
+ const fs$4 = gracefulFs;
2077
+
2078
+ function symlinkType$1 (srcpath, type, callback) {
2079
+ callback = (typeof type === 'function') ? type : callback;
2080
+ type = (typeof type === 'function') ? false : type;
2081
+ if (type) return callback(null, type)
2082
+ fs$4.lstat(srcpath, (err, stats) => {
2083
+ if (err) return callback(null, 'file')
2084
+ type = (stats && stats.isDirectory()) ? 'dir' : 'file';
2085
+ callback(null, type);
2086
+ });
2087
+ }
2088
+
2089
+ function symlinkTypeSync$1 (srcpath, type) {
2090
+ let stats;
2091
+
2092
+ if (type) return type
2093
+ try {
2094
+ stats = fs$4.lstatSync(srcpath);
2095
+ } catch {
2096
+ return 'file'
2097
+ }
2098
+ return (stats && stats.isDirectory()) ? 'dir' : 'file'
2099
+ }
2100
+
2101
+ var symlinkType_1 = {
2102
+ symlinkType: symlinkType$1,
2103
+ symlinkTypeSync: symlinkTypeSync$1
2104
+ };
2105
+
2106
+ const u$3 = universalify$1.fromCallback;
2107
+ const path$3 = require$$1;
2108
+ const fs$3 = fs$h;
2109
+ const _mkdirs = mkdirs$2;
2110
+ const mkdirs = _mkdirs.mkdirs;
2111
+ const mkdirsSync = _mkdirs.mkdirsSync;
2112
+
2113
+ const _symlinkPaths = symlinkPaths_1;
2114
+ const symlinkPaths = _symlinkPaths.symlinkPaths;
2115
+ const symlinkPathsSync = _symlinkPaths.symlinkPathsSync;
2116
+
2117
+ const _symlinkType = symlinkType_1;
2118
+ const symlinkType = _symlinkType.symlinkType;
2119
+ const symlinkTypeSync = _symlinkType.symlinkTypeSync;
2120
+
2121
+ const pathExists$2 = pathExists_1.pathExists;
2122
+
2123
+ const { areIdentical } = stat$4;
2124
+
2125
+ function createSymlink$1 (srcpath, dstpath, type, callback) {
2126
+ callback = (typeof type === 'function') ? type : callback;
2127
+ type = (typeof type === 'function') ? false : type;
2128
+
2129
+ fs$3.lstat(dstpath, (err, stats) => {
2130
+ if (!err && stats.isSymbolicLink()) {
2131
+ Promise.all([
2132
+ fs$3.stat(srcpath),
2133
+ fs$3.stat(dstpath)
2134
+ ]).then(([srcStat, dstStat]) => {
2135
+ if (areIdentical(srcStat, dstStat)) return callback(null)
2136
+ _createSymlink(srcpath, dstpath, type, callback);
2137
+ });
2138
+ } else _createSymlink(srcpath, dstpath, type, callback);
2139
+ });
2140
+ }
2141
+
2142
+ function _createSymlink (srcpath, dstpath, type, callback) {
2143
+ symlinkPaths(srcpath, dstpath, (err, relative) => {
2144
+ if (err) return callback(err)
2145
+ srcpath = relative.toDst;
2146
+ symlinkType(relative.toCwd, type, (err, type) => {
2147
+ if (err) return callback(err)
2148
+ const dir = path$3.dirname(dstpath);
2149
+ pathExists$2(dir, (err, dirExists) => {
2150
+ if (err) return callback(err)
2151
+ if (dirExists) return fs$3.symlink(srcpath, dstpath, type, callback)
2152
+ mkdirs(dir, err => {
2153
+ if (err) return callback(err)
2154
+ fs$3.symlink(srcpath, dstpath, type, callback);
2155
+ });
2156
+ });
2157
+ });
2158
+ });
2159
+ }
2160
+
2161
+ function createSymlinkSync$1 (srcpath, dstpath, type) {
2162
+ let stats;
2163
+ try {
2164
+ stats = fs$3.lstatSync(dstpath);
2165
+ } catch {}
2166
+ if (stats && stats.isSymbolicLink()) {
2167
+ const srcStat = fs$3.statSync(srcpath);
2168
+ const dstStat = fs$3.statSync(dstpath);
2169
+ if (areIdentical(srcStat, dstStat)) return
2170
+ }
2171
+
2172
+ const relative = symlinkPathsSync(srcpath, dstpath);
2173
+ srcpath = relative.toDst;
2174
+ type = symlinkTypeSync(relative.toCwd, type);
2175
+ const dir = path$3.dirname(dstpath);
2176
+ const exists = fs$3.existsSync(dir);
2177
+ if (exists) return fs$3.symlinkSync(srcpath, dstpath, type)
2178
+ mkdirsSync(dir);
2179
+ return fs$3.symlinkSync(srcpath, dstpath, type)
2180
+ }
2181
+
2182
+ var symlink = {
2183
+ createSymlink: u$3(createSymlink$1),
2184
+ createSymlinkSync: createSymlinkSync$1
2185
+ };
2186
+
2187
+ const { createFile, createFileSync } = file;
2188
+ const { createLink, createLinkSync } = link;
2189
+ const { createSymlink, createSymlinkSync } = symlink;
2190
+
2191
+ var ensure = {
2192
+ // file
2193
+ createFile,
2194
+ createFileSync,
2195
+ ensureFile: createFile,
2196
+ ensureFileSync: createFileSync,
2197
+ // link
2198
+ createLink,
2199
+ createLinkSync,
2200
+ ensureLink: createLink,
2201
+ ensureLinkSync: createLinkSync,
2202
+ // symlink
2203
+ createSymlink,
2204
+ createSymlinkSync,
2205
+ ensureSymlink: createSymlink,
2206
+ ensureSymlinkSync: createSymlinkSync
2207
+ };
2208
+
2209
+ function stringify$3 (obj, { EOL = '\n', finalEOL = true, replacer = null, spaces } = {}) {
2210
+ const EOF = finalEOL ? EOL : '';
2211
+ const str = JSON.stringify(obj, replacer, spaces);
2212
+
2213
+ if (str === undefined) {
2214
+ throw new TypeError(`Converting ${typeof obj} value to JSON is not supported`)
2215
+ }
2216
+
2217
+ return str.replace(/\n/g, EOL) + EOF
2218
+ }
2219
+
2220
+ function stripBom$1 (content) {
2221
+ // we do this because JSON.parse would convert it to a utf8 string if encoding wasn't specified
2222
+ if (Buffer.isBuffer(content)) content = content.toString('utf8');
2223
+ return content.replace(/^\uFEFF/, '')
2224
+ }
2225
+
2226
+ var utils = { stringify: stringify$3, stripBom: stripBom$1 };
2227
+
2228
+ let _fs;
2229
+ try {
2230
+ _fs = gracefulFs;
2231
+ } catch (_) {
2232
+ _fs = require$$0$2;
2233
+ }
2234
+ const universalify = universalify$1;
2235
+ const { stringify: stringify$2, stripBom } = utils;
2236
+
2237
+ async function _readFile (file, options = {}) {
2238
+ if (typeof options === 'string') {
2239
+ options = { encoding: options };
2240
+ }
2241
+
2242
+ const fs = options.fs || _fs;
2243
+
2244
+ const shouldThrow = 'throws' in options ? options.throws : true;
2245
+
2246
+ let data = await universalify.fromCallback(fs.readFile)(file, options);
2247
+
2248
+ data = stripBom(data);
2249
+
2250
+ let obj;
2251
+ try {
2252
+ obj = JSON.parse(data, options ? options.reviver : null);
2253
+ } catch (err) {
2254
+ if (shouldThrow) {
2255
+ err.message = `${file}: ${err.message}`;
2256
+ throw err
2257
+ } else {
2258
+ return null
2259
+ }
2260
+ }
2261
+
2262
+ return obj
2263
+ }
2264
+
2265
+ const readFile = universalify.fromPromise(_readFile);
2266
+
2267
+ function readFileSync (file, options = {}) {
2268
+ if (typeof options === 'string') {
2269
+ options = { encoding: options };
2270
+ }
2271
+
2272
+ const fs = options.fs || _fs;
2273
+
2274
+ const shouldThrow = 'throws' in options ? options.throws : true;
2275
+
2276
+ try {
2277
+ let content = fs.readFileSync(file, options);
2278
+ content = stripBom(content);
2279
+ return JSON.parse(content, options.reviver)
2280
+ } catch (err) {
2281
+ if (shouldThrow) {
2282
+ err.message = `${file}: ${err.message}`;
2283
+ throw err
2284
+ } else {
2285
+ return null
2286
+ }
2287
+ }
2288
+ }
2289
+
2290
+ async function _writeFile (file, obj, options = {}) {
2291
+ const fs = options.fs || _fs;
2292
+
2293
+ const str = stringify$2(obj, options);
2294
+
2295
+ await universalify.fromCallback(fs.writeFile)(file, str, options);
2296
+ }
2297
+
2298
+ const writeFile = universalify.fromPromise(_writeFile);
2299
+
2300
+ function writeFileSync (file, obj, options = {}) {
2301
+ const fs = options.fs || _fs;
2302
+
2303
+ const str = stringify$2(obj, options);
2304
+ // not sure if fs.writeFileSync returns anything, but just in case
2305
+ return fs.writeFileSync(file, str, options)
2306
+ }
2307
+
2308
+ // NOTE: do not change this export format; required for ESM compat
2309
+ // see https://github.com/jprichardson/node-jsonfile/pull/162 for details
2310
+ var jsonfile$1 = {
2311
+ readFile,
2312
+ readFileSync,
2313
+ writeFile,
2314
+ writeFileSync
2315
+ };
2316
+
2317
+ const jsonFile$1 = jsonfile$1;
2318
+
2319
+ var jsonfile = {
2320
+ // jsonfile exports
2321
+ readJson: jsonFile$1.readFile,
2322
+ readJsonSync: jsonFile$1.readFileSync,
2323
+ writeJson: jsonFile$1.writeFile,
2324
+ writeJsonSync: jsonFile$1.writeFileSync
2325
+ };
2326
+
2327
+ const u$2 = universalify$1.fromCallback;
2328
+ const fs$2 = gracefulFs;
2329
+ const path$2 = require$$1;
2330
+ const mkdir = mkdirs$2;
2331
+ const pathExists$1 = pathExists_1.pathExists;
2332
+
2333
+ function outputFile$1 (file, data, encoding, callback) {
2334
+ if (typeof encoding === 'function') {
2335
+ callback = encoding;
2336
+ encoding = 'utf8';
2337
+ }
2338
+
2339
+ const dir = path$2.dirname(file);
2340
+ pathExists$1(dir, (err, itDoes) => {
2341
+ if (err) return callback(err)
2342
+ if (itDoes) return fs$2.writeFile(file, data, encoding, callback)
2343
+
2344
+ mkdir.mkdirs(dir, err => {
2345
+ if (err) return callback(err)
2346
+
2347
+ fs$2.writeFile(file, data, encoding, callback);
2348
+ });
2349
+ });
2350
+ }
2351
+
2352
+ function outputFileSync$1 (file, ...args) {
2353
+ const dir = path$2.dirname(file);
2354
+ if (fs$2.existsSync(dir)) {
2355
+ return fs$2.writeFileSync(file, ...args)
2356
+ }
2357
+ mkdir.mkdirsSync(dir);
2358
+ fs$2.writeFileSync(file, ...args);
2359
+ }
2360
+
2361
+ var outputFile_1 = {
2362
+ outputFile: u$2(outputFile$1),
2363
+ outputFileSync: outputFileSync$1
2364
+ };
2365
+
2366
+ const { stringify: stringify$1 } = utils;
2367
+ const { outputFile } = outputFile_1;
2368
+
2369
+ async function outputJson (file, data, options = {}) {
2370
+ const str = stringify$1(data, options);
2371
+
2372
+ await outputFile(file, str, options);
2373
+ }
2374
+
2375
+ var outputJson_1 = outputJson;
2376
+
2377
+ const { stringify } = utils;
2378
+ const { outputFileSync } = outputFile_1;
2379
+
2380
+ function outputJsonSync (file, data, options) {
2381
+ const str = stringify(data, options);
2382
+
2383
+ outputFileSync(file, str, options);
2384
+ }
2385
+
2386
+ var outputJsonSync_1 = outputJsonSync;
2387
+
2388
+ const u$1 = universalify$1.fromPromise;
2389
+ const jsonFile = jsonfile;
2390
+
2391
+ jsonFile.outputJson = u$1(outputJson_1);
2392
+ jsonFile.outputJsonSync = outputJsonSync_1;
2393
+ // aliases
2394
+ jsonFile.outputJSON = jsonFile.outputJson;
2395
+ jsonFile.outputJSONSync = jsonFile.outputJsonSync;
2396
+ jsonFile.writeJSON = jsonFile.writeJson;
2397
+ jsonFile.writeJSONSync = jsonFile.writeJsonSync;
2398
+ jsonFile.readJSON = jsonFile.readJson;
2399
+ jsonFile.readJSONSync = jsonFile.readJsonSync;
2400
+
2401
+ var json = jsonFile;
2402
+
2403
+ const fs$1 = gracefulFs;
2404
+ const path$1 = require$$1;
2405
+ const copy = copy$1.copy;
2406
+ const remove = remove_1.remove;
2407
+ const mkdirp = mkdirs$2.mkdirp;
2408
+ const pathExists = pathExists_1.pathExists;
2409
+ const stat$1 = stat$4;
2410
+
2411
+ function move$1 (src, dest, opts, cb) {
2412
+ if (typeof opts === 'function') {
2413
+ cb = opts;
2414
+ opts = {};
2415
+ }
2416
+
2417
+ opts = opts || {};
2418
+
2419
+ const overwrite = opts.overwrite || opts.clobber || false;
2420
+
2421
+ stat$1.checkPaths(src, dest, 'move', opts, (err, stats) => {
2422
+ if (err) return cb(err)
2423
+ const { srcStat, isChangingCase = false } = stats;
2424
+ stat$1.checkParentPaths(src, srcStat, dest, 'move', err => {
2425
+ if (err) return cb(err)
2426
+ if (isParentRoot$1(dest)) return doRename$1(src, dest, overwrite, isChangingCase, cb)
2427
+ mkdirp(path$1.dirname(dest), err => {
2428
+ if (err) return cb(err)
2429
+ return doRename$1(src, dest, overwrite, isChangingCase, cb)
2430
+ });
2431
+ });
2432
+ });
2433
+ }
2434
+
2435
+ function isParentRoot$1 (dest) {
2436
+ const parent = path$1.dirname(dest);
2437
+ const parsedPath = path$1.parse(parent);
2438
+ return parsedPath.root === parent
2439
+ }
2440
+
2441
+ function doRename$1 (src, dest, overwrite, isChangingCase, cb) {
2442
+ if (isChangingCase) return rename$1(src, dest, overwrite, cb)
2443
+ if (overwrite) {
2444
+ return remove(dest, err => {
2445
+ if (err) return cb(err)
2446
+ return rename$1(src, dest, overwrite, cb)
2447
+ })
2448
+ }
2449
+ pathExists(dest, (err, destExists) => {
2450
+ if (err) return cb(err)
2451
+ if (destExists) return cb(new Error('dest already exists.'))
2452
+ return rename$1(src, dest, overwrite, cb)
2453
+ });
2454
+ }
2455
+
2456
+ function rename$1 (src, dest, overwrite, cb) {
2457
+ fs$1.rename(src, dest, err => {
2458
+ if (!err) return cb()
2459
+ if (err.code !== 'EXDEV') return cb(err)
2460
+ return moveAcrossDevice$1(src, dest, overwrite, cb)
2461
+ });
2462
+ }
2463
+
2464
+ function moveAcrossDevice$1 (src, dest, overwrite, cb) {
2465
+ const opts = {
2466
+ overwrite,
2467
+ errorOnExist: true,
2468
+ preserveTimestamps: true
2469
+ };
2470
+ copy(src, dest, opts, err => {
2471
+ if (err) return cb(err)
2472
+ return remove(src, cb)
2473
+ });
2474
+ }
2475
+
2476
+ var move_1 = move$1;
2477
+
2478
+ const fs = gracefulFs;
2479
+ const path = require$$1;
2480
+ const copySync = copy$1.copySync;
2481
+ const removeSync = remove_1.removeSync;
2482
+ const mkdirpSync = mkdirs$2.mkdirpSync;
2483
+ const stat = stat$4;
2484
+
2485
+ function moveSync (src, dest, opts) {
2486
+ opts = opts || {};
2487
+ const overwrite = opts.overwrite || opts.clobber || false;
2488
+
2489
+ const { srcStat, isChangingCase = false } = stat.checkPathsSync(src, dest, 'move', opts);
2490
+ stat.checkParentPathsSync(src, srcStat, dest, 'move');
2491
+ if (!isParentRoot(dest)) mkdirpSync(path.dirname(dest));
2492
+ return doRename(src, dest, overwrite, isChangingCase)
2493
+ }
2494
+
2495
+ function isParentRoot (dest) {
2496
+ const parent = path.dirname(dest);
2497
+ const parsedPath = path.parse(parent);
2498
+ return parsedPath.root === parent
2499
+ }
2500
+
2501
+ function doRename (src, dest, overwrite, isChangingCase) {
2502
+ if (isChangingCase) return rename(src, dest, overwrite)
2503
+ if (overwrite) {
2504
+ removeSync(dest);
2505
+ return rename(src, dest, overwrite)
2506
+ }
2507
+ if (fs.existsSync(dest)) throw new Error('dest already exists.')
2508
+ return rename(src, dest, overwrite)
2509
+ }
2510
+
2511
+ function rename (src, dest, overwrite) {
2512
+ try {
2513
+ fs.renameSync(src, dest);
2514
+ } catch (err) {
2515
+ if (err.code !== 'EXDEV') throw err
2516
+ return moveAcrossDevice(src, dest, overwrite)
2517
+ }
2518
+ }
2519
+
2520
+ function moveAcrossDevice (src, dest, overwrite) {
2521
+ const opts = {
2522
+ overwrite,
2523
+ errorOnExist: true,
2524
+ preserveTimestamps: true
2525
+ };
2526
+ copySync(src, dest, opts);
2527
+ return removeSync(src)
2528
+ }
2529
+
2530
+ var moveSync_1 = moveSync;
2531
+
2532
+ const u = universalify$1.fromCallback;
2533
+ var move = {
2534
+ move: u(move_1),
2535
+ moveSync: moveSync_1
2536
+ };
2537
+
2538
+ var lib = {
2539
+ // Export promiseified graceful-fs:
2540
+ ...fs$h,
2541
+ // Export extra methods:
2542
+ ...copy$1,
2543
+ ...empty,
2544
+ ...ensure,
2545
+ ...json,
2546
+ ...mkdirs$2,
2547
+ ...move,
2548
+ ...outputFile_1,
2549
+ ...pathExists_1,
2550
+ ...remove_1
2551
+ };
2552
+
2553
+ var index = /*@__PURE__*/getDefaultExportFromCjs(lib);
2554
+
2555
+ var index$1 = /*#__PURE__*/_mergeNamespaces({
2556
+ __proto__: null,
2557
+ default: index
2558
+ }, [lib]);
2559
+
2560
+ export { index$1 as i };