@initx-plugin/core 0.0.11 → 0.0.13

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