@andersbakken/fisk 5.0.13 → 5.0.16

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.
@@ -1,3867 +0,0 @@
1
- 'use strict';
2
-
3
- var EventEmitter = require('events');
4
- var assert$1 = require('assert');
5
- var child_process = require('child_process');
6
- var require$$1 = require('fs');
7
- var require$$0 = require('constants');
8
- var require$$0$1 = require('stream');
9
- var require$$4 = require('util');
10
- var path$h = require('path');
11
- var require$$1$1 = require('os');
12
- var fiskNative = require('@andersbakken/fisk-native');
13
-
14
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
15
-
16
- var EventEmitter__default = /*#__PURE__*/_interopDefaultLegacy(EventEmitter);
17
- var assert__default = /*#__PURE__*/_interopDefaultLegacy(assert$1);
18
- var child_process__default = /*#__PURE__*/_interopDefaultLegacy(child_process);
19
- var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
20
- var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
21
- var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
22
- var require$$4__default = /*#__PURE__*/_interopDefaultLegacy(require$$4);
23
- var path__default = /*#__PURE__*/_interopDefaultLegacy(path$h);
24
- var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
25
-
26
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
27
-
28
- var libExports = {};
29
- var lib = {
30
- get exports(){ return libExports; },
31
- set exports(v){ libExports = v; },
32
- };
33
-
34
- var fs$j = {};
35
-
36
- var universalify = {};
37
-
38
- universalify.fromCallback = function (fn) {
39
- return Object.defineProperty(function () {
40
- if (typeof arguments[arguments.length - 1] === 'function') fn.apply(this, arguments);
41
- else {
42
- return new Promise((resolve, reject) => {
43
- arguments[arguments.length] = (err, res) => {
44
- if (err) return reject(err)
45
- resolve(res);
46
- };
47
- arguments.length++;
48
- fn.apply(this, arguments);
49
- })
50
- }
51
- }, 'name', { value: fn.name })
52
- };
53
-
54
- universalify.fromPromise = function (fn) {
55
- return Object.defineProperty(function () {
56
- const cb = arguments[arguments.length - 1];
57
- if (typeof cb !== 'function') return fn.apply(this, arguments)
58
- else fn.apply(this, arguments).then(r => cb(null, r), cb);
59
- }, 'name', { value: fn.name })
60
- };
61
-
62
- var constants = require$$0__default["default"];
63
-
64
- var origCwd = process.cwd;
65
- var cwd = null;
66
-
67
- var platform = process.env.GRACEFUL_FS_PLATFORM || process.platform;
68
-
69
- process.cwd = function() {
70
- if (!cwd)
71
- cwd = origCwd.call(process);
72
- return cwd
73
- };
74
- try {
75
- process.cwd();
76
- } catch (er) {}
77
-
78
- // This check is needed until node.js 12 is required
79
- if (typeof process.chdir === 'function') {
80
- var chdir = process.chdir;
81
- process.chdir = function (d) {
82
- cwd = null;
83
- chdir.call(process, d);
84
- };
85
- if (Object.setPrototypeOf) Object.setPrototypeOf(process.chdir, chdir);
86
- }
87
-
88
- var polyfills$1 = patch$1;
89
-
90
- function patch$1 (fs) {
91
- // (re-)implement some things that are known busted or missing.
92
-
93
- // lchmod, broken prior to 0.6.2
94
- // back-port the fix here.
95
- if (constants.hasOwnProperty('O_SYMLINK') &&
96
- process.version.match(/^v0\.6\.[0-2]|^v0\.5\./)) {
97
- patchLchmod(fs);
98
- }
99
-
100
- // lutimes implementation, or no-op
101
- if (!fs.lutimes) {
102
- patchLutimes(fs);
103
- }
104
-
105
- // https://github.com/isaacs/node-graceful-fs/issues/4
106
- // Chown should not fail on einval or eperm if non-root.
107
- // It should not fail on enosys ever, as this just indicates
108
- // that a fs doesn't support the intended operation.
109
-
110
- fs.chown = chownFix(fs.chown);
111
- fs.fchown = chownFix(fs.fchown);
112
- fs.lchown = chownFix(fs.lchown);
113
-
114
- fs.chmod = chmodFix(fs.chmod);
115
- fs.fchmod = chmodFix(fs.fchmod);
116
- fs.lchmod = chmodFix(fs.lchmod);
117
-
118
- fs.chownSync = chownFixSync(fs.chownSync);
119
- fs.fchownSync = chownFixSync(fs.fchownSync);
120
- fs.lchownSync = chownFixSync(fs.lchownSync);
121
-
122
- fs.chmodSync = chmodFixSync(fs.chmodSync);
123
- fs.fchmodSync = chmodFixSync(fs.fchmodSync);
124
- fs.lchmodSync = chmodFixSync(fs.lchmodSync);
125
-
126
- fs.stat = statFix(fs.stat);
127
- fs.fstat = statFix(fs.fstat);
128
- fs.lstat = statFix(fs.lstat);
129
-
130
- fs.statSync = statFixSync(fs.statSync);
131
- fs.fstatSync = statFixSync(fs.fstatSync);
132
- fs.lstatSync = statFixSync(fs.lstatSync);
133
-
134
- // if lchmod/lchown do not exist, then make them no-ops
135
- if (fs.chmod && !fs.lchmod) {
136
- fs.lchmod = function (path, mode, cb) {
137
- if (cb) process.nextTick(cb);
138
- };
139
- fs.lchmodSync = function () {};
140
- }
141
- if (fs.chown && !fs.lchown) {
142
- fs.lchown = function (path, uid, gid, cb) {
143
- if (cb) process.nextTick(cb);
144
- };
145
- fs.lchownSync = function () {};
146
- }
147
-
148
- // on Windows, A/V software can lock the directory, causing this
149
- // to fail with an EACCES or EPERM if the directory contains newly
150
- // created files. Try again on failure, for up to 60 seconds.
151
-
152
- // Set the timeout this long because some Windows Anti-Virus, such as Parity
153
- // bit9, may lock files for up to a minute, causing npm package install
154
- // failures. Also, take care to yield the scheduler. Windows scheduling gives
155
- // CPU to a busy looping process, which can cause the program causing the lock
156
- // contention to be starved of CPU by node, so the contention doesn't resolve.
157
- if (platform === "win32") {
158
- fs.rename = typeof fs.rename !== 'function' ? fs.rename
159
- : (function (fs$rename) {
160
- function rename (from, to, cb) {
161
- var start = Date.now();
162
- var backoff = 0;
163
- fs$rename(from, to, function CB (er) {
164
- if (er
165
- && (er.code === "EACCES" || er.code === "EPERM")
166
- && Date.now() - start < 60000) {
167
- setTimeout(function() {
168
- fs.stat(to, function (stater, st) {
169
- if (stater && stater.code === "ENOENT")
170
- fs$rename(from, to, CB);
171
- else
172
- cb(er);
173
- });
174
- }, backoff);
175
- if (backoff < 100)
176
- backoff += 10;
177
- return;
178
- }
179
- if (cb) cb(er);
180
- });
181
- }
182
- if (Object.setPrototypeOf) Object.setPrototypeOf(rename, fs$rename);
183
- return rename
184
- })(fs.rename);
185
- }
186
-
187
- // if read() returns EAGAIN, then just try it again.
188
- fs.read = typeof fs.read !== 'function' ? fs.read
189
- : (function (fs$read) {
190
- function read (fd, buffer, offset, length, position, callback_) {
191
- var callback;
192
- if (callback_ && typeof callback_ === 'function') {
193
- var eagCounter = 0;
194
- callback = function (er, _, __) {
195
- if (er && er.code === 'EAGAIN' && eagCounter < 10) {
196
- eagCounter ++;
197
- return fs$read.call(fs, fd, buffer, offset, length, position, callback)
198
- }
199
- callback_.apply(this, arguments);
200
- };
201
- }
202
- return fs$read.call(fs, fd, buffer, offset, length, position, callback)
203
- }
204
-
205
- // This ensures `util.promisify` works as it does for native `fs.read`.
206
- if (Object.setPrototypeOf) Object.setPrototypeOf(read, fs$read);
207
- return read
208
- })(fs.read);
209
-
210
- fs.readSync = typeof fs.readSync !== 'function' ? fs.readSync
211
- : (function (fs$readSync) { return function (fd, buffer, offset, length, position) {
212
- var eagCounter = 0;
213
- while (true) {
214
- try {
215
- return fs$readSync.call(fs, fd, buffer, offset, length, position)
216
- } catch (er) {
217
- if (er.code === 'EAGAIN' && eagCounter < 10) {
218
- eagCounter ++;
219
- continue
220
- }
221
- throw er
222
- }
223
- }
224
- }})(fs.readSync);
225
-
226
- function patchLchmod (fs) {
227
- fs.lchmod = function (path, mode, callback) {
228
- fs.open( path
229
- , constants.O_WRONLY | constants.O_SYMLINK
230
- , mode
231
- , function (err, fd) {
232
- if (err) {
233
- if (callback) callback(err);
234
- return
235
- }
236
- // prefer to return the chmod error, if one occurs,
237
- // but still try to close, and report closing errors if they occur.
238
- fs.fchmod(fd, mode, function (err) {
239
- fs.close(fd, function(err2) {
240
- if (callback) callback(err || err2);
241
- });
242
- });
243
- });
244
- };
245
-
246
- fs.lchmodSync = function (path, mode) {
247
- var fd = fs.openSync(path, constants.O_WRONLY | constants.O_SYMLINK, mode);
248
-
249
- // prefer to return the chmod error, if one occurs,
250
- // but still try to close, and report closing errors if they occur.
251
- var threw = true;
252
- var ret;
253
- try {
254
- ret = fs.fchmodSync(fd, mode);
255
- threw = false;
256
- } finally {
257
- if (threw) {
258
- try {
259
- fs.closeSync(fd);
260
- } catch (er) {}
261
- } else {
262
- fs.closeSync(fd);
263
- }
264
- }
265
- return ret
266
- };
267
- }
268
-
269
- function patchLutimes (fs) {
270
- if (constants.hasOwnProperty("O_SYMLINK") && fs.futimes) {
271
- fs.lutimes = function (path, at, mt, cb) {
272
- fs.open(path, constants.O_SYMLINK, function (er, fd) {
273
- if (er) {
274
- if (cb) cb(er);
275
- return
276
- }
277
- fs.futimes(fd, at, mt, function (er) {
278
- fs.close(fd, function (er2) {
279
- if (cb) cb(er || er2);
280
- });
281
- });
282
- });
283
- };
284
-
285
- fs.lutimesSync = function (path, at, mt) {
286
- var fd = fs.openSync(path, constants.O_SYMLINK);
287
- var ret;
288
- var threw = true;
289
- try {
290
- ret = fs.futimesSync(fd, at, mt);
291
- threw = false;
292
- } finally {
293
- if (threw) {
294
- try {
295
- fs.closeSync(fd);
296
- } catch (er) {}
297
- } else {
298
- fs.closeSync(fd);
299
- }
300
- }
301
- return ret
302
- };
303
-
304
- } else if (fs.futimes) {
305
- fs.lutimes = function (_a, _b, _c, cb) { if (cb) process.nextTick(cb); };
306
- fs.lutimesSync = function () {};
307
- }
308
- }
309
-
310
- function chmodFix (orig) {
311
- if (!orig) return orig
312
- return function (target, mode, cb) {
313
- return orig.call(fs, target, mode, function (er) {
314
- if (chownErOk(er)) er = null;
315
- if (cb) cb.apply(this, arguments);
316
- })
317
- }
318
- }
319
-
320
- function chmodFixSync (orig) {
321
- if (!orig) return orig
322
- return function (target, mode) {
323
- try {
324
- return orig.call(fs, target, mode)
325
- } catch (er) {
326
- if (!chownErOk(er)) throw er
327
- }
328
- }
329
- }
330
-
331
-
332
- function chownFix (orig) {
333
- if (!orig) return orig
334
- return function (target, uid, gid, cb) {
335
- return orig.call(fs, target, uid, gid, function (er) {
336
- if (chownErOk(er)) er = null;
337
- if (cb) cb.apply(this, arguments);
338
- })
339
- }
340
- }
341
-
342
- function chownFixSync (orig) {
343
- if (!orig) return orig
344
- return function (target, uid, gid) {
345
- try {
346
- return orig.call(fs, target, uid, gid)
347
- } catch (er) {
348
- if (!chownErOk(er)) throw er
349
- }
350
- }
351
- }
352
-
353
- function statFix (orig) {
354
- if (!orig) return orig
355
- // Older versions of Node erroneously returned signed integers for
356
- // uid + gid.
357
- return function (target, options, cb) {
358
- if (typeof options === 'function') {
359
- cb = options;
360
- options = null;
361
- }
362
- function callback (er, stats) {
363
- if (stats) {
364
- if (stats.uid < 0) stats.uid += 0x100000000;
365
- if (stats.gid < 0) stats.gid += 0x100000000;
366
- }
367
- if (cb) cb.apply(this, arguments);
368
- }
369
- return options ? orig.call(fs, target, options, callback)
370
- : orig.call(fs, target, callback)
371
- }
372
- }
373
-
374
- function statFixSync (orig) {
375
- if (!orig) return orig
376
- // Older versions of Node erroneously returned signed integers for
377
- // uid + gid.
378
- return function (target, options) {
379
- var stats = options ? orig.call(fs, target, options)
380
- : orig.call(fs, target);
381
- if (stats) {
382
- if (stats.uid < 0) stats.uid += 0x100000000;
383
- if (stats.gid < 0) stats.gid += 0x100000000;
384
- }
385
- return stats;
386
- }
387
- }
388
-
389
- // ENOSYS means that the fs doesn't support the op. Just ignore
390
- // that, because it doesn't matter.
391
- //
392
- // if there's no getuid, or if getuid() is something other
393
- // than 0, and the error is EINVAL or EPERM, then just ignore
394
- // it.
395
- //
396
- // This specific case is a silent failure in cp, install, tar,
397
- // and most other unix tools that manage permissions.
398
- //
399
- // When running as root, or if other types of errors are
400
- // encountered, then it's strict.
401
- function chownErOk (er) {
402
- if (!er)
403
- return true
404
-
405
- if (er.code === "ENOSYS")
406
- return true
407
-
408
- var nonroot = !process.getuid || process.getuid() !== 0;
409
- if (nonroot) {
410
- if (er.code === "EINVAL" || er.code === "EPERM")
411
- return true
412
- }
413
-
414
- return false
415
- }
416
- }
417
-
418
- var Stream = require$$0__default$1["default"].Stream;
419
-
420
- var legacyStreams = legacy$1;
421
-
422
- function legacy$1 (fs) {
423
- return {
424
- ReadStream: ReadStream,
425
- WriteStream: WriteStream
426
- }
427
-
428
- function ReadStream (path, options) {
429
- if (!(this instanceof ReadStream)) return new ReadStream(path, options);
430
-
431
- Stream.call(this);
432
-
433
- var self = this;
434
-
435
- this.path = path;
436
- this.fd = null;
437
- this.readable = true;
438
- this.paused = false;
439
-
440
- this.flags = 'r';
441
- this.mode = 438; /*=0666*/
442
- this.bufferSize = 64 * 1024;
443
-
444
- options = options || {};
445
-
446
- // Mixin options into this
447
- var keys = Object.keys(options);
448
- for (var index = 0, length = keys.length; index < length; index++) {
449
- var key = keys[index];
450
- this[key] = options[key];
451
- }
452
-
453
- if (this.encoding) this.setEncoding(this.encoding);
454
-
455
- if (this.start !== undefined) {
456
- if ('number' !== typeof this.start) {
457
- throw TypeError('start must be a Number');
458
- }
459
- if (this.end === undefined) {
460
- this.end = Infinity;
461
- } else if ('number' !== typeof this.end) {
462
- throw TypeError('end must be a Number');
463
- }
464
-
465
- if (this.start > this.end) {
466
- throw new Error('start must be <= end');
467
- }
468
-
469
- this.pos = this.start;
470
- }
471
-
472
- if (this.fd !== null) {
473
- process.nextTick(function() {
474
- self._read();
475
- });
476
- return;
477
- }
478
-
479
- fs.open(this.path, this.flags, this.mode, function (err, fd) {
480
- if (err) {
481
- self.emit('error', err);
482
- self.readable = false;
483
- return;
484
- }
485
-
486
- self.fd = fd;
487
- self.emit('open', fd);
488
- self._read();
489
- });
490
- }
491
-
492
- function WriteStream (path, options) {
493
- if (!(this instanceof WriteStream)) return new WriteStream(path, options);
494
-
495
- Stream.call(this);
496
-
497
- this.path = path;
498
- this.fd = null;
499
- this.writable = true;
500
-
501
- this.flags = 'w';
502
- this.encoding = 'binary';
503
- this.mode = 438; /*=0666*/
504
- this.bytesWritten = 0;
505
-
506
- options = options || {};
507
-
508
- // Mixin options into this
509
- var keys = Object.keys(options);
510
- for (var index = 0, length = keys.length; index < length; index++) {
511
- var key = keys[index];
512
- this[key] = options[key];
513
- }
514
-
515
- if (this.start !== undefined) {
516
- if ('number' !== typeof this.start) {
517
- throw TypeError('start must be a Number');
518
- }
519
- if (this.start < 0) {
520
- throw new Error('start must be >= zero');
521
- }
522
-
523
- this.pos = this.start;
524
- }
525
-
526
- this.busy = false;
527
- this._queue = [];
528
-
529
- if (this.fd === null) {
530
- this._open = fs.open;
531
- this._queue.push([this._open, this.path, this.flags, this.mode, undefined]);
532
- this.flush();
533
- }
534
- }
535
- }
536
-
537
- var clone_1 = clone$1;
538
-
539
- var getPrototypeOf = Object.getPrototypeOf || function (obj) {
540
- return obj.__proto__
541
- };
542
-
543
- function clone$1 (obj) {
544
- if (obj === null || typeof obj !== 'object')
545
- return obj
546
-
547
- if (obj instanceof Object)
548
- var copy = { __proto__: getPrototypeOf(obj) };
549
- else
550
- var copy = Object.create(null);
551
-
552
- Object.getOwnPropertyNames(obj).forEach(function (key) {
553
- Object.defineProperty(copy, key, Object.getOwnPropertyDescriptor(obj, key));
554
- });
555
-
556
- return copy
557
- }
558
-
559
- var fs$i = require$$1__default["default"];
560
- var polyfills = polyfills$1;
561
- var legacy = legacyStreams;
562
- var clone = clone_1;
563
-
564
- var util = require$$4__default["default"];
565
-
566
- /* istanbul ignore next - node 0.x polyfill */
567
- var gracefulQueue;
568
- var previousSymbol;
569
-
570
- /* istanbul ignore else - node 0.x polyfill */
571
- if (typeof Symbol === 'function' && typeof Symbol.for === 'function') {
572
- gracefulQueue = Symbol.for('graceful-fs.queue');
573
- // This is used in testing by future versions
574
- previousSymbol = Symbol.for('graceful-fs.previous');
575
- } else {
576
- gracefulQueue = '___graceful-fs.queue';
577
- previousSymbol = '___graceful-fs.previous';
578
- }
579
-
580
- function noop () {}
581
-
582
- function publishQueue(context, queue) {
583
- Object.defineProperty(context, gracefulQueue, {
584
- get: function() {
585
- return queue
586
- }
587
- });
588
- }
589
-
590
- var debug = noop;
591
- if (util.debuglog)
592
- debug = util.debuglog('gfs4');
593
- else if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || ''))
594
- debug = function() {
595
- var m = util.format.apply(util, arguments);
596
- m = 'GFS4: ' + m.split(/\n/).join('\nGFS4: ');
597
- console.error(m);
598
- };
599
-
600
- // Once time initialization
601
- if (!fs$i[gracefulQueue]) {
602
- // This queue can be shared by multiple loaded instances
603
- var queue = commonjsGlobal[gracefulQueue] || [];
604
- publishQueue(fs$i, queue);
605
-
606
- // Patch fs.close/closeSync to shared queue version, because we need
607
- // to retry() whenever a close happens *anywhere* in the program.
608
- // This is essential when multiple graceful-fs instances are
609
- // in play at the same time.
610
- fs$i.close = (function (fs$close) {
611
- function close (fd, cb) {
612
- return fs$close.call(fs$i, fd, function (err) {
613
- // This function uses the graceful-fs shared queue
614
- if (!err) {
615
- resetQueue();
616
- }
617
-
618
- if (typeof cb === 'function')
619
- cb.apply(this, arguments);
620
- })
621
- }
622
-
623
- Object.defineProperty(close, previousSymbol, {
624
- value: fs$close
625
- });
626
- return close
627
- })(fs$i.close);
628
-
629
- fs$i.closeSync = (function (fs$closeSync) {
630
- function closeSync (fd) {
631
- // This function uses the graceful-fs shared queue
632
- fs$closeSync.apply(fs$i, arguments);
633
- resetQueue();
634
- }
635
-
636
- Object.defineProperty(closeSync, previousSymbol, {
637
- value: fs$closeSync
638
- });
639
- return closeSync
640
- })(fs$i.closeSync);
641
-
642
- if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || '')) {
643
- process.on('exit', function() {
644
- debug(fs$i[gracefulQueue]);
645
- assert__default["default"].equal(fs$i[gracefulQueue].length, 0);
646
- });
647
- }
648
- }
649
-
650
- if (!commonjsGlobal[gracefulQueue]) {
651
- publishQueue(commonjsGlobal, fs$i[gracefulQueue]);
652
- }
653
-
654
- var gracefulFs = patch(clone(fs$i));
655
- if (process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH && !fs$i.__patched) {
656
- gracefulFs = patch(fs$i);
657
- fs$i.__patched = true;
658
- }
659
-
660
- function patch (fs) {
661
- // Everything that references the open() function needs to be in here
662
- polyfills(fs);
663
- fs.gracefulify = patch;
664
-
665
- fs.createReadStream = createReadStream;
666
- fs.createWriteStream = createWriteStream;
667
- var fs$readFile = fs.readFile;
668
- fs.readFile = readFile;
669
- function readFile (path, options, cb) {
670
- if (typeof options === 'function')
671
- cb = options, options = null;
672
-
673
- return go$readFile(path, options, cb)
674
-
675
- function go$readFile (path, options, cb, startTime) {
676
- return fs$readFile(path, options, function (err) {
677
- if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
678
- enqueue([go$readFile, [path, options, cb], err, startTime || Date.now(), Date.now()]);
679
- else {
680
- if (typeof cb === 'function')
681
- cb.apply(this, arguments);
682
- }
683
- })
684
- }
685
- }
686
-
687
- var fs$writeFile = fs.writeFile;
688
- fs.writeFile = writeFile;
689
- function writeFile (path, data, options, cb) {
690
- if (typeof options === 'function')
691
- cb = options, options = null;
692
-
693
- return go$writeFile(path, data, options, cb)
694
-
695
- function go$writeFile (path, data, options, cb, startTime) {
696
- return fs$writeFile(path, data, options, function (err) {
697
- if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
698
- enqueue([go$writeFile, [path, data, options, cb], err, startTime || Date.now(), Date.now()]);
699
- else {
700
- if (typeof cb === 'function')
701
- cb.apply(this, arguments);
702
- }
703
- })
704
- }
705
- }
706
-
707
- var fs$appendFile = fs.appendFile;
708
- if (fs$appendFile)
709
- fs.appendFile = appendFile;
710
- function appendFile (path, data, options, cb) {
711
- if (typeof options === 'function')
712
- cb = options, options = null;
713
-
714
- return go$appendFile(path, data, options, cb)
715
-
716
- function go$appendFile (path, data, options, cb, startTime) {
717
- return fs$appendFile(path, data, options, function (err) {
718
- if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
719
- enqueue([go$appendFile, [path, data, options, cb], err, startTime || Date.now(), Date.now()]);
720
- else {
721
- if (typeof cb === 'function')
722
- cb.apply(this, arguments);
723
- }
724
- })
725
- }
726
- }
727
-
728
- var fs$copyFile = fs.copyFile;
729
- if (fs$copyFile)
730
- fs.copyFile = copyFile;
731
- function copyFile (src, dest, flags, cb) {
732
- if (typeof flags === 'function') {
733
- cb = flags;
734
- flags = 0;
735
- }
736
- return go$copyFile(src, dest, flags, cb)
737
-
738
- function go$copyFile (src, dest, flags, cb, startTime) {
739
- return fs$copyFile(src, dest, flags, function (err) {
740
- if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
741
- enqueue([go$copyFile, [src, dest, flags, cb], err, startTime || Date.now(), Date.now()]);
742
- else {
743
- if (typeof cb === 'function')
744
- cb.apply(this, arguments);
745
- }
746
- })
747
- }
748
- }
749
-
750
- var fs$readdir = fs.readdir;
751
- fs.readdir = readdir;
752
- var noReaddirOptionVersions = /^v[0-5]\./;
753
- function readdir (path, options, cb) {
754
- if (typeof options === 'function')
755
- cb = options, options = null;
756
-
757
- var go$readdir = noReaddirOptionVersions.test(process.version)
758
- ? function go$readdir (path, options, cb, startTime) {
759
- return fs$readdir(path, fs$readdirCallback(
760
- path, options, cb, startTime
761
- ))
762
- }
763
- : function go$readdir (path, options, cb, startTime) {
764
- return fs$readdir(path, options, fs$readdirCallback(
765
- path, options, cb, startTime
766
- ))
767
- };
768
-
769
- return go$readdir(path, options, cb)
770
-
771
- function fs$readdirCallback (path, options, cb, startTime) {
772
- return function (err, files) {
773
- if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
774
- enqueue([
775
- go$readdir,
776
- [path, options, cb],
777
- err,
778
- startTime || Date.now(),
779
- Date.now()
780
- ]);
781
- else {
782
- if (files && files.sort)
783
- files.sort();
784
-
785
- if (typeof cb === 'function')
786
- cb.call(this, err, files);
787
- }
788
- }
789
- }
790
- }
791
-
792
- if (process.version.substr(0, 4) === 'v0.8') {
793
- var legStreams = legacy(fs);
794
- ReadStream = legStreams.ReadStream;
795
- WriteStream = legStreams.WriteStream;
796
- }
797
-
798
- var fs$ReadStream = fs.ReadStream;
799
- if (fs$ReadStream) {
800
- ReadStream.prototype = Object.create(fs$ReadStream.prototype);
801
- ReadStream.prototype.open = ReadStream$open;
802
- }
803
-
804
- var fs$WriteStream = fs.WriteStream;
805
- if (fs$WriteStream) {
806
- WriteStream.prototype = Object.create(fs$WriteStream.prototype);
807
- WriteStream.prototype.open = WriteStream$open;
808
- }
809
-
810
- Object.defineProperty(fs, 'ReadStream', {
811
- get: function () {
812
- return ReadStream
813
- },
814
- set: function (val) {
815
- ReadStream = val;
816
- },
817
- enumerable: true,
818
- configurable: true
819
- });
820
- Object.defineProperty(fs, 'WriteStream', {
821
- get: function () {
822
- return WriteStream
823
- },
824
- set: function (val) {
825
- WriteStream = val;
826
- },
827
- enumerable: true,
828
- configurable: true
829
- });
830
-
831
- // legacy names
832
- var FileReadStream = ReadStream;
833
- Object.defineProperty(fs, 'FileReadStream', {
834
- get: function () {
835
- return FileReadStream
836
- },
837
- set: function (val) {
838
- FileReadStream = val;
839
- },
840
- enumerable: true,
841
- configurable: true
842
- });
843
- var FileWriteStream = WriteStream;
844
- Object.defineProperty(fs, 'FileWriteStream', {
845
- get: function () {
846
- return FileWriteStream
847
- },
848
- set: function (val) {
849
- FileWriteStream = val;
850
- },
851
- enumerable: true,
852
- configurable: true
853
- });
854
-
855
- function ReadStream (path, options) {
856
- if (this instanceof ReadStream)
857
- return fs$ReadStream.apply(this, arguments), this
858
- else
859
- return ReadStream.apply(Object.create(ReadStream.prototype), arguments)
860
- }
861
-
862
- function ReadStream$open () {
863
- var that = this;
864
- open(that.path, that.flags, that.mode, function (err, fd) {
865
- if (err) {
866
- if (that.autoClose)
867
- that.destroy();
868
-
869
- that.emit('error', err);
870
- } else {
871
- that.fd = fd;
872
- that.emit('open', fd);
873
- that.read();
874
- }
875
- });
876
- }
877
-
878
- function WriteStream (path, options) {
879
- if (this instanceof WriteStream)
880
- return fs$WriteStream.apply(this, arguments), this
881
- else
882
- return WriteStream.apply(Object.create(WriteStream.prototype), arguments)
883
- }
884
-
885
- function WriteStream$open () {
886
- var that = this;
887
- open(that.path, that.flags, that.mode, function (err, fd) {
888
- if (err) {
889
- that.destroy();
890
- that.emit('error', err);
891
- } else {
892
- that.fd = fd;
893
- that.emit('open', fd);
894
- }
895
- });
896
- }
897
-
898
- function createReadStream (path, options) {
899
- return new fs.ReadStream(path, options)
900
- }
901
-
902
- function createWriteStream (path, options) {
903
- return new fs.WriteStream(path, options)
904
- }
905
-
906
- var fs$open = fs.open;
907
- fs.open = open;
908
- function open (path, flags, mode, cb) {
909
- if (typeof mode === 'function')
910
- cb = mode, mode = null;
911
-
912
- return go$open(path, flags, mode, cb)
913
-
914
- function go$open (path, flags, mode, cb, startTime) {
915
- return fs$open(path, flags, mode, function (err, fd) {
916
- if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
917
- enqueue([go$open, [path, flags, mode, cb], err, startTime || Date.now(), Date.now()]);
918
- else {
919
- if (typeof cb === 'function')
920
- cb.apply(this, arguments);
921
- }
922
- })
923
- }
924
- }
925
-
926
- return fs
927
- }
928
-
929
- function enqueue (elem) {
930
- debug('ENQUEUE', elem[0].name, elem[1]);
931
- fs$i[gracefulQueue].push(elem);
932
- retry();
933
- }
934
-
935
- // keep track of the timeout between retry() calls
936
- var retryTimer;
937
-
938
- // reset the startTime and lastTime to now
939
- // this resets the start of the 60 second overall timeout as well as the
940
- // delay between attempts so that we'll retry these jobs sooner
941
- function resetQueue () {
942
- var now = Date.now();
943
- for (var i = 0; i < fs$i[gracefulQueue].length; ++i) {
944
- // entries that are only a length of 2 are from an older version, don't
945
- // bother modifying those since they'll be retried anyway.
946
- if (fs$i[gracefulQueue][i].length > 2) {
947
- fs$i[gracefulQueue][i][3] = now; // startTime
948
- fs$i[gracefulQueue][i][4] = now; // lastTime
949
- }
950
- }
951
- // call retry to make sure we're actively processing the queue
952
- retry();
953
- }
954
-
955
- function retry () {
956
- // clear the timer and remove it to help prevent unintended concurrency
957
- clearTimeout(retryTimer);
958
- retryTimer = undefined;
959
-
960
- if (fs$i[gracefulQueue].length === 0)
961
- return
962
-
963
- var elem = fs$i[gracefulQueue].shift();
964
- var fn = elem[0];
965
- var args = elem[1];
966
- // these items may be unset if they were added by an older graceful-fs
967
- var err = elem[2];
968
- var startTime = elem[3];
969
- var lastTime = elem[4];
970
-
971
- // if we don't have a startTime we have no way of knowing if we've waited
972
- // long enough, so go ahead and retry this item now
973
- if (startTime === undefined) {
974
- debug('RETRY', fn.name, args);
975
- fn.apply(null, args);
976
- } else if (Date.now() - startTime >= 60000) {
977
- // it's been more than 60 seconds total, bail now
978
- debug('TIMEOUT', fn.name, args);
979
- var cb = args.pop();
980
- if (typeof cb === 'function')
981
- cb.call(null, err);
982
- } else {
983
- // the amount of time between the last attempt and right now
984
- var sinceAttempt = Date.now() - lastTime;
985
- // the amount of time between when we first tried, and when we last tried
986
- // rounded up to at least 1
987
- var sinceStart = Math.max(lastTime - startTime, 1);
988
- // backoff. wait longer than the total time we've been retrying, but only
989
- // up to a maximum of 100ms
990
- var desiredDelay = Math.min(sinceStart * 1.2, 100);
991
- // it's been long enough since the last retry, do it again
992
- if (sinceAttempt >= desiredDelay) {
993
- debug('RETRY', fn.name, args);
994
- fn.apply(null, args.concat([startTime]));
995
- } else {
996
- // if we can't do this job yet, push it to the end of the queue
997
- // and let the next iteration check again
998
- fs$i[gracefulQueue].push(elem);
999
- }
1000
- }
1001
-
1002
- // schedule our next run if one isn't already scheduled
1003
- if (retryTimer === undefined) {
1004
- retryTimer = setTimeout(retry, 0);
1005
- }
1006
- }
1007
-
1008
- (function (exports) {
1009
- // This is adapted from https://github.com/normalize/mz
1010
- // Copyright (c) 2014-2016 Jonathan Ong me@jongleberry.com and Contributors
1011
- const u = universalify.fromCallback;
1012
- const fs = gracefulFs;
1013
-
1014
- const api = [
1015
- 'access',
1016
- 'appendFile',
1017
- 'chmod',
1018
- 'chown',
1019
- 'close',
1020
- 'copyFile',
1021
- 'fchmod',
1022
- 'fchown',
1023
- 'fdatasync',
1024
- 'fstat',
1025
- 'fsync',
1026
- 'ftruncate',
1027
- 'futimes',
1028
- 'lchown',
1029
- 'link',
1030
- 'lstat',
1031
- 'mkdir',
1032
- 'mkdtemp',
1033
- 'open',
1034
- 'readFile',
1035
- 'readdir',
1036
- 'readlink',
1037
- 'realpath',
1038
- 'rename',
1039
- 'rmdir',
1040
- 'stat',
1041
- 'symlink',
1042
- 'truncate',
1043
- 'unlink',
1044
- 'utimes',
1045
- 'writeFile'
1046
- ].filter(key => {
1047
- // Some commands are not available on some systems. Ex:
1048
- // fs.copyFile was added in Node.js v8.5.0
1049
- // fs.mkdtemp was added in Node.js v5.10.0
1050
- // fs.lchown is not available on at least some Linux
1051
- return typeof fs[key] === 'function'
1052
- });
1053
-
1054
- // Export all keys:
1055
- Object.keys(fs).forEach(key => {
1056
- if (key === 'promises') {
1057
- // fs.promises is a getter property that triggers ExperimentalWarning
1058
- // Don't re-export it here, the getter is defined in "lib/index.js"
1059
- return
1060
- }
1061
- exports[key] = fs[key];
1062
- });
1063
-
1064
- // Universalify async methods:
1065
- api.forEach(method => {
1066
- exports[method] = u(fs[method]);
1067
- });
1068
-
1069
- // We differ from mz/fs in that we still ship the old, broken, fs.exists()
1070
- // since we are a drop-in replacement for the native module
1071
- exports.exists = function (filename, callback) {
1072
- if (typeof callback === 'function') {
1073
- return fs.exists(filename, callback)
1074
- }
1075
- return new Promise(resolve => {
1076
- return fs.exists(filename, resolve)
1077
- })
1078
- };
1079
-
1080
- // fs.read() & fs.write need special treatment due to multiple callback args
1081
-
1082
- exports.read = function (fd, buffer, offset, length, position, callback) {
1083
- if (typeof callback === 'function') {
1084
- return fs.read(fd, buffer, offset, length, position, callback)
1085
- }
1086
- return new Promise((resolve, reject) => {
1087
- fs.read(fd, buffer, offset, length, position, (err, bytesRead, buffer) => {
1088
- if (err) return reject(err)
1089
- resolve({ bytesRead, buffer });
1090
- });
1091
- })
1092
- };
1093
-
1094
- // Function signature can be
1095
- // fs.write(fd, buffer[, offset[, length[, position]]], callback)
1096
- // OR
1097
- // fs.write(fd, string[, position[, encoding]], callback)
1098
- // We need to handle both cases, so we use ...args
1099
- exports.write = function (fd, buffer, ...args) {
1100
- if (typeof args[args.length - 1] === 'function') {
1101
- return fs.write(fd, buffer, ...args)
1102
- }
1103
-
1104
- return new Promise((resolve, reject) => {
1105
- fs.write(fd, buffer, ...args, (err, bytesWritten, buffer) => {
1106
- if (err) return reject(err)
1107
- resolve({ bytesWritten, buffer });
1108
- });
1109
- })
1110
- };
1111
- } (fs$j));
1112
-
1113
- const path$g = path__default["default"];
1114
-
1115
- // get drive on windows
1116
- function getRootPath (p) {
1117
- p = path$g.normalize(path$g.resolve(p)).split(path$g.sep);
1118
- if (p.length > 0) return p[0]
1119
- return null
1120
- }
1121
-
1122
- // http://stackoverflow.com/a/62888/10333 contains more accurate
1123
- // TODO: expand to include the rest
1124
- const INVALID_PATH_CHARS = /[<>:"|?*]/;
1125
-
1126
- function invalidWin32Path$2 (p) {
1127
- const rp = getRootPath(p);
1128
- p = p.replace(rp, '');
1129
- return INVALID_PATH_CHARS.test(p)
1130
- }
1131
-
1132
- var win32 = {
1133
- getRootPath,
1134
- invalidWin32Path: invalidWin32Path$2
1135
- };
1136
-
1137
- const fs$h = gracefulFs;
1138
- const path$f = path__default["default"];
1139
- const invalidWin32Path$1 = win32.invalidWin32Path;
1140
-
1141
- const o777$1 = parseInt('0777', 8);
1142
-
1143
- function mkdirs$2 (p, opts, callback, made) {
1144
- if (typeof opts === 'function') {
1145
- callback = opts;
1146
- opts = {};
1147
- } else if (!opts || typeof opts !== 'object') {
1148
- opts = { mode: opts };
1149
- }
1150
-
1151
- if (process.platform === 'win32' && invalidWin32Path$1(p)) {
1152
- const errInval = new Error(p + ' contains invalid WIN32 path characters.');
1153
- errInval.code = 'EINVAL';
1154
- return callback(errInval)
1155
- }
1156
-
1157
- let mode = opts.mode;
1158
- const xfs = opts.fs || fs$h;
1159
-
1160
- if (mode === undefined) {
1161
- mode = o777$1 & (~process.umask());
1162
- }
1163
- if (!made) made = null;
1164
-
1165
- callback = callback || function () {};
1166
- p = path$f.resolve(p);
1167
-
1168
- xfs.mkdir(p, mode, er => {
1169
- if (!er) {
1170
- made = made || p;
1171
- return callback(null, made)
1172
- }
1173
- switch (er.code) {
1174
- case 'ENOENT':
1175
- if (path$f.dirname(p) === p) return callback(er)
1176
- mkdirs$2(path$f.dirname(p), opts, (er, made) => {
1177
- if (er) callback(er, made);
1178
- else mkdirs$2(p, opts, callback, made);
1179
- });
1180
- break
1181
-
1182
- // In the case of any other error, just see if there's a dir
1183
- // there already. If so, then hooray! If not, then something
1184
- // is borked.
1185
- default:
1186
- xfs.stat(p, (er2, stat) => {
1187
- // if the stat fails, then that's super weird.
1188
- // let the original error be the failure reason.
1189
- if (er2 || !stat.isDirectory()) callback(er, made);
1190
- else callback(null, made);
1191
- });
1192
- break
1193
- }
1194
- });
1195
- }
1196
-
1197
- var mkdirs_1$1 = mkdirs$2;
1198
-
1199
- const fs$g = gracefulFs;
1200
- const path$e = path__default["default"];
1201
- const invalidWin32Path = win32.invalidWin32Path;
1202
-
1203
- const o777 = parseInt('0777', 8);
1204
-
1205
- function mkdirsSync$2 (p, opts, made) {
1206
- if (!opts || typeof opts !== 'object') {
1207
- opts = { mode: opts };
1208
- }
1209
-
1210
- let mode = opts.mode;
1211
- const xfs = opts.fs || fs$g;
1212
-
1213
- if (process.platform === 'win32' && invalidWin32Path(p)) {
1214
- const errInval = new Error(p + ' contains invalid WIN32 path characters.');
1215
- errInval.code = 'EINVAL';
1216
- throw errInval
1217
- }
1218
-
1219
- if (mode === undefined) {
1220
- mode = o777 & (~process.umask());
1221
- }
1222
- if (!made) made = null;
1223
-
1224
- p = path$e.resolve(p);
1225
-
1226
- try {
1227
- xfs.mkdirSync(p, mode);
1228
- made = made || p;
1229
- } catch (err0) {
1230
- if (err0.code === 'ENOENT') {
1231
- if (path$e.dirname(p) === p) throw err0
1232
- made = mkdirsSync$2(path$e.dirname(p), opts, made);
1233
- mkdirsSync$2(p, opts, made);
1234
- } else {
1235
- // In the case of any other error, just see if there's a dir there
1236
- // already. If so, then hooray! If not, then something is borked.
1237
- let stat;
1238
- try {
1239
- stat = xfs.statSync(p);
1240
- } catch (err1) {
1241
- throw err0
1242
- }
1243
- if (!stat.isDirectory()) throw err0
1244
- }
1245
- }
1246
-
1247
- return made
1248
- }
1249
-
1250
- var mkdirsSync_1 = mkdirsSync$2;
1251
-
1252
- const u$b = universalify.fromCallback;
1253
- const mkdirs$1 = u$b(mkdirs_1$1);
1254
- const mkdirsSync$1 = mkdirsSync_1;
1255
-
1256
- var mkdirs_1 = {
1257
- mkdirs: mkdirs$1,
1258
- mkdirsSync: mkdirsSync$1,
1259
- // alias
1260
- mkdirp: mkdirs$1,
1261
- mkdirpSync: mkdirsSync$1,
1262
- ensureDir: mkdirs$1,
1263
- ensureDirSync: mkdirsSync$1
1264
- };
1265
-
1266
- const fs$f = gracefulFs;
1267
- const os = require$$1__default$1["default"];
1268
- const path$d = path__default["default"];
1269
-
1270
- // HFS, ext{2,3}, FAT do not, Node.js v0.10 does not
1271
- function hasMillisResSync () {
1272
- let tmpfile = path$d.join('millis-test-sync' + Date.now().toString() + Math.random().toString().slice(2));
1273
- tmpfile = path$d.join(os.tmpdir(), tmpfile);
1274
-
1275
- // 550 millis past UNIX epoch
1276
- const d = new Date(1435410243862);
1277
- fs$f.writeFileSync(tmpfile, 'https://github.com/jprichardson/node-fs-extra/pull/141');
1278
- const fd = fs$f.openSync(tmpfile, 'r+');
1279
- fs$f.futimesSync(fd, d, d);
1280
- fs$f.closeSync(fd);
1281
- return fs$f.statSync(tmpfile).mtime > 1435410243000
1282
- }
1283
-
1284
- function hasMillisRes (callback) {
1285
- let tmpfile = path$d.join('millis-test' + Date.now().toString() + Math.random().toString().slice(2));
1286
- tmpfile = path$d.join(os.tmpdir(), tmpfile);
1287
-
1288
- // 550 millis past UNIX epoch
1289
- const d = new Date(1435410243862);
1290
- fs$f.writeFile(tmpfile, 'https://github.com/jprichardson/node-fs-extra/pull/141', err => {
1291
- if (err) return callback(err)
1292
- fs$f.open(tmpfile, 'r+', (err, fd) => {
1293
- if (err) return callback(err)
1294
- fs$f.futimes(fd, d, d, err => {
1295
- if (err) return callback(err)
1296
- fs$f.close(fd, err => {
1297
- if (err) return callback(err)
1298
- fs$f.stat(tmpfile, (err, stats) => {
1299
- if (err) return callback(err)
1300
- callback(null, stats.mtime > 1435410243000);
1301
- });
1302
- });
1303
- });
1304
- });
1305
- });
1306
- }
1307
-
1308
- function timeRemoveMillis (timestamp) {
1309
- if (typeof timestamp === 'number') {
1310
- return Math.floor(timestamp / 1000) * 1000
1311
- } else if (timestamp instanceof Date) {
1312
- return new Date(Math.floor(timestamp.getTime() / 1000) * 1000)
1313
- } else {
1314
- throw new Error('fs-extra: timeRemoveMillis() unknown parameter type')
1315
- }
1316
- }
1317
-
1318
- function utimesMillis (path, atime, mtime, callback) {
1319
- // if (!HAS_MILLIS_RES) return fs.utimes(path, atime, mtime, callback)
1320
- fs$f.open(path, 'r+', (err, fd) => {
1321
- if (err) return callback(err)
1322
- fs$f.futimes(fd, atime, mtime, futimesErr => {
1323
- fs$f.close(fd, closeErr => {
1324
- if (callback) callback(futimesErr || closeErr);
1325
- });
1326
- });
1327
- });
1328
- }
1329
-
1330
- function utimesMillisSync (path, atime, mtime) {
1331
- const fd = fs$f.openSync(path, 'r+');
1332
- fs$f.futimesSync(fd, atime, mtime);
1333
- return fs$f.closeSync(fd)
1334
- }
1335
-
1336
- var utimes$1 = {
1337
- hasMillisRes,
1338
- hasMillisResSync,
1339
- timeRemoveMillis,
1340
- utimesMillis,
1341
- utimesMillisSync
1342
- };
1343
-
1344
- /* eslint-disable node/no-deprecated-api */
1345
- var buffer$1 = function (size) {
1346
- if (typeof Buffer.allocUnsafe === 'function') {
1347
- try {
1348
- return Buffer.allocUnsafe(size)
1349
- } catch (e) {
1350
- return new Buffer(size)
1351
- }
1352
- }
1353
- return new Buffer(size)
1354
- };
1355
-
1356
- const fs$e = gracefulFs;
1357
- const path$c = path__default["default"];
1358
- const mkdirpSync$1 = mkdirs_1.mkdirsSync;
1359
- const utimesSync = utimes$1.utimesMillisSync;
1360
-
1361
- const notExist$1 = Symbol('notExist');
1362
- const existsReg$1 = Symbol('existsReg');
1363
-
1364
- function copySync$2 (src, dest, opts) {
1365
- if (typeof opts === 'function') {
1366
- opts = {filter: opts};
1367
- }
1368
-
1369
- opts = opts || {};
1370
- opts.clobber = 'clobber' in opts ? !!opts.clobber : true; // default to true for now
1371
- opts.overwrite = 'overwrite' in opts ? !!opts.overwrite : opts.clobber; // overwrite falls back to clobber
1372
-
1373
- // Warn about using preserveTimestamps on 32-bit node
1374
- if (opts.preserveTimestamps && process.arch === 'ia32') {
1375
- console.warn(`fs-extra: Using the preserveTimestamps option in 32-bit node is not recommended;\n
1376
- see https://github.com/jprichardson/node-fs-extra/issues/269`);
1377
- }
1378
-
1379
- const resolvedDest = checkPaths$1(src, dest);
1380
-
1381
- if (opts.filter && !opts.filter(src, dest)) return
1382
-
1383
- const destParent = path$c.dirname(dest);
1384
- if (!fs$e.existsSync(destParent)) mkdirpSync$1(destParent);
1385
- return startCopy$1(resolvedDest, src, dest, opts)
1386
- }
1387
-
1388
- function startCopy$1 (resolvedDest, src, dest, opts) {
1389
- if (opts.filter && !opts.filter(src, dest)) return
1390
- return getStats$1(resolvedDest, src, dest, opts)
1391
- }
1392
-
1393
- function getStats$1 (resolvedDest, src, dest, opts) {
1394
- const statSync = opts.dereference ? fs$e.statSync : fs$e.lstatSync;
1395
- const st = statSync(src);
1396
-
1397
- if (st.isDirectory()) return onDir$1(st, resolvedDest, src, dest, opts)
1398
- else if (st.isFile() ||
1399
- st.isCharacterDevice() ||
1400
- st.isBlockDevice()) return onFile$1(st, resolvedDest, src, dest, opts)
1401
- else if (st.isSymbolicLink()) return onLink$1(resolvedDest, src, dest, opts)
1402
- }
1403
-
1404
- function onFile$1 (srcStat, resolvedDest, src, dest, opts) {
1405
- if (resolvedDest === notExist$1) return copyFile$1(srcStat, src, dest, opts)
1406
- else if (resolvedDest === existsReg$1) return mayCopyFile$1(srcStat, src, dest, opts)
1407
- return mayCopyFile$1(srcStat, src, dest, opts)
1408
- }
1409
-
1410
- function mayCopyFile$1 (srcStat, src, dest, opts) {
1411
- if (opts.overwrite) {
1412
- fs$e.unlinkSync(dest);
1413
- return copyFile$1(srcStat, src, dest, opts)
1414
- } else if (opts.errorOnExist) {
1415
- throw new Error(`'${dest}' already exists`)
1416
- }
1417
- }
1418
-
1419
- function copyFile$1 (srcStat, src, dest, opts) {
1420
- if (typeof fs$e.copyFileSync === 'function') {
1421
- fs$e.copyFileSync(src, dest);
1422
- fs$e.chmodSync(dest, srcStat.mode);
1423
- if (opts.preserveTimestamps) {
1424
- return utimesSync(dest, srcStat.atime, srcStat.mtime)
1425
- }
1426
- return
1427
- }
1428
- return copyFileFallback$1(srcStat, src, dest, opts)
1429
- }
1430
-
1431
- function copyFileFallback$1 (srcStat, src, dest, opts) {
1432
- const BUF_LENGTH = 64 * 1024;
1433
- const _buff = buffer$1(BUF_LENGTH);
1434
-
1435
- const fdr = fs$e.openSync(src, 'r');
1436
- const fdw = fs$e.openSync(dest, 'w', srcStat.mode);
1437
- let pos = 0;
1438
-
1439
- while (pos < srcStat.size) {
1440
- const bytesRead = fs$e.readSync(fdr, _buff, 0, BUF_LENGTH, pos);
1441
- fs$e.writeSync(fdw, _buff, 0, bytesRead);
1442
- pos += bytesRead;
1443
- }
1444
-
1445
- if (opts.preserveTimestamps) fs$e.futimesSync(fdw, srcStat.atime, srcStat.mtime);
1446
-
1447
- fs$e.closeSync(fdr);
1448
- fs$e.closeSync(fdw);
1449
- }
1450
-
1451
- function onDir$1 (srcStat, resolvedDest, src, dest, opts) {
1452
- if (resolvedDest === notExist$1) {
1453
- if (isSrcSubdir$3(src, dest)) {
1454
- throw new Error(`Cannot copy '${src}' to a subdirectory of itself, '${dest}'.`)
1455
- }
1456
- return mkDirAndCopy$1(srcStat, src, dest, opts)
1457
- } else if (resolvedDest === existsReg$1) {
1458
- if (isSrcSubdir$3(src, dest)) {
1459
- throw new Error(`Cannot copy '${src}' to a subdirectory of itself, '${dest}'.`)
1460
- }
1461
- return mayCopyDir$1(src, dest, opts)
1462
- }
1463
- return copyDir$1(src, dest, opts)
1464
- }
1465
-
1466
- function mayCopyDir$1 (src, dest, opts) {
1467
- if (!fs$e.statSync(dest).isDirectory()) {
1468
- throw new Error(`Cannot overwrite non-directory '${dest}' with directory '${src}'.`)
1469
- }
1470
- return copyDir$1(src, dest, opts)
1471
- }
1472
-
1473
- function mkDirAndCopy$1 (srcStat, src, dest, opts) {
1474
- fs$e.mkdirSync(dest, srcStat.mode);
1475
- fs$e.chmodSync(dest, srcStat.mode);
1476
- return copyDir$1(src, dest, opts)
1477
- }
1478
-
1479
- function copyDir$1 (src, dest, opts) {
1480
- fs$e.readdirSync(src).forEach(item => copyDirItem$1(item, src, dest, opts));
1481
- }
1482
-
1483
- function copyDirItem$1 (item, src, dest, opts) {
1484
- const srcItem = path$c.join(src, item);
1485
- const destItem = path$c.join(dest, item);
1486
- const resolvedDest = checkPaths$1(srcItem, destItem);
1487
- return startCopy$1(resolvedDest, srcItem, destItem, opts)
1488
- }
1489
-
1490
- function onLink$1 (resolvedDest, src, dest, opts) {
1491
- let resolvedSrc = fs$e.readlinkSync(src);
1492
-
1493
- if (opts.dereference) {
1494
- resolvedSrc = path$c.resolve(process.cwd(), resolvedSrc);
1495
- }
1496
-
1497
- if (resolvedDest === notExist$1 || resolvedDest === existsReg$1) {
1498
- // if dest already exists, fs throws error anyway,
1499
- // so no need to guard against it here.
1500
- return fs$e.symlinkSync(resolvedSrc, dest)
1501
- } else {
1502
- if (opts.dereference) {
1503
- resolvedDest = path$c.resolve(process.cwd(), resolvedDest);
1504
- }
1505
- if (pathsAreIdentical$1(resolvedSrc, resolvedDest)) return
1506
-
1507
- // prevent copy if src is a subdir of dest since unlinking
1508
- // dest in this case would result in removing src contents
1509
- // and therefore a broken symlink would be created.
1510
- if (fs$e.statSync(dest).isDirectory() && isSrcSubdir$3(resolvedDest, resolvedSrc)) {
1511
- throw new Error(`Cannot overwrite '${resolvedDest}' with '${resolvedSrc}'.`)
1512
- }
1513
- return copyLink$1(resolvedSrc, dest)
1514
- }
1515
- }
1516
-
1517
- function copyLink$1 (resolvedSrc, dest) {
1518
- fs$e.unlinkSync(dest);
1519
- return fs$e.symlinkSync(resolvedSrc, dest)
1520
- }
1521
-
1522
- // return true if dest is a subdir of src, otherwise false.
1523
- // extract dest base dir and check if that is the same as src basename.
1524
- function isSrcSubdir$3 (src, dest) {
1525
- const srcArray = path$c.resolve(src).split(path$c.sep);
1526
- const destArray = path$c.resolve(dest).split(path$c.sep);
1527
-
1528
- return srcArray.reduce((acc, current, i) => {
1529
- return acc && destArray[i] === current
1530
- }, true)
1531
- }
1532
-
1533
- // check if dest exists and is a symlink.
1534
- function checkDest$1 (dest) {
1535
- let resolvedPath;
1536
- try {
1537
- resolvedPath = fs$e.readlinkSync(dest);
1538
- } catch (err) {
1539
- if (err.code === 'ENOENT') return notExist$1
1540
-
1541
- // dest exists and is a regular file or directory, Windows may throw UNKNOWN error.
1542
- if (err.code === 'EINVAL' || err.code === 'UNKNOWN') return existsReg$1
1543
-
1544
- throw err
1545
- }
1546
- return resolvedPath // dest exists and is a symlink
1547
- }
1548
-
1549
- function pathsAreIdentical$1 (src, dest) {
1550
- const os = process.platform;
1551
- const resolvedSrc = path$c.resolve(src);
1552
- const resolvedDest = path$c.resolve(dest);
1553
- // case-insensitive paths
1554
- if (os === 'darwin' || os === 'win32') {
1555
- return resolvedSrc.toLowerCase() === resolvedDest.toLowerCase()
1556
- }
1557
- return resolvedSrc === resolvedDest
1558
- }
1559
-
1560
- function checkPaths$1 (src, dest) {
1561
- const resolvedDest = checkDest$1(dest);
1562
- if (resolvedDest === notExist$1 || resolvedDest === existsReg$1) {
1563
- if (pathsAreIdentical$1(src, dest)) throw new Error('Source and destination must not be the same.')
1564
- return resolvedDest
1565
- } else {
1566
- // check resolved dest path if dest is a symlink
1567
- if (pathsAreIdentical$1(src, resolvedDest)) throw new Error('Source and destination must not be the same.')
1568
- return resolvedDest
1569
- }
1570
- }
1571
-
1572
- var copySync_1 = copySync$2;
1573
-
1574
- var copySync$1 = {
1575
- copySync: copySync_1
1576
- };
1577
-
1578
- const u$a = universalify.fromPromise;
1579
- const fs$d = fs$j;
1580
-
1581
- function pathExists$8 (path) {
1582
- return fs$d.access(path).then(() => true).catch(() => false)
1583
- }
1584
-
1585
- var pathExists_1 = {
1586
- pathExists: u$a(pathExists$8),
1587
- pathExistsSync: fs$d.existsSync
1588
- };
1589
-
1590
- const fs$c = gracefulFs;
1591
- const path$b = path__default["default"];
1592
- const mkdirp$1 = mkdirs_1.mkdirs;
1593
- const pathExists$7 = pathExists_1.pathExists;
1594
- const utimes = utimes$1.utimesMillis;
1595
-
1596
- const notExist = Symbol('notExist');
1597
- const existsReg = Symbol('existsReg');
1598
-
1599
- function copy$2 (src, dest, opts, cb) {
1600
- if (typeof opts === 'function' && !cb) {
1601
- cb = opts;
1602
- opts = {};
1603
- } else if (typeof opts === 'function') {
1604
- opts = {filter: opts};
1605
- }
1606
-
1607
- cb = cb || function () {};
1608
- opts = opts || {};
1609
-
1610
- opts.clobber = 'clobber' in opts ? !!opts.clobber : true; // default to true for now
1611
- opts.overwrite = 'overwrite' in opts ? !!opts.overwrite : opts.clobber; // overwrite falls back to clobber
1612
-
1613
- // Warn about using preserveTimestamps on 32-bit node
1614
- if (opts.preserveTimestamps && process.arch === 'ia32') {
1615
- console.warn(`fs-extra: Using the preserveTimestamps option in 32-bit node is not recommended;\n
1616
- see https://github.com/jprichardson/node-fs-extra/issues/269`);
1617
- }
1618
-
1619
- checkPaths(src, dest, (err, resolvedDest) => {
1620
- if (err) return cb(err)
1621
- if (opts.filter) return handleFilter(checkParentDir, resolvedDest, src, dest, opts, cb)
1622
- return checkParentDir(resolvedDest, src, dest, opts, cb)
1623
- });
1624
- }
1625
-
1626
- function checkParentDir (resolvedDest, src, dest, opts, cb) {
1627
- const destParent = path$b.dirname(dest);
1628
- pathExists$7(destParent, (err, dirExists) => {
1629
- if (err) return cb(err)
1630
- if (dirExists) return startCopy(resolvedDest, src, dest, opts, cb)
1631
- mkdirp$1(destParent, err => {
1632
- if (err) return cb(err)
1633
- return startCopy(resolvedDest, src, dest, opts, cb)
1634
- });
1635
- });
1636
- }
1637
-
1638
- function startCopy (resolvedDest, src, dest, opts, cb) {
1639
- if (opts.filter) return handleFilter(getStats, resolvedDest, src, dest, opts, cb)
1640
- return getStats(resolvedDest, src, dest, opts, cb)
1641
- }
1642
-
1643
- function handleFilter (onInclude, resolvedDest, src, dest, opts, cb) {
1644
- Promise.resolve(opts.filter(src, dest)).then(include => {
1645
- if (include) {
1646
- if (resolvedDest) return onInclude(resolvedDest, src, dest, opts, cb)
1647
- return onInclude(src, dest, opts, cb)
1648
- }
1649
- return cb()
1650
- }, error => cb(error));
1651
- }
1652
-
1653
- function getStats (resolvedDest, src, dest, opts, cb) {
1654
- const stat = opts.dereference ? fs$c.stat : fs$c.lstat;
1655
- stat(src, (err, st) => {
1656
- if (err) return cb(err)
1657
-
1658
- if (st.isDirectory()) return onDir(st, resolvedDest, src, dest, opts, cb)
1659
- else if (st.isFile() ||
1660
- st.isCharacterDevice() ||
1661
- st.isBlockDevice()) return onFile(st, resolvedDest, src, dest, opts, cb)
1662
- else if (st.isSymbolicLink()) return onLink(resolvedDest, src, dest, opts, cb)
1663
- });
1664
- }
1665
-
1666
- function onFile (srcStat, resolvedDest, src, dest, opts, cb) {
1667
- if (resolvedDest === notExist) return copyFile(srcStat, src, dest, opts, cb)
1668
- else if (resolvedDest === existsReg) return mayCopyFile(srcStat, src, dest, opts, cb)
1669
- return mayCopyFile(srcStat, src, dest, opts, cb)
1670
- }
1671
-
1672
- function mayCopyFile (srcStat, src, dest, opts, cb) {
1673
- if (opts.overwrite) {
1674
- fs$c.unlink(dest, err => {
1675
- if (err) return cb(err)
1676
- return copyFile(srcStat, src, dest, opts, cb)
1677
- });
1678
- } else if (opts.errorOnExist) {
1679
- return cb(new Error(`'${dest}' already exists`))
1680
- } else return cb()
1681
- }
1682
-
1683
- function copyFile (srcStat, src, dest, opts, cb) {
1684
- if (typeof fs$c.copyFile === 'function') {
1685
- return fs$c.copyFile(src, dest, err => {
1686
- if (err) return cb(err)
1687
- return setDestModeAndTimestamps(srcStat, dest, opts, cb)
1688
- })
1689
- }
1690
- return copyFileFallback(srcStat, src, dest, opts, cb)
1691
- }
1692
-
1693
- function copyFileFallback (srcStat, src, dest, opts, cb) {
1694
- const rs = fs$c.createReadStream(src);
1695
- rs.on('error', err => cb(err)).once('open', () => {
1696
- const ws = fs$c.createWriteStream(dest, { mode: srcStat.mode });
1697
- ws.on('error', err => cb(err))
1698
- .on('open', () => rs.pipe(ws))
1699
- .once('close', () => setDestModeAndTimestamps(srcStat, dest, opts, cb));
1700
- });
1701
- }
1702
-
1703
- function setDestModeAndTimestamps (srcStat, dest, opts, cb) {
1704
- fs$c.chmod(dest, srcStat.mode, err => {
1705
- if (err) return cb(err)
1706
- if (opts.preserveTimestamps) {
1707
- return utimes(dest, srcStat.atime, srcStat.mtime, cb)
1708
- }
1709
- return cb()
1710
- });
1711
- }
1712
-
1713
- function onDir (srcStat, resolvedDest, src, dest, opts, cb) {
1714
- if (resolvedDest === notExist) {
1715
- if (isSrcSubdir$2(src, dest)) {
1716
- return cb(new Error(`Cannot copy '${src}' to a subdirectory of itself, '${dest}'.`))
1717
- }
1718
- return mkDirAndCopy(srcStat, src, dest, opts, cb)
1719
- } else if (resolvedDest === existsReg) {
1720
- if (isSrcSubdir$2(src, dest)) {
1721
- return cb(new Error(`Cannot copy '${src}' to a subdirectory of itself, '${dest}'.`))
1722
- }
1723
- return mayCopyDir(src, dest, opts, cb)
1724
- }
1725
- return copyDir(src, dest, opts, cb)
1726
- }
1727
-
1728
- function mayCopyDir (src, dest, opts, cb) {
1729
- fs$c.stat(dest, (err, st) => {
1730
- if (err) return cb(err)
1731
- if (!st.isDirectory()) {
1732
- return cb(new Error(`Cannot overwrite non-directory '${dest}' with directory '${src}'.`))
1733
- }
1734
- return copyDir(src, dest, opts, cb)
1735
- });
1736
- }
1737
-
1738
- function mkDirAndCopy (srcStat, src, dest, opts, cb) {
1739
- fs$c.mkdir(dest, srcStat.mode, err => {
1740
- if (err) return cb(err)
1741
- fs$c.chmod(dest, srcStat.mode, err => {
1742
- if (err) return cb(err)
1743
- return copyDir(src, dest, opts, cb)
1744
- });
1745
- });
1746
- }
1747
-
1748
- function copyDir (src, dest, opts, cb) {
1749
- fs$c.readdir(src, (err, items) => {
1750
- if (err) return cb(err)
1751
- return copyDirItems(items, src, dest, opts, cb)
1752
- });
1753
- }
1754
-
1755
- function copyDirItems (items, src, dest, opts, cb) {
1756
- const item = items.pop();
1757
- if (!item) return cb()
1758
- return copyDirItem(items, item, src, dest, opts, cb)
1759
- }
1760
-
1761
- function copyDirItem (items, item, src, dest, opts, cb) {
1762
- const srcItem = path$b.join(src, item);
1763
- const destItem = path$b.join(dest, item);
1764
- checkPaths(srcItem, destItem, (err, resolvedDest) => {
1765
- if (err) return cb(err)
1766
- startCopy(resolvedDest, srcItem, destItem, opts, err => {
1767
- if (err) return cb(err)
1768
- return copyDirItems(items, src, dest, opts, cb)
1769
- });
1770
- });
1771
- }
1772
-
1773
- function onLink (resolvedDest, src, dest, opts, cb) {
1774
- fs$c.readlink(src, (err, resolvedSrc) => {
1775
- if (err) return cb(err)
1776
-
1777
- if (opts.dereference) {
1778
- resolvedSrc = path$b.resolve(process.cwd(), resolvedSrc);
1779
- }
1780
-
1781
- if (resolvedDest === notExist || resolvedDest === existsReg) {
1782
- // if dest already exists, fs throws error anyway,
1783
- // so no need to guard against it here.
1784
- return fs$c.symlink(resolvedSrc, dest, cb)
1785
- } else {
1786
- if (opts.dereference) {
1787
- resolvedDest = path$b.resolve(process.cwd(), resolvedDest);
1788
- }
1789
- if (pathsAreIdentical(resolvedSrc, resolvedDest)) return cb()
1790
-
1791
- // prevent copy if src is a subdir of dest since unlinking
1792
- // dest in this case would result in removing src contents
1793
- // and therefore a broken symlink would be created.
1794
- fs$c.stat(dest, (err, st) => {
1795
- if (err) return cb(err)
1796
- if (st.isDirectory() && isSrcSubdir$2(resolvedDest, resolvedSrc)) {
1797
- return cb(new Error(`Cannot overwrite '${resolvedDest}' with '${resolvedSrc}'.`))
1798
- }
1799
- return copyLink(resolvedSrc, dest, cb)
1800
- });
1801
- }
1802
- });
1803
- }
1804
-
1805
- function copyLink (resolvedSrc, dest, cb) {
1806
- fs$c.unlink(dest, err => {
1807
- if (err) return cb(err)
1808
- return fs$c.symlink(resolvedSrc, dest, cb)
1809
- });
1810
- }
1811
-
1812
- // return true if dest is a subdir of src, otherwise false.
1813
- // extract dest base dir and check if that is the same as src basename.
1814
- function isSrcSubdir$2 (src, dest) {
1815
- const srcArray = path$b.resolve(src).split(path$b.sep);
1816
- const destArray = path$b.resolve(dest).split(path$b.sep);
1817
-
1818
- return srcArray.reduce((acc, current, i) => {
1819
- return acc && destArray[i] === current
1820
- }, true)
1821
- }
1822
-
1823
- // check if dest exists and is a symlink.
1824
- function checkDest (dest, cb) {
1825
- fs$c.readlink(dest, (err, resolvedPath) => {
1826
- if (err) {
1827
- if (err.code === 'ENOENT') return cb(null, notExist)
1828
-
1829
- // dest exists and is a regular file or directory, Windows may throw UNKNOWN error.
1830
- if (err.code === 'EINVAL' || err.code === 'UNKNOWN') return cb(null, existsReg)
1831
-
1832
- return cb(err)
1833
- }
1834
- return cb(null, resolvedPath) // dest exists and is a symlink
1835
- });
1836
- }
1837
-
1838
- function pathsAreIdentical (src, dest) {
1839
- const os = process.platform;
1840
- const resolvedSrc = path$b.resolve(src);
1841
- const resolvedDest = path$b.resolve(dest);
1842
- // case-insensitive paths
1843
- if (os === 'darwin' || os === 'win32') {
1844
- return resolvedSrc.toLowerCase() === resolvedDest.toLowerCase()
1845
- }
1846
- return resolvedSrc === resolvedDest
1847
- }
1848
-
1849
- function checkPaths (src, dest, cb) {
1850
- checkDest(dest, (err, resolvedDest) => {
1851
- if (err) return cb(err)
1852
- if (resolvedDest === notExist || resolvedDest === existsReg) {
1853
- if (pathsAreIdentical(src, dest)) return cb(new Error('Source and destination must not be the same.'))
1854
- return cb(null, resolvedDest)
1855
- } else {
1856
- // check resolved dest path if dest is a symlink
1857
- if (pathsAreIdentical(src, resolvedDest)) return cb(new Error('Source and destination must not be the same.'))
1858
- return cb(null, resolvedDest)
1859
- }
1860
- });
1861
- }
1862
-
1863
- var copy_1 = copy$2;
1864
-
1865
- const u$9 = universalify.fromCallback;
1866
- var copy$1 = {
1867
- copy: u$9(copy_1)
1868
- };
1869
-
1870
- const fs$b = gracefulFs;
1871
- const path$a = path__default["default"];
1872
- const assert = assert__default["default"];
1873
-
1874
- const isWindows = (process.platform === 'win32');
1875
-
1876
- function defaults (options) {
1877
- const methods = [
1878
- 'unlink',
1879
- 'chmod',
1880
- 'stat',
1881
- 'lstat',
1882
- 'rmdir',
1883
- 'readdir'
1884
- ];
1885
- methods.forEach(m => {
1886
- options[m] = options[m] || fs$b[m];
1887
- m = m + 'Sync';
1888
- options[m] = options[m] || fs$b[m];
1889
- });
1890
-
1891
- options.maxBusyTries = options.maxBusyTries || 3;
1892
- }
1893
-
1894
- function rimraf$1 (p, options, cb) {
1895
- let busyTries = 0;
1896
-
1897
- if (typeof options === 'function') {
1898
- cb = options;
1899
- options = {};
1900
- }
1901
-
1902
- assert(p, 'rimraf: missing path');
1903
- assert.strictEqual(typeof p, 'string', 'rimraf: path should be a string');
1904
- assert.strictEqual(typeof cb, 'function', 'rimraf: callback function required');
1905
- assert(options, 'rimraf: invalid options argument provided');
1906
- assert.strictEqual(typeof options, 'object', 'rimraf: options should be object');
1907
-
1908
- defaults(options);
1909
-
1910
- rimraf_(p, options, function CB (er) {
1911
- if (er) {
1912
- if ((er.code === 'EBUSY' || er.code === 'ENOTEMPTY' || er.code === 'EPERM') &&
1913
- busyTries < options.maxBusyTries) {
1914
- busyTries++;
1915
- const time = busyTries * 100;
1916
- // try again, with the same exact callback as this one.
1917
- return setTimeout(() => rimraf_(p, options, CB), time)
1918
- }
1919
-
1920
- // already gone
1921
- if (er.code === 'ENOENT') er = null;
1922
- }
1923
-
1924
- cb(er);
1925
- });
1926
- }
1927
-
1928
- // Two possible strategies.
1929
- // 1. Assume it's a file. unlink it, then do the dir stuff on EPERM or EISDIR
1930
- // 2. Assume it's a directory. readdir, then do the file stuff on ENOTDIR
1931
- //
1932
- // Both result in an extra syscall when you guess wrong. However, there
1933
- // are likely far more normal files in the world than directories. This
1934
- // is based on the assumption that a the average number of files per
1935
- // directory is >= 1.
1936
- //
1937
- // If anyone ever complains about this, then I guess the strategy could
1938
- // be made configurable somehow. But until then, YAGNI.
1939
- function rimraf_ (p, options, cb) {
1940
- assert(p);
1941
- assert(options);
1942
- assert(typeof cb === 'function');
1943
-
1944
- // sunos lets the root user unlink directories, which is... weird.
1945
- // so we have to lstat here and make sure it's not a dir.
1946
- options.lstat(p, (er, st) => {
1947
- if (er && er.code === 'ENOENT') {
1948
- return cb(null)
1949
- }
1950
-
1951
- // Windows can EPERM on stat. Life is suffering.
1952
- if (er && er.code === 'EPERM' && isWindows) {
1953
- return fixWinEPERM(p, options, er, cb)
1954
- }
1955
-
1956
- if (st && st.isDirectory()) {
1957
- return rmdir(p, options, er, cb)
1958
- }
1959
-
1960
- options.unlink(p, er => {
1961
- if (er) {
1962
- if (er.code === 'ENOENT') {
1963
- return cb(null)
1964
- }
1965
- if (er.code === 'EPERM') {
1966
- return (isWindows)
1967
- ? fixWinEPERM(p, options, er, cb)
1968
- : rmdir(p, options, er, cb)
1969
- }
1970
- if (er.code === 'EISDIR') {
1971
- return rmdir(p, options, er, cb)
1972
- }
1973
- }
1974
- return cb(er)
1975
- });
1976
- });
1977
- }
1978
-
1979
- function fixWinEPERM (p, options, er, cb) {
1980
- assert(p);
1981
- assert(options);
1982
- assert(typeof cb === 'function');
1983
- if (er) {
1984
- assert(er instanceof Error);
1985
- }
1986
-
1987
- options.chmod(p, 0o666, er2 => {
1988
- if (er2) {
1989
- cb(er2.code === 'ENOENT' ? null : er);
1990
- } else {
1991
- options.stat(p, (er3, stats) => {
1992
- if (er3) {
1993
- cb(er3.code === 'ENOENT' ? null : er);
1994
- } else if (stats.isDirectory()) {
1995
- rmdir(p, options, er, cb);
1996
- } else {
1997
- options.unlink(p, cb);
1998
- }
1999
- });
2000
- }
2001
- });
2002
- }
2003
-
2004
- function fixWinEPERMSync (p, options, er) {
2005
- let stats;
2006
-
2007
- assert(p);
2008
- assert(options);
2009
- if (er) {
2010
- assert(er instanceof Error);
2011
- }
2012
-
2013
- try {
2014
- options.chmodSync(p, 0o666);
2015
- } catch (er2) {
2016
- if (er2.code === 'ENOENT') {
2017
- return
2018
- } else {
2019
- throw er
2020
- }
2021
- }
2022
-
2023
- try {
2024
- stats = options.statSync(p);
2025
- } catch (er3) {
2026
- if (er3.code === 'ENOENT') {
2027
- return
2028
- } else {
2029
- throw er
2030
- }
2031
- }
2032
-
2033
- if (stats.isDirectory()) {
2034
- rmdirSync(p, options, er);
2035
- } else {
2036
- options.unlinkSync(p);
2037
- }
2038
- }
2039
-
2040
- function rmdir (p, options, originalEr, cb) {
2041
- assert(p);
2042
- assert(options);
2043
- if (originalEr) {
2044
- assert(originalEr instanceof Error);
2045
- }
2046
- assert(typeof cb === 'function');
2047
-
2048
- // try to rmdir first, and only readdir on ENOTEMPTY or EEXIST (SunOS)
2049
- // if we guessed wrong, and it's not a directory, then
2050
- // raise the original error.
2051
- options.rmdir(p, er => {
2052
- if (er && (er.code === 'ENOTEMPTY' || er.code === 'EEXIST' || er.code === 'EPERM')) {
2053
- rmkids(p, options, cb);
2054
- } else if (er && er.code === 'ENOTDIR') {
2055
- cb(originalEr);
2056
- } else {
2057
- cb(er);
2058
- }
2059
- });
2060
- }
2061
-
2062
- function rmkids (p, options, cb) {
2063
- assert(p);
2064
- assert(options);
2065
- assert(typeof cb === 'function');
2066
-
2067
- options.readdir(p, (er, files) => {
2068
- if (er) return cb(er)
2069
-
2070
- let n = files.length;
2071
- let errState;
2072
-
2073
- if (n === 0) return options.rmdir(p, cb)
2074
-
2075
- files.forEach(f => {
2076
- rimraf$1(path$a.join(p, f), options, er => {
2077
- if (errState) {
2078
- return
2079
- }
2080
- if (er) return cb(errState = er)
2081
- if (--n === 0) {
2082
- options.rmdir(p, cb);
2083
- }
2084
- });
2085
- });
2086
- });
2087
- }
2088
-
2089
- // this looks simpler, and is strictly *faster*, but will
2090
- // tie up the JavaScript thread and fail on excessively
2091
- // deep directory trees.
2092
- function rimrafSync (p, options) {
2093
- let st;
2094
-
2095
- options = options || {};
2096
- defaults(options);
2097
-
2098
- assert(p, 'rimraf: missing path');
2099
- assert.strictEqual(typeof p, 'string', 'rimraf: path should be a string');
2100
- assert(options, 'rimraf: missing options');
2101
- assert.strictEqual(typeof options, 'object', 'rimraf: options should be object');
2102
-
2103
- try {
2104
- st = options.lstatSync(p);
2105
- } catch (er) {
2106
- if (er.code === 'ENOENT') {
2107
- return
2108
- }
2109
-
2110
- // Windows can EPERM on stat. Life is suffering.
2111
- if (er.code === 'EPERM' && isWindows) {
2112
- fixWinEPERMSync(p, options, er);
2113
- }
2114
- }
2115
-
2116
- try {
2117
- // sunos lets the root user unlink directories, which is... weird.
2118
- if (st && st.isDirectory()) {
2119
- rmdirSync(p, options, null);
2120
- } else {
2121
- options.unlinkSync(p);
2122
- }
2123
- } catch (er) {
2124
- if (er.code === 'ENOENT') {
2125
- return
2126
- } else if (er.code === 'EPERM') {
2127
- return isWindows ? fixWinEPERMSync(p, options, er) : rmdirSync(p, options, er)
2128
- } else if (er.code !== 'EISDIR') {
2129
- throw er
2130
- }
2131
- rmdirSync(p, options, er);
2132
- }
2133
- }
2134
-
2135
- function rmdirSync (p, options, originalEr) {
2136
- assert(p);
2137
- assert(options);
2138
- if (originalEr) {
2139
- assert(originalEr instanceof Error);
2140
- }
2141
-
2142
- try {
2143
- options.rmdirSync(p);
2144
- } catch (er) {
2145
- if (er.code === 'ENOTDIR') {
2146
- throw originalEr
2147
- } else if (er.code === 'ENOTEMPTY' || er.code === 'EEXIST' || er.code === 'EPERM') {
2148
- rmkidsSync(p, options);
2149
- } else if (er.code !== 'ENOENT') {
2150
- throw er
2151
- }
2152
- }
2153
- }
2154
-
2155
- function rmkidsSync (p, options) {
2156
- assert(p);
2157
- assert(options);
2158
- options.readdirSync(p).forEach(f => rimrafSync(path$a.join(p, f), options));
2159
-
2160
- // We only end up here once we got ENOTEMPTY at least once, and
2161
- // at this point, we are guaranteed to have removed all the kids.
2162
- // So, we know that it won't be ENOENT or ENOTDIR or anything else.
2163
- // try really hard to delete stuff on windows, because it has a
2164
- // PROFOUNDLY annoying habit of not closing handles promptly when
2165
- // files are deleted, resulting in spurious ENOTEMPTY errors.
2166
- const retries = isWindows ? 100 : 1;
2167
- let i = 0;
2168
- do {
2169
- let threw = true;
2170
- try {
2171
- const ret = options.rmdirSync(p, options);
2172
- threw = false;
2173
- return ret
2174
- } finally {
2175
- if (++i < retries && threw) continue // eslint-disable-line
2176
- }
2177
- } while (true)
2178
- }
2179
-
2180
- var rimraf_1 = rimraf$1;
2181
- rimraf$1.sync = rimrafSync;
2182
-
2183
- const u$8 = universalify.fromCallback;
2184
- const rimraf = rimraf_1;
2185
-
2186
- var remove$2 = {
2187
- remove: u$8(rimraf),
2188
- removeSync: rimraf.sync
2189
- };
2190
-
2191
- const u$7 = universalify.fromCallback;
2192
- const fs$a = require$$1__default["default"];
2193
- const path$9 = path__default["default"];
2194
- const mkdir$5 = mkdirs_1;
2195
- const remove$1 = remove$2;
2196
-
2197
- const emptyDir = u$7(function emptyDir (dir, callback) {
2198
- callback = callback || function () {};
2199
- fs$a.readdir(dir, (err, items) => {
2200
- if (err) return mkdir$5.mkdirs(dir, callback)
2201
-
2202
- items = items.map(item => path$9.join(dir, item));
2203
-
2204
- deleteItem();
2205
-
2206
- function deleteItem () {
2207
- const item = items.pop();
2208
- if (!item) return callback()
2209
- remove$1.remove(item, err => {
2210
- if (err) return callback(err)
2211
- deleteItem();
2212
- });
2213
- }
2214
- });
2215
- });
2216
-
2217
- function emptyDirSync (dir) {
2218
- let items;
2219
- try {
2220
- items = fs$a.readdirSync(dir);
2221
- } catch (err) {
2222
- return mkdir$5.mkdirsSync(dir)
2223
- }
2224
-
2225
- items.forEach(item => {
2226
- item = path$9.join(dir, item);
2227
- remove$1.removeSync(item);
2228
- });
2229
- }
2230
-
2231
- var empty = {
2232
- emptyDirSync,
2233
- emptydirSync: emptyDirSync,
2234
- emptyDir,
2235
- emptydir: emptyDir
2236
- };
2237
-
2238
- const u$6 = universalify.fromCallback;
2239
- const path$8 = path__default["default"];
2240
- const fs$9 = gracefulFs;
2241
- const mkdir$4 = mkdirs_1;
2242
- const pathExists$6 = pathExists_1.pathExists;
2243
-
2244
- function createFile (file, callback) {
2245
- function makeFile () {
2246
- fs$9.writeFile(file, '', err => {
2247
- if (err) return callback(err)
2248
- callback();
2249
- });
2250
- }
2251
-
2252
- fs$9.stat(file, (err, stats) => { // eslint-disable-line handle-callback-err
2253
- if (!err && stats.isFile()) return callback()
2254
- const dir = path$8.dirname(file);
2255
- pathExists$6(dir, (err, dirExists) => {
2256
- if (err) return callback(err)
2257
- if (dirExists) return makeFile()
2258
- mkdir$4.mkdirs(dir, err => {
2259
- if (err) return callback(err)
2260
- makeFile();
2261
- });
2262
- });
2263
- });
2264
- }
2265
-
2266
- function createFileSync (file) {
2267
- let stats;
2268
- try {
2269
- stats = fs$9.statSync(file);
2270
- } catch (e) {}
2271
- if (stats && stats.isFile()) return
2272
-
2273
- const dir = path$8.dirname(file);
2274
- if (!fs$9.existsSync(dir)) {
2275
- mkdir$4.mkdirsSync(dir);
2276
- }
2277
-
2278
- fs$9.writeFileSync(file, '');
2279
- }
2280
-
2281
- var file$1 = {
2282
- createFile: u$6(createFile),
2283
- createFileSync
2284
- };
2285
-
2286
- const u$5 = universalify.fromCallback;
2287
- const path$7 = path__default["default"];
2288
- const fs$8 = gracefulFs;
2289
- const mkdir$3 = mkdirs_1;
2290
- const pathExists$5 = pathExists_1.pathExists;
2291
-
2292
- function createLink (srcpath, dstpath, callback) {
2293
- function makeLink (srcpath, dstpath) {
2294
- fs$8.link(srcpath, dstpath, err => {
2295
- if (err) return callback(err)
2296
- callback(null);
2297
- });
2298
- }
2299
-
2300
- pathExists$5(dstpath, (err, destinationExists) => {
2301
- if (err) return callback(err)
2302
- if (destinationExists) return callback(null)
2303
- fs$8.lstat(srcpath, (err) => {
2304
- if (err) {
2305
- err.message = err.message.replace('lstat', 'ensureLink');
2306
- return callback(err)
2307
- }
2308
-
2309
- const dir = path$7.dirname(dstpath);
2310
- pathExists$5(dir, (err, dirExists) => {
2311
- if (err) return callback(err)
2312
- if (dirExists) return makeLink(srcpath, dstpath)
2313
- mkdir$3.mkdirs(dir, err => {
2314
- if (err) return callback(err)
2315
- makeLink(srcpath, dstpath);
2316
- });
2317
- });
2318
- });
2319
- });
2320
- }
2321
-
2322
- function createLinkSync (srcpath, dstpath) {
2323
- const destinationExists = fs$8.existsSync(dstpath);
2324
- if (destinationExists) return undefined
2325
-
2326
- try {
2327
- fs$8.lstatSync(srcpath);
2328
- } catch (err) {
2329
- err.message = err.message.replace('lstat', 'ensureLink');
2330
- throw err
2331
- }
2332
-
2333
- const dir = path$7.dirname(dstpath);
2334
- const dirExists = fs$8.existsSync(dir);
2335
- if (dirExists) return fs$8.linkSync(srcpath, dstpath)
2336
- mkdir$3.mkdirsSync(dir);
2337
-
2338
- return fs$8.linkSync(srcpath, dstpath)
2339
- }
2340
-
2341
- var link$1 = {
2342
- createLink: u$5(createLink),
2343
- createLinkSync
2344
- };
2345
-
2346
- const path$6 = path__default["default"];
2347
- const fs$7 = gracefulFs;
2348
- const pathExists$4 = pathExists_1.pathExists;
2349
-
2350
- /**
2351
- * Function that returns two types of paths, one relative to symlink, and one
2352
- * relative to the current working directory. Checks if path is absolute or
2353
- * relative. If the path is relative, this function checks if the path is
2354
- * relative to symlink or relative to current working directory. This is an
2355
- * initiative to find a smarter `srcpath` to supply when building symlinks.
2356
- * This allows you to determine which path to use out of one of three possible
2357
- * types of source paths. The first is an absolute path. This is detected by
2358
- * `path.isAbsolute()`. When an absolute path is provided, it is checked to
2359
- * see if it exists. If it does it's used, if not an error is returned
2360
- * (callback)/ thrown (sync). The other two options for `srcpath` are a
2361
- * relative url. By default Node's `fs.symlink` works by creating a symlink
2362
- * using `dstpath` and expects the `srcpath` to be relative to the newly
2363
- * created symlink. If you provide a `srcpath` that does not exist on the file
2364
- * system it results in a broken symlink. To minimize this, the function
2365
- * checks to see if the 'relative to symlink' source file exists, and if it
2366
- * does it will use it. If it does not, it checks if there's a file that
2367
- * exists that is relative to the current working directory, if does its used.
2368
- * This preserves the expectations of the original fs.symlink spec and adds
2369
- * the ability to pass in `relative to current working direcotry` paths.
2370
- */
2371
-
2372
- function symlinkPaths$1 (srcpath, dstpath, callback) {
2373
- if (path$6.isAbsolute(srcpath)) {
2374
- return fs$7.lstat(srcpath, (err) => {
2375
- if (err) {
2376
- err.message = err.message.replace('lstat', 'ensureSymlink');
2377
- return callback(err)
2378
- }
2379
- return callback(null, {
2380
- 'toCwd': srcpath,
2381
- 'toDst': srcpath
2382
- })
2383
- })
2384
- } else {
2385
- const dstdir = path$6.dirname(dstpath);
2386
- const relativeToDst = path$6.join(dstdir, srcpath);
2387
- return pathExists$4(relativeToDst, (err, exists) => {
2388
- if (err) return callback(err)
2389
- if (exists) {
2390
- return callback(null, {
2391
- 'toCwd': relativeToDst,
2392
- 'toDst': srcpath
2393
- })
2394
- } else {
2395
- return fs$7.lstat(srcpath, (err) => {
2396
- if (err) {
2397
- err.message = err.message.replace('lstat', 'ensureSymlink');
2398
- return callback(err)
2399
- }
2400
- return callback(null, {
2401
- 'toCwd': srcpath,
2402
- 'toDst': path$6.relative(dstdir, srcpath)
2403
- })
2404
- })
2405
- }
2406
- })
2407
- }
2408
- }
2409
-
2410
- function symlinkPathsSync$1 (srcpath, dstpath) {
2411
- let exists;
2412
- if (path$6.isAbsolute(srcpath)) {
2413
- exists = fs$7.existsSync(srcpath);
2414
- if (!exists) throw new Error('absolute srcpath does not exist')
2415
- return {
2416
- 'toCwd': srcpath,
2417
- 'toDst': srcpath
2418
- }
2419
- } else {
2420
- const dstdir = path$6.dirname(dstpath);
2421
- const relativeToDst = path$6.join(dstdir, srcpath);
2422
- exists = fs$7.existsSync(relativeToDst);
2423
- if (exists) {
2424
- return {
2425
- 'toCwd': relativeToDst,
2426
- 'toDst': srcpath
2427
- }
2428
- } else {
2429
- exists = fs$7.existsSync(srcpath);
2430
- if (!exists) throw new Error('relative srcpath does not exist')
2431
- return {
2432
- 'toCwd': srcpath,
2433
- 'toDst': path$6.relative(dstdir, srcpath)
2434
- }
2435
- }
2436
- }
2437
- }
2438
-
2439
- var symlinkPaths_1 = {
2440
- symlinkPaths: symlinkPaths$1,
2441
- symlinkPathsSync: symlinkPathsSync$1
2442
- };
2443
-
2444
- const fs$6 = gracefulFs;
2445
-
2446
- function symlinkType$1 (srcpath, type, callback) {
2447
- callback = (typeof type === 'function') ? type : callback;
2448
- type = (typeof type === 'function') ? false : type;
2449
- if (type) return callback(null, type)
2450
- fs$6.lstat(srcpath, (err, stats) => {
2451
- if (err) return callback(null, 'file')
2452
- type = (stats && stats.isDirectory()) ? 'dir' : 'file';
2453
- callback(null, type);
2454
- });
2455
- }
2456
-
2457
- function symlinkTypeSync$1 (srcpath, type) {
2458
- let stats;
2459
-
2460
- if (type) return type
2461
- try {
2462
- stats = fs$6.lstatSync(srcpath);
2463
- } catch (e) {
2464
- return 'file'
2465
- }
2466
- return (stats && stats.isDirectory()) ? 'dir' : 'file'
2467
- }
2468
-
2469
- var symlinkType_1 = {
2470
- symlinkType: symlinkType$1,
2471
- symlinkTypeSync: symlinkTypeSync$1
2472
- };
2473
-
2474
- const u$4 = universalify.fromCallback;
2475
- const path$5 = path__default["default"];
2476
- const fs$5 = gracefulFs;
2477
- const _mkdirs = mkdirs_1;
2478
- const mkdirs = _mkdirs.mkdirs;
2479
- const mkdirsSync = _mkdirs.mkdirsSync;
2480
-
2481
- const _symlinkPaths = symlinkPaths_1;
2482
- const symlinkPaths = _symlinkPaths.symlinkPaths;
2483
- const symlinkPathsSync = _symlinkPaths.symlinkPathsSync;
2484
-
2485
- const _symlinkType = symlinkType_1;
2486
- const symlinkType = _symlinkType.symlinkType;
2487
- const symlinkTypeSync = _symlinkType.symlinkTypeSync;
2488
-
2489
- const pathExists$3 = pathExists_1.pathExists;
2490
-
2491
- function createSymlink (srcpath, dstpath, type, callback) {
2492
- callback = (typeof type === 'function') ? type : callback;
2493
- type = (typeof type === 'function') ? false : type;
2494
-
2495
- pathExists$3(dstpath, (err, destinationExists) => {
2496
- if (err) return callback(err)
2497
- if (destinationExists) return callback(null)
2498
- symlinkPaths(srcpath, dstpath, (err, relative) => {
2499
- if (err) return callback(err)
2500
- srcpath = relative.toDst;
2501
- symlinkType(relative.toCwd, type, (err, type) => {
2502
- if (err) return callback(err)
2503
- const dir = path$5.dirname(dstpath);
2504
- pathExists$3(dir, (err, dirExists) => {
2505
- if (err) return callback(err)
2506
- if (dirExists) return fs$5.symlink(srcpath, dstpath, type, callback)
2507
- mkdirs(dir, err => {
2508
- if (err) return callback(err)
2509
- fs$5.symlink(srcpath, dstpath, type, callback);
2510
- });
2511
- });
2512
- });
2513
- });
2514
- });
2515
- }
2516
-
2517
- function createSymlinkSync (srcpath, dstpath, type) {
2518
- const destinationExists = fs$5.existsSync(dstpath);
2519
- if (destinationExists) return undefined
2520
-
2521
- const relative = symlinkPathsSync(srcpath, dstpath);
2522
- srcpath = relative.toDst;
2523
- type = symlinkTypeSync(relative.toCwd, type);
2524
- const dir = path$5.dirname(dstpath);
2525
- const exists = fs$5.existsSync(dir);
2526
- if (exists) return fs$5.symlinkSync(srcpath, dstpath, type)
2527
- mkdirsSync(dir);
2528
- return fs$5.symlinkSync(srcpath, dstpath, type)
2529
- }
2530
-
2531
- var symlink$1 = {
2532
- createSymlink: u$4(createSymlink),
2533
- createSymlinkSync
2534
- };
2535
-
2536
- const file = file$1;
2537
- const link = link$1;
2538
- const symlink = symlink$1;
2539
-
2540
- var ensure = {
2541
- // file
2542
- createFile: file.createFile,
2543
- createFileSync: file.createFileSync,
2544
- ensureFile: file.createFile,
2545
- ensureFileSync: file.createFileSync,
2546
- // link
2547
- createLink: link.createLink,
2548
- createLinkSync: link.createLinkSync,
2549
- ensureLink: link.createLink,
2550
- ensureLinkSync: link.createLinkSync,
2551
- // symlink
2552
- createSymlink: symlink.createSymlink,
2553
- createSymlinkSync: symlink.createSymlinkSync,
2554
- ensureSymlink: symlink.createSymlink,
2555
- ensureSymlinkSync: symlink.createSymlinkSync
2556
- };
2557
-
2558
- var _fs;
2559
- try {
2560
- _fs = gracefulFs;
2561
- } catch (_) {
2562
- _fs = require$$1__default["default"];
2563
- }
2564
-
2565
- function readFile (file, options, callback) {
2566
- if (callback == null) {
2567
- callback = options;
2568
- options = {};
2569
- }
2570
-
2571
- if (typeof options === 'string') {
2572
- options = {encoding: options};
2573
- }
2574
-
2575
- options = options || {};
2576
- var fs = options.fs || _fs;
2577
-
2578
- var shouldThrow = true;
2579
- if ('throws' in options) {
2580
- shouldThrow = options.throws;
2581
- }
2582
-
2583
- fs.readFile(file, options, function (err, data) {
2584
- if (err) return callback(err)
2585
-
2586
- data = stripBom(data);
2587
-
2588
- var obj;
2589
- try {
2590
- obj = JSON.parse(data, options ? options.reviver : null);
2591
- } catch (err2) {
2592
- if (shouldThrow) {
2593
- err2.message = file + ': ' + err2.message;
2594
- return callback(err2)
2595
- } else {
2596
- return callback(null, null)
2597
- }
2598
- }
2599
-
2600
- callback(null, obj);
2601
- });
2602
- }
2603
-
2604
- function readFileSync (file, options) {
2605
- options = options || {};
2606
- if (typeof options === 'string') {
2607
- options = {encoding: options};
2608
- }
2609
-
2610
- var fs = options.fs || _fs;
2611
-
2612
- var shouldThrow = true;
2613
- if ('throws' in options) {
2614
- shouldThrow = options.throws;
2615
- }
2616
-
2617
- try {
2618
- var content = fs.readFileSync(file, options);
2619
- content = stripBom(content);
2620
- return JSON.parse(content, options.reviver)
2621
- } catch (err) {
2622
- if (shouldThrow) {
2623
- err.message = file + ': ' + err.message;
2624
- throw err
2625
- } else {
2626
- return null
2627
- }
2628
- }
2629
- }
2630
-
2631
- function stringify (obj, options) {
2632
- var spaces;
2633
- var EOL = '\n';
2634
- if (typeof options === 'object' && options !== null) {
2635
- if (options.spaces) {
2636
- spaces = options.spaces;
2637
- }
2638
- if (options.EOL) {
2639
- EOL = options.EOL;
2640
- }
2641
- }
2642
-
2643
- var str = JSON.stringify(obj, options ? options.replacer : null, spaces);
2644
-
2645
- return str.replace(/\n/g, EOL) + EOL
2646
- }
2647
-
2648
- function writeFile (file, obj, options, callback) {
2649
- if (callback == null) {
2650
- callback = options;
2651
- options = {};
2652
- }
2653
- options = options || {};
2654
- var fs = options.fs || _fs;
2655
-
2656
- var str = '';
2657
- try {
2658
- str = stringify(obj, options);
2659
- } catch (err) {
2660
- // Need to return whether a callback was passed or not
2661
- if (callback) callback(err, null);
2662
- return
2663
- }
2664
-
2665
- fs.writeFile(file, str, options, callback);
2666
- }
2667
-
2668
- function writeFileSync (file, obj, options) {
2669
- options = options || {};
2670
- var fs = options.fs || _fs;
2671
-
2672
- var str = stringify(obj, options);
2673
- // not sure if fs.writeFileSync returns anything, but just in case
2674
- return fs.writeFileSync(file, str, options)
2675
- }
2676
-
2677
- function stripBom (content) {
2678
- // we do this because JSON.parse would convert it to a utf8 string if encoding wasn't specified
2679
- if (Buffer.isBuffer(content)) content = content.toString('utf8');
2680
- content = content.replace(/^\uFEFF/, '');
2681
- return content
2682
- }
2683
-
2684
- var jsonfile$1 = {
2685
- readFile: readFile,
2686
- readFileSync: readFileSync,
2687
- writeFile: writeFile,
2688
- writeFileSync: writeFileSync
2689
- };
2690
-
2691
- var jsonfile_1 = jsonfile$1;
2692
-
2693
- const u$3 = universalify.fromCallback;
2694
- const jsonFile$3 = jsonfile_1;
2695
-
2696
- var jsonfile = {
2697
- // jsonfile exports
2698
- readJson: u$3(jsonFile$3.readFile),
2699
- readJsonSync: jsonFile$3.readFileSync,
2700
- writeJson: u$3(jsonFile$3.writeFile),
2701
- writeJsonSync: jsonFile$3.writeFileSync
2702
- };
2703
-
2704
- const path$4 = path__default["default"];
2705
- const mkdir$2 = mkdirs_1;
2706
- const pathExists$2 = pathExists_1.pathExists;
2707
- const jsonFile$2 = jsonfile;
2708
-
2709
- function outputJson (file, data, options, callback) {
2710
- if (typeof options === 'function') {
2711
- callback = options;
2712
- options = {};
2713
- }
2714
-
2715
- const dir = path$4.dirname(file);
2716
-
2717
- pathExists$2(dir, (err, itDoes) => {
2718
- if (err) return callback(err)
2719
- if (itDoes) return jsonFile$2.writeJson(file, data, options, callback)
2720
-
2721
- mkdir$2.mkdirs(dir, err => {
2722
- if (err) return callback(err)
2723
- jsonFile$2.writeJson(file, data, options, callback);
2724
- });
2725
- });
2726
- }
2727
-
2728
- var outputJson_1 = outputJson;
2729
-
2730
- const fs$4 = gracefulFs;
2731
- const path$3 = path__default["default"];
2732
- const mkdir$1 = mkdirs_1;
2733
- const jsonFile$1 = jsonfile;
2734
-
2735
- function outputJsonSync (file, data, options) {
2736
- const dir = path$3.dirname(file);
2737
-
2738
- if (!fs$4.existsSync(dir)) {
2739
- mkdir$1.mkdirsSync(dir);
2740
- }
2741
-
2742
- jsonFile$1.writeJsonSync(file, data, options);
2743
- }
2744
-
2745
- var outputJsonSync_1 = outputJsonSync;
2746
-
2747
- const u$2 = universalify.fromCallback;
2748
- const jsonFile = jsonfile;
2749
-
2750
- jsonFile.outputJson = u$2(outputJson_1);
2751
- jsonFile.outputJsonSync = outputJsonSync_1;
2752
- // aliases
2753
- jsonFile.outputJSON = jsonFile.outputJson;
2754
- jsonFile.outputJSONSync = jsonFile.outputJsonSync;
2755
- jsonFile.writeJSON = jsonFile.writeJson;
2756
- jsonFile.writeJSONSync = jsonFile.writeJsonSync;
2757
- jsonFile.readJSON = jsonFile.readJson;
2758
- jsonFile.readJSONSync = jsonFile.readJsonSync;
2759
-
2760
- var json = jsonFile;
2761
-
2762
- const fs$3 = gracefulFs;
2763
- const path$2 = path__default["default"];
2764
- const copySync = copySync$1.copySync;
2765
- const removeSync = remove$2.removeSync;
2766
- const mkdirpSync = mkdirs_1.mkdirsSync;
2767
- const buffer = buffer$1;
2768
-
2769
- function moveSync (src, dest, options) {
2770
- options = options || {};
2771
- const overwrite = options.overwrite || options.clobber || false;
2772
-
2773
- src = path$2.resolve(src);
2774
- dest = path$2.resolve(dest);
2775
-
2776
- if (src === dest) return fs$3.accessSync(src)
2777
-
2778
- if (isSrcSubdir$1(src, dest)) throw new Error(`Cannot move '${src}' into itself '${dest}'.`)
2779
-
2780
- mkdirpSync(path$2.dirname(dest));
2781
- tryRenameSync();
2782
-
2783
- function tryRenameSync () {
2784
- if (overwrite) {
2785
- try {
2786
- return fs$3.renameSync(src, dest)
2787
- } catch (err) {
2788
- if (err.code === 'ENOTEMPTY' || err.code === 'EEXIST' || err.code === 'EPERM') {
2789
- removeSync(dest);
2790
- options.overwrite = false; // just overwriteed it, no need to do it again
2791
- return moveSync(src, dest, options)
2792
- }
2793
-
2794
- if (err.code !== 'EXDEV') throw err
2795
- return moveSyncAcrossDevice(src, dest, overwrite)
2796
- }
2797
- } else {
2798
- try {
2799
- fs$3.linkSync(src, dest);
2800
- return fs$3.unlinkSync(src)
2801
- } catch (err) {
2802
- if (err.code === 'EXDEV' || err.code === 'EISDIR' || err.code === 'EPERM' || err.code === 'ENOTSUP') {
2803
- return moveSyncAcrossDevice(src, dest, overwrite)
2804
- }
2805
- throw err
2806
- }
2807
- }
2808
- }
2809
- }
2810
-
2811
- function moveSyncAcrossDevice (src, dest, overwrite) {
2812
- const stat = fs$3.statSync(src);
2813
-
2814
- if (stat.isDirectory()) {
2815
- return moveDirSyncAcrossDevice(src, dest, overwrite)
2816
- } else {
2817
- return moveFileSyncAcrossDevice(src, dest, overwrite)
2818
- }
2819
- }
2820
-
2821
- function moveFileSyncAcrossDevice (src, dest, overwrite) {
2822
- const BUF_LENGTH = 64 * 1024;
2823
- const _buff = buffer(BUF_LENGTH);
2824
-
2825
- const flags = overwrite ? 'w' : 'wx';
2826
-
2827
- const fdr = fs$3.openSync(src, 'r');
2828
- const stat = fs$3.fstatSync(fdr);
2829
- const fdw = fs$3.openSync(dest, flags, stat.mode);
2830
- let pos = 0;
2831
-
2832
- while (pos < stat.size) {
2833
- const bytesRead = fs$3.readSync(fdr, _buff, 0, BUF_LENGTH, pos);
2834
- fs$3.writeSync(fdw, _buff, 0, bytesRead);
2835
- pos += bytesRead;
2836
- }
2837
-
2838
- fs$3.closeSync(fdr);
2839
- fs$3.closeSync(fdw);
2840
- return fs$3.unlinkSync(src)
2841
- }
2842
-
2843
- function moveDirSyncAcrossDevice (src, dest, overwrite) {
2844
- const options = {
2845
- overwrite: false
2846
- };
2847
-
2848
- if (overwrite) {
2849
- removeSync(dest);
2850
- tryCopySync();
2851
- } else {
2852
- tryCopySync();
2853
- }
2854
-
2855
- function tryCopySync () {
2856
- copySync(src, dest, options);
2857
- return removeSync(src)
2858
- }
2859
- }
2860
-
2861
- // return true if dest is a subdir of src, otherwise false.
2862
- // extract dest base dir and check if that is the same as src basename
2863
- function isSrcSubdir$1 (src, dest) {
2864
- try {
2865
- return fs$3.statSync(src).isDirectory() &&
2866
- src !== dest &&
2867
- dest.indexOf(src) > -1 &&
2868
- dest.split(path$2.dirname(src) + path$2.sep)[1].split(path$2.sep)[0] === path$2.basename(src)
2869
- } catch (e) {
2870
- return false
2871
- }
2872
- }
2873
-
2874
- var moveSync_1 = {
2875
- moveSync
2876
- };
2877
-
2878
- const u$1 = universalify.fromCallback;
2879
- const fs$2 = gracefulFs;
2880
- const path$1 = path__default["default"];
2881
- const copy = copy$1.copy;
2882
- const remove = remove$2.remove;
2883
- const mkdirp = mkdirs_1.mkdirp;
2884
- const pathExists$1 = pathExists_1.pathExists;
2885
-
2886
- function move (src, dest, opts, cb) {
2887
- if (typeof opts === 'function') {
2888
- cb = opts;
2889
- opts = {};
2890
- }
2891
-
2892
- const overwrite = opts.overwrite || opts.clobber || false;
2893
-
2894
- src = path$1.resolve(src);
2895
- dest = path$1.resolve(dest);
2896
-
2897
- if (src === dest) return fs$2.access(src, cb)
2898
-
2899
- fs$2.stat(src, (err, st) => {
2900
- if (err) return cb(err)
2901
-
2902
- if (st.isDirectory() && isSrcSubdir(src, dest)) {
2903
- return cb(new Error(`Cannot move '${src}' to a subdirectory of itself, '${dest}'.`))
2904
- }
2905
- mkdirp(path$1.dirname(dest), err => {
2906
- if (err) return cb(err)
2907
- return doRename(src, dest, overwrite, cb)
2908
- });
2909
- });
2910
- }
2911
-
2912
- function doRename (src, dest, overwrite, cb) {
2913
- if (overwrite) {
2914
- return remove(dest, err => {
2915
- if (err) return cb(err)
2916
- return rename(src, dest, overwrite, cb)
2917
- })
2918
- }
2919
- pathExists$1(dest, (err, destExists) => {
2920
- if (err) return cb(err)
2921
- if (destExists) return cb(new Error('dest already exists.'))
2922
- return rename(src, dest, overwrite, cb)
2923
- });
2924
- }
2925
-
2926
- function rename (src, dest, overwrite, cb) {
2927
- fs$2.rename(src, dest, err => {
2928
- if (!err) return cb()
2929
- if (err.code !== 'EXDEV') return cb(err)
2930
- return moveAcrossDevice(src, dest, overwrite, cb)
2931
- });
2932
- }
2933
-
2934
- function moveAcrossDevice (src, dest, overwrite, cb) {
2935
- const opts = {
2936
- overwrite,
2937
- errorOnExist: true
2938
- };
2939
-
2940
- copy(src, dest, opts, err => {
2941
- if (err) return cb(err)
2942
- return remove(src, cb)
2943
- });
2944
- }
2945
-
2946
- function isSrcSubdir (src, dest) {
2947
- const srcArray = src.split(path$1.sep);
2948
- const destArray = dest.split(path$1.sep);
2949
-
2950
- return srcArray.reduce((acc, current, i) => {
2951
- return acc && destArray[i] === current
2952
- }, true)
2953
- }
2954
-
2955
- var move_1 = {
2956
- move: u$1(move)
2957
- };
2958
-
2959
- const u = universalify.fromCallback;
2960
- const fs$1 = gracefulFs;
2961
- const path = path__default["default"];
2962
- const mkdir = mkdirs_1;
2963
- const pathExists = pathExists_1.pathExists;
2964
-
2965
- function outputFile (file, data, encoding, callback) {
2966
- if (typeof encoding === 'function') {
2967
- callback = encoding;
2968
- encoding = 'utf8';
2969
- }
2970
-
2971
- const dir = path.dirname(file);
2972
- pathExists(dir, (err, itDoes) => {
2973
- if (err) return callback(err)
2974
- if (itDoes) return fs$1.writeFile(file, data, encoding, callback)
2975
-
2976
- mkdir.mkdirs(dir, err => {
2977
- if (err) return callback(err)
2978
-
2979
- fs$1.writeFile(file, data, encoding, callback);
2980
- });
2981
- });
2982
- }
2983
-
2984
- function outputFileSync (file, ...args) {
2985
- const dir = path.dirname(file);
2986
- if (fs$1.existsSync(dir)) {
2987
- return fs$1.writeFileSync(file, ...args)
2988
- }
2989
- mkdir.mkdirsSync(dir);
2990
- fs$1.writeFileSync(file, ...args);
2991
- }
2992
-
2993
- var output = {
2994
- outputFile: u(outputFile),
2995
- outputFileSync
2996
- };
2997
-
2998
- (function (module) {
2999
-
3000
- module.exports = Object.assign(
3001
- {},
3002
- // Export promiseified graceful-fs:
3003
- fs$j,
3004
- // Export extra methods:
3005
- copySync$1,
3006
- copy$1,
3007
- empty,
3008
- ensure,
3009
- json,
3010
- mkdirs_1,
3011
- moveSync_1,
3012
- move_1,
3013
- output,
3014
- pathExists_1,
3015
- remove$2
3016
- );
3017
-
3018
- // Export fs.promises as a getter property so that we don't trigger
3019
- // ExperimentalWarning before fs.promises is actually accessed.
3020
- const fs = require$$1__default["default"];
3021
- if (Object.getOwnPropertyDescriptor(fs, 'promises')) {
3022
- Object.defineProperty(module.exports, 'promises', {
3023
- get () { return fs.promises }
3024
- });
3025
- }
3026
- } (lib));
3027
-
3028
- var fs = libExports;
3029
-
3030
- // Padded canonical prefixes for DWARF path patching. The fisk client scans
3031
- // compiled objects for these byte patterns and overwrites them in-place with
3032
- // the real paths. Because the replacement is always shorter, a NUL terminator
3033
- // followed by NUL fill fits inside the original region. This works on both ELF
3034
- // objects and LTO bitcode.
3035
- //
3036
- // The length is PATH_MAX so any path the client could legally hand us fits
3037
- // without truncation.
3038
- // Keep in sync with FISK_PAD_LENGTH in src/client/FiskPathPatcher.cpp.
3039
- const FISK_PAD_LENGTH = 4096;
3040
- const FISK_NAME_PAD = "/fisk-name" + "_".repeat(FISK_PAD_LENGTH - "/fisk-name".length);
3041
- const FISK_CDIR_PAD = "/fisk-cdir" + "_".repeat(FISK_PAD_LENGTH - "/fisk-cdir".length);
3042
- // Flags asking the compiler to record its own argv, mapped to the negation the
3043
- // same compiler spells it with. -g* forms land in DW_AT_producer, -f* forms in a
3044
- // .GCC.command.line section; clang uses the command-line names and also accepts
3045
- // the gcc-switches ones as aliases.
3046
- const RECORD_FLAG_NEGATIONS = {
3047
- "-grecord-command-line": "-gno-record-command-line",
3048
- "-frecord-command-line": "-fno-record-command-line",
3049
- "-grecord-gcc-switches": "-gno-record-gcc-switches",
3050
- "-frecord-gcc-switches": "-fno-record-gcc-switches"
3051
- };
3052
- class Compile extends EventEmitter__default["default"] {
3053
- constructor(args, argv0, dir, debug, sourceFileName, paddedPaths) {
3054
- super();
3055
- if (!args || !args.length || !dir || !argv0) {
3056
- console.error(argv0, args, dir);
3057
- throw new Error("Bad args");
3058
- }
3059
- const compiler = args.shift();
3060
- if (compiler === undefined) {
3061
- console.error(argv0, args, dir);
3062
- throw new Error("Bad args");
3063
- }
3064
- const isClang = compiler.indexOf("clang") !== -1;
3065
- let output;
3066
- let outputFileName;
3067
- let hasDashO = false;
3068
- let hasDashX = false;
3069
- let sourcePath;
3070
- for (let i = 0; i < args.length; ++i) {
3071
- // console.log(i, args[i]);
3072
- switch (args[i]) {
3073
- case "-o": {
3074
- hasDashO = true;
3075
- output = args[++i];
3076
- outputFileName = path__default["default"].basename(output);
3077
- args[i] = outputFileName;
3078
- break;
3079
- }
3080
- case "-MF": {
3081
- args.splice(i--, 2);
3082
- break;
3083
- }
3084
- case "-MMD":
3085
- case "-MD":
3086
- case "-MM":
3087
- case "-M":
3088
- args.splice(i--, 1);
3089
- continue;
3090
- case "-MT":
3091
- args.splice(i--, 2);
3092
- continue;
3093
- case "-cxx-isystem":
3094
- case "-isysroot":
3095
- case "-isystem":
3096
- case "-iquote":
3097
- case "-I":
3098
- case "-F":
3099
- args.splice(i--, 2);
3100
- break;
3101
- case "-x":
3102
- hasDashX = true;
3103
- if (!isClang) {
3104
- switch (args[++i]) {
3105
- case "c":
3106
- args[i] = "cpp-output";
3107
- break;
3108
- case "c++":
3109
- args[i] = "c++-cpp-output";
3110
- break;
3111
- case "objective-c":
3112
- args[i] = "objective-c-output";
3113
- break;
3114
- case "objective-c++":
3115
- args[i] = "objective-c++-cpp-output";
3116
- break;
3117
- }
3118
- }
3119
- else {
3120
- ++i;
3121
- }
3122
- break;
3123
- case "--param":
3124
- case "-G":
3125
- case "-T":
3126
- case "-V":
3127
- case "-Xanalyzer":
3128
- case "-Xassembler":
3129
- case "-Xclang":
3130
- case "-Xlinker":
3131
- case "-Xpreprocessor":
3132
- case "-arch":
3133
- case "-b":
3134
- case "-gcc-toolchain":
3135
- case "-imacros":
3136
- case "-imultilib":
3137
- case "-include":
3138
- case "-iprefix":
3139
- case "-ivfsoverlay":
3140
- case "-iwithprefix":
3141
- case "-iwithprefixbefore":
3142
- case "-target":
3143
- case "-framework":
3144
- ++i;
3145
- break;
3146
- default:
3147
- if (args[i].startsWith("-mlinker-version=") ||
3148
- args[i].startsWith("-stdlib=") ||
3149
- args[i].startsWith("-I") ||
3150
- args[i].startsWith("-F") ||
3151
- args[i].startsWith("-isystem") ||
3152
- args[i].startsWith("-isysroot") ||
3153
- args[i].startsWith("-cxx-isystem") ||
3154
- args[i].startsWith("-iquote") ||
3155
- args[i].startsWith("--sysroot=") ||
3156
- args[i].startsWith("--gcc-toolchain=")) {
3157
- args.splice(i--, 1);
3158
- break;
3159
- }
3160
- if (args[i][0] !== "-") {
3161
- if (sourcePath) {
3162
- console.log("Multiple source files", sourcePath, args[i]);
3163
- throw new Error("More than one source file");
3164
- }
3165
- sourcePath = args[i];
3166
- if (!sourceFileName) {
3167
- sourceFileName = path__default["default"].basename(sourcePath);
3168
- }
3169
- args[i] = path__default["default"].join(dir, sourceFileName);
3170
- }
3171
- break;
3172
- }
3173
- }
3174
- if (!sourcePath) {
3175
- throw new Error("No sourcefile");
3176
- }
3177
- const sourceFileInDir = path__default["default"].join(dir, sourceFileName || path__default["default"].basename(sourcePath));
3178
- // Padding only pays off where the client's byte scan can reach the pads,
3179
- // and it is only *needed* for LLVM bitcode, which DwarfPatcher cannot
3180
- // load. Everywhere else DwarfPatcher already works, and padding actively
3181
- // breaks it: it matches on the old /compiles path still being in
3182
- // .debug_str, so once the pads have replaced it there is nothing for the
3183
- // fallback to match and the pads stay in the debug info.
3184
- //
3185
- // - non-clang: gcc never emits bitcode, and some gcc builds (the nrdp
3186
- // desktop toolchain, for one) compress .debug_str by default with no
3187
- // flag asking for it, which the byte scan cannot see into.
3188
- // - -gz: same problem, explicitly requested. -Wl, forms are link-time
3189
- // and do not affect the object we hand back, so they do not count.
3190
- const wantsCompressedDebug = args.some((arg) => {
3191
- if (arg.startsWith("-Wl,")) {
3192
- return false;
3193
- }
3194
- return (arg.startsWith("-gz") && arg !== "-gz=none") || arg.includes("compress-debug-sections");
3195
- });
3196
- if (paddedPaths && (!isClang || wantsCompressedDebug)) {
3197
- if (debug) {
3198
- console.log("Not padding paths, leaving them to DwarfPatcher:", "isClang", isClang, "wantsCompressedDebug", wantsCompressedDebug);
3199
- }
3200
- paddedPaths = false;
3201
- }
3202
- if (paddedPaths) {
3203
- // -grecord-command-line (clang) / -frecord-gcc-switches (gcc) embed
3204
- // our own argv verbatim into DW_AT_producer or .GCC.command.line,
3205
- // which would (a) add two PATH_MAX pads to every CU and (b) leave
3206
- // the builder's /compiles path in there, where the client's byte
3207
- // scan would hit the embedded pad and NUL-truncate the rest of the
3208
- // recorded command line. The recorded line would be the builder's
3209
- // rewritten argv anyway -- not the client's -- so turn it off rather
3210
- // than record something both wrong and mangled.
3211
- //
3212
- // Negate each flag in place instead of dropping it and appending one
3213
- // fixed negation: whichever compiler accepted the positive spelling
3214
- // necessarily accepts its own negation, whereas a fixed flag is a
3215
- // guess about the compiler. That guess is what put
3216
- // -gno-record-command-line (clang 11+, and gcc spells it
3217
- // -gno-record-gcc-switches) on gcc command lines.
3218
- for (let i = 0; i < args.length; ++i) {
3219
- const negation = RECORD_FLAG_NEGATIONS[args[i]];
3220
- if (negation) {
3221
- args[i] = negation;
3222
- }
3223
- }
3224
- // The more specific source-file rule must come last: both clang and
3225
- // gcc let a later -fdebug-prefix-map win over an earlier one, and
3226
- // the directory rule is a prefix of the source-file rule.
3227
- args.push(`-fdebug-prefix-map=${dir}=${FISK_CDIR_PAD}`);
3228
- args.push(`-fdebug-prefix-map=${sourceFileInDir}=${FISK_NAME_PAD}`);
3229
- }
3230
- if (!hasDashX) {
3231
- switch (path__default["default"].extname(sourcePath)) {
3232
- case ".C":
3233
- case ".cc":
3234
- case ".cpp":
3235
- case ".CPP":
3236
- case ".c++":
3237
- case ".cp":
3238
- case ".cxx":
3239
- args.unshift(isClang ? "c++" : "c++-cpp-output");
3240
- break;
3241
- case ".ii":
3242
- args.unshift("c++-cpp-output");
3243
- break;
3244
- case ".hh":
3245
- case ".hpp":
3246
- case ".H":
3247
- args.unshift("c++-header");
3248
- break;
3249
- case ".h":
3250
- args.unshift("c-header");
3251
- break;
3252
- case ".c":
3253
- args.unshift(isClang ? "c" : "cpp-output");
3254
- break;
3255
- case ".i":
3256
- args.unshift("cpp-output");
3257
- break;
3258
- case ".m":
3259
- case ".mi":
3260
- args.unshift(isClang ? "objective-c" : "objective-c-cpp-output");
3261
- break;
3262
- case ".s":
3263
- args.unshift("assembler");
3264
- break;
3265
- case ".sx":
3266
- case ".S":
3267
- args.unshift("assembler-with-cpp");
3268
- break;
3269
- case ".mm":
3270
- case ".M":
3271
- case ".mii":
3272
- args.unshift(isClang ? "objective-c++" : "objective-c++-cpp-output");
3273
- break;
3274
- default:
3275
- throw new Error(`Can't determine source language for file: ${sourcePath}`);
3276
- }
3277
- args.unshift("-x");
3278
- }
3279
- if (!isClang) {
3280
- args.push("-fpreprocessed", "-fdirectives-only"); // this is not good for clang
3281
- }
3282
- else {
3283
- args.push("-Wno-stdlibcxx-not-found");
3284
- }
3285
- if (!hasDashO) {
3286
- const suffix = path__default["default"].extname(sourcePath);
3287
- outputFileName = output = sourcePath.substring(0, sourcePath.length - suffix.length) + ".o";
3288
- args.push("-o", outputFileName);
3289
- }
3290
- // debug = true;
3291
- if (debug) {
3292
- console.log("Calling", argv0, compiler, args.map((x) => '"' + x + '"').join(" "));
3293
- }
3294
- if (!fs.existsSync("/usr/bin/as")) {
3295
- this.emit("stderr", "as doesn't exist");
3296
- }
3297
- console.log(`Compiling source file: ${sourcePath}\n${[compiler, ...args]
3298
- .map((x) => {
3299
- if (x.startsWith("-fdebug-prefix-map=")) {
3300
- x = x.replace(/_+$/, "___");
3301
- }
3302
- return x;
3303
- })
3304
- .join(" ")}`);
3305
- // const env = Object.assign({ TMPDIR: dir, TEMPDIR: dir, TEMP: dir }, process.env);
3306
- const proc = child_process__default["default"].spawn(compiler, args, {
3307
- /*env: env, */ cwd: dir // , maxBuffer: 1024 * 1024 * 16
3308
- });
3309
- this.proc = proc;
3310
- proc.stdout.setEncoding("utf8");
3311
- proc.stderr.setEncoding("utf8");
3312
- proc.stdout.on("data", (data) => {
3313
- this.emit("stdout", data);
3314
- });
3315
- proc.stderr.on("data", (data) => {
3316
- this.emit("stderr", data);
3317
- });
3318
- proc.on("error", (err) => {
3319
- this.emit("error", err);
3320
- });
3321
- proc.on("exit", (exitCode) => {
3322
- // try {
3323
- const files = [];
3324
- let addDirError;
3325
- const addDir = (directory, prefix) => {
3326
- try {
3327
- const sourceBaseName = sourceFileName || path__default["default"].basename(sourcePath);
3328
- fs.readdirSync(directory).forEach((file) => {
3329
- if (file === sourceBaseName) {
3330
- return;
3331
- }
3332
- try {
3333
- assert__default["default"](output !== undefined, "Must have output");
3334
- const stat = fs.statSync(path__default["default"].join(directory, file));
3335
- if (stat.isDirectory()) {
3336
- addDir(path__default["default"].join(directory, file), prefix ? prefix + file + "/" : file + "/");
3337
- }
3338
- else if (stat.isFile()) {
3339
- if (file === outputFileName) {
3340
- files.push({ path: output, mapped: path__default["default"].join(prefix, file) });
3341
- }
3342
- else {
3343
- const ext = path__default["default"].extname(file);
3344
- switch (ext) {
3345
- case ".gcno":
3346
- case ".gcda":
3347
- case ".dwo":
3348
- files.push({
3349
- path: output.substring(0, output.length - 2) + ext,
3350
- mapped: path__default["default"].join(prefix, file)
3351
- });
3352
- break;
3353
- default:
3354
- files.push({ path: path__default["default"].join(prefix, file) });
3355
- break;
3356
- }
3357
- }
3358
- if (debug) {
3359
- console.log("Added file", file, files[files.length - 1]);
3360
- }
3361
- }
3362
- }
3363
- catch (err) {
3364
- console.error("Got an error file", path__default["default"].join(directory, file), err);
3365
- }
3366
- });
3367
- }
3368
- catch (err) {
3369
- console.error("Got an error processing outputs for", sourcePath, err);
3370
- addDirError = err;
3371
- }
3372
- };
3373
- if (exitCode === 0) {
3374
- addDir(dir, dir);
3375
- }
3376
- assert__default["default"](sourcePath !== undefined, "Must have sourcePath4");
3377
- if (addDirError) {
3378
- const errorExitEvent = {
3379
- exitCode: 110,
3380
- files: [],
3381
- error: addDirError.toString(),
3382
- sourcePath
3383
- };
3384
- this.emit("exit", errorExitEvent);
3385
- return;
3386
- }
3387
- if (exitCode === null) {
3388
- exitCode = 111;
3389
- }
3390
- const exitEvent = { exitCode, files, sourcePath };
3391
- this.emit("exit", exitEvent);
3392
- });
3393
- }
3394
- kill() {
3395
- this.proc.kill();
3396
- }
3397
- }
3398
- // let preproc = fs.readFileSync("/tmp/preproc");
3399
- // let f = new Compile([ "/usr/bin/c++", "-Iclient", "-I3rdparty/json11", "-I3rdparty/wslay/lib/includes", "-I3rdparty/wslay/lib", "-I3rdparty/LUrlParser", "-I3rdparty/tiny-process-library", "-std=c++14", "-Wformat", "-Wall", "-g", "-MD", "-MT", "client/CMakeFiles/fiskc.dir/Config.cpp.o", "-MF", "client/CMakeFiles/fiskc.dir/Config.cpp.o.d", "-o", "client/CMakeFiles/fiskc.dir/Config.cpp.o", "-c", "client/Config.cpp" ], preproc);
3400
- // f.on('stdout', (data) => {
3401
- // console.log("Got out", data.length);
3402
- // });
3403
- // f.on('stderr', (data) => {
3404
- // console.log("Got err", data.toString());
3405
- // });
3406
- // f.on('error', error => {
3407
- // console.log("Got error", error);
3408
- // });
3409
- // f.on('exit', event => {
3410
- // console.log("Got exit", event);
3411
- // });
3412
- module.exports = Compile;
3413
-
3414
- function hasKey(obj, keys) {
3415
- var o = obj;
3416
- keys.slice(0, -1).forEach(function (key) {
3417
- o = o[key] || {};
3418
- });
3419
-
3420
- var key = keys[keys.length - 1];
3421
- return key in o;
3422
- }
3423
-
3424
- function isNumber(x) {
3425
- if (typeof x === 'number') { return true; }
3426
- if ((/^0x[0-9a-f]+$/i).test(x)) { return true; }
3427
- return (/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/).test(x);
3428
- }
3429
-
3430
- function isConstructorOrProto(obj, key) {
3431
- return (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';
3432
- }
3433
-
3434
- var minimist = function (args, opts) {
3435
- if (!opts) { opts = {}; }
3436
-
3437
- var flags = {
3438
- bools: {},
3439
- strings: {},
3440
- unknownFn: null,
3441
- };
3442
-
3443
- if (typeof opts.unknown === 'function') {
3444
- flags.unknownFn = opts.unknown;
3445
- }
3446
-
3447
- if (typeof opts.boolean === 'boolean' && opts.boolean) {
3448
- flags.allBools = true;
3449
- } else {
3450
- [].concat(opts.boolean).filter(Boolean).forEach(function (key) {
3451
- flags.bools[key] = true;
3452
- });
3453
- }
3454
-
3455
- var aliases = {};
3456
-
3457
- function aliasIsBoolean(key) {
3458
- return aliases[key].some(function (x) {
3459
- return flags.bools[x];
3460
- });
3461
- }
3462
-
3463
- Object.keys(opts.alias || {}).forEach(function (key) {
3464
- aliases[key] = [].concat(opts.alias[key]);
3465
- aliases[key].forEach(function (x) {
3466
- aliases[x] = [key].concat(aliases[key].filter(function (y) {
3467
- return x !== y;
3468
- }));
3469
- });
3470
- });
3471
-
3472
- [].concat(opts.string).filter(Boolean).forEach(function (key) {
3473
- flags.strings[key] = true;
3474
- if (aliases[key]) {
3475
- [].concat(aliases[key]).forEach(function (k) {
3476
- flags.strings[k] = true;
3477
- });
3478
- }
3479
- });
3480
-
3481
- var defaults = opts.default || {};
3482
-
3483
- var argv = { _: [] };
3484
-
3485
- function argDefined(key, arg) {
3486
- return (flags.allBools && (/^--[^=]+$/).test(arg))
3487
- || flags.strings[key]
3488
- || flags.bools[key]
3489
- || aliases[key];
3490
- }
3491
-
3492
- function setKey(obj, keys, value) {
3493
- var o = obj;
3494
- for (var i = 0; i < keys.length - 1; i++) {
3495
- var key = keys[i];
3496
- if (isConstructorOrProto(o, key)) { return; }
3497
- if (o[key] === undefined) { o[key] = {}; }
3498
- if (
3499
- o[key] === Object.prototype
3500
- || o[key] === Number.prototype
3501
- || o[key] === String.prototype
3502
- ) {
3503
- o[key] = {};
3504
- }
3505
- if (o[key] === Array.prototype) { o[key] = []; }
3506
- o = o[key];
3507
- }
3508
-
3509
- var lastKey = keys[keys.length - 1];
3510
- if (isConstructorOrProto(o, lastKey)) { return; }
3511
- if (
3512
- o === Object.prototype
3513
- || o === Number.prototype
3514
- || o === String.prototype
3515
- ) {
3516
- o = {};
3517
- }
3518
- if (o === Array.prototype) { o = []; }
3519
- if (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {
3520
- o[lastKey] = value;
3521
- } else if (Array.isArray(o[lastKey])) {
3522
- o[lastKey].push(value);
3523
- } else {
3524
- o[lastKey] = [o[lastKey], value];
3525
- }
3526
- }
3527
-
3528
- function setArg(key, val, arg) {
3529
- if (arg && flags.unknownFn && !argDefined(key, arg)) {
3530
- if (flags.unknownFn(arg) === false) { return; }
3531
- }
3532
-
3533
- var value = !flags.strings[key] && isNumber(val)
3534
- ? Number(val)
3535
- : val;
3536
- setKey(argv, key.split('.'), value);
3537
-
3538
- (aliases[key] || []).forEach(function (x) {
3539
- setKey(argv, x.split('.'), value);
3540
- });
3541
- }
3542
-
3543
- Object.keys(flags.bools).forEach(function (key) {
3544
- setArg(key, defaults[key] === undefined ? false : defaults[key]);
3545
- });
3546
-
3547
- var notFlags = [];
3548
-
3549
- if (args.indexOf('--') !== -1) {
3550
- notFlags = args.slice(args.indexOf('--') + 1);
3551
- args = args.slice(0, args.indexOf('--'));
3552
- }
3553
-
3554
- for (var i = 0; i < args.length; i++) {
3555
- var arg = args[i];
3556
- var key;
3557
- var next;
3558
-
3559
- if ((/^--.+=/).test(arg)) {
3560
- // Using [\s\S] instead of . because js doesn't support the
3561
- // 'dotall' regex modifier. See:
3562
- // http://stackoverflow.com/a/1068308/13216
3563
- var m = arg.match(/^--([^=]+)=([\s\S]*)$/);
3564
- key = m[1];
3565
- var value = m[2];
3566
- if (flags.bools[key]) {
3567
- value = value !== 'false';
3568
- }
3569
- setArg(key, value, arg);
3570
- } else if ((/^--no-.+/).test(arg)) {
3571
- key = arg.match(/^--no-(.+)/)[1];
3572
- setArg(key, false, arg);
3573
- } else if ((/^--.+/).test(arg)) {
3574
- key = arg.match(/^--(.+)/)[1];
3575
- next = args[i + 1];
3576
- if (
3577
- next !== undefined
3578
- && !(/^(-|--)[^-]/).test(next)
3579
- && !flags.bools[key]
3580
- && !flags.allBools
3581
- && (aliases[key] ? !aliasIsBoolean(key) : true)
3582
- ) {
3583
- setArg(key, next, arg);
3584
- i += 1;
3585
- } else if ((/^(true|false)$/).test(next)) {
3586
- setArg(key, next === 'true', arg);
3587
- i += 1;
3588
- } else {
3589
- setArg(key, flags.strings[key] ? '' : true, arg);
3590
- }
3591
- } else if ((/^-[^-]+/).test(arg)) {
3592
- var letters = arg.slice(1, -1).split('');
3593
-
3594
- var broken = false;
3595
- for (var j = 0; j < letters.length; j++) {
3596
- next = arg.slice(j + 2);
3597
-
3598
- if (next === '-') {
3599
- setArg(letters[j], next, arg);
3600
- continue;
3601
- }
3602
-
3603
- if ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {
3604
- setArg(letters[j], next.slice(1), arg);
3605
- broken = true;
3606
- break;
3607
- }
3608
-
3609
- if (
3610
- (/[A-Za-z]/).test(letters[j])
3611
- && (/-?\d+(\.\d*)?(e-?\d+)?$/).test(next)
3612
- ) {
3613
- setArg(letters[j], next, arg);
3614
- broken = true;
3615
- break;
3616
- }
3617
-
3618
- if (letters[j + 1] && letters[j + 1].match(/\W/)) {
3619
- setArg(letters[j], arg.slice(j + 2), arg);
3620
- broken = true;
3621
- break;
3622
- } else {
3623
- setArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);
3624
- }
3625
- }
3626
-
3627
- key = arg.slice(-1)[0];
3628
- if (!broken && key !== '-') {
3629
- if (
3630
- args[i + 1]
3631
- && !(/^(-|--)[^-]/).test(args[i + 1])
3632
- && !flags.bools[key]
3633
- && (aliases[key] ? !aliasIsBoolean(key) : true)
3634
- ) {
3635
- setArg(key, args[i + 1], arg);
3636
- i += 1;
3637
- } else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {
3638
- setArg(key, args[i + 1] === 'true', arg);
3639
- i += 1;
3640
- } else {
3641
- setArg(key, flags.strings[key] ? '' : true, arg);
3642
- }
3643
- }
3644
- } else {
3645
- if (!flags.unknownFn || flags.unknownFn(arg) !== false) {
3646
- argv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));
3647
- }
3648
- if (opts.stopEarly) {
3649
- argv._.push.apply(argv._, args.slice(i + 1));
3650
- break;
3651
- }
3652
- }
3653
- }
3654
-
3655
- Object.keys(defaults).forEach(function (k) {
3656
- if (!hasKey(argv, k.split('.'))) {
3657
- setKey(argv, k.split('.'), defaults[k]);
3658
-
3659
- (aliases[k] || []).forEach(function (x) {
3660
- setKey(argv, x.split('.'), defaults[k]);
3661
- });
3662
- }
3663
- });
3664
-
3665
- if (opts['--']) {
3666
- argv['--'] = notFlags.slice();
3667
- } else {
3668
- notFlags.forEach(function (k) {
3669
- argv._.push(k);
3670
- });
3671
- }
3672
-
3673
- return argv;
3674
- };
3675
-
3676
- const argv = minimist(process.argv.slice(2));
3677
- function send(message) {
3678
- try {
3679
- assert__default["default"](process.send, "Must have process.send");
3680
- process.send(message);
3681
- }
3682
- catch (err) {
3683
- console.error(`Couldn't send message ${message.type}. Going down`, err);
3684
- process.exit();
3685
- }
3686
- }
3687
- process.on("unhandledRejection", (reason, p) => {
3688
- send({ type: "error", message: `Unhandled rejection at: Promise reason: ${reason === null || reason === void 0 ? void 0 : reason.stack}` });
3689
- console.error("Unhandled rejection at: Promise", p, "reason:", reason === null || reason === void 0 ? void 0 : reason.stack);
3690
- });
3691
- process.on("uncaughtException", (err) => {
3692
- send({ type: "error", message: `Uncaught exception ${err.stack} ${err.toString()}` });
3693
- console.error("Uncaught exception", err);
3694
- });
3695
- let pwd;
3696
- if (argv.user) {
3697
- try {
3698
- pwd = fiskNative.getpwnam(argv.user);
3699
- }
3700
- catch (err) {
3701
- console.error("Couldn't find user", argv.user);
3702
- throw err;
3703
- }
3704
- try {
3705
- process.initgroups(argv.user, pwd.gid);
3706
- }
3707
- catch (err) {
3708
- throw new Error("Changing groups failed: " + err.message);
3709
- }
3710
- }
3711
- try {
3712
- console.log("Chrooting to", argv.root);
3713
- fiskNative.chroot(argv.root);
3714
- }
3715
- catch (err) {
3716
- console.error("Changing root or user failed", { root: argv.root }, err);
3717
- process.exit(1);
3718
- }
3719
- if (pwd) {
3720
- process.setgid(pwd.gid);
3721
- process.setuid(pwd.uid);
3722
- }
3723
- process.on("error", (error) => {
3724
- console.error(`Got process error ${error} ${JSON.stringify(argv)}. Going down`);
3725
- process.exit();
3726
- });
3727
- const libDirs = [];
3728
- const mac = require$$1__default$1["default"].type() === "Darwin";
3729
- function isLibrary(file) {
3730
- if (file === "ld.so.conf" || file === "ld.so.cache") {
3731
- return false;
3732
- }
3733
- const suffix = path__default["default"].extname(file);
3734
- if (mac) {
3735
- return suffix === ".dylib";
3736
- }
3737
- // console.log("got file", suffix, file);
3738
- if (suffix === ".so") {
3739
- return true;
3740
- }
3741
- return file.indexOf(".so.") !== -1;
3742
- }
3743
- function findLibraries(dir) {
3744
- const files = require$$1__default["default"].readdirSync(dir);
3745
- // console.log("findLibraries", dir, files.length);
3746
- let found = false;
3747
- files.forEach((file) => {
3748
- let stat;
3749
- try {
3750
- stat = require$$1__default["default"].statSync(path__default["default"].join(dir, file));
3751
- }
3752
- catch (err) {
3753
- console.error("Got error", err);
3754
- return;
3755
- }
3756
- if (stat.isDirectory()) {
3757
- findLibraries(path__default["default"].join(dir, file));
3758
- }
3759
- else if (!found && stat.isFile() && isLibrary(file)) {
3760
- found = true;
3761
- libDirs.push(dir);
3762
- }
3763
- });
3764
- }
3765
- findLibraries("/");
3766
- if (argv.debug) {
3767
- console.log("Got lib directories", argv.root, libDirs);
3768
- }
3769
- if (libDirs.length) {
3770
- process.env[mac ? "DYLD_LIBRARY_PATH" : "LD_LIBRARY_PATH"] = libDirs.join(":");
3771
- }
3772
- setTimeout(() => {
3773
- // hack
3774
- try {
3775
- send({ type: "ready" });
3776
- }
3777
- catch (err) {
3778
- console.error("Couldn't send ready. Going down");
3779
- process.exit();
3780
- }
3781
- }, 1000);
3782
- const compiles = new Map();
3783
- let destroying = false;
3784
- process.on("message", (msg) => {
3785
- switch (msg.type) {
3786
- case "destroy":
3787
- if (!compiles.size) {
3788
- process.exit();
3789
- }
3790
- else {
3791
- destroying = true;
3792
- }
3793
- break;
3794
- case "setDebug":
3795
- if (msg.debug) {
3796
- argv.debug = true;
3797
- }
3798
- else {
3799
- delete argv.debug;
3800
- }
3801
- console.log("set debug to", msg.debug, "for", argv.root);
3802
- break;
3803
- case "cancel": {
3804
- const c = compiles.get(msg.id);
3805
- if (c) {
3806
- c.kill();
3807
- }
3808
- break;
3809
- }
3810
- case "compile":
3811
- try {
3812
- // console.log("compiling for );
3813
- if (argv.debug) {
3814
- console.log("Creating new compile", msg.commandLine, msg.argv0, msg.dir);
3815
- }
3816
- const compile = new Compile(msg.commandLine, msg.argv0, msg.dir, argv.debug, msg.sourceFileName, msg.paddedPaths);
3817
- // console.log("running thing", msg.commandLine);
3818
- compile.on("stdout", (data) => {
3819
- send({ type: "compileStdOut", id: msg.id, data: data });
3820
- });
3821
- compile.on("stderr", (data) => {
3822
- send({ type: "compileStdErr", id: msg.id, data: data });
3823
- });
3824
- compile.on("exit", (event) => {
3825
- compiles.delete(msg.id);
3826
- if ("error" in event) {
3827
- send({
3828
- type: "compileFinished",
3829
- success: false,
3830
- error: event.error,
3831
- id: msg.id,
3832
- files: event.files,
3833
- exitCode: event.exitCode,
3834
- sourcePath: event.sourcePath
3835
- });
3836
- }
3837
- else {
3838
- send({
3839
- type: "compileFinished",
3840
- success: true,
3841
- id: msg.id,
3842
- files: event.files,
3843
- exitCode: event.exitCode,
3844
- sourcePath: event.sourcePath
3845
- });
3846
- }
3847
- if (destroying && !compiles.size) {
3848
- process.exit();
3849
- }
3850
- });
3851
- compiles.set(msg.id, compile);
3852
- }
3853
- catch (err) {
3854
- compiles.delete(msg.id);
3855
- send({
3856
- type: "compileFinished",
3857
- success: false,
3858
- id: msg.id,
3859
- files: [],
3860
- exitCode: -1,
3861
- error: err.toString()
3862
- });
3863
- }
3864
- break;
3865
- }
3866
- });
3867
- //# sourceMappingURL=VM_runtime.js.map