@pnpm/exe 11.0.0-alpha.9 → 11.0.0-beta.1

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 (219) hide show
  1. package/dist/node_modules/@gar/promise-retry/lib/index.js +28 -0
  2. package/dist/node_modules/@gar/promise-retry/package.json +48 -0
  3. package/dist/node_modules/@npmcli/agent/package.json +7 -7
  4. package/dist/node_modules/@npmcli/fs/package.json +4 -4
  5. package/dist/node_modules/abbrev/package.json +11 -15
  6. package/dist/node_modules/balanced-match/package.json +4 -7
  7. package/dist/node_modules/brace-expansion/dist/commonjs/index.js +1 -1
  8. package/dist/node_modules/brace-expansion/dist/esm/index.js +1 -1
  9. package/dist/node_modules/brace-expansion/package.json +3 -3
  10. package/dist/node_modules/cacache/package.json +10 -11
  11. package/dist/node_modules/glob/dist/commonjs/glob.js +2 -1
  12. package/dist/node_modules/glob/dist/commonjs/index.min.js +4 -0
  13. package/dist/node_modules/glob/dist/commonjs/pattern.js +4 -0
  14. package/dist/node_modules/glob/dist/esm/glob.js +2 -1
  15. package/dist/node_modules/glob/dist/esm/index.min.js +4 -0
  16. package/dist/node_modules/glob/dist/esm/pattern.js +4 -0
  17. package/dist/node_modules/glob/package.json +38 -37
  18. package/dist/node_modules/iconv-lite/encodings/dbcs-codec.js +460 -525
  19. package/dist/node_modules/iconv-lite/encodings/dbcs-data.js +179 -182
  20. package/dist/node_modules/iconv-lite/encodings/index.js +15 -15
  21. package/dist/node_modules/iconv-lite/encodings/internal.js +168 -148
  22. package/dist/node_modules/iconv-lite/encodings/sbcs-codec.js +55 -52
  23. package/dist/node_modules/iconv-lite/encodings/sbcs-data.js +174 -175
  24. package/dist/node_modules/iconv-lite/encodings/utf16.js +121 -131
  25. package/dist/node_modules/iconv-lite/encodings/utf32.js +226 -238
  26. package/dist/node_modules/iconv-lite/encodings/utf7.js +208 -215
  27. package/dist/node_modules/iconv-lite/lib/bom-handling.js +30 -34
  28. package/dist/node_modules/iconv-lite/lib/helpers/merge-exports.js +13 -0
  29. package/dist/node_modules/iconv-lite/lib/index.js +125 -123
  30. package/dist/node_modules/iconv-lite/lib/streams.js +92 -96
  31. package/dist/node_modules/iconv-lite/package.json +34 -8
  32. package/dist/node_modules/isexe/package.json +65 -18
  33. package/dist/node_modules/lru-cache/dist/commonjs/index.js +134 -85
  34. package/dist/node_modules/lru-cache/dist/commonjs/index.min.js +1 -1
  35. package/dist/node_modules/lru-cache/dist/esm/index.js +134 -85
  36. package/dist/node_modules/lru-cache/dist/esm/index.min.js +1 -1
  37. package/dist/node_modules/lru-cache/package.json +18 -41
  38. package/dist/node_modules/make-fetch-happen/lib/remote.js +1 -1
  39. package/dist/node_modules/make-fetch-happen/package.json +10 -10
  40. package/dist/node_modules/minimatch/dist/commonjs/ast.js +266 -21
  41. package/dist/node_modules/minimatch/dist/commonjs/index.js +178 -92
  42. package/dist/node_modules/minimatch/dist/esm/ast.js +266 -21
  43. package/dist/node_modules/minimatch/dist/esm/index.js +178 -92
  44. package/dist/node_modules/minimatch/package.json +4 -4
  45. package/dist/node_modules/minipass/dist/commonjs/index.js +13 -3
  46. package/dist/node_modules/minipass/dist/esm/index.js +3 -1
  47. package/dist/node_modules/minipass/package.json +9 -14
  48. package/dist/node_modules/minipass-fetch/lib/body.js +25 -15
  49. package/dist/node_modules/minipass-fetch/package.json +7 -7
  50. package/dist/node_modules/minipass-sized/dist/commonjs/index.js +69 -0
  51. package/dist/node_modules/minipass-sized/dist/esm/index.js +64 -0
  52. package/dist/node_modules/minipass-sized/package.json +39 -9
  53. package/dist/node_modules/node-gyp/.release-please-manifest.json +1 -1
  54. package/dist/node_modules/node-gyp/bin/node-gyp.js +7 -0
  55. package/dist/node_modules/node-gyp/gyp/.release-please-manifest.json +1 -1
  56. package/dist/node_modules/node-gyp/gyp/pylib/gyp/MSVSNew.py +3 -3
  57. package/dist/node_modules/node-gyp/gyp/pylib/gyp/MSVSVersion.py +26 -1
  58. package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py +1 -1
  59. package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja.py +3 -4
  60. package/dist/node_modules/node-gyp/gyp/pylib/gyp/xcodeproj_file.py +1 -1
  61. package/dist/node_modules/node-gyp/gyp/pyproject.toml +1 -1
  62. package/dist/node_modules/node-gyp/lib/build.js +2 -2
  63. package/dist/node_modules/node-gyp/lib/find-python.js +2 -8
  64. package/dist/node_modules/node-gyp/lib/find-visualstudio.js +11 -5
  65. package/dist/node_modules/node-gyp/lib/install.js +1 -1
  66. package/dist/node_modules/node-gyp/lib/process-release.js +3 -3
  67. package/dist/node_modules/node-gyp/package.json +13 -13
  68. package/dist/node_modules/nopt/package.json +5 -5
  69. package/dist/node_modules/path-scurry/package.json +8 -24
  70. package/dist/node_modules/proc-log/lib/index.js +10 -5
  71. package/dist/node_modules/proc-log/package.json +5 -5
  72. package/dist/node_modules/retry/lib/retry.js +2 -2
  73. package/dist/node_modules/retry/lib/retry_operation.js +10 -6
  74. package/dist/node_modules/retry/package.json +6 -2
  75. package/dist/node_modules/ssri/lib/index.js +33 -63
  76. package/dist/node_modules/ssri/package.json +17 -17
  77. package/dist/node_modules/tar/dist/commonjs/index.min.js +2 -2
  78. package/dist/node_modules/tar/dist/commonjs/unpack.js +4 -4
  79. package/dist/node_modules/tar/dist/esm/index.min.js +2 -2
  80. package/dist/node_modules/tar/dist/esm/unpack.js +4 -4
  81. package/dist/node_modules/tar/package.json +6 -6
  82. package/dist/node_modules/unique-filename/package.json +5 -5
  83. package/dist/node_modules/unique-slug/package.json +4 -4
  84. package/dist/node_modules/which/package.json +29 -20
  85. package/dist/pnpm.mjs +225713 -208017
  86. package/dist/worker.js +4838 -5926
  87. package/package.json +10 -10
  88. package/setup.js +12 -14
  89. package/dist/node_modules/@isaacs/cliui/dist/commonjs/ansi-regex/index.js +0 -16
  90. package/dist/node_modules/@isaacs/cliui/dist/commonjs/ansi-styles/index.js +0 -170
  91. package/dist/node_modules/@isaacs/cliui/dist/commonjs/eastasianwidth/index.js +0 -307
  92. package/dist/node_modules/@isaacs/cliui/dist/commonjs/emoji-regex/index.js +0 -7
  93. package/dist/node_modules/@isaacs/cliui/dist/commonjs/index.js +0 -322
  94. package/dist/node_modules/@isaacs/cliui/dist/commonjs/index.min.js +0 -12
  95. package/dist/node_modules/@isaacs/cliui/dist/commonjs/string-width/index.js +0 -49
  96. package/dist/node_modules/@isaacs/cliui/dist/commonjs/strip-ansi/index.js +0 -8
  97. package/dist/node_modules/@isaacs/cliui/dist/commonjs/wrap-ansi/index.js +0 -176
  98. package/dist/node_modules/@isaacs/cliui/dist/esm/ansi-regex/index.js +0 -12
  99. package/dist/node_modules/@isaacs/cliui/dist/esm/ansi-styles/index.js +0 -167
  100. package/dist/node_modules/@isaacs/cliui/dist/esm/eastasianwidth/index.js +0 -299
  101. package/dist/node_modules/@isaacs/cliui/dist/esm/emoji-regex/index.js +0 -3
  102. package/dist/node_modules/@isaacs/cliui/dist/esm/index.js +0 -317
  103. package/dist/node_modules/@isaacs/cliui/dist/esm/index.min.js +0 -12
  104. package/dist/node_modules/@isaacs/cliui/dist/esm/string-width/index.js +0 -46
  105. package/dist/node_modules/@isaacs/cliui/dist/esm/strip-ansi/index.js +0 -4
  106. package/dist/node_modules/@isaacs/cliui/dist/esm/wrap-ansi/index.js +0 -172
  107. package/dist/node_modules/@isaacs/cliui/package.json +0 -163
  108. package/dist/node_modules/cross-spawn/LICENSE +0 -21
  109. package/dist/node_modules/cross-spawn/index.js +0 -39
  110. package/dist/node_modules/cross-spawn/lib/enoent.js +0 -59
  111. package/dist/node_modules/cross-spawn/lib/parse.js +0 -91
  112. package/dist/node_modules/cross-spawn/lib/util/escape.js +0 -47
  113. package/dist/node_modules/cross-spawn/lib/util/readShebang.js +0 -23
  114. package/dist/node_modules/cross-spawn/lib/util/resolveCommand.js +0 -52
  115. package/dist/node_modules/cross-spawn/package.json +0 -73
  116. package/dist/node_modules/encoding/.prettierrc.js +0 -8
  117. package/dist/node_modules/encoding/LICENSE +0 -16
  118. package/dist/node_modules/encoding/lib/encoding.js +0 -83
  119. package/dist/node_modules/encoding/package.json +0 -18
  120. package/dist/node_modules/err-code/.eslintrc.json +0 -7
  121. package/dist/node_modules/err-code/bower.json +0 -30
  122. package/dist/node_modules/err-code/index.js +0 -47
  123. package/dist/node_modules/err-code/index.umd.js +0 -51
  124. package/dist/node_modules/err-code/package.json +0 -34
  125. package/dist/node_modules/foreground-child/LICENSE +0 -15
  126. package/dist/node_modules/foreground-child/dist/commonjs/all-signals.js +0 -58
  127. package/dist/node_modules/foreground-child/dist/commonjs/index.js +0 -123
  128. package/dist/node_modules/foreground-child/dist/commonjs/proxy-signals.js +0 -38
  129. package/dist/node_modules/foreground-child/dist/commonjs/watchdog.js +0 -50
  130. package/dist/node_modules/foreground-child/dist/esm/all-signals.js +0 -52
  131. package/dist/node_modules/foreground-child/dist/esm/index.js +0 -115
  132. package/dist/node_modules/foreground-child/dist/esm/proxy-signals.js +0 -34
  133. package/dist/node_modules/foreground-child/dist/esm/watchdog.js +0 -46
  134. package/dist/node_modules/foreground-child/package.json +0 -106
  135. package/dist/node_modules/glob/dist/esm/bin.d.mts +0 -3
  136. package/dist/node_modules/glob/dist/esm/bin.mjs +0 -346
  137. package/dist/node_modules/iconv-lite/.github/dependabot.yml +0 -11
  138. package/dist/node_modules/iconv-lite/.idea/codeStyles/Project.xml +0 -47
  139. package/dist/node_modules/iconv-lite/.idea/codeStyles/codeStyleConfig.xml +0 -5
  140. package/dist/node_modules/iconv-lite/.idea/iconv-lite.iml +0 -12
  141. package/dist/node_modules/iconv-lite/.idea/inspectionProfiles/Project_Default.xml +0 -6
  142. package/dist/node_modules/iconv-lite/.idea/modules.xml +0 -8
  143. package/dist/node_modules/iconv-lite/.idea/vcs.xml +0 -6
  144. package/dist/node_modules/isexe/LICENSE +0 -15
  145. package/dist/node_modules/isexe/index.js +0 -57
  146. package/dist/node_modules/isexe/mode.js +0 -41
  147. package/dist/node_modules/isexe/windows.js +0 -42
  148. package/dist/node_modules/jackspeak/dist/commonjs/index.js +0 -944
  149. package/dist/node_modules/jackspeak/dist/commonjs/index.min.js +0 -33
  150. package/dist/node_modules/jackspeak/dist/commonjs/package.json +0 -3
  151. package/dist/node_modules/jackspeak/dist/esm/index.js +0 -936
  152. package/dist/node_modules/jackspeak/dist/esm/index.min.js +0 -33
  153. package/dist/node_modules/jackspeak/dist/esm/package.json +0 -3
  154. package/dist/node_modules/jackspeak/package.json +0 -115
  155. package/dist/node_modules/lru-cache/LICENSE +0 -15
  156. package/dist/node_modules/minipass/LICENSE +0 -15
  157. package/dist/node_modules/minipass-sized/index.js +0 -67
  158. package/dist/node_modules/minipass-sized/node_modules/minipass/LICENSE +0 -15
  159. package/dist/node_modules/minipass-sized/node_modules/minipass/index.js +0 -649
  160. package/dist/node_modules/minipass-sized/node_modules/minipass/package.json +0 -56
  161. package/dist/node_modules/minipass-sized/package-lock.json +0 -3464
  162. package/dist/node_modules/node-gyp/node_modules/isexe/dist/commonjs/package.json +0 -3
  163. package/dist/node_modules/node-gyp/node_modules/isexe/dist/esm/package.json +0 -3
  164. package/dist/node_modules/node-gyp/node_modules/isexe/package.json +0 -78
  165. package/dist/node_modules/node-gyp/node_modules/which/LICENSE +0 -15
  166. package/dist/node_modules/node-gyp/node_modules/which/package.json +0 -52
  167. package/dist/node_modules/package-json-from-dist/dist/commonjs/index.js +0 -134
  168. package/dist/node_modules/package-json-from-dist/dist/commonjs/package.json +0 -3
  169. package/dist/node_modules/package-json-from-dist/dist/esm/index.js +0 -129
  170. package/dist/node_modules/package-json-from-dist/dist/esm/package.json +0 -3
  171. package/dist/node_modules/package-json-from-dist/package.json +0 -68
  172. package/dist/node_modules/path-key/index.js +0 -16
  173. package/dist/node_modules/path-key/license +0 -9
  174. package/dist/node_modules/path-key/package.json +0 -39
  175. package/dist/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.js +0 -1589
  176. package/dist/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.min.js +0 -2
  177. package/dist/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/package.json +0 -3
  178. package/dist/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.js +0 -1585
  179. package/dist/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.min.js +0 -2
  180. package/dist/node_modules/path-scurry/node_modules/lru-cache/dist/esm/package.json +0 -3
  181. package/dist/node_modules/path-scurry/node_modules/lru-cache/package.json +0 -101
  182. package/dist/node_modules/promise-retry/index.js +0 -52
  183. package/dist/node_modules/promise-retry/package.json +0 -37
  184. package/dist/node_modules/retry/equation.gif +0 -0
  185. package/dist/node_modules/shebang-command/index.js +0 -19
  186. package/dist/node_modules/shebang-command/license +0 -9
  187. package/dist/node_modules/shebang-command/package.json +0 -34
  188. package/dist/node_modules/shebang-regex/index.js +0 -2
  189. package/dist/node_modules/shebang-regex/license +0 -9
  190. package/dist/node_modules/shebang-regex/package.json +0 -35
  191. package/dist/node_modules/signal-exit/LICENSE.txt +0 -16
  192. package/dist/node_modules/signal-exit/dist/cjs/browser.js +0 -10
  193. package/dist/node_modules/signal-exit/dist/cjs/index.js +0 -279
  194. package/dist/node_modules/signal-exit/dist/cjs/package.json +0 -3
  195. package/dist/node_modules/signal-exit/dist/cjs/signals.js +0 -42
  196. package/dist/node_modules/signal-exit/dist/mjs/browser.js +0 -4
  197. package/dist/node_modules/signal-exit/dist/mjs/index.js +0 -275
  198. package/dist/node_modules/signal-exit/dist/mjs/package.json +0 -3
  199. package/dist/node_modules/signal-exit/dist/mjs/signals.js +0 -39
  200. package/dist/node_modules/signal-exit/package.json +0 -106
  201. package/dist/node_modules/which/bin/node-which +0 -52
  202. package/dist/node_modules/which/which.js +0 -125
  203. /package/dist/node_modules/{promise-retry → @gar/promise-retry}/LICENSE +0 -0
  204. /package/dist/node_modules/{node-gyp/node_modules/isexe → isexe}/dist/commonjs/index.js +0 -0
  205. /package/dist/node_modules/{node-gyp/node_modules/isexe → isexe}/dist/commonjs/index.min.js +0 -0
  206. /package/dist/node_modules/{node-gyp/node_modules/isexe → isexe}/dist/commonjs/options.js +0 -0
  207. /package/dist/node_modules/{@isaacs/cliui → isexe}/dist/commonjs/package.json +0 -0
  208. /package/dist/node_modules/{node-gyp/node_modules/isexe → isexe}/dist/commonjs/posix.js +0 -0
  209. /package/dist/node_modules/{node-gyp/node_modules/isexe → isexe}/dist/commonjs/win32.js +0 -0
  210. /package/dist/node_modules/{node-gyp/node_modules/isexe → isexe}/dist/esm/index.js +0 -0
  211. /package/dist/node_modules/{node-gyp/node_modules/isexe → isexe}/dist/esm/index.min.js +0 -0
  212. /package/dist/node_modules/{node-gyp/node_modules/isexe → isexe}/dist/esm/options.js +0 -0
  213. /package/dist/node_modules/{@isaacs/cliui → isexe}/dist/esm/package.json +0 -0
  214. /package/dist/node_modules/{node-gyp/node_modules/isexe → isexe}/dist/esm/posix.js +0 -0
  215. /package/dist/node_modules/{node-gyp/node_modules/isexe → isexe}/dist/esm/win32.js +0 -0
  216. /package/dist/node_modules/{foreground-child → minipass-sized}/dist/commonjs/package.json +0 -0
  217. /package/dist/node_modules/{foreground-child → minipass-sized}/dist/esm/package.json +0 -0
  218. /package/dist/node_modules/{node-gyp/node_modules/which → which}/bin/which.js +0 -0
  219. /package/dist/node_modules/{node-gyp/node_modules/which → which}/lib/index.js +0 -0
