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