@create-node-app/core 0.4.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs ADDED
@@ -0,0 +1,3794 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __commonJS = (cb, mod) => function __require() {
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ };
11
+ var __export = (target, all) => {
12
+ for (var name in all)
13
+ __defProp(target, name, { get: all[name], enumerable: true });
14
+ };
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from))
18
+ if (!__hasOwnProp.call(to, key) && key !== except)
19
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
+ }
21
+ return to;
22
+ };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
+ // If the importer is in node compatibility mode or this is not an ESM
25
+ // file that has been converted to a CommonJS file using a Babel-
26
+ // compatible transform (i.e. "__esModule" has not been set), then set
27
+ // "default" to the CommonJS "module.exports" for node compatibility.
28
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
+ mod
30
+ ));
31
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
+
33
+ // ../../node_modules/universalify/index.js
34
+ var require_universalify = __commonJS({
35
+ "../../node_modules/universalify/index.js"(exports2) {
36
+ "use strict";
37
+ exports2.fromCallback = function(fn) {
38
+ return Object.defineProperty(function() {
39
+ if (typeof arguments[arguments.length - 1] === "function") fn.apply(this, arguments);
40
+ else {
41
+ return new Promise((resolve, reject) => {
42
+ arguments[arguments.length] = (err, res) => {
43
+ if (err) return reject(err);
44
+ resolve(res);
45
+ };
46
+ arguments.length++;
47
+ fn.apply(this, arguments);
48
+ });
49
+ }
50
+ }, "name", { value: fn.name });
51
+ };
52
+ exports2.fromPromise = function(fn) {
53
+ return Object.defineProperty(function() {
54
+ const cb = arguments[arguments.length - 1];
55
+ if (typeof cb !== "function") return fn.apply(this, arguments);
56
+ else fn.apply(this, arguments).then((r) => cb(null, r), cb);
57
+ }, "name", { value: fn.name });
58
+ };
59
+ }
60
+ });
61
+
62
+ // ../../node_modules/graceful-fs/polyfills.js
63
+ var require_polyfills = __commonJS({
64
+ "../../node_modules/graceful-fs/polyfills.js"(exports2, module2) {
65
+ "use strict";
66
+ var constants = require("constants");
67
+ var origCwd = process.cwd;
68
+ var cwd = null;
69
+ var platform = process.env.GRACEFUL_FS_PLATFORM || process.platform;
70
+ process.cwd = function() {
71
+ if (!cwd)
72
+ cwd = origCwd.call(process);
73
+ return cwd;
74
+ };
75
+ try {
76
+ process.cwd();
77
+ } catch (er) {
78
+ }
79
+ if (typeof process.chdir === "function") {
80
+ 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
+ var chdir;
88
+ module2.exports = patch;
89
+ function patch(fs5) {
90
+ if (constants.hasOwnProperty("O_SYMLINK") && process.version.match(/^v0\.6\.[0-2]|^v0\.5\./)) {
91
+ patchLchmod(fs5);
92
+ }
93
+ if (!fs5.lutimes) {
94
+ patchLutimes(fs5);
95
+ }
96
+ fs5.chown = chownFix(fs5.chown);
97
+ fs5.fchown = chownFix(fs5.fchown);
98
+ fs5.lchown = chownFix(fs5.lchown);
99
+ fs5.chmod = chmodFix(fs5.chmod);
100
+ fs5.fchmod = chmodFix(fs5.fchmod);
101
+ fs5.lchmod = chmodFix(fs5.lchmod);
102
+ fs5.chownSync = chownFixSync(fs5.chownSync);
103
+ fs5.fchownSync = chownFixSync(fs5.fchownSync);
104
+ fs5.lchownSync = chownFixSync(fs5.lchownSync);
105
+ fs5.chmodSync = chmodFixSync(fs5.chmodSync);
106
+ fs5.fchmodSync = chmodFixSync(fs5.fchmodSync);
107
+ fs5.lchmodSync = chmodFixSync(fs5.lchmodSync);
108
+ fs5.stat = statFix(fs5.stat);
109
+ fs5.fstat = statFix(fs5.fstat);
110
+ fs5.lstat = statFix(fs5.lstat);
111
+ fs5.statSync = statFixSync(fs5.statSync);
112
+ fs5.fstatSync = statFixSync(fs5.fstatSync);
113
+ fs5.lstatSync = statFixSync(fs5.lstatSync);
114
+ if (fs5.chmod && !fs5.lchmod) {
115
+ fs5.lchmod = function(path4, mode, cb) {
116
+ if (cb) process.nextTick(cb);
117
+ };
118
+ fs5.lchmodSync = function() {
119
+ };
120
+ }
121
+ if (fs5.chown && !fs5.lchown) {
122
+ fs5.lchown = function(path4, uid, gid, cb) {
123
+ if (cb) process.nextTick(cb);
124
+ };
125
+ fs5.lchownSync = function() {
126
+ };
127
+ }
128
+ if (platform === "win32") {
129
+ fs5.rename = typeof fs5.rename !== "function" ? fs5.rename : (function(fs$rename) {
130
+ function rename(from, to, cb) {
131
+ var start = Date.now();
132
+ var backoff = 0;
133
+ fs$rename(from, to, function CB(er) {
134
+ if (er && (er.code === "EACCES" || er.code === "EPERM") && Date.now() - start < 6e4) {
135
+ setTimeout(function() {
136
+ fs5.stat(to, function(stater, st) {
137
+ if (stater && stater.code === "ENOENT")
138
+ fs$rename(from, to, CB);
139
+ else
140
+ cb(er);
141
+ });
142
+ }, backoff);
143
+ if (backoff < 100)
144
+ backoff += 10;
145
+ return;
146
+ }
147
+ if (cb) cb(er);
148
+ });
149
+ }
150
+ if (Object.setPrototypeOf) Object.setPrototypeOf(rename, fs$rename);
151
+ return rename;
152
+ })(fs5.rename);
153
+ }
154
+ fs5.read = typeof fs5.read !== "function" ? fs5.read : (function(fs$read) {
155
+ function read(fd, buffer, offset, length, position, callback_) {
156
+ var callback;
157
+ if (callback_ && typeof callback_ === "function") {
158
+ var eagCounter = 0;
159
+ callback = function(er, _3, __) {
160
+ if (er && er.code === "EAGAIN" && eagCounter < 10) {
161
+ eagCounter++;
162
+ return fs$read.call(fs5, fd, buffer, offset, length, position, callback);
163
+ }
164
+ callback_.apply(this, arguments);
165
+ };
166
+ }
167
+ return fs$read.call(fs5, fd, buffer, offset, length, position, callback);
168
+ }
169
+ if (Object.setPrototypeOf) Object.setPrototypeOf(read, fs$read);
170
+ return read;
171
+ })(fs5.read);
172
+ fs5.readSync = typeof fs5.readSync !== "function" ? fs5.readSync : /* @__PURE__ */ (function(fs$readSync) {
173
+ return function(fd, buffer, offset, length, position) {
174
+ var eagCounter = 0;
175
+ while (true) {
176
+ try {
177
+ return fs$readSync.call(fs5, fd, buffer, offset, length, position);
178
+ } catch (er) {
179
+ if (er.code === "EAGAIN" && eagCounter < 10) {
180
+ eagCounter++;
181
+ continue;
182
+ }
183
+ throw er;
184
+ }
185
+ }
186
+ };
187
+ })(fs5.readSync);
188
+ function patchLchmod(fs6) {
189
+ fs6.lchmod = function(path4, mode, callback) {
190
+ fs6.open(
191
+ path4,
192
+ constants.O_WRONLY | constants.O_SYMLINK,
193
+ mode,
194
+ function(err, fd) {
195
+ if (err) {
196
+ if (callback) callback(err);
197
+ return;
198
+ }
199
+ fs6.fchmod(fd, mode, function(err2) {
200
+ fs6.close(fd, function(err22) {
201
+ if (callback) callback(err2 || err22);
202
+ });
203
+ });
204
+ }
205
+ );
206
+ };
207
+ fs6.lchmodSync = function(path4, mode) {
208
+ var fd = fs6.openSync(path4, constants.O_WRONLY | constants.O_SYMLINK, mode);
209
+ var threw = true;
210
+ var ret;
211
+ try {
212
+ ret = fs6.fchmodSync(fd, mode);
213
+ threw = false;
214
+ } finally {
215
+ if (threw) {
216
+ try {
217
+ fs6.closeSync(fd);
218
+ } catch (er) {
219
+ }
220
+ } else {
221
+ fs6.closeSync(fd);
222
+ }
223
+ }
224
+ return ret;
225
+ };
226
+ }
227
+ function patchLutimes(fs6) {
228
+ if (constants.hasOwnProperty("O_SYMLINK") && fs6.futimes) {
229
+ fs6.lutimes = function(path4, at, mt, cb) {
230
+ fs6.open(path4, constants.O_SYMLINK, function(er, fd) {
231
+ if (er) {
232
+ if (cb) cb(er);
233
+ return;
234
+ }
235
+ fs6.futimes(fd, at, mt, function(er2) {
236
+ fs6.close(fd, function(er22) {
237
+ if (cb) cb(er2 || er22);
238
+ });
239
+ });
240
+ });
241
+ };
242
+ fs6.lutimesSync = function(path4, at, mt) {
243
+ var fd = fs6.openSync(path4, constants.O_SYMLINK);
244
+ var ret;
245
+ var threw = true;
246
+ try {
247
+ ret = fs6.futimesSync(fd, at, mt);
248
+ threw = false;
249
+ } finally {
250
+ if (threw) {
251
+ try {
252
+ fs6.closeSync(fd);
253
+ } catch (er) {
254
+ }
255
+ } else {
256
+ fs6.closeSync(fd);
257
+ }
258
+ }
259
+ return ret;
260
+ };
261
+ } else if (fs6.futimes) {
262
+ fs6.lutimes = function(_a, _b, _c, cb) {
263
+ if (cb) process.nextTick(cb);
264
+ };
265
+ fs6.lutimesSync = function() {
266
+ };
267
+ }
268
+ }
269
+ function chmodFix(orig) {
270
+ if (!orig) return orig;
271
+ return function(target, mode, cb) {
272
+ return orig.call(fs5, target, mode, function(er) {
273
+ if (chownErOk(er)) er = null;
274
+ if (cb) cb.apply(this, arguments);
275
+ });
276
+ };
277
+ }
278
+ function chmodFixSync(orig) {
279
+ if (!orig) return orig;
280
+ return function(target, mode) {
281
+ try {
282
+ return orig.call(fs5, target, mode);
283
+ } catch (er) {
284
+ if (!chownErOk(er)) throw er;
285
+ }
286
+ };
287
+ }
288
+ function chownFix(orig) {
289
+ if (!orig) return orig;
290
+ return function(target, uid, gid, cb) {
291
+ return orig.call(fs5, target, uid, gid, function(er) {
292
+ if (chownErOk(er)) er = null;
293
+ if (cb) cb.apply(this, arguments);
294
+ });
295
+ };
296
+ }
297
+ function chownFixSync(orig) {
298
+ if (!orig) return orig;
299
+ return function(target, uid, gid) {
300
+ try {
301
+ return orig.call(fs5, target, uid, gid);
302
+ } catch (er) {
303
+ if (!chownErOk(er)) throw er;
304
+ }
305
+ };
306
+ }
307
+ function statFix(orig) {
308
+ if (!orig) return orig;
309
+ return function(target, options, cb) {
310
+ if (typeof options === "function") {
311
+ cb = options;
312
+ options = null;
313
+ }
314
+ function callback(er, stats) {
315
+ if (stats) {
316
+ if (stats.uid < 0) stats.uid += 4294967296;
317
+ if (stats.gid < 0) stats.gid += 4294967296;
318
+ }
319
+ if (cb) cb.apply(this, arguments);
320
+ }
321
+ return options ? orig.call(fs5, target, options, callback) : orig.call(fs5, target, callback);
322
+ };
323
+ }
324
+ function statFixSync(orig) {
325
+ if (!orig) return orig;
326
+ return function(target, options) {
327
+ var stats = options ? orig.call(fs5, target, options) : orig.call(fs5, target);
328
+ if (stats) {
329
+ if (stats.uid < 0) stats.uid += 4294967296;
330
+ if (stats.gid < 0) stats.gid += 4294967296;
331
+ }
332
+ return stats;
333
+ };
334
+ }
335
+ function chownErOk(er) {
336
+ if (!er)
337
+ return true;
338
+ if (er.code === "ENOSYS")
339
+ return true;
340
+ var nonroot = !process.getuid || process.getuid() !== 0;
341
+ if (nonroot) {
342
+ if (er.code === "EINVAL" || er.code === "EPERM")
343
+ return true;
344
+ }
345
+ return false;
346
+ }
347
+ }
348
+ }
349
+ });
350
+
351
+ // ../../node_modules/graceful-fs/legacy-streams.js
352
+ var require_legacy_streams = __commonJS({
353
+ "../../node_modules/graceful-fs/legacy-streams.js"(exports2, module2) {
354
+ "use strict";
355
+ var Stream = require("stream").Stream;
356
+ module2.exports = legacy;
357
+ function legacy(fs5) {
358
+ return {
359
+ ReadStream,
360
+ WriteStream
361
+ };
362
+ function ReadStream(path4, options) {
363
+ if (!(this instanceof ReadStream)) return new ReadStream(path4, options);
364
+ Stream.call(this);
365
+ var self = this;
366
+ this.path = path4;
367
+ this.fd = null;
368
+ this.readable = true;
369
+ this.paused = false;
370
+ this.flags = "r";
371
+ this.mode = 438;
372
+ this.bufferSize = 64 * 1024;
373
+ options = options || {};
374
+ var keys = Object.keys(options);
375
+ for (var index = 0, length = keys.length; index < length; index++) {
376
+ var key = keys[index];
377
+ this[key] = options[key];
378
+ }
379
+ if (this.encoding) this.setEncoding(this.encoding);
380
+ if (this.start !== void 0) {
381
+ if ("number" !== typeof this.start) {
382
+ throw TypeError("start must be a Number");
383
+ }
384
+ if (this.end === void 0) {
385
+ this.end = Infinity;
386
+ } else if ("number" !== typeof this.end) {
387
+ throw TypeError("end must be a Number");
388
+ }
389
+ if (this.start > this.end) {
390
+ throw new Error("start must be <= end");
391
+ }
392
+ this.pos = this.start;
393
+ }
394
+ if (this.fd !== null) {
395
+ process.nextTick(function() {
396
+ self._read();
397
+ });
398
+ return;
399
+ }
400
+ fs5.open(this.path, this.flags, this.mode, function(err, fd) {
401
+ if (err) {
402
+ self.emit("error", err);
403
+ self.readable = false;
404
+ return;
405
+ }
406
+ self.fd = fd;
407
+ self.emit("open", fd);
408
+ self._read();
409
+ });
410
+ }
411
+ function WriteStream(path4, options) {
412
+ if (!(this instanceof WriteStream)) return new WriteStream(path4, options);
413
+ Stream.call(this);
414
+ this.path = path4;
415
+ this.fd = null;
416
+ this.writable = true;
417
+ this.flags = "w";
418
+ this.encoding = "binary";
419
+ this.mode = 438;
420
+ this.bytesWritten = 0;
421
+ options = options || {};
422
+ var keys = Object.keys(options);
423
+ for (var index = 0, length = keys.length; index < length; index++) {
424
+ var key = keys[index];
425
+ this[key] = options[key];
426
+ }
427
+ if (this.start !== void 0) {
428
+ if ("number" !== typeof this.start) {
429
+ throw TypeError("start must be a Number");
430
+ }
431
+ if (this.start < 0) {
432
+ throw new Error("start must be >= zero");
433
+ }
434
+ this.pos = this.start;
435
+ }
436
+ this.busy = false;
437
+ this._queue = [];
438
+ if (this.fd === null) {
439
+ this._open = fs5.open;
440
+ this._queue.push([this._open, this.path, this.flags, this.mode, void 0]);
441
+ this.flush();
442
+ }
443
+ }
444
+ }
445
+ }
446
+ });
447
+
448
+ // ../../node_modules/graceful-fs/clone.js
449
+ var require_clone = __commonJS({
450
+ "../../node_modules/graceful-fs/clone.js"(exports2, module2) {
451
+ "use strict";
452
+ module2.exports = clone;
453
+ var getPrototypeOf = Object.getPrototypeOf || function(obj) {
454
+ return obj.__proto__;
455
+ };
456
+ function clone(obj) {
457
+ if (obj === null || typeof obj !== "object")
458
+ return obj;
459
+ if (obj instanceof Object)
460
+ var copy2 = { __proto__: getPrototypeOf(obj) };
461
+ else
462
+ var copy2 = /* @__PURE__ */ Object.create(null);
463
+ Object.getOwnPropertyNames(obj).forEach(function(key) {
464
+ Object.defineProperty(copy2, key, Object.getOwnPropertyDescriptor(obj, key));
465
+ });
466
+ return copy2;
467
+ }
468
+ }
469
+ });
470
+
471
+ // ../../node_modules/graceful-fs/graceful-fs.js
472
+ var require_graceful_fs = __commonJS({
473
+ "../../node_modules/graceful-fs/graceful-fs.js"(exports2, module2) {
474
+ "use strict";
475
+ var fs5 = require("fs");
476
+ var polyfills = require_polyfills();
477
+ var legacy = require_legacy_streams();
478
+ var clone = require_clone();
479
+ var util = require("util");
480
+ var gracefulQueue;
481
+ var previousSymbol;
482
+ if (typeof Symbol === "function" && typeof Symbol.for === "function") {
483
+ gracefulQueue = Symbol.for("graceful-fs.queue");
484
+ previousSymbol = Symbol.for("graceful-fs.previous");
485
+ } else {
486
+ gracefulQueue = "___graceful-fs.queue";
487
+ previousSymbol = "___graceful-fs.previous";
488
+ }
489
+ function noop() {
490
+ }
491
+ function publishQueue(context, queue2) {
492
+ Object.defineProperty(context, gracefulQueue, {
493
+ get: function() {
494
+ return queue2;
495
+ }
496
+ });
497
+ }
498
+ var debug2 = noop;
499
+ if (util.debuglog)
500
+ debug2 = util.debuglog("gfs4");
501
+ else if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || ""))
502
+ debug2 = function() {
503
+ var m = util.format.apply(util, arguments);
504
+ m = "GFS4: " + m.split(/\n/).join("\nGFS4: ");
505
+ console.error(m);
506
+ };
507
+ if (!fs5[gracefulQueue]) {
508
+ queue = global[gracefulQueue] || [];
509
+ publishQueue(fs5, queue);
510
+ fs5.close = (function(fs$close) {
511
+ function close(fd, cb) {
512
+ return fs$close.call(fs5, fd, function(err) {
513
+ if (!err) {
514
+ resetQueue();
515
+ }
516
+ if (typeof cb === "function")
517
+ cb.apply(this, arguments);
518
+ });
519
+ }
520
+ Object.defineProperty(close, previousSymbol, {
521
+ value: fs$close
522
+ });
523
+ return close;
524
+ })(fs5.close);
525
+ fs5.closeSync = (function(fs$closeSync) {
526
+ function closeSync(fd) {
527
+ fs$closeSync.apply(fs5, arguments);
528
+ resetQueue();
529
+ }
530
+ Object.defineProperty(closeSync, previousSymbol, {
531
+ value: fs$closeSync
532
+ });
533
+ return closeSync;
534
+ })(fs5.closeSync);
535
+ if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || "")) {
536
+ process.on("exit", function() {
537
+ debug2(fs5[gracefulQueue]);
538
+ require("assert").equal(fs5[gracefulQueue].length, 0);
539
+ });
540
+ }
541
+ }
542
+ var queue;
543
+ if (!global[gracefulQueue]) {
544
+ publishQueue(global, fs5[gracefulQueue]);
545
+ }
546
+ module2.exports = patch(clone(fs5));
547
+ if (process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH && !fs5.__patched) {
548
+ module2.exports = patch(fs5);
549
+ fs5.__patched = true;
550
+ }
551
+ function patch(fs6) {
552
+ polyfills(fs6);
553
+ fs6.gracefulify = patch;
554
+ fs6.createReadStream = createReadStream;
555
+ fs6.createWriteStream = createWriteStream;
556
+ var fs$readFile = fs6.readFile;
557
+ fs6.readFile = readFile;
558
+ function readFile(path4, options, cb) {
559
+ if (typeof options === "function")
560
+ cb = options, options = null;
561
+ return go$readFile(path4, options, cb);
562
+ function go$readFile(path5, options2, cb2, startTime) {
563
+ return fs$readFile(path5, options2, function(err) {
564
+ if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
565
+ enqueue([go$readFile, [path5, options2, cb2], err, startTime || Date.now(), Date.now()]);
566
+ else {
567
+ if (typeof cb2 === "function")
568
+ cb2.apply(this, arguments);
569
+ }
570
+ });
571
+ }
572
+ }
573
+ var fs$writeFile = fs6.writeFile;
574
+ fs6.writeFile = writeFile;
575
+ function writeFile(path4, data, options, cb) {
576
+ if (typeof options === "function")
577
+ cb = options, options = null;
578
+ return go$writeFile(path4, data, options, cb);
579
+ function go$writeFile(path5, data2, options2, cb2, startTime) {
580
+ return fs$writeFile(path5, data2, options2, function(err) {
581
+ if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
582
+ enqueue([go$writeFile, [path5, data2, options2, cb2], err, startTime || Date.now(), Date.now()]);
583
+ else {
584
+ if (typeof cb2 === "function")
585
+ cb2.apply(this, arguments);
586
+ }
587
+ });
588
+ }
589
+ }
590
+ var fs$appendFile = fs6.appendFile;
591
+ if (fs$appendFile)
592
+ fs6.appendFile = appendFile;
593
+ function appendFile(path4, data, options, cb) {
594
+ if (typeof options === "function")
595
+ cb = options, options = null;
596
+ return go$appendFile(path4, data, options, cb);
597
+ function go$appendFile(path5, data2, options2, cb2, startTime) {
598
+ return fs$appendFile(path5, data2, options2, function(err) {
599
+ if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
600
+ enqueue([go$appendFile, [path5, data2, options2, cb2], err, startTime || Date.now(), Date.now()]);
601
+ else {
602
+ if (typeof cb2 === "function")
603
+ cb2.apply(this, arguments);
604
+ }
605
+ });
606
+ }
607
+ }
608
+ var fs$copyFile = fs6.copyFile;
609
+ if (fs$copyFile)
610
+ fs6.copyFile = copyFile;
611
+ function copyFile(src, dest, flags, cb) {
612
+ if (typeof flags === "function") {
613
+ cb = flags;
614
+ flags = 0;
615
+ }
616
+ return go$copyFile(src, dest, flags, cb);
617
+ function go$copyFile(src2, dest2, flags2, cb2, startTime) {
618
+ return fs$copyFile(src2, dest2, flags2, function(err) {
619
+ if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
620
+ enqueue([go$copyFile, [src2, dest2, flags2, cb2], err, startTime || Date.now(), Date.now()]);
621
+ else {
622
+ if (typeof cb2 === "function")
623
+ cb2.apply(this, arguments);
624
+ }
625
+ });
626
+ }
627
+ }
628
+ var fs$readdir = fs6.readdir;
629
+ fs6.readdir = readdir;
630
+ var noReaddirOptionVersions = /^v[0-5]\./;
631
+ function readdir(path4, options, cb) {
632
+ if (typeof options === "function")
633
+ cb = options, options = null;
634
+ var go$readdir = noReaddirOptionVersions.test(process.version) ? function go$readdir2(path5, options2, cb2, startTime) {
635
+ return fs$readdir(path5, fs$readdirCallback(
636
+ path5,
637
+ options2,
638
+ cb2,
639
+ startTime
640
+ ));
641
+ } : function go$readdir2(path5, options2, cb2, startTime) {
642
+ return fs$readdir(path5, options2, fs$readdirCallback(
643
+ path5,
644
+ options2,
645
+ cb2,
646
+ startTime
647
+ ));
648
+ };
649
+ return go$readdir(path4, options, cb);
650
+ function fs$readdirCallback(path5, options2, cb2, startTime) {
651
+ return function(err, files) {
652
+ if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
653
+ enqueue([
654
+ go$readdir,
655
+ [path5, options2, cb2],
656
+ err,
657
+ startTime || Date.now(),
658
+ Date.now()
659
+ ]);
660
+ else {
661
+ if (files && files.sort)
662
+ files.sort();
663
+ if (typeof cb2 === "function")
664
+ cb2.call(this, err, files);
665
+ }
666
+ };
667
+ }
668
+ }
669
+ if (process.version.substr(0, 4) === "v0.8") {
670
+ var legStreams = legacy(fs6);
671
+ ReadStream = legStreams.ReadStream;
672
+ WriteStream = legStreams.WriteStream;
673
+ }
674
+ var fs$ReadStream = fs6.ReadStream;
675
+ if (fs$ReadStream) {
676
+ ReadStream.prototype = Object.create(fs$ReadStream.prototype);
677
+ ReadStream.prototype.open = ReadStream$open;
678
+ }
679
+ var fs$WriteStream = fs6.WriteStream;
680
+ if (fs$WriteStream) {
681
+ WriteStream.prototype = Object.create(fs$WriteStream.prototype);
682
+ WriteStream.prototype.open = WriteStream$open;
683
+ }
684
+ Object.defineProperty(fs6, "ReadStream", {
685
+ get: function() {
686
+ return ReadStream;
687
+ },
688
+ set: function(val) {
689
+ ReadStream = val;
690
+ },
691
+ enumerable: true,
692
+ configurable: true
693
+ });
694
+ Object.defineProperty(fs6, "WriteStream", {
695
+ get: function() {
696
+ return WriteStream;
697
+ },
698
+ set: function(val) {
699
+ WriteStream = val;
700
+ },
701
+ enumerable: true,
702
+ configurable: true
703
+ });
704
+ var FileReadStream = ReadStream;
705
+ Object.defineProperty(fs6, "FileReadStream", {
706
+ get: function() {
707
+ return FileReadStream;
708
+ },
709
+ set: function(val) {
710
+ FileReadStream = val;
711
+ },
712
+ enumerable: true,
713
+ configurable: true
714
+ });
715
+ var FileWriteStream = WriteStream;
716
+ Object.defineProperty(fs6, "FileWriteStream", {
717
+ get: function() {
718
+ return FileWriteStream;
719
+ },
720
+ set: function(val) {
721
+ FileWriteStream = val;
722
+ },
723
+ enumerable: true,
724
+ configurable: true
725
+ });
726
+ function ReadStream(path4, options) {
727
+ if (this instanceof ReadStream)
728
+ return fs$ReadStream.apply(this, arguments), this;
729
+ else
730
+ return ReadStream.apply(Object.create(ReadStream.prototype), arguments);
731
+ }
732
+ function ReadStream$open() {
733
+ var that = this;
734
+ open(that.path, that.flags, that.mode, function(err, fd) {
735
+ if (err) {
736
+ if (that.autoClose)
737
+ that.destroy();
738
+ that.emit("error", err);
739
+ } else {
740
+ that.fd = fd;
741
+ that.emit("open", fd);
742
+ that.read();
743
+ }
744
+ });
745
+ }
746
+ function WriteStream(path4, options) {
747
+ if (this instanceof WriteStream)
748
+ return fs$WriteStream.apply(this, arguments), this;
749
+ else
750
+ return WriteStream.apply(Object.create(WriteStream.prototype), arguments);
751
+ }
752
+ function WriteStream$open() {
753
+ var that = this;
754
+ open(that.path, that.flags, that.mode, function(err, fd) {
755
+ if (err) {
756
+ that.destroy();
757
+ that.emit("error", err);
758
+ } else {
759
+ that.fd = fd;
760
+ that.emit("open", fd);
761
+ }
762
+ });
763
+ }
764
+ function createReadStream(path4, options) {
765
+ return new fs6.ReadStream(path4, options);
766
+ }
767
+ function createWriteStream(path4, options) {
768
+ return new fs6.WriteStream(path4, options);
769
+ }
770
+ var fs$open = fs6.open;
771
+ fs6.open = open;
772
+ function open(path4, flags, mode, cb) {
773
+ if (typeof mode === "function")
774
+ cb = mode, mode = null;
775
+ return go$open(path4, flags, mode, cb);
776
+ function go$open(path5, flags2, mode2, cb2, startTime) {
777
+ return fs$open(path5, flags2, mode2, function(err, fd) {
778
+ if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
779
+ enqueue([go$open, [path5, flags2, mode2, cb2], err, startTime || Date.now(), Date.now()]);
780
+ else {
781
+ if (typeof cb2 === "function")
782
+ cb2.apply(this, arguments);
783
+ }
784
+ });
785
+ }
786
+ }
787
+ return fs6;
788
+ }
789
+ function enqueue(elem) {
790
+ debug2("ENQUEUE", elem[0].name, elem[1]);
791
+ fs5[gracefulQueue].push(elem);
792
+ retry();
793
+ }
794
+ var retryTimer;
795
+ function resetQueue() {
796
+ var now = Date.now();
797
+ for (var i = 0; i < fs5[gracefulQueue].length; ++i) {
798
+ if (fs5[gracefulQueue][i].length > 2) {
799
+ fs5[gracefulQueue][i][3] = now;
800
+ fs5[gracefulQueue][i][4] = now;
801
+ }
802
+ }
803
+ retry();
804
+ }
805
+ function retry() {
806
+ clearTimeout(retryTimer);
807
+ retryTimer = void 0;
808
+ if (fs5[gracefulQueue].length === 0)
809
+ return;
810
+ var elem = fs5[gracefulQueue].shift();
811
+ var fn = elem[0];
812
+ var args = elem[1];
813
+ var err = elem[2];
814
+ var startTime = elem[3];
815
+ var lastTime = elem[4];
816
+ if (startTime === void 0) {
817
+ debug2("RETRY", fn.name, args);
818
+ fn.apply(null, args);
819
+ } else if (Date.now() - startTime >= 6e4) {
820
+ debug2("TIMEOUT", fn.name, args);
821
+ var cb = args.pop();
822
+ if (typeof cb === "function")
823
+ cb.call(null, err);
824
+ } else {
825
+ var sinceAttempt = Date.now() - lastTime;
826
+ var sinceStart = Math.max(lastTime - startTime, 1);
827
+ var desiredDelay = Math.min(sinceStart * 1.2, 100);
828
+ if (sinceAttempt >= desiredDelay) {
829
+ debug2("RETRY", fn.name, args);
830
+ fn.apply(null, args.concat([startTime]));
831
+ } else {
832
+ fs5[gracefulQueue].push(elem);
833
+ }
834
+ }
835
+ if (retryTimer === void 0) {
836
+ retryTimer = setTimeout(retry, 0);
837
+ }
838
+ }
839
+ }
840
+ });
841
+
842
+ // ../../node_modules/fs-extra/lib/fs/index.js
843
+ var require_fs = __commonJS({
844
+ "../../node_modules/fs-extra/lib/fs/index.js"(exports2) {
845
+ "use strict";
846
+ var u = require_universalify().fromCallback;
847
+ var fs5 = require_graceful_fs();
848
+ var api = [
849
+ "access",
850
+ "appendFile",
851
+ "chmod",
852
+ "chown",
853
+ "close",
854
+ "copyFile",
855
+ "fchmod",
856
+ "fchown",
857
+ "fdatasync",
858
+ "fstat",
859
+ "fsync",
860
+ "ftruncate",
861
+ "futimes",
862
+ "lchown",
863
+ "lchmod",
864
+ "link",
865
+ "lstat",
866
+ "mkdir",
867
+ "mkdtemp",
868
+ "open",
869
+ "readFile",
870
+ "readdir",
871
+ "readlink",
872
+ "realpath",
873
+ "rename",
874
+ "rmdir",
875
+ "stat",
876
+ "symlink",
877
+ "truncate",
878
+ "unlink",
879
+ "utimes",
880
+ "writeFile"
881
+ ].filter((key) => {
882
+ return typeof fs5[key] === "function";
883
+ });
884
+ Object.keys(fs5).forEach((key) => {
885
+ if (key === "promises") {
886
+ return;
887
+ }
888
+ exports2[key] = fs5[key];
889
+ });
890
+ api.forEach((method) => {
891
+ exports2[method] = u(fs5[method]);
892
+ });
893
+ exports2.exists = function(filename, callback) {
894
+ if (typeof callback === "function") {
895
+ return fs5.exists(filename, callback);
896
+ }
897
+ return new Promise((resolve) => {
898
+ return fs5.exists(filename, resolve);
899
+ });
900
+ };
901
+ exports2.read = function(fd, buffer, offset, length, position, callback) {
902
+ if (typeof callback === "function") {
903
+ return fs5.read(fd, buffer, offset, length, position, callback);
904
+ }
905
+ return new Promise((resolve, reject) => {
906
+ fs5.read(fd, buffer, offset, length, position, (err, bytesRead, buffer2) => {
907
+ if (err) return reject(err);
908
+ resolve({ bytesRead, buffer: buffer2 });
909
+ });
910
+ });
911
+ };
912
+ exports2.write = function(fd, buffer, ...args) {
913
+ if (typeof args[args.length - 1] === "function") {
914
+ return fs5.write(fd, buffer, ...args);
915
+ }
916
+ return new Promise((resolve, reject) => {
917
+ fs5.write(fd, buffer, ...args, (err, bytesWritten, buffer2) => {
918
+ if (err) return reject(err);
919
+ resolve({ bytesWritten, buffer: buffer2 });
920
+ });
921
+ });
922
+ };
923
+ }
924
+ });
925
+
926
+ // ../../node_modules/fs-extra/lib/mkdirs/win32.js
927
+ var require_win32 = __commonJS({
928
+ "../../node_modules/fs-extra/lib/mkdirs/win32.js"(exports2, module2) {
929
+ "use strict";
930
+ var path4 = require("path");
931
+ function getRootPath(p) {
932
+ p = path4.normalize(path4.resolve(p)).split(path4.sep);
933
+ if (p.length > 0) return p[0];
934
+ return null;
935
+ }
936
+ var INVALID_PATH_CHARS = /[<>:"|?*]/;
937
+ function invalidWin32Path(p) {
938
+ const rp = getRootPath(p);
939
+ p = p.replace(rp, "");
940
+ return INVALID_PATH_CHARS.test(p);
941
+ }
942
+ module2.exports = {
943
+ getRootPath,
944
+ invalidWin32Path
945
+ };
946
+ }
947
+ });
948
+
949
+ // ../../node_modules/fs-extra/lib/mkdirs/mkdirs.js
950
+ var require_mkdirs = __commonJS({
951
+ "../../node_modules/fs-extra/lib/mkdirs/mkdirs.js"(exports2, module2) {
952
+ "use strict";
953
+ var fs5 = require_graceful_fs();
954
+ var path4 = require("path");
955
+ var invalidWin32Path = require_win32().invalidWin32Path;
956
+ var o777 = parseInt("0777", 8);
957
+ function mkdirs(p, opts, callback, made) {
958
+ if (typeof opts === "function") {
959
+ callback = opts;
960
+ opts = {};
961
+ } else if (!opts || typeof opts !== "object") {
962
+ opts = { mode: opts };
963
+ }
964
+ if (process.platform === "win32" && invalidWin32Path(p)) {
965
+ const errInval = new Error(p + " contains invalid WIN32 path characters.");
966
+ errInval.code = "EINVAL";
967
+ return callback(errInval);
968
+ }
969
+ let mode = opts.mode;
970
+ const xfs = opts.fs || fs5;
971
+ if (mode === void 0) {
972
+ mode = o777 & ~process.umask();
973
+ }
974
+ if (!made) made = null;
975
+ callback = callback || function() {
976
+ };
977
+ p = path4.resolve(p);
978
+ xfs.mkdir(p, mode, (er) => {
979
+ if (!er) {
980
+ made = made || p;
981
+ return callback(null, made);
982
+ }
983
+ switch (er.code) {
984
+ case "ENOENT":
985
+ if (path4.dirname(p) === p) return callback(er);
986
+ mkdirs(path4.dirname(p), opts, (er2, made2) => {
987
+ if (er2) callback(er2, made2);
988
+ else mkdirs(p, opts, callback, made2);
989
+ });
990
+ break;
991
+ // In the case of any other error, just see if there's a dir
992
+ // there already. If so, then hooray! If not, then something
993
+ // is borked.
994
+ default:
995
+ xfs.stat(p, (er2, stat) => {
996
+ if (er2 || !stat.isDirectory()) callback(er, made);
997
+ else callback(null, made);
998
+ });
999
+ break;
1000
+ }
1001
+ });
1002
+ }
1003
+ module2.exports = mkdirs;
1004
+ }
1005
+ });
1006
+
1007
+ // ../../node_modules/fs-extra/lib/mkdirs/mkdirs-sync.js
1008
+ var require_mkdirs_sync = __commonJS({
1009
+ "../../node_modules/fs-extra/lib/mkdirs/mkdirs-sync.js"(exports2, module2) {
1010
+ "use strict";
1011
+ var fs5 = require_graceful_fs();
1012
+ var path4 = require("path");
1013
+ var invalidWin32Path = require_win32().invalidWin32Path;
1014
+ var o777 = parseInt("0777", 8);
1015
+ function mkdirsSync(p, opts, made) {
1016
+ if (!opts || typeof opts !== "object") {
1017
+ opts = { mode: opts };
1018
+ }
1019
+ let mode = opts.mode;
1020
+ const xfs = opts.fs || fs5;
1021
+ if (process.platform === "win32" && invalidWin32Path(p)) {
1022
+ const errInval = new Error(p + " contains invalid WIN32 path characters.");
1023
+ errInval.code = "EINVAL";
1024
+ throw errInval;
1025
+ }
1026
+ if (mode === void 0) {
1027
+ mode = o777 & ~process.umask();
1028
+ }
1029
+ if (!made) made = null;
1030
+ p = path4.resolve(p);
1031
+ try {
1032
+ xfs.mkdirSync(p, mode);
1033
+ made = made || p;
1034
+ } catch (err0) {
1035
+ if (err0.code === "ENOENT") {
1036
+ if (path4.dirname(p) === p) throw err0;
1037
+ made = mkdirsSync(path4.dirname(p), opts, made);
1038
+ mkdirsSync(p, opts, made);
1039
+ } else {
1040
+ let stat;
1041
+ try {
1042
+ stat = xfs.statSync(p);
1043
+ } catch (err1) {
1044
+ throw err0;
1045
+ }
1046
+ if (!stat.isDirectory()) throw err0;
1047
+ }
1048
+ }
1049
+ return made;
1050
+ }
1051
+ module2.exports = mkdirsSync;
1052
+ }
1053
+ });
1054
+
1055
+ // ../../node_modules/fs-extra/lib/mkdirs/index.js
1056
+ var require_mkdirs2 = __commonJS({
1057
+ "../../node_modules/fs-extra/lib/mkdirs/index.js"(exports2, module2) {
1058
+ "use strict";
1059
+ var u = require_universalify().fromCallback;
1060
+ var mkdirs = u(require_mkdirs());
1061
+ var mkdirsSync = require_mkdirs_sync();
1062
+ module2.exports = {
1063
+ mkdirs,
1064
+ mkdirsSync,
1065
+ // alias
1066
+ mkdirp: mkdirs,
1067
+ mkdirpSync: mkdirsSync,
1068
+ ensureDir: mkdirs,
1069
+ ensureDirSync: mkdirsSync
1070
+ };
1071
+ }
1072
+ });
1073
+
1074
+ // ../../node_modules/fs-extra/lib/util/utimes.js
1075
+ var require_utimes = __commonJS({
1076
+ "../../node_modules/fs-extra/lib/util/utimes.js"(exports2, module2) {
1077
+ "use strict";
1078
+ var fs5 = require_graceful_fs();
1079
+ var os4 = require("os");
1080
+ var path4 = require("path");
1081
+ function hasMillisResSync() {
1082
+ let tmpfile = path4.join("millis-test-sync" + Date.now().toString() + Math.random().toString().slice(2));
1083
+ tmpfile = path4.join(os4.tmpdir(), tmpfile);
1084
+ const d = /* @__PURE__ */ new Date(1435410243862);
1085
+ fs5.writeFileSync(tmpfile, "https://github.com/jprichardson/node-fs-extra/pull/141");
1086
+ const fd = fs5.openSync(tmpfile, "r+");
1087
+ fs5.futimesSync(fd, d, d);
1088
+ fs5.closeSync(fd);
1089
+ return fs5.statSync(tmpfile).mtime > 1435410243e3;
1090
+ }
1091
+ function hasMillisRes(callback) {
1092
+ let tmpfile = path4.join("millis-test" + Date.now().toString() + Math.random().toString().slice(2));
1093
+ tmpfile = path4.join(os4.tmpdir(), tmpfile);
1094
+ const d = /* @__PURE__ */ new Date(1435410243862);
1095
+ fs5.writeFile(tmpfile, "https://github.com/jprichardson/node-fs-extra/pull/141", (err) => {
1096
+ if (err) return callback(err);
1097
+ fs5.open(tmpfile, "r+", (err2, fd) => {
1098
+ if (err2) return callback(err2);
1099
+ fs5.futimes(fd, d, d, (err3) => {
1100
+ if (err3) return callback(err3);
1101
+ fs5.close(fd, (err4) => {
1102
+ if (err4) return callback(err4);
1103
+ fs5.stat(tmpfile, (err5, stats) => {
1104
+ if (err5) return callback(err5);
1105
+ callback(null, stats.mtime > 1435410243e3);
1106
+ });
1107
+ });
1108
+ });
1109
+ });
1110
+ });
1111
+ }
1112
+ function timeRemoveMillis(timestamp) {
1113
+ if (typeof timestamp === "number") {
1114
+ return Math.floor(timestamp / 1e3) * 1e3;
1115
+ } else if (timestamp instanceof Date) {
1116
+ return new Date(Math.floor(timestamp.getTime() / 1e3) * 1e3);
1117
+ } else {
1118
+ throw new Error("fs-extra: timeRemoveMillis() unknown parameter type");
1119
+ }
1120
+ }
1121
+ function utimesMillis(path5, atime, mtime, callback) {
1122
+ fs5.open(path5, "r+", (err, fd) => {
1123
+ if (err) return callback(err);
1124
+ fs5.futimes(fd, atime, mtime, (futimesErr) => {
1125
+ fs5.close(fd, (closeErr) => {
1126
+ if (callback) callback(futimesErr || closeErr);
1127
+ });
1128
+ });
1129
+ });
1130
+ }
1131
+ function utimesMillisSync(path5, atime, mtime) {
1132
+ const fd = fs5.openSync(path5, "r+");
1133
+ fs5.futimesSync(fd, atime, mtime);
1134
+ return fs5.closeSync(fd);
1135
+ }
1136
+ module2.exports = {
1137
+ hasMillisRes,
1138
+ hasMillisResSync,
1139
+ timeRemoveMillis,
1140
+ utimesMillis,
1141
+ utimesMillisSync
1142
+ };
1143
+ }
1144
+ });
1145
+
1146
+ // ../../node_modules/fs-extra/lib/util/buffer.js
1147
+ var require_buffer = __commonJS({
1148
+ "../../node_modules/fs-extra/lib/util/buffer.js"(exports2, module2) {
1149
+ "use strict";
1150
+ module2.exports = function(size) {
1151
+ if (typeof Buffer.allocUnsafe === "function") {
1152
+ try {
1153
+ return Buffer.allocUnsafe(size);
1154
+ } catch (e) {
1155
+ return new Buffer(size);
1156
+ }
1157
+ }
1158
+ return new Buffer(size);
1159
+ };
1160
+ }
1161
+ });
1162
+
1163
+ // ../../node_modules/fs-extra/lib/copy-sync/copy-sync.js
1164
+ var require_copy_sync = __commonJS({
1165
+ "../../node_modules/fs-extra/lib/copy-sync/copy-sync.js"(exports2, module2) {
1166
+ "use strict";
1167
+ var fs5 = require_graceful_fs();
1168
+ var path4 = require("path");
1169
+ var mkdirpSync = require_mkdirs2().mkdirsSync;
1170
+ var utimesSync = require_utimes().utimesMillisSync;
1171
+ var notExist = Symbol("notExist");
1172
+ function copySync(src, dest, opts) {
1173
+ if (typeof opts === "function") {
1174
+ opts = { filter: opts };
1175
+ }
1176
+ opts = opts || {};
1177
+ opts.clobber = "clobber" in opts ? !!opts.clobber : true;
1178
+ opts.overwrite = "overwrite" in opts ? !!opts.overwrite : opts.clobber;
1179
+ if (opts.preserveTimestamps && process.arch === "ia32") {
1180
+ console.warn(`fs-extra: Using the preserveTimestamps option in 32-bit node is not recommended;
1181
+
1182
+ see https://github.com/jprichardson/node-fs-extra/issues/269`);
1183
+ }
1184
+ const destStat = checkPaths(src, dest);
1185
+ if (opts.filter && !opts.filter(src, dest)) return;
1186
+ const destParent = path4.dirname(dest);
1187
+ if (!fs5.existsSync(destParent)) mkdirpSync(destParent);
1188
+ return startCopy(destStat, src, dest, opts);
1189
+ }
1190
+ function startCopy(destStat, src, dest, opts) {
1191
+ if (opts.filter && !opts.filter(src, dest)) return;
1192
+ return getStats(destStat, src, dest, opts);
1193
+ }
1194
+ function getStats(destStat, src, dest, opts) {
1195
+ const statSync = opts.dereference ? fs5.statSync : fs5.lstatSync;
1196
+ const srcStat = statSync(src);
1197
+ if (srcStat.isDirectory()) return onDir(srcStat, destStat, src, dest, opts);
1198
+ else if (srcStat.isFile() || srcStat.isCharacterDevice() || srcStat.isBlockDevice()) return onFile(srcStat, destStat, src, dest, opts);
1199
+ else if (srcStat.isSymbolicLink()) return onLink(destStat, src, dest, opts);
1200
+ }
1201
+ function onFile(srcStat, destStat, src, dest, opts) {
1202
+ if (destStat === notExist) return copyFile(srcStat, src, dest, opts);
1203
+ return mayCopyFile(srcStat, src, dest, opts);
1204
+ }
1205
+ function mayCopyFile(srcStat, src, dest, opts) {
1206
+ if (opts.overwrite) {
1207
+ fs5.unlinkSync(dest);
1208
+ return copyFile(srcStat, src, dest, opts);
1209
+ } else if (opts.errorOnExist) {
1210
+ throw new Error(`'${dest}' already exists`);
1211
+ }
1212
+ }
1213
+ function copyFile(srcStat, src, dest, opts) {
1214
+ if (typeof fs5.copyFileSync === "function") {
1215
+ fs5.copyFileSync(src, dest);
1216
+ fs5.chmodSync(dest, srcStat.mode);
1217
+ if (opts.preserveTimestamps) {
1218
+ return utimesSync(dest, srcStat.atime, srcStat.mtime);
1219
+ }
1220
+ return;
1221
+ }
1222
+ return copyFileFallback(srcStat, src, dest, opts);
1223
+ }
1224
+ function copyFileFallback(srcStat, src, dest, opts) {
1225
+ const BUF_LENGTH = 64 * 1024;
1226
+ const _buff = require_buffer()(BUF_LENGTH);
1227
+ const fdr = fs5.openSync(src, "r");
1228
+ const fdw = fs5.openSync(dest, "w", srcStat.mode);
1229
+ let pos = 0;
1230
+ while (pos < srcStat.size) {
1231
+ const bytesRead = fs5.readSync(fdr, _buff, 0, BUF_LENGTH, pos);
1232
+ fs5.writeSync(fdw, _buff, 0, bytesRead);
1233
+ pos += bytesRead;
1234
+ }
1235
+ if (opts.preserveTimestamps) fs5.futimesSync(fdw, srcStat.atime, srcStat.mtime);
1236
+ fs5.closeSync(fdr);
1237
+ fs5.closeSync(fdw);
1238
+ }
1239
+ function onDir(srcStat, destStat, src, dest, opts) {
1240
+ if (destStat === notExist) return mkDirAndCopy(srcStat, src, dest, opts);
1241
+ if (destStat && !destStat.isDirectory()) {
1242
+ throw new Error(`Cannot overwrite non-directory '${dest}' with directory '${src}'.`);
1243
+ }
1244
+ return copyDir(src, dest, opts);
1245
+ }
1246
+ function mkDirAndCopy(srcStat, src, dest, opts) {
1247
+ fs5.mkdirSync(dest);
1248
+ copyDir(src, dest, opts);
1249
+ return fs5.chmodSync(dest, srcStat.mode);
1250
+ }
1251
+ function copyDir(src, dest, opts) {
1252
+ fs5.readdirSync(src).forEach((item) => copyDirItem(item, src, dest, opts));
1253
+ }
1254
+ function copyDirItem(item, src, dest, opts) {
1255
+ const srcItem = path4.join(src, item);
1256
+ const destItem = path4.join(dest, item);
1257
+ const destStat = checkPaths(srcItem, destItem);
1258
+ return startCopy(destStat, srcItem, destItem, opts);
1259
+ }
1260
+ function onLink(destStat, src, dest, opts) {
1261
+ let resolvedSrc = fs5.readlinkSync(src);
1262
+ if (opts.dereference) {
1263
+ resolvedSrc = path4.resolve(process.cwd(), resolvedSrc);
1264
+ }
1265
+ if (destStat === notExist) {
1266
+ return fs5.symlinkSync(resolvedSrc, dest);
1267
+ } else {
1268
+ let resolvedDest;
1269
+ try {
1270
+ resolvedDest = fs5.readlinkSync(dest);
1271
+ } catch (err) {
1272
+ if (err.code === "EINVAL" || err.code === "UNKNOWN") return fs5.symlinkSync(resolvedSrc, dest);
1273
+ throw err;
1274
+ }
1275
+ if (opts.dereference) {
1276
+ resolvedDest = path4.resolve(process.cwd(), resolvedDest);
1277
+ }
1278
+ if (isSrcSubdir(resolvedSrc, resolvedDest)) {
1279
+ throw new Error(`Cannot copy '${resolvedSrc}' to a subdirectory of itself, '${resolvedDest}'.`);
1280
+ }
1281
+ if (fs5.statSync(dest).isDirectory() && isSrcSubdir(resolvedDest, resolvedSrc)) {
1282
+ throw new Error(`Cannot overwrite '${resolvedDest}' with '${resolvedSrc}'.`);
1283
+ }
1284
+ return copyLink(resolvedSrc, dest);
1285
+ }
1286
+ }
1287
+ function copyLink(resolvedSrc, dest) {
1288
+ fs5.unlinkSync(dest);
1289
+ return fs5.symlinkSync(resolvedSrc, dest);
1290
+ }
1291
+ function isSrcSubdir(src, dest) {
1292
+ const srcArray = path4.resolve(src).split(path4.sep);
1293
+ const destArray = path4.resolve(dest).split(path4.sep);
1294
+ return srcArray.reduce((acc, current, i) => acc && destArray[i] === current, true);
1295
+ }
1296
+ function checkStats(src, dest) {
1297
+ const srcStat = fs5.statSync(src);
1298
+ let destStat;
1299
+ try {
1300
+ destStat = fs5.statSync(dest);
1301
+ } catch (err) {
1302
+ if (err.code === "ENOENT") return { srcStat, destStat: notExist };
1303
+ throw err;
1304
+ }
1305
+ return { srcStat, destStat };
1306
+ }
1307
+ function checkPaths(src, dest) {
1308
+ const { srcStat, destStat } = checkStats(src, dest);
1309
+ if (destStat.ino && destStat.ino === srcStat.ino) {
1310
+ throw new Error("Source and destination must not be the same.");
1311
+ }
1312
+ if (srcStat.isDirectory() && isSrcSubdir(src, dest)) {
1313
+ throw new Error(`Cannot copy '${src}' to a subdirectory of itself, '${dest}'.`);
1314
+ }
1315
+ return destStat;
1316
+ }
1317
+ module2.exports = copySync;
1318
+ }
1319
+ });
1320
+
1321
+ // ../../node_modules/fs-extra/lib/copy-sync/index.js
1322
+ var require_copy_sync2 = __commonJS({
1323
+ "../../node_modules/fs-extra/lib/copy-sync/index.js"(exports2, module2) {
1324
+ "use strict";
1325
+ module2.exports = {
1326
+ copySync: require_copy_sync()
1327
+ };
1328
+ }
1329
+ });
1330
+
1331
+ // ../../node_modules/fs-extra/lib/path-exists/index.js
1332
+ var require_path_exists = __commonJS({
1333
+ "../../node_modules/fs-extra/lib/path-exists/index.js"(exports2, module2) {
1334
+ "use strict";
1335
+ var u = require_universalify().fromPromise;
1336
+ var fs5 = require_fs();
1337
+ function pathExists(path4) {
1338
+ return fs5.access(path4).then(() => true).catch(() => false);
1339
+ }
1340
+ module2.exports = {
1341
+ pathExists: u(pathExists),
1342
+ pathExistsSync: fs5.existsSync
1343
+ };
1344
+ }
1345
+ });
1346
+
1347
+ // ../../node_modules/fs-extra/lib/copy/copy.js
1348
+ var require_copy = __commonJS({
1349
+ "../../node_modules/fs-extra/lib/copy/copy.js"(exports2, module2) {
1350
+ "use strict";
1351
+ var fs5 = require_graceful_fs();
1352
+ var path4 = require("path");
1353
+ var mkdirp = require_mkdirs2().mkdirs;
1354
+ var pathExists = require_path_exists().pathExists;
1355
+ var utimes = require_utimes().utimesMillis;
1356
+ var notExist = Symbol("notExist");
1357
+ function copy2(src, dest, opts, cb) {
1358
+ if (typeof opts === "function" && !cb) {
1359
+ cb = opts;
1360
+ opts = {};
1361
+ } else if (typeof opts === "function") {
1362
+ opts = { filter: opts };
1363
+ }
1364
+ cb = cb || function() {
1365
+ };
1366
+ opts = opts || {};
1367
+ opts.clobber = "clobber" in opts ? !!opts.clobber : true;
1368
+ opts.overwrite = "overwrite" in opts ? !!opts.overwrite : opts.clobber;
1369
+ if (opts.preserveTimestamps && process.arch === "ia32") {
1370
+ console.warn(`fs-extra: Using the preserveTimestamps option in 32-bit node is not recommended;
1371
+
1372
+ see https://github.com/jprichardson/node-fs-extra/issues/269`);
1373
+ }
1374
+ checkPaths(src, dest, (err, destStat) => {
1375
+ if (err) return cb(err);
1376
+ if (opts.filter) return handleFilter(checkParentDir, destStat, src, dest, opts, cb);
1377
+ return checkParentDir(destStat, src, dest, opts, cb);
1378
+ });
1379
+ }
1380
+ function checkParentDir(destStat, src, dest, opts, cb) {
1381
+ const destParent = path4.dirname(dest);
1382
+ pathExists(destParent, (err, dirExists) => {
1383
+ if (err) return cb(err);
1384
+ if (dirExists) return startCopy(destStat, src, dest, opts, cb);
1385
+ mkdirp(destParent, (err2) => {
1386
+ if (err2) return cb(err2);
1387
+ return startCopy(destStat, src, dest, opts, cb);
1388
+ });
1389
+ });
1390
+ }
1391
+ function handleFilter(onInclude, destStat, src, dest, opts, cb) {
1392
+ Promise.resolve(opts.filter(src, dest)).then((include) => {
1393
+ if (include) {
1394
+ if (destStat) return onInclude(destStat, src, dest, opts, cb);
1395
+ return onInclude(src, dest, opts, cb);
1396
+ }
1397
+ return cb();
1398
+ }, (error) => cb(error));
1399
+ }
1400
+ function startCopy(destStat, src, dest, opts, cb) {
1401
+ if (opts.filter) return handleFilter(getStats, destStat, src, dest, opts, cb);
1402
+ return getStats(destStat, src, dest, opts, cb);
1403
+ }
1404
+ function getStats(destStat, src, dest, opts, cb) {
1405
+ const stat = opts.dereference ? fs5.stat : fs5.lstat;
1406
+ stat(src, (err, srcStat) => {
1407
+ if (err) return cb(err);
1408
+ if (srcStat.isDirectory()) return onDir(srcStat, destStat, src, dest, opts, cb);
1409
+ else if (srcStat.isFile() || srcStat.isCharacterDevice() || srcStat.isBlockDevice()) return onFile(srcStat, destStat, src, dest, opts, cb);
1410
+ else if (srcStat.isSymbolicLink()) return onLink(destStat, src, dest, opts, cb);
1411
+ });
1412
+ }
1413
+ function onFile(srcStat, destStat, src, dest, opts, cb) {
1414
+ if (destStat === notExist) return copyFile(srcStat, src, dest, opts, cb);
1415
+ return mayCopyFile(srcStat, src, dest, opts, cb);
1416
+ }
1417
+ function mayCopyFile(srcStat, src, dest, opts, cb) {
1418
+ if (opts.overwrite) {
1419
+ fs5.unlink(dest, (err) => {
1420
+ if (err) return cb(err);
1421
+ return copyFile(srcStat, src, dest, opts, cb);
1422
+ });
1423
+ } else if (opts.errorOnExist) {
1424
+ return cb(new Error(`'${dest}' already exists`));
1425
+ } else return cb();
1426
+ }
1427
+ function copyFile(srcStat, src, dest, opts, cb) {
1428
+ if (typeof fs5.copyFile === "function") {
1429
+ return fs5.copyFile(src, dest, (err) => {
1430
+ if (err) return cb(err);
1431
+ return setDestModeAndTimestamps(srcStat, dest, opts, cb);
1432
+ });
1433
+ }
1434
+ return copyFileFallback(srcStat, src, dest, opts, cb);
1435
+ }
1436
+ function copyFileFallback(srcStat, src, dest, opts, cb) {
1437
+ const rs = fs5.createReadStream(src);
1438
+ rs.on("error", (err) => cb(err)).once("open", () => {
1439
+ const ws = fs5.createWriteStream(dest, { mode: srcStat.mode });
1440
+ ws.on("error", (err) => cb(err)).on("open", () => rs.pipe(ws)).once("close", () => setDestModeAndTimestamps(srcStat, dest, opts, cb));
1441
+ });
1442
+ }
1443
+ function setDestModeAndTimestamps(srcStat, dest, opts, cb) {
1444
+ fs5.chmod(dest, srcStat.mode, (err) => {
1445
+ if (err) return cb(err);
1446
+ if (opts.preserveTimestamps) {
1447
+ return utimes(dest, srcStat.atime, srcStat.mtime, cb);
1448
+ }
1449
+ return cb();
1450
+ });
1451
+ }
1452
+ function onDir(srcStat, destStat, src, dest, opts, cb) {
1453
+ if (destStat === notExist) return mkDirAndCopy(srcStat, src, dest, opts, cb);
1454
+ if (destStat && !destStat.isDirectory()) {
1455
+ return cb(new Error(`Cannot overwrite non-directory '${dest}' with directory '${src}'.`));
1456
+ }
1457
+ return copyDir(src, dest, opts, cb);
1458
+ }
1459
+ function mkDirAndCopy(srcStat, src, dest, opts, cb) {
1460
+ fs5.mkdir(dest, (err) => {
1461
+ if (err) return cb(err);
1462
+ copyDir(src, dest, opts, (err2) => {
1463
+ if (err2) return cb(err2);
1464
+ return fs5.chmod(dest, srcStat.mode, cb);
1465
+ });
1466
+ });
1467
+ }
1468
+ function copyDir(src, dest, opts, cb) {
1469
+ fs5.readdir(src, (err, items) => {
1470
+ if (err) return cb(err);
1471
+ return copyDirItems(items, src, dest, opts, cb);
1472
+ });
1473
+ }
1474
+ function copyDirItems(items, src, dest, opts, cb) {
1475
+ const item = items.pop();
1476
+ if (!item) return cb();
1477
+ return copyDirItem(items, item, src, dest, opts, cb);
1478
+ }
1479
+ function copyDirItem(items, item, src, dest, opts, cb) {
1480
+ const srcItem = path4.join(src, item);
1481
+ const destItem = path4.join(dest, item);
1482
+ checkPaths(srcItem, destItem, (err, destStat) => {
1483
+ if (err) return cb(err);
1484
+ startCopy(destStat, srcItem, destItem, opts, (err2) => {
1485
+ if (err2) return cb(err2);
1486
+ return copyDirItems(items, src, dest, opts, cb);
1487
+ });
1488
+ });
1489
+ }
1490
+ function onLink(destStat, src, dest, opts, cb) {
1491
+ fs5.readlink(src, (err, resolvedSrc) => {
1492
+ if (err) return cb(err);
1493
+ if (opts.dereference) {
1494
+ resolvedSrc = path4.resolve(process.cwd(), resolvedSrc);
1495
+ }
1496
+ if (destStat === notExist) {
1497
+ return fs5.symlink(resolvedSrc, dest, cb);
1498
+ } else {
1499
+ fs5.readlink(dest, (err2, resolvedDest) => {
1500
+ if (err2) {
1501
+ if (err2.code === "EINVAL" || err2.code === "UNKNOWN") return fs5.symlink(resolvedSrc, dest, cb);
1502
+ return cb(err2);
1503
+ }
1504
+ if (opts.dereference) {
1505
+ resolvedDest = path4.resolve(process.cwd(), resolvedDest);
1506
+ }
1507
+ if (isSrcSubdir(resolvedSrc, resolvedDest)) {
1508
+ return cb(new Error(`Cannot copy '${resolvedSrc}' to a subdirectory of itself, '${resolvedDest}'.`));
1509
+ }
1510
+ if (destStat.isDirectory() && isSrcSubdir(resolvedDest, resolvedSrc)) {
1511
+ return cb(new Error(`Cannot overwrite '${resolvedDest}' with '${resolvedSrc}'.`));
1512
+ }
1513
+ return copyLink(resolvedSrc, dest, cb);
1514
+ });
1515
+ }
1516
+ });
1517
+ }
1518
+ function copyLink(resolvedSrc, dest, cb) {
1519
+ fs5.unlink(dest, (err) => {
1520
+ if (err) return cb(err);
1521
+ return fs5.symlink(resolvedSrc, dest, cb);
1522
+ });
1523
+ }
1524
+ function isSrcSubdir(src, dest) {
1525
+ const srcArray = path4.resolve(src).split(path4.sep);
1526
+ const destArray = path4.resolve(dest).split(path4.sep);
1527
+ return srcArray.reduce((acc, current, i) => acc && destArray[i] === current, true);
1528
+ }
1529
+ function checkStats(src, dest, cb) {
1530
+ fs5.stat(src, (err, srcStat) => {
1531
+ if (err) return cb(err);
1532
+ fs5.stat(dest, (err2, destStat) => {
1533
+ if (err2) {
1534
+ if (err2.code === "ENOENT") return cb(null, { srcStat, destStat: notExist });
1535
+ return cb(err2);
1536
+ }
1537
+ return cb(null, { srcStat, destStat });
1538
+ });
1539
+ });
1540
+ }
1541
+ function checkPaths(src, dest, cb) {
1542
+ checkStats(src, dest, (err, stats) => {
1543
+ if (err) return cb(err);
1544
+ const { srcStat, destStat } = stats;
1545
+ if (destStat.ino && destStat.ino === srcStat.ino) {
1546
+ return cb(new Error("Source and destination must not be the same."));
1547
+ }
1548
+ if (srcStat.isDirectory() && isSrcSubdir(src, dest)) {
1549
+ return cb(new Error(`Cannot copy '${src}' to a subdirectory of itself, '${dest}'.`));
1550
+ }
1551
+ return cb(null, destStat);
1552
+ });
1553
+ }
1554
+ module2.exports = copy2;
1555
+ }
1556
+ });
1557
+
1558
+ // ../../node_modules/fs-extra/lib/copy/index.js
1559
+ var require_copy2 = __commonJS({
1560
+ "../../node_modules/fs-extra/lib/copy/index.js"(exports2, module2) {
1561
+ "use strict";
1562
+ var u = require_universalify().fromCallback;
1563
+ module2.exports = {
1564
+ copy: u(require_copy())
1565
+ };
1566
+ }
1567
+ });
1568
+
1569
+ // ../../node_modules/fs-extra/lib/remove/rimraf.js
1570
+ var require_rimraf = __commonJS({
1571
+ "../../node_modules/fs-extra/lib/remove/rimraf.js"(exports2, module2) {
1572
+ "use strict";
1573
+ var fs5 = require_graceful_fs();
1574
+ var path4 = require("path");
1575
+ var assert = require("assert");
1576
+ var isWindows = process.platform === "win32";
1577
+ function defaults(options) {
1578
+ const methods = [
1579
+ "unlink",
1580
+ "chmod",
1581
+ "stat",
1582
+ "lstat",
1583
+ "rmdir",
1584
+ "readdir"
1585
+ ];
1586
+ methods.forEach((m) => {
1587
+ options[m] = options[m] || fs5[m];
1588
+ m = m + "Sync";
1589
+ options[m] = options[m] || fs5[m];
1590
+ });
1591
+ options.maxBusyTries = options.maxBusyTries || 3;
1592
+ }
1593
+ function rimraf(p, options, cb) {
1594
+ let busyTries = 0;
1595
+ if (typeof options === "function") {
1596
+ cb = options;
1597
+ options = {};
1598
+ }
1599
+ assert(p, "rimraf: missing path");
1600
+ assert.strictEqual(typeof p, "string", "rimraf: path should be a string");
1601
+ assert.strictEqual(typeof cb, "function", "rimraf: callback function required");
1602
+ assert(options, "rimraf: invalid options argument provided");
1603
+ assert.strictEqual(typeof options, "object", "rimraf: options should be object");
1604
+ defaults(options);
1605
+ rimraf_(p, options, function CB(er) {
1606
+ if (er) {
1607
+ if ((er.code === "EBUSY" || er.code === "ENOTEMPTY" || er.code === "EPERM") && busyTries < options.maxBusyTries) {
1608
+ busyTries++;
1609
+ const time = busyTries * 100;
1610
+ return setTimeout(() => rimraf_(p, options, CB), time);
1611
+ }
1612
+ if (er.code === "ENOENT") er = null;
1613
+ }
1614
+ cb(er);
1615
+ });
1616
+ }
1617
+ function rimraf_(p, options, cb) {
1618
+ assert(p);
1619
+ assert(options);
1620
+ assert(typeof cb === "function");
1621
+ options.lstat(p, (er, st) => {
1622
+ if (er && er.code === "ENOENT") {
1623
+ return cb(null);
1624
+ }
1625
+ if (er && er.code === "EPERM" && isWindows) {
1626
+ return fixWinEPERM(p, options, er, cb);
1627
+ }
1628
+ if (st && st.isDirectory()) {
1629
+ return rmdir(p, options, er, cb);
1630
+ }
1631
+ options.unlink(p, (er2) => {
1632
+ if (er2) {
1633
+ if (er2.code === "ENOENT") {
1634
+ return cb(null);
1635
+ }
1636
+ if (er2.code === "EPERM") {
1637
+ return isWindows ? fixWinEPERM(p, options, er2, cb) : rmdir(p, options, er2, cb);
1638
+ }
1639
+ if (er2.code === "EISDIR") {
1640
+ return rmdir(p, options, er2, cb);
1641
+ }
1642
+ }
1643
+ return cb(er2);
1644
+ });
1645
+ });
1646
+ }
1647
+ function fixWinEPERM(p, options, er, cb) {
1648
+ assert(p);
1649
+ assert(options);
1650
+ assert(typeof cb === "function");
1651
+ if (er) {
1652
+ assert(er instanceof Error);
1653
+ }
1654
+ options.chmod(p, 438, (er2) => {
1655
+ if (er2) {
1656
+ cb(er2.code === "ENOENT" ? null : er);
1657
+ } else {
1658
+ options.stat(p, (er3, stats) => {
1659
+ if (er3) {
1660
+ cb(er3.code === "ENOENT" ? null : er);
1661
+ } else if (stats.isDirectory()) {
1662
+ rmdir(p, options, er, cb);
1663
+ } else {
1664
+ options.unlink(p, cb);
1665
+ }
1666
+ });
1667
+ }
1668
+ });
1669
+ }
1670
+ function fixWinEPERMSync(p, options, er) {
1671
+ let stats;
1672
+ assert(p);
1673
+ assert(options);
1674
+ if (er) {
1675
+ assert(er instanceof Error);
1676
+ }
1677
+ try {
1678
+ options.chmodSync(p, 438);
1679
+ } catch (er2) {
1680
+ if (er2.code === "ENOENT") {
1681
+ return;
1682
+ } else {
1683
+ throw er;
1684
+ }
1685
+ }
1686
+ try {
1687
+ stats = options.statSync(p);
1688
+ } catch (er3) {
1689
+ if (er3.code === "ENOENT") {
1690
+ return;
1691
+ } else {
1692
+ throw er;
1693
+ }
1694
+ }
1695
+ if (stats.isDirectory()) {
1696
+ rmdirSync(p, options, er);
1697
+ } else {
1698
+ options.unlinkSync(p);
1699
+ }
1700
+ }
1701
+ function rmdir(p, options, originalEr, cb) {
1702
+ assert(p);
1703
+ assert(options);
1704
+ if (originalEr) {
1705
+ assert(originalEr instanceof Error);
1706
+ }
1707
+ assert(typeof cb === "function");
1708
+ options.rmdir(p, (er) => {
1709
+ if (er && (er.code === "ENOTEMPTY" || er.code === "EEXIST" || er.code === "EPERM")) {
1710
+ rmkids(p, options, cb);
1711
+ } else if (er && er.code === "ENOTDIR") {
1712
+ cb(originalEr);
1713
+ } else {
1714
+ cb(er);
1715
+ }
1716
+ });
1717
+ }
1718
+ function rmkids(p, options, cb) {
1719
+ assert(p);
1720
+ assert(options);
1721
+ assert(typeof cb === "function");
1722
+ options.readdir(p, (er, files) => {
1723
+ if (er) return cb(er);
1724
+ let n = files.length;
1725
+ let errState;
1726
+ if (n === 0) return options.rmdir(p, cb);
1727
+ files.forEach((f) => {
1728
+ rimraf(path4.join(p, f), options, (er2) => {
1729
+ if (errState) {
1730
+ return;
1731
+ }
1732
+ if (er2) return cb(errState = er2);
1733
+ if (--n === 0) {
1734
+ options.rmdir(p, cb);
1735
+ }
1736
+ });
1737
+ });
1738
+ });
1739
+ }
1740
+ function rimrafSync(p, options) {
1741
+ let st;
1742
+ options = options || {};
1743
+ defaults(options);
1744
+ assert(p, "rimraf: missing path");
1745
+ assert.strictEqual(typeof p, "string", "rimraf: path should be a string");
1746
+ assert(options, "rimraf: missing options");
1747
+ assert.strictEqual(typeof options, "object", "rimraf: options should be object");
1748
+ try {
1749
+ st = options.lstatSync(p);
1750
+ } catch (er) {
1751
+ if (er.code === "ENOENT") {
1752
+ return;
1753
+ }
1754
+ if (er.code === "EPERM" && isWindows) {
1755
+ fixWinEPERMSync(p, options, er);
1756
+ }
1757
+ }
1758
+ try {
1759
+ if (st && st.isDirectory()) {
1760
+ rmdirSync(p, options, null);
1761
+ } else {
1762
+ options.unlinkSync(p);
1763
+ }
1764
+ } catch (er) {
1765
+ if (er.code === "ENOENT") {
1766
+ return;
1767
+ } else if (er.code === "EPERM") {
1768
+ return isWindows ? fixWinEPERMSync(p, options, er) : rmdirSync(p, options, er);
1769
+ } else if (er.code !== "EISDIR") {
1770
+ throw er;
1771
+ }
1772
+ rmdirSync(p, options, er);
1773
+ }
1774
+ }
1775
+ function rmdirSync(p, options, originalEr) {
1776
+ assert(p);
1777
+ assert(options);
1778
+ if (originalEr) {
1779
+ assert(originalEr instanceof Error);
1780
+ }
1781
+ try {
1782
+ options.rmdirSync(p);
1783
+ } catch (er) {
1784
+ if (er.code === "ENOTDIR") {
1785
+ throw originalEr;
1786
+ } else if (er.code === "ENOTEMPTY" || er.code === "EEXIST" || er.code === "EPERM") {
1787
+ rmkidsSync(p, options);
1788
+ } else if (er.code !== "ENOENT") {
1789
+ throw er;
1790
+ }
1791
+ }
1792
+ }
1793
+ function rmkidsSync(p, options) {
1794
+ assert(p);
1795
+ assert(options);
1796
+ options.readdirSync(p).forEach((f) => rimrafSync(path4.join(p, f), options));
1797
+ if (isWindows) {
1798
+ const startTime = Date.now();
1799
+ do {
1800
+ try {
1801
+ const ret = options.rmdirSync(p, options);
1802
+ return ret;
1803
+ } catch (er) {
1804
+ }
1805
+ } while (Date.now() - startTime < 500);
1806
+ } else {
1807
+ const ret = options.rmdirSync(p, options);
1808
+ return ret;
1809
+ }
1810
+ }
1811
+ module2.exports = rimraf;
1812
+ rimraf.sync = rimrafSync;
1813
+ }
1814
+ });
1815
+
1816
+ // ../../node_modules/fs-extra/lib/remove/index.js
1817
+ var require_remove = __commonJS({
1818
+ "../../node_modules/fs-extra/lib/remove/index.js"(exports2, module2) {
1819
+ "use strict";
1820
+ var u = require_universalify().fromCallback;
1821
+ var rimraf = require_rimraf();
1822
+ module2.exports = {
1823
+ remove: u(rimraf),
1824
+ removeSync: rimraf.sync
1825
+ };
1826
+ }
1827
+ });
1828
+
1829
+ // ../../node_modules/fs-extra/lib/empty/index.js
1830
+ var require_empty = __commonJS({
1831
+ "../../node_modules/fs-extra/lib/empty/index.js"(exports2, module2) {
1832
+ "use strict";
1833
+ var u = require_universalify().fromCallback;
1834
+ var fs5 = require("fs");
1835
+ var path4 = require("path");
1836
+ var mkdir = require_mkdirs2();
1837
+ var remove = require_remove();
1838
+ var emptyDir = u(function emptyDir2(dir, callback) {
1839
+ callback = callback || function() {
1840
+ };
1841
+ fs5.readdir(dir, (err, items) => {
1842
+ if (err) return mkdir.mkdirs(dir, callback);
1843
+ items = items.map((item) => path4.join(dir, item));
1844
+ deleteItem();
1845
+ function deleteItem() {
1846
+ const item = items.pop();
1847
+ if (!item) return callback();
1848
+ remove.remove(item, (err2) => {
1849
+ if (err2) return callback(err2);
1850
+ deleteItem();
1851
+ });
1852
+ }
1853
+ });
1854
+ });
1855
+ function emptyDirSync(dir) {
1856
+ let items;
1857
+ try {
1858
+ items = fs5.readdirSync(dir);
1859
+ } catch (err) {
1860
+ return mkdir.mkdirsSync(dir);
1861
+ }
1862
+ items.forEach((item) => {
1863
+ item = path4.join(dir, item);
1864
+ remove.removeSync(item);
1865
+ });
1866
+ }
1867
+ module2.exports = {
1868
+ emptyDirSync,
1869
+ emptydirSync: emptyDirSync,
1870
+ emptyDir,
1871
+ emptydir: emptyDir
1872
+ };
1873
+ }
1874
+ });
1875
+
1876
+ // ../../node_modules/fs-extra/lib/ensure/file.js
1877
+ var require_file = __commonJS({
1878
+ "../../node_modules/fs-extra/lib/ensure/file.js"(exports2, module2) {
1879
+ "use strict";
1880
+ var u = require_universalify().fromCallback;
1881
+ var path4 = require("path");
1882
+ var fs5 = require_graceful_fs();
1883
+ var mkdir = require_mkdirs2();
1884
+ var pathExists = require_path_exists().pathExists;
1885
+ function createFile(file, callback) {
1886
+ function makeFile() {
1887
+ fs5.writeFile(file, "", (err) => {
1888
+ if (err) return callback(err);
1889
+ callback();
1890
+ });
1891
+ }
1892
+ fs5.stat(file, (err, stats) => {
1893
+ if (!err && stats.isFile()) return callback();
1894
+ const dir = path4.dirname(file);
1895
+ pathExists(dir, (err2, dirExists) => {
1896
+ if (err2) return callback(err2);
1897
+ if (dirExists) return makeFile();
1898
+ mkdir.mkdirs(dir, (err3) => {
1899
+ if (err3) return callback(err3);
1900
+ makeFile();
1901
+ });
1902
+ });
1903
+ });
1904
+ }
1905
+ function createFileSync(file) {
1906
+ let stats;
1907
+ try {
1908
+ stats = fs5.statSync(file);
1909
+ } catch (e) {
1910
+ }
1911
+ if (stats && stats.isFile()) return;
1912
+ const dir = path4.dirname(file);
1913
+ if (!fs5.existsSync(dir)) {
1914
+ mkdir.mkdirsSync(dir);
1915
+ }
1916
+ fs5.writeFileSync(file, "");
1917
+ }
1918
+ module2.exports = {
1919
+ createFile: u(createFile),
1920
+ createFileSync
1921
+ };
1922
+ }
1923
+ });
1924
+
1925
+ // ../../node_modules/fs-extra/lib/ensure/link.js
1926
+ var require_link = __commonJS({
1927
+ "../../node_modules/fs-extra/lib/ensure/link.js"(exports2, module2) {
1928
+ "use strict";
1929
+ var u = require_universalify().fromCallback;
1930
+ var path4 = require("path");
1931
+ var fs5 = require_graceful_fs();
1932
+ var mkdir = require_mkdirs2();
1933
+ var pathExists = require_path_exists().pathExists;
1934
+ function createLink(srcpath, dstpath, callback) {
1935
+ function makeLink(srcpath2, dstpath2) {
1936
+ fs5.link(srcpath2, dstpath2, (err) => {
1937
+ if (err) return callback(err);
1938
+ callback(null);
1939
+ });
1940
+ }
1941
+ pathExists(dstpath, (err, destinationExists) => {
1942
+ if (err) return callback(err);
1943
+ if (destinationExists) return callback(null);
1944
+ fs5.lstat(srcpath, (err2) => {
1945
+ if (err2) {
1946
+ err2.message = err2.message.replace("lstat", "ensureLink");
1947
+ return callback(err2);
1948
+ }
1949
+ const dir = path4.dirname(dstpath);
1950
+ pathExists(dir, (err3, dirExists) => {
1951
+ if (err3) return callback(err3);
1952
+ if (dirExists) return makeLink(srcpath, dstpath);
1953
+ mkdir.mkdirs(dir, (err4) => {
1954
+ if (err4) return callback(err4);
1955
+ makeLink(srcpath, dstpath);
1956
+ });
1957
+ });
1958
+ });
1959
+ });
1960
+ }
1961
+ function createLinkSync(srcpath, dstpath) {
1962
+ const destinationExists = fs5.existsSync(dstpath);
1963
+ if (destinationExists) return void 0;
1964
+ try {
1965
+ fs5.lstatSync(srcpath);
1966
+ } catch (err) {
1967
+ err.message = err.message.replace("lstat", "ensureLink");
1968
+ throw err;
1969
+ }
1970
+ const dir = path4.dirname(dstpath);
1971
+ const dirExists = fs5.existsSync(dir);
1972
+ if (dirExists) return fs5.linkSync(srcpath, dstpath);
1973
+ mkdir.mkdirsSync(dir);
1974
+ return fs5.linkSync(srcpath, dstpath);
1975
+ }
1976
+ module2.exports = {
1977
+ createLink: u(createLink),
1978
+ createLinkSync
1979
+ };
1980
+ }
1981
+ });
1982
+
1983
+ // ../../node_modules/fs-extra/lib/ensure/symlink-paths.js
1984
+ var require_symlink_paths = __commonJS({
1985
+ "../../node_modules/fs-extra/lib/ensure/symlink-paths.js"(exports2, module2) {
1986
+ "use strict";
1987
+ var path4 = require("path");
1988
+ var fs5 = require_graceful_fs();
1989
+ var pathExists = require_path_exists().pathExists;
1990
+ function symlinkPaths(srcpath, dstpath, callback) {
1991
+ if (path4.isAbsolute(srcpath)) {
1992
+ return fs5.lstat(srcpath, (err) => {
1993
+ if (err) {
1994
+ err.message = err.message.replace("lstat", "ensureSymlink");
1995
+ return callback(err);
1996
+ }
1997
+ return callback(null, {
1998
+ "toCwd": srcpath,
1999
+ "toDst": srcpath
2000
+ });
2001
+ });
2002
+ } else {
2003
+ const dstdir = path4.dirname(dstpath);
2004
+ const relativeToDst = path4.join(dstdir, srcpath);
2005
+ return pathExists(relativeToDst, (err, exists) => {
2006
+ if (err) return callback(err);
2007
+ if (exists) {
2008
+ return callback(null, {
2009
+ "toCwd": relativeToDst,
2010
+ "toDst": srcpath
2011
+ });
2012
+ } else {
2013
+ return fs5.lstat(srcpath, (err2) => {
2014
+ if (err2) {
2015
+ err2.message = err2.message.replace("lstat", "ensureSymlink");
2016
+ return callback(err2);
2017
+ }
2018
+ return callback(null, {
2019
+ "toCwd": srcpath,
2020
+ "toDst": path4.relative(dstdir, srcpath)
2021
+ });
2022
+ });
2023
+ }
2024
+ });
2025
+ }
2026
+ }
2027
+ function symlinkPathsSync(srcpath, dstpath) {
2028
+ let exists;
2029
+ if (path4.isAbsolute(srcpath)) {
2030
+ exists = fs5.existsSync(srcpath);
2031
+ if (!exists) throw new Error("absolute srcpath does not exist");
2032
+ return {
2033
+ "toCwd": srcpath,
2034
+ "toDst": srcpath
2035
+ };
2036
+ } else {
2037
+ const dstdir = path4.dirname(dstpath);
2038
+ const relativeToDst = path4.join(dstdir, srcpath);
2039
+ exists = fs5.existsSync(relativeToDst);
2040
+ if (exists) {
2041
+ return {
2042
+ "toCwd": relativeToDst,
2043
+ "toDst": srcpath
2044
+ };
2045
+ } else {
2046
+ exists = fs5.existsSync(srcpath);
2047
+ if (!exists) throw new Error("relative srcpath does not exist");
2048
+ return {
2049
+ "toCwd": srcpath,
2050
+ "toDst": path4.relative(dstdir, srcpath)
2051
+ };
2052
+ }
2053
+ }
2054
+ }
2055
+ module2.exports = {
2056
+ symlinkPaths,
2057
+ symlinkPathsSync
2058
+ };
2059
+ }
2060
+ });
2061
+
2062
+ // ../../node_modules/fs-extra/lib/ensure/symlink-type.js
2063
+ var require_symlink_type = __commonJS({
2064
+ "../../node_modules/fs-extra/lib/ensure/symlink-type.js"(exports2, module2) {
2065
+ "use strict";
2066
+ var fs5 = require_graceful_fs();
2067
+ function symlinkType(srcpath, type, callback) {
2068
+ callback = typeof type === "function" ? type : callback;
2069
+ type = typeof type === "function" ? false : type;
2070
+ if (type) return callback(null, type);
2071
+ fs5.lstat(srcpath, (err, stats) => {
2072
+ if (err) return callback(null, "file");
2073
+ type = stats && stats.isDirectory() ? "dir" : "file";
2074
+ callback(null, type);
2075
+ });
2076
+ }
2077
+ function symlinkTypeSync(srcpath, type) {
2078
+ let stats;
2079
+ if (type) return type;
2080
+ try {
2081
+ stats = fs5.lstatSync(srcpath);
2082
+ } catch (e) {
2083
+ return "file";
2084
+ }
2085
+ return stats && stats.isDirectory() ? "dir" : "file";
2086
+ }
2087
+ module2.exports = {
2088
+ symlinkType,
2089
+ symlinkTypeSync
2090
+ };
2091
+ }
2092
+ });
2093
+
2094
+ // ../../node_modules/fs-extra/lib/ensure/symlink.js
2095
+ var require_symlink = __commonJS({
2096
+ "../../node_modules/fs-extra/lib/ensure/symlink.js"(exports2, module2) {
2097
+ "use strict";
2098
+ var u = require_universalify().fromCallback;
2099
+ var path4 = require("path");
2100
+ var fs5 = require_graceful_fs();
2101
+ var _mkdirs = require_mkdirs2();
2102
+ var mkdirs = _mkdirs.mkdirs;
2103
+ var mkdirsSync = _mkdirs.mkdirsSync;
2104
+ var _symlinkPaths = require_symlink_paths();
2105
+ var symlinkPaths = _symlinkPaths.symlinkPaths;
2106
+ var symlinkPathsSync = _symlinkPaths.symlinkPathsSync;
2107
+ var _symlinkType = require_symlink_type();
2108
+ var symlinkType = _symlinkType.symlinkType;
2109
+ var symlinkTypeSync = _symlinkType.symlinkTypeSync;
2110
+ var pathExists = require_path_exists().pathExists;
2111
+ function createSymlink(srcpath, dstpath, type, callback) {
2112
+ callback = typeof type === "function" ? type : callback;
2113
+ type = typeof type === "function" ? false : type;
2114
+ pathExists(dstpath, (err, destinationExists) => {
2115
+ if (err) return callback(err);
2116
+ if (destinationExists) return callback(null);
2117
+ symlinkPaths(srcpath, dstpath, (err2, relative) => {
2118
+ if (err2) return callback(err2);
2119
+ srcpath = relative.toDst;
2120
+ symlinkType(relative.toCwd, type, (err3, type2) => {
2121
+ if (err3) return callback(err3);
2122
+ const dir = path4.dirname(dstpath);
2123
+ pathExists(dir, (err4, dirExists) => {
2124
+ if (err4) return callback(err4);
2125
+ if (dirExists) return fs5.symlink(srcpath, dstpath, type2, callback);
2126
+ mkdirs(dir, (err5) => {
2127
+ if (err5) return callback(err5);
2128
+ fs5.symlink(srcpath, dstpath, type2, callback);
2129
+ });
2130
+ });
2131
+ });
2132
+ });
2133
+ });
2134
+ }
2135
+ function createSymlinkSync(srcpath, dstpath, type) {
2136
+ const destinationExists = fs5.existsSync(dstpath);
2137
+ if (destinationExists) return void 0;
2138
+ const relative = symlinkPathsSync(srcpath, dstpath);
2139
+ srcpath = relative.toDst;
2140
+ type = symlinkTypeSync(relative.toCwd, type);
2141
+ const dir = path4.dirname(dstpath);
2142
+ const exists = fs5.existsSync(dir);
2143
+ if (exists) return fs5.symlinkSync(srcpath, dstpath, type);
2144
+ mkdirsSync(dir);
2145
+ return fs5.symlinkSync(srcpath, dstpath, type);
2146
+ }
2147
+ module2.exports = {
2148
+ createSymlink: u(createSymlink),
2149
+ createSymlinkSync
2150
+ };
2151
+ }
2152
+ });
2153
+
2154
+ // ../../node_modules/fs-extra/lib/ensure/index.js
2155
+ var require_ensure = __commonJS({
2156
+ "../../node_modules/fs-extra/lib/ensure/index.js"(exports2, module2) {
2157
+ "use strict";
2158
+ var file = require_file();
2159
+ var link = require_link();
2160
+ var symlink = require_symlink();
2161
+ module2.exports = {
2162
+ // file
2163
+ createFile: file.createFile,
2164
+ createFileSync: file.createFileSync,
2165
+ ensureFile: file.createFile,
2166
+ ensureFileSync: file.createFileSync,
2167
+ // link
2168
+ createLink: link.createLink,
2169
+ createLinkSync: link.createLinkSync,
2170
+ ensureLink: link.createLink,
2171
+ ensureLinkSync: link.createLinkSync,
2172
+ // symlink
2173
+ createSymlink: symlink.createSymlink,
2174
+ createSymlinkSync: symlink.createSymlinkSync,
2175
+ ensureSymlink: symlink.createSymlink,
2176
+ ensureSymlinkSync: symlink.createSymlinkSync
2177
+ };
2178
+ }
2179
+ });
2180
+
2181
+ // ../../node_modules/jsonfile/index.js
2182
+ var require_jsonfile = __commonJS({
2183
+ "../../node_modules/jsonfile/index.js"(exports2, module2) {
2184
+ "use strict";
2185
+ var _fs;
2186
+ try {
2187
+ _fs = require_graceful_fs();
2188
+ } catch (_3) {
2189
+ _fs = require("fs");
2190
+ }
2191
+ function readFile(file, options, callback) {
2192
+ if (callback == null) {
2193
+ callback = options;
2194
+ options = {};
2195
+ }
2196
+ if (typeof options === "string") {
2197
+ options = { encoding: options };
2198
+ }
2199
+ options = options || {};
2200
+ var fs5 = options.fs || _fs;
2201
+ var shouldThrow = true;
2202
+ if ("throws" in options) {
2203
+ shouldThrow = options.throws;
2204
+ }
2205
+ fs5.readFile(file, options, function(err, data) {
2206
+ if (err) return callback(err);
2207
+ data = stripBom(data);
2208
+ var obj;
2209
+ try {
2210
+ obj = JSON.parse(data, options ? options.reviver : null);
2211
+ } catch (err2) {
2212
+ if (shouldThrow) {
2213
+ err2.message = file + ": " + err2.message;
2214
+ return callback(err2);
2215
+ } else {
2216
+ return callback(null, null);
2217
+ }
2218
+ }
2219
+ callback(null, obj);
2220
+ });
2221
+ }
2222
+ function readFileSync(file, options) {
2223
+ options = options || {};
2224
+ if (typeof options === "string") {
2225
+ options = { encoding: options };
2226
+ }
2227
+ var fs5 = options.fs || _fs;
2228
+ var shouldThrow = true;
2229
+ if ("throws" in options) {
2230
+ shouldThrow = options.throws;
2231
+ }
2232
+ try {
2233
+ var content = fs5.readFileSync(file, options);
2234
+ content = stripBom(content);
2235
+ return JSON.parse(content, options.reviver);
2236
+ } catch (err) {
2237
+ if (shouldThrow) {
2238
+ err.message = file + ": " + err.message;
2239
+ throw err;
2240
+ } else {
2241
+ return null;
2242
+ }
2243
+ }
2244
+ }
2245
+ function stringify(obj, options) {
2246
+ var spaces;
2247
+ var EOL = "\n";
2248
+ if (typeof options === "object" && options !== null) {
2249
+ if (options.spaces) {
2250
+ spaces = options.spaces;
2251
+ }
2252
+ if (options.EOL) {
2253
+ EOL = options.EOL;
2254
+ }
2255
+ }
2256
+ var str = JSON.stringify(obj, options ? options.replacer : null, spaces);
2257
+ return str.replace(/\n/g, EOL) + EOL;
2258
+ }
2259
+ function writeFile(file, obj, options, callback) {
2260
+ if (callback == null) {
2261
+ callback = options;
2262
+ options = {};
2263
+ }
2264
+ options = options || {};
2265
+ var fs5 = options.fs || _fs;
2266
+ var str = "";
2267
+ try {
2268
+ str = stringify(obj, options);
2269
+ } catch (err) {
2270
+ if (callback) callback(err, null);
2271
+ return;
2272
+ }
2273
+ fs5.writeFile(file, str, options, callback);
2274
+ }
2275
+ function writeFileSync(file, obj, options) {
2276
+ options = options || {};
2277
+ var fs5 = options.fs || _fs;
2278
+ var str = stringify(obj, options);
2279
+ return fs5.writeFileSync(file, str, options);
2280
+ }
2281
+ function stripBom(content) {
2282
+ if (Buffer.isBuffer(content)) content = content.toString("utf8");
2283
+ content = content.replace(/^\uFEFF/, "");
2284
+ return content;
2285
+ }
2286
+ var jsonfile = {
2287
+ readFile,
2288
+ readFileSync,
2289
+ writeFile,
2290
+ writeFileSync
2291
+ };
2292
+ module2.exports = jsonfile;
2293
+ }
2294
+ });
2295
+
2296
+ // ../../node_modules/fs-extra/lib/json/jsonfile.js
2297
+ var require_jsonfile2 = __commonJS({
2298
+ "../../node_modules/fs-extra/lib/json/jsonfile.js"(exports2, module2) {
2299
+ "use strict";
2300
+ var u = require_universalify().fromCallback;
2301
+ var jsonFile = require_jsonfile();
2302
+ module2.exports = {
2303
+ // jsonfile exports
2304
+ readJson: u(jsonFile.readFile),
2305
+ readJsonSync: jsonFile.readFileSync,
2306
+ writeJson: u(jsonFile.writeFile),
2307
+ writeJsonSync: jsonFile.writeFileSync
2308
+ };
2309
+ }
2310
+ });
2311
+
2312
+ // ../../node_modules/fs-extra/lib/json/output-json.js
2313
+ var require_output_json = __commonJS({
2314
+ "../../node_modules/fs-extra/lib/json/output-json.js"(exports2, module2) {
2315
+ "use strict";
2316
+ var path4 = require("path");
2317
+ var mkdir = require_mkdirs2();
2318
+ var pathExists = require_path_exists().pathExists;
2319
+ var jsonFile = require_jsonfile2();
2320
+ function outputJson(file, data, options, callback) {
2321
+ if (typeof options === "function") {
2322
+ callback = options;
2323
+ options = {};
2324
+ }
2325
+ const dir = path4.dirname(file);
2326
+ pathExists(dir, (err, itDoes) => {
2327
+ if (err) return callback(err);
2328
+ if (itDoes) return jsonFile.writeJson(file, data, options, callback);
2329
+ mkdir.mkdirs(dir, (err2) => {
2330
+ if (err2) return callback(err2);
2331
+ jsonFile.writeJson(file, data, options, callback);
2332
+ });
2333
+ });
2334
+ }
2335
+ module2.exports = outputJson;
2336
+ }
2337
+ });
2338
+
2339
+ // ../../node_modules/fs-extra/lib/json/output-json-sync.js
2340
+ var require_output_json_sync = __commonJS({
2341
+ "../../node_modules/fs-extra/lib/json/output-json-sync.js"(exports2, module2) {
2342
+ "use strict";
2343
+ var fs5 = require_graceful_fs();
2344
+ var path4 = require("path");
2345
+ var mkdir = require_mkdirs2();
2346
+ var jsonFile = require_jsonfile2();
2347
+ function outputJsonSync(file, data, options) {
2348
+ const dir = path4.dirname(file);
2349
+ if (!fs5.existsSync(dir)) {
2350
+ mkdir.mkdirsSync(dir);
2351
+ }
2352
+ jsonFile.writeJsonSync(file, data, options);
2353
+ }
2354
+ module2.exports = outputJsonSync;
2355
+ }
2356
+ });
2357
+
2358
+ // ../../node_modules/fs-extra/lib/json/index.js
2359
+ var require_json = __commonJS({
2360
+ "../../node_modules/fs-extra/lib/json/index.js"(exports2, module2) {
2361
+ "use strict";
2362
+ var u = require_universalify().fromCallback;
2363
+ var jsonFile = require_jsonfile2();
2364
+ jsonFile.outputJson = u(require_output_json());
2365
+ jsonFile.outputJsonSync = require_output_json_sync();
2366
+ jsonFile.outputJSON = jsonFile.outputJson;
2367
+ jsonFile.outputJSONSync = jsonFile.outputJsonSync;
2368
+ jsonFile.writeJSON = jsonFile.writeJson;
2369
+ jsonFile.writeJSONSync = jsonFile.writeJsonSync;
2370
+ jsonFile.readJSON = jsonFile.readJson;
2371
+ jsonFile.readJSONSync = jsonFile.readJsonSync;
2372
+ module2.exports = jsonFile;
2373
+ }
2374
+ });
2375
+
2376
+ // ../../node_modules/fs-extra/lib/move-sync/index.js
2377
+ var require_move_sync = __commonJS({
2378
+ "../../node_modules/fs-extra/lib/move-sync/index.js"(exports2, module2) {
2379
+ "use strict";
2380
+ var fs5 = require_graceful_fs();
2381
+ var path4 = require("path");
2382
+ var copySync = require_copy_sync2().copySync;
2383
+ var removeSync = require_remove().removeSync;
2384
+ var mkdirpSync = require_mkdirs2().mkdirsSync;
2385
+ var buffer = require_buffer();
2386
+ function moveSync(src, dest, options) {
2387
+ options = options || {};
2388
+ const overwrite = options.overwrite || options.clobber || false;
2389
+ src = path4.resolve(src);
2390
+ dest = path4.resolve(dest);
2391
+ if (src === dest) return fs5.accessSync(src);
2392
+ if (isSrcSubdir(src, dest)) throw new Error(`Cannot move '${src}' into itself '${dest}'.`);
2393
+ mkdirpSync(path4.dirname(dest));
2394
+ tryRenameSync();
2395
+ function tryRenameSync() {
2396
+ if (overwrite) {
2397
+ try {
2398
+ return fs5.renameSync(src, dest);
2399
+ } catch (err) {
2400
+ if (err.code === "ENOTEMPTY" || err.code === "EEXIST" || err.code === "EPERM") {
2401
+ removeSync(dest);
2402
+ options.overwrite = false;
2403
+ return moveSync(src, dest, options);
2404
+ }
2405
+ if (err.code !== "EXDEV") throw err;
2406
+ return moveSyncAcrossDevice(src, dest, overwrite);
2407
+ }
2408
+ } else {
2409
+ try {
2410
+ fs5.linkSync(src, dest);
2411
+ return fs5.unlinkSync(src);
2412
+ } catch (err) {
2413
+ if (err.code === "EXDEV" || err.code === "EISDIR" || err.code === "EPERM" || err.code === "ENOTSUP") {
2414
+ return moveSyncAcrossDevice(src, dest, overwrite);
2415
+ }
2416
+ throw err;
2417
+ }
2418
+ }
2419
+ }
2420
+ }
2421
+ function moveSyncAcrossDevice(src, dest, overwrite) {
2422
+ const stat = fs5.statSync(src);
2423
+ if (stat.isDirectory()) {
2424
+ return moveDirSyncAcrossDevice(src, dest, overwrite);
2425
+ } else {
2426
+ return moveFileSyncAcrossDevice(src, dest, overwrite);
2427
+ }
2428
+ }
2429
+ function moveFileSyncAcrossDevice(src, dest, overwrite) {
2430
+ const BUF_LENGTH = 64 * 1024;
2431
+ const _buff = buffer(BUF_LENGTH);
2432
+ const flags = overwrite ? "w" : "wx";
2433
+ const fdr = fs5.openSync(src, "r");
2434
+ const stat = fs5.fstatSync(fdr);
2435
+ const fdw = fs5.openSync(dest, flags, stat.mode);
2436
+ let pos = 0;
2437
+ while (pos < stat.size) {
2438
+ const bytesRead = fs5.readSync(fdr, _buff, 0, BUF_LENGTH, pos);
2439
+ fs5.writeSync(fdw, _buff, 0, bytesRead);
2440
+ pos += bytesRead;
2441
+ }
2442
+ fs5.closeSync(fdr);
2443
+ fs5.closeSync(fdw);
2444
+ return fs5.unlinkSync(src);
2445
+ }
2446
+ function moveDirSyncAcrossDevice(src, dest, overwrite) {
2447
+ const options = {
2448
+ overwrite: false
2449
+ };
2450
+ if (overwrite) {
2451
+ removeSync(dest);
2452
+ tryCopySync();
2453
+ } else {
2454
+ tryCopySync();
2455
+ }
2456
+ function tryCopySync() {
2457
+ copySync(src, dest, options);
2458
+ return removeSync(src);
2459
+ }
2460
+ }
2461
+ function isSrcSubdir(src, dest) {
2462
+ try {
2463
+ return fs5.statSync(src).isDirectory() && src !== dest && dest.indexOf(src) > -1 && dest.split(path4.dirname(src) + path4.sep)[1].split(path4.sep)[0] === path4.basename(src);
2464
+ } catch (e) {
2465
+ return false;
2466
+ }
2467
+ }
2468
+ module2.exports = {
2469
+ moveSync
2470
+ };
2471
+ }
2472
+ });
2473
+
2474
+ // ../../node_modules/fs-extra/lib/move/index.js
2475
+ var require_move = __commonJS({
2476
+ "../../node_modules/fs-extra/lib/move/index.js"(exports2, module2) {
2477
+ "use strict";
2478
+ var u = require_universalify().fromCallback;
2479
+ var fs5 = require_graceful_fs();
2480
+ var path4 = require("path");
2481
+ var copy2 = require_copy2().copy;
2482
+ var remove = require_remove().remove;
2483
+ var mkdirp = require_mkdirs2().mkdirp;
2484
+ var pathExists = require_path_exists().pathExists;
2485
+ function move(src, dest, opts, cb) {
2486
+ if (typeof opts === "function") {
2487
+ cb = opts;
2488
+ opts = {};
2489
+ }
2490
+ const overwrite = opts.overwrite || opts.clobber || false;
2491
+ src = path4.resolve(src);
2492
+ dest = path4.resolve(dest);
2493
+ if (src === dest) return fs5.access(src, cb);
2494
+ fs5.stat(src, (err, st) => {
2495
+ if (err) return cb(err);
2496
+ if (st.isDirectory() && isSrcSubdir(src, dest)) {
2497
+ return cb(new Error(`Cannot move '${src}' to a subdirectory of itself, '${dest}'.`));
2498
+ }
2499
+ mkdirp(path4.dirname(dest), (err2) => {
2500
+ if (err2) return cb(err2);
2501
+ return doRename(src, dest, overwrite, cb);
2502
+ });
2503
+ });
2504
+ }
2505
+ function doRename(src, dest, overwrite, cb) {
2506
+ if (overwrite) {
2507
+ return remove(dest, (err) => {
2508
+ if (err) return cb(err);
2509
+ return rename(src, dest, overwrite, cb);
2510
+ });
2511
+ }
2512
+ pathExists(dest, (err, destExists) => {
2513
+ if (err) return cb(err);
2514
+ if (destExists) return cb(new Error("dest already exists."));
2515
+ return rename(src, dest, overwrite, cb);
2516
+ });
2517
+ }
2518
+ function rename(src, dest, overwrite, cb) {
2519
+ fs5.rename(src, dest, (err) => {
2520
+ if (!err) return cb();
2521
+ if (err.code !== "EXDEV") return cb(err);
2522
+ return moveAcrossDevice(src, dest, overwrite, cb);
2523
+ });
2524
+ }
2525
+ function moveAcrossDevice(src, dest, overwrite, cb) {
2526
+ const opts = {
2527
+ overwrite,
2528
+ errorOnExist: true
2529
+ };
2530
+ copy2(src, dest, opts, (err) => {
2531
+ if (err) return cb(err);
2532
+ return remove(src, cb);
2533
+ });
2534
+ }
2535
+ function isSrcSubdir(src, dest) {
2536
+ const srcArray = src.split(path4.sep);
2537
+ const destArray = dest.split(path4.sep);
2538
+ return srcArray.reduce((acc, current, i) => {
2539
+ return acc && destArray[i] === current;
2540
+ }, true);
2541
+ }
2542
+ module2.exports = {
2543
+ move: u(move)
2544
+ };
2545
+ }
2546
+ });
2547
+
2548
+ // ../../node_modules/fs-extra/lib/output/index.js
2549
+ var require_output = __commonJS({
2550
+ "../../node_modules/fs-extra/lib/output/index.js"(exports2, module2) {
2551
+ "use strict";
2552
+ var u = require_universalify().fromCallback;
2553
+ var fs5 = require_graceful_fs();
2554
+ var path4 = require("path");
2555
+ var mkdir = require_mkdirs2();
2556
+ var pathExists = require_path_exists().pathExists;
2557
+ function outputFile(file, data, encoding, callback) {
2558
+ if (typeof encoding === "function") {
2559
+ callback = encoding;
2560
+ encoding = "utf8";
2561
+ }
2562
+ const dir = path4.dirname(file);
2563
+ pathExists(dir, (err, itDoes) => {
2564
+ if (err) return callback(err);
2565
+ if (itDoes) return fs5.writeFile(file, data, encoding, callback);
2566
+ mkdir.mkdirs(dir, (err2) => {
2567
+ if (err2) return callback(err2);
2568
+ fs5.writeFile(file, data, encoding, callback);
2569
+ });
2570
+ });
2571
+ }
2572
+ function outputFileSync(file, ...args) {
2573
+ const dir = path4.dirname(file);
2574
+ if (fs5.existsSync(dir)) {
2575
+ return fs5.writeFileSync(file, ...args);
2576
+ }
2577
+ mkdir.mkdirsSync(dir);
2578
+ fs5.writeFileSync(file, ...args);
2579
+ }
2580
+ module2.exports = {
2581
+ outputFile: u(outputFile),
2582
+ outputFileSync
2583
+ };
2584
+ }
2585
+ });
2586
+
2587
+ // ../../node_modules/fs-extra/lib/index.js
2588
+ var require_lib = __commonJS({
2589
+ "../../node_modules/fs-extra/lib/index.js"(exports2, module2) {
2590
+ "use strict";
2591
+ module2.exports = Object.assign(
2592
+ {},
2593
+ // Export promiseified graceful-fs:
2594
+ require_fs(),
2595
+ // Export extra methods:
2596
+ require_copy_sync2(),
2597
+ require_copy2(),
2598
+ require_empty(),
2599
+ require_ensure(),
2600
+ require_json(),
2601
+ require_mkdirs2(),
2602
+ require_move_sync(),
2603
+ require_move(),
2604
+ require_output(),
2605
+ require_path_exists(),
2606
+ require_remove()
2607
+ );
2608
+ var fs5 = require("fs");
2609
+ if (Object.getOwnPropertyDescriptor(fs5, "promises")) {
2610
+ Object.defineProperty(module2.exports, "promises", {
2611
+ get() {
2612
+ return fs5.promises;
2613
+ }
2614
+ });
2615
+ }
2616
+ }
2617
+ });
2618
+
2619
+ // index.ts
2620
+ var index_exports = {};
2621
+ __export(index_exports, {
2622
+ checkForLatestVersion: () => checkForLatestVersion,
2623
+ checkNodeVersion: () => checkNodeVersion,
2624
+ createNodeApp: () => createNodeApp,
2625
+ printEnvInfo: () => printEnvInfo
2626
+ });
2627
+ module.exports = __toCommonJS(index_exports);
2628
+ var import_picocolors4 = __toESM(require("picocolors"), 1);
2629
+ var import_envinfo = __toESM(require("envinfo"), 1);
2630
+ var import_semver3 = __toESM(require("semver"), 1);
2631
+ var import_child_process3 = require("child_process");
2632
+
2633
+ // installer.ts
2634
+ var import_underscore2 = __toESM(require("underscore"), 1);
2635
+ var import_path4 = __toESM(require("path"), 1);
2636
+ var import_fs5 = __toESM(require("fs"), 1);
2637
+ var import_picocolors3 = __toESM(require("picocolors"), 1);
2638
+ var import_os3 = __toESM(require("os"), 1);
2639
+ var import_semver2 = __toESM(require("semver"), 1);
2640
+ var import_child_process2 = require("child_process");
2641
+
2642
+ // helpers.ts
2643
+ var import_child_process = require("child_process");
2644
+ var import_cross_spawn = __toESM(require("cross-spawn"), 1);
2645
+ var import_picocolors = __toESM(require("picocolors"), 1);
2646
+ var import_semver = __toESM(require("semver"), 1);
2647
+ var import_dns = __toESM(require("dns"), 1);
2648
+ var import_url = require("url");
2649
+ var shouldUseYarn = () => {
2650
+ const { hasMinYarnPnp, hasMaxYarnPnp, yarnVersion } = checkYarnVersion();
2651
+ if (!hasMinYarnPnp) {
2652
+ console.log(
2653
+ import_picocolors.default.yellow(
2654
+ `You are using yarn version ${import_picocolors.default.bold(
2655
+ yarnVersion
2656
+ )} which is not supported yet. To use Yarn, install v1.12.0 or higher and lower than v2.0.0. See https://yarnpkg.com for instructions on how to update.`
2657
+ )
2658
+ );
2659
+ return false;
2660
+ }
2661
+ if (!hasMaxYarnPnp) {
2662
+ console.log(
2663
+ import_picocolors.default.yellow(
2664
+ `You are using a pre-release version of Yarn which is not supported yet. To use Yarn, install v1.12.0 or higher and lower than v2.0.0. See https://yarnpkg.com for instructions on how to update.`
2665
+ )
2666
+ );
2667
+ return false;
2668
+ }
2669
+ return true;
2670
+ };
2671
+ var shouldUsePnpm = () => {
2672
+ const { hasMinPnpm, pnpmVersion } = checkPnpmVersion();
2673
+ if (!hasMinPnpm) {
2674
+ console.log(
2675
+ import_picocolors.default.yellow(
2676
+ `You are using pnpm version ${import_picocolors.default.bold(
2677
+ pnpmVersion
2678
+ )} which is not supported yet. To use pnpm, install v5.0.0 or higher. See https://pnpm.js.org for instructions on how to update.`
2679
+ )
2680
+ );
2681
+ return false;
2682
+ }
2683
+ return true;
2684
+ };
2685
+ var checkThatNpmCanReadCwd = () => {
2686
+ const cwd = process.cwd();
2687
+ let childOutput = null;
2688
+ try {
2689
+ childOutput = import_cross_spawn.default.sync("npm", ["config", "list"]).output.join("");
2690
+ } catch (err) {
2691
+ return true;
2692
+ }
2693
+ if (typeof childOutput !== "string") {
2694
+ return true;
2695
+ }
2696
+ const lines = childOutput.split("\n");
2697
+ const prefix = "; cwd = ";
2698
+ const line = lines.find((line2) => line2.startsWith(prefix));
2699
+ if (typeof line !== "string") {
2700
+ return true;
2701
+ }
2702
+ const npmCWD = line.substring(prefix.length);
2703
+ if (npmCWD === cwd) {
2704
+ return true;
2705
+ }
2706
+ console.error(
2707
+ import_picocolors.default.red(
2708
+ `Could not start an npm process in the right directory.
2709
+
2710
+ The current directory is: ${import_picocolors.default.bold(cwd)}
2711
+ However, a newly started npm process runs in: ${import_picocolors.default.bold(npmCWD)}
2712
+
2713
+ This is probably caused by a misconfigured system terminal shell.`
2714
+ )
2715
+ );
2716
+ if (process.platform === "win32") {
2717
+ console.error(
2718
+ import_picocolors.default.red(`On Windows, this can usually be fixed by running:
2719
+
2720
+ `) + ` ${import_picocolors.default.cyan(
2721
+ "reg"
2722
+ )} delete "HKCU\\Software\\Microsoft\\Command Processor" /v AutoRun /f
2723
+ ${import_picocolors.default.cyan(
2724
+ "reg"
2725
+ )} delete "HKLM\\Software\\Microsoft\\Command Processor" /v AutoRun /f
2726
+
2727
+ ` + import_picocolors.default.red(`Try to run the above two lines in the terminal.
2728
+ `) + import_picocolors.default.red(
2729
+ `To learn more about this problem, read: https://blogs.msdn.microsoft.com/oldnewthing/20071121-00/?p=24433/`
2730
+ )
2731
+ );
2732
+ }
2733
+ return false;
2734
+ };
2735
+ var checkPnpmVersion = () => {
2736
+ const minPnpm = "5.0.0";
2737
+ let hasMinPnpm = false;
2738
+ let pnpmVersion = null;
2739
+ try {
2740
+ pnpmVersion = (0, import_child_process.execSync)("pnpm --version").toString().trim();
2741
+ if (import_semver.default.valid(pnpmVersion)) {
2742
+ hasMinPnpm = import_semver.default.gte(pnpmVersion, minPnpm);
2743
+ } else {
2744
+ const trimmedPnpmVersionMatch = /^(.*?)[-+].+$/.exec(pnpmVersion);
2745
+ if (trimmedPnpmVersionMatch && trimmedPnpmVersionMatch[1]) {
2746
+ hasMinPnpm = import_semver.default.gte(trimmedPnpmVersionMatch[1], minPnpm);
2747
+ }
2748
+ }
2749
+ } catch (e) {
2750
+ }
2751
+ return { hasMinPnpm, pnpmVersion };
2752
+ };
2753
+ var checkYarnVersion = () => {
2754
+ const minYarnPnp = "1.12.0";
2755
+ const maxYarnPnp = "2.0.0";
2756
+ let hasMinYarnPnp = false;
2757
+ let hasMaxYarnPnp = false;
2758
+ let yarnVersion = null;
2759
+ try {
2760
+ yarnVersion = (0, import_child_process.execSync)("yarnpkg --version").toString().trim();
2761
+ if (import_semver.default.valid(yarnVersion)) {
2762
+ hasMinYarnPnp = import_semver.default.gte(yarnVersion, minYarnPnp);
2763
+ hasMaxYarnPnp = import_semver.default.lt(yarnVersion, maxYarnPnp);
2764
+ } else {
2765
+ const trimmedYarnVersionMatch = /^(.+?)[-+].+$/.exec(yarnVersion);
2766
+ if (trimmedYarnVersionMatch) {
2767
+ const trimmedYarnVersion = trimmedYarnVersionMatch.pop();
2768
+ if (trimmedYarnVersion) {
2769
+ hasMinYarnPnp = import_semver.default.gte(trimmedYarnVersion, minYarnPnp);
2770
+ hasMaxYarnPnp = import_semver.default.lt(trimmedYarnVersion, maxYarnPnp);
2771
+ }
2772
+ }
2773
+ }
2774
+ } catch (err) {
2775
+ }
2776
+ return {
2777
+ hasMinYarnPnp,
2778
+ hasMaxYarnPnp,
2779
+ yarnVersion
2780
+ };
2781
+ };
2782
+ var checkNpmVersion = () => {
2783
+ let hasMinNpm = false;
2784
+ let npmVersion = null;
2785
+ try {
2786
+ npmVersion = (0, import_child_process.execSync)("npm --version").toString().trim();
2787
+ hasMinNpm = import_semver.default.gte(npmVersion, "6.0.0");
2788
+ } catch (err) {
2789
+ }
2790
+ return {
2791
+ hasMinNpm,
2792
+ npmVersion
2793
+ };
2794
+ };
2795
+ var getProxy = () => {
2796
+ if (process.env.HTTPS_PROXY) {
2797
+ return process.env.HTTPS_PROXY;
2798
+ }
2799
+ try {
2800
+ const httpsProxy = (0, import_child_process.execSync)("npm config get https-proxy").toString().trim();
2801
+ return httpsProxy !== "null" ? httpsProxy : void 0;
2802
+ } catch (e) {
2803
+ }
2804
+ return "";
2805
+ };
2806
+ var checkIfOnline = (useYarn) => {
2807
+ if (!useYarn) {
2808
+ return Promise.resolve(true);
2809
+ }
2810
+ return new Promise((resolve) => {
2811
+ import_dns.default.lookup("registry.yarnpkg.com", (err) => {
2812
+ let proxy;
2813
+ if (err != null && (proxy = getProxy())) {
2814
+ import_dns.default.lookup(new import_url.URL(proxy).hostname, (proxyErr) => {
2815
+ resolve(!proxyErr);
2816
+ });
2817
+ } else {
2818
+ resolve(!err);
2819
+ }
2820
+ });
2821
+ });
2822
+ };
2823
+
2824
+ // package.ts
2825
+ var import_fs3 = require("fs");
2826
+ var import_lodash = __toESM(require("lodash.merge"), 1);
2827
+
2828
+ // paths.ts
2829
+ var import_fs2 = __toESM(require("fs"), 1);
2830
+ var import_os2 = __toESM(require("os"), 1);
2831
+ var import_path2 = __toESM(require("path"), 1);
2832
+
2833
+ // git.ts
2834
+ var import_os = __toESM(require("os"), 1);
2835
+ var import_path = __toESM(require("path"), 1);
2836
+ var import_fs = __toESM(require("fs"), 1);
2837
+ var import_debug = __toESM(require("debug"), 1);
2838
+ var import_simple_git = require("simple-git");
2839
+ var fse = __toESM(require_lib(), 1);
2840
+ var log = (0, import_debug.default)("cna:git");
2841
+ var filterGit = (src) => {
2842
+ return !/(\\|\/)\.git\b/.test(src);
2843
+ };
2844
+ var gitOperationMap = /* @__PURE__ */ new Map();
2845
+ var completedTargetIds = /* @__PURE__ */ new Map();
2846
+ var downloadRepository = async ({
2847
+ url = "",
2848
+ offline = false,
2849
+ target = "./",
2850
+ branch = "main",
2851
+ targetId,
2852
+ cacheDir: optsCacheDir
2853
+ }) => {
2854
+ const absoluteTarget = import_path.default.isAbsolute(target) ? target : import_path.default.resolve(target);
2855
+ const isGithub = /^[^/]+\/[^/]+$/.test(url);
2856
+ const gitUrl = isGithub ? `https://github.com/${url}` : url;
2857
+ const id = targetId || Buffer.from(`${gitUrl}@${branch}`).toString("base64");
2858
+ let cacheDir = optsCacheDir || import_path.default.join(import_os.default.homedir(), ".cache", "cna", id);
2859
+ cacheDir = import_path.default.isAbsolute(cacheDir) ? cacheDir : import_path.default.resolve(cacheDir);
2860
+ log("cache folder: %s", cacheDir);
2861
+ if (completedTargetIds.has(id)) {
2862
+ log(
2863
+ `Git checkout for target ID '${id}' has already been completed. Skipping.`
2864
+ );
2865
+ await fse.copy(cacheDir, absoluteTarget, {
2866
+ overwrite: true,
2867
+ filter: filterGit
2868
+ });
2869
+ return;
2870
+ }
2871
+ if (gitOperationMap.has(id)) {
2872
+ log(
2873
+ `Git operation for target ID '${id}' is already in progress. Waiting...`
2874
+ );
2875
+ await gitOperationMap.get(id);
2876
+ log(`Git operation for target ID '${id}' has completed.`);
2877
+ return;
2878
+ }
2879
+ const gitOperationPromise = (async () => {
2880
+ let git = (0, import_simple_git.simpleGit)();
2881
+ const cloneOptions = {
2882
+ "--depth": 1,
2883
+ "--branch": branch,
2884
+ "--single-branch": null,
2885
+ "--no-tags": null
2886
+ };
2887
+ try {
2888
+ const cached = import_fs.default.existsSync(cacheDir);
2889
+ if (!cached) {
2890
+ log("Cloning repository...");
2891
+ await git.clone(gitUrl, cacheDir, cloneOptions);
2892
+ }
2893
+ git = (0, import_simple_git.simpleGit)(cacheDir);
2894
+ if (!offline) {
2895
+ log("Pulling repository...");
2896
+ await git.checkout(["-f", branch]);
2897
+ await git.pull();
2898
+ }
2899
+ await fse.copy(cacheDir, absoluteTarget, {
2900
+ overwrite: true,
2901
+ filter: filterGit
2902
+ });
2903
+ completedTargetIds.set(id, true);
2904
+ } catch (error) {
2905
+ console.error("Error during repository download:", error);
2906
+ } finally {
2907
+ gitOperationMap.delete(id);
2908
+ }
2909
+ })();
2910
+ gitOperationMap.set(id, gitOperationPromise);
2911
+ await gitOperationPromise;
2912
+ };
2913
+
2914
+ // paths.ts
2915
+ var solveValuesFromTemplateOrExtensionUrl = (templateOrExtension) => {
2916
+ const url = new URL(templateOrExtension);
2917
+ const origin = `${url.protocol}//${url.host}`;
2918
+ const [org, repo, , branch = "", ...subdir] = url.pathname.slice(1).split("/");
2919
+ const ignorePackage = url.searchParams.get("ignorePackage") === "true";
2920
+ return {
2921
+ url: `${origin}/${org}/${repo}`,
2922
+ branch,
2923
+ subdir: subdir.join("/"),
2924
+ protocol: url.protocol,
2925
+ host: url.host,
2926
+ pathname: url.pathname,
2927
+ ignorePackage
2928
+ };
2929
+ };
2930
+ var solveRepositoryPath = async ({
2931
+ url,
2932
+ branch,
2933
+ subdir
2934
+ }) => {
2935
+ const targetId = Buffer.from(`${url}#${branch}`).toString("base64");
2936
+ const targetWithSubdir = Buffer.from(`${url}#${branch}#${subdir}`).toString(
2937
+ "base64"
2938
+ );
2939
+ const target = import_path2.default.join(import_os2.default.homedir(), ".cna", targetWithSubdir);
2940
+ try {
2941
+ await downloadRepository({
2942
+ url,
2943
+ branch: branch || "",
2944
+ target,
2945
+ targetId
2946
+ });
2947
+ } catch {
2948
+ }
2949
+ return { dir: target, subdir };
2950
+ };
2951
+ var solveTemplateOrExtensionPath = async (templateOrExtension) => {
2952
+ try {
2953
+ const { url, branch, subdir, protocol, host, pathname, ignorePackage } = solveValuesFromTemplateOrExtensionUrl(templateOrExtension);
2954
+ if (protocol === "file:") {
2955
+ return {
2956
+ dir: import_path2.default.resolve(host, pathname),
2957
+ subdir
2958
+ };
2959
+ }
2960
+ const gitData = await solveRepositoryPath({
2961
+ url,
2962
+ branch,
2963
+ subdir
2964
+ });
2965
+ return { ...gitData, ignorePackage };
2966
+ } catch {
2967
+ return {
2968
+ dir: import_path2.default.resolve(
2969
+ __dirname,
2970
+ "..",
2971
+ "templatesOrExtensions",
2972
+ templateOrExtension
2973
+ ),
2974
+ ignorePackage: void 0
2975
+ };
2976
+ }
2977
+ };
2978
+ var getPackagePath = async (templateOrExtension, name = "package", ignorePackage = false) => {
2979
+ const {
2980
+ dir,
2981
+ subdir,
2982
+ ignorePackage: templateOrExtensionIgnorePackage
2983
+ } = await solveTemplateOrExtensionPath(templateOrExtension);
2984
+ if (name === "package.json" && (ignorePackage || templateOrExtensionIgnorePackage)) {
2985
+ throw new Error(
2986
+ "package.json should be ignored for file templateOrExtension"
2987
+ );
2988
+ }
2989
+ if (subdir) {
2990
+ return import_path2.default.resolve(dir, subdir, name);
2991
+ }
2992
+ return import_path2.default.resolve(dir, name);
2993
+ };
2994
+ var getTemplateDirPath = async (templateOrExtensionUrl) => {
2995
+ const { dir, subdir = "" } = await solveTemplateOrExtensionPath(
2996
+ templateOrExtensionUrl
2997
+ );
2998
+ let templateDirPath = import_path2.default.resolve(dir, subdir);
2999
+ const templateDirPathWithTemplate = import_path2.default.resolve(templateDirPath, "template");
3000
+ return new Promise((resolve) => {
3001
+ import_fs2.default.stat(templateDirPathWithTemplate, (_err, stats) => {
3002
+ if (_err) {
3003
+ resolve(templateDirPath);
3004
+ return;
3005
+ }
3006
+ if (stats.isDirectory()) {
3007
+ templateDirPath = templateDirPathWithTemplate;
3008
+ }
3009
+ resolve(templateDirPath);
3010
+ });
3011
+ });
3012
+ };
3013
+
3014
+ // package.ts
3015
+ var getInstallableSetup = ({
3016
+ dependencies,
3017
+ devDependencies,
3018
+ ...packageJson
3019
+ }) => {
3020
+ const getInstallableDeps = (deps = {}) => Object.entries(deps).map(([dep, version]) => `${dep}@${version}`);
3021
+ return {
3022
+ packageJson,
3023
+ dependencies: getInstallableDeps(dependencies),
3024
+ devDependencies: getInstallableDeps(devDependencies)
3025
+ };
3026
+ };
3027
+ var requireIfExists = (path4) => {
3028
+ if ((0, import_fs3.existsSync)(path4)) {
3029
+ return require(path4);
3030
+ }
3031
+ throw new Error(`File ${path4} does not exist`);
3032
+ };
3033
+ var loadPackages = async ({
3034
+ templatesOrExtensions = [],
3035
+ ignorePackage: globalIgnorePackage = false,
3036
+ ...config
3037
+ }) => {
3038
+ const setup = await Promise.all(
3039
+ templatesOrExtensions.map(async ({ url: templateOrExtension }) => {
3040
+ try {
3041
+ const template = requireIfExists(
3042
+ await getPackagePath(templateOrExtension, "template.json")
3043
+ );
3044
+ return template.package || {};
3045
+ } catch {
3046
+ return {};
3047
+ }
3048
+ })
3049
+ );
3050
+ const mergedSetup = (0, import_lodash.default)(
3051
+ {
3052
+ name: config.appName,
3053
+ dependencies: {},
3054
+ devDependencies: {},
3055
+ scripts: {}
3056
+ },
3057
+ ...setup
3058
+ );
3059
+ const finalSetup = await Promise.all(
3060
+ templatesOrExtensions.map(
3061
+ async ({ url: templateOrExtension, ignorePackage }) => {
3062
+ try {
3063
+ const templateOrExtensionPackageJson = requireIfExists(
3064
+ await getPackagePath(
3065
+ templateOrExtension,
3066
+ "package.json",
3067
+ globalIgnorePackage || ignorePackage
3068
+ )
3069
+ );
3070
+ return templateOrExtensionPackageJson;
3071
+ } catch {
3072
+ return {};
3073
+ }
3074
+ }
3075
+ )
3076
+ );
3077
+ const resolvedSetup = await Promise.all(
3078
+ templatesOrExtensions.map(async ({ url: templateOrExtension }) => {
3079
+ try {
3080
+ const resolveTemplateOrExtensionPackage = requireIfExists(
3081
+ await getPackagePath(templateOrExtension)
3082
+ );
3083
+ return resolveTemplateOrExtensionPackage(mergedSetup, config);
3084
+ } catch {
3085
+ return {};
3086
+ }
3087
+ })
3088
+ );
3089
+ const packageJson = (0, import_lodash.default)(mergedSetup, ...finalSetup, ...resolvedSetup);
3090
+ return getInstallableSetup({
3091
+ ...packageJson,
3092
+ name: config.appName
3093
+ });
3094
+ };
3095
+
3096
+ // loaders.ts
3097
+ var import_underscore = __toESM(require("underscore"), 1);
3098
+ var import_fs4 = __toESM(require("fs"), 1);
3099
+ var import_picocolors2 = __toESM(require("picocolors"), 1);
3100
+ var import_readdirp = require("readdirp");
3101
+ var import_path3 = require("path");
3102
+ var import_util = require("util");
3103
+ var writeFileAsync = (0, import_util.promisify)(import_fs4.default.writeFile);
3104
+ var copyFileAsync = (0, import_util.promisify)(import_fs4.default.copyFile);
3105
+ var SRC_PATH_PATTERN = "[src]/";
3106
+ var DEFAULT_SRC_PATH = "src/";
3107
+ var getSrcDirPattern = (srcDir) => srcDir === "." ? "" : srcDir + "/";
3108
+ var makeDirectory = (dirPath) => {
3109
+ if (!import_fs4.default.existsSync(dirPath)) {
3110
+ import_fs4.default.mkdirSync(dirPath, { recursive: true });
3111
+ }
3112
+ };
3113
+ var getModeFromPath = (path4 = "") => {
3114
+ const matchExts = (...exts) => exts.find((ext) => path4.endsWith(ext));
3115
+ if (matchExts(".append")) {
3116
+ return "append";
3117
+ }
3118
+ if (matchExts(".append.template", ".template.append")) {
3119
+ return "appendTemplate";
3120
+ }
3121
+ if (matchExts(".template")) {
3122
+ return "copyTemplate";
3123
+ }
3124
+ return "copy";
3125
+ };
3126
+ var batchedCopyFiles = async (operations) => {
3127
+ const batchedPromises = operations.map(async (operation) => {
3128
+ try {
3129
+ makeDirectory((0, import_path3.dirname)(operation.dest));
3130
+ await copyFileAsync(operation.src, operation.dest);
3131
+ if (operation.verbose) {
3132
+ console.log(
3133
+ import_picocolors2.default.green(
3134
+ `Added "${operation.dest}" from "${operation.src}" successfully`
3135
+ )
3136
+ );
3137
+ }
3138
+ } catch (err) {
3139
+ console.log(
3140
+ import_picocolors2.default.red(`Cannot copy file ${operation.src} to ${operation.dest}`)
3141
+ );
3142
+ if (operation.verbose) {
3143
+ console.log(import_picocolors2.default.red(String(err)));
3144
+ }
3145
+ throw err;
3146
+ }
3147
+ });
3148
+ await Promise.all(batchedPromises);
3149
+ };
3150
+ var batchedWriteFiles = async (operations) => {
3151
+ const batchedPromises = operations.map(async (operation) => {
3152
+ try {
3153
+ makeDirectory((0, import_path3.dirname)(operation.path));
3154
+ await writeFileAsync(operation.path, operation.content, {
3155
+ flag: operation.flag,
3156
+ mode: operation.mode
3157
+ });
3158
+ if (operation.verbose) {
3159
+ console.log(import_picocolors2.default.green(`Added "${operation.path}" successfully`));
3160
+ }
3161
+ } catch (err) {
3162
+ console.log(import_picocolors2.default.red(`Cannot write file ${operation.path}`));
3163
+ if (operation.verbose) {
3164
+ console.log(import_picocolors2.default.red(String(err)));
3165
+ }
3166
+ throw err;
3167
+ }
3168
+ });
3169
+ await Promise.all(batchedPromises);
3170
+ };
3171
+ var batchedAppendFiles = async (operations) => {
3172
+ const batchedPromises = operations.map(async (operation) => {
3173
+ try {
3174
+ const content = await (0, import_util.promisify)(import_fs4.default.readFile)(operation.src, "utf8");
3175
+ const fileMode = (await (0, import_util.promisify)(import_fs4.default.stat)(operation.src)).mode;
3176
+ await batchedWriteFiles([
3177
+ {
3178
+ path: operation.dest,
3179
+ content,
3180
+ flag: "a+",
3181
+ verbose: operation.verbose,
3182
+ mode: fileMode
3183
+ }
3184
+ ]);
3185
+ } catch (err) {
3186
+ console.log(
3187
+ import_picocolors2.default.red(`Cannot append file ${operation.src} to ${operation.dest}`)
3188
+ );
3189
+ if (operation.verbose) {
3190
+ console.log(import_picocolors2.default.red(String(err)));
3191
+ }
3192
+ throw err;
3193
+ }
3194
+ });
3195
+ await Promise.all(batchedPromises);
3196
+ };
3197
+ var copyLoader = ({ root, templateDir, verbose, srcDir }) => async ({ path: path4 }) => {
3198
+ const operations = [];
3199
+ try {
3200
+ const newPath = path4.replace(/.if-(npm|yarn|pnpm)$/, "").replace(SRC_PATH_PATTERN, getSrcDirPattern(srcDir));
3201
+ operations.push({
3202
+ src: `${templateDir}/${path4}`,
3203
+ dest: `${root}/${newPath}`,
3204
+ verbose
3205
+ });
3206
+ } catch (err) {
3207
+ if (verbose) {
3208
+ console.log(err);
3209
+ }
3210
+ throw err;
3211
+ }
3212
+ await batchedCopyFiles(operations);
3213
+ };
3214
+ var appendLoader = ({ root, templateDir, verbose, srcDir }) => async ({ path: path4 }) => {
3215
+ const operations = [];
3216
+ try {
3217
+ const newPath = path4.replace(/.append$/, "").replace(/.if-(npm|yarn|pnpm)$/, "").replace(SRC_PATH_PATTERN, getSrcDirPattern(srcDir));
3218
+ operations.push({
3219
+ src: `${templateDir}/${path4}`,
3220
+ dest: `${root}/${newPath}`,
3221
+ verbose
3222
+ });
3223
+ } catch (err) {
3224
+ if (verbose) {
3225
+ console.log(err);
3226
+ }
3227
+ throw err;
3228
+ }
3229
+ await batchedAppendFiles(operations);
3230
+ };
3231
+ var templateLoader = ({
3232
+ root,
3233
+ templateDir,
3234
+ appName,
3235
+ verbose,
3236
+ mode = "",
3237
+ srcDir,
3238
+ runCommand,
3239
+ installCommand,
3240
+ ...customOptions
3241
+ }) => async ({ path: path4 }) => {
3242
+ const operations = [];
3243
+ try {
3244
+ const flag = mode.includes("append") ? "a+" : "w";
3245
+ const filePath = `${templateDir}/${path4}`;
3246
+ const file = await (0, import_util.promisify)(import_fs4.default.readFile)(filePath, "utf8");
3247
+ const fileMode = (await (0, import_util.promisify)(import_fs4.default.stat)(filePath)).mode;
3248
+ const newFile = import_underscore.default.template(file);
3249
+ const newPath = path4.replace(/.template$/, "").replace(/.append$/, "").replace(/.if-(npm|yarn|pnpm)$/, "").replace(SRC_PATH_PATTERN, getSrcDirPattern(srcDir));
3250
+ operations.push({
3251
+ path: `${root}/${newPath}`,
3252
+ content: newFile({
3253
+ projectName: appName,
3254
+ srcDir: srcDir || ".",
3255
+ runCommand,
3256
+ installCommand,
3257
+ ...customOptions
3258
+ }),
3259
+ flag,
3260
+ verbose,
3261
+ mode: fileMode
3262
+ });
3263
+ } catch (err) {
3264
+ if (verbose) {
3265
+ console.log(err);
3266
+ }
3267
+ throw err;
3268
+ }
3269
+ await batchedWriteFiles(operations);
3270
+ };
3271
+ var fileLoader = ({
3272
+ root,
3273
+ templateDir,
3274
+ appName,
3275
+ originalDirectory,
3276
+ verbose,
3277
+ useYarn,
3278
+ usePnpm,
3279
+ srcDir = DEFAULT_SRC_PATH,
3280
+ runCommand,
3281
+ installCommand,
3282
+ ...customOptions
3283
+ }) => async ({ path: path4 }) => {
3284
+ try {
3285
+ const mode = getModeFromPath(path4);
3286
+ const loaders = {
3287
+ copy: copyLoader,
3288
+ append: appendLoader,
3289
+ copyTemplate: templateLoader,
3290
+ appendTemplate: appendLoader
3291
+ };
3292
+ await loaders[mode]({
3293
+ root,
3294
+ templateDir,
3295
+ appName,
3296
+ originalDirectory,
3297
+ verbose,
3298
+ useYarn: !!useYarn,
3299
+ usePnpm: !!usePnpm,
3300
+ mode,
3301
+ srcDir,
3302
+ runCommand,
3303
+ installCommand,
3304
+ ...customOptions
3305
+ })({
3306
+ path: path4
3307
+ });
3308
+ } catch (err) {
3309
+ if (verbose) {
3310
+ console.log(err);
3311
+ }
3312
+ throw err;
3313
+ }
3314
+ };
3315
+ var loadFiles = async ({
3316
+ root,
3317
+ templatesOrExtensions = [],
3318
+ appName,
3319
+ originalDirectory,
3320
+ verbose,
3321
+ useYarn = false,
3322
+ usePnpm = false,
3323
+ srcDir = DEFAULT_SRC_PATH,
3324
+ runCommand,
3325
+ installCommand,
3326
+ ...customOptions
3327
+ }) => {
3328
+ try {
3329
+ const operations = [];
3330
+ for await (const { url: templateOrExtensionUrl } of templatesOrExtensions) {
3331
+ const templateDir = await getTemplateDirPath(templateOrExtensionUrl);
3332
+ if (import_fs4.default.existsSync(templateDir) && import_fs4.default.statSync(templateDir).isDirectory()) {
3333
+ for await (const entry of (0, import_readdirp.readdirp)(templateDir, {
3334
+ fileFilter: [
3335
+ "!package.js",
3336
+ "!package.json",
3337
+ "!package-lock.json",
3338
+ "!template.json",
3339
+ "!yarn.lock",
3340
+ "!pnpm-lock.yaml",
3341
+ // based on the package manager we want to ignore files containing
3342
+ // the other package as condition.
3343
+ // For example, if `usePnpm` is true, the we need to ignore
3344
+ // all files with `.if-npm` or `.if-yarn` somewhere in the name.
3345
+ ...usePnpm ? ["!*.if-npm.*", "!*.if-yarn.*"] : useYarn ? ["!*.if-npm.*", "!*.if-pnpm.*"] : ["!*.if-yarn.*", "!*.if-pnpm.*"]
3346
+ ],
3347
+ directoryFilter: ["!package"]
3348
+ })) {
3349
+ operations.push({
3350
+ root,
3351
+ templateDir,
3352
+ appName,
3353
+ originalDirectory,
3354
+ verbose,
3355
+ useYarn,
3356
+ usePnpm,
3357
+ srcDir,
3358
+ runCommand,
3359
+ installCommand,
3360
+ entry,
3361
+ ...customOptions
3362
+ });
3363
+ }
3364
+ }
3365
+ }
3366
+ await Promise.all(
3367
+ operations.map((operation) => fileLoader(operation)(operation.entry))
3368
+ );
3369
+ } catch (err) {
3370
+ if (verbose) {
3371
+ console.log(err);
3372
+ }
3373
+ throw err;
3374
+ }
3375
+ };
3376
+
3377
+ // installer.ts
3378
+ var install = async (root, useYarn = false, usePnpm = false, dependencies = [], verbose = false, isOnline = true, isDevDependencies = false) => {
3379
+ let command;
3380
+ let args;
3381
+ if (useYarn) {
3382
+ command = "yarnpkg";
3383
+ args = ["add", "--ignore-workspace-root-check"];
3384
+ if (!isOnline) {
3385
+ args.push("--offline");
3386
+ }
3387
+ if (isDevDependencies) {
3388
+ args.push("--dev");
3389
+ }
3390
+ args.push(...dependencies);
3391
+ args.push("--cwd");
3392
+ args.push(root);
3393
+ if (!isOnline) {
3394
+ console.log(import_picocolors3.default.yellow("You appear to be offline."));
3395
+ console.log(import_picocolors3.default.yellow("Falling back to the local Yarn cache."));
3396
+ console.log();
3397
+ }
3398
+ } else if (usePnpm) {
3399
+ command = "pnpm";
3400
+ args = ["install", "--ignore-workspace", "--loglevel", "error"];
3401
+ if (isDevDependencies) {
3402
+ args.push("--save-dev");
3403
+ } else {
3404
+ args.push("--save");
3405
+ }
3406
+ args.push(...dependencies);
3407
+ } else {
3408
+ command = "npm";
3409
+ args = ["install", "--loglevel", "error"];
3410
+ if (isDevDependencies) {
3411
+ args.push("--save-dev");
3412
+ } else {
3413
+ args.push("--save");
3414
+ }
3415
+ args.push(...dependencies);
3416
+ }
3417
+ if (verbose) {
3418
+ args.push("--verbose");
3419
+ }
3420
+ try {
3421
+ (0, import_child_process2.execSync)(`${command} ${args.join(" ")}`, {
3422
+ cwd: root,
3423
+ stdio: "inherit"
3424
+ });
3425
+ } catch (error) {
3426
+ throw new Error(`${command} ${args.join(" ")}`);
3427
+ }
3428
+ };
3429
+ var runCommandInProjectDir = async (root, command, args = [], successMessage = "Operation completed successfully.", errorMessage = "Operation failed.") => {
3430
+ try {
3431
+ (0, import_child_process2.execSync)(`${command} ${args.join(" ")}`, {
3432
+ cwd: root,
3433
+ stdio: "ignore"
3434
+ });
3435
+ console.log(import_picocolors3.default.green(successMessage));
3436
+ } catch (error) {
3437
+ console.log();
3438
+ console.log(import_picocolors3.default.red(errorMessage));
3439
+ console.log();
3440
+ }
3441
+ };
3442
+ function extractNameAndVersion(dependencyString) {
3443
+ const lastIndex = dependencyString.lastIndexOf("@");
3444
+ if (lastIndex !== -1) {
3445
+ const name = dependencyString.substring(0, lastIndex);
3446
+ const version = dependencyString.substring(lastIndex + 1);
3447
+ return { name, version };
3448
+ } else {
3449
+ return { name: dependencyString, version: "" };
3450
+ }
3451
+ }
3452
+ var run = async ({
3453
+ root,
3454
+ appName,
3455
+ originalDirectory,
3456
+ verbose = false,
3457
+ useYarn = false,
3458
+ usePnpm = false,
3459
+ templatesOrExtensions = [],
3460
+ dependencies = [],
3461
+ devDependencies = [],
3462
+ installDependencies = true,
3463
+ runCommand = "",
3464
+ installCommand = "",
3465
+ ...customOptions
3466
+ }) => {
3467
+ const isOnline = useYarn ? await checkIfOnline(useYarn) : true;
3468
+ if (import_underscore2.default.isEmpty(templatesOrExtensions)) {
3469
+ console.log();
3470
+ console.log(
3471
+ import_picocolors3.default.yellow(
3472
+ "No templates or extensions specified to bootstrap application."
3473
+ )
3474
+ );
3475
+ console.log();
3476
+ process.exit(0);
3477
+ }
3478
+ console.log();
3479
+ console.log("Scaffolding project in " + root + "...");
3480
+ await loadFiles({
3481
+ root,
3482
+ templatesOrExtensions,
3483
+ appName,
3484
+ originalDirectory,
3485
+ verbose,
3486
+ useYarn,
3487
+ usePnpm,
3488
+ runCommand,
3489
+ installCommand,
3490
+ ...customOptions
3491
+ });
3492
+ console.log();
3493
+ console.log(import_picocolors3.default.green("Successfully scaffolded project."));
3494
+ console.log();
3495
+ if (installDependencies) {
3496
+ console.log(
3497
+ import_picocolors3.default.green("Installing packages. This might take a couple of minutes.")
3498
+ );
3499
+ console.log(import_picocolors3.default.green("Installing dependencies..."));
3500
+ console.log();
3501
+ await install(
3502
+ root,
3503
+ useYarn,
3504
+ usePnpm,
3505
+ dependencies,
3506
+ verbose,
3507
+ isOnline,
3508
+ false
3509
+ );
3510
+ if (devDependencies.length > 0) {
3511
+ console.log();
3512
+ console.log(import_picocolors3.default.green("Installing devDependencies..."));
3513
+ console.log();
3514
+ await install(
3515
+ root,
3516
+ useYarn,
3517
+ usePnpm,
3518
+ devDependencies,
3519
+ verbose,
3520
+ isOnline,
3521
+ true
3522
+ );
3523
+ }
3524
+ } else {
3525
+ console.log(import_picocolors3.default.yellow("Skip package installation."));
3526
+ const packageJson2 = JSON.parse(
3527
+ import_fs5.default.readFileSync(`${root}/package.json`, "utf8")
3528
+ );
3529
+ const updateDependencies = (deps) => {
3530
+ return deps.reduce(
3531
+ (dep, elem) => {
3532
+ const nextDep = dep;
3533
+ if (/.+@(\^|~)?[0-9a-zA-Z-.]+$/.test(elem)) {
3534
+ const { name, version } = extractNameAndVersion(elem);
3535
+ nextDep[name] = version;
3536
+ } else {
3537
+ nextDep[elem] = "*";
3538
+ }
3539
+ return nextDep;
3540
+ },
3541
+ {}
3542
+ );
3543
+ };
3544
+ packageJson2.dependencies = updateDependencies(dependencies);
3545
+ packageJson2.devDependencies = updateDependencies(devDependencies);
3546
+ import_fs5.default.writeFileSync(
3547
+ import_path4.default.join(root, "package.json"),
3548
+ JSON.stringify(packageJson2, null, 2) + import_os3.default.EOL
3549
+ );
3550
+ console.log();
3551
+ console.log(import_picocolors3.default.green("Successfully updated package.json."));
3552
+ console.log(import_picocolors3.default.yellow(`Run ${import_picocolors3.default.cyan(installCommand)} to install.`));
3553
+ }
3554
+ console.log();
3555
+ console.log("Initializing git repository...");
3556
+ try {
3557
+ const { simpleGit: simpleGit2 } = await import("simple-git");
3558
+ const git = simpleGit2(root);
3559
+ await git.init();
3560
+ console.log(import_picocolors3.default.green("Successfully initialized git repository."));
3561
+ } catch (error) {
3562
+ console.log();
3563
+ console.log(
3564
+ import_picocolors3.default.red(
3565
+ "Failed to initialize git repository. Run `git init` to initialize git repository after the process is completed."
3566
+ )
3567
+ );
3568
+ console.log();
3569
+ }
3570
+ if (installDependencies && isOnline) {
3571
+ const packageJson2 = JSON.parse(
3572
+ import_fs5.default.readFileSync(`${root}/package.json`, "utf8")
3573
+ );
3574
+ const runFormat = async () => {
3575
+ try {
3576
+ await runCommandInProjectDir(
3577
+ root,
3578
+ runCommand,
3579
+ ["format"],
3580
+ "Successfully formatted code.",
3581
+ `Failed to format code. Run \`${runCommand} format\` to format code after the process is completed.`
3582
+ );
3583
+ } catch {
3584
+ }
3585
+ };
3586
+ const runLintFix = async () => {
3587
+ try {
3588
+ await runCommandInProjectDir(
3589
+ root,
3590
+ runCommand,
3591
+ ["lint:fix"],
3592
+ "Successfully fixed linting errors.",
3593
+ `Failed to fix linting errors. Run \`${runCommand} lint:fix\` to fix linting errors after the process is completed.`
3594
+ );
3595
+ } catch {
3596
+ }
3597
+ };
3598
+ if (packageJson2.scripts && packageJson2.scripts["format"]) {
3599
+ await runFormat();
3600
+ }
3601
+ if (packageJson2.scripts && packageJson2.scripts["lint:fix"]) {
3602
+ await runLintFix();
3603
+ }
3604
+ }
3605
+ console.log();
3606
+ console.log(import_picocolors3.default.green("Successfully created project " + appName + "."));
3607
+ console.log();
3608
+ console.log("Done! Now run:");
3609
+ console.log();
3610
+ console.log(import_picocolors3.default.cyan(` cd ${appName}`));
3611
+ console.log(import_picocolors3.default.cyan(` ${installCommand}`));
3612
+ const packageJson = JSON.parse(
3613
+ import_fs5.default.readFileSync(`${root}/package.json`, "utf8")
3614
+ );
3615
+ const lookForScripts = ["compose:up", "sls:offline", "dev", "start"];
3616
+ for (const script of lookForScripts) {
3617
+ if (packageJson.scripts && packageJson.scripts[script]) {
3618
+ console.log(import_picocolors3.default.cyan(` ${runCommand} ${script}`));
3619
+ break;
3620
+ }
3621
+ }
3622
+ console.log();
3623
+ console.log(import_picocolors3.default.green("Happy hacking!"));
3624
+ };
3625
+ var createApp = async ({
3626
+ name,
3627
+ verbose = false,
3628
+ templatesOrExtensions = [],
3629
+ installDependencies = true,
3630
+ ignorePackage = false,
3631
+ ...customOptions
3632
+ }) => {
3633
+ const root = import_path4.default.resolve(name);
3634
+ const appName = import_path4.default.basename(root);
3635
+ import_fs5.default.mkdirSync(name, {
3636
+ recursive: true
3637
+ });
3638
+ console.log(`Creating a new Node app in ${import_picocolors3.default.green(root)}.`);
3639
+ console.log();
3640
+ const useYarn = customOptions.packageManager === "yarn" && shouldUseYarn();
3641
+ const usePnpm = customOptions.packageManager === "pnpm" && shouldUsePnpm();
3642
+ const runCommand = useYarn ? "yarn" : usePnpm ? "pnpm run" : "npm run";
3643
+ const installCommand = useYarn ? "yarn" : usePnpm ? "pnpm install" : "npm install";
3644
+ const { packageJson, dependencies, devDependencies } = await loadPackages({
3645
+ templatesOrExtensions,
3646
+ appName,
3647
+ usePnpm,
3648
+ useYarn,
3649
+ runCommand,
3650
+ ignorePackage
3651
+ });
3652
+ import_fs5.default.writeFileSync(
3653
+ import_path4.default.join(root, "package.json"),
3654
+ JSON.stringify(packageJson, null, 2) + import_os3.default.EOL
3655
+ );
3656
+ const originalDirectory = process.cwd();
3657
+ process.chdir(root);
3658
+ if (!useYarn && !checkThatNpmCanReadCwd()) {
3659
+ process.exit(1);
3660
+ }
3661
+ if (!import_semver2.default.satisfies(process.version, ">=18.0.0")) {
3662
+ console.log(
3663
+ import_picocolors3.default.yellow(
3664
+ `You are using Node ${process.version} so the project will be bootstrapped with an old unsupported version of tools.
3665
+
3666
+ Please update to Node 18 or higher for a better, fully supported experience.
3667
+ `
3668
+ )
3669
+ );
3670
+ }
3671
+ if (!useYarn) {
3672
+ const npmInfo = checkNpmVersion();
3673
+ if (!npmInfo.hasMinNpm) {
3674
+ if (npmInfo.npmVersion) {
3675
+ console.log(
3676
+ import_picocolors3.default.yellow(
3677
+ `You are using npm ${npmInfo.npmVersion} so the project will be bootstrapped with an old unsupported version of tools.
3678
+
3679
+ Please update to npm 3 or higher for a better, fully supported experience.
3680
+ `
3681
+ )
3682
+ );
3683
+ }
3684
+ }
3685
+ }
3686
+ if (useYarn) {
3687
+ let yarnUsesDefaultRegistry = true;
3688
+ try {
3689
+ yarnUsesDefaultRegistry = (0, import_child_process2.execSync)("yarnpkg config get registry").toString().trim() === "https://registry.yarnpkg.com";
3690
+ } catch (e) {
3691
+ }
3692
+ if (false) {
3693
+ import_fs5.default.cpSync(
3694
+ null,
3695
+ import_path4.default.join(root, "yarn.lock"),
3696
+ { force: true }
3697
+ );
3698
+ }
3699
+ }
3700
+ return run({
3701
+ root,
3702
+ appName,
3703
+ originalDirectory,
3704
+ verbose,
3705
+ useYarn,
3706
+ usePnpm,
3707
+ templatesOrExtensions,
3708
+ dependencies,
3709
+ devDependencies,
3710
+ installDependencies,
3711
+ runCommand,
3712
+ installCommand,
3713
+ ...customOptions
3714
+ });
3715
+ };
3716
+
3717
+ // index.ts
3718
+ var checkNodeVersion = (requiredVersion, packageName) => {
3719
+ if (!import_semver3.default.satisfies(process.version, requiredVersion)) {
3720
+ console.error(
3721
+ import_picocolors4.default.red(
3722
+ `You are running Node ${process.version}.
3723
+ ${packageName} requires Node ${requiredVersion}.
3724
+ Please update your version of Node.`
3725
+ )
3726
+ );
3727
+ process.exit(1);
3728
+ }
3729
+ };
3730
+ var checkForLatestVersion = async (packageName) => {
3731
+ try {
3732
+ const response = await fetch(
3733
+ `https://registry.npmjs.org/-/package/${packageName}/dist-tags`
3734
+ );
3735
+ if (!response.ok) {
3736
+ throw new Error("Registry request failed");
3737
+ }
3738
+ const json = await response.json();
3739
+ if (json && typeof json === "object" && "latest" in json) {
3740
+ return String(json["latest"]);
3741
+ }
3742
+ return null;
3743
+ } catch (error) {
3744
+ try {
3745
+ return (0, import_child_process3.execSync)(`npm view ${packageName} version`).toString().trim();
3746
+ } catch {
3747
+ }
3748
+ }
3749
+ return null;
3750
+ };
3751
+ var printEnvInfo = async () => {
3752
+ console.log(import_picocolors4.default.bold("\nEnvironment Info:"));
3753
+ const info = await import_envinfo.default.run(
3754
+ {
3755
+ System: ["OS", "CPU", "Memory", "Shell"],
3756
+ Binaries: ["Node", "npm", "pnpm", "Yarn", "Watchman"],
3757
+ Browsers: ["Chrome", "Edge", "Internet Explorer", "Firefox", "Safari"]
3758
+ },
3759
+ {
3760
+ duplicates: true,
3761
+ showNotFound: true
3762
+ }
3763
+ );
3764
+ console.log(info);
3765
+ process.exit(0);
3766
+ };
3767
+ var createNodeApp = async (programName, options, transformOptions) => {
3768
+ if (options.info) {
3769
+ await printEnvInfo();
3770
+ }
3771
+ if (typeof options.projectName === "undefined") {
3772
+ console.error("Please specify the project directory:");
3773
+ console.log(` ${import_picocolors4.default.cyan(programName)} ${import_picocolors4.default.green("[project-directory]")}`);
3774
+ console.log();
3775
+ console.log("For example:");
3776
+ console.log(` ${import_picocolors4.default.cyan(programName)} ${import_picocolors4.default.green("my-app")}`);
3777
+ console.log();
3778
+ console.log(`Run ${import_picocolors4.default.cyan(`${programName} --help`)} to see all options.`);
3779
+ process.exit(1);
3780
+ }
3781
+ const appOptions = await transformOptions(options);
3782
+ await createApp({
3783
+ ...appOptions,
3784
+ name: appOptions.projectName,
3785
+ installDependencies: options.install ?? true
3786
+ });
3787
+ };
3788
+ // Annotate the CommonJS export names for ESM import in node:
3789
+ 0 && (module.exports = {
3790
+ checkForLatestVersion,
3791
+ checkNodeVersion,
3792
+ createNodeApp,
3793
+ printEnvInfo
3794
+ });