@@ -1,8 +1,110 @@
1
1
  // parse a single path portion
2
+ var _a;
2
3
  import { parseClass } from './brace-expressions.js';
3
4
  import { unescape } from './unescape.js';
4
5
  const types = new Set(['!', '?', '+', '*', '@']);
5
6
  const isExtglobType = (c) => types.has(c);
7
+ const isExtglobAST = (c) => isExtglobType(c.type);
8
+ // Map of which extglob types can adopt the children of a nested extglob
9
+ //
10
+ // anything but ! can adopt a matching type:
11
+ // +(a|+(b|c)|d) => +(a|b|c|d)
12
+ // *(a|*(b|c)|d) => *(a|b|c|d)
13
+ // @(a|@(b|c)|d) => @(a|b|c|d)
14
+ // ?(a|?(b|c)|d) => ?(a|b|c|d)
15
+ //
16
+ // * can adopt anything, because 0 or repetition is allowed
17
+ // *(a|?(b|c)|d) => *(a|b|c|d)
18
+ // *(a|+(b|c)|d) => *(a|b|c|d)
19
+ // *(a|@(b|c)|d) => *(a|b|c|d)
20
+ //
21
+ // + can adopt @, because 1 or repetition is allowed
22
+ // +(a|@(b|c)|d) => +(a|b|c|d)
23
+ //
24
+ // + and @ CANNOT adopt *, because 0 would be allowed
25
+ // +(a|*(b|c)|d) => would match "", on *(b|c)
26
+ // @(a|*(b|c)|d) => would match "", on *(b|c)
27
+ //
28
+ // + and @ CANNOT adopt ?, because 0 would be allowed
29
+ // +(a|?(b|c)|d) => would match "", on ?(b|c)
30
+ // @(a|?(b|c)|d) => would match "", on ?(b|c)
31
+ //
32
+ // ? can adopt @, because 0 or 1 is allowed
33
+ // ?(a|@(b|c)|d) => ?(a|b|c|d)
34
+ //
35
+ // ? and @ CANNOT adopt * or +, because >1 would be allowed
36
+ // ?(a|*(b|c)|d) => would match bbb on *(b|c)
37
+ // @(a|*(b|c)|d) => would match bbb on *(b|c)
38
+ // ?(a|+(b|c)|d) => would match bbb on +(b|c)
39
+ // @(a|+(b|c)|d) => would match bbb on +(b|c)
40
+ //
41
+ // ! CANNOT adopt ! (nothing else can either)
42
+ // !(a|!(b|c)|d) => !(a|b|c|d) would fail to match on b (not not b|c)
43
+ //
44
+ // ! can adopt @
45
+ // !(a|@(b|c)|d) => !(a|b|c|d)
46
+ //
47
+ // ! CANNOT adopt *
48
+ // !(a|*(b|c)|d) => !(a|b|c|d) would match on bbb, not allowed
49
+ //
50
+ // ! CANNOT adopt +
51
+ // !(a|+(b|c)|d) => !(a|b|c|d) would match on bbb, not allowed
52
+ //
53
+ // ! CANNOT adopt ?
54
+ // x!(a|?(b|c)|d) => x!(a|b|c|d) would fail to match "x"
55
+ const adoptionMap = new Map([
56
+ ['!', ['@']],
57
+ ['?', ['?', '@']],
58
+ ['@', ['@']],
59
+ ['*', ['*', '+', '?', '@']],
60
+ ['+', ['+', '@']],
61
+ ]);
62
+ // nested extglobs that can be adopted in, but with the addition of
63
+ // a blank '' element.
64
+ const adoptionWithSpaceMap = new Map([
65
+ ['!', ['?']],
66
+ ['@', ['?']],
67
+ ['+', ['?', '*']],
68
+ ]);
69
+ // union of the previous two maps
70
+ const adoptionAnyMap = new Map([
71
+ ['!', ['?', '@']],
72
+ ['?', ['?', '@']],
73
+ ['@', ['?', '@']],
74
+ ['*', ['*', '+', '?', '@']],
75
+ ['+', ['+', '@', '?', '*']],
76
+ ]);
77
+ // Extglobs that can take over their parent if they are the only child
78
+ // the key is parent, value maps child to resulting extglob parent type
79
+ // '@' is omitted because it's a special case. An `@` extglob with a single
80
+ // member can always be usurped by that subpattern.
81
+ const usurpMap = new Map([
82
+ ['!', new Map([['!', '@']])],
83
+ [
84
+ '?',
85
+ new Map([
86
+ ['*', '*'],
87
+ ['+', '*'],
88
+ ]),
89
+ ],
90
+ [
91
+ '@',
92
+ new Map([
93
+ ['!', '!'],
94
+ ['?', '?'],
95
+ ['@', '@'],
96
+ ['*', '*'],
97
+ ['+', '+'],
98
+ ]),
99
+ ],
100
+ [
101
+ '+',
102
+ new Map([
103
+ ['?', '*'],
104
+ ['*', '*'],
105
+ ]),
106
+ ],
107
+ ]);
6
108
  // Patterns that get prepended to bind to the start of either the
