opal 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (202) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -1
  3. data/lib/opal/cli.rb +9 -1
  4. data/lib/opal/cli_options.rb +12 -3
  5. data/lib/opal/cli_runners/nodejs.rb +3 -2
  6. data/lib/opal/version.rb +1 -1
  7. data/opal/corelib/kernel.rb +7 -0
  8. data/opal/corelib/runtime.js +4 -0
  9. data/spec/lib/cli_spec.rb +16 -0
  10. data/stdlib/nodejs.rb +1 -2
  11. data/stdlib/nodejs/{process.rb → kernel.rb} +7 -4
  12. data/stdlib/nodejs/node_modules/.bin/js-yaml +140 -0
  13. data/stdlib/nodejs/node_modules/glob/LICENSE +15 -0
  14. data/stdlib/nodejs/node_modules/glob/README.md +357 -0
  15. data/stdlib/nodejs/node_modules/glob/common.js +177 -0
  16. data/stdlib/nodejs/node_modules/glob/glob.js +649 -0
  17. data/stdlib/nodejs/node_modules/glob/node_modules/inflight/.eslintrc +17 -0
  18. data/stdlib/nodejs/node_modules/glob/node_modules/inflight/LICENSE +15 -0
  19. data/stdlib/nodejs/node_modules/glob/node_modules/inflight/README.md +37 -0
  20. data/stdlib/nodejs/node_modules/glob/node_modules/inflight/inflight.js +44 -0
  21. data/stdlib/nodejs/node_modules/glob/node_modules/inflight/node_modules/wrappy/LICENSE +15 -0
  22. data/stdlib/nodejs/node_modules/glob/node_modules/inflight/node_modules/wrappy/README.md +36 -0
  23. data/stdlib/nodejs/node_modules/glob/node_modules/inflight/node_modules/wrappy/package.json +52 -0
  24. data/stdlib/nodejs/node_modules/glob/node_modules/inflight/node_modules/wrappy/test/basic.js +51 -0
  25. data/stdlib/nodejs/node_modules/glob/node_modules/inflight/node_modules/wrappy/wrappy.js +33 -0
  26. data/stdlib/nodejs/node_modules/glob/node_modules/inflight/package.json +61 -0
  27. data/stdlib/nodejs/node_modules/glob/node_modules/inflight/test.js +97 -0
  28. data/stdlib/nodejs/node_modules/glob/node_modules/inherits/LICENSE +16 -0
  29. data/stdlib/nodejs/node_modules/glob/node_modules/inherits/README.md +42 -0
  30. data/stdlib/nodejs/node_modules/glob/node_modules/inherits/inherits.js +1 -0
  31. data/stdlib/nodejs/node_modules/glob/node_modules/inherits/inherits_browser.js +23 -0
  32. data/stdlib/nodejs/node_modules/glob/node_modules/inherits/package.json +51 -0
  33. data/stdlib/nodejs/node_modules/glob/node_modules/inherits/test.js +25 -0
  34. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/.npmignore +1 -0
  35. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/.travis.yml +4 -0
  36. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/LICENSE +23 -0
  37. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/README.md +216 -0
  38. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/benchmark.js +15 -0
  39. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/browser.js +1181 -0
  40. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/minimatch.js +845 -0
  41. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/.npmignore +2 -0
  42. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/.travis.yml +3 -0
  43. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/README.md +121 -0
  44. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/example.js +8 -0
  45. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/index.js +191 -0
  46. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/.npmignore +2 -0
  47. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/.travis.yml +4 -0
  48. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/Makefile +6 -0
  49. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/README.md +80 -0
  50. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/example.js +5 -0
  51. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/index.js +38 -0
  52. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/package.json +73 -0
  53. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/test/balanced.js +56 -0
  54. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map/.travis.yml +4 -0
  55. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map/LICENSE +18 -0
  56. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map/README.markdown +62 -0
  57. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map/example/map.js +6 -0
  58. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map/index.js +13 -0
  59. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map/package.json +83 -0
  60. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map/test/map.js +39 -0
  61. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/package.json +75 -0
  62. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/bash-comparison.js +32 -0
  63. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/bash-results.txt +1075 -0
  64. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/cases.txt +182 -0
  65. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/dollar.js +9 -0
  66. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/empty-option.js +10 -0
  67. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/generate.sh +24 -0
  68. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/negative-increment.js +15 -0
  69. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/nested.js +16 -0
  70. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/order.js +10 -0
  71. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/pad.js +13 -0
  72. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/same-type.js +7 -0
  73. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/sequence.js +50 -0
  74. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/package.json +60 -0
  75. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/test/basic.js +399 -0
  76. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/test/brace-expand.js +45 -0
  77. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/test/defaults.js +274 -0
  78. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/test/extglob-ending-with-state-char.js +8 -0
  79. data/stdlib/nodejs/node_modules/glob/node_modules/once/LICENSE +27 -0
  80. data/stdlib/nodejs/node_modules/glob/node_modules/once/README.md +51 -0
  81. data/stdlib/nodejs/node_modules/glob/node_modules/once/node_modules/wrappy/LICENSE +15 -0
  82. data/stdlib/nodejs/node_modules/glob/node_modules/once/node_modules/wrappy/README.md +36 -0
  83. data/stdlib/nodejs/node_modules/glob/node_modules/once/node_modules/wrappy/package.json +52 -0
  84. data/stdlib/nodejs/node_modules/glob/node_modules/once/node_modules/wrappy/test/basic.js +51 -0
  85. data/stdlib/nodejs/node_modules/glob/node_modules/once/node_modules/wrappy/wrappy.js +33 -0
  86. data/stdlib/nodejs/node_modules/glob/node_modules/once/once.js +21 -0
  87. data/stdlib/nodejs/node_modules/glob/node_modules/once/package.json +60 -0
  88. data/stdlib/nodejs/node_modules/glob/node_modules/once/test/once.js +23 -0
  89. data/stdlib/nodejs/node_modules/glob/package.json +72 -0
  90. data/stdlib/nodejs/node_modules/glob/sync.js +409 -0
  91. data/stdlib/nodejs/node_modules/js-yaml/HISTORY.md +277 -0
  92. data/stdlib/nodejs/node_modules/js-yaml/LICENSE +21 -0
  93. data/stdlib/nodejs/node_modules/js-yaml/README.md +288 -0
  94. data/stdlib/nodejs/node_modules/js-yaml/bin/js-yaml.js +140 -0
  95. data/stdlib/nodejs/node_modules/js-yaml/bower.json +23 -0
  96. data/stdlib/nodejs/node_modules/js-yaml/dist/js-yaml.js +3666 -0
  97. data/stdlib/nodejs/node_modules/js-yaml/dist/js-yaml.min.js +3 -0
  98. data/stdlib/nodejs/node_modules/js-yaml/examples/custom_types.js +102 -0
  99. data/stdlib/nodejs/node_modules/js-yaml/examples/custom_types.yml +18 -0
  100. data/stdlib/nodejs/node_modules/js-yaml/examples/dumper.js +31 -0
  101. data/stdlib/nodejs/node_modules/js-yaml/examples/dumper.json +22 -0
  102. data/stdlib/nodejs/node_modules/js-yaml/examples/sample_document.js +18 -0
  103. data/stdlib/nodejs/node_modules/js-yaml/examples/sample_document.yml +197 -0
  104. data/stdlib/nodejs/node_modules/js-yaml/index.js +7 -0
  105. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml.js +39 -0
  106. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/common.js +62 -0
  107. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/dumper.js +554 -0
  108. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/exception.js +25 -0
  109. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/loader.js +1581 -0
  110. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/mark.js +78 -0
  111. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/schema.js +103 -0
  112. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/schema/core.js +18 -0
  113. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/schema/default_full.js +25 -0
  114. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/schema/default_safe.js +28 -0
  115. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/schema/failsafe.js +17 -0
  116. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/schema/json.js +25 -0
  117. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type.js +61 -0
  118. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/binary.js +133 -0
  119. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/bool.js +37 -0
  120. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/float.js +110 -0
  121. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/int.js +183 -0
  122. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/js/function.js +85 -0
  123. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/js/regexp.js +84 -0
  124. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/js/undefined.js +27 -0
  125. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/map.js +8 -0
  126. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/merge.js +12 -0
  127. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/null.js +36 -0
  128. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/omap.js +56 -0
  129. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/pairs.js +61 -0
  130. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/seq.js +8 -0
  131. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/set.js +33 -0
  132. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/str.js +8 -0
  133. data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/timestamp.js +98 -0
  134. data/stdlib/nodejs/node_modules/js-yaml/node_modules/.bin/esparse +117 -0
  135. data/stdlib/nodejs/node_modules/js-yaml/node_modules/.bin/esvalidate +177 -0
  136. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/HISTORY.md +115 -0
  137. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/LICENSE +21 -0
  138. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/README.md +239 -0
  139. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/arguments.js +36 -0
  140. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/choice.js +22 -0
  141. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/constants.js +59 -0
  142. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/help.js +13 -0
  143. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/nargs.js +33 -0
  144. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/parents.js +28 -0
  145. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/prefix_chars.js +23 -0
  146. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/sub_commands.js +49 -0
  147. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/sum.js +35 -0
  148. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/testformatters.js +270 -0
  149. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/index.js +1 -0
  150. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action.js +146 -0
  151. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/append.js +55 -0
  152. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/append/constant.js +47 -0
  153. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/count.js +40 -0
  154. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/help.js +48 -0
  155. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/store.js +50 -0
  156. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/store/constant.js +43 -0
  157. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/store/false.js +27 -0
  158. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/store/true.js +26 -0
  159. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/subparsers.js +148 -0
  160. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/version.js +50 -0
  161. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action_container.js +481 -0
  162. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/argparse.js +14 -0
  163. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/argument/error.js +50 -0
  164. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/argument/exclusive.js +54 -0
  165. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/argument/group.js +75 -0
  166. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/argument_parser.js +1168 -0
  167. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/const.js +18 -0
  168. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/help/added_formatters.js +88 -0
  169. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/help/formatter.js +798 -0
  170. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/namespace.js +77 -0
  171. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/.npmignore +2 -0
  172. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/.travis.yml +8 -0
  173. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/README.markdown +825 -0
  174. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/bower.json +33 -0
  175. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/component.json +11 -0
  176. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/foo.js +10 -0
  177. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/gulpfile.js +26 -0
  178. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/lib/underscore.string.js +673 -0
  179. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/libpeerconnection.log +0 -0
  180. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/package.json +107 -0
  181. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore/LICENSE +23 -0
  182. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore/README.md +22 -0
  183. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore/package.json +69 -0
  184. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore/underscore-min.js +6 -0
  185. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore/underscore.js +1415 -0
  186. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/package.json +62 -0
  187. data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/README.md +73 -0
  188. data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/bin/esparse.js +117 -0
  189. data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/bin/esvalidate.js +177 -0
  190. data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/esprima.js +3908 -0
  191. data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/package.json +69 -0
  192. data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/test/compat.js +239 -0
  193. data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/test/reflect.js +422 -0
  194. data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/test/run.js +66 -0
  195. data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/test/runner.js +387 -0
  196. data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/test/test.js +20238 -0
  197. data/stdlib/nodejs/node_modules/js-yaml/package.json +83 -0
  198. data/{package.json → stdlib/nodejs/package.json} +0 -3
  199. data/stdlib/phantomjs.rb +1 -6
  200. data/tasks/testing.rake +1 -4
  201. metadata +191 -6
  202. data/stdlib/nodejs/runtime.rb +0 -26
