@andersbakken/fisk 3.5.6 → 3.6.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.
- package/dist/VM_runtime.js +4040 -0
- package/dist/VM_runtime.js.map +1 -0
- package/dist/fisk-builder.js +55239 -0
- package/dist/fisk-builder.js.map +1 -0
- package/dist/fisk-daemon.js +4223 -0
- package/dist/fisk-daemon.js.map +1 -0
- package/dist/fisk-scheduler.js +53883 -0
- package/dist/fisk-scheduler.js.map +1 -0
- package/package.json +68 -34
- package/builder/VM.js +0 -156
- package/builder/VM_runtime.js +0 -171
- package/builder/client.js +0 -181
- package/builder/compile.js +0 -269
- package/builder/fisk-builder.js +0 -899
- package/builder/load.js +0 -85
- package/builder/objectcache.js +0 -301
- package/builder/quit-on-error.js +0 -9
- package/builder/server.js +0 -214
- package/common/index.js +0 -45
- package/daemon/client.js +0 -100
- package/daemon/clientbuffer.js +0 -73
- package/daemon/compile.js +0 -140
- package/daemon/constants.js +0 -13
- package/daemon/fisk-daemon.js +0 -166
- package/daemon/server.js +0 -81
- package/daemon/slots.js +0 -69
- package/monitor/fisk-monitor.js +0 -767
- package/proxy/fisk-proxy.js +0 -150
- package/scheduler/database.js +0 -144
- package/scheduler/environments.js +0 -386
- package/scheduler/fisk-scheduler.js +0 -1411
- package/scheduler/objectcachemanager.js +0 -306
- package/scheduler/peak.js +0 -112
- package/scheduler/public/index.html +0 -37
- package/scheduler/server.js +0 -431
- package/scheduler/usertester.js +0 -60
|
@@ -0,0 +1,4040 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var EventEmitter = require('events');
|
|
4
|
+
var assert$1 = require('assert');
|
|
5
|
+
var child_process = require('child_process');
|
|
6
|
+
var require$$1 = require('fs');
|
|
7
|
+
var require$$0 = require('constants');
|
|
8
|
+
var require$$0$1 = require('stream');
|
|
9
|
+
var require$$4 = require('util');
|
|
10
|
+
var path$j = require('path');
|
|
11
|
+
var require$$1$1 = require('os');
|
|
12
|
+
|
|
13
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
14
|
+
|
|
15
|
+
var EventEmitter__default = /*#__PURE__*/_interopDefaultLegacy(EventEmitter);
|
|
16
|
+
var assert__default = /*#__PURE__*/_interopDefaultLegacy(assert$1);
|
|
17
|
+
var child_process__default = /*#__PURE__*/_interopDefaultLegacy(child_process);
|
|
18
|
+
var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
|
|
19
|
+
var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
|
|
20
|
+
var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
|
|
21
|
+
var require$$4__default = /*#__PURE__*/_interopDefaultLegacy(require$$4);
|
|
22
|
+
var path__default = /*#__PURE__*/_interopDefaultLegacy(path$j);
|
|
23
|
+
var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
|
|
24
|
+
|
|
25
|
+
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
26
|
+
|
|
27
|
+
var libExports = {};
|
|
28
|
+
var lib = {
|
|
29
|
+
get exports(){ return libExports; },
|
|
30
|
+
set exports(v){ libExports = v; },
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
var fs$k = {};
|
|
34
|
+
|
|
35
|
+
var universalify = {};
|
|
36
|
+
|
|
37
|
+
universalify.fromCallback = function (fn) {
|
|
38
|
+
return Object.defineProperty(function () {
|
|
39
|
+
if (typeof arguments[arguments.length - 1] === 'function') fn.apply(this, arguments);
|
|
40
|
+
else {
|
|
41
|
+
return new Promise((resolve, reject) => {
|
|
42
|
+
arguments[arguments.length] = (err, res) => {
|
|
43
|
+
if (err) return reject(err)
|
|
44
|
+
resolve(res);
|
|
45
|
+
};
|
|
46
|
+
arguments.length++;
|
|
47
|
+
fn.apply(this, arguments);
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
}, 'name', { value: fn.name })
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
universalify.fromPromise = function (fn) {
|
|
54
|
+
return Object.defineProperty(function () {
|
|
55
|
+
const cb = arguments[arguments.length - 1];
|
|
56
|
+
if (typeof cb !== 'function') return fn.apply(this, arguments)
|
|
57
|
+
else fn.apply(this, arguments).then(r => cb(null, r), cb);
|
|
58
|
+
}, 'name', { value: fn.name })
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
var constants = require$$0__default["default"];
|
|
62
|
+
|
|
63
|
+
var origCwd = process.cwd;
|
|
64
|
+
var cwd = null;
|
|
65
|
+
|
|
66
|
+
var platform = process.env.GRACEFUL_FS_PLATFORM || process.platform;
|
|
67
|
+
|
|
68
|
+
process.cwd = function() {
|
|
69
|
+
if (!cwd)
|
|
70
|
+
cwd = origCwd.call(process);
|
|
71
|
+
return cwd
|
|
72
|
+
};
|
|
73
|
+
try {
|
|
74
|
+
process.cwd();
|
|
75
|
+
} catch (er) {}
|
|
76
|
+
|
|
77
|
+
// This check is needed until node.js 12 is required
|
|
78
|
+
if (typeof process.chdir === 'function') {
|
|
79
|
+
var chdir = process.chdir;
|
|
80
|
+
process.chdir = function (d) {
|
|
81
|
+
cwd = null;
|
|
82
|
+
chdir.call(process, d);
|
|
83
|
+
};
|
|
84
|
+
if (Object.setPrototypeOf) Object.setPrototypeOf(process.chdir, chdir);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
var polyfills$1 = patch$1;
|
|
88
|
+
|
|
89
|
+
function patch$1 (fs) {
|
|
90
|
+
// (re-)implement some things that are known busted or missing.
|
|
91
|
+
|
|
92
|
+
// lchmod, broken prior to 0.6.2
|
|
93
|
+
// back-port the fix here.
|
|
94
|
+
if (constants.hasOwnProperty('O_SYMLINK') &&
|
|
95
|
+
process.version.match(/^v0\.6\.[0-2]|^v0\.5\./)) {
|
|
96
|
+
patchLchmod(fs);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// lutimes implementation, or no-op
|
|
100
|
+
if (!fs.lutimes) {
|
|
101
|
+
patchLutimes(fs);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// https://github.com/isaacs/node-graceful-fs/issues/4
|
|
105
|
+
// Chown should not fail on einval or eperm if non-root.
|
|
106
|
+
// It should not fail on enosys ever, as this just indicates
|
|
107
|
+
// that a fs doesn't support the intended operation.
|
|
108
|
+
|
|
109
|
+
fs.chown = chownFix(fs.chown);
|
|
110
|
+
fs.fchown = chownFix(fs.fchown);
|
|
111
|
+
fs.lchown = chownFix(fs.lchown);
|
|
112
|
+
|
|
113
|
+
fs.chmod = chmodFix(fs.chmod);
|
|
114
|
+
fs.fchmod = chmodFix(fs.fchmod);
|
|
115
|
+
fs.lchmod = chmodFix(fs.lchmod);
|
|
116
|
+
|
|
117
|
+
fs.chownSync = chownFixSync(fs.chownSync);
|
|
118
|
+
fs.fchownSync = chownFixSync(fs.fchownSync);
|
|
119
|
+
fs.lchownSync = chownFixSync(fs.lchownSync);
|
|
120
|
+
|
|
121
|
+
fs.chmodSync = chmodFixSync(fs.chmodSync);
|
|
122
|
+
fs.fchmodSync = chmodFixSync(fs.fchmodSync);
|
|
123
|
+
fs.lchmodSync = chmodFixSync(fs.lchmodSync);
|
|
124
|
+
|
|
125
|
+
fs.stat = statFix(fs.stat);
|
|
126
|
+
fs.fstat = statFix(fs.fstat);
|
|
127
|
+
fs.lstat = statFix(fs.lstat);
|
|
128
|
+
|
|
129
|
+
fs.statSync = statFixSync(fs.statSync);
|
|
130
|
+
fs.fstatSync = statFixSync(fs.fstatSync);
|
|
131
|
+
fs.lstatSync = statFixSync(fs.lstatSync);
|
|
132
|
+
|
|
133
|
+
// if lchmod/lchown do not exist, then make them no-ops
|
|
134
|
+
if (fs.chmod && !fs.lchmod) {
|
|
135
|
+
fs.lchmod = function (path, mode, cb) {
|
|
136
|
+
if (cb) process.nextTick(cb);
|
|
137
|
+
};
|
|
138
|
+
fs.lchmodSync = function () {};
|
|
139
|
+
}
|
|
140
|
+
if (fs.chown && !fs.lchown) {
|
|
141
|
+
fs.lchown = function (path, uid, gid, cb) {
|
|
142
|
+
if (cb) process.nextTick(cb);
|
|
143
|
+
};
|
|
144
|
+
fs.lchownSync = function () {};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// on Windows, A/V software can lock the directory, causing this
|
|
148
|
+
// to fail with an EACCES or EPERM if the directory contains newly
|
|
149
|
+
// created files. Try again on failure, for up to 60 seconds.
|
|
150
|
+
|
|
151
|
+
// Set the timeout this long because some Windows Anti-Virus, such as Parity
|
|
152
|
+
// bit9, may lock files for up to a minute, causing npm package install
|
|
153
|
+
// failures. Also, take care to yield the scheduler. Windows scheduling gives
|
|
154
|
+
// CPU to a busy looping process, which can cause the program causing the lock
|
|
155
|
+
// contention to be starved of CPU by node, so the contention doesn't resolve.
|
|
156
|
+
if (platform === "win32") {
|
|
157
|
+
fs.rename = typeof fs.rename !== 'function' ? fs.rename
|
|
158
|
+
: (function (fs$rename) {
|
|
159
|
+
function rename (from, to, cb) {
|
|
160
|
+
var start = Date.now();
|
|
161
|
+
var backoff = 0;
|
|
162
|
+
fs$rename(from, to, function CB (er) {
|
|
163
|
+
if (er
|
|
164
|
+
&& (er.code === "EACCES" || er.code === "EPERM")
|
|
165
|
+
&& Date.now() - start < 60000) {
|
|
166
|
+
setTimeout(function() {
|
|
167
|
+
fs.stat(to, function (stater, st) {
|
|
168
|
+
if (stater && stater.code === "ENOENT")
|
|
169
|
+
fs$rename(from, to, CB);
|
|
170
|
+
else
|
|
171
|
+
cb(er);
|
|
172
|
+
});
|
|
173
|
+
}, backoff);
|
|
174
|
+
if (backoff < 100)
|
|
175
|
+
backoff += 10;
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
if (cb) cb(er);
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
if (Object.setPrototypeOf) Object.setPrototypeOf(rename, fs$rename);
|
|
182
|
+
return rename
|
|
183
|
+
})(fs.rename);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// if read() returns EAGAIN, then just try it again.
|
|
187
|
+
fs.read = typeof fs.read !== 'function' ? fs.read
|
|
188
|
+
: (function (fs$read) {
|
|
189
|
+
function read (fd, buffer, offset, length, position, callback_) {
|
|
190
|
+
var callback;
|
|
191
|
+
if (callback_ && typeof callback_ === 'function') {
|
|
192
|
+
var eagCounter = 0;
|
|
193
|
+
callback = function (er, _, __) {
|
|
194
|
+
if (er && er.code === 'EAGAIN' && eagCounter < 10) {
|
|
195
|
+
eagCounter ++;
|
|
196
|
+
return fs$read.call(fs, fd, buffer, offset, length, position, callback)
|
|
197
|
+
}
|
|
198
|
+
callback_.apply(this, arguments);
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
return fs$read.call(fs, fd, buffer, offset, length, position, callback)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// This ensures `util.promisify` works as it does for native `fs.read`.
|
|
205
|
+
if (Object.setPrototypeOf) Object.setPrototypeOf(read, fs$read);
|
|
206
|
+
return read
|
|
207
|
+
})(fs.read);
|
|
208
|
+
|
|
209
|
+
fs.readSync = typeof fs.readSync !== 'function' ? fs.readSync
|
|
210
|
+
: (function (fs$readSync) { return function (fd, buffer, offset, length, position) {
|
|
211
|
+
var eagCounter = 0;
|
|
212
|
+
while (true) {
|
|
213
|
+
try {
|
|
214
|
+
return fs$readSync.call(fs, fd, buffer, offset, length, position)
|
|
215
|
+
} catch (er) {
|
|
216
|
+
if (er.code === 'EAGAIN' && eagCounter < 10) {
|
|
217
|
+
eagCounter ++;
|
|
218
|
+
continue
|
|
219
|
+
}
|
|
220
|
+
throw er
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}})(fs.readSync);
|
|
224
|
+
|
|
225
|
+
function patchLchmod (fs) {
|
|
226
|
+
fs.lchmod = function (path, mode, callback) {
|
|
227
|
+
fs.open( path
|
|
228
|
+
, constants.O_WRONLY | constants.O_SYMLINK
|
|
229
|
+
, mode
|
|
230
|
+
, function (err, fd) {
|
|
231
|
+
if (err) {
|
|
232
|
+
if (callback) callback(err);
|
|
233
|
+
return
|
|
234
|
+
}
|
|
235
|
+
// prefer to return the chmod error, if one occurs,
|
|
236
|
+
// but still try to close, and report closing errors if they occur.
|
|
237
|
+
fs.fchmod(fd, mode, function (err) {
|
|
238
|
+
fs.close(fd, function(err2) {
|
|
239
|
+
if (callback) callback(err || err2);
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
fs.lchmodSync = function (path, mode) {
|
|
246
|
+
var fd = fs.openSync(path, constants.O_WRONLY | constants.O_SYMLINK, mode);
|
|
247
|
+
|
|
248
|
+
// prefer to return the chmod error, if one occurs,
|
|
249
|
+
// but still try to close, and report closing errors if they occur.
|
|
250
|
+
var threw = true;
|
|
251
|
+
var ret;
|
|
252
|
+
try {
|
|
253
|
+
ret = fs.fchmodSync(fd, mode);
|
|
254
|
+
threw = false;
|
|
255
|
+
} finally {
|
|
256
|
+
if (threw) {
|
|
257
|
+
try {
|
|
258
|
+
fs.closeSync(fd);
|
|
259
|
+
} catch (er) {}
|
|
260
|
+
} else {
|
|
261
|
+
fs.closeSync(fd);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return ret
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function patchLutimes (fs) {
|
|
269
|
+
if (constants.hasOwnProperty("O_SYMLINK") && fs.futimes) {
|
|
270
|
+
fs.lutimes = function (path, at, mt, cb) {
|
|
271
|
+
fs.open(path, constants.O_SYMLINK, function (er, fd) {
|
|
272
|
+
if (er) {
|
|
273
|
+
if (cb) cb(er);
|
|
274
|
+
return
|
|
275
|
+
}
|
|
276
|
+
fs.futimes(fd, at, mt, function (er) {
|
|
277
|
+
fs.close(fd, function (er2) {
|
|
278
|
+
if (cb) cb(er || er2);
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
fs.lutimesSync = function (path, at, mt) {
|
|
285
|
+
var fd = fs.openSync(path, constants.O_SYMLINK);
|
|
286
|
+
var ret;
|
|
287
|
+
var threw = true;
|
|
288
|
+
try {
|
|
289
|
+
ret = fs.futimesSync(fd, at, mt);
|
|
290
|
+
threw = false;
|
|
291
|
+
} finally {
|
|
292
|
+
if (threw) {
|
|
293
|
+
try {
|
|
294
|
+
fs.closeSync(fd);
|
|
295
|
+
} catch (er) {}
|
|
296
|
+
} else {
|
|
297
|
+
fs.closeSync(fd);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return ret
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
} else if (fs.futimes) {
|
|
304
|
+
fs.lutimes = function (_a, _b, _c, cb) { if (cb) process.nextTick(cb); };
|
|
305
|
+
fs.lutimesSync = function () {};
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function chmodFix (orig) {
|
|
310
|
+
if (!orig) return orig
|
|
311
|
+
return function (target, mode, cb) {
|
|
312
|
+
return orig.call(fs, target, mode, function (er) {
|
|
313
|
+
if (chownErOk(er)) er = null;
|
|
314
|
+
if (cb) cb.apply(this, arguments);
|
|
315
|
+
})
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function chmodFixSync (orig) {
|
|
320
|
+
if (!orig) return orig
|
|
321
|
+
return function (target, mode) {
|
|
322
|
+
try {
|
|
323
|
+
return orig.call(fs, target, mode)
|
|
324
|
+
} catch (er) {
|
|
325
|
+
if (!chownErOk(er)) throw er
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
function chownFix (orig) {
|
|
332
|
+
if (!orig) return orig
|
|
333
|
+
return function (target, uid, gid, cb) {
|
|
334
|
+
return orig.call(fs, target, uid, gid, function (er) {
|
|
335
|
+
if (chownErOk(er)) er = null;
|
|
336
|
+
if (cb) cb.apply(this, arguments);
|
|
337
|
+
})
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function chownFixSync (orig) {
|
|
342
|
+
if (!orig) return orig
|
|
343
|
+
return function (target, uid, gid) {
|
|
344
|
+
try {
|
|
345
|
+
return orig.call(fs, target, uid, gid)
|
|
346
|
+
} catch (er) {
|
|
347
|
+
if (!chownErOk(er)) throw er
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function statFix (orig) {
|
|
353
|
+
if (!orig) return orig
|
|
354
|
+
// Older versions of Node erroneously returned signed integers for
|
|
355
|
+
// uid + gid.
|
|
356
|
+
return function (target, options, cb) {
|
|
357
|
+
if (typeof options === 'function') {
|
|
358
|
+
cb = options;
|
|
359
|
+
options = null;
|
|
360
|
+
}
|
|
361
|
+
function callback (er, stats) {
|
|
362
|
+
if (stats) {
|
|
363
|
+
if (stats.uid < 0) stats.uid += 0x100000000;
|
|
364
|
+
if (stats.gid < 0) stats.gid += 0x100000000;
|
|
365
|
+
}
|
|
366
|
+
if (cb) cb.apply(this, arguments);
|
|
367
|
+
}
|
|
368
|
+
return options ? orig.call(fs, target, options, callback)
|
|
369
|
+
: orig.call(fs, target, callback)
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
function statFixSync (orig) {
|
|
374
|
+
if (!orig) return orig
|
|
375
|
+
// Older versions of Node erroneously returned signed integers for
|
|
376
|
+
// uid + gid.
|
|
377
|
+
return function (target, options) {
|
|
378
|
+
var stats = options ? orig.call(fs, target, options)
|
|
379
|
+
: orig.call(fs, target);
|
|
380
|
+
if (stats) {
|
|
381
|
+
if (stats.uid < 0) stats.uid += 0x100000000;
|
|
382
|
+
if (stats.gid < 0) stats.gid += 0x100000000;
|
|
383
|
+
}
|
|
384
|
+
return stats;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// ENOSYS means that the fs doesn't support the op. Just ignore
|
|
389
|
+
// that, because it doesn't matter.
|
|
390
|
+
//
|
|
391
|
+
// if there's no getuid, or if getuid() is something other
|
|
392
|
+
// than 0, and the error is EINVAL or EPERM, then just ignore
|
|
393
|
+
// it.
|
|
394
|
+
//
|
|
395
|
+
// This specific case is a silent failure in cp, install, tar,
|
|
396
|
+
// and most other unix tools that manage permissions.
|
|
397
|
+
//
|
|
398
|
+
// When running as root, or if other types of errors are
|
|
399
|
+
// encountered, then it's strict.
|
|
400
|
+
function chownErOk (er) {
|
|
401
|
+
if (!er)
|
|
402
|
+
return true
|
|
403
|
+
|
|
404
|
+
if (er.code === "ENOSYS")
|
|
405
|
+
return true
|
|
406
|
+
|
|
407
|
+
var nonroot = !process.getuid || process.getuid() !== 0;
|
|
408
|
+
if (nonroot) {
|
|
409
|
+
if (er.code === "EINVAL" || er.code === "EPERM")
|
|
410
|
+
return true
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
return false
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
var Stream = require$$0__default$1["default"].Stream;
|
|
418
|
+
|
|
419
|
+
var legacyStreams = legacy$1;
|
|
420
|
+
|
|
421
|
+
function legacy$1 (fs) {
|
|
422
|
+
return {
|
|
423
|
+
ReadStream: ReadStream,
|
|
424
|
+
WriteStream: WriteStream
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
function ReadStream (path, options) {
|
|
428
|
+
if (!(this instanceof ReadStream)) return new ReadStream(path, options);
|
|
429
|
+
|
|
430
|
+
Stream.call(this);
|
|
431
|
+
|
|
432
|
+
var self = this;
|
|
433
|
+
|
|
434
|
+
this.path = path;
|
|
435
|
+
this.fd = null;
|
|
436
|
+
this.readable = true;
|
|
437
|
+
this.paused = false;
|
|
438
|
+
|
|
439
|
+
this.flags = 'r';
|
|
440
|
+
this.mode = 438; /*=0666*/
|
|
441
|
+
this.bufferSize = 64 * 1024;
|
|
442
|
+
|
|
443
|
+
options = options || {};
|
|
444
|
+
|
|
445
|
+
// Mixin options into this
|
|
446
|
+
var keys = Object.keys(options);
|
|
447
|
+
for (var index = 0, length = keys.length; index < length; index++) {
|
|
448
|
+
var key = keys[index];
|
|
449
|
+
this[key] = options[key];
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
if (this.encoding) this.setEncoding(this.encoding);
|
|
453
|
+
|
|
454
|
+
if (this.start !== undefined) {
|
|
455
|
+
if ('number' !== typeof this.start) {
|
|
456
|
+
throw TypeError('start must be a Number');
|
|
457
|
+
}
|
|
458
|
+
if (this.end === undefined) {
|
|
459
|
+
this.end = Infinity;
|
|
460
|
+
} else if ('number' !== typeof this.end) {
|
|
461
|
+
throw TypeError('end must be a Number');
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
if (this.start > this.end) {
|
|
465
|
+
throw new Error('start must be <= end');
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
this.pos = this.start;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
if (this.fd !== null) {
|
|
472
|
+
process.nextTick(function() {
|
|
473
|
+
self._read();
|
|
474
|
+
});
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
fs.open(this.path, this.flags, this.mode, function (err, fd) {
|
|
479
|
+
if (err) {
|
|
480
|
+
self.emit('error', err);
|
|
481
|
+
self.readable = false;
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
self.fd = fd;
|
|
486
|
+
self.emit('open', fd);
|
|
487
|
+
self._read();
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
function WriteStream (path, options) {
|
|
492
|
+
if (!(this instanceof WriteStream)) return new WriteStream(path, options);
|
|
493
|
+
|
|
494
|
+
Stream.call(this);
|
|
495
|
+
|
|
496
|
+
this.path = path;
|
|
497
|
+
this.fd = null;
|
|
498
|
+
this.writable = true;
|
|
499
|
+
|
|
500
|
+
this.flags = 'w';
|
|
501
|
+
this.encoding = 'binary';
|
|
502
|
+
this.mode = 438; /*=0666*/
|
|
503
|
+
this.bytesWritten = 0;
|
|
504
|
+
|
|
505
|
+
options = options || {};
|
|
506
|
+
|
|
507
|
+
// Mixin options into this
|
|
508
|
+
var keys = Object.keys(options);
|
|
509
|
+
for (var index = 0, length = keys.length; index < length; index++) {
|
|
510
|
+
var key = keys[index];
|
|
511
|
+
this[key] = options[key];
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
if (this.start !== undefined) {
|
|
515
|
+
if ('number' !== typeof this.start) {
|
|
516
|
+
throw TypeError('start must be a Number');
|
|
517
|
+
}
|
|
518
|
+
if (this.start < 0) {
|
|
519
|
+
throw new Error('start must be >= zero');
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
this.pos = this.start;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
this.busy = false;
|
|
526
|
+
this._queue = [];
|
|
527
|
+
|
|
528
|
+
if (this.fd === null) {
|
|
529
|
+
this._open = fs.open;
|
|
530
|
+
this._queue.push([this._open, this.path, this.flags, this.mode, undefined]);
|
|
531
|
+
this.flush();
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
var clone_1 = clone$1;
|
|
537
|
+
|
|
538
|
+
var getPrototypeOf = Object.getPrototypeOf || function (obj) {
|
|
539
|
+
return obj.__proto__
|
|
540
|
+
};
|
|
541
|
+
|
|
542
|
+
function clone$1 (obj) {
|
|
543
|
+
if (obj === null || typeof obj !== 'object')
|
|
544
|
+
return obj
|
|
545
|
+
|
|
546
|
+
if (obj instanceof Object)
|
|
547
|
+
var copy = { __proto__: getPrototypeOf(obj) };
|
|
548
|
+
else
|
|
549
|
+
var copy = Object.create(null);
|
|
550
|
+
|
|
551
|
+
Object.getOwnPropertyNames(obj).forEach(function (key) {
|
|
552
|
+
Object.defineProperty(copy, key, Object.getOwnPropertyDescriptor(obj, key));
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
return copy
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
var fs$j = require$$1__default["default"];
|
|
559
|
+
var polyfills = polyfills$1;
|
|
560
|
+
var legacy = legacyStreams;
|
|
561
|
+
var clone = clone_1;
|
|
562
|
+
|
|
563
|
+
var util = require$$4__default["default"];
|
|
564
|
+
|
|
565
|
+
/* istanbul ignore next - node 0.x polyfill */
|
|
566
|
+
var gracefulQueue;
|
|
567
|
+
var previousSymbol;
|
|
568
|
+
|
|
569
|
+
/* istanbul ignore else - node 0.x polyfill */
|
|
570
|
+
if (typeof Symbol === 'function' && typeof Symbol.for === 'function') {
|
|
571
|
+
gracefulQueue = Symbol.for('graceful-fs.queue');
|
|
572
|
+
// This is used in testing by future versions
|
|
573
|
+
previousSymbol = Symbol.for('graceful-fs.previous');
|
|
574
|
+
} else {
|
|
575
|
+
gracefulQueue = '___graceful-fs.queue';
|
|
576
|
+
previousSymbol = '___graceful-fs.previous';
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
function noop () {}
|
|
580
|
+
|
|
581
|
+
function publishQueue(context, queue) {
|
|
582
|
+
Object.defineProperty(context, gracefulQueue, {
|
|
583
|
+
get: function() {
|
|
584
|
+
return queue
|
|
585
|
+
}
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
var debug = noop;
|
|
590
|
+
if (util.debuglog)
|
|
591
|
+
debug = util.debuglog('gfs4');
|
|
592
|
+
else if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || ''))
|
|
593
|
+
debug = function() {
|
|
594
|
+
var m = util.format.apply(util, arguments);
|
|
595
|
+
m = 'GFS4: ' + m.split(/\n/).join('\nGFS4: ');
|
|
596
|
+
console.error(m);
|
|
597
|
+
};
|
|
598
|
+
|
|
599
|
+
// Once time initialization
|
|
600
|
+
if (!fs$j[gracefulQueue]) {
|
|
601
|
+
// This queue can be shared by multiple loaded instances
|
|
602
|
+
var queue = commonjsGlobal[gracefulQueue] || [];
|
|
603
|
+
publishQueue(fs$j, queue);
|
|
604
|
+
|
|
605
|
+
// Patch fs.close/closeSync to shared queue version, because we need
|
|
606
|
+
// to retry() whenever a close happens *anywhere* in the program.
|
|
607
|
+
// This is essential when multiple graceful-fs instances are
|
|
608
|
+
// in play at the same time.
|
|
609
|
+
fs$j.close = (function (fs$close) {
|
|
610
|
+
function close (fd, cb) {
|
|
611
|
+
return fs$close.call(fs$j, fd, function (err) {
|
|
612
|
+
// This function uses the graceful-fs shared queue
|
|
613
|
+
if (!err) {
|
|
614
|
+
resetQueue();
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
if (typeof cb === 'function')
|
|
618
|
+
cb.apply(this, arguments);
|
|
619
|
+
})
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
Object.defineProperty(close, previousSymbol, {
|
|
623
|
+
value: fs$close
|
|
624
|
+
});
|
|
625
|
+
return close
|
|
626
|
+
})(fs$j.close);
|
|
627
|
+
|
|
628
|
+
fs$j.closeSync = (function (fs$closeSync) {
|
|
629
|
+
function closeSync (fd) {
|
|
630
|
+
// This function uses the graceful-fs shared queue
|
|
631
|
+
fs$closeSync.apply(fs$j, arguments);
|
|
632
|
+
resetQueue();
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
Object.defineProperty(closeSync, previousSymbol, {
|
|
636
|
+
value: fs$closeSync
|
|
637
|
+
});
|
|
638
|
+
return closeSync
|
|
639
|
+
})(fs$j.closeSync);
|
|
640
|
+
|
|
641
|
+
if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || '')) {
|
|
642
|
+
process.on('exit', function() {
|
|
643
|
+
debug(fs$j[gracefulQueue]);
|
|
644
|
+
assert__default["default"].equal(fs$j[gracefulQueue].length, 0);
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
if (!commonjsGlobal[gracefulQueue]) {
|
|
650
|
+
publishQueue(commonjsGlobal, fs$j[gracefulQueue]);
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
var gracefulFs = patch(clone(fs$j));
|
|
654
|
+
if (process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH && !fs$j.__patched) {
|
|
655
|
+
gracefulFs = patch(fs$j);
|
|
656
|
+
fs$j.__patched = true;
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
function patch (fs) {
|
|
660
|
+
// Everything that references the open() function needs to be in here
|
|
661
|
+
polyfills(fs);
|
|
662
|
+
fs.gracefulify = patch;
|
|
663
|
+
|
|
664
|
+
fs.createReadStream = createReadStream;
|
|
665
|
+
fs.createWriteStream = createWriteStream;
|
|
666
|
+
var fs$readFile = fs.readFile;
|
|
667
|
+
fs.readFile = readFile;
|
|
668
|
+
function readFile (path, options, cb) {
|
|
669
|
+
if (typeof options === 'function')
|
|
670
|
+
cb = options, options = null;
|
|
671
|
+
|
|
672
|
+
return go$readFile(path, options, cb)
|
|
673
|
+
|
|
674
|
+
function go$readFile (path, options, cb, startTime) {
|
|
675
|
+
return fs$readFile(path, options, function (err) {
|
|
676
|
+
if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
|
|
677
|
+
enqueue([go$readFile, [path, options, cb], err, startTime || Date.now(), Date.now()]);
|
|
678
|
+
else {
|
|
679
|
+
if (typeof cb === 'function')
|
|
680
|
+
cb.apply(this, arguments);
|
|
681
|
+
}
|
|
682
|
+
})
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
var fs$writeFile = fs.writeFile;
|
|
687
|
+
fs.writeFile = writeFile;
|
|
688
|
+
function writeFile (path, data, options, cb) {
|
|
689
|
+
if (typeof options === 'function')
|
|
690
|
+
cb = options, options = null;
|
|
691
|
+
|
|
692
|
+
return go$writeFile(path, data, options, cb)
|
|
693
|
+
|
|
694
|
+
function go$writeFile (path, data, options, cb, startTime) {
|
|
695
|
+
return fs$writeFile(path, data, options, function (err) {
|
|
696
|
+
if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
|
|
697
|
+
enqueue([go$writeFile, [path, data, options, cb], err, startTime || Date.now(), Date.now()]);
|
|
698
|
+
else {
|
|
699
|
+
if (typeof cb === 'function')
|
|
700
|
+
cb.apply(this, arguments);
|
|
701
|
+
}
|
|
702
|
+
})
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
var fs$appendFile = fs.appendFile;
|
|
707
|
+
if (fs$appendFile)
|
|
708
|
+
fs.appendFile = appendFile;
|
|
709
|
+
function appendFile (path, data, options, cb) {
|
|
710
|
+
if (typeof options === 'function')
|
|
711
|
+
cb = options, options = null;
|
|
712
|
+
|
|
713
|
+
return go$appendFile(path, data, options, cb)
|
|
714
|
+
|
|
715
|
+
function go$appendFile (path, data, options, cb, startTime) {
|
|
716
|
+
return fs$appendFile(path, data, options, function (err) {
|
|
717
|
+
if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
|
|
718
|
+
enqueue([go$appendFile, [path, data, options, cb], err, startTime || Date.now(), Date.now()]);
|
|
719
|
+
else {
|
|
720
|
+
if (typeof cb === 'function')
|
|
721
|
+
cb.apply(this, arguments);
|
|
722
|
+
}
|
|
723
|
+
})
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
var fs$copyFile = fs.copyFile;
|
|
728
|
+
if (fs$copyFile)
|
|
729
|
+
fs.copyFile = copyFile;
|
|
730
|
+
function copyFile (src, dest, flags, cb) {
|
|
731
|
+
if (typeof flags === 'function') {
|
|
732
|
+
cb = flags;
|
|
733
|
+
flags = 0;
|
|
734
|
+
}
|
|
735
|
+
return go$copyFile(src, dest, flags, cb)
|
|
736
|
+
|
|
737
|
+
function go$copyFile (src, dest, flags, cb, startTime) {
|
|
738
|
+
return fs$copyFile(src, dest, flags, function (err) {
|
|
739
|
+
if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
|
|
740
|
+
enqueue([go$copyFile, [src, dest, flags, cb], err, startTime || Date.now(), Date.now()]);
|
|
741
|
+
else {
|
|
742
|
+
if (typeof cb === 'function')
|
|
743
|
+
cb.apply(this, arguments);
|
|
744
|
+
}
|
|
745
|
+
})
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
var fs$readdir = fs.readdir;
|
|
750
|
+
fs.readdir = readdir;
|
|
751
|
+
var noReaddirOptionVersions = /^v[0-5]\./;
|
|
752
|
+
function readdir (path, options, cb) {
|
|
753
|
+
if (typeof options === 'function')
|
|
754
|
+
cb = options, options = null;
|
|
755
|
+
|
|
756
|
+
var go$readdir = noReaddirOptionVersions.test(process.version)
|
|
757
|
+
? function go$readdir (path, options, cb, startTime) {
|
|
758
|
+
return fs$readdir(path, fs$readdirCallback(
|
|
759
|
+
path, options, cb, startTime
|
|
760
|
+
))
|
|
761
|
+
}
|
|
762
|
+
: function go$readdir (path, options, cb, startTime) {
|
|
763
|
+
return fs$readdir(path, options, fs$readdirCallback(
|
|
764
|
+
path, options, cb, startTime
|
|
765
|
+
))
|
|
766
|
+
};
|
|
767
|
+
|
|
768
|
+
return go$readdir(path, options, cb)
|
|
769
|
+
|
|
770
|
+
function fs$readdirCallback (path, options, cb, startTime) {
|
|
771
|
+
return function (err, files) {
|
|
772
|
+
if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
|
|
773
|
+
enqueue([
|
|
774
|
+
go$readdir,
|
|
775
|
+
[path, options, cb],
|
|
776
|
+
err,
|
|
777
|
+
startTime || Date.now(),
|
|
778
|
+
Date.now()
|
|
779
|
+
]);
|
|
780
|
+
else {
|
|
781
|
+
if (files && files.sort)
|
|
782
|
+
files.sort();
|
|
783
|
+
|
|
784
|
+
if (typeof cb === 'function')
|
|
785
|
+
cb.call(this, err, files);
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
if (process.version.substr(0, 4) === 'v0.8') {
|
|
792
|
+
var legStreams = legacy(fs);
|
|
793
|
+
ReadStream = legStreams.ReadStream;
|
|
794
|
+
WriteStream = legStreams.WriteStream;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
var fs$ReadStream = fs.ReadStream;
|
|
798
|
+
if (fs$ReadStream) {
|
|
799
|
+
ReadStream.prototype = Object.create(fs$ReadStream.prototype);
|
|
800
|
+
ReadStream.prototype.open = ReadStream$open;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
var fs$WriteStream = fs.WriteStream;
|
|
804
|
+
if (fs$WriteStream) {
|
|
805
|
+
WriteStream.prototype = Object.create(fs$WriteStream.prototype);
|
|
806
|
+
WriteStream.prototype.open = WriteStream$open;
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
Object.defineProperty(fs, 'ReadStream', {
|
|
810
|
+
get: function () {
|
|
811
|
+
return ReadStream
|
|
812
|
+
},
|
|
813
|
+
set: function (val) {
|
|
814
|
+
ReadStream = val;
|
|
815
|
+
},
|
|
816
|
+
enumerable: true,
|
|
817
|
+
configurable: true
|
|
818
|
+
});
|
|
819
|
+
Object.defineProperty(fs, 'WriteStream', {
|
|
820
|
+
get: function () {
|
|
821
|
+
return WriteStream
|
|
822
|
+
},
|
|
823
|
+
set: function (val) {
|
|
824
|
+
WriteStream = val;
|
|
825
|
+
},
|
|
826
|
+
enumerable: true,
|
|
827
|
+
configurable: true
|
|
828
|
+
});
|
|
829
|
+
|
|
830
|
+
// legacy names
|
|
831
|
+
var FileReadStream = ReadStream;
|
|
832
|
+
Object.defineProperty(fs, 'FileReadStream', {
|
|
833
|
+
get: function () {
|
|
834
|
+
return FileReadStream
|
|
835
|
+
},
|
|
836
|
+
set: function (val) {
|
|
837
|
+
FileReadStream = val;
|
|
838
|
+
},
|
|
839
|
+
enumerable: true,
|
|
840
|
+
configurable: true
|
|
841
|
+
});
|
|
842
|
+
var FileWriteStream = WriteStream;
|
|
843
|
+
Object.defineProperty(fs, 'FileWriteStream', {
|
|
844
|
+
get: function () {
|
|
845
|
+
return FileWriteStream
|
|
846
|
+
},
|
|
847
|
+
set: function (val) {
|
|
848
|
+
FileWriteStream = val;
|
|
849
|
+
},
|
|
850
|
+
enumerable: true,
|
|
851
|
+
configurable: true
|
|
852
|
+
});
|
|
853
|
+
|
|
854
|
+
function ReadStream (path, options) {
|
|
855
|
+
if (this instanceof ReadStream)
|
|
856
|
+
return fs$ReadStream.apply(this, arguments), this
|
|
857
|
+
else
|
|
858
|
+
return ReadStream.apply(Object.create(ReadStream.prototype), arguments)
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
function ReadStream$open () {
|
|
862
|
+
var that = this;
|
|
863
|
+
open(that.path, that.flags, that.mode, function (err, fd) {
|
|
864
|
+
if (err) {
|
|
865
|
+
if (that.autoClose)
|
|
866
|
+
that.destroy();
|
|
867
|
+
|
|
868
|
+
that.emit('error', err);
|
|
869
|
+
} else {
|
|
870
|
+
that.fd = fd;
|
|
871
|
+
that.emit('open', fd);
|
|
872
|
+
that.read();
|
|
873
|
+
}
|
|
874
|
+
});
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
function WriteStream (path, options) {
|
|
878
|
+
if (this instanceof WriteStream)
|
|
879
|
+
return fs$WriteStream.apply(this, arguments), this
|
|
880
|
+
else
|
|
881
|
+
return WriteStream.apply(Object.create(WriteStream.prototype), arguments)
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
function WriteStream$open () {
|
|
885
|
+
var that = this;
|
|
886
|
+
open(that.path, that.flags, that.mode, function (err, fd) {
|
|
887
|
+
if (err) {
|
|
888
|
+
that.destroy();
|
|
889
|
+
that.emit('error', err);
|
|
890
|
+
} else {
|
|
891
|
+
that.fd = fd;
|
|
892
|
+
that.emit('open', fd);
|
|
893
|
+
}
|
|
894
|
+
});
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
function createReadStream (path, options) {
|
|
898
|
+
return new fs.ReadStream(path, options)
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
function createWriteStream (path, options) {
|
|
902
|
+
return new fs.WriteStream(path, options)
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
var fs$open = fs.open;
|
|
906
|
+
fs.open = open;
|
|
907
|
+
function open (path, flags, mode, cb) {
|
|
908
|
+
if (typeof mode === 'function')
|
|
909
|
+
cb = mode, mode = null;
|
|
910
|
+
|
|
911
|
+
return go$open(path, flags, mode, cb)
|
|
912
|
+
|
|
913
|
+
function go$open (path, flags, mode, cb, startTime) {
|
|
914
|
+
return fs$open(path, flags, mode, function (err, fd) {
|
|
915
|
+
if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
|
|
916
|
+
enqueue([go$open, [path, flags, mode, cb], err, startTime || Date.now(), Date.now()]);
|
|
917
|
+
else {
|
|
918
|
+
if (typeof cb === 'function')
|
|
919
|
+
cb.apply(this, arguments);
|
|
920
|
+
}
|
|
921
|
+
})
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
return fs
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
function enqueue (elem) {
|
|
929
|
+
debug('ENQUEUE', elem[0].name, elem[1]);
|
|
930
|
+
fs$j[gracefulQueue].push(elem);
|
|
931
|
+
retry();
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
// keep track of the timeout between retry() calls
|
|
935
|
+
var retryTimer;
|
|
936
|
+
|
|
937
|
+
// reset the startTime and lastTime to now
|
|
938
|
+
// this resets the start of the 60 second overall timeout as well as the
|
|
939
|
+
// delay between attempts so that we'll retry these jobs sooner
|
|
940
|
+
function resetQueue () {
|
|
941
|
+
var now = Date.now();
|
|
942
|
+
for (var i = 0; i < fs$j[gracefulQueue].length; ++i) {
|
|
943
|
+
// entries that are only a length of 2 are from an older version, don't
|
|
944
|
+
// bother modifying those since they'll be retried anyway.
|
|
945
|
+
if (fs$j[gracefulQueue][i].length > 2) {
|
|
946
|
+
fs$j[gracefulQueue][i][3] = now; // startTime
|
|
947
|
+
fs$j[gracefulQueue][i][4] = now; // lastTime
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
// call retry to make sure we're actively processing the queue
|
|
951
|
+
retry();
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
function retry () {
|
|
955
|
+
// clear the timer and remove it to help prevent unintended concurrency
|
|
956
|
+
clearTimeout(retryTimer);
|
|
957
|
+
retryTimer = undefined;
|
|
958
|
+
|
|
959
|
+
if (fs$j[gracefulQueue].length === 0)
|
|
960
|
+
return
|
|
961
|
+
|
|
962
|
+
var elem = fs$j[gracefulQueue].shift();
|
|
963
|
+
var fn = elem[0];
|
|
964
|
+
var args = elem[1];
|
|
965
|
+
// these items may be unset if they were added by an older graceful-fs
|
|
966
|
+
var err = elem[2];
|
|
967
|
+
var startTime = elem[3];
|
|
968
|
+
var lastTime = elem[4];
|
|
969
|
+
|
|
970
|
+
// if we don't have a startTime we have no way of knowing if we've waited
|
|
971
|
+
// long enough, so go ahead and retry this item now
|
|
972
|
+
if (startTime === undefined) {
|
|
973
|
+
debug('RETRY', fn.name, args);
|
|
974
|
+
fn.apply(null, args);
|
|
975
|
+
} else if (Date.now() - startTime >= 60000) {
|
|
976
|
+
// it's been more than 60 seconds total, bail now
|
|
977
|
+
debug('TIMEOUT', fn.name, args);
|
|
978
|
+
var cb = args.pop();
|
|
979
|
+
if (typeof cb === 'function')
|
|
980
|
+
cb.call(null, err);
|
|
981
|
+
} else {
|
|
982
|
+
// the amount of time between the last attempt and right now
|
|
983
|
+
var sinceAttempt = Date.now() - lastTime;
|
|
984
|
+
// the amount of time between when we first tried, and when we last tried
|
|
985
|
+
// rounded up to at least 1
|
|
986
|
+
var sinceStart = Math.max(lastTime - startTime, 1);
|
|
987
|
+
// backoff. wait longer than the total time we've been retrying, but only
|
|
988
|
+
// up to a maximum of 100ms
|
|
989
|
+
var desiredDelay = Math.min(sinceStart * 1.2, 100);
|
|
990
|
+
// it's been long enough since the last retry, do it again
|
|
991
|
+
if (sinceAttempt >= desiredDelay) {
|
|
992
|
+
debug('RETRY', fn.name, args);
|
|
993
|
+
fn.apply(null, args.concat([startTime]));
|
|
994
|
+
} else {
|
|
995
|
+
// if we can't do this job yet, push it to the end of the queue
|
|
996
|
+
// and let the next iteration check again
|
|
997
|
+
fs$j[gracefulQueue].push(elem);
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
// schedule our next run if one isn't already scheduled
|
|
1002
|
+
if (retryTimer === undefined) {
|
|
1003
|
+
retryTimer = setTimeout(retry, 0);
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
(function (exports) {
|
|
1008
|
+
// This is adapted from https://github.com/normalize/mz
|
|
1009
|
+
// Copyright (c) 2014-2016 Jonathan Ong me@jongleberry.com and Contributors
|
|
1010
|
+
const u = universalify.fromCallback;
|
|
1011
|
+
const fs = gracefulFs;
|
|
1012
|
+
|
|
1013
|
+
const api = [
|
|
1014
|
+
'access',
|
|
1015
|
+
'appendFile',
|
|
1016
|
+
'chmod',
|
|
1017
|
+
'chown',
|
|
1018
|
+
'close',
|
|
1019
|
+
'copyFile',
|
|
1020
|
+
'fchmod',
|
|
1021
|
+
'fchown',
|
|
1022
|
+
'fdatasync',
|
|
1023
|
+
'fstat',
|
|
1024
|
+
'fsync',
|
|
1025
|
+
'ftruncate',
|
|
1026
|
+
'futimes',
|
|
1027
|
+
'lchown',
|
|
1028
|
+
'link',
|
|
1029
|
+
'lstat',
|
|
1030
|
+
'mkdir',
|
|
1031
|
+
'mkdtemp',
|
|
1032
|
+
'open',
|
|
1033
|
+
'readFile',
|
|
1034
|
+
'readdir',
|
|
1035
|
+
'readlink',
|
|
1036
|
+
'realpath',
|
|
1037
|
+
'rename',
|
|
1038
|
+
'rmdir',
|
|
1039
|
+
'stat',
|
|
1040
|
+
'symlink',
|
|
1041
|
+
'truncate',
|
|
1042
|
+
'unlink',
|
|
1043
|
+
'utimes',
|
|
1044
|
+
'writeFile'
|
|
1045
|
+
].filter(key => {
|
|
1046
|
+
// Some commands are not available on some systems. Ex:
|
|
1047
|
+
// fs.copyFile was added in Node.js v8.5.0
|
|
1048
|
+
// fs.mkdtemp was added in Node.js v5.10.0
|
|
1049
|
+
// fs.lchown is not available on at least some Linux
|
|
1050
|
+
return typeof fs[key] === 'function'
|
|
1051
|
+
});
|
|
1052
|
+
|
|
1053
|
+
// Export all keys:
|
|
1054
|
+
Object.keys(fs).forEach(key => {
|
|
1055
|
+
if (key === 'promises') {
|
|
1056
|
+
// fs.promises is a getter property that triggers ExperimentalWarning
|
|
1057
|
+
// Don't re-export it here, the getter is defined in "lib/index.js"
|
|
1058
|
+
return
|
|
1059
|
+
}
|
|
1060
|
+
exports[key] = fs[key];
|
|
1061
|
+
});
|
|
1062
|
+
|
|
1063
|
+
// Universalify async methods:
|
|
1064
|
+
api.forEach(method => {
|
|
1065
|
+
exports[method] = u(fs[method]);
|
|
1066
|
+
});
|
|
1067
|
+
|
|
1068
|
+
// We differ from mz/fs in that we still ship the old, broken, fs.exists()
|
|
1069
|
+
// since we are a drop-in replacement for the native module
|
|
1070
|
+
exports.exists = function (filename, callback) {
|
|
1071
|
+
if (typeof callback === 'function') {
|
|
1072
|
+
return fs.exists(filename, callback)
|
|
1073
|
+
}
|
|
1074
|
+
return new Promise(resolve => {
|
|
1075
|
+
return fs.exists(filename, resolve)
|
|
1076
|
+
})
|
|
1077
|
+
};
|
|
1078
|
+
|
|
1079
|
+
// fs.read() & fs.write need special treatment due to multiple callback args
|
|
1080
|
+
|
|
1081
|
+
exports.read = function (fd, buffer, offset, length, position, callback) {
|
|
1082
|
+
if (typeof callback === 'function') {
|
|
1083
|
+
return fs.read(fd, buffer, offset, length, position, callback)
|
|
1084
|
+
}
|
|
1085
|
+
return new Promise((resolve, reject) => {
|
|
1086
|
+
fs.read(fd, buffer, offset, length, position, (err, bytesRead, buffer) => {
|
|
1087
|
+
if (err) return reject(err)
|
|
1088
|
+
resolve({ bytesRead, buffer });
|
|
1089
|
+
});
|
|
1090
|
+
})
|
|
1091
|
+
};
|
|
1092
|
+
|
|
1093
|
+
// Function signature can be
|
|
1094
|
+
// fs.write(fd, buffer[, offset[, length[, position]]], callback)
|
|
1095
|
+
// OR
|
|
1096
|
+
// fs.write(fd, string[, position[, encoding]], callback)
|
|
1097
|
+
// We need to handle both cases, so we use ...args
|
|
1098
|
+
exports.write = function (fd, buffer, ...args) {
|
|
1099
|
+
if (typeof args[args.length - 1] === 'function') {
|
|
1100
|
+
return fs.write(fd, buffer, ...args)
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
return new Promise((resolve, reject) => {
|
|
1104
|
+
fs.write(fd, buffer, ...args, (err, bytesWritten, buffer) => {
|
|
1105
|
+
if (err) return reject(err)
|
|
1106
|
+
resolve({ bytesWritten, buffer });
|
|
1107
|
+
});
|
|
1108
|
+
})
|
|
1109
|
+
};
|
|
1110
|
+
} (fs$k));
|
|
1111
|
+
|
|
1112
|
+
const path$i = path__default["default"];
|
|
1113
|
+
|
|
1114
|
+
// get drive on windows
|
|
1115
|
+
function getRootPath (p) {
|
|
1116
|
+
p = path$i.normalize(path$i.resolve(p)).split(path$i.sep);
|
|
1117
|
+
if (p.length > 0) return p[0]
|
|
1118
|
+
return null
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
// http://stackoverflow.com/a/62888/10333 contains more accurate
|
|
1122
|
+
// TODO: expand to include the rest
|
|
1123
|
+
const INVALID_PATH_CHARS = /[<>:"|?*]/;
|
|
1124
|
+
|
|
1125
|
+
function invalidWin32Path$2 (p) {
|
|
1126
|
+
const rp = getRootPath(p);
|
|
1127
|
+
p = p.replace(rp, '');
|
|
1128
|
+
return INVALID_PATH_CHARS.test(p)
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
var win32 = {
|
|
1132
|
+
getRootPath,
|
|
1133
|
+
invalidWin32Path: invalidWin32Path$2
|
|
1134
|
+
};
|
|
1135
|
+
|
|
1136
|
+
const fs$i = gracefulFs;
|
|
1137
|
+
const path$h = path__default["default"];
|
|
1138
|
+
const invalidWin32Path$1 = win32.invalidWin32Path;
|
|
1139
|
+
|
|
1140
|
+
const o777$1 = parseInt('0777', 8);
|
|
1141
|
+
|
|
1142
|
+
function mkdirs$2 (p, opts, callback, made) {
|
|
1143
|
+
if (typeof opts === 'function') {
|
|
1144
|
+
callback = opts;
|
|
1145
|
+
opts = {};
|
|
1146
|
+
} else if (!opts || typeof opts !== 'object') {
|
|
1147
|
+
opts = { mode: opts };
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
if (process.platform === 'win32' && invalidWin32Path$1(p)) {
|
|
1151
|
+
const errInval = new Error(p + ' contains invalid WIN32 path characters.');
|
|
1152
|
+
errInval.code = 'EINVAL';
|
|
1153
|
+
return callback(errInval)
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
let mode = opts.mode;
|
|
1157
|
+
const xfs = opts.fs || fs$i;
|
|
1158
|
+
|
|
1159
|
+
if (mode === undefined) {
|
|
1160
|
+
mode = o777$1 & (~process.umask());
|
|
1161
|
+
}
|
|
1162
|
+
if (!made) made = null;
|
|
1163
|
+
|
|
1164
|
+
callback = callback || function () {};
|
|
1165
|
+
p = path$h.resolve(p);
|
|
1166
|
+
|
|
1167
|
+
xfs.mkdir(p, mode, er => {
|
|
1168
|
+
if (!er) {
|
|
1169
|
+
made = made || p;
|
|
1170
|
+
return callback(null, made)
|
|
1171
|
+
}
|
|
1172
|
+
switch (er.code) {
|
|
1173
|
+
case 'ENOENT':
|
|
1174
|
+
if (path$h.dirname(p) === p) return callback(er)
|
|
1175
|
+
mkdirs$2(path$h.dirname(p), opts, (er, made) => {
|
|
1176
|
+
if (er) callback(er, made);
|
|
1177
|
+
else mkdirs$2(p, opts, callback, made);
|
|
1178
|
+
});
|
|
1179
|
+
break
|
|
1180
|
+
|
|
1181
|
+
// In the case of any other error, just see if there's a dir
|
|
1182
|
+
// there already. If so, then hooray! If not, then something
|
|
1183
|
+
// is borked.
|
|
1184
|
+
default:
|
|
1185
|
+
xfs.stat(p, (er2, stat) => {
|
|
1186
|
+
// if the stat fails, then that's super weird.
|
|
1187
|
+
// let the original error be the failure reason.
|
|
1188
|
+
if (er2 || !stat.isDirectory()) callback(er, made);
|
|
1189
|
+
else callback(null, made);
|
|
1190
|
+
});
|
|
1191
|
+
break
|
|
1192
|
+
}
|
|
1193
|
+
});
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
var mkdirs_1$1 = mkdirs$2;
|
|
1197
|
+
|
|
1198
|
+
const fs$h = gracefulFs;
|
|
1199
|
+
const path$g = path__default["default"];
|
|
1200
|
+
const invalidWin32Path = win32.invalidWin32Path;
|
|
1201
|
+
|
|
1202
|
+
const o777 = parseInt('0777', 8);
|
|
1203
|
+
|
|
1204
|
+
function mkdirsSync$2 (p, opts, made) {
|
|
1205
|
+
if (!opts || typeof opts !== 'object') {
|
|
1206
|
+
opts = { mode: opts };
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
let mode = opts.mode;
|
|
1210
|
+
const xfs = opts.fs || fs$h;
|
|
1211
|
+
|
|
1212
|
+
if (process.platform === 'win32' && invalidWin32Path(p)) {
|
|
1213
|
+
const errInval = new Error(p + ' contains invalid WIN32 path characters.');
|
|
1214
|
+
errInval.code = 'EINVAL';
|
|
1215
|
+
throw errInval
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
if (mode === undefined) {
|
|
1219
|
+
mode = o777 & (~process.umask());
|
|
1220
|
+
}
|
|
1221
|
+
if (!made) made = null;
|
|
1222
|
+
|
|
1223
|
+
p = path$g.resolve(p);
|
|
1224
|
+
|
|
1225
|
+
try {
|
|
1226
|
+
xfs.mkdirSync(p, mode);
|
|
1227
|
+
made = made || p;
|
|
1228
|
+
} catch (err0) {
|
|
1229
|
+
if (err0.code === 'ENOENT') {
|
|
1230
|
+
if (path$g.dirname(p) === p) throw err0
|
|
1231
|
+
made = mkdirsSync$2(path$g.dirname(p), opts, made);
|
|
1232
|
+
mkdirsSync$2(p, opts, made);
|
|
1233
|
+
} else {
|
|
1234
|
+
// In the case of any other error, just see if there's a dir there
|
|
1235
|
+
// already. If so, then hooray! If not, then something is borked.
|
|
1236
|
+
let stat;
|
|
1237
|
+
try {
|
|
1238
|
+
stat = xfs.statSync(p);
|
|
1239
|
+
} catch (err1) {
|
|
1240
|
+
throw err0
|
|
1241
|
+
}
|
|
1242
|
+
if (!stat.isDirectory()) throw err0
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
return made
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
var mkdirsSync_1 = mkdirsSync$2;
|
|
1250
|
+
|
|
1251
|
+
const u$b = universalify.fromCallback;
|
|
1252
|
+
const mkdirs$1 = u$b(mkdirs_1$1);
|
|
1253
|
+
const mkdirsSync$1 = mkdirsSync_1;
|
|
1254
|
+
|
|
1255
|
+
var mkdirs_1 = {
|
|
1256
|
+
mkdirs: mkdirs$1,
|
|
1257
|
+
mkdirsSync: mkdirsSync$1,
|
|
1258
|
+
// alias
|
|
1259
|
+
mkdirp: mkdirs$1,
|
|
1260
|
+
mkdirpSync: mkdirsSync$1,
|
|
1261
|
+
ensureDir: mkdirs$1,
|
|
1262
|
+
ensureDirSync: mkdirsSync$1
|
|
1263
|
+
};
|
|
1264
|
+
|
|
1265
|
+
const fs$g = gracefulFs;
|
|
1266
|
+
const os = require$$1__default$1["default"];
|
|
1267
|
+
const path$f = path__default["default"];
|
|
1268
|
+
|
|
1269
|
+
// HFS, ext{2,3}, FAT do not, Node.js v0.10 does not
|
|
1270
|
+
function hasMillisResSync () {
|
|
1271
|
+
let tmpfile = path$f.join('millis-test-sync' + Date.now().toString() + Math.random().toString().slice(2));
|
|
1272
|
+
tmpfile = path$f.join(os.tmpdir(), tmpfile);
|
|
1273
|
+
|
|
1274
|
+
// 550 millis past UNIX epoch
|
|
1275
|
+
const d = new Date(1435410243862);
|
|
1276
|
+
fs$g.writeFileSync(tmpfile, 'https://github.com/jprichardson/node-fs-extra/pull/141');
|
|
1277
|
+
const fd = fs$g.openSync(tmpfile, 'r+');
|
|
1278
|
+
fs$g.futimesSync(fd, d, d);
|
|
1279
|
+
fs$g.closeSync(fd);
|
|
1280
|
+
return fs$g.statSync(tmpfile).mtime > 1435410243000
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
function hasMillisRes (callback) {
|
|
1284
|
+
let tmpfile = path$f.join('millis-test' + Date.now().toString() + Math.random().toString().slice(2));
|
|
1285
|
+
tmpfile = path$f.join(os.tmpdir(), tmpfile);
|
|
1286
|
+
|
|
1287
|
+
// 550 millis past UNIX epoch
|
|
1288
|
+
const d = new Date(1435410243862);
|
|
1289
|
+
fs$g.writeFile(tmpfile, 'https://github.com/jprichardson/node-fs-extra/pull/141', err => {
|
|
1290
|
+
if (err) return callback(err)
|
|
1291
|
+
fs$g.open(tmpfile, 'r+', (err, fd) => {
|
|
1292
|
+
if (err) return callback(err)
|
|
1293
|
+
fs$g.futimes(fd, d, d, err => {
|
|
1294
|
+
if (err) return callback(err)
|
|
1295
|
+
fs$g.close(fd, err => {
|
|
1296
|
+
if (err) return callback(err)
|
|
1297
|
+
fs$g.stat(tmpfile, (err, stats) => {
|
|
1298
|
+
if (err) return callback(err)
|
|
1299
|
+
callback(null, stats.mtime > 1435410243000);
|
|
1300
|
+
});
|
|
1301
|
+
});
|
|
1302
|
+
});
|
|
1303
|
+
});
|
|
1304
|
+
});
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
function timeRemoveMillis (timestamp) {
|
|
1308
|
+
if (typeof timestamp === 'number') {
|
|
1309
|
+
return Math.floor(timestamp / 1000) * 1000
|
|
1310
|
+
} else if (timestamp instanceof Date) {
|
|
1311
|
+
return new Date(Math.floor(timestamp.getTime() / 1000) * 1000)
|
|
1312
|
+
} else {
|
|
1313
|
+
throw new Error('fs-extra: timeRemoveMillis() unknown parameter type')
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
function utimesMillis (path, atime, mtime, callback) {
|
|
1318
|
+
// if (!HAS_MILLIS_RES) return fs.utimes(path, atime, mtime, callback)
|
|
1319
|
+
fs$g.open(path, 'r+', (err, fd) => {
|
|
1320
|
+
if (err) return callback(err)
|
|
1321
|
+
fs$g.futimes(fd, atime, mtime, futimesErr => {
|
|
1322
|
+
fs$g.close(fd, closeErr => {
|
|
1323
|
+
if (callback) callback(futimesErr || closeErr);
|
|
1324
|
+
});
|
|
1325
|
+
});
|
|
1326
|
+
});
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
function utimesMillisSync (path, atime, mtime) {
|
|
1330
|
+
const fd = fs$g.openSync(path, 'r+');
|
|
1331
|
+
fs$g.futimesSync(fd, atime, mtime);
|
|
1332
|
+
return fs$g.closeSync(fd)
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
var utimes$1 = {
|
|
1336
|
+
hasMillisRes,
|
|
1337
|
+
hasMillisResSync,
|
|
1338
|
+
timeRemoveMillis,
|
|
1339
|
+
utimesMillis,
|
|
1340
|
+
utimesMillisSync
|
|
1341
|
+
};
|
|
1342
|
+
|
|
1343
|
+
/* eslint-disable node/no-deprecated-api */
|
|
1344
|
+
var buffer$1 = function (size) {
|
|
1345
|
+
if (typeof Buffer.allocUnsafe === 'function') {
|
|
1346
|
+
try {
|
|
1347
|
+
return Buffer.allocUnsafe(size)
|
|
1348
|
+
} catch (e) {
|
|
1349
|
+
return new Buffer(size)
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
return new Buffer(size)
|
|
1353
|
+
};
|
|
1354
|
+
|
|
1355
|
+
const fs$f = gracefulFs;
|
|
1356
|
+
const path$e = path__default["default"];
|
|
1357
|
+
const mkdirpSync$1 = mkdirs_1.mkdirsSync;
|
|
1358
|
+
const utimesSync = utimes$1.utimesMillisSync;
|
|
1359
|
+
|
|
1360
|
+
const notExist$1 = Symbol('notExist');
|
|
1361
|
+
const existsReg$1 = Symbol('existsReg');
|
|
1362
|
+
|
|
1363
|
+
function copySync$2 (src, dest, opts) {
|
|
1364
|
+
if (typeof opts === 'function') {
|
|
1365
|
+
opts = {filter: opts};
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
opts = opts || {};
|
|
1369
|
+
opts.clobber = 'clobber' in opts ? !!opts.clobber : true; // default to true for now
|
|
1370
|
+
opts.overwrite = 'overwrite' in opts ? !!opts.overwrite : opts.clobber; // overwrite falls back to clobber
|
|
1371
|
+
|
|
1372
|
+
// Warn about using preserveTimestamps on 32-bit node
|
|
1373
|
+
if (opts.preserveTimestamps && process.arch === 'ia32') {
|
|
1374
|
+
console.warn(`fs-extra: Using the preserveTimestamps option in 32-bit node is not recommended;\n
|
|
1375
|
+
see https://github.com/jprichardson/node-fs-extra/issues/269`);
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1378
|
+
const resolvedDest = checkPaths$1(src, dest);
|
|
1379
|
+
|
|
1380
|
+
if (opts.filter && !opts.filter(src, dest)) return
|
|
1381
|
+
|
|
1382
|
+
const destParent = path$e.dirname(dest);
|
|
1383
|
+
if (!fs$f.existsSync(destParent)) mkdirpSync$1(destParent);
|
|
1384
|
+
return startCopy$1(resolvedDest, src, dest, opts)
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1387
|
+
function startCopy$1 (resolvedDest, src, dest, opts) {
|
|
1388
|
+
if (opts.filter && !opts.filter(src, dest)) return
|
|
1389
|
+
return getStats$1(resolvedDest, src, dest, opts)
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
function getStats$1 (resolvedDest, src, dest, opts) {
|
|
1393
|
+
const statSync = opts.dereference ? fs$f.statSync : fs$f.lstatSync;
|
|
1394
|
+
const st = statSync(src);
|
|
1395
|
+
|
|
1396
|
+
if (st.isDirectory()) return onDir$1(st, resolvedDest, src, dest, opts)
|
|
1397
|
+
else if (st.isFile() ||
|
|
1398
|
+
st.isCharacterDevice() ||
|
|
1399
|
+
st.isBlockDevice()) return onFile$1(st, resolvedDest, src, dest, opts)
|
|
1400
|
+
else if (st.isSymbolicLink()) return onLink$1(resolvedDest, src, dest, opts)
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
function onFile$1 (srcStat, resolvedDest, src, dest, opts) {
|
|
1404
|
+
if (resolvedDest === notExist$1) return copyFile$1(srcStat, src, dest, opts)
|
|
1405
|
+
else if (resolvedDest === existsReg$1) return mayCopyFile$1(srcStat, src, dest, opts)
|
|
1406
|
+
return mayCopyFile$1(srcStat, src, dest, opts)
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1409
|
+
function mayCopyFile$1 (srcStat, src, dest, opts) {
|
|
1410
|
+
if (opts.overwrite) {
|
|
1411
|
+
fs$f.unlinkSync(dest);
|
|
1412
|
+
return copyFile$1(srcStat, src, dest, opts)
|
|
1413
|
+
} else if (opts.errorOnExist) {
|
|
1414
|
+
throw new Error(`'${dest}' already exists`)
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1418
|
+
function copyFile$1 (srcStat, src, dest, opts) {
|
|
1419
|
+
if (typeof fs$f.copyFileSync === 'function') {
|
|
1420
|
+
fs$f.copyFileSync(src, dest);
|
|
1421
|
+
fs$f.chmodSync(dest, srcStat.mode);
|
|
1422
|
+
if (opts.preserveTimestamps) {
|
|
1423
|
+
return utimesSync(dest, srcStat.atime, srcStat.mtime)
|
|
1424
|
+
}
|
|
1425
|
+
return
|
|
1426
|
+
}
|
|
1427
|
+
return copyFileFallback$1(srcStat, src, dest, opts)
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
function copyFileFallback$1 (srcStat, src, dest, opts) {
|
|
1431
|
+
const BUF_LENGTH = 64 * 1024;
|
|
1432
|
+
const _buff = buffer$1(BUF_LENGTH);
|
|
1433
|
+
|
|
1434
|
+
const fdr = fs$f.openSync(src, 'r');
|
|
1435
|
+
const fdw = fs$f.openSync(dest, 'w', srcStat.mode);
|
|
1436
|
+
let pos = 0;
|
|
1437
|
+
|
|
1438
|
+
while (pos < srcStat.size) {
|
|
1439
|
+
const bytesRead = fs$f.readSync(fdr, _buff, 0, BUF_LENGTH, pos);
|
|
1440
|
+
fs$f.writeSync(fdw, _buff, 0, bytesRead);
|
|
1441
|
+
pos += bytesRead;
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1444
|
+
if (opts.preserveTimestamps) fs$f.futimesSync(fdw, srcStat.atime, srcStat.mtime);
|
|
1445
|
+
|
|
1446
|
+
fs$f.closeSync(fdr);
|
|
1447
|
+
fs$f.closeSync(fdw);
|
|
1448
|
+
}
|
|
1449
|
+
|
|
1450
|
+
function onDir$1 (srcStat, resolvedDest, src, dest, opts) {
|
|
1451
|
+
if (resolvedDest === notExist$1) {
|
|
1452
|
+
if (isSrcSubdir$3(src, dest)) {
|
|
1453
|
+
throw new Error(`Cannot copy '${src}' to a subdirectory of itself, '${dest}'.`)
|
|
1454
|
+
}
|
|
1455
|
+
return mkDirAndCopy$1(srcStat, src, dest, opts)
|
|
1456
|
+
} else if (resolvedDest === existsReg$1) {
|
|
1457
|
+
if (isSrcSubdir$3(src, dest)) {
|
|
1458
|
+
throw new Error(`Cannot copy '${src}' to a subdirectory of itself, '${dest}'.`)
|
|
1459
|
+
}
|
|
1460
|
+
return mayCopyDir$1(src, dest, opts)
|
|
1461
|
+
}
|
|
1462
|
+
return copyDir$1(src, dest, opts)
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
function mayCopyDir$1 (src, dest, opts) {
|
|
1466
|
+
if (!fs$f.statSync(dest).isDirectory()) {
|
|
1467
|
+
throw new Error(`Cannot overwrite non-directory '${dest}' with directory '${src}'.`)
|
|
1468
|
+
}
|
|
1469
|
+
return copyDir$1(src, dest, opts)
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
function mkDirAndCopy$1 (srcStat, src, dest, opts) {
|
|
1473
|
+
fs$f.mkdirSync(dest, srcStat.mode);
|
|
1474
|
+
fs$f.chmodSync(dest, srcStat.mode);
|
|
1475
|
+
return copyDir$1(src, dest, opts)
|
|
1476
|
+
}
|
|
1477
|
+
|
|
1478
|
+
function copyDir$1 (src, dest, opts) {
|
|
1479
|
+
fs$f.readdirSync(src).forEach(item => copyDirItem$1(item, src, dest, opts));
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
function copyDirItem$1 (item, src, dest, opts) {
|
|
1483
|
+
const srcItem = path$e.join(src, item);
|
|
1484
|
+
const destItem = path$e.join(dest, item);
|
|
1485
|
+
const resolvedDest = checkPaths$1(srcItem, destItem);
|
|
1486
|
+
return startCopy$1(resolvedDest, srcItem, destItem, opts)
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1489
|
+
function onLink$1 (resolvedDest, src, dest, opts) {
|
|
1490
|
+
let resolvedSrc = fs$f.readlinkSync(src);
|
|
1491
|
+
|
|
1492
|
+
if (opts.dereference) {
|
|
1493
|
+
resolvedSrc = path$e.resolve(process.cwd(), resolvedSrc);
|
|
1494
|
+
}
|
|
1495
|
+
|
|
1496
|
+
if (resolvedDest === notExist$1 || resolvedDest === existsReg$1) {
|
|
1497
|
+
// if dest already exists, fs throws error anyway,
|
|
1498
|
+
// so no need to guard against it here.
|
|
1499
|
+
return fs$f.symlinkSync(resolvedSrc, dest)
|
|
1500
|
+
} else {
|
|
1501
|
+
if (opts.dereference) {
|
|
1502
|
+
resolvedDest = path$e.resolve(process.cwd(), resolvedDest);
|
|
1503
|
+
}
|
|
1504
|
+
if (pathsAreIdentical$1(resolvedSrc, resolvedDest)) return
|
|
1505
|
+
|
|
1506
|
+
// prevent copy if src is a subdir of dest since unlinking
|
|
1507
|
+
// dest in this case would result in removing src contents
|
|
1508
|
+
// and therefore a broken symlink would be created.
|
|
1509
|
+
if (fs$f.statSync(dest).isDirectory() && isSrcSubdir$3(resolvedDest, resolvedSrc)) {
|
|
1510
|
+
throw new Error(`Cannot overwrite '${resolvedDest}' with '${resolvedSrc}'.`)
|
|
1511
|
+
}
|
|
1512
|
+
return copyLink$1(resolvedSrc, dest)
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
function copyLink$1 (resolvedSrc, dest) {
|
|
1517
|
+
fs$f.unlinkSync(dest);
|
|
1518
|
+
return fs$f.symlinkSync(resolvedSrc, dest)
|
|
1519
|
+
}
|
|
1520
|
+
|
|
1521
|
+
// return true if dest is a subdir of src, otherwise false.
|
|
1522
|
+
// extract dest base dir and check if that is the same as src basename.
|
|
1523
|
+
function isSrcSubdir$3 (src, dest) {
|
|
1524
|
+
const srcArray = path$e.resolve(src).split(path$e.sep);
|
|
1525
|
+
const destArray = path$e.resolve(dest).split(path$e.sep);
|
|
1526
|
+
|
|
1527
|
+
return srcArray.reduce((acc, current, i) => {
|
|
1528
|
+
return acc && destArray[i] === current
|
|
1529
|
+
}, true)
|
|
1530
|
+
}
|
|
1531
|
+
|
|
1532
|
+
// check if dest exists and is a symlink.
|
|
1533
|
+
function checkDest$1 (dest) {
|
|
1534
|
+
let resolvedPath;
|
|
1535
|
+
try {
|
|
1536
|
+
resolvedPath = fs$f.readlinkSync(dest);
|
|
1537
|
+
} catch (err) {
|
|
1538
|
+
if (err.code === 'ENOENT') return notExist$1
|
|
1539
|
+
|
|
1540
|
+
// dest exists and is a regular file or directory, Windows may throw UNKNOWN error.
|
|
1541
|
+
if (err.code === 'EINVAL' || err.code === 'UNKNOWN') return existsReg$1
|
|
1542
|
+
|
|
1543
|
+
throw err
|
|
1544
|
+
}
|
|
1545
|
+
return resolvedPath // dest exists and is a symlink
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1548
|
+
function pathsAreIdentical$1 (src, dest) {
|
|
1549
|
+
const os = process.platform;
|
|
1550
|
+
const resolvedSrc = path$e.resolve(src);
|
|
1551
|
+
const resolvedDest = path$e.resolve(dest);
|
|
1552
|
+
// case-insensitive paths
|
|
1553
|
+
if (os === 'darwin' || os === 'win32') {
|
|
1554
|
+
return resolvedSrc.toLowerCase() === resolvedDest.toLowerCase()
|
|
1555
|
+
}
|
|
1556
|
+
return resolvedSrc === resolvedDest
|
|
1557
|
+
}
|
|
1558
|
+
|
|
1559
|
+
function checkPaths$1 (src, dest) {
|
|
1560
|
+
const resolvedDest = checkDest$1(dest);
|
|
1561
|
+
if (resolvedDest === notExist$1 || resolvedDest === existsReg$1) {
|
|
1562
|
+
if (pathsAreIdentical$1(src, dest)) throw new Error('Source and destination must not be the same.')
|
|
1563
|
+
return resolvedDest
|
|
1564
|
+
} else {
|
|
1565
|
+
// check resolved dest path if dest is a symlink
|
|
1566
|
+
if (pathsAreIdentical$1(src, resolvedDest)) throw new Error('Source and destination must not be the same.')
|
|
1567
|
+
return resolvedDest
|
|
1568
|
+
}
|
|
1569
|
+
}
|
|
1570
|
+
|
|
1571
|
+
var copySync_1 = copySync$2;
|
|
1572
|
+
|
|
1573
|
+
var copySync$1 = {
|
|
1574
|
+
copySync: copySync_1
|
|
1575
|
+
};
|
|
1576
|
+
|
|
1577
|
+
const u$a = universalify.fromPromise;
|
|
1578
|
+
const fs$e = fs$k;
|
|
1579
|
+
|
|
1580
|
+
function pathExists$8 (path) {
|
|
1581
|
+
return fs$e.access(path).then(() => true).catch(() => false)
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
var pathExists_1 = {
|
|
1585
|
+
pathExists: u$a(pathExists$8),
|
|
1586
|
+
pathExistsSync: fs$e.existsSync
|
|
1587
|
+
};
|
|
1588
|
+
|
|
1589
|
+
const fs$d = gracefulFs;
|
|
1590
|
+
const path$d = path__default["default"];
|
|
1591
|
+
const mkdirp$1 = mkdirs_1.mkdirs;
|
|
1592
|
+
const pathExists$7 = pathExists_1.pathExists;
|
|
1593
|
+
const utimes = utimes$1.utimesMillis;
|
|
1594
|
+
|
|
1595
|
+
const notExist = Symbol('notExist');
|
|
1596
|
+
const existsReg = Symbol('existsReg');
|
|
1597
|
+
|
|
1598
|
+
function copy$2 (src, dest, opts, cb) {
|
|
1599
|
+
if (typeof opts === 'function' && !cb) {
|
|
1600
|
+
cb = opts;
|
|
1601
|
+
opts = {};
|
|
1602
|
+
} else if (typeof opts === 'function') {
|
|
1603
|
+
opts = {filter: opts};
|
|
1604
|
+
}
|
|
1605
|
+
|
|
1606
|
+
cb = cb || function () {};
|
|
1607
|
+
opts = opts || {};
|
|
1608
|
+
|
|
1609
|
+
opts.clobber = 'clobber' in opts ? !!opts.clobber : true; // default to true for now
|
|
1610
|
+
opts.overwrite = 'overwrite' in opts ? !!opts.overwrite : opts.clobber; // overwrite falls back to clobber
|
|
1611
|
+
|
|
1612
|
+
// Warn about using preserveTimestamps on 32-bit node
|
|
1613
|
+
if (opts.preserveTimestamps && process.arch === 'ia32') {
|
|
1614
|
+
console.warn(`fs-extra: Using the preserveTimestamps option in 32-bit node is not recommended;\n
|
|
1615
|
+
see https://github.com/jprichardson/node-fs-extra/issues/269`);
|
|
1616
|
+
}
|
|
1617
|
+
|
|
1618
|
+
checkPaths(src, dest, (err, resolvedDest) => {
|
|
1619
|
+
if (err) return cb(err)
|
|
1620
|
+
if (opts.filter) return handleFilter(checkParentDir, resolvedDest, src, dest, opts, cb)
|
|
1621
|
+
return checkParentDir(resolvedDest, src, dest, opts, cb)
|
|
1622
|
+
});
|
|
1623
|
+
}
|
|
1624
|
+
|
|
1625
|
+
function checkParentDir (resolvedDest, src, dest, opts, cb) {
|
|
1626
|
+
const destParent = path$d.dirname(dest);
|
|
1627
|
+
pathExists$7(destParent, (err, dirExists) => {
|
|
1628
|
+
if (err) return cb(err)
|
|
1629
|
+
if (dirExists) return startCopy(resolvedDest, src, dest, opts, cb)
|
|
1630
|
+
mkdirp$1(destParent, err => {
|
|
1631
|
+
if (err) return cb(err)
|
|
1632
|
+
return startCopy(resolvedDest, src, dest, opts, cb)
|
|
1633
|
+
});
|
|
1634
|
+
});
|
|
1635
|
+
}
|
|
1636
|
+
|
|
1637
|
+
function startCopy (resolvedDest, src, dest, opts, cb) {
|
|
1638
|
+
if (opts.filter) return handleFilter(getStats, resolvedDest, src, dest, opts, cb)
|
|
1639
|
+
return getStats(resolvedDest, src, dest, opts, cb)
|
|
1640
|
+
}
|
|
1641
|
+
|
|
1642
|
+
function handleFilter (onInclude, resolvedDest, src, dest, opts, cb) {
|
|
1643
|
+
Promise.resolve(opts.filter(src, dest)).then(include => {
|
|
1644
|
+
if (include) {
|
|
1645
|
+
if (resolvedDest) return onInclude(resolvedDest, src, dest, opts, cb)
|
|
1646
|
+
return onInclude(src, dest, opts, cb)
|
|
1647
|
+
}
|
|
1648
|
+
return cb()
|
|
1649
|
+
}, error => cb(error));
|
|
1650
|
+
}
|
|
1651
|
+
|
|
1652
|
+
function getStats (resolvedDest, src, dest, opts, cb) {
|
|
1653
|
+
const stat = opts.dereference ? fs$d.stat : fs$d.lstat;
|
|
1654
|
+
stat(src, (err, st) => {
|
|
1655
|
+
if (err) return cb(err)
|
|
1656
|
+
|
|
1657
|
+
if (st.isDirectory()) return onDir(st, resolvedDest, src, dest, opts, cb)
|
|
1658
|
+
else if (st.isFile() ||
|
|
1659
|
+
st.isCharacterDevice() ||
|
|
1660
|
+
st.isBlockDevice()) return onFile(st, resolvedDest, src, dest, opts, cb)
|
|
1661
|
+
else if (st.isSymbolicLink()) return onLink(resolvedDest, src, dest, opts, cb)
|
|
1662
|
+
});
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1665
|
+
function onFile (srcStat, resolvedDest, src, dest, opts, cb) {
|
|
1666
|
+
if (resolvedDest === notExist) return copyFile(srcStat, src, dest, opts, cb)
|
|
1667
|
+
else if (resolvedDest === existsReg) return mayCopyFile(srcStat, src, dest, opts, cb)
|
|
1668
|
+
return mayCopyFile(srcStat, src, dest, opts, cb)
|
|
1669
|
+
}
|
|
1670
|
+
|
|
1671
|
+
function mayCopyFile (srcStat, src, dest, opts, cb) {
|
|
1672
|
+
if (opts.overwrite) {
|
|
1673
|
+
fs$d.unlink(dest, err => {
|
|
1674
|
+
if (err) return cb(err)
|
|
1675
|
+
return copyFile(srcStat, src, dest, opts, cb)
|
|
1676
|
+
});
|
|
1677
|
+
} else if (opts.errorOnExist) {
|
|
1678
|
+
return cb(new Error(`'${dest}' already exists`))
|
|
1679
|
+
} else return cb()
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1682
|
+
function copyFile (srcStat, src, dest, opts, cb) {
|
|
1683
|
+
if (typeof fs$d.copyFile === 'function') {
|
|
1684
|
+
return fs$d.copyFile(src, dest, err => {
|
|
1685
|
+
if (err) return cb(err)
|
|
1686
|
+
return setDestModeAndTimestamps(srcStat, dest, opts, cb)
|
|
1687
|
+
})
|
|
1688
|
+
}
|
|
1689
|
+
return copyFileFallback(srcStat, src, dest, opts, cb)
|
|
1690
|
+
}
|
|
1691
|
+
|
|
1692
|
+
function copyFileFallback (srcStat, src, dest, opts, cb) {
|
|
1693
|
+
const rs = fs$d.createReadStream(src);
|
|
1694
|
+
rs.on('error', err => cb(err)).once('open', () => {
|
|
1695
|
+
const ws = fs$d.createWriteStream(dest, { mode: srcStat.mode });
|
|
1696
|
+
ws.on('error', err => cb(err))
|
|
1697
|
+
.on('open', () => rs.pipe(ws))
|
|
1698
|
+
.once('close', () => setDestModeAndTimestamps(srcStat, dest, opts, cb));
|
|
1699
|
+
});
|
|
1700
|
+
}
|
|
1701
|
+
|
|
1702
|
+
function setDestModeAndTimestamps (srcStat, dest, opts, cb) {
|
|
1703
|
+
fs$d.chmod(dest, srcStat.mode, err => {
|
|
1704
|
+
if (err) return cb(err)
|
|
1705
|
+
if (opts.preserveTimestamps) {
|
|
1706
|
+
return utimes(dest, srcStat.atime, srcStat.mtime, cb)
|
|
1707
|
+
}
|
|
1708
|
+
return cb()
|
|
1709
|
+
});
|
|
1710
|
+
}
|
|
1711
|
+
|
|
1712
|
+
function onDir (srcStat, resolvedDest, src, dest, opts, cb) {
|
|
1713
|
+
if (resolvedDest === notExist) {
|
|
1714
|
+
if (isSrcSubdir$2(src, dest)) {
|
|
1715
|
+
return cb(new Error(`Cannot copy '${src}' to a subdirectory of itself, '${dest}'.`))
|
|
1716
|
+
}
|
|
1717
|
+
return mkDirAndCopy(srcStat, src, dest, opts, cb)
|
|
1718
|
+
} else if (resolvedDest === existsReg) {
|
|
1719
|
+
if (isSrcSubdir$2(src, dest)) {
|
|
1720
|
+
return cb(new Error(`Cannot copy '${src}' to a subdirectory of itself, '${dest}'.`))
|
|
1721
|
+
}
|
|
1722
|
+
return mayCopyDir(src, dest, opts, cb)
|
|
1723
|
+
}
|
|
1724
|
+
return copyDir(src, dest, opts, cb)
|
|
1725
|
+
}
|
|
1726
|
+
|
|
1727
|
+
function mayCopyDir (src, dest, opts, cb) {
|
|
1728
|
+
fs$d.stat(dest, (err, st) => {
|
|
1729
|
+
if (err) return cb(err)
|
|
1730
|
+
if (!st.isDirectory()) {
|
|
1731
|
+
return cb(new Error(`Cannot overwrite non-directory '${dest}' with directory '${src}'.`))
|
|
1732
|
+
}
|
|
1733
|
+
return copyDir(src, dest, opts, cb)
|
|
1734
|
+
});
|
|
1735
|
+
}
|
|
1736
|
+
|
|
1737
|
+
function mkDirAndCopy (srcStat, src, dest, opts, cb) {
|
|
1738
|
+
fs$d.mkdir(dest, srcStat.mode, err => {
|
|
1739
|
+
if (err) return cb(err)
|
|
1740
|
+
fs$d.chmod(dest, srcStat.mode, err => {
|
|
1741
|
+
if (err) return cb(err)
|
|
1742
|
+
return copyDir(src, dest, opts, cb)
|
|
1743
|
+
});
|
|
1744
|
+
});
|
|
1745
|
+
}
|
|
1746
|
+
|
|
1747
|
+
function copyDir (src, dest, opts, cb) {
|
|
1748
|
+
fs$d.readdir(src, (err, items) => {
|
|
1749
|
+
if (err) return cb(err)
|
|
1750
|
+
return copyDirItems(items, src, dest, opts, cb)
|
|
1751
|
+
});
|
|
1752
|
+
}
|
|
1753
|
+
|
|
1754
|
+
function copyDirItems (items, src, dest, opts, cb) {
|
|
1755
|
+
const item = items.pop();
|
|
1756
|
+
if (!item) return cb()
|
|
1757
|
+
return copyDirItem(items, item, src, dest, opts, cb)
|
|
1758
|
+
}
|
|
1759
|
+
|
|
1760
|
+
function copyDirItem (items, item, src, dest, opts, cb) {
|
|
1761
|
+
const srcItem = path$d.join(src, item);
|
|
1762
|
+
const destItem = path$d.join(dest, item);
|
|
1763
|
+
checkPaths(srcItem, destItem, (err, resolvedDest) => {
|
|
1764
|
+
if (err) return cb(err)
|
|
1765
|
+
startCopy(resolvedDest, srcItem, destItem, opts, err => {
|
|
1766
|
+
if (err) return cb(err)
|
|
1767
|
+
return copyDirItems(items, src, dest, opts, cb)
|
|
1768
|
+
});
|
|
1769
|
+
});
|
|
1770
|
+
}
|
|
1771
|
+
|
|
1772
|
+
function onLink (resolvedDest, src, dest, opts, cb) {
|
|
1773
|
+
fs$d.readlink(src, (err, resolvedSrc) => {
|
|
1774
|
+
if (err) return cb(err)
|
|
1775
|
+
|
|
1776
|
+
if (opts.dereference) {
|
|
1777
|
+
resolvedSrc = path$d.resolve(process.cwd(), resolvedSrc);
|
|
1778
|
+
}
|
|
1779
|
+
|
|
1780
|
+
if (resolvedDest === notExist || resolvedDest === existsReg) {
|
|
1781
|
+
// if dest already exists, fs throws error anyway,
|
|
1782
|
+
// so no need to guard against it here.
|
|
1783
|
+
return fs$d.symlink(resolvedSrc, dest, cb)
|
|
1784
|
+
} else {
|
|
1785
|
+
if (opts.dereference) {
|
|
1786
|
+
resolvedDest = path$d.resolve(process.cwd(), resolvedDest);
|
|
1787
|
+
}
|
|
1788
|
+
if (pathsAreIdentical(resolvedSrc, resolvedDest)) return cb()
|
|
1789
|
+
|
|
1790
|
+
// prevent copy if src is a subdir of dest since unlinking
|
|
1791
|
+
// dest in this case would result in removing src contents
|
|
1792
|
+
// and therefore a broken symlink would be created.
|
|
1793
|
+
fs$d.stat(dest, (err, st) => {
|
|
1794
|
+
if (err) return cb(err)
|
|
1795
|
+
if (st.isDirectory() && isSrcSubdir$2(resolvedDest, resolvedSrc)) {
|
|
1796
|
+
return cb(new Error(`Cannot overwrite '${resolvedDest}' with '${resolvedSrc}'.`))
|
|
1797
|
+
}
|
|
1798
|
+
return copyLink(resolvedSrc, dest, cb)
|
|
1799
|
+
});
|
|
1800
|
+
}
|
|
1801
|
+
});
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1804
|
+
function copyLink (resolvedSrc, dest, cb) {
|
|
1805
|
+
fs$d.unlink(dest, err => {
|
|
1806
|
+
if (err) return cb(err)
|
|
1807
|
+
return fs$d.symlink(resolvedSrc, dest, cb)
|
|
1808
|
+
});
|
|
1809
|
+
}
|
|
1810
|
+
|
|
1811
|
+
// return true if dest is a subdir of src, otherwise false.
|
|
1812
|
+
// extract dest base dir and check if that is the same as src basename.
|
|
1813
|
+
function isSrcSubdir$2 (src, dest) {
|
|
1814
|
+
const srcArray = path$d.resolve(src).split(path$d.sep);
|
|
1815
|
+
const destArray = path$d.resolve(dest).split(path$d.sep);
|
|
1816
|
+
|
|
1817
|
+
return srcArray.reduce((acc, current, i) => {
|
|
1818
|
+
return acc && destArray[i] === current
|
|
1819
|
+
}, true)
|
|
1820
|
+
}
|
|
1821
|
+
|
|
1822
|
+
// check if dest exists and is a symlink.
|
|
1823
|
+
function checkDest (dest, cb) {
|
|
1824
|
+
fs$d.readlink(dest, (err, resolvedPath) => {
|
|
1825
|
+
if (err) {
|
|
1826
|
+
if (err.code === 'ENOENT') return cb(null, notExist)
|
|
1827
|
+
|
|
1828
|
+
// dest exists and is a regular file or directory, Windows may throw UNKNOWN error.
|
|
1829
|
+
if (err.code === 'EINVAL' || err.code === 'UNKNOWN') return cb(null, existsReg)
|
|
1830
|
+
|
|
1831
|
+
return cb(err)
|
|
1832
|
+
}
|
|
1833
|
+
return cb(null, resolvedPath) // dest exists and is a symlink
|
|
1834
|
+
});
|
|
1835
|
+
}
|
|
1836
|
+
|
|
1837
|
+
function pathsAreIdentical (src, dest) {
|
|
1838
|
+
const os = process.platform;
|
|
1839
|
+
const resolvedSrc = path$d.resolve(src);
|
|
1840
|
+
const resolvedDest = path$d.resolve(dest);
|
|
1841
|
+
// case-insensitive paths
|
|
1842
|
+
if (os === 'darwin' || os === 'win32') {
|
|
1843
|
+
return resolvedSrc.toLowerCase() === resolvedDest.toLowerCase()
|
|
1844
|
+
}
|
|
1845
|
+
return resolvedSrc === resolvedDest
|
|
1846
|
+
}
|
|
1847
|
+
|
|
1848
|
+
function checkPaths (src, dest, cb) {
|
|
1849
|
+
checkDest(dest, (err, resolvedDest) => {
|
|
1850
|
+
if (err) return cb(err)
|
|
1851
|
+
if (resolvedDest === notExist || resolvedDest === existsReg) {
|
|
1852
|
+
if (pathsAreIdentical(src, dest)) return cb(new Error('Source and destination must not be the same.'))
|
|
1853
|
+
return cb(null, resolvedDest)
|
|
1854
|
+
} else {
|
|
1855
|
+
// check resolved dest path if dest is a symlink
|
|
1856
|
+
if (pathsAreIdentical(src, resolvedDest)) return cb(new Error('Source and destination must not be the same.'))
|
|
1857
|
+
return cb(null, resolvedDest)
|
|
1858
|
+
}
|
|
1859
|
+
});
|
|
1860
|
+
}
|
|
1861
|
+
|
|
1862
|
+
var copy_1 = copy$2;
|
|
1863
|
+
|
|
1864
|
+
const u$9 = universalify.fromCallback;
|
|
1865
|
+
var copy$1 = {
|
|
1866
|
+
copy: u$9(copy_1)
|
|
1867
|
+
};
|
|
1868
|
+
|
|
1869
|
+
const fs$c = gracefulFs;
|
|
1870
|
+
const path$c = path__default["default"];
|
|
1871
|
+
const assert = assert__default["default"];
|
|
1872
|
+
|
|
1873
|
+
const isWindows = (process.platform === 'win32');
|
|
1874
|
+
|
|
1875
|
+
function defaults (options) {
|
|
1876
|
+
const methods = [
|
|
1877
|
+
'unlink',
|
|
1878
|
+
'chmod',
|
|
1879
|
+
'stat',
|
|
1880
|
+
'lstat',
|
|
1881
|
+
'rmdir',
|
|
1882
|
+
'readdir'
|
|
1883
|
+
];
|
|
1884
|
+
methods.forEach(m => {
|
|
1885
|
+
options[m] = options[m] || fs$c[m];
|
|
1886
|
+
m = m + 'Sync';
|
|
1887
|
+
options[m] = options[m] || fs$c[m];
|
|
1888
|
+
});
|
|
1889
|
+
|
|
1890
|
+
options.maxBusyTries = options.maxBusyTries || 3;
|
|
1891
|
+
}
|
|
1892
|
+
|
|
1893
|
+
function rimraf$1 (p, options, cb) {
|
|
1894
|
+
let busyTries = 0;
|
|
1895
|
+
|
|
1896
|
+
if (typeof options === 'function') {
|
|
1897
|
+
cb = options;
|
|
1898
|
+
options = {};
|
|
1899
|
+
}
|
|
1900
|
+
|
|
1901
|
+
assert(p, 'rimraf: missing path');
|
|
1902
|
+
assert.strictEqual(typeof p, 'string', 'rimraf: path should be a string');
|
|
1903
|
+
assert.strictEqual(typeof cb, 'function', 'rimraf: callback function required');
|
|
1904
|
+
assert(options, 'rimraf: invalid options argument provided');
|
|
1905
|
+
assert.strictEqual(typeof options, 'object', 'rimraf: options should be object');
|
|
1906
|
+
|
|
1907
|
+
defaults(options);
|
|
1908
|
+
|
|
1909
|
+
rimraf_(p, options, function CB (er) {
|
|
1910
|
+
if (er) {
|
|
1911
|
+
if ((er.code === 'EBUSY' || er.code === 'ENOTEMPTY' || er.code === 'EPERM') &&
|
|
1912
|
+
busyTries < options.maxBusyTries) {
|
|
1913
|
+
busyTries++;
|
|
1914
|
+
const time = busyTries * 100;
|
|
1915
|
+
// try again, with the same exact callback as this one.
|
|
1916
|
+
return setTimeout(() => rimraf_(p, options, CB), time)
|
|
1917
|
+
}
|
|
1918
|
+
|
|
1919
|
+
// already gone
|
|
1920
|
+
if (er.code === 'ENOENT') er = null;
|
|
1921
|
+
}
|
|
1922
|
+
|
|
1923
|
+
cb(er);
|
|
1924
|
+
});
|
|
1925
|
+
}
|
|
1926
|
+
|
|
1927
|
+
// Two possible strategies.
|
|
1928
|
+
// 1. Assume it's a file. unlink it, then do the dir stuff on EPERM or EISDIR
|
|
1929
|
+
// 2. Assume it's a directory. readdir, then do the file stuff on ENOTDIR
|
|
1930
|
+
//
|
|
1931
|
+
// Both result in an extra syscall when you guess wrong. However, there
|
|
1932
|
+
// are likely far more normal files in the world than directories. This
|
|
1933
|
+
// is based on the assumption that a the average number of files per
|
|
1934
|
+
// directory is >= 1.
|
|
1935
|
+
//
|
|
1936
|
+
// If anyone ever complains about this, then I guess the strategy could
|
|
1937
|
+
// be made configurable somehow. But until then, YAGNI.
|
|
1938
|
+
function rimraf_ (p, options, cb) {
|
|
1939
|
+
assert(p);
|
|
1940
|
+
assert(options);
|
|
1941
|
+
assert(typeof cb === 'function');
|
|
1942
|
+
|
|
1943
|
+
// sunos lets the root user unlink directories, which is... weird.
|
|
1944
|
+
// so we have to lstat here and make sure it's not a dir.
|
|
1945
|
+
options.lstat(p, (er, st) => {
|
|
1946
|
+
if (er && er.code === 'ENOENT') {
|
|
1947
|
+
return cb(null)
|
|
1948
|
+
}
|
|
1949
|
+
|
|
1950
|
+
// Windows can EPERM on stat. Life is suffering.
|
|
1951
|
+
if (er && er.code === 'EPERM' && isWindows) {
|
|
1952
|
+
return fixWinEPERM(p, options, er, cb)
|
|
1953
|
+
}
|
|
1954
|
+
|
|
1955
|
+
if (st && st.isDirectory()) {
|
|
1956
|
+
return rmdir(p, options, er, cb)
|
|
1957
|
+
}
|
|
1958
|
+
|
|
1959
|
+
options.unlink(p, er => {
|
|
1960
|
+
if (er) {
|
|
1961
|
+
if (er.code === 'ENOENT') {
|
|
1962
|
+
return cb(null)
|
|
1963
|
+
}
|
|
1964
|
+
if (er.code === 'EPERM') {
|
|
1965
|
+
return (isWindows)
|
|
1966
|
+
? fixWinEPERM(p, options, er, cb)
|
|
1967
|
+
: rmdir(p, options, er, cb)
|
|
1968
|
+
}
|
|
1969
|
+
if (er.code === 'EISDIR') {
|
|
1970
|
+
return rmdir(p, options, er, cb)
|
|
1971
|
+
}
|
|
1972
|
+
}
|
|
1973
|
+
return cb(er)
|
|
1974
|
+
});
|
|
1975
|
+
});
|
|
1976
|
+
}
|
|
1977
|
+
|
|
1978
|
+
function fixWinEPERM (p, options, er, cb) {
|
|
1979
|
+
assert(p);
|
|
1980
|
+
assert(options);
|
|
1981
|
+
assert(typeof cb === 'function');
|
|
1982
|
+
if (er) {
|
|
1983
|
+
assert(er instanceof Error);
|
|
1984
|
+
}
|
|
1985
|
+
|
|
1986
|
+
options.chmod(p, 0o666, er2 => {
|
|
1987
|
+
if (er2) {
|
|
1988
|
+
cb(er2.code === 'ENOENT' ? null : er);
|
|
1989
|
+
} else {
|
|
1990
|
+
options.stat(p, (er3, stats) => {
|
|
1991
|
+
if (er3) {
|
|
1992
|
+
cb(er3.code === 'ENOENT' ? null : er);
|
|
1993
|
+
} else if (stats.isDirectory()) {
|
|
1994
|
+
rmdir(p, options, er, cb);
|
|
1995
|
+
} else {
|
|
1996
|
+
options.unlink(p, cb);
|
|
1997
|
+
}
|
|
1998
|
+
});
|
|
1999
|
+
}
|
|
2000
|
+
});
|
|
2001
|
+
}
|
|
2002
|
+
|
|
2003
|
+
function fixWinEPERMSync (p, options, er) {
|
|
2004
|
+
let stats;
|
|
2005
|
+
|
|
2006
|
+
assert(p);
|
|
2007
|
+
assert(options);
|
|
2008
|
+
if (er) {
|
|
2009
|
+
assert(er instanceof Error);
|
|
2010
|
+
}
|
|
2011
|
+
|
|
2012
|
+
try {
|
|
2013
|
+
options.chmodSync(p, 0o666);
|
|
2014
|
+
} catch (er2) {
|
|
2015
|
+
if (er2.code === 'ENOENT') {
|
|
2016
|
+
return
|
|
2017
|
+
} else {
|
|
2018
|
+
throw er
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
|
|
2022
|
+
try {
|
|
2023
|
+
stats = options.statSync(p);
|
|
2024
|
+
} catch (er3) {
|
|
2025
|
+
if (er3.code === 'ENOENT') {
|
|
2026
|
+
return
|
|
2027
|
+
} else {
|
|
2028
|
+
throw er
|
|
2029
|
+
}
|
|
2030
|
+
}
|
|
2031
|
+
|
|
2032
|
+
if (stats.isDirectory()) {
|
|
2033
|
+
rmdirSync(p, options, er);
|
|
2034
|
+
} else {
|
|
2035
|
+
options.unlinkSync(p);
|
|
2036
|
+
}
|
|
2037
|
+
}
|
|
2038
|
+
|
|
2039
|
+
function rmdir (p, options, originalEr, cb) {
|
|
2040
|
+
assert(p);
|
|
2041
|
+
assert(options);
|
|
2042
|
+
if (originalEr) {
|
|
2043
|
+
assert(originalEr instanceof Error);
|
|
2044
|
+
}
|
|
2045
|
+
assert(typeof cb === 'function');
|
|
2046
|
+
|
|
2047
|
+
// try to rmdir first, and only readdir on ENOTEMPTY or EEXIST (SunOS)
|
|
2048
|
+
// if we guessed wrong, and it's not a directory, then
|
|
2049
|
+
// raise the original error.
|
|
2050
|
+
options.rmdir(p, er => {
|
|
2051
|
+
if (er && (er.code === 'ENOTEMPTY' || er.code === 'EEXIST' || er.code === 'EPERM')) {
|
|
2052
|
+
rmkids(p, options, cb);
|
|
2053
|
+
} else if (er && er.code === 'ENOTDIR') {
|
|
2054
|
+
cb(originalEr);
|
|
2055
|
+
} else {
|
|
2056
|
+
cb(er);
|
|
2057
|
+
}
|
|
2058
|
+
});
|
|
2059
|
+
}
|
|
2060
|
+
|
|
2061
|
+
function rmkids (p, options, cb) {
|
|
2062
|
+
assert(p);
|
|
2063
|
+
assert(options);
|
|
2064
|
+
assert(typeof cb === 'function');
|
|
2065
|
+
|
|
2066
|
+
options.readdir(p, (er, files) => {
|
|
2067
|
+
if (er) return cb(er)
|
|
2068
|
+
|
|
2069
|
+
let n = files.length;
|
|
2070
|
+
let errState;
|
|
2071
|
+
|
|
2072
|
+
if (n === 0) return options.rmdir(p, cb)
|
|
2073
|
+
|
|
2074
|
+
files.forEach(f => {
|
|
2075
|
+
rimraf$1(path$c.join(p, f), options, er => {
|
|
2076
|
+
if (errState) {
|
|
2077
|
+
return
|
|
2078
|
+
}
|
|
2079
|
+
if (er) return cb(errState = er)
|
|
2080
|
+
if (--n === 0) {
|
|
2081
|
+
options.rmdir(p, cb);
|
|
2082
|
+
}
|
|
2083
|
+
});
|
|
2084
|
+
});
|
|
2085
|
+
});
|
|
2086
|
+
}
|
|
2087
|
+
|
|
2088
|
+
// this looks simpler, and is strictly *faster*, but will
|
|
2089
|
+
// tie up the JavaScript thread and fail on excessively
|
|
2090
|
+
// deep directory trees.
|
|
2091
|
+
function rimrafSync (p, options) {
|
|
2092
|
+
let st;
|
|
2093
|
+
|
|
2094
|
+
options = options || {};
|
|
2095
|
+
defaults(options);
|
|
2096
|
+
|
|
2097
|
+
assert(p, 'rimraf: missing path');
|
|
2098
|
+
assert.strictEqual(typeof p, 'string', 'rimraf: path should be a string');
|
|
2099
|
+
assert(options, 'rimraf: missing options');
|
|
2100
|
+
assert.strictEqual(typeof options, 'object', 'rimraf: options should be object');
|
|
2101
|
+
|
|
2102
|
+
try {
|
|
2103
|
+
st = options.lstatSync(p);
|
|
2104
|
+
} catch (er) {
|
|
2105
|
+
if (er.code === 'ENOENT') {
|
|
2106
|
+
return
|
|
2107
|
+
}
|
|
2108
|
+
|
|
2109
|
+
// Windows can EPERM on stat. Life is suffering.
|
|
2110
|
+
if (er.code === 'EPERM' && isWindows) {
|
|
2111
|
+
fixWinEPERMSync(p, options, er);
|
|
2112
|
+
}
|
|
2113
|
+
}
|
|
2114
|
+
|
|
2115
|
+
try {
|
|
2116
|
+
// sunos lets the root user unlink directories, which is... weird.
|
|
2117
|
+
if (st && st.isDirectory()) {
|
|
2118
|
+
rmdirSync(p, options, null);
|
|
2119
|
+
} else {
|
|
2120
|
+
options.unlinkSync(p);
|
|
2121
|
+
}
|
|
2122
|
+
} catch (er) {
|
|
2123
|
+
if (er.code === 'ENOENT') {
|
|
2124
|
+
return
|
|
2125
|
+
} else if (er.code === 'EPERM') {
|
|
2126
|
+
return isWindows ? fixWinEPERMSync(p, options, er) : rmdirSync(p, options, er)
|
|
2127
|
+
} else if (er.code !== 'EISDIR') {
|
|
2128
|
+
throw er
|
|
2129
|
+
}
|
|
2130
|
+
rmdirSync(p, options, er);
|
|
2131
|
+
}
|
|
2132
|
+
}
|
|
2133
|
+
|
|
2134
|
+
function rmdirSync (p, options, originalEr) {
|
|
2135
|
+
assert(p);
|
|
2136
|
+
assert(options);
|
|
2137
|
+
if (originalEr) {
|
|
2138
|
+
assert(originalEr instanceof Error);
|
|
2139
|
+
}
|
|
2140
|
+
|
|
2141
|
+
try {
|
|
2142
|
+
options.rmdirSync(p);
|
|
2143
|
+
} catch (er) {
|
|
2144
|
+
if (er.code === 'ENOTDIR') {
|
|
2145
|
+
throw originalEr
|
|
2146
|
+
} else if (er.code === 'ENOTEMPTY' || er.code === 'EEXIST' || er.code === 'EPERM') {
|
|
2147
|
+
rmkidsSync(p, options);
|
|
2148
|
+
} else if (er.code !== 'ENOENT') {
|
|
2149
|
+
throw er
|
|
2150
|
+
}
|
|
2151
|
+
}
|
|
2152
|
+
}
|
|
2153
|
+
|
|
2154
|
+
function rmkidsSync (p, options) {
|
|
2155
|
+
assert(p);
|
|
2156
|
+
assert(options);
|
|
2157
|
+
options.readdirSync(p).forEach(f => rimrafSync(path$c.join(p, f), options));
|
|
2158
|
+
|
|
2159
|
+
// We only end up here once we got ENOTEMPTY at least once, and
|
|
2160
|
+
// at this point, we are guaranteed to have removed all the kids.
|
|
2161
|
+
// So, we know that it won't be ENOENT or ENOTDIR or anything else.
|
|
2162
|
+
// try really hard to delete stuff on windows, because it has a
|
|
2163
|
+
// PROFOUNDLY annoying habit of not closing handles promptly when
|
|
2164
|
+
// files are deleted, resulting in spurious ENOTEMPTY errors.
|
|
2165
|
+
const retries = isWindows ? 100 : 1;
|
|
2166
|
+
let i = 0;
|
|
2167
|
+
do {
|
|
2168
|
+
let threw = true;
|
|
2169
|
+
try {
|
|
2170
|
+
const ret = options.rmdirSync(p, options);
|
|
2171
|
+
threw = false;
|
|
2172
|
+
return ret
|
|
2173
|
+
} finally {
|
|
2174
|
+
if (++i < retries && threw) continue // eslint-disable-line
|
|
2175
|
+
}
|
|
2176
|
+
} while (true)
|
|
2177
|
+
}
|
|
2178
|
+
|
|
2179
|
+
var rimraf_1 = rimraf$1;
|
|
2180
|
+
rimraf$1.sync = rimrafSync;
|
|
2181
|
+
|
|
2182
|
+
const u$8 = universalify.fromCallback;
|
|
2183
|
+
const rimraf = rimraf_1;
|
|
2184
|
+
|
|
2185
|
+
var remove$2 = {
|
|
2186
|
+
remove: u$8(rimraf),
|
|
2187
|
+
removeSync: rimraf.sync
|
|
2188
|
+
};
|
|
2189
|
+
|
|
2190
|
+
const u$7 = universalify.fromCallback;
|
|
2191
|
+
const fs$b = require$$1__default["default"];
|
|
2192
|
+
const path$b = path__default["default"];
|
|
2193
|
+
const mkdir$5 = mkdirs_1;
|
|
2194
|
+
const remove$1 = remove$2;
|
|
2195
|
+
|
|
2196
|
+
const emptyDir = u$7(function emptyDir (dir, callback) {
|
|
2197
|
+
callback = callback || function () {};
|
|
2198
|
+
fs$b.readdir(dir, (err, items) => {
|
|
2199
|
+
if (err) return mkdir$5.mkdirs(dir, callback)
|
|
2200
|
+
|
|
2201
|
+
items = items.map(item => path$b.join(dir, item));
|
|
2202
|
+
|
|
2203
|
+
deleteItem();
|
|
2204
|
+
|
|
2205
|
+
function deleteItem () {
|
|
2206
|
+
const item = items.pop();
|
|
2207
|
+
if (!item) return callback()
|
|
2208
|
+
remove$1.remove(item, err => {
|
|
2209
|
+
if (err) return callback(err)
|
|
2210
|
+
deleteItem();
|
|
2211
|
+
});
|
|
2212
|
+
}
|
|
2213
|
+
});
|
|
2214
|
+
});
|
|
2215
|
+
|
|
2216
|
+
function emptyDirSync (dir) {
|
|
2217
|
+
let items;
|
|
2218
|
+
try {
|
|
2219
|
+
items = fs$b.readdirSync(dir);
|
|
2220
|
+
} catch (err) {
|
|
2221
|
+
return mkdir$5.mkdirsSync(dir)
|
|
2222
|
+
}
|
|
2223
|
+
|
|
2224
|
+
items.forEach(item => {
|
|
2225
|
+
item = path$b.join(dir, item);
|
|
2226
|
+
remove$1.removeSync(item);
|
|
2227
|
+
});
|
|
2228
|
+
}
|
|
2229
|
+
|
|
2230
|
+
var empty = {
|
|
2231
|
+
emptyDirSync,
|
|
2232
|
+
emptydirSync: emptyDirSync,
|
|
2233
|
+
emptyDir,
|
|
2234
|
+
emptydir: emptyDir
|
|
2235
|
+
};
|
|
2236
|
+
|
|
2237
|
+
const u$6 = universalify.fromCallback;
|
|
2238
|
+
const path$a = path__default["default"];
|
|
2239
|
+
const fs$a = gracefulFs;
|
|
2240
|
+
const mkdir$4 = mkdirs_1;
|
|
2241
|
+
const pathExists$6 = pathExists_1.pathExists;
|
|
2242
|
+
|
|
2243
|
+
function createFile (file, callback) {
|
|
2244
|
+
function makeFile () {
|
|
2245
|
+
fs$a.writeFile(file, '', err => {
|
|
2246
|
+
if (err) return callback(err)
|
|
2247
|
+
callback();
|
|
2248
|
+
});
|
|
2249
|
+
}
|
|
2250
|
+
|
|
2251
|
+
fs$a.stat(file, (err, stats) => { // eslint-disable-line handle-callback-err
|
|
2252
|
+
if (!err && stats.isFile()) return callback()
|
|
2253
|
+
const dir = path$a.dirname(file);
|
|
2254
|
+
pathExists$6(dir, (err, dirExists) => {
|
|
2255
|
+
if (err) return callback(err)
|
|
2256
|
+
if (dirExists) return makeFile()
|
|
2257
|
+
mkdir$4.mkdirs(dir, err => {
|
|
2258
|
+
if (err) return callback(err)
|
|
2259
|
+
makeFile();
|
|
2260
|
+
});
|
|
2261
|
+
});
|
|
2262
|
+
});
|
|
2263
|
+
}
|
|
2264
|
+
|
|
2265
|
+
function createFileSync (file) {
|
|
2266
|
+
let stats;
|
|
2267
|
+
try {
|
|
2268
|
+
stats = fs$a.statSync(file);
|
|
2269
|
+
} catch (e) {}
|
|
2270
|
+
if (stats && stats.isFile()) return
|
|
2271
|
+
|
|
2272
|
+
const dir = path$a.dirname(file);
|
|
2273
|
+
if (!fs$a.existsSync(dir)) {
|
|
2274
|
+
mkdir$4.mkdirsSync(dir);
|
|
2275
|
+
}
|
|
2276
|
+
|
|
2277
|
+
fs$a.writeFileSync(file, '');
|
|
2278
|
+
}
|
|
2279
|
+
|
|
2280
|
+
var file$1 = {
|
|
2281
|
+
createFile: u$6(createFile),
|
|
2282
|
+
createFileSync
|
|
2283
|
+
};
|
|
2284
|
+
|
|
2285
|
+
const u$5 = universalify.fromCallback;
|
|
2286
|
+
const path$9 = path__default["default"];
|
|
2287
|
+
const fs$9 = gracefulFs;
|
|
2288
|
+
const mkdir$3 = mkdirs_1;
|
|
2289
|
+
const pathExists$5 = pathExists_1.pathExists;
|
|
2290
|
+
|
|
2291
|
+
function createLink (srcpath, dstpath, callback) {
|
|
2292
|
+
function makeLink (srcpath, dstpath) {
|
|
2293
|
+
fs$9.link(srcpath, dstpath, err => {
|
|
2294
|
+
if (err) return callback(err)
|
|
2295
|
+
callback(null);
|
|
2296
|
+
});
|
|
2297
|
+
}
|
|
2298
|
+
|
|
2299
|
+
pathExists$5(dstpath, (err, destinationExists) => {
|
|
2300
|
+
if (err) return callback(err)
|
|
2301
|
+
if (destinationExists) return callback(null)
|
|
2302
|
+
fs$9.lstat(srcpath, (err) => {
|
|
2303
|
+
if (err) {
|
|
2304
|
+
err.message = err.message.replace('lstat', 'ensureLink');
|
|
2305
|
+
return callback(err)
|
|
2306
|
+
}
|
|
2307
|
+
|
|
2308
|
+
const dir = path$9.dirname(dstpath);
|
|
2309
|
+
pathExists$5(dir, (err, dirExists) => {
|
|
2310
|
+
if (err) return callback(err)
|
|
2311
|
+
if (dirExists) return makeLink(srcpath, dstpath)
|
|
2312
|
+
mkdir$3.mkdirs(dir, err => {
|
|
2313
|
+
if (err) return callback(err)
|
|
2314
|
+
makeLink(srcpath, dstpath);
|
|
2315
|
+
});
|
|
2316
|
+
});
|
|
2317
|
+
});
|
|
2318
|
+
});
|
|
2319
|
+
}
|
|
2320
|
+
|
|
2321
|
+
function createLinkSync (srcpath, dstpath) {
|
|
2322
|
+
const destinationExists = fs$9.existsSync(dstpath);
|
|
2323
|
+
if (destinationExists) return undefined
|
|
2324
|
+
|
|
2325
|
+
try {
|
|
2326
|
+
fs$9.lstatSync(srcpath);
|
|
2327
|
+
} catch (err) {
|
|
2328
|
+
err.message = err.message.replace('lstat', 'ensureLink');
|
|
2329
|
+
throw err
|
|
2330
|
+
}
|
|
2331
|
+
|
|
2332
|
+
const dir = path$9.dirname(dstpath);
|
|
2333
|
+
const dirExists = fs$9.existsSync(dir);
|
|
2334
|
+
if (dirExists) return fs$9.linkSync(srcpath, dstpath)
|
|
2335
|
+
mkdir$3.mkdirsSync(dir);
|
|
2336
|
+
|
|
2337
|
+
return fs$9.linkSync(srcpath, dstpath)
|
|
2338
|
+
}
|
|
2339
|
+
|
|
2340
|
+
var link$1 = {
|
|
2341
|
+
createLink: u$5(createLink),
|
|
2342
|
+
createLinkSync
|
|
2343
|
+
};
|
|
2344
|
+
|
|
2345
|
+
const path$8 = path__default["default"];
|
|
2346
|
+
const fs$8 = gracefulFs;
|
|
2347
|
+
const pathExists$4 = pathExists_1.pathExists;
|
|
2348
|
+
|
|
2349
|
+
/**
|
|
2350
|
+
* Function that returns two types of paths, one relative to symlink, and one
|
|
2351
|
+
* relative to the current working directory. Checks if path is absolute or
|
|
2352
|
+
* relative. If the path is relative, this function checks if the path is
|
|
2353
|
+
* relative to symlink or relative to current working directory. This is an
|
|
2354
|
+
* initiative to find a smarter `srcpath` to supply when building symlinks.
|
|
2355
|
+
* This allows you to determine which path to use out of one of three possible
|
|
2356
|
+
* types of source paths. The first is an absolute path. This is detected by
|
|
2357
|
+
* `path.isAbsolute()`. When an absolute path is provided, it is checked to
|
|
2358
|
+
* see if it exists. If it does it's used, if not an error is returned
|
|
2359
|
+
* (callback)/ thrown (sync). The other two options for `srcpath` are a
|
|
2360
|
+
* relative url. By default Node's `fs.symlink` works by creating a symlink
|
|
2361
|
+
* using `dstpath` and expects the `srcpath` to be relative to the newly
|
|
2362
|
+
* created symlink. If you provide a `srcpath` that does not exist on the file
|
|
2363
|
+
* system it results in a broken symlink. To minimize this, the function
|
|
2364
|
+
* checks to see if the 'relative to symlink' source file exists, and if it
|
|
2365
|
+
* does it will use it. If it does not, it checks if there's a file that
|
|
2366
|
+
* exists that is relative to the current working directory, if does its used.
|
|
2367
|
+
* This preserves the expectations of the original fs.symlink spec and adds
|
|
2368
|
+
* the ability to pass in `relative to current working direcotry` paths.
|
|
2369
|
+
*/
|
|
2370
|
+
|
|
2371
|
+
function symlinkPaths$1 (srcpath, dstpath, callback) {
|
|
2372
|
+
if (path$8.isAbsolute(srcpath)) {
|
|
2373
|
+
return fs$8.lstat(srcpath, (err) => {
|
|
2374
|
+
if (err) {
|
|
2375
|
+
err.message = err.message.replace('lstat', 'ensureSymlink');
|
|
2376
|
+
return callback(err)
|
|
2377
|
+
}
|
|
2378
|
+
return callback(null, {
|
|
2379
|
+
'toCwd': srcpath,
|
|
2380
|
+
'toDst': srcpath
|
|
2381
|
+
})
|
|
2382
|
+
})
|
|
2383
|
+
} else {
|
|
2384
|
+
const dstdir = path$8.dirname(dstpath);
|
|
2385
|
+
const relativeToDst = path$8.join(dstdir, srcpath);
|
|
2386
|
+
return pathExists$4(relativeToDst, (err, exists) => {
|
|
2387
|
+
if (err) return callback(err)
|
|
2388
|
+
if (exists) {
|
|
2389
|
+
return callback(null, {
|
|
2390
|
+
'toCwd': relativeToDst,
|
|
2391
|
+
'toDst': srcpath
|
|
2392
|
+
})
|
|
2393
|
+
} else {
|
|
2394
|
+
return fs$8.lstat(srcpath, (err) => {
|
|
2395
|
+
if (err) {
|
|
2396
|
+
err.message = err.message.replace('lstat', 'ensureSymlink');
|
|
2397
|
+
return callback(err)
|
|
2398
|
+
}
|
|
2399
|
+
return callback(null, {
|
|
2400
|
+
'toCwd': srcpath,
|
|
2401
|
+
'toDst': path$8.relative(dstdir, srcpath)
|
|
2402
|
+
})
|
|
2403
|
+
})
|
|
2404
|
+
}
|
|
2405
|
+
})
|
|
2406
|
+
}
|
|
2407
|
+
}
|
|
2408
|
+
|
|
2409
|
+
function symlinkPathsSync$1 (srcpath, dstpath) {
|
|
2410
|
+
let exists;
|
|
2411
|
+
if (path$8.isAbsolute(srcpath)) {
|
|
2412
|
+
exists = fs$8.existsSync(srcpath);
|
|
2413
|
+
if (!exists) throw new Error('absolute srcpath does not exist')
|
|
2414
|
+
return {
|
|
2415
|
+
'toCwd': srcpath,
|
|
2416
|
+
'toDst': srcpath
|
|
2417
|
+
}
|
|
2418
|
+
} else {
|
|
2419
|
+
const dstdir = path$8.dirname(dstpath);
|
|
2420
|
+
const relativeToDst = path$8.join(dstdir, srcpath);
|
|
2421
|
+
exists = fs$8.existsSync(relativeToDst);
|
|
2422
|
+
if (exists) {
|
|
2423
|
+
return {
|
|
2424
|
+
'toCwd': relativeToDst,
|
|
2425
|
+
'toDst': srcpath
|
|
2426
|
+
}
|
|
2427
|
+
} else {
|
|
2428
|
+
exists = fs$8.existsSync(srcpath);
|
|
2429
|
+
if (!exists) throw new Error('relative srcpath does not exist')
|
|
2430
|
+
return {
|
|
2431
|
+
'toCwd': srcpath,
|
|
2432
|
+
'toDst': path$8.relative(dstdir, srcpath)
|
|
2433
|
+
}
|
|
2434
|
+
}
|
|
2435
|
+
}
|
|
2436
|
+
}
|
|
2437
|
+
|
|
2438
|
+
var symlinkPaths_1 = {
|
|
2439
|
+
symlinkPaths: symlinkPaths$1,
|
|
2440
|
+
symlinkPathsSync: symlinkPathsSync$1
|
|
2441
|
+
};
|
|
2442
|
+
|
|
2443
|
+
const fs$7 = gracefulFs;
|
|
2444
|
+
|
|
2445
|
+
function symlinkType$1 (srcpath, type, callback) {
|
|
2446
|
+
callback = (typeof type === 'function') ? type : callback;
|
|
2447
|
+
type = (typeof type === 'function') ? false : type;
|
|
2448
|
+
if (type) return callback(null, type)
|
|
2449
|
+
fs$7.lstat(srcpath, (err, stats) => {
|
|
2450
|
+
if (err) return callback(null, 'file')
|
|
2451
|
+
type = (stats && stats.isDirectory()) ? 'dir' : 'file';
|
|
2452
|
+
callback(null, type);
|
|
2453
|
+
});
|
|
2454
|
+
}
|
|
2455
|
+
|
|
2456
|
+
function symlinkTypeSync$1 (srcpath, type) {
|
|
2457
|
+
let stats;
|
|
2458
|
+
|
|
2459
|
+
if (type) return type
|
|
2460
|
+
try {
|
|
2461
|
+
stats = fs$7.lstatSync(srcpath);
|
|
2462
|
+
} catch (e) {
|
|
2463
|
+
return 'file'
|
|
2464
|
+
}
|
|
2465
|
+
return (stats && stats.isDirectory()) ? 'dir' : 'file'
|
|
2466
|
+
}
|
|
2467
|
+
|
|
2468
|
+
var symlinkType_1 = {
|
|
2469
|
+
symlinkType: symlinkType$1,
|
|
2470
|
+
symlinkTypeSync: symlinkTypeSync$1
|
|
2471
|
+
};
|
|
2472
|
+
|
|
2473
|
+
const u$4 = universalify.fromCallback;
|
|
2474
|
+
const path$7 = path__default["default"];
|
|
2475
|
+
const fs$6 = gracefulFs;
|
|
2476
|
+
const _mkdirs = mkdirs_1;
|
|
2477
|
+
const mkdirs = _mkdirs.mkdirs;
|
|
2478
|
+
const mkdirsSync = _mkdirs.mkdirsSync;
|
|
2479
|
+
|
|
2480
|
+
const _symlinkPaths = symlinkPaths_1;
|
|
2481
|
+
const symlinkPaths = _symlinkPaths.symlinkPaths;
|
|
2482
|
+
const symlinkPathsSync = _symlinkPaths.symlinkPathsSync;
|
|
2483
|
+
|
|
2484
|
+
const _symlinkType = symlinkType_1;
|
|
2485
|
+
const symlinkType = _symlinkType.symlinkType;
|
|
2486
|
+
const symlinkTypeSync = _symlinkType.symlinkTypeSync;
|
|
2487
|
+
|
|
2488
|
+
const pathExists$3 = pathExists_1.pathExists;
|
|
2489
|
+
|
|
2490
|
+
function createSymlink (srcpath, dstpath, type, callback) {
|
|
2491
|
+
callback = (typeof type === 'function') ? type : callback;
|
|
2492
|
+
type = (typeof type === 'function') ? false : type;
|
|
2493
|
+
|
|
2494
|
+
pathExists$3(dstpath, (err, destinationExists) => {
|
|
2495
|
+
if (err) return callback(err)
|
|
2496
|
+
if (destinationExists) return callback(null)
|
|
2497
|
+
symlinkPaths(srcpath, dstpath, (err, relative) => {
|
|
2498
|
+
if (err) return callback(err)
|
|
2499
|
+
srcpath = relative.toDst;
|
|
2500
|
+
symlinkType(relative.toCwd, type, (err, type) => {
|
|
2501
|
+
if (err) return callback(err)
|
|
2502
|
+
const dir = path$7.dirname(dstpath);
|
|
2503
|
+
pathExists$3(dir, (err, dirExists) => {
|
|
2504
|
+
if (err) return callback(err)
|
|
2505
|
+
if (dirExists) return fs$6.symlink(srcpath, dstpath, type, callback)
|
|
2506
|
+
mkdirs(dir, err => {
|
|
2507
|
+
if (err) return callback(err)
|
|
2508
|
+
fs$6.symlink(srcpath, dstpath, type, callback);
|
|
2509
|
+
});
|
|
2510
|
+
});
|
|
2511
|
+
});
|
|
2512
|
+
});
|
|
2513
|
+
});
|
|
2514
|
+
}
|
|
2515
|
+
|
|
2516
|
+
function createSymlinkSync (srcpath, dstpath, type) {
|
|
2517
|
+
const destinationExists = fs$6.existsSync(dstpath);
|
|
2518
|
+
if (destinationExists) return undefined
|
|
2519
|
+
|
|
2520
|
+
const relative = symlinkPathsSync(srcpath, dstpath);
|
|
2521
|
+
srcpath = relative.toDst;
|
|
2522
|
+
type = symlinkTypeSync(relative.toCwd, type);
|
|
2523
|
+
const dir = path$7.dirname(dstpath);
|
|
2524
|
+
const exists = fs$6.existsSync(dir);
|
|
2525
|
+
if (exists) return fs$6.symlinkSync(srcpath, dstpath, type)
|
|
2526
|
+
mkdirsSync(dir);
|
|
2527
|
+
return fs$6.symlinkSync(srcpath, dstpath, type)
|
|
2528
|
+
}
|
|
2529
|
+
|
|
2530
|
+
var symlink$1 = {
|
|
2531
|
+
createSymlink: u$4(createSymlink),
|
|
2532
|
+
createSymlinkSync
|
|
2533
|
+
};
|
|
2534
|
+
|
|
2535
|
+
const file = file$1;
|
|
2536
|
+
const link = link$1;
|
|
2537
|
+
const symlink = symlink$1;
|
|
2538
|
+
|
|
2539
|
+
var ensure = {
|
|
2540
|
+
// file
|
|
2541
|
+
createFile: file.createFile,
|
|
2542
|
+
createFileSync: file.createFileSync,
|
|
2543
|
+
ensureFile: file.createFile,
|
|
2544
|
+
ensureFileSync: file.createFileSync,
|
|
2545
|
+
// link
|
|
2546
|
+
createLink: link.createLink,
|
|
2547
|
+
createLinkSync: link.createLinkSync,
|
|
2548
|
+
ensureLink: link.createLink,
|
|
2549
|
+
ensureLinkSync: link.createLinkSync,
|
|
2550
|
+
// symlink
|
|
2551
|
+
createSymlink: symlink.createSymlink,
|
|
2552
|
+
createSymlinkSync: symlink.createSymlinkSync,
|
|
2553
|
+
ensureSymlink: symlink.createSymlink,
|
|
2554
|
+
ensureSymlinkSync: symlink.createSymlinkSync
|
|
2555
|
+
};
|
|
2556
|
+
|
|
2557
|
+
var _fs;
|
|
2558
|
+
try {
|
|
2559
|
+
_fs = gracefulFs;
|
|
2560
|
+
} catch (_) {
|
|
2561
|
+
_fs = require$$1__default["default"];
|
|
2562
|
+
}
|
|
2563
|
+
|
|
2564
|
+
function readFile (file, options, callback) {
|
|
2565
|
+
if (callback == null) {
|
|
2566
|
+
callback = options;
|
|
2567
|
+
options = {};
|
|
2568
|
+
}
|
|
2569
|
+
|
|
2570
|
+
if (typeof options === 'string') {
|
|
2571
|
+
options = {encoding: options};
|
|
2572
|
+
}
|
|
2573
|
+
|
|
2574
|
+
options = options || {};
|
|
2575
|
+
var fs = options.fs || _fs;
|
|
2576
|
+
|
|
2577
|
+
var shouldThrow = true;
|
|
2578
|
+
if ('throws' in options) {
|
|
2579
|
+
shouldThrow = options.throws;
|
|
2580
|
+
}
|
|
2581
|
+
|
|
2582
|
+
fs.readFile(file, options, function (err, data) {
|
|
2583
|
+
if (err) return callback(err)
|
|
2584
|
+
|
|
2585
|
+
data = stripBom(data);
|
|
2586
|
+
|
|
2587
|
+
var obj;
|
|
2588
|
+
try {
|
|
2589
|
+
obj = JSON.parse(data, options ? options.reviver : null);
|
|
2590
|
+
} catch (err2) {
|
|
2591
|
+
if (shouldThrow) {
|
|
2592
|
+
err2.message = file + ': ' + err2.message;
|
|
2593
|
+
return callback(err2)
|
|
2594
|
+
} else {
|
|
2595
|
+
return callback(null, null)
|
|
2596
|
+
}
|
|
2597
|
+
}
|
|
2598
|
+
|
|
2599
|
+
callback(null, obj);
|
|
2600
|
+
});
|
|
2601
|
+
}
|
|
2602
|
+
|
|
2603
|
+
function readFileSync (file, options) {
|
|
2604
|
+
options = options || {};
|
|
2605
|
+
if (typeof options === 'string') {
|
|
2606
|
+
options = {encoding: options};
|
|
2607
|
+
}
|
|
2608
|
+
|
|
2609
|
+
var fs = options.fs || _fs;
|
|
2610
|
+
|
|
2611
|
+
var shouldThrow = true;
|
|
2612
|
+
if ('throws' in options) {
|
|
2613
|
+
shouldThrow = options.throws;
|
|
2614
|
+
}
|
|
2615
|
+
|
|
2616
|
+
try {
|
|
2617
|
+
var content = fs.readFileSync(file, options);
|
|
2618
|
+
content = stripBom(content);
|
|
2619
|
+
return JSON.parse(content, options.reviver)
|
|
2620
|
+
} catch (err) {
|
|
2621
|
+
if (shouldThrow) {
|
|
2622
|
+
err.message = file + ': ' + err.message;
|
|
2623
|
+
throw err
|
|
2624
|
+
} else {
|
|
2625
|
+
return null
|
|
2626
|
+
}
|
|
2627
|
+
}
|
|
2628
|
+
}
|
|
2629
|
+
|
|
2630
|
+
function stringify (obj, options) {
|
|
2631
|
+
var spaces;
|
|
2632
|
+
var EOL = '\n';
|
|
2633
|
+
if (typeof options === 'object' && options !== null) {
|
|
2634
|
+
if (options.spaces) {
|
|
2635
|
+
spaces = options.spaces;
|
|
2636
|
+
}
|
|
2637
|
+
if (options.EOL) {
|
|
2638
|
+
EOL = options.EOL;
|
|
2639
|
+
}
|
|
2640
|
+
}
|
|
2641
|
+
|
|
2642
|
+
var str = JSON.stringify(obj, options ? options.replacer : null, spaces);
|
|
2643
|
+
|
|
2644
|
+
return str.replace(/\n/g, EOL) + EOL
|
|
2645
|
+
}
|
|
2646
|
+
|
|
2647
|
+
function writeFile (file, obj, options, callback) {
|
|
2648
|
+
if (callback == null) {
|
|
2649
|
+
callback = options;
|
|
2650
|
+
options = {};
|
|
2651
|
+
}
|
|
2652
|
+
options = options || {};
|
|
2653
|
+
var fs = options.fs || _fs;
|
|
2654
|
+
|
|
2655
|
+
var str = '';
|
|
2656
|
+
try {
|
|
2657
|
+
str = stringify(obj, options);
|
|
2658
|
+
} catch (err) {
|
|
2659
|
+
// Need to return whether a callback was passed or not
|
|
2660
|
+
if (callback) callback(err, null);
|
|
2661
|
+
return
|
|
2662
|
+
}
|
|
2663
|
+
|
|
2664
|
+
fs.writeFile(file, str, options, callback);
|
|
2665
|
+
}
|
|
2666
|
+
|
|
2667
|
+
function writeFileSync (file, obj, options) {
|
|
2668
|
+
options = options || {};
|
|
2669
|
+
var fs = options.fs || _fs;
|
|
2670
|
+
|
|
2671
|
+
var str = stringify(obj, options);
|
|
2672
|
+
// not sure if fs.writeFileSync returns anything, but just in case
|
|
2673
|
+
return fs.writeFileSync(file, str, options)
|
|
2674
|
+
}
|
|
2675
|
+
|
|
2676
|
+
function stripBom (content) {
|
|
2677
|
+
// we do this because JSON.parse would convert it to a utf8 string if encoding wasn't specified
|
|
2678
|
+
if (Buffer.isBuffer(content)) content = content.toString('utf8');
|
|
2679
|
+
content = content.replace(/^\uFEFF/, '');
|
|
2680
|
+
return content
|
|
2681
|
+
}
|
|
2682
|
+
|
|
2683
|
+
var jsonfile$1 = {
|
|
2684
|
+
readFile: readFile,
|
|
2685
|
+
readFileSync: readFileSync,
|
|
2686
|
+
writeFile: writeFile,
|
|
2687
|
+
writeFileSync: writeFileSync
|
|
2688
|
+
};
|
|
2689
|
+
|
|
2690
|
+
var jsonfile_1 = jsonfile$1;
|
|
2691
|
+
|
|
2692
|
+
const u$3 = universalify.fromCallback;
|
|
2693
|
+
const jsonFile$3 = jsonfile_1;
|
|
2694
|
+
|
|
2695
|
+
var jsonfile = {
|
|
2696
|
+
// jsonfile exports
|
|
2697
|
+
readJson: u$3(jsonFile$3.readFile),
|
|
2698
|
+
readJsonSync: jsonFile$3.readFileSync,
|
|
2699
|
+
writeJson: u$3(jsonFile$3.writeFile),
|
|
2700
|
+
writeJsonSync: jsonFile$3.writeFileSync
|
|
2701
|
+
};
|
|
2702
|
+
|
|
2703
|
+
const path$6 = path__default["default"];
|
|
2704
|
+
const mkdir$2 = mkdirs_1;
|
|
2705
|
+
const pathExists$2 = pathExists_1.pathExists;
|
|
2706
|
+
const jsonFile$2 = jsonfile;
|
|
2707
|
+
|
|
2708
|
+
function outputJson (file, data, options, callback) {
|
|
2709
|
+
if (typeof options === 'function') {
|
|
2710
|
+
callback = options;
|
|
2711
|
+
options = {};
|
|
2712
|
+
}
|
|
2713
|
+
|
|
2714
|
+
const dir = path$6.dirname(file);
|
|
2715
|
+
|
|
2716
|
+
pathExists$2(dir, (err, itDoes) => {
|
|
2717
|
+
if (err) return callback(err)
|
|
2718
|
+
if (itDoes) return jsonFile$2.writeJson(file, data, options, callback)
|
|
2719
|
+
|
|
2720
|
+
mkdir$2.mkdirs(dir, err => {
|
|
2721
|
+
if (err) return callback(err)
|
|
2722
|
+
jsonFile$2.writeJson(file, data, options, callback);
|
|
2723
|
+
});
|
|
2724
|
+
});
|
|
2725
|
+
}
|
|
2726
|
+
|
|
2727
|
+
var outputJson_1 = outputJson;
|
|
2728
|
+
|
|
2729
|
+
const fs$5 = gracefulFs;
|
|
2730
|
+
const path$5 = path__default["default"];
|
|
2731
|
+
const mkdir$1 = mkdirs_1;
|
|
2732
|
+
const jsonFile$1 = jsonfile;
|
|
2733
|
+
|
|
2734
|
+
function outputJsonSync (file, data, options) {
|
|
2735
|
+
const dir = path$5.dirname(file);
|
|
2736
|
+
|
|
2737
|
+
if (!fs$5.existsSync(dir)) {
|
|
2738
|
+
mkdir$1.mkdirsSync(dir);
|
|
2739
|
+
}
|
|
2740
|
+
|
|
2741
|
+
jsonFile$1.writeJsonSync(file, data, options);
|
|
2742
|
+
}
|
|
2743
|
+
|
|
2744
|
+
var outputJsonSync_1 = outputJsonSync;
|
|
2745
|
+
|
|
2746
|
+
const u$2 = universalify.fromCallback;
|
|
2747
|
+
const jsonFile = jsonfile;
|
|
2748
|
+
|
|
2749
|
+
jsonFile.outputJson = u$2(outputJson_1);
|
|
2750
|
+
jsonFile.outputJsonSync = outputJsonSync_1;
|
|
2751
|
+
// aliases
|
|
2752
|
+
jsonFile.outputJSON = jsonFile.outputJson;
|
|
2753
|
+
jsonFile.outputJSONSync = jsonFile.outputJsonSync;
|
|
2754
|
+
jsonFile.writeJSON = jsonFile.writeJson;
|
|
2755
|
+
jsonFile.writeJSONSync = jsonFile.writeJsonSync;
|
|
2756
|
+
jsonFile.readJSON = jsonFile.readJson;
|
|
2757
|
+
jsonFile.readJSONSync = jsonFile.readJsonSync;
|
|
2758
|
+
|
|
2759
|
+
var json = jsonFile;
|
|
2760
|
+
|
|
2761
|
+
const fs$4 = gracefulFs;
|
|
2762
|
+
const path$4 = path__default["default"];
|
|
2763
|
+
const copySync = copySync$1.copySync;
|
|
2764
|
+
const removeSync = remove$2.removeSync;
|
|
2765
|
+
const mkdirpSync = mkdirs_1.mkdirsSync;
|
|
2766
|
+
const buffer = buffer$1;
|
|
2767
|
+
|
|
2768
|
+
function moveSync (src, dest, options) {
|
|
2769
|
+
options = options || {};
|
|
2770
|
+
const overwrite = options.overwrite || options.clobber || false;
|
|
2771
|
+
|
|
2772
|
+
src = path$4.resolve(src);
|
|
2773
|
+
dest = path$4.resolve(dest);
|
|
2774
|
+
|
|
2775
|
+
if (src === dest) return fs$4.accessSync(src)
|
|
2776
|
+
|
|
2777
|
+
if (isSrcSubdir$1(src, dest)) throw new Error(`Cannot move '${src}' into itself '${dest}'.`)
|
|
2778
|
+
|
|
2779
|
+
mkdirpSync(path$4.dirname(dest));
|
|
2780
|
+
tryRenameSync();
|
|
2781
|
+
|
|
2782
|
+
function tryRenameSync () {
|
|
2783
|
+
if (overwrite) {
|
|
2784
|
+
try {
|
|
2785
|
+
return fs$4.renameSync(src, dest)
|
|
2786
|
+
} catch (err) {
|
|
2787
|
+
if (err.code === 'ENOTEMPTY' || err.code === 'EEXIST' || err.code === 'EPERM') {
|
|
2788
|
+
removeSync(dest);
|
|
2789
|
+
options.overwrite = false; // just overwriteed it, no need to do it again
|
|
2790
|
+
return moveSync(src, dest, options)
|
|
2791
|
+
}
|
|
2792
|
+
|
|
2793
|
+
if (err.code !== 'EXDEV') throw err
|
|
2794
|
+
return moveSyncAcrossDevice(src, dest, overwrite)
|
|
2795
|
+
}
|
|
2796
|
+
} else {
|
|
2797
|
+
try {
|
|
2798
|
+
fs$4.linkSync(src, dest);
|
|
2799
|
+
return fs$4.unlinkSync(src)
|
|
2800
|
+
} catch (err) {
|
|
2801
|
+
if (err.code === 'EXDEV' || err.code === 'EISDIR' || err.code === 'EPERM' || err.code === 'ENOTSUP') {
|
|
2802
|
+
return moveSyncAcrossDevice(src, dest, overwrite)
|
|
2803
|
+
}
|
|
2804
|
+
throw err
|
|
2805
|
+
}
|
|
2806
|
+
}
|
|
2807
|
+
}
|
|
2808
|
+
}
|
|
2809
|
+
|
|
2810
|
+
function moveSyncAcrossDevice (src, dest, overwrite) {
|
|
2811
|
+
const stat = fs$4.statSync(src);
|
|
2812
|
+
|
|
2813
|
+
if (stat.isDirectory()) {
|
|
2814
|
+
return moveDirSyncAcrossDevice(src, dest, overwrite)
|
|
2815
|
+
} else {
|
|
2816
|
+
return moveFileSyncAcrossDevice(src, dest, overwrite)
|
|
2817
|
+
}
|
|
2818
|
+
}
|
|
2819
|
+
|
|
2820
|
+
function moveFileSyncAcrossDevice (src, dest, overwrite) {
|
|
2821
|
+
const BUF_LENGTH = 64 * 1024;
|
|
2822
|
+
const _buff = buffer(BUF_LENGTH);
|
|
2823
|
+
|
|
2824
|
+
const flags = overwrite ? 'w' : 'wx';
|
|
2825
|
+
|
|
2826
|
+
const fdr = fs$4.openSync(src, 'r');
|
|
2827
|
+
const stat = fs$4.fstatSync(fdr);
|
|
2828
|
+
const fdw = fs$4.openSync(dest, flags, stat.mode);
|
|
2829
|
+
let pos = 0;
|
|
2830
|
+
|
|
2831
|
+
while (pos < stat.size) {
|
|
2832
|
+
const bytesRead = fs$4.readSync(fdr, _buff, 0, BUF_LENGTH, pos);
|
|
2833
|
+
fs$4.writeSync(fdw, _buff, 0, bytesRead);
|
|
2834
|
+
pos += bytesRead;
|
|
2835
|
+
}
|
|
2836
|
+
|
|
2837
|
+
fs$4.closeSync(fdr);
|
|
2838
|
+
fs$4.closeSync(fdw);
|
|
2839
|
+
return fs$4.unlinkSync(src)
|
|
2840
|
+
}
|
|
2841
|
+
|
|
2842
|
+
function moveDirSyncAcrossDevice (src, dest, overwrite) {
|
|
2843
|
+
const options = {
|
|
2844
|
+
overwrite: false
|
|
2845
|
+
};
|
|
2846
|
+
|
|
2847
|
+
if (overwrite) {
|
|
2848
|
+
removeSync(dest);
|
|
2849
|
+
tryCopySync();
|
|
2850
|
+
} else {
|
|
2851
|
+
tryCopySync();
|
|
2852
|
+
}
|
|
2853
|
+
|
|
2854
|
+
function tryCopySync () {
|
|
2855
|
+
copySync(src, dest, options);
|
|
2856
|
+
return removeSync(src)
|
|
2857
|
+
}
|
|
2858
|
+
}
|
|
2859
|
+
|
|
2860
|
+
// return true if dest is a subdir of src, otherwise false.
|
|
2861
|
+
// extract dest base dir and check if that is the same as src basename
|
|
2862
|
+
function isSrcSubdir$1 (src, dest) {
|
|
2863
|
+
try {
|
|
2864
|
+
return fs$4.statSync(src).isDirectory() &&
|
|
2865
|
+
src !== dest &&
|
|
2866
|
+
dest.indexOf(src) > -1 &&
|
|
2867
|
+
dest.split(path$4.dirname(src) + path$4.sep)[1].split(path$4.sep)[0] === path$4.basename(src)
|
|
2868
|
+
} catch (e) {
|
|
2869
|
+
return false
|
|
2870
|
+
}
|
|
2871
|
+
}
|
|
2872
|
+
|
|
2873
|
+
var moveSync_1 = {
|
|
2874
|
+
moveSync
|
|
2875
|
+
};
|
|
2876
|
+
|
|
2877
|
+
const u$1 = universalify.fromCallback;
|
|
2878
|
+
const fs$3 = gracefulFs;
|
|
2879
|
+
const path$3 = path__default["default"];
|
|
2880
|
+
const copy = copy$1.copy;
|
|
2881
|
+
const remove = remove$2.remove;
|
|
2882
|
+
const mkdirp = mkdirs_1.mkdirp;
|
|
2883
|
+
const pathExists$1 = pathExists_1.pathExists;
|
|
2884
|
+
|
|
2885
|
+
function move (src, dest, opts, cb) {
|
|
2886
|
+
if (typeof opts === 'function') {
|
|
2887
|
+
cb = opts;
|
|
2888
|
+
opts = {};
|
|
2889
|
+
}
|
|
2890
|
+
|
|
2891
|
+
const overwrite = opts.overwrite || opts.clobber || false;
|
|
2892
|
+
|
|
2893
|
+
src = path$3.resolve(src);
|
|
2894
|
+
dest = path$3.resolve(dest);
|
|
2895
|
+
|
|
2896
|
+
if (src === dest) return fs$3.access(src, cb)
|
|
2897
|
+
|
|
2898
|
+
fs$3.stat(src, (err, st) => {
|
|
2899
|
+
if (err) return cb(err)
|
|
2900
|
+
|
|
2901
|
+
if (st.isDirectory() && isSrcSubdir(src, dest)) {
|
|
2902
|
+
return cb(new Error(`Cannot move '${src}' to a subdirectory of itself, '${dest}'.`))
|
|
2903
|
+
}
|
|
2904
|
+
mkdirp(path$3.dirname(dest), err => {
|
|
2905
|
+
if (err) return cb(err)
|
|
2906
|
+
return doRename(src, dest, overwrite, cb)
|
|
2907
|
+
});
|
|
2908
|
+
});
|
|
2909
|
+
}
|
|
2910
|
+
|
|
2911
|
+
function doRename (src, dest, overwrite, cb) {
|
|
2912
|
+
if (overwrite) {
|
|
2913
|
+
return remove(dest, err => {
|
|
2914
|
+
if (err) return cb(err)
|
|
2915
|
+
return rename(src, dest, overwrite, cb)
|
|
2916
|
+
})
|
|
2917
|
+
}
|
|
2918
|
+
pathExists$1(dest, (err, destExists) => {
|
|
2919
|
+
if (err) return cb(err)
|
|
2920
|
+
if (destExists) return cb(new Error('dest already exists.'))
|
|
2921
|
+
return rename(src, dest, overwrite, cb)
|
|
2922
|
+
});
|
|
2923
|
+
}
|
|
2924
|
+
|
|
2925
|
+
function rename (src, dest, overwrite, cb) {
|
|
2926
|
+
fs$3.rename(src, dest, err => {
|
|
2927
|
+
if (!err) return cb()
|
|
2928
|
+
if (err.code !== 'EXDEV') return cb(err)
|
|
2929
|
+
return moveAcrossDevice(src, dest, overwrite, cb)
|
|
2930
|
+
});
|
|
2931
|
+
}
|
|
2932
|
+
|
|
2933
|
+
function moveAcrossDevice (src, dest, overwrite, cb) {
|
|
2934
|
+
const opts = {
|
|
2935
|
+
overwrite,
|
|
2936
|
+
errorOnExist: true
|
|
2937
|
+
};
|
|
2938
|
+
|
|
2939
|
+
copy(src, dest, opts, err => {
|
|
2940
|
+
if (err) return cb(err)
|
|
2941
|
+
return remove(src, cb)
|
|
2942
|
+
});
|
|
2943
|
+
}
|
|
2944
|
+
|
|
2945
|
+
function isSrcSubdir (src, dest) {
|
|
2946
|
+
const srcArray = src.split(path$3.sep);
|
|
2947
|
+
const destArray = dest.split(path$3.sep);
|
|
2948
|
+
|
|
2949
|
+
return srcArray.reduce((acc, current, i) => {
|
|
2950
|
+
return acc && destArray[i] === current
|
|
2951
|
+
}, true)
|
|
2952
|
+
}
|
|
2953
|
+
|
|
2954
|
+
var move_1 = {
|
|
2955
|
+
move: u$1(move)
|
|
2956
|
+
};
|
|
2957
|
+
|
|
2958
|
+
const u = universalify.fromCallback;
|
|
2959
|
+
const fs$2 = gracefulFs;
|
|
2960
|
+
const path$2 = path__default["default"];
|
|
2961
|
+
const mkdir = mkdirs_1;
|
|
2962
|
+
const pathExists = pathExists_1.pathExists;
|
|
2963
|
+
|
|
2964
|
+
function outputFile (file, data, encoding, callback) {
|
|
2965
|
+
if (typeof encoding === 'function') {
|
|
2966
|
+
callback = encoding;
|
|
2967
|
+
encoding = 'utf8';
|
|
2968
|
+
}
|
|
2969
|
+
|
|
2970
|
+
const dir = path$2.dirname(file);
|
|
2971
|
+
pathExists(dir, (err, itDoes) => {
|
|
2972
|
+
if (err) return callback(err)
|
|
2973
|
+
if (itDoes) return fs$2.writeFile(file, data, encoding, callback)
|
|
2974
|
+
|
|
2975
|
+
mkdir.mkdirs(dir, err => {
|
|
2976
|
+
if (err) return callback(err)
|
|
2977
|
+
|
|
2978
|
+
fs$2.writeFile(file, data, encoding, callback);
|
|
2979
|
+
});
|
|
2980
|
+
});
|
|
2981
|
+
}
|
|
2982
|
+
|
|
2983
|
+
function outputFileSync (file, ...args) {
|
|
2984
|
+
const dir = path$2.dirname(file);
|
|
2985
|
+
if (fs$2.existsSync(dir)) {
|
|
2986
|
+
return fs$2.writeFileSync(file, ...args)
|
|
2987
|
+
}
|
|
2988
|
+
mkdir.mkdirsSync(dir);
|
|
2989
|
+
fs$2.writeFileSync(file, ...args);
|
|
2990
|
+
}
|
|
2991
|
+
|
|
2992
|
+
var output = {
|
|
2993
|
+
outputFile: u(outputFile),
|
|
2994
|
+
outputFileSync
|
|
2995
|
+
};
|
|
2996
|
+
|
|
2997
|
+
(function (module) {
|
|
2998
|
+
|
|
2999
|
+
module.exports = Object.assign(
|
|
3000
|
+
{},
|
|
3001
|
+
// Export promiseified graceful-fs:
|
|
3002
|
+
fs$k,
|
|
3003
|
+
// Export extra methods:
|
|
3004
|
+
copySync$1,
|
|
3005
|
+
copy$1,
|
|
3006
|
+
empty,
|
|
3007
|
+
ensure,
|
|
3008
|
+
json,
|
|
3009
|
+
mkdirs_1,
|
|
3010
|
+
moveSync_1,
|
|
3011
|
+
move_1,
|
|
3012
|
+
output,
|
|
3013
|
+
pathExists_1,
|
|
3014
|
+
remove$2
|
|
3015
|
+
);
|
|
3016
|
+
|
|
3017
|
+
// Export fs.promises as a getter property so that we don't trigger
|
|
3018
|
+
// ExperimentalWarning before fs.promises is actually accessed.
|
|
3019
|
+
const fs = require$$1__default["default"];
|
|
3020
|
+
if (Object.getOwnPropertyDescriptor(fs, 'promises')) {
|
|
3021
|
+
Object.defineProperty(module.exports, 'promises', {
|
|
3022
|
+
get () { return fs.promises }
|
|
3023
|
+
});
|
|
3024
|
+
}
|
|
3025
|
+
} (lib));
|
|
3026
|
+
|
|
3027
|
+
var fs$1 = libExports;
|
|
3028
|
+
|
|
3029
|
+
class Compile extends EventEmitter__default["default"] {
|
|
3030
|
+
constructor(args, argv0, dir, debug) {
|
|
3031
|
+
super();
|
|
3032
|
+
if (!args || !args.length || !dir || !argv0) {
|
|
3033
|
+
console.error(argv0, args, dir);
|
|
3034
|
+
throw new Error("Bad args");
|
|
3035
|
+
}
|
|
3036
|
+
const compiler = args.shift();
|
|
3037
|
+
if (compiler === undefined) {
|
|
3038
|
+
console.error(argv0, args, dir);
|
|
3039
|
+
throw new Error("Bad args");
|
|
3040
|
+
}
|
|
3041
|
+
const isClang = compiler.indexOf("clang") !== -1;
|
|
3042
|
+
let output;
|
|
3043
|
+
let outputFileName;
|
|
3044
|
+
let hasDashO = false;
|
|
3045
|
+
let hasDashX = false;
|
|
3046
|
+
let sourceFile;
|
|
3047
|
+
for (let i = 0; i < args.length; ++i) {
|
|
3048
|
+
// console.log(i, args[i]);
|
|
3049
|
+
switch (args[i]) {
|
|
3050
|
+
case "-o": {
|
|
3051
|
+
hasDashO = true;
|
|
3052
|
+
output = args[++i];
|
|
3053
|
+
outputFileName = path__default["default"].basename(output);
|
|
3054
|
+
args[i] = outputFileName;
|
|
3055
|
+
break;
|
|
3056
|
+
}
|
|
3057
|
+
case "-MF": {
|
|
3058
|
+
args.splice(i--, 2);
|
|
3059
|
+
break;
|
|
3060
|
+
}
|
|
3061
|
+
case "-MMD":
|
|
3062
|
+
case "-MD":
|
|
3063
|
+
case "-MM":
|
|
3064
|
+
case "-M":
|
|
3065
|
+
args.splice(i--, 1);
|
|
3066
|
+
continue;
|
|
3067
|
+
case "-MT":
|
|
3068
|
+
args.splice(i--, 2);
|
|
3069
|
+
continue;
|
|
3070
|
+
case "-cxx-isystem":
|
|
3071
|
+
case "-isysroot":
|
|
3072
|
+
case "-isystem":
|
|
3073
|
+
case "-I":
|
|
3074
|
+
args.splice(i--, 2);
|
|
3075
|
+
break;
|
|
3076
|
+
case "-x":
|
|
3077
|
+
hasDashX = true;
|
|
3078
|
+
if (!isClang) {
|
|
3079
|
+
switch (args[++i]) {
|
|
3080
|
+
case "c":
|
|
3081
|
+
args[i] = "cpp-output";
|
|
3082
|
+
break;
|
|
3083
|
+
case "c++":
|
|
3084
|
+
args[i] = "c++-cpp-output";
|
|
3085
|
+
break;
|
|
3086
|
+
case "objective-c":
|
|
3087
|
+
args[i] = "objective-c-output";
|
|
3088
|
+
break;
|
|
3089
|
+
case "objective-c++":
|
|
3090
|
+
args[i] = "objective-c++-cpp-output";
|
|
3091
|
+
break;
|
|
3092
|
+
}
|
|
3093
|
+
}
|
|
3094
|
+
else {
|
|
3095
|
+
++i;
|
|
3096
|
+
}
|
|
3097
|
+
break;
|
|
3098
|
+
case "--param":
|
|
3099
|
+
case "-G":
|
|
3100
|
+
case "-T":
|
|
3101
|
+
case "-V":
|
|
3102
|
+
case "-Xanalyzer":
|
|
3103
|
+
case "-Xassembler":
|
|
3104
|
+
case "-Xclang":
|
|
3105
|
+
case "-Xlinker":
|
|
3106
|
+
case "-Xpreprocessor":
|
|
3107
|
+
case "-arch":
|
|
3108
|
+
case "-b":
|
|
3109
|
+
case "-gcc-toolchain":
|
|
3110
|
+
case "-imacros":
|
|
3111
|
+
case "-imultilib":
|
|
3112
|
+
case "-include":
|
|
3113
|
+
case "-iprefix":
|
|
3114
|
+
case "-ivfsoverlay":
|
|
3115
|
+
case "-iwithprefix":
|
|
3116
|
+
case "-iwithprefixbefore":
|
|
3117
|
+
case "-target":
|
|
3118
|
+
++i;
|
|
3119
|
+
break;
|
|
3120
|
+
default:
|
|
3121
|
+
if (/^-mlinker-version=/.exec(args[i]) || /^-stdlib=/.exec(args[i])) {
|
|
3122
|
+
args.splice(i--, 1);
|
|
3123
|
+
break;
|
|
3124
|
+
}
|
|
3125
|
+
if (args[i][0] !== "-") {
|
|
3126
|
+
if (sourceFile) {
|
|
3127
|
+
console.log("Multiple source files", sourceFile, args[i]);
|
|
3128
|
+
throw new Error("More than one source file");
|
|
3129
|
+
}
|
|
3130
|
+
sourceFile = args[i];
|
|
3131
|
+
args[i] = path__default["default"].join(dir, "sourcefile");
|
|
3132
|
+
}
|
|
3133
|
+
break;
|
|
3134
|
+
}
|
|
3135
|
+
}
|
|
3136
|
+
if (!sourceFile) {
|
|
3137
|
+
throw new Error("No sourcefile");
|
|
3138
|
+
}
|
|
3139
|
+
if (!hasDashX) {
|
|
3140
|
+
if (compiler.indexOf("g++") !== -1 || compiler.indexOf("c++") !== -1) {
|
|
3141
|
+
args.unshift(isClang ? "c++" : "c++-cpp-output");
|
|
3142
|
+
}
|
|
3143
|
+
else {
|
|
3144
|
+
switch (path__default["default"].extname(sourceFile)) {
|
|
3145
|
+
case ".C":
|
|
3146
|
+
case ".cc":
|
|
3147
|
+
case ".cpp":
|
|
3148
|
+
case ".CPP":
|
|
3149
|
+
case ".c++":
|
|
3150
|
+
case ".cp":
|
|
3151
|
+
case ".cxx":
|
|
3152
|
+
args.unshift(isClang ? "c++" : "c++-cpp-output");
|
|
3153
|
+
break;
|
|
3154
|
+
case ".ii":
|
|
3155
|
+
args.unshift("c++-cpp-output");
|
|
3156
|
+
break;
|
|
3157
|
+
case ".hh":
|
|
3158
|
+
case ".hpp":
|
|
3159
|
+
case ".H":
|
|
3160
|
+
args.unshift("c++-header");
|
|
3161
|
+
break;
|
|
3162
|
+
case ".h":
|
|
3163
|
+
args.unshift("c-header");
|
|
3164
|
+
break;
|
|
3165
|
+
case ".c":
|
|
3166
|
+
args.unshift(isClang ? "c" : "cpp-output");
|
|
3167
|
+
break;
|
|
3168
|
+
case ".i":
|
|
3169
|
+
args.unshift("cpp-output");
|
|
3170
|
+
break;
|
|
3171
|
+
case ".m":
|
|
3172
|
+
case ".mi":
|
|
3173
|
+
args.unshift(isClang ? "objective-c" : "objective-c-cpp-output");
|
|
3174
|
+
break;
|
|
3175
|
+
case ".s":
|
|
3176
|
+
args.unshift("assembler");
|
|
3177
|
+
break;
|
|
3178
|
+
case ".sx":
|
|
3179
|
+
case ".S":
|
|
3180
|
+
args.unshift("assembler-with-cpp");
|
|
3181
|
+
break;
|
|
3182
|
+
case ".mm":
|
|
3183
|
+
case ".M":
|
|
3184
|
+
case ".mii":
|
|
3185
|
+
args.unshift(isClang ? "objective-c++" : "objective-c++-cpp-output");
|
|
3186
|
+
break;
|
|
3187
|
+
default:
|
|
3188
|
+
throw new Error(`Can't determine source language for file: ${sourceFile}`);
|
|
3189
|
+
}
|
|
3190
|
+
}
|
|
3191
|
+
args.unshift("-x");
|
|
3192
|
+
}
|
|
3193
|
+
if (!isClang) {
|
|
3194
|
+
args.push("-fpreprocessed", "-fdirectives-only"); // this is not good for clang
|
|
3195
|
+
}
|
|
3196
|
+
else {
|
|
3197
|
+
args.push("-Wno-stdlibcxx-not-found");
|
|
3198
|
+
}
|
|
3199
|
+
if (!hasDashO) {
|
|
3200
|
+
const suffix = path__default["default"].extname(sourceFile);
|
|
3201
|
+
outputFileName = output = sourceFile.substring(0, sourceFile.length - suffix.length) + ".o";
|
|
3202
|
+
args.push("-o", outputFileName);
|
|
3203
|
+
}
|
|
3204
|
+
// debug = true;
|
|
3205
|
+
if (debug) {
|
|
3206
|
+
console.log("Calling", argv0, compiler, args.map((x) => '"' + x + '"').join(" "));
|
|
3207
|
+
}
|
|
3208
|
+
if (!fs$1.existsSync("/usr/bin/as")) {
|
|
3209
|
+
this.emit("stderr", "as doesn't exist");
|
|
3210
|
+
}
|
|
3211
|
+
// const env = Object.assign({ TMPDIR: dir, TEMPDIR: dir, TEMP: dir }, process.env);
|
|
3212
|
+
const proc = child_process__default["default"].spawn(compiler, args, {
|
|
3213
|
+
/*env: env, */ cwd: dir // , maxBuffer: 1024 * 1024 * 16
|
|
3214
|
+
});
|
|
3215
|
+
this.proc = proc;
|
|
3216
|
+
proc.stdout.setEncoding("utf8");
|
|
3217
|
+
proc.stderr.setEncoding("utf8");
|
|
3218
|
+
proc.stdout.on("data", (data) => {
|
|
3219
|
+
this.emit("stdout", data);
|
|
3220
|
+
});
|
|
3221
|
+
proc.stderr.on("data", (data) => {
|
|
3222
|
+
this.emit("stderr", data);
|
|
3223
|
+
});
|
|
3224
|
+
proc.on("error", (err) => {
|
|
3225
|
+
this.emit("error", err);
|
|
3226
|
+
});
|
|
3227
|
+
proc.on("exit", (exitCode) => {
|
|
3228
|
+
// try {
|
|
3229
|
+
const files = [];
|
|
3230
|
+
const addDir = (dir, prefix) => {
|
|
3231
|
+
try {
|
|
3232
|
+
fs$1.readdirSync(dir).forEach((file) => {
|
|
3233
|
+
if (file === "sourcefile") {
|
|
3234
|
+
return;
|
|
3235
|
+
}
|
|
3236
|
+
try {
|
|
3237
|
+
assert__default["default"](output !== undefined, "Must have output");
|
|
3238
|
+
const stat = fs$1.statSync(path__default["default"].join(dir, file));
|
|
3239
|
+
if (stat.isDirectory()) {
|
|
3240
|
+
addDir(path__default["default"].join(dir, file), prefix ? prefix + file + "/" : file + "/");
|
|
3241
|
+
}
|
|
3242
|
+
else if (stat.isFile()) {
|
|
3243
|
+
if (file === outputFileName) {
|
|
3244
|
+
files.push({ path: output, mapped: path__default["default"].join(prefix, file) });
|
|
3245
|
+
}
|
|
3246
|
+
else if (path__default["default"].extname(file) === ".gcno") {
|
|
3247
|
+
// console.log("mapping", output, prefix, file);
|
|
3248
|
+
files.push({
|
|
3249
|
+
path: output.substring(0, output.length - 1) + "gcno",
|
|
3250
|
+
mapped: path__default["default"].join(prefix, file)
|
|
3251
|
+
});
|
|
3252
|
+
}
|
|
3253
|
+
else if (path__default["default"].extname(file) === ".gcda") {
|
|
3254
|
+
files.push({
|
|
3255
|
+
path: output.substring(0, output.length - 1) + "gcda",
|
|
3256
|
+
mapped: path__default["default"].join(prefix, file)
|
|
3257
|
+
});
|
|
3258
|
+
}
|
|
3259
|
+
else {
|
|
3260
|
+
files.push({ path: path__default["default"].join(prefix, file) });
|
|
3261
|
+
}
|
|
3262
|
+
if (debug) {
|
|
3263
|
+
console.log("Added file", file, files[files.length - 1]);
|
|
3264
|
+
}
|
|
3265
|
+
}
|
|
3266
|
+
}
|
|
3267
|
+
catch (err) {
|
|
3268
|
+
/* */
|
|
3269
|
+
}
|
|
3270
|
+
});
|
|
3271
|
+
}
|
|
3272
|
+
catch (err) {
|
|
3273
|
+
console.error("Got an error processing outputs for", sourceFile, err);
|
|
3274
|
+
assert__default["default"](sourceFile !== undefined, "Must have sourceFile");
|
|
3275
|
+
const errorExitEvent = {
|
|
3276
|
+
exitCode: 110,
|
|
3277
|
+
files: [],
|
|
3278
|
+
error: err.toString(),
|
|
3279
|
+
sourceFile
|
|
3280
|
+
};
|
|
3281
|
+
this.emit("exit", errorExitEvent);
|
|
3282
|
+
}
|
|
3283
|
+
};
|
|
3284
|
+
if (exitCode === 0) {
|
|
3285
|
+
addDir(dir, dir);
|
|
3286
|
+
}
|
|
3287
|
+
if (exitCode === null) {
|
|
3288
|
+
exitCode = 111;
|
|
3289
|
+
}
|
|
3290
|
+
assert__default["default"](sourceFile !== undefined, "Must have sourceFile4");
|
|
3291
|
+
const exitEvent = { exitCode, files, sourceFile };
|
|
3292
|
+
this.emit("exit", exitEvent);
|
|
3293
|
+
});
|
|
3294
|
+
}
|
|
3295
|
+
kill() {
|
|
3296
|
+
this.proc.kill();
|
|
3297
|
+
}
|
|
3298
|
+
}
|
|
3299
|
+
// let preproc = fs.readFileSync("/tmp/preproc");
|
|
3300
|
+
// let f = new Compile([ "/usr/bin/c++", "-Iclient", "-I3rdparty/json11", "-I3rdparty/wslay/lib/includes", "-I3rdparty/wslay/lib", "-I3rdparty/LUrlParser", "-I3rdparty/tiny-process-library", "-std=c++14", "-Wformat", "-Wall", "-g", "-MD", "-MT", "client/CMakeFiles/fiskc.dir/Config.cpp.o", "-MF", "client/CMakeFiles/fiskc.dir/Config.cpp.o.d", "-o", "client/CMakeFiles/fiskc.dir/Config.cpp.o", "-c", "client/Config.cpp" ], preproc);
|
|
3301
|
+
// f.on('stdout', (data) => {
|
|
3302
|
+
// console.log("Got out", data.length);
|
|
3303
|
+
// });
|
|
3304
|
+
// f.on('stderr', (data) => {
|
|
3305
|
+
// console.log("Got err", data.toString());
|
|
3306
|
+
// });
|
|
3307
|
+
// f.on('error', error => {
|
|
3308
|
+
// console.log("Got error", error);
|
|
3309
|
+
// });
|
|
3310
|
+
// f.on('exit', event => {
|
|
3311
|
+
// console.log("Got exit", event);
|
|
3312
|
+
// });
|
|
3313
|
+
module.exports = Compile;
|
|
3314
|
+
|
|
3315
|
+
var posixExports = {};
|
|
3316
|
+
var posix$2 = {
|
|
3317
|
+
get exports(){ return posixExports; },
|
|
3318
|
+
set exports(v){ posixExports = v; },
|
|
3319
|
+
};
|
|
3320
|
+
|
|
3321
|
+
var path$1 = path__default["default"];
|
|
3322
|
+
|
|
3323
|
+
|
|
3324
|
+
var IS_LINUX = require$$1__default$1["default"].platform() === 'linux';
|
|
3325
|
+
|
|
3326
|
+
|
|
3327
|
+
// Attempt to load the bindings module from various possible locations
|
|
3328
|
+
function load_extension() {
|
|
3329
|
+
var ext_dirs = [
|
|
3330
|
+
'build/bindings', 'build/Release', 'out/Release', 'Release',
|
|
3331
|
+
'build/Debug', 'out/Debug',
|
|
3332
|
+
], i;
|
|
3333
|
+
for (i in ext_dirs) {
|
|
3334
|
+
try {
|
|
3335
|
+
return require(path$1.join(__dirname, '../..', ext_dirs[i],
|
|
3336
|
+
'posix.node'));
|
|
3337
|
+
|
|
3338
|
+
} catch (error) {
|
|
3339
|
+
if (!/Cannot find module/.test(error.message)) {
|
|
3340
|
+
throw error;
|
|
3341
|
+
}
|
|
3342
|
+
}
|
|
3343
|
+
}
|
|
3344
|
+
throw new Error("unable to load the node-posix extension module");
|
|
3345
|
+
}
|
|
3346
|
+
|
|
3347
|
+
var posix$1 = load_extension();
|
|
3348
|
+
|
|
3349
|
+
var syslog_constants = {};
|
|
3350
|
+
posix$1.update_syslog_constants(syslog_constants);
|
|
3351
|
+
|
|
3352
|
+
function syslog_const(value) {
|
|
3353
|
+
if (syslog_constants[value] === undefined) {
|
|
3354
|
+
throw new Error("invalid syslog constant value: " + value);
|
|
3355
|
+
}
|
|
3356
|
+
|
|
3357
|
+
return syslog_constants[value];
|
|
3358
|
+
}
|
|
3359
|
+
|
|
3360
|
+
function syslog_flags(option, prefix) {
|
|
3361
|
+
prefix = prefix || "";
|
|
3362
|
+
var opt = 0, key, flag;
|
|
3363
|
+
for (key in option) {
|
|
3364
|
+
flag = syslog_const(prefix + key); // checks all flags
|
|
3365
|
+
opt |= option[key] ? flag : 0;
|
|
3366
|
+
}
|
|
3367
|
+
return opt;
|
|
3368
|
+
}
|
|
3369
|
+
|
|
3370
|
+
posix$2.exports = {
|
|
3371
|
+
getgid: process.getgid,
|
|
3372
|
+
getuid: process.getuid,
|
|
3373
|
+
setgid: process.setgid,
|
|
3374
|
+
setuid: process.setuid,
|
|
3375
|
+
|
|
3376
|
+
chroot: posix$1.chroot,
|
|
3377
|
+
closelog: posix$1.closelog,
|
|
3378
|
+
getegid: posix$1.getegid,
|
|
3379
|
+
geteuid: posix$1.geteuid,
|
|
3380
|
+
getgrnam: posix$1.getgrnam,
|
|
3381
|
+
getpgid: posix$1.getpgid,
|
|
3382
|
+
setpgid: posix$1.setpgid,
|
|
3383
|
+
getppid: posix$1.getppid,
|
|
3384
|
+
getpwnam: posix$1.getpwnam,
|
|
3385
|
+
getrlimit: posix$1.getrlimit,
|
|
3386
|
+
setrlimit: posix$1.setrlimit,
|
|
3387
|
+
setsid: posix$1.setsid,
|
|
3388
|
+
|
|
3389
|
+
openlog: function (ident, option, facility) {
|
|
3390
|
+
return posix$1.openlog(ident, syslog_flags(option),
|
|
3391
|
+
syslog_const(facility));
|
|
3392
|
+
},
|
|
3393
|
+
|
|
3394
|
+
syslog: function (priority, message) {
|
|
3395
|
+
return posix$1.syslog(syslog_const(priority), message);
|
|
3396
|
+
},
|
|
3397
|
+
|
|
3398
|
+
setlogmask: function (maskpri) {
|
|
3399
|
+
var bits = posix$1.setlogmask(syslog_flags(maskpri, "mask_")), flags = {}, key;
|
|
3400
|
+
for (key in syslog_constants) {
|
|
3401
|
+
if (key.match("^mask_")) {
|
|
3402
|
+
flags[key.substr(5, 10)] = (bits & syslog_constants[key])
|
|
3403
|
+
? true : false;
|
|
3404
|
+
}
|
|
3405
|
+
}
|
|
3406
|
+
return flags;
|
|
3407
|
+
},
|
|
3408
|
+
|
|
3409
|
+
// http://pubs.opengroup.org/onlinepubs/007904875/functions/getpgrp.html
|
|
3410
|
+
getpgrp: function () {
|
|
3411
|
+
return posix$1.getpgid(0);
|
|
3412
|
+
},
|
|
3413
|
+
|
|
3414
|
+
seteuid: function (euid) {
|
|
3415
|
+
euid = (typeof (euid) === 'string') ? posix$1.getpwnam(euid).uid : euid;
|
|
3416
|
+
return posix$1.seteuid(euid);
|
|
3417
|
+
},
|
|
3418
|
+
|
|
3419
|
+
setreuid: function (ruid, euid) {
|
|
3420
|
+
ruid = (typeof (ruid) === 'string') ? posix$1.getpwnam(ruid).uid : ruid;
|
|
3421
|
+
euid = (typeof (euid) === 'string') ? posix$1.getpwnam(euid).uid : euid;
|
|
3422
|
+
return posix$1.setreuid(ruid, euid);
|
|
3423
|
+
},
|
|
3424
|
+
|
|
3425
|
+
setegid: function (egid) {
|
|
3426
|
+
egid = (typeof (egid) === 'string') ? posix$1.getgrnam(egid).gid : egid;
|
|
3427
|
+
return posix$1.setegid(egid);
|
|
3428
|
+
},
|
|
3429
|
+
|
|
3430
|
+
setregid: function (rgid, egid) {
|
|
3431
|
+
rgid = (typeof (rgid) === 'string') ? posix$1.getgrnam(rgid).gid : rgid;
|
|
3432
|
+
egid = (typeof (egid) === 'string') ? posix$1.getgrnam(egid).gid : egid;
|
|
3433
|
+
return posix$1.setregid(rgid, egid);
|
|
3434
|
+
},
|
|
3435
|
+
|
|
3436
|
+
gethostname: posix$1.gethostname,
|
|
3437
|
+
sethostname: posix$1.sethostname,
|
|
3438
|
+
};
|
|
3439
|
+
|
|
3440
|
+
var swap_constants = {};
|
|
3441
|
+
|
|
3442
|
+
function swap_const(value) {
|
|
3443
|
+
var constant = swap_constants[value];
|
|
3444
|
+
if (constant === undefined) {
|
|
3445
|
+
throw "invalid swap constant value: " + value;
|
|
3446
|
+
}
|
|
3447
|
+
|
|
3448
|
+
return constant;
|
|
3449
|
+
}
|
|
3450
|
+
|
|
3451
|
+
function swap_flags(option) {
|
|
3452
|
+
var opt = 0, key, flag;
|
|
3453
|
+
for (key in option) {
|
|
3454
|
+
flag = swap_const(key); // checks all flags
|
|
3455
|
+
opt |= option[key] ? flag : 0;
|
|
3456
|
+
}
|
|
3457
|
+
return opt;
|
|
3458
|
+
}
|
|
3459
|
+
|
|
3460
|
+
|
|
3461
|
+
if (IS_LINUX) {
|
|
3462
|
+
posix$1.update_swap_constants(swap_constants);
|
|
3463
|
+
posixExports.swapon = function (path, swapflags) {
|
|
3464
|
+
return posix$1.swapon(path, swap_flags(swapflags));
|
|
3465
|
+
};
|
|
3466
|
+
posixExports.swapoff = posix$1.swapoff;
|
|
3467
|
+
}
|
|
3468
|
+
|
|
3469
|
+
if ('initgroups' in posix$1) {
|
|
3470
|
+
// initgroups is in SVr4 and 4.3BSD, not POSIX
|
|
3471
|
+
posixExports.initgroups = function (user, group) {
|
|
3472
|
+
var gid = (typeof (group) === 'string') ? posix$1.getgrnam(group).gid : group;
|
|
3473
|
+
return posix$1.initgroups(user, gid);
|
|
3474
|
+
};
|
|
3475
|
+
}
|
|
3476
|
+
|
|
3477
|
+
/**
|
|
3478
|
+
* Copyright (c) 2014, 2015, 2021 Tim Kuijsten
|
|
3479
|
+
*
|
|
3480
|
+
* Permission to use, copy, modify, and/or distribute this software for any
|
|
3481
|
+
* purpose with or without fee is hereby granted, provided that the above
|
|
3482
|
+
* copyright notice and this permission notice appear in all copies.
|
|
3483
|
+
*
|
|
3484
|
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
3485
|
+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
3486
|
+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
3487
|
+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
3488
|
+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
3489
|
+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
3490
|
+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
3491
|
+
*/
|
|
3492
|
+
|
|
3493
|
+
var fs = require$$1__default["default"];
|
|
3494
|
+
var path = path__default["default"];
|
|
3495
|
+
|
|
3496
|
+
var posix = posixExports;
|
|
3497
|
+
|
|
3498
|
+
/**
|
|
3499
|
+
* Change the root directory of the current process. A normal user must be provided
|
|
3500
|
+
* since changing root without dropping privileges makes no sense from a security
|
|
3501
|
+
* point of view.
|
|
3502
|
+
*
|
|
3503
|
+
* @param {String} newRoot The path to the new root directory for this process.
|
|
3504
|
+
* The whole path should be owned by the super user and may not be writable
|
|
3505
|
+
* by the group owner or others.
|
|
3506
|
+
* @param {String|Number} user The user to switch to after changing the root
|
|
3507
|
+
* directory. Can be either a name or an id.
|
|
3508
|
+
* @param {String|Number} [group] The group to switch to after changing the root
|
|
3509
|
+
* directory. Can be either a name or an id of any group the user belongs to
|
|
3510
|
+
* (see /etc/groups). Defaults to the users primary group (see /etc/passwd).
|
|
3511
|
+
* @throw if any operation fails
|
|
3512
|
+
*/
|
|
3513
|
+
var chroot = function chroot(newRoot, user, group) {
|
|
3514
|
+
if (typeof newRoot !== 'string') { throw new TypeError('newRoot must be a string'); }
|
|
3515
|
+
if (typeof user !== 'string' && typeof user !== 'number') { throw new TypeError('user must be a string or a number'); }
|
|
3516
|
+
if (typeof group !== 'undefined') {
|
|
3517
|
+
if (typeof group !== 'string' && typeof group !== 'number') { throw new TypeError('group must be a string or a number'); }
|
|
3518
|
+
}
|
|
3519
|
+
|
|
3520
|
+
if (!(newRoot.length > 0)) { throw new Error('newRoot must contain at least one character'); }
|
|
3521
|
+
if (typeof user === 'string' && !(user.length > 0)) { throw new Error('user must contain at least one character'); }
|
|
3522
|
+
|
|
3523
|
+
if (process.getuid() !== 0 || posix.geteuid() !== 0) {
|
|
3524
|
+
throw new Error('chroot must be called while running as root');
|
|
3525
|
+
}
|
|
3526
|
+
|
|
3527
|
+
var pwd, grp, uid, gid;
|
|
3528
|
+
|
|
3529
|
+
// resolve user to a numeric id
|
|
3530
|
+
try {
|
|
3531
|
+
pwd = posix.getpwnam(user);
|
|
3532
|
+
} catch(err) {
|
|
3533
|
+
throw new Error('user not found: ' + user);
|
|
3534
|
+
}
|
|
3535
|
+
|
|
3536
|
+
uid = pwd.uid;
|
|
3537
|
+
gid = pwd.gid;
|
|
3538
|
+
|
|
3539
|
+
if (typeof group !== 'undefined') {
|
|
3540
|
+
if (typeof group === 'number') {
|
|
3541
|
+
gid = group;
|
|
3542
|
+
} else {
|
|
3543
|
+
// resolve group to a numeric id
|
|
3544
|
+
try {
|
|
3545
|
+
grp = posix.getgrnam(group);
|
|
3546
|
+
} catch(err) {
|
|
3547
|
+
throw new Error('group not found: ' + group);
|
|
3548
|
+
}
|
|
3549
|
+
|
|
3550
|
+
gid = grp.gid;
|
|
3551
|
+
}
|
|
3552
|
+
}
|
|
3553
|
+
|
|
3554
|
+
|
|
3555
|
+
if (typeof uid !== 'number') { throw new TypeError('could not resolve the user to a number'); }
|
|
3556
|
+
if (typeof gid !== 'number') { throw new TypeError('could not resolve the group to a number'); }
|
|
3557
|
+
|
|
3558
|
+
if (!(uid > 0)) { throw new Error('new user can not have user id 0'); }
|
|
3559
|
+
if (!(gid > 0)) { throw new Error('new group can not have group id 0'); }
|
|
3560
|
+
|
|
3561
|
+
// check permissions up to the original root of the file system
|
|
3562
|
+
var rpath = newRoot = fs.realpathSync(newRoot);
|
|
3563
|
+
|
|
3564
|
+
var stats;
|
|
3565
|
+
do {
|
|
3566
|
+
stats = fs.statSync(rpath);
|
|
3567
|
+
if (stats.uid !== 0 || (stats.mode & (fs.constants.S_IWGRP | fs.constants.S_IWOTH)) !== 0) {
|
|
3568
|
+
throw new Error('bad chroot dir ' + rpath + ' owner: ' + stats.uid + ' or permissions: 0' + stats.mode.toString(8));
|
|
3569
|
+
}
|
|
3570
|
+
rpath = path.dirname(rpath);
|
|
3571
|
+
} while (rpath !== '/');
|
|
3572
|
+
|
|
3573
|
+
try {
|
|
3574
|
+
posix.chroot(newRoot);
|
|
3575
|
+
} catch(err) {
|
|
3576
|
+
throw new Error('changing root failed: ' + err.message);
|
|
3577
|
+
}
|
|
3578
|
+
process.chdir('/');
|
|
3579
|
+
|
|
3580
|
+
// PWD might be set in some environments and is part of POSIX
|
|
3581
|
+
if (typeof process.env.PWD !== 'undefined') {
|
|
3582
|
+
process.env.PWD = '/';
|
|
3583
|
+
}
|
|
3584
|
+
|
|
3585
|
+
try {
|
|
3586
|
+
if (typeof group === 'undefined') {
|
|
3587
|
+
// change to the given user and all the groups that it is a member of
|
|
3588
|
+
process.initgroups(uid, gid);
|
|
3589
|
+
} else {
|
|
3590
|
+
// change to the given user and the given group (not all groups the user is member of)
|
|
3591
|
+
process.setgroups([gid]);
|
|
3592
|
+
}
|
|
3593
|
+
} catch(err) {
|
|
3594
|
+
throw new Error('changing groups failed: ' + err.message);
|
|
3595
|
+
}
|
|
3596
|
+
|
|
3597
|
+
process.setgid(gid);
|
|
3598
|
+
process.setuid(uid);
|
|
3599
|
+
|
|
3600
|
+
// try to restore privileges
|
|
3601
|
+
try {
|
|
3602
|
+
posix.setreuid(-1, 0);
|
|
3603
|
+
} catch(err) {
|
|
3604
|
+
// double check real and effective ids of the user and group and supplemental groups
|
|
3605
|
+
var ids = [process.getuid(), process.getgid(), posix.geteuid(), posix.getegid()];
|
|
3606
|
+
Array.prototype.push.apply(ids, process.getgroups());
|
|
3607
|
+
|
|
3608
|
+
// if none of the ids is zero, privileges are successfully dropped
|
|
3609
|
+
if (!~ids.indexOf(0)) {
|
|
3610
|
+
// success
|
|
3611
|
+
return;
|
|
3612
|
+
}
|
|
3613
|
+
}
|
|
3614
|
+
|
|
3615
|
+
throw new Error('unable to drop privileges');
|
|
3616
|
+
};
|
|
3617
|
+
|
|
3618
|
+
var minimist = function (args, opts) {
|
|
3619
|
+
if (!opts) opts = {};
|
|
3620
|
+
|
|
3621
|
+
var flags = { bools : {}, strings : {}, unknownFn: null };
|
|
3622
|
+
|
|
3623
|
+
if (typeof opts['unknown'] === 'function') {
|
|
3624
|
+
flags.unknownFn = opts['unknown'];
|
|
3625
|
+
}
|
|
3626
|
+
|
|
3627
|
+
if (typeof opts['boolean'] === 'boolean' && opts['boolean']) {
|
|
3628
|
+
flags.allBools = true;
|
|
3629
|
+
} else {
|
|
3630
|
+
[].concat(opts['boolean']).filter(Boolean).forEach(function (key) {
|
|
3631
|
+
flags.bools[key] = true;
|
|
3632
|
+
});
|
|
3633
|
+
}
|
|
3634
|
+
|
|
3635
|
+
var aliases = {};
|
|
3636
|
+
Object.keys(opts.alias || {}).forEach(function (key) {
|
|
3637
|
+
aliases[key] = [].concat(opts.alias[key]);
|
|
3638
|
+
aliases[key].forEach(function (x) {
|
|
3639
|
+
aliases[x] = [key].concat(aliases[key].filter(function (y) {
|
|
3640
|
+
return x !== y;
|
|
3641
|
+
}));
|
|
3642
|
+
});
|
|
3643
|
+
});
|
|
3644
|
+
|
|
3645
|
+
[].concat(opts.string).filter(Boolean).forEach(function (key) {
|
|
3646
|
+
flags.strings[key] = true;
|
|
3647
|
+
if (aliases[key]) {
|
|
3648
|
+
flags.strings[aliases[key]] = true;
|
|
3649
|
+
}
|
|
3650
|
+
});
|
|
3651
|
+
|
|
3652
|
+
var defaults = opts['default'] || {};
|
|
3653
|
+
|
|
3654
|
+
var argv = { _ : [] };
|
|
3655
|
+
Object.keys(flags.bools).forEach(function (key) {
|
|
3656
|
+
setArg(key, defaults[key] === undefined ? false : defaults[key]);
|
|
3657
|
+
});
|
|
3658
|
+
|
|
3659
|
+
var notFlags = [];
|
|
3660
|
+
|
|
3661
|
+
if (args.indexOf('--') !== -1) {
|
|
3662
|
+
notFlags = args.slice(args.indexOf('--')+1);
|
|
3663
|
+
args = args.slice(0, args.indexOf('--'));
|
|
3664
|
+
}
|
|
3665
|
+
|
|
3666
|
+
function argDefined(key, arg) {
|
|
3667
|
+
return (flags.allBools && /^--[^=]+$/.test(arg)) ||
|
|
3668
|
+
flags.strings[key] || flags.bools[key] || aliases[key];
|
|
3669
|
+
}
|
|
3670
|
+
|
|
3671
|
+
function setArg (key, val, arg) {
|
|
3672
|
+
if (arg && flags.unknownFn && !argDefined(key, arg)) {
|
|
3673
|
+
if (flags.unknownFn(arg) === false) return;
|
|
3674
|
+
}
|
|
3675
|
+
|
|
3676
|
+
var value = !flags.strings[key] && isNumber(val)
|
|
3677
|
+
? Number(val) : val
|
|
3678
|
+
;
|
|
3679
|
+
setKey(argv, key.split('.'), value);
|
|
3680
|
+
|
|
3681
|
+
(aliases[key] || []).forEach(function (x) {
|
|
3682
|
+
setKey(argv, x.split('.'), value);
|
|
3683
|
+
});
|
|
3684
|
+
}
|
|
3685
|
+
|
|
3686
|
+
function setKey (obj, keys, value) {
|
|
3687
|
+
var o = obj;
|
|
3688
|
+
for (var i = 0; i < keys.length-1; i++) {
|
|
3689
|
+
var key = keys[i];
|
|
3690
|
+
if (isConstructorOrProto(o, key)) return;
|
|
3691
|
+
if (o[key] === undefined) o[key] = {};
|
|
3692
|
+
if (o[key] === Object.prototype || o[key] === Number.prototype
|
|
3693
|
+
|| o[key] === String.prototype) o[key] = {};
|
|
3694
|
+
if (o[key] === Array.prototype) o[key] = [];
|
|
3695
|
+
o = o[key];
|
|
3696
|
+
}
|
|
3697
|
+
|
|
3698
|
+
var key = keys[keys.length - 1];
|
|
3699
|
+
if (isConstructorOrProto(o, key)) return;
|
|
3700
|
+
if (o === Object.prototype || o === Number.prototype
|
|
3701
|
+
|| o === String.prototype) o = {};
|
|
3702
|
+
if (o === Array.prototype) o = [];
|
|
3703
|
+
if (o[key] === undefined || flags.bools[key] || typeof o[key] === 'boolean') {
|
|
3704
|
+
o[key] = value;
|
|
3705
|
+
}
|
|
3706
|
+
else if (Array.isArray(o[key])) {
|
|
3707
|
+
o[key].push(value);
|
|
3708
|
+
}
|
|
3709
|
+
else {
|
|
3710
|
+
o[key] = [ o[key], value ];
|
|
3711
|
+
}
|
|
3712
|
+
}
|
|
3713
|
+
|
|
3714
|
+
function aliasIsBoolean(key) {
|
|
3715
|
+
return aliases[key].some(function (x) {
|
|
3716
|
+
return flags.bools[x];
|
|
3717
|
+
});
|
|
3718
|
+
}
|
|
3719
|
+
|
|
3720
|
+
for (var i = 0; i < args.length; i++) {
|
|
3721
|
+
var arg = args[i];
|
|
3722
|
+
|
|
3723
|
+
if (/^--.+=/.test(arg)) {
|
|
3724
|
+
// Using [\s\S] instead of . because js doesn't support the
|
|
3725
|
+
// 'dotall' regex modifier. See:
|
|
3726
|
+
// http://stackoverflow.com/a/1068308/13216
|
|
3727
|
+
var m = arg.match(/^--([^=]+)=([\s\S]*)$/);
|
|
3728
|
+
var key = m[1];
|
|
3729
|
+
var value = m[2];
|
|
3730
|
+
if (flags.bools[key]) {
|
|
3731
|
+
value = value !== 'false';
|
|
3732
|
+
}
|
|
3733
|
+
setArg(key, value, arg);
|
|
3734
|
+
}
|
|
3735
|
+
else if (/^--no-.+/.test(arg)) {
|
|
3736
|
+
var key = arg.match(/^--no-(.+)/)[1];
|
|
3737
|
+
setArg(key, false, arg);
|
|
3738
|
+
}
|
|
3739
|
+
else if (/^--.+/.test(arg)) {
|
|
3740
|
+
var key = arg.match(/^--(.+)/)[1];
|
|
3741
|
+
var next = args[i + 1];
|
|
3742
|
+
if (next !== undefined && !/^-/.test(next)
|
|
3743
|
+
&& !flags.bools[key]
|
|
3744
|
+
&& !flags.allBools
|
|
3745
|
+
&& (aliases[key] ? !aliasIsBoolean(key) : true)) {
|
|
3746
|
+
setArg(key, next, arg);
|
|
3747
|
+
i++;
|
|
3748
|
+
}
|
|
3749
|
+
else if (/^(true|false)$/.test(next)) {
|
|
3750
|
+
setArg(key, next === 'true', arg);
|
|
3751
|
+
i++;
|
|
3752
|
+
}
|
|
3753
|
+
else {
|
|
3754
|
+
setArg(key, flags.strings[key] ? '' : true, arg);
|
|
3755
|
+
}
|
|
3756
|
+
}
|
|
3757
|
+
else if (/^-[^-]+/.test(arg)) {
|
|
3758
|
+
var letters = arg.slice(1,-1).split('');
|
|
3759
|
+
|
|
3760
|
+
var broken = false;
|
|
3761
|
+
for (var j = 0; j < letters.length; j++) {
|
|
3762
|
+
var next = arg.slice(j+2);
|
|
3763
|
+
|
|
3764
|
+
if (next === '-') {
|
|
3765
|
+
setArg(letters[j], next, arg);
|
|
3766
|
+
continue;
|
|
3767
|
+
}
|
|
3768
|
+
|
|
3769
|
+
if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) {
|
|
3770
|
+
setArg(letters[j], next.split('=')[1], arg);
|
|
3771
|
+
broken = true;
|
|
3772
|
+
break;
|
|
3773
|
+
}
|
|
3774
|
+
|
|
3775
|
+
if (/[A-Za-z]/.test(letters[j])
|
|
3776
|
+
&& /-?\d+(\.\d*)?(e-?\d+)?$/.test(next)) {
|
|
3777
|
+
setArg(letters[j], next, arg);
|
|
3778
|
+
broken = true;
|
|
3779
|
+
break;
|
|
3780
|
+
}
|
|
3781
|
+
|
|
3782
|
+
if (letters[j+1] && letters[j+1].match(/\W/)) {
|
|
3783
|
+
setArg(letters[j], arg.slice(j+2), arg);
|
|
3784
|
+
broken = true;
|
|
3785
|
+
break;
|
|
3786
|
+
}
|
|
3787
|
+
else {
|
|
3788
|
+
setArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);
|
|
3789
|
+
}
|
|
3790
|
+
}
|
|
3791
|
+
|
|
3792
|
+
var key = arg.slice(-1)[0];
|
|
3793
|
+
if (!broken && key !== '-') {
|
|
3794
|
+
if (args[i+1] && !/^(-|--)[^-]/.test(args[i+1])
|
|
3795
|
+
&& !flags.bools[key]
|
|
3796
|
+
&& (aliases[key] ? !aliasIsBoolean(key) : true)) {
|
|
3797
|
+
setArg(key, args[i+1], arg);
|
|
3798
|
+
i++;
|
|
3799
|
+
}
|
|
3800
|
+
else if (args[i+1] && /^(true|false)$/.test(args[i+1])) {
|
|
3801
|
+
setArg(key, args[i+1] === 'true', arg);
|
|
3802
|
+
i++;
|
|
3803
|
+
}
|
|
3804
|
+
else {
|
|
3805
|
+
setArg(key, flags.strings[key] ? '' : true, arg);
|
|
3806
|
+
}
|
|
3807
|
+
}
|
|
3808
|
+
}
|
|
3809
|
+
else {
|
|
3810
|
+
if (!flags.unknownFn || flags.unknownFn(arg) !== false) {
|
|
3811
|
+
argv._.push(
|
|
3812
|
+
flags.strings['_'] || !isNumber(arg) ? arg : Number(arg)
|
|
3813
|
+
);
|
|
3814
|
+
}
|
|
3815
|
+
if (opts.stopEarly) {
|
|
3816
|
+
argv._.push.apply(argv._, args.slice(i + 1));
|
|
3817
|
+
break;
|
|
3818
|
+
}
|
|
3819
|
+
}
|
|
3820
|
+
}
|
|
3821
|
+
|
|
3822
|
+
Object.keys(defaults).forEach(function (key) {
|
|
3823
|
+
if (!hasKey(argv, key.split('.'))) {
|
|
3824
|
+
setKey(argv, key.split('.'), defaults[key]);
|
|
3825
|
+
|
|
3826
|
+
(aliases[key] || []).forEach(function (x) {
|
|
3827
|
+
setKey(argv, x.split('.'), defaults[key]);
|
|
3828
|
+
});
|
|
3829
|
+
}
|
|
3830
|
+
});
|
|
3831
|
+
|
|
3832
|
+
if (opts['--']) {
|
|
3833
|
+
argv['--'] = new Array();
|
|
3834
|
+
notFlags.forEach(function(key) {
|
|
3835
|
+
argv['--'].push(key);
|
|
3836
|
+
});
|
|
3837
|
+
}
|
|
3838
|
+
else {
|
|
3839
|
+
notFlags.forEach(function(key) {
|
|
3840
|
+
argv._.push(key);
|
|
3841
|
+
});
|
|
3842
|
+
}
|
|
3843
|
+
|
|
3844
|
+
return argv;
|
|
3845
|
+
};
|
|
3846
|
+
|
|
3847
|
+
function hasKey (obj, keys) {
|
|
3848
|
+
var o = obj;
|
|
3849
|
+
keys.slice(0,-1).forEach(function (key) {
|
|
3850
|
+
o = (o[key] || {});
|
|
3851
|
+
});
|
|
3852
|
+
|
|
3853
|
+
var key = keys[keys.length - 1];
|
|
3854
|
+
return key in o;
|
|
3855
|
+
}
|
|
3856
|
+
|
|
3857
|
+
function isNumber (x) {
|
|
3858
|
+
if (typeof x === 'number') return true;
|
|
3859
|
+
if (/^0x[0-9a-f]+$/i.test(x)) return true;
|
|
3860
|
+
return /^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(x);
|
|
3861
|
+
}
|
|
3862
|
+
|
|
3863
|
+
|
|
3864
|
+
function isConstructorOrProto (obj, key) {
|
|
3865
|
+
return key === 'constructor' && typeof obj[key] === 'function' || key === '__proto__';
|
|
3866
|
+
}
|
|
3867
|
+
|
|
3868
|
+
const argv = minimist(process.argv.slice(2));
|
|
3869
|
+
function send(message) {
|
|
3870
|
+
try {
|
|
3871
|
+
assert__default["default"](process.send, "Must have process.send");
|
|
3872
|
+
process.send(message);
|
|
3873
|
+
}
|
|
3874
|
+
catch (err) {
|
|
3875
|
+
console.error(`Couldn't send message ${message.type}. Going down`, err);
|
|
3876
|
+
process.exit();
|
|
3877
|
+
}
|
|
3878
|
+
}
|
|
3879
|
+
process.on("unhandledRejection", (reason, p) => {
|
|
3880
|
+
send({ type: "error", message: `Unhandled rejection at: Promise ${p} reason: ${reason === null || reason === void 0 ? void 0 : reason.stack}` });
|
|
3881
|
+
console.error("Unhandled rejection at: Promise", p, "reason:", reason === null || reason === void 0 ? void 0 : reason.stack);
|
|
3882
|
+
});
|
|
3883
|
+
process.on("uncaughtException", (err) => {
|
|
3884
|
+
send({ type: "error", message: `Uncaught exception ${err.stack} ${err.toString()}` });
|
|
3885
|
+
console.error("Uncaught exception", err);
|
|
3886
|
+
});
|
|
3887
|
+
// let pwd;
|
|
3888
|
+
try {
|
|
3889
|
+
console.log("Chrooting to", argv.root);
|
|
3890
|
+
chroot(argv.root, argv.user || "root");
|
|
3891
|
+
}
|
|
3892
|
+
catch (err) {
|
|
3893
|
+
console.error("Changing root or user failed", err);
|
|
3894
|
+
process.exit(1);
|
|
3895
|
+
}
|
|
3896
|
+
// if (pwd) {
|
|
3897
|
+
// process.setgid(pwd.gid);
|
|
3898
|
+
// process.setuid(pwd.uid);
|
|
3899
|
+
// }
|
|
3900
|
+
process.on("error", (error) => {
|
|
3901
|
+
console.error(`Got process error ${error} ${JSON.stringify(argv)}. Going down`);
|
|
3902
|
+
process.exit();
|
|
3903
|
+
});
|
|
3904
|
+
const libDirs = [];
|
|
3905
|
+
const mac = require$$1__default$1["default"].type() === "Darwin";
|
|
3906
|
+
function isLibrary(file) {
|
|
3907
|
+
if (file === "ld.so.conf" || file === "ld.so.cache") {
|
|
3908
|
+
return false;
|
|
3909
|
+
}
|
|
3910
|
+
const suffix = path__default["default"].extname(file);
|
|
3911
|
+
if (mac) {
|
|
3912
|
+
return suffix === ".dylib";
|
|
3913
|
+
}
|
|
3914
|
+
// console.log("got file", suffix, file);
|
|
3915
|
+
if (suffix === ".so") {
|
|
3916
|
+
return true;
|
|
3917
|
+
}
|
|
3918
|
+
return file.indexOf(".so.") !== -1;
|
|
3919
|
+
}
|
|
3920
|
+
function findLibraries(dir) {
|
|
3921
|
+
const files = require$$1__default["default"].readdirSync(dir);
|
|
3922
|
+
// console.log("findLibraries", dir, files.length);
|
|
3923
|
+
let found = false;
|
|
3924
|
+
files.forEach((file) => {
|
|
3925
|
+
let stat;
|
|
3926
|
+
try {
|
|
3927
|
+
stat = require$$1__default["default"].statSync(path__default["default"].join(dir, file));
|
|
3928
|
+
}
|
|
3929
|
+
catch (err) {
|
|
3930
|
+
console.error("Got error", err);
|
|
3931
|
+
return;
|
|
3932
|
+
}
|
|
3933
|
+
if (stat.isDirectory()) {
|
|
3934
|
+
findLibraries(path__default["default"].join(dir, file));
|
|
3935
|
+
}
|
|
3936
|
+
else if (!found && stat.isFile() && isLibrary(file)) {
|
|
3937
|
+
found = true;
|
|
3938
|
+
libDirs.push(dir);
|
|
3939
|
+
}
|
|
3940
|
+
});
|
|
3941
|
+
}
|
|
3942
|
+
findLibraries("/");
|
|
3943
|
+
if (argv.debug) {
|
|
3944
|
+
console.log("Got lib directories", argv.root, libDirs);
|
|
3945
|
+
}
|
|
3946
|
+
if (libDirs.length) {
|
|
3947
|
+
process.env[mac ? "DYLD_LIBRARY_PATH" : "LD_LIBRARY_PATH"] = libDirs.join(":");
|
|
3948
|
+
}
|
|
3949
|
+
setTimeout(() => {
|
|
3950
|
+
// hack
|
|
3951
|
+
try {
|
|
3952
|
+
send({ type: "ready" });
|
|
3953
|
+
}
|
|
3954
|
+
catch (err) {
|
|
3955
|
+
console.error("Couldn't send ready. Going down");
|
|
3956
|
+
process.exit();
|
|
3957
|
+
}
|
|
3958
|
+
}, 1000);
|
|
3959
|
+
const compiles = new Map();
|
|
3960
|
+
let destroying = false;
|
|
3961
|
+
process.on("message", (msg) => {
|
|
3962
|
+
switch (msg.type) {
|
|
3963
|
+
case "destroy":
|
|
3964
|
+
if (!compiles.size) {
|
|
3965
|
+
process.exit();
|
|
3966
|
+
}
|
|
3967
|
+
else {
|
|
3968
|
+
destroying = true;
|
|
3969
|
+
}
|
|
3970
|
+
break;
|
|
3971
|
+
case "setDebug":
|
|
3972
|
+
if (msg.debug) {
|
|
3973
|
+
argv.debug = true;
|
|
3974
|
+
}
|
|
3975
|
+
else {
|
|
3976
|
+
delete argv.debug;
|
|
3977
|
+
}
|
|
3978
|
+
console.log("set debug to", msg.debug, "for", argv.root);
|
|
3979
|
+
break;
|
|
3980
|
+
case "cancel": {
|
|
3981
|
+
const c = compiles.get(msg.id);
|
|
3982
|
+
if (c) {
|
|
3983
|
+
c.kill();
|
|
3984
|
+
}
|
|
3985
|
+
break;
|
|
3986
|
+
}
|
|
3987
|
+
case "compile":
|
|
3988
|
+
try {
|
|
3989
|
+
// console.log("compiling for );
|
|
3990
|
+
if (argv.debug) {
|
|
3991
|
+
console.log("Creating new compile", msg.commandLine, msg.argv0, msg.dir);
|
|
3992
|
+
}
|
|
3993
|
+
const compile = new Compile(msg.commandLine, msg.argv0, msg.dir, argv.debug);
|
|
3994
|
+
// console.log("running thing", msg.commandLine);
|
|
3995
|
+
compile.on("stdout", (data) => send({ type: "compileStdOut", id: msg.id, data: data }));
|
|
3996
|
+
compile.on("stderr", (data) => send({ type: "compileStdErr", id: msg.id, data: data }));
|
|
3997
|
+
compile.on("exit", (event) => {
|
|
3998
|
+
compiles.delete(msg.id);
|
|
3999
|
+
if ("error" in event) {
|
|
4000
|
+
send({
|
|
4001
|
+
type: "compileFinished",
|
|
4002
|
+
success: false,
|
|
4003
|
+
error: event.error,
|
|
4004
|
+
id: msg.id,
|
|
4005
|
+
files: event.files,
|
|
4006
|
+
exitCode: event.exitCode,
|
|
4007
|
+
sourceFile: event.sourceFile
|
|
4008
|
+
});
|
|
4009
|
+
}
|
|
4010
|
+
else {
|
|
4011
|
+
send({
|
|
4012
|
+
type: "compileFinished",
|
|
4013
|
+
success: true,
|
|
4014
|
+
id: msg.id,
|
|
4015
|
+
files: event.files,
|
|
4016
|
+
exitCode: event.exitCode,
|
|
4017
|
+
sourceFile: event.sourceFile
|
|
4018
|
+
});
|
|
4019
|
+
}
|
|
4020
|
+
if (destroying && !compiles.size) {
|
|
4021
|
+
process.exit();
|
|
4022
|
+
}
|
|
4023
|
+
});
|
|
4024
|
+
compiles.set(msg.id, compile);
|
|
4025
|
+
}
|
|
4026
|
+
catch (err) {
|
|
4027
|
+
compiles.delete(msg.id);
|
|
4028
|
+
send({
|
|
4029
|
+
type: "compileFinished",
|
|
4030
|
+
success: false,
|
|
4031
|
+
id: msg.id,
|
|
4032
|
+
files: [],
|
|
4033
|
+
exitCode: -1,
|
|
4034
|
+
error: err.toString()
|
|
4035
|
+
});
|
|
4036
|
+
}
|
|
4037
|
+
break;
|
|
4038
|
+
}
|
|
4039
|
+
});
|
|
4040
|
+
//# sourceMappingURL=VM_runtime.js.map
|