phantom-pr 0.2.2 → 0.2.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 (243) hide show
  1. package/bin/phantom-pr.cjs +20 -0
  2. package/dist/cli.js +7 -0
  3. package/dist/cli.js.map +1 -1
  4. package/node_modules/ignore/LICENSE-MIT +21 -0
  5. package/node_modules/ignore/README.md +452 -0
  6. package/node_modules/ignore/index.d.ts +81 -0
  7. package/node_modules/ignore/index.js +784 -0
  8. package/node_modules/ignore/legacy.js +681 -0
  9. package/node_modules/ignore/package.json +87 -0
  10. package/node_modules/yaml/LICENSE +13 -0
  11. package/node_modules/yaml/README.md +172 -0
  12. package/node_modules/yaml/bin.mjs +11 -0
  13. package/node_modules/yaml/browser/dist/compose/compose-collection.js +88 -0
  14. package/node_modules/yaml/browser/dist/compose/compose-doc.js +43 -0
  15. package/node_modules/yaml/browser/dist/compose/compose-node.js +102 -0
  16. package/node_modules/yaml/browser/dist/compose/compose-scalar.js +86 -0
  17. package/node_modules/yaml/browser/dist/compose/composer.js +217 -0
  18. package/node_modules/yaml/browser/dist/compose/resolve-block-map.js +115 -0
  19. package/node_modules/yaml/browser/dist/compose/resolve-block-scalar.js +198 -0
  20. package/node_modules/yaml/browser/dist/compose/resolve-block-seq.js +49 -0
  21. package/node_modules/yaml/browser/dist/compose/resolve-end.js +37 -0
  22. package/node_modules/yaml/browser/dist/compose/resolve-flow-collection.js +207 -0
  23. package/node_modules/yaml/browser/dist/compose/resolve-flow-scalar.js +223 -0
  24. package/node_modules/yaml/browser/dist/compose/resolve-props.js +146 -0
  25. package/node_modules/yaml/browser/dist/compose/util-contains-newline.js +34 -0
  26. package/node_modules/yaml/browser/dist/compose/util-empty-scalar-position.js +26 -0
  27. package/node_modules/yaml/browser/dist/compose/util-flow-indent-check.js +15 -0
  28. package/node_modules/yaml/browser/dist/compose/util-map-includes.js +13 -0
  29. package/node_modules/yaml/browser/dist/doc/Document.js +335 -0
  30. package/node_modules/yaml/browser/dist/doc/anchors.js +71 -0
  31. package/node_modules/yaml/browser/dist/doc/applyReviver.js +55 -0
  32. package/node_modules/yaml/browser/dist/doc/createNode.js +88 -0
  33. package/node_modules/yaml/browser/dist/doc/directives.js +176 -0
  34. package/node_modules/yaml/browser/dist/errors.js +57 -0
  35. package/node_modules/yaml/browser/dist/index.js +17 -0
  36. package/node_modules/yaml/browser/dist/log.js +11 -0
  37. package/node_modules/yaml/browser/dist/nodes/Alias.js +114 -0
  38. package/node_modules/yaml/browser/dist/nodes/Collection.js +147 -0
  39. package/node_modules/yaml/browser/dist/nodes/Node.js +38 -0
  40. package/node_modules/yaml/browser/dist/nodes/Pair.js +36 -0
  41. package/node_modules/yaml/browser/dist/nodes/Scalar.js +24 -0
  42. package/node_modules/yaml/browser/dist/nodes/YAMLMap.js +144 -0
  43. package/node_modules/yaml/browser/dist/nodes/YAMLSeq.js +113 -0
  44. package/node_modules/yaml/browser/dist/nodes/addPairToJSMap.js +63 -0
  45. package/node_modules/yaml/browser/dist/nodes/identity.js +36 -0
  46. package/node_modules/yaml/browser/dist/nodes/toJS.js +37 -0
  47. package/node_modules/yaml/browser/dist/parse/cst-scalar.js +214 -0
  48. package/node_modules/yaml/browser/dist/parse/cst-stringify.js +61 -0
  49. package/node_modules/yaml/browser/dist/parse/cst-visit.js +97 -0
  50. package/node_modules/yaml/browser/dist/parse/cst.js +98 -0
  51. package/node_modules/yaml/browser/dist/parse/lexer.js +717 -0
  52. package/node_modules/yaml/browser/dist/parse/line-counter.js +39 -0
  53. package/node_modules/yaml/browser/dist/parse/parser.js +967 -0
  54. package/node_modules/yaml/browser/dist/public-api.js +102 -0
  55. package/node_modules/yaml/browser/dist/schema/Schema.js +37 -0
  56. package/node_modules/yaml/browser/dist/schema/common/map.js +17 -0
  57. package/node_modules/yaml/browser/dist/schema/common/null.js +15 -0
  58. package/node_modules/yaml/browser/dist/schema/common/seq.js +17 -0
  59. package/node_modules/yaml/browser/dist/schema/common/string.js +14 -0
  60. package/node_modules/yaml/browser/dist/schema/core/bool.js +19 -0
  61. package/node_modules/yaml/browser/dist/schema/core/float.js +43 -0
  62. package/node_modules/yaml/browser/dist/schema/core/int.js +38 -0
  63. package/node_modules/yaml/browser/dist/schema/core/schema.js +23 -0
  64. package/node_modules/yaml/browser/dist/schema/json/schema.js +62 -0
  65. package/node_modules/yaml/browser/dist/schema/tags.js +96 -0
  66. package/node_modules/yaml/browser/dist/schema/yaml-1.1/binary.js +58 -0
  67. package/node_modules/yaml/browser/dist/schema/yaml-1.1/bool.js +26 -0
  68. package/node_modules/yaml/browser/dist/schema/yaml-1.1/float.js +46 -0
  69. package/node_modules/yaml/browser/dist/schema/yaml-1.1/int.js +71 -0
  70. package/node_modules/yaml/browser/dist/schema/yaml-1.1/merge.js +64 -0
  71. package/node_modules/yaml/browser/dist/schema/yaml-1.1/omap.js +74 -0
  72. package/node_modules/yaml/browser/dist/schema/yaml-1.1/pairs.js +78 -0
  73. package/node_modules/yaml/browser/dist/schema/yaml-1.1/schema.js +39 -0
  74. package/node_modules/yaml/browser/dist/schema/yaml-1.1/set.js +93 -0
  75. package/node_modules/yaml/browser/dist/schema/yaml-1.1/timestamp.js +101 -0
  76. package/node_modules/yaml/browser/dist/stringify/foldFlowLines.js +146 -0
  77. package/node_modules/yaml/browser/dist/stringify/stringify.js +128 -0
  78. package/node_modules/yaml/browser/dist/stringify/stringifyCollection.js +143 -0
  79. package/node_modules/yaml/browser/dist/stringify/stringifyComment.js +20 -0
  80. package/node_modules/yaml/browser/dist/stringify/stringifyDocument.js +85 -0
  81. package/node_modules/yaml/browser/dist/stringify/stringifyNumber.js +24 -0
  82. package/node_modules/yaml/browser/dist/stringify/stringifyPair.js +150 -0
  83. package/node_modules/yaml/browser/dist/stringify/stringifyString.js +336 -0
  84. package/node_modules/yaml/browser/dist/util.js +11 -0
  85. package/node_modules/yaml/browser/dist/visit.js +233 -0
  86. package/node_modules/yaml/browser/index.js +5 -0
  87. package/node_modules/yaml/browser/package.json +3 -0
  88. package/node_modules/yaml/dist/cli.d.ts +8 -0
  89. package/node_modules/yaml/dist/cli.mjs +201 -0
  90. package/node_modules/yaml/dist/compose/compose-collection.d.ts +11 -0
  91. package/node_modules/yaml/dist/compose/compose-collection.js +90 -0
  92. package/node_modules/yaml/dist/compose/compose-doc.d.ts +7 -0
  93. package/node_modules/yaml/dist/compose/compose-doc.js +45 -0
  94. package/node_modules/yaml/dist/compose/compose-node.d.ts +29 -0
  95. package/node_modules/yaml/dist/compose/compose-node.js +105 -0
  96. package/node_modules/yaml/dist/compose/compose-scalar.d.ts +5 -0
  97. package/node_modules/yaml/dist/compose/compose-scalar.js +88 -0
  98. package/node_modules/yaml/dist/compose/composer.d.ts +63 -0
  99. package/node_modules/yaml/dist/compose/composer.js +222 -0
  100. package/node_modules/yaml/dist/compose/resolve-block-map.d.ts +6 -0
  101. package/node_modules/yaml/dist/compose/resolve-block-map.js +117 -0
  102. package/node_modules/yaml/dist/compose/resolve-block-scalar.d.ts +11 -0
  103. package/node_modules/yaml/dist/compose/resolve-block-scalar.js +200 -0
  104. package/node_modules/yaml/dist/compose/resolve-block-seq.d.ts +6 -0
  105. package/node_modules/yaml/dist/compose/resolve-block-seq.js +51 -0
  106. package/node_modules/yaml/dist/compose/resolve-end.d.ts +6 -0
  107. package/node_modules/yaml/dist/compose/resolve-end.js +39 -0
  108. package/node_modules/yaml/dist/compose/resolve-flow-collection.d.ts +7 -0
  109. package/node_modules/yaml/dist/compose/resolve-flow-collection.js +209 -0
  110. package/node_modules/yaml/dist/compose/resolve-flow-scalar.d.ts +10 -0
  111. package/node_modules/yaml/dist/compose/resolve-flow-scalar.js +225 -0
  112. package/node_modules/yaml/dist/compose/resolve-props.d.ts +23 -0
  113. package/node_modules/yaml/dist/compose/resolve-props.js +148 -0
  114. package/node_modules/yaml/dist/compose/util-contains-newline.d.ts +2 -0
  115. package/node_modules/yaml/dist/compose/util-contains-newline.js +36 -0
  116. package/node_modules/yaml/dist/compose/util-empty-scalar-position.d.ts +2 -0
  117. package/node_modules/yaml/dist/compose/util-empty-scalar-position.js +28 -0
  118. package/node_modules/yaml/dist/compose/util-flow-indent-check.d.ts +3 -0
  119. package/node_modules/yaml/dist/compose/util-flow-indent-check.js +17 -0
  120. package/node_modules/yaml/dist/compose/util-map-includes.d.ts +4 -0
  121. package/node_modules/yaml/dist/compose/util-map-includes.js +15 -0
  122. package/node_modules/yaml/dist/doc/Document.d.ts +141 -0
  123. package/node_modules/yaml/dist/doc/Document.js +337 -0
  124. package/node_modules/yaml/dist/doc/anchors.d.ts +24 -0
  125. package/node_modules/yaml/dist/doc/anchors.js +76 -0
  126. package/node_modules/yaml/dist/doc/applyReviver.d.ts +9 -0
  127. package/node_modules/yaml/dist/doc/applyReviver.js +57 -0
  128. package/node_modules/yaml/dist/doc/createNode.d.ts +17 -0
  129. package/node_modules/yaml/dist/doc/createNode.js +90 -0
  130. package/node_modules/yaml/dist/doc/directives.d.ts +49 -0
  131. package/node_modules/yaml/dist/doc/directives.js +178 -0
  132. package/node_modules/yaml/dist/errors.d.ts +21 -0
  133. package/node_modules/yaml/dist/errors.js +62 -0
  134. package/node_modules/yaml/dist/index.d.ts +25 -0
  135. package/node_modules/yaml/dist/index.js +50 -0
  136. package/node_modules/yaml/dist/log.d.ts +3 -0
  137. package/node_modules/yaml/dist/log.js +19 -0
  138. package/node_modules/yaml/dist/nodes/Alias.d.ts +29 -0
  139. package/node_modules/yaml/dist/nodes/Alias.js +116 -0
  140. package/node_modules/yaml/dist/nodes/Collection.d.ts +73 -0
  141. package/node_modules/yaml/dist/nodes/Collection.js +151 -0
  142. package/node_modules/yaml/dist/nodes/Node.d.ts +53 -0
  143. package/node_modules/yaml/dist/nodes/Node.js +40 -0
  144. package/node_modules/yaml/dist/nodes/Pair.d.ts +22 -0
  145. package/node_modules/yaml/dist/nodes/Pair.js +39 -0
  146. package/node_modules/yaml/dist/nodes/Scalar.d.ts +43 -0
  147. package/node_modules/yaml/dist/nodes/Scalar.js +27 -0
  148. package/node_modules/yaml/dist/nodes/YAMLMap.d.ts +53 -0
  149. package/node_modules/yaml/dist/nodes/YAMLMap.js +147 -0
  150. package/node_modules/yaml/dist/nodes/YAMLSeq.d.ts +60 -0
  151. package/node_modules/yaml/dist/nodes/YAMLSeq.js +115 -0
  152. package/node_modules/yaml/dist/nodes/addPairToJSMap.d.ts +4 -0
  153. package/node_modules/yaml/dist/nodes/addPairToJSMap.js +65 -0
  154. package/node_modules/yaml/dist/nodes/identity.d.ts +23 -0
  155. package/node_modules/yaml/dist/nodes/identity.js +53 -0
  156. package/node_modules/yaml/dist/nodes/toJS.d.ts +29 -0
  157. package/node_modules/yaml/dist/nodes/toJS.js +39 -0
  158. package/node_modules/yaml/dist/options.d.ts +344 -0
  159. package/node_modules/yaml/dist/parse/cst-scalar.d.ts +64 -0
  160. package/node_modules/yaml/dist/parse/cst-scalar.js +218 -0
  161. package/node_modules/yaml/dist/parse/cst-stringify.d.ts +8 -0
  162. package/node_modules/yaml/dist/parse/cst-stringify.js +63 -0
  163. package/node_modules/yaml/dist/parse/cst-visit.d.ts +39 -0
  164. package/node_modules/yaml/dist/parse/cst-visit.js +99 -0
  165. package/node_modules/yaml/dist/parse/cst.d.ts +109 -0
  166. package/node_modules/yaml/dist/parse/cst.js +112 -0
  167. package/node_modules/yaml/dist/parse/lexer.d.ts +87 -0
  168. package/node_modules/yaml/dist/parse/lexer.js +719 -0
  169. package/node_modules/yaml/dist/parse/line-counter.d.ts +22 -0
  170. package/node_modules/yaml/dist/parse/line-counter.js +41 -0
  171. package/node_modules/yaml/dist/parse/parser.d.ts +84 -0
  172. package/node_modules/yaml/dist/parse/parser.js +972 -0
  173. package/node_modules/yaml/dist/public-api.d.ts +44 -0
  174. package/node_modules/yaml/dist/public-api.js +107 -0
  175. package/node_modules/yaml/dist/schema/Schema.d.ts +17 -0
  176. package/node_modules/yaml/dist/schema/Schema.js +39 -0
  177. package/node_modules/yaml/dist/schema/common/map.d.ts +2 -0
  178. package/node_modules/yaml/dist/schema/common/map.js +19 -0
  179. package/node_modules/yaml/dist/schema/common/null.d.ts +4 -0
  180. package/node_modules/yaml/dist/schema/common/null.js +17 -0
  181. package/node_modules/yaml/dist/schema/common/seq.d.ts +2 -0
  182. package/node_modules/yaml/dist/schema/common/seq.js +19 -0
  183. package/node_modules/yaml/dist/schema/common/string.d.ts +2 -0
  184. package/node_modules/yaml/dist/schema/common/string.js +16 -0
  185. package/node_modules/yaml/dist/schema/core/bool.d.ts +4 -0
  186. package/node_modules/yaml/dist/schema/core/bool.js +21 -0
  187. package/node_modules/yaml/dist/schema/core/float.d.ts +4 -0
  188. package/node_modules/yaml/dist/schema/core/float.js +47 -0
  189. package/node_modules/yaml/dist/schema/core/int.d.ts +4 -0
  190. package/node_modules/yaml/dist/schema/core/int.js +42 -0
  191. package/node_modules/yaml/dist/schema/core/schema.d.ts +1 -0
  192. package/node_modules/yaml/dist/schema/core/schema.js +25 -0
  193. package/node_modules/yaml/dist/schema/json/schema.d.ts +2 -0
  194. package/node_modules/yaml/dist/schema/json/schema.js +64 -0
  195. package/node_modules/yaml/dist/schema/json-schema.d.ts +69 -0
  196. package/node_modules/yaml/dist/schema/tags.d.ts +48 -0
  197. package/node_modules/yaml/dist/schema/tags.js +99 -0
  198. package/node_modules/yaml/dist/schema/types.d.ts +92 -0
  199. package/node_modules/yaml/dist/schema/yaml-1.1/binary.d.ts +2 -0
  200. package/node_modules/yaml/dist/schema/yaml-1.1/binary.js +70 -0
  201. package/node_modules/yaml/dist/schema/yaml-1.1/bool.d.ts +7 -0
  202. package/node_modules/yaml/dist/schema/yaml-1.1/bool.js +29 -0
  203. package/node_modules/yaml/dist/schema/yaml-1.1/float.d.ts +4 -0
  204. package/node_modules/yaml/dist/schema/yaml-1.1/float.js +50 -0
  205. package/node_modules/yaml/dist/schema/yaml-1.1/int.d.ts +5 -0
  206. package/node_modules/yaml/dist/schema/yaml-1.1/int.js +76 -0
  207. package/node_modules/yaml/dist/schema/yaml-1.1/merge.d.ts +9 -0
  208. package/node_modules/yaml/dist/schema/yaml-1.1/merge.js +68 -0
  209. package/node_modules/yaml/dist/schema/yaml-1.1/omap.d.ts +22 -0
  210. package/node_modules/yaml/dist/schema/yaml-1.1/omap.js +77 -0
  211. package/node_modules/yaml/dist/schema/yaml-1.1/pairs.d.ts +10 -0
  212. package/node_modules/yaml/dist/schema/yaml-1.1/pairs.js +82 -0
  213. package/node_modules/yaml/dist/schema/yaml-1.1/schema.d.ts +1 -0
  214. package/node_modules/yaml/dist/schema/yaml-1.1/schema.js +41 -0
  215. package/node_modules/yaml/dist/schema/yaml-1.1/set.d.ts +28 -0
  216. package/node_modules/yaml/dist/schema/yaml-1.1/set.js +96 -0
  217. package/node_modules/yaml/dist/schema/yaml-1.1/timestamp.d.ts +6 -0
  218. package/node_modules/yaml/dist/schema/yaml-1.1/timestamp.js +105 -0
  219. package/node_modules/yaml/dist/stringify/foldFlowLines.d.ts +34 -0
  220. package/node_modules/yaml/dist/stringify/foldFlowLines.js +151 -0
  221. package/node_modules/yaml/dist/stringify/stringify.d.ts +21 -0
  222. package/node_modules/yaml/dist/stringify/stringify.js +131 -0
  223. package/node_modules/yaml/dist/stringify/stringifyCollection.d.ts +17 -0
  224. package/node_modules/yaml/dist/stringify/stringifyCollection.js +145 -0
  225. package/node_modules/yaml/dist/stringify/stringifyComment.d.ts +10 -0
  226. package/node_modules/yaml/dist/stringify/stringifyComment.js +24 -0
  227. package/node_modules/yaml/dist/stringify/stringifyDocument.d.ts +4 -0
  228. package/node_modules/yaml/dist/stringify/stringifyDocument.js +87 -0
  229. package/node_modules/yaml/dist/stringify/stringifyNumber.d.ts +2 -0
  230. package/node_modules/yaml/dist/stringify/stringifyNumber.js +26 -0
  231. package/node_modules/yaml/dist/stringify/stringifyPair.d.ts +3 -0
  232. package/node_modules/yaml/dist/stringify/stringifyPair.js +152 -0
  233. package/node_modules/yaml/dist/stringify/stringifyString.d.ts +9 -0
  234. package/node_modules/yaml/dist/stringify/stringifyString.js +338 -0
  235. package/node_modules/yaml/dist/test-events.d.ts +4 -0
  236. package/node_modules/yaml/dist/test-events.js +134 -0
  237. package/node_modules/yaml/dist/util.d.ts +16 -0
  238. package/node_modules/yaml/dist/util.js +28 -0
  239. package/node_modules/yaml/dist/visit.d.ts +102 -0
  240. package/node_modules/yaml/dist/visit.js +236 -0
  241. package/node_modules/yaml/package.json +97 -0
  242. package/node_modules/yaml/util.js +2 -0
  243. package/package.json +7 -3