@@ -0,0 +1,177 @@
1
+ exports.alphasort = alphasort
2
+ exports.alphasorti = alphasorti
3
+ exports.isAbsolute = process.platform === "win32" ? absWin : absUnix
4
+ exports.setopts = setopts
5
+ exports.ownProp = ownProp
6
+ exports.makeAbs = makeAbs
7
+ exports.finish = finish
8
+ exports.mark = mark
9
+
10
+ function ownProp (obj, field) {
11
+ return Object.prototype.hasOwnProperty.call(obj, field)
12
+ }
13
+
14
+ var path = require("path")
15
+ var minimatch = require("minimatch")
16
+ var Minimatch = minimatch.Minimatch
17
+
18
+ function absWin (p) {
19
+ if (absUnix(p)) return true
20
+ // pull off the device/UNC bit from a windows path.
21
+ // from node's lib/path.js
22
+ var splitDeviceRe =
23
+ /^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?([\s\S]*?)$/
24
+ var result = splitDeviceRe.exec(p)
25
+ var device = result[1] || ''
26
+ var isUnc = device && device.charAt(1) !== ':'
27
+ var isAbsolute = !!result[2] || isUnc // UNC paths are always absolute
28
+
29
+ return isAbsolute
30
+ }
31
+
32
+ function absUnix (p) {
33
+ return p.charAt(0) === "/" || p === ""
34
+ }
35
+
36
+ function alphasorti (a, b) {
37
+ return a.toLowerCase().localeCompare(b.toLowerCase())
38
+ }
39
+
40
+ function alphasort (a, b) {
41
+ return a.localeCompare(b)
42
+ }
43
+
44
+
45
+ function setopts (self, pattern, options) {
46
+ if (!options)
47
+ options = {}
48
+
49
+ // base-matching: just use globstar for that.
50
+ if (options.matchBase && -1 === pattern.indexOf("/")) {
51
+ if (options.noglobstar) {
52
+ throw new Error("base matching requires globstar")
53
+ }
54
+ pattern = "**/" + pattern
55
+ }
56
+
57
+ self.pattern = pattern
58
+ self.strict = options.strict !== false
59
+ self.dot = !!options.dot
60
+ self.mark = !!options.mark
61
+ self.nodir = !!options.nodir
62
+ if (self.nodir)
63
+ self.mark = true
64
+ self.sync = !!options.sync
65
+ self.nounique = !!options.nounique
66
+ self.nonull = !!options.nonull
67
+ self.nosort = !!options.nosort
68
+ self.nocase = !!options.nocase
69
+ self.stat = !!options.stat
70
+ self.noprocess = !!options.noprocess
71
+
72
+ self.maxLength = options.maxLength || Infinity
73
+ self.cache = options.cache || Object.create(null)
74
+ self.statCache = options.statCache || Object.create(null)
75
+ self.symlinks = options.symlinks || Object.create(null)
76
+
77
+ self.changedCwd = false
78
+ var cwd = process.cwd()
79
+ if (!ownProp(options, "cwd"))
80
+ self.cwd = cwd
81
+ else {
82
+ self.cwd = options.cwd
83
+ self.changedCwd = path.resolve(options.cwd) !== cwd
84
+ }
85
+
86
+ self.root = options.root || path.resolve(self.cwd, "/")
87
+ self.root = path.resolve(self.root)
88
+ if (process.platform === "win32")
89
+ self.root = self.root.replace(/\\/g, "/")
90
+
91
+ self.nomount = !!options.nomount
92
+
93
+ self.minimatch = new Minimatch(pattern, options)
94
+ self.options = self.minimatch.options
95
+ }
96
+
97
+ function finish (self) {
98
+ var nou = self.nounique
99
+ var all = nou ? [] : Object.create(null)
100
+
101
+ for (var i = 0, l = self.matches.length; i < l; i ++) {
102
+ var matches = self.matches[i]
103
+ if (!matches) {
104
+ if (self.nonull) {
105
+ // do like the shell, and spit out the literal glob
106
+ var literal = self.minimatch.globSet[i]
107
+ if (nou)
108
+ all.push(literal)
109
+ else
110
+ all[literal] = true
111
+ }
112
+ } else {
113
+ // had matches
114
+ var m = Object.keys(matches)
115
+ if (nou)
116
+ all.push.apply(all, m)
117
+ else
118
+ m.forEach(function (m) {
119
+ all[m] = true
120
+ })
121
+ }
122
+ }
123
+
124
+ if (!nou)
125
+ all = Object.keys(all)
126
+
127
+ if (!self.nosort)
128
+ all = all.sort(self.nocase ? alphasorti : alphasort)
129
+
130
+ // at *some* point we statted all of these
131
+ if (self.mark) {
132
+ for (var i = 0; i < all.length; i++) {
133
+ all[i] = self._mark(all[i])
134
+ }
135
+ if (self.nodir) {
136
+ all = all.filter(function (e) {
137
+ return !(/\/$/.test(e))
138
+ })
139
+ }
140
+ }
141
+
142
+ self.found = all
143
+ }
144
+
145
+ function mark (self, p) {
146
+ var c = self.cache[p]
147
+ var m = p
148
+ if (c) {
149
+ var isDir = c === 'DIR' || Array.isArray(c)
150
+ var slash = p.slice(-1) === '/'
151
+
152
+ if (isDir && !slash)
153
+ m += '/'
154
+ else if (!isDir && slash)
155
+ m = m.slice(0, -1)
156
+
157
+ if (m !== p) {
158
+ self.statCache[m] = self.statCache[p]
159
+ self.cache[m] = self.cache[p]
160
+ }
161
+ }
162
+
163
+ return m
164
+ }
165
+
166
+ // lotta situps...
167
+ function makeAbs (self, f) {
168
+ var abs = f
169
+ if (f.charAt(0) === "/") {
170
+ abs = path.join(self.root, f)
171
+ } else if (exports.isAbsolute(f)) {
172
+ abs = f
173
+ } else if (self.changedCwd) {
174
+ abs = path.resolve(self.cwd, f)
175
+ }
176
+ return abs
177
+ }
@@ -0,0 +1,649 @@
1
+ // Approach:
2
+ //
3
+ // 1. Get the minimatch set
4
+ // 2. For each pattern in the set, PROCESS(pattern, false)
5
+ // 3. Store matches per-set, then uniq them
6
+ //
7
+ // PROCESS(pattern, inGlobStar)
8
+ // Get the first [n] items from pattern that are all strings
9
+ // Join these together. This is PREFIX.
10
+ // If there is no more remaining, then stat(PREFIX) and
11
+ // add to matches if it succeeds. END.
12
+ //
13
+ // If inGlobStar and PREFIX is symlink and points to dir
14
+ // set ENTRIES = []
15
+ // else readdir(PREFIX) as ENTRIES
16
+ // If fail, END
17
+ //
18
+ // with ENTRIES
19
+ // If pattern[n] is GLOBSTAR
20
+ // // handle the case where the globstar match is empty
21
+ // // by pruning it out, and testing the resulting pattern
22
+ // PROCESS(pattern[0..n] + pattern[n+1 .. $], false)
23
+ // // handle other cases.
24
+ // for ENTRY in ENTRIES (not dotfiles)
25
+ // // attach globstar + tail onto the entry
26
+ // // Mark that this entry is a globstar match
27
+ // PROCESS(pattern[0..n] + ENTRY + pattern[n .. $], true)
28
+ //
29
+ // else // not globstar
30
+ // for ENTRY in ENTRIES (not dotfiles, unless pattern[n] is dot)
31
+ // Test ENTRY against pattern[n]
32
+ // If fails, continue
33
+ // If passes, PROCESS(pattern[0..n] + item + pattern[n+1 .. $])
34
+ //
35
+ // Caveat:
36
+ // Cache all stats and readdirs results to minimize syscall. Since all
37
+ // we ever care about is existence and directory-ness, we can just keep
38
+ // `true` for files, and [children,...] for directories, or `false` for
39
+ // things that don't exist.
40
+
41
+ module.exports = glob
42
+
43
+ var fs = require('fs')
44
+ var minimatch = require('minimatch')
45
+ var Minimatch = minimatch.Minimatch
46
+ var inherits = require('inherits')
47
+ var EE = require('events').EventEmitter
48
+ var path = require('path')
49
+ var assert = require('assert')
50
+ var globSync = require('./sync.js')
51
+ var common = require('./common.js')
52
+ var alphasort = common.alphasort
53
+ var alphasorti = common.alphasorti
54
+ var isAbsolute = common.isAbsolute
55
+ var setopts = common.setopts
56
+ var ownProp = common.ownProp
57
+ var inflight = require('inflight')
58
+ var util = require('util')
59
+
60
+ var once = require('once')
61
+
62
+ function glob (pattern, options, cb) {
63
+ if (typeof options === 'function') cb = options, options = {}
64
+ if (!options) options = {}
65
+
66
+ if (options.sync) {
67
+ if (cb)
68
+ throw new TypeError('callback provided to sync glob')
69
+ return globSync(pattern, options)
70
+ }
71
+
72
+ return new Glob(pattern, options, cb)
73
+ }
74
+
75
+ glob.sync = globSync
76
+ var GlobSync = glob.GlobSync = globSync.GlobSync
77
+
78
+ // old api surface
79
+ glob.glob = glob
80
+
81
+ glob.hasMagic = function (pattern, options_) {
82
+ var options = util._extend({}, options_)
83
+ options.noprocess = true
84
+
85
+ var g = new Glob(pattern, options)
86
+ var set = g.minimatch.set
87
+ if (set.length > 1)
88
+ return true
89
+
90
+ for (var j = 0; j < set[0].length; j++) {
91
+ if (typeof set[0][j] !== 'string')
92
+ return true
93
+ }
94
+
95
+ return false
96
+ }
97
+
98
+ glob.Glob = Glob
99
+ inherits(Glob, EE)
100
+ function Glob (pattern, options, cb) {
101
+ if (typeof options === 'function') {
102
+ cb = options
103
+ options = null
104
+ }
105
+
106
+ if (options && options.sync) {
107
+ if (cb)
108
+ throw new TypeError('callback provided to sync glob')
109
+ return new GlobSync(pattern, options)
110
+ }
111
+
112
+ if (!(this instanceof Glob))
113
+ return new Glob(pattern, options, cb)
114
+
115
+ setopts(this, pattern, options)
116
+
117
+ // process each pattern in the minimatch set
118
+ var n = this.minimatch.set.length
119
+
120
+ // The matches are stored as {<filename>: true,...} so that
121
+ // duplicates are automagically pruned.
122
+ // Later, we do an Object.keys() on these.
123
+ // Keep them as a list so we can fill in when nonull is set.
124
+ this.matches = new Array(n)
125
+
126
+ if (typeof cb === 'function') {
127
+ cb = once(cb)
128
+ this.on('error', cb)
129
+ this.on('end', function (matches) {
130
+ cb(null, matches)
131
+ })
132
+ }
133
+
134
+ var self = this
135
+ var n = this.minimatch.set.length
136
+ this._processing = 0
137
+ this.matches = new Array(n)
138
+
139
+ this._emitQueue = []
140
+ this._processQueue = []
141
+ this.paused = false
142
+
143
+ if (this.noprocess)
144
+ return this
145
+
146
+ if (n === 0)
147
+ return done()
148
+
149
+ for (var i = 0; i < n; i ++) {
150
+ this._process(this.minimatch.set[i], i, false, done)
151
+ }
152
+
153
+ function done () {
154
+ --self._processing
155
+ if (self._processing <= 0)
156
+ self._finish()
157
+ }
158
+ }
159
+
160
+ Glob.prototype._finish = function () {
161
+ assert(this instanceof Glob)
162
+ if (this.aborted)
163
+ return
164
+
165
+ //console.error('FINISH', this.matches)
166
+ common.finish(this)
167
+ this.emit('end', this.found)
168
+ }
169
+
170
+ Glob.prototype._mark = function (p) {
171
+ return common.mark(this, p)
172
+ }
173
+
174
+ Glob.prototype._makeAbs = function (f) {
175
+ return common.makeAbs(this, f)
176
+ }
177
+
178
+ Glob.prototype.abort = function () {
179
+ this.aborted = true
180
+ this.emit('abort')
181
+ }
182
+
183
+ Glob.prototype.pause = function () {
184
+ if (!this.paused) {
185
+ this.paused = true
186
+ this.emit('pause')
187
+ }
188
+ }
189
+
190
+ Glob.prototype.resume = function () {
191
+ if (this.paused) {
192
+ this.emit('resume')
193
+ this.paused = false
194
+ if (this._emitQueue.length) {
195
+ var eq = this._emitQueue.slice(0)
196
+ this._emitQueue.length = 0
197
+ for (var i = 0; i < eq.length; i ++) {
198
+ var e = eq[i]
199
+ this._emitMatch(e[0], e[1])
200
+ }
201
+ }
202
+ if (this._processQueue.length) {
203
+ var pq = this._processQueue.slice(0)
204
+ this._processQueue.length = 0
205
+ for (var i = 0; i < pq.length; i ++) {
206
+ var p = pq[i]
207
+ this._processing--
208
+ this._process(p[0], p[1], p[2], p[3])
209
+ }
210
+ }
211
+ }
212
+ }
213
+
214
+ Glob.prototype._process = function (pattern, index, inGlobStar, cb) {
215
+ assert(this instanceof Glob)
216
+ assert(typeof cb === 'function')
217
+
218
+ if (this.aborted)
219
+ return
220
+
221
+ this._processing++
222
+ if (this.paused) {
223
+ this._processQueue.push([pattern, index, inGlobStar, cb])
224
+ return
225
+ }
226
+
227
+ //console.error('PROCESS %d', this._processing, pattern)
228
+
229
+ // Get the first [n] parts of pattern that are all strings.
230
+ var n = 0
231
+ while (typeof pattern[n] === 'string') {
232
+ n ++
233
+ }
234
+ // now n is the index of the first one that is *not* a string.
235
+
236
+ // see if there's anything else
237
+ var prefix
238
+ switch (n) {
239
+ // if not, then this is rather simple
240
+ case pattern.length:
241
+ this._processSimple(pattern.join('/'), index, cb)
242
+ return
243
+
244
+ case 0:
245
+ // pattern *starts* with some non-trivial item.
246
+ // going to readdir(cwd), but not include the prefix in matches.
247
+ prefix = null
248
+ break
249
+
250
+ default:
251
+ // pattern has some string bits in the front.
252
+ // whatever it starts with, whether that's 'absolute' like /foo/bar,
253
+ // or 'relative' like '../baz'
254
+ prefix = pattern.slice(0, n).join('/')
255
+ break
256
+ }
257
+
258
+ var remain = pattern.slice(n)
259
+
260
+ // get the list of entries.
261
+ var read
262
+ if (prefix === null)
263
+ read = '.'
264
+ else if (isAbsolute(prefix) || isAbsolute(pattern.join('/'))) {
265
+ if (!prefix || !isAbsolute(prefix))
266
+ prefix = '/' + prefix
267
+ read = prefix
268
+ } else
269
+ read = prefix
270
+
271
+ var abs = this._makeAbs(read)
272
+
273
+ var isGlobStar = remain[0] === minimatch.GLOBSTAR
274
+ if (isGlobStar)
275
+ this._processGlobStar(prefix, read, abs, remain, index, inGlobStar, cb)
276
+ else
277
+ this._processReaddir(prefix, read, abs, remain, index, inGlobStar, cb)
278
+ }
279
+
280
+
281
+ Glob.prototype._processReaddir = function (prefix, read, abs, remain, index, inGlobStar, cb) {
282
+ var self = this
283
+ this._readdir(abs, inGlobStar, function (er, entries) {
284
+ return self._processReaddir2(prefix, read, abs, remain, index, inGlobStar, entries, cb)
285
+ })
286
+ }
287
+
288
+ Glob.prototype._processReaddir2 = function (prefix, read, abs, remain, index, inGlobStar, entries, cb) {
289
+
290
+ // if the abs isn't a dir, then nothing can match!
291
+ if (!entries)
292
+ return cb()
293
+
294
+ // It will only match dot entries if it starts with a dot, or if
295
+ // dot is set. Stuff like @(.foo|.bar) isn't allowed.
296
+ var pn = remain[0]
297
+ var negate = !!this.minimatch.negate
298
+ var rawGlob = pn._glob
299
+ var dotOk = this.dot || rawGlob.charAt(0) === '.'
300
+
301
+ var matchedEntries = []
302
+ for (var i = 0; i < entries.length; i++) {
303
+ var e = entries[i]
304
+ if (e.charAt(0) !== '.' || dotOk) {
305
+ var m
306
+ if (negate && !prefix) {
307
+ m = !e.match(pn)
308
+ } else {
309
+ m = e.match(pn)
310
+ }
311
+ if (m)
312
+ matchedEntries.push(e)
313
+ }
314
+ }
315
+
316
+ //console.error('prd2', prefix, entries, remain[0]._glob, matchedEntries)
317
+
318
+ var len = matchedEntries.length
319
+ // If there are no matched entries, then nothing matches.
320
+ if (len === 0)
321
+ return cb()
322
+
323
+ // if this is the last remaining pattern bit, then no need for
324
+ // an additional stat *unless* the user has specified mark or
325
+ // stat explicitly. We know they exist, since readdir returned
326
+ // them.
327
+
328
+ if (remain.length === 1 && !this.mark && !this.stat) {
329
+ if (!this.matches[index])
330
+ this.matches[index] = Object.create(null)
331
+
332
+ for (var i = 0; i < len; i ++) {
333
+ var e = matchedEntries[i]
334
+ if (prefix) {
335
+ if (prefix !== '/')
336
+ e = prefix + '/' + e
337
+ else
338
+ e = prefix + e
339
+ }
340
+
341
+ if (e.charAt(0) === '/' && !this.nomount) {
342
+ e = path.join(this.root, e)
343
+ }
344
+ this._emitMatch(index, e)
345
+ }
346
+ // This was the last one, and no stats were needed
347
+ return cb()
348
+ }
349
+
350
+ // now test all matched entries as stand-ins for that part
351
+ // of the pattern.
352
+ remain.shift()
353
+ for (var i = 0; i < len; i ++) {
354
+ var e = matchedEntries[i]
355
+ var newPattern
356
+ if (prefix) {
357
+ if (prefix !== '/')
358
+ e = prefix + '/' + e
359
+ else
360
+ e = prefix + e
361
+ }
362
+ this._process([e].concat(remain), index, inGlobStar, cb)
363
+ }
364
+ cb()
365
+ }
366
+
367
+ Glob.prototype._emitMatch = function (index, e) {
368
+ if (this.aborted)
369
+ return
370
+
371
+ if (!this.matches[index][e]) {
372
+ if (this.paused) {
373
+ this._emitQueue.push([index, e])
374
+ return
375
+ }
376
+
377
+ if (this.nodir) {
378
+ var c = this.cache[this._makeAbs(e)]
379
+ if (c === 'DIR' || Array.isArray(c))
380
+ return
381
+ }
382
+
383
+ this.matches[index][e] = true
384
+ if (!this.stat && !this.mark)
385
+ return this.emit('match', e)
386
+
387
+ var self = this
388
+ this._stat(this._makeAbs(e), function (er, c, st) {
389
+ self.emit('stat', e, st)
390
+ self.emit('match', e)
391
+ })
392
+ }
393
+ }
394
+
395
+ Glob.prototype._readdirInGlobStar = function (abs, cb) {
396
+ if (this.aborted)
397
+ return
398
+
399
+ var lstatkey = 'lstat\0' + abs
400
+ var self = this
401
+ var lstatcb = inflight(lstatkey, lstatcb_)
402
+
403
+ if (lstatcb)
404
+ fs.lstat(abs, lstatcb)
405
+
406
+ function lstatcb_ (er, lstat) {
407
+ if (er)
408
+ return cb()
409
+
410
+ var isSym = lstat.isSymbolicLink()
411
+ self.symlinks[abs] = isSym
412
+
413
+ // If it's not a symlink or a dir, then it's definitely a regular file.
414
+ // don't bother doing a readdir in that case.
415
+ if (!isSym && !lstat.isDirectory()) {
416
+ self.cache[abs] = 'FILE'
417
+ cb()
418
+ } else
419
+ self._readdir(abs, false, cb)
420
+ }
421
+ }
422
+
423
+ Glob.prototype._readdir = function (abs, inGlobStar, cb) {
424
+ if (this.aborted)
425
+ return
426
+
427
+ cb = inflight('readdir\0'+abs+'\0'+inGlobStar, cb)
428
+ if (!cb)
429
+ return
430
+
431
+ //console.error('RD %j %j', +inGlobStar, abs)
432
+ if (inGlobStar && !ownProp(this.symlinks, abs))
433
+ return this._readdirInGlobStar(abs, cb)
434
+
435
+ if (ownProp(this.cache, abs)) {
436
+ var c = this.cache[abs]
437
+ if (!c || c === 'FILE')
438
+ return cb()
439
+
440
+ if (Array.isArray(c))
441
+ return cb(null, c)
442
+ }
443
+
444
+ var self = this
445
+ fs.readdir(abs, readdirCb(this, abs, cb))
446
+ }
447
+
448
+ function readdirCb (self, abs, cb) {
449
+ return function (er, entries) {
450
+ if (er)
451
+ self._readdirError(abs, er, cb)
452
+ else
453
+ self._readdirEntries(abs, entries, cb)
454
+ }
455
+ }
456
+
457
+ Glob.prototype._readdirEntries = function (abs, entries, cb) {
458
+ if (this.aborted)
459
+ return
460
+
461
+ // if we haven't asked to stat everything, then just
462
+ // assume that everything in there exists, so we can avoid
463
+ // having to stat it a second time.
464
+ if (!this.mark && !this.stat) {
465
+ for (var i = 0; i < entries.length; i ++) {
466
+ var e = entries[i]
467
+ if (abs === '/')
468
+ e = abs + e
469
+ else
470
+ e = abs + '/' + e
471
+ this.cache[e] = true
472
+ }
473
+ }
474
+
475
+ this.cache[abs] = entries
476
+ return cb(null, entries)
477
+ }
478
+
479
+ Glob.prototype._readdirError = function (f, er, cb) {
480
+ if (this.aborted)
481
+ return
482
+
483
+ // handle errors, and cache the information
484
+ switch (er.code) {
485
+ case 'ENOTDIR': // totally normal. means it *does* exist.
486
+ this.cache[f] = 'FILE'
487
+ break
488
+
489
+ case 'ENOENT': // not terribly unusual
490
+ case 'ELOOP':
491
+ case 'ENAMETOOLONG':
492
+ case 'UNKNOWN':
493
+ this.cache[f] = false
494
+ break
495
+
496
+ default: // some unusual error. Treat as failure.
497
+ this.cache[f] = false
498
+ if (this.strict) return this.emit('error', er)
499
+ if (!this.silent) console.error('glob error', er)
500
+ break
501
+ }
502
+ return cb()
503
+ }
504
+
505
+ Glob.prototype._processGlobStar = function (prefix, read, abs, remain, index, inGlobStar, cb) {
506
+ var self = this
507
+ this._readdir(abs, inGlobStar, function (er, entries) {
508
+ self._processGlobStar2(prefix, read, abs, remain, index, inGlobStar, entries, cb)
509
+ })
510
+ }
511
+
512
+
513
+ Glob.prototype._processGlobStar2 = function (prefix, read, abs, remain, index, inGlobStar, entries, cb) {
514
+ //console.error('pgs2', prefix, remain[0], entries)
515
+
516
+ // no entries means not a dir, so it can never have matches
517
+ // foo.txt/** doesn't match foo.txt
518
+ if (!entries)
519
+ return cb()
520
+
521
+ // test without the globstar, and with every child both below
522
+ // and replacing the globstar.
523
+ var remainWithoutGlobStar = remain.slice(1)
524
+ var gspref = prefix ? [ prefix ] : []
525
+ var noGlobStar = gspref.concat(remainWithoutGlobStar)
526
+
527
+ // the noGlobStar pattern exits the inGlobStar state
528
+ this._process(noGlobStar, index, false, cb)
529
+
530
+ var isSym = this.symlinks[abs]
531
+ var len = entries.length
532
+
533
+ // If it's a symlink, and we're in a globstar, then stop
534
+ if (isSym && inGlobStar)
535
+ return cb()
536
+
537
+ for (var i = 0; i < len; i++) {
538
+ var e = entries[i]
539
+ if (e.charAt(0) === '.' && !this.dot)
540
+ continue
541
+
542
+ // these two cases enter the inGlobStar state
543
+ var instead = gspref.concat(entries[i], remainWithoutGlobStar)
544
+ this._process(instead, index, true, cb)
545
+
546
+ var below = gspref.concat(entries[i], remain)
547
+ this._process(below, index, true, cb)
548
+ }
549
+
550
+ cb()
551
+ }
552
+
553
+ Glob.prototype._processSimple = function (prefix, index, cb) {
554
+ // XXX review this. Shouldn't it be doing the mounting etc
555
+ // before doing stat? kinda weird?
556
+ var self = this
557
+ this._stat(prefix, function (er, exists) {
558
+ self._processSimple2(prefix, index, er, exists, cb)
559
+ })
560
+ }
561
+ Glob.prototype._processSimple2 = function (prefix, index, er, exists, cb) {
562
+
563
+ //console.error('ps2', prefix, exists)
564
+
565
+ if (!this.matches[index])
566
+ this.matches[index] = Object.create(null)
567
+
568
+ // If it doesn't exist, then just mark the lack of results
569
+ if (!exists)
570
+ return cb()
571
+
572
+ if (prefix && isAbsolute(prefix) && !this.nomount) {
573
+ var trail = /[\/\\]$/.test(prefix)
574
+ if (prefix.charAt(0) === '/') {
575
+ prefix = path.join(this.root, prefix)
576
+ } else {
577
+ prefix = path.resolve(this.root, prefix)
578
+ if (trail)
579
+ prefix += '/'
580
+ }
581
+ }
582
+
583
+ if (process.platform === 'win32')
584
+ prefix = prefix.replace(/\\/g, '/')
585
+
586
+ // Mark this as a match
587
+ this._emitMatch(index, prefix)
588
+ cb()
589
+ }
590
+
591
+ // Returns either 'DIR', 'FILE', or false
592
+ Glob.prototype._stat = function (f, cb) {
593
+ var abs = f
594
+ if (f.charAt(0) === '/')
595
+ abs = path.join(this.root, f)
596
+ else if (this.changedCwd)
597
+ abs = path.resolve(this.cwd, f)
598
+
599
+
600
+ if (f.length > this.maxLength)
601
+ return cb()
602
+
603
+ if (!this.stat && ownProp(this.cache, f)) {
604
+ var c = this.cache[f]
605
+
606
+ if (Array.isArray(c))
607
+ c = 'DIR'
608
+
609
+ // It exists, but not how we need it
610
+ if (abs.slice(-1) === '/' && c !== 'DIR')
611
+ return cb()
612
+
613
+ return cb(null, c)
614
+ }
615
+
616
+ var exists
617
+ var stat = this.statCache[abs]
618
+ if (stat !== undefined) {
619
+ if (stat === false)
620
+ return cb(null, stat)
621
+ else
622
+ return cb(null, stat.isDirectory() ? 'DIR' : 'FILE', stat)
623
+ }
624
+
625
+ var self = this
626
+ var statcb = inflight('stat\0' + abs, statcb_)
627
+ if (statcb)
628
+ fs.stat(abs, statcb)
629
+
630
+ function statcb_ (er, stat) {
631
+ self._stat2(f, abs, er, stat, cb)
632
+ }
633
+ }
634
+
635
+ Glob.prototype._stat2 = function (f, abs, er, stat, cb) {
636
+ if (er) {
637
+ this.statCache[abs] = false
638
+ return cb()
639
+ }
640
+
641
+ this.statCache[abs] = stat
642
+
643
+ if (abs.slice(-1) === '/' && !stat.isDirectory())
644
+ return cb(null, false, stat)
645
+
646
+ var c = stat.isDirectory() ? 'DIR' : 'FILE'
647
+ this.cache[f] = this.cache[f] || c
648
+ return cb(null, c, stat)
649
+ }