@rspress/core 2.1.3 → 2.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/dist/bb~0.js +1 -0
  2. package/dist/b~0.js +3026 -1
  3. package/dist/cli/index.js +1 -1
  4. package/dist/config/loadConfigFile.js +1 -1
  5. package/dist/eject-theme/components/Callout/index.test.tsx +52 -0
  6. package/dist/eject-theme/components/Callout/index.tsx +11 -0
  7. package/dist/eject-theme/components/CodeBlock/index.tsx +1 -1
  8. package/dist/eject-theme/components/HomeFeature/index.scss +12 -0
  9. package/dist/eject-theme/components/HomeHero/index.scss +4 -1
  10. package/dist/eject-theme/components/PageTabs/index.test.tsx +45 -0
  11. package/dist/eject-theme/components/PageTabs/index.tsx +17 -0
  12. package/dist/eject-theme/components/Prompt/index.tsx +2 -1
  13. package/dist/eject-theme/components/Sidebar/SidebarGroup.scss +14 -0
  14. package/dist/eject-theme/components/Sidebar/SidebarGroup.tsx +6 -1
  15. package/dist/eject-theme/components/Sidebar/SidebarItem.scss +0 -10
  16. package/dist/eject-theme/components/Sidebar/SidebarItem.tsx +2 -2
  17. package/dist/eject-theme/components/Tabs/index.test.tsx +26 -4
  18. package/dist/eject-theme/components/Tabs/index.tsx +8 -5
  19. package/dist/node/PluginDriver.js +1 -1
  20. package/dist/node/auto-nav-sidebar/index.js +1 -1
  21. package/dist/node/auto-nav-sidebar/locales.js +1 -1
  22. package/dist/node/auto-nav-sidebar/normalize.js +1 -1
  23. package/dist/node/auto-nav-sidebar/utils.js +1 -1
  24. package/dist/node/auto-nav-sidebar/walk.js +1 -1
  25. package/dist/node/eject.js +1 -1
  26. package/dist/node/initRsbuild.js +6 -1
  27. package/dist/node/mdx/options.js +1 -1
  28. package/dist/node/mdx/processor.js +1 -1
  29. package/dist/node/mdx/rehypePlugins/codeMeta.js +1 -1
  30. package/dist/node/mdx/rehypePlugins/headerAnchor.js +1 -1
  31. package/dist/node/mdx/rehypePlugins/shiki.js +1 -1
  32. package/dist/node/mdx/remarkPlugins/builtin.js +1 -1
  33. package/dist/node/route/RoutePage.js +1 -1
  34. package/dist/node/route/RouteService.js +1 -1
  35. package/dist/node/route/extractPageData.js +19 -3
  36. package/dist/node/route/normalizeRoutePath.js +1 -1
  37. package/dist/node/route/routeChunkAssets.d.ts +2 -0
  38. package/dist/node/route/routeChunkAssets.js +6 -0
  39. package/dist/node/runtimeModule/i18n/getI18nData.js +1 -1
  40. package/dist/node/runtimeModule/i18n/rsbuildPlugin.js +1 -1
  41. package/dist/node/runtimeModule/pageData/createPageData.js +1 -1
  42. package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
  43. package/dist/node/runtimeModule/searchHooks.js +1 -1
  44. package/dist/node/runtimeModule/siteData/createSiteData.js +1 -1
  45. package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +1 -1
  46. package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +1 -1
  47. package/dist/node/serve.js +1 -1
  48. package/dist/node/sitemap.js +1 -1
  49. package/dist/node/ssg/alternateLinks.js +1 -1
  50. package/dist/node/ssg/renderHtmlTemplate.js +5 -1
  51. package/dist/node/ssg/renderPageWorker.js +1 -1
  52. package/dist/node/ssg/renderPages.js +1 -1
  53. package/dist/node/ssg/rsbuildPluginSSG.js +1 -1
  54. package/dist/node/ssg/ssgEnv.js +1 -1
  55. package/dist/node/ssg-md/llms/emitLlmsTxt.js +1 -1
  56. package/dist/node/ssg-md/llms/llmsTxt.js +1 -1
  57. package/dist/node/ssg-md/remarkSplitMdx.d.ts +0 -4
  58. package/dist/node/ssg-md/remarkSplitMdx.js +266 -163
  59. package/dist/node/ssg-md/renderPage.js +1 -1
  60. package/dist/node/ssg-md/renderPages.js +1 -1
  61. package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
  62. package/dist/node/utils/checkLanguageParity.js +1 -1
  63. package/dist/node/utils/createHash.js +1 -1
  64. package/dist/node/utils/flattenMdxContent.js +1 -1
  65. package/dist/node/utils/getPageKey.js +1 -1
  66. package/dist/node/utils/reactAlias.js +3 -1
  67. package/dist/n~0.js +1 -1
  68. package/dist/{tx~0.js → q~0.js} +3 -3
  69. package/dist/shiki-transformers.js +1 -1
  70. package/dist/theme/components/Callout/index.js +10 -0
  71. package/dist/theme/components/CodeBlock/index.d.ts +1 -1
  72. package/dist/theme/components/HomeFeature/index.css +10 -0
  73. package/dist/theme/components/HomeHero/index.css +5 -1
  74. package/dist/theme/components/PageTabs/index.js +12 -0
  75. package/dist/theme/components/Prompt/index.js +1 -1
  76. package/dist/theme/components/Sidebar/SidebarGroup.css +14 -0
  77. package/dist/theme/components/Sidebar/SidebarGroup.js +29 -22
  78. package/dist/theme/components/Sidebar/SidebarItem.css +0 -10
  79. package/dist/theme/components/Sidebar/SidebarItem.js +2 -2
  80. package/dist/theme/components/Tabs/index.js +8 -5
  81. package/dist/tinypool~0.js +2 -2
  82. package/dist/y~0.js +1 -1
  83. package/package.json +14 -11
  84. package/skills/rspress-best-practices/SKILL.md +82 -0
  85. package/skills/rspress-custom-theme/SKILL.md +242 -0
  86. package/skills/rspress-custom-theme/references/css-variables.md +177 -0
  87. package/skills/rspress-custom-theme/references/eject-components.md +154 -0
  88. package/skills/rspress-custom-theme/references/layout-slots.md +153 -0
  89. package/skills/rspress-description-generator/SKILL.md +118 -0
  90. package/skills/rspress-docs-generator/SKILL.md +60 -0
  91. package/skills/rspress-docs-generator/references/create-new-docs.md +73 -0
  92. package/skills/rspress-docs-generator/references/doc-structure-conventions.md +117 -0
  93. package/skills/rspress-docs-generator/references/maintain-docs-for-prs.md +31 -0
  94. package/skills/rspress-docs-generator/references/rspress-version-guard.md +13 -0
  95. package/dist/p~0.js +0 -3032