@@ -0,0 +1,784 @@
1
+ // A simple implementation of make-array
2
+ function makeArray (subject) {
3
+ return Array.isArray(subject)
4
+ ? subject
5
+ : [subject]
6
+ }
7
+
8
+ const UNDEFINED = undefined
9
+ const EMPTY = ''
10
+ const SPACE = ' '
11
+ const ESCAPE = '\\'
12
+ const REGEX_TEST_BLANK_LINE = /^\s+$/
13
+ const REGEX_INVALID_TRAILING_BACKSLASH = /(?:[^\\]|^)\\$/
14
+ const REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION = /^\\!/
15
+ const REGEX_REPLACE_LEADING_EXCAPED_HASH = /^\\#/
16
+ const REGEX_SPLITALL_CRLF = /\r?\n/g
17
+
18
+ // Invalid:
19
+ // - /foo,
20
+ // - ./foo,
21
+ // - ../foo,
22
+ // - .
23
+ // - ..
24
+ // Valid:
25
+ // - .foo
26
+ const REGEX_TEST_INVALID_PATH = /^\.{0,2}\/|^\.{1,2}$/
27
+
28
+ const REGEX_TEST_TRAILING_SLASH = /\/$/
29
+
30
+ const SLASH = '/'
31
+
32
+ // Do not use ternary expression here, since "istanbul ignore next" is buggy
33
+ let TMP_KEY_IGNORE = 'node-ignore'
34
+ /* istanbul ignore else */
35
+ if (typeof Symbol !== 'undefined') {
36
+ TMP_KEY_IGNORE = Symbol.for('node-ignore')
37
+ }
38
+ const KEY_IGNORE = TMP_KEY_IGNORE
39
+
40
+ const define = (object, key, value) => {
41
+ Object.defineProperty(object, key, {value})
42
+ return value
43
+ }
44
+
45
+ const REGEX_REGEXP_RANGE = /([0-z])-([0-z])/g
46
+
47
+ const RETURN_FALSE = () => false
48
+
49
+ // Sanitize the range of a regular expression
50
+ // The cases are complicated, see test cases for details
51
+ const sanitizeRange = range => range.replace(
52
+ REGEX_REGEXP_RANGE,
53
+ (match, from, to) => from.charCodeAt(0) <= to.charCodeAt(0)
54
+ ? match
55
+ // Invalid range (out of order) which is ok for gitignore rules but
56
+ // fatal for JavaScript regular expression, so eliminate it.
57
+ : EMPTY
58
+ )
59
+
60
+ // See fixtures #59
61
+ const cleanRangeBackSlash = slashes => {
62
+ const {length} = slashes
63
+ return slashes.slice(0, length - length % 2)
64
+ }
65
+
66
+ // > If the pattern ends with a slash,
67
+ // > it is removed for the purpose of the following description,
68
+ // > but it would only find a match with a directory.
69
+ // > In other words, foo/ will match a directory foo and paths underneath it,
70
+ // > but will not match a regular file or a symbolic link foo
71
+ // > (this is consistent with the way how pathspec works in general in Git).
72
+ // '`foo/`' will not match regular file '`foo`' or symbolic link '`foo`'
73
+ // -> ignore-rules will not deal with it, because it costs extra `fs.stat` call
74
+ // you could use option `mark: true` with `glob`
75
+
76
+ // '`foo/`' should not continue with the '`..`'
77
+ const REPLACERS = [
78
+
79
+ [
80
+ // Remove BOM
81
+ // TODO:
82
+ // Other similar zero-width characters?
83
+ /^\uFEFF/,
84
+ () => EMPTY
85
+ ],
86
+
87
+ // > Trailing spaces are ignored unless they are quoted with backslash ("\")
88
+ [
89
+ // (a\ ) -> (a )
90
+ // (a ) -> (a)
91
+ // (a ) -> (a)
92
+ // (a \ ) -> (a )
93
+ /((?:\\\\)*?)(\\?\s+)$/,
94
+ (_, m1, m2) => m1 + (
95
+ m2.indexOf('\\') === 0
96
+ ? SPACE
97
+ : EMPTY
98
+ )
99
+ ],
100
+
101
+ // Replace (\ ) with ' '
102
+ // (\ ) -> ' '
103
+ // (\\ ) -> '\\ '
104
+ // (\\\ ) -> '\\ '
105
+ [
106
+ /(\\+?)\s/g,
107
+ (_, m1) => {
108
+ const {length} = m1
109
+ return m1.slice(0, length - length % 2) + SPACE
110
+ }
111
+ ],
112
+
113
+ // Escape metacharacters
114
+ // which is written down by users but means special for regular expressions.
115
+
116
+ // > There are 12 characters with special meanings:
117
+ // > - the backslash \,
118
+ // > - the caret ^,
119
+ // > - the dollar sign $,
120
+ // > - the period or dot .,
121
+ // > - the vertical bar or pipe symbol |,
122
+ // > - the question mark ?,
123
+ // > - the asterisk or star *,
124
+ // > - the plus sign +,
125
+ // > - the opening parenthesis (,
126
+ // > - the closing parenthesis ),
127
+ // > - and the opening square bracket [,
128
+ // > - the opening curly brace {,
129
+ // > These special characters are often called "metacharacters".
130
+ [
131
+ /[\\$.|*+(){^]/g,
132
+ match => `\\${match}`
133
+ ],
134
+
135
+ [
136
+ // > a question mark (?) matches a single character
137
+ /(?!\\)\?/g,
138
+ () => '[^/]'
139
+ ],
140
+
141
+ // leading slash
142
+ [
143
+
144
+ // > A leading slash matches the beginning of the pathname.
145
+ // > For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".
146
+ // A leading slash matches the beginning of the pathname
147
+ /^\//,
148
+ () => '^'
149
+ ],
150
+
151
+ // replace special metacharacter slash after the leading slash
152
+ [
153
+ /\//g,
154
+ () => '\\/'
155
+ ],
156
+
157
+ [
158
+ // > A leading "**" followed by a slash means match in all directories.
159
+ // > For example, "**/foo" matches file or directory "foo" anywhere,
160
+ // > the same as pattern "foo".
161
+ // > "**/foo/bar" matches file or directory "bar" anywhere that is directly
162
+ // > under directory "foo".
163
+ // Notice that the '*'s have been replaced as '\\*'
164
+ /^\^*\\\*\\\*\\\//,
165
+
166
+ // '**/foo' <-> 'foo'
167
+ () => '^(?:.*\\/)?'
168
+ ],
169
+
170
+ // starting
171
+ [
172
+ // there will be no leading '/'
173
+ // (which has been replaced by section "leading slash")
174
+ // If starts with '**', adding a '^' to the regular expression also works
175
+ /^(?=[^^])/,
176
+ function startingReplacer () {
177
+ // If has a slash `/` at the beginning or middle
178
+ return !/\/(?!$)/.test(this)
179
+ // > Prior to 2.22.1
180
+ // > If the pattern does not contain a slash /,
181
+ // > Git treats it as a shell glob pattern
182
+ // Actually, if there is only a trailing slash,
183
+ // git also treats it as a shell glob pattern
184
+
185
+ // After 2.22.1 (compatible but clearer)
186
+ // > If there is a separator at the beginning or middle (or both)
187
+ // > of the pattern, then the pattern is relative to the directory
188
+ // > level of the particular .gitignore file itself.
189
+ // > Otherwise the pattern may also match at any level below
190
+ // > the .gitignore level.
191
+ ? '(?:^|\\/)'
192
+
193
+ // > Otherwise, Git treats the pattern as a shell glob suitable for
194
+ // > consumption by fnmatch(3)
195
+ : '^'
196
+ }
197
+ ],
198
+
199
+ // two globstars
200
+ [
201
+ // Use lookahead assertions so that we could match more than one `'/**'`
202
+ /\\\/\\\*\\\*(?=\\\/|$)/g,
203
+
204
+ // Zero, one or several directories
205
+ // should not use '*', or it will be replaced by the next replacer
206
+
207
+ // Check if it is not the last `'/**'`
208
+ (_, index, str) => index + 6 < str.length
209
+
210
+ // case: /**/
211
+ // > A slash followed by two consecutive asterisks then a slash matches
212
+ // > zero or more directories.
213
+ // > For example, "a/**/b" matches "a/b", "a/x/b", "a/x/y/b" and so on.
214
+ // '/**/'
215
+ ? '(?:\\/[^\\/]+)*'
216
+
217
+ // case: /**
218
+ // > A trailing `"/**"` matches everything inside.
219
+
220
+ // #21: everything inside but it should not include the current folder
221
+ : '\\/.+'
222
+ ],
223
+
224
+ // normal intermediate wildcards
225
+ [
226
+ // Never replace escaped '*'
227
+ // ignore rule '\*' will match the path '*'
228
+
229
+ // 'abc.*/' -> go
230
+ // 'abc.*' -> skip this rule,
231
+ // coz trailing single wildcard will be handed by [trailing wildcard]
232
+ /(^|[^\\]+)(\\\*)+(?=.+)/g,
233
+
234
+ // '*.js' matches '.js'
235
+ // '*.js' doesn't match 'abc'
236
+ (_, p1, p2) => {
237
+ // 1.
238
+ // > An asterisk "*" matches anything except a slash.
239
+ // 2.
240
+ // > Other consecutive asterisks are considered regular asterisks
241
+ // > and will match according to the previous rules.
242
+ const unescaped = p2.replace(/\\\*/g, '[^\\/]*')
243
+ return p1 + unescaped
244
+ }
245
+ ],
246
+
247
+ [
248
+ // unescape, revert step 3 except for back slash
249
+ // For example, if a user escape a '\\*',
250
+ // after step 3, the result will be '\\\\\\*'
251
+ /\\\\\\(?=[$.|*+(){^])/g,
252
+ () => ESCAPE
253
+ ],
254
+
255
+ [
256
+ // '\\\\' -> '\\'
257
+ /\\\\/g,
258
+ () => ESCAPE
259
+ ],
260
+
261
+ [
262
+ // > The range notation, e.g. [a-zA-Z],
263
+ // > can be used to match one of the characters in a range.
264
+
265
+ // `\` is escaped by step 3
266
+ /(\\)?\[([^\]/]*?)(\\*)($|\])/g,
267
+ (match, leadEscape, range, endEscape, close) => leadEscape === ESCAPE
268
+ // '\\[bar]' -> '\\\\[bar\\]'
269
+ ? `\\[${range}${cleanRangeBackSlash(endEscape)}${close}`
270
+ : close === ']'
271
+ ? endEscape.length % 2 === 0
272
+ // A normal case, and it is a range notation
273
+ // '[bar]'
274
+ // '[bar\\\\]'
275
+ ? `[${sanitizeRange(range)}${endEscape}]`
276
+ // Invalid range notaton
277
+ // '[bar\\]' -> '[bar\\\\]'
278
+ : '[]'
279
+ : '[]'
280
+ ],
281
+
282
+ // ending
283
+ [
284
+ // 'js' will not match 'js.'
285
+ // 'ab' will not match 'abc'
286
+ /(?:[^*])$/,
287
+
288
+ // WTF!
289
+ // https://git-scm.com/docs/gitignore
290
+ // changes in [2.22.1](https://git-scm.com/docs/gitignore/2.22.1)
291
+ // which re-fixes #24, #38
292
+
293
+ // > If there is a separator at the end of the pattern then the pattern
294
+ // > will only match directories, otherwise the pattern can match both
295
+ // > files and directories.
296
+
297
+ // 'js*' will not match 'a.js'
298
+ // 'js/' will not match 'a.js'
299
+ // 'js' will match 'a.js' and 'a.js/'
300
+ match => /\/$/.test(match)
301
+ // foo/ will not match 'foo'
302
+ ? `${match}$`
303
+ // foo matches 'foo' and 'foo/'
304
+ : `${match}(?=$|\\/$)`
305
+ ]
306
+ ]
307
+
308
+ const REGEX_REPLACE_TRAILING_WILDCARD = /(^|\\\/)?\\\*$/
309
+ const MODE_IGNORE = 'regex'
310
+ const MODE_CHECK_IGNORE = 'checkRegex'
311
+ const UNDERSCORE = '_'
312
+
313
+ const TRAILING_WILD_CARD_REPLACERS = {
314
+ [MODE_IGNORE] (_, p1) {
315
+ const prefix = p1
316
+ // '\^':
317
+ // '/*' does not match EMPTY
318
+ // '/*' does not match everything
319
+
320
+ // '\\\/':
321
+ // 'abc/*' does not match 'abc/'
322
+ ? `${p1}[^/]+`
323
+
324
+ // 'a*' matches 'a'
325
+ // 'a*' matches 'aa'
326
+ : '[^/]*'
327
+
328
+ return `${prefix}(?=$|\\/$)`
329
+ },
330
+
331
+ [MODE_CHECK_IGNORE] (_, p1) {
332
+ // When doing `git check-ignore`
333
+ const prefix = p1
334
+ // '\\\/':
335
+ // 'abc/*' DOES match 'abc/' !
336
+ ? `${p1}[^/]*`
337
+
338
+ // 'a*' matches 'a'
339
+ // 'a*' matches 'aa'
340
+ : '[^/]*'
341
+
342
+ return `${prefix}(?=$|\\/$)`
343
+ }
344
+ }
345
+
346
+ // @param {pattern}
347
+ const makeRegexPrefix = pattern => REPLACERS.reduce(
348
+ (prev, [matcher, replacer]) =>
349
+ prev.replace(matcher, replacer.bind(pattern)),
350
+ pattern
351
+ )
352
+
353
+ const isString = subject => typeof subject === 'string'
354
+
355
+ // > A blank line matches no files, so it can serve as a separator for readability.
356
+ const checkPattern = pattern => pattern
357
+ && isString(pattern)
358
+ && !REGEX_TEST_BLANK_LINE.test(pattern)
359
+ && !REGEX_INVALID_TRAILING_BACKSLASH.test(pattern)
360
+
361
+ // > A line starting with # serves as a comment.
362
+ && pattern.indexOf('#') !== 0
363
+
364
+ const splitPattern = pattern => pattern
365
+ .split(REGEX_SPLITALL_CRLF)
366
+ .filter(Boolean)
367
+
368
+ class IgnoreRule {
369
+ constructor (
370
+ pattern,
371
+ mark,
372
+ body,
373
+ ignoreCase,
374
+ negative,
375
+ prefix
376
+ ) {
377
+ this.pattern = pattern
378
+ this.mark = mark
379
+ this.negative = negative
380
+
381
+ define(this, 'body', body)
382
+ define(this, 'ignoreCase', ignoreCase)
383
+ define(this, 'regexPrefix', prefix)
384
+ }
385
+
386
+ get regex () {
387
+ const key = UNDERSCORE + MODE_IGNORE
388
+
389
+ if (this[key]) {
390
+ return this[key]
391
+ }
392
+
393
+ return this._make(MODE_IGNORE, key)
394
+ }
395
+
396
+ get checkRegex () {
397
+ const key = UNDERSCORE + MODE_CHECK_IGNORE
398
+
399
+ if (this[key]) {
400
+ return this[key]
401
+ }
402
+
403
+ return this._make(MODE_CHECK_IGNORE, key)
404
+ }
405
+
406
+ _make (mode, key) {
407
+ const str = this.regexPrefix.replace(
408
+ REGEX_REPLACE_TRAILING_WILDCARD,
409
+
410
+ // It does not need to bind pattern
411
+ TRAILING_WILD_CARD_REPLACERS[mode]
412
+ )
413
+
414
+ const regex = this.ignoreCase
415
+ ? new RegExp(str, 'i')
416
+ : new RegExp(str)
417
+
418
+ return define(this, key, regex)
419
+ }
420
+ }
421
+
422
+ const createRule = ({
423
+ pattern,
424
+ mark
425
+ }, ignoreCase) => {
426
+ let negative = false
427
+ let body = pattern
428
+
429
+ // > An optional prefix "!" which negates the pattern;
430
+ if (body.indexOf('!') === 0) {
431
+ negative = true
432
+ body = body.substr(1)
433
+ }
434
+
435
+ body = body
436
+ // > Put a backslash ("\") in front of the first "!" for patterns that
437
+ // > begin with a literal "!", for example, `"\!important!.txt"`.
438
+ .replace(REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION, '!')
439
+ // > Put a backslash ("\") in front of the first hash for patterns that
440
+ // > begin with a hash.
441
+ .replace(REGEX_REPLACE_LEADING_EXCAPED_HASH, '#')
442
+
443
+ const regexPrefix = makeRegexPrefix(body)
444
+
445
+ return new IgnoreRule(
446
+ pattern,
447
+ mark,
448
+ body,
449
+ ignoreCase,
450
+ negative,
451
+ regexPrefix
452
+ )
453
+ }
454
+
455
+ class RuleManager {
456
+ constructor (ignoreCase) {
457
+ this._ignoreCase = ignoreCase
458
+ this._rules = []
459
+ }
460
+
461
+ _add (pattern) {
462
+ // #32
463
+ if (pattern && pattern[KEY_IGNORE]) {
464
+ this._rules = this._rules.concat(pattern._rules._rules)
465
+ this._added = true
466
+ return
467
+ }
468
+
469
+ if (isString(pattern)) {
470
+ pattern = {
471
+ pattern
472
+ }
473
+ }
474
+
475
+ if (checkPattern(pattern.pattern)) {
476
+ const rule = createRule(pattern, this._ignoreCase)
477
+ this._added = true
478
+ this._rules.push(rule)
479
+ }
480
+ }
481
+
482
+ // @param {Array<string> | string | Ignore} pattern
483
+ add (pattern) {
484
+ this._added = false
485
+
486
+ makeArray(
487
+ isString(pattern)
488
+ ? splitPattern(pattern)
489
+ : pattern
490
+ ).forEach(this._add, this)
491
+
492
+ return this._added
493
+ }
494
+
495
+ // Test one single path without recursively checking parent directories
496
+ //
497
+ // - checkUnignored `boolean` whether should check if the path is unignored,
498
+ // setting `checkUnignored` to `false` could reduce additional
499
+ // path matching.
500
+ // - check `string` either `MODE_IGNORE` or `MODE_CHECK_IGNORE`
501
+
502
+ // @returns {TestResult} true if a file is ignored
503
+ test (path, checkUnignored, mode) {
504
+ let ignored = false
505
+ let unignored = false
506
+ let matchedRule
507
+
508
+ this._rules.forEach(rule => {
509
+ const {negative} = rule
510
+
511
+ // | ignored : unignored
512
+ // -------- | ---------------------------------------
513
+ // negative | 0:0 | 0:1 | 1:0 | 1:1
514
+ // -------- | ------- | ------- | ------- | --------
515
+ // 0 | TEST | TEST | SKIP | X
516
+ // 1 | TESTIF | SKIP | TEST | X
517
+
518
+ // - SKIP: always skip
519
+ // - TEST: always test
520
+ // - TESTIF: only test if checkUnignored
521
+ // - X: that never happen
522
+ if (
523
+ unignored === negative && ignored !== unignored
524
+ || negative && !ignored && !unignored && !checkUnignored
525
+ ) {
526
+ return
527
+ }
528
+
529
+ const matched = rule[mode].test(path)
530
+
531
+ if (!matched) {
532
+ return
533
+ }
534
+
535
+ ignored = !negative
536
+ unignored = negative
537
+
538
+ matchedRule = negative
539
+ ? UNDEFINED
540
+ : rule
541
+ })
542
+
543
+ const ret = {
544
+ ignored,
545
+ unignored
546
+ }
547
+
548
+ if (matchedRule) {
549
+ ret.rule = matchedRule
550
+ }
551
+
552
+ return ret
553
+ }
554
+ }
555
+
556
+ const throwError = (message, Ctor) => {
557
+ throw new Ctor(message)
558
+ }
559
+
560
+ const checkPath = (path, originalPath, doThrow) => {
561
+ if (!isString(path)) {
562
+ return doThrow(
563
+ `path must be a string, but got \`${originalPath}\``,
564
+ TypeError
565
+ )
566
+ }
567
+
568
+ // We don't know if we should ignore EMPTY, so throw
569
+ if (!path) {
570
+ return doThrow(`path must not be empty`, TypeError)
571
+ }
572
+
573
+ // Check if it is a relative path
574
+ if (checkPath.isNotRelative(path)) {
575
+ const r = '`path.relative()`d'
576
+ return doThrow(
577
+ `path should be a ${r} string, but got "${originalPath}"`,
578
+ RangeError
579
+ )
580
+ }
581
+
582
+ return true
583
+ }
584
+
585
+ const isNotRelative = path => REGEX_TEST_INVALID_PATH.test(path)
586
+
587
+ checkPath.isNotRelative = isNotRelative
588
+
589
+ // On windows, the following function will be replaced
590
+ /* istanbul ignore next */
591
+ checkPath.convert = p => p
592
+
593
+
594
+ class Ignore {
595
+ constructor ({
596
+ ignorecase = true,
597
+ ignoreCase = ignorecase,
598
+ allowRelativePaths = false
599
+ } = {}) {
600
+ define(this, KEY_IGNORE, true)
601
+
602
+ this._rules = new RuleManager(ignoreCase)
603
+ this._strictPathCheck = !allowRelativePaths
604
+ this._initCache()
605
+ }
606
+
607
+ _initCache () {
608
+ // A cache for the result of `.ignores()`
609
+ this._ignoreCache = Object.create(null)
610
+
611
+ // A cache for the result of `.test()`
612
+ this._testCache = Object.create(null)
613
+ }
614
+
615
+ add (pattern) {
616
+ if (this._rules.add(pattern)) {
617
+ // Some rules have just added to the ignore,
618
+ // making the behavior changed,
619
+ // so we need to re-initialize the result cache
620
+ this._initCache()
621
+ }
622
+
623
+ return this
624
+ }
625
+
626
+ // legacy
627
+ addPattern (pattern) {
628
+ return this.add(pattern)
629
+ }
630
+
631
+ // @returns {TestResult}
632
+ _test (originalPath, cache, checkUnignored, slices) {
633
+ const path = originalPath
634
+ // Supports nullable path
635
+ && checkPath.convert(originalPath)
636
+
637
+ checkPath(
638
+ path,
639
+ originalPath,
640
+ this._strictPathCheck
641
+ ? throwError
642
+ : RETURN_FALSE
643
+ )
644
+
645
+ return this._t(path, cache, checkUnignored, slices)
646
+ }
647
+
648
+ checkIgnore (path) {
649
+ // If the path doest not end with a slash, `.ignores()` is much equivalent
650
+ // to `git check-ignore`
651
+ if (!REGEX_TEST_TRAILING_SLASH.test(path)) {
652
+ return this.test(path)
653
+ }
654
+
655
+ const slices = path.split(SLASH).filter(Boolean)
656
+ slices.pop()
657
+
658
+ if (slices.length) {
659
+ const parent = this._t(
660
+ slices.join(SLASH) + SLASH,
661
+ this._testCache,
662
+ true,
663
+ slices
664
+ )
665
+
666
+ if (parent.ignored) {
667
+ return parent
668
+ }
669
+ }
670
+
671
+ return this._rules.test(path, false, MODE_CHECK_IGNORE)
672
+ }
673
+
674
+ _t (
675
+ // The path to be tested
676
+ path,
677
+
678
+ // The cache for the result of a certain checking
679
+ cache,
680
+
681
+ // Whether should check if the path is unignored
682
+ checkUnignored,
683
+
684
+ // The path slices
685
+ slices
686
+ ) {
687
+ if (path in cache) {
688
+ return cache[path]
689
+ }
690
+
691
+ if (!slices) {
692
+ // path/to/a.js
693
+ // ['path', 'to', 'a.js']
694
+ slices = path.split(SLASH).filter(Boolean)
695
+ }
696
+
697
+ slices.pop()
698
+
699
+ // If the path has no parent directory, just test it
700
+ if (!slices.length) {
701
+ return cache[path] = this._rules.test(path, checkUnignored, MODE_IGNORE)
702
+ }
703
+
704
+ const parent = this._t(
705
+ slices.join(SLASH) + SLASH,
706
+ cache,
707
+ checkUnignored,
708
+ slices
709
+ )
710
+
711
+ // If the path contains a parent directory, check the parent first
712
+ return cache[path] = parent.ignored
713
+ // > It is not possible to re-include a file if a parent directory of
714
+ // > that file is excluded.
715
+ ? parent
716
+ : this._rules.test(path, checkUnignored, MODE_IGNORE)
717
+ }
718
+
719
+ ignores (path) {
720
+ return this._test(path, this._ignoreCache, false).ignored
721
+ }
722
+
723
+ createFilter () {
724
+ return path => !this.ignores(path)
725
+ }
726
+
727
+ filter (paths) {
728
+ return makeArray(paths).filter(this.createFilter())
729
+ }
730
+
731
+ // @returns {TestResult}
732
+ test (path) {
733
+ return this._test(path, this._testCache, true)
734
+ }
735
+ }
736
+
737
+ const factory = options => new Ignore(options)
738
+
739
+ const isPathValid = path =>
740
+ checkPath(path && checkPath.convert(path), path, RETURN_FALSE)
741
+
742
+ /* istanbul ignore next */
743
+ const setupWindows = () => {
744
+ /* eslint no-control-regex: "off" */
745
+ const makePosix = str => /^\\\\\?\\/.test(str)
746
+ || /["<>|\u0000-\u001F]+/u.test(str)
747
+ ? str
748
+ : str.replace(/\\/g, '/')
749
+
750
+ checkPath.convert = makePosix
751
+
752
+ // 'C:\\foo' <- 'C:\\foo' has been converted to 'C:/'
753
+ // 'd:\\foo'
754
+ const REGEX_TEST_WINDOWS_PATH_ABSOLUTE = /^[a-z]:\//i
755
+ checkPath.isNotRelative = path =>
756
+ REGEX_TEST_WINDOWS_PATH_ABSOLUTE.test(path)
757
+ || isNotRelative(path)
758
+ }
759
+
760
+
761
+ // Windows
762
+ // --------------------------------------------------------------
763
+ /* istanbul ignore next */
764
+ if (
765
+ // Detect `process` so that it can run in browsers.
766
+ typeof process !== 'undefined'
767
+ && process.platform === 'win32'
768
+ ) {
769
+ setupWindows()
770
+ }
771
+
772
+ // COMMONJS_EXPORTS ////////////////////////////////////////////////////////////
773
+
774
+ module.exports = factory
775
+
776
+ // Although it is an anti-pattern,
777
+ // it is still widely misused by a lot of libraries in github
778
+ // Ref: https://github.com/search?q=ignore.default%28%29&type=code
779
+ factory.default = factory
780
+
781
+ module.exports.isPathValid = isPathValid
782
+
783
+ // For testing purposes
784
+ define(module.exports, Symbol.for('setupWindows'), setupWindows)