@theia/plugin-ext 1.27.0-next.9 → 1.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (273) hide show
  1. package/lib/common/connection.d.ts +3 -3
  2. package/lib/common/connection.d.ts.map +1 -1
  3. package/lib/common/connection.js +0 -1
  4. package/lib/common/connection.js.map +1 -1
  5. package/lib/common/plugin-api-rpc.d.ts +18 -8
  6. package/lib/common/plugin-api-rpc.d.ts.map +1 -1
  7. package/lib/common/plugin-api-rpc.js.map +1 -1
  8. package/lib/common/plugin-identifiers.d.ts +41 -0
  9. package/lib/common/plugin-identifiers.d.ts.map +1 -0
  10. package/lib/common/plugin-identifiers.js +81 -0
  11. package/lib/common/plugin-identifiers.js.map +1 -0
  12. package/lib/common/plugin-protocol.d.ts +50 -11
  13. package/lib/common/plugin-protocol.d.ts.map +1 -1
  14. package/lib/common/plugin-protocol.js +3 -1
  15. package/lib/common/plugin-protocol.js.map +1 -1
  16. package/lib/hosted/browser/hosted-plugin.d.ts +2 -2
  17. package/lib/hosted/browser/hosted-plugin.d.ts.map +1 -1
  18. package/lib/hosted/browser/hosted-plugin.js +26 -18
  19. package/lib/hosted/browser/hosted-plugin.js.map +1 -1
  20. package/lib/hosted/browser/worker/debug-stub.d.ts +1 -1
  21. package/lib/hosted/browser/worker/debug-stub.d.ts.map +1 -1
  22. package/lib/hosted/browser/worker/debug-stub.js +2 -2
  23. package/lib/hosted/browser/worker/debug-stub.js.map +1 -1
  24. package/lib/hosted/browser/worker/plugin-manifest-loader.d.ts.map +1 -1
  25. package/lib/hosted/browser/worker/plugin-manifest-loader.js +4 -1
  26. package/lib/hosted/browser/worker/plugin-manifest-loader.js.map +1 -1
  27. package/lib/hosted/node/hosted-plugin-deployer-handler.d.ts +17 -9
  28. package/lib/hosted/node/hosted-plugin-deployer-handler.d.ts.map +1 -1
  29. package/lib/hosted/node/hosted-plugin-deployer-handler.js +99 -18
  30. package/lib/hosted/node/hosted-plugin-deployer-handler.js.map +1 -1
  31. package/lib/hosted/node/hosted-plugin-localization-service.d.ts.map +1 -1
  32. package/lib/hosted/node/hosted-plugin-localization-service.js +2 -4
  33. package/lib/hosted/node/hosted-plugin-localization-service.js.map +1 -1
  34. package/lib/hosted/node/hosted-plugin-process.d.ts +2 -2
  35. package/lib/hosted/node/hosted-plugin-process.d.ts.map +1 -1
  36. package/lib/hosted/node/hosted-plugin-process.js.map +1 -1
  37. package/lib/hosted/node/hosted-plugin.d.ts +2 -2
  38. package/lib/hosted/node/hosted-plugin.d.ts.map +1 -1
  39. package/lib/hosted/node/hosted-plugin.js.map +1 -1
  40. package/lib/hosted/node/metadata-scanner.d.ts +3 -2
  41. package/lib/hosted/node/metadata-scanner.d.ts.map +1 -1
  42. package/lib/hosted/node/metadata-scanner.js +8 -3
  43. package/lib/hosted/node/metadata-scanner.js.map +1 -1
  44. package/lib/hosted/node/plugin-host-rpc.js +2 -2
  45. package/lib/hosted/node/plugin-host-rpc.js.map +1 -1
  46. package/lib/hosted/node/plugin-manifest-loader.d.ts.map +1 -1
  47. package/lib/hosted/node/plugin-manifest-loader.js +3 -0
  48. package/lib/hosted/node/plugin-manifest-loader.js.map +1 -1
  49. package/lib/hosted/node/plugin-service.d.ts +18 -4
  50. package/lib/hosted/node/plugin-service.d.ts.map +1 -1
  51. package/lib/hosted/node/plugin-service.js +73 -18
  52. package/lib/hosted/node/plugin-service.js.map +1 -1
  53. package/lib/hosted/node/scanners/scanner-theia.d.ts.map +1 -1
  54. package/lib/hosted/node/scanners/scanner-theia.js +6 -3
  55. package/lib/hosted/node/scanners/scanner-theia.js.map +1 -1
  56. package/lib/main/browser/custom-editors/custom-editor-opener.d.ts.map +1 -1
  57. package/lib/main/browser/custom-editors/custom-editor-opener.js +2 -2
  58. package/lib/main/browser/custom-editors/custom-editor-opener.js.map +1 -1
  59. package/lib/main/browser/debug/plugin-debug-session-factory.d.ts +3 -3
  60. package/lib/main/browser/debug/plugin-debug-session-factory.d.ts.map +1 -1
  61. package/lib/main/browser/debug/plugin-debug-session-factory.js.map +1 -1
  62. package/lib/main/browser/documents-main.d.ts +1 -2
  63. package/lib/main/browser/documents-main.d.ts.map +1 -1
  64. package/lib/main/browser/documents-main.js +26 -6
  65. package/lib/main/browser/documents-main.js.map +1 -1
  66. package/lib/main/browser/editors-and-documents-main.d.ts +2 -0
  67. package/lib/main/browser/editors-and-documents-main.d.ts.map +1 -1
  68. package/lib/main/browser/editors-and-documents-main.js +14 -2
  69. package/lib/main/browser/editors-and-documents-main.js.map +1 -1
  70. package/lib/main/browser/languages-main.d.ts.map +1 -1
  71. package/lib/main/browser/languages-main.js +2 -1
  72. package/lib/main/browser/languages-main.js.map +1 -1
  73. package/lib/main/browser/main-context.d.ts.map +1 -1
  74. package/lib/main/browser/main-context.js +5 -4
  75. package/lib/main/browser/main-context.js.map +1 -1
  76. package/lib/main/browser/plugin-contribution-handler.d.ts +2 -0
  77. package/lib/main/browser/plugin-contribution-handler.d.ts.map +1 -1
  78. package/lib/main/browser/plugin-contribution-handler.js +36 -1
  79. package/lib/main/browser/plugin-contribution-handler.js.map +1 -1
  80. package/lib/main/browser/plugin-shared-style.d.ts +4 -2
  81. package/lib/main/browser/plugin-shared-style.d.ts.map +1 -1
  82. package/lib/main/browser/plugin-shared-style.js +15 -4
  83. package/lib/main/browser/plugin-shared-style.js.map +1 -1
  84. package/lib/main/browser/text-editors-main.d.ts +6 -3
  85. package/lib/main/browser/text-editors-main.d.ts.map +1 -1
  86. package/lib/main/browser/text-editors-main.js +8 -1
  87. package/lib/main/browser/text-editors-main.js.map +1 -1
  88. package/lib/main/browser/theming-main.d.ts +2 -1
  89. package/lib/main/browser/theming-main.d.ts.map +1 -1
  90. package/lib/main/browser/theming-main.js +3 -6
  91. package/lib/main/browser/theming-main.js.map +1 -1
  92. package/lib/main/browser/view/plugin-tree-view-node-label-provider.d.ts.map +1 -1
  93. package/lib/main/browser/view/plugin-tree-view-node-label-provider.js +7 -5
  94. package/lib/main/browser/view/plugin-tree-view-node-label-provider.js.map +1 -1
  95. package/lib/main/browser/view/plugin-view-registry.d.ts +1 -1
  96. package/lib/main/browser/view/plugin-view-registry.d.ts.map +1 -1
  97. package/lib/main/browser/view/plugin-view-registry.js +11 -6
  98. package/lib/main/browser/view/plugin-view-registry.js.map +1 -1
  99. package/lib/main/browser/view/tree-view-widget.d.ts +10 -5
  100. package/lib/main/browser/view/tree-view-widget.d.ts.map +1 -1
  101. package/lib/main/browser/view/tree-view-widget.js +40 -14
  102. package/lib/main/browser/view/tree-view-widget.js.map +1 -1
  103. package/lib/main/browser/webview/webview-theme-data-provider.d.ts +3 -1
  104. package/lib/main/browser/webview/webview-theme-data-provider.d.ts.map +1 -1
  105. package/lib/main/browser/webview/webview-theme-data-provider.js +5 -1
  106. package/lib/main/browser/webview/webview-theme-data-provider.js.map +1 -1
  107. package/lib/main/node/handlers/plugin-theia-directory-handler.d.ts +6 -1
  108. package/lib/main/node/handlers/plugin-theia-directory-handler.d.ts.map +1 -1
  109. package/lib/main/node/handlers/plugin-theia-directory-handler.js +61 -20
  110. package/lib/main/node/handlers/plugin-theia-directory-handler.js.map +1 -1
  111. package/lib/main/node/handlers/plugin-theia-file-handler.d.ts +4 -0
  112. package/lib/main/node/handlers/plugin-theia-file-handler.d.ts.map +1 -1
  113. package/lib/main/node/handlers/plugin-theia-file-handler.js +26 -4
  114. package/lib/main/node/handlers/plugin-theia-file-handler.js.map +1 -1
  115. package/lib/main/node/plugin-cli-contribution.d.ts +3 -0
  116. package/lib/main/node/plugin-cli-contribution.d.ts.map +1 -1
  117. package/lib/main/node/plugin-cli-contribution.js +13 -0
  118. package/lib/main/node/plugin-cli-contribution.js.map +1 -1
  119. package/lib/main/node/plugin-deployer-directory-handler-context-impl.d.ts +1 -0
  120. package/lib/main/node/plugin-deployer-directory-handler-context-impl.d.ts.map +1 -1
  121. package/lib/main/node/plugin-deployer-directory-handler-context-impl.js +17 -0
  122. package/lib/main/node/plugin-deployer-directory-handler-context-impl.js.map +1 -1
  123. package/lib/main/node/plugin-deployer-file-handler-context-impl.d.ts.map +1 -1
  124. package/lib/main/node/plugin-deployer-file-handler-context-impl.js +0 -1
  125. package/lib/main/node/plugin-deployer-file-handler-context-impl.js.map +1 -1
  126. package/lib/main/node/plugin-deployer-impl.d.ts +10 -7
  127. package/lib/main/node/plugin-deployer-impl.d.ts.map +1 -1
  128. package/lib/main/node/plugin-deployer-impl.js +84 -38
  129. package/lib/main/node/plugin-deployer-impl.js.map +1 -1
  130. package/lib/main/node/plugin-ext-backend-module.d.ts.map +1 -1
  131. package/lib/main/node/plugin-ext-backend-module.js +2 -0
  132. package/lib/main/node/plugin-ext-backend-module.js.map +1 -1
  133. package/lib/main/node/plugin-server-handler.d.ts +5 -4
  134. package/lib/main/node/plugin-server-handler.d.ts.map +1 -1
  135. package/lib/main/node/plugin-server-handler.js +12 -5
  136. package/lib/main/node/plugin-server-handler.js.map +1 -1
  137. package/lib/main/node/plugin-uninstallation-manager.d.ts +15 -0
  138. package/lib/main/node/plugin-uninstallation-manager.d.ts.map +1 -0
  139. package/lib/main/node/plugin-uninstallation-manager.js +85 -0
  140. package/lib/main/node/plugin-uninstallation-manager.js.map +1 -0
  141. package/lib/plugin/{node/debug/debug.d.ts → debug/debug-ext.d.ts} +15 -13
  142. package/lib/plugin/debug/debug-ext.d.ts.map +1 -0
  143. package/lib/plugin/{node/debug/debug.js → debug/debug-ext.js} +17 -51
  144. package/lib/plugin/debug/debug-ext.js.map +1 -0
  145. package/lib/plugin/debug/plugin-debug-adapter-creator.d.ts +11 -0
  146. package/lib/plugin/debug/plugin-debug-adapter-creator.d.ts.map +1 -0
  147. package/lib/plugin/debug/plugin-debug-adapter-creator.js +42 -0
  148. package/lib/plugin/debug/plugin-debug-adapter-creator.js.map +1 -0
  149. package/lib/plugin/{node/debug → debug}/plugin-debug-adapter-session.d.ts +4 -4
  150. package/lib/plugin/debug/plugin-debug-adapter-session.d.ts.map +1 -0
  151. package/lib/plugin/{node/debug → debug}/plugin-debug-adapter-session.js +1 -1
  152. package/lib/plugin/debug/plugin-debug-adapter-session.js.map +1 -0
  153. package/lib/plugin/{node/debug → debug}/plugin-debug-adapter-tracker.d.ts +0 -0
  154. package/lib/plugin/debug/plugin-debug-adapter-tracker.d.ts.map +1 -0
  155. package/lib/plugin/{node/debug → debug}/plugin-debug-adapter-tracker.js +0 -0
  156. package/lib/plugin/debug/plugin-debug-adapter-tracker.js.map +1 -0
  157. package/lib/plugin/languages-utils.d.ts.map +1 -1
  158. package/lib/plugin/languages-utils.js +3 -2
  159. package/lib/plugin/languages-utils.js.map +1 -1
  160. package/lib/plugin/node/debug/plugin-node-debug-adapter-creator.d.ts +18 -0
  161. package/lib/plugin/node/debug/plugin-node-debug-adapter-creator.d.ts.map +1 -0
  162. package/lib/plugin/node/debug/plugin-node-debug-adapter-creator.js +155 -0
  163. package/lib/plugin/node/debug/plugin-node-debug-adapter-creator.js.map +1 -0
  164. package/lib/plugin/plugin-context.d.ts +1 -1
  165. package/lib/plugin/plugin-context.d.ts.map +1 -1
  166. package/lib/plugin/plugin-context.js +1 -2
  167. package/lib/plugin/plugin-context.js.map +1 -1
  168. package/lib/plugin/plugin-manager.d.ts.map +1 -1
  169. package/lib/plugin/plugin-manager.js +5 -9
  170. package/lib/plugin/plugin-manager.js.map +1 -1
  171. package/lib/plugin/text-editor.d.ts +2 -0
  172. package/lib/plugin/text-editor.d.ts.map +1 -1
  173. package/lib/plugin/text-editor.js +9 -0
  174. package/lib/plugin/text-editor.js.map +1 -1
  175. package/lib/plugin/theming.d.ts +1 -1
  176. package/lib/plugin/theming.d.ts.map +1 -1
  177. package/lib/plugin/tree/tree-views.d.ts +1 -0
  178. package/lib/plugin/tree/tree-views.d.ts.map +1 -1
  179. package/lib/plugin/tree/tree-views.js +10 -9
  180. package/lib/plugin/tree/tree-views.js.map +1 -1
  181. package/lib/plugin/types-impl.d.ts +1 -0
  182. package/lib/plugin/types-impl.d.ts.map +1 -1
  183. package/lib/plugin/types-impl.js +3 -2
  184. package/lib/plugin/types-impl.js.map +1 -1
  185. package/package.json +26 -25
  186. package/src/common/connection.ts +3 -4
  187. package/src/common/plugin-api-rpc.ts +20 -12
  188. package/src/common/plugin-identifiers.ts +84 -0
  189. package/src/common/plugin-protocol.ts +57 -12
  190. package/src/hosted/browser/hosted-plugin.ts +28 -21
  191. package/src/hosted/browser/worker/debug-stub.ts +1 -1
  192. package/src/hosted/browser/worker/plugin-manifest-loader.ts +4 -2
  193. package/src/hosted/node/hosted-plugin-deployer-handler.ts +109 -28
  194. package/src/hosted/node/hosted-plugin-localization-service.ts +4 -6
  195. package/src/hosted/node/hosted-plugin-process.ts +4 -4
  196. package/src/hosted/node/hosted-plugin.ts +2 -2
  197. package/src/hosted/node/metadata-scanner.ts +8 -6
  198. package/src/hosted/node/plugin-host-rpc.ts +2 -2
  199. package/src/hosted/node/plugin-manifest-loader.ts +2 -0
  200. package/src/hosted/node/plugin-service.ts +79 -23
  201. package/src/hosted/node/scanners/scanner-theia.ts +7 -4
  202. package/src/main/browser/custom-editors/custom-editor-opener.tsx +2 -2
  203. package/src/main/browser/debug/plugin-debug-session-factory.ts +2 -2
  204. package/src/main/browser/documents-main.ts +26 -8
  205. package/src/main/browser/editors-and-documents-main.ts +16 -2
  206. package/src/main/browser/languages-main.ts +2 -1
  207. package/src/main/browser/main-context.ts +4 -3
  208. package/src/main/browser/plugin-contribution-handler.ts +41 -3
  209. package/src/main/browser/plugin-icon-theme-service.ts +1 -1
  210. package/src/main/browser/plugin-shared-style.ts +9 -5
  211. package/src/main/browser/text-editors-main.ts +12 -2
  212. package/src/main/browser/theming-main.ts +3 -7
  213. package/src/main/browser/view/plugin-tree-view-node-label-provider.ts +7 -5
  214. package/src/main/browser/view/plugin-view-registry.ts +12 -7
  215. package/src/main/browser/view/tree-view-widget.tsx +45 -17
  216. package/src/main/browser/webview/webview-theme-data-provider.ts +7 -10
  217. package/src/main/node/handlers/plugin-theia-directory-handler.ts +56 -28
  218. package/src/main/node/handlers/plugin-theia-file-handler.ts +26 -4
  219. package/src/main/node/plugin-cli-contribution.ts +12 -0
  220. package/src/main/node/plugin-deployer-directory-handler-context-impl.ts +17 -1
  221. package/src/main/node/plugin-deployer-file-handler-context-impl.ts +0 -1
  222. package/src/main/node/plugin-deployer-impl.ts +88 -41
  223. package/src/main/node/plugin-ext-backend-module.ts +3 -0
  224. package/src/main/node/plugin-server-handler.ts +15 -7
  225. package/src/main/node/plugin-uninstallation-manager.ts +74 -0
  226. package/src/plugin/{node/debug/debug.ts → debug/debug-ext.ts} +25 -56
  227. package/src/plugin/debug/plugin-debug-adapter-creator.ts +50 -0
  228. package/src/plugin/{node/debug → debug}/plugin-debug-adapter-session.ts +4 -4
  229. package/src/plugin/{node/debug → debug}/plugin-debug-adapter-tracker.ts +0 -0
  230. package/src/plugin/languages-utils.ts +3 -2
  231. package/src/plugin/node/debug/plugin-node-debug-adapter-creator.ts +167 -0
  232. package/src/plugin/plugin-context.ts +2 -3
  233. package/src/plugin/plugin-manager.ts +5 -9
  234. package/src/plugin/text-editor.ts +16 -5
  235. package/src/plugin/theming.ts +1 -1
  236. package/src/plugin/tree/tree-views.ts +15 -12
  237. package/src/plugin/types-impl.ts +1 -1
  238. package/lib/main/browser/custom-editors/glob.d.ts +0 -51
  239. package/lib/main/browser/custom-editors/glob.d.ts.map +0 -1
  240. package/lib/main/browser/custom-editors/glob.js +0 -593
  241. package/lib/main/browser/custom-editors/glob.js.map +0 -1
  242. package/lib/main/browser/custom-editors/paths.d.ts +0 -25
  243. package/lib/main/browser/custom-editors/paths.d.ts.map +0 -1
  244. package/lib/main/browser/custom-editors/paths.js +0 -227
  245. package/lib/main/browser/custom-editors/paths.js.map +0 -1
  246. package/lib/main/browser/editor/untitled-resource.d.ts +0 -3
  247. package/lib/main/browser/editor/untitled-resource.d.ts.map +0 -1
  248. package/lib/main/browser/editor/untitled-resource.js +0 -24
  249. package/lib/main/browser/editor/untitled-resource.js.map +0 -1
  250. package/lib/plugin/node/debug/debug.d.ts.map +0 -1
  251. package/lib/plugin/node/debug/debug.js.map +0 -1
  252. package/lib/plugin/node/debug/plugin-debug-adapter-executable-resolver.d.ts +0 -7
  253. package/lib/plugin/node/debug/plugin-debug-adapter-executable-resolver.d.ts.map +0 -1
  254. package/lib/plugin/node/debug/plugin-debug-adapter-executable-resolver.js +0 -57
  255. package/lib/plugin/node/debug/plugin-debug-adapter-executable-resolver.js.map +0 -1
  256. package/lib/plugin/node/debug/plugin-debug-adapter-session.d.ts.map +0 -1
  257. package/lib/plugin/node/debug/plugin-debug-adapter-session.js.map +0 -1
  258. package/lib/plugin/node/debug/plugin-debug-adapter-starter.d.ts +0 -15
  259. package/lib/plugin/node/debug/plugin-debug-adapter-starter.d.ts.map +0 -1
  260. package/lib/plugin/node/debug/plugin-debug-adapter-starter.js +0 -85
  261. package/lib/plugin/node/debug/plugin-debug-adapter-starter.js.map +0 -1
  262. package/lib/plugin/node/debug/plugin-debug-adapter-tracker.d.ts.map +0 -1
  263. package/lib/plugin/node/debug/plugin-debug-adapter-tracker.js.map +0 -1
  264. package/lib/plugin/node/debug/plugin-inline-debug-adapter.d.ts +0 -19
  265. package/lib/plugin/node/debug/plugin-inline-debug-adapter.d.ts.map +0 -1
  266. package/lib/plugin/node/debug/plugin-inline-debug-adapter.js +0 -45
  267. package/lib/plugin/node/debug/plugin-inline-debug-adapter.js.map +0 -1
  268. package/src/main/browser/custom-editors/glob.ts +0 -743
  269. package/src/main/browser/custom-editors/paths.ts +0 -250
  270. package/src/main/browser/editor/untitled-resource.ts +0 -18
  271. package/src/plugin/node/debug/plugin-debug-adapter-executable-resolver.ts +0 -58
  272. package/src/plugin/node/debug/plugin-debug-adapter-starter.ts +0 -86
  273. package/src/plugin/node/debug/plugin-inline-debug-adapter.ts +0 -47