package/dist/p~0.js DELETED
@@ -1,3032 +0,0 @@
1
- import { rspackRequire, moduleFactories } from "./rslib-runtime~0.js";
2
- import { fileURLToPath as external_url_fileURLToPath } from "url";
3
- import node_path, { extname, join, relative as external_node_path_relative } from "node:path";
4
- import { basename, dirname, isAbsolute, normalize, posix, relative as external_path_relative, resolve, sep } from "path";
5
- import * as __rspack_external_fs from "fs";
6
- import { readdir, readdirSync, realpath, realpathSync, stat as external_fs_stat, statSync } from "fs";
7
- import { createRequire as external_module_createRequire } from "module";
8
- moduleFactories.add({
9
- "../../node_modules/.pnpm/picomatch@4.0.7/node_modules/picomatch/index.js" (module) {
10
- const pico = rspackRequire("../../node_modules/.pnpm/picomatch@4.0.7/node_modules/picomatch/lib/picomatch.js");
11
- const utils = rspackRequire("../../node_modules/.pnpm/picomatch@4.0.7/node_modules/picomatch/lib/utils.js");
12
- function picomatch(glob, options, returnState = false) {
13
- if (options && (null === options.windows || void 0 === options.windows)) options = {
14
- ...options,
15
- windows: utils.isWindows()
16
- };
17
- return pico(glob, options, returnState);
18
- }
19
- Object.assign(picomatch, pico);
20
- module.exports = picomatch;
21
- },
22
- "../../node_modules/.pnpm/picomatch@4.0.7/node_modules/picomatch/lib/constants.js" (module) {
23
- const WIN_SLASH = '\\\\/';
24
- const WIN_NO_SLASH = `[^${WIN_SLASH}]`;
25
- const DEFAULT_MAX_EXTGLOB_RECURSION = 0;
26
- const DOT_LITERAL = '\\.';
27
- const PLUS_LITERAL = '\\+';
28
- const QMARK_LITERAL = '\\?';
29
- const SLASH_LITERAL = '\\/';
30
- const ONE_CHAR = '(?=.)';
31
- const QMARK = '[^/]';
32
- const END_ANCHOR = `(?:${SLASH_LITERAL}|$)`;
33
- const START_ANCHOR = `(?:^|${SLASH_LITERAL})`;
34
- const DOTS_SLASH = `${DOT_LITERAL}{1,2}${END_ANCHOR}`;
35
- const NO_DOT = `(?!${DOT_LITERAL})`;
36
- const NO_DOTS = `(?!${START_ANCHOR}${DOTS_SLASH})`;
37
- const NO_DOT_SLASH = `(?!${DOT_LITERAL}{0,1}${END_ANCHOR})`;
38
- const NO_DOTS_SLASH = `(?!${DOTS_SLASH})`;
39
- const QMARK_NO_DOT = `[^.${SLASH_LITERAL}]`;
40
- const STAR = `${QMARK}*?`;
41
- const SEP = '/';
42
- const POSIX_CHARS = {
43
- DOT_LITERAL,
44
- PLUS_LITERAL,
45
- QMARK_LITERAL,
46
- SLASH_LITERAL,
47
- ONE_CHAR,
48
- QMARK,
49
- END_ANCHOR,
50
- DOTS_SLASH,
51
- NO_DOT,
52
- NO_DOTS,
53
- NO_DOT_SLASH,
54
- NO_DOTS_SLASH,
55
- QMARK_NO_DOT,
56
- STAR,
57
- START_ANCHOR,
58
- SEP
59
- };
60
- const WINDOWS_CHARS = {
61
- ...POSIX_CHARS,
62
- SLASH_LITERAL: `[${WIN_SLASH}]`,
63
- QMARK: WIN_NO_SLASH,
64
- STAR: `${WIN_NO_SLASH}*?`,
65
- DOTS_SLASH: `${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$)`,
66
- NO_DOT: `(?!${DOT_LITERAL})`,
67
- NO_DOTS: `(?!(?:^|[${WIN_SLASH}])${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
68
- NO_DOT_SLASH: `(?!${DOT_LITERAL}{0,1}(?:[${WIN_SLASH}]|$))`,
69
- NO_DOTS_SLASH: `(?!${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
70
- QMARK_NO_DOT: `[^.${WIN_SLASH}]`,
71
- START_ANCHOR: `(?:^|[${WIN_SLASH}])`,
72
- END_ANCHOR: `(?:[${WIN_SLASH}]|$)`,
73
- SEP: '\\'
74
- };
75
- const POSIX_REGEX_SOURCE = {
76
- __proto__: null,
77
- alnum: 'a-zA-Z0-9',
78
- alpha: 'a-zA-Z',
79
- ascii: '\\x00-\\x7F',
80
- blank: ' \\t',
81
- cntrl: '\\x00-\\x1F\\x7F',
82
- digit: '0-9',
83
- graph: '\\x21-\\x7E',
84
- lower: 'a-z',
85
- print: '\\x20-\\x7E ',
86
- punct: '\\-!"#$%&\'()\\*+,./:;<=>?@[\\]^_`{|}~',
87
- space: ' \\t\\r\\n\\v\\f',
88
- upper: 'A-Z',
89
- word: 'A-Za-z0-9_',
90
- xdigit: 'A-Fa-f0-9'
91
- };
92
- module.exports = {
93
- DEFAULT_MAX_EXTGLOB_RECURSION,
94
- MAX_LENGTH: 65536,
95
- POSIX_REGEX_SOURCE,
96
- REGEX_BACKSLASH: /\\(?![*+?^${}(|)[\]])/g,
97
- REGEX_NON_SPECIAL_CHARS: /^[^@![\].,$*+?^{}()|\\/]+/,
98
- REGEX_SPECIAL_CHARS: /[-*+?.^${}(|)[\]]/,
99
- REGEX_SPECIAL_CHARS_BACKREF: /(\\?)((\W)(\3*))/g,
100
- REGEX_SPECIAL_CHARS_GLOBAL: /([-*+?.^${}(|)[\]])/g,
101
- REGEX_REMOVE_BACKSLASH: /(?:\[.*?[^\\]\]|\\(?=.))/g,
102
- REPLACEMENTS: {
103
- __proto__: null,
104
- '***': '*',
105
- '**/**': '**',
106
- '**/**/**': '**'
107
- },
108
- CHAR_0: 48,
109
- CHAR_9: 57,
110
- CHAR_UPPERCASE_A: 65,
111
- CHAR_LOWERCASE_A: 97,
112
- CHAR_UPPERCASE_Z: 90,
113
- CHAR_LOWERCASE_Z: 122,
114
- CHAR_LEFT_PARENTHESES: 40,
115
- CHAR_RIGHT_PARENTHESES: 41,
116
- CHAR_ASTERISK: 42,
117
- CHAR_AMPERSAND: 38,
118
- CHAR_AT: 64,
119
- CHAR_BACKWARD_SLASH: 92,
120
- CHAR_CARRIAGE_RETURN: 13,
121
- CHAR_CIRCUMFLEX_ACCENT: 94,
122
- CHAR_COLON: 58,
123
- CHAR_COMMA: 44,
124
- CHAR_DOT: 46,
125
- CHAR_DOUBLE_QUOTE: 34,
126
- CHAR_EQUAL: 61,
127
- CHAR_EXCLAMATION_MARK: 33,
128
- CHAR_FORM_FEED: 12,
129
- CHAR_FORWARD_SLASH: 47,
130
- CHAR_GRAVE_ACCENT: 96,
131
- CHAR_HASH: 35,
132
- CHAR_HYPHEN_MINUS: 45,
133
- CHAR_LEFT_ANGLE_BRACKET: 60,
134
- CHAR_LEFT_CURLY_BRACE: 123,
135
- CHAR_LEFT_SQUARE_BRACKET: 91,
136
- CHAR_LINE_FEED: 10,
137
- CHAR_NO_BREAK_SPACE: 160,
138
- CHAR_PERCENT: 37,
139
- CHAR_PLUS: 43,
140
- CHAR_QUESTION_MARK: 63,
141
- CHAR_RIGHT_ANGLE_BRACKET: 62,
142
- CHAR_RIGHT_CURLY_BRACE: 125,
143
- CHAR_RIGHT_SQUARE_BRACKET: 93,
144
- CHAR_SEMICOLON: 59,
145
- CHAR_SINGLE_QUOTE: 39,
146
- CHAR_SPACE: 32,
147
- CHAR_TAB: 9,
148
- CHAR_UNDERSCORE: 95,
149
- CHAR_VERTICAL_LINE: 124,
150
- CHAR_ZERO_WIDTH_NOBREAK_SPACE: 65279,
151
- extglobChars (chars) {
152
- return {
153
- '!': {
154
- type: 'negate',
155
- open: '(?:(?!(?:',
156
- close: `))${chars.STAR})`
157
- },
158
- '?': {
159
- type: 'qmark',
160
- open: '(?:',
161
- close: ')?'
162
- },
163
- '+': {
164
- type: 'plus',
165
- open: '(?:',
166
- close: ')+'
167
- },
168
- '*': {
169
- type: 'star',
170
- open: '(?:',
171
- close: ')*'
172
- },
173
- '@': {
174
- type: 'at',
175
- open: '(?:',
176
- close: ')'
177
- }
178
- };
179
- },
180
- globChars (win32) {
181
- return true === win32 ? WINDOWS_CHARS : POSIX_CHARS;
182
- }
183
- };
184
- },
185
- "../../node_modules/.pnpm/picomatch@4.0.7/node_modules/picomatch/lib/parse.js" (module) {
186
- const constants = rspackRequire("../../node_modules/.pnpm/picomatch@4.0.7/node_modules/picomatch/lib/constants.js");
187
- const utils = rspackRequire("../../node_modules/.pnpm/picomatch@4.0.7/node_modules/picomatch/lib/utils.js");
188
- const { MAX_LENGTH, POSIX_REGEX_SOURCE, REGEX_NON_SPECIAL_CHARS, REGEX_SPECIAL_CHARS_BACKREF, REPLACEMENTS } = constants;
189
- const expandRange = (args, options)=>{
190
- if ('function' == typeof options.expandRange) return options.expandRange(...args, options);
191
- args.sort();
192
- const value = `[${args.join('-')}]`;
193
- try {
194
- new RegExp(value);
195
- } catch (ex) {
196
- return args.map((v)=>utils.escapeRegex(v)).join('..');
197
- }
198
- return value;
199
- };
200
- const syntaxError = (type, char)=>`Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`;
201
- const splitTopLevel = (input)=>{
202
- const parts = [];
203
- let bracket = 0;
204
- let paren = 0;
205
- let quote = 0;
206
- let value = '';
207
- let escaped = false;
208
- for (const ch of input){
209
- if (true === escaped) {
210
- value += ch;
211
- escaped = false;
212
- continue;
213
- }
214
- if ('\\' === ch) {
215
- value += ch;
216
- escaped = true;
217
- continue;
218
- }
219
- if ('"' === ch) {
220
- quote = 1 === quote ? 0 : 1;
221
- value += ch;
222
- continue;
223
- }
224
- if (0 === quote) {
225
- if ('[' === ch) bracket++;
226
- else if (']' === ch && bracket > 0) bracket--;
227
- else if (0 === bracket) {
228
- if ('(' === ch) paren++;
229
- else if (')' === ch && paren > 0) paren--;
230
- else if ('|' === ch && 0 === paren) {
231
- parts.push(value);
232
- value = '';
233
- continue;
234
- }
235
- }
236
- }
237
- value += ch;
238
- }
239
- parts.push(value);
240
- return parts;
241
- };
242
- const isPlainBranch = (branch)=>{
243
- let escaped = false;
244
- for (const ch of branch){
245
- if (true === escaped) {
246
- escaped = false;
247
- continue;
248
- }
249
- if ('\\' === ch) {
250
- escaped = true;
251
- continue;
252
- }
253
- if (/[?*+@!()[\]{}]/.test(ch)) return false;
254
- }
255
- return true;
256
- };
257
- const normalizeSimpleBranch = (branch)=>{
258
- let value = branch.trim();
259
- let changed = true;
260
- while(true === changed){
261
- changed = false;
262
- if (/^@\([^\\()[\]{}|]+\)$/.test(value)) {
263
- value = value.slice(2, -1);
264
- changed = true;
265
- }
266
- }
267
- if (!isPlainBranch(value)) return;
268
- return value.replace(/\\(.)/g, '$1');
269
- };
270
- const hasRepeatedCharPrefixOverlap = (branches)=>{
271
- const values = branches.map(normalizeSimpleBranch).filter(Boolean);
272
- for(let i = 0; i < values.length; i++)for(let j = i + 1; j < values.length; j++){
273
- const a = values[i];
274
- const b = values[j];
275
- const char = a[0];
276
- if (char && a === char.repeat(a.length) && b === char.repeat(b.length)) {
277
- if (a === b || a.startsWith(b) || b.startsWith(a)) return true;
278
- }
279
- }
280
- return false;
281
- };
282
- const parseRepeatedExtglob = (pattern, requireEnd = true)=>{
283
- if ('+' !== pattern[0] && '*' !== pattern[0] || '(' !== pattern[1]) return;
284
- let bracket = 0;
285
- let paren = 0;
286
- let quote = 0;
287
- let escaped = false;
288
- for(let i = 1; i < pattern.length; i++){
289
- const ch = pattern[i];
290
- if (true === escaped) {
291
- escaped = false;
292
- continue;
293
- }
294
- if ('\\' === ch) {
295
- escaped = true;
296
- continue;
297
- }
298
- if ('"' === ch) {
299
- quote = 1 === quote ? 0 : 1;
300
- continue;
301
- }
302
- if (1 !== quote) {
303
- if ('[' === ch) {
304
- bracket++;
305
- continue;
306
- }
307
- if (']' === ch && bracket > 0) {
308
- bracket--;
309
- continue;
310
- }
311
- if (!(bracket > 0)) {
312
- if ('(' === ch) {
313
- paren++;
314
- continue;
315
- }
316
- if (')' === ch) {
317
- paren--;
318
- if (0 === paren) {
319
- if (true === requireEnd && i !== pattern.length - 1) return;
320
- return {
321
- type: pattern[0],
322
- body: pattern.slice(2, i),
323
- end: i
324
- };
325
- }
326
- }
327
- }
328
- }
329
- }
330
- };
331
- const buildCharClassStar = (chars)=>{
332
- const source = 1 === chars.length ? utils.escapeRegex(chars[0]) : `[${chars.map((ch)=>utils.escapeRegex(ch)).join('')}]`;
333
- return `${source}*`;
334
- };
335
- const getStarExtglobSequenceChars = (pattern)=>{
336
- let index = 0;
337
- const chars = [];
338
- while(index < pattern.length){
339
- const match = parseRepeatedExtglob(pattern.slice(index), false);
340
- if (!match || '*' !== match.type) return;
341
- const branches = splitTopLevel(match.body).map((branch)=>branch.trim());
342
- if (1 !== branches.length) return;
343
- const branch = normalizeSimpleBranch(branches[0]);
344
- if (!branch || 1 !== branch.length) return;
345
- chars.push(branch);
346
- index += match.end + 1;
347
- }
348
- if (chars.length < 1) return;
349
- return chars;
350
- };
351
- const repeatedExtglobRecursion = (pattern)=>{
352
- let depth = 0;
353
- let value = pattern.trim();
354
- let match = parseRepeatedExtglob(value);
355
- while(match){
356
- depth++;
357
- value = match.body.trim();
358
- match = parseRepeatedExtglob(value);
359
- }
360
- return depth;
361
- };
362
- const analyzeRepeatedExtglob = (body, options)=>{
363
- if (false === options.maxExtglobRecursion) return {
364
- risky: false
365
- };
366
- const max = 'number' == typeof options.maxExtglobRecursion ? options.maxExtglobRecursion : constants.DEFAULT_MAX_EXTGLOB_RECURSION;
367
- const branches = splitTopLevel(body).map((branch)=>branch.trim());
368
- if (branches.length > 1) {
369
- if (branches.some((branch)=>'' === branch) || branches.some((branch)=>/^[*?]+$/.test(branch)) || hasRepeatedCharPrefixOverlap(branches)) return {
370
- risky: true
371
- };
372
- }
373
- const safeChars = [];
374
- let sawStarSequence = false;
375
- let combinable = true;
376
- for (const branch of branches){
377
- const chars = getStarExtglobSequenceChars(branch);
378
- if (chars) {
379
- sawStarSequence = true;
380
- safeChars.push(...chars);
381
- continue;
382
- }
383
- const literal = normalizeSimpleBranch(branch);
384
- if (literal && 1 === literal.length) {
385
- safeChars.push(literal);
386
- continue;
387
- }
388
- combinable = false;
389
- if (repeatedExtglobRecursion(branch) > max) return {
390
- risky: true
391
- };
392
- }
393
- if (sawStarSequence) return combinable ? {
394
- risky: true,
395
- safeOutput: buildCharClassStar([
396
- ...new Set(safeChars)
397
- ])
398
- } : {
399
- risky: true
400
- };
401
- return {
402
- risky: false
403
- };
404
- };
405
- const parse = (input, options)=>{
406
- if ('string' != typeof input) throw new TypeError('Expected a string');
407
- input = REPLACEMENTS[input] || input;
408
- const opts = {
409
- ...options
410
- };
411
- const max = 'number' == typeof opts.maxLength ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
412
- let len = input.length;
413
- if (len > max) throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
414
- const bos = {
415
- type: 'bos',
416
- value: '',
417
- output: opts.prepend || ''
418
- };
419
- const tokens = [
420
- bos
421
- ];
422
- const capture = opts.capture ? '' : '?:';
423
- const PLATFORM_CHARS = constants.globChars(opts.windows);
424
- const EXTGLOB_CHARS = constants.extglobChars(PLATFORM_CHARS);
425
- const { DOT_LITERAL, PLUS_LITERAL, SLASH_LITERAL, ONE_CHAR, DOTS_SLASH, NO_DOT, NO_DOT_SLASH, NO_DOTS_SLASH, QMARK, QMARK_NO_DOT, STAR, START_ANCHOR } = PLATFORM_CHARS;
426
- const globstar = (opts)=>`(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
427
- const nodot = opts.dot ? '' : NO_DOT;
428
- const qmarkNoDot = opts.dot ? QMARK : QMARK_NO_DOT;
429
- let star = true === opts.bash ? globstar(opts) : STAR;
430
- if (opts.capture) star = `(${star})`;
431
- if ('boolean' == typeof opts.noext) opts.noextglob = opts.noext;
432
- const state = {
433
- input,
434
- index: -1,
435
- start: 0,
436
- dot: true === opts.dot,
437
- consumed: '',
438
- output: '',
439
- prefix: '',
440
- backtrack: false,
441
- negated: false,
442
- brackets: 0,
443
- braces: 0,
444
- parens: 0,
445
- quotes: 0,
446
- globstar: false,
447
- tokens
448
- };
449
- input = utils.removePrefix(input, state);
450
- len = input.length;
451
- const extglobs = [];
452
- const braces = [];
453
- const stack = [];
454
- let prev = bos;
455
- let value;
456
- const eos = ()=>state.index === len - 1;
457
- const peek = state.peek = (n = 1)=>input[state.index + n];
458
- const advance = state.advance = ()=>input[++state.index] || '';
459
- const remaining = ()=>input.slice(state.index + 1);
460
- const consume = (value = '', num = 0)=>{
461
- state.consumed += value;
462
- state.index += num;
463
- };
464
- const append = (token)=>{
465
- state.output += null != token.output ? token.output : token.value;
466
- consume(token.value);
467
- };
468
- const negate = ()=>{
469
- let count = 1;
470
- while('!' === peek() && ('(' !== peek(2) || '?' === peek(3))){
471
- advance();
472
- state.start++;
473
- count++;
474
- }
475
- if (count % 2 === 0) return false;
476
- state.negated = true;
477
- state.start++;
478
- return true;
479
- };
480
- const increment = (type)=>{
481
- state[type]++;
482
- stack.push(type);
483
- };
484
- const decrement = (type)=>{
485
- state[type]--;
486
- stack.pop();
487
- };
488
- const push = (tok)=>{
489
- if ('globstar' === prev.type) {
490
- const isBrace = state.braces > 0 && ('comma' === tok.type || 'brace' === tok.type);
491
- const isExtglob = true === tok.extglob || extglobs.length && ('pipe' === tok.type || 'paren' === tok.type);
492
- if ('slash' !== tok.type && 'paren' !== tok.type && !isBrace && !isExtglob) {
493
- state.output = state.output.slice(0, -prev.output.length);
494
- prev.type = 'star';
495
- prev.value = '*';
496
- prev.output = star;
497
- state.output += prev.output;
498
- }
499
- }
500
- if (extglobs.length && 'paren' !== tok.type) extglobs[extglobs.length - 1].inner += tok.value;
501
- if (tok.value || tok.output) append(tok);
502
- if (prev && 'text' === prev.type && 'text' === tok.type) {
503
- prev.output = (prev.output || prev.value) + tok.value;
504
- prev.value += tok.value;
505
- return;
506
- }
507
- tok.prev = prev;
508
- tokens.push(tok);
509
- prev = tok;
510
- };
511
- const extglobOpen = (type, value)=>{
512
- const token = {
513
- ...EXTGLOB_CHARS[value],
514
- conditions: 1,
515
- inner: ''
516
- };
517
- token.prev = prev;
518
- token.parens = state.parens;
519
- token.output = state.output;
520
- token.startIndex = state.index;
521
- token.tokensIndex = tokens.length;
522
- const output = (opts.capture ? '(' : '') + token.open;
523
- increment('parens');
524
- push({
525
- type,
526
- value,
527
- output: state.output ? '' : ONE_CHAR
528
- });
529
- push({
530
- type: 'paren',
531
- extglob: true,
532
- value: advance(),
533
- output
534
- });
535
- extglobs.push(token);
536
- };
537
- const extglobClose = (token)=>{
538
- const literal = input.slice(token.startIndex, state.index + 1);
539
- const body = input.slice(token.startIndex + 2, state.index);
540
- const analysis = analyzeRepeatedExtglob(body, opts);
541
- if (('plus' === token.type || 'star' === token.type) && analysis.risky) {
542
- const safeOutput = analysis.safeOutput ? (token.output ? '' : ONE_CHAR) + (opts.capture ? `(${analysis.safeOutput})` : analysis.safeOutput) : void 0;
543
- const open = tokens[token.tokensIndex];
544
- open.type = 'text';
545
- open.value = literal;
546
- open.output = safeOutput || utils.escapeRegex(literal);
547
- for(let i = token.tokensIndex + 1; i < tokens.length; i++){
548
- tokens[i].value = '';
549
- tokens[i].output = '';
550
- delete tokens[i].suffix;
551
- }
552
- state.output = token.output + open.output;
553
- state.backtrack = true;
554
- push({
555
- type: 'paren',
556
- extglob: true,
557
- value,
558
- output: ''
559
- });
560
- decrement('parens');
561
- return;
562
- }
563
- let output = token.close + (opts.capture ? ')' : '');
564
- let rest;
565
- if ('negate' === token.type) {
566
- let extglobStar = star;
567
- if (token.inner && token.inner.length > 1 && token.inner.includes('/')) extglobStar = globstar(opts);
568
- if (extglobStar !== star || eos() || /^\)+$/.test(remaining())) output = token.close = `)$))${extglobStar}`;
569
- if (token.inner.includes('*') && (rest = remaining()) && /^\.[^\\/.]+$/.test(rest)) {
570
- const expression = parse(rest, {
571
- ...options,
572
- fastpaths: false
573
- }).output;
574
- output = token.close = `)${expression})${extglobStar})`;
575
- }
576
- if ('bos' === token.prev.type) state.negatedExtglob = true;
577
- }
578
- push({
579
- type: 'paren',
580
- extglob: true,
581
- value,
582
- output
583
- });
584
- decrement('parens');
585
- };
586
- if (false !== opts.fastpaths && !/(^[*!]|[/()[\]{}"])/.test(input)) {
587
- let backslashes = false;
588
- let output = input.replace(REGEX_SPECIAL_CHARS_BACKREF, (m, esc, chars, first, rest, index)=>{
589
- if ('\\' === first) {
590
- backslashes = true;
591
- return m;
592
- }
593
- if ('?' === first) {
594
- if (esc) return esc + first + (rest ? QMARK.repeat(rest.length) : '');
595
- if (0 === index) return qmarkNoDot + (rest ? QMARK.repeat(rest.length) : '');
596
- return QMARK.repeat(chars.length);
597
- }
598
- if ('.' === first) return DOT_LITERAL.repeat(chars.length);
599
- if ('*' === first) {
600
- if (esc) return esc + first + (rest ? star : '');
601
- return star;
602
- }
603
- return esc ? m : `\\${m}`;
604
- });
605
- if (true === backslashes) output = true === opts.unescape ? output.replace(/\\/g, '') : output.replace(/\\+/g, (m)=>m.length % 2 === 0 ? '\\\\' : m ? '\\' : '');
606
- if (output === input && true === opts.contains) {
607
- state.output = input;
608
- return state;
609
- }
610
- state.output = utils.wrapOutput(output, state, options);
611
- return state;
612
- }
613
- while(!eos()){
614
- value = advance();
615
- if ('\u0000' === value) continue;
616
- if ('\\' === value) {
617
- const next = peek();
618
- if ('/' === next && true !== opts.bash) continue;
619
- if ('.' === next || ';' === next) continue;
620
- if (!next) {
621
- value += '\\';
622
- push({
623
- type: 'text',
624
- value
625
- });
626
- continue;
627
- }
628
- const match = /^\\+/.exec(remaining());
629
- let slashes = 0;
630
- if (match && match[0].length > 2) {
631
- slashes = match[0].length;
632
- state.index += slashes;
633
- if (slashes % 2 !== 0) value += '\\';
634
- }
635
- if (true === opts.unescape) value = advance();
636
- else value += advance();
637
- if (0 === state.brackets) {
638
- push({
639
- type: 'text',
640
- value
641
- });
642
- continue;
643
- }
644
- }
645
- if (state.brackets > 0 && (']' !== value || '[' === prev.value || '[^' === prev.value)) {
646
- if (false !== opts.posix && ':' === value) {
647
- const inner = prev.value.slice(1);
648
- if (inner.includes('[')) {
649
- prev.posix = true;
650
- if (inner.includes(':')) {
651
- const idx = prev.value.lastIndexOf('[');
652
- const pre = prev.value.slice(0, idx);
653
- const rest = prev.value.slice(idx + 2);
654
- const posix = POSIX_REGEX_SOURCE[rest];
655
- if (posix) {
656
- prev.value = pre + posix;
657
- state.backtrack = true;
658
- advance();
659
- if (!bos.output && 1 === tokens.indexOf(prev)) bos.output = ONE_CHAR;
660
- continue;
661
- }
662
- }
663
- }
664
- }
665
- if ('[' === value && ':' !== peek() || '-' === value && ']' === peek()) value = `\\${value}`;
666
- if (']' === value && ('[' === prev.value || '[^' === prev.value)) value = `\\${value}`;
667
- if (true === opts.posix && '!' === value && '[' === prev.value) value = '^';
668
- prev.value += value;
669
- append({
670
- value
671
- });
672
- continue;
673
- }
674
- if (1 === state.quotes && '"' !== value) {
675
- value = utils.escapeRegex(value);
676
- prev.value += value;
677
- append({
678
- value
679
- });
680
- continue;
681
- }
682
- if ('"' === value) {
683
- state.quotes = 1 === state.quotes ? 0 : 1;
684
- if (true === opts.keepQuotes) push({
685
- type: 'text',
686
- value
687
- });
688
- continue;
689
- }
690
- if ('(' === value) {
691
- increment('parens');
692
- push({
693
- type: 'paren',
694
- value
695
- });
696
- continue;
697
- }
698
- if (')' === value) {
699
- if (0 === state.parens && true === opts.strictBrackets) throw new SyntaxError(syntaxError('opening', '('));
700
- const extglob = extglobs[extglobs.length - 1];
701
- if (extglob && state.parens === extglob.parens + 1) {
702
- extglobClose(extglobs.pop());
703
- continue;
704
- }
705
- push({
706
- type: 'paren',
707
- value,
708
- output: state.parens ? ')' : '\\)'
709
- });
710
- decrement('parens');
711
- continue;
712
- }
713
- if ('[' === value) {
714
- if (true !== opts.nobracket && remaining().includes(']')) increment('brackets');
715
- else {
716
- if (true !== opts.nobracket && true === opts.strictBrackets) throw new SyntaxError(syntaxError('closing', ']'));
717
- value = `\\${value}`;
718
- }
719
- push({
720
- type: 'bracket',
721
- value
722
- });
723
- continue;
724
- }
725
- if (']' === value) {
726
- if (true === opts.nobracket || prev && 'bracket' === prev.type && 1 === prev.value.length) {
727
- push({
728
- type: 'text',
729
- value,
730
- output: `\\${value}`
731
- });
732
- continue;
733
- }
734
- if (0 === state.brackets) {
735
- if (true === opts.strictBrackets) throw new SyntaxError(syntaxError('opening', '['));
736
- push({
737
- type: 'text',
738
- value,
739
- output: `\\${value}`
740
- });
741
- continue;
742
- }
743
- decrement('brackets');
744
- const prevValue = prev.value.slice(1);
745
- if (true !== prev.posix && '^' === prevValue[0] && !prevValue.includes('/')) value = `/${value}`;
746
- prev.value += value;
747
- append({
748
- value
749
- });
750
- if (false === opts.literalBrackets || utils.hasRegexChars(prevValue)) continue;
751
- const escaped = utils.escapeRegex(prev.value);
752
- state.output = state.output.slice(0, -prev.value.length);
753
- if (true === opts.literalBrackets) {
754
- state.output += escaped;
755
- prev.value = escaped;
756
- continue;
757
- }
758
- prev.value = `(${capture}${escaped}|${prev.value})`;
759
- state.output += prev.value;
760
- continue;
761
- }
762
- if ('{' === value && true !== opts.nobrace) {
763
- increment('braces');
764
- const open = {
765
- type: 'brace',
766
- value,
767
- output: '(',
768
- outputIndex: state.output.length,
769
- tokensIndex: state.tokens.length
770
- };
771
- braces.push(open);
772
- push(open);
773
- continue;
774
- }
775
- if ('}' === value) {
776
- const brace = braces[braces.length - 1];
777
- if (true === opts.nobrace || !brace) {
778
- push({
779
- type: 'text',
780
- value,
781
- output: value
782
- });
783
- continue;
784
- }
785
- let output = ')';
786
- if (true === brace.dots) {
787
- const arr = tokens.slice();
788
- const range = [];
789
- for(let i = arr.length - 1; i >= 0; i--){
790
- tokens.pop();
791
- if ('brace' === arr[i].type) break;
792
- if ('dots' !== arr[i].type) range.unshift(arr[i].value);
793
- }
794
- output = expandRange(range, opts);
795
- state.backtrack = true;
796
- }
797
- if (true !== brace.comma && true !== brace.dots) {
798
- const out = state.output.slice(0, brace.outputIndex);
799
- const toks = state.tokens.slice(brace.tokensIndex);
800
- brace.value = brace.output = '\\{';
801
- value = output = '\\}';
802
- state.output = out;
803
- for (const t of toks)state.output += t.output || t.value;
804
- }
805
- push({
806
- type: 'brace',
807
- value,
808
- output
809
- });
810
- decrement('braces');
811
- braces.pop();
812
- continue;
813
- }
814
- if ('|' === value) {
815
- if (extglobs.length > 0) extglobs[extglobs.length - 1].conditions++;
816
- push({
817
- type: 'text',
818
- value
819
- });
820
- continue;
821
- }
822
- if (',' === value) {
823
- let output = value;
824
- const brace = braces[braces.length - 1];
825
- if (brace && 'braces' === stack[stack.length - 1]) {
826
- brace.comma = true;
827
- output = '|';
828
- }
829
- push({
830
- type: 'comma',
831
- value,
832
- output
833
- });
834
- continue;
835
- }
836
- if ('/' === value) {
837
- if ('dot' === prev.type && state.index === state.start + 1) {
838
- state.start = state.index + 1;
839
- state.consumed = '';
840
- state.output = '';
841
- tokens.pop();
842
- prev = bos;
843
- continue;
844
- }
845
- push({
846
- type: 'slash',
847
- value,
848
- output: SLASH_LITERAL
849
- });
850
- continue;
851
- }
852
- if ('.' === value) {
853
- if (state.braces > 0 && 'dot' === prev.type) {
854
- if ('.' === prev.value) prev.output = DOT_LITERAL;
855
- const brace = braces[braces.length - 1];
856
- prev.type = 'dots';
857
- prev.output += value;
858
- prev.value += value;
859
- brace.dots = true;
860
- continue;
861
- }
862
- if (state.braces + state.parens === 0 && 'bos' !== prev.type && 'slash' !== prev.type) {
863
- push({
864
- type: 'text',
865
- value,
866
- output: DOT_LITERAL
867
- });
868
- continue;
869
- }
870
- push({
871
- type: 'dot',
872
- value,
873
- output: DOT_LITERAL
874
- });
875
- continue;
876
- }
877
- if ('?' === value) {
878
- const isGroup = prev && '(' === prev.value;
879
- if (!isGroup && true !== opts.noextglob && '(' === peek() && '?' !== peek(2)) {
880
- extglobOpen('qmark', value);
881
- continue;
882
- }
883
- if (prev && 'paren' === prev.type) {
884
- const next = peek();
885
- let output = value;
886
- if ('(' === prev.value && !/[!=<:]/.test(next) || '<' === next && !/<([!=]|\w+>)/.test(remaining())) output = `\\${value}`;
887
- push({
888
- type: 'text',
889
- value,
890
- output
891
- });
892
- continue;
893
- }
894
- if (true !== opts.dot && ('slash' === prev.type || 'bos' === prev.type)) {
895
- push({
896
- type: 'qmark',
897
- value,
898
- output: QMARK_NO_DOT
899
- });
900
- continue;
901
- }
902
- push({
903
- type: 'qmark',
904
- value,
905
- output: QMARK
906
- });
907
- continue;
908
- }
909
- if ('!' === value) {
910
- if (true !== opts.noextglob && '(' === peek()) {
911
- if ('?' !== peek(2) || !/[!=<:]/.test(peek(3))) {
912
- extglobOpen('negate', value);
913
- continue;
914
- }
915
- }
916
- if (true !== opts.nonegate && 0 === state.index) {
917
- negate();
918
- continue;
919
- }
920
- }
921
- if ('+' === value) {
922
- if (true !== opts.noextglob && '(' === peek() && '?' !== peek(2)) {
923
- extglobOpen('plus', value);
924
- continue;
925
- }
926
- if (prev && '(' === prev.value || false === opts.regex) {
927
- push({
928
- type: 'plus',
929
- value,
930
- output: PLUS_LITERAL
931
- });
932
- continue;
933
- }
934
- if (prev && ('bracket' === prev.type || 'paren' === prev.type || 'brace' === prev.type) || state.parens > 0) {
935
- push({
936
- type: 'plus',
937
- value
938
- });
939
- continue;
940
- }
941
- push({
942
- type: 'plus',
943
- value: PLUS_LITERAL
944
- });
945
- continue;
946
- }
947
- if ('@' === value) {
948
- if (true !== opts.noextglob && '(' === peek() && '?' !== peek(2)) {
949
- push({
950
- type: 'at',
951
- extglob: true,
952
- value,
953
- output: ''
954
- });
955
- continue;
956
- }
957
- push({
958
- type: 'text',
959
- value
960
- });
961
- continue;
962
- }
963
- if ('*' !== value) {
964
- if ('$' === value || '^' === value) value = `\\${value}`;
965
- const match = REGEX_NON_SPECIAL_CHARS.exec(remaining());
966
- if (match) {
967
- value += match[0];
968
- state.index += match[0].length;
969
- }
970
- push({
971
- type: 'text',
972
- value
973
- });
974
- continue;
975
- }
976
- if (prev && ('globstar' === prev.type || true === prev.star)) {
977
- prev.type = 'star';
978
- prev.star = true;
979
- prev.value += value;
980
- prev.output = star;
981
- state.backtrack = true;
982
- state.globstar = true;
983
- consume(value);
984
- continue;
985
- }
986
- let rest = remaining();
987
- if (true !== opts.noextglob && /^\([^?]/.test(rest)) {
988
- extglobOpen('star', value);
989
- continue;
990
- }
991
- if ('star' === prev.type) {
992
- if (true === opts.noglobstar) {
993
- consume(value);
994
- continue;
995
- }
996
- const prior = prev.prev;
997
- const before = prior.prev;
998
- const isStart = 'slash' === prior.type || 'bos' === prior.type;
999
- const afterStar = before && ('star' === before.type || 'globstar' === before.type);
1000
- if (true === opts.bash && (!isStart || rest[0] && '/' !== rest[0])) {
1001
- push({
1002
- type: 'star',
1003
- value,
1004
- output: ''
1005
- });
1006
- continue;
1007
- }
1008
- const isBrace = state.braces > 0 && ('comma' === prior.type || 'brace' === prior.type);
1009
- const isExtglob = extglobs.length && ('pipe' === prior.type || 'paren' === prior.type);
1010
- if (!isStart && 'paren' !== prior.type && !isBrace && !isExtglob) {
1011
- push({
1012
- type: 'star',
1013
- value,
1014
- output: ''
1015
- });
1016
- continue;
1017
- }
1018
- while('/**' === rest.slice(0, 3)){
1019
- const after = input[state.index + 4];
1020
- if (after && '/' !== after) break;
1021
- rest = rest.slice(3);
1022
- consume('/**', 3);
1023
- }
1024
- const isEnd = eos() || state.parens > 0 && rest === ')'.repeat(state.parens) && !extglobs.some((extglob)=>'negate' === extglob.type);
1025
- if ('bos' === prior.type && eos()) {
1026
- prev.type = 'globstar';
1027
- prev.value += value;
1028
- prev.output = globstar(opts);
1029
- state.output = prev.output;
1030
- state.globstar = true;
1031
- consume(value);
1032
- continue;
1033
- }
1034
- if ('slash' === prior.type && 'bos' !== prior.prev.type && !afterStar && isEnd) {
1035
- state.output = state.output.slice(0, -(prior.output + prev.output).length);
1036
- prior.output = `(?:${prior.output}`;
1037
- prev.type = 'globstar';
1038
- prev.output = globstar(opts) + (opts.strictSlashes ? ')' : '|$)');
1039
- prev.value += value;
1040
- state.globstar = true;
1041
- state.output += prior.output + prev.output;
1042
- consume(value);
1043
- continue;
1044
- }
1045
- if ('slash' === prior.type && 'bos' !== prior.prev.type && '/' === rest[0]) {
1046
- const end = void 0 !== rest[1] ? '|$' : '';
1047
- state.output = state.output.slice(0, -(prior.output + prev.output).length);
1048
- prior.output = `(?:${prior.output}`;
1049
- prev.type = 'globstar';
1050
- prev.output = `${globstar(opts)}${SLASH_LITERAL}|${SLASH_LITERAL}${end})`;
1051
- prev.value += value;
1052
- state.output += prior.output + prev.output;
1053
- state.globstar = true;
1054
- consume(value + advance());
1055
- push({
1056
- type: 'slash',
1057
- value: '/',
1058
- output: ''
1059
- });
1060
- continue;
1061
- }
1062
- if ('bos' === prior.type && '/' === rest[0]) {
1063
- prev.type = 'globstar';
1064
- prev.value += value;
1065
- prev.output = `(?:^|${SLASH_LITERAL}|${globstar(opts)}${SLASH_LITERAL})`;
1066
- state.output = prev.output;
1067
- state.globstar = true;
1068
- consume(value + advance());
1069
- push({
1070
- type: 'slash',
1071
- value: '/',
1072
- output: ''
1073
- });
1074
- continue;
1075
- }
1076
- state.output = state.output.slice(0, -prev.output.length);
1077
- prev.type = 'globstar';
1078
- prev.output = globstar(opts);
1079
- prev.value += value;
1080
- state.output += prev.output;
1081
- state.globstar = true;
1082
- consume(value);
1083
- continue;
1084
- }
1085
- const token = {
1086
- type: 'star',
1087
- value,
1088
- output: star
1089
- };
1090
- if (true === opts.bash) {
1091
- token.output = '.*?';
1092
- if ('bos' === prev.type || 'slash' === prev.type) token.output = nodot + token.output;
1093
- push(token);
1094
- continue;
1095
- }
1096
- if (prev && ('bracket' === prev.type || 'paren' === prev.type) && true === opts.regex) {
1097
- token.output = value;
1098
- push(token);
1099
- continue;
1100
- }
1101
- if (state.index === state.start || 'slash' === prev.type || 'dot' === prev.type) {
1102
- if ('dot' === prev.type) {
1103
- state.output += NO_DOT_SLASH;
1104
- prev.output += NO_DOT_SLASH;
1105
- } else if (true === opts.dot) {
1106
- state.output += NO_DOTS_SLASH;
1107
- prev.output += NO_DOTS_SLASH;
1108
- } else {
1109
- state.output += nodot;
1110
- prev.output += nodot;
1111
- }
1112
- if ('*' !== peek()) {
1113
- state.output += ONE_CHAR;
1114
- prev.output += ONE_CHAR;
1115
- }
1116
- }
1117
- push(token);
1118
- }
1119
- while(state.brackets > 0){
1120
- if (true === opts.strictBrackets) throw new SyntaxError(syntaxError('closing', ']'));
1121
- state.output = utils.escapeLast(state.output, '[');
1122
- decrement('brackets');
1123
- }
1124
- while(state.parens > 0){
1125
- if (true === opts.strictBrackets) throw new SyntaxError(syntaxError('closing', ')'));
1126
- state.output = utils.escapeLast(state.output, '(');
1127
- decrement('parens');
1128
- }
1129
- while(state.braces > 0){
1130
- if (true === opts.strictBrackets) throw new SyntaxError(syntaxError('closing', '}'));
1131
- state.output = utils.escapeLast(state.output, '{');
1132
- decrement('braces');
1133
- }
1134
- if (true !== opts.strictSlashes && ('star' === prev.type || 'bracket' === prev.type)) push({
1135
- type: 'maybe_slash',
1136
- value: '',
1137
- output: `${SLASH_LITERAL}?`
1138
- });
1139
- if (true === state.backtrack) {
1140
- state.output = '';
1141
- for (const token of state.tokens){
1142
- state.output += null != token.output ? token.output : token.value;
1143
- if (token.suffix) state.output += token.suffix;
1144
- }
1145
- }
1146
- return state;
1147
- };
1148
- parse.fastpaths = (input, options)=>{
1149
- const opts = {
1150
- ...options
1151
- };
1152
- const max = 'number' == typeof opts.maxLength ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
1153
- const len = input.length;
1154
- if (len > max) throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
1155
- input = REPLACEMENTS[input] || input;
1156
- const { DOT_LITERAL, SLASH_LITERAL, ONE_CHAR, DOTS_SLASH, NO_DOT, NO_DOTS, NO_DOTS_SLASH, STAR, START_ANCHOR } = constants.globChars(opts.windows);
1157
- const nodot = opts.dot ? NO_DOTS : NO_DOT;
1158
- const slashDot = opts.dot ? NO_DOTS_SLASH : NO_DOT;
1159
- const capture = opts.capture ? '' : '?:';
1160
- const state = {
1161
- negated: false,
1162
- prefix: ''
1163
- };
1164
- let star = true === opts.bash ? '.*?' : STAR;
1165
- if (opts.capture) star = `(${star})`;
1166
- const globstar = (opts)=>{
1167
- if (true === opts.noglobstar) return star;
1168
- return `(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
1169
- };
1170
- const create = (str)=>{
1171
- switch(str){
1172
- case '*':
1173
- return `${nodot}${ONE_CHAR}${star}`;
1174
- case '.*':
1175
- return `${DOT_LITERAL}${ONE_CHAR}${star}`;
1176
- case '*.*':
1177
- return `${nodot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
1178
- case '*/*':
1179
- return `${nodot}${star}${SLASH_LITERAL}${ONE_CHAR}${slashDot}${star}`;
1180
- case '**':
1181
- return nodot + globstar(opts);
1182
- case '**/*':
1183
- return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${ONE_CHAR}${star}`;
1184
- case '**/*.*':
1185
- return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
1186
- case '**/.*':
1187
- return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${DOT_LITERAL}${ONE_CHAR}${star}`;
1188
- default:
1189
- {
1190
- const match = /^(.*?)\.(\w+)$/.exec(str);
1191
- if (!match) return;
1192
- const source = create(match[1]);
1193
- if (!source) return;
1194
- return source + DOT_LITERAL + match[2];
1195
- }
1196
- }
1197
- };
1198
- const output = utils.removePrefix(input, state);
1199
- let source = create(output);
1200
- if (source && true !== opts.strictSlashes) source += `${SLASH_LITERAL}?`;
1201
- return source;
1202
- };
1203
- module.exports = parse;
1204
- },
1205
- "../../node_modules/.pnpm/picomatch@4.0.7/node_modules/picomatch/lib/picomatch.js" (module) {
1206
- const scan = rspackRequire("../../node_modules/.pnpm/picomatch@4.0.7/node_modules/picomatch/lib/scan.js");
1207
- const parse = rspackRequire("../../node_modules/.pnpm/picomatch@4.0.7/node_modules/picomatch/lib/parse.js");
1208
- const utils = rspackRequire("../../node_modules/.pnpm/picomatch@4.0.7/node_modules/picomatch/lib/utils.js");
1209
- const constants = rspackRequire("../../node_modules/.pnpm/picomatch@4.0.7/node_modules/picomatch/lib/constants.js");
1210
- const isObject = (val)=>val && 'object' == typeof val && !Array.isArray(val);
1211
- const picomatch = (glob, options, returnState = false)=>{
1212
- if (Array.isArray(glob)) {
1213
- const fns = glob.map((input)=>picomatch(input, options, returnState));
1214
- const arrayMatcher = (str)=>{
1215
- for (const isMatch of fns){
1216
- const state = isMatch(str);
1217
- if (state) return state;
1218
- }
1219
- return false;
1220
- };
1221
- return arrayMatcher;
1222
- }
1223
- const isState = isObject(glob) && glob.tokens && glob.input;
1224
- if ('' === glob || 'string' != typeof glob && !isState) throw new TypeError('Expected pattern to be a non-empty string');
1225
- const opts = options || {};
1226
- const posix = opts.windows;
1227
- const regex = isState ? picomatch.compileRe(glob, options) : picomatch.makeRe(glob, options, false, true);
1228
- const state = regex.state;
1229
- delete regex.state;
1230
- let isIgnored = ()=>false;
1231
- if (opts.ignore) {
1232
- const ignoreOpts = {
1233
- ...options,
1234
- ignore: null,
1235
- onMatch: null,
1236
- onResult: null
1237
- };
1238
- isIgnored = picomatch(opts.ignore, ignoreOpts, returnState);
1239
- }
1240
- const matcher = (input, returnObject = false)=>{
1241
- const { isMatch, match, output } = picomatch.test(input, regex, options, {
1242
- glob,
1243
- posix
1244
- });
1245
- const result = {
1246
- glob,
1247
- state,
1248
- regex,
1249
- posix,
1250
- input,
1251
- output,
1252
- match,
1253
- isMatch
1254
- };
1255
- if ('function' == typeof opts.onResult) opts.onResult(result);
1256
- if (false === isMatch) {
1257
- result.isMatch = false;
1258
- return returnObject ? result : false;
1259
- }
1260
- if (isIgnored(input)) {
1261
- if ('function' == typeof opts.onIgnore) opts.onIgnore(result);
1262
- result.isMatch = false;
1263
- return returnObject ? result : false;
1264
- }
1265
- if ('function' == typeof opts.onMatch) opts.onMatch(result);
1266
- return returnObject ? result : true;
1267
- };
1268
- if (returnState) matcher.state = state;
1269
- return matcher;
1270
- };
1271
- picomatch.test = (input, regex, options, { glob, posix } = {})=>{
1272
- if ('string' != typeof input) throw new TypeError('Expected input to be a string');
1273
- if ('' === input) return {
1274
- isMatch: false,
1275
- output: ''
1276
- };
1277
- const opts = options || {};
1278
- const format = opts.format || (posix ? utils.toPosixSlashes : null);
1279
- let match = input === glob;
1280
- let output = match && format ? format(input) : input;
1281
- if (false === match) {
1282
- output = format ? format(input) : input;
1283
- match = output === glob;
1284
- }
1285
- if (false === match || true === opts.capture) match = true === opts.matchBase || true === opts.basename ? picomatch.matchBase(input, regex, options, posix) : regex.exec(output);
1286
- return {
1287
- isMatch: Boolean(match),
1288
- match,
1289
- output
1290
- };
1291
- };
1292
- picomatch.matchBase = (input, glob, options, posix = options && options.windows)=>{
1293
- const regex = glob instanceof RegExp ? glob : picomatch.makeRe(glob, options);
1294
- return regex.test(utils.basename(input, {
1295
- windows: posix
1296
- }));
1297
- };
1298
- picomatch.isMatch = (str, patterns, options)=>picomatch(patterns, options)(str);
1299
- picomatch.parse = (pattern, options)=>{
1300
- if (Array.isArray(pattern)) return pattern.map((p)=>picomatch.parse(p, options));
1301
- return parse(pattern, {
1302
- ...options,
1303
- fastpaths: false
1304
- });
1305
- };
1306
- picomatch.scan = (input, options)=>scan(input, options);
1307
- picomatch.compileRe = (state, options, returnOutput = false, returnState = false)=>{
1308
- if (true === returnOutput) return state.output;
1309
- const opts = options || {};
1310
- const prepend = opts.contains ? '' : '^';
1311
- const append = opts.contains ? '' : '$';
1312
- let source = `${prepend}(?:${state.output})${append}`;
1313
- if (state && true === state.negated) source = `^(?!${source}).*$`;
1314
- const regex = picomatch.toRegex(source, options);
1315
- if (true === returnState) regex.state = state;
1316
- return regex;
1317
- };
1318
- picomatch.makeRe = (input, options = {}, returnOutput = false, returnState = false)=>{
1319
- if (!input || 'string' != typeof input) throw new TypeError('Expected a non-empty string');
1320
- let parsed = {
1321
- negated: false,
1322
- fastpaths: true
1323
- };
1324
- if (false !== options.fastpaths && ('.' === input[0] || '*' === input[0])) parsed.output = parse.fastpaths(input, options);
1325
- if (!parsed.output) parsed = parse(input, options);
1326
- return picomatch.compileRe(parsed, options, returnOutput, returnState);
1327
- };
1328
- picomatch.toRegex = (source, options)=>{
1329
- try {
1330
- const opts = options || {};
1331
- return new RegExp(source, opts.flags || (opts.nocase ? 'i' : ''));
1332
- } catch (err) {
1333
- if (options && true === options.debug) throw err;
1334
- return /$^/;
1335
- }
1336
- };
1337
- picomatch.constants = constants;
1338
- module.exports = picomatch;
1339
- },
1340
- "../../node_modules/.pnpm/picomatch@4.0.7/node_modules/picomatch/lib/scan.js" (module) {
1341
- const utils = rspackRequire("../../node_modules/.pnpm/picomatch@4.0.7/node_modules/picomatch/lib/utils.js");
1342
- const { CHAR_ASTERISK, CHAR_AT, CHAR_BACKWARD_SLASH, CHAR_COMMA, CHAR_DOT, CHAR_EXCLAMATION_MARK, CHAR_FORWARD_SLASH, CHAR_LEFT_CURLY_BRACE, CHAR_LEFT_PARENTHESES, CHAR_LEFT_SQUARE_BRACKET, CHAR_PLUS, CHAR_QUESTION_MARK, CHAR_RIGHT_CURLY_BRACE, CHAR_RIGHT_PARENTHESES, CHAR_RIGHT_SQUARE_BRACKET } = rspackRequire("../../node_modules/.pnpm/picomatch@4.0.7/node_modules/picomatch/lib/constants.js");
1343
- const isPathSeparator = (code)=>code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
1344
- const depth = (token)=>{
1345
- if (true !== token.isPrefix) token.depth = token.isGlobstar ? 1 / 0 : 1;
1346
- };
1347
- const scan = (input, options)=>{
1348
- const opts = options || {};
1349
- const length = input.length - 1;
1350
- const scanToEnd = true === opts.parts || true === opts.tokens || true === opts.scanToEnd;
1351
- const slashes = [];
1352
- const tokens = [];
1353
- const parts = [];
1354
- let str = input;
1355
- let index = -1;
1356
- let start = 0;
1357
- let lastIndex = 0;
1358
- let isBrace = false;
1359
- let isBracket = false;
1360
- let isGlob = false;
1361
- let isExtglob = false;
1362
- let isGlobstar = false;
1363
- let braceEscaped = false;
1364
- let backslashes = false;
1365
- let negated = false;
1366
- let negatedExtglob = false;
1367
- let finished = false;
1368
- let braces = 0;
1369
- let prev;
1370
- let code;
1371
- let token = {
1372
- value: '',
1373
- depth: 0,
1374
- isGlob: false
1375
- };
1376
- const eos = ()=>index >= length;
1377
- const peek = ()=>str.charCodeAt(index + 1);
1378
- const advance = ()=>{
1379
- prev = code;
1380
- return str.charCodeAt(++index);
1381
- };
1382
- while(index < length){
1383
- code = advance();
1384
- let next;
1385
- if (code === CHAR_BACKWARD_SLASH) {
1386
- backslashes = token.backslashes = true;
1387
- code = advance();
1388
- if (code === CHAR_LEFT_CURLY_BRACE) braceEscaped = true;
1389
- continue;
1390
- }
1391
- if (true === braceEscaped || code === CHAR_LEFT_CURLY_BRACE) {
1392
- braces++;
1393
- while(true !== eos() && (code = advance())){
1394
- if (code === CHAR_BACKWARD_SLASH) {
1395
- backslashes = token.backslashes = true;
1396
- advance();
1397
- continue;
1398
- }
1399
- if (code === CHAR_LEFT_CURLY_BRACE) {
1400
- braces++;
1401
- continue;
1402
- }
1403
- if (true !== braceEscaped && code === CHAR_DOT && (code = advance()) === CHAR_DOT) {
1404
- isBrace = token.isBrace = true;
1405
- isGlob = token.isGlob = true;
1406
- finished = true;
1407
- if (true === scanToEnd) continue;
1408
- break;
1409
- }
1410
- if (true !== braceEscaped && code === CHAR_COMMA) {
1411
- isBrace = token.isBrace = true;
1412
- isGlob = token.isGlob = true;
1413
- finished = true;
1414
- if (true === scanToEnd) continue;
1415
- break;
1416
- }
1417
- if (code === CHAR_RIGHT_CURLY_BRACE) {
1418
- braces--;
1419
- if (0 === braces) {
1420
- braceEscaped = false;
1421
- isBrace = token.isBrace = true;
1422
- finished = true;
1423
- break;
1424
- }
1425
- }
1426
- }
1427
- if (true === scanToEnd) continue;
1428
- break;
1429
- }
1430
- if (code === CHAR_FORWARD_SLASH) {
1431
- slashes.push(index);
1432
- tokens.push(token);
1433
- token = {
1434
- value: '',
1435
- depth: 0,
1436
- isGlob: false
1437
- };
1438
- if (true === finished) continue;
1439
- if (prev === CHAR_DOT && index === start + 1) {
1440
- start += 2;
1441
- continue;
1442
- }
1443
- lastIndex = index + 1;
1444
- continue;
1445
- }
1446
- if (true !== opts.noext) {
1447
- const isExtglobChar = code === CHAR_PLUS || code === CHAR_AT || code === CHAR_ASTERISK || code === CHAR_QUESTION_MARK || code === CHAR_EXCLAMATION_MARK;
1448
- if (true === isExtglobChar && peek() === CHAR_LEFT_PARENTHESES) {
1449
- isGlob = token.isGlob = true;
1450
- isExtglob = token.isExtglob = true;
1451
- finished = true;
1452
- if (code === CHAR_EXCLAMATION_MARK && index === start) negatedExtglob = true;
1453
- if (true === scanToEnd) {
1454
- let parens = 0;
1455
- while(true !== eos() && (code = advance())){
1456
- if (code === CHAR_BACKWARD_SLASH) {
1457
- backslashes = token.backslashes = true;
1458
- advance();
1459
- continue;
1460
- }
1461
- if (code === CHAR_LEFT_PARENTHESES) {
1462
- parens++;
1463
- continue;
1464
- }
1465
- if (code === CHAR_RIGHT_PARENTHESES && 0 === --parens) {
1466
- finished = true;
1467
- break;
1468
- }
1469
- }
1470
- continue;
1471
- }
1472
- break;
1473
- }
1474
- }
1475
- if (code === CHAR_ASTERISK) {
1476
- if (prev === CHAR_ASTERISK) isGlobstar = token.isGlobstar = true;
1477
- isGlob = token.isGlob = true;
1478
- finished = true;
1479
- if (true === scanToEnd) continue;
1480
- break;
1481
- }
1482
- if (code === CHAR_QUESTION_MARK) {
1483
- isGlob = token.isGlob = true;
1484
- finished = true;
1485
- if (true === scanToEnd) continue;
1486
- break;
1487
- }
1488
- if (code === CHAR_LEFT_SQUARE_BRACKET) {
1489
- while(true !== eos() && (next = advance())){
1490
- if (next === CHAR_BACKWARD_SLASH) {
1491
- backslashes = token.backslashes = true;
1492
- advance();
1493
- continue;
1494
- }
1495
- if (next === CHAR_RIGHT_SQUARE_BRACKET) {
1496
- isBracket = token.isBracket = true;
1497
- isGlob = token.isGlob = true;
1498
- finished = true;
1499
- break;
1500
- }
1501
- }
1502
- if (true === scanToEnd) continue;
1503
- break;
1504
- }
1505
- if (true !== opts.nonegate && code === CHAR_EXCLAMATION_MARK && index === start) {
1506
- negated = token.negated = true;
1507
- start++;
1508
- continue;
1509
- }
1510
- if (true !== opts.noparen && code === CHAR_LEFT_PARENTHESES) {
1511
- isGlob = token.isGlob = true;
1512
- if (true === scanToEnd) {
1513
- let parens = 1;
1514
- while(true !== eos() && (code = advance())){
1515
- if (code === CHAR_BACKWARD_SLASH) {
1516
- backslashes = token.backslashes = true;
1517
- advance();
1518
- continue;
1519
- }
1520
- if (code === CHAR_LEFT_PARENTHESES) {
1521
- parens++;
1522
- continue;
1523
- }
1524
- if (code === CHAR_RIGHT_PARENTHESES && 0 === --parens) {
1525
- finished = true;
1526
- break;
1527
- }
1528
- }
1529
- continue;
1530
- }
1531
- break;
1532
- }
1533
- if (true === isGlob) {
1534
- finished = true;
1535
- if (true === scanToEnd) continue;
1536
- break;
1537
- }
1538
- }
1539
- if (true === opts.noext) {
1540
- isExtglob = false;
1541
- isGlob = false;
1542
- }
1543
- let base = str;
1544
- let prefix = '';
1545
- let glob = '';
1546
- if (start > 0) {
1547
- prefix = str.slice(0, start);
1548
- str = str.slice(start);
1549
- lastIndex -= start;
1550
- }
1551
- if (base && true === isGlob && lastIndex > 0) {
1552
- base = str.slice(0, lastIndex);
1553
- glob = str.slice(lastIndex);
1554
- } else if (true === isGlob) {
1555
- base = '';
1556
- glob = str;
1557
- } else base = str;
1558
- if (base && '' !== base && '/' !== base && base !== str) {
1559
- if (isPathSeparator(base.charCodeAt(base.length - 1))) base = base.slice(0, -1);
1560
- }
1561
- if (true === opts.unescape) {
1562
- if (glob) glob = utils.removeBackslashes(glob);
1563
- if (base && true === backslashes) base = utils.removeBackslashes(base);
1564
- }
1565
- const state = {
1566
- prefix,
1567
- input,
1568
- start,
1569
- base,
1570
- glob,
1571
- isBrace,
1572
- isBracket,
1573
- isGlob,
1574
- isExtglob,
1575
- isGlobstar,
1576
- negated,
1577
- negatedExtglob
1578
- };
1579
- if (true === opts.tokens) {
1580
- state.maxDepth = 0;
1581
- if (!isPathSeparator(code)) tokens.push(token);
1582
- state.tokens = tokens;
1583
- }
1584
- if (true === opts.parts || true === opts.tokens) {
1585
- let prevIndex;
1586
- for(let idx = 0; idx < slashes.length; idx++){
1587
- const n = void 0 !== prevIndex ? prevIndex + 1 : start;
1588
- const i = slashes[idx];
1589
- const value = input.slice(n, i);
1590
- if (opts.tokens) {
1591
- if (0 === idx && 0 !== start) {
1592
- tokens[idx].isPrefix = true;
1593
- tokens[idx].value = prefix;
1594
- } else tokens[idx].value = value;
1595
- depth(tokens[idx]);
1596
- state.maxDepth += tokens[idx].depth;
1597
- }
1598
- if (i >= start) {
1599
- parts.push(value);
1600
- prevIndex = i;
1601
- }
1602
- }
1603
- const n = void 0 !== prevIndex ? prevIndex + 1 : start;
1604
- const value = input.slice(n);
1605
- parts.push(value);
1606
- if (opts.tokens && prevIndex && prevIndex + 1 < input.length) {
1607
- tokens[tokens.length - 1].value = value;
1608
- depth(tokens[tokens.length - 1]);
1609
- state.maxDepth += tokens[tokens.length - 1].depth;
1610
- }
1611
- state.slashes = slashes;
1612
- state.parts = parts;
1613
- }
1614
- return state;
1615
- };
1616
- module.exports = scan;
1617
- },
1618
- "../../node_modules/.pnpm/picomatch@4.0.7/node_modules/picomatch/lib/utils.js" (__unused_rspack_module, exports) {
1619
- const { REGEX_BACKSLASH, REGEX_REMOVE_BACKSLASH, REGEX_SPECIAL_CHARS, REGEX_SPECIAL_CHARS_GLOBAL } = rspackRequire("../../node_modules/.pnpm/picomatch@4.0.7/node_modules/picomatch/lib/constants.js");
1620
- exports.isObject = (val)=>null !== val && 'object' == typeof val && !Array.isArray(val);
1621
- exports.hasRegexChars = (str)=>REGEX_SPECIAL_CHARS.test(str);
1622
- exports.isRegexChar = (str)=>1 === str.length && exports.hasRegexChars(str);
1623
- exports.escapeRegex = (str)=>str.replace(REGEX_SPECIAL_CHARS_GLOBAL, '\\$1');
1624
- exports.toPosixSlashes = (str)=>str.replace(REGEX_BACKSLASH, '/');
1625
- exports.isWindows = ()=>{
1626
- if ("u" > typeof navigator && navigator.platform) {
1627
- const platform = navigator.platform.toLowerCase();
1628
- return 'win32' === platform || 'windows' === platform;
1629
- }
1630
- if ("u" > typeof process && process.platform) return 'win32' === process.platform;
1631
- return false;
1632
- };
1633
- exports.removeBackslashes = (str)=>str.replace(REGEX_REMOVE_BACKSLASH, (match)=>'\\' === match ? '' : match);
1634
- exports.escapeLast = (input, char, lastIdx)=>{
1635
- const idx = input.lastIndexOf(char, lastIdx);
1636
- if (-1 === idx) return input;
1637
- if ('\\' === input[idx - 1]) return exports.escapeLast(input, char, idx - 1);
1638
- return `${input.slice(0, idx)}\\${input.slice(idx)}`;
1639
- };
1640
- exports.removePrefix = (input, state = {})=>{
1641
- let output = input;
1642
- if (output.startsWith('./')) {
1643
- output = output.slice(2);
1644
- state.prefix = './';
1645
- }
1646
- return output;
1647
- };
1648
- exports.wrapOutput = (input, state = {}, options = {})=>{
1649
- const prepend = options.contains ? '' : '^';
1650
- const append = options.contains ? '' : '$';
1651
- let output = `${prepend}(?:${input})${append}`;
1652
- if (true === state.negated) output = `(?:^(?!${output}).*$)`;
1653
- return output;
1654
- };
1655
- exports.basename = (path, { windows } = {})=>{
1656
- const segs = path.split(windows ? /[\\/]/ : '/');
1657
- const last = segs[segs.length - 1];
1658
- if ('' === last) return segs[segs.length - 2];
1659
- return last;
1660
- };
1661
- }
1662
- });
1663
- function toArr(any) {
1664
- return null == any ? [] : Array.isArray(any) ? any : [
1665
- any
1666
- ];
1667
- }
1668
- function toVal(out, key, val, opts) {
1669
- var x, old = out[key], nxt = ~opts.string.indexOf(key) ? null == val || true === val ? "" : String(val) : "boolean" == typeof val ? val : ~opts.boolean.indexOf(key) ? "false" === val ? false : "true" === val || (out._.push((x = +val, 0 * x === 0) ? x : val), !!val) : (x = +val, 0 * x === 0) ? x : val;
1670
- out[key] = null == old ? nxt : Array.isArray(old) ? old.concat(nxt) : [
1671
- old,
1672
- nxt
1673
- ];
1674
- }
1675
- function lib_default(args, opts) {
1676
- args = args || [];
1677
- opts = opts || {};
1678
- var k, arr, arg, name, val, out = {
1679
- _: []
1680
- };
1681
- var i = 0, j = 0, idx = 0, len = args.length;
1682
- const alibi = void 0 !== opts.alias;
1683
- const strict = void 0 !== opts.unknown;
1684
- const defaults = void 0 !== opts.default;
1685
- opts.alias = opts.alias || {};
1686
- opts.string = toArr(opts.string);
1687
- opts.boolean = toArr(opts.boolean);
1688
- if (alibi) for(k in opts.alias){
1689
- arr = opts.alias[k] = toArr(opts.alias[k]);
1690
- for(i = 0; i < arr.length; i++)(opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
1691
- }
1692
- for(i = opts.boolean.length; i-- > 0;){
1693
- arr = opts.alias[opts.boolean[i]] || [];
1694
- for(j = arr.length; j-- > 0;)opts.boolean.push(arr[j]);
1695
- }
1696
- for(i = opts.string.length; i-- > 0;){
1697
- arr = opts.alias[opts.string[i]] || [];
1698
- for(j = arr.length; j-- > 0;)opts.string.push(arr[j]);
1699
- }
1700
- if (defaults) for(k in opts.default){
1701
- name = typeof opts.default[k];
1702
- arr = opts.alias[k] = opts.alias[k] || [];
1703
- if (void 0 !== opts[name]) {
1704
- opts[name].push(k);
1705
- for(i = 0; i < arr.length; i++)opts[name].push(arr[i]);
1706
- }
1707
- }
1708
- const keys = strict ? Object.keys(opts.alias) : [];
1709
- for(i = 0; i < len; i++){
1710
- arg = args[i];
1711
- if ("--" === arg) {
1712
- out._ = out._.concat(args.slice(++i));
1713
- break;
1714
- }
1715
- for(j = 0; j < arg.length && 45 === arg.charCodeAt(j); j++);
1716
- if (0 === j) out._.push(arg);
1717
- else if ("no-" === arg.substring(j, j + 3)) {
1718
- name = arg.substring(j + 3);
1719
- if (strict && !~keys.indexOf(name)) return opts.unknown(arg);
1720
- out[name] = false;
1721
- } else {
1722
- for(idx = j + 1; idx < arg.length && 61 !== arg.charCodeAt(idx); idx++);
1723
- name = arg.substring(j, idx);
1724
- val = arg.substring(++idx) || i + 1 === len || 45 === ("" + args[i + 1]).charCodeAt(0) || args[++i];
1725
- arr = 2 === j ? [
1726
- name
1727
- ] : name;
1728
- for(idx = 0; idx < arr.length; idx++){
1729
- name = arr[idx];
1730
- if (strict && !~keys.indexOf(name)) return opts.unknown("-".repeat(j) + name);
1731
- toVal(out, name, idx + 1 < arr.length || val, opts);
1732
- }
1733
- }
1734
- }
1735
- if (defaults) {
1736
- for(k in opts.default)if (void 0 === out[k]) out[k] = opts.default[k];
1737
- }
1738
- if (alibi) for(k in out){
1739
- arr = opts.alias[k] || [];
1740
- while(arr.length > 0)out[arr.shift()] = out[k];
1741
- }
1742
- return out;
1743
- }
1744
- function removeBrackets(v) {
1745
- return v.replace(/[<[].+/, "").trim();
1746
- }
1747
- function findAllBrackets(v) {
1748
- const ANGLED_BRACKET_RE_GLOBAL = /<([^>]+)>/g;
1749
- const SQUARE_BRACKET_RE_GLOBAL = /\[([^\]]+)\]/g;
1750
- const res = [];
1751
- const parse = (match)=>{
1752
- let variadic = false;
1753
- let value = match[1];
1754
- if (value.startsWith("...")) {
1755
- value = value.slice(3);
1756
- variadic = true;
1757
- }
1758
- return {
1759
- required: match[0].startsWith("<"),
1760
- value,
1761
- variadic
1762
- };
1763
- };
1764
- let angledMatch;
1765
- while(angledMatch = ANGLED_BRACKET_RE_GLOBAL.exec(v))res.push(parse(angledMatch));
1766
- let squareMatch;
1767
- while(squareMatch = SQUARE_BRACKET_RE_GLOBAL.exec(v))res.push(parse(squareMatch));
1768
- return res;
1769
- }
1770
- function getMriOptions(options) {
1771
- const result = {
1772
- alias: Object.create(null),
1773
- boolean: []
1774
- };
1775
- for (const [index, option] of options.entries()){
1776
- if (option.names.length > 1) result.alias[option.names[0]] = option.names.slice(1);
1777
- if (option.isBoolean) if (option.negated) {
1778
- if (!options.some((o, i)=>i !== index && o.names.some((name)=>option.names.includes(name)) && "boolean" == typeof o.required)) result.boolean.push(option.names[0]);
1779
- } else result.boolean.push(option.names[0]);
1780
- }
1781
- return result;
1782
- }
1783
- function findLongest(arr) {
1784
- return arr.sort((a, b)=>b.length - a.length)[0];
1785
- }
1786
- function padRight(str, length) {
1787
- return str.length >= length ? str : `${str}${" ".repeat(length - str.length)}`;
1788
- }
1789
- function camelcase(input) {
1790
- return input.replaceAll(/([a-z])-([a-z])/g, (_, p1, p2)=>p1 + p2.toUpperCase());
1791
- }
1792
- const UNSAFE_KEYS = /* @__PURE__ */ new Set([
1793
- "__proto__",
1794
- "constructor",
1795
- "prototype"
1796
- ]);
1797
- function setDotProp(obj, keys, val) {
1798
- if (keys.some((key)=>UNSAFE_KEYS.has(key))) return;
1799
- let current = obj;
1800
- for(let i = 0; i < keys.length; i++){
1801
- const key = keys[i];
1802
- if (i === keys.length - 1) {
1803
- current[key] = val;
1804
- return;
1805
- }
1806
- if (null == current[key]) {
1807
- const nextKeyIsArrayIndex = +keys[i + 1] > -1;
1808
- current[key] = nextKeyIsArrayIndex ? [] : {};
1809
- }
1810
- current = current[key];
1811
- }
1812
- }
1813
- function setByType(obj, transforms) {
1814
- for (const [key, transform] of Object.entries(transforms))if (transform.shouldTransform && key in obj) {
1815
- obj[key] = [
1816
- obj[key]
1817
- ].flat();
1818
- if ("function" == typeof transform.transformFunction) obj[key] = obj[key].map(transform.transformFunction);
1819
- }
1820
- }
1821
- function getFileName(input) {
1822
- const m = /([^\\/]+)$/.exec(input);
1823
- return m ? m[1] : "";
1824
- }
1825
- function camelcaseOptionName(name) {
1826
- return name.split(".").map((v, i)=>0 === i ? camelcase(v) : v).join(".");
1827
- }
1828
- var CACError = class extends Error {
1829
- constructor(message){
1830
- super(message);
1831
- this.name = "CACError";
1832
- if ("function" != typeof Error.captureStackTrace) this.stack = new Error(message).stack;
1833
- }
1834
- };
1835
- var Option = class {
1836
- rawName;
1837
- description;
1838
- name;
1839
- names;
1840
- isBoolean;
1841
- required;
1842
- config;
1843
- negated;
1844
- constructor(rawName, description, config){
1845
- this.rawName = rawName;
1846
- this.description = description;
1847
- this.config = Object.assign({}, config);
1848
- rawName = rawName.replaceAll(".*", "");
1849
- this.negated = false;
1850
- this.names = removeBrackets(rawName).split(",").map((v)=>{
1851
- let name = v.trim().replace(/^-{1,2}/, "");
1852
- if (name.startsWith("no-")) {
1853
- this.negated = true;
1854
- name = name.replace(/^no-/, "");
1855
- }
1856
- return camelcaseOptionName(name);
1857
- }).sort((a, b)=>a.length - b.length);
1858
- this.name = this.names.at(-1);
1859
- if (this.negated && null == this.config.default) this.config.default = true;
1860
- if (rawName.includes("<")) this.required = true;
1861
- else if (rawName.includes("[")) this.required = false;
1862
- else this.isBoolean = true;
1863
- }
1864
- };
1865
- let runtimeInfo;
1866
- if ("u" > typeof process) {
1867
- let runtimeName;
1868
- runtimeName = "u" > typeof Deno && "string" == typeof Deno.version?.deno ? "deno" : "u" > typeof Bun && "string" == typeof Bun.version ? "bun" : "node";
1869
- runtimeInfo = `${process.platform}-${process.arch} ${runtimeName}-${process.version}`;
1870
- } else runtimeInfo = "u" < typeof navigator ? "unknown" : `${navigator.platform} ${navigator.userAgent}`;
1871
- function getRuntimeProcessArgs() {
1872
- return "u" < typeof process ? void 0 : process.argv;
1873
- }
1874
- var Command = class {
1875
- rawName;
1876
- description;
1877
- config;
1878
- cli;
1879
- options;
1880
- aliasNames;
1881
- name;
1882
- args;
1883
- commandAction;
1884
- usageText;
1885
- versionNumber;
1886
- examples;
1887
- helpCallback;
1888
- globalCommand;
1889
- constructor(rawName, description, config = {}, cli){
1890
- this.rawName = rawName;
1891
- this.description = description;
1892
- this.config = config;
1893
- this.cli = cli;
1894
- this.options = [];
1895
- this.aliasNames = [];
1896
- this.name = removeBrackets(rawName);
1897
- this.args = findAllBrackets(rawName);
1898
- this.examples = [];
1899
- }
1900
- usage(text) {
1901
- this.usageText = text;
1902
- return this;
1903
- }
1904
- allowUnknownOptions() {
1905
- this.config.allowUnknownOptions = true;
1906
- return this;
1907
- }
1908
- ignoreOptionDefaultValue() {
1909
- this.config.ignoreOptionDefaultValue = true;
1910
- return this;
1911
- }
1912
- version(version, customFlags = "-v, --version") {
1913
- this.versionNumber = version;
1914
- this.option(customFlags, "Display version number");
1915
- return this;
1916
- }
1917
- example(example) {
1918
- this.examples.push(example);
1919
- return this;
1920
- }
1921
- option(rawName, description, config) {
1922
- const option = new Option(rawName, description, config);
1923
- this.options.push(option);
1924
- return this;
1925
- }
1926
- alias(name) {
1927
- this.aliasNames.push(name);
1928
- return this;
1929
- }
1930
- action(callback) {
1931
- this.commandAction = callback;
1932
- return this;
1933
- }
1934
- isMatched(name) {
1935
- return this.name === name || this.aliasNames.includes(name);
1936
- }
1937
- get isDefaultCommand() {
1938
- return "" === this.name || this.aliasNames.includes("!");
1939
- }
1940
- get isGlobalCommand() {
1941
- return this instanceof GlobalCommand;
1942
- }
1943
- hasOption(name) {
1944
- name = name.split(".", 1)[0];
1945
- return this.options.find((option)=>option.names.includes(name));
1946
- }
1947
- outputHelp() {
1948
- const { name, commands } = this.cli;
1949
- const { versionNumber, options: globalOptions, helpCallback } = this.cli.globalCommand;
1950
- let sections = [
1951
- {
1952
- body: `${name}${versionNumber ? `/${versionNumber}` : ""}`
1953
- }
1954
- ];
1955
- sections.push({
1956
- title: "Usage",
1957
- body: ` $ ${name} ${this.usageText || this.rawName}`
1958
- });
1959
- if ((this.isGlobalCommand || this.isDefaultCommand) && commands.length > 0) {
1960
- const longestCommandName = findLongest(commands.map((command)=>command.rawName));
1961
- sections.push({
1962
- title: "Commands",
1963
- body: commands.map((command)=>` ${padRight(command.rawName, longestCommandName.length)} ${command.description}`).join("\n")
1964
- }, {
1965
- title: "For more info, run any command with the `--help` flag",
1966
- body: commands.map((command)=>` $ ${name}${"" === command.name ? "" : ` ${command.name}`} --help`).join("\n")
1967
- });
1968
- }
1969
- let options = this.isGlobalCommand ? globalOptions : [
1970
- ...this.options,
1971
- ...globalOptions || []
1972
- ];
1973
- if (!this.isGlobalCommand && !this.isDefaultCommand) options = options.filter((option)=>"version" !== option.name);
1974
- if (options.length > 0) {
1975
- const longestOptionName = findLongest(options.map((option)=>option.rawName));
1976
- sections.push({
1977
- title: "Options",
1978
- body: options.map((option)=>` ${padRight(option.rawName, longestOptionName.length)} ${option.description} ${void 0 === option.config.default ? "" : `(default: ${option.config.default})`}`).join("\n")
1979
- });
1980
- }
1981
- if (this.examples.length > 0) sections.push({
1982
- title: "Examples",
1983
- body: this.examples.map((example)=>{
1984
- if ("function" == typeof example) return example(name);
1985
- return example;
1986
- }).join("\n")
1987
- });
1988
- if (helpCallback) sections = helpCallback(sections) || sections;
1989
- console.info(sections.map((section)=>section.title ? `${section.title}:\n${section.body}` : section.body).join("\n\n"));
1990
- }
1991
- outputVersion() {
1992
- const { name } = this.cli;
1993
- const { versionNumber } = this.cli.globalCommand;
1994
- if (versionNumber) console.info(`${name}/${versionNumber} ${runtimeInfo}`);
1995
- }
1996
- checkRequiredArgs() {
1997
- const minimalArgsCount = this.args.filter((arg)=>arg.required).length;
1998
- if (this.cli.args.length < minimalArgsCount) throw new CACError(`missing required args for command \`${this.rawName}\``);
1999
- }
2000
- checkUnknownOptions() {
2001
- const { options, globalCommand } = this.cli;
2002
- if (!this.config.allowUnknownOptions) {
2003
- for (const name of Object.keys(options))if ("--" !== name && !this.hasOption(name) && !globalCommand.hasOption(name)) throw new CACError(`Unknown option \`${name.length > 1 ? `--${name}` : `-${name}`}\``);
2004
- }
2005
- }
2006
- checkOptionValue() {
2007
- const { options: parsedOptions, globalCommand } = this.cli;
2008
- const options = [
2009
- ...globalCommand.options,
2010
- ...this.options
2011
- ];
2012
- for (const option of options){
2013
- const value = parsedOptions[option.name.split(".", 1)[0]];
2014
- if (option.required) {
2015
- const hasNegated = options.some((o)=>o.negated && o.names.includes(option.name));
2016
- if (true === value || false === value && !hasNegated) throw new CACError(`option \`${option.rawName}\` value is missing`);
2017
- }
2018
- }
2019
- }
2020
- checkUnusedArgs() {
2021
- const maximumArgsCount = this.args.some((arg)=>arg.variadic) ? 1 / 0 : this.args.length;
2022
- if (maximumArgsCount < this.cli.args.length) throw new CACError(`Unused args: ${this.cli.args.slice(maximumArgsCount).map((arg)=>`\`${arg}\``).join(", ")}`);
2023
- }
2024
- };
2025
- var GlobalCommand = class extends Command {
2026
- constructor(cli){
2027
- super("@@global@@", "", {}, cli);
2028
- }
2029
- };
2030
- var CAC = class extends EventTarget {
2031
- name;
2032
- commands;
2033
- globalCommand;
2034
- matchedCommand;
2035
- matchedCommandName;
2036
- rawArgs;
2037
- args;
2038
- options;
2039
- showHelpOnExit;
2040
- showVersionOnExit;
2041
- constructor(name = ""){
2042
- super();
2043
- this.name = name;
2044
- this.commands = [];
2045
- this.rawArgs = [];
2046
- this.args = [];
2047
- this.options = {};
2048
- this.globalCommand = new GlobalCommand(this);
2049
- this.globalCommand.usage("<command> [options]");
2050
- }
2051
- usage(text) {
2052
- this.globalCommand.usage(text);
2053
- return this;
2054
- }
2055
- command(rawName, description, config) {
2056
- const command = new Command(rawName, description || "", config, this);
2057
- command.globalCommand = this.globalCommand;
2058
- this.commands.push(command);
2059
- return command;
2060
- }
2061
- option(rawName, description, config) {
2062
- this.globalCommand.option(rawName, description, config);
2063
- return this;
2064
- }
2065
- help(callback) {
2066
- this.globalCommand.option("-h, --help", "Display this message");
2067
- this.globalCommand.helpCallback = callback;
2068
- this.showHelpOnExit = true;
2069
- return this;
2070
- }
2071
- version(version, customFlags = "-v, --version") {
2072
- this.globalCommand.version(version, customFlags);
2073
- this.showVersionOnExit = true;
2074
- return this;
2075
- }
2076
- example(example) {
2077
- this.globalCommand.example(example);
2078
- return this;
2079
- }
2080
- outputHelp() {
2081
- if (this.matchedCommand) this.matchedCommand.outputHelp();
2082
- else this.globalCommand.outputHelp();
2083
- }
2084
- outputVersion() {
2085
- this.globalCommand.outputVersion();
2086
- }
2087
- setParsedInfo({ args, options }, matchedCommand, matchedCommandName) {
2088
- this.args = args;
2089
- this.options = options;
2090
- if (matchedCommand) this.matchedCommand = matchedCommand;
2091
- if (matchedCommandName) this.matchedCommandName = matchedCommandName;
2092
- return this;
2093
- }
2094
- unsetMatchedCommand() {
2095
- this.matchedCommand = void 0;
2096
- this.matchedCommandName = void 0;
2097
- }
2098
- parse(argv, { run = true } = {}) {
2099
- if (!argv) {
2100
- const runtimeProcessArgs = getRuntimeProcessArgs();
2101
- if (!runtimeProcessArgs) throw new Error("No argv provided and runtime process argv is not available.");
2102
- argv = runtimeProcessArgs;
2103
- }
2104
- this.rawArgs = argv;
2105
- if (!this.name) this.name = argv[1] ? getFileName(argv[1]) : "cli";
2106
- let shouldParse = true;
2107
- for (const command of this.commands){
2108
- const parsed = this.mri(argv.slice(2), command);
2109
- const commandName = parsed.args[0];
2110
- if (command.isMatched(commandName)) {
2111
- shouldParse = false;
2112
- const parsedInfo = {
2113
- ...parsed,
2114
- args: parsed.args.slice(1)
2115
- };
2116
- this.setParsedInfo(parsedInfo, command, commandName);
2117
- this.dispatchEvent(new CustomEvent(`command:${commandName}`, {
2118
- detail: command
2119
- }));
2120
- }
2121
- }
2122
- if (shouldParse) {
2123
- for (const command of this.commands)if (command.isDefaultCommand) {
2124
- shouldParse = false;
2125
- const parsed = this.mri(argv.slice(2), command);
2126
- this.setParsedInfo(parsed, command);
2127
- this.dispatchEvent(new CustomEvent("command:!", {
2128
- detail: command
2129
- }));
2130
- }
2131
- }
2132
- if (shouldParse) {
2133
- const parsed = this.mri(argv.slice(2));
2134
- this.setParsedInfo(parsed);
2135
- }
2136
- if (this.options.help && this.showHelpOnExit) {
2137
- this.outputHelp();
2138
- run = false;
2139
- this.unsetMatchedCommand();
2140
- }
2141
- if (this.options.version && this.showVersionOnExit && null == this.matchedCommandName) {
2142
- this.outputVersion();
2143
- run = false;
2144
- this.unsetMatchedCommand();
2145
- }
2146
- const parsedArgv = {
2147
- args: this.args,
2148
- options: this.options
2149
- };
2150
- if (run) this.runMatchedCommand();
2151
- if (!this.matchedCommand && this.args[0]) this.dispatchEvent(new CustomEvent("command:*", {
2152
- detail: this.args[0]
2153
- }));
2154
- return parsedArgv;
2155
- }
2156
- mri(argv, command) {
2157
- const cliOptions = [
2158
- ...this.globalCommand.options,
2159
- ...command ? command.options : []
2160
- ];
2161
- const mriOptions = getMriOptions(cliOptions);
2162
- let argsAfterDoubleDashes = [];
2163
- const doubleDashesIndex = argv.indexOf("--");
2164
- if (-1 !== doubleDashesIndex) {
2165
- argsAfterDoubleDashes = argv.slice(doubleDashesIndex + 1);
2166
- argv = argv.slice(0, doubleDashesIndex);
2167
- }
2168
- let parsed = lib_default(argv, mriOptions);
2169
- parsed = Object.keys(parsed).reduce((res, name)=>({
2170
- ...res,
2171
- [camelcaseOptionName(name)]: parsed[name]
2172
- }), {
2173
- _: []
2174
- });
2175
- const args = parsed._;
2176
- const options = {
2177
- "--": argsAfterDoubleDashes
2178
- };
2179
- const ignoreDefault = command && command.config.ignoreOptionDefaultValue ? command.config.ignoreOptionDefaultValue : this.globalCommand.config.ignoreOptionDefaultValue;
2180
- const transforms = Object.create(null);
2181
- for (const cliOption of cliOptions){
2182
- if (!ignoreDefault && void 0 !== cliOption.config.default) for (const name of cliOption.names)options[name] = cliOption.config.default;
2183
- if (Array.isArray(cliOption.config.type) && void 0 === transforms[cliOption.name]) {
2184
- transforms[cliOption.name] = Object.create(null);
2185
- transforms[cliOption.name].shouldTransform = true;
2186
- transforms[cliOption.name].transformFunction = cliOption.config.type[0];
2187
- }
2188
- }
2189
- for (const [key, value] of Object.entries(parsed))if ("_" !== key) {
2190
- setDotProp(options, key.split("."), value);
2191
- setByType(options, transforms);
2192
- }
2193
- return {
2194
- args,
2195
- options
2196
- };
2197
- }
2198
- runMatchedCommand() {
2199
- const { args, options, matchedCommand: command } = this;
2200
- if (!command || !command.commandAction) return;
2201
- command.checkUnknownOptions();
2202
- command.checkOptionValue();
2203
- command.checkRequiredArgs();
2204
- command.checkUnusedArgs();
2205
- const actionArgs = [];
2206
- command.args.forEach((arg, index)=>{
2207
- if (arg.variadic) actionArgs.push(args.slice(index));
2208
- else actionArgs.push(args[index]);
2209
- });
2210
- actionArgs.push(options);
2211
- return command.commandAction.apply(this, actionArgs);
2212
- }
2213
- };
2214
- const cac = (name = "")=>new CAC(name);
2215
- const PLUGIN_VIRTUAL_MODULE_NAME = 'rsbuild:virtual-module';
2216
- const pluginVirtualModule = (pluginOptions = {})=>({
2217
- name: PLUGIN_VIRTUAL_MODULE_NAME,
2218
- async setup (api) {
2219
- const { virtualModules = {}, tempDir: virtualFolderName = '.rsbuild-virtual-module' } = pluginOptions;
2220
- const TEMP_DIR = join(api.context.rootPath, virtualFolderName);
2221
- const virtualFileAbsolutePaths = Object.keys(virtualModules).map((i)=>{
2222
- let absolutePath = join(TEMP_DIR, i);
2223
- if (!extname(absolutePath)) absolutePath = `${absolutePath}.js`;
2224
- return [
2225
- i,
2226
- absolutePath
2227
- ];
2228
- });
2229
- api.modifyBundlerChain((chain, { rspack })=>{
2230
- const pluginId = 'RSBUILD_VIRTUAL_MODULE_PLUGIN';
2231
- const virtualModules = Object.fromEntries(virtualFileAbsolutePaths.map((i)=>[
2232
- i[1],
2233
- ''
2234
- ]));
2235
- if (chain.plugins.has(pluginId)) chain.plugin(pluginId).tap((options)=>{
2236
- const existingPaths = new Set(Object.keys(options[0] ?? {}));
2237
- const conflictPath = virtualFileAbsolutePaths.find(([, path])=>existingPaths.has(path));
2238
- if (conflictPath) throw new Error(`Virtual module name conflicted: ${conflictPath[0]}`);
2239
- return [
2240
- {
2241
- ...options[0],
2242
- ...virtualModules
2243
- }
2244
- ];
2245
- });
2246
- else chain.plugin(pluginId).use(rspack.experiments.VirtualModulesPlugin, [
2247
- virtualModules
2248
- ]);
2249
- chain.resolve.alias.merge(Object.fromEntries(virtualFileAbsolutePaths));
2250
- });
2251
- for (const [moduleName, absolutePath] of virtualFileAbsolutePaths){
2252
- const handler = virtualModules[moduleName];
2253
- if (handler) api.transform({
2254
- test: absolutePath
2255
- }, handler);
2256
- }
2257
- }
2258
- });
2259
- var __require = /* @__PURE__ */ external_module_createRequire(import.meta.url);
2260
- function cleanPath(path) {
2261
- let normalized = normalize(path);
2262
- if (normalized.length > 1 && normalized[normalized.length - 1] === sep) normalized = normalized.substring(0, normalized.length - 1);
2263
- return normalized;
2264
- }
2265
- const SLASHES_REGEX = /[\\/]/g;
2266
- function convertSlashes(path, separator) {
2267
- return path.replace(SLASHES_REGEX, separator);
2268
- }
2269
- const WINDOWS_ROOT_DIR_REGEX = /^[a-z]:[\\/]$/i;
2270
- function isRootDirectory(path) {
2271
- return "/" === path || WINDOWS_ROOT_DIR_REGEX.test(path);
2272
- }
2273
- function normalizePath(path, options) {
2274
- const { resolvePaths, normalizePath: normalizePath$1, pathSeparator } = options;
2275
- const pathNeedsCleaning = "win32" === process.platform && path.includes("/") || path.startsWith(".");
2276
- if (resolvePaths) path = resolve(path);
2277
- if (normalizePath$1 || pathNeedsCleaning) path = cleanPath(path);
2278
- if ("." === path) return "";
2279
- const needsSeperator = path[path.length - 1] !== pathSeparator;
2280
- return convertSlashes(needsSeperator ? path + pathSeparator : path, pathSeparator);
2281
- }
2282
- function joinPathWithBasePath(filename, directoryPath) {
2283
- return directoryPath + filename;
2284
- }
2285
- function joinPathWithRelativePath(root, options) {
2286
- return function(filename, directoryPath) {
2287
- const sameRoot = directoryPath.startsWith(root);
2288
- if (sameRoot) return directoryPath.slice(root.length) + filename;
2289
- else return convertSlashes(external_path_relative(root, directoryPath), options.pathSeparator) + options.pathSeparator + filename;
2290
- };
2291
- }
2292
- function joinPath(filename) {
2293
- return filename;
2294
- }
2295
- function joinDirectoryPath(filename, directoryPath, separator) {
2296
- return directoryPath + filename + separator;
2297
- }
2298
- function build$7(root, options) {
2299
- const { relativePaths, includeBasePath } = options;
2300
- return relativePaths && root ? joinPathWithRelativePath(root, options) : includeBasePath ? joinPathWithBasePath : joinPath;
2301
- }
2302
- function pushDirectoryWithRelativePath(root) {
2303
- return function(directoryPath, paths) {
2304
- paths.push(directoryPath.substring(root.length) || ".");
2305
- };
2306
- }
2307
- function pushDirectoryFilterWithRelativePath(root) {
2308
- return function(directoryPath, paths, filters) {
2309
- const relativePath = directoryPath.substring(root.length) || ".";
2310
- if (filters.every((filter)=>filter(relativePath, true))) paths.push(relativePath);
2311
- };
2312
- }
2313
- const pushDirectory = (directoryPath, paths)=>{
2314
- paths.push(directoryPath || ".");
2315
- };
2316
- const pushDirectoryFilter = (directoryPath, paths, filters)=>{
2317
- const path = directoryPath || ".";
2318
- if (filters.every((filter)=>filter(path, true))) paths.push(path);
2319
- };
2320
- const empty$2 = ()=>{};
2321
- function build$6(root, options) {
2322
- const { includeDirs, filters, relativePaths } = options;
2323
- if (!includeDirs) return empty$2;
2324
- if (relativePaths) return filters && filters.length ? pushDirectoryFilterWithRelativePath(root) : pushDirectoryWithRelativePath(root);
2325
- return filters && filters.length ? pushDirectoryFilter : pushDirectory;
2326
- }
2327
- const pushFileFilterAndCount = (filename, _paths, counts, filters)=>{
2328
- if (filters.every((filter)=>filter(filename, false))) counts.files++;
2329
- };
2330
- const pushFileFilter = (filename, paths, _counts, filters)=>{
2331
- if (filters.every((filter)=>filter(filename, false))) paths.push(filename);
2332
- };
2333
- const pushFileCount = (_filename, _paths, counts, _filters)=>{
2334
- counts.files++;
2335
- };
2336
- const pushFile = (filename, paths)=>{
2337
- paths.push(filename);
2338
- };
2339
- const empty$1 = ()=>{};
2340
- function build$5(options) {
2341
- const { excludeFiles, filters, onlyCounts } = options;
2342
- if (excludeFiles) return empty$1;
2343
- if (filters && filters.length) return onlyCounts ? pushFileFilterAndCount : pushFileFilter;
2344
- else if (onlyCounts) return pushFileCount;
2345
- else return pushFile;
2346
- }
2347
- const getArray = (paths)=>paths;
2348
- const getArrayGroup = ()=>[
2349
- ""
2350
- ].slice(0, 0);
2351
- function build$4(options) {
2352
- return options.group ? getArrayGroup : getArray;
2353
- }
2354
- const groupFiles = (groups, directory, files)=>{
2355
- groups.push({
2356
- directory,
2357
- files,
2358
- dir: directory
2359
- });
2360
- };
2361
- const empty = ()=>{};
2362
- function build$3(options) {
2363
- return options.group ? groupFiles : empty;
2364
- }
2365
- const resolveSymlinksAsync = function(path, state, callback$1) {
2366
- const { queue, fs, options: { suppressErrors } } = state;
2367
- queue.enqueue();
2368
- fs.realpath(path, (error, resolvedPath)=>{
2369
- if (error) return queue.dequeue(suppressErrors ? null : error, state);
2370
- fs.stat(resolvedPath, (error$1, stat)=>{
2371
- if (error$1) return queue.dequeue(suppressErrors ? null : error$1, state);
2372
- if (stat.isDirectory() && isRecursive(path, resolvedPath, state)) return queue.dequeue(null, state);
2373
- callback$1(stat, resolvedPath);
2374
- queue.dequeue(null, state);
2375
- });
2376
- });
2377
- };
2378
- const resolveSymlinks = function(path, state, callback$1) {
2379
- const { queue, fs, options: { suppressErrors } } = state;
2380
- queue.enqueue();
2381
- try {
2382
- const resolvedPath = fs.realpathSync(path);
2383
- const stat = fs.statSync(resolvedPath);
2384
- if (stat.isDirectory() && isRecursive(path, resolvedPath, state)) return;
2385
- callback$1(stat, resolvedPath);
2386
- } catch (e) {
2387
- if (!suppressErrors) throw e;
2388
- }
2389
- };
2390
- function build$2(options, isSynchronous) {
2391
- if (!options.resolveSymlinks || options.excludeSymlinks) return null;
2392
- return isSynchronous ? resolveSymlinks : resolveSymlinksAsync;
2393
- }
2394
- function isRecursive(path, resolved, state) {
2395
- if (state.options.useRealPaths) return isRecursiveUsingRealPaths(resolved, state);
2396
- let parent = dirname(path);
2397
- let depth = 1;
2398
- while(parent !== state.root && depth < 2){
2399
- const resolvedPath = state.symlinks.get(parent);
2400
- const isSameRoot = !!resolvedPath && (resolvedPath === resolved || resolvedPath.startsWith(resolved) || resolved.startsWith(resolvedPath));
2401
- if (isSameRoot) depth++;
2402
- else parent = dirname(parent);
2403
- }
2404
- state.symlinks.set(path, resolved);
2405
- return depth > 1;
2406
- }
2407
- function isRecursiveUsingRealPaths(resolved, state) {
2408
- return state.visited.includes(resolved + state.options.pathSeparator);
2409
- }
2410
- const onlyCountsSync = (state)=>state.counts;
2411
- const groupsSync = (state)=>state.groups;
2412
- const defaultSync = (state)=>state.paths;
2413
- const limitFilesSync = (state)=>state.paths.slice(0, state.options.maxFiles);
2414
- const onlyCountsAsync = (state, error, callback$1)=>{
2415
- report(error, callback$1, state.counts, state.options.suppressErrors);
2416
- return null;
2417
- };
2418
- const defaultAsync = (state, error, callback$1)=>{
2419
- report(error, callback$1, state.paths, state.options.suppressErrors);
2420
- return null;
2421
- };
2422
- const limitFilesAsync = (state, error, callback$1)=>{
2423
- report(error, callback$1, state.paths.slice(0, state.options.maxFiles), state.options.suppressErrors);
2424
- return null;
2425
- };
2426
- const groupsAsync = (state, error, callback$1)=>{
2427
- report(error, callback$1, state.groups, state.options.suppressErrors);
2428
- return null;
2429
- };
2430
- function report(error, callback$1, output, suppressErrors) {
2431
- callback$1(error && !suppressErrors ? error : null, output);
2432
- }
2433
- function build$1(options, isSynchronous) {
2434
- const { onlyCounts, group, maxFiles } = options;
2435
- if (onlyCounts) return isSynchronous ? onlyCountsSync : onlyCountsAsync;
2436
- else if (group) return isSynchronous ? groupsSync : groupsAsync;
2437
- else if (maxFiles) return isSynchronous ? limitFilesSync : limitFilesAsync;
2438
- else return isSynchronous ? defaultSync : defaultAsync;
2439
- }
2440
- const readdirOpts = {
2441
- withFileTypes: true
2442
- };
2443
- const walkAsync = (state, crawlPath, directoryPath, currentDepth, callback$1)=>{
2444
- state.queue.enqueue();
2445
- if (currentDepth < 0) return state.queue.dequeue(null, state);
2446
- const { fs } = state;
2447
- state.visited.push(crawlPath);
2448
- state.counts.directories++;
2449
- fs.readdir(crawlPath || ".", readdirOpts, (error, entries = [])=>{
2450
- callback$1(entries, directoryPath, currentDepth);
2451
- state.queue.dequeue(state.options.suppressErrors ? null : error, state);
2452
- });
2453
- };
2454
- const walkSync = (state, crawlPath, directoryPath, currentDepth, callback$1)=>{
2455
- const { fs } = state;
2456
- if (currentDepth < 0) return;
2457
- state.visited.push(crawlPath);
2458
- state.counts.directories++;
2459
- let entries = [];
2460
- try {
2461
- entries = fs.readdirSync(crawlPath || ".", readdirOpts);
2462
- } catch (e) {
2463
- if (!state.options.suppressErrors) throw e;
2464
- }
2465
- callback$1(entries, directoryPath, currentDepth);
2466
- };
2467
- function build(isSynchronous) {
2468
- return isSynchronous ? walkSync : walkAsync;
2469
- }
2470
- var Queue = class {
2471
- count = 0;
2472
- constructor(onQueueEmpty){
2473
- this.onQueueEmpty = onQueueEmpty;
2474
- }
2475
- enqueue() {
2476
- this.count++;
2477
- return this.count;
2478
- }
2479
- dequeue(error, output) {
2480
- if (this.onQueueEmpty && (--this.count <= 0 || error)) {
2481
- this.onQueueEmpty(error, output);
2482
- if (error) {
2483
- output.controller.abort();
2484
- this.onQueueEmpty = void 0;
2485
- }
2486
- }
2487
- }
2488
- };
2489
- var Counter = class {
2490
- _files = 0;
2491
- _directories = 0;
2492
- set files(num) {
2493
- this._files = num;
2494
- }
2495
- get files() {
2496
- return this._files;
2497
- }
2498
- set directories(num) {
2499
- this._directories = num;
2500
- }
2501
- get directories() {
2502
- return this._directories;
2503
- }
2504
- get dirs() {
2505
- return this._directories;
2506
- }
2507
- };
2508
- var Aborter = class {
2509
- aborted = false;
2510
- abort() {
2511
- this.aborted = true;
2512
- }
2513
- };
2514
- var Walker = class {
2515
- root;
2516
- isSynchronous;
2517
- state;
2518
- joinPath;
2519
- pushDirectory;
2520
- pushFile;
2521
- getArray;
2522
- groupFiles;
2523
- resolveSymlink;
2524
- walkDirectory;
2525
- callbackInvoker;
2526
- constructor(root, options, callback$1){
2527
- this.isSynchronous = !callback$1;
2528
- this.callbackInvoker = build$1(options, this.isSynchronous);
2529
- this.root = normalizePath(root, options);
2530
- this.state = {
2531
- root: isRootDirectory(this.root) ? this.root : this.root.slice(0, -1),
2532
- paths: [
2533
- ""
2534
- ].slice(0, 0),
2535
- groups: [],
2536
- counts: new Counter(),
2537
- options,
2538
- queue: new Queue((error, state)=>this.callbackInvoker(state, error, callback$1)),
2539
- symlinks: /* @__PURE__ */ new Map(),
2540
- visited: [
2541
- ""
2542
- ].slice(0, 0),
2543
- controller: new Aborter(),
2544
- fs: options.fs || __rspack_external_fs
2545
- };
2546
- this.joinPath = build$7(this.root, options);
2547
- this.pushDirectory = build$6(this.root, options);
2548
- this.pushFile = build$5(options);
2549
- this.getArray = build$4(options);
2550
- this.groupFiles = build$3(options);
2551
- this.resolveSymlink = build$2(options, this.isSynchronous);
2552
- this.walkDirectory = build(this.isSynchronous);
2553
- }
2554
- start() {
2555
- this.pushDirectory(this.root, this.state.paths, this.state.options.filters);
2556
- this.walkDirectory(this.state, this.root, this.root, this.state.options.maxDepth, this.walk);
2557
- return this.isSynchronous ? this.callbackInvoker(this.state, null) : null;
2558
- }
2559
- walk = (entries, directoryPath, depth)=>{
2560
- const { paths, options: { filters, resolveSymlinks: resolveSymlinks$1, excludeSymlinks, exclude, maxFiles, signal, useRealPaths, pathSeparator }, controller } = this.state;
2561
- if (controller.aborted || signal && signal.aborted || maxFiles && paths.length > maxFiles) return;
2562
- const files = this.getArray(this.state.paths);
2563
- for(let i = 0; i < entries.length; ++i){
2564
- const entry = entries[i];
2565
- if (entry.isFile() || entry.isSymbolicLink() && !resolveSymlinks$1 && !excludeSymlinks) {
2566
- const filename = this.joinPath(entry.name, directoryPath);
2567
- this.pushFile(filename, files, this.state.counts, filters);
2568
- } else if (entry.isDirectory()) {
2569
- let path = joinDirectoryPath(entry.name, directoryPath, this.state.options.pathSeparator);
2570
- if (exclude && exclude(entry.name, path)) continue;
2571
- this.pushDirectory(path, paths, filters);
2572
- this.walkDirectory(this.state, path, path, depth - 1, this.walk);
2573
- } else if (this.resolveSymlink && entry.isSymbolicLink()) {
2574
- let path = joinPathWithBasePath(entry.name, directoryPath);
2575
- this.resolveSymlink(path, this.state, (stat, resolvedPath)=>{
2576
- if (stat.isDirectory()) {
2577
- resolvedPath = normalizePath(resolvedPath, this.state.options);
2578
- if (exclude && exclude(entry.name, useRealPaths ? resolvedPath : path + pathSeparator)) return;
2579
- this.walkDirectory(this.state, resolvedPath, useRealPaths ? resolvedPath : path + pathSeparator, depth - 1, this.walk);
2580
- } else {
2581
- resolvedPath = useRealPaths ? resolvedPath : path;
2582
- const filename = basename(resolvedPath);
2583
- const directoryPath$1 = normalizePath(dirname(resolvedPath), this.state.options);
2584
- resolvedPath = this.joinPath(filename, directoryPath$1);
2585
- this.pushFile(resolvedPath, files, this.state.counts, filters);
2586
- }
2587
- });
2588
- }
2589
- }
2590
- this.groupFiles(this.state.groups, directoryPath, files);
2591
- };
2592
- };
2593
- function promise(root, options) {
2594
- return new Promise((resolve$1, reject)=>{
2595
- dist_callback(root, options, (err, output)=>{
2596
- if (err) return reject(err);
2597
- resolve$1(output);
2598
- });
2599
- });
2600
- }
2601
- function dist_callback(root, options, callback$1) {
2602
- let walker = new Walker(root, options, callback$1);
2603
- walker.start();
2604
- }
2605
- function sync(root, options) {
2606
- const walker = new Walker(root, options);
2607
- return walker.start();
2608
- }
2609
- var APIBuilder = class {
2610
- constructor(root, options){
2611
- this.root = root;
2612
- this.options = options;
2613
- }
2614
- withPromise() {
2615
- return promise(this.root, this.options);
2616
- }
2617
- withCallback(cb) {
2618
- dist_callback(this.root, this.options, cb);
2619
- }
2620
- sync() {
2621
- return sync(this.root, this.options);
2622
- }
2623
- };
2624
- let pm = null;
2625
- try {
2626
- __require.resolve("picomatch");
2627
- pm = __require("picomatch");
2628
- } catch {}
2629
- var Builder = class {
2630
- globCache = {};
2631
- options = {
2632
- maxDepth: 1 / 0,
2633
- suppressErrors: true,
2634
- pathSeparator: sep,
2635
- filters: []
2636
- };
2637
- globFunction;
2638
- constructor(options){
2639
- this.options = {
2640
- ...this.options,
2641
- ...options
2642
- };
2643
- this.globFunction = this.options.globFunction;
2644
- }
2645
- group() {
2646
- this.options.group = true;
2647
- return this;
2648
- }
2649
- withPathSeparator(separator) {
2650
- this.options.pathSeparator = separator;
2651
- return this;
2652
- }
2653
- withBasePath() {
2654
- this.options.includeBasePath = true;
2655
- return this;
2656
- }
2657
- withRelativePaths() {
2658
- this.options.relativePaths = true;
2659
- return this;
2660
- }
2661
- withDirs() {
2662
- this.options.includeDirs = true;
2663
- return this;
2664
- }
2665
- withMaxDepth(depth) {
2666
- this.options.maxDepth = depth;
2667
- return this;
2668
- }
2669
- withMaxFiles(limit) {
2670
- this.options.maxFiles = limit;
2671
- return this;
2672
- }
2673
- withFullPaths() {
2674
- this.options.resolvePaths = true;
2675
- this.options.includeBasePath = true;
2676
- return this;
2677
- }
2678
- withErrors() {
2679
- this.options.suppressErrors = false;
2680
- return this;
2681
- }
2682
- withSymlinks({ resolvePaths = true } = {}) {
2683
- this.options.resolveSymlinks = true;
2684
- this.options.useRealPaths = resolvePaths;
2685
- return this.withFullPaths();
2686
- }
2687
- withAbortSignal(signal) {
2688
- this.options.signal = signal;
2689
- return this;
2690
- }
2691
- normalize() {
2692
- this.options.normalizePath = true;
2693
- return this;
2694
- }
2695
- filter(predicate) {
2696
- this.options.filters.push(predicate);
2697
- return this;
2698
- }
2699
- onlyDirs() {
2700
- this.options.excludeFiles = true;
2701
- this.options.includeDirs = true;
2702
- return this;
2703
- }
2704
- exclude(predicate) {
2705
- this.options.exclude = predicate;
2706
- return this;
2707
- }
2708
- onlyCounts() {
2709
- this.options.onlyCounts = true;
2710
- return this;
2711
- }
2712
- crawl(root) {
2713
- return new APIBuilder(root || ".", this.options);
2714
- }
2715
- withGlobFunction(fn) {
2716
- this.globFunction = fn;
2717
- return this;
2718
- }
2719
- crawlWithOptions(root, options) {
2720
- this.options = {
2721
- ...this.options,
2722
- ...options
2723
- };
2724
- return new APIBuilder(root || ".", this.options);
2725
- }
2726
- glob(...patterns) {
2727
- if (this.globFunction) return this.globWithOptions(patterns);
2728
- return this.globWithOptions(patterns, {
2729
- dot: true
2730
- });
2731
- }
2732
- globWithOptions(patterns, ...options) {
2733
- const globFn = this.globFunction || pm;
2734
- if (!globFn) throw new Error("Please specify a glob function to use glob matching.");
2735
- var isMatch = this.globCache[patterns.join("\0")];
2736
- if (!isMatch) {
2737
- isMatch = globFn(patterns, ...options);
2738
- this.globCache[patterns.join("\0")] = isMatch;
2739
- }
2740
- this.options.filters.push((path)=>isMatch(path));
2741
- return this;
2742
- }
2743
- };
2744
- const picomatch = rspackRequire("../../node_modules/.pnpm/picomatch@4.0.7/node_modules/picomatch/index.js");
2745
- const isReadonlyArray = Array.isArray;
2746
- const BACKSLASHES = /\\/g;
2747
- const DRIVE_RELATIVE_PATH = /^[A-Za-z]:$/;
2748
- const isWin = "win32" === process.platform;
2749
- const ONLY_PARENT_DIRECTORIES = /^(\/?\.\.)+$/;
2750
- function getPartialMatcher(patterns, options = {}) {
2751
- const patternsCount = patterns.length;
2752
- const patternsParts = Array(patternsCount);
2753
- const matchers = Array(patternsCount);
2754
- let i, j;
2755
- for(i = 0; i < patternsCount; i++){
2756
- const parts = splitPattern(patterns[i]);
2757
- patternsParts[i] = parts;
2758
- const partsCount = parts.length;
2759
- const partMatchers = Array(partsCount);
2760
- for(j = 0; j < partsCount; j++)partMatchers[j] = picomatch(parts[j], options);
2761
- matchers[i] = partMatchers;
2762
- }
2763
- return (input)=>{
2764
- const inputParts = input.split("/");
2765
- if (".." === inputParts[0] && ONLY_PARENT_DIRECTORIES.test(input)) return true;
2766
- for(i = 0; i < patternsCount; i++){
2767
- const patternParts = patternsParts[i];
2768
- const matcher = matchers[i];
2769
- const inputPatternCount = inputParts.length;
2770
- const minParts = Math.min(inputPatternCount, patternParts.length);
2771
- j = 0;
2772
- while(j < minParts){
2773
- const part = patternParts[j];
2774
- if (part.includes("/")) return true;
2775
- if (!matcher[j](inputParts[j])) break;
2776
- if (!options.noglobstar && "**" === part) return true;
2777
- j++;
2778
- }
2779
- if (j === inputPatternCount) return true;
2780
- }
2781
- return false;
2782
- };
2783
- }
2784
- const WIN32_ROOT_DIR = /^[A-Z]:\/$/i;
2785
- const isRoot = isWin ? (p)=>WIN32_ROOT_DIR.test(p) : (p)=>"/" === p;
2786
- function buildFormat(cwd, root, absolute) {
2787
- if (cwd === root || root.startsWith(`${cwd}/`)) {
2788
- if (absolute) {
2789
- const start = cwd.length + +!isRoot(cwd);
2790
- return (p, isDir)=>p.slice(start, isDir ? -1 : void 0) || ".";
2791
- }
2792
- const prefix = root.slice(cwd.length + 1);
2793
- if (prefix) return (p, isDir)=>{
2794
- if ("." === p) return prefix;
2795
- const result = `${prefix}/${p}`;
2796
- return isDir ? result.slice(0, -1) : result;
2797
- };
2798
- return (p, isDir)=>isDir && "." !== p ? p.slice(0, -1) : p;
2799
- }
2800
- if (absolute) return (p)=>posix.relative(cwd, p) || ".";
2801
- return (p)=>posix.relative(cwd, `${root}/${p}`) || ".";
2802
- }
2803
- function buildRelative(cwd, root) {
2804
- if (root.startsWith(`${cwd}/`)) {
2805
- const prefix = root.slice(cwd.length + 1);
2806
- return (p)=>`${prefix}/${p}`;
2807
- }
2808
- return (p)=>{
2809
- const result = posix.relative(cwd, `${root}/${p}`);
2810
- return "/" === p[p.length - 1] && "" !== result ? `${result}/` : result || ".";
2811
- };
2812
- }
2813
- function ensureNonDriveRelativePath(path) {
2814
- return path.replace(DRIVE_RELATIVE_PATH, (match)=>`${match}/`);
2815
- }
2816
- const splitPatternOptions = {
2817
- parts: true
2818
- };
2819
- function splitPattern(path) {
2820
- var _result$parts;
2821
- const result = picomatch.scan(path, splitPatternOptions);
2822
- return (null == (_result$parts = result.parts) ? void 0 : _result$parts.length) ? result.parts : [
2823
- path
2824
- ];
2825
- }
2826
- const POSIX_UNESCAPED_GLOB_SYMBOLS = /(?<!\\)([()[\]{}*?|]|^!|[!+@](?=\()|\\(?![()[\]{}!*+?@|]))/g;
2827
- const WIN32_UNESCAPED_GLOB_SYMBOLS = /(?<!\\)([()[\]{}]|^!|[!+@](?=\())/g;
2828
- const escapePosixPath = (path)=>path.replace(POSIX_UNESCAPED_GLOB_SYMBOLS, "\\$&");
2829
- const escapeWin32Path = (path)=>path.replace(WIN32_UNESCAPED_GLOB_SYMBOLS, "\\$&");
2830
- const escapePath = isWin ? escapeWin32Path : escapePosixPath;
2831
- function isDynamicPattern(pattern, options) {
2832
- if ((null == options ? void 0 : options.caseSensitiveMatch) === false) return true;
2833
- const scan = picomatch.scan(pattern);
2834
- return scan.isGlob || scan.negated;
2835
- }
2836
- function log(...tasks) {
2837
- console.log(`[tinyglobby ${(/* @__PURE__ */ new Date()).toLocaleTimeString("es")}]`, ...tasks);
2838
- }
2839
- function ensureStringArray(value) {
2840
- return "string" == typeof value ? [
2841
- value
2842
- ] : null != value ? value : [];
2843
- }
2844
- const PARENT_DIRECTORY = /^(\/?\.\.)+/;
2845
- const ESCAPING_BACKSLASHES = /\\(?=[()[\]{}!*+?@|])/g;
2846
- function normalizePattern(pattern, opts, props, isIgnore) {
2847
- var _PARENT_DIRECTORY$exe;
2848
- const cwd = opts.cwd;
2849
- let result = pattern;
2850
- if ("/" === pattern[pattern.length - 1]) result = pattern.slice(0, -1);
2851
- if ("*" !== result[result.length - 1] && opts.expandDirectories) result += "/**";
2852
- const escapedCwd = escapePath(cwd);
2853
- result = isAbsolute(result.replace(ESCAPING_BACKSLASHES, "")) ? posix.relative(escapedCwd, result) : posix.normalize(result);
2854
- const parentDir = null == (_PARENT_DIRECTORY$exe = PARENT_DIRECTORY.exec(result)) ? void 0 : _PARENT_DIRECTORY$exe[0];
2855
- const parts = splitPattern(result);
2856
- if (parentDir) {
2857
- const n = (parentDir.length + 1) / 3;
2858
- let i = 0;
2859
- const cwdParts = escapedCwd.split("/");
2860
- while(i < n && parts[i + n] === cwdParts[cwdParts.length + i - n]){
2861
- result = result.slice(0, (n - i - 1) * 3) + result.slice((n - i) * 3 + parts[i + n].length + 1) || ".";
2862
- i++;
2863
- }
2864
- const potentialRoot = posix.join(cwd, parentDir.slice(3 * i));
2865
- if ("." !== potentialRoot[0] && props.root.length > potentialRoot.length) {
2866
- props.root = ensureNonDriveRelativePath(potentialRoot);
2867
- props.depthOffset = -n + i;
2868
- }
2869
- }
2870
- if (!isIgnore && props.depthOffset >= 0) {
2871
- null != props.commonPath || (props.commonPath = parts);
2872
- const newCommonPath = [];
2873
- const length = Math.min(props.commonPath.length, parts.length);
2874
- for(let i = 0; i < length; i++){
2875
- const part = parts[i];
2876
- if ("**" === part && !parts[i + 1]) {
2877
- newCommonPath.pop();
2878
- break;
2879
- }
2880
- if (i === parts.length - 1 || part !== props.commonPath[i] || isDynamicPattern(part)) break;
2881
- newCommonPath.push(part);
2882
- }
2883
- props.depthOffset = newCommonPath.length;
2884
- props.commonPath = newCommonPath;
2885
- props.root = ensureNonDriveRelativePath(newCommonPath.length > 0 ? posix.join(cwd, ...newCommonPath) : cwd);
2886
- }
2887
- return result;
2888
- }
2889
- function processPatterns(options, patterns, props) {
2890
- const matchPatterns = [];
2891
- const ignorePatterns = [];
2892
- for (const pattern of options.ignore)if (pattern) {
2893
- if ("!" !== pattern[0] || "(" === pattern[1]) ignorePatterns.push(normalizePattern(pattern, options, props, true));
2894
- }
2895
- for (const pattern of patterns)if (pattern) {
2896
- if ("!" !== pattern[0] || "(" === pattern[1]) matchPatterns.push(normalizePattern(pattern, options, props, false));
2897
- else if ("!" !== pattern[1] || "(" === pattern[2]) ignorePatterns.push(normalizePattern(pattern.slice(1), options, props, true));
2898
- }
2899
- return {
2900
- match: matchPatterns,
2901
- ignore: ignorePatterns
2902
- };
2903
- }
2904
- function buildCrawler(options, patterns) {
2905
- const cwd = options.cwd;
2906
- const props = {
2907
- root: cwd,
2908
- depthOffset: 0
2909
- };
2910
- const processed = processPatterns(options, patterns, props);
2911
- if (options.debug) log("internal processing patterns:", processed);
2912
- const { absolute, caseSensitiveMatch, debug, dot, followSymbolicLinks, onlyDirectories } = options;
2913
- const root = props.root.replace(BACKSLASHES, "");
2914
- const matchOptions = {
2915
- dot,
2916
- nobrace: false === options.braceExpansion,
2917
- nocase: !caseSensitiveMatch,
2918
- noextglob: false === options.extglob,
2919
- noglobstar: false === options.globstar,
2920
- posix: true
2921
- };
2922
- const matcher = picomatch(processed.match, matchOptions);
2923
- const ignore = picomatch(processed.ignore, matchOptions);
2924
- const partialMatcher = getPartialMatcher(processed.match, matchOptions);
2925
- const format = buildFormat(cwd, root, absolute);
2926
- const excludeFormatter = absolute ? format : buildFormat(cwd, root, true);
2927
- const excludePredicate = (_, p)=>{
2928
- const relativePath = excludeFormatter(p, true);
2929
- return "." !== relativePath && !partialMatcher(relativePath) || ignore(relativePath);
2930
- };
2931
- let maxDepth;
2932
- if (void 0 !== options.deep) maxDepth = Math.round(options.deep - props.depthOffset);
2933
- const crawler = new Builder({
2934
- filters: [
2935
- debug ? (p, isDirectory)=>{
2936
- const path = format(p, isDirectory);
2937
- const matches = matcher(path) && !ignore(path);
2938
- if (matches) log(`matched ${path}`);
2939
- return matches;
2940
- } : (p, isDirectory)=>{
2941
- const path = format(p, isDirectory);
2942
- return matcher(path) && !ignore(path);
2943
- }
2944
- ],
2945
- exclude: debug ? (_, p)=>{
2946
- const skipped = excludePredicate(_, p);
2947
- log(`${skipped ? "skipped" : "crawling"} ${p}`);
2948
- return skipped;
2949
- } : excludePredicate,
2950
- fs: options.fs,
2951
- pathSeparator: "/",
2952
- relativePaths: !absolute,
2953
- resolvePaths: absolute,
2954
- includeBasePath: absolute,
2955
- resolveSymlinks: followSymbolicLinks,
2956
- excludeSymlinks: !followSymbolicLinks,
2957
- excludeFiles: onlyDirectories,
2958
- includeDirs: onlyDirectories || !options.onlyFiles,
2959
- maxDepth,
2960
- signal: options.signal
2961
- }).crawl(root);
2962
- if (options.debug) log("internal properties:", {
2963
- ...props,
2964
- root
2965
- });
2966
- return [
2967
- crawler,
2968
- cwd !== root && !absolute && buildRelative(cwd, root)
2969
- ];
2970
- }
2971
- function formatPaths(paths, mapper) {
2972
- if (mapper) for(let i = paths.length - 1; i >= 0; i--)paths[i] = mapper(paths[i]);
2973
- return paths;
2974
- }
2975
- const defaultOptions = {
2976
- caseSensitiveMatch: true,
2977
- debug: !!process.env.TINYGLOBBY_DEBUG,
2978
- expandDirectories: true,
2979
- followSymbolicLinks: true,
2980
- onlyFiles: true
2981
- };
2982
- function getOptions(options) {
2983
- const opts = Object.assign({}, options);
2984
- for(const key in defaultOptions)if (void 0 === opts[key]) Object.assign(opts, {
2985
- [key]: defaultOptions[key]
2986
- });
2987
- opts.cwd = (opts.cwd instanceof URL ? external_url_fileURLToPath(opts.cwd) : resolve(opts.cwd || process.cwd())).replace(BACKSLASHES, "/");
2988
- opts.ignore = ensureStringArray(opts.ignore);
2989
- opts.fs && (opts.fs = {
2990
- readdir: opts.fs.readdir || readdir,
2991
- readdirSync: opts.fs.readdirSync || readdirSync,
2992
- realpath: opts.fs.realpath || realpath,
2993
- realpathSync: opts.fs.realpathSync || realpathSync,
2994
- stat: opts.fs.stat || external_fs_stat,
2995
- statSync: opts.fs.statSync || statSync
2996
- });
2997
- if (opts.debug) log("globbing with options:", opts);
2998
- return opts;
2999
- }
3000
- function getCrawler(globInput, inputOptions = {}) {
3001
- var _ref;
3002
- if (globInput && (null == inputOptions ? void 0 : inputOptions.patterns)) throw new Error("Cannot pass patterns as both an argument and an option");
3003
- const isModern = isReadonlyArray(globInput) || "string" == typeof globInput;
3004
- const patterns = ensureStringArray(null != (_ref = isModern ? globInput : globInput.patterns) ? _ref : "**/*");
3005
- const options = getOptions(isModern ? inputOptions : globInput);
3006
- return patterns.length > 0 ? buildCrawler(options, patterns) : [];
3007
- }
3008
- async function glob(globInput, options) {
3009
- const [crawler, relative] = getCrawler(globInput, options);
3010
- return crawler ? formatPaths(await crawler.withPromise(), relative) : [];
3011
- }
3012
- export { logger } from "@rspress/shared/logger";
3013
- export { DEFAULT_CONFIG_EXTENSIONS, DEFAULT_CONFIG_NAME, DEFAULT_PAGE_EXTENSIONS } from "@rspress/shared/constants";
3014
- export { default as promises, mkdir, readFile, readdir as promises_readdir, rm, stat as promises_stat, writeFile } from "node:fs/promises";
3015
- export { createRequire } from "node:module";
3016
- export { cwd as external_node_process_cwd } from "node:process";
3017
- export { fileURLToPath, pathToFileURL } from "node:url";
3018
- export { PLUGIN_REACT_NAME, pluginReact } from "@rsbuild/plugin-react";
3019
- export { MDX_OR_MD_REGEXP, RSPRESS_TEMP_DIR, SEARCH_INDEX_NAME, addLeadingSlash, addTrailingSlash, getSidebarDataGroup, isDebugMode, isExternalUrl, isProduction, normalizeDarkMode, normalizeHref, normalizePosixPath, removeLeadingSlash, removeTrailingSlash, slash, withBase, withSiteOrigin } from "@rspress/shared";
3020
- export { createHash } from "node:crypto";
3021
- export { chunk, groupBy } from "@rspress/shared/lodash-es";
3022
- export { extractTextAndId, getIconUrlPath, loadFrontMatter } from "@rspress/shared/node-utils";
3023
- export { default as remark_gfm } from "remark-gfm";
3024
- export { default as remark_parse } from "remark-parse";
3025
- export { unified } from "unified";
3026
- export { default as node_fs } from "node:fs";
3027
- export { createProcessor } from "@mdx-js/mdx";
3028
- export { mergeRsbuildConfig, rspack as core_rspack } from "@rsbuild/core";
3029
- export { default as node_os } from "node:os";
3030
- export { matchPath } from "react-router-dom";
3031
- export { createHead } from "@unhead/react/server";
3032
- export { cac, external_node_path_relative, extname, glob, join, node_path, pluginVirtualModule };