jiek 0.4.7-alpha.1 → 0.4.7-alpha.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. package/bin/jiek.js +7 -4
  2. package/dist/cli.cjs +5028 -0
  3. package/dist/cli.js +4274 -92
  4. package/dist/cli.min.cjs +19 -0
  5. package/dist/cli.min.js +19 -1
  6. package/dist/index.cjs +5 -0
  7. package/dist/index.js +1 -3
  8. package/dist/index.min.cjs +1 -0
  9. package/dist/index.min.js +1 -1
  10. package/dist/rollup/index.cjs +4669 -0
  11. package/dist/rollup/index.js +4178 -65
  12. package/dist/rollup/index.min.cjs +19 -0
  13. package/dist/rollup/index.min.js +19 -1
  14. package/package.json +13 -11
  15. package/src/commands/base.ts +1 -2
  16. package/src/commands/build.ts +3 -0
  17. package/src/rollup/index.ts +2 -2
  18. package/src/utils/filterSupport.ts +2 -0
  19. package/dist/cli.d.mts.map +0 -1
  20. package/dist/cli.d.ts.map +0 -1
  21. package/dist/cli.js.map +0 -1
  22. package/dist/cli.min.js.map +0 -1
  23. package/dist/cli.min.mjs +0 -1
  24. package/dist/cli.min.mjs.map +0 -1
  25. package/dist/cli.mjs +0 -803
  26. package/dist/cli.mjs.map +0 -1
  27. package/dist/index.d.mts.map +0 -1
  28. package/dist/index.d.ts.map +0 -1
  29. package/dist/index.js.map +0 -1
  30. package/dist/index.min.js.map +0 -1
  31. package/dist/index.min.mjs +0 -1
  32. package/dist/index.min.mjs.map +0 -1
  33. package/dist/index.mjs +0 -3
  34. package/dist/index.mjs.map +0 -1
  35. package/dist/rollup/index.d.mts.map +0 -1
  36. package/dist/rollup/index.d.ts.map +0 -1
  37. package/dist/rollup/index.js.map +0 -1
  38. package/dist/rollup/index.min.js.map +0 -1
  39. package/dist/rollup/index.min.mjs +0 -1
  40. package/dist/rollup/index.min.mjs.map +0 -1
  41. package/dist/rollup/index.mjs +0 -551
  42. package/dist/rollup/index.mjs.map +0 -1
  43. package/src/pkg.ts +0 -1
  44. /package/dist/{cli.d.mts → cli.d.cts} +0 -0
  45. /package/dist/{index.d.mts → index.d.cts} +0 -0
  46. /package/dist/rollup/{index.d.mts → index.d.cts} +0 -0
