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