@sanity/pkg-utils 1.12.0 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/dist/_chunks/{build-8b5bd627.js → build-83c36253.js} +2 -2
  2. package/dist/_chunks/build-83c36253.js.map +1 -0
  3. package/dist/_chunks/{buildAction-87c64945.js → buildAction-19b87a46.js} +4 -6
  4. package/dist/_chunks/{buildAction-87c64945.js.map → buildAction-19b87a46.js.map} +1 -1
  5. package/dist/_chunks/index-33f2afe8.js +789 -0
  6. package/dist/_chunks/index-33f2afe8.js.map +1 -0
  7. package/dist/_chunks/{watch-ccb7daf2.js → watch-12e6eafa.js} +2 -2
  8. package/dist/_chunks/watch-12e6eafa.js.map +1 -0
  9. package/dist/_chunks/{watchAction-b7c1e241.js → watchAction-d4ae9e80.js} +4 -6
  10. package/dist/_chunks/{watchAction-b7c1e241.js.map → watchAction-d4ae9e80.js.map} +1 -1
  11. package/dist/cli.js +3 -3
  12. package/dist/index.d.ts +45 -1
  13. package/dist/index.esm.js +121 -3565
  14. package/dist/index.esm.js.map +1 -1
  15. package/dist/index.js +5 -6
  16. package/dist/index.js.map +1 -1
  17. package/package.json +6 -4
  18. package/src/node/_core/config/types.ts +22 -0
  19. package/src/node/_resolveBuildTasks.ts +1 -1
  20. package/src/node/_resolveWatchTasks.ts +1 -1
  21. package/src/node/_tasks/dts/_doExtract.ts +1 -0
  22. package/src/node/_tasks/dts/_extractTypes.ts +16 -85
  23. package/src/node/_tasks/dts/_getExtractMessagesConfig.ts +87 -0
  24. package/src/node/_tasks/dts/index.ts +1 -0
  25. package/src/node/_tasks/rollup/_resolveRollupConfig.ts +8 -1
  26. package/src/node/build.ts +19 -1
  27. package/dist/_chunks/build-8b5bd627.js.map +0 -1
  28. package/dist/_chunks/index-4a1fe6d6.js +0 -4239
  29. package/dist/_chunks/index-4a1fe6d6.js.map +0 -1
  30. package/dist/_chunks/watch-ccb7daf2.js.map +0 -1
