@markw65/monkeyc-optimizer 1.0.9 → 1.0.10
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/README.md +8 -0
- package/build/api.cjs +26 -26
- package/build/optimizer.cjs +3364 -200
- package/build/sdk-util.cjs +3 -3
- package/build/util.cjs +0 -1
- package/package.json +3 -2
package/build/optimizer.cjs
CHANGED
|
@@ -2,6 +2,782 @@
|
|
|
2
2
|
/******/ (() => { // webpackBootstrap
|
|
3
3
|
/******/ var __webpack_modules__ = ({
|
|
4
4
|
|
|
5
|
+
/***/ 2779:
|
|
6
|
+
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
7
|
+
|
|
8
|
+
var Buffer = (__webpack_require__(871).Buffer);
|
|
9
|
+
|
|
10
|
+
var CRC_TABLE = [
|
|
11
|
+
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
|
|
12
|
+
0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
|
|
13
|
+
0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
|
|
14
|
+
0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
|
|
15
|
+
0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
|
|
16
|
+
0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
|
|
17
|
+
0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
|
|
18
|
+
0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
|
|
19
|
+
0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
|
|
20
|
+
0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
|
|
21
|
+
0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
|
|
22
|
+
0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
|
|
23
|
+
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
|
|
24
|
+
0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
|
|
25
|
+
0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
|
|
26
|
+
0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
|
|
27
|
+
0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
|
|
28
|
+
0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
|
|
29
|
+
0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
|
|
30
|
+
0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
|
|
31
|
+
0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
|
|
32
|
+
0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
|
|
33
|
+
0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
|
|
34
|
+
0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
|
|
35
|
+
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
|
|
36
|
+
0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
|
|
37
|
+
0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
|
|
38
|
+
0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
|
|
39
|
+
0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
|
|
40
|
+
0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
|
|
41
|
+
0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
|
|
42
|
+
0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
|
|
43
|
+
0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
|
|
44
|
+
0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
|
|
45
|
+
0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
|
|
46
|
+
0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
|
|
47
|
+
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
|
|
48
|
+
0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
|
|
49
|
+
0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
|
|
50
|
+
0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
|
|
51
|
+
0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
|
|
52
|
+
0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
|
|
53
|
+
0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
|
|
54
|
+
0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
|
|
55
|
+
0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
|
|
56
|
+
0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
|
|
57
|
+
0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
|
|
58
|
+
0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
|
|
59
|
+
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
|
|
60
|
+
0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
|
|
61
|
+
0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
|
|
62
|
+
0x2d02ef8d
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
if (typeof Int32Array !== 'undefined') {
|
|
66
|
+
CRC_TABLE = new Int32Array(CRC_TABLE);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function ensureBuffer(input) {
|
|
70
|
+
if (Buffer.isBuffer(input)) {
|
|
71
|
+
return input;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
var hasNewBufferAPI =
|
|
75
|
+
typeof Buffer.alloc === "function" &&
|
|
76
|
+
typeof Buffer.from === "function";
|
|
77
|
+
|
|
78
|
+
if (typeof input === "number") {
|
|
79
|
+
return hasNewBufferAPI ? Buffer.alloc(input) : new Buffer(input);
|
|
80
|
+
}
|
|
81
|
+
else if (typeof input === "string") {
|
|
82
|
+
return hasNewBufferAPI ? Buffer.from(input) : new Buffer(input);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
throw new Error("input must be buffer, number, or string, received " +
|
|
86
|
+
typeof input);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function bufferizeInt(num) {
|
|
91
|
+
var tmp = ensureBuffer(4);
|
|
92
|
+
tmp.writeInt32BE(num, 0);
|
|
93
|
+
return tmp;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function _crc32(buf, previous) {
|
|
97
|
+
buf = ensureBuffer(buf);
|
|
98
|
+
if (Buffer.isBuffer(previous)) {
|
|
99
|
+
previous = previous.readUInt32BE(0);
|
|
100
|
+
}
|
|
101
|
+
var crc = ~~previous ^ -1;
|
|
102
|
+
for (var n = 0; n < buf.length; n++) {
|
|
103
|
+
crc = CRC_TABLE[(crc ^ buf[n]) & 0xff] ^ (crc >>> 8);
|
|
104
|
+
}
|
|
105
|
+
return (crc ^ -1);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function crc32() {
|
|
109
|
+
return bufferizeInt(_crc32.apply(null, arguments));
|
|
110
|
+
}
|
|
111
|
+
crc32.signed = function () {
|
|
112
|
+
return _crc32.apply(null, arguments);
|
|
113
|
+
};
|
|
114
|
+
crc32.unsigned = function () {
|
|
115
|
+
return _crc32.apply(null, arguments) >>> 0;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
module.exports = crc32;
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
/***/ }),
|
|
122
|
+
|
|
123
|
+
/***/ 1227:
|
|
124
|
+
/***/ ((module, exports, __webpack_require__) => {
|
|
125
|
+
|
|
126
|
+
/* eslint-env browser */
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* This is the web browser implementation of `debug()`.
|
|
130
|
+
*/
|
|
131
|
+
|
|
132
|
+
exports.formatArgs = formatArgs;
|
|
133
|
+
exports.save = save;
|
|
134
|
+
exports.load = load;
|
|
135
|
+
exports.useColors = useColors;
|
|
136
|
+
exports.storage = localstorage();
|
|
137
|
+
exports.destroy = (() => {
|
|
138
|
+
let warned = false;
|
|
139
|
+
|
|
140
|
+
return () => {
|
|
141
|
+
if (!warned) {
|
|
142
|
+
warned = true;
|
|
143
|
+
console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
})();
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Colors.
|
|
150
|
+
*/
|
|
151
|
+
|
|
152
|
+
exports.colors = [
|
|
153
|
+
'#0000CC',
|
|
154
|
+
'#0000FF',
|
|
155
|
+
'#0033CC',
|
|
156
|
+
'#0033FF',
|
|
157
|
+
'#0066CC',
|
|
158
|
+
'#0066FF',
|
|
159
|
+
'#0099CC',
|
|
160
|
+
'#0099FF',
|
|
161
|
+
'#00CC00',
|
|
162
|
+
'#00CC33',
|
|
163
|
+
'#00CC66',
|
|
164
|
+
'#00CC99',
|
|
165
|
+
'#00CCCC',
|
|
166
|
+
'#00CCFF',
|
|
167
|
+
'#3300CC',
|
|
168
|
+
'#3300FF',
|
|
169
|
+
'#3333CC',
|
|
170
|
+
'#3333FF',
|
|
171
|
+
'#3366CC',
|
|
172
|
+
'#3366FF',
|
|
173
|
+
'#3399CC',
|
|
174
|
+
'#3399FF',
|
|
175
|
+
'#33CC00',
|
|
176
|
+
'#33CC33',
|
|
177
|
+
'#33CC66',
|
|
178
|
+
'#33CC99',
|
|
179
|
+
'#33CCCC',
|
|
180
|
+
'#33CCFF',
|
|
181
|
+
'#6600CC',
|
|
182
|
+
'#6600FF',
|
|
183
|
+
'#6633CC',
|
|
184
|
+
'#6633FF',
|
|
185
|
+
'#66CC00',
|
|
186
|
+
'#66CC33',
|
|
187
|
+
'#9900CC',
|
|
188
|
+
'#9900FF',
|
|
189
|
+
'#9933CC',
|
|
190
|
+
'#9933FF',
|
|
191
|
+
'#99CC00',
|
|
192
|
+
'#99CC33',
|
|
193
|
+
'#CC0000',
|
|
194
|
+
'#CC0033',
|
|
195
|
+
'#CC0066',
|
|
196
|
+
'#CC0099',
|
|
197
|
+
'#CC00CC',
|
|
198
|
+
'#CC00FF',
|
|
199
|
+
'#CC3300',
|
|
200
|
+
'#CC3333',
|
|
201
|
+
'#CC3366',
|
|
202
|
+
'#CC3399',
|
|
203
|
+
'#CC33CC',
|
|
204
|
+
'#CC33FF',
|
|
205
|
+
'#CC6600',
|
|
206
|
+
'#CC6633',
|
|
207
|
+
'#CC9900',
|
|
208
|
+
'#CC9933',
|
|
209
|
+
'#CCCC00',
|
|
210
|
+
'#CCCC33',
|
|
211
|
+
'#FF0000',
|
|
212
|
+
'#FF0033',
|
|
213
|
+
'#FF0066',
|
|
214
|
+
'#FF0099',
|
|
215
|
+
'#FF00CC',
|
|
216
|
+
'#FF00FF',
|
|
217
|
+
'#FF3300',
|
|
218
|
+
'#FF3333',
|
|
219
|
+
'#FF3366',
|
|
220
|
+
'#FF3399',
|
|
221
|
+
'#FF33CC',
|
|
222
|
+
'#FF33FF',
|
|
223
|
+
'#FF6600',
|
|
224
|
+
'#FF6633',
|
|
225
|
+
'#FF9900',
|
|
226
|
+
'#FF9933',
|
|
227
|
+
'#FFCC00',
|
|
228
|
+
'#FFCC33'
|
|
229
|
+
];
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Currently only WebKit-based Web Inspectors, Firefox >= v31,
|
|
233
|
+
* and the Firebug extension (any Firefox version) are known
|
|
234
|
+
* to support "%c" CSS customizations.
|
|
235
|
+
*
|
|
236
|
+
* TODO: add a `localStorage` variable to explicitly enable/disable colors
|
|
237
|
+
*/
|
|
238
|
+
|
|
239
|
+
// eslint-disable-next-line complexity
|
|
240
|
+
function useColors() {
|
|
241
|
+
// NB: In an Electron preload script, document will be defined but not fully
|
|
242
|
+
// initialized. Since we know we're in Chrome, we'll just detect this case
|
|
243
|
+
// explicitly
|
|
244
|
+
if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
|
|
245
|
+
return true;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// Internet Explorer and Edge do not support colors.
|
|
249
|
+
if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// Is webkit? http://stackoverflow.com/a/16459606/376773
|
|
254
|
+
// document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
|
|
255
|
+
return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
|
|
256
|
+
// Is firebug? http://stackoverflow.com/a/398120/376773
|
|
257
|
+
(typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
|
|
258
|
+
// Is firefox >= v31?
|
|
259
|
+
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
|
|
260
|
+
(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
|
|
261
|
+
// Double check webkit in userAgent just in case we are in a worker
|
|
262
|
+
(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Colorize log arguments if enabled.
|
|
267
|
+
*
|
|
268
|
+
* @api public
|
|
269
|
+
*/
|
|
270
|
+
|
|
271
|
+
function formatArgs(args) {
|
|
272
|
+
args[0] = (this.useColors ? '%c' : '') +
|
|
273
|
+
this.namespace +
|
|
274
|
+
(this.useColors ? ' %c' : ' ') +
|
|
275
|
+
args[0] +
|
|
276
|
+
(this.useColors ? '%c ' : ' ') +
|
|
277
|
+
'+' + module.exports.humanize(this.diff);
|
|
278
|
+
|
|
279
|
+
if (!this.useColors) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const c = 'color: ' + this.color;
|
|
284
|
+
args.splice(1, 0, c, 'color: inherit');
|
|
285
|
+
|
|
286
|
+
// The final "%c" is somewhat tricky, because there could be other
|
|
287
|
+
// arguments passed either before or after the %c, so we need to
|
|
288
|
+
// figure out the correct index to insert the CSS into
|
|
289
|
+
let index = 0;
|
|
290
|
+
let lastC = 0;
|
|
291
|
+
args[0].replace(/%[a-zA-Z%]/g, match => {
|
|
292
|
+
if (match === '%%') {
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
index++;
|
|
296
|
+
if (match === '%c') {
|
|
297
|
+
// We only are interested in the *last* %c
|
|
298
|
+
// (the user may have provided their own)
|
|
299
|
+
lastC = index;
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
args.splice(lastC, 0, c);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Invokes `console.debug()` when available.
|
|
308
|
+
* No-op when `console.debug` is not a "function".
|
|
309
|
+
* If `console.debug` is not available, falls back
|
|
310
|
+
* to `console.log`.
|
|
311
|
+
*
|
|
312
|
+
* @api public
|
|
313
|
+
*/
|
|
314
|
+
exports.log = console.debug || console.log || (() => {});
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Save `namespaces`.
|
|
318
|
+
*
|
|
319
|
+
* @param {String} namespaces
|
|
320
|
+
* @api private
|
|
321
|
+
*/
|
|
322
|
+
function save(namespaces) {
|
|
323
|
+
try {
|
|
324
|
+
if (namespaces) {
|
|
325
|
+
exports.storage.setItem('debug', namespaces);
|
|
326
|
+
} else {
|
|
327
|
+
exports.storage.removeItem('debug');
|
|
328
|
+
}
|
|
329
|
+
} catch (error) {
|
|
330
|
+
// Swallow
|
|
331
|
+
// XXX (@Qix-) should we be logging these?
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Load `namespaces`.
|
|
337
|
+
*
|
|
338
|
+
* @return {String} returns the previously persisted debug modes
|
|
339
|
+
* @api private
|
|
340
|
+
*/
|
|
341
|
+
function load() {
|
|
342
|
+
let r;
|
|
343
|
+
try {
|
|
344
|
+
r = exports.storage.getItem('debug');
|
|
345
|
+
} catch (error) {
|
|
346
|
+
// Swallow
|
|
347
|
+
// XXX (@Qix-) should we be logging these?
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// If debug isn't set in LS, and we're in Electron, try to load $DEBUG
|
|
351
|
+
if (!r && typeof process !== 'undefined' && 'env' in process) {
|
|
352
|
+
r = process.env.DEBUG;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
return r;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Localstorage attempts to return the localstorage.
|
|
360
|
+
*
|
|
361
|
+
* This is necessary because safari throws
|
|
362
|
+
* when a user disables cookies/localstorage
|
|
363
|
+
* and you attempt to access it.
|
|
364
|
+
*
|
|
365
|
+
* @return {LocalStorage}
|
|
366
|
+
* @api private
|
|
367
|
+
*/
|
|
368
|
+
|
|
369
|
+
function localstorage() {
|
|
370
|
+
try {
|
|
371
|
+
// TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
|
|
372
|
+
// The Browser also has localStorage in the global context.
|
|
373
|
+
return localStorage;
|
|
374
|
+
} catch (error) {
|
|
375
|
+
// Swallow
|
|
376
|
+
// XXX (@Qix-) should we be logging these?
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
module.exports = __webpack_require__(2447)(exports);
|
|
381
|
+
|
|
382
|
+
const {formatters} = module.exports;
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
|
|
386
|
+
*/
|
|
387
|
+
|
|
388
|
+
formatters.j = function (v) {
|
|
389
|
+
try {
|
|
390
|
+
return JSON.stringify(v);
|
|
391
|
+
} catch (error) {
|
|
392
|
+
return '[UnexpectedJSONParseError]: ' + error.message;
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
/***/ }),
|
|
398
|
+
|
|
399
|
+
/***/ 2447:
|
|
400
|
+
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* This is the common logic for both the Node.js and web browser
|
|
405
|
+
* implementations of `debug()`.
|
|
406
|
+
*/
|
|
407
|
+
|
|
408
|
+
function setup(env) {
|
|
409
|
+
createDebug.debug = createDebug;
|
|
410
|
+
createDebug.default = createDebug;
|
|
411
|
+
createDebug.coerce = coerce;
|
|
412
|
+
createDebug.disable = disable;
|
|
413
|
+
createDebug.enable = enable;
|
|
414
|
+
createDebug.enabled = enabled;
|
|
415
|
+
createDebug.humanize = __webpack_require__(7824);
|
|
416
|
+
createDebug.destroy = destroy;
|
|
417
|
+
|
|
418
|
+
Object.keys(env).forEach(key => {
|
|
419
|
+
createDebug[key] = env[key];
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* The currently active debug mode names, and names to skip.
|
|
424
|
+
*/
|
|
425
|
+
|
|
426
|
+
createDebug.names = [];
|
|
427
|
+
createDebug.skips = [];
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Map of special "%n" handling functions, for the debug "format" argument.
|
|
431
|
+
*
|
|
432
|
+
* Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
|
|
433
|
+
*/
|
|
434
|
+
createDebug.formatters = {};
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Selects a color for a debug namespace
|
|
438
|
+
* @param {String} namespace The namespace string for the debug instance to be colored
|
|
439
|
+
* @return {Number|String} An ANSI color code for the given namespace
|
|
440
|
+
* @api private
|
|
441
|
+
*/
|
|
442
|
+
function selectColor(namespace) {
|
|
443
|
+
let hash = 0;
|
|
444
|
+
|
|
445
|
+
for (let i = 0; i < namespace.length; i++) {
|
|
446
|
+
hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
|
|
447
|
+
hash |= 0; // Convert to 32bit integer
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
|
|
451
|
+
}
|
|
452
|
+
createDebug.selectColor = selectColor;
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Create a debugger with the given `namespace`.
|
|
456
|
+
*
|
|
457
|
+
* @param {String} namespace
|
|
458
|
+
* @return {Function}
|
|
459
|
+
* @api public
|
|
460
|
+
*/
|
|
461
|
+
function createDebug(namespace) {
|
|
462
|
+
let prevTime;
|
|
463
|
+
let enableOverride = null;
|
|
464
|
+
let namespacesCache;
|
|
465
|
+
let enabledCache;
|
|
466
|
+
|
|
467
|
+
function debug(...args) {
|
|
468
|
+
// Disabled?
|
|
469
|
+
if (!debug.enabled) {
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
const self = debug;
|
|
474
|
+
|
|
475
|
+
// Set `diff` timestamp
|
|
476
|
+
const curr = Number(new Date());
|
|
477
|
+
const ms = curr - (prevTime || curr);
|
|
478
|
+
self.diff = ms;
|
|
479
|
+
self.prev = prevTime;
|
|
480
|
+
self.curr = curr;
|
|
481
|
+
prevTime = curr;
|
|
482
|
+
|
|
483
|
+
args[0] = createDebug.coerce(args[0]);
|
|
484
|
+
|
|
485
|
+
if (typeof args[0] !== 'string') {
|
|
486
|
+
// Anything else let's inspect with %O
|
|
487
|
+
args.unshift('%O');
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
// Apply any `formatters` transformations
|
|
491
|
+
let index = 0;
|
|
492
|
+
args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
|
|
493
|
+
// If we encounter an escaped % then don't increase the array index
|
|
494
|
+
if (match === '%%') {
|
|
495
|
+
return '%';
|
|
496
|
+
}
|
|
497
|
+
index++;
|
|
498
|
+
const formatter = createDebug.formatters[format];
|
|
499
|
+
if (typeof formatter === 'function') {
|
|
500
|
+
const val = args[index];
|
|
501
|
+
match = formatter.call(self, val);
|
|
502
|
+
|
|
503
|
+
// Now we need to remove `args[index]` since it's inlined in the `format`
|
|
504
|
+
args.splice(index, 1);
|
|
505
|
+
index--;
|
|
506
|
+
}
|
|
507
|
+
return match;
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
// Apply env-specific formatting (colors, etc.)
|
|
511
|
+
createDebug.formatArgs.call(self, args);
|
|
512
|
+
|
|
513
|
+
const logFn = self.log || createDebug.log;
|
|
514
|
+
logFn.apply(self, args);
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
debug.namespace = namespace;
|
|
518
|
+
debug.useColors = createDebug.useColors();
|
|
519
|
+
debug.color = createDebug.selectColor(namespace);
|
|
520
|
+
debug.extend = extend;
|
|
521
|
+
debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release.
|
|
522
|
+
|
|
523
|
+
Object.defineProperty(debug, 'enabled', {
|
|
524
|
+
enumerable: true,
|
|
525
|
+
configurable: false,
|
|
526
|
+
get: () => {
|
|
527
|
+
if (enableOverride !== null) {
|
|
528
|
+
return enableOverride;
|
|
529
|
+
}
|
|
530
|
+
if (namespacesCache !== createDebug.namespaces) {
|
|
531
|
+
namespacesCache = createDebug.namespaces;
|
|
532
|
+
enabledCache = createDebug.enabled(namespace);
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
return enabledCache;
|
|
536
|
+
},
|
|
537
|
+
set: v => {
|
|
538
|
+
enableOverride = v;
|
|
539
|
+
}
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
// Env-specific initialization logic for debug instances
|
|
543
|
+
if (typeof createDebug.init === 'function') {
|
|
544
|
+
createDebug.init(debug);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
return debug;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
function extend(namespace, delimiter) {
|
|
551
|
+
const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
|
|
552
|
+
newDebug.log = this.log;
|
|
553
|
+
return newDebug;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* Enables a debug mode by namespaces. This can include modes
|
|
558
|
+
* separated by a colon and wildcards.
|
|
559
|
+
*
|
|
560
|
+
* @param {String} namespaces
|
|
561
|
+
* @api public
|
|
562
|
+
*/
|
|
563
|
+
function enable(namespaces) {
|
|
564
|
+
createDebug.save(namespaces);
|
|
565
|
+
createDebug.namespaces = namespaces;
|
|
566
|
+
|
|
567
|
+
createDebug.names = [];
|
|
568
|
+
createDebug.skips = [];
|
|
569
|
+
|
|
570
|
+
let i;
|
|
571
|
+
const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
|
|
572
|
+
const len = split.length;
|
|
573
|
+
|
|
574
|
+
for (i = 0; i < len; i++) {
|
|
575
|
+
if (!split[i]) {
|
|
576
|
+
// ignore empty strings
|
|
577
|
+
continue;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
namespaces = split[i].replace(/\*/g, '.*?');
|
|
581
|
+
|
|
582
|
+
if (namespaces[0] === '-') {
|
|
583
|
+
createDebug.skips.push(new RegExp('^' + namespaces.slice(1) + '$'));
|
|
584
|
+
} else {
|
|
585
|
+
createDebug.names.push(new RegExp('^' + namespaces + '$'));
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
/**
|
|
591
|
+
* Disable debug output.
|
|
592
|
+
*
|
|
593
|
+
* @return {String} namespaces
|
|
594
|
+
* @api public
|
|
595
|
+
*/
|
|
596
|
+
function disable() {
|
|
597
|
+
const namespaces = [
|
|
598
|
+
...createDebug.names.map(toNamespace),
|
|
599
|
+
...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace)
|
|
600
|
+
].join(',');
|
|
601
|
+
createDebug.enable('');
|
|
602
|
+
return namespaces;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
/**
|
|
606
|
+
* Returns true if the given mode name is enabled, false otherwise.
|
|
607
|
+
*
|
|
608
|
+
* @param {String} name
|
|
609
|
+
* @return {Boolean}
|
|
610
|
+
* @api public
|
|
611
|
+
*/
|
|
612
|
+
function enabled(name) {
|
|
613
|
+
if (name[name.length - 1] === '*') {
|
|
614
|
+
return true;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
let i;
|
|
618
|
+
let len;
|
|
619
|
+
|
|
620
|
+
for (i = 0, len = createDebug.skips.length; i < len; i++) {
|
|
621
|
+
if (createDebug.skips[i].test(name)) {
|
|
622
|
+
return false;
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
for (i = 0, len = createDebug.names.length; i < len; i++) {
|
|
627
|
+
if (createDebug.names[i].test(name)) {
|
|
628
|
+
return true;
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
return false;
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
/**
|
|
636
|
+
* Convert regexp to namespace
|
|
637
|
+
*
|
|
638
|
+
* @param {RegExp} regxep
|
|
639
|
+
* @return {String} namespace
|
|
640
|
+
* @api private
|
|
641
|
+
*/
|
|
642
|
+
function toNamespace(regexp) {
|
|
643
|
+
return regexp.toString()
|
|
644
|
+
.substring(2, regexp.toString().length - 2)
|
|
645
|
+
.replace(/\.\*\?$/, '*');
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
/**
|
|
649
|
+
* Coerce `val`.
|
|
650
|
+
*
|
|
651
|
+
* @param {Mixed} val
|
|
652
|
+
* @return {Mixed}
|
|
653
|
+
* @api private
|
|
654
|
+
*/
|
|
655
|
+
function coerce(val) {
|
|
656
|
+
if (val instanceof Error) {
|
|
657
|
+
return val.stack || val.message;
|
|
658
|
+
}
|
|
659
|
+
return val;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
/**
|
|
663
|
+
* XXX DO NOT USE. This is a temporary stub function.
|
|
664
|
+
* XXX It WILL be removed in the next major release.
|
|
665
|
+
*/
|
|
666
|
+
function destroy() {
|
|
667
|
+
console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
createDebug.enable(createDebug.load());
|
|
671
|
+
|
|
672
|
+
return createDebug;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
module.exports = setup;
|
|
676
|
+
|
|
677
|
+
|
|
678
|
+
/***/ }),
|
|
679
|
+
|
|
680
|
+
/***/ 2840:
|
|
681
|
+
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
682
|
+
|
|
683
|
+
var once = __webpack_require__(778);
|
|
684
|
+
|
|
685
|
+
var noop = function() {};
|
|
686
|
+
|
|
687
|
+
var isRequest = function(stream) {
|
|
688
|
+
return stream.setHeader && typeof stream.abort === 'function';
|
|
689
|
+
};
|
|
690
|
+
|
|
691
|
+
var isChildProcess = function(stream) {
|
|
692
|
+
return stream.stdio && Array.isArray(stream.stdio) && stream.stdio.length === 3
|
|
693
|
+
};
|
|
694
|
+
|
|
695
|
+
var eos = function(stream, opts, callback) {
|
|
696
|
+
if (typeof opts === 'function') return eos(stream, null, opts);
|
|
697
|
+
if (!opts) opts = {};
|
|
698
|
+
|
|
699
|
+
callback = once(callback || noop);
|
|
700
|
+
|
|
701
|
+
var ws = stream._writableState;
|
|
702
|
+
var rs = stream._readableState;
|
|
703
|
+
var readable = opts.readable || (opts.readable !== false && stream.readable);
|
|
704
|
+
var writable = opts.writable || (opts.writable !== false && stream.writable);
|
|
705
|
+
var cancelled = false;
|
|
706
|
+
|
|
707
|
+
var onlegacyfinish = function() {
|
|
708
|
+
if (!stream.writable) onfinish();
|
|
709
|
+
};
|
|
710
|
+
|
|
711
|
+
var onfinish = function() {
|
|
712
|
+
writable = false;
|
|
713
|
+
if (!readable) callback.call(stream);
|
|
714
|
+
};
|
|
715
|
+
|
|
716
|
+
var onend = function() {
|
|
717
|
+
readable = false;
|
|
718
|
+
if (!writable) callback.call(stream);
|
|
719
|
+
};
|
|
720
|
+
|
|
721
|
+
var onexit = function(exitCode) {
|
|
722
|
+
callback.call(stream, exitCode ? new Error('exited with error code: ' + exitCode) : null);
|
|
723
|
+
};
|
|
724
|
+
|
|
725
|
+
var onerror = function(err) {
|
|
726
|
+
callback.call(stream, err);
|
|
727
|
+
};
|
|
728
|
+
|
|
729
|
+
var onclose = function() {
|
|
730
|
+
process.nextTick(onclosenexttick);
|
|
731
|
+
};
|
|
732
|
+
|
|
733
|
+
var onclosenexttick = function() {
|
|
734
|
+
if (cancelled) return;
|
|
735
|
+
if (readable && !(rs && (rs.ended && !rs.destroyed))) return callback.call(stream, new Error('premature close'));
|
|
736
|
+
if (writable && !(ws && (ws.ended && !ws.destroyed))) return callback.call(stream, new Error('premature close'));
|
|
737
|
+
};
|
|
738
|
+
|
|
739
|
+
var onrequest = function() {
|
|
740
|
+
stream.req.on('finish', onfinish);
|
|
741
|
+
};
|
|
742
|
+
|
|
743
|
+
if (isRequest(stream)) {
|
|
744
|
+
stream.on('complete', onfinish);
|
|
745
|
+
stream.on('abort', onclose);
|
|
746
|
+
if (stream.req) onrequest();
|
|
747
|
+
else stream.on('request', onrequest);
|
|
748
|
+
} else if (writable && !ws) { // legacy streams
|
|
749
|
+
stream.on('end', onlegacyfinish);
|
|
750
|
+
stream.on('close', onlegacyfinish);
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
if (isChildProcess(stream)) stream.on('exit', onexit);
|
|
754
|
+
|
|
755
|
+
stream.on('end', onend);
|
|
756
|
+
stream.on('finish', onfinish);
|
|
757
|
+
if (opts.error !== false) stream.on('error', onerror);
|
|
758
|
+
stream.on('close', onclose);
|
|
759
|
+
|
|
760
|
+
return function() {
|
|
761
|
+
cancelled = true;
|
|
762
|
+
stream.removeListener('complete', onfinish);
|
|
763
|
+
stream.removeListener('abort', onclose);
|
|
764
|
+
stream.removeListener('request', onrequest);
|
|
765
|
+
if (stream.req) stream.req.removeListener('finish', onfinish);
|
|
766
|
+
stream.removeListener('end', onlegacyfinish);
|
|
767
|
+
stream.removeListener('close', onlegacyfinish);
|
|
768
|
+
stream.removeListener('finish', onfinish);
|
|
769
|
+
stream.removeListener('exit', onexit);
|
|
770
|
+
stream.removeListener('end', onend);
|
|
771
|
+
stream.removeListener('error', onerror);
|
|
772
|
+
stream.removeListener('close', onclose);
|
|
773
|
+
};
|
|
774
|
+
};
|
|
775
|
+
|
|
776
|
+
module.exports = eos;
|
|
777
|
+
|
|
778
|
+
|
|
779
|
+
/***/ }),
|
|
780
|
+
|
|
5
781
|
/***/ 7187:
|
|
6
782
|
/***/ ((module) => {
|
|
7
783
|
|
|
@@ -461,49 +1237,1029 @@ function once(emitter, name) {
|
|
|
461
1237
|
reject(err);
|
|
462
1238
|
}
|
|
463
1239
|
|
|
464
|
-
function resolver() {
|
|
465
|
-
if (typeof emitter.removeListener === 'function') {
|
|
466
|
-
emitter.removeListener('error', errorListener);
|
|
467
|
-
}
|
|
468
|
-
resolve([].slice.call(arguments));
|
|
469
|
-
};
|
|
1240
|
+
function resolver() {
|
|
1241
|
+
if (typeof emitter.removeListener === 'function') {
|
|
1242
|
+
emitter.removeListener('error', errorListener);
|
|
1243
|
+
}
|
|
1244
|
+
resolve([].slice.call(arguments));
|
|
1245
|
+
};
|
|
1246
|
+
|
|
1247
|
+
eventTargetAgnosticAddListener(emitter, name, resolver, { once: true });
|
|
1248
|
+
if (name !== 'error') {
|
|
1249
|
+
addErrorHandlerIfEventEmitter(emitter, errorListener, { once: true });
|
|
1250
|
+
}
|
|
1251
|
+
});
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
function addErrorHandlerIfEventEmitter(emitter, handler, flags) {
|
|
1255
|
+
if (typeof emitter.on === 'function') {
|
|
1256
|
+
eventTargetAgnosticAddListener(emitter, 'error', handler, flags);
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
|
|
1261
|
+
if (typeof emitter.on === 'function') {
|
|
1262
|
+
if (flags.once) {
|
|
1263
|
+
emitter.once(name, listener);
|
|
1264
|
+
} else {
|
|
1265
|
+
emitter.on(name, listener);
|
|
1266
|
+
}
|
|
1267
|
+
} else if (typeof emitter.addEventListener === 'function') {
|
|
1268
|
+
// EventTarget does not have `error` event semantics like Node
|
|
1269
|
+
// EventEmitters, we do not listen for `error` events here.
|
|
1270
|
+
emitter.addEventListener(name, function wrapListener(arg) {
|
|
1271
|
+
// IE does not have builtin `{ once: true }` support so we
|
|
1272
|
+
// have to do it manually.
|
|
1273
|
+
if (flags.once) {
|
|
1274
|
+
emitter.removeEventListener(name, wrapListener);
|
|
1275
|
+
}
|
|
1276
|
+
listener(arg);
|
|
1277
|
+
});
|
|
1278
|
+
} else {
|
|
1279
|
+
throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof emitter);
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
|
|
1284
|
+
/***/ }),
|
|
1285
|
+
|
|
1286
|
+
/***/ 2106:
|
|
1287
|
+
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
1288
|
+
|
|
1289
|
+
const debug = __webpack_require__(1227)('extract-zip')
|
|
1290
|
+
// eslint-disable-next-line node/no-unsupported-features/node-builtins
|
|
1291
|
+
const { createWriteStream, promises: fs } = __webpack_require__(6231)
|
|
1292
|
+
const getStream = __webpack_require__(7491)
|
|
1293
|
+
const path = __webpack_require__(1423)
|
|
1294
|
+
const { promisify } = __webpack_require__(6464)
|
|
1295
|
+
const stream = __webpack_require__(8311)
|
|
1296
|
+
const yauzl = __webpack_require__(7766)
|
|
1297
|
+
|
|
1298
|
+
const openZip = promisify(yauzl.open)
|
|
1299
|
+
const pipeline = promisify(stream.pipeline)
|
|
1300
|
+
|
|
1301
|
+
class Extractor {
|
|
1302
|
+
constructor (zipPath, opts) {
|
|
1303
|
+
this.zipPath = zipPath
|
|
1304
|
+
this.opts = opts
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
async extract () {
|
|
1308
|
+
debug('opening', this.zipPath, 'with opts', this.opts)
|
|
1309
|
+
|
|
1310
|
+
this.zipfile = await openZip(this.zipPath, { lazyEntries: true })
|
|
1311
|
+
this.canceled = false
|
|
1312
|
+
|
|
1313
|
+
return new Promise((resolve, reject) => {
|
|
1314
|
+
this.zipfile.on('error', err => {
|
|
1315
|
+
this.canceled = true
|
|
1316
|
+
reject(err)
|
|
1317
|
+
})
|
|
1318
|
+
this.zipfile.readEntry()
|
|
1319
|
+
|
|
1320
|
+
this.zipfile.on('close', () => {
|
|
1321
|
+
if (!this.canceled) {
|
|
1322
|
+
debug('zip extraction complete')
|
|
1323
|
+
resolve()
|
|
1324
|
+
}
|
|
1325
|
+
})
|
|
1326
|
+
|
|
1327
|
+
this.zipfile.on('entry', async entry => {
|
|
1328
|
+
/* istanbul ignore if */
|
|
1329
|
+
if (this.canceled) {
|
|
1330
|
+
debug('skipping entry', entry.fileName, { cancelled: this.canceled })
|
|
1331
|
+
return
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1334
|
+
debug('zipfile entry', entry.fileName)
|
|
1335
|
+
|
|
1336
|
+
if (entry.fileName.startsWith('__MACOSX/')) {
|
|
1337
|
+
this.zipfile.readEntry()
|
|
1338
|
+
return
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
const destDir = path.dirname(path.join(this.opts.dir, entry.fileName))
|
|
1342
|
+
|
|
1343
|
+
try {
|
|
1344
|
+
await fs.mkdir(destDir, { recursive: true })
|
|
1345
|
+
|
|
1346
|
+
const canonicalDestDir = await fs.realpath(destDir)
|
|
1347
|
+
const relativeDestDir = path.relative(this.opts.dir, canonicalDestDir)
|
|
1348
|
+
|
|
1349
|
+
if (relativeDestDir.split(path.sep).includes('..')) {
|
|
1350
|
+
throw new Error(`Out of bound path "${canonicalDestDir}" found while processing file ${entry.fileName}`)
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1353
|
+
await this.extractEntry(entry)
|
|
1354
|
+
debug('finished processing', entry.fileName)
|
|
1355
|
+
this.zipfile.readEntry()
|
|
1356
|
+
} catch (err) {
|
|
1357
|
+
this.canceled = true
|
|
1358
|
+
this.zipfile.close()
|
|
1359
|
+
reject(err)
|
|
1360
|
+
}
|
|
1361
|
+
})
|
|
1362
|
+
})
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
async extractEntry (entry) {
|
|
1366
|
+
/* istanbul ignore if */
|
|
1367
|
+
if (this.canceled) {
|
|
1368
|
+
debug('skipping entry extraction', entry.fileName, { cancelled: this.canceled })
|
|
1369
|
+
return
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
if (this.opts.onEntry) {
|
|
1373
|
+
this.opts.onEntry(entry, this.zipfile)
|
|
1374
|
+
}
|
|
1375
|
+
|
|
1376
|
+
const dest = path.join(this.opts.dir, entry.fileName)
|
|
1377
|
+
|
|
1378
|
+
// convert external file attr int into a fs stat mode int
|
|
1379
|
+
const mode = (entry.externalFileAttributes >> 16) & 0xFFFF
|
|
1380
|
+
// check if it's a symlink or dir (using stat mode constants)
|
|
1381
|
+
const IFMT = 61440
|
|
1382
|
+
const IFDIR = 16384
|
|
1383
|
+
const IFLNK = 40960
|
|
1384
|
+
const symlink = (mode & IFMT) === IFLNK
|
|
1385
|
+
let isDir = (mode & IFMT) === IFDIR
|
|
1386
|
+
|
|
1387
|
+
// Failsafe, borrowed from jsZip
|
|
1388
|
+
if (!isDir && entry.fileName.endsWith('/')) {
|
|
1389
|
+
isDir = true
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
// check for windows weird way of specifying a directory
|
|
1393
|
+
// https://github.com/maxogden/extract-zip/issues/13#issuecomment-154494566
|
|
1394
|
+
const madeBy = entry.versionMadeBy >> 8
|
|
1395
|
+
if (!isDir) isDir = (madeBy === 0 && entry.externalFileAttributes === 16)
|
|
1396
|
+
|
|
1397
|
+
debug('extracting entry', { filename: entry.fileName, isDir: isDir, isSymlink: symlink })
|
|
1398
|
+
|
|
1399
|
+
const procMode = this.getExtractedMode(mode, isDir) & 0o777
|
|
1400
|
+
|
|
1401
|
+
// always ensure folders are created
|
|
1402
|
+
const destDir = isDir ? dest : path.dirname(dest)
|
|
1403
|
+
|
|
1404
|
+
const mkdirOptions = { recursive: true }
|
|
1405
|
+
if (isDir) {
|
|
1406
|
+
mkdirOptions.mode = procMode
|
|
1407
|
+
}
|
|
1408
|
+
debug('mkdir', { dir: destDir, ...mkdirOptions })
|
|
1409
|
+
await fs.mkdir(destDir, mkdirOptions)
|
|
1410
|
+
if (isDir) return
|
|
1411
|
+
|
|
1412
|
+
debug('opening read stream', dest)
|
|
1413
|
+
const readStream = await promisify(this.zipfile.openReadStream.bind(this.zipfile))(entry)
|
|
1414
|
+
|
|
1415
|
+
if (symlink) {
|
|
1416
|
+
const link = await getStream(readStream)
|
|
1417
|
+
debug('creating symlink', link, dest)
|
|
1418
|
+
await fs.symlink(link, dest)
|
|
1419
|
+
} else {
|
|
1420
|
+
await pipeline(readStream, createWriteStream(dest, { mode: procMode }))
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1424
|
+
getExtractedMode (entryMode, isDir) {
|
|
1425
|
+
let mode = entryMode
|
|
1426
|
+
// Set defaults, if necessary
|
|
1427
|
+
if (mode === 0) {
|
|
1428
|
+
if (isDir) {
|
|
1429
|
+
if (this.opts.defaultDirMode) {
|
|
1430
|
+
mode = parseInt(this.opts.defaultDirMode, 10)
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
if (!mode) {
|
|
1434
|
+
mode = 0o755
|
|
1435
|
+
}
|
|
1436
|
+
} else {
|
|
1437
|
+
if (this.opts.defaultFileMode) {
|
|
1438
|
+
mode = parseInt(this.opts.defaultFileMode, 10)
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
if (!mode) {
|
|
1442
|
+
mode = 0o644
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1447
|
+
return mode
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
|
|
1451
|
+
module.exports = async function (zipPath, opts) {
|
|
1452
|
+
debug('creating target directory', opts.dir)
|
|
1453
|
+
|
|
1454
|
+
if (!path.isAbsolute(opts.dir)) {
|
|
1455
|
+
throw new Error('Target directory is expected to be absolute')
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
await fs.mkdir(opts.dir, { recursive: true })
|
|
1459
|
+
opts.dir = await fs.realpath(opts.dir)
|
|
1460
|
+
return new Extractor(zipPath, opts).extract()
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
|
|
1464
|
+
/***/ }),
|
|
1465
|
+
|
|
1466
|
+
/***/ 2297:
|
|
1467
|
+
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
1468
|
+
|
|
1469
|
+
"use strict";
|
|
1470
|
+
|
|
1471
|
+
const {PassThrough: PassThroughStream} = __webpack_require__(8311);
|
|
1472
|
+
|
|
1473
|
+
module.exports = options => {
|
|
1474
|
+
options = {...options};
|
|
1475
|
+
|
|
1476
|
+
const {array} = options;
|
|
1477
|
+
let {encoding} = options;
|
|
1478
|
+
const isBuffer = encoding === 'buffer';
|
|
1479
|
+
let objectMode = false;
|
|
1480
|
+
|
|
1481
|
+
if (array) {
|
|
1482
|
+
objectMode = !(encoding || isBuffer);
|
|
1483
|
+
} else {
|
|
1484
|
+
encoding = encoding || 'utf8';
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1487
|
+
if (isBuffer) {
|
|
1488
|
+
encoding = null;
|
|
1489
|
+
}
|
|
1490
|
+
|
|
1491
|
+
const stream = new PassThroughStream({objectMode});
|
|
1492
|
+
|
|
1493
|
+
if (encoding) {
|
|
1494
|
+
stream.setEncoding(encoding);
|
|
1495
|
+
}
|
|
1496
|
+
|
|
1497
|
+
let length = 0;
|
|
1498
|
+
const chunks = [];
|
|
1499
|
+
|
|
1500
|
+
stream.on('data', chunk => {
|
|
1501
|
+
chunks.push(chunk);
|
|
1502
|
+
|
|
1503
|
+
if (objectMode) {
|
|
1504
|
+
length = chunks.length;
|
|
1505
|
+
} else {
|
|
1506
|
+
length += chunk.length;
|
|
1507
|
+
}
|
|
1508
|
+
});
|
|
1509
|
+
|
|
1510
|
+
stream.getBufferedValue = () => {
|
|
1511
|
+
if (array) {
|
|
1512
|
+
return chunks;
|
|
1513
|
+
}
|
|
1514
|
+
|
|
1515
|
+
return isBuffer ? Buffer.concat(chunks, length) : chunks.join('');
|
|
1516
|
+
};
|
|
1517
|
+
|
|
1518
|
+
stream.getBufferedLength = () => length;
|
|
1519
|
+
|
|
1520
|
+
return stream;
|
|
1521
|
+
};
|
|
1522
|
+
|
|
1523
|
+
|
|
1524
|
+
/***/ }),
|
|
1525
|
+
|
|
1526
|
+
/***/ 7491:
|
|
1527
|
+
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
1528
|
+
|
|
1529
|
+
"use strict";
|
|
1530
|
+
|
|
1531
|
+
const {constants: BufferConstants} = __webpack_require__(871);
|
|
1532
|
+
const pump = __webpack_require__(4286);
|
|
1533
|
+
const bufferStream = __webpack_require__(2297);
|
|
1534
|
+
|
|
1535
|
+
class MaxBufferError extends Error {
|
|
1536
|
+
constructor() {
|
|
1537
|
+
super('maxBuffer exceeded');
|
|
1538
|
+
this.name = 'MaxBufferError';
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1542
|
+
async function getStream(inputStream, options) {
|
|
1543
|
+
if (!inputStream) {
|
|
1544
|
+
return Promise.reject(new Error('Expected a stream'));
|
|
1545
|
+
}
|
|
1546
|
+
|
|
1547
|
+
options = {
|
|
1548
|
+
maxBuffer: Infinity,
|
|
1549
|
+
...options
|
|
1550
|
+
};
|
|
1551
|
+
|
|
1552
|
+
const {maxBuffer} = options;
|
|
1553
|
+
|
|
1554
|
+
let stream;
|
|
1555
|
+
await new Promise((resolve, reject) => {
|
|
1556
|
+
const rejectPromise = error => {
|
|
1557
|
+
// Don't retrieve an oversized buffer.
|
|
1558
|
+
if (error && stream.getBufferedLength() <= BufferConstants.MAX_LENGTH) {
|
|
1559
|
+
error.bufferedData = stream.getBufferedValue();
|
|
1560
|
+
}
|
|
1561
|
+
|
|
1562
|
+
reject(error);
|
|
1563
|
+
};
|
|
1564
|
+
|
|
1565
|
+
stream = pump(inputStream, bufferStream(options), error => {
|
|
1566
|
+
if (error) {
|
|
1567
|
+
rejectPromise(error);
|
|
1568
|
+
return;
|
|
1569
|
+
}
|
|
1570
|
+
|
|
1571
|
+
resolve();
|
|
1572
|
+
});
|
|
1573
|
+
|
|
1574
|
+
stream.on('data', () => {
|
|
1575
|
+
if (stream.getBufferedLength() > maxBuffer) {
|
|
1576
|
+
rejectPromise(new MaxBufferError());
|
|
1577
|
+
}
|
|
1578
|
+
});
|
|
1579
|
+
});
|
|
1580
|
+
|
|
1581
|
+
return stream.getBufferedValue();
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
module.exports = getStream;
|
|
1585
|
+
// TODO: Remove this for the next major release
|
|
1586
|
+
module.exports["default"] = getStream;
|
|
1587
|
+
module.exports.buffer = (stream, options) => getStream(stream, {...options, encoding: 'buffer'});
|
|
1588
|
+
module.exports.array = (stream, options) => getStream(stream, {...options, array: true});
|
|
1589
|
+
module.exports.MaxBufferError = MaxBufferError;
|
|
1590
|
+
|
|
1591
|
+
|
|
1592
|
+
/***/ }),
|
|
1593
|
+
|
|
1594
|
+
/***/ 8913:
|
|
1595
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
1596
|
+
|
|
1597
|
+
var fs = __webpack_require__(6231);
|
|
1598
|
+
var util = __webpack_require__(6464);
|
|
1599
|
+
var stream = __webpack_require__(8311);
|
|
1600
|
+
var Readable = stream.Readable;
|
|
1601
|
+
var Writable = stream.Writable;
|
|
1602
|
+
var PassThrough = stream.PassThrough;
|
|
1603
|
+
var Pend = __webpack_require__(9916);
|
|
1604
|
+
var EventEmitter = (__webpack_require__(7187).EventEmitter);
|
|
1605
|
+
|
|
1606
|
+
exports.createFromBuffer = createFromBuffer;
|
|
1607
|
+
exports.createFromFd = createFromFd;
|
|
1608
|
+
exports.BufferSlicer = BufferSlicer;
|
|
1609
|
+
exports.FdSlicer = FdSlicer;
|
|
1610
|
+
|
|
1611
|
+
util.inherits(FdSlicer, EventEmitter);
|
|
1612
|
+
function FdSlicer(fd, options) {
|
|
1613
|
+
options = options || {};
|
|
1614
|
+
EventEmitter.call(this);
|
|
1615
|
+
|
|
1616
|
+
this.fd = fd;
|
|
1617
|
+
this.pend = new Pend();
|
|
1618
|
+
this.pend.max = 1;
|
|
1619
|
+
this.refCount = 0;
|
|
1620
|
+
this.autoClose = !!options.autoClose;
|
|
1621
|
+
}
|
|
1622
|
+
|
|
1623
|
+
FdSlicer.prototype.read = function(buffer, offset, length, position, callback) {
|
|
1624
|
+
var self = this;
|
|
1625
|
+
self.pend.go(function(cb) {
|
|
1626
|
+
fs.read(self.fd, buffer, offset, length, position, function(err, bytesRead, buffer) {
|
|
1627
|
+
cb();
|
|
1628
|
+
callback(err, bytesRead, buffer);
|
|
1629
|
+
});
|
|
1630
|
+
});
|
|
1631
|
+
};
|
|
1632
|
+
|
|
1633
|
+
FdSlicer.prototype.write = function(buffer, offset, length, position, callback) {
|
|
1634
|
+
var self = this;
|
|
1635
|
+
self.pend.go(function(cb) {
|
|
1636
|
+
fs.write(self.fd, buffer, offset, length, position, function(err, written, buffer) {
|
|
1637
|
+
cb();
|
|
1638
|
+
callback(err, written, buffer);
|
|
1639
|
+
});
|
|
1640
|
+
});
|
|
1641
|
+
};
|
|
1642
|
+
|
|
1643
|
+
FdSlicer.prototype.createReadStream = function(options) {
|
|
1644
|
+
return new ReadStream(this, options);
|
|
1645
|
+
};
|
|
1646
|
+
|
|
1647
|
+
FdSlicer.prototype.createWriteStream = function(options) {
|
|
1648
|
+
return new WriteStream(this, options);
|
|
1649
|
+
};
|
|
1650
|
+
|
|
1651
|
+
FdSlicer.prototype.ref = function() {
|
|
1652
|
+
this.refCount += 1;
|
|
1653
|
+
};
|
|
1654
|
+
|
|
1655
|
+
FdSlicer.prototype.unref = function() {
|
|
1656
|
+
var self = this;
|
|
1657
|
+
self.refCount -= 1;
|
|
1658
|
+
|
|
1659
|
+
if (self.refCount > 0) return;
|
|
1660
|
+
if (self.refCount < 0) throw new Error("invalid unref");
|
|
1661
|
+
|
|
1662
|
+
if (self.autoClose) {
|
|
1663
|
+
fs.close(self.fd, onCloseDone);
|
|
1664
|
+
}
|
|
1665
|
+
|
|
1666
|
+
function onCloseDone(err) {
|
|
1667
|
+
if (err) {
|
|
1668
|
+
self.emit('error', err);
|
|
1669
|
+
} else {
|
|
1670
|
+
self.emit('close');
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
};
|
|
1674
|
+
|
|
1675
|
+
util.inherits(ReadStream, Readable);
|
|
1676
|
+
function ReadStream(context, options) {
|
|
1677
|
+
options = options || {};
|
|
1678
|
+
Readable.call(this, options);
|
|
1679
|
+
|
|
1680
|
+
this.context = context;
|
|
1681
|
+
this.context.ref();
|
|
1682
|
+
|
|
1683
|
+
this.start = options.start || 0;
|
|
1684
|
+
this.endOffset = options.end;
|
|
1685
|
+
this.pos = this.start;
|
|
1686
|
+
this.destroyed = false;
|
|
1687
|
+
}
|
|
1688
|
+
|
|
1689
|
+
ReadStream.prototype._read = function(n) {
|
|
1690
|
+
var self = this;
|
|
1691
|
+
if (self.destroyed) return;
|
|
1692
|
+
|
|
1693
|
+
var toRead = Math.min(self._readableState.highWaterMark, n);
|
|
1694
|
+
if (self.endOffset != null) {
|
|
1695
|
+
toRead = Math.min(toRead, self.endOffset - self.pos);
|
|
1696
|
+
}
|
|
1697
|
+
if (toRead <= 0) {
|
|
1698
|
+
self.destroyed = true;
|
|
1699
|
+
self.push(null);
|
|
1700
|
+
self.context.unref();
|
|
1701
|
+
return;
|
|
1702
|
+
}
|
|
1703
|
+
self.context.pend.go(function(cb) {
|
|
1704
|
+
if (self.destroyed) return cb();
|
|
1705
|
+
var buffer = new Buffer(toRead);
|
|
1706
|
+
fs.read(self.context.fd, buffer, 0, toRead, self.pos, function(err, bytesRead) {
|
|
1707
|
+
if (err) {
|
|
1708
|
+
self.destroy(err);
|
|
1709
|
+
} else if (bytesRead === 0) {
|
|
1710
|
+
self.destroyed = true;
|
|
1711
|
+
self.push(null);
|
|
1712
|
+
self.context.unref();
|
|
1713
|
+
} else {
|
|
1714
|
+
self.pos += bytesRead;
|
|
1715
|
+
self.push(buffer.slice(0, bytesRead));
|
|
1716
|
+
}
|
|
1717
|
+
cb();
|
|
1718
|
+
});
|
|
1719
|
+
});
|
|
1720
|
+
};
|
|
1721
|
+
|
|
1722
|
+
ReadStream.prototype.destroy = function(err) {
|
|
1723
|
+
if (this.destroyed) return;
|
|
1724
|
+
err = err || new Error("stream destroyed");
|
|
1725
|
+
this.destroyed = true;
|
|
1726
|
+
this.emit('error', err);
|
|
1727
|
+
this.context.unref();
|
|
1728
|
+
};
|
|
1729
|
+
|
|
1730
|
+
util.inherits(WriteStream, Writable);
|
|
1731
|
+
function WriteStream(context, options) {
|
|
1732
|
+
options = options || {};
|
|
1733
|
+
Writable.call(this, options);
|
|
1734
|
+
|
|
1735
|
+
this.context = context;
|
|
1736
|
+
this.context.ref();
|
|
1737
|
+
|
|
1738
|
+
this.start = options.start || 0;
|
|
1739
|
+
this.endOffset = (options.end == null) ? Infinity : +options.end;
|
|
1740
|
+
this.bytesWritten = 0;
|
|
1741
|
+
this.pos = this.start;
|
|
1742
|
+
this.destroyed = false;
|
|
1743
|
+
|
|
1744
|
+
this.on('finish', this.destroy.bind(this));
|
|
1745
|
+
}
|
|
1746
|
+
|
|
1747
|
+
WriteStream.prototype._write = function(buffer, encoding, callback) {
|
|
1748
|
+
var self = this;
|
|
1749
|
+
if (self.destroyed) return;
|
|
1750
|
+
|
|
1751
|
+
if (self.pos + buffer.length > self.endOffset) {
|
|
1752
|
+
var err = new Error("maximum file length exceeded");
|
|
1753
|
+
err.code = 'ETOOBIG';
|
|
1754
|
+
self.destroy();
|
|
1755
|
+
callback(err);
|
|
1756
|
+
return;
|
|
1757
|
+
}
|
|
1758
|
+
self.context.pend.go(function(cb) {
|
|
1759
|
+
if (self.destroyed) return cb();
|
|
1760
|
+
fs.write(self.context.fd, buffer, 0, buffer.length, self.pos, function(err, bytes) {
|
|
1761
|
+
if (err) {
|
|
1762
|
+
self.destroy();
|
|
1763
|
+
cb();
|
|
1764
|
+
callback(err);
|
|
1765
|
+
} else {
|
|
1766
|
+
self.bytesWritten += bytes;
|
|
1767
|
+
self.pos += bytes;
|
|
1768
|
+
self.emit('progress');
|
|
1769
|
+
cb();
|
|
1770
|
+
callback();
|
|
1771
|
+
}
|
|
1772
|
+
});
|
|
1773
|
+
});
|
|
1774
|
+
};
|
|
1775
|
+
|
|
1776
|
+
WriteStream.prototype.destroy = function() {
|
|
1777
|
+
if (this.destroyed) return;
|
|
1778
|
+
this.destroyed = true;
|
|
1779
|
+
this.context.unref();
|
|
1780
|
+
};
|
|
1781
|
+
|
|
1782
|
+
util.inherits(BufferSlicer, EventEmitter);
|
|
1783
|
+
function BufferSlicer(buffer, options) {
|
|
1784
|
+
EventEmitter.call(this);
|
|
1785
|
+
|
|
1786
|
+
options = options || {};
|
|
1787
|
+
this.refCount = 0;
|
|
1788
|
+
this.buffer = buffer;
|
|
1789
|
+
this.maxChunkSize = options.maxChunkSize || Number.MAX_SAFE_INTEGER;
|
|
1790
|
+
}
|
|
1791
|
+
|
|
1792
|
+
BufferSlicer.prototype.read = function(buffer, offset, length, position, callback) {
|
|
1793
|
+
var end = position + length;
|
|
1794
|
+
var delta = end - this.buffer.length;
|
|
1795
|
+
var written = (delta > 0) ? delta : length;
|
|
1796
|
+
this.buffer.copy(buffer, offset, position, end);
|
|
1797
|
+
setImmediate(function() {
|
|
1798
|
+
callback(null, written);
|
|
1799
|
+
});
|
|
1800
|
+
};
|
|
1801
|
+
|
|
1802
|
+
BufferSlicer.prototype.write = function(buffer, offset, length, position, callback) {
|
|
1803
|
+
buffer.copy(this.buffer, position, offset, offset + length);
|
|
1804
|
+
setImmediate(function() {
|
|
1805
|
+
callback(null, length, buffer);
|
|
1806
|
+
});
|
|
1807
|
+
};
|
|
1808
|
+
|
|
1809
|
+
BufferSlicer.prototype.createReadStream = function(options) {
|
|
1810
|
+
options = options || {};
|
|
1811
|
+
var readStream = new PassThrough(options);
|
|
1812
|
+
readStream.destroyed = false;
|
|
1813
|
+
readStream.start = options.start || 0;
|
|
1814
|
+
readStream.endOffset = options.end;
|
|
1815
|
+
// by the time this function returns, we'll be done.
|
|
1816
|
+
readStream.pos = readStream.endOffset || this.buffer.length;
|
|
1817
|
+
|
|
1818
|
+
// respect the maxChunkSize option to slice up the chunk into smaller pieces.
|
|
1819
|
+
var entireSlice = this.buffer.slice(readStream.start, readStream.pos);
|
|
1820
|
+
var offset = 0;
|
|
1821
|
+
while (true) {
|
|
1822
|
+
var nextOffset = offset + this.maxChunkSize;
|
|
1823
|
+
if (nextOffset >= entireSlice.length) {
|
|
1824
|
+
// last chunk
|
|
1825
|
+
if (offset < entireSlice.length) {
|
|
1826
|
+
readStream.write(entireSlice.slice(offset, entireSlice.length));
|
|
1827
|
+
}
|
|
1828
|
+
break;
|
|
1829
|
+
}
|
|
1830
|
+
readStream.write(entireSlice.slice(offset, nextOffset));
|
|
1831
|
+
offset = nextOffset;
|
|
1832
|
+
}
|
|
1833
|
+
|
|
1834
|
+
readStream.end();
|
|
1835
|
+
readStream.destroy = function() {
|
|
1836
|
+
readStream.destroyed = true;
|
|
1837
|
+
};
|
|
1838
|
+
return readStream;
|
|
1839
|
+
};
|
|
1840
|
+
|
|
1841
|
+
BufferSlicer.prototype.createWriteStream = function(options) {
|
|
1842
|
+
var bufferSlicer = this;
|
|
1843
|
+
options = options || {};
|
|
1844
|
+
var writeStream = new Writable(options);
|
|
1845
|
+
writeStream.start = options.start || 0;
|
|
1846
|
+
writeStream.endOffset = (options.end == null) ? this.buffer.length : +options.end;
|
|
1847
|
+
writeStream.bytesWritten = 0;
|
|
1848
|
+
writeStream.pos = writeStream.start;
|
|
1849
|
+
writeStream.destroyed = false;
|
|
1850
|
+
writeStream._write = function(buffer, encoding, callback) {
|
|
1851
|
+
if (writeStream.destroyed) return;
|
|
1852
|
+
|
|
1853
|
+
var end = writeStream.pos + buffer.length;
|
|
1854
|
+
if (end > writeStream.endOffset) {
|
|
1855
|
+
var err = new Error("maximum file length exceeded");
|
|
1856
|
+
err.code = 'ETOOBIG';
|
|
1857
|
+
writeStream.destroyed = true;
|
|
1858
|
+
callback(err);
|
|
1859
|
+
return;
|
|
1860
|
+
}
|
|
1861
|
+
buffer.copy(bufferSlicer.buffer, writeStream.pos, 0, buffer.length);
|
|
1862
|
+
|
|
1863
|
+
writeStream.bytesWritten += buffer.length;
|
|
1864
|
+
writeStream.pos = end;
|
|
1865
|
+
writeStream.emit('progress');
|
|
1866
|
+
callback();
|
|
1867
|
+
};
|
|
1868
|
+
writeStream.destroy = function() {
|
|
1869
|
+
writeStream.destroyed = true;
|
|
1870
|
+
};
|
|
1871
|
+
return writeStream;
|
|
1872
|
+
};
|
|
1873
|
+
|
|
1874
|
+
BufferSlicer.prototype.ref = function() {
|
|
1875
|
+
this.refCount += 1;
|
|
1876
|
+
};
|
|
1877
|
+
|
|
1878
|
+
BufferSlicer.prototype.unref = function() {
|
|
1879
|
+
this.refCount -= 1;
|
|
1880
|
+
|
|
1881
|
+
if (this.refCount < 0) {
|
|
1882
|
+
throw new Error("invalid unref");
|
|
1883
|
+
}
|
|
1884
|
+
};
|
|
1885
|
+
|
|
1886
|
+
function createFromBuffer(buffer, options) {
|
|
1887
|
+
return new BufferSlicer(buffer, options);
|
|
1888
|
+
}
|
|
1889
|
+
|
|
1890
|
+
function createFromFd(fd, options) {
|
|
1891
|
+
return new FdSlicer(fd, options);
|
|
1892
|
+
}
|
|
1893
|
+
|
|
1894
|
+
|
|
1895
|
+
/***/ }),
|
|
1896
|
+
|
|
1897
|
+
/***/ 7824:
|
|
1898
|
+
/***/ ((module) => {
|
|
1899
|
+
|
|
1900
|
+
/**
|
|
1901
|
+
* Helpers.
|
|
1902
|
+
*/
|
|
1903
|
+
|
|
1904
|
+
var s = 1000;
|
|
1905
|
+
var m = s * 60;
|
|
1906
|
+
var h = m * 60;
|
|
1907
|
+
var d = h * 24;
|
|
1908
|
+
var w = d * 7;
|
|
1909
|
+
var y = d * 365.25;
|
|
1910
|
+
|
|
1911
|
+
/**
|
|
1912
|
+
* Parse or format the given `val`.
|
|
1913
|
+
*
|
|
1914
|
+
* Options:
|
|
1915
|
+
*
|
|
1916
|
+
* - `long` verbose formatting [false]
|
|
1917
|
+
*
|
|
1918
|
+
* @param {String|Number} val
|
|
1919
|
+
* @param {Object} [options]
|
|
1920
|
+
* @throws {Error} throw an error if val is not a non-empty string or a number
|
|
1921
|
+
* @return {String|Number}
|
|
1922
|
+
* @api public
|
|
1923
|
+
*/
|
|
1924
|
+
|
|
1925
|
+
module.exports = function(val, options) {
|
|
1926
|
+
options = options || {};
|
|
1927
|
+
var type = typeof val;
|
|
1928
|
+
if (type === 'string' && val.length > 0) {
|
|
1929
|
+
return parse(val);
|
|
1930
|
+
} else if (type === 'number' && isFinite(val)) {
|
|
1931
|
+
return options.long ? fmtLong(val) : fmtShort(val);
|
|
1932
|
+
}
|
|
1933
|
+
throw new Error(
|
|
1934
|
+
'val is not a non-empty string or a valid number. val=' +
|
|
1935
|
+
JSON.stringify(val)
|
|
1936
|
+
);
|
|
1937
|
+
};
|
|
1938
|
+
|
|
1939
|
+
/**
|
|
1940
|
+
* Parse the given `str` and return milliseconds.
|
|
1941
|
+
*
|
|
1942
|
+
* @param {String} str
|
|
1943
|
+
* @return {Number}
|
|
1944
|
+
* @api private
|
|
1945
|
+
*/
|
|
1946
|
+
|
|
1947
|
+
function parse(str) {
|
|
1948
|
+
str = String(str);
|
|
1949
|
+
if (str.length > 100) {
|
|
1950
|
+
return;
|
|
1951
|
+
}
|
|
1952
|
+
var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
|
|
1953
|
+
str
|
|
1954
|
+
);
|
|
1955
|
+
if (!match) {
|
|
1956
|
+
return;
|
|
1957
|
+
}
|
|
1958
|
+
var n = parseFloat(match[1]);
|
|
1959
|
+
var type = (match[2] || 'ms').toLowerCase();
|
|
1960
|
+
switch (type) {
|
|
1961
|
+
case 'years':
|
|
1962
|
+
case 'year':
|
|
1963
|
+
case 'yrs':
|
|
1964
|
+
case 'yr':
|
|
1965
|
+
case 'y':
|
|
1966
|
+
return n * y;
|
|
1967
|
+
case 'weeks':
|
|
1968
|
+
case 'week':
|
|
1969
|
+
case 'w':
|
|
1970
|
+
return n * w;
|
|
1971
|
+
case 'days':
|
|
1972
|
+
case 'day':
|
|
1973
|
+
case 'd':
|
|
1974
|
+
return n * d;
|
|
1975
|
+
case 'hours':
|
|
1976
|
+
case 'hour':
|
|
1977
|
+
case 'hrs':
|
|
1978
|
+
case 'hr':
|
|
1979
|
+
case 'h':
|
|
1980
|
+
return n * h;
|
|
1981
|
+
case 'minutes':
|
|
1982
|
+
case 'minute':
|
|
1983
|
+
case 'mins':
|
|
1984
|
+
case 'min':
|
|
1985
|
+
case 'm':
|
|
1986
|
+
return n * m;
|
|
1987
|
+
case 'seconds':
|
|
1988
|
+
case 'second':
|
|
1989
|
+
case 'secs':
|
|
1990
|
+
case 'sec':
|
|
1991
|
+
case 's':
|
|
1992
|
+
return n * s;
|
|
1993
|
+
case 'milliseconds':
|
|
1994
|
+
case 'millisecond':
|
|
1995
|
+
case 'msecs':
|
|
1996
|
+
case 'msec':
|
|
1997
|
+
case 'ms':
|
|
1998
|
+
return n;
|
|
1999
|
+
default:
|
|
2000
|
+
return undefined;
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
|
|
2004
|
+
/**
|
|
2005
|
+
* Short format for `ms`.
|
|
2006
|
+
*
|
|
2007
|
+
* @param {Number} ms
|
|
2008
|
+
* @return {String}
|
|
2009
|
+
* @api private
|
|
2010
|
+
*/
|
|
2011
|
+
|
|
2012
|
+
function fmtShort(ms) {
|
|
2013
|
+
var msAbs = Math.abs(ms);
|
|
2014
|
+
if (msAbs >= d) {
|
|
2015
|
+
return Math.round(ms / d) + 'd';
|
|
2016
|
+
}
|
|
2017
|
+
if (msAbs >= h) {
|
|
2018
|
+
return Math.round(ms / h) + 'h';
|
|
2019
|
+
}
|
|
2020
|
+
if (msAbs >= m) {
|
|
2021
|
+
return Math.round(ms / m) + 'm';
|
|
2022
|
+
}
|
|
2023
|
+
if (msAbs >= s) {
|
|
2024
|
+
return Math.round(ms / s) + 's';
|
|
2025
|
+
}
|
|
2026
|
+
return ms + 'ms';
|
|
2027
|
+
}
|
|
2028
|
+
|
|
2029
|
+
/**
|
|
2030
|
+
* Long format for `ms`.
|
|
2031
|
+
*
|
|
2032
|
+
* @param {Number} ms
|
|
2033
|
+
* @return {String}
|
|
2034
|
+
* @api private
|
|
2035
|
+
*/
|
|
2036
|
+
|
|
2037
|
+
function fmtLong(ms) {
|
|
2038
|
+
var msAbs = Math.abs(ms);
|
|
2039
|
+
if (msAbs >= d) {
|
|
2040
|
+
return plural(ms, msAbs, d, 'day');
|
|
2041
|
+
}
|
|
2042
|
+
if (msAbs >= h) {
|
|
2043
|
+
return plural(ms, msAbs, h, 'hour');
|
|
2044
|
+
}
|
|
2045
|
+
if (msAbs >= m) {
|
|
2046
|
+
return plural(ms, msAbs, m, 'minute');
|
|
2047
|
+
}
|
|
2048
|
+
if (msAbs >= s) {
|
|
2049
|
+
return plural(ms, msAbs, s, 'second');
|
|
2050
|
+
}
|
|
2051
|
+
return ms + ' ms';
|
|
2052
|
+
}
|
|
2053
|
+
|
|
2054
|
+
/**
|
|
2055
|
+
* Pluralization helper.
|
|
2056
|
+
*/
|
|
2057
|
+
|
|
2058
|
+
function plural(ms, msAbs, n, name) {
|
|
2059
|
+
var isPlural = msAbs >= n * 1.5;
|
|
2060
|
+
return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
|
|
2061
|
+
}
|
|
2062
|
+
|
|
2063
|
+
|
|
2064
|
+
/***/ }),
|
|
2065
|
+
|
|
2066
|
+
/***/ 778:
|
|
2067
|
+
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
2068
|
+
|
|
2069
|
+
var wrappy = __webpack_require__(2479)
|
|
2070
|
+
module.exports = wrappy(once)
|
|
2071
|
+
module.exports.strict = wrappy(onceStrict)
|
|
2072
|
+
|
|
2073
|
+
once.proto = once(function () {
|
|
2074
|
+
Object.defineProperty(Function.prototype, 'once', {
|
|
2075
|
+
value: function () {
|
|
2076
|
+
return once(this)
|
|
2077
|
+
},
|
|
2078
|
+
configurable: true
|
|
2079
|
+
})
|
|
2080
|
+
|
|
2081
|
+
Object.defineProperty(Function.prototype, 'onceStrict', {
|
|
2082
|
+
value: function () {
|
|
2083
|
+
return onceStrict(this)
|
|
2084
|
+
},
|
|
2085
|
+
configurable: true
|
|
2086
|
+
})
|
|
2087
|
+
})
|
|
2088
|
+
|
|
2089
|
+
function once (fn) {
|
|
2090
|
+
var f = function () {
|
|
2091
|
+
if (f.called) return f.value
|
|
2092
|
+
f.called = true
|
|
2093
|
+
return f.value = fn.apply(this, arguments)
|
|
2094
|
+
}
|
|
2095
|
+
f.called = false
|
|
2096
|
+
return f
|
|
2097
|
+
}
|
|
2098
|
+
|
|
2099
|
+
function onceStrict (fn) {
|
|
2100
|
+
var f = function () {
|
|
2101
|
+
if (f.called)
|
|
2102
|
+
throw new Error(f.onceError)
|
|
2103
|
+
f.called = true
|
|
2104
|
+
return f.value = fn.apply(this, arguments)
|
|
2105
|
+
}
|
|
2106
|
+
var name = fn.name || 'Function wrapped with `once`'
|
|
2107
|
+
f.onceError = name + " shouldn't be called more than once"
|
|
2108
|
+
f.called = false
|
|
2109
|
+
return f
|
|
2110
|
+
}
|
|
2111
|
+
|
|
2112
|
+
|
|
2113
|
+
/***/ }),
|
|
2114
|
+
|
|
2115
|
+
/***/ 9916:
|
|
2116
|
+
/***/ ((module) => {
|
|
2117
|
+
|
|
2118
|
+
module.exports = Pend;
|
|
2119
|
+
|
|
2120
|
+
function Pend() {
|
|
2121
|
+
this.pending = 0;
|
|
2122
|
+
this.max = Infinity;
|
|
2123
|
+
this.listeners = [];
|
|
2124
|
+
this.waiting = [];
|
|
2125
|
+
this.error = null;
|
|
2126
|
+
}
|
|
2127
|
+
|
|
2128
|
+
Pend.prototype.go = function(fn) {
|
|
2129
|
+
if (this.pending < this.max) {
|
|
2130
|
+
pendGo(this, fn);
|
|
2131
|
+
} else {
|
|
2132
|
+
this.waiting.push(fn);
|
|
2133
|
+
}
|
|
2134
|
+
};
|
|
2135
|
+
|
|
2136
|
+
Pend.prototype.wait = function(cb) {
|
|
2137
|
+
if (this.pending === 0) {
|
|
2138
|
+
cb(this.error);
|
|
2139
|
+
} else {
|
|
2140
|
+
this.listeners.push(cb);
|
|
2141
|
+
}
|
|
2142
|
+
};
|
|
2143
|
+
|
|
2144
|
+
Pend.prototype.hold = function() {
|
|
2145
|
+
return pendHold(this);
|
|
2146
|
+
};
|
|
2147
|
+
|
|
2148
|
+
function pendHold(self) {
|
|
2149
|
+
self.pending += 1;
|
|
2150
|
+
var called = false;
|
|
2151
|
+
return onCb;
|
|
2152
|
+
function onCb(err) {
|
|
2153
|
+
if (called) throw new Error("callback called twice");
|
|
2154
|
+
called = true;
|
|
2155
|
+
self.error = self.error || err;
|
|
2156
|
+
self.pending -= 1;
|
|
2157
|
+
if (self.waiting.length > 0 && self.pending < self.max) {
|
|
2158
|
+
pendGo(self, self.waiting.shift());
|
|
2159
|
+
} else if (self.pending === 0) {
|
|
2160
|
+
var listeners = self.listeners;
|
|
2161
|
+
self.listeners = [];
|
|
2162
|
+
listeners.forEach(cbListener);
|
|
2163
|
+
}
|
|
2164
|
+
}
|
|
2165
|
+
function cbListener(listener) {
|
|
2166
|
+
listener(self.error);
|
|
2167
|
+
}
|
|
2168
|
+
}
|
|
2169
|
+
|
|
2170
|
+
function pendGo(self, fn) {
|
|
2171
|
+
fn(pendHold(self));
|
|
2172
|
+
}
|
|
2173
|
+
|
|
2174
|
+
|
|
2175
|
+
/***/ }),
|
|
2176
|
+
|
|
2177
|
+
/***/ 4286:
|
|
2178
|
+
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
2179
|
+
|
|
2180
|
+
var once = __webpack_require__(778)
|
|
2181
|
+
var eos = __webpack_require__(2840)
|
|
2182
|
+
var fs = __webpack_require__(6231) // we only need fs to get the ReadStream and WriteStream prototypes
|
|
2183
|
+
|
|
2184
|
+
var noop = function () {}
|
|
2185
|
+
var ancient = /^v?\.0/.test(process.version)
|
|
2186
|
+
|
|
2187
|
+
var isFn = function (fn) {
|
|
2188
|
+
return typeof fn === 'function'
|
|
2189
|
+
}
|
|
2190
|
+
|
|
2191
|
+
var isFS = function (stream) {
|
|
2192
|
+
if (!ancient) return false // newer node version do not need to care about fs is a special way
|
|
2193
|
+
if (!fs) return false // browser
|
|
2194
|
+
return (stream instanceof (fs.ReadStream || noop) || stream instanceof (fs.WriteStream || noop)) && isFn(stream.close)
|
|
2195
|
+
}
|
|
470
2196
|
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
addErrorHandlerIfEventEmitter(emitter, errorListener, { once: true });
|
|
474
|
-
}
|
|
475
|
-
});
|
|
2197
|
+
var isRequest = function (stream) {
|
|
2198
|
+
return stream.setHeader && isFn(stream.abort)
|
|
476
2199
|
}
|
|
477
2200
|
|
|
478
|
-
function
|
|
479
|
-
|
|
480
|
-
|
|
2201
|
+
var destroyer = function (stream, reading, writing, callback) {
|
|
2202
|
+
callback = once(callback)
|
|
2203
|
+
|
|
2204
|
+
var closed = false
|
|
2205
|
+
stream.on('close', function () {
|
|
2206
|
+
closed = true
|
|
2207
|
+
})
|
|
2208
|
+
|
|
2209
|
+
eos(stream, {readable: reading, writable: writing}, function (err) {
|
|
2210
|
+
if (err) return callback(err)
|
|
2211
|
+
closed = true
|
|
2212
|
+
callback()
|
|
2213
|
+
})
|
|
2214
|
+
|
|
2215
|
+
var destroyed = false
|
|
2216
|
+
return function (err) {
|
|
2217
|
+
if (closed) return
|
|
2218
|
+
if (destroyed) return
|
|
2219
|
+
destroyed = true
|
|
2220
|
+
|
|
2221
|
+
if (isFS(stream)) return stream.close(noop) // use close for fs streams to avoid fd leaks
|
|
2222
|
+
if (isRequest(stream)) return stream.abort() // request.destroy just do .end - .abort is what we want
|
|
2223
|
+
|
|
2224
|
+
if (isFn(stream.destroy)) return stream.destroy()
|
|
2225
|
+
|
|
2226
|
+
callback(err || new Error('stream was destroyed'))
|
|
481
2227
|
}
|
|
482
2228
|
}
|
|
483
2229
|
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
2230
|
+
var call = function (fn) {
|
|
2231
|
+
fn()
|
|
2232
|
+
}
|
|
2233
|
+
|
|
2234
|
+
var pipe = function (from, to) {
|
|
2235
|
+
return from.pipe(to)
|
|
2236
|
+
}
|
|
2237
|
+
|
|
2238
|
+
var pump = function () {
|
|
2239
|
+
var streams = Array.prototype.slice.call(arguments)
|
|
2240
|
+
var callback = isFn(streams[streams.length - 1] || noop) && streams.pop() || noop
|
|
2241
|
+
|
|
2242
|
+
if (Array.isArray(streams[0])) streams = streams[0]
|
|
2243
|
+
if (streams.length < 2) throw new Error('pump requires two streams per minimum')
|
|
2244
|
+
|
|
2245
|
+
var error
|
|
2246
|
+
var destroys = streams.map(function (stream, i) {
|
|
2247
|
+
var reading = i < streams.length - 1
|
|
2248
|
+
var writing = i > 0
|
|
2249
|
+
return destroyer(stream, reading, writing, function (err) {
|
|
2250
|
+
if (!error) error = err
|
|
2251
|
+
if (err) destroys.forEach(call)
|
|
2252
|
+
if (reading) return
|
|
2253
|
+
destroys.forEach(call)
|
|
2254
|
+
callback(error)
|
|
2255
|
+
})
|
|
2256
|
+
})
|
|
2257
|
+
|
|
2258
|
+
return streams.reduce(pipe)
|
|
505
2259
|
}
|
|
506
2260
|
|
|
2261
|
+
module.exports = pump
|
|
2262
|
+
|
|
507
2263
|
|
|
508
2264
|
/***/ }),
|
|
509
2265
|
|
|
@@ -2077,6 +3833,46 @@ function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
|
|
|
2077
3833
|
})( false ? 0 : exports)
|
|
2078
3834
|
|
|
2079
3835
|
|
|
3836
|
+
/***/ }),
|
|
3837
|
+
|
|
3838
|
+
/***/ 2479:
|
|
3839
|
+
/***/ ((module) => {
|
|
3840
|
+
|
|
3841
|
+
// Returns a wrapper function that returns a wrapped callback
|
|
3842
|
+
// The wrapper function should do some stuff, and return a
|
|
3843
|
+
// presumably different callback function.
|
|
3844
|
+
// This makes sure that own properties are retained, so that
|
|
3845
|
+
// decorations and such are not lost along the way.
|
|
3846
|
+
module.exports = wrappy
|
|
3847
|
+
function wrappy (fn, cb) {
|
|
3848
|
+
if (fn && cb) return wrappy(fn)(cb)
|
|
3849
|
+
|
|
3850
|
+
if (typeof fn !== 'function')
|
|
3851
|
+
throw new TypeError('need wrapper function')
|
|
3852
|
+
|
|
3853
|
+
Object.keys(fn).forEach(function (k) {
|
|
3854
|
+
wrapper[k] = fn[k]
|
|
3855
|
+
})
|
|
3856
|
+
|
|
3857
|
+
return wrapper
|
|
3858
|
+
|
|
3859
|
+
function wrapper() {
|
|
3860
|
+
var args = new Array(arguments.length)
|
|
3861
|
+
for (var i = 0; i < args.length; i++) {
|
|
3862
|
+
args[i] = arguments[i]
|
|
3863
|
+
}
|
|
3864
|
+
var ret = fn.apply(this, args)
|
|
3865
|
+
var cb = args[args.length-1]
|
|
3866
|
+
if (typeof ret === 'function' && ret !== cb) {
|
|
3867
|
+
Object.keys(cb).forEach(function (k) {
|
|
3868
|
+
ret[k] = cb[k]
|
|
3869
|
+
})
|
|
3870
|
+
}
|
|
3871
|
+
return ret
|
|
3872
|
+
}
|
|
3873
|
+
}
|
|
3874
|
+
|
|
3875
|
+
|
|
2080
3876
|
/***/ }),
|
|
2081
3877
|
|
|
2082
3878
|
/***/ 306:
|
|
@@ -4694,7 +6490,7 @@ function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
|
|
|
4694
6490
|
|
|
4695
6491
|
/***/ }),
|
|
4696
6492
|
|
|
4697
|
-
/***/
|
|
6493
|
+
/***/ 8833:
|
|
4698
6494
|
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
|
|
4699
6495
|
|
|
4700
6496
|
// Generated by CoffeeScript 1.12.7
|
|
@@ -5157,7 +6953,7 @@ function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
|
|
|
5157
6953
|
XMLRaw = __webpack_require__(9406);
|
|
5158
6954
|
XMLText = __webpack_require__(3595);
|
|
5159
6955
|
XMLProcessingInstruction = __webpack_require__(9181);
|
|
5160
|
-
XMLDummy = __webpack_require__(
|
|
6956
|
+
XMLDummy = __webpack_require__(8833);
|
|
5161
6957
|
NodeType = __webpack_require__(9335);
|
|
5162
6958
|
XMLNodeList = __webpack_require__(2390);
|
|
5163
6959
|
XMLNamedNodeMap = __webpack_require__(663);
|
|
@@ -6603,7 +8399,7 @@ function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
|
|
|
6603
8399
|
|
|
6604
8400
|
XMLProcessingInstruction = __webpack_require__(9181);
|
|
6605
8401
|
|
|
6606
|
-
XMLDummy = __webpack_require__(
|
|
8402
|
+
XMLDummy = __webpack_require__(8833);
|
|
6607
8403
|
|
|
6608
8404
|
XMLDTDAttList = __webpack_require__(1179);
|
|
6609
8405
|
|
|
@@ -7017,68 +8813,895 @@ function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
|
|
|
7017
8813
|
(function() {
|
|
7018
8814
|
var NodeType, WriterState, XMLDOMImplementation, XMLDocument, XMLDocumentCB, XMLStreamWriter, XMLStringWriter, assign, isFunction, ref;
|
|
7019
8815
|
|
|
7020
|
-
ref = __webpack_require__(8369), assign = ref.assign, isFunction = ref.isFunction;
|
|
8816
|
+
ref = __webpack_require__(8369), assign = ref.assign, isFunction = ref.isFunction;
|
|
8817
|
+
|
|
8818
|
+
XMLDOMImplementation = __webpack_require__(1770);
|
|
8819
|
+
|
|
8820
|
+
XMLDocument = __webpack_require__(6934);
|
|
8821
|
+
|
|
8822
|
+
XMLDocumentCB = __webpack_require__(9227);
|
|
8823
|
+
|
|
8824
|
+
XMLStringWriter = __webpack_require__(6434);
|
|
8825
|
+
|
|
8826
|
+
XMLStreamWriter = __webpack_require__(1996);
|
|
8827
|
+
|
|
8828
|
+
NodeType = __webpack_require__(9335);
|
|
8829
|
+
|
|
8830
|
+
WriterState = __webpack_require__(594);
|
|
8831
|
+
|
|
8832
|
+
module.exports.create = function(name, xmldec, doctype, options) {
|
|
8833
|
+
var doc, root;
|
|
8834
|
+
if (name == null) {
|
|
8835
|
+
throw new Error("Root element needs a name.");
|
|
8836
|
+
}
|
|
8837
|
+
options = assign({}, xmldec, doctype, options);
|
|
8838
|
+
doc = new XMLDocument(options);
|
|
8839
|
+
root = doc.element(name);
|
|
8840
|
+
if (!options.headless) {
|
|
8841
|
+
doc.declaration(options);
|
|
8842
|
+
if ((options.pubID != null) || (options.sysID != null)) {
|
|
8843
|
+
doc.dtd(options);
|
|
8844
|
+
}
|
|
8845
|
+
}
|
|
8846
|
+
return root;
|
|
8847
|
+
};
|
|
8848
|
+
|
|
8849
|
+
module.exports.begin = function(options, onData, onEnd) {
|
|
8850
|
+
var ref1;
|
|
8851
|
+
if (isFunction(options)) {
|
|
8852
|
+
ref1 = [options, onData], onData = ref1[0], onEnd = ref1[1];
|
|
8853
|
+
options = {};
|
|
8854
|
+
}
|
|
8855
|
+
if (onData) {
|
|
8856
|
+
return new XMLDocumentCB(options, onData, onEnd);
|
|
8857
|
+
} else {
|
|
8858
|
+
return new XMLDocument(options);
|
|
8859
|
+
}
|
|
8860
|
+
};
|
|
8861
|
+
|
|
8862
|
+
module.exports.stringWriter = function(options) {
|
|
8863
|
+
return new XMLStringWriter(options);
|
|
8864
|
+
};
|
|
8865
|
+
|
|
8866
|
+
module.exports.streamWriter = function(stream, options) {
|
|
8867
|
+
return new XMLStreamWriter(stream, options);
|
|
8868
|
+
};
|
|
8869
|
+
|
|
8870
|
+
module.exports.implementation = new XMLDOMImplementation();
|
|
8871
|
+
|
|
8872
|
+
module.exports.nodeType = NodeType;
|
|
8873
|
+
|
|
8874
|
+
module.exports.writerState = WriterState;
|
|
8875
|
+
|
|
8876
|
+
}).call(this);
|
|
8877
|
+
|
|
8878
|
+
|
|
8879
|
+
/***/ }),
|
|
8880
|
+
|
|
8881
|
+
/***/ 7766:
|
|
8882
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
8883
|
+
|
|
8884
|
+
var fs = __webpack_require__(6231);
|
|
8885
|
+
var zlib = __webpack_require__(8884);
|
|
8886
|
+
var fd_slicer = __webpack_require__(8913);
|
|
8887
|
+
var crc32 = __webpack_require__(2779);
|
|
8888
|
+
var util = __webpack_require__(6464);
|
|
8889
|
+
var EventEmitter = (__webpack_require__(7187).EventEmitter);
|
|
8890
|
+
var Transform = (__webpack_require__(8311).Transform);
|
|
8891
|
+
var PassThrough = (__webpack_require__(8311).PassThrough);
|
|
8892
|
+
var Writable = (__webpack_require__(8311).Writable);
|
|
8893
|
+
|
|
8894
|
+
exports.open = open;
|
|
8895
|
+
exports.fromFd = fromFd;
|
|
8896
|
+
exports.fromBuffer = fromBuffer;
|
|
8897
|
+
exports.fromRandomAccessReader = fromRandomAccessReader;
|
|
8898
|
+
exports.dosDateTimeToDate = dosDateTimeToDate;
|
|
8899
|
+
exports.validateFileName = validateFileName;
|
|
8900
|
+
exports.ZipFile = ZipFile;
|
|
8901
|
+
exports.Entry = Entry;
|
|
8902
|
+
exports.RandomAccessReader = RandomAccessReader;
|
|
8903
|
+
|
|
8904
|
+
function open(path, options, callback) {
|
|
8905
|
+
if (typeof options === "function") {
|
|
8906
|
+
callback = options;
|
|
8907
|
+
options = null;
|
|
8908
|
+
}
|
|
8909
|
+
if (options == null) options = {};
|
|
8910
|
+
if (options.autoClose == null) options.autoClose = true;
|
|
8911
|
+
if (options.lazyEntries == null) options.lazyEntries = false;
|
|
8912
|
+
if (options.decodeStrings == null) options.decodeStrings = true;
|
|
8913
|
+
if (options.validateEntrySizes == null) options.validateEntrySizes = true;
|
|
8914
|
+
if (options.strictFileNames == null) options.strictFileNames = false;
|
|
8915
|
+
if (callback == null) callback = defaultCallback;
|
|
8916
|
+
fs.open(path, "r", function(err, fd) {
|
|
8917
|
+
if (err) return callback(err);
|
|
8918
|
+
fromFd(fd, options, function(err, zipfile) {
|
|
8919
|
+
if (err) fs.close(fd, defaultCallback);
|
|
8920
|
+
callback(err, zipfile);
|
|
8921
|
+
});
|
|
8922
|
+
});
|
|
8923
|
+
}
|
|
8924
|
+
|
|
8925
|
+
function fromFd(fd, options, callback) {
|
|
8926
|
+
if (typeof options === "function") {
|
|
8927
|
+
callback = options;
|
|
8928
|
+
options = null;
|
|
8929
|
+
}
|
|
8930
|
+
if (options == null) options = {};
|
|
8931
|
+
if (options.autoClose == null) options.autoClose = false;
|
|
8932
|
+
if (options.lazyEntries == null) options.lazyEntries = false;
|
|
8933
|
+
if (options.decodeStrings == null) options.decodeStrings = true;
|
|
8934
|
+
if (options.validateEntrySizes == null) options.validateEntrySizes = true;
|
|
8935
|
+
if (options.strictFileNames == null) options.strictFileNames = false;
|
|
8936
|
+
if (callback == null) callback = defaultCallback;
|
|
8937
|
+
fs.fstat(fd, function(err, stats) {
|
|
8938
|
+
if (err) return callback(err);
|
|
8939
|
+
var reader = fd_slicer.createFromFd(fd, {autoClose: true});
|
|
8940
|
+
fromRandomAccessReader(reader, stats.size, options, callback);
|
|
8941
|
+
});
|
|
8942
|
+
}
|
|
8943
|
+
|
|
8944
|
+
function fromBuffer(buffer, options, callback) {
|
|
8945
|
+
if (typeof options === "function") {
|
|
8946
|
+
callback = options;
|
|
8947
|
+
options = null;
|
|
8948
|
+
}
|
|
8949
|
+
if (options == null) options = {};
|
|
8950
|
+
options.autoClose = false;
|
|
8951
|
+
if (options.lazyEntries == null) options.lazyEntries = false;
|
|
8952
|
+
if (options.decodeStrings == null) options.decodeStrings = true;
|
|
8953
|
+
if (options.validateEntrySizes == null) options.validateEntrySizes = true;
|
|
8954
|
+
if (options.strictFileNames == null) options.strictFileNames = false;
|
|
8955
|
+
// limit the max chunk size. see https://github.com/thejoshwolfe/yauzl/issues/87
|
|
8956
|
+
var reader = fd_slicer.createFromBuffer(buffer, {maxChunkSize: 0x10000});
|
|
8957
|
+
fromRandomAccessReader(reader, buffer.length, options, callback);
|
|
8958
|
+
}
|
|
8959
|
+
|
|
8960
|
+
function fromRandomAccessReader(reader, totalSize, options, callback) {
|
|
8961
|
+
if (typeof options === "function") {
|
|
8962
|
+
callback = options;
|
|
8963
|
+
options = null;
|
|
8964
|
+
}
|
|
8965
|
+
if (options == null) options = {};
|
|
8966
|
+
if (options.autoClose == null) options.autoClose = true;
|
|
8967
|
+
if (options.lazyEntries == null) options.lazyEntries = false;
|
|
8968
|
+
if (options.decodeStrings == null) options.decodeStrings = true;
|
|
8969
|
+
var decodeStrings = !!options.decodeStrings;
|
|
8970
|
+
if (options.validateEntrySizes == null) options.validateEntrySizes = true;
|
|
8971
|
+
if (options.strictFileNames == null) options.strictFileNames = false;
|
|
8972
|
+
if (callback == null) callback = defaultCallback;
|
|
8973
|
+
if (typeof totalSize !== "number") throw new Error("expected totalSize parameter to be a number");
|
|
8974
|
+
if (totalSize > Number.MAX_SAFE_INTEGER) {
|
|
8975
|
+
throw new Error("zip file too large. only file sizes up to 2^52 are supported due to JavaScript's Number type being an IEEE 754 double.");
|
|
8976
|
+
}
|
|
8977
|
+
|
|
8978
|
+
// the matching unref() call is in zipfile.close()
|
|
8979
|
+
reader.ref();
|
|
8980
|
+
|
|
8981
|
+
// eocdr means End of Central Directory Record.
|
|
8982
|
+
// search backwards for the eocdr signature.
|
|
8983
|
+
// the last field of the eocdr is a variable-length comment.
|
|
8984
|
+
// the comment size is encoded in a 2-byte field in the eocdr, which we can't find without trudging backwards through the comment to find it.
|
|
8985
|
+
// as a consequence of this design decision, it's possible to have ambiguous zip file metadata if a coherent eocdr was in the comment.
|
|
8986
|
+
// we search backwards for a eocdr signature, and hope that whoever made the zip file was smart enough to forbid the eocdr signature in the comment.
|
|
8987
|
+
var eocdrWithoutCommentSize = 22;
|
|
8988
|
+
var maxCommentSize = 0xffff; // 2-byte size
|
|
8989
|
+
var bufferSize = Math.min(eocdrWithoutCommentSize + maxCommentSize, totalSize);
|
|
8990
|
+
var buffer = newBuffer(bufferSize);
|
|
8991
|
+
var bufferReadStart = totalSize - buffer.length;
|
|
8992
|
+
readAndAssertNoEof(reader, buffer, 0, bufferSize, bufferReadStart, function(err) {
|
|
8993
|
+
if (err) return callback(err);
|
|
8994
|
+
for (var i = bufferSize - eocdrWithoutCommentSize; i >= 0; i -= 1) {
|
|
8995
|
+
if (buffer.readUInt32LE(i) !== 0x06054b50) continue;
|
|
8996
|
+
// found eocdr
|
|
8997
|
+
var eocdrBuffer = buffer.slice(i);
|
|
8998
|
+
|
|
8999
|
+
// 0 - End of central directory signature = 0x06054b50
|
|
9000
|
+
// 4 - Number of this disk
|
|
9001
|
+
var diskNumber = eocdrBuffer.readUInt16LE(4);
|
|
9002
|
+
if (diskNumber !== 0) {
|
|
9003
|
+
return callback(new Error("multi-disk zip files are not supported: found disk number: " + diskNumber));
|
|
9004
|
+
}
|
|
9005
|
+
// 6 - Disk where central directory starts
|
|
9006
|
+
// 8 - Number of central directory records on this disk
|
|
9007
|
+
// 10 - Total number of central directory records
|
|
9008
|
+
var entryCount = eocdrBuffer.readUInt16LE(10);
|
|
9009
|
+
// 12 - Size of central directory (bytes)
|
|
9010
|
+
// 16 - Offset of start of central directory, relative to start of archive
|
|
9011
|
+
var centralDirectoryOffset = eocdrBuffer.readUInt32LE(16);
|
|
9012
|
+
// 20 - Comment length
|
|
9013
|
+
var commentLength = eocdrBuffer.readUInt16LE(20);
|
|
9014
|
+
var expectedCommentLength = eocdrBuffer.length - eocdrWithoutCommentSize;
|
|
9015
|
+
if (commentLength !== expectedCommentLength) {
|
|
9016
|
+
return callback(new Error("invalid comment length. expected: " + expectedCommentLength + ". found: " + commentLength));
|
|
9017
|
+
}
|
|
9018
|
+
// 22 - Comment
|
|
9019
|
+
// the encoding is always cp437.
|
|
9020
|
+
var comment = decodeStrings ? decodeBuffer(eocdrBuffer, 22, eocdrBuffer.length, false)
|
|
9021
|
+
: eocdrBuffer.slice(22);
|
|
9022
|
+
|
|
9023
|
+
if (!(entryCount === 0xffff || centralDirectoryOffset === 0xffffffff)) {
|
|
9024
|
+
return callback(null, new ZipFile(reader, centralDirectoryOffset, totalSize, entryCount, comment, options.autoClose, options.lazyEntries, decodeStrings, options.validateEntrySizes, options.strictFileNames));
|
|
9025
|
+
}
|
|
9026
|
+
|
|
9027
|
+
// ZIP64 format
|
|
9028
|
+
|
|
9029
|
+
// ZIP64 Zip64 end of central directory locator
|
|
9030
|
+
var zip64EocdlBuffer = newBuffer(20);
|
|
9031
|
+
var zip64EocdlOffset = bufferReadStart + i - zip64EocdlBuffer.length;
|
|
9032
|
+
readAndAssertNoEof(reader, zip64EocdlBuffer, 0, zip64EocdlBuffer.length, zip64EocdlOffset, function(err) {
|
|
9033
|
+
if (err) return callback(err);
|
|
9034
|
+
|
|
9035
|
+
// 0 - zip64 end of central dir locator signature = 0x07064b50
|
|
9036
|
+
if (zip64EocdlBuffer.readUInt32LE(0) !== 0x07064b50) {
|
|
9037
|
+
return callback(new Error("invalid zip64 end of central directory locator signature"));
|
|
9038
|
+
}
|
|
9039
|
+
// 4 - number of the disk with the start of the zip64 end of central directory
|
|
9040
|
+
// 8 - relative offset of the zip64 end of central directory record
|
|
9041
|
+
var zip64EocdrOffset = readUInt64LE(zip64EocdlBuffer, 8);
|
|
9042
|
+
// 16 - total number of disks
|
|
9043
|
+
|
|
9044
|
+
// ZIP64 end of central directory record
|
|
9045
|
+
var zip64EocdrBuffer = newBuffer(56);
|
|
9046
|
+
readAndAssertNoEof(reader, zip64EocdrBuffer, 0, zip64EocdrBuffer.length, zip64EocdrOffset, function(err) {
|
|
9047
|
+
if (err) return callback(err);
|
|
9048
|
+
|
|
9049
|
+
// 0 - zip64 end of central dir signature 4 bytes (0x06064b50)
|
|
9050
|
+
if (zip64EocdrBuffer.readUInt32LE(0) !== 0x06064b50) {
|
|
9051
|
+
return callback(new Error("invalid zip64 end of central directory record signature"));
|
|
9052
|
+
}
|
|
9053
|
+
// 4 - size of zip64 end of central directory record 8 bytes
|
|
9054
|
+
// 12 - version made by 2 bytes
|
|
9055
|
+
// 14 - version needed to extract 2 bytes
|
|
9056
|
+
// 16 - number of this disk 4 bytes
|
|
9057
|
+
// 20 - number of the disk with the start of the central directory 4 bytes
|
|
9058
|
+
// 24 - total number of entries in the central directory on this disk 8 bytes
|
|
9059
|
+
// 32 - total number of entries in the central directory 8 bytes
|
|
9060
|
+
entryCount = readUInt64LE(zip64EocdrBuffer, 32);
|
|
9061
|
+
// 40 - size of the central directory 8 bytes
|
|
9062
|
+
// 48 - offset of start of central directory with respect to the starting disk number 8 bytes
|
|
9063
|
+
centralDirectoryOffset = readUInt64LE(zip64EocdrBuffer, 48);
|
|
9064
|
+
// 56 - zip64 extensible data sector (variable size)
|
|
9065
|
+
return callback(null, new ZipFile(reader, centralDirectoryOffset, totalSize, entryCount, comment, options.autoClose, options.lazyEntries, decodeStrings, options.validateEntrySizes, options.strictFileNames));
|
|
9066
|
+
});
|
|
9067
|
+
});
|
|
9068
|
+
return;
|
|
9069
|
+
}
|
|
9070
|
+
callback(new Error("end of central directory record signature not found"));
|
|
9071
|
+
});
|
|
9072
|
+
}
|
|
9073
|
+
|
|
9074
|
+
util.inherits(ZipFile, EventEmitter);
|
|
9075
|
+
function ZipFile(reader, centralDirectoryOffset, fileSize, entryCount, comment, autoClose, lazyEntries, decodeStrings, validateEntrySizes, strictFileNames) {
|
|
9076
|
+
var self = this;
|
|
9077
|
+
EventEmitter.call(self);
|
|
9078
|
+
self.reader = reader;
|
|
9079
|
+
// forward close events
|
|
9080
|
+
self.reader.on("error", function(err) {
|
|
9081
|
+
// error closing the fd
|
|
9082
|
+
emitError(self, err);
|
|
9083
|
+
});
|
|
9084
|
+
self.reader.once("close", function() {
|
|
9085
|
+
self.emit("close");
|
|
9086
|
+
});
|
|
9087
|
+
self.readEntryCursor = centralDirectoryOffset;
|
|
9088
|
+
self.fileSize = fileSize;
|
|
9089
|
+
self.entryCount = entryCount;
|
|
9090
|
+
self.comment = comment;
|
|
9091
|
+
self.entriesRead = 0;
|
|
9092
|
+
self.autoClose = !!autoClose;
|
|
9093
|
+
self.lazyEntries = !!lazyEntries;
|
|
9094
|
+
self.decodeStrings = !!decodeStrings;
|
|
9095
|
+
self.validateEntrySizes = !!validateEntrySizes;
|
|
9096
|
+
self.strictFileNames = !!strictFileNames;
|
|
9097
|
+
self.isOpen = true;
|
|
9098
|
+
self.emittedError = false;
|
|
9099
|
+
|
|
9100
|
+
if (!self.lazyEntries) self._readEntry();
|
|
9101
|
+
}
|
|
9102
|
+
ZipFile.prototype.close = function() {
|
|
9103
|
+
if (!this.isOpen) return;
|
|
9104
|
+
this.isOpen = false;
|
|
9105
|
+
this.reader.unref();
|
|
9106
|
+
};
|
|
9107
|
+
|
|
9108
|
+
function emitErrorAndAutoClose(self, err) {
|
|
9109
|
+
if (self.autoClose) self.close();
|
|
9110
|
+
emitError(self, err);
|
|
9111
|
+
}
|
|
9112
|
+
function emitError(self, err) {
|
|
9113
|
+
if (self.emittedError) return;
|
|
9114
|
+
self.emittedError = true;
|
|
9115
|
+
self.emit("error", err);
|
|
9116
|
+
}
|
|
9117
|
+
|
|
9118
|
+
ZipFile.prototype.readEntry = function() {
|
|
9119
|
+
if (!this.lazyEntries) throw new Error("readEntry() called without lazyEntries:true");
|
|
9120
|
+
this._readEntry();
|
|
9121
|
+
};
|
|
9122
|
+
ZipFile.prototype._readEntry = function() {
|
|
9123
|
+
var self = this;
|
|
9124
|
+
if (self.entryCount === self.entriesRead) {
|
|
9125
|
+
// done with metadata
|
|
9126
|
+
setImmediate(function() {
|
|
9127
|
+
if (self.autoClose) self.close();
|
|
9128
|
+
if (self.emittedError) return;
|
|
9129
|
+
self.emit("end");
|
|
9130
|
+
});
|
|
9131
|
+
return;
|
|
9132
|
+
}
|
|
9133
|
+
if (self.emittedError) return;
|
|
9134
|
+
var buffer = newBuffer(46);
|
|
9135
|
+
readAndAssertNoEof(self.reader, buffer, 0, buffer.length, self.readEntryCursor, function(err) {
|
|
9136
|
+
if (err) return emitErrorAndAutoClose(self, err);
|
|
9137
|
+
if (self.emittedError) return;
|
|
9138
|
+
var entry = new Entry();
|
|
9139
|
+
// 0 - Central directory file header signature
|
|
9140
|
+
var signature = buffer.readUInt32LE(0);
|
|
9141
|
+
if (signature !== 0x02014b50) return emitErrorAndAutoClose(self, new Error("invalid central directory file header signature: 0x" + signature.toString(16)));
|
|
9142
|
+
// 4 - Version made by
|
|
9143
|
+
entry.versionMadeBy = buffer.readUInt16LE(4);
|
|
9144
|
+
// 6 - Version needed to extract (minimum)
|
|
9145
|
+
entry.versionNeededToExtract = buffer.readUInt16LE(6);
|
|
9146
|
+
// 8 - General purpose bit flag
|
|
9147
|
+
entry.generalPurposeBitFlag = buffer.readUInt16LE(8);
|
|
9148
|
+
// 10 - Compression method
|
|
9149
|
+
entry.compressionMethod = buffer.readUInt16LE(10);
|
|
9150
|
+
// 12 - File last modification time
|
|
9151
|
+
entry.lastModFileTime = buffer.readUInt16LE(12);
|
|
9152
|
+
// 14 - File last modification date
|
|
9153
|
+
entry.lastModFileDate = buffer.readUInt16LE(14);
|
|
9154
|
+
// 16 - CRC-32
|
|
9155
|
+
entry.crc32 = buffer.readUInt32LE(16);
|
|
9156
|
+
// 20 - Compressed size
|
|
9157
|
+
entry.compressedSize = buffer.readUInt32LE(20);
|
|
9158
|
+
// 24 - Uncompressed size
|
|
9159
|
+
entry.uncompressedSize = buffer.readUInt32LE(24);
|
|
9160
|
+
// 28 - File name length (n)
|
|
9161
|
+
entry.fileNameLength = buffer.readUInt16LE(28);
|
|
9162
|
+
// 30 - Extra field length (m)
|
|
9163
|
+
entry.extraFieldLength = buffer.readUInt16LE(30);
|
|
9164
|
+
// 32 - File comment length (k)
|
|
9165
|
+
entry.fileCommentLength = buffer.readUInt16LE(32);
|
|
9166
|
+
// 34 - Disk number where file starts
|
|
9167
|
+
// 36 - Internal file attributes
|
|
9168
|
+
entry.internalFileAttributes = buffer.readUInt16LE(36);
|
|
9169
|
+
// 38 - External file attributes
|
|
9170
|
+
entry.externalFileAttributes = buffer.readUInt32LE(38);
|
|
9171
|
+
// 42 - Relative offset of local file header
|
|
9172
|
+
entry.relativeOffsetOfLocalHeader = buffer.readUInt32LE(42);
|
|
9173
|
+
|
|
9174
|
+
if (entry.generalPurposeBitFlag & 0x40) return emitErrorAndAutoClose(self, new Error("strong encryption is not supported"));
|
|
9175
|
+
|
|
9176
|
+
self.readEntryCursor += 46;
|
|
9177
|
+
|
|
9178
|
+
buffer = newBuffer(entry.fileNameLength + entry.extraFieldLength + entry.fileCommentLength);
|
|
9179
|
+
readAndAssertNoEof(self.reader, buffer, 0, buffer.length, self.readEntryCursor, function(err) {
|
|
9180
|
+
if (err) return emitErrorAndAutoClose(self, err);
|
|
9181
|
+
if (self.emittedError) return;
|
|
9182
|
+
// 46 - File name
|
|
9183
|
+
var isUtf8 = (entry.generalPurposeBitFlag & 0x800) !== 0;
|
|
9184
|
+
entry.fileName = self.decodeStrings ? decodeBuffer(buffer, 0, entry.fileNameLength, isUtf8)
|
|
9185
|
+
: buffer.slice(0, entry.fileNameLength);
|
|
9186
|
+
|
|
9187
|
+
// 46+n - Extra field
|
|
9188
|
+
var fileCommentStart = entry.fileNameLength + entry.extraFieldLength;
|
|
9189
|
+
var extraFieldBuffer = buffer.slice(entry.fileNameLength, fileCommentStart);
|
|
9190
|
+
entry.extraFields = [];
|
|
9191
|
+
var i = 0;
|
|
9192
|
+
while (i < extraFieldBuffer.length - 3) {
|
|
9193
|
+
var headerId = extraFieldBuffer.readUInt16LE(i + 0);
|
|
9194
|
+
var dataSize = extraFieldBuffer.readUInt16LE(i + 2);
|
|
9195
|
+
var dataStart = i + 4;
|
|
9196
|
+
var dataEnd = dataStart + dataSize;
|
|
9197
|
+
if (dataEnd > extraFieldBuffer.length) return emitErrorAndAutoClose(self, new Error("extra field length exceeds extra field buffer size"));
|
|
9198
|
+
var dataBuffer = newBuffer(dataSize);
|
|
9199
|
+
extraFieldBuffer.copy(dataBuffer, 0, dataStart, dataEnd);
|
|
9200
|
+
entry.extraFields.push({
|
|
9201
|
+
id: headerId,
|
|
9202
|
+
data: dataBuffer,
|
|
9203
|
+
});
|
|
9204
|
+
i = dataEnd;
|
|
9205
|
+
}
|
|
9206
|
+
|
|
9207
|
+
// 46+n+m - File comment
|
|
9208
|
+
entry.fileComment = self.decodeStrings ? decodeBuffer(buffer, fileCommentStart, fileCommentStart + entry.fileCommentLength, isUtf8)
|
|
9209
|
+
: buffer.slice(fileCommentStart, fileCommentStart + entry.fileCommentLength);
|
|
9210
|
+
// compatibility hack for https://github.com/thejoshwolfe/yauzl/issues/47
|
|
9211
|
+
entry.comment = entry.fileComment;
|
|
9212
|
+
|
|
9213
|
+
self.readEntryCursor += buffer.length;
|
|
9214
|
+
self.entriesRead += 1;
|
|
9215
|
+
|
|
9216
|
+
if (entry.uncompressedSize === 0xffffffff ||
|
|
9217
|
+
entry.compressedSize === 0xffffffff ||
|
|
9218
|
+
entry.relativeOffsetOfLocalHeader === 0xffffffff) {
|
|
9219
|
+
// ZIP64 format
|
|
9220
|
+
// find the Zip64 Extended Information Extra Field
|
|
9221
|
+
var zip64EiefBuffer = null;
|
|
9222
|
+
for (var i = 0; i < entry.extraFields.length; i++) {
|
|
9223
|
+
var extraField = entry.extraFields[i];
|
|
9224
|
+
if (extraField.id === 0x0001) {
|
|
9225
|
+
zip64EiefBuffer = extraField.data;
|
|
9226
|
+
break;
|
|
9227
|
+
}
|
|
9228
|
+
}
|
|
9229
|
+
if (zip64EiefBuffer == null) {
|
|
9230
|
+
return emitErrorAndAutoClose(self, new Error("expected zip64 extended information extra field"));
|
|
9231
|
+
}
|
|
9232
|
+
var index = 0;
|
|
9233
|
+
// 0 - Original Size 8 bytes
|
|
9234
|
+
if (entry.uncompressedSize === 0xffffffff) {
|
|
9235
|
+
if (index + 8 > zip64EiefBuffer.length) {
|
|
9236
|
+
return emitErrorAndAutoClose(self, new Error("zip64 extended information extra field does not include uncompressed size"));
|
|
9237
|
+
}
|
|
9238
|
+
entry.uncompressedSize = readUInt64LE(zip64EiefBuffer, index);
|
|
9239
|
+
index += 8;
|
|
9240
|
+
}
|
|
9241
|
+
// 8 - Compressed Size 8 bytes
|
|
9242
|
+
if (entry.compressedSize === 0xffffffff) {
|
|
9243
|
+
if (index + 8 > zip64EiefBuffer.length) {
|
|
9244
|
+
return emitErrorAndAutoClose(self, new Error("zip64 extended information extra field does not include compressed size"));
|
|
9245
|
+
}
|
|
9246
|
+
entry.compressedSize = readUInt64LE(zip64EiefBuffer, index);
|
|
9247
|
+
index += 8;
|
|
9248
|
+
}
|
|
9249
|
+
// 16 - Relative Header Offset 8 bytes
|
|
9250
|
+
if (entry.relativeOffsetOfLocalHeader === 0xffffffff) {
|
|
9251
|
+
if (index + 8 > zip64EiefBuffer.length) {
|
|
9252
|
+
return emitErrorAndAutoClose(self, new Error("zip64 extended information extra field does not include relative header offset"));
|
|
9253
|
+
}
|
|
9254
|
+
entry.relativeOffsetOfLocalHeader = readUInt64LE(zip64EiefBuffer, index);
|
|
9255
|
+
index += 8;
|
|
9256
|
+
}
|
|
9257
|
+
// 24 - Disk Start Number 4 bytes
|
|
9258
|
+
}
|
|
9259
|
+
|
|
9260
|
+
// check for Info-ZIP Unicode Path Extra Field (0x7075)
|
|
9261
|
+
// see https://github.com/thejoshwolfe/yauzl/issues/33
|
|
9262
|
+
if (self.decodeStrings) {
|
|
9263
|
+
for (var i = 0; i < entry.extraFields.length; i++) {
|
|
9264
|
+
var extraField = entry.extraFields[i];
|
|
9265
|
+
if (extraField.id === 0x7075) {
|
|
9266
|
+
if (extraField.data.length < 6) {
|
|
9267
|
+
// too short to be meaningful
|
|
9268
|
+
continue;
|
|
9269
|
+
}
|
|
9270
|
+
// Version 1 byte version of this extra field, currently 1
|
|
9271
|
+
if (extraField.data.readUInt8(0) !== 1) {
|
|
9272
|
+
// > Changes may not be backward compatible so this extra
|
|
9273
|
+
// > field should not be used if the version is not recognized.
|
|
9274
|
+
continue;
|
|
9275
|
+
}
|
|
9276
|
+
// NameCRC32 4 bytes File Name Field CRC32 Checksum
|
|
9277
|
+
var oldNameCrc32 = extraField.data.readUInt32LE(1);
|
|
9278
|
+
if (crc32.unsigned(buffer.slice(0, entry.fileNameLength)) !== oldNameCrc32) {
|
|
9279
|
+
// > If the CRC check fails, this UTF-8 Path Extra Field should be
|
|
9280
|
+
// > ignored and the File Name field in the header should be used instead.
|
|
9281
|
+
continue;
|
|
9282
|
+
}
|
|
9283
|
+
// UnicodeName Variable UTF-8 version of the entry File Name
|
|
9284
|
+
entry.fileName = decodeBuffer(extraField.data, 5, extraField.data.length, true);
|
|
9285
|
+
break;
|
|
9286
|
+
}
|
|
9287
|
+
}
|
|
9288
|
+
}
|
|
9289
|
+
|
|
9290
|
+
// validate file size
|
|
9291
|
+
if (self.validateEntrySizes && entry.compressionMethod === 0) {
|
|
9292
|
+
var expectedCompressedSize = entry.uncompressedSize;
|
|
9293
|
+
if (entry.isEncrypted()) {
|
|
9294
|
+
// traditional encryption prefixes the file data with a header
|
|
9295
|
+
expectedCompressedSize += 12;
|
|
9296
|
+
}
|
|
9297
|
+
if (entry.compressedSize !== expectedCompressedSize) {
|
|
9298
|
+
var msg = "compressed/uncompressed size mismatch for stored file: " + entry.compressedSize + " != " + entry.uncompressedSize;
|
|
9299
|
+
return emitErrorAndAutoClose(self, new Error(msg));
|
|
9300
|
+
}
|
|
9301
|
+
}
|
|
9302
|
+
|
|
9303
|
+
if (self.decodeStrings) {
|
|
9304
|
+
if (!self.strictFileNames) {
|
|
9305
|
+
// allow backslash
|
|
9306
|
+
entry.fileName = entry.fileName.replace(/\\/g, "/");
|
|
9307
|
+
}
|
|
9308
|
+
var errorMessage = validateFileName(entry.fileName, self.validateFileNameOptions);
|
|
9309
|
+
if (errorMessage != null) return emitErrorAndAutoClose(self, new Error(errorMessage));
|
|
9310
|
+
}
|
|
9311
|
+
self.emit("entry", entry);
|
|
9312
|
+
|
|
9313
|
+
if (!self.lazyEntries) self._readEntry();
|
|
9314
|
+
});
|
|
9315
|
+
});
|
|
9316
|
+
};
|
|
9317
|
+
|
|
9318
|
+
ZipFile.prototype.openReadStream = function(entry, options, callback) {
|
|
9319
|
+
var self = this;
|
|
9320
|
+
// parameter validation
|
|
9321
|
+
var relativeStart = 0;
|
|
9322
|
+
var relativeEnd = entry.compressedSize;
|
|
9323
|
+
if (callback == null) {
|
|
9324
|
+
callback = options;
|
|
9325
|
+
options = {};
|
|
9326
|
+
} else {
|
|
9327
|
+
// validate options that the caller has no excuse to get wrong
|
|
9328
|
+
if (options.decrypt != null) {
|
|
9329
|
+
if (!entry.isEncrypted()) {
|
|
9330
|
+
throw new Error("options.decrypt can only be specified for encrypted entries");
|
|
9331
|
+
}
|
|
9332
|
+
if (options.decrypt !== false) throw new Error("invalid options.decrypt value: " + options.decrypt);
|
|
9333
|
+
if (entry.isCompressed()) {
|
|
9334
|
+
if (options.decompress !== false) throw new Error("entry is encrypted and compressed, and options.decompress !== false");
|
|
9335
|
+
}
|
|
9336
|
+
}
|
|
9337
|
+
if (options.decompress != null) {
|
|
9338
|
+
if (!entry.isCompressed()) {
|
|
9339
|
+
throw new Error("options.decompress can only be specified for compressed entries");
|
|
9340
|
+
}
|
|
9341
|
+
if (!(options.decompress === false || options.decompress === true)) {
|
|
9342
|
+
throw new Error("invalid options.decompress value: " + options.decompress);
|
|
9343
|
+
}
|
|
9344
|
+
}
|
|
9345
|
+
if (options.start != null || options.end != null) {
|
|
9346
|
+
if (entry.isCompressed() && options.decompress !== false) {
|
|
9347
|
+
throw new Error("start/end range not allowed for compressed entry without options.decompress === false");
|
|
9348
|
+
}
|
|
9349
|
+
if (entry.isEncrypted() && options.decrypt !== false) {
|
|
9350
|
+
throw new Error("start/end range not allowed for encrypted entry without options.decrypt === false");
|
|
9351
|
+
}
|
|
9352
|
+
}
|
|
9353
|
+
if (options.start != null) {
|
|
9354
|
+
relativeStart = options.start;
|
|
9355
|
+
if (relativeStart < 0) throw new Error("options.start < 0");
|
|
9356
|
+
if (relativeStart > entry.compressedSize) throw new Error("options.start > entry.compressedSize");
|
|
9357
|
+
}
|
|
9358
|
+
if (options.end != null) {
|
|
9359
|
+
relativeEnd = options.end;
|
|
9360
|
+
if (relativeEnd < 0) throw new Error("options.end < 0");
|
|
9361
|
+
if (relativeEnd > entry.compressedSize) throw new Error("options.end > entry.compressedSize");
|
|
9362
|
+
if (relativeEnd < relativeStart) throw new Error("options.end < options.start");
|
|
9363
|
+
}
|
|
9364
|
+
}
|
|
9365
|
+
// any further errors can either be caused by the zipfile,
|
|
9366
|
+
// or were introduced in a minor version of yauzl,
|
|
9367
|
+
// so should be passed to the client rather than thrown.
|
|
9368
|
+
if (!self.isOpen) return callback(new Error("closed"));
|
|
9369
|
+
if (entry.isEncrypted()) {
|
|
9370
|
+
if (options.decrypt !== false) return callback(new Error("entry is encrypted, and options.decrypt !== false"));
|
|
9371
|
+
}
|
|
9372
|
+
// make sure we don't lose the fd before we open the actual read stream
|
|
9373
|
+
self.reader.ref();
|
|
9374
|
+
var buffer = newBuffer(30);
|
|
9375
|
+
readAndAssertNoEof(self.reader, buffer, 0, buffer.length, entry.relativeOffsetOfLocalHeader, function(err) {
|
|
9376
|
+
try {
|
|
9377
|
+
if (err) return callback(err);
|
|
9378
|
+
// 0 - Local file header signature = 0x04034b50
|
|
9379
|
+
var signature = buffer.readUInt32LE(0);
|
|
9380
|
+
if (signature !== 0x04034b50) {
|
|
9381
|
+
return callback(new Error("invalid local file header signature: 0x" + signature.toString(16)));
|
|
9382
|
+
}
|
|
9383
|
+
// all this should be redundant
|
|
9384
|
+
// 4 - Version needed to extract (minimum)
|
|
9385
|
+
// 6 - General purpose bit flag
|
|
9386
|
+
// 8 - Compression method
|
|
9387
|
+
// 10 - File last modification time
|
|
9388
|
+
// 12 - File last modification date
|
|
9389
|
+
// 14 - CRC-32
|
|
9390
|
+
// 18 - Compressed size
|
|
9391
|
+
// 22 - Uncompressed size
|
|
9392
|
+
// 26 - File name length (n)
|
|
9393
|
+
var fileNameLength = buffer.readUInt16LE(26);
|
|
9394
|
+
// 28 - Extra field length (m)
|
|
9395
|
+
var extraFieldLength = buffer.readUInt16LE(28);
|
|
9396
|
+
// 30 - File name
|
|
9397
|
+
// 30+n - Extra field
|
|
9398
|
+
var localFileHeaderEnd = entry.relativeOffsetOfLocalHeader + buffer.length + fileNameLength + extraFieldLength;
|
|
9399
|
+
var decompress;
|
|
9400
|
+
if (entry.compressionMethod === 0) {
|
|
9401
|
+
// 0 - The file is stored (no compression)
|
|
9402
|
+
decompress = false;
|
|
9403
|
+
} else if (entry.compressionMethod === 8) {
|
|
9404
|
+
// 8 - The file is Deflated
|
|
9405
|
+
decompress = options.decompress != null ? options.decompress : true;
|
|
9406
|
+
} else {
|
|
9407
|
+
return callback(new Error("unsupported compression method: " + entry.compressionMethod));
|
|
9408
|
+
}
|
|
9409
|
+
var fileDataStart = localFileHeaderEnd;
|
|
9410
|
+
var fileDataEnd = fileDataStart + entry.compressedSize;
|
|
9411
|
+
if (entry.compressedSize !== 0) {
|
|
9412
|
+
// bounds check now, because the read streams will probably not complain loud enough.
|
|
9413
|
+
// since we're dealing with an unsigned offset plus an unsigned size,
|
|
9414
|
+
// we only have 1 thing to check for.
|
|
9415
|
+
if (fileDataEnd > self.fileSize) {
|
|
9416
|
+
return callback(new Error("file data overflows file bounds: " +
|
|
9417
|
+
fileDataStart + " + " + entry.compressedSize + " > " + self.fileSize));
|
|
9418
|
+
}
|
|
9419
|
+
}
|
|
9420
|
+
var readStream = self.reader.createReadStream({
|
|
9421
|
+
start: fileDataStart + relativeStart,
|
|
9422
|
+
end: fileDataStart + relativeEnd,
|
|
9423
|
+
});
|
|
9424
|
+
var endpointStream = readStream;
|
|
9425
|
+
if (decompress) {
|
|
9426
|
+
var destroyed = false;
|
|
9427
|
+
var inflateFilter = zlib.createInflateRaw();
|
|
9428
|
+
readStream.on("error", function(err) {
|
|
9429
|
+
// setImmediate here because errors can be emitted during the first call to pipe()
|
|
9430
|
+
setImmediate(function() {
|
|
9431
|
+
if (!destroyed) inflateFilter.emit("error", err);
|
|
9432
|
+
});
|
|
9433
|
+
});
|
|
9434
|
+
readStream.pipe(inflateFilter);
|
|
9435
|
+
|
|
9436
|
+
if (self.validateEntrySizes) {
|
|
9437
|
+
endpointStream = new AssertByteCountStream(entry.uncompressedSize);
|
|
9438
|
+
inflateFilter.on("error", function(err) {
|
|
9439
|
+
// forward zlib errors to the client-visible stream
|
|
9440
|
+
setImmediate(function() {
|
|
9441
|
+
if (!destroyed) endpointStream.emit("error", err);
|
|
9442
|
+
});
|
|
9443
|
+
});
|
|
9444
|
+
inflateFilter.pipe(endpointStream);
|
|
9445
|
+
} else {
|
|
9446
|
+
// the zlib filter is the client-visible stream
|
|
9447
|
+
endpointStream = inflateFilter;
|
|
9448
|
+
}
|
|
9449
|
+
// this is part of yauzl's API, so implement this function on the client-visible stream
|
|
9450
|
+
endpointStream.destroy = function() {
|
|
9451
|
+
destroyed = true;
|
|
9452
|
+
if (inflateFilter !== endpointStream) inflateFilter.unpipe(endpointStream);
|
|
9453
|
+
readStream.unpipe(inflateFilter);
|
|
9454
|
+
// TODO: the inflateFilter may cause a memory leak. see Issue #27.
|
|
9455
|
+
readStream.destroy();
|
|
9456
|
+
};
|
|
9457
|
+
}
|
|
9458
|
+
callback(null, endpointStream);
|
|
9459
|
+
} finally {
|
|
9460
|
+
self.reader.unref();
|
|
9461
|
+
}
|
|
9462
|
+
});
|
|
9463
|
+
};
|
|
9464
|
+
|
|
9465
|
+
function Entry() {
|
|
9466
|
+
}
|
|
9467
|
+
Entry.prototype.getLastModDate = function() {
|
|
9468
|
+
return dosDateTimeToDate(this.lastModFileDate, this.lastModFileTime);
|
|
9469
|
+
};
|
|
9470
|
+
Entry.prototype.isEncrypted = function() {
|
|
9471
|
+
return (this.generalPurposeBitFlag & 0x1) !== 0;
|
|
9472
|
+
};
|
|
9473
|
+
Entry.prototype.isCompressed = function() {
|
|
9474
|
+
return this.compressionMethod === 8;
|
|
9475
|
+
};
|
|
9476
|
+
|
|
9477
|
+
function dosDateTimeToDate(date, time) {
|
|
9478
|
+
var day = date & 0x1f; // 1-31
|
|
9479
|
+
var month = (date >> 5 & 0xf) - 1; // 1-12, 0-11
|
|
9480
|
+
var year = (date >> 9 & 0x7f) + 1980; // 0-128, 1980-2108
|
|
9481
|
+
|
|
9482
|
+
var millisecond = 0;
|
|
9483
|
+
var second = (time & 0x1f) * 2; // 0-29, 0-58 (even numbers)
|
|
9484
|
+
var minute = time >> 5 & 0x3f; // 0-59
|
|
9485
|
+
var hour = time >> 11 & 0x1f; // 0-23
|
|
9486
|
+
|
|
9487
|
+
return new Date(year, month, day, hour, minute, second, millisecond);
|
|
9488
|
+
}
|
|
9489
|
+
|
|
9490
|
+
function validateFileName(fileName) {
|
|
9491
|
+
if (fileName.indexOf("\\") !== -1) {
|
|
9492
|
+
return "invalid characters in fileName: " + fileName;
|
|
9493
|
+
}
|
|
9494
|
+
if (/^[a-zA-Z]:/.test(fileName) || /^\//.test(fileName)) {
|
|
9495
|
+
return "absolute path: " + fileName;
|
|
9496
|
+
}
|
|
9497
|
+
if (fileName.split("/").indexOf("..") !== -1) {
|
|
9498
|
+
return "invalid relative path: " + fileName;
|
|
9499
|
+
}
|
|
9500
|
+
// all good
|
|
9501
|
+
return null;
|
|
9502
|
+
}
|
|
9503
|
+
|
|
9504
|
+
function readAndAssertNoEof(reader, buffer, offset, length, position, callback) {
|
|
9505
|
+
if (length === 0) {
|
|
9506
|
+
// fs.read will throw an out-of-bounds error if you try to read 0 bytes from a 0 byte file
|
|
9507
|
+
return setImmediate(function() { callback(null, newBuffer(0)); });
|
|
9508
|
+
}
|
|
9509
|
+
reader.read(buffer, offset, length, position, function(err, bytesRead) {
|
|
9510
|
+
if (err) return callback(err);
|
|
9511
|
+
if (bytesRead < length) {
|
|
9512
|
+
return callback(new Error("unexpected EOF"));
|
|
9513
|
+
}
|
|
9514
|
+
callback();
|
|
9515
|
+
});
|
|
9516
|
+
}
|
|
9517
|
+
|
|
9518
|
+
util.inherits(AssertByteCountStream, Transform);
|
|
9519
|
+
function AssertByteCountStream(byteCount) {
|
|
9520
|
+
Transform.call(this);
|
|
9521
|
+
this.actualByteCount = 0;
|
|
9522
|
+
this.expectedByteCount = byteCount;
|
|
9523
|
+
}
|
|
9524
|
+
AssertByteCountStream.prototype._transform = function(chunk, encoding, cb) {
|
|
9525
|
+
this.actualByteCount += chunk.length;
|
|
9526
|
+
if (this.actualByteCount > this.expectedByteCount) {
|
|
9527
|
+
var msg = "too many bytes in the stream. expected " + this.expectedByteCount + ". got at least " + this.actualByteCount;
|
|
9528
|
+
return cb(new Error(msg));
|
|
9529
|
+
}
|
|
9530
|
+
cb(null, chunk);
|
|
9531
|
+
};
|
|
9532
|
+
AssertByteCountStream.prototype._flush = function(cb) {
|
|
9533
|
+
if (this.actualByteCount < this.expectedByteCount) {
|
|
9534
|
+
var msg = "not enough bytes in the stream. expected " + this.expectedByteCount + ". got only " + this.actualByteCount;
|
|
9535
|
+
return cb(new Error(msg));
|
|
9536
|
+
}
|
|
9537
|
+
cb();
|
|
9538
|
+
};
|
|
9539
|
+
|
|
9540
|
+
util.inherits(RandomAccessReader, EventEmitter);
|
|
9541
|
+
function RandomAccessReader() {
|
|
9542
|
+
EventEmitter.call(this);
|
|
9543
|
+
this.refCount = 0;
|
|
9544
|
+
}
|
|
9545
|
+
RandomAccessReader.prototype.ref = function() {
|
|
9546
|
+
this.refCount += 1;
|
|
9547
|
+
};
|
|
9548
|
+
RandomAccessReader.prototype.unref = function() {
|
|
9549
|
+
var self = this;
|
|
9550
|
+
self.refCount -= 1;
|
|
7021
9551
|
|
|
7022
|
-
|
|
9552
|
+
if (self.refCount > 0) return;
|
|
9553
|
+
if (self.refCount < 0) throw new Error("invalid unref");
|
|
7023
9554
|
|
|
7024
|
-
|
|
9555
|
+
self.close(onCloseDone);
|
|
7025
9556
|
|
|
7026
|
-
|
|
9557
|
+
function onCloseDone(err) {
|
|
9558
|
+
if (err) return self.emit('error', err);
|
|
9559
|
+
self.emit('close');
|
|
9560
|
+
}
|
|
9561
|
+
};
|
|
9562
|
+
RandomAccessReader.prototype.createReadStream = function(options) {
|
|
9563
|
+
var start = options.start;
|
|
9564
|
+
var end = options.end;
|
|
9565
|
+
if (start === end) {
|
|
9566
|
+
var emptyStream = new PassThrough();
|
|
9567
|
+
setImmediate(function() {
|
|
9568
|
+
emptyStream.end();
|
|
9569
|
+
});
|
|
9570
|
+
return emptyStream;
|
|
9571
|
+
}
|
|
9572
|
+
var stream = this._readStreamForRange(start, end);
|
|
7027
9573
|
|
|
7028
|
-
|
|
9574
|
+
var destroyed = false;
|
|
9575
|
+
var refUnrefFilter = new RefUnrefFilter(this);
|
|
9576
|
+
stream.on("error", function(err) {
|
|
9577
|
+
setImmediate(function() {
|
|
9578
|
+
if (!destroyed) refUnrefFilter.emit("error", err);
|
|
9579
|
+
});
|
|
9580
|
+
});
|
|
9581
|
+
refUnrefFilter.destroy = function() {
|
|
9582
|
+
stream.unpipe(refUnrefFilter);
|
|
9583
|
+
refUnrefFilter.unref();
|
|
9584
|
+
stream.destroy();
|
|
9585
|
+
};
|
|
7029
9586
|
|
|
7030
|
-
|
|
9587
|
+
var byteCounter = new AssertByteCountStream(end - start);
|
|
9588
|
+
refUnrefFilter.on("error", function(err) {
|
|
9589
|
+
setImmediate(function() {
|
|
9590
|
+
if (!destroyed) byteCounter.emit("error", err);
|
|
9591
|
+
});
|
|
9592
|
+
});
|
|
9593
|
+
byteCounter.destroy = function() {
|
|
9594
|
+
destroyed = true;
|
|
9595
|
+
refUnrefFilter.unpipe(byteCounter);
|
|
9596
|
+
refUnrefFilter.destroy();
|
|
9597
|
+
};
|
|
7031
9598
|
|
|
7032
|
-
|
|
9599
|
+
return stream.pipe(refUnrefFilter).pipe(byteCounter);
|
|
9600
|
+
};
|
|
9601
|
+
RandomAccessReader.prototype._readStreamForRange = function(start, end) {
|
|
9602
|
+
throw new Error("not implemented");
|
|
9603
|
+
};
|
|
9604
|
+
RandomAccessReader.prototype.read = function(buffer, offset, length, position, callback) {
|
|
9605
|
+
var readStream = this.createReadStream({start: position, end: position + length});
|
|
9606
|
+
var writeStream = new Writable();
|
|
9607
|
+
var written = 0;
|
|
9608
|
+
writeStream._write = function(chunk, encoding, cb) {
|
|
9609
|
+
chunk.copy(buffer, offset + written, 0, chunk.length);
|
|
9610
|
+
written += chunk.length;
|
|
9611
|
+
cb();
|
|
9612
|
+
};
|
|
9613
|
+
writeStream.on("finish", callback);
|
|
9614
|
+
readStream.on("error", function(error) {
|
|
9615
|
+
callback(error);
|
|
9616
|
+
});
|
|
9617
|
+
readStream.pipe(writeStream);
|
|
9618
|
+
};
|
|
9619
|
+
RandomAccessReader.prototype.close = function(callback) {
|
|
9620
|
+
setImmediate(callback);
|
|
9621
|
+
};
|
|
7033
9622
|
|
|
7034
|
-
|
|
9623
|
+
util.inherits(RefUnrefFilter, PassThrough);
|
|
9624
|
+
function RefUnrefFilter(context) {
|
|
9625
|
+
PassThrough.call(this);
|
|
9626
|
+
this.context = context;
|
|
9627
|
+
this.context.ref();
|
|
9628
|
+
this.unreffedYet = false;
|
|
9629
|
+
}
|
|
9630
|
+
RefUnrefFilter.prototype._flush = function(cb) {
|
|
9631
|
+
this.unref();
|
|
9632
|
+
cb();
|
|
9633
|
+
};
|
|
9634
|
+
RefUnrefFilter.prototype.unref = function(cb) {
|
|
9635
|
+
if (this.unreffedYet) return;
|
|
9636
|
+
this.unreffedYet = true;
|
|
9637
|
+
this.context.unref();
|
|
9638
|
+
};
|
|
7035
9639
|
|
|
7036
|
-
|
|
7037
|
-
|
|
7038
|
-
|
|
7039
|
-
|
|
7040
|
-
|
|
7041
|
-
|
|
7042
|
-
|
|
7043
|
-
|
|
7044
|
-
if (!options.headless) {
|
|
7045
|
-
doc.declaration(options);
|
|
7046
|
-
if ((options.pubID != null) || (options.sysID != null)) {
|
|
7047
|
-
doc.dtd(options);
|
|
7048
|
-
}
|
|
9640
|
+
var cp437 = '\u0000☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ ';
|
|
9641
|
+
function decodeBuffer(buffer, start, end, isUtf8) {
|
|
9642
|
+
if (isUtf8) {
|
|
9643
|
+
return buffer.toString("utf8", start, end);
|
|
9644
|
+
} else {
|
|
9645
|
+
var result = "";
|
|
9646
|
+
for (var i = start; i < end; i++) {
|
|
9647
|
+
result += cp437[buffer[i]];
|
|
7049
9648
|
}
|
|
7050
|
-
return
|
|
7051
|
-
}
|
|
9649
|
+
return result;
|
|
9650
|
+
}
|
|
9651
|
+
}
|
|
7052
9652
|
|
|
7053
|
-
|
|
7054
|
-
|
|
7055
|
-
|
|
7056
|
-
|
|
7057
|
-
|
|
7058
|
-
|
|
7059
|
-
|
|
7060
|
-
|
|
7061
|
-
|
|
7062
|
-
|
|
7063
|
-
|
|
7064
|
-
};
|
|
9653
|
+
function readUInt64LE(buffer, offset) {
|
|
9654
|
+
// there is no native function for this, because we can't actually store 64-bit integers precisely.
|
|
9655
|
+
// after 53 bits, JavaScript's Number type (IEEE 754 double) can't store individual integers anymore.
|
|
9656
|
+
// but since 53 bits is a whole lot more than 32 bits, we do our best anyway.
|
|
9657
|
+
var lower32 = buffer.readUInt32LE(offset);
|
|
9658
|
+
var upper32 = buffer.readUInt32LE(offset + 4);
|
|
9659
|
+
// we can't use bitshifting here, because JavaScript bitshifting only works on 32-bit integers.
|
|
9660
|
+
return upper32 * 0x100000000 + lower32;
|
|
9661
|
+
// as long as we're bounds checking the result of this function against the total file size,
|
|
9662
|
+
// we'll catch any overflow errors, because we already made sure the total file size was within reason.
|
|
9663
|
+
}
|
|
7065
9664
|
|
|
7066
|
-
|
|
7067
|
-
|
|
9665
|
+
// Node 10 deprecated new Buffer().
|
|
9666
|
+
var newBuffer;
|
|
9667
|
+
if (typeof Buffer.allocUnsafe === "function") {
|
|
9668
|
+
newBuffer = function(len) {
|
|
9669
|
+
return Buffer.allocUnsafe(len);
|
|
7068
9670
|
};
|
|
7069
|
-
|
|
7070
|
-
|
|
7071
|
-
return new
|
|
9671
|
+
} else {
|
|
9672
|
+
newBuffer = function(len) {
|
|
9673
|
+
return new Buffer(len);
|
|
7072
9674
|
};
|
|
9675
|
+
}
|
|
7073
9676
|
|
|
7074
|
-
|
|
9677
|
+
function defaultCallback(err) {
|
|
9678
|
+
if (err) throw err;
|
|
9679
|
+
}
|
|
7075
9680
|
|
|
7076
|
-
module.exports.nodeType = NodeType;
|
|
7077
9681
|
|
|
7078
|
-
|
|
9682
|
+
/***/ }),
|
|
7079
9683
|
|
|
7080
|
-
|
|
9684
|
+
/***/ 871:
|
|
9685
|
+
/***/ ((module) => {
|
|
9686
|
+
|
|
9687
|
+
"use strict";
|
|
9688
|
+
module.exports = require("buffer");
|
|
9689
|
+
|
|
9690
|
+
/***/ }),
|
|
9691
|
+
|
|
9692
|
+
/***/ 6231:
|
|
9693
|
+
/***/ ((module) => {
|
|
7081
9694
|
|
|
9695
|
+
"use strict";
|
|
9696
|
+
module.exports = require("fs");
|
|
9697
|
+
|
|
9698
|
+
/***/ }),
|
|
9699
|
+
|
|
9700
|
+
/***/ 1423:
|
|
9701
|
+
/***/ ((module) => {
|
|
9702
|
+
|
|
9703
|
+
"use strict";
|
|
9704
|
+
module.exports = require("path");
|
|
7082
9705
|
|
|
7083
9706
|
/***/ }),
|
|
7084
9707
|
|
|
@@ -7104,6 +9727,22 @@ module.exports = require("string_decoder");
|
|
|
7104
9727
|
"use strict";
|
|
7105
9728
|
module.exports = require("timers");
|
|
7106
9729
|
|
|
9730
|
+
/***/ }),
|
|
9731
|
+
|
|
9732
|
+
/***/ 6464:
|
|
9733
|
+
/***/ ((module) => {
|
|
9734
|
+
|
|
9735
|
+
"use strict";
|
|
9736
|
+
module.exports = require("util");
|
|
9737
|
+
|
|
9738
|
+
/***/ }),
|
|
9739
|
+
|
|
9740
|
+
/***/ 8884:
|
|
9741
|
+
/***/ ((module) => {
|
|
9742
|
+
|
|
9743
|
+
"use strict";
|
|
9744
|
+
module.exports = require("zlib");
|
|
9745
|
+
|
|
7107
9746
|
/***/ })
|
|
7108
9747
|
|
|
7109
9748
|
/******/ });
|
|
@@ -7179,10 +9818,12 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
7179
9818
|
"launchSimulator": () => (/* reexport */ launchSimulator)
|
|
7180
9819
|
});
|
|
7181
9820
|
|
|
9821
|
+
;// CONCATENATED MODULE: external "crypto"
|
|
9822
|
+
const external_crypto_namespaceObject = require("crypto");
|
|
7182
9823
|
;// CONCATENATED MODULE: external "fs/promises"
|
|
7183
9824
|
const promises_namespaceObject = require("fs/promises");
|
|
7184
|
-
|
|
7185
|
-
|
|
9825
|
+
// EXTERNAL MODULE: external "path"
|
|
9826
|
+
var external_path_ = __webpack_require__(1423);
|
|
7186
9827
|
;// CONCATENATED MODULE: external "./api.cjs"
|
|
7187
9828
|
const external_api_cjs_namespaceObject = require("./api.cjs");
|
|
7188
9829
|
;// CONCATENATED MODULE: external "./sdk-util.cjs"
|
|
@@ -7238,7 +9879,7 @@ async function build_project(product, options, lineCallback) {
|
|
|
7238
9879
|
if (product) {
|
|
7239
9880
|
extraArgs.push("-d", simulatorBuild !== false ? `${product}_sim` : product);
|
|
7240
9881
|
}
|
|
7241
|
-
const exe =
|
|
9882
|
+
const exe = external_path_.resolve(sdk, "bin", external_sdk_util_cjs_namespaceObject.isWin ? "monkeyc.bat" : "monkeyc");
|
|
7242
9883
|
const args = [
|
|
7243
9884
|
["-o", program],
|
|
7244
9885
|
["-f", jungleFiles],
|
|
@@ -7251,12 +9892,14 @@ async function build_project(product, options, lineCallback) {
|
|
|
7251
9892
|
(line) => console.error(line),
|
|
7252
9893
|
];
|
|
7253
9894
|
return returnCommand
|
|
7254
|
-
? { exe, args }
|
|
9895
|
+
? { exe, args, program: external_path_.resolve(workspace, program), product }
|
|
7255
9896
|
: (0,external_util_cjs_namespaceObject.spawnByLine)(exe, args, handlers, {
|
|
7256
9897
|
cwd: workspace,
|
|
7257
9898
|
});
|
|
7258
9899
|
}
|
|
7259
9900
|
|
|
9901
|
+
// EXTERNAL MODULE: ./node_modules/extract-zip/index.js
|
|
9902
|
+
var extract_zip = __webpack_require__(2106);
|
|
7260
9903
|
// EXTERNAL MODULE: ./node_modules/xml2js/lib/xml2js.js
|
|
7261
9904
|
var xml2js = __webpack_require__(5055);
|
|
7262
9905
|
;// CONCATENATED MODULE: ./build/jungle.js
|
|
@@ -7281,12 +9924,47 @@ function manifestProducts(manifest) {
|
|
|
7281
9924
|
const app =
|
|
7282
9925
|
manifest["iq:manifest"]["iq:application"] ||
|
|
7283
9926
|
manifest["iq:manifest"]["iq:barrel"];
|
|
7284
|
-
return app[0]["iq:products"][0]["iq:product"]
|
|
9927
|
+
return ((app[0]["iq:products"] || [{}])[0]["iq:product"] || [])
|
|
7285
9928
|
.map((p) => p.$.id)
|
|
7286
9929
|
.sort()
|
|
7287
9930
|
.filter((p, i, a) => !i || p !== a[i - 1]);
|
|
7288
9931
|
}
|
|
7289
9932
|
|
|
9933
|
+
function manifestBarrels(manifest) {
|
|
9934
|
+
const app = manifest["iq:manifest"]["iq:application"];
|
|
9935
|
+
if (
|
|
9936
|
+
Array.isArray(app) &&
|
|
9937
|
+
app.length &&
|
|
9938
|
+
app[0] &&
|
|
9939
|
+
Array.isArray(app[0]["iq:barrels"]) &&
|
|
9940
|
+
app[0]["iq:barrels"].length &&
|
|
9941
|
+
Array.isArray(app[0]["iq:barrels"][0]["iq:depends"])
|
|
9942
|
+
) {
|
|
9943
|
+
return app[0]["iq:barrels"][0]["iq:depends"]
|
|
9944
|
+
.map((p) => p.$.name)
|
|
9945
|
+
.sort()
|
|
9946
|
+
.filter((p, i, a) => !i || p !== a[i - 1]);
|
|
9947
|
+
}
|
|
9948
|
+
return [];
|
|
9949
|
+
}
|
|
9950
|
+
|
|
9951
|
+
function manifestDropBarrels(manifest) {
|
|
9952
|
+
delete manifest["iq:manifest"]["iq:application"][0]["iq:barrels"];
|
|
9953
|
+
}
|
|
9954
|
+
|
|
9955
|
+
function manifestBarrelName(manifestName, manifest) {
|
|
9956
|
+
const barrel = manifest["iq:manifest"]["iq:barrel"];
|
|
9957
|
+
if (!barrel) throw new Error(`Not a barrel manifest: ${manifestName}`);
|
|
9958
|
+
return barrel[0].$.module;
|
|
9959
|
+
}
|
|
9960
|
+
|
|
9961
|
+
function manifestAnnotations(manifest) {
|
|
9962
|
+
const barrel = manifest["iq:manifest"]["iq:barrel"];
|
|
9963
|
+
if (!barrel) return null;
|
|
9964
|
+
const annotations = barrel[0]["iq:annotations"];
|
|
9965
|
+
return annotations && annotations[0]["iq:annotation"];
|
|
9966
|
+
}
|
|
9967
|
+
|
|
7290
9968
|
async function checkManifest(manifest, products) {
|
|
7291
9969
|
let ok = true;
|
|
7292
9970
|
if (!manifest["iq:manifest"]["$"]["xmlns:iq"]) {
|
|
@@ -7303,13 +9981,14 @@ async function checkManifest(manifest, products) {
|
|
|
7303
9981
|
ok = false;
|
|
7304
9982
|
elm.$.id = "08070f9d-8b4e-40a4-9c49-fe67a2a55dec";
|
|
7305
9983
|
}
|
|
7306
|
-
const type = elm.$.type.replace(
|
|
9984
|
+
const type = elm.$.type.replace(/-/g, "").toLowerCase();
|
|
7307
9985
|
const deviceInfo = await (0,external_sdk_util_cjs_namespaceObject.getDeviceInfo)();
|
|
7308
9986
|
const allowedProducts = products.sort().filter(
|
|
7309
9987
|
(p) =>
|
|
7310
9988
|
deviceInfo[p] &&
|
|
7311
9989
|
deviceInfo[p].appTypes.find((at) => {
|
|
7312
|
-
|
|
9990
|
+
const t = at.type.toLowerCase();
|
|
9991
|
+
return t === type || `${t}app` === type;
|
|
7313
9992
|
})
|
|
7314
9993
|
);
|
|
7315
9994
|
if (
|
|
@@ -7350,6 +10029,8 @@ async function checkManifest(manifest, products) {
|
|
|
7350
10029
|
|
|
7351
10030
|
|
|
7352
10031
|
|
|
10032
|
+
|
|
10033
|
+
|
|
7353
10034
|
async function default_jungle() {
|
|
7354
10035
|
const assignments = [];
|
|
7355
10036
|
const devices = await (0,external_sdk_util_cjs_namespaceObject.getDeviceInfo)();
|
|
@@ -7597,8 +10278,8 @@ function resolve_node(state, node) {
|
|
|
7597
10278
|
|
|
7598
10279
|
function resolve_filename(literal, default_source) {
|
|
7599
10280
|
if (typeof literal === "string") return literal;
|
|
7600
|
-
const root =
|
|
7601
|
-
return
|
|
10281
|
+
const root = external_path_.dirname(literal.source || default_source);
|
|
10282
|
+
return external_path_.resolve(root, literal.value);
|
|
7602
10283
|
}
|
|
7603
10284
|
|
|
7604
10285
|
async function resolve_literals(qualifier, default_source) {
|
|
@@ -7655,23 +10336,36 @@ async function resolve_literals(qualifier, default_source) {
|
|
|
7655
10336
|
base[name] = literals.map((v) => v.value);
|
|
7656
10337
|
};
|
|
7657
10338
|
resolve_literal_list(qualifier, "excludeAnnotations");
|
|
7658
|
-
|
|
10339
|
+
// turn the annotations inside out.
|
|
10340
|
+
// in the jungle we have
|
|
10341
|
+
// qualifier.BarrelName.annotations = Foo;Bar
|
|
10342
|
+
// but its more convenient as
|
|
10343
|
+
// qualifier.annotations.BarrelName = Foo;Bar
|
|
10344
|
+
const annotations = {};
|
|
10345
|
+
Object.entries(qualifier).forEach(([k, v]) => {
|
|
10346
|
+
if ((0,external_api_cjs_namespaceObject.hasProperty)(v, "annotations")) {
|
|
10347
|
+
annotations[k] = v.annotations;
|
|
10348
|
+
resolve_literal_list(annotations, k);
|
|
10349
|
+
delete qualifier[k];
|
|
10350
|
+
}
|
|
10351
|
+
});
|
|
10352
|
+
qualifier.annotations = annotations;
|
|
7659
10353
|
}
|
|
7660
10354
|
|
|
7661
10355
|
async function find_build_instructions_in_resource(file) {
|
|
7662
10356
|
const data = await promises_namespaceObject.readFile(file);
|
|
7663
10357
|
const rez = await (0,xml2js.parseStringPromise)(data).catch(() => ({}));
|
|
7664
10358
|
if (rez.build && rez.build.exclude) {
|
|
7665
|
-
const dir =
|
|
10359
|
+
const dir = external_path_.dirname(file);
|
|
7666
10360
|
const sourceExcludes = rez.build.exclude
|
|
7667
10361
|
.map((e) => e.$.file)
|
|
7668
10362
|
.filter((f) => f != null)
|
|
7669
|
-
.map((f) =>
|
|
10363
|
+
.map((f) => external_path_.resolve(dir, f).replace(/\\/g, "/"));
|
|
7670
10364
|
|
|
7671
10365
|
const filePatterns = rez.build.exclude
|
|
7672
10366
|
.map((e) => e.$.dir)
|
|
7673
10367
|
.filter((f) => f != null)
|
|
7674
|
-
.map((f) =>
|
|
10368
|
+
.map((f) => external_path_.join(dir, f, "**", "*.mc").replace(/\\/g, "/"));
|
|
7675
10369
|
if (filePatterns.length) {
|
|
7676
10370
|
const files = (
|
|
7677
10371
|
await Promise.all(filePatterns.map((p) => (0,external_util_cjs_namespaceObject.globa)(p)))
|
|
@@ -7795,6 +10489,7 @@ function identify_optimizer_groups(targets, options) {
|
|
|
7795
10489
|
sourcePath,
|
|
7796
10490
|
sourceExcludes,
|
|
7797
10491
|
barrelPath,
|
|
10492
|
+
barrelMap,
|
|
7798
10493
|
excludeAnnotations,
|
|
7799
10494
|
annotations,
|
|
7800
10495
|
} = target.qualifier;
|
|
@@ -7804,9 +10499,11 @@ function identify_optimizer_groups(targets, options) {
|
|
|
7804
10499
|
ignoredExcludeAnnotations
|
|
7805
10500
|
);
|
|
7806
10501
|
}
|
|
7807
|
-
|
|
7808
|
-
|
|
7809
|
-
|
|
10502
|
+
Object.entries(annotations).forEach(([key, value]) => {
|
|
10503
|
+
if (ignoredAnnotations) {
|
|
10504
|
+
annotations[key] = getStrsWithIgnore(value, ignoredAnnotations);
|
|
10505
|
+
}
|
|
10506
|
+
});
|
|
7810
10507
|
if (ignoredSourcePaths) {
|
|
7811
10508
|
sourcePath = sourcePath
|
|
7812
10509
|
.map((path) => Object.keys(ignoredSourcePaths[path]))
|
|
@@ -7818,6 +10515,7 @@ function identify_optimizer_groups(targets, options) {
|
|
|
7818
10515
|
sourcePath,
|
|
7819
10516
|
sourceExcludes,
|
|
7820
10517
|
barrelPath,
|
|
10518
|
+
barrelMap,
|
|
7821
10519
|
excludeAnnotations,
|
|
7822
10520
|
annotations,
|
|
7823
10521
|
};
|
|
@@ -7837,11 +10535,248 @@ function identify_optimizer_groups(targets, options) {
|
|
|
7837
10535
|
});
|
|
7838
10536
|
}
|
|
7839
10537
|
|
|
7840
|
-
|
|
7841
|
-
|
|
7842
|
-
|
|
10538
|
+
/**
|
|
10539
|
+
* Find the barrels referred to by barrelPath.
|
|
10540
|
+
*
|
|
10541
|
+
* Each string in barrelPath is a glob that can expand to a
|
|
10542
|
+
* .jungle file, a .barrel file, or a directory. If it
|
|
10543
|
+
* expands to a directory, that directory is searched recursively
|
|
10544
|
+
* for .barrel files.
|
|
10545
|
+
*
|
|
10546
|
+
* @param {string|string[]} barrelPath the path or paths to search
|
|
10547
|
+
* @returns {Promise<string[]>}
|
|
10548
|
+
*/
|
|
10549
|
+
function find_barrels(barrelPath) {
|
|
10550
|
+
if (Array.isArray(barrelPath)) {
|
|
10551
|
+
// This is a sublist. The barrel has more than one jungle file.
|
|
10552
|
+
return Promise.all(
|
|
10553
|
+
barrelPath.map((path) => (0,external_util_cjs_namespaceObject.globa)(path, { mark: true }))
|
|
10554
|
+
).then((paths) => [
|
|
10555
|
+
paths
|
|
10556
|
+
.flat()
|
|
10557
|
+
.filter((path) => path.endsWith(".jungle"))
|
|
10558
|
+
.join(";"),
|
|
10559
|
+
]);
|
|
10560
|
+
}
|
|
10561
|
+
return (0,external_util_cjs_namespaceObject.globa)(barrelPath, { mark: true })
|
|
10562
|
+
.then((paths) =>
|
|
10563
|
+
Promise.all(
|
|
10564
|
+
paths.map((path) =>
|
|
10565
|
+
path.endsWith("/") ? (0,external_util_cjs_namespaceObject.globa)(`${path}**/*.barrel`) : path
|
|
10566
|
+
)
|
|
10567
|
+
)
|
|
10568
|
+
)
|
|
10569
|
+
.then((barrelPaths) =>
|
|
10570
|
+
barrelPaths
|
|
10571
|
+
.flat()
|
|
10572
|
+
.filter((path) => path.endsWith(".jungle") || path.endsWith(".barrel"))
|
|
10573
|
+
);
|
|
10574
|
+
}
|
|
10575
|
+
|
|
10576
|
+
/**
|
|
10577
|
+
*@typedef {Object} Target - Build instructions for a particular product in a jungle
|
|
10578
|
+
*
|
|
10579
|
+
* @typedef {Object} JungleInfoBase - The result of parsing a jungle file, without resolving any products
|
|
10580
|
+
* @property {string[]} jungles - Paths to the barrel's jungle files
|
|
10581
|
+
* @property {string} manifest - Path to the barrel's manifest file
|
|
10582
|
+
* @property {Object} xml - The xml content of the manifest, as returned by xml2js
|
|
10583
|
+
* @property {string[]=} annotations - Array of annotations supported by this barrel
|
|
10584
|
+
*
|
|
10585
|
+
* @typedef {Object} PartialJungle - Used to extend JungleInfoBase to ResolvedJungle
|
|
10586
|
+
* @property {Target[]} targets - All of the supported targets in the manifest
|
|
10587
|
+
*
|
|
10588
|
+
* @typedef {Object} PartialBarrel - Used to extend JungleInfoBase to ResolvedBarrel
|
|
10589
|
+
* @property {JungleQualifier} qualifier - the qualifier for this PartialBarrel's target
|
|
10590
|
+
*
|
|
10591
|
+
* @typedef {JungleInfoBase & PartialJungle} ResolvedJungle - The result of parsing an application's jungle file
|
|
10592
|
+
* @typedef {JungleInfoBase & PartialBarrel} ResolvedBarrel - The result of parsing a barrel's jungle file for a particular product
|
|
10593
|
+
*
|
|
10594
|
+
* @typedef {Object} JungleQualifier
|
|
10595
|
+
* @property {string[]=} sourcePath - locations to find source file
|
|
10596
|
+
* @property {string[]=} sourceExcludes - array of files to exclude from the build (from resource build instructions)
|
|
10597
|
+
* @property {string[]=} excludeAnnotations - array of excludeAnnotations
|
|
10598
|
+
* @property {string[]=} resourcePath - locations to find resource files
|
|
10599
|
+
* @property {LangResourcePaths} lang - locations to find resource files
|
|
10600
|
+
* @property {(string|string[])[]=} barrelPath - locations to find barrels
|
|
10601
|
+
* @property {BarrelAnnotations=} annotations - map from barrel names to arrays of annotations
|
|
10602
|
+
* @property {BarrelMap=} barrelMap
|
|
10603
|
+
*
|
|
10604
|
+
* @typedef {{[key:string]:string[]}} LangResourcePaths - Map from language codes to the corresponding resource paths
|
|
10605
|
+
* @typedef {{[key:string]:string[]}} BarrelAnnotations - Map from barrel name to imported annotations
|
|
10606
|
+
* @typedef {{[key:string]:ResolvedBarrel}} BarrelMap - Map from barrel name to the set of resolved barrel projects for that name. Note that they must all share a manifest.
|
|
10607
|
+
*/
|
|
10608
|
+
|
|
10609
|
+
/**
|
|
10610
|
+
* Given a .barrel file, unpack it into barrelDir, then process its .jungle file as below
|
|
10611
|
+
* Given a .jungle file, resolve it to a ResolvedJungle
|
|
10612
|
+
*
|
|
10613
|
+
* @param {string} barrel Path to a .jungle or .barrel file to resolve
|
|
10614
|
+
* @param {string} barrelDir Directory where .barrel files should be unpacked
|
|
10615
|
+
* @param {string[]} products The products supported by the importing project
|
|
10616
|
+
* @param {*} options
|
|
10617
|
+
* @returns {Promise<ResolvedJungle>}
|
|
10618
|
+
*/
|
|
10619
|
+
function resolve_barrel(barrel, barrelDir, products, options) {
|
|
10620
|
+
const cache = options._cache;
|
|
10621
|
+
if ((0,external_api_cjs_namespaceObject.hasProperty)(cache.barrels, barrel)) {
|
|
10622
|
+
return cache.barrels[barrel];
|
|
10623
|
+
}
|
|
10624
|
+
let promise = Promise.resolve();
|
|
10625
|
+
let rawBarrel = barrel;
|
|
10626
|
+
if (barrel.endsWith(".barrel")) {
|
|
10627
|
+
// A barrel with the given name could in theory resolve to a different physical
|
|
10628
|
+
// barrel file for each product, so uniqify the local name with a sha1.
|
|
10629
|
+
const sha1 = external_crypto_namespaceObject.createHash("sha1")
|
|
10630
|
+
.update(barrel, "binary")
|
|
10631
|
+
.digest("base64")
|
|
10632
|
+
.replace(/[\/=+]/g, "");
|
|
10633
|
+
const localPath = external_path_.resolve(
|
|
10634
|
+
barrelDir,
|
|
10635
|
+
`${external_path_.basename(barrel, ".barrel")}-${sha1}`
|
|
10636
|
+
);
|
|
10637
|
+
rawBarrel = external_path_.resolve(localPath, "barrel.jungle");
|
|
10638
|
+
promise = promise.then(() =>
|
|
10639
|
+
promises_namespaceObject.stat(localPath)
|
|
10640
|
+
.then(
|
|
10641
|
+
(localStat) =>
|
|
10642
|
+
!localStat.isDirectory() ||
|
|
10643
|
+
promises_namespaceObject.stat(barrel)
|
|
10644
|
+
.then((barrelStat) => localStat.mtimeMs < barrelStat.mtimeMs),
|
|
10645
|
+
() => true
|
|
10646
|
+
)
|
|
10647
|
+
.then(
|
|
10648
|
+
(needsUpdate) =>
|
|
10649
|
+
needsUpdate &&
|
|
10650
|
+
promises_namespaceObject.rm(localPath, { recursive: true, force: true })
|
|
10651
|
+
.then(() => extract_zip(barrel, { dir: localPath }))
|
|
10652
|
+
)
|
|
10653
|
+
);
|
|
10654
|
+
}
|
|
10655
|
+
return promise
|
|
10656
|
+
.then(() => get_jungle_and_barrels(rawBarrel, products, options))
|
|
10657
|
+
.then((result) => {
|
|
10658
|
+
if (!cache.barrels) cache.barrels = {};
|
|
10659
|
+
return (cache.barrels[barrel] = { ...result });
|
|
10660
|
+
});
|
|
10661
|
+
}
|
|
10662
|
+
|
|
10663
|
+
/**
|
|
10664
|
+
* Find and resolve the BarrelMap for product, and add it to qualifier.
|
|
10665
|
+
*
|
|
10666
|
+
* @param {string} product The device id we're resolving
|
|
10667
|
+
* @param {JungleQualifier} qualifier The qualifier for product from the main jungle
|
|
10668
|
+
* @param {string[]} barrels The barrels imported by the project's manifest
|
|
10669
|
+
* @param {string[]} products The products supported by the importing project (used when the barrel project has none)
|
|
10670
|
+
* @param {*} options
|
|
10671
|
+
* @returns {Promise<void>}
|
|
10672
|
+
*/
|
|
10673
|
+
function resolve_barrels(product, qualifier, barrels, products, options) {
|
|
10674
|
+
if (qualifier.annotations) {
|
|
10675
|
+
Object.keys(qualifier.annotations).forEach((key) => {
|
|
10676
|
+
// delete annotations for non-existent barrels such as
|
|
10677
|
+
if (!barrels.includes(key)) {
|
|
10678
|
+
delete qualifier.annotations[key];
|
|
10679
|
+
}
|
|
10680
|
+
});
|
|
10681
|
+
}
|
|
10682
|
+
if (!barrels.length) {
|
|
10683
|
+
delete qualifier.barrelPath;
|
|
10684
|
+
return;
|
|
10685
|
+
}
|
|
10686
|
+
const cache = options._cache || (options._cache = {});
|
|
10687
|
+
const barrelMapKey = JSON.stringify([barrels, qualifier.barrelPath]);
|
|
10688
|
+
const setBarrelMap = (barrelMap) => {
|
|
10689
|
+
qualifier.barrelMap = barrels.reduce((result, barrel) => {
|
|
10690
|
+
const { targets, ...rest } = barrelMap[barrel];
|
|
10691
|
+
const target = targets.find((t) => t.product === product);
|
|
10692
|
+
if (!target) {
|
|
10693
|
+
throw new Error(`Barrel ${barrel} does not support device ${product}`);
|
|
10694
|
+
}
|
|
10695
|
+
rest.qualifier = target.qualifier;
|
|
10696
|
+
result[barrel] = rest;
|
|
10697
|
+
return result;
|
|
10698
|
+
}, {});
|
|
10699
|
+
};
|
|
10700
|
+
if ((0,external_api_cjs_namespaceObject.hasProperty)(cache.barrelMap, barrelMapKey)) {
|
|
10701
|
+
setBarrelMap(cache.barrelMap[barrelMapKey]);
|
|
10702
|
+
return;
|
|
10703
|
+
}
|
|
10704
|
+
const barrelDir = external_path_.resolve(
|
|
10705
|
+
options.workspace,
|
|
10706
|
+
options.outputPath,
|
|
10707
|
+
"raw-barrels"
|
|
10708
|
+
);
|
|
10709
|
+
const barrelMap = Object.fromEntries(barrels.map((b) => [b, null]));
|
|
10710
|
+
return (qualifier.barrelPath || [])
|
|
10711
|
+
.reduce(
|
|
10712
|
+
(promise, barrelPath) =>
|
|
10713
|
+
promise
|
|
10714
|
+
.then(() => find_barrels(barrelPath))
|
|
10715
|
+
.then((barrelPaths) => {
|
|
10716
|
+
return Promise.all(
|
|
10717
|
+
barrelPaths.map((barrel) =>
|
|
10718
|
+
resolve_barrel(barrel, barrelDir, products, options)
|
|
10719
|
+
)
|
|
10720
|
+
);
|
|
10721
|
+
})
|
|
10722
|
+
.then((resolvedBarrels) => {
|
|
10723
|
+
resolvedBarrels.forEach((resolvedBarrel) => {
|
|
10724
|
+
const name = manifestBarrelName(
|
|
10725
|
+
resolvedBarrel.manifest,
|
|
10726
|
+
resolvedBarrel.xml
|
|
10727
|
+
);
|
|
10728
|
+
if (!(0,external_api_cjs_namespaceObject.hasProperty)(barrelMap, name)) return;
|
|
10729
|
+
if (barrelMap[name]) {
|
|
10730
|
+
const bname = (r) => r.jungles.join(";");
|
|
10731
|
+
throw new Error(
|
|
10732
|
+
`Barrel ${name} already resolved to ${bname(
|
|
10733
|
+
barrelMap[name]
|
|
10734
|
+
)}; can't also resolve to ${bname(resolvedBarrel)}`
|
|
10735
|
+
);
|
|
10736
|
+
}
|
|
10737
|
+
barrelMap[name] = resolvedBarrel;
|
|
10738
|
+
});
|
|
10739
|
+
}),
|
|
10740
|
+
Promise.resolve()
|
|
10741
|
+
)
|
|
10742
|
+
.then(() => {
|
|
10743
|
+
const unresolved = Object.entries(barrelMap).filter((v) => v[1] === null);
|
|
10744
|
+
if (unresolved.length) {
|
|
10745
|
+
throw new Error(
|
|
10746
|
+
`Failed to resolve some barrels: ${unresolved
|
|
10747
|
+
.map(([name]) => name)
|
|
10748
|
+
.join(",")}`
|
|
10749
|
+
);
|
|
10750
|
+
}
|
|
10751
|
+
if (!cache.barrelMap) cache.barrelMap = {};
|
|
10752
|
+
cache.barrelMap[barrelMapKey] = barrelMap;
|
|
10753
|
+
setBarrelMap(barrelMap);
|
|
10754
|
+
});
|
|
10755
|
+
}
|
|
10756
|
+
/**
|
|
10757
|
+
*
|
|
10758
|
+
* @param {string} jungleFiles Semicolon separated list of jungle files
|
|
10759
|
+
* @param {string[]} defaultProducts Default set of products. Only used by a barrel with no products of its own
|
|
10760
|
+
* @param {*} options
|
|
10761
|
+
* @returns {Promise<ResolvedJungle>}
|
|
10762
|
+
*/
|
|
10763
|
+
async function get_jungle_and_barrels(jungleFiles, defaultProducts, options) {
|
|
10764
|
+
const jungles = jungleFiles
|
|
7843
10765
|
.split(";")
|
|
7844
|
-
.map((jungle) =>
|
|
10766
|
+
.map((jungle) => external_path_.resolve(options.workspace || "./", jungle));
|
|
10767
|
+
const barrels_jungle = external_path_.resolve(
|
|
10768
|
+
external_path_.dirname(jungles[0]),
|
|
10769
|
+
"barrels.jungle"
|
|
10770
|
+
);
|
|
10771
|
+
if (!jungles.includes(barrels_jungle)) {
|
|
10772
|
+
if (
|
|
10773
|
+
await promises_namespaceObject.stat(barrels_jungle)
|
|
10774
|
+
.then((s) => s.isFile())
|
|
10775
|
+
.catch(() => false)
|
|
10776
|
+
) {
|
|
10777
|
+
jungles.push(barrels_jungle);
|
|
10778
|
+
}
|
|
10779
|
+
}
|
|
7845
10780
|
const state = await process_jungles(jungles);
|
|
7846
10781
|
// apparently square_watch is an alias for rectangle_watch
|
|
7847
10782
|
state["square_watch"] = state["rectangle_watch"];
|
|
@@ -7851,17 +10786,29 @@ async function get_jungle(jungles, options) {
|
|
|
7851
10786
|
);
|
|
7852
10787
|
if (!manifest_node) throw new Error("No manifest found!");
|
|
7853
10788
|
const manifest = resolve_filename(manifest_node[0]);
|
|
10789
|
+
if (!options.workspace) {
|
|
10790
|
+
options.workspace = external_path_.dirname(manifest);
|
|
10791
|
+
}
|
|
7854
10792
|
const xml = await readManifest(manifest);
|
|
7855
10793
|
const targets = [];
|
|
10794
|
+
const barrels = manifestBarrels(xml);
|
|
10795
|
+
const annotations = manifestAnnotations(xml);
|
|
10796
|
+
const products = manifestProducts(xml);
|
|
10797
|
+
if (products.length === 0) products.push(...defaultProducts);
|
|
7856
10798
|
let promise = Promise.resolve();
|
|
7857
10799
|
const add_one = (product, shape) => {
|
|
7858
10800
|
const qualifier = resolve_node(state, state[product]);
|
|
7859
10801
|
if (!qualifier) return;
|
|
7860
10802
|
promise = promise
|
|
7861
10803
|
.then(() => resolve_literals(qualifier, manifest))
|
|
7862
|
-
.then(() =>
|
|
10804
|
+
.then(() =>
|
|
10805
|
+
resolve_barrels(product, qualifier, barrels, products, options)
|
|
10806
|
+
)
|
|
10807
|
+
.then(() => {
|
|
10808
|
+
targets.push({ product, qualifier, shape });
|
|
10809
|
+
});
|
|
7863
10810
|
};
|
|
7864
|
-
|
|
10811
|
+
products.forEach((product) => {
|
|
7865
10812
|
if ((0,external_api_cjs_namespaceObject.hasProperty)(state, product) && state[product].products) {
|
|
7866
10813
|
// this was something like round_watch. Add all the corresponding
|
|
7867
10814
|
// products.
|
|
@@ -7872,8 +10819,14 @@ async function get_jungle(jungles, options) {
|
|
|
7872
10819
|
});
|
|
7873
10820
|
await promise;
|
|
7874
10821
|
await find_build_instructions(targets);
|
|
7875
|
-
|
|
7876
|
-
|
|
10822
|
+
return { manifest, targets, xml, annotations, jungles };
|
|
10823
|
+
}
|
|
10824
|
+
|
|
10825
|
+
async function get_jungle(jungles, options) {
|
|
10826
|
+
options = options || {};
|
|
10827
|
+
const result = await get_jungle_and_barrels(jungles, [], options);
|
|
10828
|
+
identify_optimizer_groups(result.targets, options);
|
|
10829
|
+
return result;
|
|
7877
10830
|
}
|
|
7878
10831
|
|
|
7879
10832
|
;// CONCATENATED MODULE: external "child_process"
|
|
@@ -7883,15 +10836,24 @@ const external_child_process_namespaceObject = require("child_process");
|
|
|
7883
10836
|
|
|
7884
10837
|
|
|
7885
10838
|
|
|
10839
|
+
|
|
7886
10840
|
function launchSimulator() {
|
|
7887
10841
|
return (0,external_sdk_util_cjs_namespaceObject.getSdkPath)().then((sdk) => {
|
|
7888
10842
|
const child = (0,external_child_process_namespaceObject.execFile)(
|
|
7889
|
-
|
|
10843
|
+
external_path_.resolve(sdk, "bin", external_sdk_util_cjs_namespaceObject.isWin ? "simulator" : "connectiq")
|
|
7890
10844
|
);
|
|
7891
10845
|
child.unref();
|
|
7892
10846
|
});
|
|
7893
10847
|
}
|
|
7894
10848
|
|
|
10849
|
+
function simulateProgram(prg, device) {
|
|
10850
|
+
return getSdkPath().then((sdk) =>
|
|
10851
|
+
spawnByLine(path.resolve(sdk, "bin", "monkeydo"), [prg, device], (line) =>
|
|
10852
|
+
console.log(line)
|
|
10853
|
+
)
|
|
10854
|
+
);
|
|
10855
|
+
}
|
|
10856
|
+
|
|
7895
10857
|
;// CONCATENATED MODULE: external "@markw65/prettier-plugin-monkeyc"
|
|
7896
10858
|
const prettier_plugin_monkeyc_namespaceObject = require("@markw65/prettier-plugin-monkeyc");
|
|
7897
10859
|
;// CONCATENATED MODULE: ./src/mc-rewrite.js
|
|
@@ -7948,12 +10910,8 @@ function collectClassInfo(state) {
|
|
|
7948
10910
|
});
|
|
7949
10911
|
}
|
|
7950
10912
|
|
|
7951
|
-
async function analyze(
|
|
7952
|
-
|
|
7953
|
-
buildConfig && buildConfig.excludeAnnotations
|
|
7954
|
-
? Object.fromEntries(buildConfig.excludeAnnotations.map((a) => [a, true]))
|
|
7955
|
-
: {};
|
|
7956
|
-
|
|
10913
|
+
async function analyze(fnMap) {
|
|
10914
|
+
let excludeAnnotations;
|
|
7957
10915
|
const allImports = [];
|
|
7958
10916
|
const state = {
|
|
7959
10917
|
allFunctions: [],
|
|
@@ -7961,11 +10919,11 @@ async function analyze(fileNames, buildConfig) {
|
|
|
7961
10919
|
shouldExclude(node) {
|
|
7962
10920
|
if (node.attrs && node.attrs.attrs) {
|
|
7963
10921
|
if (
|
|
7964
|
-
node.attrs.attrs.
|
|
10922
|
+
node.attrs.attrs.some((attr) => {
|
|
7965
10923
|
if (attr.type != "UnaryExpression") return false;
|
|
7966
10924
|
if (attr.argument.type != "Identifier") return false;
|
|
7967
10925
|
return (0,external_api_cjs_namespaceObject.hasProperty)(excludeAnnotations, attr.argument.name);
|
|
7968
|
-
})
|
|
10926
|
+
})
|
|
7969
10927
|
) {
|
|
7970
10928
|
return true;
|
|
7971
10929
|
}
|
|
@@ -8008,25 +10966,29 @@ async function analyze(fileNames, buildConfig) {
|
|
|
8008
10966
|
};
|
|
8009
10967
|
markApi(state.stack[0]);
|
|
8010
10968
|
|
|
10969
|
+
const getAst = (source, monkeyCSource, exclude) => {
|
|
10970
|
+
excludeAnnotations = exclude;
|
|
10971
|
+
const ast = prettier_plugin_monkeyc_namespaceObject.parsers.monkeyc.parse(monkeyCSource, {
|
|
10972
|
+
grammarSource: source,
|
|
10973
|
+
});
|
|
10974
|
+
ast.source = source;
|
|
10975
|
+
ast.monkeyCSource = monkeyCSource;
|
|
10976
|
+
(0,external_api_cjs_namespaceObject.collectNamespaces)(ast, state);
|
|
10977
|
+
return ast;
|
|
10978
|
+
};
|
|
8011
10979
|
const files = await Promise.all(
|
|
8012
|
-
|
|
8013
|
-
name
|
|
8014
|
-
|
|
8015
|
-
|
|
8016
|
-
|
|
8017
|
-
|
|
10980
|
+
Object.entries(fnMap).map(([name, { excludeAnnotations }]) =>
|
|
10981
|
+
promises_namespaceObject.readFile(name).then((data) => ({
|
|
10982
|
+
name,
|
|
10983
|
+
ast: getAst(
|
|
10984
|
+
name,
|
|
10985
|
+
data.toString().replace(/\r\n/g, "\n"),
|
|
10986
|
+
excludeAnnotations
|
|
10987
|
+
),
|
|
10988
|
+
}))
|
|
10989
|
+
)
|
|
8018
10990
|
);
|
|
8019
10991
|
|
|
8020
|
-
files.forEach((f) => {
|
|
8021
|
-
f.ast = prettier_plugin_monkeyc_namespaceObject.parsers.monkeyc.parse(f.monkeyCSource, {
|
|
8022
|
-
grammarSource: f.name,
|
|
8023
|
-
});
|
|
8024
|
-
f.ast.source = f.name;
|
|
8025
|
-
f.ast.monkeyCSource = f.monkeyCSource;
|
|
8026
|
-
delete f.monkeyCSource;
|
|
8027
|
-
(0,external_api_cjs_namespaceObject.collectNamespaces)(f.ast, state);
|
|
8028
|
-
});
|
|
8029
|
-
|
|
8030
10992
|
delete state.shouldExclude;
|
|
8031
10993
|
delete state.post;
|
|
8032
10994
|
|
|
@@ -8247,8 +11209,8 @@ function evaluateFunction(func, args) {
|
|
|
8247
11209
|
}
|
|
8248
11210
|
}
|
|
8249
11211
|
|
|
8250
|
-
async function optimizeMonkeyC(
|
|
8251
|
-
const { files, state } = await analyze(
|
|
11212
|
+
async function optimizeMonkeyC(fnMap) {
|
|
11213
|
+
const { files, state } = await analyze(fnMap);
|
|
8252
11214
|
const replace = (node, obj) => {
|
|
8253
11215
|
for (const k of Object.keys(node)) {
|
|
8254
11216
|
delete node[k];
|
|
@@ -8655,6 +11617,7 @@ async function optimizeMonkeyC(fileNames, buildConfig) {
|
|
|
8655
11617
|
|
|
8656
11618
|
|
|
8657
11619
|
|
|
11620
|
+
|
|
8658
11621
|
function relative_path_no_dotdot(relative) {
|
|
8659
11622
|
return relative.replace(
|
|
8660
11623
|
/^(\.\.[\\\/])+/,
|
|
@@ -8721,35 +11684,121 @@ async function buildOptimizedProject(product, options) {
|
|
|
8721
11684
|
if (product) {
|
|
8722
11685
|
product = config.products[0];
|
|
8723
11686
|
if (config.simulatorBuild === false) {
|
|
8724
|
-
bin =
|
|
11687
|
+
bin = external_path_.join(bin, product);
|
|
8725
11688
|
}
|
|
8726
11689
|
} else {
|
|
8727
|
-
bin =
|
|
11690
|
+
bin = external_path_.join(bin, "exported");
|
|
8728
11691
|
name = `${program}.iq`;
|
|
8729
11692
|
}
|
|
8730
|
-
config.program =
|
|
11693
|
+
config.program = external_path_.join(bin, name);
|
|
8731
11694
|
return build_project(product, config);
|
|
8732
11695
|
}
|
|
8733
11696
|
|
|
11697
|
+
/**
|
|
11698
|
+
* For each barrel project included in the build, we want to build
|
|
11699
|
+
* a local barrel project inside the optimized directory.
|
|
11700
|
+
*
|
|
11701
|
+
* Note that for each named barrel, each target could include a
|
|
11702
|
+
* different barrel, or barrel project. It could even include more
|
|
11703
|
+
* than one - but in that case, they should be separate jungle files
|
|
11704
|
+
* with the same manifest file.
|
|
11705
|
+
*
|
|
11706
|
+
* So for each input barrel (resolvedBarrel.jungles are the jungle
|
|
11707
|
+
* files corresponding to an input barrel), we create a copy of
|
|
11708
|
+
* the barrel with all the sources removed (and pick up the sources
|
|
11709
|
+
* from the input barrel)
|
|
11710
|
+
*/
|
|
11711
|
+
async function createLocalBarrels(targets, options) {
|
|
11712
|
+
if (
|
|
11713
|
+
targets.every(
|
|
11714
|
+
(target) =>
|
|
11715
|
+
!target.group.optimizerConfig.barrelMap ||
|
|
11716
|
+
Object.values(target.group.optimizerConfig.barrelMap).every(
|
|
11717
|
+
(resolvedBarrel) => !resolvedBarrel.qualifier.resourcePath
|
|
11718
|
+
)
|
|
11719
|
+
)
|
|
11720
|
+
) {
|
|
11721
|
+
// there are no barrels, or every barrel has no resources.
|
|
11722
|
+
// we can drop any barrels altogether (we'll need to drop them
|
|
11723
|
+
// from the manifest file too).
|
|
11724
|
+
return;
|
|
11725
|
+
}
|
|
11726
|
+
// where to create the local barrel projects.
|
|
11727
|
+
const barrelDir = external_path_.resolve(
|
|
11728
|
+
options.workspace,
|
|
11729
|
+
options.outputPath,
|
|
11730
|
+
"opt-barrels"
|
|
11731
|
+
);
|
|
11732
|
+
return targets.reduce((promise, target) => {
|
|
11733
|
+
const barrelMap = target.group.optimizerConfig.barrelMap;
|
|
11734
|
+
if (!barrelMap || target.group.optBarrels) {
|
|
11735
|
+
return promise;
|
|
11736
|
+
}
|
|
11737
|
+
const optBarrels = (target.group.optimizerConfig.optBarrels = {});
|
|
11738
|
+
return Object.entries(barrelMap).reduce(
|
|
11739
|
+
(promise, [barrel, resolvedBarrel]) => {
|
|
11740
|
+
const { manifest, jungles } = resolvedBarrel;
|
|
11741
|
+
const rawBarrelDir = external_path_.dirname(jungles[0]);
|
|
11742
|
+
const rawJungles = jungles.map((jungle) =>
|
|
11743
|
+
external_path_.relative(rawBarrelDir, jungle)
|
|
11744
|
+
);
|
|
11745
|
+
const sha1 = external_crypto_namespaceObject.createHash("sha1")
|
|
11746
|
+
.update(rawBarrelDir, "binary")
|
|
11747
|
+
.digest("base64")
|
|
11748
|
+
.replace(/[\/=+]/g, "");
|
|
11749
|
+
const optBarrelDir = external_path_.resolve(barrelDir, `${barrel}-${sha1}`);
|
|
11750
|
+
if (!(0,external_api_cjs_namespaceObject.hasProperty)(optBarrels, barrel)) {
|
|
11751
|
+
optBarrels[barrel] = {
|
|
11752
|
+
rawBarrelDir,
|
|
11753
|
+
manifest,
|
|
11754
|
+
jungleFiles: [...rawJungles],
|
|
11755
|
+
optBarrelDir,
|
|
11756
|
+
};
|
|
11757
|
+
return promise.then(() =>
|
|
11758
|
+
(0,external_util_cjs_namespaceObject.copyRecursiveAsNeeded)(
|
|
11759
|
+
rawBarrelDir,
|
|
11760
|
+
optBarrelDir,
|
|
11761
|
+
(src) => !src.endsWith(".mc")
|
|
11762
|
+
)
|
|
11763
|
+
);
|
|
11764
|
+
}
|
|
11765
|
+
if (
|
|
11766
|
+
optBarrels[barrel].manifest !== manifest ||
|
|
11767
|
+
optBarrels[barrel].optBarrelDir !== optBarrelDir ||
|
|
11768
|
+
optBarrels[barrel].rawBarrelDir != rawBarrelDir
|
|
11769
|
+
) {
|
|
11770
|
+
throw new Error(
|
|
11771
|
+
`For device ${
|
|
11772
|
+
target.product
|
|
11773
|
+
}, barrel ${barrel} was mapped to both ${external_path_.relative(
|
|
11774
|
+
optBarrels[barrel].rawBarrelDir,
|
|
11775
|
+
optBarrels[barrel].manifest
|
|
11776
|
+
)} in ${optBarrels[barrel].rawBarrelDir} and ${external_path_.relative(
|
|
11777
|
+
rawBarrelDir,
|
|
11778
|
+
manifest
|
|
11779
|
+
)} in ${rawBarrelDir}.`
|
|
11780
|
+
);
|
|
11781
|
+
}
|
|
11782
|
+
optBarrels[barrel].jungleFiles.push(...rawJungles);
|
|
11783
|
+
return promise;
|
|
11784
|
+
},
|
|
11785
|
+
promise
|
|
11786
|
+
);
|
|
11787
|
+
}, Promise.resolve());
|
|
11788
|
+
}
|
|
11789
|
+
|
|
8734
11790
|
async function generateOptimizedProject(options) {
|
|
8735
11791
|
const config = await getConfig(options);
|
|
8736
11792
|
const workspace = config.workspace;
|
|
8737
11793
|
|
|
8738
|
-
const
|
|
8739
|
-
|
|
8740
|
-
const barrels = external_path_namespaceObject.resolve(workspace, "barrels.jungle");
|
|
8741
|
-
if (
|
|
8742
|
-
await promises_namespaceObject.stat(barrels)
|
|
8743
|
-
.then((s) => s.isFile())
|
|
8744
|
-
.catch(() => false)
|
|
8745
|
-
) {
|
|
8746
|
-
jungleFiles.push(barrels);
|
|
8747
|
-
}
|
|
8748
|
-
}
|
|
8749
|
-
const { manifest, targets, xml } = await get_jungle(
|
|
8750
|
-
jungleFiles.join(";"),
|
|
11794
|
+
const { manifest, targets, xml, jungles } = await get_jungle(
|
|
11795
|
+
config.jungleFiles,
|
|
8751
11796
|
config
|
|
8752
11797
|
);
|
|
11798
|
+
|
|
11799
|
+
const dependencyFiles = [manifest, ...jungles];
|
|
11800
|
+
await createLocalBarrels(targets, options);
|
|
11801
|
+
|
|
8753
11802
|
const buildConfigs = {};
|
|
8754
11803
|
const products = {};
|
|
8755
11804
|
let pick_one = config.products ? config.products.indexOf("pick-one") : -1;
|
|
@@ -8759,25 +11808,24 @@ async function generateOptimizedProject(options) {
|
|
|
8759
11808
|
options.products[pick_one] = targets[0].product;
|
|
8760
11809
|
}
|
|
8761
11810
|
return {
|
|
8762
|
-
jungleFiles: jungleFiles
|
|
8763
|
-
program:
|
|
11811
|
+
jungleFiles: config.jungleFiles,
|
|
11812
|
+
program: external_path_.basename(external_path_.dirname(manifest)),
|
|
8764
11813
|
};
|
|
8765
11814
|
}
|
|
11815
|
+
let dropBarrels = false;
|
|
8766
11816
|
const configKey = (p) =>
|
|
8767
11817
|
p.group.key + (config.releaseBuild ? "-release" : "-debug");
|
|
8768
11818
|
targets.forEach((p) => {
|
|
8769
11819
|
const key = configKey(p);
|
|
8770
11820
|
if (!(0,external_api_cjs_namespaceObject.hasProperty)(buildConfigs, key)) {
|
|
8771
11821
|
p.group.dir = key;
|
|
8772
|
-
|
|
8773
|
-
|
|
8774
|
-
p.group.optimizerConfig
|
|
11822
|
+
if (
|
|
11823
|
+
p.group.optimizerConfig.barrelMap &&
|
|
11824
|
+
!p.group.optimizerConfig.optBarrels
|
|
11825
|
+
) {
|
|
11826
|
+
dropBarrels = true;
|
|
8775
11827
|
}
|
|
8776
|
-
|
|
8777
|
-
// exclude (:release) in debug builds. This isn't backwards!
|
|
8778
|
-
p.group.optimizerConfig["excludeAnnotations"].push(
|
|
8779
|
-
config.releaseBuild ? "debug" : "release"
|
|
8780
|
-
);
|
|
11828
|
+
buildConfigs[key] = null;
|
|
8781
11829
|
}
|
|
8782
11830
|
if (
|
|
8783
11831
|
pick_one >= 0 ||
|
|
@@ -8802,27 +11850,29 @@ async function generateOptimizedProject(options) {
|
|
|
8802
11850
|
|
|
8803
11851
|
// console.log(JSON.stringify(targets));
|
|
8804
11852
|
|
|
8805
|
-
const jungle_dir =
|
|
11853
|
+
const jungle_dir = external_path_.resolve(workspace, config.outputPath);
|
|
8806
11854
|
await promises_namespaceObject.mkdir(jungle_dir, { recursive: true });
|
|
8807
|
-
const relative_path = (s) =>
|
|
11855
|
+
const relative_path = (s) => external_path_.relative(jungle_dir, s);
|
|
8808
11856
|
let relative_manifest = relative_path(manifest);
|
|
8809
11857
|
const manifestOk =
|
|
8810
|
-
!config.checkManifest ||
|
|
8811
|
-
|
|
8812
|
-
|
|
8813
|
-
|
|
8814
|
-
|
|
11858
|
+
(!config.checkManifest ||
|
|
11859
|
+
(await checkManifest(
|
|
11860
|
+
xml,
|
|
11861
|
+
targets.map((t) => t.product)
|
|
11862
|
+
))) &&
|
|
11863
|
+
!dropBarrels;
|
|
8815
11864
|
const promises = Object.keys(buildConfigs)
|
|
8816
11865
|
.sort()
|
|
8817
11866
|
.map((key) => {
|
|
8818
11867
|
const buildConfig = buildConfigs[key];
|
|
8819
|
-
const outputPath =
|
|
11868
|
+
const outputPath = external_path_.join(config.outputPath, key);
|
|
8820
11869
|
|
|
8821
11870
|
return buildConfig
|
|
8822
11871
|
? generateOneConfig({
|
|
8823
11872
|
...config,
|
|
8824
11873
|
buildConfig,
|
|
8825
11874
|
outputPath,
|
|
11875
|
+
dependencyFiles,
|
|
8826
11876
|
}).catch((e) => {
|
|
8827
11877
|
if (!e.stack) {
|
|
8828
11878
|
e = new Error(e.toString());
|
|
@@ -8830,14 +11880,17 @@ async function generateOptimizedProject(options) {
|
|
|
8830
11880
|
e.products = products[key];
|
|
8831
11881
|
throw e;
|
|
8832
11882
|
})
|
|
8833
|
-
: promises_namespaceObject.rm(
|
|
11883
|
+
: promises_namespaceObject.rm(external_path_.resolve(workspace, outputPath), {
|
|
8834
11884
|
recursive: true,
|
|
8835
11885
|
force: true,
|
|
8836
11886
|
});
|
|
8837
11887
|
});
|
|
8838
11888
|
|
|
8839
11889
|
if (!manifestOk) {
|
|
8840
|
-
|
|
11890
|
+
if (dropBarrels) {
|
|
11891
|
+
manifestDropBarrels(xml);
|
|
11892
|
+
}
|
|
11893
|
+
const manifestFile = external_path_.join(jungle_dir, "manifest.xml");
|
|
8841
11894
|
promises.push(writeManifest(manifestFile, xml));
|
|
8842
11895
|
relative_manifest = "manifest.xml";
|
|
8843
11896
|
}
|
|
@@ -8855,12 +11908,46 @@ async function generateOptimizedProject(options) {
|
|
|
8855
11908
|
const { product, qualifier, group } = jungle;
|
|
8856
11909
|
const prefix = `${product}.`;
|
|
8857
11910
|
process_field(prefix, qualifier, "sourcePath", (s) =>
|
|
8858
|
-
|
|
11911
|
+
external_path_.join(
|
|
11912
|
+
group.dir,
|
|
11913
|
+
"source",
|
|
11914
|
+
relative_path_no_dotdot(external_path_.relative(workspace, s))
|
|
11915
|
+
)
|
|
8859
11916
|
.replace(/([\\\/]\*\*)[\\\/]\*/g, "$1")
|
|
8860
11917
|
);
|
|
11918
|
+
if (group.optimizerConfig.optBarrels) {
|
|
11919
|
+
parts.push(
|
|
11920
|
+
`${prefix}barrelPath = ${Object.values(group.optimizerConfig.optBarrels)
|
|
11921
|
+
.map(
|
|
11922
|
+
(value) =>
|
|
11923
|
+
`[${value.jungleFiles
|
|
11924
|
+
.map((j) => relative_path(external_path_.join(value.optBarrelDir, j)))
|
|
11925
|
+
.join(";")}]`
|
|
11926
|
+
)
|
|
11927
|
+
.join(";")}`
|
|
11928
|
+
);
|
|
11929
|
+
}
|
|
11930
|
+
if (group.optimizerConfig.barrelMap) {
|
|
11931
|
+
parts.push(
|
|
11932
|
+
`${prefix}sourcePath = ${[`$(${prefix}sourcePath)`]
|
|
11933
|
+
.concat(
|
|
11934
|
+
Object.entries(group.optimizerConfig.barrelMap)
|
|
11935
|
+
.map(([barrel, resolvedBarrel]) => {
|
|
11936
|
+
const root = external_path_.dirname(resolvedBarrel.jungles[0]);
|
|
11937
|
+
return (resolvedBarrel.qualifier.sourcePath || []).map((s) =>
|
|
11938
|
+
external_path_.join(group.dir, "barrels", barrel, external_path_.relative(root, s))
|
|
11939
|
+
.replace(/([\\\/]\*\*)[\\\/]\*/g, "$1")
|
|
11940
|
+
);
|
|
11941
|
+
})
|
|
11942
|
+
.flat()
|
|
11943
|
+
.sort()
|
|
11944
|
+
.filter((s, i, arr) => !i || s !== arr[i - 1])
|
|
11945
|
+
)
|
|
11946
|
+
.join(";")}`
|
|
11947
|
+
);
|
|
11948
|
+
}
|
|
11949
|
+
// annotations were handled via source transformations.
|
|
8861
11950
|
process_field(prefix, qualifier, "resourcePath", relative_path);
|
|
8862
|
-
process_field(prefix, qualifier, "barrelPath", relative_path);
|
|
8863
|
-
process_field(prefix, qualifier, "annotations");
|
|
8864
11951
|
process_field(prefix, qualifier, "excludeAnnotations");
|
|
8865
11952
|
if (qualifier.lang) {
|
|
8866
11953
|
Object.keys(qualifier.lang).forEach((key) => {
|
|
@@ -8869,23 +11956,25 @@ async function generateOptimizedProject(options) {
|
|
|
8869
11956
|
}
|
|
8870
11957
|
});
|
|
8871
11958
|
|
|
8872
|
-
const
|
|
11959
|
+
const jungleFiles = external_path_.join(
|
|
8873
11960
|
jungle_dir,
|
|
8874
11961
|
`${config.releaseBuild ? "release" : "debug"}.jungle`
|
|
8875
11962
|
);
|
|
8876
|
-
promises.push(promises_namespaceObject.writeFile(
|
|
11963
|
+
promises.push(promises_namespaceObject.writeFile(jungleFiles, parts.join("\n")));
|
|
8877
11964
|
|
|
8878
11965
|
await Promise.all(promises);
|
|
8879
11966
|
return {
|
|
8880
|
-
jungleFiles
|
|
8881
|
-
program:
|
|
11967
|
+
jungleFiles,
|
|
11968
|
+
program: external_path_.basename(external_path_.dirname(manifest)),
|
|
8882
11969
|
};
|
|
8883
11970
|
}
|
|
8884
11971
|
|
|
8885
|
-
async function
|
|
8886
|
-
|
|
8887
|
-
|
|
8888
|
-
|
|
11972
|
+
async function fileInfoFromConfig(
|
|
11973
|
+
workspace,
|
|
11974
|
+
output,
|
|
11975
|
+
buildConfig,
|
|
11976
|
+
extraExcludes
|
|
11977
|
+
) {
|
|
8889
11978
|
const paths = (
|
|
8890
11979
|
await Promise.all(
|
|
8891
11980
|
buildConfig.sourcePath.map((pattern) =>
|
|
@@ -8906,24 +11995,94 @@ async function generateOneConfig(config) {
|
|
|
8906
11995
|
.flat()
|
|
8907
11996
|
.filter(
|
|
8908
11997
|
(file) =>
|
|
8909
|
-
|
|
11998
|
+
file.endsWith(".mc") &&
|
|
11999
|
+
!external_path_.relative(workspace, file).startsWith("bin") &&
|
|
8910
12000
|
(!buildConfig.sourceExcludes ||
|
|
8911
12001
|
!buildConfig.sourceExcludes.includes(file))
|
|
8912
|
-
)
|
|
8913
|
-
|
|
8914
|
-
|
|
8915
|
-
|
|
8916
|
-
|
|
8917
|
-
|
|
8918
|
-
|
|
8919
|
-
|
|
8920
|
-
|
|
8921
|
-
|
|
8922
|
-
|
|
12002
|
+
);
|
|
12003
|
+
|
|
12004
|
+
const excludeAnnotations = Object.assign(
|
|
12005
|
+
buildConfig.excludeAnnotations
|
|
12006
|
+
? Object.fromEntries(
|
|
12007
|
+
buildConfig.excludeAnnotations.map((ex) => [ex, true])
|
|
12008
|
+
)
|
|
12009
|
+
: {},
|
|
12010
|
+
extraExcludes
|
|
12011
|
+
);
|
|
12012
|
+
|
|
12013
|
+
return Object.fromEntries(
|
|
12014
|
+
files.map((file) => [
|
|
12015
|
+
file,
|
|
12016
|
+
{
|
|
12017
|
+
output: external_path_.join(
|
|
12018
|
+
output,
|
|
12019
|
+
relative_path_no_dotdot(external_path_.relative(workspace, file))
|
|
12020
|
+
),
|
|
12021
|
+
excludeAnnotations,
|
|
12022
|
+
},
|
|
12023
|
+
])
|
|
12024
|
+
);
|
|
12025
|
+
}
|
|
12026
|
+
|
|
12027
|
+
function excludesFromAnnotations(barrel, annotations, resolvedBarrel) {
|
|
12028
|
+
const excludes = resolvedBarrel.annotations
|
|
12029
|
+
? Object.fromEntries(resolvedBarrel.annotations.map((a) => [a, true]))
|
|
12030
|
+
: {};
|
|
12031
|
+
if (annotations && annotations[barrel]) {
|
|
12032
|
+
annotations[barrel].forEach((a) => {
|
|
12033
|
+
delete excludes[a];
|
|
12034
|
+
});
|
|
12035
|
+
}
|
|
12036
|
+
return excludes;
|
|
12037
|
+
}
|
|
12038
|
+
|
|
12039
|
+
async function generateOneConfig(config) {
|
|
12040
|
+
const { workspace, buildConfig } = config;
|
|
12041
|
+
const output = external_path_.join(workspace, config.outputPath);
|
|
12042
|
+
|
|
12043
|
+
const dependencyFiles = [...config.dependencyFiles];
|
|
12044
|
+
|
|
12045
|
+
const buildModeExcludes = {
|
|
12046
|
+
// note: exclude debug in release builds, and release in debug builds
|
|
12047
|
+
[config.releaseBuild ? "debug" : "release"]: true,
|
|
12048
|
+
};
|
|
12049
|
+
|
|
12050
|
+
const fnMap = await fileInfoFromConfig(
|
|
12051
|
+
workspace,
|
|
12052
|
+
external_path_.join(output, "source"),
|
|
12053
|
+
buildConfig,
|
|
12054
|
+
buildModeExcludes
|
|
8923
12055
|
);
|
|
8924
12056
|
|
|
12057
|
+
if (buildConfig.barrelMap) {
|
|
12058
|
+
const barrelFnMaps = await Promise.all(
|
|
12059
|
+
Object.entries(buildConfig.barrelMap)
|
|
12060
|
+
.map(([barrel, resolvedBarrel]) => {
|
|
12061
|
+
dependencyFiles.push(
|
|
12062
|
+
...resolvedBarrel.jungles,
|
|
12063
|
+
resolvedBarrel.manifest
|
|
12064
|
+
);
|
|
12065
|
+
return fileInfoFromConfig(
|
|
12066
|
+
external_path_.dirname(resolvedBarrel.jungles[0]),
|
|
12067
|
+
external_path_.join(output, "barrels", barrel),
|
|
12068
|
+
resolvedBarrel.qualifier,
|
|
12069
|
+
{
|
|
12070
|
+
...buildModeExcludes,
|
|
12071
|
+
...excludesFromAnnotations(
|
|
12072
|
+
barrel,
|
|
12073
|
+
buildConfig.annotations,
|
|
12074
|
+
resolvedBarrel
|
|
12075
|
+
),
|
|
12076
|
+
}
|
|
12077
|
+
);
|
|
12078
|
+
})
|
|
12079
|
+
.flat()
|
|
12080
|
+
);
|
|
12081
|
+
barrelFnMaps.forEach((barrelFnMap) => Object.assign(fnMap, barrelFnMap));
|
|
12082
|
+
}
|
|
12083
|
+
|
|
8925
12084
|
const actualOptimizedFiles = (
|
|
8926
|
-
await (0,external_util_cjs_namespaceObject.globa)(
|
|
12085
|
+
await (0,external_util_cjs_namespaceObject.globa)(external_path_.join(output, "**", "*.mc"), { mark: true })
|
|
8927
12086
|
)
|
|
8928
12087
|
.filter((file) => !file.endsWith("/"))
|
|
8929
12088
|
.sort();
|
|
@@ -8932,25 +12091,30 @@ async function generateOneConfig(config) {
|
|
|
8932
12091
|
// set of files we're going to generate (in case eg a jungle file change
|
|
8933
12092
|
// might have altered it)
|
|
8934
12093
|
if (
|
|
8935
|
-
actualOptimizedFiles.length ==
|
|
12094
|
+
actualOptimizedFiles.length == Object.values(fnMap).length &&
|
|
8936
12095
|
Object.values(fnMap)
|
|
12096
|
+
.map((v) => v.output)
|
|
8937
12097
|
.sort()
|
|
8938
12098
|
.every((f, i) => f == actualOptimizedFiles[i])
|
|
8939
12099
|
) {
|
|
8940
12100
|
// now if the newest source file is older than
|
|
8941
12101
|
// the oldest optimized file, we don't need to regenerate
|
|
8942
|
-
const source_time = await (0,external_util_cjs_namespaceObject.last_modified)(
|
|
8943
|
-
|
|
8944
|
-
|
|
12102
|
+
const source_time = await (0,external_util_cjs_namespaceObject.last_modified)(
|
|
12103
|
+
Object.keys(fnMap).concat(dependencyFiles)
|
|
12104
|
+
);
|
|
12105
|
+
const opt_time = await (0,external_util_cjs_namespaceObject.first_modified)(
|
|
12106
|
+
Object.values(fnMap).map((v) => v.output)
|
|
12107
|
+
);
|
|
12108
|
+
if (source_time < opt_time && 1652050734499 < opt_time) return;
|
|
8945
12109
|
}
|
|
8946
12110
|
|
|
8947
12111
|
await promises_namespaceObject.rm(output, { recursive: true, force: true });
|
|
8948
12112
|
await promises_namespaceObject.mkdir(output, { recursive: true });
|
|
8949
|
-
const optFiles = await optimizeMonkeyC(
|
|
12113
|
+
const optFiles = await optimizeMonkeyC(fnMap);
|
|
8950
12114
|
return await Promise.all(
|
|
8951
12115
|
optFiles.map(async (file) => {
|
|
8952
|
-
const name = fnMap[file.name];
|
|
8953
|
-
const dir =
|
|
12116
|
+
const name = fnMap[file.name].output;
|
|
12117
|
+
const dir = external_path_.dirname(name);
|
|
8954
12118
|
await promises_namespaceObject.mkdir(dir, { recursive: true });
|
|
8955
12119
|
|
|
8956
12120
|
const opt_source = (0,external_api_cjs_namespaceObject.formatAst)(file.ast);
|