package/dist/cli.cjs ADDED
@@ -0,0 +1,5028 @@
1
+ 'use strict';
2
+
3
+ var fs = require('node:fs');
4
+ var node_module = require('node:module');
5
+ var path = require('node:path');
6
+ var filterWorkspacePackages = require('@pnpm/filter-workspace-packages');
7
+ var commander = require('commander');
8
+ var jsYaml = require('js-yaml');
9
+ var getWorkspaceDir = require('@jiek/utils/getWorkspaceDir');
10
+ var cliProgress = require('cli-progress');
11
+ var execa = require('execa');
12
+ var detectIndent = require('detect-indent');
13
+ var inquirer = require('inquirer');
14
+ var jsoncParser = require('jsonc-parser');
15
+ var require$$0 = require('util');
16
+ var require$$0$1 = require('path');
17
+ var childProcess = require('node:child_process');
18
+ var bumper = require('@jiek/utils/bumper');
19
+ var entrypoints = require('@jiek/pkger/entrypoints');
20
+
21
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
22
+ function _interopNamespaceDefault(e) {
23
+ var n = Object.create(null);
24
+ if (e) {
25
+ Object.keys(e).forEach(function (k) {
26
+ if (k !== 'default') {
27
+ var d = Object.getOwnPropertyDescriptor(e, k);
28
+ Object.defineProperty(n, k, d.get ? d : {
29
+ enumerable: true,
30
+ get: function () { return e[k]; }
31
+ });
32
+ }
33
+ });
34
+ }
35
+ n.default = e;
36
+ return Object.freeze(n);
37
+ }
38
+
39
+ var childProcess__namespace = /*#__PURE__*/_interopNamespaceDefault(childProcess);
40
+
41
+ let root;
42
+ function getRoot() {
43
+ if (root)
44
+ return root;
45
+ const rootOption = commander.program.getOptionValue("root");
46
+ root = rootOption ? path.isAbsolute(rootOption) ? rootOption : path.resolve(process.cwd(), rootOption) : void 0;
47
+ return root;
48
+ }
49
+
50
+ let wd;
51
+ let notWorkspace = false;
52
+ function getWD() {
53
+ if (wd)
54
+ return { wd, notWorkspace };
55
+ const root = getRoot();
56
+ if (root !== void 0) {
57
+ const isWorkspace = getWorkspaceDir.isWorkspaceDir(root, type$1);
58
+ notWorkspace = !isWorkspace;
59
+ wd = root;
60
+ return { wd, notWorkspace };
61
+ }
62
+ try {
63
+ wd = getWorkspaceDir.getWorkspaceDir(type$1);
64
+ } catch (e) {
65
+ if ("message" in e && e.message === "workspace root not found") {
66
+ wd = root;
67
+ notWorkspace = true;
68
+ } else {
69
+ throw e;
70
+ }
71
+ }
72
+ return { wd, notWorkspace };
73
+ }
74
+
75
+ let type$1 = "";
76
+ try {
77
+ const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('cli.cjs', document.baseURI).href)));
78
+ require$1.resolve("@pnpm/filter-workspace-packages");
79
+ type$1 = "pnpm";
80
+ } catch {
81
+ }
82
+ if (type$1 !== "") {
83
+ commander.program.option("-f, --filter <filter>", "filter packages");
84
+ }
85
+ async function getSelectedProjectsGraph() {
86
+ let filter = commander.program.getOptionValue("filter");
87
+ const root = getRoot();
88
+ const { wd, notWorkspace } = getWD();
89
+ if (!notWorkspace && type$1 === "pnpm") {
90
+ const pnpmWorkspaceFilePath = path.resolve(wd, "pnpm-workspace.yaml");
91
+ const pnpmWorkspaceFileContent = fs.readFileSync(pnpmWorkspaceFilePath, "utf-8");
92
+ const pnpmWorkspace = jsYaml.load(pnpmWorkspaceFileContent);
93
+ if (root === wd && !filter) {
94
+ throw new Error("root path is workspace root, please provide a filter");
95
+ }
96
+ if (root !== wd && !filter) {
97
+ const packageJSONIsExist = fs.existsSync(path.resolve(root, "package.json"));
98
+ if (!packageJSONIsExist) {
99
+ throw new Error("root path is not workspace root, please provide a filter");
100
+ }
101
+ const packageJSON = JSON.parse(fs.readFileSync(path.resolve(root, "package.json"), "utf-8"));
102
+ if (!packageJSON.name) {
103
+ throw new Error("root path is not workspace root, please provide a filter");
104
+ }
105
+ filter = packageJSON.name;
106
+ }
107
+ const { selectedProjectsGraph } = await filterWorkspacePackages.filterPackagesFromDir(wd, [{
108
+ filter: filter ?? "",
109
+ followProdDepsOnly: true
110
+ }], {
111
+ prefix: root,
112
+ workspaceDir: wd,
113
+ patterns: pnpmWorkspace.packages
114
+ });
115
+ return {
116
+ wd,
117
+ root,
118
+ value: Object.entries(selectedProjectsGraph).reduce((acc, [key, value]) => {
119
+ acc[key] = value.package.manifest;
120
+ return acc;
121
+ }, {})
122
+ };
123
+ }
124
+ return {
125
+ wd,
126
+ root,
127
+ value: {
128
+ [wd]: JSON.parse(fs.readFileSync(path.resolve(wd, "package.json"), "utf-8"))
129
+ }
130
+ };
131
+ }
132
+
133
+ var name = "jiek";
134
+ var type = "module";
135
+ var version = "0.4.7-alpha.9";
136
+ var description = "YiJie's personal kits.";
137
+ var bin = {
138
+ jiek: "bin/jiek.js",
139
+ jk: "bin/jiek.js"
140
+ };
141
+ var files = [
142
+ "dist",
143
+ "src",
144
+ "bin",
145
+ "LICENSE",
146
+ "README.md"
147
+ ];
148
+ var typesVersions = {
149
+ "<5.0": {
150
+ "*": [
151
+ "*",
152
+ "./dist/*",
153
+ "./dist/*/index.d.ts"
154
+ ]
155
+ }
156
+ };
157
+ var exports$1 = {
158
+ "./package.json": "./package.json",
159
+ ".": "./src/index.ts",
160
+ "./cli": "./src/cli.ts",
161
+ "./rollup": "./src/rollup/index.ts"
162
+ };
163
+ var imports = {
164
+ "#~/*": "./src/*"
165
+ };
166
+ var dependencies = {
167
+ "@jiek/pkger": "workspace:^",
168
+ "@jiek/rollup-plugin-dts": "^6.1.1",
169
+ "@jiek/utils": "workspace:^",
170
+ "@rollup/plugin-commonjs": "^28.0.0",
171
+ "@rollup/plugin-json": "^6.0.1",
172
+ "@rollup/plugin-node-resolve": "^15.3.0",
173
+ "@rollup/plugin-terser": "^0.4.4",
174
+ autoprefixer: "^10.4.16",
175
+ "cli-progress": "^3.12.0",
176
+ commander: "^12.0.0",
177
+ "detect-indent": "^6.1.0",
178
+ execa: "9.3.1",
179
+ inquirer: "^8.2.6",
180
+ "js-yaml": "^4.1.0",
181
+ "jsonc-parser": "^3.2.1",
182
+ rollup: "^4.1.5",
183
+ "rollup-plugin-copy": "^3.5.0",
184
+ "rollup-plugin-esbuild": "^6.1.0",
185
+ typescript: "^5.0.0"
186
+ };
187
+ var optionalDependencies = {
188
+ "@pnpm/filter-workspace-packages": "^7.2.13",
189
+ "esbuild-register": "^3.5.0",
190
+ postcss: "^8.4.47",
191
+ "rollup-plugin-postcss": "^4.0.2"
192
+ };
193
+ var devDependencies = {
194
+ "@npm/types": "^1.0.2",
195
+ "@pnpm/filter-workspace-packages": "^7.2.13",
196
+ "@pnpm/workspace.pkgs-graph": "^2.0.15",
197
+ "@types/cli-progress": "^3.11.5",
198
+ "@types/inquirer": "^9.0.7",
199
+ "@types/js-yaml": "^4.0.9",
200
+ "@types/micromatch": "^4.0.6",
201
+ "esbuild-register": "^3.5.0",
202
+ micromatch: "^4.0.5",
203
+ "node-sass": "^9.0.0",
204
+ postcss: "^8.4.47",
205
+ "rollup-plugin-postcss": "^4.0.2"
206
+ };
207
+ var pkg = {
208
+ name: name,
209
+ type: type,
210
+ version: version,
211
+ description: description,
212
+ bin: bin,
213
+ files: files,
214
+ typesVersions: typesVersions,
215
+ exports: exports$1,
216
+ imports: imports,
217
+ dependencies: dependencies,
218
+ optionalDependencies: optionalDependencies,
219
+ devDependencies: devDependencies
220
+ };
221
+
222
+ commander.program.version(pkg.version).description(pkg.description).option("--root <root>", "root path").option("-c, --config-path <configPath>", "config path");
223
+
224
+ let resolve;
225
+ function actionDone() {
226
+ resolve();
227
+ }
228
+ function actionRestore() {
229
+ new Promise((r) => resolve = r);
230
+ }
231
+
232
+ function packageIsExist(name) {
233
+ try {
234
+ require.resolve(name);
235
+ return true;
236
+ } catch (e) {
237
+ return false;
238
+ }
239
+ }
240
+ let tsRegisterName;
241
+ const registers = [
242
+ process.env.JIEK_TS_REGISTER,
243
+ "esbuild-register",
244
+ "@swc-node/register",
245
+ "ts-node/register"
246
+ ].filter(Boolean);
247
+ for (const register of registers) {
248
+ if (packageIsExist(register)) {
249
+ tsRegisterName = register;
250
+ break;
251
+ }
252
+ }
253
+
254
+ let configName = "jiek.config";
255
+ function getConfigPath(root, dir) {
256
+ const isSupportTsLoader = !!tsRegisterName;
257
+ function configWithExtIsExist(ext) {
258
+ const filenames = [
259
+ path.resolve(process.cwd(), `${configName}.${ext}`),
260
+ path.resolve(process.cwd(), `.${configName}.${ext}`),
261
+ path.resolve(root, `${configName}.${ext}`),
262
+ path.resolve(root, `.${configName}.${ext}`)
263
+ ];
264
+ if (dir) {
265
+ filenames.unshift(...[
266
+ path.resolve(dir, `${configName}.${ext}`),
267
+ path.resolve(dir, `.${configName}.${ext}`)
268
+ ]);
269
+ }
270
+ for (const filename of filenames) {
271
+ if (fs.existsSync(filename) && fs.lstatSync(filename).isFile()) {
272
+ return filename;
273
+ }
274
+ }
275
+ return;
276
+ }
277
+ configName = configWithExtIsExist("js") ?? configName;
278
+ configName = configWithExtIsExist("json") ?? configName;
279
+ configName = configWithExtIsExist("yaml") ?? configName;
280
+ if (isSupportTsLoader) {
281
+ configName = configWithExtIsExist("ts") ?? configName;
282
+ }
283
+ return path.resolve(root, configName);
284
+ }
285
+ function loadConfig(dir) {
286
+ const { wd: root } = getWD();
287
+ let configPath = commander.program.getOptionValue("configPath");
288
+ if (!configPath) {
289
+ configPath = getConfigPath(root, dir);
290
+ } else {
291
+ if (!fs.existsSync(configPath)) {
292
+ throw new Error(`config file not found: ${configPath}`);
293
+ }
294
+ if (!path.isAbsolute(configPath)) {
295
+ configPath = path.resolve(root, configPath);
296
+ }
297
+ }
298
+ const ext = path.extname(configPath);
299
+ let module;
300
+ switch (ext) {
301
+ case ".js":
302
+ module = require(configPath);
303
+ break;
304
+ case ".json":
305
+ return require(configPath);
306
+ case ".yaml":
307
+ return jsYaml.load(fs.readFileSync(configPath, "utf-8"));
308
+ case ".ts":
309
+ if (tsRegisterName) {
310
+ require(tsRegisterName);
311
+ module = require(configPath);
312
+ break;
313
+ }
314
+ throw new Error(
315
+ "ts config file is not supported without ts register, please install esbuild-register or set JIEK_TS_REGISTER env for custom ts register"
316
+ );
317
+ case ".config":
318
+ module = {};
319
+ break;
320
+ default:
321
+ throw new Error(`unsupported config file type: ${ext}`);
322
+ }
323
+ if (!module)
324
+ throw new Error("config file is empty");
325
+ return module.default ?? module;
326
+ }
327
+
328
+ const FILE_TEMPLATE = (manifest) => `
329
+ const manifest = ${JSON.stringify(manifest, null, 2)}
330
+ module.exports = require('jiek/rollup').template(manifest)
331
+ `.trimStart();
332
+ const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('cli.cjs', document.baseURI).href)));
333
+ commander.program.command("build").option("-s, --silent", "Don't display logs.").option("-e, --entries <ENTRIES>", "Specify the entries of the package.json's 'exports' field.(support glob)").action(async ({
334
+ silent,
335
+ entries
336
+ }) => {
337
+ actionRestore();
338
+ const { build } = loadConfig();
339
+ silent = silent ?? build?.silent ?? false;
340
+ const {
341
+ wd,
342
+ value = {}
343
+ } = await getSelectedProjectsGraph() ?? {};
344
+ if (Object.keys(value).length === 0) {
345
+ throw new Error("no package found");
346
+ }
347
+ const wdNodeModules = path.resolve(wd, "node_modules");
348
+ if (!fs.existsSync(wdNodeModules)) {
349
+ fs.mkdirSync(wdNodeModules);
350
+ }
351
+ const jiekTempDir = (...paths) => path.resolve(wdNodeModules, ".jiek", ...paths);
352
+ if (!fs.existsSync(jiekTempDir())) {
353
+ fs.mkdirSync(jiekTempDir());
354
+ }
355
+ const rollupBinaryPath = require$1.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
356
+ const multiBars = new cliProgress.MultiBar({
357
+ clearOnComplete: false,
358
+ hideCursor: true,
359
+ format: "- {bar} | {status} | {input} | {message}"
360
+ }, cliProgress.Presets.shades_classic);
361
+ let i = 0;
362
+ await Promise.all(
363
+ Object.entries(value).map(async ([dir, manifest]) => {
364
+ const escapeManifestName = manifest.name?.replace(/^@/g, "").replace(/\//g, "+");
365
+ const configFile = jiekTempDir(
366
+ `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
367
+ );
368
+ fs.writeFileSync(configFile, FILE_TEMPLATE(manifest));
369
+ let prefix = "";
370
+ if (tsRegisterName) {
371
+ prefix = `node -r ${tsRegisterName} `;
372
+ }
373
+ const command = `${prefix}${rollupBinaryPath} --silent -c ${configFile}`;
374
+ const child = execa.execaCommand(command, {
375
+ ipc: true,
376
+ cwd: dir,
377
+ env: {
378
+ ...process.env,
379
+ JIEK_ROOT: wd,
380
+ JIEK_ENTRIES: entries
381
+ }
382
+ });
383
+ const bars = {};
384
+ let inputMaxLen = 10;
385
+ child.on("message", (e) => {
386
+ if (e.type === "debug")
387
+ console.log(...Array.isArray(e.data) ? e.data : [e.data]);
388
+ });
389
+ !silent && child.on("message", (e) => {
390
+ if (e.type === "init") {
391
+ const { leafMap, targetsLength } = e.data;
392
+ const leafs = Array.from(leafMap.entries()).flatMap(
393
+ ([input, pathAndCondiions]) => pathAndCondiions.map(([path2, ...conditions]) => ({
394
+ input,
395
+ path: path2,
396
+ conditions
397
+ }))
398
+ );
399
+ console.log(`Package '${manifest.name}' has ${targetsLength} targets to build`);
400
+ leafs.forEach(({ input }) => {
401
+ inputMaxLen = Math.max(inputMaxLen, input.length);
402
+ });
403
+ leafs.forEach(({ input, path: path2 }) => {
404
+ const key = `${input}:${path2}`;
405
+ if (bars[key])
406
+ return;
407
+ bars[key] = multiBars.create(50, 0, {
408
+ input: input.padEnd(inputMaxLen),
409
+ status: "waiting".padEnd(10)
410
+ }, {
411
+ barsize: 20,
412
+ linewrap: true
413
+ });
414
+ });
415
+ }
416
+ if (e.type === "progress") {
417
+ const {
418
+ path: path2,
419
+ tags,
420
+ input,
421
+ event,
422
+ message
423
+ } = e.data;
424
+ const bar = bars[`${input}:${path2}`];
425
+ if (!bar)
426
+ return;
427
+ bar.update(
428
+ {
429
+ start: 0,
430
+ resolve: 20,
431
+ end: 50
432
+ }[event ?? "start"] ?? 0,
433
+ {
434
+ input: input.padEnd(inputMaxLen),
435
+ status: event?.padEnd(10),
436
+ message: `${tags?.join(", ")}: ${message}`
437
+ }
438
+ );
439
+ }
440
+ });
441
+ await new Promise((resolve, reject) => {
442
+ let errorStr = "";
443
+ child.stderr?.on("data", (data) => {
444
+ errorStr += data;
445
+ });
446
+ child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(`rollup build failed:
447
+ ${errorStr}`)));
448
+ });
449
+ })
450
+ ).finally(() => {
451
+ multiBars.stop();
452
+ });
453
+ actionDone();
454
+ });
455
+
456
+ var utils$1 = {};
457
+
458
+ var hasRequiredUtils$1;
459
+
460
+ function requireUtils$1 () {
461
+ if (hasRequiredUtils$1) return utils$1;
462
+ hasRequiredUtils$1 = 1;
463
+ (function (exports) {
464
+
465
+ exports.isInteger = num => {
466
+ if (typeof num === 'number') {
467
+ return Number.isInteger(num);
468
+ }
469
+ if (typeof num === 'string' && num.trim() !== '') {
470
+ return Number.isInteger(Number(num));
471
+ }
472
+ return false;
473
+ };
474
+
475
+ /**
476
+ * Find a node of the given type
477
+ */
478
+
479
+ exports.find = (node, type) => node.nodes.find(node => node.type === type);
480
+
481
+ /**
482
+ * Find a node of the given type
483
+ */
484
+
485
+ exports.exceedsLimit = (min, max, step = 1, limit) => {
486
+ if (limit === false) return false;
487
+ if (!exports.isInteger(min) || !exports.isInteger(max)) return false;
488
+ return ((Number(max) - Number(min)) / Number(step)) >= limit;
489
+ };
490
+
491
+ /**
492
+ * Escape the given node with '\\' before node.value
493
+ */
494
+
495
+ exports.escapeNode = (block, n = 0, type) => {
496
+ let node = block.nodes[n];
497
+ if (!node) return;
498
+
499
+ if ((type && node.type === type) || node.type === 'open' || node.type === 'close') {
500
+ if (node.escaped !== true) {
501
+ node.value = '\\' + node.value;
502
+ node.escaped = true;
503
+ }
504
+ }
505
+ };
506
+
507
+ /**
508
+ * Returns true if the given brace node should be enclosed in literal braces
509
+ */
510
+
511
+ exports.encloseBrace = node => {
512
+ if (node.type !== 'brace') return false;
513
+ if ((node.commas >> 0 + node.ranges >> 0) === 0) {
514
+ node.invalid = true;
515
+ return true;
516
+ }
517
+ return false;
518
+ };
519
+
520
+ /**
521
+ * Returns true if a brace node is invalid.
522
+ */
523
+
524
+ exports.isInvalidBrace = block => {
525
+ if (block.type !== 'brace') return false;
526
+ if (block.invalid === true || block.dollar) return true;
527
+ if ((block.commas >> 0 + block.ranges >> 0) === 0) {
528
+ block.invalid = true;
529
+ return true;
530
+ }
531
+ if (block.open !== true || block.close !== true) {
532
+ block.invalid = true;
533
+ return true;
534
+ }
535
+ return false;
536
+ };
537
+
538
+ /**
539
+ * Returns true if a node is an open or close node
540
+ */
541
+
542
+ exports.isOpenOrClose = node => {
543
+ if (node.type === 'open' || node.type === 'close') {
544
+ return true;
545
+ }
546
+ return node.open === true || node.close === true;
547
+ };
548
+
549
+ /**
550
+ * Reduce an array of text nodes.
551
+ */
552
+
553
+ exports.reduce = nodes => nodes.reduce((acc, node) => {
554
+ if (node.type === 'text') acc.push(node.value);
555
+ if (node.type === 'range') node.type = 'text';
556
+ return acc;
557
+ }, []);
558
+
559
+ /**
560
+ * Flatten an array
561
+ */
562
+
563
+ exports.flatten = (...args) => {
564
+ const result = [];
565
+ const flat = arr => {
566
+ for (let i = 0; i < arr.length; i++) {
567
+ let ele = arr[i];
568
+ Array.isArray(ele) ? flat(ele) : ele !== void 0 && result.push(ele);
569
+ }
570
+ return result;
571
+ };
572
+ flat(args);
573
+ return result;
574
+ };
575
+ } (utils$1));
576
+ return utils$1;
577
+ }
578
+
579
+ var stringify;
580
+ var hasRequiredStringify;
581
+
582
+ function requireStringify () {
583
+ if (hasRequiredStringify) return stringify;
584
+ hasRequiredStringify = 1;
585
+
586
+ const utils = requireUtils$1();
587
+
588
+ stringify = (ast, options = {}) => {
589
+ let stringify = (node, parent = {}) => {
590
+ let invalidBlock = options.escapeInvalid && utils.isInvalidBrace(parent);
591
+ let invalidNode = node.invalid === true && options.escapeInvalid === true;
592
+ let output = '';
593
+
594
+ if (node.value) {
595
+ if ((invalidBlock || invalidNode) && utils.isOpenOrClose(node)) {
596
+ return '\\' + node.value;
597
+ }
598
+ return node.value;
599
+ }
600
+
601
+ if (node.value) {
602
+ return node.value;
603
+ }
604
+
605
+ if (node.nodes) {
606
+ for (let child of node.nodes) {
607
+ output += stringify(child);
608
+ }
609
+ }
610
+ return output;
611
+ };
612
+
613
+ return stringify(ast);
614
+ };
615
+ return stringify;
616
+ }
617
+
618
+ /*!
619
+ * is-number <https://github.com/jonschlinkert/is-number>
620
+ *
621
+ * Copyright (c) 2014-present, Jon Schlinkert.
622
+ * Released under the MIT License.
623
+ */
624
+
625
+ var isNumber;
626
+ var hasRequiredIsNumber;
627
+
628
+ function requireIsNumber () {
629
+ if (hasRequiredIsNumber) return isNumber;
630
+ hasRequiredIsNumber = 1;
631
+
632
+ isNumber = function(num) {
633
+ if (typeof num === 'number') {
634
+ return num - num === 0;
635
+ }
636
+ if (typeof num === 'string' && num.trim() !== '') {
637
+ return Number.isFinite ? Number.isFinite(+num) : isFinite(+num);
638
+ }
639
+ return false;
640
+ };
641
+ return isNumber;
642
+ }
643
+
644
+ /*!
645
+ * to-regex-range <https://github.com/micromatch/to-regex-range>
646
+ *
647
+ * Copyright (c) 2015-present, Jon Schlinkert.
648
+ * Released under the MIT License.
649
+ */
650
+
651
+ var toRegexRange_1;
652
+ var hasRequiredToRegexRange;
653
+
654
+ function requireToRegexRange () {
655
+ if (hasRequiredToRegexRange) return toRegexRange_1;
656
+ hasRequiredToRegexRange = 1;
657
+
658
+ const isNumber = requireIsNumber();
659
+
660
+ const toRegexRange = (min, max, options) => {
661
+ if (isNumber(min) === false) {
662
+ throw new TypeError('toRegexRange: expected the first argument to be a number');
663
+ }
664
+
665
+ if (max === void 0 || min === max) {
666
+ return String(min);
667
+ }
668
+
669
+ if (isNumber(max) === false) {
670
+ throw new TypeError('toRegexRange: expected the second argument to be a number.');
671
+ }
672
+
673
+ let opts = { relaxZeros: true, ...options };
674
+ if (typeof opts.strictZeros === 'boolean') {
675
+ opts.relaxZeros = opts.strictZeros === false;
676
+ }
677
+
678
+ let relax = String(opts.relaxZeros);
679
+ let shorthand = String(opts.shorthand);
680
+ let capture = String(opts.capture);
681
+ let wrap = String(opts.wrap);
682
+ let cacheKey = min + ':' + max + '=' + relax + shorthand + capture + wrap;
683
+
684
+ if (toRegexRange.cache.hasOwnProperty(cacheKey)) {
685
+ return toRegexRange.cache[cacheKey].result;
686
+ }
687
+
688
+ let a = Math.min(min, max);
689
+ let b = Math.max(min, max);
690
+
691
+ if (Math.abs(a - b) === 1) {
692
+ let result = min + '|' + max;
693
+ if (opts.capture) {
694
+ return `(${result})`;
695
+ }
696
+ if (opts.wrap === false) {
697
+ return result;
698
+ }
699
+ return `(?:${result})`;
700
+ }
701
+
702
+ let isPadded = hasPadding(min) || hasPadding(max);
703
+ let state = { min, max, a, b };
704
+ let positives = [];
705
+ let negatives = [];
706
+
707
+ if (isPadded) {
708
+ state.isPadded = isPadded;
709
+ state.maxLen = String(state.max).length;
710
+ }
711
+
712
+ if (a < 0) {
713
+ let newMin = b < 0 ? Math.abs(b) : 1;
714
+ negatives = splitToPatterns(newMin, Math.abs(a), state, opts);
715
+ a = state.a = 0;
716
+ }
717
+
718
+ if (b >= 0) {
719
+ positives = splitToPatterns(a, b, state, opts);
720
+ }
721
+
722
+ state.negatives = negatives;
723
+ state.positives = positives;
724
+ state.result = collatePatterns(negatives, positives);
725
+
726
+ if (opts.capture === true) {
727
+ state.result = `(${state.result})`;
728
+ } else if (opts.wrap !== false && (positives.length + negatives.length) > 1) {
729
+ state.result = `(?:${state.result})`;
730
+ }
731
+
732
+ toRegexRange.cache[cacheKey] = state;
733
+ return state.result;
734
+ };
735
+
736
+ function collatePatterns(neg, pos, options) {
737
+ let onlyNegative = filterPatterns(neg, pos, '-', false) || [];
738
+ let onlyPositive = filterPatterns(pos, neg, '', false) || [];
739
+ let intersected = filterPatterns(neg, pos, '-?', true) || [];
740
+ let subpatterns = onlyNegative.concat(intersected).concat(onlyPositive);
741
+ return subpatterns.join('|');
742
+ }
743
+
744
+ function splitToRanges(min, max) {
745
+ let nines = 1;
746
+ let zeros = 1;
747
+
748
+ let stop = countNines(min, nines);
749
+ let stops = new Set([max]);
750
+
751
+ while (min <= stop && stop <= max) {
752
+ stops.add(stop);
753
+ nines += 1;
754
+ stop = countNines(min, nines);
755
+ }
756
+
757
+ stop = countZeros(max + 1, zeros) - 1;
758
+
759
+ while (min < stop && stop <= max) {
760
+ stops.add(stop);
761
+ zeros += 1;
762
+ stop = countZeros(max + 1, zeros) - 1;
763
+ }
764
+
765
+ stops = [...stops];
766
+ stops.sort(compare);
767
+ return stops;
768
+ }
769
+
770
+ /**
771
+ * Convert a range to a regex pattern
772
+ * @param {Number} `start`
773
+ * @param {Number} `stop`
774
+ * @return {String}
775
+ */
776
+
777
+ function rangeToPattern(start, stop, options) {
778
+ if (start === stop) {
779
+ return { pattern: start, count: [], digits: 0 };
780
+ }
781
+
782
+ let zipped = zip(start, stop);
783
+ let digits = zipped.length;
784
+ let pattern = '';
785
+ let count = 0;
786
+
787
+ for (let i = 0; i < digits; i++) {
788
+ let [startDigit, stopDigit] = zipped[i];
789
+
790
+ if (startDigit === stopDigit) {
791
+ pattern += startDigit;
792
+
793
+ } else if (startDigit !== '0' || stopDigit !== '9') {
794
+ pattern += toCharacterClass(startDigit, stopDigit);
795
+
796
+ } else {
797
+ count++;
798
+ }
799
+ }
800
+
801
+ if (count) {
802
+ pattern += options.shorthand === true ? '\\d' : '[0-9]';
803
+ }
804
+
805
+ return { pattern, count: [count], digits };
806
+ }
807
+
808
+ function splitToPatterns(min, max, tok, options) {
809
+ let ranges = splitToRanges(min, max);
810
+ let tokens = [];
811
+ let start = min;
812
+ let prev;
813
+
814
+ for (let i = 0; i < ranges.length; i++) {
815
+ let max = ranges[i];
816
+ let obj = rangeToPattern(String(start), String(max), options);
817
+ let zeros = '';
818
+
819
+ if (!tok.isPadded && prev && prev.pattern === obj.pattern) {
820
+ if (prev.count.length > 1) {
821
+ prev.count.pop();
822
+ }
823
+
824
+ prev.count.push(obj.count[0]);
825
+ prev.string = prev.pattern + toQuantifier(prev.count);
826
+ start = max + 1;
827
+ continue;
828
+ }
829
+
830
+ if (tok.isPadded) {
831
+ zeros = padZeros(max, tok, options);
832
+ }
833
+
834
+ obj.string = zeros + obj.pattern + toQuantifier(obj.count);
835
+ tokens.push(obj);
836
+ start = max + 1;
837
+ prev = obj;
838
+ }
839
+
840
+ return tokens;
841
+ }
842
+
843
+ function filterPatterns(arr, comparison, prefix, intersection, options) {
844
+ let result = [];
845
+
846
+ for (let ele of arr) {
847
+ let { string } = ele;
848
+
849
+ // only push if _both_ are negative...
850
+ if (!intersection && !contains(comparison, 'string', string)) {
851
+ result.push(prefix + string);
852
+ }
853
+
854
+ // or _both_ are positive
855
+ if (intersection && contains(comparison, 'string', string)) {
856
+ result.push(prefix + string);
857
+ }
858
+ }
859
+ return result;
860
+ }
861
+
862
+ /**
863
+ * Zip strings
864
+ */
865
+
866
+ function zip(a, b) {
867
+ let arr = [];
868
+ for (let i = 0; i < a.length; i++) arr.push([a[i], b[i]]);
869
+ return arr;
870
+ }
871
+
872
+ function compare(a, b) {
873
+ return a > b ? 1 : b > a ? -1 : 0;
874
+ }
875
+
876
+ function contains(arr, key, val) {
877
+ return arr.some(ele => ele[key] === val);
878
+ }
879
+
880
+ function countNines(min, len) {
881
+ return Number(String(min).slice(0, -len) + '9'.repeat(len));
882
+ }
883
+
884
+ function countZeros(integer, zeros) {
885
+ return integer - (integer % Math.pow(10, zeros));
886
+ }
887
+
888
+ function toQuantifier(digits) {
889
+ let [start = 0, stop = ''] = digits;
890
+ if (stop || start > 1) {
891
+ return `{${start + (stop ? ',' + stop : '')}}`;
892
+ }
893
+ return '';
894
+ }
895
+
896
+ function toCharacterClass(a, b, options) {
897
+ return `[${a}${(b - a === 1) ? '' : '-'}${b}]`;
898
+ }
899
+
900
+ function hasPadding(str) {
901
+ return /^-?(0+)\d/.test(str);
902
+ }
903
+
904
+ function padZeros(value, tok, options) {
905
+ if (!tok.isPadded) {
906
+ return value;
907
+ }
908
+
909
+ let diff = Math.abs(tok.maxLen - String(value).length);
910
+ let relax = options.relaxZeros !== false;
911
+
912
+ switch (diff) {
913
+ case 0:
914
+ return '';
915
+ case 1:
916
+ return relax ? '0?' : '0';
917
+ case 2:
918
+ return relax ? '0{0,2}' : '00';
919
+ default: {
920
+ return relax ? `0{0,${diff}}` : `0{${diff}}`;
921
+ }
922
+ }
923
+ }
924
+
925
+ /**
926
+ * Cache
927
+ */
928
+
929
+ toRegexRange.cache = {};
930
+ toRegexRange.clearCache = () => (toRegexRange.cache = {});
931
+
932
+ /**
933
+ * Expose `toRegexRange`
934
+ */
935
+
936
+ toRegexRange_1 = toRegexRange;
937
+ return toRegexRange_1;
938
+ }
939
+
940
+ /*!
941
+ * fill-range <https://github.com/jonschlinkert/fill-range>
942
+ *
943
+ * Copyright (c) 2014-present, Jon Schlinkert.
944
+ * Licensed under the MIT License.
945
+ */
946
+
947
+ var fillRange;
948
+ var hasRequiredFillRange;
949
+
950
+ function requireFillRange () {
951
+ if (hasRequiredFillRange) return fillRange;
952
+ hasRequiredFillRange = 1;
953
+
954
+ const util = require$$0;
955
+ const toRegexRange = requireToRegexRange();
956
+
957
+ const isObject = val => val !== null && typeof val === 'object' && !Array.isArray(val);
958
+
959
+ const transform = toNumber => {
960
+ return value => toNumber === true ? Number(value) : String(value);
961
+ };
962
+
963
+ const isValidValue = value => {
964
+ return typeof value === 'number' || (typeof value === 'string' && value !== '');
965
+ };
966
+
967
+ const isNumber = num => Number.isInteger(+num);
968
+
969
+ const zeros = input => {
970
+ let value = `${input}`;
971
+ let index = -1;
972
+ if (value[0] === '-') value = value.slice(1);
973
+ if (value === '0') return false;
974
+ while (value[++index] === '0');
975
+ return index > 0;
976
+ };
977
+
978
+ const stringify = (start, end, options) => {
979
+ if (typeof start === 'string' || typeof end === 'string') {
980
+ return true;
981
+ }
982
+ return options.stringify === true;
983
+ };
984
+
985
+ const pad = (input, maxLength, toNumber) => {
986
+ if (maxLength > 0) {
987
+ let dash = input[0] === '-' ? '-' : '';
988
+ if (dash) input = input.slice(1);
989
+ input = (dash + input.padStart(dash ? maxLength - 1 : maxLength, '0'));
990
+ }
991
+ if (toNumber === false) {
992
+ return String(input);
993
+ }
994
+ return input;
995
+ };
996
+
997
+ const toMaxLen = (input, maxLength) => {
998
+ let negative = input[0] === '-' ? '-' : '';
999
+ if (negative) {
1000
+ input = input.slice(1);
1001
+ maxLength--;
1002
+ }
1003
+ while (input.length < maxLength) input = '0' + input;
1004
+ return negative ? ('-' + input) : input;
1005
+ };
1006
+
1007
+ const toSequence = (parts, options) => {
1008
+ parts.negatives.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
1009
+ parts.positives.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
1010
+
1011
+ let prefix = options.capture ? '' : '?:';
1012
+ let positives = '';
1013
+ let negatives = '';
1014
+ let result;
1015
+
1016
+ if (parts.positives.length) {
1017
+ positives = parts.positives.join('|');
1018
+ }
1019
+
1020
+ if (parts.negatives.length) {
1021
+ negatives = `-(${prefix}${parts.negatives.join('|')})`;
1022
+ }
1023
+
1024
+ if (positives && negatives) {
1025
+ result = `${positives}|${negatives}`;
1026
+ } else {
1027
+ result = positives || negatives;
1028
+ }
1029
+
1030
+ if (options.wrap) {
1031
+ return `(${prefix}${result})`;
1032
+ }
1033
+
1034
+ return result;
1035
+ };
1036
+
1037
+ const toRange = (a, b, isNumbers, options) => {
1038
+ if (isNumbers) {
1039
+ return toRegexRange(a, b, { wrap: false, ...options });
1040
+ }
1041
+
1042
+ let start = String.fromCharCode(a);
1043
+ if (a === b) return start;
1044
+
1045
+ let stop = String.fromCharCode(b);
1046
+ return `[${start}-${stop}]`;
1047
+ };
1048
+
1049
+ const toRegex = (start, end, options) => {
1050
+ if (Array.isArray(start)) {
1051
+ let wrap = options.wrap === true;
1052
+ let prefix = options.capture ? '' : '?:';
1053
+ return wrap ? `(${prefix}${start.join('|')})` : start.join('|');
1054
+ }
1055
+ return toRegexRange(start, end, options);
1056
+ };
1057
+
1058
+ const rangeError = (...args) => {
1059
+ return new RangeError('Invalid range arguments: ' + util.inspect(...args));
1060
+ };
1061
+
1062
+ const invalidRange = (start, end, options) => {
1063
+ if (options.strictRanges === true) throw rangeError([start, end]);
1064
+ return [];
1065
+ };
1066
+
1067
+ const invalidStep = (step, options) => {
1068
+ if (options.strictRanges === true) {
1069
+ throw new TypeError(`Expected step "${step}" to be a number`);
1070
+ }
1071
+ return [];
1072
+ };
1073
+
1074
+ const fillNumbers = (start, end, step = 1, options = {}) => {
1075
+ let a = Number(start);
1076
+ let b = Number(end);
1077
+
1078
+ if (!Number.isInteger(a) || !Number.isInteger(b)) {
1079
+ if (options.strictRanges === true) throw rangeError([start, end]);
1080
+ return [];
1081
+ }
1082
+
1083
+ // fix negative zero
1084
+ if (a === 0) a = 0;
1085
+ if (b === 0) b = 0;
1086
+
1087
+ let descending = a > b;
1088
+ let startString = String(start);
1089
+ let endString = String(end);
1090
+ let stepString = String(step);
1091
+ step = Math.max(Math.abs(step), 1);
1092
+
1093
+ let padded = zeros(startString) || zeros(endString) || zeros(stepString);
1094
+ let maxLen = padded ? Math.max(startString.length, endString.length, stepString.length) : 0;
1095
+ let toNumber = padded === false && stringify(start, end, options) === false;
1096
+ let format = options.transform || transform(toNumber);
1097
+
1098
+ if (options.toRegex && step === 1) {
1099
+ return toRange(toMaxLen(start, maxLen), toMaxLen(end, maxLen), true, options);
1100
+ }
1101
+
1102
+ let parts = { negatives: [], positives: [] };
1103
+ let push = num => parts[num < 0 ? 'negatives' : 'positives'].push(Math.abs(num));
1104
+ let range = [];
1105
+ let index = 0;
1106
+
1107
+ while (descending ? a >= b : a <= b) {
1108
+ if (options.toRegex === true && step > 1) {
1109
+ push(a);
1110
+ } else {
1111
+ range.push(pad(format(a, index), maxLen, toNumber));
1112
+ }
1113
+ a = descending ? a - step : a + step;
1114
+ index++;
1115
+ }
1116
+
1117
+ if (options.toRegex === true) {
1118
+ return step > 1
1119
+ ? toSequence(parts, options)
1120
+ : toRegex(range, null, { wrap: false, ...options });
1121
+ }
1122
+
1123
+ return range;
1124
+ };
1125
+
1126
+ const fillLetters = (start, end, step = 1, options = {}) => {
1127
+ if ((!isNumber(start) && start.length > 1) || (!isNumber(end) && end.length > 1)) {
1128
+ return invalidRange(start, end, options);
1129
+ }
1130
+
1131
+
1132
+ let format = options.transform || (val => String.fromCharCode(val));
1133
+ let a = `${start}`.charCodeAt(0);
1134
+ let b = `${end}`.charCodeAt(0);
1135
+
1136
+ let descending = a > b;
1137
+ let min = Math.min(a, b);
1138
+ let max = Math.max(a, b);
1139
+
1140
+ if (options.toRegex && step === 1) {
1141
+ return toRange(min, max, false, options);
1142
+ }
1143
+
1144
+ let range = [];
1145
+ let index = 0;
1146
+
1147
+ while (descending ? a >= b : a <= b) {
1148
+ range.push(format(a, index));
1149
+ a = descending ? a - step : a + step;
1150
+ index++;
1151
+ }
1152
+
1153
+ if (options.toRegex === true) {
1154
+ return toRegex(range, null, { wrap: false, options });
1155
+ }
1156
+
1157
+ return range;
1158
+ };
1159
+
1160
+ const fill = (start, end, step, options = {}) => {
1161
+ if (end == null && isValidValue(start)) {
1162
+ return [start];
1163
+ }
1164
+
1165
+ if (!isValidValue(start) || !isValidValue(end)) {
1166
+ return invalidRange(start, end, options);
1167
+ }
1168
+
1169
+ if (typeof step === 'function') {
1170
+ return fill(start, end, 1, { transform: step });
1171
+ }
1172
+
1173
+ if (isObject(step)) {
1174
+ return fill(start, end, 0, step);
1175
+ }
1176
+
1177
+ let opts = { ...options };
1178
+ if (opts.capture === true) opts.wrap = true;
1179
+ step = step || opts.step || 1;
1180
+
1181
+ if (!isNumber(step)) {
1182
+ if (step != null && !isObject(step)) return invalidStep(step, opts);
1183
+ return fill(start, end, 1, step);
1184
+ }
1185
+
1186
+ if (isNumber(start) && isNumber(end)) {
1187
+ return fillNumbers(start, end, step, opts);
1188
+ }
1189
+
1190
+ return fillLetters(start, end, Math.max(Math.abs(step), 1), opts);
1191
+ };
1192
+
1193
+ fillRange = fill;
1194
+ return fillRange;
1195
+ }
1196
+
1197
+ var compile_1;
1198
+ var hasRequiredCompile;
1199
+
1200
+ function requireCompile () {
1201
+ if (hasRequiredCompile) return compile_1;
1202
+ hasRequiredCompile = 1;
1203
+
1204
+ const fill = requireFillRange();
1205
+ const utils = requireUtils$1();
1206
+
1207
+ const compile = (ast, options = {}) => {
1208
+ let walk = (node, parent = {}) => {
1209
+ let invalidBlock = utils.isInvalidBrace(parent);
1210
+ let invalidNode = node.invalid === true && options.escapeInvalid === true;
1211
+ let invalid = invalidBlock === true || invalidNode === true;
1212
+ let prefix = options.escapeInvalid === true ? '\\' : '';
1213
+ let output = '';
1214
+
1215
+ if (node.isOpen === true) {
1216
+ return prefix + node.value;
1217
+ }
1218
+ if (node.isClose === true) {
1219
+ return prefix + node.value;
1220
+ }
1221
+
1222
+ if (node.type === 'open') {
1223
+ return invalid ? (prefix + node.value) : '(';
1224
+ }
1225
+
1226
+ if (node.type === 'close') {
1227
+ return invalid ? (prefix + node.value) : ')';
1228
+ }
1229
+
1230
+ if (node.type === 'comma') {
1231
+ return node.prev.type === 'comma' ? '' : (invalid ? node.value : '|');
1232
+ }
1233
+
1234
+ if (node.value) {
1235
+ return node.value;
1236
+ }
1237
+
1238
+ if (node.nodes && node.ranges > 0) {
1239
+ let args = utils.reduce(node.nodes);
1240
+ let range = fill(...args, { ...options, wrap: false, toRegex: true });
1241
+
1242
+ if (range.length !== 0) {
1243
+ return args.length > 1 && range.length > 1 ? `(${range})` : range;
1244
+ }
1245
+ }
1246
+
1247
+ if (node.nodes) {
1248
+ for (let child of node.nodes) {
1249
+ output += walk(child, node);
1250
+ }
1251
+ }
1252
+ return output;
1253
+ };
1254
+
1255
+ return walk(ast);
1256
+ };
1257
+
1258
+ compile_1 = compile;
1259
+ return compile_1;
1260
+ }
1261
+
1262
+ var expand_1;
1263
+ var hasRequiredExpand;
1264
+
1265
+ function requireExpand () {
1266
+ if (hasRequiredExpand) return expand_1;
1267
+ hasRequiredExpand = 1;
1268
+
1269
+ const fill = requireFillRange();
1270
+ const stringify = requireStringify();
1271
+ const utils = requireUtils$1();
1272
+
1273
+ const append = (queue = '', stash = '', enclose = false) => {
1274
+ let result = [];
1275
+
1276
+ queue = [].concat(queue);
1277
+ stash = [].concat(stash);
1278
+
1279
+ if (!stash.length) return queue;
1280
+ if (!queue.length) {
1281
+ return enclose ? utils.flatten(stash).map(ele => `{${ele}}`) : stash;
1282
+ }
1283
+
1284
+ for (let item of queue) {
1285
+ if (Array.isArray(item)) {
1286
+ for (let value of item) {
1287
+ result.push(append(value, stash, enclose));
1288
+ }
1289
+ } else {
1290
+ for (let ele of stash) {
1291
+ if (enclose === true && typeof ele === 'string') ele = `{${ele}}`;
1292
+ result.push(Array.isArray(ele) ? append(item, ele, enclose) : (item + ele));
1293
+ }
1294
+ }
1295
+ }
1296
+ return utils.flatten(result);
1297
+ };
1298
+
1299
+ const expand = (ast, options = {}) => {
1300
+ let rangeLimit = options.rangeLimit === void 0 ? 1000 : options.rangeLimit;
1301
+
1302
+ let walk = (node, parent = {}) => {
1303
+ node.queue = [];
1304
+
1305
+ let p = parent;
1306
+ let q = parent.queue;
1307
+
1308
+ while (p.type !== 'brace' && p.type !== 'root' && p.parent) {
1309
+ p = p.parent;
1310
+ q = p.queue;
1311
+ }
1312
+
1313
+ if (node.invalid || node.dollar) {
1314
+ q.push(append(q.pop(), stringify(node, options)));
1315
+ return;
1316
+ }
1317
+
1318
+ if (node.type === 'brace' && node.invalid !== true && node.nodes.length === 2) {
1319
+ q.push(append(q.pop(), ['{}']));
1320
+ return;
1321
+ }
1322
+
1323
+ if (node.nodes && node.ranges > 0) {
1324
+ let args = utils.reduce(node.nodes);
1325
+
1326
+ if (utils.exceedsLimit(...args, options.step, rangeLimit)) {
1327
+ throw new RangeError('expanded array length exceeds range limit. Use options.rangeLimit to increase or disable the limit.');
1328
+ }
1329
+
1330
+ let range = fill(...args, options);
1331
+ if (range.length === 0) {
1332
+ range = stringify(node, options);
1333
+ }
1334
+
1335
+ q.push(append(q.pop(), range));
1336
+ node.nodes = [];
1337
+ return;
1338
+ }
1339
+
1340
+ let enclose = utils.encloseBrace(node);
1341
+ let queue = node.queue;
1342
+ let block = node;
1343
+
1344
+ while (block.type !== 'brace' && block.type !== 'root' && block.parent) {
1345
+ block = block.parent;
1346
+ queue = block.queue;
1347
+ }
1348
+
1349
+ for (let i = 0; i < node.nodes.length; i++) {
1350
+ let child = node.nodes[i];
1351
+
1352
+ if (child.type === 'comma' && node.type === 'brace') {
1353
+ if (i === 1) queue.push('');
1354
+ queue.push('');
1355
+ continue;
1356
+ }
1357
+
1358
+ if (child.type === 'close') {
1359
+ q.push(append(q.pop(), queue, enclose));
1360
+ continue;
1361
+ }
1362
+
1363
+ if (child.value && child.type !== 'open') {
1364
+ queue.push(append(queue.pop(), child.value));
1365
+ continue;
1366
+ }
1367
+
1368
+ if (child.nodes) {
1369
+ walk(child, node);
1370
+ }
1371
+ }
1372
+
1373
+ return queue;
1374
+ };
1375
+
1376
+ return utils.flatten(walk(ast));
1377
+ };
1378
+
1379
+ expand_1 = expand;
1380
+ return expand_1;
1381
+ }
1382
+
1383
+ var constants$1;
1384
+ var hasRequiredConstants$1;
1385
+
1386
+ function requireConstants$1 () {
1387
+ if (hasRequiredConstants$1) return constants$1;
1388
+ hasRequiredConstants$1 = 1;
1389
+
1390
+ constants$1 = {
1391
+ MAX_LENGTH: 1024 * 64,
1392
+
1393
+ // Digits
1394
+ CHAR_0: '0', /* 0 */
1395
+ CHAR_9: '9', /* 9 */
1396
+
1397
+ // Alphabet chars.
1398
+ CHAR_UPPERCASE_A: 'A', /* A */
1399
+ CHAR_LOWERCASE_A: 'a', /* a */
1400
+ CHAR_UPPERCASE_Z: 'Z', /* Z */
1401
+ CHAR_LOWERCASE_Z: 'z', /* z */
1402
+
1403
+ CHAR_LEFT_PARENTHESES: '(', /* ( */
1404
+ CHAR_RIGHT_PARENTHESES: ')', /* ) */
1405
+
1406
+ CHAR_ASTERISK: '*', /* * */
1407
+
1408
+ // Non-alphabetic chars.
1409
+ CHAR_AMPERSAND: '&', /* & */
1410
+ CHAR_AT: '@', /* @ */
1411
+ CHAR_BACKSLASH: '\\', /* \ */
1412
+ CHAR_BACKTICK: '`', /* ` */
1413
+ CHAR_CARRIAGE_RETURN: '\r', /* \r */
1414
+ CHAR_CIRCUMFLEX_ACCENT: '^', /* ^ */
1415
+ CHAR_COLON: ':', /* : */
1416
+ CHAR_COMMA: ',', /* , */
1417
+ CHAR_DOLLAR: '$', /* . */
1418
+ CHAR_DOT: '.', /* . */
1419
+ CHAR_DOUBLE_QUOTE: '"', /* " */
1420
+ CHAR_EQUAL: '=', /* = */
1421
+ CHAR_EXCLAMATION_MARK: '!', /* ! */
1422
+ CHAR_FORM_FEED: '\f', /* \f */
1423
+ CHAR_FORWARD_SLASH: '/', /* / */
1424
+ CHAR_HASH: '#', /* # */
1425
+ CHAR_HYPHEN_MINUS: '-', /* - */
1426
+ CHAR_LEFT_ANGLE_BRACKET: '<', /* < */
1427
+ CHAR_LEFT_CURLY_BRACE: '{', /* { */
1428
+ CHAR_LEFT_SQUARE_BRACKET: '[', /* [ */
1429
+ CHAR_LINE_FEED: '\n', /* \n */
1430
+ CHAR_NO_BREAK_SPACE: '\u00A0', /* \u00A0 */
1431
+ CHAR_PERCENT: '%', /* % */
1432
+ CHAR_PLUS: '+', /* + */
1433
+ CHAR_QUESTION_MARK: '?', /* ? */
1434
+ CHAR_RIGHT_ANGLE_BRACKET: '>', /* > */
1435
+ CHAR_RIGHT_CURLY_BRACE: '}', /* } */
1436
+ CHAR_RIGHT_SQUARE_BRACKET: ']', /* ] */
1437
+ CHAR_SEMICOLON: ';', /* ; */
1438
+ CHAR_SINGLE_QUOTE: '\'', /* ' */
1439
+ CHAR_SPACE: ' ', /* */
1440
+ CHAR_TAB: '\t', /* \t */
1441
+ CHAR_UNDERSCORE: '_', /* _ */
1442
+ CHAR_VERTICAL_LINE: '|', /* | */
1443
+ CHAR_ZERO_WIDTH_NOBREAK_SPACE: '\uFEFF' /* \uFEFF */
1444
+ };
1445
+ return constants$1;
1446
+ }
1447
+
1448
+ var parse_1$1;
1449
+ var hasRequiredParse$1;
1450
+
1451
+ function requireParse$1 () {
1452
+ if (hasRequiredParse$1) return parse_1$1;
1453
+ hasRequiredParse$1 = 1;
1454
+
1455
+ const stringify = requireStringify();
1456
+
1457
+ /**
1458
+ * Constants
1459
+ */
1460
+
1461
+ const {
1462
+ MAX_LENGTH,
1463
+ CHAR_BACKSLASH, /* \ */
1464
+ CHAR_BACKTICK, /* ` */
1465
+ CHAR_COMMA, /* , */
1466
+ CHAR_DOT, /* . */
1467
+ CHAR_LEFT_PARENTHESES, /* ( */
1468
+ CHAR_RIGHT_PARENTHESES, /* ) */
1469
+ CHAR_LEFT_CURLY_BRACE, /* { */
1470
+ CHAR_RIGHT_CURLY_BRACE, /* } */
1471
+ CHAR_LEFT_SQUARE_BRACKET, /* [ */
1472
+ CHAR_RIGHT_SQUARE_BRACKET, /* ] */
1473
+ CHAR_DOUBLE_QUOTE, /* " */
1474
+ CHAR_SINGLE_QUOTE, /* ' */
1475
+ CHAR_NO_BREAK_SPACE,
1476
+ CHAR_ZERO_WIDTH_NOBREAK_SPACE
1477
+ } = requireConstants$1();
1478
+
1479
+ /**
1480
+ * parse
1481
+ */
1482
+
1483
+ const parse = (input, options = {}) => {
1484
+ if (typeof input !== 'string') {
1485
+ throw new TypeError('Expected a string');
1486
+ }
1487
+
1488
+ let opts = options || {};
1489
+ let max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
1490
+ if (input.length > max) {
1491
+ throw new SyntaxError(`Input length (${input.length}), exceeds max characters (${max})`);
1492
+ }
1493
+
1494
+ let ast = { type: 'root', input, nodes: [] };
1495
+ let stack = [ast];
1496
+ let block = ast;
1497
+ let prev = ast;
1498
+ let brackets = 0;
1499
+ let length = input.length;
1500
+ let index = 0;
1501
+ let depth = 0;
1502
+ let value;
1503
+
1504
+ /**
1505
+ * Helpers
1506
+ */
1507
+
1508
+ const advance = () => input[index++];
1509
+ const push = node => {
1510
+ if (node.type === 'text' && prev.type === 'dot') {
1511
+ prev.type = 'text';
1512
+ }
1513
+
1514
+ if (prev && prev.type === 'text' && node.type === 'text') {
1515
+ prev.value += node.value;
1516
+ return;
1517
+ }
1518
+
1519
+ block.nodes.push(node);
1520
+ node.parent = block;
1521
+ node.prev = prev;
1522
+ prev = node;
1523
+ return node;
1524
+ };
1525
+
1526
+ push({ type: 'bos' });
1527
+
1528
+ while (index < length) {
1529
+ block = stack[stack.length - 1];
1530
+ value = advance();
1531
+
1532
+ /**
1533
+ * Invalid chars
1534
+ */
1535
+
1536
+ if (value === CHAR_ZERO_WIDTH_NOBREAK_SPACE || value === CHAR_NO_BREAK_SPACE) {
1537
+ continue;
1538
+ }
1539
+
1540
+ /**
1541
+ * Escaped chars
1542
+ */
1543
+
1544
+ if (value === CHAR_BACKSLASH) {
1545
+ push({ type: 'text', value: (options.keepEscaping ? value : '') + advance() });
1546
+ continue;
1547
+ }
1548
+
1549
+ /**
1550
+ * Right square bracket (literal): ']'
1551
+ */
1552
+
1553
+ if (value === CHAR_RIGHT_SQUARE_BRACKET) {
1554
+ push({ type: 'text', value: '\\' + value });
1555
+ continue;
1556
+ }
1557
+
1558
+ /**
1559
+ * Left square bracket: '['
1560
+ */
1561
+
1562
+ if (value === CHAR_LEFT_SQUARE_BRACKET) {
1563
+ brackets++;
1564
+ let next;
1565
+
1566
+ while (index < length && (next = advance())) {
1567
+ value += next;
1568
+
1569
+ if (next === CHAR_LEFT_SQUARE_BRACKET) {
1570
+ brackets++;
1571
+ continue;
1572
+ }
1573
+
1574
+ if (next === CHAR_BACKSLASH) {
1575
+ value += advance();
1576
+ continue;
1577
+ }
1578
+
1579
+ if (next === CHAR_RIGHT_SQUARE_BRACKET) {
1580
+ brackets--;
1581
+
1582
+ if (brackets === 0) {
1583
+ break;
1584
+ }
1585
+ }
1586
+ }
1587
+
1588
+ push({ type: 'text', value });
1589
+ continue;
1590
+ }
1591
+
1592
+ /**
1593
+ * Parentheses
1594
+ */
1595
+
1596
+ if (value === CHAR_LEFT_PARENTHESES) {
1597
+ block = push({ type: 'paren', nodes: [] });
1598
+ stack.push(block);
1599
+ push({ type: 'text', value });
1600
+ continue;
1601
+ }
1602
+
1603
+ if (value === CHAR_RIGHT_PARENTHESES) {
1604
+ if (block.type !== 'paren') {
1605
+ push({ type: 'text', value });
1606
+ continue;
1607
+ }
1608
+ block = stack.pop();
1609
+ push({ type: 'text', value });
1610
+ block = stack[stack.length - 1];
1611
+ continue;
1612
+ }
1613
+
1614
+ /**
1615
+ * Quotes: '|"|`
1616
+ */
1617
+
1618
+ if (value === CHAR_DOUBLE_QUOTE || value === CHAR_SINGLE_QUOTE || value === CHAR_BACKTICK) {
1619
+ let open = value;
1620
+ let next;
1621
+
1622
+ if (options.keepQuotes !== true) {
1623
+ value = '';
1624
+ }
1625
+
1626
+ while (index < length && (next = advance())) {
1627
+ if (next === CHAR_BACKSLASH) {
1628
+ value += next + advance();
1629
+ continue;
1630
+ }
1631
+
1632
+ if (next === open) {
1633
+ if (options.keepQuotes === true) value += next;
1634
+ break;
1635
+ }
1636
+
1637
+ value += next;
1638
+ }
1639
+
1640
+ push({ type: 'text', value });
1641
+ continue;
1642
+ }
1643
+
1644
+ /**
1645
+ * Left curly brace: '{'
1646
+ */
1647
+
1648
+ if (value === CHAR_LEFT_CURLY_BRACE) {
1649
+ depth++;
1650
+
1651
+ let dollar = prev.value && prev.value.slice(-1) === '$' || block.dollar === true;
1652
+ let brace = {
1653
+ type: 'brace',
1654
+ open: true,
1655
+ close: false,
1656
+ dollar,
1657
+ depth,
1658
+ commas: 0,
1659
+ ranges: 0,
1660
+ nodes: []
1661
+ };
1662
+
1663
+ block = push(brace);
1664
+ stack.push(block);
1665
+ push({ type: 'open', value });
1666
+ continue;
1667
+ }
1668
+
1669
+ /**
1670
+ * Right curly brace: '}'
1671
+ */
1672
+
1673
+ if (value === CHAR_RIGHT_CURLY_BRACE) {
1674
+ if (block.type !== 'brace') {
1675
+ push({ type: 'text', value });
1676
+ continue;
1677
+ }
1678
+
1679
+ let type = 'close';
1680
+ block = stack.pop();
1681
+ block.close = true;
1682
+
1683
+ push({ type, value });
1684
+ depth--;
1685
+
1686
+ block = stack[stack.length - 1];
1687
+ continue;
1688
+ }
1689
+
1690
+ /**
1691
+ * Comma: ','
1692
+ */
1693
+
1694
+ if (value === CHAR_COMMA && depth > 0) {
1695
+ if (block.ranges > 0) {
1696
+ block.ranges = 0;
1697
+ let open = block.nodes.shift();
1698
+ block.nodes = [open, { type: 'text', value: stringify(block) }];
1699
+ }
1700
+
1701
+ push({ type: 'comma', value });
1702
+ block.commas++;
1703
+ continue;
1704
+ }
1705
+
1706
+ /**
1707
+ * Dot: '.'
1708
+ */
1709
+
1710
+ if (value === CHAR_DOT && depth > 0 && block.commas === 0) {
1711
+ let siblings = block.nodes;
1712
+
1713
+ if (depth === 0 || siblings.length === 0) {
1714
+ push({ type: 'text', value });
1715
+ continue;
1716
+ }
1717
+
1718
+ if (prev.type === 'dot') {
1719
+ block.range = [];
1720
+ prev.value += value;
1721
+ prev.type = 'range';
1722
+
1723
+ if (block.nodes.length !== 3 && block.nodes.length !== 5) {
1724
+ block.invalid = true;
1725
+ block.ranges = 0;
1726
+ prev.type = 'text';
1727
+ continue;
1728
+ }
1729
+
1730
+ block.ranges++;
1731
+ block.args = [];
1732
+ continue;
1733
+ }
1734
+
1735
+ if (prev.type === 'range') {
1736
+ siblings.pop();
1737
+
1738
+ let before = siblings[siblings.length - 1];
1739
+ before.value += prev.value + value;
1740
+ prev = before;
1741
+ block.ranges--;
1742
+ continue;
1743
+ }
1744
+
1745
+ push({ type: 'dot', value });
1746
+ continue;
1747
+ }
1748
+
1749
+ /**
1750
+ * Text
1751
+ */
1752
+
1753
+ push({ type: 'text', value });
1754
+ }
1755
+
1756
+ // Mark imbalanced braces and brackets as invalid
1757
+ do {
1758
+ block = stack.pop();
1759
+
1760
+ if (block.type !== 'root') {
1761
+ block.nodes.forEach(node => {
1762
+ if (!node.nodes) {
1763
+ if (node.type === 'open') node.isOpen = true;
1764
+ if (node.type === 'close') node.isClose = true;
1765
+ if (!node.nodes) node.type = 'text';
1766
+ node.invalid = true;
1767
+ }
1768
+ });
1769
+
1770
+ // get the location of the block on parent.nodes (block's siblings)
1771
+ let parent = stack[stack.length - 1];
1772
+ let index = parent.nodes.indexOf(block);
1773
+ // replace the (invalid) block with it's nodes
1774
+ parent.nodes.splice(index, 1, ...block.nodes);
1775
+ }
1776
+ } while (stack.length > 0);
1777
+
1778
+ push({ type: 'eos' });
1779
+ return ast;
1780
+ };
1781
+
1782
+ parse_1$1 = parse;
1783
+ return parse_1$1;
1784
+ }
1785
+
1786
+ var braces_1;
1787
+ var hasRequiredBraces;
1788
+
1789
+ function requireBraces () {
1790
+ if (hasRequiredBraces) return braces_1;
1791
+ hasRequiredBraces = 1;
1792
+
1793
+ const stringify = requireStringify();
1794
+ const compile = requireCompile();
1795
+ const expand = requireExpand();
1796
+ const parse = requireParse$1();
1797
+
1798
+ /**
1799
+ * Expand the given pattern or create a regex-compatible string.
1800
+ *
1801
+ * ```js
1802
+ * const braces = require('braces');
1803
+ * console.log(braces('{a,b,c}', { compile: true })); //=> ['(a|b|c)']
1804
+ * console.log(braces('{a,b,c}')); //=> ['a', 'b', 'c']
1805
+ * ```
1806
+ * @param {String} `str`
1807
+ * @param {Object} `options`
1808
+ * @return {String}
1809
+ * @api public
1810
+ */
1811
+
1812
+ const braces = (input, options = {}) => {
1813
+ let output = [];
1814
+
1815
+ if (Array.isArray(input)) {
1816
+ for (let pattern of input) {
1817
+ let result = braces.create(pattern, options);
1818
+ if (Array.isArray(result)) {
1819
+ output.push(...result);
1820
+ } else {
1821
+ output.push(result);
1822
+ }
1823
+ }
1824
+ } else {
1825
+ output = [].concat(braces.create(input, options));
1826
+ }
1827
+
1828
+ if (options && options.expand === true && options.nodupes === true) {
1829
+ output = [...new Set(output)];
1830
+ }
1831
+ return output;
1832
+ };
1833
+
1834
+ /**
1835
+ * Parse the given `str` with the given `options`.
1836
+ *
1837
+ * ```js
1838
+ * // braces.parse(pattern, [, options]);
1839
+ * const ast = braces.parse('a/{b,c}/d');
1840
+ * console.log(ast);
1841
+ * ```
1842
+ * @param {String} pattern Brace pattern to parse
1843
+ * @param {Object} options
1844
+ * @return {Object} Returns an AST
1845
+ * @api public
1846
+ */
1847
+
1848
+ braces.parse = (input, options = {}) => parse(input, options);
1849
+
1850
+ /**
1851
+ * Creates a braces string from an AST, or an AST node.
1852
+ *
1853
+ * ```js
1854
+ * const braces = require('braces');
1855
+ * let ast = braces.parse('foo/{a,b}/bar');
1856
+ * console.log(stringify(ast.nodes[2])); //=> '{a,b}'
1857
+ * ```
1858
+ * @param {String} `input` Brace pattern or AST.
1859
+ * @param {Object} `options`
1860
+ * @return {Array} Returns an array of expanded values.
1861
+ * @api public
1862
+ */
1863
+
1864
+ braces.stringify = (input, options = {}) => {
1865
+ if (typeof input === 'string') {
1866
+ return stringify(braces.parse(input, options), options);
1867
+ }
1868
+ return stringify(input, options);
1869
+ };
1870
+
1871
+ /**
1872
+ * Compiles a brace pattern into a regex-compatible, optimized string.
1873
+ * This method is called by the main [braces](#braces) function by default.
1874
+ *
1875
+ * ```js
1876
+ * const braces = require('braces');
1877
+ * console.log(braces.compile('a/{b,c}/d'));
1878
+ * //=> ['a/(b|c)/d']
1879
+ * ```
1880
+ * @param {String} `input` Brace pattern or AST.
1881
+ * @param {Object} `options`
1882
+ * @return {Array} Returns an array of expanded values.
1883
+ * @api public
1884
+ */
1885
+
1886
+ braces.compile = (input, options = {}) => {
1887
+ if (typeof input === 'string') {
1888
+ input = braces.parse(input, options);
1889
+ }
1890
+ return compile(input, options);
1891
+ };
1892
+
1893
+ /**
1894
+ * Expands a brace pattern into an array. This method is called by the
1895
+ * main [braces](#braces) function when `options.expand` is true. Before
1896
+ * using this method it's recommended that you read the [performance notes](#performance))
1897
+ * and advantages of using [.compile](#compile) instead.
1898
+ *
1899
+ * ```js
1900
+ * const braces = require('braces');
1901
+ * console.log(braces.expand('a/{b,c}/d'));
1902
+ * //=> ['a/b/d', 'a/c/d'];
1903
+ * ```
1904
+ * @param {String} `pattern` Brace pattern
1905
+ * @param {Object} `options`
1906
+ * @return {Array} Returns an array of expanded values.
1907
+ * @api public
1908
+ */
1909
+
1910
+ braces.expand = (input, options = {}) => {
1911
+ if (typeof input === 'string') {
1912
+ input = braces.parse(input, options);
1913
+ }
1914
+
1915
+ let result = expand(input, options);
1916
+
1917
+ // filter out empty strings if specified
1918
+ if (options.noempty === true) {
1919
+ result = result.filter(Boolean);
1920
+ }
1921
+
1922
+ // filter out duplicates if specified
1923
+ if (options.nodupes === true) {
1924
+ result = [...new Set(result)];
1925
+ }
1926
+
1927
+ return result;
1928
+ };
1929
+
1930
+ /**
1931
+ * Processes a brace pattern and returns either an expanded array
1932
+ * (if `options.expand` is true), a highly optimized regex-compatible string.
1933
+ * This method is called by the main [braces](#braces) function.
1934
+ *
1935
+ * ```js
1936
+ * const braces = require('braces');
1937
+ * console.log(braces.create('user-{200..300}/project-{a,b,c}-{1..10}'))
1938
+ * //=> 'user-(20[0-9]|2[1-9][0-9]|300)/project-(a|b|c)-([1-9]|10)'
1939
+ * ```
1940
+ * @param {String} `pattern` Brace pattern
1941
+ * @param {Object} `options`
1942
+ * @return {Array} Returns an array of expanded values.
1943
+ * @api public
1944
+ */
1945
+
1946
+ braces.create = (input, options = {}) => {
1947
+ if (input === '' || input.length < 3) {
1948
+ return [input];
1949
+ }
1950
+
1951
+ return options.expand !== true
1952
+ ? braces.compile(input, options)
1953
+ : braces.expand(input, options);
1954
+ };
1955
+
1956
+ /**
1957
+ * Expose "braces"
1958
+ */
1959
+
1960
+ braces_1 = braces;
1961
+ return braces_1;
1962
+ }
1963
+
1964
+ var utils = {};
1965
+
1966
+ var constants;
1967
+ var hasRequiredConstants;
1968
+
1969
+ function requireConstants () {
1970
+ if (hasRequiredConstants) return constants;
1971
+ hasRequiredConstants = 1;
1972
+
1973
+ const path = require$$0$1;
1974
+ const WIN_SLASH = '\\\\/';
1975
+ const WIN_NO_SLASH = `[^${WIN_SLASH}]`;
1976
+
1977
+ /**
1978
+ * Posix glob regex
1979
+ */
1980
+
1981
+ const DOT_LITERAL = '\\.';
1982
+ const PLUS_LITERAL = '\\+';
1983
+ const QMARK_LITERAL = '\\?';
1984
+ const SLASH_LITERAL = '\\/';
1985
+ const ONE_CHAR = '(?=.)';
1986
+ const QMARK = '[^/]';
1987
+ const END_ANCHOR = `(?:${SLASH_LITERAL}|$)`;
1988
+ const START_ANCHOR = `(?:^|${SLASH_LITERAL})`;
1989
+ const DOTS_SLASH = `${DOT_LITERAL}{1,2}${END_ANCHOR}`;
1990
+ const NO_DOT = `(?!${DOT_LITERAL})`;
1991
+ const NO_DOTS = `(?!${START_ANCHOR}${DOTS_SLASH})`;
1992
+ const NO_DOT_SLASH = `(?!${DOT_LITERAL}{0,1}${END_ANCHOR})`;
1993
+ const NO_DOTS_SLASH = `(?!${DOTS_SLASH})`;
1994
+ const QMARK_NO_DOT = `[^.${SLASH_LITERAL}]`;
1995
+ const STAR = `${QMARK}*?`;
1996
+
1997
+ const POSIX_CHARS = {
1998
+ DOT_LITERAL,
1999
+ PLUS_LITERAL,
2000
+ QMARK_LITERAL,
2001
+ SLASH_LITERAL,
2002
+ ONE_CHAR,
2003
+ QMARK,
2004
+ END_ANCHOR,
2005
+ DOTS_SLASH,
2006
+ NO_DOT,
2007
+ NO_DOTS,
2008
+ NO_DOT_SLASH,
2009
+ NO_DOTS_SLASH,
2010
+ QMARK_NO_DOT,
2011
+ STAR,
2012
+ START_ANCHOR
2013
+ };
2014
+
2015
+ /**
2016
+ * Windows glob regex
2017
+ */
2018
+
2019
+ const WINDOWS_CHARS = {
2020
+ ...POSIX_CHARS,
2021
+
2022
+ SLASH_LITERAL: `[${WIN_SLASH}]`,
2023
+ QMARK: WIN_NO_SLASH,
2024
+ STAR: `${WIN_NO_SLASH}*?`,
2025
+ DOTS_SLASH: `${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$)`,
2026
+ NO_DOT: `(?!${DOT_LITERAL})`,
2027
+ NO_DOTS: `(?!(?:^|[${WIN_SLASH}])${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
2028
+ NO_DOT_SLASH: `(?!${DOT_LITERAL}{0,1}(?:[${WIN_SLASH}]|$))`,
2029
+ NO_DOTS_SLASH: `(?!${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
2030
+ QMARK_NO_DOT: `[^.${WIN_SLASH}]`,
2031
+ START_ANCHOR: `(?:^|[${WIN_SLASH}])`,
2032
+ END_ANCHOR: `(?:[${WIN_SLASH}]|$)`
2033
+ };
2034
+
2035
+ /**
2036
+ * POSIX Bracket Regex
2037
+ */
2038
+
2039
+ const POSIX_REGEX_SOURCE = {
2040
+ alnum: 'a-zA-Z0-9',
2041
+ alpha: 'a-zA-Z',
2042
+ ascii: '\\x00-\\x7F',
2043
+ blank: ' \\t',
2044
+ cntrl: '\\x00-\\x1F\\x7F',
2045
+ digit: '0-9',
2046
+ graph: '\\x21-\\x7E',
2047
+ lower: 'a-z',
2048
+ print: '\\x20-\\x7E ',
2049
+ punct: '\\-!"#$%&\'()\\*+,./:;<=>?@[\\]^_`{|}~',
2050
+ space: ' \\t\\r\\n\\v\\f',
2051
+ upper: 'A-Z',
2052
+ word: 'A-Za-z0-9_',
2053
+ xdigit: 'A-Fa-f0-9'
2054
+ };
2055
+
2056
+ constants = {
2057
+ MAX_LENGTH: 1024 * 64,
2058
+ POSIX_REGEX_SOURCE,
2059
+
2060
+ // regular expressions
2061
+ REGEX_BACKSLASH: /\\(?![*+?^${}(|)[\]])/g,
2062
+ REGEX_NON_SPECIAL_CHARS: /^[^@![\].,$*+?^{}()|\\/]+/,
2063
+ REGEX_SPECIAL_CHARS: /[-*+?.^${}(|)[\]]/,
2064
+ REGEX_SPECIAL_CHARS_BACKREF: /(\\?)((\W)(\3*))/g,
2065
+ REGEX_SPECIAL_CHARS_GLOBAL: /([-*+?.^${}(|)[\]])/g,
2066
+ REGEX_REMOVE_BACKSLASH: /(?:\[.*?[^\\]\]|\\(?=.))/g,
2067
+
2068
+ // Replace globs with equivalent patterns to reduce parsing time.
2069
+ REPLACEMENTS: {
2070
+ '***': '*',
2071
+ '**/**': '**',
2072
+ '**/**/**': '**'
2073
+ },
2074
+
2075
+ // Digits
2076
+ CHAR_0: 48, /* 0 */
2077
+ CHAR_9: 57, /* 9 */
2078
+
2079
+ // Alphabet chars.
2080
+ CHAR_UPPERCASE_A: 65, /* A */
2081
+ CHAR_LOWERCASE_A: 97, /* a */
2082
+ CHAR_UPPERCASE_Z: 90, /* Z */
2083
+ CHAR_LOWERCASE_Z: 122, /* z */
2084
+
2085
+ CHAR_LEFT_PARENTHESES: 40, /* ( */
2086
+ CHAR_RIGHT_PARENTHESES: 41, /* ) */
2087
+
2088
+ CHAR_ASTERISK: 42, /* * */
2089
+
2090
+ // Non-alphabetic chars.
2091
+ CHAR_AMPERSAND: 38, /* & */
2092
+ CHAR_AT: 64, /* @ */
2093
+ CHAR_BACKWARD_SLASH: 92, /* \ */
2094
+ CHAR_CARRIAGE_RETURN: 13, /* \r */
2095
+ CHAR_CIRCUMFLEX_ACCENT: 94, /* ^ */
2096
+ CHAR_COLON: 58, /* : */
2097
+ CHAR_COMMA: 44, /* , */
2098
+ CHAR_DOT: 46, /* . */
2099
+ CHAR_DOUBLE_QUOTE: 34, /* " */
2100
+ CHAR_EQUAL: 61, /* = */
2101
+ CHAR_EXCLAMATION_MARK: 33, /* ! */
2102
+ CHAR_FORM_FEED: 12, /* \f */
2103
+ CHAR_FORWARD_SLASH: 47, /* / */
2104
+ CHAR_GRAVE_ACCENT: 96, /* ` */
2105
+ CHAR_HASH: 35, /* # */
2106
+ CHAR_HYPHEN_MINUS: 45, /* - */
2107
+ CHAR_LEFT_ANGLE_BRACKET: 60, /* < */
2108
+ CHAR_LEFT_CURLY_BRACE: 123, /* { */
2109
+ CHAR_LEFT_SQUARE_BRACKET: 91, /* [ */
2110
+ CHAR_LINE_FEED: 10, /* \n */
2111
+ CHAR_NO_BREAK_SPACE: 160, /* \u00A0 */
2112
+ CHAR_PERCENT: 37, /* % */
2113
+ CHAR_PLUS: 43, /* + */
2114
+ CHAR_QUESTION_MARK: 63, /* ? */
2115
+ CHAR_RIGHT_ANGLE_BRACKET: 62, /* > */
2116
+ CHAR_RIGHT_CURLY_BRACE: 125, /* } */
2117
+ CHAR_RIGHT_SQUARE_BRACKET: 93, /* ] */
2118
+ CHAR_SEMICOLON: 59, /* ; */
2119
+ CHAR_SINGLE_QUOTE: 39, /* ' */
2120
+ CHAR_SPACE: 32, /* */
2121
+ CHAR_TAB: 9, /* \t */
2122
+ CHAR_UNDERSCORE: 95, /* _ */
2123
+ CHAR_VERTICAL_LINE: 124, /* | */
2124
+ CHAR_ZERO_WIDTH_NOBREAK_SPACE: 65279, /* \uFEFF */
2125
+
2126
+ SEP: path.sep,
2127
+
2128
+ /**
2129
+ * Create EXTGLOB_CHARS
2130
+ */
2131
+
2132
+ extglobChars(chars) {
2133
+ return {
2134
+ '!': { type: 'negate', open: '(?:(?!(?:', close: `))${chars.STAR})` },
2135
+ '?': { type: 'qmark', open: '(?:', close: ')?' },
2136
+ '+': { type: 'plus', open: '(?:', close: ')+' },
2137
+ '*': { type: 'star', open: '(?:', close: ')*' },
2138
+ '@': { type: 'at', open: '(?:', close: ')' }
2139
+ };
2140
+ },
2141
+
2142
+ /**
2143
+ * Create GLOB_CHARS
2144
+ */
2145
+
2146
+ globChars(win32) {
2147
+ return win32 === true ? WINDOWS_CHARS : POSIX_CHARS;
2148
+ }
2149
+ };
2150
+ return constants;
2151
+ }
2152
+
2153
+ var hasRequiredUtils;
2154
+
2155
+ function requireUtils () {
2156
+ if (hasRequiredUtils) return utils;
2157
+ hasRequiredUtils = 1;
2158
+ (function (exports) {
2159
+
2160
+ const path = require$$0$1;
2161
+ const win32 = process.platform === 'win32';
2162
+ const {
2163
+ REGEX_BACKSLASH,
2164
+ REGEX_REMOVE_BACKSLASH,
2165
+ REGEX_SPECIAL_CHARS,
2166
+ REGEX_SPECIAL_CHARS_GLOBAL
2167
+ } = requireConstants();
2168
+
2169
+ exports.isObject = val => val !== null && typeof val === 'object' && !Array.isArray(val);
2170
+ exports.hasRegexChars = str => REGEX_SPECIAL_CHARS.test(str);
2171
+ exports.isRegexChar = str => str.length === 1 && exports.hasRegexChars(str);
2172
+ exports.escapeRegex = str => str.replace(REGEX_SPECIAL_CHARS_GLOBAL, '\\$1');
2173
+ exports.toPosixSlashes = str => str.replace(REGEX_BACKSLASH, '/');
2174
+
2175
+ exports.removeBackslashes = str => {
2176
+ return str.replace(REGEX_REMOVE_BACKSLASH, match => {
2177
+ return match === '\\' ? '' : match;
2178
+ });
2179
+ };
2180
+
2181
+ exports.supportsLookbehinds = () => {
2182
+ const segs = process.version.slice(1).split('.').map(Number);
2183
+ if (segs.length === 3 && segs[0] >= 9 || (segs[0] === 8 && segs[1] >= 10)) {
2184
+ return true;
2185
+ }
2186
+ return false;
2187
+ };
2188
+
2189
+ exports.isWindows = options => {
2190
+ if (options && typeof options.windows === 'boolean') {
2191
+ return options.windows;
2192
+ }
2193
+ return win32 === true || path.sep === '\\';
2194
+ };
2195
+
2196
+ exports.escapeLast = (input, char, lastIdx) => {
2197
+ const idx = input.lastIndexOf(char, lastIdx);
2198
+ if (idx === -1) return input;
2199
+ if (input[idx - 1] === '\\') return exports.escapeLast(input, char, idx - 1);
2200
+ return `${input.slice(0, idx)}\\${input.slice(idx)}`;
2201
+ };
2202
+
2203
+ exports.removePrefix = (input, state = {}) => {
2204
+ let output = input;
2205
+ if (output.startsWith('./')) {
2206
+ output = output.slice(2);
2207
+ state.prefix = './';
2208
+ }
2209
+ return output;
2210
+ };
2211
+
2212
+ exports.wrapOutput = (input, state = {}, options = {}) => {
2213
+ const prepend = options.contains ? '' : '^';
2214
+ const append = options.contains ? '' : '$';
2215
+
2216
+ let output = `${prepend}(?:${input})${append}`;
2217
+ if (state.negated === true) {
2218
+ output = `(?:^(?!${output}).*$)`;
2219
+ }
2220
+ return output;
2221
+ };
2222
+ } (utils));
2223
+ return utils;
2224
+ }
2225
+
2226
+ var scan_1;
2227
+ var hasRequiredScan;
2228
+
2229
+ function requireScan () {
2230
+ if (hasRequiredScan) return scan_1;
2231
+ hasRequiredScan = 1;
2232
+
2233
+ const utils = requireUtils();
2234
+ const {
2235
+ CHAR_ASTERISK, /* * */
2236
+ CHAR_AT, /* @ */
2237
+ CHAR_BACKWARD_SLASH, /* \ */
2238
+ CHAR_COMMA, /* , */
2239
+ CHAR_DOT, /* . */
2240
+ CHAR_EXCLAMATION_MARK, /* ! */
2241
+ CHAR_FORWARD_SLASH, /* / */
2242
+ CHAR_LEFT_CURLY_BRACE, /* { */
2243
+ CHAR_LEFT_PARENTHESES, /* ( */
2244
+ CHAR_LEFT_SQUARE_BRACKET, /* [ */
2245
+ CHAR_PLUS, /* + */
2246
+ CHAR_QUESTION_MARK, /* ? */
2247
+ CHAR_RIGHT_CURLY_BRACE, /* } */
2248
+ CHAR_RIGHT_PARENTHESES, /* ) */
2249
+ CHAR_RIGHT_SQUARE_BRACKET /* ] */
2250
+ } = requireConstants();
2251
+
2252
+ const isPathSeparator = code => {
2253
+ return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
2254
+ };
2255
+
2256
+ const depth = token => {
2257
+ if (token.isPrefix !== true) {
2258
+ token.depth = token.isGlobstar ? Infinity : 1;
2259
+ }
2260
+ };
2261
+
2262
+ /**
2263
+ * Quickly scans a glob pattern and returns an object with a handful of
2264
+ * useful properties, like `isGlob`, `path` (the leading non-glob, if it exists),
2265
+ * `glob` (the actual pattern), `negated` (true if the path starts with `!` but not
2266
+ * with `!(`) and `negatedExtglob` (true if the path starts with `!(`).
2267
+ *
2268
+ * ```js
2269
+ * const pm = require('picomatch');
2270
+ * console.log(pm.scan('foo/bar/*.js'));
2271
+ * { isGlob: true, input: 'foo/bar/*.js', base: 'foo/bar', glob: '*.js' }
2272
+ * ```
2273
+ * @param {String} `str`
2274
+ * @param {Object} `options`
2275
+ * @return {Object} Returns an object with tokens and regex source string.
2276
+ * @api public
2277
+ */
2278
+
2279
+ const scan = (input, options) => {
2280
+ const opts = options || {};
2281
+
2282
+ const length = input.length - 1;
2283
+ const scanToEnd = opts.parts === true || opts.scanToEnd === true;
2284
+ const slashes = [];
2285
+ const tokens = [];
2286
+ const parts = [];
2287
+
2288
+ let str = input;
2289
+ let index = -1;
2290
+ let start = 0;
2291
+ let lastIndex = 0;
2292
+ let isBrace = false;
2293
+ let isBracket = false;
2294
+ let isGlob = false;
2295
+ let isExtglob = false;
2296
+ let isGlobstar = false;
2297
+ let braceEscaped = false;
2298
+ let backslashes = false;
2299
+ let negated = false;
2300
+ let negatedExtglob = false;
2301
+ let finished = false;
2302
+ let braces = 0;
2303
+ let prev;
2304
+ let code;
2305
+ let token = { value: '', depth: 0, isGlob: false };
2306
+
2307
+ const eos = () => index >= length;
2308
+ const peek = () => str.charCodeAt(index + 1);
2309
+ const advance = () => {
2310
+ prev = code;
2311
+ return str.charCodeAt(++index);
2312
+ };
2313
+
2314
+ while (index < length) {
2315
+ code = advance();
2316
+ let next;
2317
+
2318
+ if (code === CHAR_BACKWARD_SLASH) {
2319
+ backslashes = token.backslashes = true;
2320
+ code = advance();
2321
+
2322
+ if (code === CHAR_LEFT_CURLY_BRACE) {
2323
+ braceEscaped = true;
2324
+ }
2325
+ continue;
2326
+ }
2327
+
2328
+ if (braceEscaped === true || code === CHAR_LEFT_CURLY_BRACE) {
2329
+ braces++;
2330
+
2331
+ while (eos() !== true && (code = advance())) {
2332
+ if (code === CHAR_BACKWARD_SLASH) {
2333
+ backslashes = token.backslashes = true;
2334
+ advance();
2335
+ continue;
2336
+ }
2337
+
2338
+ if (code === CHAR_LEFT_CURLY_BRACE) {
2339
+ braces++;
2340
+ continue;
2341
+ }
2342
+
2343
+ if (braceEscaped !== true && code === CHAR_DOT && (code = advance()) === CHAR_DOT) {
2344
+ isBrace = token.isBrace = true;
2345
+ isGlob = token.isGlob = true;
2346
+ finished = true;
2347
+
2348
+ if (scanToEnd === true) {
2349
+ continue;
2350
+ }
2351
+
2352
+ break;
2353
+ }
2354
+
2355
+ if (braceEscaped !== true && code === CHAR_COMMA) {
2356
+ isBrace = token.isBrace = true;
2357
+ isGlob = token.isGlob = true;
2358
+ finished = true;
2359
+
2360
+ if (scanToEnd === true) {
2361
+ continue;
2362
+ }
2363
+
2364
+ break;
2365
+ }
2366
+
2367
+ if (code === CHAR_RIGHT_CURLY_BRACE) {
2368
+ braces--;
2369
+
2370
+ if (braces === 0) {
2371
+ braceEscaped = false;
2372
+ isBrace = token.isBrace = true;
2373
+ finished = true;
2374
+ break;
2375
+ }
2376
+ }
2377
+ }
2378
+
2379
+ if (scanToEnd === true) {
2380
+ continue;
2381
+ }
2382
+
2383
+ break;
2384
+ }
2385
+
2386
+ if (code === CHAR_FORWARD_SLASH) {
2387
+ slashes.push(index);
2388
+ tokens.push(token);
2389
+ token = { value: '', depth: 0, isGlob: false };
2390
+
2391
+ if (finished === true) continue;
2392
+ if (prev === CHAR_DOT && index === (start + 1)) {
2393
+ start += 2;
2394
+ continue;
2395
+ }
2396
+
2397
+ lastIndex = index + 1;
2398
+ continue;
2399
+ }
2400
+
2401
+ if (opts.noext !== true) {
2402
+ const isExtglobChar = code === CHAR_PLUS
2403
+ || code === CHAR_AT
2404
+ || code === CHAR_ASTERISK
2405
+ || code === CHAR_QUESTION_MARK
2406
+ || code === CHAR_EXCLAMATION_MARK;
2407
+
2408
+ if (isExtglobChar === true && peek() === CHAR_LEFT_PARENTHESES) {
2409
+ isGlob = token.isGlob = true;
2410
+ isExtglob = token.isExtglob = true;
2411
+ finished = true;
2412
+ if (code === CHAR_EXCLAMATION_MARK && index === start) {
2413
+ negatedExtglob = true;
2414
+ }
2415
+
2416
+ if (scanToEnd === true) {
2417
+ while (eos() !== true && (code = advance())) {
2418
+ if (code === CHAR_BACKWARD_SLASH) {
2419
+ backslashes = token.backslashes = true;
2420
+ code = advance();
2421
+ continue;
2422
+ }
2423
+
2424
+ if (code === CHAR_RIGHT_PARENTHESES) {
2425
+ isGlob = token.isGlob = true;
2426
+ finished = true;
2427
+ break;
2428
+ }
2429
+ }
2430
+ continue;
2431
+ }
2432
+ break;
2433
+ }
2434
+ }
2435
+
2436
+ if (code === CHAR_ASTERISK) {
2437
+ if (prev === CHAR_ASTERISK) isGlobstar = token.isGlobstar = true;
2438
+ isGlob = token.isGlob = true;
2439
+ finished = true;
2440
+
2441
+ if (scanToEnd === true) {
2442
+ continue;
2443
+ }
2444
+ break;
2445
+ }
2446
+
2447
+ if (code === CHAR_QUESTION_MARK) {
2448
+ isGlob = token.isGlob = true;
2449
+ finished = true;
2450
+
2451
+ if (scanToEnd === true) {
2452
+ continue;
2453
+ }
2454
+ break;
2455
+ }
2456
+
2457
+ if (code === CHAR_LEFT_SQUARE_BRACKET) {
2458
+ while (eos() !== true && (next = advance())) {
2459
+ if (next === CHAR_BACKWARD_SLASH) {
2460
+ backslashes = token.backslashes = true;
2461
+ advance();
2462
+ continue;
2463
+ }
2464
+
2465
+ if (next === CHAR_RIGHT_SQUARE_BRACKET) {
2466
+ isBracket = token.isBracket = true;
2467
+ isGlob = token.isGlob = true;
2468
+ finished = true;
2469
+ break;
2470
+ }
2471
+ }
2472
+
2473
+ if (scanToEnd === true) {
2474
+ continue;
2475
+ }
2476
+
2477
+ break;
2478
+ }
2479
+
2480
+ if (opts.nonegate !== true && code === CHAR_EXCLAMATION_MARK && index === start) {
2481
+ negated = token.negated = true;
2482
+ start++;
2483
+ continue;
2484
+ }
2485
+
2486
+ if (opts.noparen !== true && code === CHAR_LEFT_PARENTHESES) {
2487
+ isGlob = token.isGlob = true;
2488
+
2489
+ if (scanToEnd === true) {
2490
+ while (eos() !== true && (code = advance())) {
2491
+ if (code === CHAR_LEFT_PARENTHESES) {
2492
+ backslashes = token.backslashes = true;
2493
+ code = advance();
2494
+ continue;
2495
+ }
2496
+
2497
+ if (code === CHAR_RIGHT_PARENTHESES) {
2498
+ finished = true;
2499
+ break;
2500
+ }
2501
+ }
2502
+ continue;
2503
+ }
2504
+ break;
2505
+ }
2506
+
2507
+ if (isGlob === true) {
2508
+ finished = true;
2509
+
2510
+ if (scanToEnd === true) {
2511
+ continue;
2512
+ }
2513
+
2514
+ break;
2515
+ }
2516
+ }
2517
+
2518
+ if (opts.noext === true) {
2519
+ isExtglob = false;
2520
+ isGlob = false;
2521
+ }
2522
+
2523
+ let base = str;
2524
+ let prefix = '';
2525
+ let glob = '';
2526
+
2527
+ if (start > 0) {
2528
+ prefix = str.slice(0, start);
2529
+ str = str.slice(start);
2530
+ lastIndex -= start;
2531
+ }
2532
+
2533
+ if (base && isGlob === true && lastIndex > 0) {
2534
+ base = str.slice(0, lastIndex);
2535
+ glob = str.slice(lastIndex);
2536
+ } else if (isGlob === true) {
2537
+ base = '';
2538
+ glob = str;
2539
+ } else {
2540
+ base = str;
2541
+ }
2542
+
2543
+ if (base && base !== '' && base !== '/' && base !== str) {
2544
+ if (isPathSeparator(base.charCodeAt(base.length - 1))) {
2545
+ base = base.slice(0, -1);
2546
+ }
2547
+ }
2548
+
2549
+ if (opts.unescape === true) {
2550
+ if (glob) glob = utils.removeBackslashes(glob);
2551
+
2552
+ if (base && backslashes === true) {
2553
+ base = utils.removeBackslashes(base);
2554
+ }
2555
+ }
2556
+
2557
+ const state = {
2558
+ prefix,
2559
+ input,
2560
+ start,
2561
+ base,
2562
+ glob,
2563
+ isBrace,
2564
+ isBracket,
2565
+ isGlob,
2566
+ isExtglob,
2567
+ isGlobstar,
2568
+ negated,
2569
+ negatedExtglob
2570
+ };
2571
+
2572
+ if (opts.tokens === true) {
2573
+ state.maxDepth = 0;
2574
+ if (!isPathSeparator(code)) {
2575
+ tokens.push(token);
2576
+ }
2577
+ state.tokens = tokens;
2578
+ }
2579
+
2580
+ if (opts.parts === true || opts.tokens === true) {
2581
+ let prevIndex;
2582
+
2583
+ for (let idx = 0; idx < slashes.length; idx++) {
2584
+ const n = prevIndex ? prevIndex + 1 : start;
2585
+ const i = slashes[idx];
2586
+ const value = input.slice(n, i);
2587
+ if (opts.tokens) {
2588
+ if (idx === 0 && start !== 0) {
2589
+ tokens[idx].isPrefix = true;
2590
+ tokens[idx].value = prefix;
2591
+ } else {
2592
+ tokens[idx].value = value;
2593
+ }
2594
+ depth(tokens[idx]);
2595
+ state.maxDepth += tokens[idx].depth;
2596
+ }
2597
+ if (idx !== 0 || value !== '') {
2598
+ parts.push(value);
2599
+ }
2600
+ prevIndex = i;
2601
+ }
2602
+
2603
+ if (prevIndex && prevIndex + 1 < input.length) {
2604
+ const value = input.slice(prevIndex + 1);
2605
+ parts.push(value);
2606
+
2607
+ if (opts.tokens) {
2608
+ tokens[tokens.length - 1].value = value;
2609
+ depth(tokens[tokens.length - 1]);
2610
+ state.maxDepth += tokens[tokens.length - 1].depth;
2611
+ }
2612
+ }
2613
+
2614
+ state.slashes = slashes;
2615
+ state.parts = parts;
2616
+ }
2617
+
2618
+ return state;
2619
+ };
2620
+
2621
+ scan_1 = scan;
2622
+ return scan_1;
2623
+ }
2624
+
2625
+ var parse_1;
2626
+ var hasRequiredParse;
2627
+
2628
+ function requireParse () {
2629
+ if (hasRequiredParse) return parse_1;
2630
+ hasRequiredParse = 1;
2631
+
2632
+ const constants = requireConstants();
2633
+ const utils = requireUtils();
2634
+
2635
+ /**
2636
+ * Constants
2637
+ */
2638
+
2639
+ const {
2640
+ MAX_LENGTH,
2641
+ POSIX_REGEX_SOURCE,
2642
+ REGEX_NON_SPECIAL_CHARS,
2643
+ REGEX_SPECIAL_CHARS_BACKREF,
2644
+ REPLACEMENTS
2645
+ } = constants;
2646
+
2647
+ /**
2648
+ * Helpers
2649
+ */
2650
+
2651
+ const expandRange = (args, options) => {
2652
+ if (typeof options.expandRange === 'function') {
2653
+ return options.expandRange(...args, options);
2654
+ }
2655
+
2656
+ args.sort();
2657
+ const value = `[${args.join('-')}]`;
2658
+
2659
+ try {
2660
+ /* eslint-disable-next-line no-new */
2661
+ new RegExp(value);
2662
+ } catch (ex) {
2663
+ return args.map(v => utils.escapeRegex(v)).join('..');
2664
+ }
2665
+
2666
+ return value;
2667
+ };
2668
+
2669
+ /**
2670
+ * Create the message for a syntax error
2671
+ */
2672
+
2673
+ const syntaxError = (type, char) => {
2674
+ return `Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`;
2675
+ };
2676
+
2677
+ /**
2678
+ * Parse the given input string.
2679
+ * @param {String} input
2680
+ * @param {Object} options
2681
+ * @return {Object}
2682
+ */
2683
+
2684
+ const parse = (input, options) => {
2685
+ if (typeof input !== 'string') {
2686
+ throw new TypeError('Expected a string');
2687
+ }
2688
+
2689
+ input = REPLACEMENTS[input] || input;
2690
+
2691
+ const opts = { ...options };
2692
+ const max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
2693
+
2694
+ let len = input.length;
2695
+ if (len > max) {
2696
+ throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
2697
+ }
2698
+
2699
+ const bos = { type: 'bos', value: '', output: opts.prepend || '' };
2700
+ const tokens = [bos];
2701
+
2702
+ const capture = opts.capture ? '' : '?:';
2703
+ const win32 = utils.isWindows(options);
2704
+
2705
+ // create constants based on platform, for windows or posix
2706
+ const PLATFORM_CHARS = constants.globChars(win32);
2707
+ const EXTGLOB_CHARS = constants.extglobChars(PLATFORM_CHARS);
2708
+
2709
+ const {
2710
+ DOT_LITERAL,
2711
+ PLUS_LITERAL,
2712
+ SLASH_LITERAL,
2713
+ ONE_CHAR,
2714
+ DOTS_SLASH,
2715
+ NO_DOT,
2716
+ NO_DOT_SLASH,
2717
+ NO_DOTS_SLASH,
2718
+ QMARK,
2719
+ QMARK_NO_DOT,
2720
+ STAR,
2721
+ START_ANCHOR
2722
+ } = PLATFORM_CHARS;
2723
+
2724
+ const globstar = opts => {
2725
+ return `(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
2726
+ };
2727
+
2728
+ const nodot = opts.dot ? '' : NO_DOT;
2729
+ const qmarkNoDot = opts.dot ? QMARK : QMARK_NO_DOT;
2730
+ let star = opts.bash === true ? globstar(opts) : STAR;
2731
+
2732
+ if (opts.capture) {
2733
+ star = `(${star})`;
2734
+ }
2735
+
2736
+ // minimatch options support
2737
+ if (typeof opts.noext === 'boolean') {
2738
+ opts.noextglob = opts.noext;
2739
+ }
2740
+
2741
+ const state = {
2742
+ input,
2743
+ index: -1,
2744
+ start: 0,
2745
+ dot: opts.dot === true,
2746
+ consumed: '',
2747
+ output: '',
2748
+ prefix: '',
2749
+ backtrack: false,
2750
+ negated: false,
2751
+ brackets: 0,
2752
+ braces: 0,
2753
+ parens: 0,
2754
+ quotes: 0,
2755
+ globstar: false,
2756
+ tokens
2757
+ };
2758
+
2759
+ input = utils.removePrefix(input, state);
2760
+ len = input.length;
2761
+
2762
+ const extglobs = [];
2763
+ const braces = [];
2764
+ const stack = [];
2765
+ let prev = bos;
2766
+ let value;
2767
+
2768
+ /**
2769
+ * Tokenizing helpers
2770
+ */
2771
+
2772
+ const eos = () => state.index === len - 1;
2773
+ const peek = state.peek = (n = 1) => input[state.index + n];
2774
+ const advance = state.advance = () => input[++state.index] || '';
2775
+ const remaining = () => input.slice(state.index + 1);
2776
+ const consume = (value = '', num = 0) => {
2777
+ state.consumed += value;
2778
+ state.index += num;
2779
+ };
2780
+
2781
+ const append = token => {
2782
+ state.output += token.output != null ? token.output : token.value;
2783
+ consume(token.value);
2784
+ };
2785
+
2786
+ const negate = () => {
2787
+ let count = 1;
2788
+
2789
+ while (peek() === '!' && (peek(2) !== '(' || peek(3) === '?')) {
2790
+ advance();
2791
+ state.start++;
2792
+ count++;
2793
+ }
2794
+
2795
+ if (count % 2 === 0) {
2796
+ return false;
2797
+ }
2798
+
2799
+ state.negated = true;
2800
+ state.start++;
2801
+ return true;
2802
+ };
2803
+
2804
+ const increment = type => {
2805
+ state[type]++;
2806
+ stack.push(type);
2807
+ };
2808
+
2809
+ const decrement = type => {
2810
+ state[type]--;
2811
+ stack.pop();
2812
+ };
2813
+
2814
+ /**
2815
+ * Push tokens onto the tokens array. This helper speeds up
2816
+ * tokenizing by 1) helping us avoid backtracking as much as possible,
2817
+ * and 2) helping us avoid creating extra tokens when consecutive
2818
+ * characters are plain text. This improves performance and simplifies
2819
+ * lookbehinds.
2820
+ */
2821
+
2822
+ const push = tok => {
2823
+ if (prev.type === 'globstar') {
2824
+ const isBrace = state.braces > 0 && (tok.type === 'comma' || tok.type === 'brace');
2825
+ const isExtglob = tok.extglob === true || (extglobs.length && (tok.type === 'pipe' || tok.type === 'paren'));
2826
+
2827
+ if (tok.type !== 'slash' && tok.type !== 'paren' && !isBrace && !isExtglob) {
2828
+ state.output = state.output.slice(0, -prev.output.length);
2829
+ prev.type = 'star';
2830
+ prev.value = '*';
2831
+ prev.output = star;
2832
+ state.output += prev.output;
2833
+ }
2834
+ }
2835
+
2836
+ if (extglobs.length && tok.type !== 'paren') {
2837
+ extglobs[extglobs.length - 1].inner += tok.value;
2838
+ }
2839
+
2840
+ if (tok.value || tok.output) append(tok);
2841
+ if (prev && prev.type === 'text' && tok.type === 'text') {
2842
+ prev.value += tok.value;
2843
+ prev.output = (prev.output || '') + tok.value;
2844
+ return;
2845
+ }
2846
+
2847
+ tok.prev = prev;
2848
+ tokens.push(tok);
2849
+ prev = tok;
2850
+ };
2851
+
2852
+ const extglobOpen = (type, value) => {
2853
+ const token = { ...EXTGLOB_CHARS[value], conditions: 1, inner: '' };
2854
+
2855
+ token.prev = prev;
2856
+ token.parens = state.parens;
2857
+ token.output = state.output;
2858
+ const output = (opts.capture ? '(' : '') + token.open;
2859
+
2860
+ increment('parens');
2861
+ push({ type, value, output: state.output ? '' : ONE_CHAR });
2862
+ push({ type: 'paren', extglob: true, value: advance(), output });
2863
+ extglobs.push(token);
2864
+ };
2865
+
2866
+ const extglobClose = token => {
2867
+ let output = token.close + (opts.capture ? ')' : '');
2868
+ let rest;
2869
+
2870
+ if (token.type === 'negate') {
2871
+ let extglobStar = star;
2872
+
2873
+ if (token.inner && token.inner.length > 1 && token.inner.includes('/')) {
2874
+ extglobStar = globstar(opts);
2875
+ }
2876
+
2877
+ if (extglobStar !== star || eos() || /^\)+$/.test(remaining())) {
2878
+ output = token.close = `)$))${extglobStar}`;
2879
+ }
2880
+
2881
+ if (token.inner.includes('*') && (rest = remaining()) && /^\.[^\\/.]+$/.test(rest)) {
2882
+ // Any non-magical string (`.ts`) or even nested expression (`.{ts,tsx}`) can follow after the closing parenthesis.
2883
+ // In this case, we need to parse the string and use it in the output of the original pattern.
2884
+ // Suitable patterns: `/!(*.d).ts`, `/!(*.d).{ts,tsx}`, `**/!(*-dbg).@(js)`.
2885
+ //
2886
+ // Disabling the `fastpaths` option due to a problem with parsing strings as `.ts` in the pattern like `**/!(*.d).ts`.
2887
+ const expression = parse(rest, { ...options, fastpaths: false }).output;
2888
+
2889
+ output = token.close = `)${expression})${extglobStar})`;
2890
+ }
2891
+
2892
+ if (token.prev.type === 'bos') {
2893
+ state.negatedExtglob = true;
2894
+ }
2895
+ }
2896
+
2897
+ push({ type: 'paren', extglob: true, value, output });
2898
+ decrement('parens');
2899
+ };
2900
+
2901
+ /**
2902
+ * Fast paths
2903
+ */
2904
+
2905
+ if (opts.fastpaths !== false && !/(^[*!]|[/()[\]{}"])/.test(input)) {
2906
+ let backslashes = false;
2907
+
2908
+ let output = input.replace(REGEX_SPECIAL_CHARS_BACKREF, (m, esc, chars, first, rest, index) => {
2909
+ if (first === '\\') {
2910
+ backslashes = true;
2911
+ return m;
2912
+ }
2913
+
2914
+ if (first === '?') {
2915
+ if (esc) {
2916
+ return esc + first + (rest ? QMARK.repeat(rest.length) : '');
2917
+ }
2918
+ if (index === 0) {
2919
+ return qmarkNoDot + (rest ? QMARK.repeat(rest.length) : '');
2920
+ }
2921
+ return QMARK.repeat(chars.length);
2922
+ }
2923
+
2924
+ if (first === '.') {
2925
+ return DOT_LITERAL.repeat(chars.length);
2926
+ }
2927
+
2928
+ if (first === '*') {
2929
+ if (esc) {
2930
+ return esc + first + (rest ? star : '');
2931
+ }
2932
+ return star;
2933
+ }
2934
+ return esc ? m : `\\${m}`;
2935
+ });
2936
+
2937
+ if (backslashes === true) {
2938
+ if (opts.unescape === true) {
2939
+ output = output.replace(/\\/g, '');
2940
+ } else {
2941
+ output = output.replace(/\\+/g, m => {
2942
+ return m.length % 2 === 0 ? '\\\\' : (m ? '\\' : '');
2943
+ });
2944
+ }
2945
+ }
2946
+
2947
+ if (output === input && opts.contains === true) {
2948
+ state.output = input;
2949
+ return state;
2950
+ }
2951
+
2952
+ state.output = utils.wrapOutput(output, state, options);
2953
+ return state;
2954
+ }
2955
+
2956
+ /**
2957
+ * Tokenize input until we reach end-of-string
2958
+ */
2959
+
2960
+ while (!eos()) {
2961
+ value = advance();
2962
+
2963
+ if (value === '\u0000') {
2964
+ continue;
2965
+ }
2966
+
2967
+ /**
2968
+ * Escaped characters
2969
+ */
2970
+
2971
+ if (value === '\\') {
2972
+ const next = peek();
2973
+
2974
+ if (next === '/' && opts.bash !== true) {
2975
+ continue;
2976
+ }
2977
+
2978
+ if (next === '.' || next === ';') {
2979
+ continue;
2980
+ }
2981
+
2982
+ if (!next) {
2983
+ value += '\\';
2984
+ push({ type: 'text', value });
2985
+ continue;
2986
+ }
2987
+
2988
+ // collapse slashes to reduce potential for exploits
2989
+ const match = /^\\+/.exec(remaining());
2990
+ let slashes = 0;
2991
+
2992
+ if (match && match[0].length > 2) {
2993
+ slashes = match[0].length;
2994
+ state.index += slashes;
2995
+ if (slashes % 2 !== 0) {
2996
+ value += '\\';
2997
+ }
2998
+ }
2999
+
3000
+ if (opts.unescape === true) {
3001
+ value = advance();
3002
+ } else {
3003
+ value += advance();
3004
+ }
3005
+
3006
+ if (state.brackets === 0) {
3007
+ push({ type: 'text', value });
3008
+ continue;
3009
+ }
3010
+ }
3011
+
3012
+ /**
3013
+ * If we're inside a regex character class, continue
3014
+ * until we reach the closing bracket.
3015
+ */
3016
+
3017
+ if (state.brackets > 0 && (value !== ']' || prev.value === '[' || prev.value === '[^')) {
3018
+ if (opts.posix !== false && value === ':') {
3019
+ const inner = prev.value.slice(1);
3020
+ if (inner.includes('[')) {
3021
+ prev.posix = true;
3022
+
3023
+ if (inner.includes(':')) {
3024
+ const idx = prev.value.lastIndexOf('[');
3025
+ const pre = prev.value.slice(0, idx);
3026
+ const rest = prev.value.slice(idx + 2);
3027
+ const posix = POSIX_REGEX_SOURCE[rest];
3028
+ if (posix) {
3029
+ prev.value = pre + posix;
3030
+ state.backtrack = true;
3031
+ advance();
3032
+
3033
+ if (!bos.output && tokens.indexOf(prev) === 1) {
3034
+ bos.output = ONE_CHAR;
3035
+ }
3036
+ continue;
3037
+ }
3038
+ }
3039
+ }
3040
+ }
3041
+
3042
+ if ((value === '[' && peek() !== ':') || (value === '-' && peek() === ']')) {
3043
+ value = `\\${value}`;
3044
+ }
3045
+
3046
+ if (value === ']' && (prev.value === '[' || prev.value === '[^')) {
3047
+ value = `\\${value}`;
3048
+ }
3049
+
3050
+ if (opts.posix === true && value === '!' && prev.value === '[') {
3051
+ value = '^';
3052
+ }
3053
+
3054
+ prev.value += value;
3055
+ append({ value });
3056
+ continue;
3057
+ }
3058
+
3059
+ /**
3060
+ * If we're inside a quoted string, continue
3061
+ * until we reach the closing double quote.
3062
+ */
3063
+
3064
+ if (state.quotes === 1 && value !== '"') {
3065
+ value = utils.escapeRegex(value);
3066
+ prev.value += value;
3067
+ append({ value });
3068
+ continue;
3069
+ }
3070
+
3071
+ /**
3072
+ * Double quotes
3073
+ */
3074
+
3075
+ if (value === '"') {
3076
+ state.quotes = state.quotes === 1 ? 0 : 1;
3077
+ if (opts.keepQuotes === true) {
3078
+ push({ type: 'text', value });
3079
+ }
3080
+ continue;
3081
+ }
3082
+
3083
+ /**
3084
+ * Parentheses
3085
+ */
3086
+
3087
+ if (value === '(') {
3088
+ increment('parens');
3089
+ push({ type: 'paren', value });
3090
+ continue;
3091
+ }
3092
+
3093
+ if (value === ')') {
3094
+ if (state.parens === 0 && opts.strictBrackets === true) {
3095
+ throw new SyntaxError(syntaxError('opening', '('));
3096
+ }
3097
+
3098
+ const extglob = extglobs[extglobs.length - 1];
3099
+ if (extglob && state.parens === extglob.parens + 1) {
3100
+ extglobClose(extglobs.pop());
3101
+ continue;
3102
+ }
3103
+
3104
+ push({ type: 'paren', value, output: state.parens ? ')' : '\\)' });
3105
+ decrement('parens');
3106
+ continue;
3107
+ }
3108
+
3109
+ /**
3110
+ * Square brackets
3111
+ */
3112
+
3113
+ if (value === '[') {
3114
+ if (opts.nobracket === true || !remaining().includes(']')) {
3115
+ if (opts.nobracket !== true && opts.strictBrackets === true) {
3116
+ throw new SyntaxError(syntaxError('closing', ']'));
3117
+ }
3118
+
3119
+ value = `\\${value}`;
3120
+ } else {
3121
+ increment('brackets');
3122
+ }
3123
+
3124
+ push({ type: 'bracket', value });
3125
+ continue;
3126
+ }
3127
+
3128
+ if (value === ']') {
3129
+ if (opts.nobracket === true || (prev && prev.type === 'bracket' && prev.value.length === 1)) {
3130
+ push({ type: 'text', value, output: `\\${value}` });
3131
+ continue;
3132
+ }
3133
+
3134
+ if (state.brackets === 0) {
3135
+ if (opts.strictBrackets === true) {
3136
+ throw new SyntaxError(syntaxError('opening', '['));
3137
+ }
3138
+
3139
+ push({ type: 'text', value, output: `\\${value}` });
3140
+ continue;
3141
+ }
3142
+
3143
+ decrement('brackets');
3144
+
3145
+ const prevValue = prev.value.slice(1);
3146
+ if (prev.posix !== true && prevValue[0] === '^' && !prevValue.includes('/')) {
3147
+ value = `/${value}`;
3148
+ }
3149
+
3150
+ prev.value += value;
3151
+ append({ value });
3152
+
3153
+ // when literal brackets are explicitly disabled
3154
+ // assume we should match with a regex character class
3155
+ if (opts.literalBrackets === false || utils.hasRegexChars(prevValue)) {
3156
+ continue;
3157
+ }
3158
+
3159
+ const escaped = utils.escapeRegex(prev.value);
3160
+ state.output = state.output.slice(0, -prev.value.length);
3161
+
3162
+ // when literal brackets are explicitly enabled
3163
+ // assume we should escape the brackets to match literal characters
3164
+ if (opts.literalBrackets === true) {
3165
+ state.output += escaped;
3166
+ prev.value = escaped;
3167
+ continue;
3168
+ }
3169
+
3170
+ // when the user specifies nothing, try to match both
3171
+ prev.value = `(${capture}${escaped}|${prev.value})`;
3172
+ state.output += prev.value;
3173
+ continue;
3174
+ }
3175
+
3176
+ /**
3177
+ * Braces
3178
+ */
3179
+
3180
+ if (value === '{' && opts.nobrace !== true) {
3181
+ increment('braces');
3182
+
3183
+ const open = {
3184
+ type: 'brace',
3185
+ value,
3186
+ output: '(',
3187
+ outputIndex: state.output.length,
3188
+ tokensIndex: state.tokens.length
3189
+ };
3190
+
3191
+ braces.push(open);
3192
+ push(open);
3193
+ continue;
3194
+ }
3195
+
3196
+ if (value === '}') {
3197
+ const brace = braces[braces.length - 1];
3198
+
3199
+ if (opts.nobrace === true || !brace) {
3200
+ push({ type: 'text', value, output: value });
3201
+ continue;
3202
+ }
3203
+
3204
+ let output = ')';
3205
+
3206
+ if (brace.dots === true) {
3207
+ const arr = tokens.slice();
3208
+ const range = [];
3209
+
3210
+ for (let i = arr.length - 1; i >= 0; i--) {
3211
+ tokens.pop();
3212
+ if (arr[i].type === 'brace') {
3213
+ break;
3214
+ }
3215
+ if (arr[i].type !== 'dots') {
3216
+ range.unshift(arr[i].value);
3217
+ }
3218
+ }
3219
+
3220
+ output = expandRange(range, opts);
3221
+ state.backtrack = true;
3222
+ }
3223
+
3224
+ if (brace.comma !== true && brace.dots !== true) {
3225
+ const out = state.output.slice(0, brace.outputIndex);
3226
+ const toks = state.tokens.slice(brace.tokensIndex);
3227
+ brace.value = brace.output = '\\{';
3228
+ value = output = '\\}';
3229
+ state.output = out;
3230
+ for (const t of toks) {
3231
+ state.output += (t.output || t.value);
3232
+ }
3233
+ }
3234
+
3235
+ push({ type: 'brace', value, output });
3236
+ decrement('braces');
3237
+ braces.pop();
3238
+ continue;
3239
+ }
3240
+
3241
+ /**
3242
+ * Pipes
3243
+ */
3244
+
3245
+ if (value === '|') {
3246
+ if (extglobs.length > 0) {
3247
+ extglobs[extglobs.length - 1].conditions++;
3248
+ }
3249
+ push({ type: 'text', value });
3250
+ continue;
3251
+ }
3252
+
3253
+ /**
3254
+ * Commas
3255
+ */
3256
+
3257
+ if (value === ',') {
3258
+ let output = value;
3259
+
3260
+ const brace = braces[braces.length - 1];
3261
+ if (brace && stack[stack.length - 1] === 'braces') {
3262
+ brace.comma = true;
3263
+ output = '|';
3264
+ }
3265
+
3266
+ push({ type: 'comma', value, output });
3267
+ continue;
3268
+ }
3269
+
3270
+ /**
3271
+ * Slashes
3272
+ */
3273
+
3274
+ if (value === '/') {
3275
+ // if the beginning of the glob is "./", advance the start
3276
+ // to the current index, and don't add the "./" characters
3277
+ // to the state. This greatly simplifies lookbehinds when
3278
+ // checking for BOS characters like "!" and "." (not "./")
3279
+ if (prev.type === 'dot' && state.index === state.start + 1) {
3280
+ state.start = state.index + 1;
3281
+ state.consumed = '';
3282
+ state.output = '';
3283
+ tokens.pop();
3284
+ prev = bos; // reset "prev" to the first token
3285
+ continue;
3286
+ }
3287
+
3288
+ push({ type: 'slash', value, output: SLASH_LITERAL });
3289
+ continue;
3290
+ }
3291
+
3292
+ /**
3293
+ * Dots
3294
+ */
3295
+
3296
+ if (value === '.') {
3297
+ if (state.braces > 0 && prev.type === 'dot') {
3298
+ if (prev.value === '.') prev.output = DOT_LITERAL;
3299
+ const brace = braces[braces.length - 1];
3300
+ prev.type = 'dots';
3301
+ prev.output += value;
3302
+ prev.value += value;
3303
+ brace.dots = true;
3304
+ continue;
3305
+ }
3306
+
3307
+ if ((state.braces + state.parens) === 0 && prev.type !== 'bos' && prev.type !== 'slash') {
3308
+ push({ type: 'text', value, output: DOT_LITERAL });
3309
+ continue;
3310
+ }
3311
+
3312
+ push({ type: 'dot', value, output: DOT_LITERAL });
3313
+ continue;
3314
+ }
3315
+
3316
+ /**
3317
+ * Question marks
3318
+ */
3319
+
3320
+ if (value === '?') {
3321
+ const isGroup = prev && prev.value === '(';
3322
+ if (!isGroup && opts.noextglob !== true && peek() === '(' && peek(2) !== '?') {
3323
+ extglobOpen('qmark', value);
3324
+ continue;
3325
+ }
3326
+
3327
+ if (prev && prev.type === 'paren') {
3328
+ const next = peek();
3329
+ let output = value;
3330
+
3331
+ if (next === '<' && !utils.supportsLookbehinds()) {
3332
+ throw new Error('Node.js v10 or higher is required for regex lookbehinds');
3333
+ }
3334
+
3335
+ if ((prev.value === '(' && !/[!=<:]/.test(next)) || (next === '<' && !/<([!=]|\w+>)/.test(remaining()))) {
3336
+ output = `\\${value}`;
3337
+ }
3338
+
3339
+ push({ type: 'text', value, output });
3340
+ continue;
3341
+ }
3342
+
3343
+ if (opts.dot !== true && (prev.type === 'slash' || prev.type === 'bos')) {
3344
+ push({ type: 'qmark', value, output: QMARK_NO_DOT });
3345
+ continue;
3346
+ }
3347
+
3348
+ push({ type: 'qmark', value, output: QMARK });
3349
+ continue;
3350
+ }
3351
+
3352
+ /**
3353
+ * Exclamation
3354
+ */
3355
+
3356
+ if (value === '!') {
3357
+ if (opts.noextglob !== true && peek() === '(') {
3358
+ if (peek(2) !== '?' || !/[!=<:]/.test(peek(3))) {
3359
+ extglobOpen('negate', value);
3360
+ continue;
3361
+ }
3362
+ }
3363
+
3364
+ if (opts.nonegate !== true && state.index === 0) {
3365
+ negate();
3366
+ continue;
3367
+ }
3368
+ }
3369
+
3370
+ /**
3371
+ * Plus
3372
+ */
3373
+
3374
+ if (value === '+') {
3375
+ if (opts.noextglob !== true && peek() === '(' && peek(2) !== '?') {
3376
+ extglobOpen('plus', value);
3377
+ continue;
3378
+ }
3379
+
3380
+ if ((prev && prev.value === '(') || opts.regex === false) {
3381
+ push({ type: 'plus', value, output: PLUS_LITERAL });
3382
+ continue;
3383
+ }
3384
+
3385
+ if ((prev && (prev.type === 'bracket' || prev.type === 'paren' || prev.type === 'brace')) || state.parens > 0) {
3386
+ push({ type: 'plus', value });
3387
+ continue;
3388
+ }
3389
+
3390
+ push({ type: 'plus', value: PLUS_LITERAL });
3391
+ continue;
3392
+ }
3393
+
3394
+ /**
3395
+ * Plain text
3396
+ */
3397
+
3398
+ if (value === '@') {
3399
+ if (opts.noextglob !== true && peek() === '(' && peek(2) !== '?') {
3400
+ push({ type: 'at', extglob: true, value, output: '' });
3401
+ continue;
3402
+ }
3403
+
3404
+ push({ type: 'text', value });
3405
+ continue;
3406
+ }
3407
+
3408
+ /**
3409
+ * Plain text
3410
+ */
3411
+
3412
+ if (value !== '*') {
3413
+ if (value === '$' || value === '^') {
3414
+ value = `\\${value}`;
3415
+ }
3416
+
3417
+ const match = REGEX_NON_SPECIAL_CHARS.exec(remaining());
3418
+ if (match) {
3419
+ value += match[0];
3420
+ state.index += match[0].length;
3421
+ }
3422
+
3423
+ push({ type: 'text', value });
3424
+ continue;
3425
+ }
3426
+
3427
+ /**
3428
+ * Stars
3429
+ */
3430
+
3431
+ if (prev && (prev.type === 'globstar' || prev.star === true)) {
3432
+ prev.type = 'star';
3433
+ prev.star = true;
3434
+ prev.value += value;
3435
+ prev.output = star;
3436
+ state.backtrack = true;
3437
+ state.globstar = true;
3438
+ consume(value);
3439
+ continue;
3440
+ }
3441
+
3442
+ let rest = remaining();
3443
+ if (opts.noextglob !== true && /^\([^?]/.test(rest)) {
3444
+ extglobOpen('star', value);
3445
+ continue;
3446
+ }
3447
+
3448
+ if (prev.type === 'star') {
3449
+ if (opts.noglobstar === true) {
3450
+ consume(value);
3451
+ continue;
3452
+ }
3453
+
3454
+ const prior = prev.prev;
3455
+ const before = prior.prev;
3456
+ const isStart = prior.type === 'slash' || prior.type === 'bos';
3457
+ const afterStar = before && (before.type === 'star' || before.type === 'globstar');
3458
+
3459
+ if (opts.bash === true && (!isStart || (rest[0] && rest[0] !== '/'))) {
3460
+ push({ type: 'star', value, output: '' });
3461
+ continue;
3462
+ }
3463
+
3464
+ const isBrace = state.braces > 0 && (prior.type === 'comma' || prior.type === 'brace');
3465
+ const isExtglob = extglobs.length && (prior.type === 'pipe' || prior.type === 'paren');
3466
+ if (!isStart && prior.type !== 'paren' && !isBrace && !isExtglob) {
3467
+ push({ type: 'star', value, output: '' });
3468
+ continue;
3469
+ }
3470
+
3471
+ // strip consecutive `/**/`
3472
+ while (rest.slice(0, 3) === '/**') {
3473
+ const after = input[state.index + 4];
3474
+ if (after && after !== '/') {
3475
+ break;
3476
+ }
3477
+ rest = rest.slice(3);
3478
+ consume('/**', 3);
3479
+ }
3480
+
3481
+ if (prior.type === 'bos' && eos()) {
3482
+ prev.type = 'globstar';
3483
+ prev.value += value;
3484
+ prev.output = globstar(opts);
3485
+ state.output = prev.output;
3486
+ state.globstar = true;
3487
+ consume(value);
3488
+ continue;
3489
+ }
3490
+
3491
+ if (prior.type === 'slash' && prior.prev.type !== 'bos' && !afterStar && eos()) {
3492
+ state.output = state.output.slice(0, -(prior.output + prev.output).length);
3493
+ prior.output = `(?:${prior.output}`;
3494
+
3495
+ prev.type = 'globstar';
3496
+ prev.output = globstar(opts) + (opts.strictSlashes ? ')' : '|$)');
3497
+ prev.value += value;
3498
+ state.globstar = true;
3499
+ state.output += prior.output + prev.output;
3500
+ consume(value);
3501
+ continue;
3502
+ }
3503
+
3504
+ if (prior.type === 'slash' && prior.prev.type !== 'bos' && rest[0] === '/') {
3505
+ const end = rest[1] !== void 0 ? '|$' : '';
3506
+
3507
+ state.output = state.output.slice(0, -(prior.output + prev.output).length);
3508
+ prior.output = `(?:${prior.output}`;
3509
+
3510
+ prev.type = 'globstar';
3511
+ prev.output = `${globstar(opts)}${SLASH_LITERAL}|${SLASH_LITERAL}${end})`;
3512
+ prev.value += value;
3513
+
3514
+ state.output += prior.output + prev.output;
3515
+ state.globstar = true;
3516
+
3517
+ consume(value + advance());
3518
+
3519
+ push({ type: 'slash', value: '/', output: '' });
3520
+ continue;
3521
+ }
3522
+
3523
+ if (prior.type === 'bos' && rest[0] === '/') {
3524
+ prev.type = 'globstar';
3525
+ prev.value += value;
3526
+ prev.output = `(?:^|${SLASH_LITERAL}|${globstar(opts)}${SLASH_LITERAL})`;
3527
+ state.output = prev.output;
3528
+ state.globstar = true;
3529
+ consume(value + advance());
3530
+ push({ type: 'slash', value: '/', output: '' });
3531
+ continue;
3532
+ }
3533
+
3534
+ // remove single star from output
3535
+ state.output = state.output.slice(0, -prev.output.length);
3536
+
3537
+ // reset previous token to globstar
3538
+ prev.type = 'globstar';
3539
+ prev.output = globstar(opts);
3540
+ prev.value += value;
3541
+
3542
+ // reset output with globstar
3543
+ state.output += prev.output;
3544
+ state.globstar = true;
3545
+ consume(value);
3546
+ continue;
3547
+ }
3548
+
3549
+ const token = { type: 'star', value, output: star };
3550
+
3551
+ if (opts.bash === true) {
3552
+ token.output = '.*?';
3553
+ if (prev.type === 'bos' || prev.type === 'slash') {
3554
+ token.output = nodot + token.output;
3555
+ }
3556
+ push(token);
3557
+ continue;
3558
+ }
3559
+
3560
+ if (prev && (prev.type === 'bracket' || prev.type === 'paren') && opts.regex === true) {
3561
+ token.output = value;
3562
+ push(token);
3563
+ continue;
3564
+ }
3565
+
3566
+ if (state.index === state.start || prev.type === 'slash' || prev.type === 'dot') {
3567
+ if (prev.type === 'dot') {
3568
+ state.output += NO_DOT_SLASH;
3569
+ prev.output += NO_DOT_SLASH;
3570
+
3571
+ } else if (opts.dot === true) {
3572
+ state.output += NO_DOTS_SLASH;
3573
+ prev.output += NO_DOTS_SLASH;
3574
+
3575
+ } else {
3576
+ state.output += nodot;
3577
+ prev.output += nodot;
3578
+ }
3579
+
3580
+ if (peek() !== '*') {
3581
+ state.output += ONE_CHAR;
3582
+ prev.output += ONE_CHAR;
3583
+ }
3584
+ }
3585
+
3586
+ push(token);
3587
+ }
3588
+
3589
+ while (state.brackets > 0) {
3590
+ if (opts.strictBrackets === true) throw new SyntaxError(syntaxError('closing', ']'));
3591
+ state.output = utils.escapeLast(state.output, '[');
3592
+ decrement('brackets');
3593
+ }
3594
+
3595
+ while (state.parens > 0) {
3596
+ if (opts.strictBrackets === true) throw new SyntaxError(syntaxError('closing', ')'));
3597
+ state.output = utils.escapeLast(state.output, '(');
3598
+ decrement('parens');
3599
+ }
3600
+
3601
+ while (state.braces > 0) {
3602
+ if (opts.strictBrackets === true) throw new SyntaxError(syntaxError('closing', '}'));
3603
+ state.output = utils.escapeLast(state.output, '{');
3604
+ decrement('braces');
3605
+ }
3606
+
3607
+ if (opts.strictSlashes !== true && (prev.type === 'star' || prev.type === 'bracket')) {
3608
+ push({ type: 'maybe_slash', value: '', output: `${SLASH_LITERAL}?` });
3609
+ }
3610
+
3611
+ // rebuild the output if we had to backtrack at any point
3612
+ if (state.backtrack === true) {
3613
+ state.output = '';
3614
+
3615
+ for (const token of state.tokens) {
3616
+ state.output += token.output != null ? token.output : token.value;
3617
+
3618
+ if (token.suffix) {
3619
+ state.output += token.suffix;
3620
+ }
3621
+ }
3622
+ }
3623
+
3624
+ return state;
3625
+ };
3626
+
3627
+ /**
3628
+ * Fast paths for creating regular expressions for common glob patterns.
3629
+ * This can significantly speed up processing and has very little downside
3630
+ * impact when none of the fast paths match.
3631
+ */
3632
+
3633
+ parse.fastpaths = (input, options) => {
3634
+ const opts = { ...options };
3635
+ const max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
3636
+ const len = input.length;
3637
+ if (len > max) {
3638
+ throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
3639
+ }
3640
+
3641
+ input = REPLACEMENTS[input] || input;
3642
+ const win32 = utils.isWindows(options);
3643
+
3644
+ // create constants based on platform, for windows or posix
3645
+ const {
3646
+ DOT_LITERAL,
3647
+ SLASH_LITERAL,
3648
+ ONE_CHAR,
3649
+ DOTS_SLASH,
3650
+ NO_DOT,
3651
+ NO_DOTS,
3652
+ NO_DOTS_SLASH,
3653
+ STAR,
3654
+ START_ANCHOR
3655
+ } = constants.globChars(win32);
3656
+
3657
+ const nodot = opts.dot ? NO_DOTS : NO_DOT;
3658
+ const slashDot = opts.dot ? NO_DOTS_SLASH : NO_DOT;
3659
+ const capture = opts.capture ? '' : '?:';
3660
+ const state = { negated: false, prefix: '' };
3661
+ let star = opts.bash === true ? '.*?' : STAR;
3662
+
3663
+ if (opts.capture) {
3664
+ star = `(${star})`;
3665
+ }
3666
+
3667
+ const globstar = opts => {
3668
+ if (opts.noglobstar === true) return star;
3669
+ return `(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
3670
+ };
3671
+
3672
+ const create = str => {
3673
+ switch (str) {
3674
+ case '*':
3675
+ return `${nodot}${ONE_CHAR}${star}`;
3676
+
3677
+ case '.*':
3678
+ return `${DOT_LITERAL}${ONE_CHAR}${star}`;
3679
+
3680
+ case '*.*':
3681
+ return `${nodot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
3682
+
3683
+ case '*/*':
3684
+ return `${nodot}${star}${SLASH_LITERAL}${ONE_CHAR}${slashDot}${star}`;
3685
+
3686
+ case '**':
3687
+ return nodot + globstar(opts);
3688
+
3689
+ case '**/*':
3690
+ return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${ONE_CHAR}${star}`;
3691
+
3692
+ case '**/*.*':
3693
+ return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
3694
+
3695
+ case '**/.*':
3696
+ return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${DOT_LITERAL}${ONE_CHAR}${star}`;
3697
+
3698
+ default: {
3699
+ const match = /^(.*?)\.(\w+)$/.exec(str);
3700
+ if (!match) return;
3701
+
3702
+ const source = create(match[1]);
3703
+ if (!source) return;
3704
+
3705
+ return source + DOT_LITERAL + match[2];
3706
+ }
3707
+ }
3708
+ };
3709
+
3710
+ const output = utils.removePrefix(input, state);
3711
+ let source = create(output);
3712
+
3713
+ if (source && opts.strictSlashes !== true) {
3714
+ source += `${SLASH_LITERAL}?`;
3715
+ }
3716
+
3717
+ return source;
3718
+ };
3719
+
3720
+ parse_1 = parse;
3721
+ return parse_1;
3722
+ }
3723
+
3724
+ var picomatch_1;
3725
+ var hasRequiredPicomatch$1;
3726
+
3727
+ function requirePicomatch$1 () {
3728
+ if (hasRequiredPicomatch$1) return picomatch_1;
3729
+ hasRequiredPicomatch$1 = 1;
3730
+
3731
+ const path = require$$0$1;
3732
+ const scan = requireScan();
3733
+ const parse = requireParse();
3734
+ const utils = requireUtils();
3735
+ const constants = requireConstants();
3736
+ const isObject = val => val && typeof val === 'object' && !Array.isArray(val);
3737
+
3738
+ /**
3739
+ * Creates a matcher function from one or more glob patterns. The
3740
+ * returned function takes a string to match as its first argument,
3741
+ * and returns true if the string is a match. The returned matcher
3742
+ * function also takes a boolean as the second argument that, when true,
3743
+ * returns an object with additional information.
3744
+ *
3745
+ * ```js
3746
+ * const picomatch = require('picomatch');
3747
+ * // picomatch(glob[, options]);
3748
+ *
3749
+ * const isMatch = picomatch('*.!(*a)');
3750
+ * console.log(isMatch('a.a')); //=> false
3751
+ * console.log(isMatch('a.b')); //=> true
3752
+ * ```
3753
+ * @name picomatch
3754
+ * @param {String|Array} `globs` One or more glob patterns.
3755
+ * @param {Object=} `options`
3756
+ * @return {Function=} Returns a matcher function.
3757
+ * @api public
3758
+ */
3759
+
3760
+ const picomatch = (glob, options, returnState = false) => {
3761
+ if (Array.isArray(glob)) {
3762
+ const fns = glob.map(input => picomatch(input, options, returnState));
3763
+ const arrayMatcher = str => {
3764
+ for (const isMatch of fns) {
3765
+ const state = isMatch(str);
3766
+ if (state) return state;
3767
+ }
3768
+ return false;
3769
+ };
3770
+ return arrayMatcher;
3771
+ }
3772
+
3773
+ const isState = isObject(glob) && glob.tokens && glob.input;
3774
+
3775
+ if (glob === '' || (typeof glob !== 'string' && !isState)) {
3776
+ throw new TypeError('Expected pattern to be a non-empty string');
3777
+ }
3778
+
3779
+ const opts = options || {};
3780
+ const posix = utils.isWindows(options);
3781
+ const regex = isState
3782
+ ? picomatch.compileRe(glob, options)
3783
+ : picomatch.makeRe(glob, options, false, true);
3784
+
3785
+ const state = regex.state;
3786
+ delete regex.state;
3787
+
3788
+ let isIgnored = () => false;
3789
+ if (opts.ignore) {
3790
+ const ignoreOpts = { ...options, ignore: null, onMatch: null, onResult: null };
3791
+ isIgnored = picomatch(opts.ignore, ignoreOpts, returnState);
3792
+ }
3793
+
3794
+ const matcher = (input, returnObject = false) => {
3795
+ const { isMatch, match, output } = picomatch.test(input, regex, options, { glob, posix });
3796
+ const result = { glob, state, regex, posix, input, output, match, isMatch };
3797
+
3798
+ if (typeof opts.onResult === 'function') {
3799
+ opts.onResult(result);
3800
+ }
3801
+
3802
+ if (isMatch === false) {
3803
+ result.isMatch = false;
3804
+ return returnObject ? result : false;
3805
+ }
3806
+
3807
+ if (isIgnored(input)) {
3808
+ if (typeof opts.onIgnore === 'function') {
3809
+ opts.onIgnore(result);
3810
+ }
3811
+ result.isMatch = false;
3812
+ return returnObject ? result : false;
3813
+ }
3814
+
3815
+ if (typeof opts.onMatch === 'function') {
3816
+ opts.onMatch(result);
3817
+ }
3818
+ return returnObject ? result : true;
3819
+ };
3820
+
3821
+ if (returnState) {
3822
+ matcher.state = state;
3823
+ }
3824
+
3825
+ return matcher;
3826
+ };
3827
+
3828
+ /**
3829
+ * Test `input` with the given `regex`. This is used by the main
3830
+ * `picomatch()` function to test the input string.
3831
+ *
3832
+ * ```js
3833
+ * const picomatch = require('picomatch');
3834
+ * // picomatch.test(input, regex[, options]);
3835
+ *
3836
+ * console.log(picomatch.test('foo/bar', /^(?:([^/]*?)\/([^/]*?))$/));
3837
+ * // { isMatch: true, match: [ 'foo/', 'foo', 'bar' ], output: 'foo/bar' }
3838
+ * ```
3839
+ * @param {String} `input` String to test.
3840
+ * @param {RegExp} `regex`
3841
+ * @return {Object} Returns an object with matching info.
3842
+ * @api public
3843
+ */
3844
+
3845
+ picomatch.test = (input, regex, options, { glob, posix } = {}) => {
3846
+ if (typeof input !== 'string') {
3847
+ throw new TypeError('Expected input to be a string');
3848
+ }
3849
+
3850
+ if (input === '') {
3851
+ return { isMatch: false, output: '' };
3852
+ }
3853
+
3854
+ const opts = options || {};
3855
+ const format = opts.format || (posix ? utils.toPosixSlashes : null);
3856
+ let match = input === glob;
3857
+ let output = (match && format) ? format(input) : input;
3858
+
3859
+ if (match === false) {
3860
+ output = format ? format(input) : input;
3861
+ match = output === glob;
3862
+ }
3863
+
3864
+ if (match === false || opts.capture === true) {
3865
+ if (opts.matchBase === true || opts.basename === true) {
3866
+ match = picomatch.matchBase(input, regex, options, posix);
3867
+ } else {
3868
+ match = regex.exec(output);
3869
+ }
3870
+ }
3871
+
3872
+ return { isMatch: Boolean(match), match, output };
3873
+ };
3874
+
3875
+ /**
3876
+ * Match the basename of a filepath.
3877
+ *
3878
+ * ```js
3879
+ * const picomatch = require('picomatch');
3880
+ * // picomatch.matchBase(input, glob[, options]);
3881
+ * console.log(picomatch.matchBase('foo/bar.js', '*.js'); // true
3882
+ * ```
3883
+ * @param {String} `input` String to test.
3884
+ * @param {RegExp|String} `glob` Glob pattern or regex created by [.makeRe](#makeRe).
3885
+ * @return {Boolean}
3886
+ * @api public
3887
+ */
3888
+
3889
+ picomatch.matchBase = (input, glob, options, posix = utils.isWindows(options)) => {
3890
+ const regex = glob instanceof RegExp ? glob : picomatch.makeRe(glob, options);
3891
+ return regex.test(path.basename(input));
3892
+ };
3893
+
3894
+ /**
3895
+ * Returns true if **any** of the given glob `patterns` match the specified `string`.
3896
+ *
3897
+ * ```js
3898
+ * const picomatch = require('picomatch');
3899
+ * // picomatch.isMatch(string, patterns[, options]);
3900
+ *
3901
+ * console.log(picomatch.isMatch('a.a', ['b.*', '*.a'])); //=> true
3902
+ * console.log(picomatch.isMatch('a.a', 'b.*')); //=> false
3903
+ * ```
3904
+ * @param {String|Array} str The string to test.
3905
+ * @param {String|Array} patterns One or more glob patterns to use for matching.
3906
+ * @param {Object} [options] See available [options](#options).
3907
+ * @return {Boolean} Returns true if any patterns match `str`
3908
+ * @api public
3909
+ */
3910
+
3911
+ picomatch.isMatch = (str, patterns, options) => picomatch(patterns, options)(str);
3912
+
3913
+ /**
3914
+ * Parse a glob pattern to create the source string for a regular
3915
+ * expression.
3916
+ *
3917
+ * ```js
3918
+ * const picomatch = require('picomatch');
3919
+ * const result = picomatch.parse(pattern[, options]);
3920
+ * ```
3921
+ * @param {String} `pattern`
3922
+ * @param {Object} `options`
3923
+ * @return {Object} Returns an object with useful properties and output to be used as a regex source string.
3924
+ * @api public
3925
+ */
3926
+
3927
+ picomatch.parse = (pattern, options) => {
3928
+ if (Array.isArray(pattern)) return pattern.map(p => picomatch.parse(p, options));
3929
+ return parse(pattern, { ...options, fastpaths: false });
3930
+ };
3931
+
3932
+ /**
3933
+ * Scan a glob pattern to separate the pattern into segments.
3934
+ *
3935
+ * ```js
3936
+ * const picomatch = require('picomatch');
3937
+ * // picomatch.scan(input[, options]);
3938
+ *
3939
+ * const result = picomatch.scan('!./foo/*.js');
3940
+ * console.log(result);
3941
+ * { prefix: '!./',
3942
+ * input: '!./foo/*.js',
3943
+ * start: 3,
3944
+ * base: 'foo',
3945
+ * glob: '*.js',
3946
+ * isBrace: false,
3947
+ * isBracket: false,
3948
+ * isGlob: true,
3949
+ * isExtglob: false,
3950
+ * isGlobstar: false,
3951
+ * negated: true }
3952
+ * ```
3953
+ * @param {String} `input` Glob pattern to scan.
3954
+ * @param {Object} `options`
3955
+ * @return {Object} Returns an object with
3956
+ * @api public
3957
+ */
3958
+
3959
+ picomatch.scan = (input, options) => scan(input, options);
3960
+
3961
+ /**
3962
+ * Compile a regular expression from the `state` object returned by the
3963
+ * [parse()](#parse) method.
3964
+ *
3965
+ * @param {Object} `state`
3966
+ * @param {Object} `options`
3967
+ * @param {Boolean} `returnOutput` Intended for implementors, this argument allows you to return the raw output from the parser.
3968
+ * @param {Boolean} `returnState` Adds the state to a `state` property on the returned regex. Useful for implementors and debugging.
3969
+ * @return {RegExp}
3970
+ * @api public
3971
+ */
3972
+
3973
+ picomatch.compileRe = (state, options, returnOutput = false, returnState = false) => {
3974
+ if (returnOutput === true) {
3975
+ return state.output;
3976
+ }
3977
+
3978
+ const opts = options || {};
3979
+ const prepend = opts.contains ? '' : '^';
3980
+ const append = opts.contains ? '' : '$';
3981
+
3982
+ let source = `${prepend}(?:${state.output})${append}`;
3983
+ if (state && state.negated === true) {
3984
+ source = `^(?!${source}).*$`;
3985
+ }
3986
+
3987
+ const regex = picomatch.toRegex(source, options);
3988
+ if (returnState === true) {
3989
+ regex.state = state;
3990
+ }
3991
+
3992
+ return regex;
3993
+ };
3994
+
3995
+ /**
3996
+ * Create a regular expression from a parsed glob pattern.
3997
+ *
3998
+ * ```js
3999
+ * const picomatch = require('picomatch');
4000
+ * const state = picomatch.parse('*.js');
4001
+ * // picomatch.compileRe(state[, options]);
4002
+ *
4003
+ * console.log(picomatch.compileRe(state));
4004
+ * //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
4005
+ * ```
4006
+ * @param {String} `state` The object returned from the `.parse` method.
4007
+ * @param {Object} `options`
4008
+ * @param {Boolean} `returnOutput` Implementors may use this argument to return the compiled output, instead of a regular expression. This is not exposed on the options to prevent end-users from mutating the result.
4009
+ * @param {Boolean} `returnState` Implementors may use this argument to return the state from the parsed glob with the returned regular expression.
4010
+ * @return {RegExp} Returns a regex created from the given pattern.
4011
+ * @api public
4012
+ */
4013
+
4014
+ picomatch.makeRe = (input, options = {}, returnOutput = false, returnState = false) => {
4015
+ if (!input || typeof input !== 'string') {
4016
+ throw new TypeError('Expected a non-empty string');
4017
+ }
4018
+
4019
+ let parsed = { negated: false, fastpaths: true };
4020
+
4021
+ if (options.fastpaths !== false && (input[0] === '.' || input[0] === '*')) {
4022
+ parsed.output = parse.fastpaths(input, options);
4023
+ }
4024
+
4025
+ if (!parsed.output) {
4026
+ parsed = parse(input, options);
4027
+ }
4028
+
4029
+ return picomatch.compileRe(parsed, options, returnOutput, returnState);
4030
+ };
4031
+
4032
+ /**
4033
+ * Create a regular expression from the given regex source string.
4034
+ *
4035
+ * ```js
4036
+ * const picomatch = require('picomatch');
4037
+ * // picomatch.toRegex(source[, options]);
4038
+ *
4039
+ * const { output } = picomatch.parse('*.js');
4040
+ * console.log(picomatch.toRegex(output));
4041
+ * //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
4042
+ * ```
4043
+ * @param {String} `source` Regular expression source string.
4044
+ * @param {Object} `options`
4045
+ * @return {RegExp}
4046
+ * @api public
4047
+ */
4048
+
4049
+ picomatch.toRegex = (source, options) => {
4050
+ try {
4051
+ const opts = options || {};
4052
+ return new RegExp(source, opts.flags || (opts.nocase ? 'i' : ''));
4053
+ } catch (err) {
4054
+ if (options && options.debug === true) throw err;
4055
+ return /$^/;
4056
+ }
4057
+ };
4058
+
4059
+ /**
4060
+ * Picomatch constants.
4061
+ * @return {Object}
4062
+ */
4063
+
4064
+ picomatch.constants = constants;
4065
+
4066
+ /**
4067
+ * Expose "picomatch"
4068
+ */
4069
+
4070
+ picomatch_1 = picomatch;
4071
+ return picomatch_1;
4072
+ }
4073
+
4074
+ var picomatch;
4075
+ var hasRequiredPicomatch;
4076
+
4077
+ function requirePicomatch () {
4078
+ if (hasRequiredPicomatch) return picomatch;
4079
+ hasRequiredPicomatch = 1;
4080
+
4081
+ picomatch = requirePicomatch$1();
4082
+ return picomatch;
4083
+ }
4084
+
4085
+ var micromatch_1;
4086
+ var hasRequiredMicromatch;
4087
+
4088
+ function requireMicromatch () {
4089
+ if (hasRequiredMicromatch) return micromatch_1;
4090
+ hasRequiredMicromatch = 1;
4091
+
4092
+ const util = require$$0;
4093
+ const braces = requireBraces();
4094
+ const picomatch = requirePicomatch();
4095
+ const utils = requireUtils();
4096
+ const isEmptyString = val => val === '' || val === './';
4097
+
4098
+ /**
4099
+ * Returns an array of strings that match one or more glob patterns.
4100
+ *
4101
+ * ```js
4102
+ * const mm = require('micromatch');
4103
+ * // mm(list, patterns[, options]);
4104
+ *
4105
+ * console.log(mm(['a.js', 'a.txt'], ['*.js']));
4106
+ * //=> [ 'a.js' ]
4107
+ * ```
4108
+ * @param {String|Array<string>} `list` List of strings to match.
4109
+ * @param {String|Array<string>} `patterns` One or more glob patterns to use for matching.
4110
+ * @param {Object} `options` See available [options](#options)
4111
+ * @return {Array} Returns an array of matches
4112
+ * @summary false
4113
+ * @api public
4114
+ */
4115
+
4116
+ const micromatch = (list, patterns, options) => {
4117
+ patterns = [].concat(patterns);
4118
+ list = [].concat(list);
4119
+
4120
+ let omit = new Set();
4121
+ let keep = new Set();
4122
+ let items = new Set();
4123
+ let negatives = 0;
4124
+
4125
+ let onResult = state => {
4126
+ items.add(state.output);
4127
+ if (options && options.onResult) {
4128
+ options.onResult(state);
4129
+ }
4130
+ };
4131
+
4132
+ for (let i = 0; i < patterns.length; i++) {
4133
+ let isMatch = picomatch(String(patterns[i]), { ...options, onResult }, true);
4134
+ let negated = isMatch.state.negated || isMatch.state.negatedExtglob;
4135
+ if (negated) negatives++;
4136
+
4137
+ for (let item of list) {
4138
+ let matched = isMatch(item, true);
4139
+
4140
+ let match = negated ? !matched.isMatch : matched.isMatch;
4141
+ if (!match) continue;
4142
+
4143
+ if (negated) {
4144
+ omit.add(matched.output);
4145
+ } else {
4146
+ omit.delete(matched.output);
4147
+ keep.add(matched.output);
4148
+ }
4149
+ }
4150
+ }
4151
+
4152
+ let result = negatives === patterns.length ? [...items] : [...keep];
4153
+ let matches = result.filter(item => !omit.has(item));
4154
+
4155
+ if (options && matches.length === 0) {
4156
+ if (options.failglob === true) {
4157
+ throw new Error(`No matches found for "${patterns.join(', ')}"`);
4158
+ }
4159
+
4160
+ if (options.nonull === true || options.nullglob === true) {
4161
+ return options.unescape ? patterns.map(p => p.replace(/\\/g, '')) : patterns;
4162
+ }
4163
+ }
4164
+
4165
+ return matches;
4166
+ };
4167
+
4168
+ /**
4169
+ * Backwards compatibility
4170
+ */
4171
+
4172
+ micromatch.match = micromatch;
4173
+
4174
+ /**
4175
+ * Returns a matcher function from the given glob `pattern` and `options`.
4176
+ * The returned function takes a string to match as its only argument and returns
4177
+ * true if the string is a match.
4178
+ *
4179
+ * ```js
4180
+ * const mm = require('micromatch');
4181
+ * // mm.matcher(pattern[, options]);
4182
+ *
4183
+ * const isMatch = mm.matcher('*.!(*a)');
4184
+ * console.log(isMatch('a.a')); //=> false
4185
+ * console.log(isMatch('a.b')); //=> true
4186
+ * ```
4187
+ * @param {String} `pattern` Glob pattern
4188
+ * @param {Object} `options`
4189
+ * @return {Function} Returns a matcher function.
4190
+ * @api public
4191
+ */
4192
+
4193
+ micromatch.matcher = (pattern, options) => picomatch(pattern, options);
4194
+
4195
+ /**
4196
+ * Returns true if **any** of the given glob `patterns` match the specified `string`.
4197
+ *
4198
+ * ```js
4199
+ * const mm = require('micromatch');
4200
+ * // mm.isMatch(string, patterns[, options]);
4201
+ *
4202
+ * console.log(mm.isMatch('a.a', ['b.*', '*.a'])); //=> true
4203
+ * console.log(mm.isMatch('a.a', 'b.*')); //=> false
4204
+ * ```
4205
+ * @param {String} `str` The string to test.
4206
+ * @param {String|Array} `patterns` One or more glob patterns to use for matching.
4207
+ * @param {Object} `[options]` See available [options](#options).
4208
+ * @return {Boolean} Returns true if any patterns match `str`
4209
+ * @api public
4210
+ */
4211
+
4212
+ micromatch.isMatch = (str, patterns, options) => picomatch(patterns, options)(str);
4213
+
4214
+ /**
4215
+ * Backwards compatibility
4216
+ */
4217
+
4218
+ micromatch.any = micromatch.isMatch;
4219
+
4220
+ /**
4221
+ * Returns a list of strings that _**do not match any**_ of the given `patterns`.
4222
+ *
4223
+ * ```js
4224
+ * const mm = require('micromatch');
4225
+ * // mm.not(list, patterns[, options]);
4226
+ *
4227
+ * console.log(mm.not(['a.a', 'b.b', 'c.c'], '*.a'));
4228
+ * //=> ['b.b', 'c.c']
4229
+ * ```
4230
+ * @param {Array} `list` Array of strings to match.
4231
+ * @param {String|Array} `patterns` One or more glob pattern to use for matching.
4232
+ * @param {Object} `options` See available [options](#options) for changing how matches are performed
4233
+ * @return {Array} Returns an array of strings that **do not match** the given patterns.
4234
+ * @api public
4235
+ */
4236
+
4237
+ micromatch.not = (list, patterns, options = {}) => {
4238
+ patterns = [].concat(patterns).map(String);
4239
+ let result = new Set();
4240
+ let items = [];
4241
+
4242
+ let onResult = state => {
4243
+ if (options.onResult) options.onResult(state);
4244
+ items.push(state.output);
4245
+ };
4246
+
4247
+ let matches = new Set(micromatch(list, patterns, { ...options, onResult }));
4248
+
4249
+ for (let item of items) {
4250
+ if (!matches.has(item)) {
4251
+ result.add(item);
4252
+ }
4253
+ }
4254
+ return [...result];
4255
+ };
4256
+
4257
+ /**
4258
+ * Returns true if the given `string` contains the given pattern. Similar
4259
+ * to [.isMatch](#isMatch) but the pattern can match any part of the string.
4260
+ *
4261
+ * ```js
4262
+ * var mm = require('micromatch');
4263
+ * // mm.contains(string, pattern[, options]);
4264
+ *
4265
+ * console.log(mm.contains('aa/bb/cc', '*b'));
4266
+ * //=> true
4267
+ * console.log(mm.contains('aa/bb/cc', '*d'));
4268
+ * //=> false
4269
+ * ```
4270
+ * @param {String} `str` The string to match.
4271
+ * @param {String|Array} `patterns` Glob pattern to use for matching.
4272
+ * @param {Object} `options` See available [options](#options) for changing how matches are performed
4273
+ * @return {Boolean} Returns true if any of the patterns matches any part of `str`.
4274
+ * @api public
4275
+ */
4276
+
4277
+ micromatch.contains = (str, pattern, options) => {
4278
+ if (typeof str !== 'string') {
4279
+ throw new TypeError(`Expected a string: "${util.inspect(str)}"`);
4280
+ }
4281
+
4282
+ if (Array.isArray(pattern)) {
4283
+ return pattern.some(p => micromatch.contains(str, p, options));
4284
+ }
4285
+
4286
+ if (typeof pattern === 'string') {
4287
+ if (isEmptyString(str) || isEmptyString(pattern)) {
4288
+ return false;
4289
+ }
4290
+
4291
+ if (str.includes(pattern) || (str.startsWith('./') && str.slice(2).includes(pattern))) {
4292
+ return true;
4293
+ }
4294
+ }
4295
+
4296
+ return micromatch.isMatch(str, pattern, { ...options, contains: true });
4297
+ };
4298
+
4299
+ /**
4300
+ * Filter the keys of the given object with the given `glob` pattern
4301
+ * and `options`. Does not attempt to match nested keys. If you need this feature,
4302
+ * use [glob-object][] instead.
4303
+ *
4304
+ * ```js
4305
+ * const mm = require('micromatch');
4306
+ * // mm.matchKeys(object, patterns[, options]);
4307
+ *
4308
+ * const obj = { aa: 'a', ab: 'b', ac: 'c' };
4309
+ * console.log(mm.matchKeys(obj, '*b'));
4310
+ * //=> { ab: 'b' }
4311
+ * ```
4312
+ * @param {Object} `object` The object with keys to filter.
4313
+ * @param {String|Array} `patterns` One or more glob patterns to use for matching.
4314
+ * @param {Object} `options` See available [options](#options) for changing how matches are performed
4315
+ * @return {Object} Returns an object with only keys that match the given patterns.
4316
+ * @api public
4317
+ */
4318
+
4319
+ micromatch.matchKeys = (obj, patterns, options) => {
4320
+ if (!utils.isObject(obj)) {
4321
+ throw new TypeError('Expected the first argument to be an object');
4322
+ }
4323
+ let keys = micromatch(Object.keys(obj), patterns, options);
4324
+ let res = {};
4325
+ for (let key of keys) res[key] = obj[key];
4326
+ return res;
4327
+ };
4328
+
4329
+ /**
4330
+ * Returns true if some of the strings in the given `list` match any of the given glob `patterns`.
4331
+ *
4332
+ * ```js
4333
+ * const mm = require('micromatch');
4334
+ * // mm.some(list, patterns[, options]);
4335
+ *
4336
+ * console.log(mm.some(['foo.js', 'bar.js'], ['*.js', '!foo.js']));
4337
+ * // true
4338
+ * console.log(mm.some(['foo.js'], ['*.js', '!foo.js']));
4339
+ * // false
4340
+ * ```
4341
+ * @param {String|Array} `list` The string or array of strings to test. Returns as soon as the first match is found.
4342
+ * @param {String|Array} `patterns` One or more glob patterns to use for matching.
4343
+ * @param {Object} `options` See available [options](#options) for changing how matches are performed
4344
+ * @return {Boolean} Returns true if any `patterns` matches any of the strings in `list`
4345
+ * @api public
4346
+ */
4347
+
4348
+ micromatch.some = (list, patterns, options) => {
4349
+ let items = [].concat(list);
4350
+
4351
+ for (let pattern of [].concat(patterns)) {
4352
+ let isMatch = picomatch(String(pattern), options);
4353
+ if (items.some(item => isMatch(item))) {
4354
+ return true;
4355
+ }
4356
+ }
4357
+ return false;
4358
+ };
4359
+
4360
+ /**
4361
+ * Returns true if every string in the given `list` matches
4362
+ * any of the given glob `patterns`.
4363
+ *
4364
+ * ```js
4365
+ * const mm = require('micromatch');
4366
+ * // mm.every(list, patterns[, options]);
4367
+ *
4368
+ * console.log(mm.every('foo.js', ['foo.js']));
4369
+ * // true
4370
+ * console.log(mm.every(['foo.js', 'bar.js'], ['*.js']));
4371
+ * // true
4372
+ * console.log(mm.every(['foo.js', 'bar.js'], ['*.js', '!foo.js']));
4373
+ * // false
4374
+ * console.log(mm.every(['foo.js'], ['*.js', '!foo.js']));
4375
+ * // false
4376
+ * ```
4377
+ * @param {String|Array} `list` The string or array of strings to test.
4378
+ * @param {String|Array} `patterns` One or more glob patterns to use for matching.
4379
+ * @param {Object} `options` See available [options](#options) for changing how matches are performed
4380
+ * @return {Boolean} Returns true if all `patterns` matches all of the strings in `list`
4381
+ * @api public
4382
+ */
4383
+
4384
+ micromatch.every = (list, patterns, options) => {
4385
+ let items = [].concat(list);
4386
+
4387
+ for (let pattern of [].concat(patterns)) {
4388
+ let isMatch = picomatch(String(pattern), options);
4389
+ if (!items.every(item => isMatch(item))) {
4390
+ return false;
4391
+ }
4392
+ }
4393
+ return true;
4394
+ };
4395
+
4396
+ /**
4397
+ * Returns true if **all** of the given `patterns` match
4398
+ * the specified string.
4399
+ *
4400
+ * ```js
4401
+ * const mm = require('micromatch');
4402
+ * // mm.all(string, patterns[, options]);
4403
+ *
4404
+ * console.log(mm.all('foo.js', ['foo.js']));
4405
+ * // true
4406
+ *
4407
+ * console.log(mm.all('foo.js', ['*.js', '!foo.js']));
4408
+ * // false
4409
+ *
4410
+ * console.log(mm.all('foo.js', ['*.js', 'foo.js']));
4411
+ * // true
4412
+ *
4413
+ * console.log(mm.all('foo.js', ['*.js', 'f*', '*o*', '*o.js']));
4414
+ * // true
4415
+ * ```
4416
+ * @param {String|Array} `str` The string to test.
4417
+ * @param {String|Array} `patterns` One or more glob patterns to use for matching.
4418
+ * @param {Object} `options` See available [options](#options) for changing how matches are performed
4419
+ * @return {Boolean} Returns true if any patterns match `str`
4420
+ * @api public
4421
+ */
4422
+
4423
+ micromatch.all = (str, patterns, options) => {
4424
+ if (typeof str !== 'string') {
4425
+ throw new TypeError(`Expected a string: "${util.inspect(str)}"`);
4426
+ }
4427
+
4428
+ return [].concat(patterns).every(p => picomatch(p, options)(str));
4429
+ };
4430
+
4431
+ /**
4432
+ * Returns an array of matches captured by `pattern` in `string, or `null` if the pattern did not match.
4433
+ *
4434
+ * ```js
4435
+ * const mm = require('micromatch');
4436
+ * // mm.capture(pattern, string[, options]);
4437
+ *
4438
+ * console.log(mm.capture('test/*.js', 'test/foo.js'));
4439
+ * //=> ['foo']
4440
+ * console.log(mm.capture('test/*.js', 'foo/bar.css'));
4441
+ * //=> null
4442
+ * ```
4443
+ * @param {String} `glob` Glob pattern to use for matching.
4444
+ * @param {String} `input` String to match
4445
+ * @param {Object} `options` See available [options](#options) for changing how matches are performed
4446
+ * @return {Array|null} Returns an array of captures if the input matches the glob pattern, otherwise `null`.
4447
+ * @api public
4448
+ */
4449
+
4450
+ micromatch.capture = (glob, input, options) => {
4451
+ let posix = utils.isWindows(options);
4452
+ let regex = picomatch.makeRe(String(glob), { ...options, capture: true });
4453
+ let match = regex.exec(posix ? utils.toPosixSlashes(input) : input);
4454
+
4455
+ if (match) {
4456
+ return match.slice(1).map(v => v === void 0 ? '' : v);
4457
+ }
4458
+ };
4459
+
4460
+ /**
4461
+ * Create a regular expression from the given glob `pattern`.
4462
+ *
4463
+ * ```js
4464
+ * const mm = require('micromatch');
4465
+ * // mm.makeRe(pattern[, options]);
4466
+ *
4467
+ * console.log(mm.makeRe('*.js'));
4468
+ * //=> /^(?:(\.[\\\/])?(?!\.)(?=.)[^\/]*?\.js)$/
4469
+ * ```
4470
+ * @param {String} `pattern` A glob pattern to convert to regex.
4471
+ * @param {Object} `options`
4472
+ * @return {RegExp} Returns a regex created from the given pattern.
4473
+ * @api public
4474
+ */
4475
+
4476
+ micromatch.makeRe = (...args) => picomatch.makeRe(...args);
4477
+
4478
+ /**
4479
+ * Scan a glob pattern to separate the pattern into segments. Used
4480
+ * by the [split](#split) method.
4481
+ *
4482
+ * ```js
4483
+ * const mm = require('micromatch');
4484
+ * const state = mm.scan(pattern[, options]);
4485
+ * ```
4486
+ * @param {String} `pattern`
4487
+ * @param {Object} `options`
4488
+ * @return {Object} Returns an object with
4489
+ * @api public
4490
+ */
4491
+
4492
+ micromatch.scan = (...args) => picomatch.scan(...args);
4493
+
4494
+ /**
4495
+ * Parse a glob pattern to create the source string for a regular
4496
+ * expression.
4497
+ *
4498
+ * ```js
4499
+ * const mm = require('micromatch');
4500
+ * const state = mm.parse(pattern[, options]);
4501
+ * ```
4502
+ * @param {String} `glob`
4503
+ * @param {Object} `options`
4504
+ * @return {Object} Returns an object with useful properties and output to be used as regex source string.
4505
+ * @api public
4506
+ */
4507
+
4508
+ micromatch.parse = (patterns, options) => {
4509
+ let res = [];
4510
+ for (let pattern of [].concat(patterns || [])) {
4511
+ for (let str of braces(String(pattern), options)) {
4512
+ res.push(picomatch.parse(str, options));
4513
+ }
4514
+ }
4515
+ return res;
4516
+ };
4517
+
4518
+ /**
4519
+ * Process the given brace `pattern`.
4520
+ *
4521
+ * ```js
4522
+ * const { braces } = require('micromatch');
4523
+ * console.log(braces('foo/{a,b,c}/bar'));
4524
+ * //=> [ 'foo/(a|b|c)/bar' ]
4525
+ *
4526
+ * console.log(braces('foo/{a,b,c}/bar', { expand: true }));
4527
+ * //=> [ 'foo/a/bar', 'foo/b/bar', 'foo/c/bar' ]
4528
+ * ```
4529
+ * @param {String} `pattern` String with brace pattern to process.
4530
+ * @param {Object} `options` Any [options](#options) to change how expansion is performed. See the [braces][] library for all available options.
4531
+ * @return {Array}
4532
+ * @api public
4533
+ */
4534
+
4535
+ micromatch.braces = (pattern, options) => {
4536
+ if (typeof pattern !== 'string') throw new TypeError('Expected a string');
4537
+ if ((options && options.nobrace === true) || !/\{.*\}/.test(pattern)) {
4538
+ return [pattern];
4539
+ }
4540
+ return braces(pattern, options);
4541
+ };
4542
+
4543
+ /**
4544
+ * Expand braces
4545
+ */
4546
+
4547
+ micromatch.braceExpand = (pattern, options) => {
4548
+ if (typeof pattern !== 'string') throw new TypeError('Expected a string');
4549
+ return micromatch.braces(pattern, { ...options, expand: true });
4550
+ };
4551
+
4552
+ /**
4553
+ * Expose micromatch
4554
+ */
4555
+
4556
+ micromatch_1 = micromatch;
4557
+ return micromatch_1;
4558
+ }
4559
+
4560
+ var micromatchExports = requireMicromatch();
4561
+
4562
+ const PACKAGE_JSON_TEMPLATE = `{
4563
+ "name": "",
4564
+ "version": "0.0.1",
4565
+ "description": "",
4566
+ "license": "",
4567
+ "author": "",
4568
+ "files": ["dist"],
4569
+ "exports": {
4570
+ ".": "./src/index.ts"
4571
+ },
4572
+ "scripts": {
4573
+ },
4574
+ "homepage": "",
4575
+ "repository": "",
4576
+ "bugs": ""
4577
+ }`.trimStart();
4578
+ const README_TEMPLATE = `# $name
4579
+
4580
+ ## Installation
4581
+
4582
+ \`\`\`bash
4583
+ npm install $name
4584
+ # or
4585
+ pnpm install $name
4586
+ # or
4587
+ yarn add $name
4588
+ \`\`\`
4589
+
4590
+ ## Usage
4591
+
4592
+
4593
+ ## License
4594
+
4595
+ $license
4596
+ `.trimStart();
4597
+ function getTemplateStr(wd, template) {
4598
+ let templateString = template ?? PACKAGE_JSON_TEMPLATE;
4599
+ let isTemplateFile = false;
4600
+ try {
4601
+ if (template)
4602
+ JSON.parse(template);
4603
+ } catch (e) {
4604
+ isTemplateFile = true;
4605
+ }
4606
+ if (isTemplateFile) {
4607
+ const templatePath = path.resolve(wd, template);
4608
+ templateString = fs.readFileSync(templatePath, "utf-8");
4609
+ }
4610
+ return templateString;
4611
+ }
4612
+ const wdCache = /* @__PURE__ */ new Map();
4613
+ function getWDPackageJSONFiled(wd, field) {
4614
+ if (wdCache.has(wd)) {
4615
+ return wdCache.get(wd)[field];
4616
+ }
4617
+ const packageJSONPath = path.resolve(wd, "package.json");
4618
+ const packageJSON = JSON.parse(fs.readFileSync(packageJSONPath, "utf-8"));
4619
+ wdCache.set(wd, packageJSON);
4620
+ return packageJSON[field];
4621
+ }
4622
+ async function getName(named, name, {
4623
+ wd,
4624
+ cwd,
4625
+ workspaceName
4626
+ }) {
4627
+ const relativePath = cwd.replace(`${wd}/`, "");
4628
+ let basename = path.basename(cwd);
4629
+ if (typeof named === "function") {
4630
+ return named(name, {
4631
+ full: wd,
4632
+ relative: cwd
4633
+ });
4634
+ }
4635
+ let isParentMatched = false;
4636
+ let matchedKey;
4637
+ let matchedRule;
4638
+ if (typeof named === "object") {
4639
+ const isWD = cwd === wd;
4640
+ if (isWD) {
4641
+ const { rule } = await inquirer.prompt({
4642
+ type: "list",
4643
+ name: "rule",
4644
+ message: "choose a rule",
4645
+ default: "default",
4646
+ choices: ["default"].concat(Object.keys(named))
4647
+ });
4648
+ if (rule !== "default") {
4649
+ matchedKey = rule;
4650
+ matchedRule = named[rule];
4651
+ }
4652
+ } else {
4653
+ for (const [key, value] of Object.entries(named)) {
4654
+ if (micromatchExports.isMatch(relativePath, key)) {
4655
+ matchedKey = key;
4656
+ matchedRule = value;
4657
+ break;
4658
+ }
4659
+ if (micromatchExports.isMatch(`${relativePath}/jiek_ignore_dont_use_same_file_name`, key)) {
4660
+ isParentMatched = true;
4661
+ matchedKey = key;
4662
+ matchedRule = value;
4663
+ break;
4664
+ }
4665
+ }
4666
+ }
4667
+ }
4668
+ if (!matchedRule) {
4669
+ matchedKey = "packages/*";
4670
+ matchedRule = `@${workspaceName}/$basename`;
4671
+ }
4672
+ if (!matchedRule) {
4673
+ throw new Error("no matched rule");
4674
+ }
4675
+ if (!name && isParentMatched) {
4676
+ basename = await inquirer.prompt({
4677
+ type: "input",
4678
+ name: "name",
4679
+ message: `the matched rule is \`${String(matchedRule)}\`, please input the basename
4680
+ `
4681
+ }).then(({ name: name2 }) => name2);
4682
+ }
4683
+ if (typeof matchedRule === "function") {
4684
+ return matchedRule(name, {
4685
+ full: wd,
4686
+ relative: cwd,
4687
+ basename
4688
+ });
4689
+ }
4690
+ if (typeof matchedRule === "string") {
4691
+ const dirName = name ?? basename;
4692
+ return [
4693
+ matchedRule.replace(/\$basename/g, dirName),
4694
+ matchedKey?.replace(/\/\*$/g, `/${dirName}`)
4695
+ ];
4696
+ }
4697
+ throw new Error("no matched rule");
4698
+ }
4699
+ commander.program.command("init [name]").option("-t, --template <template>", "the package.json template file path or file content").action(async () => {
4700
+ const [, name] = commander.program.args;
4701
+ const cwd = process.cwd();
4702
+ const { init = {} } = loadConfig() ?? {};
4703
+ const { wd } = getWD();
4704
+ const workspaceName = path.basename(wd);
4705
+ const {
4706
+ named,
4707
+ template,
4708
+ bug = {},
4709
+ readme: _readme = README_TEMPLATE,
4710
+ readmeTemplate
4711
+ } = init;
4712
+ const resolvedBug = {
4713
+ template: "bug_report.yml",
4714
+ labels: ["bug"],
4715
+ ...bug
4716
+ };
4717
+ let readme = _readme;
4718
+ if (readmeTemplate) {
4719
+ const readmeTemplatePath = path.resolve(wd, readmeTemplate);
4720
+ readme = fs.readFileSync(readmeTemplatePath, "utf-8");
4721
+ }
4722
+ const templateString = getTemplateStr(wd, template);
4723
+ const { indent = " " } = detectIndent(templateString);
4724
+ const formattingOptions = {
4725
+ tabSize: indent.length,
4726
+ insertSpaces: true
4727
+ };
4728
+ const passFields = [
4729
+ "license",
4730
+ "author"
4731
+ ];
4732
+ let newJSONString = templateString;
4733
+ for (const field of passFields) {
4734
+ newJSONString = jsoncParser.applyEdits(
4735
+ newJSONString,
4736
+ jsoncParser.modify(
4737
+ newJSONString,
4738
+ [field],
4739
+ getWDPackageJSONFiled(wd, field),
4740
+ { formattingOptions }
4741
+ )
4742
+ );
4743
+ }
4744
+ let [pkgName, pkgDir] = await getName(named, name, {
4745
+ wd,
4746
+ cwd,
4747
+ workspaceName
4748
+ });
4749
+ if (!pkgDir) {
4750
+ const { dir } = await inquirer.prompt({
4751
+ type: "input",
4752
+ name: "dir",
4753
+ message: "package directory",
4754
+ default: name
4755
+ });
4756
+ pkgDir = dir;
4757
+ }
4758
+ if (!pkgName) {
4759
+ const { name: inputName } = await inquirer.prompt({
4760
+ type: "input",
4761
+ name: "name",
4762
+ message: "package name",
4763
+ default: name
4764
+ });
4765
+ pkgName = inputName;
4766
+ }
4767
+ newJSONString = jsoncParser.applyEdits(newJSONString, jsoncParser.modify(newJSONString, ["name"], pkgName, { formattingOptions }));
4768
+ let pkgRepo = getWDPackageJSONFiled(wd, "repository");
4769
+ if (typeof pkgRepo === "string") {
4770
+ pkgRepo = {
4771
+ type: "git",
4772
+ url: pkgRepo,
4773
+ directory: pkgDir
4774
+ };
4775
+ }
4776
+ newJSONString = jsoncParser.applyEdits(
4777
+ newJSONString,
4778
+ jsoncParser.modify(
4779
+ newJSONString,
4780
+ ["repository"],
4781
+ pkgRepo,
4782
+ { formattingOptions }
4783
+ )
4784
+ );
4785
+ const homepage = `${pkgRepo?.url}/blob/master/${pkgDir}/README.md`;
4786
+ newJSONString = jsoncParser.applyEdits(
4787
+ newJSONString,
4788
+ jsoncParser.modify(
4789
+ newJSONString,
4790
+ ["homepage"],
4791
+ homepage,
4792
+ { formattingOptions }
4793
+ )
4794
+ );
4795
+ let labels = resolvedBug.labels;
4796
+ if (typeof labels === "function") {
4797
+ labels = labels({
4798
+ name: pkgName,
4799
+ dir: pkgDir
4800
+ });
4801
+ }
4802
+ labels.push(`scope:${pkgName}`);
4803
+ const bugs = `${pkgRepo?.url}/issues/new?template=${resolvedBug.template}&labels=${labels.join(",")}`;
4804
+ newJSONString = jsoncParser.applyEdits(
4805
+ newJSONString,
4806
+ jsoncParser.modify(
4807
+ newJSONString,
4808
+ ["bugs"],
4809
+ bugs,
4810
+ { formattingOptions }
4811
+ )
4812
+ );
4813
+ function pkgDirTo(to) {
4814
+ if (!pkgDir)
4815
+ throw new Error("pkgDir is not defined");
4816
+ return path.resolve(pkgDir, to);
4817
+ }
4818
+ if (!fs.existsSync(pkgDir))
4819
+ fs.mkdirSync(pkgDir);
4820
+ const pkgJSONFilePath = pkgDirTo("package.json");
4821
+ if (fs.existsSync(pkgJSONFilePath)) {
4822
+ throw new Error("package.json already exists");
4823
+ }
4824
+ fs.writeFileSync(pkgJSONFilePath, newJSONString);
4825
+ console.log(newJSONString, "written to", pkgJSONFilePath);
4826
+ const license = getWDPackageJSONFiled(wd, "license");
4827
+ const readmeFilePath = pkgDirTo("README.md");
4828
+ if (typeof readme === "function") {
4829
+ readme = readme({
4830
+ dir: pkgDir,
4831
+ packageJson: JSON.parse(newJSONString)
4832
+ });
4833
+ }
4834
+ const readmeContent = readme.replace(/\$name/g, pkgName).replace(/\$license/g, license);
4835
+ fs.writeFileSync(readmeFilePath, readmeContent);
4836
+ });
4837
+
4838
+ const intersection = (a, b) => new Set([...a].filter((i) => b.has(i)));
4839
+ function getExports({
4840
+ entrypoints: entrypoints$1,
4841
+ pkgIsModule,
4842
+ entries,
4843
+ config,
4844
+ dir,
4845
+ noFilter,
4846
+ withSource,
4847
+ withSuffix
4848
+ }) {
4849
+ const dirResolve = (...paths) => path.resolve(dir ?? process.cwd(), ...paths);
4850
+ const dirRelative = (path$1) => path.relative(dir ?? process.cwd(), path$1);
4851
+ const { build = {} } = config ?? {};
4852
+ const {
4853
+ crossModuleConvertor = true
4854
+ } = build;
4855
+ const jsOutdir = `./${dirRelative(dirResolve(
4856
+ (typeof build?.output?.dir === "object" ? build.output.dir.js : build?.output?.dir) ?? "dist"
4857
+ ))}`;
4858
+ const [, resolvedEntrypoints] = entrypoints.resolveEntrypoints(entrypoints$1);
4859
+ if (entries) {
4860
+ Object.entries(resolvedEntrypoints).forEach(([key]) => {
4861
+ if (!entries.some((e) => micromatchExports.isMatch(key, e, { matchBase: true }))) {
4862
+ delete resolvedEntrypoints[key];
4863
+ }
4864
+ });
4865
+ }
4866
+ const filteredResolvedEntrypoints = noFilter ? resolvedEntrypoints : entrypoints.filterLeafs(
4867
+ resolvedEntrypoints,
4868
+ {
4869
+ skipValue: [
4870
+ // ignore values that filename starts with `.jk-noentry`
4871
+ /(^|\/)\.jk-noentry/,
4872
+ ...entrypoints.DEFAULT_SKIP_VALUES
4873
+ ]
4874
+ }
4875
+ );
4876
+ const crossModuleWithConditional = crossModuleConvertor ? {
4877
+ import: (opts) => !pkgIsModule && intersection(
4878
+ new Set(opts.conditionals),
4879
+ /* @__PURE__ */ new Set(["import", "module"])
4880
+ ).size === 0 ? opts.dist.replace(/\.js$/, ".mjs") : false,
4881
+ require: (opts) => pkgIsModule && intersection(
4882
+ new Set(opts.conditionals),
4883
+ /* @__PURE__ */ new Set(["require", "node"])
4884
+ ).size === 0 ? opts.dist.replace(/\.js$/, ".cjs") : false
4885
+ } : {};
4886
+ return [
4887
+ filteredResolvedEntrypoints,
4888
+ entrypoints.entrypoints2Exports(filteredResolvedEntrypoints, {
4889
+ outdir: jsOutdir,
4890
+ withSource,
4891
+ withSuffix,
4892
+ withConditional: {
4893
+ ...crossModuleWithConditional
4894
+ }
4895
+ })
4896
+ ];
4897
+ }
4898
+
4899
+ commander.program.command("publish").aliases(["pub", "p"]).option("-b, --bumper <bumper>", "bump version", "patch").option("-p, --preview", "preview publish").action(async ({ preview, bumper: bumper$1, ...options }) => {
4900
+ actionRestore();
4901
+ const { value = {} } = await getSelectedProjectsGraph() ?? {};
4902
+ const selectedProjectsGraphEntries = Object.entries(value);
4903
+ if (selectedProjectsGraphEntries.length === 0) {
4904
+ throw new Error("no packages selected");
4905
+ }
4906
+ const manifests = selectedProjectsGraphEntries.map(([dir, manifest]) => {
4907
+ const { type, exports: entrypoints = {} } = manifest;
4908
+ const pkgIsModule = type === "module";
4909
+ const newManifest = { ...manifest };
4910
+ const [resolvedEntrypoints, exports] = getExports({
4911
+ entrypoints,
4912
+ pkgIsModule,
4913
+ config: loadConfig(dir),
4914
+ dir,
4915
+ noFilter: true,
4916
+ withSource: true,
4917
+ withSuffix: true
4918
+ });
4919
+ newManifest.exports = {
4920
+ ...resolvedEntrypoints,
4921
+ ...exports
4922
+ };
4923
+ return [dir, newManifest];
4924
+ });
4925
+ const passArgs = Object.entries(options).reduce((acc, [key, value2]) => {
4926
+ if (value2) {
4927
+ acc.push(`--${key}`, value2);
4928
+ }
4929
+ return acc;
4930
+ }, []);
4931
+ for (const [dir, manifest] of manifests) {
4932
+ const oldJSONString = fs.readFileSync(path.join(dir, "package.json"), "utf-8");
4933
+ const oldJSON = JSON.parse(oldJSONString) ?? "0.0.0";
4934
+ const newVersion = bumper.bump(oldJSON.version, bumper$1);
4935
+ const { indent = " " } = detectIndent(oldJSONString);
4936
+ const formattingOptions = {
4937
+ tabSize: indent.length,
4938
+ insertSpaces: true
4939
+ };
4940
+ let newJSONString = oldJSONString;
4941
+ newJSONString = jsoncParser.applyEdits(
4942
+ newJSONString,
4943
+ jsoncParser.modify(
4944
+ newJSONString,
4945
+ ["version"],
4946
+ newVersion,
4947
+ { formattingOptions }
4948
+ )
4949
+ );
4950
+ for (const [key, value2] of Object.entries(manifest)) {
4951
+ if (JSON.stringify(value2) === JSON.stringify(oldJSON[key]))
4952
+ continue;
4953
+ if (key !== "exports") {
4954
+ newJSONString = jsoncParser.applyEdits(
4955
+ newJSONString,
4956
+ jsoncParser.modify(
4957
+ newJSONString,
4958
+ ["publishConfig", key],
4959
+ value2,
4960
+ { formattingOptions }
4961
+ )
4962
+ );
4963
+ } else {
4964
+ const exports = value2;
4965
+ for (const [k, v] of Object.entries(exports)) {
4966
+ newJSONString = jsoncParser.applyEdits(
4967
+ newJSONString,
4968
+ jsoncParser.modify(
4969
+ newJSONString,
4970
+ ["publishConfig", "exports", k],
4971
+ v,
4972
+ { formattingOptions }
4973
+ )
4974
+ );
4975
+ }
4976
+ const index = exports?.["."];
4977
+ const indexPublishConfig = {};
4978
+ if (index) {
4979
+ switch (typeof index) {
4980
+ case "string":
4981
+ indexPublishConfig[manifest?.type === "module" ? "module" : "main"] = index;
4982
+ break;
4983
+ case "object": {
4984
+ const indexExports = index;
4985
+ indexPublishConfig.main = indexExports["require"] ?? indexExports["default"];
4986
+ indexPublishConfig.module = indexExports["import"] ?? indexExports["module"] ?? indexExports["default"];
4987
+ break;
4988
+ }
4989
+ }
4990
+ for (const [k, v] of Object.entries(indexPublishConfig)) {
4991
+ if (v === void 0)
4992
+ continue;
4993
+ newJSONString = jsoncParser.applyEdits(
4994
+ newJSONString,
4995
+ jsoncParser.modify(
4996
+ newJSONString,
4997
+ ["publishConfig", k],
4998
+ v,
4999
+ { formattingOptions }
5000
+ )
5001
+ );
5002
+ }
5003
+ }
5004
+ }
5005
+ }
5006
+ try {
5007
+ fs.renameSync(path.join(dir, "package.json"), path.join(dir, "package.json.bak"));
5008
+ fs.writeFileSync(path.join(dir, "package.json"), newJSONString);
5009
+ console.log(newJSONString);
5010
+ if (preview) {
5011
+ console.warn("preview mode");
5012
+ continue;
5013
+ }
5014
+ childProcess__namespace.execSync(["pnpm", "publish", "--access", "public", "--no-git-checks", ...passArgs].join(" "), {
5015
+ cwd: dir,
5016
+ stdio: "inherit"
5017
+ });
5018
+ const modifyVersionPackageJSON = jsoncParser.applyEdits(oldJSONString, jsoncParser.modify(oldJSONString, ["version"], newVersion, {}));
5019
+ fs.writeFileSync(path.join(dir, "package.json.bak"), modifyVersionPackageJSON);
5020
+ } finally {
5021
+ fs.unlinkSync(path.join(dir, "package.json"));
5022
+ fs.renameSync(path.join(dir, "package.json.bak"), path.join(dir, "package.json"));
5023
+ }
5024
+ }
5025
+ actionDone();
5026
+ });
5027
+
5028
+ commander.program.parse(process.argv);