@@ -1,4239 +0,0 @@
1
- 'use strict';
2
-
3
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
4
-
5
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
6
-
7
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
8
-
9
- var chalk = require('chalk');
10
-
11
- var rxjs = require('rxjs');
12
-
13
- var path$1 = require('path');
14
-
15
- var require$$3$1 = require('util');
16
-
17
- var require$$5 = require('assert');
18
-
19
- var fs$1 = require('fs');
20
-
21
- var require$$3 = require('events');
22
-
23
- var ts = require('typescript');
24
-
25
- var fs$2 = require('fs/promises');
26
-
27
- var apiExtractor = require('@microsoft/api-extractor');
28
-
29
- var mkdirp = require('mkdirp');
30
-
31
- var prettier = require('prettier');
32
-
33
- var tsdocConfig = require('@microsoft/tsdoc-config');
34
-
35
- var jsoncParser = require('jsonc-parser');
36
-
37
- var rollup = require('rollup');
38
-
39
- var alias = require('@rollup/plugin-alias');
40
-
41
- var pluginBabel = require('@rollup/plugin-babel');
42
-
43
- var commonjs = require('@rollup/plugin-commonjs');
44
-
45
- var json = require('@rollup/plugin-json');
46
-
47
- var pluginNodeResolve = require('@rollup/plugin-node-resolve');
48
-
49
- var replace = require('@rollup/plugin-replace');
50
-
51
- var esbuild = require('rollup-plugin-esbuild');
52
-
53
- var rollupPluginTerser = require('rollup-plugin-terser');
54
-
55
- var _resolveBuildContext = require('./_resolveBuildContext-ef196a3e.js');
56
-
57
- require('esbuild-register/dist/node');
58
-
59
- require('pkg-up');
60
-
61
- require('find-config');
62
-
63
- require('zod');
64
-
65
- function _interopDefaultLegacy(e) {
66
- return e && typeof e === 'object' && 'default' in e ? e : {
67
- 'default': e
68
- };
69
- }
70
-
71
- var chalk__default = /*#__PURE__*/_interopDefaultLegacy(chalk);
72
-
73
- var path__default = /*#__PURE__*/_interopDefaultLegacy(path$1);
74
-
75
- var require$$5__default = /*#__PURE__*/_interopDefaultLegacy(require$$5);
76
-
77
- var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs$1);
78
-
79
- var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3);
80
-
81
- var ts__default = /*#__PURE__*/_interopDefaultLegacy(ts);
82
-
83
- var fs__default$1 = /*#__PURE__*/_interopDefaultLegacy(fs$2);
84
-
85
- var mkdirp__default = /*#__PURE__*/_interopDefaultLegacy(mkdirp);
86
-
87
- var prettier__default = /*#__PURE__*/_interopDefaultLegacy(prettier);
88
-
89
- var alias__default = /*#__PURE__*/_interopDefaultLegacy(alias);
90
-
91
- var commonjs__default = /*#__PURE__*/_interopDefaultLegacy(commonjs);
92
-
93
- var json__default = /*#__PURE__*/_interopDefaultLegacy(json);
94
-
95
- var replace__default = /*#__PURE__*/_interopDefaultLegacy(replace);
96
-
97
- var esbuild__default = /*#__PURE__*/_interopDefaultLegacy(esbuild);
98
-
99
- function _printExtractMessages(ctx, messages) {
100
- const {
101
- cwd,
102
- logger
103
- } = ctx;
104
- const warnings = messages.filter(msg => msg.logLevel === "warning");
105
-
106
- if (warnings.length) {
107
- logger.log();
108
- }
109
-
110
- for (const msg of warnings) {
111
- const sourceFilePath = msg.sourceFilePath && path__default["default"].relative(cwd, msg.sourceFilePath);
112
-
113
- if (msg.messageId === "TS6307") {
114
- continue;
115
- }
116
-
117
- logger.log(["".concat(chalk__default["default"].cyan(sourceFilePath || "?")), ":".concat(chalk__default["default"].yellow(msg.sourceFileLine), ":").concat(chalk__default["default"].yellow(msg.sourceFileColumn)), " - ".concat(chalk__default["default"].yellow("warning"), " ").concat(chalk__default["default"].gray(msg.messageId), "\n"), msg.text, "\n"].join(""));
118
- }
119
-
120
- const errors = messages.filter(msg => msg.logLevel === "error");
121
-
122
- if (!warnings.length && errors.length) {
123
- logger.log("");
124
- }
125
-
126
- for (const msg of errors) {
127
- const sourceFilePath = msg.sourceFilePath && path__default["default"].relative(cwd, msg.sourceFilePath);
128
- logger.log(["".concat(chalk__default["default"].cyan(sourceFilePath || "?")), ":".concat(chalk__default["default"].yellow(msg.sourceFileLine), ":").concat(chalk__default["default"].yellow(msg.sourceFileColumn)), " - ".concat(chalk__default["default"].red("error"), " ").concat(chalk__default["default"].gray(msg.messageId), "\n"), msg.text, "\n"].join(""));
129
- }
130
-
131
- if (errors.length) {
132
- process.exit(1);
133
- }
134
- }
135
-
136
- var old = {};
137
- var hasRequiredOld;
138
-
139
- function requireOld() {
140
- if (hasRequiredOld) return old;
141
- hasRequiredOld = 1; // Copyright Joyent, Inc. and other Node contributors.
142
- //
143
- // Permission is hereby granted, free of charge, to any person obtaining a
144
- // copy of this software and associated documentation files (the
145
- // "Software"), to deal in the Software without restriction, including
146
- // without limitation the rights to use, copy, modify, merge, publish,
147
- // distribute, sublicense, and/or sell copies of the Software, and to permit
148
- // persons to whom the Software is furnished to do so, subject to the
149
- // following conditions:
150
- //
151
- // The above copyright notice and this permission notice shall be included
152
- // in all copies or substantial portions of the Software.
153
- //
154
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
155
- // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
156
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
157
- // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
158
- // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
159
- // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
160
- // USE OR OTHER DEALINGS IN THE SOFTWARE.
161
-
162
- var pathModule = path__default["default"];
163
- var isWindows = process.platform === 'win32';
164
- var fs = fs__default["default"]; // JavaScript implementation of realpath, ported from node pre-v6
165
-
166
- var DEBUG = process.env.NODE_DEBUG && /fs/.test(process.env.NODE_DEBUG);
167
-
168
- function rethrow() {
169
- // Only enable in debug mode. A backtrace uses ~1000 bytes of heap space and
170
- // is fairly slow to generate.
171
- var callback;
172
-
173
- if (DEBUG) {
174
- var backtrace = new Error();
175
- callback = debugCallback;
176
- } else callback = missingCallback;
177
-
178
- return callback;
179
-
180
- function debugCallback(err) {
181
- if (err) {
182
- backtrace.message = err.message;
183
- err = backtrace;
184
- missingCallback(err);
185
- }
186
- }
187
-
188
- function missingCallback(err) {
189
- if (err) {
190
- if (process.throwDeprecation) throw err; // Forgot a callback but don't know where? Use NODE_DEBUG=fs
191
- else if (!process.noDeprecation) {
192
- var msg = 'fs: missing callback ' + (err.stack || err.message);
193
- if (process.traceDeprecation) console.trace(msg);else console.error(msg);
194
- }
195
- }
196
- }
197
- }
198
-
199
- function maybeCallback(cb) {
200
- return typeof cb === 'function' ? cb : rethrow();
201
- } // Regexp that finds the next partion of a (partial) path
202
- // result is [base_with_slash, base], e.g. ['somedir/', 'somedir']
203
-
204
-
205
- if (isWindows) {
206
- var nextPartRe = /(.*?)(?:[\/\\]+|$)/g;
207
- } else {
208
- var nextPartRe = /(.*?)(?:[\/]+|$)/g;
209
- } // Regex to find the device root, including trailing slash. E.g. 'c:\\'.
210
-
211
-
212
- if (isWindows) {
213
- var splitRootRe = /^(?:[a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/][^\\\/]+)?[\\\/]*/;
214
- } else {
215
- var splitRootRe = /^[\/]*/;
216
- }
217
-
218
- old.realpathSync = function realpathSync(p, cache) {
219
- // make p is absolute
220
- p = pathModule.resolve(p);
221
-
222
- if (cache && Object.prototype.hasOwnProperty.call(cache, p)) {
223
- return cache[p];
224
- }
225
-
226
- var original = p,
227
- seenLinks = {},
228
- knownHard = {}; // current character position in p
229
-
230
- var pos; // the partial path so far, including a trailing slash if any
231
-
232
- var current; // the partial path without a trailing slash (except when pointing at a root)
233
-
234
- var base; // the partial path scanned in the previous round, with slash
235
-
236
- var previous;
237
- start();
238
-
239
- function start() {
240
- // Skip over roots
241
- var m = splitRootRe.exec(p);
242
- pos = m[0].length;
243
- current = m[0];
244
- base = m[0];
245
- previous = ''; // On windows, check that the root exists. On unix there is no need.
246
-
247
- if (isWindows && !knownHard[base]) {
248
- fs.lstatSync(base);
249
- knownHard[base] = true;
250
- }
251
- } // walk down the path, swapping out linked pathparts for their real
252
- // values
253
- // NB: p.length changes.
254
-
255
-
256
- while (pos < p.length) {
257
- // find the next part
258
- nextPartRe.lastIndex = pos;
259
- var result = nextPartRe.exec(p);
260
- previous = current;
261
- current += result[0];
262
- base = previous + result[1];
263
- pos = nextPartRe.lastIndex; // continue if not a symlink
264
-
265
- if (knownHard[base] || cache && cache[base] === base) {
266
- continue;
267
- }
268
-
269
- var resolvedLink;
270
-
271
- if (cache && Object.prototype.hasOwnProperty.call(cache, base)) {
272
- // some known symbolic link. no need to stat again.
273
- resolvedLink = cache[base];
274
- } else {
275
- var stat = fs.lstatSync(base);
276
-
277
- if (!stat.isSymbolicLink()) {
278
- knownHard[base] = true;
279
- if (cache) cache[base] = base;
280
- continue;
281
- } // read the link if it wasn't read before
282
- // dev/ino always return 0 on windows, so skip the check.
283
-
284
-
285
- var linkTarget = null;
286
-
287
- if (!isWindows) {
288
- var id = stat.dev.toString(32) + ':' + stat.ino.toString(32);
289
-
290
- if (seenLinks.hasOwnProperty(id)) {
291
- linkTarget = seenLinks[id];
292
- }
293
- }
294
-
295
- if (linkTarget === null) {
296
- fs.statSync(base);
297
- linkTarget = fs.readlinkSync(base);
298
- }
299
-
300
- resolvedLink = pathModule.resolve(previous, linkTarget); // track this, if given a cache.
301
-
302
- if (cache) cache[base] = resolvedLink;
303
- if (!isWindows) seenLinks[id] = linkTarget;
304
- } // resolve the link, then start over
305
-
306
-
307
- p = pathModule.resolve(resolvedLink, p.slice(pos));
308
- start();
309
- }
310
-
311
- if (cache) cache[original] = p;
312
- return p;
313
- };
314
-
315
- old.realpath = function realpath(p, cache, cb) {
316
- if (typeof cb !== 'function') {
317
- cb = maybeCallback(cache);
318
- cache = null;
319
- } // make p is absolute
320
-
321
-
322
- p = pathModule.resolve(p);
323
-
324
- if (cache && Object.prototype.hasOwnProperty.call(cache, p)) {
325
- return process.nextTick(cb.bind(null, null, cache[p]));
326
- }
327
-
328
- var original = p,
329
- seenLinks = {},
330
- knownHard = {}; // current character position in p
331
-
332
- var pos; // the partial path so far, including a trailing slash if any
333
-
334
- var current; // the partial path without a trailing slash (except when pointing at a root)
335
-
336
- var base; // the partial path scanned in the previous round, with slash
337
-
338
- var previous;
339
- start();
340
-
341
- function start() {
342
- // Skip over roots
343
- var m = splitRootRe.exec(p);
344
- pos = m[0].length;
345
- current = m[0];
346
- base = m[0];
347
- previous = ''; // On windows, check that the root exists. On unix there is no need.
348
-
349
- if (isWindows && !knownHard[base]) {
350
- fs.lstat(base, function (err) {
351
- if (err) return cb(err);
352
- knownHard[base] = true;
353
- LOOP();
354
- });
355
- } else {
356
- process.nextTick(LOOP);
357
- }
358
- } // walk down the path, swapping out linked pathparts for their real
359
- // values
360
-
361
-
362
- function LOOP() {
363
- // stop if scanned past end of path
364
- if (pos >= p.length) {
365
- if (cache) cache[original] = p;
366
- return cb(null, p);
367
- } // find the next part
368
-
369
-
370
- nextPartRe.lastIndex = pos;
371
- var result = nextPartRe.exec(p);
372
- previous = current;
373
- current += result[0];
374
- base = previous + result[1];
375
- pos = nextPartRe.lastIndex; // continue if not a symlink
376
-
377
- if (knownHard[base] || cache && cache[base] === base) {
378
- return process.nextTick(LOOP);
379
- }
380
-
381
- if (cache && Object.prototype.hasOwnProperty.call(cache, base)) {
382
- // known symbolic link. no need to stat again.
383
- return gotResolvedLink(cache[base]);
384
- }
385
-
386
- return fs.lstat(base, gotStat);
387
- }
388
-
389
- function gotStat(err, stat) {
390
- if (err) return cb(err); // if not a symlink, skip to the next path part
391
-
392
- if (!stat.isSymbolicLink()) {
393
- knownHard[base] = true;
394
- if (cache) cache[base] = base;
395
- return process.nextTick(LOOP);
396
- } // stat & read the link if not read before
397
- // call gotTarget as soon as the link target is known
398
- // dev/ino always return 0 on windows, so skip the check.
399
-
400
-
401
- if (!isWindows) {
402
- var id = stat.dev.toString(32) + ':' + stat.ino.toString(32);
403
-
404
- if (seenLinks.hasOwnProperty(id)) {
405
- return gotTarget(null, seenLinks[id], base);
406
- }
407
- }
408
-
409
- fs.stat(base, function (err) {
410
- if (err) return cb(err);
411
- fs.readlink(base, function (err, target) {
412
- if (!isWindows) seenLinks[id] = target;
413
- gotTarget(err, target);
414
- });
415
- });
416
- }
417
-
418
- function gotTarget(err, target, base) {
419
- if (err) return cb(err);
420
- var resolvedLink = pathModule.resolve(previous, target);
421
- if (cache) cache[base] = resolvedLink;
422
- gotResolvedLink(resolvedLink);
423
- }
424
-
425
- function gotResolvedLink(resolvedLink) {
426
- // resolve the link, then start over
427
- p = pathModule.resolve(resolvedLink, p.slice(pos));
428
- start();
429
- }
430
- };
431
-
432
- return old;
433
- }
434
-
435
- var fs_realpath;
436
- var hasRequiredFs_realpath;
437
-
438
- function requireFs_realpath() {
439
- if (hasRequiredFs_realpath) return fs_realpath;
440
- hasRequiredFs_realpath = 1;
441
- fs_realpath = realpath;
442
- realpath.realpath = realpath;
443
- realpath.sync = realpathSync;
444
- realpath.realpathSync = realpathSync;
445
- realpath.monkeypatch = monkeypatch;
446
- realpath.unmonkeypatch = unmonkeypatch;
447
- var fs = fs__default["default"];
448
- var origRealpath = fs.realpath;
449
- var origRealpathSync = fs.realpathSync;
450
- var version = process.version;
451
- var ok = /^v[0-5]\./.test(version);
452
- var old = requireOld();
453
-
454
- function newError(er) {
455
- return er && er.syscall === 'realpath' && (er.code === 'ELOOP' || er.code === 'ENOMEM' || er.code === 'ENAMETOOLONG');
456
- }
457
-
458
- function realpath(p, cache, cb) {
459
- if (ok) {
460
- return origRealpath(p, cache, cb);
461
- }
462
-
463
- if (typeof cache === 'function') {
464
- cb = cache;
465
- cache = null;
466
- }
467
-
468
- origRealpath(p, cache, function (er, result) {
469
- if (newError(er)) {
470
- old.realpath(p, cache, cb);
471
- } else {
472
- cb(er, result);
473
- }
474
- });
475
- }
476
-
477
- function realpathSync(p, cache) {
478
- if (ok) {
479
- return origRealpathSync(p, cache);
480
- }
481
-
482
- try {
483
- return origRealpathSync(p, cache);
484
- } catch (er) {
485
- if (newError(er)) {
486
- return old.realpathSync(p, cache);
487
- } else {
488
- throw er;
489
- }
490
- }
491
- }
492
-
493
- function monkeypatch() {
494
- fs.realpath = realpath;
495
- fs.realpathSync = realpathSync;
496
- }
497
-
498
- function unmonkeypatch() {
499
- fs.realpath = origRealpath;
500
- fs.realpathSync = origRealpathSync;
501
- }
502
-
503
- return fs_realpath;
504
- }
505
-
506
- var concatMap;
507
- var hasRequiredConcatMap;
508
-
509
- function requireConcatMap() {
510
- if (hasRequiredConcatMap) return concatMap;
511
- hasRequiredConcatMap = 1;
512
-
513
- concatMap = function (xs, fn) {
514
- var res = [];
515
-
516
- for (var i = 0; i < xs.length; i++) {
517
- var x = fn(xs[i], i);
518
- if (isArray(x)) res.push.apply(res, x);else res.push(x);
519
- }
520
-
521
- return res;
522
- };
523
-
524
- var isArray = Array.isArray || function (xs) {
525
- return Object.prototype.toString.call(xs) === '[object Array]';
526
- };
527
-
528
- return concatMap;
529
- }
530
-
531
- var balancedMatch;
532
- var hasRequiredBalancedMatch;
533
-
534
- function requireBalancedMatch() {
535
- if (hasRequiredBalancedMatch) return balancedMatch;
536
- hasRequiredBalancedMatch = 1;
537
- balancedMatch = balanced;
538
-
539
- function balanced(a, b, str) {
540
- if (a instanceof RegExp) a = maybeMatch(a, str);
541
- if (b instanceof RegExp) b = maybeMatch(b, str);
542
- var r = range(a, b, str);
543
- return r && {
544
- start: r[0],
545
- end: r[1],
546
- pre: str.slice(0, r[0]),
547
- body: str.slice(r[0] + a.length, r[1]),
548
- post: str.slice(r[1] + b.length)
549
- };
550
- }
551
-
552
- function maybeMatch(reg, str) {
553
- var m = str.match(reg);
554
- return m ? m[0] : null;
555
- }
556
-
557
- balanced.range = range;
558
-
559
- function range(a, b, str) {
560
- var begs, beg, left, right, result;
561
- var ai = str.indexOf(a);
562
- var bi = str.indexOf(b, ai + 1);
563
- var i = ai;
564
-
565
- if (ai >= 0 && bi > 0) {
566
- if (a === b) {
567
- return [ai, bi];
568
- }
569
-
570
- begs = [];
571
- left = str.length;
572
-
573
- while (i >= 0 && !result) {
574
- if (i == ai) {
575
- begs.push(i);
576
- ai = str.indexOf(a, i + 1);
577
- } else if (begs.length == 1) {
578
- result = [begs.pop(), bi];
579
- } else {
580
- beg = begs.pop();
581
-
582
- if (beg < left) {
583
- left = beg;
584
- right = bi;
585
- }
586
-
587
- bi = str.indexOf(b, i + 1);
588
- }
589
-
590
- i = ai < bi && ai >= 0 ? ai : bi;
591
- }
592
-
593
- if (begs.length) {
594
- result = [left, right];
595
- }
596
- }
597
-
598
- return result;
599
- }
600
-
601
- return balancedMatch;
602
- }
603
-
604
- var braceExpansion;
605
- var hasRequiredBraceExpansion;
606
-
607
- function requireBraceExpansion() {
608
- if (hasRequiredBraceExpansion) return braceExpansion;
609
- hasRequiredBraceExpansion = 1;
610
- var concatMap = requireConcatMap();
611
- var balanced = requireBalancedMatch();
612
- braceExpansion = expandTop;
613
- var escSlash = '\0SLASH' + Math.random() + '\0';
614
- var escOpen = '\0OPEN' + Math.random() + '\0';
615
- var escClose = '\0CLOSE' + Math.random() + '\0';
616
- var escComma = '\0COMMA' + Math.random() + '\0';
617
- var escPeriod = '\0PERIOD' + Math.random() + '\0';
618
-
619
- function numeric(str) {
620
- return parseInt(str, 10) == str ? parseInt(str, 10) : str.charCodeAt(0);
621
- }
622
-
623
- function escapeBraces(str) {
624
- return str.split('\\\\').join(escSlash).split('\\{').join(escOpen).split('\\}').join(escClose).split('\\,').join(escComma).split('\\.').join(escPeriod);
625
- }
626
-
627
- function unescapeBraces(str) {
628
- return str.split(escSlash).join('\\').split(escOpen).join('{').split(escClose).join('}').split(escComma).join(',').split(escPeriod).join('.');
629
- } // Basically just str.split(","), but handling cases
630
- // where we have nested braced sections, which should be
631
- // treated as individual members, like {a,{b,c},d}
632
-
633
-
634
- function parseCommaParts(str) {
635
- if (!str) return [''];
636
- var parts = [];
637
- var m = balanced('{', '}', str);
638
- if (!m) return str.split(',');
639
- var pre = m.pre;
640
- var body = m.body;
641
- var post = m.post;
642
- var p = pre.split(',');
643
- p[p.length - 1] += '{' + body + '}';
644
- var postParts = parseCommaParts(post);
645
-
646
- if (post.length) {
647
- p[p.length - 1] += postParts.shift();
648
- p.push.apply(p, postParts);
649
- }
650
-
651
- parts.push.apply(parts, p);
652
- return parts;
653
- }
654
-
655
- function expandTop(str) {
656
- if (!str) return []; // I don't know why Bash 4.3 does this, but it does.
657
- // Anything starting with {} will have the first two bytes preserved
658
- // but *only* at the top level, so {},a}b will not expand to anything,
659
- // but a{},b}c will be expanded to [a}c,abc].
660
- // One could argue that this is a bug in Bash, but since the goal of
661
- // this module is to match Bash's rules, we escape a leading {}
662
-
663
- if (str.substr(0, 2) === '{}') {
664
- str = '\\{\\}' + str.substr(2);
665
- }
666
-
667
- return expand(escapeBraces(str), true).map(unescapeBraces);
668
- }
669
-
670
- function embrace(str) {
671
- return '{' + str + '}';
672
- }
673
-
674
- function isPadded(el) {
675
- return /^-?0\d/.test(el);
676
- }
677
-
678
- function lte(i, y) {
679
- return i <= y;
680
- }
681
-
682
- function gte(i, y) {
683
- return i >= y;
684
- }
685
-
686
- function expand(str, isTop) {
687
- var expansions = [];
688
- var m = balanced('{', '}', str);
689
- if (!m || /\$$/.test(m.pre)) return [str];
690
- var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
691
- var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
692
- var isSequence = isNumericSequence || isAlphaSequence;
693
- var isOptions = m.body.indexOf(',') >= 0;
694
-
695
- if (!isSequence && !isOptions) {
696
- // {a},b}
697
- if (m.post.match(/,.*\}/)) {
698
- str = m.pre + '{' + m.body + escClose + m.post;
699
- return expand(str);
700
- }
701
-
702
- return [str];
703
- }
704
-
705
- var n;
706
-
707
- if (isSequence) {
708
- n = m.body.split(/\.\./);
709
- } else {
710
- n = parseCommaParts(m.body);
711
-
712
- if (n.length === 1) {
713
- // x{{a,b}}y ==> x{a}y x{b}y
714
- n = expand(n[0], false).map(embrace);
715
-
716
- if (n.length === 1) {
717
- var post = m.post.length ? expand(m.post, false) : [''];
718
- return post.map(function (p) {
719
- return m.pre + n[0] + p;
720
- });
721
- }
722
- }
723
- } // at this point, n is the parts, and we know it's not a comma set
724
- // with a single entry.
725
- // no need to expand pre, since it is guaranteed to be free of brace-sets
726
-
727
-
728
- var pre = m.pre;
729
- var post = m.post.length ? expand(m.post, false) : [''];
730
- var N;
731
-
732
- if (isSequence) {
733
- var x = numeric(n[0]);
734
- var y = numeric(n[1]);
735
- var width = Math.max(n[0].length, n[1].length);
736
- var incr = n.length == 3 ? Math.abs(numeric(n[2])) : 1;
737
- var test = lte;
738
- var reverse = y < x;
739
-
740
- if (reverse) {
741
- incr *= -1;
742
- test = gte;
743
- }
744
-
745
- var pad = n.some(isPadded);
746
- N = [];
747
-
748
- for (var i = x; test(i, y); i += incr) {
749
- var c;
750
-
751
- if (isAlphaSequence) {
752
- c = String.fromCharCode(i);
753
- if (c === '\\') c = '';
754
- } else {
755
- c = String(i);
756
-
757
- if (pad) {
758
- var need = width - c.length;
759
-
760
- if (need > 0) {
761
- var z = new Array(need + 1).join('0');
762
- if (i < 0) c = '-' + z + c.slice(1);else c = z + c;
763
- }
764
- }
765
- }
766
-
767
- N.push(c);
768
- }
769
- } else {
770
- N = concatMap(n, function (el) {
771
- return expand(el, false);
772
- });
773
- }
774
-
775
- for (var j = 0; j < N.length; j++) {
776
- for (var k = 0; k < post.length; k++) {
777
- var expansion = pre + N[j] + post[k];
778
- if (!isTop || isSequence || expansion) expansions.push(expansion);
779
- }
780
- }
781
-
782
- return expansions;
783
- }
784
-
785
- return braceExpansion;
786
- }
787
-
788
- var minimatch_1;
789
- var hasRequiredMinimatch;
790
-
791
- function requireMinimatch() {
792
- if (hasRequiredMinimatch) return minimatch_1;
793
- hasRequiredMinimatch = 1;
794
- minimatch_1 = minimatch;
795
- minimatch.Minimatch = Minimatch;
796
-
797
- var path = function () {
798
- try {
799
- return require('path');
800
- } catch (e) {}
801
- }() || {
802
- sep: '/'
803
- };
804
-
805
- minimatch.sep = path.sep;
806
- var GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {};
807
- var expand = requireBraceExpansion();
808
- var plTypes = {
809
- '!': {
810
- open: '(?:(?!(?:',
811
- close: '))[^/]*?)'
812
- },
813
- '?': {
814
- open: '(?:',
815
- close: ')?'
816
- },
817
- '+': {
818
- open: '(?:',
819
- close: ')+'
820
- },
821
- '*': {
822
- open: '(?:',
823
- close: ')*'
824
- },
825
- '@': {
826
- open: '(?:',
827
- close: ')'
828
- }
829
- }; // any single thing other than /
830
- // don't need to escape / when using new RegExp()
831
-
832
- var qmark = '[^/]'; // * => any number of characters
833
-
834
- var star = qmark + '*?'; // ** when dots are allowed. Anything goes, except .. and .
835
- // not (^ or / followed by one or two dots followed by $ or /),
836
- // followed by anything, any number of times.
837
-
838
- var twoStarDot = '(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?'; // not a ^ or / followed by a dot,
839
- // followed by anything, any number of times.
840
-
841
- var twoStarNoDot = '(?:(?!(?:\\\/|^)\\.).)*?'; // characters that need to be escaped in RegExp.
842
-
843
- var reSpecials = charSet('().*{}+?[]^$\\!'); // "abc" -> { a:true, b:true, c:true }
844
-
845
- function charSet(s) {
846
- return s.split('').reduce(function (set, c) {
847
- set[c] = true;
848
- return set;
849
- }, {});
850
- } // normalizes slashes.
851
-
852
-
853
- var slashSplit = /\/+/;
854
- minimatch.filter = filter;
855
-
856
- function filter(pattern, options) {
857
- options = options || {};
858
- return function (p, i, list) {
859
- return minimatch(p, pattern, options);
860
- };
861
- }
862
-
863
- function ext(a, b) {
864
- b = b || {};
865
- var t = {};
866
- Object.keys(a).forEach(function (k) {
867
- t[k] = a[k];
868
- });
869
- Object.keys(b).forEach(function (k) {
870
- t[k] = b[k];
871
- });
872
- return t;
873
- }
874
-
875
- minimatch.defaults = function (def) {
876
- if (!def || typeof def !== 'object' || !Object.keys(def).length) {
877
- return minimatch;
878
- }
879
-
880
- var orig = minimatch;
881
-
882
- var m = function minimatch(p, pattern, options) {
883
- return orig(p, pattern, ext(def, options));
884
- };
885
-
886
- m.Minimatch = function Minimatch(pattern, options) {
887
- return new orig.Minimatch(pattern, ext(def, options));
888
- };
889
-
890
- m.Minimatch.defaults = function defaults(options) {
891
- return orig.defaults(ext(def, options)).Minimatch;
892
- };
893
-
894
- m.filter = function filter(pattern, options) {
895
- return orig.filter(pattern, ext(def, options));
896
- };
897
-
898
- m.defaults = function defaults(options) {
899
- return orig.defaults(ext(def, options));
900
- };
901
-
902
- m.makeRe = function makeRe(pattern, options) {
903
- return orig.makeRe(pattern, ext(def, options));
904
- };
905
-
906
- m.braceExpand = function braceExpand(pattern, options) {
907
- return orig.braceExpand(pattern, ext(def, options));
908
- };
909
-
910
- m.match = function (list, pattern, options) {
911
- return orig.match(list, pattern, ext(def, options));
912
- };
913
-
914
- return m;
915
- };
916
-
917
- Minimatch.defaults = function (def) {
918
- return minimatch.defaults(def).Minimatch;
919
- };
920
-
921
- function minimatch(p, pattern, options) {
922
- assertValidPattern(pattern);
923
- if (!options) options = {}; // shortcut: comments match nothing.
924
-
925
- if (!options.nocomment && pattern.charAt(0) === '#') {
926
- return false;
927
- }
928
-
929
- return new Minimatch(pattern, options).match(p);
930
- }
931
-
932
- function Minimatch(pattern, options) {
933
- if (!(this instanceof Minimatch)) {
934
- return new Minimatch(pattern, options);
935
- }
936
-
937
- assertValidPattern(pattern);
938
- if (!options) options = {};
939
- pattern = pattern.trim(); // windows support: need to use /, not \
940
-
941
- if (!options.allowWindowsEscape && path.sep !== '/') {
942
- pattern = pattern.split(path.sep).join('/');
943
- }
944
-
945
- this.options = options;
946
- this.set = [];
947
- this.pattern = pattern;
948
- this.regexp = null;
949
- this.negate = false;
950
- this.comment = false;
951
- this.empty = false;
952
- this.partial = !!options.partial; // make the set of regexps etc.
953
-
954
- this.make();
955
- }
956
-
957
- Minimatch.prototype.debug = function () {};
958
-
959
- Minimatch.prototype.make = make;
960
-
961
- function make() {
962
- var pattern = this.pattern;
963
- var options = this.options; // empty patterns and comments match nothing.
964
-
965
- if (!options.nocomment && pattern.charAt(0) === '#') {
966
- this.comment = true;
967
- return;
968
- }
969
-
970
- if (!pattern) {
971
- this.empty = true;
972
- return;
973
- } // step 1: figure out negation, etc.
974
-
975
-
976
- this.parseNegate(); // step 2: expand braces
977
-
978
- var set = this.globSet = this.braceExpand();
979
- if (options.debug) this.debug = function debug() {
980
- console.error.apply(console, arguments);
981
- };
982
- this.debug(this.pattern, set); // step 3: now we have a set, so turn each one into a series of path-portion
983
- // matching patterns.
984
- // These will be regexps, except in the case of "**", which is
985
- // set to the GLOBSTAR object for globstar behavior,
986
- // and will not contain any / characters
987
-
988
- set = this.globParts = set.map(function (s) {
989
- return s.split(slashSplit);
990
- });
991
- this.debug(this.pattern, set); // glob --> regexps
992
-
993
- set = set.map(function (s, si, set) {
994
- return s.map(this.parse, this);
995
- }, this);
996
- this.debug(this.pattern, set); // filter out everything that didn't compile properly.
997
-
998
- set = set.filter(function (s) {
999
- return s.indexOf(false) === -1;
1000
- });
1001
- this.debug(this.pattern, set);
1002
- this.set = set;
1003
- }
1004
-
1005
- Minimatch.prototype.parseNegate = parseNegate;
1006
-
1007
- function parseNegate() {
1008
- var pattern = this.pattern;
1009
- var negate = false;
1010
- var options = this.options;
1011
- var negateOffset = 0;
1012
- if (options.nonegate) return;
1013
-
1014
- for (var i = 0, l = pattern.length; i < l && pattern.charAt(i) === '!'; i++) {
1015
- negate = !negate;
1016
- negateOffset++;
1017
- }
1018
-
1019
- if (negateOffset) this.pattern = pattern.substr(negateOffset);
1020
- this.negate = negate;
1021
- } // Brace expansion:
1022
- // a{b,c}d -> abd acd
1023
- // a{b,}c -> abc ac
1024
- // a{0..3}d -> a0d a1d a2d a3d
1025
- // a{b,c{d,e}f}g -> abg acdfg acefg
1026
- // a{b,c}d{e,f}g -> abdeg acdeg abdeg abdfg
1027
- //
1028
- // Invalid sets are not expanded.
1029
- // a{2..}b -> a{2..}b
1030
- // a{b}c -> a{b}c
1031
-
1032
-
1033
- minimatch.braceExpand = function (pattern, options) {
1034
- return braceExpand(pattern, options);
1035
- };
1036
-
1037
- Minimatch.prototype.braceExpand = braceExpand;
1038
-
1039
- function braceExpand(pattern, options) {
1040
- if (!options) {
1041
- if (this instanceof Minimatch) {
1042
- options = this.options;
1043
- } else {
1044
- options = {};
1045
- }
1046
- }
1047
-
1048
- pattern = typeof pattern === 'undefined' ? this.pattern : pattern;
1049
- assertValidPattern(pattern); // Thanks to Yeting Li <https://github.com/yetingli> for
1050
- // improving this regexp to avoid a ReDOS vulnerability.
1051
-
1052
- if (options.nobrace || !/\{(?:(?!\{).)*\}/.test(pattern)) {
1053
- // shortcut. no need to expand.
1054
- return [pattern];
1055
- }
1056
-
1057
- return expand(pattern);
1058
- }
1059
-
1060
- var MAX_PATTERN_LENGTH = 1024 * 64;
1061
-
1062
- var assertValidPattern = function (pattern) {
1063
- if (typeof pattern !== 'string') {
1064
- throw new TypeError('invalid pattern');
1065
- }
1066
-
1067
- if (pattern.length > MAX_PATTERN_LENGTH) {
1068
- throw new TypeError('pattern is too long');
1069
- }
1070
- }; // parse a component of the expanded set.
1071
- // At this point, no pattern may contain "/" in it
1072
- // so we're going to return a 2d array, where each entry is the full
1073
- // pattern, split on '/', and then turned into a regular expression.
1074
- // A regexp is made at the end which joins each array with an
1075
- // escaped /, and another full one which joins each regexp with |.
1076
- //
1077
- // Following the lead of Bash 4.1, note that "**" only has special meaning
1078
- // when it is the *only* thing in a path portion. Otherwise, any series
1079
- // of * is equivalent to a single *. Globstar behavior is enabled by
1080
- // default, and can be disabled by setting options.noglobstar.
1081
-
1082
-
1083
- Minimatch.prototype.parse = parse;
1084
- var SUBPARSE = {};
1085
-
1086
- function parse(pattern, isSub) {
1087
- assertValidPattern(pattern);
1088
- var options = this.options; // shortcuts
1089
-
1090
- if (pattern === '**') {
1091
- if (!options.noglobstar) return GLOBSTAR;else pattern = '*';
1092
- }
1093
-
1094
- if (pattern === '') return '';
1095
- var re = '';
1096
- var hasMagic = !!options.nocase;
1097
- var escaping = false; // ? => one single character
1098
-
1099
- var patternListStack = [];
1100
- var negativeLists = [];
1101
- var stateChar;
1102
- var inClass = false;
1103
- var reClassStart = -1;
1104
- var classStart = -1; // . and .. never match anything that doesn't start with .,
1105
- // even when options.dot is set.
1106
-
1107
- var patternStart = pattern.charAt(0) === '.' ? '' // anything
1108
- // not (start or / followed by . or .. followed by / or end)
1109
- : options.dot ? '(?!(?:^|\\\/)\\.{1,2}(?:$|\\\/))' : '(?!\\.)';
1110
- var self = this;
1111
-
1112
- function clearStateChar() {
1113
- if (stateChar) {
1114
- // we had some state-tracking character
1115
- // that wasn't consumed by this pass.
1116
- switch (stateChar) {
1117
- case '*':
1118
- re += star;
1119
- hasMagic = true;
1120
- break;
1121
-
1122
- case '?':
1123
- re += qmark;
1124
- hasMagic = true;
1125
- break;
1126
-
1127
- default:
1128
- re += '\\' + stateChar;
1129
- break;
1130
- }
1131
-
1132
- self.debug('clearStateChar %j %j', stateChar, re);
1133
- stateChar = false;
1134
- }
1135
- }
1136
-
1137
- for (var i = 0, len = pattern.length, c; i < len && (c = pattern.charAt(i)); i++) {
1138
- this.debug('%s\t%s %s %j', pattern, i, re, c); // skip over any that are escaped.
1139
-
1140
- if (escaping && reSpecials[c]) {
1141
- re += '\\' + c;
1142
- escaping = false;
1143
- continue;
1144
- }
1145
-
1146
- switch (c) {
1147
- /* istanbul ignore next */
1148
- case '/':
1149
- {
1150
- // completely not allowed, even escaped.
1151
- // Should already be path-split by now.
1152
- return false;
1153
- }
1154
-
1155
- case '\\':
1156
- clearStateChar();
1157
- escaping = true;
1158
- continue;
1159
- // the various stateChar values
1160
- // for the "extglob" stuff.
1161
-
1162
- case '?':
1163
- case '*':
1164
- case '+':
1165
- case '@':
1166
- case '!':
1167
- this.debug('%s\t%s %s %j <-- stateChar', pattern, i, re, c); // all of those are literals inside a class, except that
1168
- // the glob [!a] means [^a] in regexp
1169
-
1170
- if (inClass) {
1171
- this.debug(' in class');
1172
- if (c === '!' && i === classStart + 1) c = '^';
1173
- re += c;
1174
- continue;
1175
- } // if we already have a stateChar, then it means
1176
- // that there was something like ** or +? in there.
1177
- // Handle the stateChar, then proceed with this one.
1178
-
1179
-
1180
- self.debug('call clearStateChar %j', stateChar);
1181
- clearStateChar();
1182
- stateChar = c; // if extglob is disabled, then +(asdf|foo) isn't a thing.
1183
- // just clear the statechar *now*, rather than even diving into
1184
- // the patternList stuff.
1185
-
1186
- if (options.noext) clearStateChar();
1187
- continue;
1188
-
1189
- case '(':
1190
- if (inClass) {
1191
- re += '(';
1192
- continue;
1193
- }
1194
-
1195
- if (!stateChar) {
1196
- re += '\\(';
1197
- continue;
1198
- }
1199
-
1200
- patternListStack.push({
1201
- type: stateChar,
1202
- start: i - 1,
1203
- reStart: re.length,
1204
- open: plTypes[stateChar].open,
1205
- close: plTypes[stateChar].close
1206
- }); // negation is (?:(?!js)[^/]*)
1207
-
1208
- re += stateChar === '!' ? '(?:(?!(?:' : '(?:';
1209
- this.debug('plType %j %j', stateChar, re);
1210
- stateChar = false;
1211
- continue;
1212
-
1213
- case ')':
1214
- if (inClass || !patternListStack.length) {
1215
- re += '\\)';
1216
- continue;
1217
- }
1218
-
1219
- clearStateChar();
1220
- hasMagic = true;
1221
- var pl = patternListStack.pop(); // negation is (?:(?!js)[^/]*)
1222
- // The others are (?:<pattern>)<type>
1223
-
1224
- re += pl.close;
1225
-
1226
- if (pl.type === '!') {
1227
- negativeLists.push(pl);
1228
- }
1229
-
1230
- pl.reEnd = re.length;
1231
- continue;
1232
-
1233
- case '|':
1234
- if (inClass || !patternListStack.length || escaping) {
1235
- re += '\\|';
1236
- escaping = false;
1237
- continue;
1238
- }
1239
-
1240
- clearStateChar();
1241
- re += '|';
1242
- continue;
1243
- // these are mostly the same in regexp and glob
1244
-
1245
- case '[':
1246
- // swallow any state-tracking char before the [
1247
- clearStateChar();
1248
-
1249
- if (inClass) {
1250
- re += '\\' + c;
1251
- continue;
1252
- }
1253
-
1254
- inClass = true;
1255
- classStart = i;
1256
- reClassStart = re.length;
1257
- re += c;
1258
- continue;
1259
-
1260
- case ']':
1261
- // a right bracket shall lose its special
1262
- // meaning and represent itself in
1263
- // a bracket expression if it occurs
1264
- // first in the list. -- POSIX.2 2.8.3.2
1265
- if (i === classStart + 1 || !inClass) {
1266
- re += '\\' + c;
1267
- escaping = false;
1268
- continue;
1269
- } // handle the case where we left a class open.
1270
- // "[z-a]" is valid, equivalent to "\[z-a\]"
1271
- // split where the last [ was, make sure we don't have
1272
- // an invalid re. if so, re-walk the contents of the
1273
- // would-be class to re-translate any characters that
1274
- // were passed through as-is
1275
- // TODO: It would probably be faster to determine this
1276
- // without a try/catch and a new RegExp, but it's tricky
1277
- // to do safely. For now, this is safe and works.
1278
-
1279
-
1280
- var cs = pattern.substring(classStart + 1, i);
1281
-
1282
- try {
1283
- RegExp('[' + cs + ']');
1284
- } catch (er) {
1285
- // not a valid class!
1286
- var sp = this.parse(cs, SUBPARSE);
1287
- re = re.substr(0, reClassStart) + '\\[' + sp[0] + '\\]';
1288
- hasMagic = hasMagic || sp[1];
1289
- inClass = false;
1290
- continue;
1291
- } // finish up the class.
1292
-
1293
-
1294
- hasMagic = true;
1295
- inClass = false;
1296
- re += c;
1297
- continue;
1298
-
1299
- default:
1300
- // swallow any state char that wasn't consumed
1301
- clearStateChar();
1302
-
1303
- if (escaping) {
1304
- // no need
1305
- escaping = false;
1306
- } else if (reSpecials[c] && !(c === '^' && inClass)) {
1307
- re += '\\';
1308
- }
1309
-
1310
- re += c;
1311
- } // switch
1312
-
1313
- } // for
1314
- // handle the case where we left a class open.
1315
- // "[abc" is valid, equivalent to "\[abc"
1316
-
1317
-
1318
- if (inClass) {
1319
- // split where the last [ was, and escape it
1320
- // this is a huge pita. We now have to re-walk
1321
- // the contents of the would-be class to re-translate
1322
- // any characters that were passed through as-is
1323
- cs = pattern.substr(classStart + 1);
1324
- sp = this.parse(cs, SUBPARSE);
1325
- re = re.substr(0, reClassStart) + '\\[' + sp[0];
1326
- hasMagic = hasMagic || sp[1];
1327
- } // handle the case where we had a +( thing at the *end*
1328
- // of the pattern.
1329
- // each pattern list stack adds 3 chars, and we need to go through
1330
- // and escape any | chars that were passed through as-is for the regexp.
1331
- // Go through and escape them, taking care not to double-escape any
1332
- // | chars that were already escaped.
1333
-
1334
-
1335
- for (pl = patternListStack.pop(); pl; pl = patternListStack.pop()) {
1336
- var tail = re.slice(pl.reStart + pl.open.length);
1337
- this.debug('setting tail', re, pl); // maybe some even number of \, then maybe 1 \, followed by a |
1338
-
1339
- tail = tail.replace(/((?:\\{2}){0,64})(\\?)\|/g, function (_, $1, $2) {
1340
- if (!$2) {
1341
- // the | isn't already escaped, so escape it.
1342
- $2 = '\\';
1343
- } // need to escape all those slashes *again*, without escaping the
1344
- // one that we need for escaping the | character. As it works out,
1345
- // escaping an even number of slashes can be done by simply repeating
1346
- // it exactly after itself. That's why this trick works.
1347
- //
1348
- // I am sorry that you have to see this.
1349
-
1350
-
1351
- return $1 + $1 + $2 + '|';
1352
- });
1353
- this.debug('tail=%j\n %s', tail, tail, pl, re);
1354
- var t = pl.type === '*' ? star : pl.type === '?' ? qmark : '\\' + pl.type;
1355
- hasMagic = true;
1356
- re = re.slice(0, pl.reStart) + t + '\\(' + tail;
1357
- } // handle trailing things that only matter at the very end.
1358
-
1359
-
1360
- clearStateChar();
1361
-
1362
- if (escaping) {
1363
- // trailing \\
1364
- re += '\\\\';
1365
- } // only need to apply the nodot start if the re starts with
1366
- // something that could conceivably capture a dot
1367
-
1368
-
1369
- var addPatternStart = false;
1370
-
1371
- switch (re.charAt(0)) {
1372
- case '[':
1373
- case '.':
1374
- case '(':
1375
- addPatternStart = true;
1376
- } // Hack to work around lack of negative lookbehind in JS
1377
- // A pattern like: *.!(x).!(y|z) needs to ensure that a name
1378
- // like 'a.xyz.yz' doesn't match. So, the first negative
1379
- // lookahead, has to look ALL the way ahead, to the end of
1380
- // the pattern.
1381
-
1382
-
1383
- for (var n = negativeLists.length - 1; n > -1; n--) {
1384
- var nl = negativeLists[n];
1385
- var nlBefore = re.slice(0, nl.reStart);
1386
- var nlFirst = re.slice(nl.reStart, nl.reEnd - 8);
1387
- var nlLast = re.slice(nl.reEnd - 8, nl.reEnd);
1388
- var nlAfter = re.slice(nl.reEnd);
1389
- nlLast += nlAfter; // Handle nested stuff like *(*.js|!(*.json)), where open parens
1390
- // mean that we should *not* include the ) in the bit that is considered
1391
- // "after" the negated section.
1392
-
1393
- var openParensBefore = nlBefore.split('(').length - 1;
1394
- var cleanAfter = nlAfter;
1395
-
1396
- for (i = 0; i < openParensBefore; i++) {
1397
- cleanAfter = cleanAfter.replace(/\)[+*?]?/, '');
1398
- }
1399
-
1400
- nlAfter = cleanAfter;
1401
- var dollar = '';
1402
-
1403
- if (nlAfter === '' && isSub !== SUBPARSE) {
1404
- dollar = '$';
1405
- }
1406
-
1407
- var newRe = nlBefore + nlFirst + nlAfter + dollar + nlLast;
1408
- re = newRe;
1409
- } // if the re is not "" at this point, then we need to make sure
1410
- // it doesn't match against an empty path part.
1411
- // Otherwise a/* will match a/, which it should not.
1412
-
1413
-
1414
- if (re !== '' && hasMagic) {
1415
- re = '(?=.)' + re;
1416
- }
1417
-
1418
- if (addPatternStart) {
1419
- re = patternStart + re;
1420
- } // parsing just a piece of a larger pattern.
1421
-
1422
-
1423
- if (isSub === SUBPARSE) {
1424
- return [re, hasMagic];
1425
- } // skip the regexp for non-magical patterns
1426
- // unescape anything in it, though, so that it'll be
1427
- // an exact match against a file etc.
1428
-
1429
-
1430
- if (!hasMagic) {
1431
- return globUnescape(pattern);
1432
- }
1433
-
1434
- var flags = options.nocase ? 'i' : '';
1435
-
1436
- try {
1437
- var regExp = new RegExp('^' + re + '$', flags);
1438
- } catch (er)
1439
- /* istanbul ignore next - should be impossible */
1440
- {
1441
- // If it was an invalid regular expression, then it can't match
1442
- // anything. This trick looks for a character after the end of
1443
- // the string, which is of course impossible, except in multi-line
1444
- // mode, but it's not a /m regex.
1445
- return new RegExp('$.');
1446
- }
1447
-
1448
- regExp._glob = pattern;
1449
- regExp._src = re;
1450
- return regExp;
1451
- }
1452
-
1453
- minimatch.makeRe = function (pattern, options) {
1454
- return new Minimatch(pattern, options || {}).makeRe();
1455
- };
1456
-
1457
- Minimatch.prototype.makeRe = makeRe;
1458
-
1459
- function makeRe() {
1460
- if (this.regexp || this.regexp === false) return this.regexp; // at this point, this.set is a 2d array of partial
1461
- // pattern strings, or "**".
1462
- //
1463
- // It's better to use .match(). This function shouldn't
1464
- // be used, really, but it's pretty convenient sometimes,
1465
- // when you just want to work with a regex.
1466
-
1467
- var set = this.set;
1468
-
1469
- if (!set.length) {
1470
- this.regexp = false;
1471
- return this.regexp;
1472
- }
1473
-
1474
- var options = this.options;
1475
- var twoStar = options.noglobstar ? star : options.dot ? twoStarDot : twoStarNoDot;
1476
- var flags = options.nocase ? 'i' : '';
1477
- var re = set.map(function (pattern) {
1478
- return pattern.map(function (p) {
1479
- return p === GLOBSTAR ? twoStar : typeof p === 'string' ? regExpEscape(p) : p._src;
1480
- }).join('\\\/');
1481
- }).join('|'); // must match entire pattern
1482
- // ending in a * or ** will make it less strict.
1483
-
1484
- re = '^(?:' + re + ')$'; // can match anything, as long as it's not this.
1485
-
1486
- if (this.negate) re = '^(?!' + re + ').*$';
1487
-
1488
- try {
1489
- this.regexp = new RegExp(re, flags);
1490
- } catch (ex)
1491
- /* istanbul ignore next - should be impossible */
1492
- {
1493
- this.regexp = false;
1494
- }
1495
-
1496
- return this.regexp;
1497
- }
1498
-
1499
- minimatch.match = function (list, pattern, options) {
1500
- options = options || {};
1501
- var mm = new Minimatch(pattern, options);
1502
- list = list.filter(function (f) {
1503
- return mm.match(f);
1504
- });
1505
-
1506
- if (mm.options.nonull && !list.length) {
1507
- list.push(pattern);
1508
- }
1509
-
1510
- return list;
1511
- };
1512
-
1513
- Minimatch.prototype.match = function match(f, partial) {
1514
- if (typeof partial === 'undefined') partial = this.partial;
1515
- this.debug('match', f, this.pattern); // short-circuit in the case of busted things.
1516
- // comments, etc.
1517
-
1518
- if (this.comment) return false;
1519
- if (this.empty) return f === '';
1520
- if (f === '/' && partial) return true;
1521
- var options = this.options; // windows: need to use /, not \
1522
-
1523
- if (path.sep !== '/') {
1524
- f = f.split(path.sep).join('/');
1525
- } // treat the test path as a set of pathparts.
1526
-
1527
-
1528
- f = f.split(slashSplit);
1529
- this.debug(this.pattern, 'split', f); // just ONE of the pattern sets in this.set needs to match
1530
- // in order for it to be valid. If negating, then just one
1531
- // match means that we have failed.
1532
- // Either way, return on the first hit.
1533
-
1534
- var set = this.set;
1535
- this.debug(this.pattern, 'set', set); // Find the basename of the path by looking for the last non-empty segment
1536
-
1537
- var filename;
1538
- var i;
1539
-
1540
- for (i = f.length - 1; i >= 0; i--) {
1541
- filename = f[i];
1542
- if (filename) break;
1543
- }
1544
-
1545
- for (i = 0; i < set.length; i++) {
1546
- var pattern = set[i];
1547
- var file = f;
1548
-
1549
- if (options.matchBase && pattern.length === 1) {
1550
- file = [filename];
1551
- }
1552
-
1553
- var hit = this.matchOne(file, pattern, partial);
1554
-
1555
- if (hit) {
1556
- if (options.flipNegate) return true;
1557
- return !this.negate;
1558
- }
1559
- } // didn't get any hits. this is success if it's a negative
1560
- // pattern, failure otherwise.
1561
-
1562
-
1563
- if (options.flipNegate) return false;
1564
- return this.negate;
1565
- }; // set partial to true to test if, for example,
1566
- // "/a/b" matches the start of "/*/b/*/d"
1567
- // Partial means, if you run out of file before you run
1568
- // out of pattern, then that's fine, as long as all
1569
- // the parts match.
1570
-
1571
-
1572
- Minimatch.prototype.matchOne = function (file, pattern, partial) {
1573
- var options = this.options;
1574
- this.debug('matchOne', {
1575
- 'this': this,
1576
- file: file,
1577
- pattern: pattern
1578
- });
1579
- this.debug('matchOne', file.length, pattern.length);
1580
-
1581
- for (var fi = 0, pi = 0, fl = file.length, pl = pattern.length; fi < fl && pi < pl; fi++, pi++) {
1582
- this.debug('matchOne loop');
1583
- var p = pattern[pi];
1584
- var f = file[fi];
1585
- this.debug(pattern, p, f); // should be impossible.
1586
- // some invalid regexp stuff in the set.
1587
-
1588
- /* istanbul ignore if */
1589
-
1590
- if (p === false) return false;
1591
-
1592
- if (p === GLOBSTAR) {
1593
- this.debug('GLOBSTAR', [pattern, p, f]); // "**"
1594
- // a/**/b/**/c would match the following:
1595
- // a/b/x/y/z/c
1596
- // a/x/y/z/b/c
1597
- // a/b/x/b/x/c
1598
- // a/b/c
1599
- // To do this, take the rest of the pattern after
1600
- // the **, and see if it would match the file remainder.
1601
- // If so, return success.
1602
- // If not, the ** "swallows" a segment, and try again.
1603
- // This is recursively awful.
1604
- //
1605
- // a/**/b/**/c matching a/b/x/y/z/c
1606
- // - a matches a
1607
- // - doublestar
1608
- // - matchOne(b/x/y/z/c, b/**/c)
1609
- // - b matches b
1610
- // - doublestar
1611
- // - matchOne(x/y/z/c, c) -> no
1612
- // - matchOne(y/z/c, c) -> no
1613
- // - matchOne(z/c, c) -> no
1614
- // - matchOne(c, c) yes, hit
1615
-
1616
- var fr = fi;
1617
- var pr = pi + 1;
1618
-
1619
- if (pr === pl) {
1620
- this.debug('** at the end'); // a ** at the end will just swallow the rest.
1621
- // We have found a match.
1622
- // however, it will not swallow /.x, unless
1623
- // options.dot is set.
1624
- // . and .. are *never* matched by **, for explosively
1625
- // exponential reasons.
1626
-
1627
- for (; fi < fl; fi++) {
1628
- if (file[fi] === '.' || file[fi] === '..' || !options.dot && file[fi].charAt(0) === '.') return false;
1629
- }
1630
-
1631
- return true;
1632
- } // ok, let's see if we can swallow whatever we can.
1633
-
1634
-
1635
- while (fr < fl) {
1636
- var swallowee = file[fr];
1637
- this.debug('\nglobstar while', file, fr, pattern, pr, swallowee); // XXX remove this slice. Just pass the start index.
1638
-
1639
- if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
1640
- this.debug('globstar found match!', fr, fl, swallowee); // found a match.
1641
-
1642
- return true;
1643
- } else {
1644
- // can't swallow "." or ".." ever.
1645
- // can only swallow ".foo" when explicitly asked.
1646
- if (swallowee === '.' || swallowee === '..' || !options.dot && swallowee.charAt(0) === '.') {
1647
- this.debug('dot detected!', file, fr, pattern, pr);
1648
- break;
1649
- } // ** swallows a segment, and continue.
1650
-
1651
-
1652
- this.debug('globstar swallow a segment, and continue');
1653
- fr++;
1654
- }
1655
- } // no match was found.
1656
- // However, in partial mode, we can't say this is necessarily over.
1657
- // If there's more *pattern* left, then
1658
-
1659
- /* istanbul ignore if */
1660
-
1661
-
1662
- if (partial) {
1663
- // ran out of file
1664
- this.debug('\n>>> no match, partial?', file, fr, pattern, pr);
1665
- if (fr === fl) return true;
1666
- }
1667
-
1668
- return false;
1669
- } // something other than **
1670
- // non-magic patterns just have to match exactly
1671
- // patterns with magic have been turned into regexps.
1672
-
1673
-
1674
- var hit;
1675
-
1676
- if (typeof p === 'string') {
1677
- hit = f === p;
1678
- this.debug('string match', p, f, hit);
1679
- } else {
1680
- hit = f.match(p);
1681
- this.debug('pattern match', p, f, hit);
1682
- }
1683
-
1684
- if (!hit) return false;
1685
- } // Note: ending in / means that we'll get a final ""
1686
- // at the end of the pattern. This can only match a
1687
- // corresponding "" at the end of the file.
1688
- // If the file ends in /, then it can only match a
1689
- // a pattern that ends in /, unless the pattern just
1690
- // doesn't have any more for it. But, a/b/ should *not*
1691
- // match "a/b/*", even though "" matches against the
1692
- // [^/]*? pattern, except in partial mode, where it might
1693
- // simply not be reached yet.
1694
- // However, a/b/ should still satisfy a/*
1695
- // now either we fell off the end of the pattern, or we're done.
1696
-
1697
-
1698
- if (fi === fl && pi === pl) {
1699
- // ran out of pattern and filename at the same time.
1700
- // an exact hit!
1701
- return true;
1702
- } else if (fi === fl) {
1703
- // ran out of file, but still had pattern left.
1704
- // this is ok if we're doing the match as part of
1705
- // a glob fs traversal.
1706
- return partial;
1707
- } else
1708
- /* istanbul ignore else */
1709
- if (pi === pl) {
1710
- // ran out of pattern, still have file left.
1711
- // this is only acceptable if we're on the very last
1712
- // empty segment of a file with a trailing slash.
1713
- // a/* should match a/b/
1714
- return fi === fl - 1 && file[fi] === '';
1715
- } // should be unreachable.
1716
-
1717
- /* istanbul ignore next */
1718
-
1719
-
1720
- throw new Error('wtf?');
1721
- }; // replace stuff like \* with *
1722
-
1723
-
1724
- function globUnescape(s) {
1725
- return s.replace(/\\(.)/g, '$1');
1726
- }
1727
-
1728
- function regExpEscape(s) {
1729
- return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
1730
- }
1731
-
1732
- return minimatch_1;
1733
- }
1734
-
1735
- var inherits = {
1736
- exports: {}
1737
- };
1738
- var inherits_browser = {
1739
- exports: {}
1740
- };
1741
- var hasRequiredInherits_browser;
1742
-
1743
- function requireInherits_browser() {
1744
- if (hasRequiredInherits_browser) return inherits_browser.exports;
1745
- hasRequiredInherits_browser = 1;
1746
-
1747
- if (typeof Object.create === 'function') {
1748
- // implementation from standard node.js 'util' module
1749
- inherits_browser.exports = function inherits(ctor, superCtor) {
1750
- if (superCtor) {
1751
- ctor.super_ = superCtor;
1752
- ctor.prototype = Object.create(superCtor.prototype, {
1753
- constructor: {
1754
- value: ctor,
1755
- enumerable: false,
1756
- writable: true,
1757
- configurable: true
1758
- }
1759
- });
1760
- }
1761
- };
1762
- } else {
1763
- // old school shim for old browsers
1764
- inherits_browser.exports = function inherits(ctor, superCtor) {
1765
- if (superCtor) {
1766
- ctor.super_ = superCtor;
1767
-
1768
- var TempCtor = function () {};
1769
-
1770
- TempCtor.prototype = superCtor.prototype;
1771
- ctor.prototype = new TempCtor();
1772
- ctor.prototype.constructor = ctor;
1773
- }
1774
- };
1775
- }
1776
-
1777
- return inherits_browser.exports;
1778
- }
1779
-
1780
- var hasRequiredInherits;
1781
-
1782
- function requireInherits() {
1783
- if (hasRequiredInherits) return inherits.exports;
1784
- hasRequiredInherits = 1;
1785
-
1786
- (function (module) {
1787
- try {
1788
- var util = require('util');
1789
- /* istanbul ignore next */
1790
-
1791
-
1792
- if (typeof util.inherits !== 'function') throw '';
1793
- module.exports = util.inherits;
1794
- } catch (e) {
1795
- /* istanbul ignore next */
1796
- module.exports = requireInherits_browser();
1797
- }
1798
- })(inherits);
1799
-
1800
- return inherits.exports;
1801
- }
1802
-
1803
- var pathIsAbsolute = {
1804
- exports: {}
1805
- };
1806
- var hasRequiredPathIsAbsolute;
1807
-
1808
- function requirePathIsAbsolute() {
1809
- if (hasRequiredPathIsAbsolute) return pathIsAbsolute.exports;
1810
- hasRequiredPathIsAbsolute = 1;
1811
-
1812
- function posix(path) {
1813
- return path.charAt(0) === '/';
1814
- }
1815
-
1816
- function win32(path) {
1817
- // https://github.com/nodejs/node/blob/b3fcc245fb25539909ef1d5eaa01dbf92e168633/lib/path.js#L56
1818
- var splitDeviceRe = /^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?([\s\S]*?)$/;
1819
- var result = splitDeviceRe.exec(path);
1820
- var device = result[1] || '';
1821
- var isUnc = Boolean(device && device.charAt(1) !== ':'); // UNC paths are always absolute
1822
-
1823
- return Boolean(result[2] || isUnc);
1824
- }
1825
-
1826
- pathIsAbsolute.exports = process.platform === 'win32' ? win32 : posix;
1827
- pathIsAbsolute.exports.posix = posix;
1828
- pathIsAbsolute.exports.win32 = win32;
1829
- return pathIsAbsolute.exports;
1830
- }
1831
-
1832
- var common = {};
1833
- var hasRequiredCommon;
1834
-
1835
- function requireCommon() {
1836
- if (hasRequiredCommon) return common;
1837
- hasRequiredCommon = 1;
1838
- common.setopts = setopts;
1839
- common.ownProp = ownProp;
1840
- common.makeAbs = makeAbs;
1841
- common.finish = finish;
1842
- common.mark = mark;
1843
- common.isIgnored = isIgnored;
1844
- common.childrenIgnored = childrenIgnored;
1845
-
1846
- function ownProp(obj, field) {
1847
- return Object.prototype.hasOwnProperty.call(obj, field);
1848
- }
1849
-
1850
- var fs = fs__default["default"];
1851
- var path = path__default["default"];
1852
- var minimatch = requireMinimatch();
1853
- var isAbsolute = requirePathIsAbsolute();
1854
- var Minimatch = minimatch.Minimatch;
1855
-
1856
- function alphasort(a, b) {
1857
- return a.localeCompare(b, 'en');
1858
- }
1859
-
1860
- function setupIgnores(self, options) {
1861
- self.ignore = options.ignore || [];
1862
- if (!Array.isArray(self.ignore)) self.ignore = [self.ignore];
1863
-
1864
- if (self.ignore.length) {
1865
- self.ignore = self.ignore.map(ignoreMap);
1866
- }
1867
- } // ignore patterns are always in dot:true mode.
1868
-
1869
-
1870
- function ignoreMap(pattern) {
1871
- var gmatcher = null;
1872
-
1873
- if (pattern.slice(-3) === '/**') {
1874
- var gpattern = pattern.replace(/(\/\*\*)+$/, '');
1875
- gmatcher = new Minimatch(gpattern, {
1876
- dot: true
1877
- });
1878
- }
1879
-
1880
- return {
1881
- matcher: new Minimatch(pattern, {
1882
- dot: true
1883
- }),
1884
- gmatcher: gmatcher
1885
- };
1886
- }
1887
-
1888
- function setopts(self, pattern, options) {
1889
- if (!options) options = {}; // base-matching: just use globstar for that.
1890
-
1891
- if (options.matchBase && -1 === pattern.indexOf("/")) {
1892
- if (options.noglobstar) {
1893
- throw new Error("base matching requires globstar");
1894
- }
1895
-
1896
- pattern = "**/" + pattern;
1897
- }
1898
-
1899
- self.silent = !!options.silent;
1900
- self.pattern = pattern;
1901
- self.strict = options.strict !== false;
1902
- self.realpath = !!options.realpath;
1903
- self.realpathCache = options.realpathCache || Object.create(null);
1904
- self.follow = !!options.follow;
1905
- self.dot = !!options.dot;
1906
- self.mark = !!options.mark;
1907
- self.nodir = !!options.nodir;
1908
- if (self.nodir) self.mark = true;
1909
- self.sync = !!options.sync;
1910
- self.nounique = !!options.nounique;
1911
- self.nonull = !!options.nonull;
1912
- self.nosort = !!options.nosort;
1913
- self.nocase = !!options.nocase;
1914
- self.stat = !!options.stat;
1915
- self.noprocess = !!options.noprocess;
1916
- self.absolute = !!options.absolute;
1917
- self.fs = options.fs || fs;
1918
- self.maxLength = options.maxLength || Infinity;
1919
- self.cache = options.cache || Object.create(null);
1920
- self.statCache = options.statCache || Object.create(null);
1921
- self.symlinks = options.symlinks || Object.create(null);
1922
- setupIgnores(self, options);
1923
- self.changedCwd = false;
1924
- var cwd = process.cwd();
1925
- if (!ownProp(options, "cwd")) self.cwd = cwd;else {
1926
- self.cwd = path.resolve(options.cwd);
1927
- self.changedCwd = self.cwd !== cwd;
1928
- }
1929
- self.root = options.root || path.resolve(self.cwd, "/");
1930
- self.root = path.resolve(self.root);
1931
- if (process.platform === "win32") self.root = self.root.replace(/\\/g, "/"); // TODO: is an absolute `cwd` supposed to be resolved against `root`?
1932
- // e.g. { cwd: '/test', root: __dirname } === path.join(__dirname, '/test')
1933
-
1934
- self.cwdAbs = isAbsolute(self.cwd) ? self.cwd : makeAbs(self, self.cwd);
1935
- if (process.platform === "win32") self.cwdAbs = self.cwdAbs.replace(/\\/g, "/");
1936
- self.nomount = !!options.nomount; // disable comments and negation in Minimatch.
1937
- // Note that they are not supported in Glob itself anyway.
1938
-
1939
- options.nonegate = true;
1940
- options.nocomment = true; // always treat \ in patterns as escapes, not path separators
1941
-
1942
- options.allowWindowsEscape = false;
1943
- self.minimatch = new Minimatch(pattern, options);
1944
- self.options = self.minimatch.options;
1945
- }
1946
-
1947
- function finish(self) {
1948
- var nou = self.nounique;
1949
- var all = nou ? [] : Object.create(null);
1950
-
1951
- for (var i = 0, l = self.matches.length; i < l; i++) {
1952
- var matches = self.matches[i];
1953
-
1954
- if (!matches || Object.keys(matches).length === 0) {
1955
- if (self.nonull) {
1956
- // do like the shell, and spit out the literal glob
1957
- var literal = self.minimatch.globSet[i];
1958
- if (nou) all.push(literal);else all[literal] = true;
1959
- }
1960
- } else {
1961
- // had matches
1962
- var m = Object.keys(matches);
1963
- if (nou) all.push.apply(all, m);else m.forEach(function (m) {
1964
- all[m] = true;
1965
- });
1966
- }
1967
- }
1968
-
1969
- if (!nou) all = Object.keys(all);
1970
- if (!self.nosort) all = all.sort(alphasort); // at *some* point we statted all of these
1971
-
1972
- if (self.mark) {
1973
- for (var i = 0; i < all.length; i++) {
1974
- all[i] = self._mark(all[i]);
1975
- }
1976
-
1977
- if (self.nodir) {
1978
- all = all.filter(function (e) {
1979
- var notDir = !/\/$/.test(e);
1980
- var c = self.cache[e] || self.cache[makeAbs(self, e)];
1981
- if (notDir && c) notDir = c !== 'DIR' && !Array.isArray(c);
1982
- return notDir;
1983
- });
1984
- }
1985
- }
1986
-
1987
- if (self.ignore.length) all = all.filter(function (m) {
1988
- return !isIgnored(self, m);
1989
- });
1990
- self.found = all;
1991
- }
1992
-
1993
- function mark(self, p) {
1994
- var abs = makeAbs(self, p);
1995
- var c = self.cache[abs];
1996
- var m = p;
1997
-
1998
- if (c) {
1999
- var isDir = c === 'DIR' || Array.isArray(c);
2000
- var slash = p.slice(-1) === '/';
2001
- if (isDir && !slash) m += '/';else if (!isDir && slash) m = m.slice(0, -1);
2002
-
2003
- if (m !== p) {
2004
- var mabs = makeAbs(self, m);
2005
- self.statCache[mabs] = self.statCache[abs];
2006
- self.cache[mabs] = self.cache[abs];
2007
- }
2008
- }
2009
-
2010
- return m;
2011
- } // lotta situps...
2012
-
2013
-
2014
- function makeAbs(self, f) {
2015
- var abs = f;
2016
-
2017
- if (f.charAt(0) === '/') {
2018
- abs = path.join(self.root, f);
2019
- } else if (isAbsolute(f) || f === '') {
2020
- abs = f;
2021
- } else if (self.changedCwd) {
2022
- abs = path.resolve(self.cwd, f);
2023
- } else {
2024
- abs = path.resolve(f);
2025
- }
2026
-
2027
- if (process.platform === 'win32') abs = abs.replace(/\\/g, '/');
2028
- return abs;
2029
- } // Return true, if pattern ends with globstar '**', for the accompanying parent directory.
2030
- // Ex:- If node_modules/** is the pattern, add 'node_modules' to ignore list along with it's contents
2031
-
2032
-
2033
- function isIgnored(self, path) {
2034
- if (!self.ignore.length) return false;
2035
- return self.ignore.some(function (item) {
2036
- return item.matcher.match(path) || !!(item.gmatcher && item.gmatcher.match(path));
2037
- });
2038
- }
2039
-
2040
- function childrenIgnored(self, path) {
2041
- if (!self.ignore.length) return false;
2042
- return self.ignore.some(function (item) {
2043
- return !!(item.gmatcher && item.gmatcher.match(path));
2044
- });
2045
- }
2046
-
2047
- return common;
2048
- }
2049
-
2050
- var sync;
2051
- var hasRequiredSync;
2052
-
2053
- function requireSync() {
2054
- if (hasRequiredSync) return sync;
2055
- hasRequiredSync = 1;
2056
- sync = globSync;
2057
- globSync.GlobSync = GlobSync;
2058
- var rp = requireFs_realpath();
2059
- var minimatch = requireMinimatch();
2060
- requireGlob().Glob;
2061
- var path = path__default["default"];
2062
- var assert = require$$5__default["default"];
2063
- var isAbsolute = requirePathIsAbsolute();
2064
- var common = requireCommon();
2065
- var setopts = common.setopts;
2066
- var ownProp = common.ownProp;
2067
- var childrenIgnored = common.childrenIgnored;
2068
- var isIgnored = common.isIgnored;
2069
-
2070
- function globSync(pattern, options) {
2071
- if (typeof options === 'function' || arguments.length === 3) throw new TypeError('callback provided to sync glob\n' + 'See: https://github.com/isaacs/node-glob/issues/167');
2072
- return new GlobSync(pattern, options).found;
2073
- }
2074
-
2075
- function GlobSync(pattern, options) {
2076
- if (!pattern) throw new Error('must provide pattern');
2077
- if (typeof options === 'function' || arguments.length === 3) throw new TypeError('callback provided to sync glob\n' + 'See: https://github.com/isaacs/node-glob/issues/167');
2078
- if (!(this instanceof GlobSync)) return new GlobSync(pattern, options);
2079
- setopts(this, pattern, options);
2080
- if (this.noprocess) return this;
2081
- var n = this.minimatch.set.length;
2082
- this.matches = new Array(n);
2083
-
2084
- for (var i = 0; i < n; i++) {
2085
- this._process(this.minimatch.set[i], i, false);
2086
- }
2087
-
2088
- this._finish();
2089
- }
2090
-
2091
- GlobSync.prototype._finish = function () {
2092
- assert.ok(this instanceof GlobSync);
2093
-
2094
- if (this.realpath) {
2095
- var self = this;
2096
- this.matches.forEach(function (matchset, index) {
2097
- var set = self.matches[index] = Object.create(null);
2098
-
2099
- for (var p in matchset) {
2100
- try {
2101
- p = self._makeAbs(p);
2102
- var real = rp.realpathSync(p, self.realpathCache);
2103
- set[real] = true;
2104
- } catch (er) {
2105
- if (er.syscall === 'stat') set[self._makeAbs(p)] = true;else throw er;
2106
- }
2107
- }
2108
- });
2109
- }
2110
-
2111
- common.finish(this);
2112
- };
2113
-
2114
- GlobSync.prototype._process = function (pattern, index, inGlobStar) {
2115
- assert.ok(this instanceof GlobSync); // Get the first [n] parts of pattern that are all strings.
2116
-
2117
- var n = 0;
2118
-
2119
- while (typeof pattern[n] === 'string') {
2120
- n++;
2121
- } // now n is the index of the first one that is *not* a string.
2122
- // See if there's anything else
2123
-
2124
-
2125
- var prefix;
2126
-
2127
- switch (n) {
2128
- // if not, then this is rather simple
2129
- case pattern.length:
2130
- this._processSimple(pattern.join('/'), index);
2131
-
2132
- return;
2133
-
2134
- case 0:
2135
- // pattern *starts* with some non-trivial item.
2136
- // going to readdir(cwd), but not include the prefix in matches.
2137
- prefix = null;
2138
- break;
2139
-
2140
- default:
2141
- // pattern has some string bits in the front.
2142
- // whatever it starts with, whether that's 'absolute' like /foo/bar,
2143
- // or 'relative' like '../baz'
2144
- prefix = pattern.slice(0, n).join('/');
2145
- break;
2146
- }
2147
-
2148
- var remain = pattern.slice(n); // get the list of entries.
2149
-
2150
- var read;
2151
- if (prefix === null) read = '.';else if (isAbsolute(prefix) || isAbsolute(pattern.map(function (p) {
2152
- return typeof p === 'string' ? p : '[*]';
2153
- }).join('/'))) {
2154
- if (!prefix || !isAbsolute(prefix)) prefix = '/' + prefix;
2155
- read = prefix;
2156
- } else read = prefix;
2157
-
2158
- var abs = this._makeAbs(read); //if ignored, skip processing
2159
-
2160
-
2161
- if (childrenIgnored(this, read)) return;
2162
- var isGlobStar = remain[0] === minimatch.GLOBSTAR;
2163
- if (isGlobStar) this._processGlobStar(prefix, read, abs, remain, index, inGlobStar);else this._processReaddir(prefix, read, abs, remain, index, inGlobStar);
2164
- };
2165
-
2166
- GlobSync.prototype._processReaddir = function (prefix, read, abs, remain, index, inGlobStar) {
2167
- var entries = this._readdir(abs, inGlobStar); // if the abs isn't a dir, then nothing can match!
2168
-
2169
-
2170
- if (!entries) return; // It will only match dot entries if it starts with a dot, or if
2171
- // dot is set. Stuff like @(.foo|.bar) isn't allowed.
2172
-
2173
- var pn = remain[0];
2174
- var negate = !!this.minimatch.negate;
2175
- var rawGlob = pn._glob;
2176
- var dotOk = this.dot || rawGlob.charAt(0) === '.';
2177
- var matchedEntries = [];
2178
-
2179
- for (var i = 0; i < entries.length; i++) {
2180
- var e = entries[i];
2181
-
2182
- if (e.charAt(0) !== '.' || dotOk) {
2183
- var m;
2184
-
2185
- if (negate && !prefix) {
2186
- m = !e.match(pn);
2187
- } else {
2188
- m = e.match(pn);
2189
- }
2190
-
2191
- if (m) matchedEntries.push(e);
2192
- }
2193
- }
2194
-
2195
- var len = matchedEntries.length; // If there are no matched entries, then nothing matches.
2196
-
2197
- if (len === 0) return; // if this is the last remaining pattern bit, then no need for
2198
- // an additional stat *unless* the user has specified mark or
2199
- // stat explicitly. We know they exist, since readdir returned
2200
- // them.
2201
-
2202
- if (remain.length === 1 && !this.mark && !this.stat) {
2203
- if (!this.matches[index]) this.matches[index] = Object.create(null);
2204
-
2205
- for (var i = 0; i < len; i++) {
2206
- var e = matchedEntries[i];
2207
-
2208
- if (prefix) {
2209
- if (prefix.slice(-1) !== '/') e = prefix + '/' + e;else e = prefix + e;
2210
- }
2211
-
2212
- if (e.charAt(0) === '/' && !this.nomount) {
2213
- e = path.join(this.root, e);
2214
- }
2215
-
2216
- this._emitMatch(index, e);
2217
- } // This was the last one, and no stats were needed
2218
-
2219
-
2220
- return;
2221
- } // now test all matched entries as stand-ins for that part
2222
- // of the pattern.
2223
-
2224
-
2225
- remain.shift();
2226
-
2227
- for (var i = 0; i < len; i++) {
2228
- var e = matchedEntries[i];
2229
- var newPattern;
2230
- if (prefix) newPattern = [prefix, e];else newPattern = [e];
2231
-
2232
- this._process(newPattern.concat(remain), index, inGlobStar);
2233
- }
2234
- };
2235
-
2236
- GlobSync.prototype._emitMatch = function (index, e) {
2237
- if (isIgnored(this, e)) return;
2238
-
2239
- var abs = this._makeAbs(e);
2240
-
2241
- if (this.mark) e = this._mark(e);
2242
-
2243
- if (this.absolute) {
2244
- e = abs;
2245
- }
2246
-
2247
- if (this.matches[index][e]) return;
2248
-
2249
- if (this.nodir) {
2250
- var c = this.cache[abs];
2251
- if (c === 'DIR' || Array.isArray(c)) return;
2252
- }
2253
-
2254
- this.matches[index][e] = true;
2255
- if (this.stat) this._stat(e);
2256
- };
2257
-
2258
- GlobSync.prototype._readdirInGlobStar = function (abs) {
2259
- // follow all symlinked directories forever
2260
- // just proceed as if this is a non-globstar situation
2261
- if (this.follow) return this._readdir(abs, false);
2262
- var entries;
2263
- var lstat;
2264
-
2265
- try {
2266
- lstat = this.fs.lstatSync(abs);
2267
- } catch (er) {
2268
- if (er.code === 'ENOENT') {
2269
- // lstat failed, doesn't exist
2270
- return null;
2271
- }
2272
- }
2273
-
2274
- var isSym = lstat && lstat.isSymbolicLink();
2275
- this.symlinks[abs] = isSym; // If it's not a symlink or a dir, then it's definitely a regular file.
2276
- // don't bother doing a readdir in that case.
2277
-
2278
- if (!isSym && lstat && !lstat.isDirectory()) this.cache[abs] = 'FILE';else entries = this._readdir(abs, false);
2279
- return entries;
2280
- };
2281
-
2282
- GlobSync.prototype._readdir = function (abs, inGlobStar) {
2283
- if (inGlobStar && !ownProp(this.symlinks, abs)) return this._readdirInGlobStar(abs);
2284
-
2285
- if (ownProp(this.cache, abs)) {
2286
- var c = this.cache[abs];
2287
- if (!c || c === 'FILE') return null;
2288
- if (Array.isArray(c)) return c;
2289
- }
2290
-
2291
- try {
2292
- return this._readdirEntries(abs, this.fs.readdirSync(abs));
2293
- } catch (er) {
2294
- this._readdirError(abs, er);
2295
-
2296
- return null;
2297
- }
2298
- };
2299
-
2300
- GlobSync.prototype._readdirEntries = function (abs, entries) {
2301
- // if we haven't asked to stat everything, then just
2302
- // assume that everything in there exists, so we can avoid
2303
- // having to stat it a second time.
2304
- if (!this.mark && !this.stat) {
2305
- for (var i = 0; i < entries.length; i++) {
2306
- var e = entries[i];
2307
- if (abs === '/') e = abs + e;else e = abs + '/' + e;
2308
- this.cache[e] = true;
2309
- }
2310
- }
2311
-
2312
- this.cache[abs] = entries; // mark and cache dir-ness
2313
-
2314
- return entries;
2315
- };
2316
-
2317
- GlobSync.prototype._readdirError = function (f, er) {
2318
- // handle errors, and cache the information
2319
- switch (er.code) {
2320
- case 'ENOTSUP': // https://github.com/isaacs/node-glob/issues/205
2321
-
2322
- case 'ENOTDIR':
2323
- // totally normal. means it *does* exist.
2324
- var abs = this._makeAbs(f);
2325
-
2326
- this.cache[abs] = 'FILE';
2327
-
2328
- if (abs === this.cwdAbs) {
2329
- var error = new Error(er.code + ' invalid cwd ' + this.cwd);
2330
- error.path = this.cwd;
2331
- error.code = er.code;
2332
- throw error;
2333
- }
2334
-
2335
- break;
2336
-
2337
- case 'ENOENT': // not terribly unusual
2338
-
2339
- case 'ELOOP':
2340
- case 'ENAMETOOLONG':
2341
- case 'UNKNOWN':
2342
- this.cache[this._makeAbs(f)] = false;
2343
- break;
2344
-
2345
- default:
2346
- // some unusual error. Treat as failure.
2347
- this.cache[this._makeAbs(f)] = false;
2348
- if (this.strict) throw er;
2349
- if (!this.silent) console.error('glob error', er);
2350
- break;
2351
- }
2352
- };
2353
-
2354
- GlobSync.prototype._processGlobStar = function (prefix, read, abs, remain, index, inGlobStar) {
2355
- var entries = this._readdir(abs, inGlobStar); // no entries means not a dir, so it can never have matches
2356
- // foo.txt/** doesn't match foo.txt
2357
-
2358
-
2359
- if (!entries) return; // test without the globstar, and with every child both below
2360
- // and replacing the globstar.
2361
-
2362
- var remainWithoutGlobStar = remain.slice(1);
2363
- var gspref = prefix ? [prefix] : [];
2364
- var noGlobStar = gspref.concat(remainWithoutGlobStar); // the noGlobStar pattern exits the inGlobStar state
2365
-
2366
- this._process(noGlobStar, index, false);
2367
-
2368
- var len = entries.length;
2369
- var isSym = this.symlinks[abs]; // If it's a symlink, and we're in a globstar, then stop
2370
-
2371
- if (isSym && inGlobStar) return;
2372
-
2373
- for (var i = 0; i < len; i++) {
2374
- var e = entries[i];
2375
- if (e.charAt(0) === '.' && !this.dot) continue; // these two cases enter the inGlobStar state
2376
-
2377
- var instead = gspref.concat(entries[i], remainWithoutGlobStar);
2378
-
2379
- this._process(instead, index, true);
2380
-
2381
- var below = gspref.concat(entries[i], remain);
2382
-
2383
- this._process(below, index, true);
2384
- }
2385
- };
2386
-
2387
- GlobSync.prototype._processSimple = function (prefix, index) {
2388
- // XXX review this. Shouldn't it be doing the mounting etc
2389
- // before doing stat? kinda weird?
2390
- var exists = this._stat(prefix);
2391
-
2392
- if (!this.matches[index]) this.matches[index] = Object.create(null); // If it doesn't exist, then just mark the lack of results
2393
-
2394
- if (!exists) return;
2395
-
2396
- if (prefix && isAbsolute(prefix) && !this.nomount) {
2397
- var trail = /[\/\\]$/.test(prefix);
2398
-
2399
- if (prefix.charAt(0) === '/') {
2400
- prefix = path.join(this.root, prefix);
2401
- } else {
2402
- prefix = path.resolve(this.root, prefix);
2403
- if (trail) prefix += '/';
2404
- }
2405
- }
2406
-
2407
- if (process.platform === 'win32') prefix = prefix.replace(/\\/g, '/'); // Mark this as a match
2408
-
2409
- this._emitMatch(index, prefix);
2410
- }; // Returns either 'DIR', 'FILE', or false
2411
-
2412
-
2413
- GlobSync.prototype._stat = function (f) {
2414
- var abs = this._makeAbs(f);
2415
-
2416
- var needDir = f.slice(-1) === '/';
2417
- if (f.length > this.maxLength) return false;
2418
-
2419
- if (!this.stat && ownProp(this.cache, abs)) {
2420
- var c = this.cache[abs];
2421
- if (Array.isArray(c)) c = 'DIR'; // It exists, but maybe not how we need it
2422
-
2423
- if (!needDir || c === 'DIR') return c;
2424
- if (needDir && c === 'FILE') return false; // otherwise we have to stat, because maybe c=true
2425
- // if we know it exists, but not what it is.
2426
- }
2427
-
2428
- var stat = this.statCache[abs];
2429
-
2430
- if (!stat) {
2431
- var lstat;
2432
-
2433
- try {
2434
- lstat = this.fs.lstatSync(abs);
2435
- } catch (er) {
2436
- if (er && (er.code === 'ENOENT' || er.code === 'ENOTDIR')) {
2437
- this.statCache[abs] = false;
2438
- return false;
2439
- }
2440
- }
2441
-
2442
- if (lstat && lstat.isSymbolicLink()) {
2443
- try {
2444
- stat = this.fs.statSync(abs);
2445
- } catch (er) {
2446
- stat = lstat;
2447
- }
2448
- } else {
2449
- stat = lstat;
2450
- }
2451
- }
2452
-
2453
- this.statCache[abs] = stat;
2454
- var c = true;
2455
- if (stat) c = stat.isDirectory() ? 'DIR' : 'FILE';
2456
- this.cache[abs] = this.cache[abs] || c;
2457
- if (needDir && c === 'FILE') return false;
2458
- return c;
2459
- };
2460
-
2461
- GlobSync.prototype._mark = function (p) {
2462
- return common.mark(this, p);
2463
- };
2464
-
2465
- GlobSync.prototype._makeAbs = function (f) {
2466
- return common.makeAbs(this, f);
2467
- };
2468
-
2469
- return sync;
2470
- }
2471
-
2472
- var wrappy_1;
2473
- var hasRequiredWrappy;
2474
-
2475
- function requireWrappy() {
2476
- if (hasRequiredWrappy) return wrappy_1;
2477
- hasRequiredWrappy = 1; // Returns a wrapper function that returns a wrapped callback
2478
- // The wrapper function should do some stuff, and return a
2479
- // presumably different callback function.
2480
- // This makes sure that own properties are retained, so that
2481
- // decorations and such are not lost along the way.
2482
-
2483
- wrappy_1 = wrappy;
2484
-
2485
- function wrappy(fn, cb) {
2486
- if (fn && cb) return wrappy(fn)(cb);
2487
- if (typeof fn !== 'function') throw new TypeError('need wrapper function');
2488
- Object.keys(fn).forEach(function (k) {
2489
- wrapper[k] = fn[k];
2490
- });
2491
- return wrapper;
2492
-
2493
- function wrapper() {
2494
- var args = new Array(arguments.length);
2495
-
2496
- for (var i = 0; i < args.length; i++) {
2497
- args[i] = arguments[i];
2498
- }
2499
-
2500
- var ret = fn.apply(this, args);
2501
- var cb = args[args.length - 1];
2502
-
2503
- if (typeof ret === 'function' && ret !== cb) {
2504
- Object.keys(cb).forEach(function (k) {
2505
- ret[k] = cb[k];
2506
- });
2507
- }
2508
-
2509
- return ret;
2510
- }
2511
- }
2512
-
2513
- return wrappy_1;
2514
- }
2515
-
2516
- var once = {
2517
- exports: {}
2518
- };
2519
- var hasRequiredOnce;
2520
-
2521
- function requireOnce() {
2522
- if (hasRequiredOnce) return once.exports;
2523
- hasRequiredOnce = 1;
2524
- var wrappy = requireWrappy();
2525
- once.exports = wrappy(once$1);
2526
- once.exports.strict = wrappy(onceStrict);
2527
- once$1.proto = once$1(function () {
2528
- Object.defineProperty(Function.prototype, 'once', {
2529
- value: function () {
2530
- return once$1(this);
2531
- },
2532
- configurable: true
2533
- });
2534
- Object.defineProperty(Function.prototype, 'onceStrict', {
2535
- value: function () {
2536
- return onceStrict(this);
2537
- },
2538
- configurable: true
2539
- });
2540
- });
2541
-
2542
- function once$1(fn) {
2543
- var f = function () {
2544
- if (f.called) return f.value;
2545
- f.called = true;
2546
- return f.value = fn.apply(this, arguments);
2547
- };
2548
-
2549
- f.called = false;
2550
- return f;
2551
- }
2552
-
2553
- function onceStrict(fn) {
2554
- var f = function () {
2555
- if (f.called) throw new Error(f.onceError);
2556
- f.called = true;
2557
- return f.value = fn.apply(this, arguments);
2558
- };
2559
-
2560
- var name = fn.name || 'Function wrapped with `once`';
2561
- f.onceError = name + " shouldn't be called more than once";
2562
- f.called = false;
2563
- return f;
2564
- }
2565
-
2566
- return once.exports;
2567
- }
2568
-
2569
- var inflight_1;
2570
- var hasRequiredInflight;
2571
-
2572
- function requireInflight() {
2573
- if (hasRequiredInflight) return inflight_1;
2574
- hasRequiredInflight = 1;
2575
- var wrappy = requireWrappy();
2576
- var reqs = Object.create(null);
2577
- var once = requireOnce();
2578
- inflight_1 = wrappy(inflight);
2579
-
2580
- function inflight(key, cb) {
2581
- if (reqs[key]) {
2582
- reqs[key].push(cb);
2583
- return null;
2584
- } else {
2585
- reqs[key] = [cb];
2586
- return makeres(key);
2587
- }
2588
- }
2589
-
2590
- function makeres(key) {
2591
- return once(function RES() {
2592
- var cbs = reqs[key];
2593
- var len = cbs.length;
2594
- var args = slice(arguments); // XXX It's somewhat ambiguous whether a new callback added in this
2595
- // pass should be queued for later execution if something in the
2596
- // list of callbacks throws, or if it should just be discarded.
2597
- // However, it's such an edge case that it hardly matters, and either
2598
- // choice is likely as surprising as the other.
2599
- // As it happens, we do go ahead and schedule it for later execution.
2600
-
2601
- try {
2602
- for (var i = 0; i < len; i++) {
2603
- cbs[i].apply(null, args);
2604
- }
2605
- } finally {
2606
- if (cbs.length > len) {
2607
- // added more in the interim.
2608
- // de-zalgo, just in case, but don't call again.
2609
- cbs.splice(0, len);
2610
- process.nextTick(function () {
2611
- RES.apply(null, args);
2612
- });
2613
- } else {
2614
- delete reqs[key];
2615
- }
2616
- }
2617
- });
2618
- }
2619
-
2620
- function slice(args) {
2621
- var length = args.length;
2622
- var array = [];
2623
-
2624
- for (var i = 0; i < length; i++) array[i] = args[i];
2625
-
2626
- return array;
2627
- }
2628
-
2629
- return inflight_1;
2630
- }
2631
-
2632
- var glob_1;
2633
- var hasRequiredGlob;
2634
-
2635
- function requireGlob() {
2636
- if (hasRequiredGlob) return glob_1;
2637
- hasRequiredGlob = 1; // Approach:
2638
- //
2639
- // 1. Get the minimatch set
2640
- // 2. For each pattern in the set, PROCESS(pattern, false)
2641
- // 3. Store matches per-set, then uniq them
2642
- //
2643
- // PROCESS(pattern, inGlobStar)
2644
- // Get the first [n] items from pattern that are all strings
2645
- // Join these together. This is PREFIX.
2646
- // If there is no more remaining, then stat(PREFIX) and
2647
- // add to matches if it succeeds. END.
2648
- //
2649
- // If inGlobStar and PREFIX is symlink and points to dir
2650
- // set ENTRIES = []
2651
- // else readdir(PREFIX) as ENTRIES
2652
- // If fail, END
2653
- //
2654
- // with ENTRIES
2655
- // If pattern[n] is GLOBSTAR
2656
- // // handle the case where the globstar match is empty
2657
- // // by pruning it out, and testing the resulting pattern
2658
- // PROCESS(pattern[0..n] + pattern[n+1 .. $], false)
2659
- // // handle other cases.
2660
- // for ENTRY in ENTRIES (not dotfiles)
2661
- // // attach globstar + tail onto the entry
2662
- // // Mark that this entry is a globstar match
2663
- // PROCESS(pattern[0..n] + ENTRY + pattern[n .. $], true)
2664
- //
2665
- // else // not globstar
2666
- // for ENTRY in ENTRIES (not dotfiles, unless pattern[n] is dot)
2667
- // Test ENTRY against pattern[n]
2668
- // If fails, continue
2669
- // If passes, PROCESS(pattern[0..n] + item + pattern[n+1 .. $])
2670
- //
2671
- // Caveat:
2672
- // Cache all stats and readdirs results to minimize syscall. Since all
2673
- // we ever care about is existence and directory-ness, we can just keep
2674
- // `true` for files, and [children,...] for directories, or `false` for
2675
- // things that don't exist.
2676
-
2677
- glob_1 = glob;
2678
- var rp = requireFs_realpath();
2679
- var minimatch = requireMinimatch();
2680
- var inherits = requireInherits();
2681
- var EE = require$$3__default["default"].EventEmitter;
2682
- var path = path__default["default"];
2683
- var assert = require$$5__default["default"];
2684
- var isAbsolute = requirePathIsAbsolute();
2685
- var globSync = requireSync();
2686
- var common = requireCommon();
2687
- var setopts = common.setopts;
2688
- var ownProp = common.ownProp;
2689
- var inflight = requireInflight();
2690
- var childrenIgnored = common.childrenIgnored;
2691
- var isIgnored = common.isIgnored;
2692
- var once = requireOnce();
2693
-
2694
- function glob(pattern, options, cb) {
2695
- if (typeof options === 'function') cb = options, options = {};
2696
- if (!options) options = {};
2697
-
2698
- if (options.sync) {
2699
- if (cb) throw new TypeError('callback provided to sync glob');
2700
- return globSync(pattern, options);
2701
- }
2702
-
2703
- return new Glob(pattern, options, cb);
2704
- }
2705
-
2706
- glob.sync = globSync;
2707
- var GlobSync = glob.GlobSync = globSync.GlobSync; // old api surface
2708
-
2709
- glob.glob = glob;
2710
-
2711
- function extend(origin, add) {
2712
- if (add === null || typeof add !== 'object') {
2713
- return origin;
2714
- }
2715
-
2716
- var keys = Object.keys(add);
2717
- var i = keys.length;
2718
-
2719
- while (i--) {
2720
- origin[keys[i]] = add[keys[i]];
2721
- }
2722
-
2723
- return origin;
2724
- }
2725
-
2726
- glob.hasMagic = function (pattern, options_) {
2727
- var options = extend({}, options_);
2728
- options.noprocess = true;
2729
- var g = new Glob(pattern, options);
2730
- var set = g.minimatch.set;
2731
- if (!pattern) return false;
2732
- if (set.length > 1) return true;
2733
-
2734
- for (var j = 0; j < set[0].length; j++) {
2735
- if (typeof set[0][j] !== 'string') return true;
2736
- }
2737
-
2738
- return false;
2739
- };
2740
-
2741
- glob.Glob = Glob;
2742
- inherits(Glob, EE);
2743
-
2744
- function Glob(pattern, options, cb) {
2745
- if (typeof options === 'function') {
2746
- cb = options;
2747
- options = null;
2748
- }
2749
-
2750
- if (options && options.sync) {
2751
- if (cb) throw new TypeError('callback provided to sync glob');
2752
- return new GlobSync(pattern, options);
2753
- }
2754
-
2755
- if (!(this instanceof Glob)) return new Glob(pattern, options, cb);
2756
- setopts(this, pattern, options);
2757
- this._didRealPath = false; // process each pattern in the minimatch set
2758
-
2759
- var n = this.minimatch.set.length; // The matches are stored as {<filename>: true,...} so that
2760
- // duplicates are automagically pruned.
2761
- // Later, we do an Object.keys() on these.
2762
- // Keep them as a list so we can fill in when nonull is set.
2763
-
2764
- this.matches = new Array(n);
2765
-
2766
- if (typeof cb === 'function') {
2767
- cb = once(cb);
2768
- this.on('error', cb);
2769
- this.on('end', function (matches) {
2770
- cb(null, matches);
2771
- });
2772
- }
2773
-
2774
- var self = this;
2775
- this._processing = 0;
2776
- this._emitQueue = [];
2777
- this._processQueue = [];
2778
- this.paused = false;
2779
- if (this.noprocess) return this;
2780
- if (n === 0) return done();
2781
- var sync = true;
2782
-
2783
- for (var i = 0; i < n; i++) {
2784
- this._process(this.minimatch.set[i], i, false, done);
2785
- }
2786
-
2787
- sync = false;
2788
-
2789
- function done() {
2790
- --self._processing;
2791
-
2792
- if (self._processing <= 0) {
2793
- if (sync) {
2794
- process.nextTick(function () {
2795
- self._finish();
2796
- });
2797
- } else {
2798
- self._finish();
2799
- }
2800
- }
2801
- }
2802
- }
2803
-
2804
- Glob.prototype._finish = function () {
2805
- assert(this instanceof Glob);
2806
- if (this.aborted) return;
2807
- if (this.realpath && !this._didRealpath) return this._realpath();
2808
- common.finish(this);
2809
- this.emit('end', this.found);
2810
- };
2811
-
2812
- Glob.prototype._realpath = function () {
2813
- if (this._didRealpath) return;
2814
- this._didRealpath = true;
2815
- var n = this.matches.length;
2816
- if (n === 0) return this._finish();
2817
- var self = this;
2818
-
2819
- for (var i = 0; i < this.matches.length; i++) this._realpathSet(i, next);
2820
-
2821
- function next() {
2822
- if (--n === 0) self._finish();
2823
- }
2824
- };
2825
-
2826
- Glob.prototype._realpathSet = function (index, cb) {
2827
- var matchset = this.matches[index];
2828
- if (!matchset) return cb();
2829
- var found = Object.keys(matchset);
2830
- var self = this;
2831
- var n = found.length;
2832
- if (n === 0) return cb();
2833
- var set = this.matches[index] = Object.create(null);
2834
- found.forEach(function (p, i) {
2835
- // If there's a problem with the stat, then it means that
2836
- // one or more of the links in the realpath couldn't be
2837
- // resolved. just return the abs value in that case.
2838
- p = self._makeAbs(p);
2839
- rp.realpath(p, self.realpathCache, function (er, real) {
2840
- if (!er) set[real] = true;else if (er.syscall === 'stat') set[p] = true;else self.emit('error', er); // srsly wtf right here
2841
-
2842
- if (--n === 0) {
2843
- self.matches[index] = set;
2844
- cb();
2845
- }
2846
- });
2847
- });
2848
- };
2849
-
2850
- Glob.prototype._mark = function (p) {
2851
- return common.mark(this, p);
2852
- };
2853
-
2854
- Glob.prototype._makeAbs = function (f) {
2855
- return common.makeAbs(this, f);
2856
- };
2857
-
2858
- Glob.prototype.abort = function () {
2859
- this.aborted = true;
2860
- this.emit('abort');
2861
- };
2862
-
2863
- Glob.prototype.pause = function () {
2864
- if (!this.paused) {
2865
- this.paused = true;
2866
- this.emit('pause');
2867
- }
2868
- };
2869
-
2870
- Glob.prototype.resume = function () {
2871
- if (this.paused) {
2872
- this.emit('resume');
2873
- this.paused = false;
2874
-
2875
- if (this._emitQueue.length) {
2876
- var eq = this._emitQueue.slice(0);
2877
-
2878
- this._emitQueue.length = 0;
2879
-
2880
- for (var i = 0; i < eq.length; i++) {
2881
- var e = eq[i];
2882
-
2883
- this._emitMatch(e[0], e[1]);
2884
- }
2885
- }
2886
-
2887
- if (this._processQueue.length) {
2888
- var pq = this._processQueue.slice(0);
2889
-
2890
- this._processQueue.length = 0;
2891
-
2892
- for (var i = 0; i < pq.length; i++) {
2893
- var p = pq[i];
2894
- this._processing--;
2895
-
2896
- this._process(p[0], p[1], p[2], p[3]);
2897
- }
2898
- }
2899
- }
2900
- };
2901
-
2902
- Glob.prototype._process = function (pattern, index, inGlobStar, cb) {
2903
- assert(this instanceof Glob);
2904
- assert(typeof cb === 'function');
2905
- if (this.aborted) return;
2906
- this._processing++;
2907
-
2908
- if (this.paused) {
2909
- this._processQueue.push([pattern, index, inGlobStar, cb]);
2910
-
2911
- return;
2912
- } //console.error('PROCESS %d', this._processing, pattern)
2913
- // Get the first [n] parts of pattern that are all strings.
2914
-
2915
-
2916
- var n = 0;
2917
-
2918
- while (typeof pattern[n] === 'string') {
2919
- n++;
2920
- } // now n is the index of the first one that is *not* a string.
2921
- // see if there's anything else
2922
-
2923
-
2924
- var prefix;
2925
-
2926
- switch (n) {
2927
- // if not, then this is rather simple
2928
- case pattern.length:
2929
- this._processSimple(pattern.join('/'), index, cb);
2930
-
2931
- return;
2932
-
2933
- case 0:
2934
- // pattern *starts* with some non-trivial item.
2935
- // going to readdir(cwd), but not include the prefix in matches.
2936
- prefix = null;
2937
- break;
2938
-
2939
- default:
2940
- // pattern has some string bits in the front.
2941
- // whatever it starts with, whether that's 'absolute' like /foo/bar,
2942
- // or 'relative' like '../baz'
2943
- prefix = pattern.slice(0, n).join('/');
2944
- break;
2945
- }
2946
-
2947
- var remain = pattern.slice(n); // get the list of entries.
2948
-
2949
- var read;
2950
- if (prefix === null) read = '.';else if (isAbsolute(prefix) || isAbsolute(pattern.map(function (p) {
2951
- return typeof p === 'string' ? p : '[*]';
2952
- }).join('/'))) {
2953
- if (!prefix || !isAbsolute(prefix)) prefix = '/' + prefix;
2954
- read = prefix;
2955
- } else read = prefix;
2956
-
2957
- var abs = this._makeAbs(read); //if ignored, skip _processing
2958
-
2959
-
2960
- if (childrenIgnored(this, read)) return cb();
2961
- var isGlobStar = remain[0] === minimatch.GLOBSTAR;
2962
- if (isGlobStar) this._processGlobStar(prefix, read, abs, remain, index, inGlobStar, cb);else this._processReaddir(prefix, read, abs, remain, index, inGlobStar, cb);
2963
- };
2964
-
2965
- Glob.prototype._processReaddir = function (prefix, read, abs, remain, index, inGlobStar, cb) {
2966
- var self = this;
2967
-
2968
- this._readdir(abs, inGlobStar, function (er, entries) {
2969
- return self._processReaddir2(prefix, read, abs, remain, index, inGlobStar, entries, cb);
2970
- });
2971
- };
2972
-
2973
- Glob.prototype._processReaddir2 = function (prefix, read, abs, remain, index, inGlobStar, entries, cb) {
2974
- // if the abs isn't a dir, then nothing can match!
2975
- if (!entries) return cb(); // It will only match dot entries if it starts with a dot, or if
2976
- // dot is set. Stuff like @(.foo|.bar) isn't allowed.
2977
-
2978
- var pn = remain[0];
2979
- var negate = !!this.minimatch.negate;
2980
- var rawGlob = pn._glob;
2981
- var dotOk = this.dot || rawGlob.charAt(0) === '.';
2982
- var matchedEntries = [];
2983
-
2984
- for (var i = 0; i < entries.length; i++) {
2985
- var e = entries[i];
2986
-
2987
- if (e.charAt(0) !== '.' || dotOk) {
2988
- var m;
2989
-
2990
- if (negate && !prefix) {
2991
- m = !e.match(pn);
2992
- } else {
2993
- m = e.match(pn);
2994
- }
2995
-
2996
- if (m) matchedEntries.push(e);
2997
- }
2998
- } //console.error('prd2', prefix, entries, remain[0]._glob, matchedEntries)
2999
-
3000
-
3001
- var len = matchedEntries.length; // If there are no matched entries, then nothing matches.
3002
-
3003
- if (len === 0) return cb(); // if this is the last remaining pattern bit, then no need for
3004
- // an additional stat *unless* the user has specified mark or
3005
- // stat explicitly. We know they exist, since readdir returned
3006
- // them.
3007
-
3008
- if (remain.length === 1 && !this.mark && !this.stat) {
3009
- if (!this.matches[index]) this.matches[index] = Object.create(null);
3010
-
3011
- for (var i = 0; i < len; i++) {
3012
- var e = matchedEntries[i];
3013
-
3014
- if (prefix) {
3015
- if (prefix !== '/') e = prefix + '/' + e;else e = prefix + e;
3016
- }
3017
-
3018
- if (e.charAt(0) === '/' && !this.nomount) {
3019
- e = path.join(this.root, e);
3020
- }
3021
-
3022
- this._emitMatch(index, e);
3023
- } // This was the last one, and no stats were needed
3024
-
3025
-
3026
- return cb();
3027
- } // now test all matched entries as stand-ins for that part
3028
- // of the pattern.
3029
-
3030
-
3031
- remain.shift();
3032
-
3033
- for (var i = 0; i < len; i++) {
3034
- var e = matchedEntries[i];
3035
-
3036
- if (prefix) {
3037
- if (prefix !== '/') e = prefix + '/' + e;else e = prefix + e;
3038
- }
3039
-
3040
- this._process([e].concat(remain), index, inGlobStar, cb);
3041
- }
3042
-
3043
- cb();
3044
- };
3045
-
3046
- Glob.prototype._emitMatch = function (index, e) {
3047
- if (this.aborted) return;
3048
- if (isIgnored(this, e)) return;
3049
-
3050
- if (this.paused) {
3051
- this._emitQueue.push([index, e]);
3052
-
3053
- return;
3054
- }
3055
-
3056
- var abs = isAbsolute(e) ? e : this._makeAbs(e);
3057
- if (this.mark) e = this._mark(e);
3058
- if (this.absolute) e = abs;
3059
- if (this.matches[index][e]) return;
3060
-
3061
- if (this.nodir) {
3062
- var c = this.cache[abs];
3063
- if (c === 'DIR' || Array.isArray(c)) return;
3064
- }
3065
-
3066
- this.matches[index][e] = true;
3067
- var st = this.statCache[abs];
3068
- if (st) this.emit('stat', e, st);
3069
- this.emit('match', e);
3070
- };
3071
-
3072
- Glob.prototype._readdirInGlobStar = function (abs, cb) {
3073
- if (this.aborted) return; // follow all symlinked directories forever
3074
- // just proceed as if this is a non-globstar situation
3075
-
3076
- if (this.follow) return this._readdir(abs, false, cb);
3077
- var lstatkey = 'lstat\0' + abs;
3078
- var self = this;
3079
- var lstatcb = inflight(lstatkey, lstatcb_);
3080
- if (lstatcb) self.fs.lstat(abs, lstatcb);
3081
-
3082
- function lstatcb_(er, lstat) {
3083
- if (er && er.code === 'ENOENT') return cb();
3084
- var isSym = lstat && lstat.isSymbolicLink();
3085
- self.symlinks[abs] = isSym; // If it's not a symlink or a dir, then it's definitely a regular file.
3086
- // don't bother doing a readdir in that case.
3087
-
3088
- if (!isSym && lstat && !lstat.isDirectory()) {
3089
- self.cache[abs] = 'FILE';
3090
- cb();
3091
- } else self._readdir(abs, false, cb);
3092
- }
3093
- };
3094
-
3095
- Glob.prototype._readdir = function (abs, inGlobStar, cb) {
3096
- if (this.aborted) return;
3097
- cb = inflight('readdir\0' + abs + '\0' + inGlobStar, cb);
3098
- if (!cb) return; //console.error('RD %j %j', +inGlobStar, abs)
3099
-
3100
- if (inGlobStar && !ownProp(this.symlinks, abs)) return this._readdirInGlobStar(abs, cb);
3101
-
3102
- if (ownProp(this.cache, abs)) {
3103
- var c = this.cache[abs];
3104
- if (!c || c === 'FILE') return cb();
3105
- if (Array.isArray(c)) return cb(null, c);
3106
- }
3107
-
3108
- var self = this;
3109
- self.fs.readdir(abs, readdirCb(this, abs, cb));
3110
- };
3111
-
3112
- function readdirCb(self, abs, cb) {
3113
- return function (er, entries) {
3114
- if (er) self._readdirError(abs, er, cb);else self._readdirEntries(abs, entries, cb);
3115
- };
3116
- }
3117
-
3118
- Glob.prototype._readdirEntries = function (abs, entries, cb) {
3119
- if (this.aborted) return; // if we haven't asked to stat everything, then just
3120
- // assume that everything in there exists, so we can avoid
3121
- // having to stat it a second time.
3122
-
3123
- if (!this.mark && !this.stat) {
3124
- for (var i = 0; i < entries.length; i++) {
3125
- var e = entries[i];
3126
- if (abs === '/') e = abs + e;else e = abs + '/' + e;
3127
- this.cache[e] = true;
3128
- }
3129
- }
3130
-
3131
- this.cache[abs] = entries;
3132
- return cb(null, entries);
3133
- };
3134
-
3135
- Glob.prototype._readdirError = function (f, er, cb) {
3136
- if (this.aborted) return; // handle errors, and cache the information
3137
-
3138
- switch (er.code) {
3139
- case 'ENOTSUP': // https://github.com/isaacs/node-glob/issues/205
3140
-
3141
- case 'ENOTDIR':
3142
- // totally normal. means it *does* exist.
3143
- var abs = this._makeAbs(f);
3144
-
3145
- this.cache[abs] = 'FILE';
3146
-
3147
- if (abs === this.cwdAbs) {
3148
- var error = new Error(er.code + ' invalid cwd ' + this.cwd);
3149
- error.path = this.cwd;
3150
- error.code = er.code;
3151
- this.emit('error', error);
3152
- this.abort();
3153
- }
3154
-
3155
- break;
3156
-
3157
- case 'ENOENT': // not terribly unusual
3158
-
3159
- case 'ELOOP':
3160
- case 'ENAMETOOLONG':
3161
- case 'UNKNOWN':
3162
- this.cache[this._makeAbs(f)] = false;
3163
- break;
3164
-
3165
- default:
3166
- // some unusual error. Treat as failure.
3167
- this.cache[this._makeAbs(f)] = false;
3168
-
3169
- if (this.strict) {
3170
- this.emit('error', er); // If the error is handled, then we abort
3171
- // if not, we threw out of here
3172
-
3173
- this.abort();
3174
- }
3175
-
3176
- if (!this.silent) console.error('glob error', er);
3177
- break;
3178
- }
3179
-
3180
- return cb();
3181
- };
3182
-
3183
- Glob.prototype._processGlobStar = function (prefix, read, abs, remain, index, inGlobStar, cb) {
3184
- var self = this;
3185
-
3186
- this._readdir(abs, inGlobStar, function (er, entries) {
3187
- self._processGlobStar2(prefix, read, abs, remain, index, inGlobStar, entries, cb);
3188
- });
3189
- };
3190
-
3191
- Glob.prototype._processGlobStar2 = function (prefix, read, abs, remain, index, inGlobStar, entries, cb) {
3192
- //console.error('pgs2', prefix, remain[0], entries)
3193
- // no entries means not a dir, so it can never have matches
3194
- // foo.txt/** doesn't match foo.txt
3195
- if (!entries) return cb(); // test without the globstar, and with every child both below
3196
- // and replacing the globstar.
3197
-
3198
- var remainWithoutGlobStar = remain.slice(1);
3199
- var gspref = prefix ? [prefix] : [];
3200
- var noGlobStar = gspref.concat(remainWithoutGlobStar); // the noGlobStar pattern exits the inGlobStar state
3201
-
3202
- this._process(noGlobStar, index, false, cb);
3203
-
3204
- var isSym = this.symlinks[abs];
3205
- var len = entries.length; // If it's a symlink, and we're in a globstar, then stop
3206
-
3207
- if (isSym && inGlobStar) return cb();
3208
-
3209
- for (var i = 0; i < len; i++) {
3210
- var e = entries[i];
3211
- if (e.charAt(0) === '.' && !this.dot) continue; // these two cases enter the inGlobStar state
3212
-
3213
- var instead = gspref.concat(entries[i], remainWithoutGlobStar);
3214
-
3215
- this._process(instead, index, true, cb);
3216
-
3217
- var below = gspref.concat(entries[i], remain);
3218
-
3219
- this._process(below, index, true, cb);
3220
- }
3221
-
3222
- cb();
3223
- };
3224
-
3225
- Glob.prototype._processSimple = function (prefix, index, cb) {
3226
- // XXX review this. Shouldn't it be doing the mounting etc
3227
- // before doing stat? kinda weird?
3228
- var self = this;
3229
-
3230
- this._stat(prefix, function (er, exists) {
3231
- self._processSimple2(prefix, index, er, exists, cb);
3232
- });
3233
- };
3234
-
3235
- Glob.prototype._processSimple2 = function (prefix, index, er, exists, cb) {
3236
- //console.error('ps2', prefix, exists)
3237
- if (!this.matches[index]) this.matches[index] = Object.create(null); // If it doesn't exist, then just mark the lack of results
3238
-
3239
- if (!exists) return cb();
3240
-
3241
- if (prefix && isAbsolute(prefix) && !this.nomount) {
3242
- var trail = /[\/\\]$/.test(prefix);
3243
-
3244
- if (prefix.charAt(0) === '/') {
3245
- prefix = path.join(this.root, prefix);
3246
- } else {
3247
- prefix = path.resolve(this.root, prefix);
3248
- if (trail) prefix += '/';
3249
- }
3250
- }
3251
-
3252
- if (process.platform === 'win32') prefix = prefix.replace(/\\/g, '/'); // Mark this as a match
3253
-
3254
- this._emitMatch(index, prefix);
3255
-
3256
- cb();
3257
- }; // Returns either 'DIR', 'FILE', or false
3258
-
3259
-
3260
- Glob.prototype._stat = function (f, cb) {
3261
- var abs = this._makeAbs(f);
3262
-
3263
- var needDir = f.slice(-1) === '/';
3264
- if (f.length > this.maxLength) return cb();
3265
-
3266
- if (!this.stat && ownProp(this.cache, abs)) {
3267
- var c = this.cache[abs];
3268
- if (Array.isArray(c)) c = 'DIR'; // It exists, but maybe not how we need it
3269
-
3270
- if (!needDir || c === 'DIR') return cb(null, c);
3271
- if (needDir && c === 'FILE') return cb(); // otherwise we have to stat, because maybe c=true
3272
- // if we know it exists, but not what it is.
3273
- }
3274
-
3275
- var stat = this.statCache[abs];
3276
-
3277
- if (stat !== undefined) {
3278
- if (stat === false) return cb(null, stat);else {
3279
- var type = stat.isDirectory() ? 'DIR' : 'FILE';
3280
- if (needDir && type === 'FILE') return cb();else return cb(null, type, stat);
3281
- }
3282
- }
3283
-
3284
- var self = this;
3285
- var statcb = inflight('stat\0' + abs, lstatcb_);
3286
- if (statcb) self.fs.lstat(abs, statcb);
3287
-
3288
- function lstatcb_(er, lstat) {
3289
- if (lstat && lstat.isSymbolicLink()) {
3290
- // If it's a symlink, then treat it as the target, unless
3291
- // the target does not exist, then treat it as a file.
3292
- return self.fs.stat(abs, function (er, stat) {
3293
- if (er) self._stat2(f, abs, null, lstat, cb);else self._stat2(f, abs, er, stat, cb);
3294
- });
3295
- } else {
3296
- self._stat2(f, abs, er, lstat, cb);
3297
- }
3298
- }
3299
- };
3300
-
3301
- Glob.prototype._stat2 = function (f, abs, er, stat, cb) {
3302
- if (er && (er.code === 'ENOENT' || er.code === 'ENOTDIR')) {
3303
- this.statCache[abs] = false;
3304
- return cb();
3305
- }
3306
-
3307
- var needDir = f.slice(-1) === '/';
3308
- this.statCache[abs] = stat;
3309
- if (abs.slice(-1) === '/' && stat && !stat.isDirectory()) return cb(null, false, stat);
3310
- var c = true;
3311
- if (stat) c = stat.isDirectory() ? 'DIR' : 'FILE';
3312
- this.cache[abs] = this.cache[abs] || c;
3313
- if (needDir && c === 'FILE') return cb();
3314
- return cb(null, c, stat);
3315
- };
3316
-
3317
- return glob_1;
3318
- }
3319
-
3320
- const assert = require$$5__default["default"];
3321
- const path = path__default["default"];
3322
- const fs = fs__default["default"];
3323
- let glob = undefined;
3324
-
3325
- try {
3326
- glob = requireGlob();
3327
- } catch (_err) {// treat glob as optional.
3328
- }
3329
-
3330
- const defaultGlobOpts = {
3331
- nosort: true,
3332
- silent: true
3333
- }; // for EMFILE handling
3334
-
3335
- let timeout = 0;
3336
- const isWindows = process.platform === "win32";
3337
-
3338
- const defaults = options => {
3339
- const methods = ['unlink', 'chmod', 'stat', 'lstat', 'rmdir', 'readdir'];
3340
- methods.forEach(m => {
3341
- options[m] = options[m] || fs[m];
3342
- m = m + 'Sync';
3343
- options[m] = options[m] || fs[m];
3344
- });
3345
- options.maxBusyTries = options.maxBusyTries || 3;
3346
- options.emfileWait = options.emfileWait || 1000;
3347
-
3348
- if (options.glob === false) {
3349
- options.disableGlob = true;
3350
- }
3351
-
3352
- if (options.disableGlob !== true && glob === undefined) {
3353
- throw Error('glob dependency not found, set `options.disableGlob = true` if intentional');
3354
- }
3355
-
3356
- options.disableGlob = options.disableGlob || false;
3357
- options.glob = options.glob || defaultGlobOpts;
3358
- };
3359
-
3360
- const rimraf$1 = (p, options, cb) => {
3361
- if (typeof options === 'function') {
3362
- cb = options;
3363
- options = {};
3364
- }
3365
-
3366
- assert(p, 'rimraf: missing path');
3367
- assert.equal(typeof p, 'string', 'rimraf: path should be a string');
3368
- assert.equal(typeof cb, 'function', 'rimraf: callback function required');
3369
- assert(options, 'rimraf: invalid options argument provided');
3370
- assert.equal(typeof options, 'object', 'rimraf: options should be object');
3371
- defaults(options);
3372
- let busyTries = 0;
3373
- let errState = null;
3374
- let n = 0;
3375
-
3376
- const next = er => {
3377
- errState = errState || er;
3378
- if (--n === 0) cb(errState);
3379
- };
3380
-
3381
- const afterGlob = (er, results) => {
3382
- if (er) return cb(er);
3383
- n = results.length;
3384
- if (n === 0) return cb();
3385
- results.forEach(p => {
3386
- const CB = er => {
3387
- if (er) {
3388
- if ((er.code === "EBUSY" || er.code === "ENOTEMPTY" || er.code === "EPERM") && busyTries < options.maxBusyTries) {
3389
- busyTries++; // try again, with the same exact callback as this one.
3390
-
3391
- return setTimeout(() => rimraf_(p, options, CB), busyTries * 100);
3392
- } // this one won't happen if graceful-fs is used.
3393
-
3394
-
3395
- if (er.code === "EMFILE" && timeout < options.emfileWait) {
3396
- return setTimeout(() => rimraf_(p, options, CB), timeout++);
3397
- } // already gone
3398
-
3399
-
3400
- if (er.code === "ENOENT") er = null;
3401
- }
3402
-
3403
- timeout = 0;
3404
- next(er);
3405
- };
3406
-
3407
- rimraf_(p, options, CB);
3408
- });
3409
- };
3410
-
3411
- if (options.disableGlob || !glob.hasMagic(p)) return afterGlob(null, [p]);
3412
- options.lstat(p, (er, stat) => {
3413
- if (!er) return afterGlob(null, [p]);
3414
- glob(p, options.glob, afterGlob);
3415
- });
3416
- }; // Two possible strategies.
3417
- // 1. Assume it's a file. unlink it, then do the dir stuff on EPERM or EISDIR
3418
- // 2. Assume it's a directory. readdir, then do the file stuff on ENOTDIR
3419
- //
3420
- // Both result in an extra syscall when you guess wrong. However, there
3421
- // are likely far more normal files in the world than directories. This
3422
- // is based on the assumption that a the average number of files per
3423
- // directory is >= 1.
3424
- //
3425
- // If anyone ever complains about this, then I guess the strategy could
3426
- // be made configurable somehow. But until then, YAGNI.
3427
-
3428
-
3429
- const rimraf_ = (p, options, cb) => {
3430
- assert(p);
3431
- assert(options);
3432
- assert(typeof cb === 'function'); // sunos lets the root user unlink directories, which is... weird.
3433
- // so we have to lstat here and make sure it's not a dir.
3434
-
3435
- options.lstat(p, (er, st) => {
3436
- if (er && er.code === "ENOENT") return cb(null); // Windows can EPERM on stat. Life is suffering.
3437
-
3438
- if (er && er.code === "EPERM" && isWindows) fixWinEPERM(p, options, er, cb);
3439
- if (st && st.isDirectory()) return rmdir(p, options, er, cb);
3440
- options.unlink(p, er => {
3441
- if (er) {
3442
- if (er.code === "ENOENT") return cb(null);
3443
- if (er.code === "EPERM") return isWindows ? fixWinEPERM(p, options, er, cb) : rmdir(p, options, er, cb);
3444
- if (er.code === "EISDIR") return rmdir(p, options, er, cb);
3445
- }
3446
-
3447
- return cb(er);
3448
- });
3449
- });
3450
- };
3451
-
3452
- const fixWinEPERM = (p, options, er, cb) => {
3453
- assert(p);
3454
- assert(options);
3455
- assert(typeof cb === 'function');
3456
- options.chmod(p, 0o666, er2 => {
3457
- if (er2) cb(er2.code === "ENOENT" ? null : er);else options.stat(p, (er3, stats) => {
3458
- if (er3) cb(er3.code === "ENOENT" ? null : er);else if (stats.isDirectory()) rmdir(p, options, er, cb);else options.unlink(p, cb);
3459
- });
3460
- });
3461
- };
3462
-
3463
- const fixWinEPERMSync = (p, options, er) => {
3464
- assert(p);
3465
- assert(options);
3466
-
3467
- try {
3468
- options.chmodSync(p, 0o666);
3469
- } catch (er2) {
3470
- if (er2.code === "ENOENT") return;else throw er;
3471
- }
3472
-
3473
- let stats;
3474
-
3475
- try {
3476
- stats = options.statSync(p);
3477
- } catch (er3) {
3478
- if (er3.code === "ENOENT") return;else throw er;
3479
- }
3480
-
3481
- if (stats.isDirectory()) rmdirSync(p, options, er);else options.unlinkSync(p);
3482
- };
3483
-
3484
- const rmdir = (p, options, originalEr, cb) => {
3485
- assert(p);
3486
- assert(options);
3487
- assert(typeof cb === 'function'); // try to rmdir first, and only readdir on ENOTEMPTY or EEXIST (SunOS)
3488
- // if we guessed wrong, and it's not a directory, then
3489
- // raise the original error.
3490
-
3491
- options.rmdir(p, er => {
3492
- if (er && (er.code === "ENOTEMPTY" || er.code === "EEXIST" || er.code === "EPERM")) rmkids(p, options, cb);else if (er && er.code === "ENOTDIR") cb(originalEr);else cb(er);
3493
- });
3494
- };
3495
-
3496
- const rmkids = (p, options, cb) => {
3497
- assert(p);
3498
- assert(options);
3499
- assert(typeof cb === 'function');
3500
- options.readdir(p, (er, files) => {
3501
- if (er) return cb(er);
3502
- let n = files.length;
3503
- if (n === 0) return options.rmdir(p, cb);
3504
- let errState;
3505
- files.forEach(f => {
3506
- rimraf$1(path.join(p, f), options, er => {
3507
- if (errState) return;
3508
- if (er) return cb(errState = er);
3509
- if (--n === 0) options.rmdir(p, cb);
3510
- });
3511
- });
3512
- });
3513
- }; // this looks simpler, and is strictly *faster*, but will
3514
- // tie up the JavaScript thread and fail on excessively
3515
- // deep directory trees.
3516
-
3517
-
3518
- const rimrafSync = (p, options) => {
3519
- options = options || {};
3520
- defaults(options);
3521
- assert(p, 'rimraf: missing path');
3522
- assert.equal(typeof p, 'string', 'rimraf: path should be a string');
3523
- assert(options, 'rimraf: missing options');
3524
- assert.equal(typeof options, 'object', 'rimraf: options should be object');
3525
- let results;
3526
-
3527
- if (options.disableGlob || !glob.hasMagic(p)) {
3528
- results = [p];
3529
- } else {
3530
- try {
3531
- options.lstatSync(p);
3532
- results = [p];
3533
- } catch (er) {
3534
- results = glob.sync(p, options.glob);
3535
- }
3536
- }
3537
-
3538
- if (!results.length) return;
3539
-
3540
- for (let i = 0; i < results.length; i++) {
3541
- const p = results[i];
3542
- let st;
3543
-
3544
- try {
3545
- st = options.lstatSync(p);
3546
- } catch (er) {
3547
- if (er.code === "ENOENT") return; // Windows can EPERM on stat. Life is suffering.
3548
-
3549
- if (er.code === "EPERM" && isWindows) fixWinEPERMSync(p, options, er);
3550
- }
3551
-
3552
- try {
3553
- // sunos lets the root user unlink directories, which is... weird.
3554
- if (st && st.isDirectory()) rmdirSync(p, options, null);else options.unlinkSync(p);
3555
- } catch (er) {
3556
- if (er.code === "ENOENT") return;
3557
- if (er.code === "EPERM") return isWindows ? fixWinEPERMSync(p, options, er) : rmdirSync(p, options, er);
3558
- if (er.code !== "EISDIR") throw er;
3559
- rmdirSync(p, options, er);
3560
- }
3561
- }
3562
- };
3563
-
3564
- const rmdirSync = (p, options, originalEr) => {
3565
- assert(p);
3566
- assert(options);
3567
-
3568
- try {
3569
- options.rmdirSync(p);
3570
- } catch (er) {
3571
- if (er.code === "ENOENT") return;
3572
- if (er.code === "ENOTDIR") throw originalEr;
3573
- if (er.code === "ENOTEMPTY" || er.code === "EEXIST" || er.code === "EPERM") rmkidsSync(p, options);
3574
- }
3575
- };
3576
-
3577
- const rmkidsSync = (p, options) => {
3578
- assert(p);
3579
- assert(options);
3580
- options.readdirSync(p).forEach(f => rimrafSync(path.join(p, f), options)); // We only end up here once we got ENOTEMPTY at least once, and
3581
- // at this point, we are guaranteed to have removed all the kids.
3582
- // So, we know that it won't be ENOENT or ENOTDIR or anything else.
3583
- // try really hard to delete stuff on windows, because it has a
3584
- // PROFOUNDLY annoying habit of not closing handles promptly when
3585
- // files are deleted, resulting in spurious ENOTEMPTY errors.
3586
-
3587
- const retries = isWindows ? 100 : 1;
3588
- let i = 0;
3589
-
3590
- do {
3591
- let threw = true;
3592
-
3593
- try {
3594
- const ret = options.rmdirSync(p, options);
3595
- threw = false;
3596
- return ret;
3597
- } finally {
3598
- if (++i < retries && threw) continue;
3599
- }
3600
- } while (true);
3601
- };
3602
-
3603
- var rimraf_1 = rimraf$1;
3604
- rimraf$1.sync = rimrafSync;
3605
- const formatHost = {
3606
- getCurrentDirectory: () => ts__default["default"].sys.getCurrentDirectory(),
3607
- getNewLine: () => ts__default["default"].sys.newLine,
3608
- getCanonicalFileName: ts__default["default"].sys.useCaseSensitiveFileNames ? f => f : f => f.toLowerCase()
3609
- };
3610
-
3611
- async function _buildTypes(options) {
3612
- const {
3613
- outDir,
3614
- tsconfig
3615
- } = options;
3616
-
3617
- const compilerOptions = _objectSpread(_objectSpread({}, tsconfig.options), {}, {
3618
- declaration: true,
3619
- declarationDir: outDir,
3620
- emitDeclarationOnly: true,
3621
- noEmit: false,
3622
- outDir
3623
- });
3624
-
3625
- const program = ts__default["default"].createProgram(tsconfig.fileNames, compilerOptions);
3626
- const emitResult = program.emit();
3627
- const allDiagnostics = ts__default["default"].getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
3628
- allDiagnostics.forEach(diagnostic => {
3629
- if (diagnostic.file && diagnostic.start) {
3630
- const {
3631
- line,
3632
- character
3633
- } = ts__default["default"].getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
3634
- const message = ts__default["default"].flattenDiagnosticMessageText(diagnostic.messageText, "\n");
3635
- console.log("".concat(diagnostic.file.fileName, " ").concat(line + 1, ":").concat(character + 1, "\n").concat(message));
3636
- } else {
3637
- console.log(ts__default["default"].flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
3638
- }
3639
- });
3640
-
3641
- if (emitResult.emitSkipped) {
3642
- const errors = allDiagnostics.filter(diag => diag.category === ts__default["default"].DiagnosticCategory.Error);
3643
-
3644
- if (errors.length) {
3645
- console.error(ts__default["default"].formatDiagnostics(errors, formatHost));
3646
- throw new Error("failed to compile");
3647
- }
3648
- }
3649
- }
3650
-
3651
- class _DtsError extends Error {
3652
- constructor(message, messages) {
3653
- super(message);
3654
- this.messages = messages;
3655
- }
3656
-
3657
- }
3658
-
3659
- function _createApiExtractorConfig(options) {
3660
- const {
3661
- distPath,
3662
- exportPath,
3663
- filePath,
3664
- messages,
3665
- projectFolder,
3666
- mainEntryPointFilePath,
3667
- tsconfigPath
3668
- } = options;
3669
- return {
3670
- apiReport: {
3671
- enabled: false,
3672
- reportFileName: "<unscopedPackageName>.api.md"
3673
- },
3674
- compiler: {
3675
- tsconfigFilePath: tsconfigPath
3676
- },
3677
- docModel: {
3678
- enabled: false,
3679
- apiJsonFilePath: path__default["default"].resolve(distPath, "".concat(exportPath, ".api.json"))
3680
- },
3681
- dtsRollup: {
3682
- enabled: true,
3683
- untrimmedFilePath: path__default["default"].resolve(distPath, filePath)
3684
- },
3685
- tsdocMetadata: {
3686
- enabled: false
3687
- },
3688
- messages,
3689
- mainEntryPointFilePath,
3690
- projectFolder
3691
- };
3692
- }
3693
-
3694
- async function _createTSDocConfig(opts) {
3695
- const {
3696
- customTags
3697
- } = opts;
3698
-
3699
- if (customTags.length === 0) {
3700
- return void 0;
3701
- }
3702
-
3703
- const tsDocBaseBuf = await fs$2.readFile(require.resolve("@microsoft/api-extractor/extends/tsdoc-base.json"));
3704
- const tsDocBaseConfig = jsoncParser.parse(tsDocBaseBuf.toString());
3705
- const tagDefinitions = (tsDocBaseConfig.tagDefinitions || []).concat(customTags.map(t => ({
3706
- tagName: "@".concat(t.name),
3707
- syntaxKind: t.syntaxKind,
3708
- allowMultiple: t.allowMultiple
3709
- })));
3710
-
3711
- const supportForTags = _objectSpread({}, tsDocBaseConfig.supportForTags);
3712
-
3713
- for (const customTag of customTags) {
3714
- supportForTags["@".concat(customTag.name)] = true;
3715
- }
3716
-
3717
- return tsdocConfig.TSDocConfigFile.loadFromObject(_objectSpread(_objectSpread({}, tsDocBaseConfig), {}, {
3718
- noStandardTags: false,
3719
- tagDefinitions,
3720
- supportForTags
3721
- }));
3722
- }
3723
-
3724
- const _LOG_LEVELS = {
3725
- error: "error",
3726
- info: "info",
3727
- off: "none",
3728
- warn: "warning"
3729
- };
3730
-
3731
- async function _extractTypes(options) {
3732
- const {
3733
- distPath,
3734
- exportPath,
3735
- files,
3736
- filePath,
3737
- projectPath,
3738
- rules,
3739
- sourceTypesPath,
3740
- tsconfigPath
3741
- } = options;
3742
- const tsdocConfigFile = await _createTSDocConfig({
3743
- customTags: []
3744
- });
3745
-
3746
- function _ruleToLogLevel(key, defaultLevel) {
3747
- const r = rules == null ? void 0 : rules[key];
3748
- return r ? _LOG_LEVELS[r] : defaultLevel || "warning";
3749
- }
3750
-
3751
- const messagesConfig = {
3752
- compilerMessageReporting: {
3753
- default: {
3754
- logLevel: "warning"
3755
- }
3756
- },
3757
- extractorMessageReporting: {
3758
- default: {
3759
- logLevel: "warning",
3760
- addToApiReportFile: false
3761
- },
3762
- "ae-forgotten-export": {
3763
- logLevel: _ruleToLogLevel("ae-forgotten-export", "error"),
3764
- addToApiReportFile: false
3765
- },
3766
- "ae-incompatible-release-tags": {
3767
- logLevel: _ruleToLogLevel("ae-incompatible-release-tags", "error"),
3768
- addToApiReportFile: false
3769
- },
3770
- "ae-internal-missing-underscore": {
3771
- logLevel: _ruleToLogLevel("ae-internal-missing-underscore"),
3772
- addToApiReportFile: false
3773
- },
3774
- "ae-missing-release-tag": {
3775
- logLevel: _ruleToLogLevel("ae-missing-release-tag", "error"),
3776
- addToApiReportFile: false
3777
- },
3778
- "ae-wrong-input-file-type": {
3779
- logLevel: "none",
3780
- addToApiReportFile: false
3781
- }
3782
- },
3783
- tsdocMessageReporting: {
3784
- default: {
3785
- logLevel: "warning",
3786
- addToApiReportFile: false
3787
- }
3788
- }
3789
- };
3790
- const extractorConfig = apiExtractor.ExtractorConfig.prepare({
3791
- configObject: _createApiExtractorConfig({
3792
- distPath,
3793
- exportPath,
3794
- filePath,
3795
- messages: messagesConfig,
3796
- projectFolder: projectPath,
3797
- mainEntryPointFilePath: sourceTypesPath,
3798
- tsconfigPath
3799
- }),
3800
- configObjectFullPath: void 0,
3801
- tsdocConfigFile,
3802
- packageJsonFullPath: path__default["default"].resolve(projectPath, "package.json")
3803
- });
3804
- const messages = [];
3805
- const extractorResult = apiExtractor.Extractor.invoke(extractorConfig, {
3806
- localBuild: true,
3807
- showVerboseMessages: true,
3808
-
3809
- messageCallback(message) {
3810
- messages.push(message);
3811
- message.handled = true;
3812
- }
3813
-
3814
- });
3815
- const typesPath = path__default["default"].resolve(distPath, filePath);
3816
- const typesBuf = await fs__default$1["default"].readFile(typesPath);
3817
- const prettierConfig = await prettier__default["default"].resolveConfig(typesPath);
3818
- await mkdirp__default["default"](path__default["default"].dirname(typesPath));
3819
- await fs__default$1["default"].writeFile(typesPath, prettier__default["default"].format(typesBuf.toString(), _objectSpread(_objectSpread({}, prettierConfig), {}, {
3820
- filepath: typesPath
3821
- })));
3822
- files.push({
3823
- type: "types",
3824
- path: typesPath
3825
- });
3826
- return {
3827
- extractorResult,
3828
- messages
3829
- };
3830
- }
3831
-
3832
- const rimraf = require$$3$1.promisify(rimraf_1);
3833
-
3834
- async function _doExtract(ctx, task) {
3835
- var _a;
3836
-
3837
- const {
3838
- config,
3839
- cwd,
3840
- files,
3841
- ts
3842
- } = ctx;
3843
-
3844
- if (!ts.config || !ts.configPath) {
3845
- return {
3846
- type: "dts",
3847
- messages: [],
3848
- results: []
3849
- };
3850
- }
3851
-
3852
- const {
3853
- outDir,
3854
- rootDir = cwd
3855
- } = ts.config.options;
3856
-
3857
- if (!outDir) {
3858
- throw new Error("tsconfig.json is missing `compilerOptions.outDir`");
3859
- }
3860
-
3861
- const tmpPath = path__default["default"].resolve(outDir, "__tmp__");
3862
- await _buildTypes({
3863
- cwd,
3864
- outDir: tmpPath,
3865
- tsconfig: ts.config
3866
- });
3867
- const messages = [];
3868
- const results = [];
3869
-
3870
- for (const entry of task.entries) {
3871
- const exportPath = entry.exportPath === "." ? "./index" : entry.exportPath;
3872
- const sourceTypesPath = path__default["default"].resolve(tmpPath, path__default["default"].relative(rootDir, path__default["default"].resolve(cwd, entry.sourcePath)).replace(/\.ts$/, ".d.ts"));
3873
- const targetPath = path__default["default"].resolve(cwd, entry.targetPath);
3874
- const result = await _extractTypes({
3875
- cwd,
3876
- exportPath,
3877
- files,
3878
- filePath: path__default["default"].relative(outDir, targetPath),
3879
- projectPath: cwd,
3880
- rules: (_a = config == null ? void 0 : config.extract) == null ? void 0 : _a.rules,
3881
- sourceTypesPath,
3882
- tsconfigPath: path__default["default"].resolve(cwd, ts.configPath || "tsconfig.json"),
3883
- distPath: outDir
3884
- });
3885
- messages.push(...result.messages);
3886
-
3887
- if (result.messages.some(msg => msg.logLevel === "error")) {
3888
- await rimraf(tmpPath);
3889
- throw new _DtsError("encountered errors when extracting types", result.messages);
3890
- }
3891
-
3892
- results.push({
3893
- sourcePath: path__default["default"].resolve(cwd, entry.sourcePath),
3894
- filePath: targetPath
3895
- });
3896
- }
3897
-
3898
- await rimraf(tmpPath);
3899
- return {
3900
- type: "dts",
3901
- messages,
3902
- results
3903
- };
3904
- }
3905
-
3906
- const _dtsTask = {
3907
- name: (_ctx, task) => ["build type definitions", ...task.entries.map(entry => " ".concat(chalk__default["default"].blue(entry.importId), ": ").concat(entry.sourcePath, " -> ").concat(entry.targetPath))].join("\n"),
3908
- exec: (ctx, task) => {
3909
- return new rxjs.Observable(observer => {
3910
- _doExtract(ctx, task).then(result => {
3911
- observer.next(result);
3912
- observer.complete();
3913
- }).catch(err => {
3914
- observer.error(err);
3915
- });
3916
- });
3917
- },
3918
- complete: (ctx, _task, result) => {
3919
- _printExtractMessages(ctx, result.messages);
3920
- },
3921
- error: (ctx, _task, err) => {
3922
- const {
3923
- logger
3924
- } = ctx;
3925
-
3926
- if (err instanceof _DtsError) {
3927
- _printExtractMessages(ctx, err.messages);
3928
- } else if (err instanceof Error) {
3929
- logger.error(err);
3930
- }
3931
- }
3932
- };
3933
- const _dtsWatchTask = {
3934
- name: (_ctx, task) => ["build type definitions", ...task.entries.map(entry => " ".concat(chalk__default["default"].blue(entry.importId), ": ").concat(entry.sourcePath, " -> ").concat(entry.targetPath))].join("\n"),
3935
- exec: (ctx, task) => {
3936
- return new rxjs.Observable(observer => {
3937
- _doExtract(ctx, task).then(result => {
3938
- observer.next(result);
3939
- observer.complete();
3940
- }).catch(err => observer.error(err));
3941
- });
3942
- },
3943
- complete: (ctx, _task, result) => {
3944
- const {
3945
- logger
3946
- } = ctx;
3947
-
3948
- _printExtractMessages(ctx, result.messages);
3949
-
3950
- logger.warn("watching typescript definitions is currently not supported");
3951
- logger.log();
3952
- },
3953
- error: (ctx, _task, err) => {
3954
- const {
3955
- logger
3956
- } = ctx;
3957
-
3958
- if (err instanceof _DtsError) {
3959
- _printExtractMessages(ctx, err.messages);
3960
- } else if (err instanceof Error) {
3961
- logger.error(err);
3962
- }
3963
- }
3964
- };
3965
-
3966
- function _resolveRollupConfig(ctx, buildTask) {
3967
- var _ref, _ref3, _ref4, _ref5, _ref6, _ref7;
3968
-
3969
- var _a;
3970
-
3971
- const {
3972
- format,
3973
- runtime,
3974
- target
3975
- } = buildTask;
3976
- const {
3977
- config,
3978
- cwd,
3979
- exports: _exports,
3980
- external,
3981
- distPath,
3982
- logger,
3983
- pkg,
3984
- ts
3985
- } = ctx;
3986
- const outputExt = _resolveBuildContext._MODULE_EXT[pkg.type][format];
3987
- const minify = (_ref = config == null ? void 0 : config.minify) !== null && _ref !== void 0 ? _ref : true;
3988
- const outDir = path__default["default"].relative(cwd, distPath);
3989
- const pathAliases = Object.fromEntries(Object.entries(((_a = ts.config) == null ? void 0 : _a.options.paths) || {}).map(_ref2 => {
3990
- let [key, val] = _ref2;
3991
-
3992
- var _a2;
3993
-
3994
- return [key, path__default["default"].resolve(cwd, ((_a2 = ts.config) == null ? void 0 : _a2.options.baseUrl) || ".", val[0])];
3995
- }));
3996
- const entries = buildTask.entries.map(entry => {
3997
- return _objectSpread(_objectSpread({}, entry), {}, {
3998
- name: path__default["default"].relative(outDir, entry.output).replace(/\.[^/.]+$/, "")
3999
- });
4000
- }, {});
4001
-
4002
- const exportIds = _exports && Object.keys(_exports).map(exportPath => path__default["default"].join(pkg.name, exportPath));
4003
-
4004
- const sourcePaths = _exports && Object.values(_exports).map(e => path__default["default"].resolve(cwd, e.source));
4005
-
4006
- return {
4007
- inputOptions: {
4008
- context: cwd,
4009
- external: (id, importer) => {
4010
- if (exportIds == null ? void 0 : exportIds.includes(id)) {
4011
- return true;
4012
- }
4013
-
4014
- if (importer && (id.startsWith(".") || id.startsWith("/"))) {
4015
- const idPath = path__default["default"].resolve(path__default["default"].dirname(importer), id);
4016
-
4017
- if (sourcePaths == null ? void 0 : sourcePaths.includes(idPath)) {
4018
- logger.warn("detected self-referencing import \u2013 treating as external: ".concat(path__default["default"].relative(cwd, idPath)));
4019
- return true;
4020
- }
4021
- }
4022
-
4023
- const idParts = id.split("/");
4024
- const name = idParts[0].startsWith("@") ? "".concat(idParts[0], "/").concat(idParts[1]) : idParts[0];
4025
-
4026
- if (name && external.includes(name)) {
4027
- return true;
4028
- }
4029
-
4030
- return false;
4031
- },
4032
- input: entries.reduce((acc, entry) => {
4033
- return _objectSpread(_objectSpread({}, acc), {}, {
4034
- [entry.name]: entry.source
4035
- });
4036
- }, {}),
4037
-
4038
- onwarn(warning, rollupWarn) {
4039
- if (!warning.code || !["CIRCULAR_DEPENDENCY"].includes(warning.code)) {
4040
- rollupWarn(warning);
4041
- }
4042
- },
4043
-
4044
- plugins: [replace__default["default"]({
4045
- preventAssignment: true,
4046
- values: _objectSpread({}, pkg.name === "@sanity/pkg-utils" ? {} : {
4047
- "process.env.PKG_FILE_PATH": arg => {
4048
- const sourcePath = "./" + path__default["default"].relative(cwd, arg);
4049
- const entry = entries.find(e => e.source === sourcePath);
4050
-
4051
- if (!entry) {
4052
- throw new Error("could not find source entry: ".concat(sourcePath));
4053
- }
4054
-
4055
- return JSON.stringify(path__default["default"].relative(cwd, path__default["default"].resolve(outDir, entry.name + outputExt)));
4056
- },
4057
- "process.env.PKG_FORMAT": JSON.stringify(format),
4058
- "process.env.PKG_RUNTIME": JSON.stringify(runtime),
4059
- "process.env.PKG_VERSION": JSON.stringify(process.env.PKG_VERSION || pkg.version)
4060
- })
4061
- }), alias__default["default"]({
4062
- entries: _objectSpread({}, pathAliases)
4063
- }), pluginNodeResolve.nodeResolve({
4064
- browser: runtime === "browser",
4065
- extensions: [".cjs", ".mjs", ".js", ".jsx", ".json", ".node"],
4066
- preferBuiltins: true
4067
- }), commonjs__default["default"]({
4068
- esmExternals: false,
4069
- extensions: [".js"]
4070
- }), json__default["default"](), esbuild__default["default"]({
4071
- jsx: (_ref3 = config == null ? void 0 : config.jsx) !== null && _ref3 !== void 0 ? _ref3 : "automatic",
4072
- jsxFactory: (_ref4 = config == null ? void 0 : config.jsxFactory) !== null && _ref4 !== void 0 ? _ref4 : "createElement",
4073
- jsxFragment: (_ref5 = config == null ? void 0 : config.jsxFragment) !== null && _ref5 !== void 0 ? _ref5 : "Fragment",
4074
- jsxImportSource: (_ref6 = config == null ? void 0 : config.jsxImportSource) !== null && _ref6 !== void 0 ? _ref6 : "react",
4075
- target,
4076
- tsconfig: ctx.ts.configPath || "tsconfig.json"
4077
- }), pluginBabel.getBabelOutputPlugin({
4078
- babelrc: false,
4079
- plugins: ["@babel/plugin-proposal-object-rest-spread"],
4080
- presets: [["@babel/preset-env", {
4081
- targets: pkg.browserslist || _resolveBuildContext._DEFAULTS.browserslist
4082
- }]]
4083
- }), minify && rollupPluginTerser.terser({
4084
- output: {
4085
- comments: (_node, comment) => {
4086
- const text = comment.value;
4087
- const type = comment.type;
4088
-
4089
- if (type == "comment2") {
4090
- return /@preserve|@license|@cc_on/i.test(text);
4091
- }
4092
-
4093
- return false;
4094
- }
4095
- }
4096
- })].filter(Boolean),
4097
- treeshake: {
4098
- propertyReadSideEffects: false
4099
- }
4100
- },
4101
- outputOptions: {
4102
- chunkFileNames: () => "_chunks/[name]-[hash]".concat(outputExt),
4103
- dir: outDir,
4104
- entryFileNames: () => outputExt === ".esm.js" ? "[name].js" : "[name]".concat(outputExt),
4105
- format,
4106
- exports: "auto",
4107
- sourcemap: (_ref7 = config == null ? void 0 : config.sourcemap) !== null && _ref7 !== void 0 ? _ref7 : true
4108
- }
4109
- };
4110
- }
4111
-
4112
- const _rollupTask = {
4113
- name: (ctx, task) => "build javascript files (target ".concat(task.target.join(" + "), ", format ").concat(task.format, ")\n ").concat(task.entries.map(e => "".concat(chalk__default["default"].blue(path__default["default"].join(ctx.pkg.name, e.path)), ": ").concat(e.source, " -> ").concat(e.output)).join("\n ")),
4114
- exec: (ctx, task) => {
4115
- return new rxjs.Observable(observer => {
4116
- _execPromise(ctx, task).then(result => {
4117
- observer.next(result);
4118
- observer.complete();
4119
- }).catch(err => observer.error(err));
4120
- });
4121
- },
4122
- complete: () => {},
4123
- error: (_ctx, _task, err) => {
4124
- if (err instanceof Error) {
4125
- console.log(err);
4126
- }
4127
- }
4128
- };
4129
-
4130
- async function _execPromise(ctx, task) {
4131
- const {
4132
- files,
4133
- distPath
4134
- } = ctx;
4135
- const outDir = path__default["default"].relative(ctx.cwd, distPath);
4136
-
4137
- const {
4138
- inputOptions,
4139
- outputOptions
4140
- } = _resolveRollupConfig(ctx, task);
4141
-
4142
- const bundle = await rollup.rollup(inputOptions);
4143
- const {
4144
- output
4145
- } = await bundle.generate(outputOptions);
4146
-
4147
- for (const chunkOrAsset of output) {
4148
- if (chunkOrAsset.type === "asset") {
4149
- files.push({
4150
- type: "asset",
4151
- path: path__default["default"].resolve(outDir, chunkOrAsset.fileName)
4152
- });
4153
- } else {
4154
- files.push({
4155
- type: "chunk",
4156
- path: path__default["default"].resolve(outDir, chunkOrAsset.fileName)
4157
- });
4158
- }
4159
- }
4160
-
4161
- await bundle.write(outputOptions);
4162
- await bundle.close();
4163
- }
4164
-
4165
- const _rollupWatchTask = {
4166
- name: (ctx, task) => "build javascript files (target ".concat(task.target.join(" + "), ", format ").concat(task.format, ")\n ").concat(task.entries.map(e => "".concat(chalk__default["default"].blue(path__default["default"].join(ctx.pkg.name, e.path)), ": ").concat(e.source, " -> ").concat(e.output)).join("\n ")),
4167
- exec: (ctx, task) => {
4168
- const {
4169
- inputOptions,
4170
- outputOptions
4171
- } = _resolveRollupConfig(ctx, task);
4172
-
4173
- return new rxjs.Observable(observer => {
4174
- const watchOptions = _objectSpread(_objectSpread({}, inputOptions), {}, {
4175
- output: outputOptions
4176
- });
4177
-
4178
- const watcher = rollup.watch(watchOptions);
4179
- watcher.on("event", event => {
4180
- observer.next(event);
4181
- });
4182
- return () => {
4183
- watcher.close();
4184
- };
4185
- });
4186
- },
4187
- complete: (ctx, task, event) => {
4188
- const {
4189
- logger
4190
- } = ctx;
4191
-
4192
- if (event.code === "BUNDLE_END") {
4193
- logger.success("build javascript files (target ".concat(task.target.join(" + "), ", format ").concat(task.format, ")\n ").concat(task.entries.map(e => "".concat(chalk__default["default"].blue(path__default["default"].join(ctx.pkg.name, e.path)), ": ").concat(e.source, " -> ").concat(e.output)).join("\n ")));
4194
- logger.log("");
4195
- return;
4196
- }
4197
-
4198
- if (event.code === "BUNDLE_START") {
4199
- return;
4200
- }
4201
-
4202
- if (event.code === "END") {
4203
- return;
4204
- }
4205
-
4206
- if (event.code === "ERROR") {
4207
- logger.error(event.code, event);
4208
- return;
4209
- }
4210
-
4211
- if (event.code === "START") {
4212
- return;
4213
- }
4214
- },
4215
- error: (ctx, _task, err) => {
4216
- const {
4217
- logger
4218
- } = ctx;
4219
-
4220
- if (err instanceof Error) {
4221
- logger.log(err);
4222
- }
4223
- }
4224
- };
4225
- const _buildTaskHandlers = {
4226
- "build:dts": _dtsTask,
4227
- "build:js": _rollupTask
4228
- };
4229
- const _watchTaskHandlers = {
4230
- "watch:dts": _dtsWatchTask,
4231
- "watch:js": _rollupWatchTask
4232
- };
4233
- exports._buildTaskHandlers = _buildTaskHandlers;
4234
- exports._dtsTask = _dtsTask;
4235
- exports._dtsWatchTask = _dtsWatchTask;
4236
- exports._rollupTask = _rollupTask;
4237
- exports._rollupWatchTask = _rollupWatchTask;
4238
- exports._watchTaskHandlers = _watchTaskHandlers;
4239
- //# sourceMappingURL=index-4a1fe6d6.js.map