prettier 1.13.7 → 1.14.3
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/LICENSE +7 -0
- package/README.md +3 -2
- package/bin-prettier.js +4760 -1136
- package/index.js +7887 -4185
- package/package.json +4 -1
- package/parser-babylon.js +1 -1
- package/parser-flow.js +1 -1
- package/parser-glimmer.js +1 -1
- package/parser-graphql.js +1 -1
- package/parser-markdown.js +1 -1
- package/parser-postcss.js +26082 -23115
- package/parser-typescript.js +1 -1
- package/parser-vue.js +1 -1
- package/parser-yaml.js +1 -0
- package/standalone.js +2605 -804
- package/third-party.js +535 -1161
package/third-party.js
CHANGED
|
@@ -5,9 +5,8 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
|
|
|
5
5
|
var stream = _interopDefault(require('stream'));
|
|
6
6
|
var os = _interopDefault(require('os'));
|
|
7
7
|
var path = _interopDefault(require('path'));
|
|
8
|
-
var fs = _interopDefault(require('fs'));
|
|
9
8
|
var util = _interopDefault(require('util'));
|
|
10
|
-
var
|
|
9
|
+
var fs = _interopDefault(require('fs'));
|
|
11
10
|
|
|
12
11
|
function commonjsRequire () {
|
|
13
12
|
throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs');
|
|
@@ -139,37 +138,27 @@ var array = function array(stream$$1, opts) {
|
|
|
139
138
|
getStream_1.buffer = buffer;
|
|
140
139
|
getStream_1.array = array;
|
|
141
140
|
|
|
142
|
-
function
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
fs.readFile(filepath, 'utf8', function (err, content) {
|
|
147
|
-
if (err && err.code === 'ENOENT' && !throwNotFound) {
|
|
148
|
-
return resolve(null);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (err) return reject(err);
|
|
152
|
-
resolve(content);
|
|
153
|
-
});
|
|
154
|
-
});
|
|
141
|
+
function _classCallCheck(instance, Constructor) {
|
|
142
|
+
if (!(instance instanceof Constructor)) {
|
|
143
|
+
throw new TypeError("Cannot call a class as a function");
|
|
144
|
+
}
|
|
155
145
|
}
|
|
156
146
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
if (err.code === 'ENOENT' && !throwNotFound) {
|
|
165
|
-
return null;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
throw err;
|
|
147
|
+
function _defineProperties(target, props) {
|
|
148
|
+
for (var i = 0; i < props.length; i++) {
|
|
149
|
+
var descriptor = props[i];
|
|
150
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
151
|
+
descriptor.configurable = true;
|
|
152
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
153
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
169
154
|
}
|
|
170
|
-
}
|
|
155
|
+
}
|
|
171
156
|
|
|
172
|
-
|
|
157
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
158
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
159
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
160
|
+
return Constructor;
|
|
161
|
+
}
|
|
173
162
|
|
|
174
163
|
var isArrayish = function isArrayish(obj) {
|
|
175
164
|
if (!obj) {
|
|
@@ -301,785 +290,40 @@ errorEx.line = function (str, def) {
|
|
|
301
290
|
|
|
302
291
|
var errorEx_1 = errorEx;
|
|
303
292
|
|
|
304
|
-
var
|
|
305
|
-
// This is autogenerated with esprima tools, see:
|
|
306
|
-
// https://github.com/ariya/esprima/blob/master/esprima.js
|
|
307
|
-
//
|
|
308
|
-
// PS: oh God, I hate Unicode
|
|
309
|
-
// ECMAScript 5.1/Unicode v6.3.0 NonAsciiIdentifierStart:
|
|
310
|
-
var Uni = module.exports;
|
|
311
|
-
|
|
312
|
-
module.exports.isWhiteSpace = function isWhiteSpace(x) {
|
|
313
|
-
// section 7.2, table 2
|
|
314
|
-
return x === '\u0020' || x === '\u00A0' || x === '\uFEFF' // <-- this is not a Unicode WS, only a JS one
|
|
315
|
-
|| x >= '\u0009' && x <= '\u000D' // 9 A B C D
|
|
316
|
-
// + whitespace characters from unicode, category Zs
|
|
317
|
-
|| x === '\u1680' || x === '\u180E' || x >= '\u2000' && x <= '\u200A' // 0 1 2 3 4 5 6 7 8 9 A
|
|
318
|
-
|| x === '\u2028' || x === '\u2029' || x === '\u202F' || x === '\u205F' || x === '\u3000';
|
|
319
|
-
};
|
|
320
|
-
|
|
321
|
-
module.exports.isWhiteSpaceJSON = function isWhiteSpaceJSON(x) {
|
|
322
|
-
return x === '\u0020' || x === '\u0009' || x === '\u000A' || x === '\u000D';
|
|
323
|
-
};
|
|
324
|
-
|
|
325
|
-
module.exports.isLineTerminator = function isLineTerminator(x) {
|
|
326
|
-
// ok, here is the part when JSON is wrong
|
|
327
|
-
// section 7.3, table 3
|
|
328
|
-
return x === '\u000A' || x === '\u000D' || x === '\u2028' || x === '\u2029';
|
|
329
|
-
};
|
|
330
|
-
|
|
331
|
-
module.exports.isLineTerminatorJSON = function isLineTerminatorJSON(x) {
|
|
332
|
-
return x === '\u000A' || x === '\u000D';
|
|
333
|
-
};
|
|
334
|
-
|
|
335
|
-
module.exports.isIdentifierStart = function isIdentifierStart(x) {
|
|
336
|
-
return x === '$' || x === '_' || x >= 'A' && x <= 'Z' || x >= 'a' && x <= 'z' || x >= '\u0080' && Uni.NonAsciiIdentifierStart.test(x);
|
|
337
|
-
};
|
|
338
|
-
|
|
339
|
-
module.exports.isIdentifierPart = function isIdentifierPart(x) {
|
|
340
|
-
return x === '$' || x === '_' || x >= 'A' && x <= 'Z' || x >= 'a' && x <= 'z' || x >= '0' && x <= '9' // <-- addition to Start
|
|
341
|
-
|| x >= '\u0080' && Uni.NonAsciiIdentifierPart.test(x);
|
|
342
|
-
};
|
|
343
|
-
|
|
344
|
-
module.exports.NonAsciiIdentifierStart = /[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0\u08A2-\u08AC\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0977\u0979-\u097F\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C33\u0C35-\u0C39\u0C3D\u0C58\u0C59\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D60\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F4\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F0\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191C\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19C1-\u19C7\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA697\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA793\uA7A0-\uA7AA\uA7F8-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA80-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uABC0-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]/; // ECMAScript 5.1/Unicode v6.3.0 NonAsciiIdentifierPart:
|
|
345
|
-
|
|
346
|
-
module.exports.NonAsciiIdentifierPart = /[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u0527\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u08A0\u08A2-\u08AC\u08E4-\u08FE\u0900-\u0963\u0966-\u096F\u0971-\u0977\u0979-\u097F\u0981-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C01-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C33\u0C35-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58\u0C59\u0C60-\u0C63\u0C66-\u0C6F\u0C82\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D02\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D57\u0D60-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1380-\u138F\u13A0-\u13F4\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F0\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191C\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19D9\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1CD0-\u1CD2\u1CD4-\u1CF6\u1D00-\u1DE6\u1DFC-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u200C\u200D\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u2E2F\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099\u309A\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA697\uA69F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA793\uA7A0-\uA7AA\uA7F8-\uA827\uA840-\uA873\uA880-\uA8C4\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A\uAA7B\uAA80-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uABC0-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE26\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]/;
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
var parse_1 = createCommonjsModule(function (module) {
|
|
350
|
-
/*
|
|
351
|
-
* Author: Alex Kocharin <alex@kocharin.ru>
|
|
352
|
-
* GIT: https://github.com/rlidwka/jju
|
|
353
|
-
* License: WTFPL, grab your copy here: http://www.wtfpl.net/txt/copying/
|
|
354
|
-
*/
|
|
355
|
-
// RTFM: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf
|
|
356
|
-
function isHexDigit(x) {
|
|
357
|
-
return x >= '0' && x <= '9' || x >= 'A' && x <= 'F' || x >= 'a' && x <= 'f';
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
function isOctDigit(x) {
|
|
361
|
-
return x >= '0' && x <= '7';
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
function isDecDigit(x) {
|
|
365
|
-
return x >= '0' && x <= '9';
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
var unescapeMap = {
|
|
369
|
-
'\'': '\'',
|
|
370
|
-
'"': '"',
|
|
371
|
-
'\\': '\\',
|
|
372
|
-
'b': '\b',
|
|
373
|
-
'f': '\f',
|
|
374
|
-
'n': '\n',
|
|
375
|
-
'r': '\r',
|
|
376
|
-
't': '\t',
|
|
377
|
-
'v': '\v',
|
|
378
|
-
'/': '/'
|
|
379
|
-
};
|
|
380
|
-
|
|
381
|
-
function formatError(input, msg, position, lineno, column, json5) {
|
|
382
|
-
var result = msg + ' at ' + (lineno + 1) + ':' + (column + 1),
|
|
383
|
-
tmppos = position - column - 1,
|
|
384
|
-
srcline = '',
|
|
385
|
-
underline = '';
|
|
386
|
-
var isLineTerminator = json5 ? unicode.isLineTerminator : unicode.isLineTerminatorJSON; // output no more than 70 characters before the wrong ones
|
|
387
|
-
|
|
388
|
-
if (tmppos < position - 70) {
|
|
389
|
-
tmppos = position - 70;
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
while (1) {
|
|
393
|
-
var chr = input[++tmppos];
|
|
394
|
-
|
|
395
|
-
if (isLineTerminator(chr) || tmppos === input.length) {
|
|
396
|
-
if (position >= tmppos) {
|
|
397
|
-
// ending line error, so show it after the last char
|
|
398
|
-
underline += '^';
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
break;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
srcline += chr;
|
|
405
|
-
|
|
406
|
-
if (position === tmppos) {
|
|
407
|
-
underline += '^';
|
|
408
|
-
} else if (position > tmppos) {
|
|
409
|
-
underline += input[tmppos] === '\t' ? '\t' : ' ';
|
|
410
|
-
} // output no more than 78 characters on the string
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
if (srcline.length > 78) break;
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
return result + '\n' + srcline + '\n' + underline;
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
function parse(input, options) {
|
|
420
|
-
// parse as a standard JSON mode
|
|
421
|
-
var json5 = !(options.mode === 'json' || options.legacy);
|
|
422
|
-
var isLineTerminator = json5 ? unicode.isLineTerminator : unicode.isLineTerminatorJSON;
|
|
423
|
-
var isWhiteSpace = json5 ? unicode.isWhiteSpace : unicode.isWhiteSpaceJSON;
|
|
424
|
-
var length = input.length,
|
|
425
|
-
lineno = 0,
|
|
426
|
-
linestart = 0,
|
|
427
|
-
position = 0,
|
|
428
|
-
stack = [];
|
|
429
|
-
|
|
430
|
-
var tokenStart = function tokenStart() {};
|
|
431
|
-
|
|
432
|
-
var tokenEnd = function tokenEnd(v) {
|
|
433
|
-
return v;
|
|
434
|
-
};
|
|
435
|
-
/* tokenize({
|
|
436
|
-
raw: '...',
|
|
437
|
-
type: 'whitespace'|'comment'|'key'|'literal'|'separator'|'newline',
|
|
438
|
-
value: 'number'|'string'|'whatever',
|
|
439
|
-
path: [...],
|
|
440
|
-
})
|
|
441
|
-
*/
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
if (options._tokenize) {
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
(function () {
|
|
448
|
-
var start = null;
|
|
449
|
-
|
|
450
|
-
tokenStart = function tokenStart() {
|
|
451
|
-
if (start !== null) throw Error('internal error, token overlap');
|
|
452
|
-
start = position;
|
|
453
|
-
};
|
|
454
|
-
|
|
455
|
-
tokenEnd = function tokenEnd(v, type) {
|
|
456
|
-
if (start != position) {
|
|
457
|
-
var hash = {
|
|
458
|
-
raw: input.substr(start, position - start),
|
|
459
|
-
type: type,
|
|
460
|
-
stack: stack.slice(0)
|
|
461
|
-
};
|
|
462
|
-
if (v !== undefined) hash.value = v;
|
|
463
|
-
|
|
464
|
-
options._tokenize.call(null, hash);
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
start = null;
|
|
468
|
-
return v;
|
|
469
|
-
};
|
|
470
|
-
})();
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
function fail(msg) {
|
|
474
|
-
var column = position - linestart;
|
|
475
|
-
|
|
476
|
-
if (!msg) {
|
|
477
|
-
if (position < length) {
|
|
478
|
-
var token = '\'' + JSON.stringify(input[position]).replace(/^"|"$/g, '').replace(/'/g, "\\'").replace(/\\"/g, '"') + '\'';
|
|
479
|
-
if (!msg) msg = 'Unexpected token ' + token;
|
|
480
|
-
} else {
|
|
481
|
-
if (!msg) msg = 'Unexpected end of input';
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
var error = SyntaxError(formatError(input, msg, position, lineno, column, json5));
|
|
486
|
-
error.row = lineno + 1;
|
|
487
|
-
error.column = column + 1;
|
|
488
|
-
throw error;
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
function newline(chr) {
|
|
492
|
-
// account for <cr><lf>
|
|
493
|
-
if (chr === '\r' && input[position] === '\n') position++;
|
|
494
|
-
linestart = position;
|
|
495
|
-
lineno++;
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
function parseGeneric() {
|
|
499
|
-
var result;
|
|
500
|
-
|
|
501
|
-
while (position < length) {
|
|
502
|
-
tokenStart();
|
|
503
|
-
var chr = input[position++];
|
|
504
|
-
|
|
505
|
-
if (chr === '"' || chr === '\'' && json5) {
|
|
506
|
-
return tokenEnd(parseString(chr), 'literal');
|
|
507
|
-
} else if (chr === '{') {
|
|
508
|
-
tokenEnd(undefined, 'separator');
|
|
509
|
-
return parseObject();
|
|
510
|
-
} else if (chr === '[') {
|
|
511
|
-
tokenEnd(undefined, 'separator');
|
|
512
|
-
return parseArray();
|
|
513
|
-
} else if (chr === '-' || chr === '.' || isDecDigit(chr) // + number Infinity NaN
|
|
514
|
-
|| json5 && (chr === '+' || chr === 'I' || chr === 'N')) {
|
|
515
|
-
return tokenEnd(parseNumber(), 'literal');
|
|
516
|
-
} else if (chr === 'n') {
|
|
517
|
-
parseKeyword('null');
|
|
518
|
-
return tokenEnd(null, 'literal');
|
|
519
|
-
} else if (chr === 't') {
|
|
520
|
-
parseKeyword('true');
|
|
521
|
-
return tokenEnd(true, 'literal');
|
|
522
|
-
} else if (chr === 'f') {
|
|
523
|
-
parseKeyword('false');
|
|
524
|
-
return tokenEnd(false, 'literal');
|
|
525
|
-
} else {
|
|
526
|
-
position--;
|
|
527
|
-
return tokenEnd(undefined);
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
function parseKey() {
|
|
533
|
-
var result;
|
|
534
|
-
|
|
535
|
-
while (position < length) {
|
|
536
|
-
tokenStart();
|
|
537
|
-
var chr = input[position++];
|
|
538
|
-
|
|
539
|
-
if (chr === '"' || chr === '\'' && json5) {
|
|
540
|
-
return tokenEnd(parseString(chr), 'key');
|
|
541
|
-
} else if (chr === '{') {
|
|
542
|
-
tokenEnd(undefined, 'separator');
|
|
543
|
-
return parseObject();
|
|
544
|
-
} else if (chr === '[') {
|
|
545
|
-
tokenEnd(undefined, 'separator');
|
|
546
|
-
return parseArray();
|
|
547
|
-
} else if (chr === '.' || isDecDigit(chr)) {
|
|
548
|
-
return tokenEnd(parseNumber(true), 'key');
|
|
549
|
-
} else if (json5 && unicode.isIdentifierStart(chr) || chr === '\\' && input[position] === 'u') {
|
|
550
|
-
// unicode char or a unicode sequence
|
|
551
|
-
var rollback = position - 1;
|
|
552
|
-
var result = parseIdentifier();
|
|
553
|
-
|
|
554
|
-
if (result === undefined) {
|
|
555
|
-
position = rollback;
|
|
556
|
-
return tokenEnd(undefined);
|
|
557
|
-
} else {
|
|
558
|
-
return tokenEnd(result, 'key');
|
|
559
|
-
}
|
|
560
|
-
} else {
|
|
561
|
-
position--;
|
|
562
|
-
return tokenEnd(undefined);
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
function skipWhiteSpace() {
|
|
568
|
-
tokenStart();
|
|
569
|
-
|
|
570
|
-
while (position < length) {
|
|
571
|
-
var chr = input[position++];
|
|
572
|
-
|
|
573
|
-
if (isLineTerminator(chr)) {
|
|
574
|
-
position--;
|
|
575
|
-
tokenEnd(undefined, 'whitespace');
|
|
576
|
-
tokenStart();
|
|
577
|
-
position++;
|
|
578
|
-
newline(chr);
|
|
579
|
-
tokenEnd(undefined, 'newline');
|
|
580
|
-
tokenStart();
|
|
581
|
-
} else if (isWhiteSpace(chr)) {// nothing
|
|
582
|
-
} else if (chr === '/' && json5 && (input[position] === '/' || input[position] === '*')) {
|
|
583
|
-
position--;
|
|
584
|
-
tokenEnd(undefined, 'whitespace');
|
|
585
|
-
tokenStart();
|
|
586
|
-
position++;
|
|
587
|
-
skipComment(input[position++] === '*');
|
|
588
|
-
tokenEnd(undefined, 'comment');
|
|
589
|
-
tokenStart();
|
|
590
|
-
} else {
|
|
591
|
-
position--;
|
|
592
|
-
break;
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
return tokenEnd(undefined, 'whitespace');
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
function skipComment(multi) {
|
|
600
|
-
while (position < length) {
|
|
601
|
-
var chr = input[position++];
|
|
602
|
-
|
|
603
|
-
if (isLineTerminator(chr)) {
|
|
604
|
-
// LineTerminator is an end of singleline comment
|
|
605
|
-
if (!multi) {
|
|
606
|
-
// let parent function deal with newline
|
|
607
|
-
position--;
|
|
608
|
-
return;
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
newline(chr);
|
|
612
|
-
} else if (chr === '*' && multi) {
|
|
613
|
-
// end of multiline comment
|
|
614
|
-
if (input[position] === '/') {
|
|
615
|
-
position++;
|
|
616
|
-
return;
|
|
617
|
-
}
|
|
618
|
-
} else {// nothing
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
if (multi) {
|
|
623
|
-
fail('Unclosed multiline comment');
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
function parseKeyword(keyword) {
|
|
628
|
-
// keyword[0] is not checked because it should've checked earlier
|
|
629
|
-
var _pos = position;
|
|
630
|
-
var len = keyword.length;
|
|
631
|
-
|
|
632
|
-
for (var i = 1; i < len; i++) {
|
|
633
|
-
if (position >= length || keyword[i] != input[position]) {
|
|
634
|
-
position = _pos - 1;
|
|
635
|
-
fail();
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
position++;
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
function parseObject() {
|
|
643
|
-
var result = options.null_prototype ? Object.create(null) : {},
|
|
644
|
-
empty_object = {},
|
|
645
|
-
is_non_empty = false;
|
|
646
|
-
|
|
647
|
-
while (position < length) {
|
|
648
|
-
skipWhiteSpace();
|
|
649
|
-
var item1 = parseKey();
|
|
650
|
-
skipWhiteSpace();
|
|
651
|
-
tokenStart();
|
|
652
|
-
var chr = input[position++];
|
|
653
|
-
tokenEnd(undefined, 'separator');
|
|
654
|
-
|
|
655
|
-
if (chr === '}' && item1 === undefined) {
|
|
656
|
-
if (!json5 && is_non_empty) {
|
|
657
|
-
position--;
|
|
658
|
-
fail('Trailing comma in object');
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
return result;
|
|
662
|
-
} else if (chr === ':' && item1 !== undefined) {
|
|
663
|
-
skipWhiteSpace();
|
|
664
|
-
stack.push(item1);
|
|
665
|
-
var item2 = parseGeneric();
|
|
666
|
-
stack.pop();
|
|
667
|
-
if (item2 === undefined) fail('No value found for key ' + item1);
|
|
668
|
-
|
|
669
|
-
if (typeof item1 !== 'string') {
|
|
670
|
-
if (!json5 || typeof item1 !== 'number') {
|
|
671
|
-
fail('Wrong key type: ' + item1);
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
if ((item1 in empty_object || empty_object[item1] != null) && options.reserved_keys !== 'replace') {
|
|
676
|
-
if (options.reserved_keys === 'throw') {
|
|
677
|
-
fail('Reserved key: ' + item1);
|
|
678
|
-
} else {// silently ignore it
|
|
679
|
-
}
|
|
680
|
-
} else {
|
|
681
|
-
if (typeof options.reviver === 'function') {
|
|
682
|
-
item2 = options.reviver.call(null, item1, item2);
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
if (item2 !== undefined) {
|
|
686
|
-
is_non_empty = true;
|
|
687
|
-
Object.defineProperty(result, item1, {
|
|
688
|
-
value: item2,
|
|
689
|
-
enumerable: true,
|
|
690
|
-
configurable: true,
|
|
691
|
-
writable: true
|
|
692
|
-
});
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
skipWhiteSpace();
|
|
697
|
-
tokenStart();
|
|
698
|
-
var chr = input[position++];
|
|
699
|
-
tokenEnd(undefined, 'separator');
|
|
700
|
-
|
|
701
|
-
if (chr === ',') {
|
|
702
|
-
continue;
|
|
703
|
-
} else if (chr === '}') {
|
|
704
|
-
return result;
|
|
705
|
-
} else {
|
|
706
|
-
fail();
|
|
707
|
-
}
|
|
708
|
-
} else {
|
|
709
|
-
position--;
|
|
710
|
-
fail();
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
|
|
714
|
-
fail();
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
function parseArray() {
|
|
718
|
-
var result = [];
|
|
719
|
-
|
|
720
|
-
while (position < length) {
|
|
721
|
-
skipWhiteSpace();
|
|
722
|
-
stack.push(result.length);
|
|
723
|
-
var item = parseGeneric();
|
|
724
|
-
stack.pop();
|
|
725
|
-
skipWhiteSpace();
|
|
726
|
-
tokenStart();
|
|
727
|
-
var chr = input[position++];
|
|
728
|
-
tokenEnd(undefined, 'separator');
|
|
729
|
-
|
|
730
|
-
if (item !== undefined) {
|
|
731
|
-
if (typeof options.reviver === 'function') {
|
|
732
|
-
item = options.reviver.call(null, String(result.length), item);
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
if (item === undefined) {
|
|
736
|
-
result.length++;
|
|
737
|
-
item = true; // hack for check below, not included into result
|
|
738
|
-
} else {
|
|
739
|
-
result.push(item);
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
|
|
743
|
-
if (chr === ',') {
|
|
744
|
-
if (item === undefined) {
|
|
745
|
-
fail('Elisions are not supported');
|
|
746
|
-
}
|
|
747
|
-
} else if (chr === ']') {
|
|
748
|
-
if (!json5 && item === undefined && result.length) {
|
|
749
|
-
position--;
|
|
750
|
-
fail('Trailing comma in array');
|
|
751
|
-
}
|
|
752
|
-
|
|
753
|
-
return result;
|
|
754
|
-
} else {
|
|
755
|
-
position--;
|
|
756
|
-
fail();
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
|
|
761
|
-
function parseNumber() {
|
|
762
|
-
// rewind because we don't know first char
|
|
763
|
-
position--;
|
|
764
|
-
var start = position,
|
|
765
|
-
chr = input[position++],
|
|
766
|
-
t;
|
|
767
|
-
|
|
768
|
-
var to_num = function to_num(is_octal) {
|
|
769
|
-
var str = input.substr(start, position - start);
|
|
770
|
-
|
|
771
|
-
if (is_octal) {
|
|
772
|
-
var result = parseInt(str.replace(/^0o?/, ''), 8);
|
|
773
|
-
} else {
|
|
774
|
-
var result = Number(str);
|
|
775
|
-
}
|
|
776
|
-
|
|
777
|
-
if (Number.isNaN(result)) {
|
|
778
|
-
position--;
|
|
779
|
-
fail('Bad numeric literal - "' + input.substr(start, position - start + 1) + '"');
|
|
780
|
-
} else if (!json5 && !str.match(/^-?(0|[1-9][0-9]*)(\.[0-9]+)?(e[+-]?[0-9]+)?$/i)) {
|
|
781
|
-
// additional restrictions imposed by json
|
|
782
|
-
position--;
|
|
783
|
-
fail('Non-json numeric literal - "' + input.substr(start, position - start + 1) + '"');
|
|
784
|
-
} else {
|
|
785
|
-
return result;
|
|
786
|
-
}
|
|
787
|
-
}; // ex: -5982475.249875e+29384
|
|
788
|
-
// ^ skipping this
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
if (chr === '-' || chr === '+' && json5) chr = input[position++];
|
|
792
|
-
|
|
793
|
-
if (chr === 'N' && json5) {
|
|
794
|
-
parseKeyword('NaN');
|
|
795
|
-
return NaN;
|
|
796
|
-
}
|
|
797
|
-
|
|
798
|
-
if (chr === 'I' && json5) {
|
|
799
|
-
parseKeyword('Infinity'); // returning +inf or -inf
|
|
800
|
-
|
|
801
|
-
return to_num();
|
|
802
|
-
}
|
|
803
|
-
|
|
804
|
-
if (chr >= '1' && chr <= '9') {
|
|
805
|
-
// ex: -5982475.249875e+29384
|
|
806
|
-
// ^^^ skipping these
|
|
807
|
-
while (position < length && isDecDigit(input[position])) {
|
|
808
|
-
position++;
|
|
809
|
-
}
|
|
810
|
-
|
|
811
|
-
chr = input[position++];
|
|
812
|
-
} // special case for leading zero: 0.123456
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
if (chr === '0') {
|
|
816
|
-
chr = input[position++]; // new syntax, "0o777" old syntax, "0777"
|
|
817
|
-
|
|
818
|
-
var is_octal = chr === 'o' || chr === 'O' || isOctDigit(chr);
|
|
819
|
-
var is_hex = chr === 'x' || chr === 'X';
|
|
820
|
-
|
|
821
|
-
if (json5 && (is_octal || is_hex)) {
|
|
822
|
-
while (position < length && (is_hex ? isHexDigit : isOctDigit)(input[position])) {
|
|
823
|
-
position++;
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
var sign = 1;
|
|
827
|
-
|
|
828
|
-
if (input[start] === '-') {
|
|
829
|
-
sign = -1;
|
|
830
|
-
start++;
|
|
831
|
-
} else if (input[start] === '+') {
|
|
832
|
-
start++;
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
return sign * to_num(is_octal);
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
|
|
839
|
-
if (chr === '.') {
|
|
840
|
-
// ex: -5982475.249875e+29384
|
|
841
|
-
// ^^^ skipping these
|
|
842
|
-
while (position < length && isDecDigit(input[position])) {
|
|
843
|
-
position++;
|
|
844
|
-
}
|
|
845
|
-
|
|
846
|
-
chr = input[position++];
|
|
847
|
-
}
|
|
848
|
-
|
|
849
|
-
if (chr === 'e' || chr === 'E') {
|
|
850
|
-
chr = input[position++];
|
|
851
|
-
if (chr === '-' || chr === '+') position++; // ex: -5982475.249875e+29384
|
|
852
|
-
// ^^^ skipping these
|
|
853
|
-
|
|
854
|
-
while (position < length && isDecDigit(input[position])) {
|
|
855
|
-
position++;
|
|
856
|
-
}
|
|
857
|
-
|
|
858
|
-
chr = input[position++];
|
|
859
|
-
} // we have char in the buffer, so count for it
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
position--;
|
|
863
|
-
return to_num();
|
|
864
|
-
}
|
|
865
|
-
|
|
866
|
-
function parseIdentifier() {
|
|
867
|
-
// rewind because we don't know first char
|
|
868
|
-
position--;
|
|
869
|
-
var result = '';
|
|
870
|
-
|
|
871
|
-
while (position < length) {
|
|
872
|
-
var chr = input[position++];
|
|
873
|
-
|
|
874
|
-
if (chr === '\\' && input[position] === 'u' && isHexDigit(input[position + 1]) && isHexDigit(input[position + 2]) && isHexDigit(input[position + 3]) && isHexDigit(input[position + 4])) {
|
|
875
|
-
// UnicodeEscapeSequence
|
|
876
|
-
chr = String.fromCharCode(parseInt(input.substr(position + 1, 4), 16));
|
|
877
|
-
position += 5;
|
|
878
|
-
}
|
|
879
|
-
|
|
880
|
-
if (result.length) {
|
|
881
|
-
// identifier started
|
|
882
|
-
if (unicode.isIdentifierPart(chr)) {
|
|
883
|
-
result += chr;
|
|
884
|
-
} else {
|
|
885
|
-
position--;
|
|
886
|
-
return result;
|
|
887
|
-
}
|
|
888
|
-
} else {
|
|
889
|
-
if (unicode.isIdentifierStart(chr)) {
|
|
890
|
-
result += chr;
|
|
891
|
-
} else {
|
|
892
|
-
return undefined;
|
|
893
|
-
}
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
|
|
897
|
-
fail();
|
|
898
|
-
}
|
|
293
|
+
var jsonParseBetterErrors = parseJson$2;
|
|
899
294
|
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
var result = '';
|
|
295
|
+
function parseJson$2(txt, reviver, context) {
|
|
296
|
+
context = context || 20;
|
|
903
297
|
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
chr = input[position++];
|
|
912
|
-
|
|
913
|
-
if (unescapeMap[chr] && (json5 || chr != 'v' && chr != "'")) {
|
|
914
|
-
result += unescapeMap[chr];
|
|
915
|
-
} else if (json5 && isLineTerminator(chr)) {
|
|
916
|
-
// line continuation
|
|
917
|
-
newline(chr);
|
|
918
|
-
} else if (chr === 'u' || chr === 'x' && json5) {
|
|
919
|
-
// unicode/character escape sequence
|
|
920
|
-
var off = chr === 'u' ? 4 : 2; // validation for \uXXXX
|
|
921
|
-
|
|
922
|
-
for (var i = 0; i < off; i++) {
|
|
923
|
-
if (position >= length) fail();
|
|
924
|
-
if (!isHexDigit(input[position])) fail('Bad escape sequence');
|
|
925
|
-
position++;
|
|
926
|
-
}
|
|
927
|
-
|
|
928
|
-
result += String.fromCharCode(parseInt(input.substr(position - off, off), 16));
|
|
929
|
-
} else if (json5 && isOctDigit(chr)) {
|
|
930
|
-
if (chr < '4' && isOctDigit(input[position]) && isOctDigit(input[position + 1])) {
|
|
931
|
-
// three-digit octal
|
|
932
|
-
var digits = 3;
|
|
933
|
-
} else if (isOctDigit(input[position])) {
|
|
934
|
-
// two-digit octal
|
|
935
|
-
var digits = 2;
|
|
936
|
-
} else {
|
|
937
|
-
var digits = 1;
|
|
938
|
-
}
|
|
939
|
-
|
|
940
|
-
position += digits - 1;
|
|
941
|
-
result += String.fromCharCode(parseInt(input.substr(position - digits, digits), 8));
|
|
942
|
-
/*if (!isOctDigit(input[position])) {
|
|
943
|
-
// \0 is allowed still
|
|
944
|
-
result += '\0'
|
|
945
|
-
} else {
|
|
946
|
-
fail('Octal literals are not supported')
|
|
947
|
-
}*/
|
|
948
|
-
} else if (json5) {
|
|
949
|
-
// \X -> x
|
|
950
|
-
result += chr;
|
|
951
|
-
} else {
|
|
952
|
-
position--;
|
|
953
|
-
fail();
|
|
954
|
-
}
|
|
955
|
-
} else if (isLineTerminator(chr)) {
|
|
956
|
-
fail();
|
|
957
|
-
} else {
|
|
958
|
-
if (!json5 && chr.charCodeAt(0) < 32) {
|
|
959
|
-
position--;
|
|
960
|
-
fail('Unexpected control character');
|
|
961
|
-
} // SourceCharacter but not one of " or \ or LineTerminator
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
result += chr;
|
|
965
|
-
}
|
|
966
|
-
}
|
|
967
|
-
|
|
968
|
-
fail();
|
|
298
|
+
try {
|
|
299
|
+
return JSON.parse(txt, reviver);
|
|
300
|
+
} catch (e) {
|
|
301
|
+
if (typeof txt !== 'string') {
|
|
302
|
+
var isEmptyArray = Array.isArray(txt) && txt.length === 0;
|
|
303
|
+
var errorMessage = 'Cannot parse ' + (isEmptyArray ? 'an empty array' : String(txt));
|
|
304
|
+
throw new TypeError(errorMessage);
|
|
969
305
|
}
|
|
970
306
|
|
|
971
|
-
|
|
972
|
-
var
|
|
973
|
-
|
|
974
|
-
if (return_value !== undefined || position < length) {
|
|
975
|
-
skipWhiteSpace();
|
|
307
|
+
var syntaxErr = e.message.match(/^Unexpected token.*position\s+(\d+)/i);
|
|
308
|
+
var errIdx = syntaxErr ? +syntaxErr[1] : e.message.match(/^Unexpected end of JSON.*/i) ? txt.length - 1 : null;
|
|
976
309
|
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
return return_value;
|
|
983
|
-
} else {
|
|
984
|
-
fail();
|
|
985
|
-
}
|
|
310
|
+
if (errIdx != null) {
|
|
311
|
+
var start = errIdx <= context ? 0 : errIdx - context;
|
|
312
|
+
var end = errIdx + context >= txt.length ? txt.length : errIdx + context;
|
|
313
|
+
e.message += ` while parsing near '${start === 0 ? '' : '...'}${txt.slice(start, end)}${end === txt.length ? '' : '...'}'`;
|
|
986
314
|
} else {
|
|
987
|
-
|
|
988
|
-
fail('No data, only a whitespace');
|
|
989
|
-
} else {
|
|
990
|
-
fail('No data, empty input');
|
|
991
|
-
}
|
|
992
|
-
}
|
|
993
|
-
}
|
|
994
|
-
/*
|
|
995
|
-
* parse(text, options)
|
|
996
|
-
* or
|
|
997
|
-
* parse(text, reviver)
|
|
998
|
-
*
|
|
999
|
-
* where:
|
|
1000
|
-
* text - string
|
|
1001
|
-
* options - object
|
|
1002
|
-
* reviver - function
|
|
1003
|
-
*/
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
module.exports.parse = function parseJSON(input, options) {
|
|
1007
|
-
// support legacy functions
|
|
1008
|
-
if (typeof options === 'function') {
|
|
1009
|
-
options = {
|
|
1010
|
-
reviver: options
|
|
1011
|
-
};
|
|
1012
|
-
}
|
|
1013
|
-
|
|
1014
|
-
if (input === undefined) {
|
|
1015
|
-
// parse(stringify(x)) should be equal x
|
|
1016
|
-
// with JSON functions it is not 'cause of undefined
|
|
1017
|
-
// so we're fixing it
|
|
1018
|
-
return undefined;
|
|
1019
|
-
} // JSON.parse compat
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
if (typeof input !== 'string') input = String(input);
|
|
1023
|
-
if (options == null) options = {};
|
|
1024
|
-
if (options.reserved_keys == null) options.reserved_keys = 'ignore';
|
|
1025
|
-
|
|
1026
|
-
if (options.reserved_keys === 'throw' || options.reserved_keys === 'ignore') {
|
|
1027
|
-
if (options.null_prototype == null) {
|
|
1028
|
-
options.null_prototype = true;
|
|
1029
|
-
}
|
|
315
|
+
e.message += ` while parsing '${txt.slice(0, context * 2)}'`;
|
|
1030
316
|
}
|
|
1031
317
|
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
// jju is a recursive parser, so JSON.parse("{{{{{{{") could blow up the stack
|
|
1036
|
-
//
|
|
1037
|
-
// this catch is used to skip all those internal calls
|
|
1038
|
-
if (err instanceof SyntaxError && err.row != null && err.column != null) {
|
|
1039
|
-
var old_err = err;
|
|
1040
|
-
err = SyntaxError(old_err.message);
|
|
1041
|
-
err.column = old_err.column;
|
|
1042
|
-
err.row = old_err.row;
|
|
1043
|
-
}
|
|
1044
|
-
|
|
1045
|
-
throw err;
|
|
1046
|
-
}
|
|
1047
|
-
};
|
|
1048
|
-
|
|
1049
|
-
module.exports.tokenize = function tokenizeJSON(input, options) {
|
|
1050
|
-
if (options == null) options = {};
|
|
1051
|
-
|
|
1052
|
-
options._tokenize = function (smth) {
|
|
1053
|
-
if (options._addstack) smth.stack.unshift.apply(smth.stack, options._addstack);
|
|
1054
|
-
tokens.push(smth);
|
|
1055
|
-
};
|
|
1056
|
-
|
|
1057
|
-
var tokens = [];
|
|
1058
|
-
tokens.data = module.exports.parse(input, options);
|
|
1059
|
-
return tokens;
|
|
1060
|
-
};
|
|
1061
|
-
});
|
|
318
|
+
throw e;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
1062
321
|
|
|
1063
322
|
var parseJson = createCommonjsModule(function (module) {
|
|
1064
323
|
'use strict';
|
|
1065
324
|
|
|
1066
|
-
function appendPosition(message) {
|
|
1067
|
-
var posRe = / at (\d+:\d+) in/;
|
|
1068
|
-
var numbers = posRe.exec(message);
|
|
1069
|
-
return message.replace(posRe, ' in') + ':' + numbers[1];
|
|
1070
|
-
}
|
|
1071
|
-
|
|
1072
325
|
var JSONError = errorEx_1('JSONError', {
|
|
1073
|
-
fileName: errorEx_1.append('in %s')
|
|
1074
|
-
appendPosition: {
|
|
1075
|
-
message: function message(shouldAppend, original) {
|
|
1076
|
-
if (shouldAppend) {
|
|
1077
|
-
original[0] = appendPosition(original[0]);
|
|
1078
|
-
}
|
|
1079
|
-
|
|
1080
|
-
return original;
|
|
1081
|
-
}
|
|
1082
|
-
}
|
|
326
|
+
fileName: errorEx_1.append('in %s')
|
|
1083
327
|
});
|
|
1084
328
|
|
|
1085
329
|
module.exports = function (input, reviver, filename) {
|
|
@@ -1092,18 +336,15 @@ var parseJson = createCommonjsModule(function (module) {
|
|
|
1092
336
|
try {
|
|
1093
337
|
return JSON.parse(input, reviver);
|
|
1094
338
|
} catch (err) {
|
|
1095
|
-
|
|
1096
|
-
mode: 'json',
|
|
1097
|
-
reviver
|
|
1098
|
-
});
|
|
339
|
+
jsonParseBetterErrors(input, reviver);
|
|
1099
340
|
throw err;
|
|
1100
341
|
}
|
|
1101
342
|
} catch (err) {
|
|
343
|
+
err.message = err.message.replace(/\n/g, '');
|
|
1102
344
|
var jsonErr = new JSONError(err);
|
|
1103
345
|
|
|
1104
346
|
if (filename) {
|
|
1105
347
|
jsonErr.fileName = filename;
|
|
1106
|
-
jsonErr.appendPosition = true;
|
|
1107
348
|
}
|
|
1108
349
|
|
|
1109
350
|
throw jsonErr;
|
|
@@ -1111,32 +352,6 @@ var parseJson = createCommonjsModule(function (module) {
|
|
|
1111
352
|
};
|
|
1112
353
|
});
|
|
1113
354
|
|
|
1114
|
-
var parseJson_1 = function parseJsonWrapper(json, filepath) {
|
|
1115
|
-
try {
|
|
1116
|
-
return parseJson(json);
|
|
1117
|
-
} catch (err) {
|
|
1118
|
-
err.message = `JSON Error in ${filepath}:\n${err.message}`;
|
|
1119
|
-
throw err;
|
|
1120
|
-
}
|
|
1121
|
-
};
|
|
1122
|
-
|
|
1123
|
-
var loadPackageProp = function loadPackageProp(packageDir, options) {
|
|
1124
|
-
var packagePath = path.join(packageDir, 'package.json');
|
|
1125
|
-
|
|
1126
|
-
function parseContent(content) {
|
|
1127
|
-
if (!content) return null;
|
|
1128
|
-
var parsedContent = parseJson_1(content, packagePath);
|
|
1129
|
-
var packagePropValue = parsedContent[options.packageProp];
|
|
1130
|
-
if (!packagePropValue) return null;
|
|
1131
|
-
return {
|
|
1132
|
-
config: packagePropValue,
|
|
1133
|
-
filepath: packagePath
|
|
1134
|
-
};
|
|
1135
|
-
}
|
|
1136
|
-
|
|
1137
|
-
return !options.sync ? readFile_1(packagePath).then(parseContent) : parseContent(readFile_1.sync(packagePath));
|
|
1138
|
-
};
|
|
1139
|
-
|
|
1140
355
|
function isNothing(subject) {
|
|
1141
356
|
return typeof subject === 'undefined' || subject === null;
|
|
1142
357
|
}
|
|
@@ -2194,7 +1409,7 @@ function constructYamlSet(data) {
|
|
|
2194
1409
|
return data !== null ? data : {};
|
|
2195
1410
|
}
|
|
2196
1411
|
|
|
2197
|
-
var set = new type('tag:yaml.org,2002:set', {
|
|
1412
|
+
var set$1 = new type('tag:yaml.org,2002:set', {
|
|
2198
1413
|
kind: 'mapping',
|
|
2199
1414
|
resolve: resolveYamlSet,
|
|
2200
1415
|
construct: constructYamlSet
|
|
@@ -2203,7 +1418,7 @@ var set = new type('tag:yaml.org,2002:set', {
|
|
|
2203
1418
|
var default_safe = new schema({
|
|
2204
1419
|
include: [core],
|
|
2205
1420
|
implicit: [timestamp, merge],
|
|
2206
|
-
explicit: [binary, omap, pairs, set]
|
|
1421
|
+
explicit: [binary, omap, pairs, set$1]
|
|
2207
1422
|
});
|
|
2208
1423
|
|
|
2209
1424
|
function resolveJavascriptUndefined() {
|
|
@@ -3435,7 +2650,7 @@ function readBlockMapping(state, nodeIndent, flowIndent) {
|
|
|
3435
2650
|
atExplicitKey = false;
|
|
3436
2651
|
allowCompact = true;
|
|
3437
2652
|
} else {
|
|
3438
|
-
throwError(state, 'incomplete explicit mapping pair; a key node is missed');
|
|
2653
|
+
throwError(state, 'incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line');
|
|
3439
2654
|
}
|
|
3440
2655
|
|
|
3441
2656
|
state.position += 1;
|
|
@@ -4511,11 +3726,28 @@ function foldLine(line, width) {
|
|
|
4511
3726
|
|
|
4512
3727
|
function escapeString(string) {
|
|
4513
3728
|
var result = '';
|
|
4514
|
-
var char;
|
|
3729
|
+
var char, nextChar;
|
|
4515
3730
|
var escapeSeq;
|
|
4516
3731
|
|
|
4517
3732
|
for (var i = 0; i < string.length; i++) {
|
|
4518
|
-
char = string.charCodeAt(i);
|
|
3733
|
+
char = string.charCodeAt(i); // Check for surrogate pairs (reference Unicode 3.0 section "3.7 Surrogates").
|
|
3734
|
+
|
|
3735
|
+
if (char >= 0xD800 && char <= 0xDBFF
|
|
3736
|
+
/* high surrogate */
|
|
3737
|
+
) {
|
|
3738
|
+
nextChar = string.charCodeAt(i + 1);
|
|
3739
|
+
|
|
3740
|
+
if (nextChar >= 0xDC00 && nextChar <= 0xDFFF
|
|
3741
|
+
/* low surrogate */
|
|
3742
|
+
) {
|
|
3743
|
+
// Combine the surrogate pair and store it escaped.
|
|
3744
|
+
result += encodeHex((char - 0xD800) * 0x400 + nextChar - 0xDC00 + 0x10000); // Advance index one extra since we already used that char here.
|
|
3745
|
+
|
|
3746
|
+
i++;
|
|
3747
|
+
continue;
|
|
3748
|
+
}
|
|
3749
|
+
}
|
|
3750
|
+
|
|
4519
3751
|
escapeSeq = ESCAPE_SEQUENCES[char];
|
|
4520
3752
|
result += !escapeSeq && isPrintable(char) ? string[i] : escapeSeq || encodeHex(char);
|
|
4521
3753
|
}
|
|
@@ -4579,7 +3811,7 @@ function writeFlowMapping(state, level, object) {
|
|
|
4579
3811
|
pairBuffer;
|
|
4580
3812
|
|
|
4581
3813
|
for (index = 0, length = objectKeyList.length; index < length; index += 1) {
|
|
4582
|
-
pairBuffer = '';
|
|
3814
|
+
pairBuffer = state.condenseFlow ? '"' : '';
|
|
4583
3815
|
if (index !== 0) pairBuffer += ', ';
|
|
4584
3816
|
objectKey = objectKeyList[index];
|
|
4585
3817
|
objectValue = object[objectKey];
|
|
@@ -4589,7 +3821,7 @@ function writeFlowMapping(state, level, object) {
|
|
|
4589
3821
|
}
|
|
4590
3822
|
|
|
4591
3823
|
if (state.dump.length > 1024) pairBuffer += '? ';
|
|
4592
|
-
pairBuffer += state.dump + ':' + (state.condenseFlow ? '' : ' ');
|
|
3824
|
+
pairBuffer += state.dump + (state.condenseFlow ? '"' : '') + ':' + (state.condenseFlow ? '' : ' ');
|
|
4593
3825
|
|
|
4594
3826
|
if (!writeNode(state, level, objectValue, false, false)) {
|
|
4595
3827
|
continue; // Skip this pair because of invalid value.
|
|
@@ -4907,254 +4139,84 @@ var jsYaml$2 = {
|
|
|
4907
4139
|
|
|
4908
4140
|
var jsYaml = jsYaml$2;
|
|
4909
4141
|
|
|
4910
|
-
|
|
4911
|
-
|
|
4912
|
-
|
|
4913
|
-
module.exports = function requireFromString(code, filename, opts) {
|
|
4914
|
-
if (typeof filename === 'object') {
|
|
4915
|
-
opts = filename;
|
|
4916
|
-
filename = undefined;
|
|
4917
|
-
}
|
|
4918
|
-
|
|
4919
|
-
opts = opts || {};
|
|
4920
|
-
filename = filename || '';
|
|
4921
|
-
opts.appendPaths = opts.appendPaths || [];
|
|
4922
|
-
opts.prependPaths = opts.prependPaths || [];
|
|
4923
|
-
|
|
4924
|
-
if (typeof code !== 'string') {
|
|
4925
|
-
throw new Error('code must be a string, not ' + typeof code);
|
|
4926
|
-
}
|
|
4927
|
-
|
|
4928
|
-
var paths = module$1._nodeModulePaths(path.dirname(filename));
|
|
4929
|
-
|
|
4930
|
-
var parent = module.parent || module;
|
|
4931
|
-
var m = new module$1(filename, parent);
|
|
4932
|
-
m.filename = filename;
|
|
4933
|
-
m.paths = [].concat(opts.prependPaths).concat(paths).concat(opts.appendPaths);
|
|
4934
|
-
|
|
4935
|
-
m._compile(code, filename);
|
|
4936
|
-
|
|
4937
|
-
var exports = m.exports;
|
|
4938
|
-
parent.children && parent.children.splice(parent.children.indexOf(m), 1);
|
|
4939
|
-
return exports;
|
|
4940
|
-
};
|
|
4941
|
-
});
|
|
4942
|
-
|
|
4943
|
-
//
|
|
4944
|
-
var chainFuncsAsync = function chainFuncsAsync(result, func) {
|
|
4945
|
-
return result.then(func);
|
|
4946
|
-
};
|
|
4947
|
-
|
|
4948
|
-
var chainFuncsSync = function chainFuncsSync(result, func) {
|
|
4949
|
-
return func(result);
|
|
4950
|
-
};
|
|
4951
|
-
/**
|
|
4952
|
-
* Runs the given functions sequentially. If the `init` param is a promise,
|
|
4953
|
-
* functions are chained using `p.then()`. Otherwise, functions are chained by passing
|
|
4954
|
-
* the result of each function to the next.
|
|
4955
|
-
*/
|
|
4956
|
-
|
|
4957
|
-
|
|
4958
|
-
var funcRunner = function funcRunner(init, funcs) {
|
|
4959
|
-
var isAsync = init instanceof Promise;
|
|
4960
|
-
return funcs.reduce(isAsync === true ? chainFuncsAsync : chainFuncsSync, init);
|
|
4961
|
-
};
|
|
4962
|
-
|
|
4963
|
-
var loadRc = function loadRc(filepath, options) {
|
|
4964
|
-
if (!options.sync) {
|
|
4965
|
-
return readFile_1(filepath).then(parseExtensionlessRcFile).then(checkExtensionlessRcResult);
|
|
4966
|
-
} else {
|
|
4967
|
-
return checkExtensionlessRcResult(parseExtensionlessRcFile(readFile_1.sync(filepath)));
|
|
4968
|
-
}
|
|
4969
|
-
|
|
4970
|
-
function checkExtensionlessRcResult(result) {
|
|
4971
|
-
if (result) return result;
|
|
4972
|
-
if (options.rcExtensions) return loadRcWithExtensions();
|
|
4973
|
-
return null;
|
|
4974
|
-
}
|
|
4975
|
-
|
|
4976
|
-
function parseExtensionlessRcFile(content) {
|
|
4977
|
-
if (!content) return null;
|
|
4978
|
-
var pasedConfig = options.rcStrictJson ? parseJson_1(content, filepath) : jsYaml.safeLoad(content, {
|
|
4979
|
-
filename: filepath
|
|
4980
|
-
});
|
|
4981
|
-
return {
|
|
4982
|
-
config: pasedConfig,
|
|
4983
|
-
filepath
|
|
4984
|
-
};
|
|
4985
|
-
}
|
|
4142
|
+
function loadJs(filepath) {
|
|
4143
|
+
var result = require(filepath);
|
|
4986
4144
|
|
|
4987
|
-
|
|
4988
|
-
|
|
4989
|
-
return funcRunner(readRcFile('json'), [function (jsonContent) {
|
|
4990
|
-
// Since this is the first try, config cannot have been found, so don't
|
|
4991
|
-
// check `if (foundConfig)`.
|
|
4992
|
-
if (jsonContent) {
|
|
4993
|
-
var successFilepath = `${filepath}.json`;
|
|
4994
|
-
foundConfig = {
|
|
4995
|
-
config: parseJson_1(jsonContent, successFilepath),
|
|
4996
|
-
filepath: successFilepath
|
|
4997
|
-
};
|
|
4998
|
-
} else {
|
|
4999
|
-
return readRcFile('yaml');
|
|
5000
|
-
}
|
|
5001
|
-
}, function (yamlContent) {
|
|
5002
|
-
if (foundConfig) {
|
|
5003
|
-
return;
|
|
5004
|
-
} else if (yamlContent) {
|
|
5005
|
-
var successFilepath = `${filepath}.yaml`;
|
|
5006
|
-
foundConfig = {
|
|
5007
|
-
config: jsYaml.safeLoad(yamlContent, {
|
|
5008
|
-
filename: successFilepath
|
|
5009
|
-
}),
|
|
5010
|
-
filepath: successFilepath
|
|
5011
|
-
};
|
|
5012
|
-
} else {
|
|
5013
|
-
return readRcFile('yml');
|
|
5014
|
-
}
|
|
5015
|
-
}, function (ymlContent) {
|
|
5016
|
-
if (foundConfig) {
|
|
5017
|
-
return;
|
|
5018
|
-
} else if (ymlContent) {
|
|
5019
|
-
var successFilepath = `${filepath}.yml`;
|
|
5020
|
-
foundConfig = {
|
|
5021
|
-
config: jsYaml.safeLoad(ymlContent, {
|
|
5022
|
-
filename: successFilepath
|
|
5023
|
-
}),
|
|
5024
|
-
filepath: successFilepath
|
|
5025
|
-
};
|
|
5026
|
-
} else {
|
|
5027
|
-
return readRcFile('js');
|
|
5028
|
-
}
|
|
5029
|
-
}, function (jsContent) {
|
|
5030
|
-
if (foundConfig) {
|
|
5031
|
-
return;
|
|
5032
|
-
} else if (jsContent) {
|
|
5033
|
-
var successFilepath = `${filepath}.js`;
|
|
5034
|
-
foundConfig = {
|
|
5035
|
-
config: requireFromString(jsContent, successFilepath),
|
|
5036
|
-
filepath: successFilepath
|
|
5037
|
-
};
|
|
5038
|
-
} else {
|
|
5039
|
-
return;
|
|
5040
|
-
}
|
|
5041
|
-
}, function () {
|
|
5042
|
-
return foundConfig;
|
|
5043
|
-
}]);
|
|
5044
|
-
}
|
|
4145
|
+
return result;
|
|
4146
|
+
}
|
|
5045
4147
|
|
|
5046
|
-
|
|
5047
|
-
|
|
5048
|
-
return
|
|
4148
|
+
function loadJson(filepath, content) {
|
|
4149
|
+
try {
|
|
4150
|
+
return parseJson(content);
|
|
4151
|
+
} catch (err) {
|
|
4152
|
+
err.message = `JSON Error in ${filepath}:\n${err.message}`;
|
|
4153
|
+
throw err;
|
|
5049
4154
|
}
|
|
5050
|
-
}
|
|
4155
|
+
}
|
|
5051
4156
|
|
|
5052
|
-
|
|
5053
|
-
|
|
5054
|
-
|
|
5055
|
-
|
|
5056
|
-
|
|
5057
|
-
filepath
|
|
5058
|
-
};
|
|
5059
|
-
}
|
|
4157
|
+
function loadYaml(filepath, content) {
|
|
4158
|
+
return jsYaml.safeLoad(content, {
|
|
4159
|
+
filename: filepath
|
|
4160
|
+
});
|
|
4161
|
+
}
|
|
5060
4162
|
|
|
5061
|
-
|
|
4163
|
+
var loaders = {
|
|
4164
|
+
loadJs,
|
|
4165
|
+
loadJson,
|
|
4166
|
+
loadYaml
|
|
5062
4167
|
};
|
|
5063
4168
|
|
|
5064
|
-
|
|
5065
|
-
|
|
5066
|
-
|
|
5067
|
-
|
|
5068
|
-
|
|
5069
|
-
|
|
5070
|
-
|
|
5071
|
-
|
|
5072
|
-
switch (options.format || inferFormat(filepath)) {
|
|
5073
|
-
case 'json':
|
|
5074
|
-
parsedConfig = parseJson_1(content, filepath);
|
|
5075
|
-
break;
|
|
5076
|
-
|
|
5077
|
-
case 'yaml':
|
|
5078
|
-
parsedConfig = jsYaml.safeLoad(content, {
|
|
5079
|
-
filename: filepath
|
|
5080
|
-
});
|
|
5081
|
-
break;
|
|
4169
|
+
function readFile(filepath, options) {
|
|
4170
|
+
options = options || {};
|
|
4171
|
+
var throwNotFound = options.throwNotFound || false;
|
|
4172
|
+
return new Promise(function (resolve, reject) {
|
|
4173
|
+
fs.readFile(filepath, 'utf8', function (err, content) {
|
|
4174
|
+
if (err && err.code === 'ENOENT' && !throwNotFound) {
|
|
4175
|
+
return resolve(null);
|
|
4176
|
+
}
|
|
5082
4177
|
|
|
5083
|
-
|
|
5084
|
-
|
|
5085
|
-
|
|
4178
|
+
if (err) return reject(err);
|
|
4179
|
+
resolve(content);
|
|
4180
|
+
});
|
|
4181
|
+
});
|
|
4182
|
+
}
|
|
5086
4183
|
|
|
5087
|
-
|
|
5088
|
-
|
|
5089
|
-
|
|
4184
|
+
readFile.sync = function readFileSync(filepath, options) {
|
|
4185
|
+
options = options || {};
|
|
4186
|
+
var throwNotFound = options.throwNotFound || false;
|
|
5090
4187
|
|
|
5091
|
-
|
|
5092
|
-
|
|
4188
|
+
try {
|
|
4189
|
+
return fs.readFileSync(filepath, 'utf8');
|
|
4190
|
+
} catch (err) {
|
|
4191
|
+
if (err.code === 'ENOENT' && !throwNotFound) {
|
|
4192
|
+
return null;
|
|
5093
4193
|
}
|
|
5094
4194
|
|
|
5095
|
-
|
|
5096
|
-
config: parsedConfig,
|
|
5097
|
-
filepath
|
|
5098
|
-
};
|
|
4195
|
+
throw err;
|
|
5099
4196
|
}
|
|
5100
|
-
|
|
5101
|
-
return !options.sync ? readFile_1(filepath, {
|
|
5102
|
-
throwNotFound: true
|
|
5103
|
-
}).then(parseContent) : parseContent(readFile_1.sync(filepath, {
|
|
5104
|
-
throwNotFound: true
|
|
5105
|
-
}));
|
|
5106
4197
|
};
|
|
5107
4198
|
|
|
5108
|
-
|
|
5109
|
-
switch (path.extname(filepath)) {
|
|
5110
|
-
case '.js':
|
|
5111
|
-
return 'js';
|
|
5112
|
-
|
|
5113
|
-
case '.json':
|
|
5114
|
-
return 'json';
|
|
5115
|
-
// istanbul ignore next
|
|
5116
|
-
|
|
5117
|
-
case '.yml':
|
|
5118
|
-
case '.yaml':
|
|
5119
|
-
return 'yaml';
|
|
4199
|
+
var readFile_1 = readFile;
|
|
5120
4200
|
|
|
5121
|
-
|
|
5122
|
-
|
|
4201
|
+
//
|
|
4202
|
+
function cacheWrapper(cache, key, fn) {
|
|
4203
|
+
if (!cache) {
|
|
4204
|
+
return fn();
|
|
5123
4205
|
}
|
|
5124
|
-
}
|
|
5125
4206
|
|
|
5126
|
-
|
|
5127
|
-
return tryYaml(content, filepath, function () {
|
|
5128
|
-
return tryRequire(content, filepath, function () {
|
|
5129
|
-
return null;
|
|
5130
|
-
});
|
|
5131
|
-
});
|
|
5132
|
-
}
|
|
5133
|
-
|
|
5134
|
-
function tryYaml(content, filepath, cb) {
|
|
5135
|
-
try {
|
|
5136
|
-
var result = jsYaml.safeLoad(content, {
|
|
5137
|
-
filename: filepath
|
|
5138
|
-
});
|
|
5139
|
-
|
|
5140
|
-
if (typeof result === 'string') {
|
|
5141
|
-
return cb();
|
|
5142
|
-
}
|
|
4207
|
+
var cached = cache.get(key);
|
|
5143
4208
|
|
|
5144
|
-
|
|
5145
|
-
|
|
5146
|
-
return cb();
|
|
4209
|
+
if (cached !== undefined) {
|
|
4210
|
+
return cached;
|
|
5147
4211
|
}
|
|
5148
|
-
}
|
|
5149
4212
|
|
|
5150
|
-
|
|
5151
|
-
|
|
5152
|
-
|
|
5153
|
-
} catch (e) {
|
|
5154
|
-
return cb();
|
|
5155
|
-
}
|
|
4213
|
+
var result = fn();
|
|
4214
|
+
cache.set(key, result);
|
|
4215
|
+
return result;
|
|
5156
4216
|
}
|
|
5157
4217
|
|
|
4218
|
+
var cacheWrapper_1 = cacheWrapper;
|
|
4219
|
+
|
|
5158
4220
|
/**
|
|
5159
4221
|
* async
|
|
5160
4222
|
*/
|
|
@@ -5214,11 +4276,7 @@ isDirectory.sync = function isDirectorySync(filepath) {
|
|
|
5214
4276
|
|
|
5215
4277
|
var isDirectory_1 = isDirectory;
|
|
5216
4278
|
|
|
5217
|
-
|
|
5218
|
-
if (sync === true) {
|
|
5219
|
-
return isDirectory_1.sync(filepath) ? filepath : path.dirname(filepath);
|
|
5220
|
-
}
|
|
5221
|
-
|
|
4279
|
+
function getDirectory(filepath) {
|
|
5222
4280
|
return new Promise(function (resolve, reject) {
|
|
5223
4281
|
return isDirectory_1(filepath, function (err, filepathIsDirectory) {
|
|
5224
4282
|
if (err) {
|
|
@@ -5228,143 +4286,459 @@ var getDirectory = function getDirectory(filepath, sync) {
|
|
|
5228
4286
|
return resolve(filepathIsDirectory ? filepath : path.dirname(filepath));
|
|
5229
4287
|
});
|
|
5230
4288
|
});
|
|
4289
|
+
}
|
|
4290
|
+
|
|
4291
|
+
getDirectory.sync = function getDirectorySync(filepath) {
|
|
4292
|
+
return isDirectory_1.sync(filepath) ? filepath : path.dirname(filepath);
|
|
5231
4293
|
};
|
|
5232
4294
|
|
|
5233
|
-
var
|
|
5234
|
-
// When `options.sync` is `false` (default),
|
|
5235
|
-
// these cache Promises that resolve with results, not the results themselves.
|
|
5236
|
-
var fileCache = options.cache ? new Map() : null;
|
|
5237
|
-
var directoryCache = options.cache ? new Map() : null;
|
|
5238
|
-
var transform = options.transform || identity;
|
|
5239
|
-
var packageProp = options.packageProp;
|
|
4295
|
+
var getDirectory_1 = getDirectory;
|
|
5240
4296
|
|
|
5241
|
-
|
|
5242
|
-
|
|
5243
|
-
|
|
4297
|
+
var MODE_SYNC = 'sync'; // An object value represents a config object.
|
|
4298
|
+
// null represents that the loader did not find anything relevant.
|
|
4299
|
+
// undefined represents that the loader found something relevant
|
|
4300
|
+
// but it was empty.
|
|
5244
4301
|
|
|
5245
|
-
|
|
5246
|
-
|
|
5247
|
-
|
|
4302
|
+
var Explorer =
|
|
4303
|
+
/*#__PURE__*/
|
|
4304
|
+
function () {
|
|
4305
|
+
function Explorer(options) {
|
|
4306
|
+
_classCallCheck(this, Explorer);
|
|
5248
4307
|
|
|
5249
|
-
|
|
5250
|
-
|
|
5251
|
-
|
|
4308
|
+
this.loadCache = options.cache ? new Map() : null;
|
|
4309
|
+
this.loadSyncCache = options.cache ? new Map() : null;
|
|
4310
|
+
this.searchCache = options.cache ? new Map() : null;
|
|
4311
|
+
this.searchSyncCache = options.cache ? new Map() : null;
|
|
4312
|
+
this.config = options;
|
|
4313
|
+
this.validateConfig();
|
|
5252
4314
|
}
|
|
5253
4315
|
|
|
5254
|
-
|
|
5255
|
-
|
|
5256
|
-
|
|
5257
|
-
|
|
5258
|
-
|
|
4316
|
+
_createClass(Explorer, [{
|
|
4317
|
+
key: "clearLoadCache",
|
|
4318
|
+
value: function clearLoadCache() {
|
|
4319
|
+
if (this.loadCache) {
|
|
4320
|
+
this.loadCache.clear();
|
|
4321
|
+
}
|
|
4322
|
+
|
|
4323
|
+
if (this.loadSyncCache) {
|
|
4324
|
+
this.loadSyncCache.clear();
|
|
4325
|
+
}
|
|
5259
4326
|
}
|
|
5260
|
-
}
|
|
4327
|
+
}, {
|
|
4328
|
+
key: "clearSearchCache",
|
|
4329
|
+
value: function clearSearchCache() {
|
|
4330
|
+
if (this.searchCache) {
|
|
4331
|
+
this.searchCache.clear();
|
|
4332
|
+
}
|
|
4333
|
+
|
|
4334
|
+
if (this.searchSyncCache) {
|
|
4335
|
+
this.searchSyncCache.clear();
|
|
4336
|
+
}
|
|
4337
|
+
}
|
|
4338
|
+
}, {
|
|
4339
|
+
key: "clearCaches",
|
|
4340
|
+
value: function clearCaches() {
|
|
4341
|
+
this.clearLoadCache();
|
|
4342
|
+
this.clearSearchCache();
|
|
4343
|
+
}
|
|
4344
|
+
}, {
|
|
4345
|
+
key: "validateConfig",
|
|
4346
|
+
value: function validateConfig() {
|
|
4347
|
+
var config = this.config;
|
|
4348
|
+
config.searchPlaces.forEach(function (place) {
|
|
4349
|
+
var loaderKey = path.extname(place) || 'noExt';
|
|
4350
|
+
var loader = config.loaders[loaderKey];
|
|
4351
|
+
|
|
4352
|
+
if (!loader) {
|
|
4353
|
+
throw new Error(`No loader specified for ${getExtensionDescription(place)}, so searchPlaces item "${place}" is invalid`);
|
|
4354
|
+
}
|
|
4355
|
+
});
|
|
4356
|
+
}
|
|
4357
|
+
}, {
|
|
4358
|
+
key: "search",
|
|
4359
|
+
value: function search(searchFrom) {
|
|
4360
|
+
var _this = this;
|
|
5261
4361
|
|
|
5262
|
-
|
|
5263
|
-
|
|
5264
|
-
|
|
4362
|
+
searchFrom = searchFrom || process.cwd();
|
|
4363
|
+
return getDirectory_1(searchFrom).then(function (dir) {
|
|
4364
|
+
return _this.searchFromDirectory(dir);
|
|
4365
|
+
});
|
|
5265
4366
|
}
|
|
4367
|
+
}, {
|
|
4368
|
+
key: "searchFromDirectory",
|
|
4369
|
+
value: function searchFromDirectory(dir) {
|
|
4370
|
+
var _this2 = this;
|
|
4371
|
+
|
|
4372
|
+
var absoluteDir = path.resolve(process.cwd(), dir);
|
|
4373
|
+
|
|
4374
|
+
var run = function run() {
|
|
4375
|
+
return _this2.searchDirectory(absoluteDir).then(function (result) {
|
|
4376
|
+
var nextDir = _this2.nextDirectoryToSearch(absoluteDir, result);
|
|
4377
|
+
|
|
4378
|
+
if (nextDir) {
|
|
4379
|
+
return _this2.searchFromDirectory(nextDir);
|
|
4380
|
+
}
|
|
5266
4381
|
|
|
5267
|
-
|
|
5268
|
-
|
|
4382
|
+
return _this2.config.transform(result);
|
|
4383
|
+
});
|
|
4384
|
+
};
|
|
5269
4385
|
|
|
5270
|
-
if (
|
|
5271
|
-
return
|
|
4386
|
+
if (this.searchCache) {
|
|
4387
|
+
return cacheWrapper_1(this.searchCache, absoluteDir, run);
|
|
5272
4388
|
}
|
|
5273
4389
|
|
|
5274
|
-
|
|
4390
|
+
return run();
|
|
4391
|
+
}
|
|
4392
|
+
}, {
|
|
4393
|
+
key: "searchSync",
|
|
4394
|
+
value: function searchSync(searchFrom) {
|
|
4395
|
+
searchFrom = searchFrom || process.cwd();
|
|
4396
|
+
var dir = getDirectory_1.sync(searchFrom);
|
|
4397
|
+
return this.searchFromDirectorySync(dir);
|
|
4398
|
+
}
|
|
4399
|
+
}, {
|
|
4400
|
+
key: "searchFromDirectorySync",
|
|
4401
|
+
value: function searchFromDirectorySync(dir) {
|
|
4402
|
+
var _this3 = this;
|
|
4403
|
+
|
|
4404
|
+
var absoluteDir = path.resolve(process.cwd(), dir);
|
|
4405
|
+
|
|
4406
|
+
var run = function run() {
|
|
4407
|
+
var result = _this3.searchDirectorySync(absoluteDir);
|
|
4408
|
+
|
|
4409
|
+
var nextDir = _this3.nextDirectoryToSearch(absoluteDir, result);
|
|
5275
4410
|
|
|
5276
|
-
|
|
5277
|
-
|
|
5278
|
-
return throwError(new Error('Please specify the packageProp option. The configPath argument cannot point to a package.json file if packageProp is false.'));
|
|
4411
|
+
if (nextDir) {
|
|
4412
|
+
return _this3.searchFromDirectorySync(nextDir);
|
|
5279
4413
|
}
|
|
5280
4414
|
|
|
5281
|
-
|
|
5282
|
-
|
|
5283
|
-
|
|
5284
|
-
|
|
5285
|
-
|
|
5286
|
-
};
|
|
5287
|
-
} else {
|
|
5288
|
-
_load = function _load() {
|
|
5289
|
-
return loadDefinedFile(absoluteConfigPath, {
|
|
5290
|
-
sync: options.sync,
|
|
5291
|
-
format: options.format
|
|
5292
|
-
});
|
|
5293
|
-
};
|
|
4415
|
+
return _this3.config.transform(result);
|
|
4416
|
+
};
|
|
4417
|
+
|
|
4418
|
+
if (this.searchSyncCache) {
|
|
4419
|
+
return cacheWrapper_1(this.searchSyncCache, absoluteDir, run);
|
|
5294
4420
|
}
|
|
5295
4421
|
|
|
5296
|
-
|
|
4422
|
+
return run();
|
|
4423
|
+
}
|
|
4424
|
+
}, {
|
|
4425
|
+
key: "searchDirectory",
|
|
4426
|
+
value: function searchDirectory(dir) {
|
|
4427
|
+
var _this4 = this;
|
|
4428
|
+
|
|
4429
|
+
return this.config.searchPlaces.reduce(function (prevResultPromise, place) {
|
|
4430
|
+
return prevResultPromise.then(function (prevResult) {
|
|
4431
|
+
if (_this4.shouldSearchStopWithResult(prevResult)) {
|
|
4432
|
+
return prevResult;
|
|
4433
|
+
}
|
|
4434
|
+
|
|
4435
|
+
return _this4.loadSearchPlace(dir, place);
|
|
4436
|
+
});
|
|
4437
|
+
}, Promise.resolve(null));
|
|
4438
|
+
}
|
|
4439
|
+
}, {
|
|
4440
|
+
key: "searchDirectorySync",
|
|
4441
|
+
value: function searchDirectorySync(dir) {
|
|
4442
|
+
var result = null;
|
|
4443
|
+
var _iteratorNormalCompletion = true;
|
|
4444
|
+
var _didIteratorError = false;
|
|
4445
|
+
var _iteratorError = undefined;
|
|
4446
|
+
|
|
4447
|
+
try {
|
|
4448
|
+
for (var _iterator = this.config.searchPlaces[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
4449
|
+
var place = _step.value;
|
|
4450
|
+
result = this.loadSearchPlaceSync(dir, place);
|
|
4451
|
+
if (this.shouldSearchStopWithResult(result)) break;
|
|
4452
|
+
}
|
|
4453
|
+
} catch (err) {
|
|
4454
|
+
_didIteratorError = true;
|
|
4455
|
+
_iteratorError = err;
|
|
4456
|
+
} finally {
|
|
4457
|
+
try {
|
|
4458
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
4459
|
+
_iterator.return();
|
|
4460
|
+
}
|
|
4461
|
+
} finally {
|
|
4462
|
+
if (_didIteratorError) {
|
|
4463
|
+
throw _iteratorError;
|
|
4464
|
+
}
|
|
4465
|
+
}
|
|
4466
|
+
}
|
|
5297
4467
|
|
|
5298
|
-
var result = loadResult instanceof Promise ? loadResult.then(transform) : transform(loadResult);
|
|
5299
|
-
if (fileCache) fileCache.set(absoluteConfigPath, result);
|
|
5300
4468
|
return result;
|
|
5301
4469
|
}
|
|
4470
|
+
}, {
|
|
4471
|
+
key: "shouldSearchStopWithResult",
|
|
4472
|
+
value: function shouldSearchStopWithResult(result) {
|
|
4473
|
+
if (result === null) return false;
|
|
4474
|
+
if (result.isEmpty && this.config.ignoreEmptySearchPlaces) return false;
|
|
4475
|
+
return true;
|
|
4476
|
+
}
|
|
4477
|
+
}, {
|
|
4478
|
+
key: "loadSearchPlace",
|
|
4479
|
+
value: function loadSearchPlace(dir, place) {
|
|
4480
|
+
var _this5 = this;
|
|
5302
4481
|
|
|
5303
|
-
|
|
5304
|
-
|
|
5305
|
-
|
|
5306
|
-
|
|
5307
|
-
|
|
4482
|
+
var filepath = path.join(dir, place);
|
|
4483
|
+
return readFile_1(filepath).then(function (content) {
|
|
4484
|
+
return _this5.createCosmiconfigResult(filepath, content);
|
|
4485
|
+
});
|
|
4486
|
+
}
|
|
4487
|
+
}, {
|
|
4488
|
+
key: "loadSearchPlaceSync",
|
|
4489
|
+
value: function loadSearchPlaceSync(dir, place) {
|
|
4490
|
+
var filepath = path.join(dir, place);
|
|
4491
|
+
var content = readFile_1.sync(filepath);
|
|
4492
|
+
return this.createCosmiconfigResultSync(filepath, content);
|
|
4493
|
+
}
|
|
4494
|
+
}, {
|
|
4495
|
+
key: "nextDirectoryToSearch",
|
|
4496
|
+
value: function nextDirectoryToSearch(currentDir, currentResult) {
|
|
4497
|
+
if (this.shouldSearchStopWithResult(currentResult)) {
|
|
4498
|
+
return null;
|
|
4499
|
+
}
|
|
4500
|
+
|
|
4501
|
+
var nextDir = nextDirUp(currentDir);
|
|
4502
|
+
|
|
4503
|
+
if (nextDir === currentDir || currentDir === this.config.stopDir) {
|
|
4504
|
+
return null;
|
|
4505
|
+
}
|
|
4506
|
+
|
|
4507
|
+
return nextDir;
|
|
4508
|
+
}
|
|
4509
|
+
}, {
|
|
4510
|
+
key: "loadPackageProp",
|
|
4511
|
+
value: function loadPackageProp(filepath, content) {
|
|
4512
|
+
var parsedContent = loaders.loadJson(filepath, content);
|
|
4513
|
+
var packagePropValue = parsedContent[this.config.packageProp];
|
|
4514
|
+
return packagePropValue || null;
|
|
4515
|
+
}
|
|
4516
|
+
}, {
|
|
4517
|
+
key: "getLoaderEntryForFile",
|
|
4518
|
+
value: function getLoaderEntryForFile(filepath) {
|
|
4519
|
+
if (path.basename(filepath) === 'package.json') {
|
|
4520
|
+
var loader = this.loadPackageProp.bind(this);
|
|
4521
|
+
return {
|
|
4522
|
+
sync: loader,
|
|
4523
|
+
async: loader
|
|
4524
|
+
};
|
|
4525
|
+
}
|
|
4526
|
+
|
|
4527
|
+
var loaderKey = path.extname(filepath) || 'noExt';
|
|
4528
|
+
return this.config.loaders[loaderKey];
|
|
4529
|
+
}
|
|
4530
|
+
}, {
|
|
4531
|
+
key: "getSyncLoaderForFile",
|
|
4532
|
+
value: function getSyncLoaderForFile(filepath) {
|
|
4533
|
+
var entry = this.getLoaderEntryForFile(filepath);
|
|
4534
|
+
|
|
4535
|
+
if (!entry.sync) {
|
|
4536
|
+
throw new Error(`No sync loader specified for ${getExtensionDescription(filepath)}`);
|
|
4537
|
+
}
|
|
4538
|
+
|
|
4539
|
+
return entry.sync;
|
|
4540
|
+
}
|
|
4541
|
+
}, {
|
|
4542
|
+
key: "getAsyncLoaderForFile",
|
|
4543
|
+
value: function getAsyncLoaderForFile(filepath) {
|
|
4544
|
+
var entry = this.getLoaderEntryForFile(filepath);
|
|
4545
|
+
var loader = entry.async || entry.sync;
|
|
4546
|
+
|
|
4547
|
+
if (!loader) {
|
|
4548
|
+
throw new Error(`No async loader specified for ${getExtensionDescription(filepath)}`);
|
|
4549
|
+
}
|
|
4550
|
+
|
|
4551
|
+
return loader;
|
|
4552
|
+
}
|
|
4553
|
+
}, {
|
|
4554
|
+
key: "loadFileContent",
|
|
4555
|
+
value: function loadFileContent(mode, filepath, content) {
|
|
4556
|
+
if (content === null) {
|
|
4557
|
+
return null;
|
|
4558
|
+
}
|
|
4559
|
+
|
|
4560
|
+
if (content.trim() === '') {
|
|
4561
|
+
return undefined;
|
|
4562
|
+
}
|
|
4563
|
+
|
|
4564
|
+
var loader = mode === MODE_SYNC ? this.getSyncLoaderForFile(filepath) : this.getAsyncLoaderForFile(filepath);
|
|
4565
|
+
return loader(filepath, content);
|
|
4566
|
+
}
|
|
4567
|
+
}, {
|
|
4568
|
+
key: "loadedContentToCosmiconfigResult",
|
|
4569
|
+
value: function loadedContentToCosmiconfigResult(filepath, loadedContent) {
|
|
4570
|
+
if (loadedContent === null) {
|
|
4571
|
+
return null;
|
|
4572
|
+
}
|
|
4573
|
+
|
|
4574
|
+
if (loadedContent === undefined) {
|
|
4575
|
+
return {
|
|
4576
|
+
filepath,
|
|
4577
|
+
config: undefined,
|
|
4578
|
+
isEmpty: true
|
|
4579
|
+
};
|
|
4580
|
+
}
|
|
5308
4581
|
|
|
5309
|
-
|
|
5310
|
-
|
|
5311
|
-
|
|
4582
|
+
return {
|
|
4583
|
+
config: loadedContent,
|
|
4584
|
+
filepath
|
|
4585
|
+
};
|
|
5312
4586
|
}
|
|
4587
|
+
}, {
|
|
4588
|
+
key: "createCosmiconfigResult",
|
|
4589
|
+
value: function createCosmiconfigResult(filepath, content) {
|
|
4590
|
+
var _this6 = this;
|
|
5313
4591
|
|
|
5314
|
-
|
|
5315
|
-
|
|
5316
|
-
|
|
5317
|
-
|
|
5318
|
-
sync: options.sync
|
|
4592
|
+
return Promise.resolve().then(function () {
|
|
4593
|
+
return _this6.loadFileContent('async', filepath, content);
|
|
4594
|
+
}).then(function (loaderResult) {
|
|
4595
|
+
return _this6.loadedContentToCosmiconfigResult(filepath, loaderResult);
|
|
5319
4596
|
});
|
|
5320
|
-
}
|
|
5321
|
-
|
|
5322
|
-
|
|
5323
|
-
|
|
5324
|
-
|
|
5325
|
-
|
|
4597
|
+
}
|
|
4598
|
+
}, {
|
|
4599
|
+
key: "createCosmiconfigResultSync",
|
|
4600
|
+
value: function createCosmiconfigResultSync(filepath, content) {
|
|
4601
|
+
var loaderResult = this.loadFileContent('sync', filepath, content);
|
|
4602
|
+
return this.loadedContentToCosmiconfigResult(filepath, loaderResult);
|
|
4603
|
+
}
|
|
4604
|
+
}, {
|
|
4605
|
+
key: "validateFilePath",
|
|
4606
|
+
value: function validateFilePath(filepath) {
|
|
4607
|
+
if (!filepath) {
|
|
4608
|
+
throw new Error('load and loadSync must pass a non-empty string');
|
|
4609
|
+
}
|
|
4610
|
+
}
|
|
4611
|
+
}, {
|
|
4612
|
+
key: "load",
|
|
4613
|
+
value: function load(filepath) {
|
|
4614
|
+
var _this7 = this;
|
|
4615
|
+
|
|
4616
|
+
return Promise.resolve().then(function () {
|
|
4617
|
+
_this7.validateFilePath(filepath);
|
|
4618
|
+
|
|
4619
|
+
var absoluteFilePath = path.resolve(process.cwd(), filepath);
|
|
4620
|
+
return cacheWrapper_1(_this7.loadCache, absoluteFilePath, function () {
|
|
4621
|
+
return readFile_1(absoluteFilePath, {
|
|
4622
|
+
throwNotFound: true
|
|
4623
|
+
}).then(function (content) {
|
|
4624
|
+
return _this7.createCosmiconfigResult(absoluteFilePath, content);
|
|
4625
|
+
}).then(_this7.config.transform);
|
|
4626
|
+
});
|
|
5326
4627
|
});
|
|
5327
|
-
}
|
|
5328
|
-
|
|
5329
|
-
|
|
5330
|
-
|
|
4628
|
+
}
|
|
4629
|
+
}, {
|
|
4630
|
+
key: "loadSync",
|
|
4631
|
+
value: function loadSync(filepath) {
|
|
4632
|
+
var _this8 = this;
|
|
4633
|
+
|
|
4634
|
+
this.validateFilePath(filepath);
|
|
4635
|
+
var absoluteFilePath = path.resolve(process.cwd(), filepath);
|
|
4636
|
+
return cacheWrapper_1(this.loadSyncCache, absoluteFilePath, function () {
|
|
4637
|
+
var content = readFile_1.sync(absoluteFilePath, {
|
|
4638
|
+
throwNotFound: true
|
|
4639
|
+
});
|
|
4640
|
+
|
|
4641
|
+
var result = _this8.createCosmiconfigResultSync(absoluteFilePath, content);
|
|
4642
|
+
|
|
4643
|
+
return _this8.config.transform(result);
|
|
5331
4644
|
});
|
|
5332
|
-
}
|
|
5333
|
-
|
|
5334
|
-
|
|
5335
|
-
|
|
5336
|
-
|
|
5337
|
-
}, transform]);
|
|
5338
|
-
if (directoryCache) directoryCache.set(directory, result);
|
|
5339
|
-
return result;
|
|
5340
|
-
}
|
|
4645
|
+
}
|
|
4646
|
+
}]);
|
|
4647
|
+
|
|
4648
|
+
return Explorer;
|
|
4649
|
+
}();
|
|
5341
4650
|
|
|
4651
|
+
var createExplorer = function createExplorer(options) {
|
|
4652
|
+
var explorer = new Explorer(options);
|
|
5342
4653
|
return {
|
|
5343
|
-
|
|
5344
|
-
|
|
5345
|
-
|
|
5346
|
-
|
|
4654
|
+
search: explorer.search.bind(explorer),
|
|
4655
|
+
searchSync: explorer.searchSync.bind(explorer),
|
|
4656
|
+
load: explorer.load.bind(explorer),
|
|
4657
|
+
loadSync: explorer.loadSync.bind(explorer),
|
|
4658
|
+
clearLoadCache: explorer.clearLoadCache.bind(explorer),
|
|
4659
|
+
clearSearchCache: explorer.clearSearchCache.bind(explorer),
|
|
4660
|
+
clearCaches: explorer.clearCaches.bind(explorer)
|
|
5347
4661
|
};
|
|
5348
4662
|
};
|
|
5349
4663
|
|
|
5350
|
-
function
|
|
5351
|
-
return
|
|
4664
|
+
function nextDirUp(dir) {
|
|
4665
|
+
return path.dirname(dir);
|
|
4666
|
+
}
|
|
4667
|
+
|
|
4668
|
+
function getExtensionDescription(filepath) {
|
|
4669
|
+
var ext = path.extname(filepath);
|
|
4670
|
+
return ext ? `extension "${ext}"` : 'files without extensions';
|
|
5352
4671
|
}
|
|
5353
4672
|
|
|
5354
|
-
var
|
|
4673
|
+
var dist = cosmiconfig;
|
|
5355
4674
|
|
|
5356
|
-
|
|
5357
|
-
options =
|
|
4675
|
+
function cosmiconfig(moduleName, options) {
|
|
4676
|
+
options = options || {};
|
|
4677
|
+
var defaults = {
|
|
5358
4678
|
packageProp: moduleName,
|
|
5359
|
-
|
|
5360
|
-
|
|
5361
|
-
|
|
5362
|
-
stopDir: homedir,
|
|
4679
|
+
searchPlaces: ['package.json', `.${moduleName}rc`, `.${moduleName}rc.json`, `.${moduleName}rc.yaml`, `.${moduleName}rc.yml`, `.${moduleName}rc.js`, `${moduleName}.config.js`],
|
|
4680
|
+
ignoreEmptySearchPlaces: true,
|
|
4681
|
+
stopDir: os.homedir(),
|
|
5363
4682
|
cache: true,
|
|
5364
|
-
|
|
5365
|
-
}
|
|
5366
|
-
|
|
5367
|
-
|
|
4683
|
+
transform: identity
|
|
4684
|
+
};
|
|
4685
|
+
var normalizedOptions = Object.assign({}, defaults, options, {
|
|
4686
|
+
loaders: normalizeLoaders(options.loaders)
|
|
4687
|
+
});
|
|
4688
|
+
return createExplorer(normalizedOptions);
|
|
4689
|
+
}
|
|
4690
|
+
|
|
4691
|
+
cosmiconfig.loadJs = loaders.loadJs;
|
|
4692
|
+
cosmiconfig.loadJson = loaders.loadJson;
|
|
4693
|
+
cosmiconfig.loadYaml = loaders.loadYaml;
|
|
4694
|
+
|
|
4695
|
+
function normalizeLoaders(rawLoaders) {
|
|
4696
|
+
var defaults = {
|
|
4697
|
+
'.js': {
|
|
4698
|
+
sync: loaders.loadJs,
|
|
4699
|
+
async: loaders.loadJs
|
|
4700
|
+
},
|
|
4701
|
+
'.json': {
|
|
4702
|
+
sync: loaders.loadJson,
|
|
4703
|
+
async: loaders.loadJson
|
|
4704
|
+
},
|
|
4705
|
+
'.yaml': {
|
|
4706
|
+
sync: loaders.loadYaml,
|
|
4707
|
+
async: loaders.loadYaml
|
|
4708
|
+
},
|
|
4709
|
+
'.yml': {
|
|
4710
|
+
sync: loaders.loadYaml,
|
|
4711
|
+
async: loaders.loadYaml
|
|
4712
|
+
},
|
|
4713
|
+
noExt: {
|
|
4714
|
+
sync: loaders.loadYaml,
|
|
4715
|
+
async: loaders.loadYaml
|
|
4716
|
+
}
|
|
4717
|
+
};
|
|
4718
|
+
|
|
4719
|
+
if (!rawLoaders) {
|
|
4720
|
+
return defaults;
|
|
4721
|
+
}
|
|
4722
|
+
|
|
4723
|
+
return Object.keys(rawLoaders).reduce(function (result, ext) {
|
|
4724
|
+
var entry = rawLoaders && rawLoaders[ext];
|
|
4725
|
+
|
|
4726
|
+
if (typeof entry === 'function') {
|
|
4727
|
+
result[ext] = {
|
|
4728
|
+
sync: entry,
|
|
4729
|
+
async: entry
|
|
4730
|
+
};
|
|
4731
|
+
} else {
|
|
4732
|
+
result[ext] = entry;
|
|
4733
|
+
}
|
|
4734
|
+
|
|
4735
|
+
return result;
|
|
4736
|
+
}, defaults);
|
|
4737
|
+
}
|
|
4738
|
+
|
|
4739
|
+
function identity(x) {
|
|
4740
|
+
return x;
|
|
4741
|
+
}
|
|
5368
4742
|
|
|
5369
4743
|
var findParentDir$1 = createCommonjsModule(function (module, exports) {
|
|
5370
4744
|
'use strict';
|