dragonfly_chrome_headless 0.2.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 (228) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.travis.yml +12 -0
  4. data/Gemfile +4 -0
  5. data/README.md +53 -0
  6. data/Rakefile +10 -0
  7. data/bin/console +14 -0
  8. data/bin/setup +8 -0
  9. data/dragonfly_chrome_headless.gemspec +27 -0
  10. data/lib/dragonfly_chrome_headless.rb +9 -0
  11. data/lib/dragonfly_chrome_headless/plugin.rb +17 -0
  12. data/lib/dragonfly_chrome_headless/processors/rasterize.rb +33 -0
  13. data/lib/dragonfly_chrome_headless/version.rb +3 -0
  14. data/node_modules/.bin/chrome-remote-interface +1 -0
  15. data/node_modules/.bin/mkdirp +1 -0
  16. data/node_modules/.bin/rimraf +1 -0
  17. data/node_modules/@types/core-js/LICENSE +21 -0
  18. data/node_modules/@types/core-js/README.md +16 -0
  19. data/node_modules/@types/core-js/index.d.ts +2452 -0
  20. data/node_modules/@types/core-js/package.json +85 -0
  21. data/node_modules/@types/mkdirp/README.md +18 -0
  22. data/node_modules/@types/mkdirp/index.d.ts +14 -0
  23. data/node_modules/@types/mkdirp/package.json +77 -0
  24. data/node_modules/@types/mkdirp/types-metadata.json +25 -0
  25. data/node_modules/@types/node/README.md +16 -0
  26. data/node_modules/@types/node/index.d.ts +4132 -0
  27. data/node_modules/@types/node/package.json +84 -0
  28. data/node_modules/balanced-match/.npmignore +5 -0
  29. data/node_modules/balanced-match/LICENSE.md +21 -0
  30. data/node_modules/balanced-match/README.md +91 -0
  31. data/node_modules/balanced-match/index.js +59 -0
  32. data/node_modules/balanced-match/package.json +112 -0
  33. data/node_modules/brace-expansion/README.md +123 -0
  34. data/node_modules/brace-expansion/index.js +201 -0
  35. data/node_modules/brace-expansion/package.json +114 -0
  36. data/node_modules/chrome-launcher/.clang-format +6 -0
  37. data/node_modules/chrome-launcher/.npmignore +11 -0
  38. data/node_modules/chrome-launcher/README.md +123 -0
  39. data/node_modules/chrome-launcher/ask.js +32 -0
  40. data/node_modules/chrome-launcher/ask.ts +35 -0
  41. data/node_modules/chrome-launcher/chrome-finder.js +157 -0
  42. data/node_modules/chrome-launcher/chrome-finder.ts +186 -0
  43. data/node_modules/chrome-launcher/chrome-launcher.js +245 -0
  44. data/node_modules/chrome-launcher/chrome-launcher.ts +312 -0
  45. data/node_modules/chrome-launcher/compiled-check.js +14 -0
  46. data/node_modules/chrome-launcher/flags.js +27 -0
  47. data/node_modules/chrome-launcher/flags.ts +26 -0
  48. data/node_modules/chrome-launcher/index.js +7 -0
  49. data/node_modules/chrome-launcher/index.ts +1 -0
  50. data/node_modules/chrome-launcher/manual-chrome-launcher.js +30 -0
  51. data/node_modules/chrome-launcher/package.json +116 -0
  52. data/node_modules/chrome-launcher/random-port.js +24 -0
  53. data/node_modules/chrome-launcher/random-port.ts +23 -0
  54. data/node_modules/chrome-launcher/tsconfig.json +19 -0
  55. data/node_modules/chrome-launcher/utils.js +52 -0
  56. data/node_modules/chrome-launcher/utils.ts +44 -0
  57. data/node_modules/chrome-launcher/yarn.lock +1486 -0
  58. data/node_modules/chrome-remote-interface/LICENSE +18 -0
  59. data/node_modules/chrome-remote-interface/README.md +849 -0
  60. data/node_modules/chrome-remote-interface/bin/client.js +337 -0
  61. data/node_modules/chrome-remote-interface/chrome-remote-interface.js +11 -0
  62. data/node_modules/chrome-remote-interface/index.js +39 -0
  63. data/node_modules/chrome-remote-interface/lib/api.js +84 -0
  64. data/node_modules/chrome-remote-interface/lib/chrome.js +307 -0
  65. data/node_modules/chrome-remote-interface/lib/defaults.js +4 -0
  66. data/node_modules/chrome-remote-interface/lib/devtools.js +245 -0
  67. data/node_modules/chrome-remote-interface/lib/external-request.js +28 -0
  68. data/node_modules/chrome-remote-interface/lib/protocol.json +13780 -0
  69. data/node_modules/chrome-remote-interface/lib/websocket-wrapper.js +32 -0
  70. data/node_modules/chrome-remote-interface/package.json +128 -0
  71. data/node_modules/chrome-remote-interface/webpack.config.js +55 -0
  72. data/node_modules/commander/Readme.md +195 -0
  73. data/node_modules/commander/index.js +851 -0
  74. data/node_modules/commander/package.json +92 -0
  75. data/node_modules/concat-map/.travis.yml +4 -0
  76. data/node_modules/concat-map/LICENSE +18 -0
  77. data/node_modules/concat-map/README.markdown +62 -0
  78. data/node_modules/concat-map/example/map.js +6 -0
  79. data/node_modules/concat-map/index.js +13 -0
  80. data/node_modules/concat-map/package.json +117 -0
  81. data/node_modules/concat-map/test/map.js +39 -0
  82. data/node_modules/debug/.coveralls.yml +1 -0
  83. data/node_modules/debug/.eslintrc +11 -0
  84. data/node_modules/debug/.npmignore +9 -0
  85. data/node_modules/debug/.travis.yml +14 -0
  86. data/node_modules/debug/CHANGELOG.md +357 -0
  87. data/node_modules/debug/LICENSE +19 -0
  88. data/node_modules/debug/Makefile +50 -0
  89. data/node_modules/debug/Readme.md +312 -0
  90. data/node_modules/debug/component.json +19 -0
  91. data/node_modules/debug/karma.conf.js +70 -0
  92. data/node_modules/debug/node.js +1 -0
  93. data/node_modules/debug/package.json +124 -0
  94. data/node_modules/debug/src/browser.js +185 -0
  95. data/node_modules/debug/src/debug.js +202 -0
  96. data/node_modules/debug/src/index.js +10 -0
  97. data/node_modules/debug/src/node.js +246 -0
  98. data/node_modules/fs.realpath/LICENSE +43 -0
  99. data/node_modules/fs.realpath/README.md +33 -0
  100. data/node_modules/fs.realpath/index.js +66 -0
  101. data/node_modules/fs.realpath/old.js +303 -0
  102. data/node_modules/fs.realpath/package.json +94 -0
  103. data/node_modules/glob/LICENSE +15 -0
  104. data/node_modules/glob/README.md +368 -0
  105. data/node_modules/glob/changelog.md +67 -0
  106. data/node_modules/glob/common.js +240 -0
  107. data/node_modules/glob/glob.js +790 -0
  108. data/node_modules/glob/package.json +112 -0
  109. data/node_modules/glob/sync.js +486 -0
  110. data/node_modules/html-pdf-chrome/.npmignore +9 -0
  111. data/node_modules/html-pdf-chrome/LICENSE +21 -0
  112. data/node_modules/html-pdf-chrome/README.md +165 -0
  113. data/node_modules/html-pdf-chrome/lib/src/ChromePrintOptions.d.ts +87 -0
  114. data/node_modules/html-pdf-chrome/lib/src/ChromePrintOptions.js +4 -0
  115. data/node_modules/html-pdf-chrome/lib/src/ChromePrintOptions.js.map +1 -0
  116. data/node_modules/html-pdf-chrome/lib/src/CompletionTrigger.d.ts +120 -0
  117. data/node_modules/html-pdf-chrome/lib/src/CompletionTrigger.js +206 -0
  118. data/node_modules/html-pdf-chrome/lib/src/CompletionTrigger.js.map +1 -0
  119. data/node_modules/html-pdf-chrome/lib/src/CreateResult.d.ts +70 -0
  120. data/node_modules/html-pdf-chrome/lib/src/CreateResult.js +98 -0
  121. data/node_modules/html-pdf-chrome/lib/src/CreateResult.js.map +1 -0
  122. data/node_modules/html-pdf-chrome/lib/src/index.d.ts +72 -0
  123. data/node_modules/html-pdf-chrome/lib/src/index.js +123 -0
  124. data/node_modules/html-pdf-chrome/lib/src/index.js.map +1 -0
  125. data/node_modules/html-pdf-chrome/package.json +133 -0
  126. data/node_modules/html-pdf-chrome/src/ChromePrintOptions.ts +99 -0
  127. data/node_modules/html-pdf-chrome/src/CompletionTrigger.ts +201 -0
  128. data/node_modules/html-pdf-chrome/src/CreateResult.ts +100 -0
  129. data/node_modules/html-pdf-chrome/src/index.ts +179 -0
  130. data/node_modules/inflight/LICENSE +15 -0
  131. data/node_modules/inflight/README.md +37 -0
  132. data/node_modules/inflight/inflight.js +54 -0
  133. data/node_modules/inflight/package.json +105 -0
  134. data/node_modules/inherits/LICENSE +16 -0
  135. data/node_modules/inherits/README.md +42 -0
  136. data/node_modules/inherits/inherits.js +7 -0
  137. data/node_modules/inherits/inherits_browser.js +23 -0
  138. data/node_modules/inherits/package.json +97 -0
  139. data/node_modules/lighthouse-logger/README.md +4 -0
  140. data/node_modules/lighthouse-logger/index.js +212 -0
  141. data/node_modules/lighthouse-logger/package.json +69 -0
  142. data/node_modules/lighthouse-logger/yarn.lock +13 -0
  143. data/node_modules/minimatch/LICENSE +15 -0
  144. data/node_modules/minimatch/README.md +209 -0
  145. data/node_modules/minimatch/minimatch.js +923 -0
  146. data/node_modules/minimatch/package.json +99 -0
  147. data/node_modules/minimist/.travis.yml +4 -0
  148. data/node_modules/minimist/LICENSE +18 -0
  149. data/node_modules/minimist/example/parse.js +2 -0
  150. data/node_modules/minimist/index.js +187 -0
  151. data/node_modules/minimist/package.json +101 -0
  152. data/node_modules/minimist/readme.markdown +73 -0
  153. data/node_modules/minimist/test/dash.js +24 -0
  154. data/node_modules/minimist/test/default_bool.js +20 -0
  155. data/node_modules/minimist/test/dotted.js +16 -0
  156. data/node_modules/minimist/test/long.js +31 -0
  157. data/node_modules/minimist/test/parse.js +318 -0
  158. data/node_modules/minimist/test/parse_modified.js +9 -0
  159. data/node_modules/minimist/test/short.js +67 -0
  160. data/node_modules/minimist/test/whitespace.js +8 -0
  161. data/node_modules/mkdirp/.travis.yml +8 -0
  162. data/node_modules/mkdirp/LICENSE +21 -0
  163. data/node_modules/mkdirp/bin/cmd.js +33 -0
  164. data/node_modules/mkdirp/bin/usage.txt +12 -0
  165. data/node_modules/mkdirp/examples/pow.js +6 -0
  166. data/node_modules/mkdirp/index.js +98 -0
  167. data/node_modules/mkdirp/package.json +93 -0
  168. data/node_modules/mkdirp/readme.markdown +100 -0
  169. data/node_modules/mkdirp/test/chmod.js +41 -0
  170. data/node_modules/mkdirp/test/clobber.js +38 -0
  171. data/node_modules/mkdirp/test/mkdirp.js +28 -0
  172. data/node_modules/mkdirp/test/opts_fs.js +29 -0
  173. data/node_modules/mkdirp/test/opts_fs_sync.js +27 -0
  174. data/node_modules/mkdirp/test/perm.js +32 -0
  175. data/node_modules/mkdirp/test/perm_sync.js +36 -0
  176. data/node_modules/mkdirp/test/race.js +37 -0
  177. data/node_modules/mkdirp/test/rel.js +32 -0
  178. data/node_modules/mkdirp/test/return.js +25 -0
  179. data/node_modules/mkdirp/test/return_sync.js +24 -0
  180. data/node_modules/mkdirp/test/root.js +19 -0
  181. data/node_modules/mkdirp/test/sync.js +32 -0
  182. data/node_modules/mkdirp/test/umask.js +28 -0
  183. data/node_modules/mkdirp/test/umask_sync.js +32 -0
  184. data/node_modules/ms/README.md +51 -0
  185. data/node_modules/ms/index.js +152 -0
  186. data/node_modules/ms/license.md +21 -0
  187. data/node_modules/ms/package.json +109 -0
  188. data/node_modules/once/LICENSE +15 -0
  189. data/node_modules/once/README.md +79 -0
  190. data/node_modules/once/once.js +42 -0
  191. data/node_modules/once/package.json +101 -0
  192. data/node_modules/path-is-absolute/index.js +20 -0
  193. data/node_modules/path-is-absolute/license +21 -0
  194. data/node_modules/path-is-absolute/package.json +111 -0
  195. data/node_modules/path-is-absolute/readme.md +59 -0
  196. data/node_modules/rimraf/LICENSE +15 -0
  197. data/node_modules/rimraf/README.md +101 -0
  198. data/node_modules/rimraf/bin.js +50 -0
  199. data/node_modules/rimraf/package.json +99 -0
  200. data/node_modules/rimraf/rimraf.js +363 -0
  201. data/node_modules/ultron/LICENSE +22 -0
  202. data/node_modules/ultron/index.js +138 -0
  203. data/node_modules/ultron/package.json +112 -0
  204. data/node_modules/wrappy/LICENSE +15 -0
  205. data/node_modules/wrappy/README.md +36 -0
  206. data/node_modules/wrappy/package.json +97 -0
  207. data/node_modules/wrappy/wrappy.js +33 -0
  208. data/node_modules/ws/LICENSE +21 -0
  209. data/node_modules/ws/README.md +259 -0
  210. data/node_modules/ws/SECURITY.md +33 -0
  211. data/node_modules/ws/index.js +15 -0
  212. data/node_modules/ws/lib/BufferUtil.fallback.js +56 -0
  213. data/node_modules/ws/lib/BufferUtil.js +15 -0
  214. data/node_modules/ws/lib/ErrorCodes.js +28 -0
  215. data/node_modules/ws/lib/EventTarget.js +158 -0
  216. data/node_modules/ws/lib/Extensions.js +69 -0
  217. data/node_modules/ws/lib/PerMessageDeflate.js +339 -0
  218. data/node_modules/ws/lib/Receiver.js +520 -0
  219. data/node_modules/ws/lib/Sender.js +438 -0
  220. data/node_modules/ws/lib/Validation.fallback.js +9 -0
  221. data/node_modules/ws/lib/Validation.js +17 -0
  222. data/node_modules/ws/lib/WebSocket.js +705 -0
  223. data/node_modules/ws/lib/WebSocketServer.js +336 -0
  224. data/node_modules/ws/package.json +122 -0
  225. data/package.json +26 -0
  226. data/samples/sample.html +13 -0
  227. data/script/rasterize.js +18 -0
  228. metadata +325 -0
