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