7
109
  // entire string, or just a single path portion, to prevent dots
8
110
  // and/or traversal patterns, when needed.
@@ -26,6 +128,7 @@ const star = qmark + '*?';
26
128
  const starNoEmpty = qmark + '+?';
27
129
  // remove the \ chars that we added if we end up doing a nonmagic compare
28
130
  // const deslash = (s: string) => s.replace(/\\(.)/g, '$1')
131
+ let ID = 0;
29
132
  export class AST {
30
133
  type;
31
134
  #root;
@@ -41,6 +144,22 @@ export class AST {
41
144
  // set to true if it's an extglob with no children
42
145
  // (which really means one child of '')
43
146
  #emptyExt = false;
147
+ id = ++ID;
148
+ get depth() {
149
+ return (this.#parent?.depth ?? -1) + 1;
150
+ }
151
+ [Symbol.for('nodejs.util.inspect.custom')]() {
152
+ return {
153
+ '@@type': 'AST',
154
+ id: this.id,
155
+ type: this.type,
156
+ root: this.#root.id,
157
+ parent: this.#parent?.id,
158
+ depth: this.depth,
159
+ partsLength: this.#parts.length,
160
+ parts: this.#parts,
161
+ };
162
+ }
44
163
  constructor(type, parent, options = {}) {
45
164
  this.type = type;
46
165
  // extglobs are inherently magical
@@ -120,7 +239,7 @@ export class AST {
120
239
  continue;
121
240
  /* c8 ignore start */
122
241
  if (typeof p !== 'string' &&
123
- !(p instanceof AST && p.#parent === this)) {
242
+ !(p instanceof _a && p.#parent === this)) {
124
243
  throw new Error('invalid part: ' + p);
125
244
  }
126
245
  /* c8 ignore stop */
@@ -154,7 +273,7 @@ export class AST {
154
273
  const p = this.#parent;
155
274
  for (let i = 0; i < this.#parentIndex; i++) {
156
275
  const pp = p.#parts[i];
157
- if (!(pp instanceof AST && pp.type === '!')) {
276
+ if (!(pp instanceof _a && pp.type === '!')) {
158
277
  return false;
159
278
  }
160
279
  }
@@ -182,13 +301,14 @@ export class AST {
182
301
  this.push(part.clone(this));
183
302
  }
184
303
  clone(parent) {
185
- const c = new AST(this.type, parent);
304
+ const c = new _a(this.type, parent);
186
305
  for (const p of this.#parts) {
187
306
  c.copyIn(p);
188
307
  }
189
308
  return c;
190
309
  }
191
- static #parseAST(str, ast, pos, opt) {
310
+ static #parseAST(str, ast, pos, opt, extDepth) {
311
+ const maxDepth = opt.maxExtglobRecursion ?? 2;
192
312
  let escaping = false;
193
313
  let inBrace = false;
194
314
  let braceStart = -1;
@@ -225,11 +345,17 @@ export class AST {
225
345
  acc += c;
226
346
  continue;
227
347
  }
228
- if (!opt.noext && isExtglobType(c) && str.charAt(i) === '(') {
348
+ // we don't have to check for adoption here, because that's
349
+ // done at the other recursion point.
350
+ const doRecurse = !opt.noext &&
351
+ isExtglobType(c) &&
352
+ str.charAt(i) === '(' &&
353
+ extDepth <= maxDepth;
354
+ if (doRecurse) {
229
355
  ast.push(acc);
230
356
  acc = '';
231
- const ext = new AST(c, ast);
232
- i = AST.#parseAST(str, ext, i, opt);
357
+ const ext = new _a(c, ast);
358
+ i = _a.#parseAST(str, ext, i, opt, extDepth + 1);
233
359
  ast.push(ext);
234
360
  continue;
235
361
  }
@@ -241,7 +367,7 @@ export class AST {
241
367
  // some kind of extglob, pos is at the (
242
368
  // find the next | or )
243
369
  let i = pos + 1;
244
- let part = new AST(null, ast);
370
+ let part = new _a(null, ast);
245
371
  const parts = [];
246
372
  let acc = '';
247
373
  while (i < str.length) {
@@ -272,19 +398,26 @@ export class AST {
272
398
  acc += c;
273
399
  continue;
274
400
  }
275
- if (isExtglobType(c) && str.charAt(i) === '(') {
401
+ const doRecurse = !opt.noext &&
402
+ isExtglobType(c) &&
403
+ str.charAt(i) === '(' &&
404
+ /* c8 ignore start - the maxDepth is sufficient here */
405
+ (extDepth <= maxDepth || (ast && ast.#canAdoptType(c)));
406
+ /* c8 ignore stop */
407
+ if (doRecurse) {
408
+ const depthAdd = ast && ast.#canAdoptType(c) ? 0 : 1;
276
409
  part.push(acc);
277
410
  acc = '';
278
- const ext = new AST(c, part);
411
+ const ext = new _a(c, part);
279
412
  part.push(ext);
280
- i = AST.#parseAST(str, ext, i, opt);
413
+ i = _a.#parseAST(str, ext, i, opt, extDepth + depthAdd);
281
414
  continue;
282
415
  }
283
416
  if (c === '|') {
284
417
  part.push(acc);
285
418
  acc = '';
286
419
  parts.push(part);
287
- part = new AST(null, ast);
420
+ part = new _a(null, ast);
288
421
  continue;
289
422
  }
290
423
  if (c === ')') {
@@ -306,9 +439,82 @@ export class AST {
306
439
  ast.#parts = [str.substring(pos - 1)];
307
440
  return i;
308
441
  }
442
+ #canAdoptWithSpace(child) {
443
+ return this.#canAdopt(child, adoptionWithSpaceMap);
444
+ }
445
+ #canAdopt(child, map = adoptionMap) {
446
+ if (!child ||
447
+ typeof child !== 'object' ||
448
+ child.type !== null ||
449
+ child.#parts.length !== 1 ||
450
+ this.type === null) {
451
+ return false;
452
+ }
453
+ const gc = child.#parts[0];
454
+ if (!gc || typeof gc !== 'object' || gc.type === null) {
455
+ return false;
456
+ }
457
+ return this.#canAdoptType(gc.type, map);
458
+ }
459
+ #canAdoptType(c, map = adoptionAnyMap) {
460
+ return !!map.get(this.type)?.includes(c);
461
+ }
462
+ #adoptWithSpace(child, index) {
463
+ const gc = child.#parts[0];
464
+ const blank = new _a(null, gc, this.options);
465
+ blank.#parts.push('');
466
+ gc.push(blank);
467
+ this.#adopt(child, index);
468
+ }
469
+ #adopt(child, index) {
470
+ const gc = child.#parts[0];
471
+ this.#parts.splice(index, 1, ...gc.#parts);
472
+ for (const p of gc.#parts) {
473
+ if (typeof p === 'object')
474
+ p.#parent = this;
475
+ }
476
+ this.#toString = undefined;
477
+ }
478
+ #canUsurpType(c) {
479
+ const m = usurpMap.get(this.type);
480
+ return !!(m?.has(c));
481
+ }
482
+ #canUsurp(child) {
483
+ if (!child ||
484
+ typeof child !== 'object' ||
485
+ child.type !== null ||
486
+ child.#parts.length !== 1 ||
487
+ this.type === null ||
488
+ this.#parts.length !== 1) {
489
+ return false;
490
+ }
491
+ const gc = child.#parts[0];
492
+ if (!gc || typeof gc !== 'object' || gc.type === null) {
493
+ return false;
494
+ }
495
+ return this.#canUsurpType(gc.type);
496
+ }
497
+ #usurp(child) {
498
+ const m = usurpMap.get(this.type);
499
+ const gc = child.#parts[0];
500
+ const nt = m?.get(gc.type);
501
+ /* c8 ignore start - impossible */
502
+ if (!nt)
503
+ return false;
504
+ /* c8 ignore stop */
505
+ this.#parts = gc.#parts;
506
+ for (const p of this.#parts) {
507
+ if (typeof p === 'object') {
508
+ p.#parent = this;
509
+ }
510
+ }
511
+ this.type = nt;
512
+ this.#toString = undefined;
513
+ this.#emptyExt = false;
514
+ }
309
515
  static fromGlob(pattern, options = {}) {
310
- const ast = new AST(null, undefined, options);
311
- AST.#parseAST(pattern, ast, 0, options);
516
+ const ast = new _a(null, undefined, options);
517
+ _a.#parseAST(pattern, ast, 0, options, 0);
312
518
  return ast;
313
519
  }
314
520
  // returns the regular expression if there's magic, or the unescaped
@@ -412,16 +618,18 @@ export class AST {
412
618
  // or start or whatever) and prepend ^ or / at the Regexp construction.
413
619
  toRegExpSource(allowDot) {
414
620
  const dot = allowDot ?? !!this.#options.dot;
415
- if (this.#root === this)
621
+ if (this.#root === this) {
622
+ this.#flatten();
416
623
  this.#fillNegs();
417
- if (!this.type) {
624
+ }
625
+ if (!isExtglobAST(this)) {
418
626
  const noEmpty = this.isStart() &&
419
627
  this.isEnd() &&
420
628
  !this.#parts.some(s => typeof s !== 'string');
421
629
  const src = this.#parts
422
630
  .map(p => {
423
631
  const [re, _, hasMagic, uflag] = typeof p === 'string' ?
424
- AST.#parseGlob(p, this.#hasMagic, noEmpty)
632
+ _a.#parseGlob(p, this.#hasMagic, noEmpty)
425
633
  : p.toRegExpSource(allowDot);
426
634
  this.#hasMagic = this.#hasMagic || hasMagic;
427
635
  this.#uflag = this.#uflag || uflag;
@@ -483,12 +691,12 @@ export class AST {
483
691
  // invalid extglob, has to at least be *something* present, if it's
484
692
  // the entire path portion.
485
693
  const s = this.toString();
486
- this.#parts = [s];
487
- this.type = null;
488
- this.#hasMagic = undefined;
694
+ const me = this;
695
+ me.#parts = [s];
696
+ me.type = null;
697
+ me.#hasMagic = undefined;
489
698
  return [s, unescape(this.toString()), false, false];
490
699
  }
491
- // XXX abstract out this map method
492
700
  let bodyDotAllowed = !repeated || allowDot || dot || !startNoDot ?
493
701
  ''
494
702
  : this.#partsToRegExp(true);
@@ -524,6 +732,42 @@ export class AST {
524
732
  this.#uflag,
525
733
  ];
526
734
  }
735
+ #flatten() {
736
+ if (!isExtglobAST(this)) {
737
+ for (const p of this.#parts) {
738
+ if (typeof p === 'object') {
739
+ p.#flatten();
740
+ }
741
+ }
742
+ }
743
+ else {
744
+ // do up to 10 passes to flatten as much as possible
745
+ let iterations = 0;
746
+ let done = false;
747
+ do {
748
+ done = true;
749
+ for (let i = 0; i < this.#parts.length; i++) {
750
+ const c = this.#parts[i];
751
+ if (typeof c === 'object') {
752
+ c.#flatten();
753
+ if (this.#canAdopt(c)) {
754
+ done = false;
755
+ this.#adopt(c, i);
756
+ }
757
+ else if (this.#canAdoptWithSpace(c)) {
758
+ done = false;
759
+ this.#adoptWithSpace(c, i);
760
+ }
761
+ else if (this.#canUsurp(c)) {
762
+ done = false;
763
+ this.#usurp(c);
764
+ }
765
+ }
766
+ }
767
+ } while (!done && ++iterations < 10);
768
+ }
769
+ this.#toString = undefined;
770
+ }
527
771
  #partsToRegExp(dot) {
528
772
  return this.#parts
529
773
  .map(p => {
@@ -594,4 +838,5 @@ export class AST {
594
838
  return [re, unescape(glob), !!hasMagic, uflag];
595
839
  }
596
840
  }
841
+ _a = AST;
597
842
  //# sourceMappingURL=ast.js.map