@@ -0,0 +1,363 @@
1
+ module.exports = rimraf
2
+ rimraf.sync = rimrafSync
3
+
4
+ var assert = require("assert")
5
+ var path = require("path")
6
+ var fs = require("fs")
7
+ var glob = require("glob")
8
+
9
+ var defaultGlobOpts = {
10
+ nosort: true,
11
+ silent: true
12
+ }
13
+
14
+ // for EMFILE handling
15
+ var timeout = 0
16
+
17
+ var isWindows = (process.platform === "win32")
18
+
19
+ function defaults (options) {
20
+ var methods = [
21
+ 'unlink',
22
+ 'chmod',
23
+ 'stat',
24
+ 'lstat',
25
+ 'rmdir',
26
+ 'readdir'
27
+ ]
28
+ methods.forEach(function(m) {
29
+ options[m] = options[m] || fs[m]
30
+ m = m + 'Sync'
31
+ options[m] = options[m] || fs[m]
32
+ })
33
+
34
+ options.maxBusyTries = options.maxBusyTries || 3
35
+ options.emfileWait = options.emfileWait || 1000
36
+ if (options.glob === false) {
37
+ options.disableGlob = true
38
+ }
39
+ options.disableGlob = options.disableGlob || false
40
+ options.glob = options.glob || defaultGlobOpts
41
+ }
42
+
43
+ function rimraf (p, options, cb) {
44
+ if (typeof options === 'function') {
45
+ cb = options
46
+ options = {}
47
+ }
48
+
49
+ assert(p, 'rimraf: missing path')
50
+ assert.equal(typeof p, 'string', 'rimraf: path should be a string')
51
+ assert.equal(typeof cb, 'function', 'rimraf: callback function required')
52
+ assert(options, 'rimraf: invalid options argument provided')
53
+ assert.equal(typeof options, 'object', 'rimraf: options should be object')
54
+
55
+ defaults(options)
56
+
57
+ var busyTries = 0
58
+ var errState = null
59
+ var n = 0
60
+
61
+ if (options.disableGlob || !glob.hasMagic(p))
62
+ return afterGlob(null, [p])
63
+
64
+ options.lstat(p, function (er, stat) {
65
+ if (!er)
66
+ return afterGlob(null, [p])
67
+
68
+ glob(p, options.glob, afterGlob)
69
+ })
70
+
71
+ function next (er) {
72
+ errState = errState || er
73
+ if (--n === 0)
74
+ cb(errState)
75
+ }
76
+
77
+ function afterGlob (er, results) {
78
+ if (er)
79
+ return cb(er)
80
+
81
+ n = results.length
82
+ if (n === 0)
83
+ return cb()
84
+
85
+ results.forEach(function (p) {
86
+ rimraf_(p, options, function CB (er) {
87
+ if (er) {
88
+ if ((er.code === "EBUSY" || er.code === "ENOTEMPTY" || er.code === "EPERM") &&
89
+ busyTries < options.maxBusyTries) {
90
+ busyTries ++
91
+ var time = busyTries * 100
92
+ // try again, with the same exact callback as this one.
93
+ return setTimeout(function () {
94
+ rimraf_(p, options, CB)
95
+ }, time)
96
+ }
97
+
98
+ // this one won't happen if graceful-fs is used.
99
+ if (er.code === "EMFILE" && timeout < options.emfileWait) {
100
+ return setTimeout(function () {
101
+ rimraf_(p, options, CB)
102
+ }, timeout ++)
103
+ }
104
+
105
+ // already gone
106
+ if (er.code === "ENOENT") er = null
107
+ }
108
+
109
+ timeout = 0
110
+ next(er)
111
+ })
112
+ })
113
+ }
114
+ }
115
+
116
+ // Two possible strategies.
117
+ // 1. Assume it's a file. unlink it, then do the dir stuff on EPERM or EISDIR
118
+ // 2. Assume it's a directory. readdir, then do the file stuff on ENOTDIR
119
+ //
120
+ // Both result in an extra syscall when you guess wrong. However, there
121
+ // are likely far more normal files in the world than directories. This
122
+ // is based on the assumption that a the average number of files per
123
+ // directory is >= 1.
124
+ //
125
+ // If anyone ever complains about this, then I guess the strategy could
126
+ // be made configurable somehow. But until then, YAGNI.
127
+ function rimraf_ (p, options, cb) {
128
+ assert(p)
129
+ assert(options)
130
+ assert(typeof cb === 'function')
131
+
132
+ // sunos lets the root user unlink directories, which is... weird.
133
+ // so we have to lstat here and make sure it's not a dir.
134
+ options.lstat(p, function (er, st) {
135
+ if (er && er.code === "ENOENT")
136
+ return cb(null)
137
+
138
+ // Windows can EPERM on stat. Life is suffering.
139
+ if (er && er.code === "EPERM" && isWindows)
140
+ fixWinEPERM(p, options, er, cb)
141
+
142
+ if (st && st.isDirectory())
143
+ return rmdir(p, options, er, cb)
144
+
145
+ options.unlink(p, function (er) {
146
+ if (er) {
147
+ if (er.code === "ENOENT")
148
+ return cb(null)
149
+ if (er.code === "EPERM")
150
+ return (isWindows)
151
+ ? fixWinEPERM(p, options, er, cb)
152
+ : rmdir(p, options, er, cb)
153
+ if (er.code === "EISDIR")
154
+ return rmdir(p, options, er, cb)
155
+ }
156
+ return cb(er)
157
+ })
158
+ })
159
+ }
160
+
161
+ function fixWinEPERM (p, options, er, cb) {
162
+ assert(p)
163
+ assert(options)
164
+ assert(typeof cb === 'function')
165
+ if (er)
166
+ assert(er instanceof Error)
167
+
168
+ options.chmod(p, 666, function (er2) {
169
+ if (er2)
170
+ cb(er2.code === "ENOENT" ? null : er)
171
+ else
172
+ options.stat(p, function(er3, stats) {
173
+ if (er3)
174
+ cb(er3.code === "ENOENT" ? null : er)
175
+ else if (stats.isDirectory())
176
+ rmdir(p, options, er, cb)
177
+ else
178
+ options.unlink(p, cb)
179
+ })
180
+ })
181
+ }
182
+
183
+ function fixWinEPERMSync (p, options, er) {
184
+ assert(p)
185
+ assert(options)
186
+ if (er)
187
+ assert(er instanceof Error)
188
+
189
+ try {
190
+ options.chmodSync(p, 666)
191
+ } catch (er2) {
192
+ if (er2.code === "ENOENT")
193
+ return
194
+ else
195
+ throw er
196
+ }
197
+
198
+ try {
199
+ var stats = options.statSync(p)
200
+ } catch (er3) {
201
+ if (er3.code === "ENOENT")
202
+ return
203
+ else
204
+ throw er
205
+ }
206
+
207
+ if (stats.isDirectory())
208
+ rmdirSync(p, options, er)
209
+ else
210
+ options.unlinkSync(p)
211
+ }
212
+
213
+ function rmdir (p, options, originalEr, cb) {
214
+ assert(p)
215
+ assert(options)
216
+ if (originalEr)
217
+ assert(originalEr instanceof Error)
218
+ assert(typeof cb === 'function')
219
+
220
+ // try to rmdir first, and only readdir on ENOTEMPTY or EEXIST (SunOS)
221
+ // if we guessed wrong, and it's not a directory, then
222
+ // raise the original error.
223
+ options.rmdir(p, function (er) {
224
+ if (er && (er.code === "ENOTEMPTY" || er.code === "EEXIST" || er.code === "EPERM"))
225
+ rmkids(p, options, cb)
226
+ else if (er && er.code === "ENOTDIR")
227
+ cb(originalEr)
228
+ else
229
+ cb(er)
230
+ })
231
+ }
232
+
233
+ function rmkids(p, options, cb) {
234
+ assert(p)
235
+ assert(options)
236
+ assert(typeof cb === 'function')
237
+
238
+ options.readdir(p, function (er, files) {
239
+ if (er)
240
+ return cb(er)
241
+ var n = files.length
242
+ if (n === 0)
243
+ return options.rmdir(p, cb)
244
+ var errState
245
+ files.forEach(function (f) {
246
+ rimraf(path.join(p, f), options, function (er) {
247
+ if (errState)
248
+ return
249
+ if (er)
250
+ return cb(errState = er)
251
+ if (--n === 0)
252
+ options.rmdir(p, cb)
253
+ })
254
+ })
255
+ })
256
+ }
257
+
258
+ // this looks simpler, and is strictly *faster*, but will
259
+ // tie up the JavaScript thread and fail on excessively
260
+ // deep directory trees.
261
+ function rimrafSync (p, options) {
262
+ options = options || {}
263
+ defaults(options)
264
+
265
+ assert(p, 'rimraf: missing path')
266
+ assert.equal(typeof p, 'string', 'rimraf: path should be a string')
267
+ assert(options, 'rimraf: missing options')
268
+ assert.equal(typeof options, 'object', 'rimraf: options should be object')
269
+
270
+ var results
271
+
272
+ if (options.disableGlob || !glob.hasMagic(p)) {
273
+ results = [p]
274
+ } else {
275
+ try {
276
+ options.lstatSync(p)
277
+ results = [p]
278
+ } catch (er) {
279
+ results = glob.sync(p, options.glob)
280
+ }
281
+ }
282
+
283
+ if (!results.length)
284
+ return
285
+
286
+ for (var i = 0; i < results.length; i++) {
287
+ var p = results[i]
288
+
289
+ try {
290
+ var st = options.lstatSync(p)
291
+ } catch (er) {
292
+ if (er.code === "ENOENT")
293
+ return
294
+
295
+ // Windows can EPERM on stat. Life is suffering.
296
+ if (er.code === "EPERM" && isWindows)
297
+ fixWinEPERMSync(p, options, er)
298
+ }
299
+
300
+ try {
301
+ // sunos lets the root user unlink directories, which is... weird.
302
+ if (st && st.isDirectory())
303
+ rmdirSync(p, options, null)
304
+ else
305
+ options.unlinkSync(p)
306
+ } catch (er) {
307
+ if (er.code === "ENOENT")
308
+ return
309
+ if (er.code === "EPERM")
310
+ return isWindows ? fixWinEPERMSync(p, options, er) : rmdirSync(p, options, er)
311
+ if (er.code !== "EISDIR")
312
+ throw er
313
+
314
+ rmdirSync(p, options, er)
315
+ }
316
+ }
317
+ }
318
+
319
+ function rmdirSync (p, options, originalEr) {
320
+ assert(p)
321
+ assert(options)
322
+ if (originalEr)
323
+ assert(originalEr instanceof Error)
324
+
325
+ try {
326
+ options.rmdirSync(p)
327
+ } catch (er) {
328
+ if (er.code === "ENOENT")
329
+ return
330
+ if (er.code === "ENOTDIR")
331
+ throw originalEr
332
+ if (er.code === "ENOTEMPTY" || er.code === "EEXIST" || er.code === "EPERM")
333
+ rmkidsSync(p, options)
334
+ }
335
+ }
336
+
337
+ function rmkidsSync (p, options) {
338
+ assert(p)
339
+ assert(options)
340
+ options.readdirSync(p).forEach(function (f) {
341
+ rimrafSync(path.join(p, f), options)
342
+ })
343
+
344
+ // We only end up here once we got ENOTEMPTY at least once, and
345
+ // at this point, we are guaranteed to have removed all the kids.
346
+ // So, we know that it won't be ENOENT or ENOTDIR or anything else.
347
+ // try really hard to delete stuff on windows, because it has a
348
+ // PROFOUNDLY annoying habit of not closing handles promptly when
349
+ // files are deleted, resulting in spurious ENOTEMPTY errors.
350
+ var retries = isWindows ? 100 : 1
351
+ var i = 0
352
+ do {
353
+ var threw = true
354
+ try {
355
+ var ret = options.rmdirSync(p, options)
356
+ threw = false
357
+ return ret
358
+ } finally {
359
+ if (++i < retries && threw)
360
+ continue
361
+ }
362
+ } while (true)
363
+ }
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Unshift.io, Arnout Kazemier, the Contributors.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,138 @@
1
+ 'use strict';
2
+
3
+ var has = Object.prototype.hasOwnProperty;
4
+
5
+ /**
6
+ * An auto incrementing id which we can use to create "unique" Ultron instances
7
+ * so we can track the event emitters that are added through the Ultron
8
+ * interface.
9
+ *
10
+ * @type {Number}
11
+ * @private
12
+ */
13
+ var id = 0;
14
+
15
+ /**
16
+ * Ultron is high-intelligence robot. It gathers intelligence so it can start improving
17
+ * upon his rudimentary design. It will learn from your EventEmitting patterns
18
+ * and exterminate them.
19
+ *
20
+ * @constructor
21
+ * @param {EventEmitter} ee EventEmitter instance we need to wrap.
22
+ * @api public
23
+ */
24
+ function Ultron(ee) {
25
+ if (!(this instanceof Ultron)) return new Ultron(ee);
26
+
27
+ this.id = id++;
28
+ this.ee = ee;
29
+ }
30
+
31
+ /**
32
+ * Register a new EventListener for the given event.
33
+ *
34
+ * @param {String} event Name of the event.
35
+ * @param {Functon} fn Callback function.
36
+ * @param {Mixed} context The context of the function.
37
+ * @returns {Ultron}
38
+ * @api public
39
+ */
40
+ Ultron.prototype.on = function on(event, fn, context) {
41
+ fn.__ultron = this.id;
42
+ this.ee.on(event, fn, context);
43
+
44
+ return this;
45
+ };
46
+ /**
47
+ * Add an EventListener that's only called once.
48
+ *
49
+ * @param {String} event Name of the event.
50
+ * @param {Function} fn Callback function.
51
+ * @param {Mixed} context The context of the function.
52
+ * @returns {Ultron}
53
+ * @api public
54
+ */
55
+ Ultron.prototype.once = function once(event, fn, context) {
56
+ fn.__ultron = this.id;
57
+ this.ee.once(event, fn, context);
58
+
59
+ return this;
60
+ };
61
+
62
+ /**
63
+ * Remove the listeners we assigned for the given event.
64
+ *
65
+ * @returns {Ultron}
66
+ * @api public
67
+ */
68
+ Ultron.prototype.remove = function remove() {
69
+ var args = arguments
70
+ , ee = this.ee
71
+ , event;
72
+
73
+ //
74
+ // When no event names are provided we assume that we need to clear all the
75
+ // events that were assigned through us.
76
+ //
77
+ if (args.length === 1 && 'string' === typeof args[0]) {
78
+ args = args[0].split(/[, ]+/);
79
+ } else if (!args.length) {
80
+ if (ee.eventNames) {
81
+ args = ee.eventNames();
82
+ } else if (ee._events) {
83
+ args = [];
84
+
85
+ for (event in ee._events) {
86
+ if (has.call(ee._events, event)) args.push(event);
87
+ }
88
+
89
+ if (Object.getOwnPropertySymbols) {
90
+ args = args.concat(Object.getOwnPropertySymbols(ee._events));
91
+ }
92
+ }
93
+ }
94
+
95
+ for (var i = 0; i < args.length; i++) {
96
+ var listeners = ee.listeners(args[i]);
97
+
98
+ for (var j = 0; j < listeners.length; j++) {
99
+ event = listeners[j];
100
+
101
+ //
102
+ // Once listeners have a `listener` property that stores the real listener
103
+ // in the EventEmitter that ships with Node.js.
104
+ //
105
+ if (event.listener) {
106
+ if (event.listener.__ultron !== this.id) continue;
107
+ delete event.listener.__ultron;
108
+ } else {
109
+ if (event.__ultron !== this.id) continue;
110
+ delete event.__ultron;
111
+ }
112
+
113
+ ee.removeListener(args[i], event);
114
+ }
115
+ }
116
+
117
+ return this;
118
+ };
119
+
120
+ /**
121
+ * Destroy the Ultron instance, remove all listeners and release all references.
122
+ *
123
+ * @returns {Boolean}
124
+ * @api public
125
+ */
126
+ Ultron.prototype.destroy = function destroy() {
127
+ if (!this.ee) return false;
128
+
129
+ this.remove();
130
+ this.ee = null;
131
+
132
+ return true;
133
+ };
134
+
135
+ //
136
+ // Expose the module.
137
+ //
138
+ module.exports = Ultron;