@@ -1,743 +0,0 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2021 SAP SE or an SAP affiliate company and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
- // copied from https://github.com/Microsoft/vscode/blob/bf7ac9201e7a7d01741d4e6e64b5dc9f3197d97b/src/vs/base/common/glob.ts
17
- /*---------------------------------------------------------------------------------------------
18
- * Copyright (c) Microsoft Corporation. All rights reserved.
19
- * Licensed under the MIT License. See License.txt in the project root for license information.
20
- *--------------------------------------------------------------------------------------------*/
21
- 'use strict';
22
-
23
- import * as strings from '@theia/core/lib/common/strings';
24
- import * as paths from './paths';
25
- import { CharCode } from '@theia/core/lib/common/char-code';
26
-
27
- /* eslint-disable @typescript-eslint/no-shadow, no-null/no-null */
28
-
29
- export interface IExpression {
30
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
- [pattern: string]: boolean | SiblingClause | any;
32
- }
33
-
34
- export interface IRelativePattern {
35
- base: string;
36
- pattern: string;
37
- pathToRelative(from: string, to: string): string;
38
- }
39
-
40
- export function getEmptyExpression(): IExpression {
41
- return Object.create(null);
42
- }
43
-
44
- export interface SiblingClause {
45
- when: string;
46
- }
47
-
48
- const GLOBSTAR = '**';
49
- const GLOB_SPLIT = '/';
50
- const PATH_REGEX = '[/\\\\]'; // any slash or backslash
51
- const NO_PATH_REGEX = '[^/\\\\]'; // any non-slash and non-backslash
52
- const ALL_FORWARD_SLASHES = /\//g;
53
-
54
- function starsToRegExp(starCount: number): string {
55
- switch (starCount) {
56
- case 0:
57
- return '';
58
- case 1:
59
- return `${NO_PATH_REGEX}*?`; // 1 star matches any number of characters except path separator (/ and \) - non greedy (?)
60
- default:
61
- // Matches: (Path Sep OR Path Val followed by Path Sep OR Path Sep followed by Path Val) 0-many times
62
- // Group is non capturing because we don't need to capture at all (?:...)
63
- // Overall we use non-greedy matching because it could be that we match too much
64
- return `(?:${PATH_REGEX}|${NO_PATH_REGEX}+${PATH_REGEX}|${PATH_REGEX}${NO_PATH_REGEX}+)*?`;
65
- }
66
- }
67
-
68
- export function splitGlobAware(pattern: string, splitChar: string): string[] {
69
- if (!pattern) {
70
- return [];
71
- }
72
-
73
- const segments: string[] = [];
74
-
75
- let inBraces = false;
76
- let inBrackets = false;
77
-
78
- let char: string;
79
- let curVal = '';
80
- for (let i = 0; i < pattern.length; i++) {
81
- char = pattern[i];
82
-
83
- switch (char) {
84
- case splitChar:
85
- if (!inBraces && !inBrackets) {
86
- segments.push(curVal);
87
- curVal = '';
88
-
89
- continue;
90
- }
91
- break;
92
- case '{':
93
- inBraces = true;
94
- break;
95
- case '}':
96
- inBraces = false;
97
- break;
98
- case '[':
99
- inBrackets = true;
100
- break;
101
- case ']':
102
- inBrackets = false;
103
- break;
104
- }
105
-
106
- curVal += char;
107
- }
108
-
109
- // Tail
110
- if (curVal) {
111
- segments.push(curVal);
112
- }
113
-
114
- return segments;
115
- }
116
-
117
- function parseRegExp(pattern: string): string {
118
- if (!pattern) {
119
- return '';
120
- }
121
-
122
- let regEx = '';
123
-
124
- // Split up into segments for each slash found
125
- // eslint-disable-next-line prefer-const
126
- let segments = splitGlobAware(pattern, GLOB_SPLIT);
127
-
128
- // Special case where we only have globstars
129
- if (segments.every(s => s === GLOBSTAR)) {
130
- regEx = '.*';
131
- }
132
-
133
- // Build regex over segments
134
- // tslint:disable-next-line:one-line
135
- else {
136
- let previousSegmentWasGlobStar = false;
137
- segments.forEach((segment, index) => {
138
-
139
- // Globstar is special
140
- if (segment === GLOBSTAR) {
141
-
142
- // if we have more than one globstar after another, just ignore it
143
- if (!previousSegmentWasGlobStar) {
144
- regEx += starsToRegExp(2);
145
- previousSegmentWasGlobStar = true;
146
- }
147
-
148
- return;
149
- }
150
-
151
- // States
152
- let inBraces = false;
153
- let braceVal = '';
154
-
155
- let inBrackets = false;
156
- let bracketVal = '';
157
-
158
- let char: string;
159
- for (let i = 0; i < segment.length; i++) {
160
- char = segment[i];
161
-
162
- // Support brace expansion
163
- if (char !== '}' && inBraces) {
164
- braceVal += char;
165
- continue;
166
- }
167
-
168
- // Support brackets
169
- if (inBrackets && (char !== ']' || !bracketVal) /* ] is literally only allowed as first character in brackets to match it */) {
170
- let res: string;
171
-
172
- // range operator
173
- if (char === '-') {
174
- res = char;
175
- }
176
-
177
- // negation operator (only valid on first index in bracket)
178
- // tslint:disable-next-line:one-line
179
- else if ((char === '^' || char === '!') && !bracketVal) {
180
- res = '^';
181
- }
182
-
183
- // glob split matching is not allowed within character ranges
184
- // see http://man7.org/linux/man-pages/man7/glob.7.html
185
- // tslint:disable-next-line:one-line
186
- else if (char === GLOB_SPLIT) {
187
- res = '';
188
- }
189
-
190
- // anything else gets escaped
191
- // tslint:disable-next-line:one-line
192
- else {
193
- res = strings.escapeRegExpCharacters(char);
194
- }
195
-
196
- bracketVal += res;
197
- continue;
198
- }
199
-
200
- switch (char) {
201
- case '{':
202
- inBraces = true;
203
- continue;
204
-
205
- case '[':
206
- inBrackets = true;
207
- continue;
208
-
209
- case '}':
210
- // eslint-disable-next-line prefer-const
211
- let choices = splitGlobAware(braceVal, ',');
212
-
213
- // Converts {foo,bar} => [foo|bar]
214
- // eslint-disable-next-line prefer-const
215
- let braceRegExp = `(?:${choices.map(c => parseRegExp(c)).join('|')})`;
216
-
217
- regEx += braceRegExp;
218
-
219
- inBraces = false;
220
- braceVal = '';
221
-
222
- break;
223
-
224
- case ']':
225
- regEx += ('[' + bracketVal + ']');
226
-
227
- inBrackets = false;
228
- bracketVal = '';
229
-
230
- break;
231
-
232
- case '?':
233
- regEx += NO_PATH_REGEX; // 1 ? matches any single character except path separator (/ and \)
234
- continue;
235
-
236
- case '*':
237
- regEx += starsToRegExp(1);
238
- continue;
239
-
240
- default:
241
- regEx += strings.escapeRegExpCharacters(char);
242
- }
243
- }
244
-
245
- // Tail: Add the slash we had split on if there is more to come and the remaining pattern is not a globstar
246
- // For example if pattern: some/**/*.js we want the "/" after some to be included in the RegEx to prevent
247
- // a folder called "something" to match as well.
248
- // However, if pattern: some/**, we tolerate that we also match on "something" because our globstar behavior
249
- // is to match 0-N segments.
250
- if (index < segments.length - 1 && (segments[index + 1] !== GLOBSTAR || index + 2 < segments.length)) {
251
- regEx += PATH_REGEX;
252
- }
253
-
254
- // reset state
255
- previousSegmentWasGlobStar = false;
256
- });
257
- }
258
-
259
- return regEx;
260
- }
261
-
262
- // regexes to check for trivial glob patterns that just check for String#endsWith
263
- const T1 = /^\*\*\/\*\.[\w\.-]+$/; // **/*.something
264
- const T2 = /^\*\*\/([\w\.-]+)\/?$/; // **/something
265
- const T3 = /^{\*\*\/[\*\.]?[\w\.-]+\/?(,\*\*\/[\*\.]?[\w\.-]+\/?)*}$/; // {**/*.something,**/*.else} or {**/package.json,**/project.json}
266
- const T3_2 = /^{\*\*\/[\*\.]?[\w\.-]+(\/(\*\*)?)?(,\*\*\/[\*\.]?[\w\.-]+(\/(\*\*)?)?)*}$/; // Like T3, with optional trailing /**
267
- const T4 = /^\*\*((\/[\w\.-]+)+)\/?$/; // **/something/else
268
- const T5 = /^([\w\.-]+(\/[\w\.-]+)*)\/?$/; // something/else
269
-
270
- export type ParsedPattern = (path: string, basename?: string) => boolean;
271
-
272
- // The ParsedExpression returns a Promise iff hasSibling returns a Promise.
273
- // eslint-disable-next-line max-len
274
- export type ParsedExpression = (path: string, basename?: string, hasSibling?: (name: string) => boolean | Promise<boolean>) => string | Promise<string> /* the matching pattern */;
275
-
276
- export interface IGlobOptions {
277
- /**
278
- * Simplify patterns for use as exclusion filters during tree traversal to skip entire subtrees. Cannot be used outside of a tree traversal.
279
- */
280
- trimForExclusions?: boolean;
281
- }
282
-
283
- interface ParsedStringPattern {
284
- (path: string, basename: string): string | Promise<string> /* the matching pattern */;
285
- basenames?: string[];
286
- patterns?: string[];
287
- allBasenames?: string[];
288
- allPaths?: string[];
289
- }
290
- interface ParsedExpressionPattern {
291
- (path: string, basename: string, name: string, hasSibling: (name: string) => boolean | Promise<boolean>): string | Promise<string> /* the matching pattern */;
292
- requiresSiblings?: boolean;
293
- allBasenames?: string[];
294
- allPaths?: string[];
295
- }
296
-
297
- const CACHE = new Map<string, ParsedStringPattern>(); // new LRUCache<string, ParsedStringPattern>(10000); // bounded to 10000 elements
298
-
299
- const FALSE = function (): boolean {
300
- return false;
301
- };
302
-
303
- const NULL = function (): string {
304
- return null!;
305
- };
306
-
307
- function parsePattern(arg1: string | IRelativePattern, options: IGlobOptions): ParsedStringPattern {
308
- if (!arg1) {
309
- return NULL;
310
- }
311
-
312
- // Handle IRelativePattern
313
- let pattern: string;
314
- if (typeof arg1 !== 'string') {
315
- pattern = arg1.pattern;
316
- } else {
317
- pattern = arg1;
318
- }
319
-
320
- // Whitespace trimming
321
- pattern = pattern.trim();
322
-
323
- // Check cache
324
- const patternKey = `${pattern}_${!!options.trimForExclusions}`;
325
- let parsedPattern = CACHE.get(patternKey);
326
- if (parsedPattern) {
327
- return wrapRelativePattern(parsedPattern, arg1);
328
- }
329
-
330
- // Check for Trivias
331
- let match: RegExpExecArray;
332
- if (T1.test(pattern)) { // common pattern: **/*.txt just need endsWith check
333
- const base = pattern.substr(4); // '**/*'.length === 4
334
- parsedPattern = function (path, basename): string {
335
- return path && strings.endsWith(path, base) ? pattern : null!;
336
- };
337
- } else if (match = T2.exec(trimForExclusions(pattern, options))!) { // common pattern: **/some.txt just need basename check
338
- parsedPattern = trivia2(match[1], pattern);
339
- } else if ((options.trimForExclusions ? T3_2 : T3).test(pattern)) { // repetition of common patterns (see above) {**/*.txt,**/*.png}
340
- parsedPattern = trivia3(pattern, options);
341
- } else if (match = T4.exec(trimForExclusions(pattern, options))!) { // common pattern: **/something/else just need endsWith check
342
- parsedPattern = trivia4and5(match[1].substr(1), pattern, true);
343
- } else if (match = T5.exec(trimForExclusions(pattern, options))!) { // common pattern: something/else just need equals check
344
- parsedPattern = trivia4and5(match[1], pattern, false);
345
- }
346
-
347
- // Otherwise convert to pattern
348
- // tslint:disable-next-line:one-line
349
- else {
350
- parsedPattern = toRegExp(pattern);
351
- }
352
-
353
- // Cache
354
- CACHE.set(patternKey, parsedPattern);
355
-
356
- return wrapRelativePattern(parsedPattern, arg1);
357
- }
358
-
359
- function wrapRelativePattern(parsedPattern: ParsedStringPattern, arg2: string | IRelativePattern): ParsedStringPattern {
360
- if (typeof arg2 === 'string') {
361
- return parsedPattern;
362
- }
363
-
364
- return function (path, basename): string | Promise<string> {
365
- if (!paths.isEqualOrParent(path, arg2.base)) {
366
- return null!;
367
- }
368
-
369
- return parsedPattern(paths.normalize(arg2.pathToRelative(arg2.base, path)), basename);
370
- };
371
- }
372
-
373
- function trimForExclusions(pattern: string, options: IGlobOptions): string {
374
- return options.trimForExclusions && strings.endsWith(pattern, '/**') ? pattern.substr(0, pattern.length - 2) : pattern; // dropping **, tailing / is dropped later
375
- }
376
-
377
- // common pattern: **/some.txt just need basename check
378
- function trivia2(base: string, originalPattern: string): ParsedStringPattern {
379
- const slashBase = `/${base}`;
380
- const backslashBase = `\\${base}`;
381
- const parsedPattern: ParsedStringPattern = function (path, basename): string {
382
- if (!path) {
383
- return null!;
384
- }
385
- if (basename) {
386
- return basename === base ? originalPattern : null!;
387
- }
388
- return path === base || strings.endsWith(path, slashBase) || strings.endsWith(path, backslashBase) ? originalPattern : null!;
389
- };
390
- const basenames = [base];
391
- parsedPattern.basenames = basenames;
392
- parsedPattern.patterns = [originalPattern];
393
- parsedPattern.allBasenames = basenames;
394
- return parsedPattern;
395
- }
396
-
397
- // repetition of common patterns (see above) {**/*.txt,**/*.png}
398
- function trivia3(pattern: string, options: IGlobOptions): ParsedStringPattern {
399
- const parsedPatterns = aggregateBasenameMatches(pattern.slice(1, -1).split(',')
400
- .map(pattern => parsePattern(pattern, options))
401
- .filter(pattern => pattern !== NULL), pattern);
402
- const n = parsedPatterns.length;
403
- if (!n) {
404
- return NULL;
405
- }
406
- if (n === 1) {
407
- return <ParsedStringPattern>parsedPatterns[0];
408
- }
409
- const parsedPattern: ParsedStringPattern = function (path: string, basename: string): string {
410
- for (let i = 0, n = parsedPatterns.length; i < n; i++) {
411
- if ((<ParsedStringPattern>parsedPatterns[i])(path, basename)) {
412
- return pattern;
413
- }
414
- }
415
- return null!;
416
- };
417
- const withBasenames = parsedPatterns.find(pattern => !!(<ParsedStringPattern>pattern).allBasenames);
418
- // const withBasenames = arrays.first(parsedPatterns, pattern => !!(<ParsedStringPattern>pattern).allBasenames);
419
- if (withBasenames) {
420
- parsedPattern.allBasenames = (<ParsedStringPattern>withBasenames).allBasenames;
421
- }
422
- const allPaths = parsedPatterns.reduce((all, current) => current.allPaths ? all.concat(current.allPaths) : all, <string[]>[]);
423
- if (allPaths.length) {
424
- parsedPattern.allPaths = allPaths;
425
- }
426
- return parsedPattern;
427
- }
428
-
429
- // common patterns: **/something/else just need endsWith check, something/else just needs and equals check
430
- function trivia4and5(path: string, pattern: string, matchPathEnds: boolean): ParsedStringPattern {
431
- const nativePath = paths.nativeSep !== paths.sep ? path.replace(ALL_FORWARD_SLASHES, paths.nativeSep) : path;
432
- const nativePathEnd = paths.nativeSep + nativePath;
433
- // eslint-disable-next-line @typescript-eslint/no-shadow
434
- const parsedPattern: ParsedStringPattern = matchPathEnds ? function (path, basename): string {
435
- return path && (path === nativePath || strings.endsWith(path, nativePathEnd)) ? pattern : null!;
436
- // eslint-disable-next-line @typescript-eslint/no-shadow
437
- } : function (path, basename): string {
438
- return path && path === nativePath ? pattern : null!;
439
- };
440
- parsedPattern.allPaths = [(matchPathEnds ? '*/' : './') + path];
441
- return parsedPattern;
442
- }
443
-
444
- function toRegExp(pattern: string): ParsedStringPattern {
445
- try {
446
- const regExp = new RegExp(`^${parseRegExp(pattern)}$`);
447
- return function (path: string, basename: string): string {
448
- regExp.lastIndex = 0; // reset RegExp to its initial state to reuse it!
449
- return path && regExp.test(path) ? pattern : null!;
450
- };
451
- } catch (error) {
452
- return NULL;
453
- }
454
- }
455
-
456
- /**
457
- * Simplified glob matching. Supports a subset of glob patterns:
458
- * - * matches anything inside a path segment
459
- * - ? matches 1 character inside a path segment
460
- * - ** matches anything including an empty path segment
461
- * - simple brace expansion ({js,ts} => js or ts)
462
- * - character ranges (using [...])
463
- */
464
- export function match(pattern: string | IRelativePattern, path: string): boolean;
465
- export function match(expression: IExpression, path: string, hasSibling?: (name: string) => boolean): string /* the matching pattern */;
466
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
467
- export function match(arg1: string | IExpression | IRelativePattern, path: string, hasSibling?: (name: string) => boolean): any {
468
- if (!arg1 || !path) {
469
- return false;
470
- }
471
-
472
- return parse(<IExpression>arg1)(path, undefined, hasSibling);
473
- }
474
-
475
- /**
476
- * Simplified glob matching. Supports a subset of glob patterns:
477
- * - * matches anything inside a path segment
478
- * - ? matches 1 character inside a path segment
479
- * - ** matches anything including an empty path segment
480
- * - simple brace expansion ({js,ts} => js or ts)
481
- * - character ranges (using [...])
482
- */
483
- export function parse(pattern: string | IRelativePattern, options?: IGlobOptions): ParsedPattern;
484
- export function parse(expression: IExpression, options?: IGlobOptions): ParsedExpression;
485
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
486
- export function parse(arg1: string | IExpression | IRelativePattern, options: IGlobOptions = {}): any {
487
- if (!arg1) {
488
- return FALSE;
489
- }
490
-
491
- // Glob with String
492
- if (typeof arg1 === 'string' || isRelativePattern(arg1)) {
493
- const parsedPattern = parsePattern(arg1 as string | IRelativePattern, options);
494
- if (parsedPattern === NULL) {
495
- return FALSE;
496
- }
497
- const resultPattern = function (path: string, basename: string): boolean {
498
- return !!parsedPattern(path, basename);
499
- };
500
- if (parsedPattern.allBasenames) {
501
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
502
- (<ParsedStringPattern><any>resultPattern).allBasenames = parsedPattern.allBasenames;
503
- }
504
- if (parsedPattern.allPaths) {
505
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
506
- (<ParsedStringPattern><any>resultPattern).allPaths = parsedPattern.allPaths;
507
- }
508
- return resultPattern;
509
- }
510
-
511
- // Glob with Expression
512
- return parsedExpression(<IExpression>arg1, options);
513
- }
514
-
515
- export function hasSiblingPromiseFn(siblingsFn?: () => Promise<string[]>): ((name: string) => Promise<boolean>) | undefined {
516
- if (!siblingsFn) {
517
- return undefined;
518
- }
519
-
520
- let siblings: Promise<Record<string, true>>;
521
- return (name: string) => {
522
- if (!siblings) {
523
- siblings = (siblingsFn() || Promise.resolve([]))
524
- .then(list => list ? listToMap(list) : {});
525
- }
526
- return siblings.then(map => !!map[name]);
527
- };
528
- }
529
-
530
- export function hasSiblingFn(siblingsFn?: () => string[]): ((name: string) => boolean) | undefined {
531
- if (!siblingsFn) {
532
- return undefined;
533
- }
534
-
535
- let siblings: Record<string, true>;
536
- return (name: string) => {
537
- if (!siblings) {
538
- const list = siblingsFn();
539
- siblings = list ? listToMap(list) : {};
540
- }
541
- return !!siblings[name];
542
- };
543
- }
544
-
545
- function listToMap(list: string[]): Record<string, true> {
546
- const map: Record<string, true> = {};
547
- for (const key of list) {
548
- map[key] = true;
549
- }
550
- return map;
551
- }
552
-
553
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
554
- export function isRelativePattern(obj: any): obj is IRelativePattern {
555
- const rp = obj as IRelativePattern;
556
-
557
- return rp && typeof rp.base === 'string' && typeof rp.pattern === 'string' && typeof rp.pathToRelative === 'function';
558
- }
559
-
560
- /**
561
- * Same as `parse`, but the ParsedExpression is guaranteed to return a Promise
562
- */
563
- export function parseToAsync(expression: IExpression, options?: IGlobOptions): ParsedExpression {
564
- // eslint-disable-next-line @typescript-eslint/no-shadow
565
- const parsedExpression = parse(expression, options);
566
- return (path: string, basename?: string, hasSibling?: (name: string) => boolean | Promise<boolean>): string | Promise<string> => {
567
- const result = parsedExpression(path, basename, hasSibling);
568
- return result instanceof Promise ? result : Promise.resolve(result);
569
- };
570
- }
571
-
572
- export function getBasenameTerms(patternOrExpression: ParsedPattern | ParsedExpression): string[] {
573
- return (<ParsedStringPattern>patternOrExpression).allBasenames || [];
574
- }
575
-
576
- export function getPathTerms(patternOrExpression: ParsedPattern | ParsedExpression): string[] {
577
- return (<ParsedStringPattern>patternOrExpression).allPaths || [];
578
- }
579
-
580
- function parsedExpression(expression: IExpression, options: IGlobOptions): ParsedExpression {
581
- const parsedPatterns = aggregateBasenameMatches(Object.getOwnPropertyNames(expression)
582
- .map(pattern => parseExpressionPattern(pattern, expression[pattern], options))
583
- .filter(pattern => pattern !== NULL));
584
-
585
- const n = parsedPatterns.length;
586
- if (!n) {
587
- return NULL;
588
- }
589
-
590
- if (!parsedPatterns.some(parsedPattern => (<ParsedExpressionPattern>parsedPattern).requiresSiblings!)) {
591
- if (n === 1) {
592
- return <ParsedStringPattern>parsedPatterns[0];
593
- }
594
-
595
- // eslint-disable-next-line @typescript-eslint/no-shadow
596
- const resultExpression: ParsedStringPattern = function (path: string, basename: string): string | Promise<string> {
597
- // eslint-disable-next-line @typescript-eslint/no-shadow
598
- // tslint:disable-next-line:one-variable-per-declaration
599
- for (let i = 0, n = parsedPatterns.length; i < n; i++) {
600
- // Pattern matches path
601
- const result = (<ParsedStringPattern>parsedPatterns[i])(path, basename);
602
- if (result) {
603
- return result;
604
- }
605
- }
606
-
607
- return null!;
608
- };
609
-
610
- // eslint-disable-next-line @typescript-eslint/no-shadow
611
- const withBasenames = parsedPatterns.find(pattern => !!(<ParsedStringPattern>pattern).allBasenames);
612
- if (withBasenames) {
613
- resultExpression.allBasenames = (<ParsedStringPattern>withBasenames).allBasenames;
614
- }
615
-
616
- // eslint-disable-next-line @typescript-eslint/no-shadow
617
- const allPaths = parsedPatterns.reduce((all, current) => current.allPaths ? all.concat(current.allPaths) : all, <string[]>[]);
618
- if (allPaths.length) {
619
- resultExpression.allPaths = allPaths;
620
- }
621
-
622
- return resultExpression;
623
- }
624
-
625
- const resultExpression: ParsedStringPattern = function (path: string, basename: string, hasSibling?: (name: string) => boolean | Promise<boolean>): string | Promise<string> {
626
- let name: string = null!;
627
-
628
- // eslint-disable-next-line @typescript-eslint/no-shadow
629
- for (let i = 0, n = parsedPatterns.length; i < n; i++) {
630
- // Pattern matches path
631
- const parsedPattern = (<ParsedExpressionPattern>parsedPatterns[i]);
632
- if (parsedPattern.requiresSiblings && hasSibling) {
633
- if (!basename) {
634
- basename = paths.basename(path);
635
- }
636
- if (!name) {
637
- name = basename.substr(0, basename.length - paths.extname(path).length);
638
- }
639
- }
640
- const result = parsedPattern(path, basename, name, hasSibling!);
641
- if (result) {
642
- return result;
643
- }
644
- }
645
-
646
- return null!;
647
- };
648
-
649
- const withBasenames = parsedPatterns.find(pattern => !!(<ParsedStringPattern>pattern).allBasenames);
650
- if (withBasenames) {
651
- resultExpression.allBasenames = (<ParsedStringPattern>withBasenames).allBasenames;
652
- }
653
-
654
- const allPaths = parsedPatterns.reduce((all, current) => current.allPaths ? all.concat(current.allPaths) : all, <string[]>[]);
655
- if (allPaths.length) {
656
- resultExpression.allPaths = allPaths;
657
- }
658
-
659
- return resultExpression;
660
- }
661
-
662
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
663
- function parseExpressionPattern(pattern: string, value: any, options: IGlobOptions): (ParsedStringPattern | ParsedExpressionPattern) {
664
- if (value === false) {
665
- return NULL; // pattern is disabled
666
- }
667
-
668
- const parsedPattern = parsePattern(pattern, options);
669
- if (parsedPattern === NULL) {
670
- return NULL;
671
- }
672
-
673
- // Expression Pattern is <boolean>
674
- if (typeof value === 'boolean') {
675
- return parsedPattern;
676
- }
677
-
678
- // Expression Pattern is <SiblingClause>
679
- if (value) {
680
- const when = (<SiblingClause>value).when;
681
- if (typeof when === 'string') {
682
- const result: ParsedExpressionPattern = (path: string, basename: string, name: string, hasSibling: (name: string) => boolean | Promise<boolean>) => {
683
- if (!hasSibling || !parsedPattern(path, basename)) {
684
- return null!;
685
- }
686
-
687
- const clausePattern = when.replace('$(basename)', name);
688
- const matched = hasSibling(clausePattern);
689
- return matched instanceof Promise ?
690
- matched.then(m => m ? pattern : null!) :
691
- matched ? pattern : null!;
692
- };
693
- result.requiresSiblings = true;
694
- return result;
695
- }
696
- }
697
-
698
- // Expression is Anything
699
- return parsedPattern;
700
- }
701
-
702
- function aggregateBasenameMatches(parsedPatterns: (ParsedStringPattern | ParsedExpressionPattern)[], result?: string): (ParsedStringPattern | ParsedExpressionPattern)[] {
703
- const basenamePatterns = parsedPatterns.filter(parsedPattern => !!(<ParsedStringPattern>parsedPattern).basenames);
704
- if (basenamePatterns.length < 2) {
705
- return parsedPatterns;
706
- }
707
-
708
- const basenames = basenamePatterns.reduce<string[]>((all, current) => all.concat((<ParsedStringPattern>current).basenames!), []);
709
- let patterns: string[];
710
- if (result) {
711
- patterns = [];
712
- // tslint:disable-next-line:one-variable-per-declaration
713
- for (let i = 0, n = basenames.length; i < n; i++) {
714
- patterns.push(result);
715
- }
716
- } else {
717
- patterns = basenamePatterns.reduce((all, current) => all.concat((<ParsedStringPattern>current).patterns!), <string[]>[]);
718
- }
719
- const aggregate: ParsedStringPattern = function (path, basename): string {
720
- if (!path) {
721
- return null!;
722
- }
723
- if (!basename) {
724
- let i: number;
725
- for (i = path.length; i > 0; i--) {
726
- const ch = path.charCodeAt(i - 1);
727
- if (ch === CharCode.Slash || ch === CharCode.Backslash) {
728
- break;
729
- }
730
- }
731
- basename = path.substr(i);
732
- }
733
- const index = basenames.indexOf(basename);
734
- return index !== -1 ? patterns[index] : null!;
735
- };
736
- aggregate.basenames = basenames;
737
- aggregate.patterns = patterns;
738
- aggregate.allBasenames = basenames;
739
-
740
- const aggregatedPatterns = parsedPatterns.filter(parsedPattern => !(<ParsedStringPattern>parsedPattern).basenames);
741
- aggregatedPatterns.push(aggregate);
742
- return aggregatedPatterns;
743
- }