dragonfly_chrome_headless 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
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,10 @@
1
+ /**
2
+ * Detect Electron renderer process, which is node, but we should
3
+ * treat as a browser.
4
+ */
5
+
6
+ if (typeof process !== 'undefined' && process.type === 'renderer') {
7
+ module.exports = require('./browser.js');
8
+ } else {
9
+ module.exports = require('./node.js');
10
+ }
@@ -0,0 +1,246 @@
1
+ /**
2
+ * Module dependencies.
3
+ */
4
+
5
+ var tty = require('tty');
6
+ var util = require('util');
7
+
8
+ /**
9
+ * This is the Node.js implementation of `debug()`.
10
+ *
11
+ * Expose `debug()` as the module.
12
+ */
13
+
14
+ exports = module.exports = require('./debug');
15
+ exports.init = init;
16
+ exports.log = log;
17
+ exports.formatArgs = formatArgs;
18
+ exports.save = save;
19
+ exports.load = load;
20
+ exports.useColors = useColors;
21
+
22
+ /**
23
+ * Colors.
24
+ */
25
+
26
+ exports.colors = [6, 2, 3, 4, 5, 1];
27
+
28
+ /**
29
+ * Build up the default `inspectOpts` object from the environment variables.
30
+ *
31
+ * $ DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js
32
+ */
33
+
34
+ exports.inspectOpts = Object.keys(process.env).filter(function (key) {
35
+ return /^debug_/i.test(key);
36
+ }).reduce(function (obj, key) {
37
+ // camel-case
38
+ var prop = key
39
+ .substring(6)
40
+ .toLowerCase()
41
+ .replace(/_([a-z])/g, function (_, k) { return k.toUpperCase() });
42
+
43
+ // coerce string value into JS value
44
+ var val = process.env[key];
45
+ if (/^(yes|on|true|enabled)$/i.test(val)) val = true;
46
+ else if (/^(no|off|false|disabled)$/i.test(val)) val = false;
47
+ else if (val === 'null') val = null;
48
+ else val = Number(val);
49
+
50
+ obj[prop] = val;
51
+ return obj;
52
+ }, {});
53
+
54
+ /**
55
+ * The file descriptor to write the `debug()` calls to.
56
+ * Set the `DEBUG_FD` env variable to override with another value. i.e.:
57
+ *
58
+ * $ DEBUG_FD=3 node script.js 3>debug.log
59
+ */
60
+
61
+ var fd = parseInt(process.env.DEBUG_FD, 10) || 2;
62
+
63
+ if (1 !== fd && 2 !== fd) {
64
+ util.deprecate(function(){}, 'except for stderr(2) and stdout(1), any other usage of DEBUG_FD is deprecated. Override debug.log if you want to use a different log function (https://git.io/debug_fd)')()
65
+ }
66
+
67
+ var stream = 1 === fd ? process.stdout :
68
+ 2 === fd ? process.stderr :
69
+ createWritableStdioStream(fd);
70
+
71
+ /**
72
+ * Is stdout a TTY? Colored output is enabled when `true`.
73
+ */
74
+
75
+ function useColors() {
76
+ return 'colors' in exports.inspectOpts
77
+ ? Boolean(exports.inspectOpts.colors)
78
+ : tty.isatty(fd);
79
+ }
80
+
81
+ /**
82
+ * Map %o to `util.inspect()`, all on a single line.
83
+ */
84
+
85
+ exports.formatters.o = function(v) {
86
+ this.inspectOpts.colors = this.useColors;
87
+ return util.inspect(v, this.inspectOpts)
88
+ .replace(/\s*\n\s*/g, ' ');
89
+ };
90
+
91
+ /**
92
+ * Map %o to `util.inspect()`, allowing multiple lines if needed.
93
+ */
94
+
95
+ exports.formatters.O = function(v) {
96
+ this.inspectOpts.colors = this.useColors;
97
+ return util.inspect(v, this.inspectOpts);
98
+ };
99
+
100
+ /**
101
+ * Adds ANSI color escape codes if enabled.
102
+ *
103
+ * @api public
104
+ */
105
+
106
+ function formatArgs(args) {
107
+ var name = this.namespace;
108
+ var useColors = this.useColors;
109
+
110
+ if (useColors) {
111
+ var c = this.color;
112
+ var prefix = ' \u001b[3' + c + ';1m' + name + ' ' + '\u001b[0m';
113
+
114
+ args[0] = prefix + args[0].split('\n').join('\n' + prefix);
115
+ args.push('\u001b[3' + c + 'm+' + exports.humanize(this.diff) + '\u001b[0m');
116
+ } else {
117
+ args[0] = new Date().toUTCString()
118
+ + ' ' + name + ' ' + args[0];
119
+ }
120
+ }
121
+
122
+ /**
123
+ * Invokes `util.format()` with the specified arguments and writes to `stream`.
124
+ */
125
+
126
+ function log() {
127
+ return stream.write(util.format.apply(util, arguments) + '\n');
128
+ }
129
+
130
+ /**
131
+ * Save `namespaces`.
132
+ *
133
+ * @param {String} namespaces
134
+ * @api private
135
+ */
136
+
137
+ function save(namespaces) {
138
+ if (null == namespaces) {
139
+ // If you set a process.env field to null or undefined, it gets cast to the
140
+ // string 'null' or 'undefined'. Just delete instead.
141
+ delete process.env.DEBUG;
142
+ } else {
143
+ process.env.DEBUG = namespaces;
144
+ }
145
+ }
146
+
147
+ /**
148
+ * Load `namespaces`.
149
+ *
150
+ * @return {String} returns the previously persisted debug modes
151
+ * @api private
152
+ */
153
+
154
+ function load() {
155
+ return process.env.DEBUG;
156
+ }
157
+
158
+ /**
159
+ * Copied from `node/src/node.js`.
160
+ *
161
+ * XXX: It's lame that node doesn't expose this API out-of-the-box. It also
162
+ * relies on the undocumented `tty_wrap.guessHandleType()` which is also lame.
163
+ */
164
+
165
+ function createWritableStdioStream (fd) {
166
+ var stream;
167
+ var tty_wrap = process.binding('tty_wrap');
168
+
169
+ // Note stream._type is used for test-module-load-list.js
170
+
171
+ switch (tty_wrap.guessHandleType(fd)) {
172
+ case 'TTY':
173
+ stream = new tty.WriteStream(fd);
174
+ stream._type = 'tty';
175
+
176
+ // Hack to have stream not keep the event loop alive.
177
+ // See https://github.com/joyent/node/issues/1726
178
+ if (stream._handle && stream._handle.unref) {
179
+ stream._handle.unref();
180
+ }
181
+ break;
182
+
183
+ case 'FILE':
184
+ var fs = require('fs');
185
+ stream = new fs.SyncWriteStream(fd, { autoClose: false });
186
+ stream._type = 'fs';
187
+ break;
188
+
189
+ case 'PIPE':
190
+ case 'TCP':
191
+ var net = require('net');
192
+ stream = new net.Socket({
193
+ fd: fd,
194
+ readable: false,
195
+ writable: true
196
+ });
197
+
198
+ // FIXME Should probably have an option in net.Socket to create a
199
+ // stream from an existing fd which is writable only. But for now
200
+ // we'll just add this hack and set the `readable` member to false.
201
+ // Test: ./node test/fixtures/echo.js < /etc/passwd
202
+ stream.readable = false;
203
+ stream.read = null;
204
+ stream._type = 'pipe';
205
+
206
+ // FIXME Hack to have stream not keep the event loop alive.
207
+ // See https://github.com/joyent/node/issues/1726
208
+ if (stream._handle && stream._handle.unref) {
209
+ stream._handle.unref();
210
+ }
211
+ break;
212
+
213
+ default:
214
+ // Probably an error on in uv_guess_handle()
215
+ throw new Error('Implement me. Unknown stream file type!');
216
+ }
217
+
218
+ // For supporting legacy API we put the FD here.
219
+ stream.fd = fd;
220
+
221
+ stream._isStdio = true;
222
+
223
+ return stream;
224
+ }
225
+
226
+ /**
227
+ * Init logic for `debug` instances.
228
+ *
229
+ * Create a new `inspectOpts` object in case `useColors` is set
230
+ * differently for a particular `debug` instance.
231
+ */
232
+
233
+ function init (debug) {
234
+ debug.inspectOpts = {};
235
+
236
+ var keys = Object.keys(exports.inspectOpts);
237
+ for (var i = 0; i < keys.length; i++) {
238
+ debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
239
+ }
240
+ }
241
+
242
+ /**
243
+ * Enable namespaces listed in `process.env.DEBUG` initially.
244
+ */
245
+
246
+ exports.enable(load());
@@ -0,0 +1,43 @@
1
+ The ISC License
2
+
3
+ Copyright (c) Isaac Z. Schlueter and Contributors
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
15
+ IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
+
17
+ ----
18
+
19
+ This library bundles a version of the `fs.realpath` and `fs.realpathSync`
20
+ methods from Node.js v0.10 under the terms of the Node.js MIT license.
21
+
22
+ Node's license follows, also included at the header of `old.js` which contains
23
+ the licensed code:
24
+
25
+ Copyright Joyent, Inc. and other Node contributors.
26
+
27
+ Permission is hereby granted, free of charge, to any person obtaining a
28
+ copy of this software and associated documentation files (the "Software"),
29
+ to deal in the Software without restriction, including without limitation
30
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
31
+ and/or sell copies of the Software, and to permit persons to whom the
32
+ Software is furnished to do so, subject to the following conditions:
33
+
34
+ The above copyright notice and this permission notice shall be included in
35
+ all copies or substantial portions of the Software.
36
+
37
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
38
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
39
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
40
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
41
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
42
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
43
+ DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,33 @@
1
+ # fs.realpath
2
+
3
+ A backwards-compatible fs.realpath for Node v6 and above
4
+
5
+ In Node v6, the JavaScript implementation of fs.realpath was replaced
6
+ with a faster (but less resilient) native implementation. That raises
7
+ new and platform-specific errors and cannot handle long or excessively
8
+ symlink-looping paths.
9
+
10
+ This module handles those cases by detecting the new errors and
11
+ falling back to the JavaScript implementation. On versions of Node
12
+ prior to v6, it has no effect.
13
+
14
+ ## USAGE
15
+
16
+ ```js
17
+ var rp = require('fs.realpath')
18
+
19
+ // async version
20
+ rp.realpath(someLongAndLoopingPath, function (er, real) {
21
+ // the ELOOP was handled, but it was a bit slower
22
+ })
23
+
24
+ // sync version
25
+ var real = rp.realpathSync(someLongAndLoopingPath)
26
+
27
+ // monkeypatch at your own risk!
28
+ // This replaces the fs.realpath/fs.realpathSync builtins
29
+ rp.monkeypatch()
30
+
31
+ // un-do the monkeypatching
32
+ rp.unmonkeypatch()
33
+ ```
@@ -0,0 +1,66 @@
1
+ module.exports = realpath
2
+ realpath.realpath = realpath
3
+ realpath.sync = realpathSync
4
+ realpath.realpathSync = realpathSync
5
+ realpath.monkeypatch = monkeypatch
6
+ realpath.unmonkeypatch = unmonkeypatch
7
+
8
+ var fs = require('fs')
9
+ var origRealpath = fs.realpath
10
+ var origRealpathSync = fs.realpathSync
11
+
12
+ var version = process.version
13
+ var ok = /^v[0-5]\./.test(version)
14
+ var old = require('./old.js')
15
+
16
+ function newError (er) {
17
+ return er && er.syscall === 'realpath' && (
18
+ er.code === 'ELOOP' ||
19
+ er.code === 'ENOMEM' ||
20
+ er.code === 'ENAMETOOLONG'
21
+ )
22
+ }
23
+
24
+ function realpath (p, cache, cb) {
25
+ if (ok) {
26
+ return origRealpath(p, cache, cb)
27
+ }
28
+
29
+ if (typeof cache === 'function') {
30
+ cb = cache
31
+ cache = null
32
+ }
33
+ origRealpath(p, cache, function (er, result) {
34
+ if (newError(er)) {
35
+ old.realpath(p, cache, cb)
36
+ } else {
37
+ cb(er, result)
38
+ }
39
+ })
40
+ }
41
+
42
+ function realpathSync (p, cache) {
43
+ if (ok) {
44
+ return origRealpathSync(p, cache)
45
+ }
46
+
47
+ try {
48
+ return origRealpathSync(p, cache)
49
+ } catch (er) {
50
+ if (newError(er)) {
51
+ return old.realpathSync(p, cache)
52
+ } else {
53
+ throw er
54
+ }
55
+ }
56
+ }
57
+
58
+ function monkeypatch () {
59
+ fs.realpath = realpath
60
+ fs.realpathSync = realpathSync
61
+ }
62
+
63
+ function unmonkeypatch () {
64
+ fs.realpath = origRealpath
65
+ fs.realpathSync = origRealpathSync
66
+ }
@@ -0,0 +1,303 @@
1
+ // Copyright Joyent, Inc. and other Node contributors.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a
4
+ // copy of this software and associated documentation files (the
5
+ // "Software"), to deal in the Software without restriction, including
6
+ // without limitation the rights to use, copy, modify, merge, publish,
7
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
8
+ // persons to whom the Software is furnished to do so, subject to the
9
+ // following conditions:
10
+ //
11
+ // The above copyright notice and this permission notice shall be included
12
+ // in all copies or substantial portions of the Software.
13
+ //
14
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ var pathModule = require('path');
23
+ var isWindows = process.platform === 'win32';
24
+ var fs = require('fs');
25
+
26
+ // JavaScript implementation of realpath, ported from node pre-v6
27
+
28
+ var DEBUG = process.env.NODE_DEBUG && /fs/.test(process.env.NODE_DEBUG);
29
+
30
+ function rethrow() {
31
+ // Only enable in debug mode. A backtrace uses ~1000 bytes of heap space and
32
+ // is fairly slow to generate.
33
+ var callback;
34
+ if (DEBUG) {
35
+ var backtrace = new Error;
36
+ callback = debugCallback;
37
+ } else
38
+ callback = missingCallback;
39
+
40
+ return callback;
41
+
42
+ function debugCallback(err) {
43
+ if (err) {
44
+ backtrace.message = err.message;
45
+ err = backtrace;
46
+ missingCallback(err);
47
+ }
48
+ }
49
+
50
+ function missingCallback(err) {
51
+ if (err) {
52
+ if (process.throwDeprecation)
53
+ throw err; // Forgot a callback but don't know where? Use NODE_DEBUG=fs
54
+ else if (!process.noDeprecation) {
55
+ var msg = 'fs: missing callback ' + (err.stack || err.message);
56
+ if (process.traceDeprecation)
57
+ console.trace(msg);
58
+ else
59
+ console.error(msg);
60
+ }
61
+ }
62
+ }
63
+ }
64
+
65
+ function maybeCallback(cb) {
66
+ return typeof cb === 'function' ? cb : rethrow();
67
+ }
68
+
69
+ var normalize = pathModule.normalize;
70
+
71
+ // Regexp that finds the next partion of a (partial) path
72
+ // result is [base_with_slash, base], e.g. ['somedir/', 'somedir']
73
+ if (isWindows) {
74
+ var nextPartRe = /(.*?)(?:[\/\\]+|$)/g;
75
+ } else {
76
+ var nextPartRe = /(.*?)(?:[\/]+|$)/g;
77
+ }
78
+
79
+ // Regex to find the device root, including trailing slash. E.g. 'c:\\'.
80
+ if (isWindows) {
81
+ var splitRootRe = /^(?:[a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/][^\\\/]+)?[\\\/]*/;
82
+ } else {
83
+ var splitRootRe = /^[\/]*/;
84
+ }
85
+
86
+ exports.realpathSync = function realpathSync(p, cache) {
87
+ // make p is absolute
88
+ p = pathModule.resolve(p);
89
+
90
+ if (cache && Object.prototype.hasOwnProperty.call(cache, p)) {
91
+ return cache[p];
92
+ }
93
+
94
+ var original = p,
95
+ seenLinks = {},
96
+ knownHard = {};
97
+
98
+ // current character position in p
99
+ var pos;
100
+ // the partial path so far, including a trailing slash if any
101
+ var current;
102
+ // the partial path without a trailing slash (except when pointing at a root)
103
+ var base;
104
+ // the partial path scanned in the previous round, with slash
105
+ var previous;
106
+
107
+ start();
108
+
109
+ function start() {
110
+ // Skip over roots
111
+ var m = splitRootRe.exec(p);
112
+ pos = m[0].length;
113
+ current = m[0];
114
+ base = m[0];
115
+ previous = '';
116
+
117
+ // On windows, check that the root exists. On unix there is no need.
118
+ if (isWindows && !knownHard[base]) {
119
+ fs.lstatSync(base);
120
+ knownHard[base] = true;
121
+ }
122
+ }
123
+
124
+ // walk down the path, swapping out linked pathparts for their real
125
+ // values
126
+ // NB: p.length changes.
127
+ while (pos < p.length) {
128
+ // find the next part
129
+ nextPartRe.lastIndex = pos;
130
+ var result = nextPartRe.exec(p);
131
+ previous = current;
132
+ current += result[0];
133
+ base = previous + result[1];
134
+ pos = nextPartRe.lastIndex;
135
+
136
+ // continue if not a symlink
137
+ if (knownHard[base] || (cache && cache[base] === base)) {
138
+ continue;
139
+ }
140
+
141
+ var resolvedLink;
142
+ if (cache && Object.prototype.hasOwnProperty.call(cache, base)) {
143
+ // some known symbolic link. no need to stat again.
144
+ resolvedLink = cache[base];
145
+ } else {
146
+ var stat = fs.lstatSync(base);
147
+ if (!stat.isSymbolicLink()) {
148
+ knownHard[base] = true;
149
+ if (cache) cache[base] = base;
150
+ continue;
151
+ }
152
+
153
+ // read the link if it wasn't read before
154
+ // dev/ino always return 0 on windows, so skip the check.
155
+ var linkTarget = null;
156
+ if (!isWindows) {
157
+ var id = stat.dev.toString(32) + ':' + stat.ino.toString(32);
158
+ if (seenLinks.hasOwnProperty(id)) {
159
+ linkTarget = seenLinks[id];
160
+ }
161
+ }
162
+ if (linkTarget === null) {
163
+ fs.statSync(base);
164
+ linkTarget = fs.readlinkSync(base);
165
+ }
166
+ resolvedLink = pathModule.resolve(previous, linkTarget);
167
+ // track this, if given a cache.
168
+ if (cache) cache[base] = resolvedLink;
169
+ if (!isWindows) seenLinks[id] = linkTarget;
170
+ }
171
+
172
+ // resolve the link, then start over
173
+ p = pathModule.resolve(resolvedLink, p.slice(pos));
174
+ start();
175
+ }
176
+
177
+ if (cache) cache[original] = p;
178
+
179
+ return p;
180
+ };
181
+
182
+
183
+ exports.realpath = function realpath(p, cache, cb) {
184
+ if (typeof cb !== 'function') {
185
+ cb = maybeCallback(cache);
186
+ cache = null;
187
+ }
188
+
189
+ // make p is absolute
190
+ p = pathModule.resolve(p);
191
+
192
+ if (cache && Object.prototype.hasOwnProperty.call(cache, p)) {
193
+ return process.nextTick(cb.bind(null, null, cache[p]));
194
+ }
195
+
196
+ var original = p,
197
+ seenLinks = {},
198
+ knownHard = {};
199
+
200
+ // current character position in p
201
+ var pos;
202
+ // the partial path so far, including a trailing slash if any
203
+ var current;
204
+ // the partial path without a trailing slash (except when pointing at a root)
205
+ var base;
206
+ // the partial path scanned in the previous round, with slash
207
+ var previous;
208
+
209
+ start();
210
+
211
+ function start() {
212
+ // Skip over roots
213
+ var m = splitRootRe.exec(p);
214
+ pos = m[0].length;
215
+ current = m[0];
216
+ base = m[0];
217
+ previous = '';
218
+
219
+ // On windows, check that the root exists. On unix there is no need.
220
+ if (isWindows && !knownHard[base]) {
221
+ fs.lstat(base, function(err) {
222
+ if (err) return cb(err);
223
+ knownHard[base] = true;
224
+ LOOP();
225
+ });
226
+ } else {
227
+ process.nextTick(LOOP);
228
+ }
229
+ }
230
+
231
+ // walk down the path, swapping out linked pathparts for their real
232
+ // values
233
+ function LOOP() {
234
+ // stop if scanned past end of path
235
+ if (pos >= p.length) {
236
+ if (cache) cache[original] = p;
237
+ return cb(null, p);
238
+ }
239
+
240
+ // find the next part
241
+ nextPartRe.lastIndex = pos;
242
+ var result = nextPartRe.exec(p);
243
+ previous = current;
244
+ current += result[0];
245
+ base = previous + result[1];
246
+ pos = nextPartRe.lastIndex;
247
+
248
+ // continue if not a symlink
249
+ if (knownHard[base] || (cache && cache[base] === base)) {
250
+ return process.nextTick(LOOP);
251
+ }
252
+
253
+ if (cache && Object.prototype.hasOwnProperty.call(cache, base)) {
254
+ // known symbolic link. no need to stat again.
255
+ return gotResolvedLink(cache[base]);
256
+ }
257
+
258
+ return fs.lstat(base, gotStat);
259
+ }
260
+
261
+ function gotStat(err, stat) {
262
+ if (err) return cb(err);
263
+
264
+ // if not a symlink, skip to the next path part
265
+ if (!stat.isSymbolicLink()) {
266
+ knownHard[base] = true;
267
+ if (cache) cache[base] = base;
268
+ return process.nextTick(LOOP);
269
+ }
270
+
271
+ // stat & read the link if not read before
272
+ // call gotTarget as soon as the link target is known
273
+ // dev/ino always return 0 on windows, so skip the check.
274
+ if (!isWindows) {
275
+ var id = stat.dev.toString(32) + ':' + stat.ino.toString(32);
276
+ if (seenLinks.hasOwnProperty(id)) {
277
+ return gotTarget(null, seenLinks[id], base);
278
+ }
279
+ }
280
+ fs.stat(base, function(err) {
281
+ if (err) return cb(err);
282
+
283
+ fs.readlink(base, function(err, target) {
284
+ if (!isWindows) seenLinks[id] = target;
285
+ gotTarget(err, target);
286
+ });
287
+ });
288
+ }
289
+
290
+ function gotTarget(err, target, base) {
291
+ if (err) return cb(err);
292
+
293
+ var resolvedLink = pathModule.resolve(previous, target);
294
+ if (cache) cache[base] = resolvedLink;
295
+ gotResolvedLink(resolvedLink);
296
+ }
297
+
298
+ function gotResolvedLink(resolvedLink) {
299
+ // resolve the link, then start over
300
+ p = pathModule.resolve(resolvedLink, p.slice(pos));
301
+ start();
302
+ }
303
+ };