dragonfly_chrome_headless 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +12 -0
- data/Gemfile +4 -0
- data/README.md +53 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/dragonfly_chrome_headless.gemspec +27 -0
- data/lib/dragonfly_chrome_headless.rb +9 -0
- data/lib/dragonfly_chrome_headless/plugin.rb +17 -0
- data/lib/dragonfly_chrome_headless/processors/rasterize.rb +33 -0
- data/lib/dragonfly_chrome_headless/version.rb +3 -0
- data/node_modules/.bin/chrome-remote-interface +1 -0
- data/node_modules/.bin/mkdirp +1 -0
- data/node_modules/.bin/rimraf +1 -0
- data/node_modules/@types/core-js/LICENSE +21 -0
- data/node_modules/@types/core-js/README.md +16 -0
- data/node_modules/@types/core-js/index.d.ts +2452 -0
- data/node_modules/@types/core-js/package.json +85 -0
- data/node_modules/@types/mkdirp/README.md +18 -0
- data/node_modules/@types/mkdirp/index.d.ts +14 -0
- data/node_modules/@types/mkdirp/package.json +77 -0
- data/node_modules/@types/mkdirp/types-metadata.json +25 -0
- data/node_modules/@types/node/README.md +16 -0
- data/node_modules/@types/node/index.d.ts +4132 -0
- data/node_modules/@types/node/package.json +84 -0
- data/node_modules/balanced-match/.npmignore +5 -0
- data/node_modules/balanced-match/LICENSE.md +21 -0
- data/node_modules/balanced-match/README.md +91 -0
- data/node_modules/balanced-match/index.js +59 -0
- data/node_modules/balanced-match/package.json +112 -0
- data/node_modules/brace-expansion/README.md +123 -0
- data/node_modules/brace-expansion/index.js +201 -0
- data/node_modules/brace-expansion/package.json +114 -0
- data/node_modules/chrome-launcher/.clang-format +6 -0
- data/node_modules/chrome-launcher/.npmignore +11 -0
- data/node_modules/chrome-launcher/README.md +123 -0
- data/node_modules/chrome-launcher/ask.js +32 -0
- data/node_modules/chrome-launcher/ask.ts +35 -0
- data/node_modules/chrome-launcher/chrome-finder.js +157 -0
- data/node_modules/chrome-launcher/chrome-finder.ts +186 -0
- data/node_modules/chrome-launcher/chrome-launcher.js +245 -0
- data/node_modules/chrome-launcher/chrome-launcher.ts +312 -0
- data/node_modules/chrome-launcher/compiled-check.js +14 -0
- data/node_modules/chrome-launcher/flags.js +27 -0
- data/node_modules/chrome-launcher/flags.ts +26 -0
- data/node_modules/chrome-launcher/index.js +7 -0
- data/node_modules/chrome-launcher/index.ts +1 -0
- data/node_modules/chrome-launcher/manual-chrome-launcher.js +30 -0
- data/node_modules/chrome-launcher/package.json +116 -0
- data/node_modules/chrome-launcher/random-port.js +24 -0
- data/node_modules/chrome-launcher/random-port.ts +23 -0
- data/node_modules/chrome-launcher/tsconfig.json +19 -0
- data/node_modules/chrome-launcher/utils.js +52 -0
- data/node_modules/chrome-launcher/utils.ts +44 -0
- data/node_modules/chrome-launcher/yarn.lock +1486 -0
- data/node_modules/chrome-remote-interface/LICENSE +18 -0
- data/node_modules/chrome-remote-interface/README.md +849 -0
- data/node_modules/chrome-remote-interface/bin/client.js +337 -0
- data/node_modules/chrome-remote-interface/chrome-remote-interface.js +11 -0
- data/node_modules/chrome-remote-interface/index.js +39 -0
- data/node_modules/chrome-remote-interface/lib/api.js +84 -0
- data/node_modules/chrome-remote-interface/lib/chrome.js +307 -0
- data/node_modules/chrome-remote-interface/lib/defaults.js +4 -0
- data/node_modules/chrome-remote-interface/lib/devtools.js +245 -0
- data/node_modules/chrome-remote-interface/lib/external-request.js +28 -0
- data/node_modules/chrome-remote-interface/lib/protocol.json +13780 -0
- data/node_modules/chrome-remote-interface/lib/websocket-wrapper.js +32 -0
- data/node_modules/chrome-remote-interface/package.json +128 -0
- data/node_modules/chrome-remote-interface/webpack.config.js +55 -0
- data/node_modules/commander/Readme.md +195 -0
- data/node_modules/commander/index.js +851 -0
- data/node_modules/commander/package.json +92 -0
- data/node_modules/concat-map/.travis.yml +4 -0
- data/node_modules/concat-map/LICENSE +18 -0
- data/node_modules/concat-map/README.markdown +62 -0
- data/node_modules/concat-map/example/map.js +6 -0
- data/node_modules/concat-map/index.js +13 -0
- data/node_modules/concat-map/package.json +117 -0
- data/node_modules/concat-map/test/map.js +39 -0
- data/node_modules/debug/.coveralls.yml +1 -0
- data/node_modules/debug/.eslintrc +11 -0
- data/node_modules/debug/.npmignore +9 -0
- data/node_modules/debug/.travis.yml +14 -0
- data/node_modules/debug/CHANGELOG.md +357 -0
- data/node_modules/debug/LICENSE +19 -0
- data/node_modules/debug/Makefile +50 -0
- data/node_modules/debug/Readme.md +312 -0
- data/node_modules/debug/component.json +19 -0
- data/node_modules/debug/karma.conf.js +70 -0
- data/node_modules/debug/node.js +1 -0
- data/node_modules/debug/package.json +124 -0
- data/node_modules/debug/src/browser.js +185 -0
- data/node_modules/debug/src/debug.js +202 -0
- data/node_modules/debug/src/index.js +10 -0
- data/node_modules/debug/src/node.js +246 -0
- data/node_modules/fs.realpath/LICENSE +43 -0
- data/node_modules/fs.realpath/README.md +33 -0
- data/node_modules/fs.realpath/index.js +66 -0
- data/node_modules/fs.realpath/old.js +303 -0
- data/node_modules/fs.realpath/package.json +94 -0
- data/node_modules/glob/LICENSE +15 -0
- data/node_modules/glob/README.md +368 -0
- data/node_modules/glob/changelog.md +67 -0
- data/node_modules/glob/common.js +240 -0
- data/node_modules/glob/glob.js +790 -0
- data/node_modules/glob/package.json +112 -0
- data/node_modules/glob/sync.js +486 -0
- data/node_modules/html-pdf-chrome/.npmignore +9 -0
- data/node_modules/html-pdf-chrome/LICENSE +21 -0
- data/node_modules/html-pdf-chrome/README.md +165 -0
- data/node_modules/html-pdf-chrome/lib/src/ChromePrintOptions.d.ts +87 -0
- data/node_modules/html-pdf-chrome/lib/src/ChromePrintOptions.js +4 -0
- data/node_modules/html-pdf-chrome/lib/src/ChromePrintOptions.js.map +1 -0
- data/node_modules/html-pdf-chrome/lib/src/CompletionTrigger.d.ts +120 -0
- data/node_modules/html-pdf-chrome/lib/src/CompletionTrigger.js +206 -0
- data/node_modules/html-pdf-chrome/lib/src/CompletionTrigger.js.map +1 -0
- data/node_modules/html-pdf-chrome/lib/src/CreateResult.d.ts +70 -0
- data/node_modules/html-pdf-chrome/lib/src/CreateResult.js +98 -0
- data/node_modules/html-pdf-chrome/lib/src/CreateResult.js.map +1 -0
- data/node_modules/html-pdf-chrome/lib/src/index.d.ts +72 -0
- data/node_modules/html-pdf-chrome/lib/src/index.js +123 -0
- data/node_modules/html-pdf-chrome/lib/src/index.js.map +1 -0
- data/node_modules/html-pdf-chrome/package.json +133 -0
- data/node_modules/html-pdf-chrome/src/ChromePrintOptions.ts +99 -0
- data/node_modules/html-pdf-chrome/src/CompletionTrigger.ts +201 -0
- data/node_modules/html-pdf-chrome/src/CreateResult.ts +100 -0
- data/node_modules/html-pdf-chrome/src/index.ts +179 -0
- data/node_modules/inflight/LICENSE +15 -0
- data/node_modules/inflight/README.md +37 -0
- data/node_modules/inflight/inflight.js +54 -0
- data/node_modules/inflight/package.json +105 -0
- data/node_modules/inherits/LICENSE +16 -0
- data/node_modules/inherits/README.md +42 -0
- data/node_modules/inherits/inherits.js +7 -0
- data/node_modules/inherits/inherits_browser.js +23 -0
- data/node_modules/inherits/package.json +97 -0
- data/node_modules/lighthouse-logger/README.md +4 -0
- data/node_modules/lighthouse-logger/index.js +212 -0
- data/node_modules/lighthouse-logger/package.json +69 -0
- data/node_modules/lighthouse-logger/yarn.lock +13 -0
- data/node_modules/minimatch/LICENSE +15 -0
- data/node_modules/minimatch/README.md +209 -0
- data/node_modules/minimatch/minimatch.js +923 -0
- data/node_modules/minimatch/package.json +99 -0
- data/node_modules/minimist/.travis.yml +4 -0
- data/node_modules/minimist/LICENSE +18 -0
- data/node_modules/minimist/example/parse.js +2 -0
- data/node_modules/minimist/index.js +187 -0
- data/node_modules/minimist/package.json +101 -0
- data/node_modules/minimist/readme.markdown +73 -0
- data/node_modules/minimist/test/dash.js +24 -0
- data/node_modules/minimist/test/default_bool.js +20 -0
- data/node_modules/minimist/test/dotted.js +16 -0
- data/node_modules/minimist/test/long.js +31 -0
- data/node_modules/minimist/test/parse.js +318 -0
- data/node_modules/minimist/test/parse_modified.js +9 -0
- data/node_modules/minimist/test/short.js +67 -0
- data/node_modules/minimist/test/whitespace.js +8 -0
- data/node_modules/mkdirp/.travis.yml +8 -0
- data/node_modules/mkdirp/LICENSE +21 -0
- data/node_modules/mkdirp/bin/cmd.js +33 -0
- data/node_modules/mkdirp/bin/usage.txt +12 -0
- data/node_modules/mkdirp/examples/pow.js +6 -0
- data/node_modules/mkdirp/index.js +98 -0
- data/node_modules/mkdirp/package.json +93 -0
- data/node_modules/mkdirp/readme.markdown +100 -0
- data/node_modules/mkdirp/test/chmod.js +41 -0
- data/node_modules/mkdirp/test/clobber.js +38 -0
- data/node_modules/mkdirp/test/mkdirp.js +28 -0
- data/node_modules/mkdirp/test/opts_fs.js +29 -0
- data/node_modules/mkdirp/test/opts_fs_sync.js +27 -0
- data/node_modules/mkdirp/test/perm.js +32 -0
- data/node_modules/mkdirp/test/perm_sync.js +36 -0
- data/node_modules/mkdirp/test/race.js +37 -0
- data/node_modules/mkdirp/test/rel.js +32 -0
- data/node_modules/mkdirp/test/return.js +25 -0
- data/node_modules/mkdirp/test/return_sync.js +24 -0
- data/node_modules/mkdirp/test/root.js +19 -0
- data/node_modules/mkdirp/test/sync.js +32 -0
- data/node_modules/mkdirp/test/umask.js +28 -0
- data/node_modules/mkdirp/test/umask_sync.js +32 -0
- data/node_modules/ms/README.md +51 -0
- data/node_modules/ms/index.js +152 -0
- data/node_modules/ms/license.md +21 -0
- data/node_modules/ms/package.json +109 -0
- data/node_modules/once/LICENSE +15 -0
- data/node_modules/once/README.md +79 -0
- data/node_modules/once/once.js +42 -0
- data/node_modules/once/package.json +101 -0
- data/node_modules/path-is-absolute/index.js +20 -0
- data/node_modules/path-is-absolute/license +21 -0
- data/node_modules/path-is-absolute/package.json +111 -0
- data/node_modules/path-is-absolute/readme.md +59 -0
- data/node_modules/rimraf/LICENSE +15 -0
- data/node_modules/rimraf/README.md +101 -0
- data/node_modules/rimraf/bin.js +50 -0
- data/node_modules/rimraf/package.json +99 -0
- data/node_modules/rimraf/rimraf.js +363 -0
- data/node_modules/ultron/LICENSE +22 -0
- data/node_modules/ultron/index.js +138 -0
- data/node_modules/ultron/package.json +112 -0
- data/node_modules/wrappy/LICENSE +15 -0
- data/node_modules/wrappy/README.md +36 -0
- data/node_modules/wrappy/package.json +97 -0
- data/node_modules/wrappy/wrappy.js +33 -0
- data/node_modules/ws/LICENSE +21 -0
- data/node_modules/ws/README.md +259 -0
- data/node_modules/ws/SECURITY.md +33 -0
- data/node_modules/ws/index.js +15 -0
- data/node_modules/ws/lib/BufferUtil.fallback.js +56 -0
- data/node_modules/ws/lib/BufferUtil.js +15 -0
- data/node_modules/ws/lib/ErrorCodes.js +28 -0
- data/node_modules/ws/lib/EventTarget.js +158 -0
- data/node_modules/ws/lib/Extensions.js +69 -0
- data/node_modules/ws/lib/PerMessageDeflate.js +339 -0
- data/node_modules/ws/lib/Receiver.js +520 -0
- data/node_modules/ws/lib/Sender.js +438 -0
- data/node_modules/ws/lib/Validation.fallback.js +9 -0
- data/node_modules/ws/lib/Validation.js +17 -0
- data/node_modules/ws/lib/WebSocket.js +705 -0
- data/node_modules/ws/lib/WebSocketServer.js +336 -0
- data/node_modules/ws/package.json +122 -0
- data/package.json +26 -0
- data/samples/sample.html +13 -0
- data/script/rasterize.js +18 -0
- 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;
|