pretierr 3.3.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 +4379 -0
- package/README.md +109 -0
- package/bin/prettier.cjs +64 -0
- package/doc.d.ts +243 -0
- package/doc.js +1319 -0
- package/doc.mjs +1291 -0
- package/index.cjs +648 -0
- package/index.d.ts +941 -0
- package/index.mjs +22795 -0
- package/internal/cli.mjs +3884 -0
- package/package.json +206 -0
- package/plugins/acorn.d.ts +6 -0
- package/plugins/acorn.js +15 -0
- package/plugins/acorn.mjs +15 -0
- package/plugins/angular.d.ts +8 -0
- package/plugins/angular.js +1 -0
- package/plugins/angular.mjs +1 -0
- package/plugins/babel.d.ts +18 -0
- package/plugins/babel.js +15 -0
- package/plugins/babel.mjs +15 -0
- package/plugins/estree.d.ts +1 -0
- package/plugins/estree.js +36 -0
- package/plugins/estree.mjs +36 -0
- package/plugins/flow.d.ts +5 -0
- package/plugins/flow.js +19 -0
- package/plugins/flow.mjs +19 -0
- package/plugins/glimmer.d.ts +5 -0
- package/plugins/glimmer.js +30 -0
- package/plugins/glimmer.mjs +30 -0
- package/plugins/graphql.d.ts +5 -0
- package/plugins/graphql.js +29 -0
- package/plugins/graphql.mjs +29 -0
- package/plugins/html.d.ts +8 -0
- package/plugins/html.js +22 -0
- package/plugins/html.mjs +22 -0
- package/plugins/markdown.d.ts +7 -0
- package/plugins/markdown.js +62 -0
- package/plugins/markdown.mjs +62 -0
- package/plugins/meriyah.d.ts +5 -0
- package/plugins/meriyah.js +4 -0
- package/plugins/meriyah.mjs +4 -0
- package/plugins/postcss.d.ts +7 -0
- package/plugins/postcss.js +52 -0
- package/plugins/postcss.mjs +52 -0
- package/plugins/typescript.d.ts +5 -0
- package/plugins/typescript.js +20 -0
- package/plugins/typescript.mjs +20 -0
- package/plugins/yaml.d.ts +5 -0
- package/plugins/yaml.js +161 -0
- package/plugins/yaml.mjs +161 -0
- package/standalone.d.ts +33 -0
- package/standalone.js +35 -0
- package/standalone.mjs +35 -0
- package/te24xjoq.cjs +1 -0
package/internal/cli.mjs
ADDED
@@ -0,0 +1,3884 @@
|
|
1
|
+
import { createRequire as __prettierCreateRequire } from "module";
|
2
|
+
import { fileURLToPath as __prettierFileUrlToPath } from "url";
|
3
|
+
import { dirname as __prettierDirname } from "path";
|
4
|
+
const require = __prettierCreateRequire(import.meta.url);
|
5
|
+
const __filename = __prettierFileUrlToPath(import.meta.url);
|
6
|
+
const __dirname = __prettierDirname(__filename);
|
7
|
+
|
8
|
+
var __create = Object.create;
|
9
|
+
var __defProp = Object.defineProperty;
|
10
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
11
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
12
|
+
var __getProtoOf = Object.getPrototypeOf;
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
14
|
+
var __typeError = (msg) => {
|
15
|
+
throw TypeError(msg);
|
16
|
+
};
|
17
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
18
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
19
|
+
}) : x)(function(x) {
|
20
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
21
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
22
|
+
});
|
23
|
+
var __commonJS = (cb, mod) => function __require2() {
|
24
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
25
|
+
};
|
26
|
+
var __copyProps = (to, from, except, desc) => {
|
27
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
28
|
+
for (let key of __getOwnPropNames(from))
|
29
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
30
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
31
|
+
}
|
32
|
+
return to;
|
33
|
+
};
|
34
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
35
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
36
|
+
// file that has been converted to a CommonJS file using a Babel-
|
37
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
38
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
39
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
40
|
+
mod
|
41
|
+
));
|
42
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
43
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
44
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
45
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
46
|
+
|
47
|
+
// node_modules/dashify/index.js
|
48
|
+
var require_dashify = __commonJS({
|
49
|
+
"node_modules/dashify/index.js"(exports, module) {
|
50
|
+
"use strict";
|
51
|
+
module.exports = (str, options) => {
|
52
|
+
if (typeof str !== "string") throw new TypeError("expected a string");
|
53
|
+
return str.trim().replace(/([a-z])([A-Z])/g, "$1-$2").replace(/\W/g, (m) => /[À-ž]/.test(m) ? m : "-").replace(/^-+|-+$/g, "").replace(/-{2,}/g, (m) => options && options.condense ? "-" : m).toLowerCase();
|
54
|
+
};
|
55
|
+
}
|
56
|
+
});
|
57
|
+
|
58
|
+
// node_modules/minimist/index.js
|
59
|
+
var require_minimist = __commonJS({
|
60
|
+
"node_modules/minimist/index.js"(exports, module) {
|
61
|
+
"use strict";
|
62
|
+
function hasKey(obj, keys) {
|
63
|
+
var o = obj;
|
64
|
+
keys.slice(0, -1).forEach(function(key2) {
|
65
|
+
o = o[key2] || {};
|
66
|
+
});
|
67
|
+
var key = keys[keys.length - 1];
|
68
|
+
return key in o;
|
69
|
+
}
|
70
|
+
function isNumber(x) {
|
71
|
+
if (typeof x === "number") {
|
72
|
+
return true;
|
73
|
+
}
|
74
|
+
if (/^0x[0-9a-f]+$/i.test(x)) {
|
75
|
+
return true;
|
76
|
+
}
|
77
|
+
return /^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(x);
|
78
|
+
}
|
79
|
+
function isConstructorOrProto(obj, key) {
|
80
|
+
return key === "constructor" && typeof obj[key] === "function" || key === "__proto__";
|
81
|
+
}
|
82
|
+
module.exports = function(args, opts) {
|
83
|
+
if (!opts) {
|
84
|
+
opts = {};
|
85
|
+
}
|
86
|
+
var flags = {
|
87
|
+
bools: {},
|
88
|
+
strings: {},
|
89
|
+
unknownFn: null
|
90
|
+
};
|
91
|
+
if (typeof opts.unknown === "function") {
|
92
|
+
flags.unknownFn = opts.unknown;
|
93
|
+
}
|
94
|
+
if (typeof opts.boolean === "boolean" && opts.boolean) {
|
95
|
+
flags.allBools = true;
|
96
|
+
} else {
|
97
|
+
[].concat(opts.boolean).filter(Boolean).forEach(function(key2) {
|
98
|
+
flags.bools[key2] = true;
|
99
|
+
});
|
100
|
+
}
|
101
|
+
var aliases = {};
|
102
|
+
function aliasIsBoolean(key2) {
|
103
|
+
return aliases[key2].some(function(x) {
|
104
|
+
return flags.bools[x];
|
105
|
+
});
|
106
|
+
}
|
107
|
+
Object.keys(opts.alias || {}).forEach(function(key2) {
|
108
|
+
aliases[key2] = [].concat(opts.alias[key2]);
|
109
|
+
aliases[key2].forEach(function(x) {
|
110
|
+
aliases[x] = [key2].concat(aliases[key2].filter(function(y) {
|
111
|
+
return x !== y;
|
112
|
+
}));
|
113
|
+
});
|
114
|
+
});
|
115
|
+
[].concat(opts.string).filter(Boolean).forEach(function(key2) {
|
116
|
+
flags.strings[key2] = true;
|
117
|
+
if (aliases[key2]) {
|
118
|
+
[].concat(aliases[key2]).forEach(function(k) {
|
119
|
+
flags.strings[k] = true;
|
120
|
+
});
|
121
|
+
}
|
122
|
+
});
|
123
|
+
var defaults = opts.default || {};
|
124
|
+
var argv = { _: [] };
|
125
|
+
function argDefined(key2, arg2) {
|
126
|
+
return flags.allBools && /^--[^=]+$/.test(arg2) || flags.strings[key2] || flags.bools[key2] || aliases[key2];
|
127
|
+
}
|
128
|
+
function setKey(obj, keys, value2) {
|
129
|
+
var o = obj;
|
130
|
+
for (var i2 = 0; i2 < keys.length - 1; i2++) {
|
131
|
+
var key2 = keys[i2];
|
132
|
+
if (isConstructorOrProto(o, key2)) {
|
133
|
+
return;
|
134
|
+
}
|
135
|
+
if (o[key2] === void 0) {
|
136
|
+
o[key2] = {};
|
137
|
+
}
|
138
|
+
if (o[key2] === Object.prototype || o[key2] === Number.prototype || o[key2] === String.prototype) {
|
139
|
+
o[key2] = {};
|
140
|
+
}
|
141
|
+
if (o[key2] === Array.prototype) {
|
142
|
+
o[key2] = [];
|
143
|
+
}
|
144
|
+
o = o[key2];
|
145
|
+
}
|
146
|
+
var lastKey = keys[keys.length - 1];
|
147
|
+
if (isConstructorOrProto(o, lastKey)) {
|
148
|
+
return;
|
149
|
+
}
|
150
|
+
if (o === Object.prototype || o === Number.prototype || o === String.prototype) {
|
151
|
+
o = {};
|
152
|
+
}
|
153
|
+
if (o === Array.prototype) {
|
154
|
+
o = [];
|
155
|
+
}
|
156
|
+
if (o[lastKey] === void 0 || flags.bools[lastKey] || typeof o[lastKey] === "boolean") {
|
157
|
+
o[lastKey] = value2;
|
158
|
+
} else if (Array.isArray(o[lastKey])) {
|
159
|
+
o[lastKey].push(value2);
|
160
|
+
} else {
|
161
|
+
o[lastKey] = [o[lastKey], value2];
|
162
|
+
}
|
163
|
+
}
|
164
|
+
function setArg(key2, val, arg2) {
|
165
|
+
if (arg2 && flags.unknownFn && !argDefined(key2, arg2)) {
|
166
|
+
if (flags.unknownFn(arg2) === false) {
|
167
|
+
return;
|
168
|
+
}
|
169
|
+
}
|
170
|
+
var value2 = !flags.strings[key2] && isNumber(val) ? Number(val) : val;
|
171
|
+
setKey(argv, key2.split("."), value2);
|
172
|
+
(aliases[key2] || []).forEach(function(x) {
|
173
|
+
setKey(argv, x.split("."), value2);
|
174
|
+
});
|
175
|
+
}
|
176
|
+
Object.keys(flags.bools).forEach(function(key2) {
|
177
|
+
setArg(key2, defaults[key2] === void 0 ? false : defaults[key2]);
|
178
|
+
});
|
179
|
+
var notFlags = [];
|
180
|
+
if (args.indexOf("--") !== -1) {
|
181
|
+
notFlags = args.slice(args.indexOf("--") + 1);
|
182
|
+
args = args.slice(0, args.indexOf("--"));
|
183
|
+
}
|
184
|
+
for (var i = 0; i < args.length; i++) {
|
185
|
+
var arg = args[i];
|
186
|
+
var key;
|
187
|
+
var next;
|
188
|
+
if (/^--.+=/.test(arg)) {
|
189
|
+
var m = arg.match(/^--([^=]+)=([\s\S]*)$/);
|
190
|
+
key = m[1];
|
191
|
+
var value = m[2];
|
192
|
+
if (flags.bools[key]) {
|
193
|
+
value = value !== "false";
|
194
|
+
}
|
195
|
+
setArg(key, value, arg);
|
196
|
+
} else if (/^--no-.+/.test(arg)) {
|
197
|
+
key = arg.match(/^--no-(.+)/)[1];
|
198
|
+
setArg(key, false, arg);
|
199
|
+
} else if (/^--.+/.test(arg)) {
|
200
|
+
key = arg.match(/^--(.+)/)[1];
|
201
|
+
next = args[i + 1];
|
202
|
+
if (next !== void 0 && !/^(-|--)[^-]/.test(next) && !flags.bools[key] && !flags.allBools && (aliases[key] ? !aliasIsBoolean(key) : true)) {
|
203
|
+
setArg(key, next, arg);
|
204
|
+
i += 1;
|
205
|
+
} else if (/^(true|false)$/.test(next)) {
|
206
|
+
setArg(key, next === "true", arg);
|
207
|
+
i += 1;
|
208
|
+
} else {
|
209
|
+
setArg(key, flags.strings[key] ? "" : true, arg);
|
210
|
+
}
|
211
|
+
} else if (/^-[^-]+/.test(arg)) {
|
212
|
+
var letters = arg.slice(1, -1).split("");
|
213
|
+
var broken = false;
|
214
|
+
for (var j = 0; j < letters.length; j++) {
|
215
|
+
next = arg.slice(j + 2);
|
216
|
+
if (next === "-") {
|
217
|
+
setArg(letters[j], next, arg);
|
218
|
+
continue;
|
219
|
+
}
|
220
|
+
if (/[A-Za-z]/.test(letters[j]) && next[0] === "=") {
|
221
|
+
setArg(letters[j], next.slice(1), arg);
|
222
|
+
broken = true;
|
223
|
+
break;
|
224
|
+
}
|
225
|
+
if (/[A-Za-z]/.test(letters[j]) && /-?\d+(\.\d*)?(e-?\d+)?$/.test(next)) {
|
226
|
+
setArg(letters[j], next, arg);
|
227
|
+
broken = true;
|
228
|
+
break;
|
229
|
+
}
|
230
|
+
if (letters[j + 1] && letters[j + 1].match(/\W/)) {
|
231
|
+
setArg(letters[j], arg.slice(j + 2), arg);
|
232
|
+
broken = true;
|
233
|
+
break;
|
234
|
+
} else {
|
235
|
+
setArg(letters[j], flags.strings[letters[j]] ? "" : true, arg);
|
236
|
+
}
|
237
|
+
}
|
238
|
+
key = arg.slice(-1)[0];
|
239
|
+
if (!broken && key !== "-") {
|
240
|
+
if (args[i + 1] && !/^(-|--)[^-]/.test(args[i + 1]) && !flags.bools[key] && (aliases[key] ? !aliasIsBoolean(key) : true)) {
|
241
|
+
setArg(key, args[i + 1], arg);
|
242
|
+
i += 1;
|
243
|
+
} else if (args[i + 1] && /^(true|false)$/.test(args[i + 1])) {
|
244
|
+
setArg(key, args[i + 1] === "true", arg);
|
245
|
+
i += 1;
|
246
|
+
} else {
|
247
|
+
setArg(key, flags.strings[key] ? "" : true, arg);
|
248
|
+
}
|
249
|
+
}
|
250
|
+
} else {
|
251
|
+
if (!flags.unknownFn || flags.unknownFn(arg) !== false) {
|
252
|
+
argv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));
|
253
|
+
}
|
254
|
+
if (opts.stopEarly) {
|
255
|
+
argv._.push.apply(argv._, args.slice(i + 1));
|
256
|
+
break;
|
257
|
+
}
|
258
|
+
}
|
259
|
+
}
|
260
|
+
Object.keys(defaults).forEach(function(k) {
|
261
|
+
if (!hasKey(argv, k.split("."))) {
|
262
|
+
setKey(argv, k.split("."), defaults[k]);
|
263
|
+
(aliases[k] || []).forEach(function(x) {
|
264
|
+
setKey(argv, x.split("."), defaults[k]);
|
265
|
+
});
|
266
|
+
}
|
267
|
+
});
|
268
|
+
if (opts["--"]) {
|
269
|
+
argv["--"] = notFlags.slice();
|
270
|
+
} else {
|
271
|
+
notFlags.forEach(function(k) {
|
272
|
+
argv._.push(k);
|
273
|
+
});
|
274
|
+
}
|
275
|
+
return argv;
|
276
|
+
};
|
277
|
+
}
|
278
|
+
});
|
279
|
+
|
280
|
+
// node_modules/fast-json-stable-stringify/index.js
|
281
|
+
var require_fast_json_stable_stringify = __commonJS({
|
282
|
+
"node_modules/fast-json-stable-stringify/index.js"(exports, module) {
|
283
|
+
"use strict";
|
284
|
+
module.exports = function(data, opts) {
|
285
|
+
if (!opts) opts = {};
|
286
|
+
if (typeof opts === "function") opts = { cmp: opts };
|
287
|
+
var cycles = typeof opts.cycles === "boolean" ? opts.cycles : false;
|
288
|
+
var cmp = opts.cmp && /* @__PURE__ */ function(f) {
|
289
|
+
return function(node) {
|
290
|
+
return function(a, b) {
|
291
|
+
var aobj = { key: a, value: node[a] };
|
292
|
+
var bobj = { key: b, value: node[b] };
|
293
|
+
return f(aobj, bobj);
|
294
|
+
};
|
295
|
+
};
|
296
|
+
}(opts.cmp);
|
297
|
+
var seen = [];
|
298
|
+
return function stringify4(node) {
|
299
|
+
if (node && node.toJSON && typeof node.toJSON === "function") {
|
300
|
+
node = node.toJSON();
|
301
|
+
}
|
302
|
+
if (node === void 0) return;
|
303
|
+
if (typeof node == "number") return isFinite(node) ? "" + node : "null";
|
304
|
+
if (typeof node !== "object") return JSON.stringify(node);
|
305
|
+
var i, out;
|
306
|
+
if (Array.isArray(node)) {
|
307
|
+
out = "[";
|
308
|
+
for (i = 0; i < node.length; i++) {
|
309
|
+
if (i) out += ",";
|
310
|
+
out += stringify4(node[i]) || "null";
|
311
|
+
}
|
312
|
+
return out + "]";
|
313
|
+
}
|
314
|
+
if (node === null) return "null";
|
315
|
+
if (seen.indexOf(node) !== -1) {
|
316
|
+
if (cycles) return JSON.stringify("__cycle__");
|
317
|
+
throw new TypeError("Converting circular structure to JSON");
|
318
|
+
}
|
319
|
+
var seenIndex = seen.push(node) - 1;
|
320
|
+
var keys = Object.keys(node).sort(cmp && cmp(node));
|
321
|
+
out = "";
|
322
|
+
for (i = 0; i < keys.length; i++) {
|
323
|
+
var key = keys[i];
|
324
|
+
var value = stringify4(node[key]);
|
325
|
+
if (!value) continue;
|
326
|
+
if (out) out += ",";
|
327
|
+
out += JSON.stringify(key) + ":" + value;
|
328
|
+
}
|
329
|
+
seen.splice(seenIndex, 1);
|
330
|
+
return "{" + out + "}";
|
331
|
+
}(data);
|
332
|
+
};
|
333
|
+
}
|
334
|
+
});
|
335
|
+
|
336
|
+
// node_modules/common-path-prefix/index.js
|
337
|
+
var require_common_path_prefix = __commonJS({
|
338
|
+
"node_modules/common-path-prefix/index.js"(exports, module) {
|
339
|
+
"use strict";
|
340
|
+
var { sep: DEFAULT_SEPARATOR } = __require("path");
|
341
|
+
var determineSeparator = (paths) => {
|
342
|
+
for (const path10 of paths) {
|
343
|
+
const match = /(\/|\\)/.exec(path10);
|
344
|
+
if (match !== null) return match[0];
|
345
|
+
}
|
346
|
+
return DEFAULT_SEPARATOR;
|
347
|
+
};
|
348
|
+
module.exports = function commonPathPrefix2(paths, sep = determineSeparator(paths)) {
|
349
|
+
const [first = "", ...remaining] = paths;
|
350
|
+
if (first === "" || remaining.length === 0) return "";
|
351
|
+
const parts = first.split(sep);
|
352
|
+
let endOfPrefix = parts.length;
|
353
|
+
for (const path10 of remaining) {
|
354
|
+
const compare = path10.split(sep);
|
355
|
+
for (let i = 0; i < endOfPrefix; i++) {
|
356
|
+
if (compare[i] !== parts[i]) {
|
357
|
+
endOfPrefix = i;
|
358
|
+
}
|
359
|
+
}
|
360
|
+
if (endOfPrefix === 0) return "";
|
361
|
+
}
|
362
|
+
const prefix = parts.slice(0, endOfPrefix).join(sep);
|
363
|
+
return prefix.endsWith(sep) ? prefix : prefix + sep;
|
364
|
+
};
|
365
|
+
}
|
366
|
+
});
|
367
|
+
|
368
|
+
// node_modules/json-buffer/index.js
|
369
|
+
var require_json_buffer = __commonJS({
|
370
|
+
"node_modules/json-buffer/index.js"(exports) {
|
371
|
+
exports.stringify = function stringify4(o) {
|
372
|
+
if ("undefined" == typeof o) return o;
|
373
|
+
if (o && Buffer.isBuffer(o))
|
374
|
+
return JSON.stringify(":base64:" + o.toString("base64"));
|
375
|
+
if (o && o.toJSON)
|
376
|
+
o = o.toJSON();
|
377
|
+
if (o && "object" === typeof o) {
|
378
|
+
var s = "";
|
379
|
+
var array2 = Array.isArray(o);
|
380
|
+
s = array2 ? "[" : "{";
|
381
|
+
var first = true;
|
382
|
+
for (var k in o) {
|
383
|
+
var ignore = "function" == typeof o[k] || !array2 && "undefined" === typeof o[k];
|
384
|
+
if (Object.hasOwnProperty.call(o, k) && !ignore) {
|
385
|
+
if (!first)
|
386
|
+
s += ",";
|
387
|
+
first = false;
|
388
|
+
if (array2) {
|
389
|
+
if (o[k] == void 0)
|
390
|
+
s += "null";
|
391
|
+
else
|
392
|
+
s += stringify4(o[k]);
|
393
|
+
} else if (o[k] !== void 0) {
|
394
|
+
s += stringify4(k) + ":" + stringify4(o[k]);
|
395
|
+
}
|
396
|
+
}
|
397
|
+
}
|
398
|
+
s += array2 ? "]" : "}";
|
399
|
+
return s;
|
400
|
+
} else if ("string" === typeof o) {
|
401
|
+
return JSON.stringify(/^:/.test(o) ? ":" + o : o);
|
402
|
+
} else if ("undefined" === typeof o) {
|
403
|
+
return "null";
|
404
|
+
} else
|
405
|
+
return JSON.stringify(o);
|
406
|
+
};
|
407
|
+
exports.parse = function(s) {
|
408
|
+
return JSON.parse(s, function(key, value) {
|
409
|
+
if ("string" === typeof value) {
|
410
|
+
if (/^:base64:/.test(value))
|
411
|
+
return Buffer.from(value.substring(8), "base64");
|
412
|
+
else
|
413
|
+
return /^:/.test(value) ? value.substring(1) : value;
|
414
|
+
}
|
415
|
+
return value;
|
416
|
+
});
|
417
|
+
};
|
418
|
+
}
|
419
|
+
});
|
420
|
+
|
421
|
+
// node_modules/keyv/src/index.js
|
422
|
+
var require_src = __commonJS({
|
423
|
+
"node_modules/keyv/src/index.js"(exports, module) {
|
424
|
+
"use strict";
|
425
|
+
var EventEmitter = __require("events");
|
426
|
+
var JSONB = require_json_buffer();
|
427
|
+
var loadStore = (options) => {
|
428
|
+
const adapters = {
|
429
|
+
redis: "@keyv/redis",
|
430
|
+
rediss: "@keyv/redis",
|
431
|
+
mongodb: "@keyv/mongo",
|
432
|
+
mongo: "@keyv/mongo",
|
433
|
+
sqlite: "@keyv/sqlite",
|
434
|
+
postgresql: "@keyv/postgres",
|
435
|
+
postgres: "@keyv/postgres",
|
436
|
+
mysql: "@keyv/mysql",
|
437
|
+
etcd: "@keyv/etcd",
|
438
|
+
offline: "@keyv/offline",
|
439
|
+
tiered: "@keyv/tiered"
|
440
|
+
};
|
441
|
+
if (options.adapter || options.uri) {
|
442
|
+
const adapter = options.adapter || /^[^:+]*/.exec(options.uri)[0];
|
443
|
+
return new (__require(adapters[adapter]))(options);
|
444
|
+
}
|
445
|
+
return /* @__PURE__ */ new Map();
|
446
|
+
};
|
447
|
+
var iterableAdapters = [
|
448
|
+
"sqlite",
|
449
|
+
"postgres",
|
450
|
+
"mysql",
|
451
|
+
"mongo",
|
452
|
+
"redis",
|
453
|
+
"tiered"
|
454
|
+
];
|
455
|
+
var Keyv = class extends EventEmitter {
|
456
|
+
constructor(uri, { emitErrors = true, ...options } = {}) {
|
457
|
+
super();
|
458
|
+
this.opts = {
|
459
|
+
namespace: "keyv",
|
460
|
+
serialize: JSONB.stringify,
|
461
|
+
deserialize: JSONB.parse,
|
462
|
+
...typeof uri === "string" ? { uri } : uri,
|
463
|
+
...options
|
464
|
+
};
|
465
|
+
if (!this.opts.store) {
|
466
|
+
const adapterOptions = { ...this.opts };
|
467
|
+
this.opts.store = loadStore(adapterOptions);
|
468
|
+
}
|
469
|
+
if (this.opts.compression) {
|
470
|
+
const compression = this.opts.compression;
|
471
|
+
this.opts.serialize = compression.serialize.bind(compression);
|
472
|
+
this.opts.deserialize = compression.deserialize.bind(compression);
|
473
|
+
}
|
474
|
+
if (typeof this.opts.store.on === "function" && emitErrors) {
|
475
|
+
this.opts.store.on("error", (error) => this.emit("error", error));
|
476
|
+
}
|
477
|
+
this.opts.store.namespace = this.opts.namespace;
|
478
|
+
const generateIterator = (iterator) => async function* () {
|
479
|
+
for await (const [key, raw] of typeof iterator === "function" ? iterator(this.opts.store.namespace) : iterator) {
|
480
|
+
const data = await this.opts.deserialize(raw);
|
481
|
+
if (this.opts.store.namespace && !key.includes(this.opts.store.namespace)) {
|
482
|
+
continue;
|
483
|
+
}
|
484
|
+
if (typeof data.expires === "number" && Date.now() > data.expires) {
|
485
|
+
this.delete(key);
|
486
|
+
continue;
|
487
|
+
}
|
488
|
+
yield [this._getKeyUnprefix(key), data.value];
|
489
|
+
}
|
490
|
+
};
|
491
|
+
if (typeof this.opts.store[Symbol.iterator] === "function" && this.opts.store instanceof Map) {
|
492
|
+
this.iterator = generateIterator(this.opts.store);
|
493
|
+
} else if (typeof this.opts.store.iterator === "function" && this.opts.store.opts && this._checkIterableAdaptar()) {
|
494
|
+
this.iterator = generateIterator(this.opts.store.iterator.bind(this.opts.store));
|
495
|
+
}
|
496
|
+
}
|
497
|
+
_checkIterableAdaptar() {
|
498
|
+
return iterableAdapters.includes(this.opts.store.opts.dialect) || iterableAdapters.findIndex((element) => this.opts.store.opts.url.includes(element)) >= 0;
|
499
|
+
}
|
500
|
+
_getKeyPrefix(key) {
|
501
|
+
return `${this.opts.namespace}:${key}`;
|
502
|
+
}
|
503
|
+
_getKeyPrefixArray(keys) {
|
504
|
+
return keys.map((key) => `${this.opts.namespace}:${key}`);
|
505
|
+
}
|
506
|
+
_getKeyUnprefix(key) {
|
507
|
+
return key.split(":").splice(1).join(":");
|
508
|
+
}
|
509
|
+
get(key, options) {
|
510
|
+
const { store } = this.opts;
|
511
|
+
const isArray = Array.isArray(key);
|
512
|
+
const keyPrefixed = isArray ? this._getKeyPrefixArray(key) : this._getKeyPrefix(key);
|
513
|
+
if (isArray && store.getMany === void 0) {
|
514
|
+
const promises = [];
|
515
|
+
for (const key2 of keyPrefixed) {
|
516
|
+
promises.push(
|
517
|
+
Promise.resolve().then(() => store.get(key2)).then((data) => typeof data === "string" ? this.opts.deserialize(data) : this.opts.compression ? this.opts.deserialize(data) : data).then((data) => {
|
518
|
+
if (data === void 0 || data === null) {
|
519
|
+
return void 0;
|
520
|
+
}
|
521
|
+
if (typeof data.expires === "number" && Date.now() > data.expires) {
|
522
|
+
return this.delete(key2).then(() => void 0);
|
523
|
+
}
|
524
|
+
return options && options.raw ? data : data.value;
|
525
|
+
})
|
526
|
+
);
|
527
|
+
}
|
528
|
+
return Promise.allSettled(promises).then((values) => {
|
529
|
+
const data = [];
|
530
|
+
for (const value of values) {
|
531
|
+
data.push(value.value);
|
532
|
+
}
|
533
|
+
return data;
|
534
|
+
});
|
535
|
+
}
|
536
|
+
return Promise.resolve().then(() => isArray ? store.getMany(keyPrefixed) : store.get(keyPrefixed)).then((data) => typeof data === "string" ? this.opts.deserialize(data) : this.opts.compression ? this.opts.deserialize(data) : data).then((data) => {
|
537
|
+
if (data === void 0 || data === null) {
|
538
|
+
return void 0;
|
539
|
+
}
|
540
|
+
if (isArray) {
|
541
|
+
return data.map((row, index) => {
|
542
|
+
if (typeof row === "string") {
|
543
|
+
row = this.opts.deserialize(row);
|
544
|
+
}
|
545
|
+
if (row === void 0 || row === null) {
|
546
|
+
return void 0;
|
547
|
+
}
|
548
|
+
if (typeof row.expires === "number" && Date.now() > row.expires) {
|
549
|
+
this.delete(key[index]).then(() => void 0);
|
550
|
+
return void 0;
|
551
|
+
}
|
552
|
+
return options && options.raw ? row : row.value;
|
553
|
+
});
|
554
|
+
}
|
555
|
+
if (typeof data.expires === "number" && Date.now() > data.expires) {
|
556
|
+
return this.delete(key).then(() => void 0);
|
557
|
+
}
|
558
|
+
return options && options.raw ? data : data.value;
|
559
|
+
});
|
560
|
+
}
|
561
|
+
set(key, value, ttl) {
|
562
|
+
const keyPrefixed = this._getKeyPrefix(key);
|
563
|
+
if (typeof ttl === "undefined") {
|
564
|
+
ttl = this.opts.ttl;
|
565
|
+
}
|
566
|
+
if (ttl === 0) {
|
567
|
+
ttl = void 0;
|
568
|
+
}
|
569
|
+
const { store } = this.opts;
|
570
|
+
return Promise.resolve().then(() => {
|
571
|
+
const expires = typeof ttl === "number" ? Date.now() + ttl : null;
|
572
|
+
if (typeof value === "symbol") {
|
573
|
+
this.emit("error", "symbol cannot be serialized");
|
574
|
+
}
|
575
|
+
value = { value, expires };
|
576
|
+
return this.opts.serialize(value);
|
577
|
+
}).then((value2) => store.set(keyPrefixed, value2, ttl)).then(() => true);
|
578
|
+
}
|
579
|
+
delete(key) {
|
580
|
+
const { store } = this.opts;
|
581
|
+
if (Array.isArray(key)) {
|
582
|
+
const keyPrefixed2 = this._getKeyPrefixArray(key);
|
583
|
+
if (store.deleteMany === void 0) {
|
584
|
+
const promises = [];
|
585
|
+
for (const key2 of keyPrefixed2) {
|
586
|
+
promises.push(store.delete(key2));
|
587
|
+
}
|
588
|
+
return Promise.allSettled(promises).then((values) => values.every((x) => x.value === true));
|
589
|
+
}
|
590
|
+
return Promise.resolve().then(() => store.deleteMany(keyPrefixed2));
|
591
|
+
}
|
592
|
+
const keyPrefixed = this._getKeyPrefix(key);
|
593
|
+
return Promise.resolve().then(() => store.delete(keyPrefixed));
|
594
|
+
}
|
595
|
+
clear() {
|
596
|
+
const { store } = this.opts;
|
597
|
+
return Promise.resolve().then(() => store.clear());
|
598
|
+
}
|
599
|
+
has(key) {
|
600
|
+
const keyPrefixed = this._getKeyPrefix(key);
|
601
|
+
const { store } = this.opts;
|
602
|
+
return Promise.resolve().then(async () => {
|
603
|
+
if (typeof store.has === "function") {
|
604
|
+
return store.has(keyPrefixed);
|
605
|
+
}
|
606
|
+
const value = await store.get(keyPrefixed);
|
607
|
+
return value !== void 0;
|
608
|
+
});
|
609
|
+
}
|
610
|
+
disconnect() {
|
611
|
+
const { store } = this.opts;
|
612
|
+
if (typeof store.disconnect === "function") {
|
613
|
+
return store.disconnect();
|
614
|
+
}
|
615
|
+
}
|
616
|
+
};
|
617
|
+
module.exports = Keyv;
|
618
|
+
}
|
619
|
+
});
|
620
|
+
|
621
|
+
// node_modules/flatted/cjs/index.js
|
622
|
+
var require_cjs = __commonJS({
|
623
|
+
"node_modules/flatted/cjs/index.js"(exports) {
|
624
|
+
"use strict";
|
625
|
+
var { parse: $parse, stringify: $stringify } = JSON;
|
626
|
+
var { keys } = Object;
|
627
|
+
var Primitive = String;
|
628
|
+
var primitive = "string";
|
629
|
+
var ignore = {};
|
630
|
+
var object = "object";
|
631
|
+
var noop = (_, value) => value;
|
632
|
+
var primitives = (value) => value instanceof Primitive ? Primitive(value) : value;
|
633
|
+
var Primitives = (_, value) => typeof value === primitive ? new Primitive(value) : value;
|
634
|
+
var revive = (input, parsed, output, $) => {
|
635
|
+
const lazy = [];
|
636
|
+
for (let ke = keys(output), { length } = ke, y = 0; y < length; y++) {
|
637
|
+
const k = ke[y];
|
638
|
+
const value = output[k];
|
639
|
+
if (value instanceof Primitive) {
|
640
|
+
const tmp = input[value];
|
641
|
+
if (typeof tmp === object && !parsed.has(tmp)) {
|
642
|
+
parsed.add(tmp);
|
643
|
+
output[k] = ignore;
|
644
|
+
lazy.push({ k, a: [input, parsed, tmp, $] });
|
645
|
+
} else
|
646
|
+
output[k] = $.call(output, k, tmp);
|
647
|
+
} else if (output[k] !== ignore)
|
648
|
+
output[k] = $.call(output, k, value);
|
649
|
+
}
|
650
|
+
for (let { length } = lazy, i = 0; i < length; i++) {
|
651
|
+
const { k, a } = lazy[i];
|
652
|
+
output[k] = $.call(output, k, revive.apply(null, a));
|
653
|
+
}
|
654
|
+
return output;
|
655
|
+
};
|
656
|
+
var set = (known, input, value) => {
|
657
|
+
const index = Primitive(input.push(value) - 1);
|
658
|
+
known.set(value, index);
|
659
|
+
return index;
|
660
|
+
};
|
661
|
+
var parse = (text, reviver) => {
|
662
|
+
const input = $parse(text, Primitives).map(primitives);
|
663
|
+
const value = input[0];
|
664
|
+
const $ = reviver || noop;
|
665
|
+
const tmp = typeof value === object && value ? revive(input, /* @__PURE__ */ new Set(), value, $) : value;
|
666
|
+
return $.call({ "": tmp }, "", tmp);
|
667
|
+
};
|
668
|
+
exports.parse = parse;
|
669
|
+
var stringify4 = (value, replacer, space) => {
|
670
|
+
const $ = replacer && typeof replacer === object ? (k, v) => k === "" || -1 < replacer.indexOf(k) ? v : void 0 : replacer || noop;
|
671
|
+
const known = /* @__PURE__ */ new Map();
|
672
|
+
const input = [];
|
673
|
+
const output = [];
|
674
|
+
let i = +set(known, input, $.call({ "": value }, "", value));
|
675
|
+
let firstRun = !i;
|
676
|
+
while (i < input.length) {
|
677
|
+
firstRun = true;
|
678
|
+
output[i] = $stringify(input[i++], replace, space);
|
679
|
+
}
|
680
|
+
return "[" + output.join(",") + "]";
|
681
|
+
function replace(key, value2) {
|
682
|
+
if (firstRun) {
|
683
|
+
firstRun = !firstRun;
|
684
|
+
return value2;
|
685
|
+
}
|
686
|
+
const after = $.call(this, key, value2);
|
687
|
+
switch (typeof after) {
|
688
|
+
case object:
|
689
|
+
if (after === null) return after;
|
690
|
+
case primitive:
|
691
|
+
return known.get(after) || set(known, input, after);
|
692
|
+
}
|
693
|
+
return after;
|
694
|
+
}
|
695
|
+
};
|
696
|
+
exports.stringify = stringify4;
|
697
|
+
var toJSON = (value) => $parse(stringify4(value));
|
698
|
+
exports.toJSON = toJSON;
|
699
|
+
var fromJSON = (value) => parse($stringify(value));
|
700
|
+
exports.fromJSON = fromJSON;
|
701
|
+
}
|
702
|
+
});
|
703
|
+
|
704
|
+
// node_modules/file-entry-cache/node_modules/flat-cache/src/utils.js
|
705
|
+
var require_utils = __commonJS({
|
706
|
+
"node_modules/file-entry-cache/node_modules/flat-cache/src/utils.js"(exports, module) {
|
707
|
+
var fs6 = __require("fs");
|
708
|
+
var path10 = __require("path");
|
709
|
+
var flatted = require_cjs();
|
710
|
+
function tryParse(filePath, defaultValue) {
|
711
|
+
let result;
|
712
|
+
try {
|
713
|
+
result = readJSON(filePath);
|
714
|
+
} catch {
|
715
|
+
result = defaultValue;
|
716
|
+
}
|
717
|
+
return result;
|
718
|
+
}
|
719
|
+
function readJSON(filePath) {
|
720
|
+
return flatted.parse(
|
721
|
+
fs6.readFileSync(filePath, {
|
722
|
+
encoding: "utf8"
|
723
|
+
})
|
724
|
+
);
|
725
|
+
}
|
726
|
+
function writeJSON(filePath, data) {
|
727
|
+
fs6.mkdirSync(path10.dirname(filePath), {
|
728
|
+
recursive: true
|
729
|
+
});
|
730
|
+
fs6.writeFileSync(filePath, flatted.stringify(data));
|
731
|
+
}
|
732
|
+
module.exports = { tryParse, readJSON, writeJSON };
|
733
|
+
}
|
734
|
+
});
|
735
|
+
|
736
|
+
// node_modules/file-entry-cache/node_modules/flat-cache/src/del.js
|
737
|
+
var require_del = __commonJS({
|
738
|
+
"node_modules/file-entry-cache/node_modules/flat-cache/src/del.js"(exports, module) {
|
739
|
+
var fs6 = __require("fs");
|
740
|
+
var path10 = __require("path");
|
741
|
+
function del(targetPath) {
|
742
|
+
if (!fs6.existsSync(targetPath)) {
|
743
|
+
return false;
|
744
|
+
}
|
745
|
+
try {
|
746
|
+
if (fs6.statSync(targetPath).isDirectory()) {
|
747
|
+
for (const file of fs6.readdirSync(targetPath)) {
|
748
|
+
const currentPath = path10.join(targetPath, file);
|
749
|
+
if (fs6.statSync(currentPath).isFile()) {
|
750
|
+
fs6.unlinkSync(currentPath);
|
751
|
+
}
|
752
|
+
}
|
753
|
+
fs6.rmdirSync(targetPath);
|
754
|
+
} else {
|
755
|
+
fs6.unlinkSync(targetPath);
|
756
|
+
}
|
757
|
+
return true;
|
758
|
+
} catch (error) {
|
759
|
+
console.error(`Error while deleting ${targetPath}: ${error.message}`);
|
760
|
+
}
|
761
|
+
}
|
762
|
+
module.exports = { del };
|
763
|
+
}
|
764
|
+
});
|
765
|
+
|
766
|
+
// node_modules/file-entry-cache/node_modules/flat-cache/src/cache.js
|
767
|
+
var require_cache = __commonJS({
|
768
|
+
"node_modules/file-entry-cache/node_modules/flat-cache/src/cache.js"(exports, module) {
|
769
|
+
var path10 = __require("path");
|
770
|
+
var fs6 = __require("fs");
|
771
|
+
var Keyv = require_src();
|
772
|
+
var { writeJSON, tryParse } = require_utils();
|
773
|
+
var { del } = require_del();
|
774
|
+
var cache = {
|
775
|
+
/**
|
776
|
+
* Load a cache identified by the given Id. If the element does not exists, then initialize an empty
|
777
|
+
* cache storage. If specified `cacheDir` will be used as the directory to persist the data to. If omitted
|
778
|
+
* then the cache module directory `./cache` will be used instead
|
779
|
+
*
|
780
|
+
* @method load
|
781
|
+
* @param docId {String} the id of the cache, would also be used as the name of the file cache
|
782
|
+
* @param [cacheDir] {String} directory for the cache entry
|
783
|
+
*/
|
784
|
+
load(documentId, cacheDir) {
|
785
|
+
const me = this;
|
786
|
+
me.keyv = new Keyv();
|
787
|
+
me.__visited = {};
|
788
|
+
me.__persisted = {};
|
789
|
+
me._pathToFile = cacheDir ? path10.resolve(cacheDir, documentId) : path10.resolve(__dirname, "../.cache/", documentId);
|
790
|
+
if (fs6.existsSync(me._pathToFile)) {
|
791
|
+
me._persisted = tryParse(me._pathToFile, {});
|
792
|
+
}
|
793
|
+
},
|
794
|
+
get _persisted() {
|
795
|
+
return this.__persisted;
|
796
|
+
},
|
797
|
+
set _persisted(value) {
|
798
|
+
this.__persisted = value;
|
799
|
+
},
|
800
|
+
get _visited() {
|
801
|
+
return this.__visited;
|
802
|
+
},
|
803
|
+
set _visited(value) {
|
804
|
+
this.__visited = value;
|
805
|
+
},
|
806
|
+
/**
|
807
|
+
* Load the cache from the provided file
|
808
|
+
* @method loadFile
|
809
|
+
* @param {String} pathToFile the path to the file containing the info for the cache
|
810
|
+
*/
|
811
|
+
loadFile(pathToFile) {
|
812
|
+
const me = this;
|
813
|
+
const dir = path10.dirname(pathToFile);
|
814
|
+
const fName = path10.basename(pathToFile);
|
815
|
+
me.load(fName, dir);
|
816
|
+
},
|
817
|
+
/**
|
818
|
+
* Returns the entire persisted object
|
819
|
+
* @method all
|
820
|
+
* @returns {*}
|
821
|
+
*/
|
822
|
+
all() {
|
823
|
+
return this._persisted;
|
824
|
+
},
|
825
|
+
keys() {
|
826
|
+
return Object.keys(this._persisted);
|
827
|
+
},
|
828
|
+
/**
|
829
|
+
* Sets a key to a given value
|
830
|
+
* @method setKey
|
831
|
+
* @param key {string} the key to set
|
832
|
+
* @param value {object} the value of the key. Could be any object that can be serialized with JSON.stringify
|
833
|
+
*/
|
834
|
+
setKey(key, value) {
|
835
|
+
this._visited[key] = true;
|
836
|
+
this._persisted[key] = value;
|
837
|
+
},
|
838
|
+
/**
|
839
|
+
* Remove a given key from the cache
|
840
|
+
* @method removeKey
|
841
|
+
* @param key {String} the key to remove from the object
|
842
|
+
*/
|
843
|
+
removeKey(key) {
|
844
|
+
delete this._visited[key];
|
845
|
+
delete this._persisted[key];
|
846
|
+
},
|
847
|
+
/**
|
848
|
+
* Return the value of the provided key
|
849
|
+
* @method getKey
|
850
|
+
* @param key {String} the name of the key to retrieve
|
851
|
+
* @returns {*} the value from the key
|
852
|
+
*/
|
853
|
+
getKey(key) {
|
854
|
+
this._visited[key] = true;
|
855
|
+
return this._persisted[key];
|
856
|
+
},
|
857
|
+
/**
|
858
|
+
* Remove keys that were not accessed/set since the
|
859
|
+
* last time the `prune` method was called.
|
860
|
+
* @method _prune
|
861
|
+
* @private
|
862
|
+
*/
|
863
|
+
_prune() {
|
864
|
+
const me = this;
|
865
|
+
const object = {};
|
866
|
+
const keys = Object.keys(me._visited);
|
867
|
+
if (keys.length === 0) {
|
868
|
+
return;
|
869
|
+
}
|
870
|
+
for (const key of keys) {
|
871
|
+
object[key] = me._persisted[key];
|
872
|
+
}
|
873
|
+
me._visited = {};
|
874
|
+
me._persisted = object;
|
875
|
+
},
|
876
|
+
/**
|
877
|
+
* Save the state of the cache identified by the docId to disk
|
878
|
+
* as a JSON structure
|
879
|
+
* @param [noPrune=false] {Boolean} whether to remove from cache the non visited files
|
880
|
+
* @method save
|
881
|
+
*/
|
882
|
+
save(noPrune) {
|
883
|
+
const me = this;
|
884
|
+
!noPrune && me._prune();
|
885
|
+
writeJSON(me._pathToFile, me._persisted);
|
886
|
+
},
|
887
|
+
/**
|
888
|
+
* Remove the file where the cache is persisted
|
889
|
+
* @method removeCacheFile
|
890
|
+
* @return {Boolean} true or false if the file was successfully deleted
|
891
|
+
*/
|
892
|
+
removeCacheFile() {
|
893
|
+
return del(this._pathToFile);
|
894
|
+
},
|
895
|
+
/**
|
896
|
+
* Destroy the file cache and cache content.
|
897
|
+
* @method destroy
|
898
|
+
*/
|
899
|
+
destroy() {
|
900
|
+
const me = this;
|
901
|
+
me._visited = {};
|
902
|
+
me._persisted = {};
|
903
|
+
me.removeCacheFile();
|
904
|
+
}
|
905
|
+
};
|
906
|
+
module.exports = {
|
907
|
+
/**
|
908
|
+
* Alias for create. Should be considered depreacted. Will be removed in next releases
|
909
|
+
*
|
910
|
+
* @method load
|
911
|
+
* @param docId {String} the id of the cache, would also be used as the name of the file cache
|
912
|
+
* @param [cacheDir] {String} directory for the cache entry
|
913
|
+
* @returns {cache} cache instance
|
914
|
+
*/
|
915
|
+
load(documentId, cacheDir) {
|
916
|
+
return this.create(documentId, cacheDir);
|
917
|
+
},
|
918
|
+
/**
|
919
|
+
* Load a cache identified by the given Id. If the element does not exists, then initialize an empty
|
920
|
+
* cache storage.
|
921
|
+
*
|
922
|
+
* @method create
|
923
|
+
* @param docId {String} the id of the cache, would also be used as the name of the file cache
|
924
|
+
* @param [cacheDir] {String} directory for the cache entry
|
925
|
+
* @returns {cache} cache instance
|
926
|
+
*/
|
927
|
+
create(documentId, cacheDir) {
|
928
|
+
const object = Object.create(cache);
|
929
|
+
object.load(documentId, cacheDir);
|
930
|
+
return object;
|
931
|
+
},
|
932
|
+
createFromFile(filePath) {
|
933
|
+
const object = Object.create(cache);
|
934
|
+
object.loadFile(filePath);
|
935
|
+
return object;
|
936
|
+
},
|
937
|
+
/**
|
938
|
+
* Clear the cache identified by the given id. Caches stored in a different cache directory can be deleted directly
|
939
|
+
*
|
940
|
+
* @method clearCache
|
941
|
+
* @param docId {String} the id of the cache, would also be used as the name of the file cache
|
942
|
+
* @param cacheDir {String} the directory where the cache file was written
|
943
|
+
* @returns {Boolean} true if the cache folder was deleted. False otherwise
|
944
|
+
*/
|
945
|
+
clearCacheById(documentId, cacheDir) {
|
946
|
+
const filePath = cacheDir ? path10.resolve(cacheDir, documentId) : path10.resolve(__dirname, "../.cache/", documentId);
|
947
|
+
return del(filePath);
|
948
|
+
},
|
949
|
+
/**
|
950
|
+
* Remove all cache stored in the cache directory
|
951
|
+
* @method clearAll
|
952
|
+
* @returns {Boolean} true if the cache folder was deleted. False otherwise
|
953
|
+
*/
|
954
|
+
clearAll(cacheDir) {
|
955
|
+
const filePath = cacheDir ? path10.resolve(cacheDir) : path10.resolve(__dirname, "../.cache/");
|
956
|
+
return del(filePath);
|
957
|
+
}
|
958
|
+
};
|
959
|
+
}
|
960
|
+
});
|
961
|
+
|
962
|
+
// node_modules/file-entry-cache/cache.js
|
963
|
+
var require_cache2 = __commonJS({
|
964
|
+
"node_modules/file-entry-cache/cache.js"(exports, module) {
|
965
|
+
var path10 = __require("path");
|
966
|
+
var process5 = __require("process");
|
967
|
+
var crypto = __require("crypto");
|
968
|
+
module.exports = {
|
969
|
+
createFromFile(filePath, useChecksum) {
|
970
|
+
const fname = path10.basename(filePath);
|
971
|
+
const dir = path10.dirname(filePath);
|
972
|
+
return this.create(fname, dir, useChecksum);
|
973
|
+
},
|
974
|
+
create(cacheId, _path, useChecksum) {
|
975
|
+
const fs6 = __require("fs");
|
976
|
+
const flatCache = require_cache();
|
977
|
+
const cache = flatCache.load(cacheId, _path);
|
978
|
+
let normalizedEntries = {};
|
979
|
+
const removeNotFoundFiles = function removeNotFoundFiles2() {
|
980
|
+
const cachedEntries = cache.keys();
|
981
|
+
for (const fPath of cachedEntries) {
|
982
|
+
try {
|
983
|
+
fs6.statSync(fPath);
|
984
|
+
} catch (error) {
|
985
|
+
if (error.code === "ENOENT") {
|
986
|
+
cache.removeKey(fPath);
|
987
|
+
}
|
988
|
+
}
|
989
|
+
}
|
990
|
+
};
|
991
|
+
removeNotFoundFiles();
|
992
|
+
return {
|
993
|
+
/**
|
994
|
+
* The flat cache storage used to persist the metadata of the `files
|
995
|
+
* @type {Object}
|
996
|
+
*/
|
997
|
+
cache,
|
998
|
+
/**
|
999
|
+
* Given a buffer, calculate md5 hash of its content.
|
1000
|
+
* @method getHash
|
1001
|
+
* @param {Buffer} buffer buffer to calculate hash on
|
1002
|
+
* @return {String} content hash digest
|
1003
|
+
*/
|
1004
|
+
getHash(buffer) {
|
1005
|
+
return crypto.createHash("md5").update(buffer).digest("hex");
|
1006
|
+
},
|
1007
|
+
/**
|
1008
|
+
* Return whether or not a file has changed since last time reconcile was called.
|
1009
|
+
* @method hasFileChanged
|
1010
|
+
* @param {String} file the filepath to check
|
1011
|
+
* @return {Boolean} wheter or not the file has changed
|
1012
|
+
*/
|
1013
|
+
hasFileChanged(file) {
|
1014
|
+
return this.getFileDescriptor(file).changed;
|
1015
|
+
},
|
1016
|
+
/**
|
1017
|
+
* Given an array of file paths it return and object with three arrays:
|
1018
|
+
* - changedFiles: Files that changed since previous run
|
1019
|
+
* - notChangedFiles: Files that haven't change
|
1020
|
+
* - notFoundFiles: Files that were not found, probably deleted
|
1021
|
+
*
|
1022
|
+
* @param {Array} files the files to analyze and compare to the previous seen files
|
1023
|
+
* @return {[type]} [description]
|
1024
|
+
*/
|
1025
|
+
analyzeFiles(files) {
|
1026
|
+
const me = this;
|
1027
|
+
files || (files = []);
|
1028
|
+
const res = {
|
1029
|
+
changedFiles: [],
|
1030
|
+
notFoundFiles: [],
|
1031
|
+
notChangedFiles: []
|
1032
|
+
};
|
1033
|
+
for (const entry of me.normalizeEntries(files)) {
|
1034
|
+
if (entry.changed) {
|
1035
|
+
res.changedFiles.push(entry.key);
|
1036
|
+
continue;
|
1037
|
+
}
|
1038
|
+
if (entry.notFound) {
|
1039
|
+
res.notFoundFiles.push(entry.key);
|
1040
|
+
continue;
|
1041
|
+
}
|
1042
|
+
res.notChangedFiles.push(entry.key);
|
1043
|
+
}
|
1044
|
+
return res;
|
1045
|
+
},
|
1046
|
+
getFileDescriptor(file) {
|
1047
|
+
let fstat;
|
1048
|
+
try {
|
1049
|
+
if (!path10.isAbsolute(file)) {
|
1050
|
+
file = path10.resolve(process5.cwd(), file);
|
1051
|
+
}
|
1052
|
+
fstat = fs6.statSync(file);
|
1053
|
+
} catch (error) {
|
1054
|
+
this.removeEntry(file);
|
1055
|
+
return { key: file, notFound: true, err: error };
|
1056
|
+
}
|
1057
|
+
if (useChecksum) {
|
1058
|
+
return this._getFileDescriptorUsingChecksum(file);
|
1059
|
+
}
|
1060
|
+
return this._getFileDescriptorUsingMtimeAndSize(file, fstat);
|
1061
|
+
},
|
1062
|
+
_getFileDescriptorUsingMtimeAndSize(file, fstat) {
|
1063
|
+
let meta = cache.getKey(file);
|
1064
|
+
const cacheExists = Boolean(meta);
|
1065
|
+
const cSize = fstat.size;
|
1066
|
+
const cTime = fstat.mtime.getTime();
|
1067
|
+
let isDifferentDate;
|
1068
|
+
let isDifferentSize;
|
1069
|
+
if (meta) {
|
1070
|
+
isDifferentDate = cTime !== meta.mtime;
|
1071
|
+
isDifferentSize = cSize !== meta.size;
|
1072
|
+
} else {
|
1073
|
+
meta = { size: cSize, mtime: cTime };
|
1074
|
+
}
|
1075
|
+
const nEntry = normalizedEntries[file] = {
|
1076
|
+
key: file,
|
1077
|
+
changed: !cacheExists || isDifferentDate || isDifferentSize,
|
1078
|
+
meta
|
1079
|
+
};
|
1080
|
+
return nEntry;
|
1081
|
+
},
|
1082
|
+
_getFileDescriptorUsingChecksum(file) {
|
1083
|
+
let meta = cache.getKey(file);
|
1084
|
+
const cacheExists = Boolean(meta);
|
1085
|
+
let contentBuffer;
|
1086
|
+
try {
|
1087
|
+
contentBuffer = fs6.readFileSync(file);
|
1088
|
+
} catch {
|
1089
|
+
contentBuffer = "";
|
1090
|
+
}
|
1091
|
+
let isDifferent = true;
|
1092
|
+
const hash = this.getHash(contentBuffer);
|
1093
|
+
if (meta) {
|
1094
|
+
isDifferent = hash !== meta.hash;
|
1095
|
+
} else {
|
1096
|
+
meta = { hash };
|
1097
|
+
}
|
1098
|
+
const nEntry = normalizedEntries[file] = {
|
1099
|
+
key: file,
|
1100
|
+
changed: !cacheExists || isDifferent,
|
1101
|
+
meta
|
1102
|
+
};
|
1103
|
+
return nEntry;
|
1104
|
+
},
|
1105
|
+
/**
|
1106
|
+
* Return the list o the files that changed compared
|
1107
|
+
* against the ones stored in the cache
|
1108
|
+
*
|
1109
|
+
* @method getUpdated
|
1110
|
+
* @param files {Array} the array of files to compare against the ones in the cache
|
1111
|
+
* @returns {Array}
|
1112
|
+
*/
|
1113
|
+
getUpdatedFiles(files) {
|
1114
|
+
const me = this;
|
1115
|
+
files || (files = []);
|
1116
|
+
return me.normalizeEntries(files).filter((entry) => entry.changed).map((entry) => entry.key);
|
1117
|
+
},
|
1118
|
+
/**
|
1119
|
+
* Return the list of files
|
1120
|
+
* @method normalizeEntries
|
1121
|
+
* @param files
|
1122
|
+
* @returns {*}
|
1123
|
+
*/
|
1124
|
+
normalizeEntries(files) {
|
1125
|
+
files || (files = []);
|
1126
|
+
const me = this;
|
1127
|
+
const nEntries = files.map((file) => me.getFileDescriptor(file));
|
1128
|
+
return nEntries;
|
1129
|
+
},
|
1130
|
+
/**
|
1131
|
+
* Remove an entry from the file-entry-cache. Useful to force the file to still be considered
|
1132
|
+
* modified the next time the process is run
|
1133
|
+
*
|
1134
|
+
* @method removeEntry
|
1135
|
+
* @param entryName
|
1136
|
+
*/
|
1137
|
+
removeEntry(entryName) {
|
1138
|
+
if (!path10.isAbsolute(entryName)) {
|
1139
|
+
entryName = path10.resolve(process5.cwd(), entryName);
|
1140
|
+
}
|
1141
|
+
delete normalizedEntries[entryName];
|
1142
|
+
cache.removeKey(entryName);
|
1143
|
+
},
|
1144
|
+
/**
|
1145
|
+
* Delete the cache file from the disk
|
1146
|
+
* @method deleteCacheFile
|
1147
|
+
*/
|
1148
|
+
deleteCacheFile() {
|
1149
|
+
cache.removeCacheFile();
|
1150
|
+
},
|
1151
|
+
/**
|
1152
|
+
* Remove the cache from the file and clear the memory cache
|
1153
|
+
*/
|
1154
|
+
destroy() {
|
1155
|
+
normalizedEntries = {};
|
1156
|
+
cache.destroy();
|
1157
|
+
},
|
1158
|
+
_getMetaForFileUsingCheckSum(cacheEntry) {
|
1159
|
+
const contentBuffer = fs6.readFileSync(cacheEntry.key);
|
1160
|
+
const hash = this.getHash(contentBuffer);
|
1161
|
+
const meta = Object.assign(cacheEntry.meta, { hash });
|
1162
|
+
delete meta.size;
|
1163
|
+
delete meta.mtime;
|
1164
|
+
return meta;
|
1165
|
+
},
|
1166
|
+
_getMetaForFileUsingMtimeAndSize(cacheEntry) {
|
1167
|
+
const stat = fs6.statSync(cacheEntry.key);
|
1168
|
+
const meta = Object.assign(cacheEntry.meta, {
|
1169
|
+
size: stat.size,
|
1170
|
+
mtime: stat.mtime.getTime()
|
1171
|
+
});
|
1172
|
+
delete meta.hash;
|
1173
|
+
return meta;
|
1174
|
+
},
|
1175
|
+
/**
|
1176
|
+
* Sync the files and persist them to the cache
|
1177
|
+
* @method reconcile
|
1178
|
+
*/
|
1179
|
+
reconcile(noPrune) {
|
1180
|
+
removeNotFoundFiles();
|
1181
|
+
noPrune = noPrune === void 0 ? true : noPrune;
|
1182
|
+
const entries = normalizedEntries;
|
1183
|
+
const keys = Object.keys(entries);
|
1184
|
+
if (keys.length === 0) {
|
1185
|
+
return;
|
1186
|
+
}
|
1187
|
+
const me = this;
|
1188
|
+
for (const entryName of keys) {
|
1189
|
+
const cacheEntry = entries[entryName];
|
1190
|
+
try {
|
1191
|
+
const meta = useChecksum ? me._getMetaForFileUsingCheckSum(cacheEntry) : me._getMetaForFileUsingMtimeAndSize(cacheEntry);
|
1192
|
+
cache.setKey(entryName, meta);
|
1193
|
+
} catch (error) {
|
1194
|
+
if (error.code !== "ENOENT") {
|
1195
|
+
throw error;
|
1196
|
+
}
|
1197
|
+
}
|
1198
|
+
}
|
1199
|
+
cache.save(noPrune);
|
1200
|
+
}
|
1201
|
+
};
|
1202
|
+
}
|
1203
|
+
};
|
1204
|
+
}
|
1205
|
+
});
|
1206
|
+
|
1207
|
+
// node_modules/wcwidth.js/combining.js
|
1208
|
+
var require_combining = __commonJS({
|
1209
|
+
"node_modules/wcwidth.js/combining.js"(exports, module) {
|
1210
|
+
module.exports = [
|
1211
|
+
[768, 879],
|
1212
|
+
[1155, 1158],
|
1213
|
+
[1160, 1161],
|
1214
|
+
[1425, 1469],
|
1215
|
+
[1471, 1471],
|
1216
|
+
[1473, 1474],
|
1217
|
+
[1476, 1477],
|
1218
|
+
[1479, 1479],
|
1219
|
+
[1536, 1539],
|
1220
|
+
[1552, 1557],
|
1221
|
+
[1611, 1630],
|
1222
|
+
[1648, 1648],
|
1223
|
+
[1750, 1764],
|
1224
|
+
[1767, 1768],
|
1225
|
+
[1770, 1773],
|
1226
|
+
[1807, 1807],
|
1227
|
+
[1809, 1809],
|
1228
|
+
[1840, 1866],
|
1229
|
+
[1958, 1968],
|
1230
|
+
[2027, 2035],
|
1231
|
+
[2305, 2306],
|
1232
|
+
[2364, 2364],
|
1233
|
+
[2369, 2376],
|
1234
|
+
[2381, 2381],
|
1235
|
+
[2385, 2388],
|
1236
|
+
[2402, 2403],
|
1237
|
+
[2433, 2433],
|
1238
|
+
[2492, 2492],
|
1239
|
+
[2497, 2500],
|
1240
|
+
[2509, 2509],
|
1241
|
+
[2530, 2531],
|
1242
|
+
[2561, 2562],
|
1243
|
+
[2620, 2620],
|
1244
|
+
[2625, 2626],
|
1245
|
+
[2631, 2632],
|
1246
|
+
[2635, 2637],
|
1247
|
+
[2672, 2673],
|
1248
|
+
[2689, 2690],
|
1249
|
+
[2748, 2748],
|
1250
|
+
[2753, 2757],
|
1251
|
+
[2759, 2760],
|
1252
|
+
[2765, 2765],
|
1253
|
+
[2786, 2787],
|
1254
|
+
[2817, 2817],
|
1255
|
+
[2876, 2876],
|
1256
|
+
[2879, 2879],
|
1257
|
+
[2881, 2883],
|
1258
|
+
[2893, 2893],
|
1259
|
+
[2902, 2902],
|
1260
|
+
[2946, 2946],
|
1261
|
+
[3008, 3008],
|
1262
|
+
[3021, 3021],
|
1263
|
+
[3134, 3136],
|
1264
|
+
[3142, 3144],
|
1265
|
+
[3146, 3149],
|
1266
|
+
[3157, 3158],
|
1267
|
+
[3260, 3260],
|
1268
|
+
[3263, 3263],
|
1269
|
+
[3270, 3270],
|
1270
|
+
[3276, 3277],
|
1271
|
+
[3298, 3299],
|
1272
|
+
[3393, 3395],
|
1273
|
+
[3405, 3405],
|
1274
|
+
[3530, 3530],
|
1275
|
+
[3538, 3540],
|
1276
|
+
[3542, 3542],
|
1277
|
+
[3633, 3633],
|
1278
|
+
[3636, 3642],
|
1279
|
+
[3655, 3662],
|
1280
|
+
[3761, 3761],
|
1281
|
+
[3764, 3769],
|
1282
|
+
[3771, 3772],
|
1283
|
+
[3784, 3789],
|
1284
|
+
[3864, 3865],
|
1285
|
+
[3893, 3893],
|
1286
|
+
[3895, 3895],
|
1287
|
+
[3897, 3897],
|
1288
|
+
[3953, 3966],
|
1289
|
+
[3968, 3972],
|
1290
|
+
[3974, 3975],
|
1291
|
+
[3984, 3991],
|
1292
|
+
[3993, 4028],
|
1293
|
+
[4038, 4038],
|
1294
|
+
[4141, 4144],
|
1295
|
+
[4146, 4146],
|
1296
|
+
[4150, 4151],
|
1297
|
+
[4153, 4153],
|
1298
|
+
[4184, 4185],
|
1299
|
+
[4448, 4607],
|
1300
|
+
[4959, 4959],
|
1301
|
+
[5906, 5908],
|
1302
|
+
[5938, 5940],
|
1303
|
+
[5970, 5971],
|
1304
|
+
[6002, 6003],
|
1305
|
+
[6068, 6069],
|
1306
|
+
[6071, 6077],
|
1307
|
+
[6086, 6086],
|
1308
|
+
[6089, 6099],
|
1309
|
+
[6109, 6109],
|
1310
|
+
[6155, 6157],
|
1311
|
+
[6313, 6313],
|
1312
|
+
[6432, 6434],
|
1313
|
+
[6439, 6440],
|
1314
|
+
[6450, 6450],
|
1315
|
+
[6457, 6459],
|
1316
|
+
[6679, 6680],
|
1317
|
+
[6912, 6915],
|
1318
|
+
[6964, 6964],
|
1319
|
+
[6966, 6970],
|
1320
|
+
[6972, 6972],
|
1321
|
+
[6978, 6978],
|
1322
|
+
[7019, 7027],
|
1323
|
+
[7616, 7626],
|
1324
|
+
[7678, 7679],
|
1325
|
+
[8203, 8207],
|
1326
|
+
[8234, 8238],
|
1327
|
+
[8288, 8291],
|
1328
|
+
[8298, 8303],
|
1329
|
+
[8400, 8431],
|
1330
|
+
[12330, 12335],
|
1331
|
+
[12441, 12442],
|
1332
|
+
[43014, 43014],
|
1333
|
+
[43019, 43019],
|
1334
|
+
[43045, 43046],
|
1335
|
+
[64286, 64286],
|
1336
|
+
[65024, 65039],
|
1337
|
+
[65056, 65059],
|
1338
|
+
[65279, 65279],
|
1339
|
+
[65529, 65531],
|
1340
|
+
[68097, 68099],
|
1341
|
+
[68101, 68102],
|
1342
|
+
[68108, 68111],
|
1343
|
+
[68152, 68154],
|
1344
|
+
[68159, 68159],
|
1345
|
+
[119143, 119145],
|
1346
|
+
[119155, 119170],
|
1347
|
+
[119173, 119179],
|
1348
|
+
[119210, 119213],
|
1349
|
+
[119362, 119364],
|
1350
|
+
[917505, 917505],
|
1351
|
+
[917536, 917631],
|
1352
|
+
[917760, 917999]
|
1353
|
+
];
|
1354
|
+
}
|
1355
|
+
});
|
1356
|
+
|
1357
|
+
// node_modules/wcwidth.js/index.js
|
1358
|
+
var require_wcwidth = __commonJS({
|
1359
|
+
"node_modules/wcwidth.js/index.js"(exports, module) {
|
1360
|
+
var combining = require_combining();
|
1361
|
+
var DEFAULTS = {
|
1362
|
+
nul: 0,
|
1363
|
+
control: 0
|
1364
|
+
};
|
1365
|
+
function bisearch(ucs) {
|
1366
|
+
let min = 0;
|
1367
|
+
let max = combining.length - 1;
|
1368
|
+
let mid;
|
1369
|
+
if (ucs < combining[0][0] || ucs > combining[max][1]) return false;
|
1370
|
+
while (max >= min) {
|
1371
|
+
mid = Math.floor((min + max) / 2);
|
1372
|
+
if (ucs > combining[mid][1]) min = mid + 1;
|
1373
|
+
else if (ucs < combining[mid][0]) max = mid - 1;
|
1374
|
+
else return true;
|
1375
|
+
}
|
1376
|
+
return false;
|
1377
|
+
}
|
1378
|
+
function wcwidth2(ucs, opts) {
|
1379
|
+
if (ucs === 0) return opts.nul;
|
1380
|
+
if (ucs < 32 || ucs >= 127 && ucs < 160) return opts.control;
|
1381
|
+
if (bisearch(ucs)) return 0;
|
1382
|
+
return 1 + (ucs >= 4352 && (ucs <= 4447 || // Hangul Jamo init. consonants
|
1383
|
+
ucs == 9001 || ucs == 9002 || ucs >= 11904 && ucs <= 42191 && ucs != 12351 || // CJK ... Yi
|
1384
|
+
ucs >= 44032 && ucs <= 55203 || // Hangul Syllables
|
1385
|
+
ucs >= 63744 && ucs <= 64255 || // CJK Compatibility Ideographs
|
1386
|
+
ucs >= 65040 && ucs <= 65049 || // Vertical forms
|
1387
|
+
ucs >= 65072 && ucs <= 65135 || // CJK Compatibility Forms
|
1388
|
+
ucs >= 65280 && ucs <= 65376 || // Fullwidth Forms
|
1389
|
+
ucs >= 65504 && ucs <= 65510 || ucs >= 131072 && ucs <= 196605 || ucs >= 196608 && ucs <= 262141));
|
1390
|
+
}
|
1391
|
+
function wcswidth(str, opts) {
|
1392
|
+
let h;
|
1393
|
+
let l;
|
1394
|
+
let s = 0;
|
1395
|
+
let n;
|
1396
|
+
if (typeof str !== "string") return wcwidth2(str, opts);
|
1397
|
+
for (let i = 0; i < str.length; i++) {
|
1398
|
+
h = str.charCodeAt(i);
|
1399
|
+
if (h >= 55296 && h <= 56319) {
|
1400
|
+
l = str.charCodeAt(++i);
|
1401
|
+
if (l >= 56320 && l <= 57343) {
|
1402
|
+
h = (h - 55296) * 1024 + (l - 56320) + 65536;
|
1403
|
+
} else {
|
1404
|
+
i--;
|
1405
|
+
}
|
1406
|
+
}
|
1407
|
+
n = wcwidth2(h, opts);
|
1408
|
+
if (n < 0) return -1;
|
1409
|
+
s += n;
|
1410
|
+
}
|
1411
|
+
return s;
|
1412
|
+
}
|
1413
|
+
module.exports = (str) => wcswidth(str, DEFAULTS);
|
1414
|
+
module.exports.config = (opts = {}) => {
|
1415
|
+
opts = {
|
1416
|
+
...DEFAULTS,
|
1417
|
+
...opts
|
1418
|
+
};
|
1419
|
+
return (str) => wcswidth(str, opts);
|
1420
|
+
};
|
1421
|
+
}
|
1422
|
+
});
|
1423
|
+
|
1424
|
+
// src/cli/index.js
|
1425
|
+
import * as prettier2 from "../index.mjs";
|
1426
|
+
|
1427
|
+
// scripts/build/shims/at.js
|
1428
|
+
var at = (isOptionalObject, object, index) => {
|
1429
|
+
if (isOptionalObject && (object === void 0 || object === null)) {
|
1430
|
+
return;
|
1431
|
+
}
|
1432
|
+
if (Array.isArray(object) || typeof object === "string") {
|
1433
|
+
return object[index < 0 ? object.length + index : index];
|
1434
|
+
}
|
1435
|
+
return object.at(index);
|
1436
|
+
};
|
1437
|
+
var at_default = at;
|
1438
|
+
|
1439
|
+
// src/cli/options/get-context-options.js
|
1440
|
+
var import_dashify = __toESM(require_dashify(), 1);
|
1441
|
+
import { getSupportInfo } from "../index.mjs";
|
1442
|
+
|
1443
|
+
// src/cli/cli-options.evaluate.js
|
1444
|
+
var cli_options_evaluate_default = {
|
1445
|
+
"cache": {
|
1446
|
+
"default": false,
|
1447
|
+
"description": "Only format changed files. Cannot use with --stdin-filepath.",
|
1448
|
+
"type": "boolean"
|
1449
|
+
},
|
1450
|
+
"cacheLocation": {
|
1451
|
+
"description": "Path to the cache file.",
|
1452
|
+
"type": "path"
|
1453
|
+
},
|
1454
|
+
"cacheStrategy": {
|
1455
|
+
"choices": [
|
1456
|
+
{
|
1457
|
+
"description": "Use the file metadata such as timestamps as cache keys",
|
1458
|
+
"value": "metadata"
|
1459
|
+
},
|
1460
|
+
{
|
1461
|
+
"description": "Use the file content as cache keys",
|
1462
|
+
"value": "content"
|
1463
|
+
}
|
1464
|
+
],
|
1465
|
+
"description": "Strategy for the cache to use for detecting changed files.",
|
1466
|
+
"type": "choice"
|
1467
|
+
},
|
1468
|
+
"check": {
|
1469
|
+
"alias": "c",
|
1470
|
+
"category": "Output",
|
1471
|
+
"description": "Check if the given files are formatted, print a human-friendly summary\nmessage and paths to unformatted files (see also --list-different).",
|
1472
|
+
"type": "boolean"
|
1473
|
+
},
|
1474
|
+
"color": {
|
1475
|
+
"default": true,
|
1476
|
+
"description": "Colorize error messages.",
|
1477
|
+
"oppositeDescription": "Do not colorize error messages.",
|
1478
|
+
"type": "boolean"
|
1479
|
+
},
|
1480
|
+
"config": {
|
1481
|
+
"category": "Config",
|
1482
|
+
"description": "Path to a Prettier configuration file (.prettierrc, package.json, prettier.config.js).",
|
1483
|
+
"exception": (value) => value === false,
|
1484
|
+
"oppositeDescription": "Do not look for a configuration file.",
|
1485
|
+
"type": "path"
|
1486
|
+
},
|
1487
|
+
"configPrecedence": {
|
1488
|
+
"category": "Config",
|
1489
|
+
"choices": [
|
1490
|
+
{
|
1491
|
+
"description": "CLI options take precedence over config file",
|
1492
|
+
"value": "cli-override"
|
1493
|
+
},
|
1494
|
+
{
|
1495
|
+
"description": "Config file take precedence over CLI options",
|
1496
|
+
"value": "file-override"
|
1497
|
+
},
|
1498
|
+
{
|
1499
|
+
"description": "If a config file is found will evaluate it and ignore other CLI options.\nIf no config file is found CLI options will evaluate as normal.",
|
1500
|
+
"value": "prefer-file"
|
1501
|
+
}
|
1502
|
+
],
|
1503
|
+
"default": "cli-override",
|
1504
|
+
"description": "Define in which order config files and CLI options should be evaluated.",
|
1505
|
+
"type": "choice"
|
1506
|
+
},
|
1507
|
+
"debugBenchmark": {
|
1508
|
+
"type": "boolean"
|
1509
|
+
},
|
1510
|
+
"debugCheck": {
|
1511
|
+
"type": "boolean"
|
1512
|
+
},
|
1513
|
+
"debugPrintAst": {
|
1514
|
+
"type": "boolean"
|
1515
|
+
},
|
1516
|
+
"debugPrintComments": {
|
1517
|
+
"type": "boolean"
|
1518
|
+
},
|
1519
|
+
"debugPrintDoc": {
|
1520
|
+
"type": "boolean"
|
1521
|
+
},
|
1522
|
+
"debugRepeat": {
|
1523
|
+
"default": 0,
|
1524
|
+
"type": "int"
|
1525
|
+
},
|
1526
|
+
"editorconfig": {
|
1527
|
+
"category": "Config",
|
1528
|
+
"default": true,
|
1529
|
+
"description": "Take .editorconfig into account when parsing configuration.",
|
1530
|
+
"oppositeDescription": "Don't take .editorconfig into account when parsing configuration.",
|
1531
|
+
"type": "boolean"
|
1532
|
+
},
|
1533
|
+
"errorOnUnmatchedPattern": {
|
1534
|
+
"oppositeDescription": "Prevent errors when pattern is unmatched.",
|
1535
|
+
"type": "boolean"
|
1536
|
+
},
|
1537
|
+
"fileInfo": {
|
1538
|
+
"description": "Extract the following info (as JSON) for a given file path. Reported fields:\n* ignored (boolean) - true if file path is filtered by --ignore-path\n* inferredParser (string | null) - name of parser inferred from file path",
|
1539
|
+
"type": "path"
|
1540
|
+
},
|
1541
|
+
"findConfigPath": {
|
1542
|
+
"category": "Config",
|
1543
|
+
"description": "Find and print the path to a configuration file for the given input file.",
|
1544
|
+
"type": "path"
|
1545
|
+
},
|
1546
|
+
"help": {
|
1547
|
+
"alias": "h",
|
1548
|
+
"description": "Show CLI usage, or details about the given flag.\nExample: --help write",
|
1549
|
+
"exception": (value) => value === "",
|
1550
|
+
"type": "flag"
|
1551
|
+
},
|
1552
|
+
"ignorePath": {
|
1553
|
+
"array": true,
|
1554
|
+
"category": "Config",
|
1555
|
+
"default": [
|
1556
|
+
{
|
1557
|
+
"value": [
|
1558
|
+
".gitignore",
|
1559
|
+
".prettierignore"
|
1560
|
+
]
|
1561
|
+
}
|
1562
|
+
],
|
1563
|
+
"description": "Path to a file with patterns describing files to ignore.\nMultiple values are accepted.",
|
1564
|
+
"type": "path"
|
1565
|
+
},
|
1566
|
+
"ignoreUnknown": {
|
1567
|
+
"alias": "u",
|
1568
|
+
"description": "Ignore unknown files.",
|
1569
|
+
"type": "boolean"
|
1570
|
+
},
|
1571
|
+
"listDifferent": {
|
1572
|
+
"alias": "l",
|
1573
|
+
"category": "Output",
|
1574
|
+
"description": "Print the names of files that are different from Prettier's formatting (see also --check).",
|
1575
|
+
"type": "boolean"
|
1576
|
+
},
|
1577
|
+
"logLevel": {
|
1578
|
+
"choices": [
|
1579
|
+
"silent",
|
1580
|
+
"error",
|
1581
|
+
"warn",
|
1582
|
+
"log",
|
1583
|
+
"debug"
|
1584
|
+
],
|
1585
|
+
"default": "log",
|
1586
|
+
"description": "What level of logs to report.",
|
1587
|
+
"type": "choice"
|
1588
|
+
},
|
1589
|
+
"supportInfo": {
|
1590
|
+
"description": "Print support information as JSON.",
|
1591
|
+
"type": "boolean"
|
1592
|
+
},
|
1593
|
+
"version": {
|
1594
|
+
"alias": "v",
|
1595
|
+
"description": "Print Prettier version.",
|
1596
|
+
"type": "boolean"
|
1597
|
+
},
|
1598
|
+
"withNodeModules": {
|
1599
|
+
"category": "Config",
|
1600
|
+
"description": "Process files inside 'node_modules' directory.",
|
1601
|
+
"type": "boolean"
|
1602
|
+
},
|
1603
|
+
"write": {
|
1604
|
+
"alias": "w",
|
1605
|
+
"category": "Output",
|
1606
|
+
"description": "Edit files in-place. (Beware!)",
|
1607
|
+
"type": "boolean"
|
1608
|
+
}
|
1609
|
+
};
|
1610
|
+
|
1611
|
+
// src/cli/prettier-internal.js
|
1612
|
+
import { __internal as sharedWithCli } from "../index.mjs";
|
1613
|
+
var {
|
1614
|
+
errors,
|
1615
|
+
optionCategories,
|
1616
|
+
createIsIgnoredFunction,
|
1617
|
+
formatOptionsHiddenDefaults,
|
1618
|
+
normalizeOptions,
|
1619
|
+
getSupportInfoWithoutPlugins,
|
1620
|
+
normalizeOptionSettings,
|
1621
|
+
vnopts,
|
1622
|
+
fastGlob,
|
1623
|
+
createTwoFilesPatch,
|
1624
|
+
mockable
|
1625
|
+
} = sharedWithCli;
|
1626
|
+
|
1627
|
+
// src/cli/options/get-context-options.js
|
1628
|
+
var detailedCliOptions = normalizeOptionSettings(cli_options_evaluate_default).map(
|
1629
|
+
(option) => normalizeDetailedOption(option)
|
1630
|
+
);
|
1631
|
+
function apiOptionToCliOption(apiOption) {
|
1632
|
+
const cliOption = {
|
1633
|
+
...apiOption,
|
1634
|
+
description: apiOption.cliDescription ?? apiOption.description,
|
1635
|
+
category: apiOption.cliCategory ?? optionCategories.CATEGORY_FORMAT,
|
1636
|
+
forwardToApi: apiOption.name
|
1637
|
+
};
|
1638
|
+
if (apiOption.deprecated) {
|
1639
|
+
delete cliOption.forwardToApi;
|
1640
|
+
delete cliOption.description;
|
1641
|
+
delete cliOption.oppositeDescription;
|
1642
|
+
cliOption.deprecated = true;
|
1643
|
+
}
|
1644
|
+
return normalizeDetailedOption(cliOption);
|
1645
|
+
}
|
1646
|
+
function normalizeDetailedOption(option) {
|
1647
|
+
var _a;
|
1648
|
+
return {
|
1649
|
+
category: optionCategories.CATEGORY_OTHER,
|
1650
|
+
...option,
|
1651
|
+
name: option.cliName ?? (0, import_dashify.default)(option.name),
|
1652
|
+
choices: (_a = option.choices) == null ? void 0 : _a.map((choice) => {
|
1653
|
+
const newChoice = {
|
1654
|
+
description: "",
|
1655
|
+
deprecated: false,
|
1656
|
+
...typeof choice === "object" ? choice : { value: choice }
|
1657
|
+
};
|
1658
|
+
if (newChoice.value === true) {
|
1659
|
+
newChoice.value = "";
|
1660
|
+
}
|
1661
|
+
return newChoice;
|
1662
|
+
})
|
1663
|
+
};
|
1664
|
+
}
|
1665
|
+
function supportInfoToContextOptions({ options: supportOptions, languages }) {
|
1666
|
+
const detailedOptions = [
|
1667
|
+
...detailedCliOptions,
|
1668
|
+
...supportOptions.map((apiOption) => apiOptionToCliOption(apiOption))
|
1669
|
+
];
|
1670
|
+
return {
|
1671
|
+
supportOptions,
|
1672
|
+
languages,
|
1673
|
+
detailedOptions
|
1674
|
+
};
|
1675
|
+
}
|
1676
|
+
async function getContextOptions(plugins) {
|
1677
|
+
const supportInfo = await getSupportInfo({
|
1678
|
+
showDeprecated: true,
|
1679
|
+
plugins
|
1680
|
+
});
|
1681
|
+
return supportInfoToContextOptions(supportInfo);
|
1682
|
+
}
|
1683
|
+
function getContextOptionsWithoutPlugins() {
|
1684
|
+
const supportInfo = getSupportInfoWithoutPlugins();
|
1685
|
+
return supportInfoToContextOptions(supportInfo);
|
1686
|
+
}
|
1687
|
+
|
1688
|
+
// scripts/build/shims/string-replace-all.js
|
1689
|
+
var stringReplaceAll = (isOptionalObject, original, pattern, replacement) => {
|
1690
|
+
if (isOptionalObject && (original === void 0 || original === null)) {
|
1691
|
+
return;
|
1692
|
+
}
|
1693
|
+
if (original.replaceAll) {
|
1694
|
+
return original.replaceAll(pattern, replacement);
|
1695
|
+
}
|
1696
|
+
if (pattern.global) {
|
1697
|
+
return original.replace(pattern, replacement);
|
1698
|
+
}
|
1699
|
+
return original.split(pattern).join(replacement);
|
1700
|
+
};
|
1701
|
+
var string_replace_all_default = stringReplaceAll;
|
1702
|
+
|
1703
|
+
// node_modules/camelcase/index.js
|
1704
|
+
var UPPERCASE = /[\p{Lu}]/u;
|
1705
|
+
var LOWERCASE = /[\p{Ll}]/u;
|
1706
|
+
var LEADING_CAPITAL = /^[\p{Lu}](?![\p{Lu}])/gu;
|
1707
|
+
var IDENTIFIER = /([\p{Alpha}\p{N}_]|$)/u;
|
1708
|
+
var SEPARATORS = /[_.\- ]+/;
|
1709
|
+
var LEADING_SEPARATORS = new RegExp("^" + SEPARATORS.source);
|
1710
|
+
var SEPARATORS_AND_IDENTIFIER = new RegExp(SEPARATORS.source + IDENTIFIER.source, "gu");
|
1711
|
+
var NUMBERS_AND_IDENTIFIER = new RegExp("\\d+" + IDENTIFIER.source, "gu");
|
1712
|
+
var preserveCamelCase = (string, toLowerCase, toUpperCase, preserveConsecutiveUppercase2) => {
|
1713
|
+
let isLastCharLower = false;
|
1714
|
+
let isLastCharUpper = false;
|
1715
|
+
let isLastLastCharUpper = false;
|
1716
|
+
let isLastLastCharPreserved = false;
|
1717
|
+
for (let index = 0; index < string.length; index++) {
|
1718
|
+
const character = string[index];
|
1719
|
+
isLastLastCharPreserved = index > 2 ? string[index - 3] === "-" : true;
|
1720
|
+
if (isLastCharLower && UPPERCASE.test(character)) {
|
1721
|
+
string = string.slice(0, index) + "-" + string.slice(index);
|
1722
|
+
isLastCharLower = false;
|
1723
|
+
isLastLastCharUpper = isLastCharUpper;
|
1724
|
+
isLastCharUpper = true;
|
1725
|
+
index++;
|
1726
|
+
} else if (isLastCharUpper && isLastLastCharUpper && LOWERCASE.test(character) && (!isLastLastCharPreserved || preserveConsecutiveUppercase2)) {
|
1727
|
+
string = string.slice(0, index - 1) + "-" + string.slice(index - 1);
|
1728
|
+
isLastLastCharUpper = isLastCharUpper;
|
1729
|
+
isLastCharUpper = false;
|
1730
|
+
isLastCharLower = true;
|
1731
|
+
} else {
|
1732
|
+
isLastCharLower = toLowerCase(character) === character && toUpperCase(character) !== character;
|
1733
|
+
isLastLastCharUpper = isLastCharUpper;
|
1734
|
+
isLastCharUpper = toUpperCase(character) === character && toLowerCase(character) !== character;
|
1735
|
+
}
|
1736
|
+
}
|
1737
|
+
return string;
|
1738
|
+
};
|
1739
|
+
var preserveConsecutiveUppercase = (input, toLowerCase) => {
|
1740
|
+
LEADING_CAPITAL.lastIndex = 0;
|
1741
|
+
return string_replace_all_default(
|
1742
|
+
/* isOptionalObject */
|
1743
|
+
false,
|
1744
|
+
input,
|
1745
|
+
LEADING_CAPITAL,
|
1746
|
+
(match) => toLowerCase(match)
|
1747
|
+
);
|
1748
|
+
};
|
1749
|
+
var postProcess = (input, toUpperCase) => {
|
1750
|
+
SEPARATORS_AND_IDENTIFIER.lastIndex = 0;
|
1751
|
+
NUMBERS_AND_IDENTIFIER.lastIndex = 0;
|
1752
|
+
return string_replace_all_default(
|
1753
|
+
/* isOptionalObject */
|
1754
|
+
false,
|
1755
|
+
string_replace_all_default(
|
1756
|
+
/* isOptionalObject */
|
1757
|
+
false,
|
1758
|
+
input,
|
1759
|
+
NUMBERS_AND_IDENTIFIER,
|
1760
|
+
(match, pattern, offset) => ["_", "-"].includes(input.charAt(offset + match.length)) ? match : toUpperCase(match)
|
1761
|
+
),
|
1762
|
+
SEPARATORS_AND_IDENTIFIER,
|
1763
|
+
(_, identifier) => toUpperCase(identifier)
|
1764
|
+
);
|
1765
|
+
};
|
1766
|
+
function camelCase(input, options) {
|
1767
|
+
if (!(typeof input === "string" || Array.isArray(input))) {
|
1768
|
+
throw new TypeError("Expected the input to be `string | string[]`");
|
1769
|
+
}
|
1770
|
+
options = {
|
1771
|
+
pascalCase: false,
|
1772
|
+
preserveConsecutiveUppercase: false,
|
1773
|
+
...options
|
1774
|
+
};
|
1775
|
+
if (Array.isArray(input)) {
|
1776
|
+
input = input.map((x) => x.trim()).filter((x) => x.length).join("-");
|
1777
|
+
} else {
|
1778
|
+
input = input.trim();
|
1779
|
+
}
|
1780
|
+
if (input.length === 0) {
|
1781
|
+
return "";
|
1782
|
+
}
|
1783
|
+
const toLowerCase = options.locale === false ? (string) => string.toLowerCase() : (string) => string.toLocaleLowerCase(options.locale);
|
1784
|
+
const toUpperCase = options.locale === false ? (string) => string.toUpperCase() : (string) => string.toLocaleUpperCase(options.locale);
|
1785
|
+
if (input.length === 1) {
|
1786
|
+
if (SEPARATORS.test(input)) {
|
1787
|
+
return "";
|
1788
|
+
}
|
1789
|
+
return options.pascalCase ? toUpperCase(input) : toLowerCase(input);
|
1790
|
+
}
|
1791
|
+
const hasUpperCase = input !== toLowerCase(input);
|
1792
|
+
if (hasUpperCase) {
|
1793
|
+
input = preserveCamelCase(input, toLowerCase, toUpperCase, options.preserveConsecutiveUppercase);
|
1794
|
+
}
|
1795
|
+
input = input.replace(LEADING_SEPARATORS, "");
|
1796
|
+
input = options.preserveConsecutiveUppercase ? preserveConsecutiveUppercase(input, toLowerCase) : toLowerCase(input);
|
1797
|
+
if (options.pascalCase) {
|
1798
|
+
input = toUpperCase(input.charAt(0)) + input.slice(1);
|
1799
|
+
}
|
1800
|
+
return postProcess(input, toUpperCase);
|
1801
|
+
}
|
1802
|
+
|
1803
|
+
// src/cli/utils.js
|
1804
|
+
import fs from "fs/promises";
|
1805
|
+
import path from "path";
|
1806
|
+
|
1807
|
+
// node_modules/sdbm/index.js
|
1808
|
+
function sdbm(string) {
|
1809
|
+
let hash = 0;
|
1810
|
+
for (let i = 0; i < string.length; i++) {
|
1811
|
+
hash = string.charCodeAt(i) + (hash << 6) + (hash << 16) - hash;
|
1812
|
+
}
|
1813
|
+
return hash >>> 0;
|
1814
|
+
}
|
1815
|
+
|
1816
|
+
// src/cli/utils.js
|
1817
|
+
import { __internal as sharedWithCli2 } from "../index.mjs";
|
1818
|
+
var printToScreen = console.log.bind(console);
|
1819
|
+
function groupBy(array2, iteratee) {
|
1820
|
+
const result = /* @__PURE__ */ Object.create(null);
|
1821
|
+
for (const value of array2) {
|
1822
|
+
const key = iteratee(value);
|
1823
|
+
if (Array.isArray(result[key])) {
|
1824
|
+
result[key].push(value);
|
1825
|
+
} else {
|
1826
|
+
result[key] = [value];
|
1827
|
+
}
|
1828
|
+
}
|
1829
|
+
return result;
|
1830
|
+
}
|
1831
|
+
function pick(object, keys) {
|
1832
|
+
const entries = keys.map((key) => [key, object[key]]);
|
1833
|
+
return Object.fromEntries(entries);
|
1834
|
+
}
|
1835
|
+
function createHash(source) {
|
1836
|
+
return String(sdbm(source));
|
1837
|
+
}
|
1838
|
+
async function statSafe(filePath) {
|
1839
|
+
try {
|
1840
|
+
return await fs.stat(filePath);
|
1841
|
+
} catch (error) {
|
1842
|
+
if (error.code !== "ENOENT") {
|
1843
|
+
throw error;
|
1844
|
+
}
|
1845
|
+
}
|
1846
|
+
}
|
1847
|
+
async function lstatSafe(filePath) {
|
1848
|
+
try {
|
1849
|
+
return await fs.lstat(filePath);
|
1850
|
+
} catch (error) {
|
1851
|
+
if (error.code !== "ENOENT") {
|
1852
|
+
throw error;
|
1853
|
+
}
|
1854
|
+
}
|
1855
|
+
}
|
1856
|
+
function isJson(value) {
|
1857
|
+
try {
|
1858
|
+
JSON.parse(value);
|
1859
|
+
return true;
|
1860
|
+
} catch {
|
1861
|
+
return false;
|
1862
|
+
}
|
1863
|
+
}
|
1864
|
+
var normalizeToPosix = path.sep === "\\" ? (filepath) => string_replace_all_default(
|
1865
|
+
/* isOptionalObject */
|
1866
|
+
false,
|
1867
|
+
filepath,
|
1868
|
+
"\\",
|
1869
|
+
"/"
|
1870
|
+
) : (filepath) => filepath;
|
1871
|
+
var {
|
1872
|
+
isNonEmptyArray,
|
1873
|
+
partition,
|
1874
|
+
omit
|
1875
|
+
} = sharedWithCli2.utils;
|
1876
|
+
|
1877
|
+
// src/cli/options/create-minimist-options.js
|
1878
|
+
function createMinimistOptions(detailedOptions) {
|
1879
|
+
const booleanNames = [];
|
1880
|
+
const stringNames = [];
|
1881
|
+
const defaultValues = {};
|
1882
|
+
for (const option of detailedOptions) {
|
1883
|
+
const { name, alias, type } = option;
|
1884
|
+
const names = type === "boolean" ? booleanNames : stringNames;
|
1885
|
+
names.push(name);
|
1886
|
+
if (alias) {
|
1887
|
+
names.push(alias);
|
1888
|
+
}
|
1889
|
+
if (!option.deprecated && (!option.forwardToApi || name === "plugin") && option.default !== void 0) {
|
1890
|
+
defaultValues[option.name] = option.default;
|
1891
|
+
}
|
1892
|
+
}
|
1893
|
+
return {
|
1894
|
+
// we use vnopts' AliasSchema to handle aliases for better error messages
|
1895
|
+
alias: {},
|
1896
|
+
boolean: booleanNames,
|
1897
|
+
string: stringNames,
|
1898
|
+
default: defaultValues
|
1899
|
+
};
|
1900
|
+
}
|
1901
|
+
|
1902
|
+
// src/cli/options/minimist.js
|
1903
|
+
var import_minimist = __toESM(require_minimist(), 1);
|
1904
|
+
var PLACEHOLDER = null;
|
1905
|
+
function minimistParse(args, options) {
|
1906
|
+
const boolean = options.boolean ?? [];
|
1907
|
+
const defaults = options.default ?? {};
|
1908
|
+
const booleanWithoutDefault = boolean.filter((key) => !(key in defaults));
|
1909
|
+
const newDefaults = {
|
1910
|
+
...defaults,
|
1911
|
+
...Object.fromEntries(
|
1912
|
+
booleanWithoutDefault.map((key) => [key, PLACEHOLDER])
|
1913
|
+
)
|
1914
|
+
};
|
1915
|
+
const parsed = (0, import_minimist.default)(args, { ...options, default: newDefaults });
|
1916
|
+
return Object.fromEntries(
|
1917
|
+
Object.entries(parsed).filter(([, value]) => value !== PLACEHOLDER)
|
1918
|
+
);
|
1919
|
+
}
|
1920
|
+
|
1921
|
+
// node_modules/chalk/source/vendor/ansi-styles/index.js
|
1922
|
+
var ANSI_BACKGROUND_OFFSET = 10;
|
1923
|
+
var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
|
1924
|
+
var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
|
1925
|
+
var wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`;
|
1926
|
+
var styles = {
|
1927
|
+
modifier: {
|
1928
|
+
reset: [0, 0],
|
1929
|
+
// 21 isn't widely supported and 22 does the same thing
|
1930
|
+
bold: [1, 22],
|
1931
|
+
dim: [2, 22],
|
1932
|
+
italic: [3, 23],
|
1933
|
+
underline: [4, 24],
|
1934
|
+
overline: [53, 55],
|
1935
|
+
inverse: [7, 27],
|
1936
|
+
hidden: [8, 28],
|
1937
|
+
strikethrough: [9, 29]
|
1938
|
+
},
|
1939
|
+
color: {
|
1940
|
+
black: [30, 39],
|
1941
|
+
red: [31, 39],
|
1942
|
+
green: [32, 39],
|
1943
|
+
yellow: [33, 39],
|
1944
|
+
blue: [34, 39],
|
1945
|
+
magenta: [35, 39],
|
1946
|
+
cyan: [36, 39],
|
1947
|
+
white: [37, 39],
|
1948
|
+
// Bright color
|
1949
|
+
blackBright: [90, 39],
|
1950
|
+
gray: [90, 39],
|
1951
|
+
// Alias of `blackBright`
|
1952
|
+
grey: [90, 39],
|
1953
|
+
// Alias of `blackBright`
|
1954
|
+
redBright: [91, 39],
|
1955
|
+
greenBright: [92, 39],
|
1956
|
+
yellowBright: [93, 39],
|
1957
|
+
blueBright: [94, 39],
|
1958
|
+
magentaBright: [95, 39],
|
1959
|
+
cyanBright: [96, 39],
|
1960
|
+
whiteBright: [97, 39]
|
1961
|
+
},
|
1962
|
+
bgColor: {
|
1963
|
+
bgBlack: [40, 49],
|
1964
|
+
bgRed: [41, 49],
|
1965
|
+
bgGreen: [42, 49],
|
1966
|
+
bgYellow: [43, 49],
|
1967
|
+
bgBlue: [44, 49],
|
1968
|
+
bgMagenta: [45, 49],
|
1969
|
+
bgCyan: [46, 49],
|
1970
|
+
bgWhite: [47, 49],
|
1971
|
+
// Bright color
|
1972
|
+
bgBlackBright: [100, 49],
|
1973
|
+
bgGray: [100, 49],
|
1974
|
+
// Alias of `bgBlackBright`
|
1975
|
+
bgGrey: [100, 49],
|
1976
|
+
// Alias of `bgBlackBright`
|
1977
|
+
bgRedBright: [101, 49],
|
1978
|
+
bgGreenBright: [102, 49],
|
1979
|
+
bgYellowBright: [103, 49],
|
1980
|
+
bgBlueBright: [104, 49],
|
1981
|
+
bgMagentaBright: [105, 49],
|
1982
|
+
bgCyanBright: [106, 49],
|
1983
|
+
bgWhiteBright: [107, 49]
|
1984
|
+
}
|
1985
|
+
};
|
1986
|
+
var modifierNames = Object.keys(styles.modifier);
|
1987
|
+
var foregroundColorNames = Object.keys(styles.color);
|
1988
|
+
var backgroundColorNames = Object.keys(styles.bgColor);
|
1989
|
+
var colorNames = [...foregroundColorNames, ...backgroundColorNames];
|
1990
|
+
function assembleStyles() {
|
1991
|
+
const codes = /* @__PURE__ */ new Map();
|
1992
|
+
for (const [groupName, group] of Object.entries(styles)) {
|
1993
|
+
for (const [styleName, style] of Object.entries(group)) {
|
1994
|
+
styles[styleName] = {
|
1995
|
+
open: `\x1B[${style[0]}m`,
|
1996
|
+
close: `\x1B[${style[1]}m`
|
1997
|
+
};
|
1998
|
+
group[styleName] = styles[styleName];
|
1999
|
+
codes.set(style[0], style[1]);
|
2000
|
+
}
|
2001
|
+
Object.defineProperty(styles, groupName, {
|
2002
|
+
value: group,
|
2003
|
+
enumerable: false
|
2004
|
+
});
|
2005
|
+
}
|
2006
|
+
Object.defineProperty(styles, "codes", {
|
2007
|
+
value: codes,
|
2008
|
+
enumerable: false
|
2009
|
+
});
|
2010
|
+
styles.color.close = "\x1B[39m";
|
2011
|
+
styles.bgColor.close = "\x1B[49m";
|
2012
|
+
styles.color.ansi = wrapAnsi16();
|
2013
|
+
styles.color.ansi256 = wrapAnsi256();
|
2014
|
+
styles.color.ansi16m = wrapAnsi16m();
|
2015
|
+
styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
|
2016
|
+
styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
|
2017
|
+
styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
|
2018
|
+
Object.defineProperties(styles, {
|
2019
|
+
rgbToAnsi256: {
|
2020
|
+
value(red, green, blue) {
|
2021
|
+
if (red === green && green === blue) {
|
2022
|
+
if (red < 8) {
|
2023
|
+
return 16;
|
2024
|
+
}
|
2025
|
+
if (red > 248) {
|
2026
|
+
return 231;
|
2027
|
+
}
|
2028
|
+
return Math.round((red - 8) / 247 * 24) + 232;
|
2029
|
+
}
|
2030
|
+
return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
|
2031
|
+
},
|
2032
|
+
enumerable: false
|
2033
|
+
},
|
2034
|
+
hexToRgb: {
|
2035
|
+
value(hex) {
|
2036
|
+
const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
|
2037
|
+
if (!matches) {
|
2038
|
+
return [0, 0, 0];
|
2039
|
+
}
|
2040
|
+
let [colorString] = matches;
|
2041
|
+
if (colorString.length === 3) {
|
2042
|
+
colorString = [...colorString].map((character) => character + character).join("");
|
2043
|
+
}
|
2044
|
+
const integer = Number.parseInt(colorString, 16);
|
2045
|
+
return [
|
2046
|
+
/* eslint-disable no-bitwise */
|
2047
|
+
integer >> 16 & 255,
|
2048
|
+
integer >> 8 & 255,
|
2049
|
+
integer & 255
|
2050
|
+
/* eslint-enable no-bitwise */
|
2051
|
+
];
|
2052
|
+
},
|
2053
|
+
enumerable: false
|
2054
|
+
},
|
2055
|
+
hexToAnsi256: {
|
2056
|
+
value: (hex) => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
|
2057
|
+
enumerable: false
|
2058
|
+
},
|
2059
|
+
ansi256ToAnsi: {
|
2060
|
+
value(code) {
|
2061
|
+
if (code < 8) {
|
2062
|
+
return 30 + code;
|
2063
|
+
}
|
2064
|
+
if (code < 16) {
|
2065
|
+
return 90 + (code - 8);
|
2066
|
+
}
|
2067
|
+
let red;
|
2068
|
+
let green;
|
2069
|
+
let blue;
|
2070
|
+
if (code >= 232) {
|
2071
|
+
red = ((code - 232) * 10 + 8) / 255;
|
2072
|
+
green = red;
|
2073
|
+
blue = red;
|
2074
|
+
} else {
|
2075
|
+
code -= 16;
|
2076
|
+
const remainder = code % 36;
|
2077
|
+
red = Math.floor(code / 36) / 5;
|
2078
|
+
green = Math.floor(remainder / 6) / 5;
|
2079
|
+
blue = remainder % 6 / 5;
|
2080
|
+
}
|
2081
|
+
const value = Math.max(red, green, blue) * 2;
|
2082
|
+
if (value === 0) {
|
2083
|
+
return 30;
|
2084
|
+
}
|
2085
|
+
let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
|
2086
|
+
if (value === 2) {
|
2087
|
+
result += 60;
|
2088
|
+
}
|
2089
|
+
return result;
|
2090
|
+
},
|
2091
|
+
enumerable: false
|
2092
|
+
},
|
2093
|
+
rgbToAnsi: {
|
2094
|
+
value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
|
2095
|
+
enumerable: false
|
2096
|
+
},
|
2097
|
+
hexToAnsi: {
|
2098
|
+
value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
|
2099
|
+
enumerable: false
|
2100
|
+
}
|
2101
|
+
});
|
2102
|
+
return styles;
|
2103
|
+
}
|
2104
|
+
var ansiStyles = assembleStyles();
|
2105
|
+
var ansi_styles_default = ansiStyles;
|
2106
|
+
|
2107
|
+
// node_modules/chalk/source/vendor/supports-color/index.js
|
2108
|
+
import process2 from "process";
|
2109
|
+
import os from "os";
|
2110
|
+
import tty from "tty";
|
2111
|
+
function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process2.argv) {
|
2112
|
+
const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
|
2113
|
+
const position = argv.indexOf(prefix + flag);
|
2114
|
+
const terminatorPosition = argv.indexOf("--");
|
2115
|
+
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
|
2116
|
+
}
|
2117
|
+
var { env } = process2;
|
2118
|
+
var flagForceColor;
|
2119
|
+
if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
|
2120
|
+
flagForceColor = 0;
|
2121
|
+
} else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
|
2122
|
+
flagForceColor = 1;
|
2123
|
+
}
|
2124
|
+
function envForceColor() {
|
2125
|
+
if ("FORCE_COLOR" in env) {
|
2126
|
+
if (env.FORCE_COLOR === "true") {
|
2127
|
+
return 1;
|
2128
|
+
}
|
2129
|
+
if (env.FORCE_COLOR === "false") {
|
2130
|
+
return 0;
|
2131
|
+
}
|
2132
|
+
return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
|
2133
|
+
}
|
2134
|
+
}
|
2135
|
+
function translateLevel(level) {
|
2136
|
+
if (level === 0) {
|
2137
|
+
return false;
|
2138
|
+
}
|
2139
|
+
return {
|
2140
|
+
level,
|
2141
|
+
hasBasic: true,
|
2142
|
+
has256: level >= 2,
|
2143
|
+
has16m: level >= 3
|
2144
|
+
};
|
2145
|
+
}
|
2146
|
+
function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
|
2147
|
+
const noFlagForceColor = envForceColor();
|
2148
|
+
if (noFlagForceColor !== void 0) {
|
2149
|
+
flagForceColor = noFlagForceColor;
|
2150
|
+
}
|
2151
|
+
const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
|
2152
|
+
if (forceColor === 0) {
|
2153
|
+
return 0;
|
2154
|
+
}
|
2155
|
+
if (sniffFlags) {
|
2156
|
+
if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
|
2157
|
+
return 3;
|
2158
|
+
}
|
2159
|
+
if (hasFlag("color=256")) {
|
2160
|
+
return 2;
|
2161
|
+
}
|
2162
|
+
}
|
2163
|
+
if ("TF_BUILD" in env && "AGENT_NAME" in env) {
|
2164
|
+
return 1;
|
2165
|
+
}
|
2166
|
+
if (haveStream && !streamIsTTY && forceColor === void 0) {
|
2167
|
+
return 0;
|
2168
|
+
}
|
2169
|
+
const min = forceColor || 0;
|
2170
|
+
if (env.TERM === "dumb") {
|
2171
|
+
return min;
|
2172
|
+
}
|
2173
|
+
if (process2.platform === "win32") {
|
2174
|
+
const osRelease = os.release().split(".");
|
2175
|
+
if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
|
2176
|
+
return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
2177
|
+
}
|
2178
|
+
return 1;
|
2179
|
+
}
|
2180
|
+
if ("CI" in env) {
|
2181
|
+
if ("GITHUB_ACTIONS" in env || "GITEA_ACTIONS" in env) {
|
2182
|
+
return 3;
|
2183
|
+
}
|
2184
|
+
if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
|
2185
|
+
return 1;
|
2186
|
+
}
|
2187
|
+
return min;
|
2188
|
+
}
|
2189
|
+
if ("TEAMCITY_VERSION" in env) {
|
2190
|
+
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
2191
|
+
}
|
2192
|
+
if (env.COLORTERM === "truecolor") {
|
2193
|
+
return 3;
|
2194
|
+
}
|
2195
|
+
if (env.TERM === "xterm-kitty") {
|
2196
|
+
return 3;
|
2197
|
+
}
|
2198
|
+
if ("TERM_PROGRAM" in env) {
|
2199
|
+
const version2 = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
|
2200
|
+
switch (env.TERM_PROGRAM) {
|
2201
|
+
case "iTerm.app": {
|
2202
|
+
return version2 >= 3 ? 3 : 2;
|
2203
|
+
}
|
2204
|
+
case "Apple_Terminal": {
|
2205
|
+
return 2;
|
2206
|
+
}
|
2207
|
+
}
|
2208
|
+
}
|
2209
|
+
if (/-256(color)?$/i.test(env.TERM)) {
|
2210
|
+
return 2;
|
2211
|
+
}
|
2212
|
+
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
2213
|
+
return 1;
|
2214
|
+
}
|
2215
|
+
if ("COLORTERM" in env) {
|
2216
|
+
return 1;
|
2217
|
+
}
|
2218
|
+
return min;
|
2219
|
+
}
|
2220
|
+
function createSupportsColor(stream, options = {}) {
|
2221
|
+
const level = _supportsColor(stream, {
|
2222
|
+
streamIsTTY: stream && stream.isTTY,
|
2223
|
+
...options
|
2224
|
+
});
|
2225
|
+
return translateLevel(level);
|
2226
|
+
}
|
2227
|
+
var supportsColor = {
|
2228
|
+
stdout: createSupportsColor({ isTTY: tty.isatty(1) }),
|
2229
|
+
stderr: createSupportsColor({ isTTY: tty.isatty(2) })
|
2230
|
+
};
|
2231
|
+
var supports_color_default = supportsColor;
|
2232
|
+
|
2233
|
+
// node_modules/chalk/source/utilities.js
|
2234
|
+
function stringReplaceAll2(string, substring, replacer) {
|
2235
|
+
let index = string.indexOf(substring);
|
2236
|
+
if (index === -1) {
|
2237
|
+
return string;
|
2238
|
+
}
|
2239
|
+
const substringLength = substring.length;
|
2240
|
+
let endIndex = 0;
|
2241
|
+
let returnValue = "";
|
2242
|
+
do {
|
2243
|
+
returnValue += string.slice(endIndex, index) + substring + replacer;
|
2244
|
+
endIndex = index + substringLength;
|
2245
|
+
index = string.indexOf(substring, endIndex);
|
2246
|
+
} while (index !== -1);
|
2247
|
+
returnValue += string.slice(endIndex);
|
2248
|
+
return returnValue;
|
2249
|
+
}
|
2250
|
+
function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
|
2251
|
+
let endIndex = 0;
|
2252
|
+
let returnValue = "";
|
2253
|
+
do {
|
2254
|
+
const gotCR = string[index - 1] === "\r";
|
2255
|
+
returnValue += string.slice(endIndex, gotCR ? index - 1 : index) + prefix + (gotCR ? "\r\n" : "\n") + postfix;
|
2256
|
+
endIndex = index + 1;
|
2257
|
+
index = string.indexOf("\n", endIndex);
|
2258
|
+
} while (index !== -1);
|
2259
|
+
returnValue += string.slice(endIndex);
|
2260
|
+
return returnValue;
|
2261
|
+
}
|
2262
|
+
|
2263
|
+
// node_modules/chalk/source/index.js
|
2264
|
+
var { stdout: stdoutColor, stderr: stderrColor } = supports_color_default;
|
2265
|
+
var GENERATOR = Symbol("GENERATOR");
|
2266
|
+
var STYLER = Symbol("STYLER");
|
2267
|
+
var IS_EMPTY = Symbol("IS_EMPTY");
|
2268
|
+
var levelMapping = [
|
2269
|
+
"ansi",
|
2270
|
+
"ansi",
|
2271
|
+
"ansi256",
|
2272
|
+
"ansi16m"
|
2273
|
+
];
|
2274
|
+
var styles2 = /* @__PURE__ */ Object.create(null);
|
2275
|
+
var applyOptions = (object, options = {}) => {
|
2276
|
+
if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
|
2277
|
+
throw new Error("The `level` option should be an integer from 0 to 3");
|
2278
|
+
}
|
2279
|
+
const colorLevel = stdoutColor ? stdoutColor.level : 0;
|
2280
|
+
object.level = options.level === void 0 ? colorLevel : options.level;
|
2281
|
+
};
|
2282
|
+
var chalkFactory = (options) => {
|
2283
|
+
const chalk2 = (...strings) => strings.join(" ");
|
2284
|
+
applyOptions(chalk2, options);
|
2285
|
+
Object.setPrototypeOf(chalk2, createChalk.prototype);
|
2286
|
+
return chalk2;
|
2287
|
+
};
|
2288
|
+
function createChalk(options) {
|
2289
|
+
return chalkFactory(options);
|
2290
|
+
}
|
2291
|
+
Object.setPrototypeOf(createChalk.prototype, Function.prototype);
|
2292
|
+
for (const [styleName, style] of Object.entries(ansi_styles_default)) {
|
2293
|
+
styles2[styleName] = {
|
2294
|
+
get() {
|
2295
|
+
const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
|
2296
|
+
Object.defineProperty(this, styleName, { value: builder });
|
2297
|
+
return builder;
|
2298
|
+
}
|
2299
|
+
};
|
2300
|
+
}
|
2301
|
+
styles2.visible = {
|
2302
|
+
get() {
|
2303
|
+
const builder = createBuilder(this, this[STYLER], true);
|
2304
|
+
Object.defineProperty(this, "visible", { value: builder });
|
2305
|
+
return builder;
|
2306
|
+
}
|
2307
|
+
};
|
2308
|
+
var getModelAnsi = (model, level, type, ...arguments_) => {
|
2309
|
+
if (model === "rgb") {
|
2310
|
+
if (level === "ansi16m") {
|
2311
|
+
return ansi_styles_default[type].ansi16m(...arguments_);
|
2312
|
+
}
|
2313
|
+
if (level === "ansi256") {
|
2314
|
+
return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_));
|
2315
|
+
}
|
2316
|
+
return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_));
|
2317
|
+
}
|
2318
|
+
if (model === "hex") {
|
2319
|
+
return getModelAnsi("rgb", level, type, ...ansi_styles_default.hexToRgb(...arguments_));
|
2320
|
+
}
|
2321
|
+
return ansi_styles_default[type][model](...arguments_);
|
2322
|
+
};
|
2323
|
+
var usedModels = ["rgb", "hex", "ansi256"];
|
2324
|
+
for (const model of usedModels) {
|
2325
|
+
styles2[model] = {
|
2326
|
+
get() {
|
2327
|
+
const { level } = this;
|
2328
|
+
return function(...arguments_) {
|
2329
|
+
const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]);
|
2330
|
+
return createBuilder(this, styler, this[IS_EMPTY]);
|
2331
|
+
};
|
2332
|
+
}
|
2333
|
+
};
|
2334
|
+
const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
|
2335
|
+
styles2[bgModel] = {
|
2336
|
+
get() {
|
2337
|
+
const { level } = this;
|
2338
|
+
return function(...arguments_) {
|
2339
|
+
const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]);
|
2340
|
+
return createBuilder(this, styler, this[IS_EMPTY]);
|
2341
|
+
};
|
2342
|
+
}
|
2343
|
+
};
|
2344
|
+
}
|
2345
|
+
var proto = Object.defineProperties(() => {
|
2346
|
+
}, {
|
2347
|
+
...styles2,
|
2348
|
+
level: {
|
2349
|
+
enumerable: true,
|
2350
|
+
get() {
|
2351
|
+
return this[GENERATOR].level;
|
2352
|
+
},
|
2353
|
+
set(level) {
|
2354
|
+
this[GENERATOR].level = level;
|
2355
|
+
}
|
2356
|
+
}
|
2357
|
+
});
|
2358
|
+
var createStyler = (open, close, parent) => {
|
2359
|
+
let openAll;
|
2360
|
+
let closeAll;
|
2361
|
+
if (parent === void 0) {
|
2362
|
+
openAll = open;
|
2363
|
+
closeAll = close;
|
2364
|
+
} else {
|
2365
|
+
openAll = parent.openAll + open;
|
2366
|
+
closeAll = close + parent.closeAll;
|
2367
|
+
}
|
2368
|
+
return {
|
2369
|
+
open,
|
2370
|
+
close,
|
2371
|
+
openAll,
|
2372
|
+
closeAll,
|
2373
|
+
parent
|
2374
|
+
};
|
2375
|
+
};
|
2376
|
+
var createBuilder = (self, _styler, _isEmpty) => {
|
2377
|
+
const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
|
2378
|
+
Object.setPrototypeOf(builder, proto);
|
2379
|
+
builder[GENERATOR] = self;
|
2380
|
+
builder[STYLER] = _styler;
|
2381
|
+
builder[IS_EMPTY] = _isEmpty;
|
2382
|
+
return builder;
|
2383
|
+
};
|
2384
|
+
var applyStyle = (self, string) => {
|
2385
|
+
if (self.level <= 0 || !string) {
|
2386
|
+
return self[IS_EMPTY] ? "" : string;
|
2387
|
+
}
|
2388
|
+
let styler = self[STYLER];
|
2389
|
+
if (styler === void 0) {
|
2390
|
+
return string;
|
2391
|
+
}
|
2392
|
+
const { openAll, closeAll } = styler;
|
2393
|
+
if (string.includes("\x1B")) {
|
2394
|
+
while (styler !== void 0) {
|
2395
|
+
string = stringReplaceAll2(string, styler.close, styler.open);
|
2396
|
+
styler = styler.parent;
|
2397
|
+
}
|
2398
|
+
}
|
2399
|
+
const lfIndex = string.indexOf("\n");
|
2400
|
+
if (lfIndex !== -1) {
|
2401
|
+
string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
|
2402
|
+
}
|
2403
|
+
return openAll + string + closeAll;
|
2404
|
+
};
|
2405
|
+
Object.defineProperties(createChalk.prototype, styles2);
|
2406
|
+
var chalk = createChalk();
|
2407
|
+
var chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
|
2408
|
+
var source_default = chalk;
|
2409
|
+
|
2410
|
+
// node_modules/leven/index.js
|
2411
|
+
var array = [];
|
2412
|
+
var characterCodeCache = [];
|
2413
|
+
function leven(first, second) {
|
2414
|
+
if (first === second) {
|
2415
|
+
return 0;
|
2416
|
+
}
|
2417
|
+
const swap = first;
|
2418
|
+
if (first.length > second.length) {
|
2419
|
+
first = second;
|
2420
|
+
second = swap;
|
2421
|
+
}
|
2422
|
+
let firstLength = first.length;
|
2423
|
+
let secondLength = second.length;
|
2424
|
+
while (firstLength > 0 && first.charCodeAt(~-firstLength) === second.charCodeAt(~-secondLength)) {
|
2425
|
+
firstLength--;
|
2426
|
+
secondLength--;
|
2427
|
+
}
|
2428
|
+
let start = 0;
|
2429
|
+
while (start < firstLength && first.charCodeAt(start) === second.charCodeAt(start)) {
|
2430
|
+
start++;
|
2431
|
+
}
|
2432
|
+
firstLength -= start;
|
2433
|
+
secondLength -= start;
|
2434
|
+
if (firstLength === 0) {
|
2435
|
+
return secondLength;
|
2436
|
+
}
|
2437
|
+
let bCharacterCode;
|
2438
|
+
let result;
|
2439
|
+
let temporary;
|
2440
|
+
let temporary2;
|
2441
|
+
let index = 0;
|
2442
|
+
let index2 = 0;
|
2443
|
+
while (index < firstLength) {
|
2444
|
+
characterCodeCache[index] = first.charCodeAt(start + index);
|
2445
|
+
array[index] = ++index;
|
2446
|
+
}
|
2447
|
+
while (index2 < secondLength) {
|
2448
|
+
bCharacterCode = second.charCodeAt(start + index2);
|
2449
|
+
temporary = index2++;
|
2450
|
+
result = index2;
|
2451
|
+
for (index = 0; index < firstLength; index++) {
|
2452
|
+
temporary2 = bCharacterCode === characterCodeCache[index] ? temporary : temporary + 1;
|
2453
|
+
temporary = array[index];
|
2454
|
+
result = array[index] = temporary > result ? temporary2 > result ? result + 1 : temporary2 : temporary2 > temporary ? temporary + 1 : temporary2;
|
2455
|
+
}
|
2456
|
+
}
|
2457
|
+
return result;
|
2458
|
+
}
|
2459
|
+
|
2460
|
+
// src/cli/options/normalize-cli-options.js
|
2461
|
+
var descriptor = {
|
2462
|
+
key: (key) => key.length === 1 ? `-${key}` : `--${key}`,
|
2463
|
+
value: (value) => vnopts.apiDescriptor.value(value),
|
2464
|
+
pair: ({ key, value }) => value === false ? `--no-${key}` : value === true ? descriptor.key(key) : value === "" ? `${descriptor.key(key)} without an argument` : `${descriptor.key(key)}=${value}`
|
2465
|
+
};
|
2466
|
+
var _flags;
|
2467
|
+
var FlagSchema = class extends vnopts.ChoiceSchema {
|
2468
|
+
constructor({ name, flags }) {
|
2469
|
+
super({ name, choices: flags });
|
2470
|
+
__privateAdd(this, _flags, []);
|
2471
|
+
__privateSet(this, _flags, [...flags].sort());
|
2472
|
+
}
|
2473
|
+
preprocess(value, utils) {
|
2474
|
+
if (typeof value === "string" && value.length > 0 && !__privateGet(this, _flags).includes(value)) {
|
2475
|
+
const suggestion = __privateGet(this, _flags).find((flag) => leven(flag, value) < 3);
|
2476
|
+
if (suggestion) {
|
2477
|
+
utils.logger.warn(
|
2478
|
+
[
|
2479
|
+
`Unknown flag ${source_default.yellow(utils.descriptor.value(value))},`,
|
2480
|
+
`did you mean ${source_default.blue(utils.descriptor.value(suggestion))}?`
|
2481
|
+
].join(" ")
|
2482
|
+
);
|
2483
|
+
return suggestion;
|
2484
|
+
}
|
2485
|
+
}
|
2486
|
+
return value;
|
2487
|
+
}
|
2488
|
+
expected() {
|
2489
|
+
return "a flag";
|
2490
|
+
}
|
2491
|
+
};
|
2492
|
+
_flags = new WeakMap();
|
2493
|
+
function normalizeCliOptions(options, optionInfos, opts) {
|
2494
|
+
return normalizeOptions(options, optionInfos, {
|
2495
|
+
...opts,
|
2496
|
+
isCLI: true,
|
2497
|
+
FlagSchema,
|
2498
|
+
descriptor
|
2499
|
+
});
|
2500
|
+
}
|
2501
|
+
var normalize_cli_options_default = normalizeCliOptions;
|
2502
|
+
|
2503
|
+
// src/cli/options/parse-cli-arguments.js
|
2504
|
+
function parseArgv(rawArguments, detailedOptions, logger, keys) {
|
2505
|
+
var _a;
|
2506
|
+
const minimistOptions = createMinimistOptions(detailedOptions);
|
2507
|
+
let argv = minimistParse(rawArguments, minimistOptions);
|
2508
|
+
if (keys) {
|
2509
|
+
detailedOptions = detailedOptions.filter(
|
2510
|
+
(option) => keys.includes(option.name)
|
2511
|
+
);
|
2512
|
+
argv = pick(argv, keys);
|
2513
|
+
}
|
2514
|
+
const normalized = normalize_cli_options_default(argv, detailedOptions, { logger });
|
2515
|
+
return {
|
2516
|
+
...Object.fromEntries(
|
2517
|
+
Object.entries(normalized).map(([key, value]) => {
|
2518
|
+
const option = detailedOptions.find(({ name }) => name === key) || {};
|
2519
|
+
return [option.forwardToApi || camelCase(key), value];
|
2520
|
+
})
|
2521
|
+
),
|
2522
|
+
_: (_a = normalized._) == null ? void 0 : _a.map(String),
|
2523
|
+
get __raw() {
|
2524
|
+
return argv;
|
2525
|
+
}
|
2526
|
+
};
|
2527
|
+
}
|
2528
|
+
var { detailedOptions: detailedOptionsWithoutPlugins } = getContextOptionsWithoutPlugins();
|
2529
|
+
function parseArgvWithoutPlugins(rawArguments, logger, keys) {
|
2530
|
+
return parseArgv(
|
2531
|
+
rawArguments,
|
2532
|
+
detailedOptionsWithoutPlugins,
|
2533
|
+
logger,
|
2534
|
+
typeof keys === "string" ? [keys] : keys
|
2535
|
+
);
|
2536
|
+
}
|
2537
|
+
|
2538
|
+
// src/cli/context.js
|
2539
|
+
var _stack;
|
2540
|
+
var Context = class {
|
2541
|
+
constructor({
|
2542
|
+
rawArguments,
|
2543
|
+
logger
|
2544
|
+
}) {
|
2545
|
+
__privateAdd(this, _stack, []);
|
2546
|
+
this.rawArguments = rawArguments;
|
2547
|
+
this.logger = logger;
|
2548
|
+
}
|
2549
|
+
async init() {
|
2550
|
+
const {
|
2551
|
+
rawArguments,
|
2552
|
+
logger
|
2553
|
+
} = this;
|
2554
|
+
const {
|
2555
|
+
plugins
|
2556
|
+
} = parseArgvWithoutPlugins(rawArguments, logger, ["plugin"]);
|
2557
|
+
await this.pushContextPlugins(plugins);
|
2558
|
+
const argv = parseArgv(rawArguments, this.detailedOptions, logger);
|
2559
|
+
this.argv = argv;
|
2560
|
+
this.filePatterns = argv._;
|
2561
|
+
}
|
2562
|
+
/**
|
2563
|
+
* @param {string[]} plugins
|
2564
|
+
*/
|
2565
|
+
async pushContextPlugins(plugins) {
|
2566
|
+
const options = await getContextOptions(plugins);
|
2567
|
+
__privateGet(this, _stack).push(options);
|
2568
|
+
Object.assign(this, options);
|
2569
|
+
}
|
2570
|
+
popContextPlugins() {
|
2571
|
+
__privateGet(this, _stack).pop();
|
2572
|
+
Object.assign(this, at_default(
|
2573
|
+
/* isOptionalObject */
|
2574
|
+
false,
|
2575
|
+
__privateGet(this, _stack),
|
2576
|
+
-1
|
2577
|
+
));
|
2578
|
+
}
|
2579
|
+
// eslint-disable-next-line getter-return
|
2580
|
+
get performanceTestFlag() {
|
2581
|
+
const {
|
2582
|
+
debugBenchmark,
|
2583
|
+
debugRepeat
|
2584
|
+
} = this.argv;
|
2585
|
+
if (debugBenchmark) {
|
2586
|
+
return {
|
2587
|
+
name: "--debug-benchmark",
|
2588
|
+
debugBenchmark: true
|
2589
|
+
};
|
2590
|
+
}
|
2591
|
+
if (debugRepeat > 0) {
|
2592
|
+
return {
|
2593
|
+
name: "--debug-repeat",
|
2594
|
+
debugRepeat
|
2595
|
+
};
|
2596
|
+
}
|
2597
|
+
const {
|
2598
|
+
PRETTIER_PERF_REPEAT
|
2599
|
+
} = process.env;
|
2600
|
+
if (PRETTIER_PERF_REPEAT && /^\d+$/u.test(PRETTIER_PERF_REPEAT)) {
|
2601
|
+
return {
|
2602
|
+
name: "PRETTIER_PERF_REPEAT (environment variable)",
|
2603
|
+
debugRepeat: Number(PRETTIER_PERF_REPEAT)
|
2604
|
+
};
|
2605
|
+
}
|
2606
|
+
}
|
2607
|
+
};
|
2608
|
+
_stack = new WeakMap();
|
2609
|
+
var context_default = Context;
|
2610
|
+
|
2611
|
+
// src/cli/file-info.js
|
2612
|
+
var import_fast_json_stable_stringify = __toESM(require_fast_json_stable_stringify(), 1);
|
2613
|
+
import { format, getFileInfo } from "../index.mjs";
|
2614
|
+
async function logFileInfoOrDie(context) {
|
2615
|
+
const {
|
2616
|
+
fileInfo: file,
|
2617
|
+
ignorePath,
|
2618
|
+
withNodeModules,
|
2619
|
+
plugins,
|
2620
|
+
config
|
2621
|
+
} = context.argv;
|
2622
|
+
const fileInfo = await getFileInfo(file, {
|
2623
|
+
ignorePath,
|
2624
|
+
withNodeModules,
|
2625
|
+
plugins,
|
2626
|
+
resolveConfig: config !== false
|
2627
|
+
});
|
2628
|
+
printToScreen(await format((0, import_fast_json_stable_stringify.default)(fileInfo), { parser: "json" }));
|
2629
|
+
}
|
2630
|
+
var file_info_default = logFileInfoOrDie;
|
2631
|
+
|
2632
|
+
// src/cli/find-config-path.js
|
2633
|
+
import path2 from "path";
|
2634
|
+
import { resolveConfigFile } from "../index.mjs";
|
2635
|
+
async function logResolvedConfigPathOrDie(context) {
|
2636
|
+
const file = context.argv.findConfigPath;
|
2637
|
+
const configFile = await resolveConfigFile(file);
|
2638
|
+
if (configFile) {
|
2639
|
+
printToScreen(normalizeToPosix(path2.relative(process.cwd(), configFile)));
|
2640
|
+
} else {
|
2641
|
+
throw new Error(`Can not find configure file for "${file}".`);
|
2642
|
+
}
|
2643
|
+
}
|
2644
|
+
var find_config_path_default = logResolvedConfigPathOrDie;
|
2645
|
+
|
2646
|
+
// src/cli/format.js
|
2647
|
+
import fs5 from "fs/promises";
|
2648
|
+
import path9 from "path";
|
2649
|
+
import * as prettier from "../index.mjs";
|
2650
|
+
|
2651
|
+
// src/cli/expand-patterns.js
|
2652
|
+
import path3 from "path";
|
2653
|
+
async function* expandPatterns(context) {
|
2654
|
+
const seen = /* @__PURE__ */ new Set();
|
2655
|
+
let noResults = true;
|
2656
|
+
for await (const {
|
2657
|
+
filePath,
|
2658
|
+
ignoreUnknown,
|
2659
|
+
error
|
2660
|
+
} of expandPatternsInternal(context)) {
|
2661
|
+
noResults = false;
|
2662
|
+
if (error) {
|
2663
|
+
yield {
|
2664
|
+
error
|
2665
|
+
};
|
2666
|
+
continue;
|
2667
|
+
}
|
2668
|
+
const filename = path3.resolve(filePath);
|
2669
|
+
if (seen.has(filename)) {
|
2670
|
+
continue;
|
2671
|
+
}
|
2672
|
+
seen.add(filename);
|
2673
|
+
yield {
|
2674
|
+
filename,
|
2675
|
+
ignoreUnknown
|
2676
|
+
};
|
2677
|
+
}
|
2678
|
+
if (noResults && context.argv.errorOnUnmatchedPattern !== false) {
|
2679
|
+
yield {
|
2680
|
+
error: `No matching files. Patterns: ${context.filePatterns.join(" ")}`
|
2681
|
+
};
|
2682
|
+
}
|
2683
|
+
}
|
2684
|
+
async function* expandPatternsInternal(context) {
|
2685
|
+
const silentlyIgnoredDirs = [".git", ".sl", ".svn", ".hg"];
|
2686
|
+
if (context.argv.withNodeModules !== true) {
|
2687
|
+
silentlyIgnoredDirs.push("node_modules");
|
2688
|
+
}
|
2689
|
+
const globOptions = {
|
2690
|
+
dot: true,
|
2691
|
+
ignore: silentlyIgnoredDirs.map((dir) => "**/" + dir),
|
2692
|
+
followSymbolicLinks: false
|
2693
|
+
};
|
2694
|
+
const cwd2 = process.cwd();
|
2695
|
+
const entries = [];
|
2696
|
+
for (const pattern of context.filePatterns) {
|
2697
|
+
const absolutePath = path3.resolve(cwd2, pattern);
|
2698
|
+
if (containsIgnoredPathSegment(absolutePath, cwd2, silentlyIgnoredDirs)) {
|
2699
|
+
continue;
|
2700
|
+
}
|
2701
|
+
const stat = await lstatSafe(absolutePath);
|
2702
|
+
if (stat) {
|
2703
|
+
if (stat.isSymbolicLink()) {
|
2704
|
+
if (context.argv.errorOnUnmatchedPattern !== false) {
|
2705
|
+
yield {
|
2706
|
+
error: `Explicitly specified pattern "${pattern}" is a symbolic link.`
|
2707
|
+
};
|
2708
|
+
} else {
|
2709
|
+
context.logger.debug(`Skipping pattern "${pattern}", as it is a symbolic link.`);
|
2710
|
+
}
|
2711
|
+
} else if (stat.isFile()) {
|
2712
|
+
entries.push({
|
2713
|
+
type: "file",
|
2714
|
+
glob: escapePathForGlob(fixWindowsSlashes(pattern)),
|
2715
|
+
input: pattern
|
2716
|
+
});
|
2717
|
+
} else if (stat.isDirectory()) {
|
2718
|
+
const relativePath = path3.relative(cwd2, absolutePath) || ".";
|
2719
|
+
const prefix = escapePathForGlob(fixWindowsSlashes(relativePath));
|
2720
|
+
entries.push({
|
2721
|
+
type: "dir",
|
2722
|
+
glob: `${prefix}/**/*`,
|
2723
|
+
input: pattern,
|
2724
|
+
ignoreUnknown: true
|
2725
|
+
});
|
2726
|
+
}
|
2727
|
+
} else if (pattern[0] === "!") {
|
2728
|
+
globOptions.ignore.push(fixWindowsSlashes(pattern.slice(1)));
|
2729
|
+
} else {
|
2730
|
+
entries.push({
|
2731
|
+
type: "glob",
|
2732
|
+
glob: fixWindowsSlashes(pattern),
|
2733
|
+
input: pattern
|
2734
|
+
});
|
2735
|
+
}
|
2736
|
+
}
|
2737
|
+
for (const {
|
2738
|
+
type,
|
2739
|
+
glob,
|
2740
|
+
input,
|
2741
|
+
ignoreUnknown
|
2742
|
+
} of entries) {
|
2743
|
+
let result;
|
2744
|
+
try {
|
2745
|
+
result = await fastGlob(glob, globOptions);
|
2746
|
+
} catch ({
|
2747
|
+
message
|
2748
|
+
}) {
|
2749
|
+
yield {
|
2750
|
+
error: `${errorMessages.globError[type]}: "${input}".
|
2751
|
+
${message}`
|
2752
|
+
};
|
2753
|
+
continue;
|
2754
|
+
}
|
2755
|
+
if (result.length === 0) {
|
2756
|
+
if (context.argv.errorOnUnmatchedPattern !== false) {
|
2757
|
+
yield {
|
2758
|
+
error: `${errorMessages.emptyResults[type]}: "${input}".`
|
2759
|
+
};
|
2760
|
+
}
|
2761
|
+
} else {
|
2762
|
+
yield* sortPaths(result).map((filePath) => ({
|
2763
|
+
filePath,
|
2764
|
+
ignoreUnknown
|
2765
|
+
}));
|
2766
|
+
}
|
2767
|
+
}
|
2768
|
+
}
|
2769
|
+
var errorMessages = {
|
2770
|
+
globError: {
|
2771
|
+
file: "Unable to resolve file",
|
2772
|
+
dir: "Unable to expand directory",
|
2773
|
+
glob: "Unable to expand glob pattern"
|
2774
|
+
},
|
2775
|
+
emptyResults: {
|
2776
|
+
file: "Explicitly specified file was ignored due to negative glob patterns",
|
2777
|
+
dir: "No supported files were found in the directory",
|
2778
|
+
glob: "No files matching the pattern were found"
|
2779
|
+
}
|
2780
|
+
};
|
2781
|
+
function containsIgnoredPathSegment(absolutePath, cwd2, ignoredDirectories) {
|
2782
|
+
return path3.relative(cwd2, absolutePath).split(path3.sep).some((dir) => ignoredDirectories.includes(dir));
|
2783
|
+
}
|
2784
|
+
function sortPaths(paths) {
|
2785
|
+
return paths.sort((a, b) => a.localeCompare(b));
|
2786
|
+
}
|
2787
|
+
function escapePathForGlob(path10) {
|
2788
|
+
return string_replace_all_default(
|
2789
|
+
/* isOptionalObject */
|
2790
|
+
false,
|
2791
|
+
string_replace_all_default(
|
2792
|
+
/* isOptionalObject */
|
2793
|
+
false,
|
2794
|
+
fastGlob.escapePath(
|
2795
|
+
string_replace_all_default(
|
2796
|
+
/* isOptionalObject */
|
2797
|
+
false,
|
2798
|
+
path10,
|
2799
|
+
"\\",
|
2800
|
+
"\0"
|
2801
|
+
)
|
2802
|
+
// Workaround for fast-glob#262 (part 1)
|
2803
|
+
),
|
2804
|
+
String.raw`\!`,
|
2805
|
+
"@(!)"
|
2806
|
+
),
|
2807
|
+
"\0",
|
2808
|
+
String.raw`@(\\)`
|
2809
|
+
);
|
2810
|
+
}
|
2811
|
+
var fixWindowsSlashes = normalizeToPosix;
|
2812
|
+
|
2813
|
+
// src/cli/find-cache-file.js
|
2814
|
+
import fs4 from "fs/promises";
|
2815
|
+
import os2 from "os";
|
2816
|
+
import path8 from "path";
|
2817
|
+
|
2818
|
+
// node_modules/find-cache-dir/index.js
|
2819
|
+
var import_common_path_prefix = __toESM(require_common_path_prefix(), 1);
|
2820
|
+
import process4 from "process";
|
2821
|
+
import path7 from "path";
|
2822
|
+
import fs3 from "fs";
|
2823
|
+
|
2824
|
+
// node_modules/pkg-dir/index.js
|
2825
|
+
import path6 from "path";
|
2826
|
+
|
2827
|
+
// node_modules/pkg-dir/node_modules/find-up/index.js
|
2828
|
+
import path5 from "path";
|
2829
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
2830
|
+
|
2831
|
+
// node_modules/pkg-dir/node_modules/locate-path/index.js
|
2832
|
+
import process3 from "process";
|
2833
|
+
import path4 from "path";
|
2834
|
+
import fs2, { promises as fsPromises } from "fs";
|
2835
|
+
import { fileURLToPath } from "url";
|
2836
|
+
var typeMappings = {
|
2837
|
+
directory: "isDirectory",
|
2838
|
+
file: "isFile"
|
2839
|
+
};
|
2840
|
+
function checkType(type) {
|
2841
|
+
if (Object.hasOwnProperty.call(typeMappings, type)) {
|
2842
|
+
return;
|
2843
|
+
}
|
2844
|
+
throw new Error(`Invalid type specified: ${type}`);
|
2845
|
+
}
|
2846
|
+
var matchType = (type, stat) => stat[typeMappings[type]]();
|
2847
|
+
var toPath = (urlOrPath) => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;
|
2848
|
+
function locatePathSync(paths, {
|
2849
|
+
cwd: cwd2 = process3.cwd(),
|
2850
|
+
type = "file",
|
2851
|
+
allowSymlinks = true
|
2852
|
+
} = {}) {
|
2853
|
+
checkType(type);
|
2854
|
+
cwd2 = toPath(cwd2);
|
2855
|
+
const statFunction = allowSymlinks ? fs2.statSync : fs2.lstatSync;
|
2856
|
+
for (const path_ of paths) {
|
2857
|
+
try {
|
2858
|
+
const stat = statFunction(path4.resolve(cwd2, path_), {
|
2859
|
+
throwIfNoEntry: false
|
2860
|
+
});
|
2861
|
+
if (!stat) {
|
2862
|
+
continue;
|
2863
|
+
}
|
2864
|
+
if (matchType(type, stat)) {
|
2865
|
+
return path_;
|
2866
|
+
}
|
2867
|
+
} catch {
|
2868
|
+
}
|
2869
|
+
}
|
2870
|
+
}
|
2871
|
+
|
2872
|
+
// node_modules/pkg-dir/node_modules/find-up/index.js
|
2873
|
+
var toPath2 = (urlOrPath) => urlOrPath instanceof URL ? fileURLToPath2(urlOrPath) : urlOrPath;
|
2874
|
+
var findUpStop = Symbol("findUpStop");
|
2875
|
+
function findUpMultipleSync(name, options = {}) {
|
2876
|
+
let directory = path5.resolve(toPath2(options.cwd) || "");
|
2877
|
+
const { root } = path5.parse(directory);
|
2878
|
+
const stopAt = options.stopAt || root;
|
2879
|
+
const limit = options.limit || Number.POSITIVE_INFINITY;
|
2880
|
+
const paths = [name].flat();
|
2881
|
+
const runMatcher = (locateOptions) => {
|
2882
|
+
if (typeof name !== "function") {
|
2883
|
+
return locatePathSync(paths, locateOptions);
|
2884
|
+
}
|
2885
|
+
const foundPath = name(locateOptions.cwd);
|
2886
|
+
if (typeof foundPath === "string") {
|
2887
|
+
return locatePathSync([foundPath], locateOptions);
|
2888
|
+
}
|
2889
|
+
return foundPath;
|
2890
|
+
};
|
2891
|
+
const matches = [];
|
2892
|
+
while (true) {
|
2893
|
+
const foundPath = runMatcher({ ...options, cwd: directory });
|
2894
|
+
if (foundPath === findUpStop) {
|
2895
|
+
break;
|
2896
|
+
}
|
2897
|
+
if (foundPath) {
|
2898
|
+
matches.push(path5.resolve(directory, foundPath));
|
2899
|
+
}
|
2900
|
+
if (directory === stopAt || matches.length >= limit) {
|
2901
|
+
break;
|
2902
|
+
}
|
2903
|
+
directory = path5.dirname(directory);
|
2904
|
+
}
|
2905
|
+
return matches;
|
2906
|
+
}
|
2907
|
+
function findUpSync(name, options = {}) {
|
2908
|
+
const matches = findUpMultipleSync(name, { ...options, limit: 1 });
|
2909
|
+
return matches[0];
|
2910
|
+
}
|
2911
|
+
|
2912
|
+
// node_modules/pkg-dir/index.js
|
2913
|
+
function packageDirectorySync({ cwd: cwd2 } = {}) {
|
2914
|
+
const filePath = findUpSync("package.json", { cwd: cwd2 });
|
2915
|
+
return filePath && path6.dirname(filePath);
|
2916
|
+
}
|
2917
|
+
|
2918
|
+
// node_modules/find-cache-dir/index.js
|
2919
|
+
var { env: env2, cwd } = process4;
|
2920
|
+
var isWritable = (path10) => {
|
2921
|
+
try {
|
2922
|
+
fs3.accessSync(path10, fs3.constants.W_OK);
|
2923
|
+
return true;
|
2924
|
+
} catch {
|
2925
|
+
return false;
|
2926
|
+
}
|
2927
|
+
};
|
2928
|
+
function useDirectory(directory, options) {
|
2929
|
+
if (options.create) {
|
2930
|
+
fs3.mkdirSync(directory, { recursive: true });
|
2931
|
+
}
|
2932
|
+
return directory;
|
2933
|
+
}
|
2934
|
+
function getNodeModuleDirectory(directory) {
|
2935
|
+
const nodeModules = path7.join(directory, "node_modules");
|
2936
|
+
if (!isWritable(nodeModules) && (fs3.existsSync(nodeModules) || !isWritable(path7.join(directory)))) {
|
2937
|
+
return;
|
2938
|
+
}
|
2939
|
+
return nodeModules;
|
2940
|
+
}
|
2941
|
+
function findCacheDirectory(options = {}) {
|
2942
|
+
if (env2.CACHE_DIR && !["true", "false", "1", "0"].includes(env2.CACHE_DIR)) {
|
2943
|
+
return useDirectory(path7.join(env2.CACHE_DIR, options.name), options);
|
2944
|
+
}
|
2945
|
+
let { cwd: directory = cwd(), files } = options;
|
2946
|
+
if (files) {
|
2947
|
+
if (!Array.isArray(files)) {
|
2948
|
+
throw new TypeError(`Expected \`files\` option to be an array, got \`${typeof files}\`.`);
|
2949
|
+
}
|
2950
|
+
directory = (0, import_common_path_prefix.default)(files.map((file) => path7.resolve(directory, file)));
|
2951
|
+
}
|
2952
|
+
directory = packageDirectorySync({ cwd: directory });
|
2953
|
+
if (!directory) {
|
2954
|
+
return;
|
2955
|
+
}
|
2956
|
+
const nodeModules = getNodeModuleDirectory(directory);
|
2957
|
+
if (!nodeModules) {
|
2958
|
+
return;
|
2959
|
+
}
|
2960
|
+
return useDirectory(path7.join(directory, "node_modules", ".cache", options.name), options);
|
2961
|
+
}
|
2962
|
+
|
2963
|
+
// src/cli/find-cache-file.js
|
2964
|
+
function findDefaultCacheFile() {
|
2965
|
+
const cacheDir = findCacheDirectory({ name: "prettier", create: true }) || os2.tmpdir();
|
2966
|
+
const cacheFilePath = path8.join(cacheDir, ".prettier-cache");
|
2967
|
+
return cacheFilePath;
|
2968
|
+
}
|
2969
|
+
async function findCacheFileFromOption(cacheLocation) {
|
2970
|
+
const cacheFile = path8.resolve(cacheLocation);
|
2971
|
+
const stat = await statSafe(cacheFile);
|
2972
|
+
if (stat) {
|
2973
|
+
if (stat.isDirectory()) {
|
2974
|
+
throw new Error(
|
2975
|
+
`Resolved --cache-location '${cacheFile}' is a directory`
|
2976
|
+
);
|
2977
|
+
}
|
2978
|
+
const data = await fs4.readFile(cacheFile, "utf8");
|
2979
|
+
if (!isJson(data)) {
|
2980
|
+
throw new Error(`'${cacheFile}' isn't a valid JSON file`);
|
2981
|
+
}
|
2982
|
+
}
|
2983
|
+
return cacheFile;
|
2984
|
+
}
|
2985
|
+
async function findCacheFile(cacheLocation) {
|
2986
|
+
if (!cacheLocation) {
|
2987
|
+
return findDefaultCacheFile();
|
2988
|
+
}
|
2989
|
+
const cacheFile = await findCacheFileFromOption(cacheLocation);
|
2990
|
+
return cacheFile;
|
2991
|
+
}
|
2992
|
+
var find_cache_file_default = findCacheFile;
|
2993
|
+
|
2994
|
+
// src/cli/format-results-cache.js
|
2995
|
+
var import_fast_json_stable_stringify2 = __toESM(require_fast_json_stable_stringify(), 1);
|
2996
|
+
var import_file_entry_cache = __toESM(require_cache2(), 1);
|
2997
|
+
import { version as prettierVersion } from "../index.mjs";
|
2998
|
+
var optionsHashCache = /* @__PURE__ */ new WeakMap();
|
2999
|
+
var nodeVersion = process.version;
|
3000
|
+
function getHashOfOptions(options) {
|
3001
|
+
if (optionsHashCache.has(options)) {
|
3002
|
+
return optionsHashCache.get(options);
|
3003
|
+
}
|
3004
|
+
const hash = createHash(
|
3005
|
+
`${prettierVersion}_${nodeVersion}_${(0, import_fast_json_stable_stringify2.default)(options)}`
|
3006
|
+
);
|
3007
|
+
optionsHashCache.set(options, hash);
|
3008
|
+
return hash;
|
3009
|
+
}
|
3010
|
+
function getMetadataFromFileDescriptor(fileDescriptor) {
|
3011
|
+
return fileDescriptor.meta;
|
3012
|
+
}
|
3013
|
+
var _fileEntryCache;
|
3014
|
+
var FormatResultsCache = class {
|
3015
|
+
/**
|
3016
|
+
* @param {string} cacheFileLocation The path of cache file location. (default: `node_modules/.cache/prettier/.prettier-cache`)
|
3017
|
+
* @param {string} cacheStrategy
|
3018
|
+
*/
|
3019
|
+
constructor(cacheFileLocation, cacheStrategy) {
|
3020
|
+
__privateAdd(this, _fileEntryCache);
|
3021
|
+
const useChecksum = cacheStrategy === "content";
|
3022
|
+
__privateSet(this, _fileEntryCache, import_file_entry_cache.default.create(
|
3023
|
+
/* cacheId */
|
3024
|
+
cacheFileLocation,
|
3025
|
+
/* directory */
|
3026
|
+
void 0,
|
3027
|
+
useChecksum
|
3028
|
+
));
|
3029
|
+
}
|
3030
|
+
/**
|
3031
|
+
* @param {string} filePath
|
3032
|
+
* @param {any} options
|
3033
|
+
*/
|
3034
|
+
existsAvailableFormatResultsCache(filePath, options) {
|
3035
|
+
const fileDescriptor = __privateGet(this, _fileEntryCache).getFileDescriptor(filePath);
|
3036
|
+
if (fileDescriptor.notFound) {
|
3037
|
+
return false;
|
3038
|
+
}
|
3039
|
+
const hashOfOptions = getHashOfOptions(options);
|
3040
|
+
const meta = getMetadataFromFileDescriptor(fileDescriptor);
|
3041
|
+
const changed = fileDescriptor.changed || meta.hashOfOptions !== hashOfOptions;
|
3042
|
+
return !changed;
|
3043
|
+
}
|
3044
|
+
/**
|
3045
|
+
* @param {string} filePath
|
3046
|
+
* @param {any} options
|
3047
|
+
*/
|
3048
|
+
setFormatResultsCache(filePath, options) {
|
3049
|
+
const fileDescriptor = __privateGet(this, _fileEntryCache).getFileDescriptor(filePath);
|
3050
|
+
const meta = getMetadataFromFileDescriptor(fileDescriptor);
|
3051
|
+
if (fileDescriptor && !fileDescriptor.notFound) {
|
3052
|
+
meta.hashOfOptions = getHashOfOptions(options);
|
3053
|
+
}
|
3054
|
+
}
|
3055
|
+
/**
|
3056
|
+
* @param {string} filePath
|
3057
|
+
*/
|
3058
|
+
removeFormatResultsCache(filePath) {
|
3059
|
+
__privateGet(this, _fileEntryCache).removeEntry(filePath);
|
3060
|
+
}
|
3061
|
+
reconcile() {
|
3062
|
+
__privateGet(this, _fileEntryCache).reconcile();
|
3063
|
+
}
|
3064
|
+
};
|
3065
|
+
_fileEntryCache = new WeakMap();
|
3066
|
+
var format_results_cache_default = FormatResultsCache;
|
3067
|
+
|
3068
|
+
// src/cli/is-tty.js
|
3069
|
+
function isTTY() {
|
3070
|
+
return process.stdout.isTTY && !mockable.isCI();
|
3071
|
+
}
|
3072
|
+
|
3073
|
+
// src/cli/options/get-options-for-file.js
|
3074
|
+
var import_dashify2 = __toESM(require_dashify(), 1);
|
3075
|
+
import { resolveConfig } from "../index.mjs";
|
3076
|
+
function getOptions(argv, detailedOptions) {
|
3077
|
+
return Object.fromEntries(
|
3078
|
+
detailedOptions.filter(({ forwardToApi }) => forwardToApi).map(({ forwardToApi, name }) => [forwardToApi, argv[name]])
|
3079
|
+
);
|
3080
|
+
}
|
3081
|
+
function cliifyOptions(object, apiDetailedOptionMap) {
|
3082
|
+
return Object.fromEntries(
|
3083
|
+
Object.entries(object || {}).map(([key, value]) => {
|
3084
|
+
const apiOption = apiDetailedOptionMap[key];
|
3085
|
+
const cliKey = apiOption ? apiOption.name : key;
|
3086
|
+
return [(0, import_dashify2.default)(cliKey), value];
|
3087
|
+
})
|
3088
|
+
);
|
3089
|
+
}
|
3090
|
+
function createApiDetailedOptionMap(detailedOptions) {
|
3091
|
+
return Object.fromEntries(
|
3092
|
+
detailedOptions.filter(
|
3093
|
+
(option) => option.forwardToApi && option.forwardToApi !== option.name
|
3094
|
+
).map((option) => [option.forwardToApi, option])
|
3095
|
+
);
|
3096
|
+
}
|
3097
|
+
function parseArgsToOptions(context, overrideDefaults) {
|
3098
|
+
const minimistOptions = createMinimistOptions(context.detailedOptions);
|
3099
|
+
const apiDetailedOptionMap = createApiDetailedOptionMap(
|
3100
|
+
context.detailedOptions
|
3101
|
+
);
|
3102
|
+
return getOptions(
|
3103
|
+
normalize_cli_options_default(
|
3104
|
+
minimistParse(context.rawArguments, {
|
3105
|
+
string: minimistOptions.string,
|
3106
|
+
boolean: minimistOptions.boolean,
|
3107
|
+
default: cliifyOptions(overrideDefaults, apiDetailedOptionMap)
|
3108
|
+
}),
|
3109
|
+
context.detailedOptions,
|
3110
|
+
{ logger: false }
|
3111
|
+
),
|
3112
|
+
context.detailedOptions
|
3113
|
+
);
|
3114
|
+
}
|
3115
|
+
async function getOptionsOrDie(context, filePath) {
|
3116
|
+
try {
|
3117
|
+
if (context.argv.config === false) {
|
3118
|
+
context.logger.debug(
|
3119
|
+
"'--no-config' option found, skip loading config file."
|
3120
|
+
);
|
3121
|
+
return null;
|
3122
|
+
}
|
3123
|
+
context.logger.debug(
|
3124
|
+
context.argv.config ? `load config file from '${context.argv.config}'` : `resolve config from '${filePath}'`
|
3125
|
+
);
|
3126
|
+
const options = await resolveConfig(filePath, {
|
3127
|
+
editorconfig: context.argv.editorconfig,
|
3128
|
+
config: context.argv.config
|
3129
|
+
});
|
3130
|
+
context.logger.debug("loaded options `" + JSON.stringify(options) + "`");
|
3131
|
+
return options;
|
3132
|
+
} catch (error) {
|
3133
|
+
context.logger.error(
|
3134
|
+
`Invalid configuration${filePath ? ` for file "${filePath}"` : ""}:
|
3135
|
+
` + error.message
|
3136
|
+
);
|
3137
|
+
process.exit(2);
|
3138
|
+
}
|
3139
|
+
}
|
3140
|
+
function applyConfigPrecedence(context, options) {
|
3141
|
+
try {
|
3142
|
+
switch (context.argv.configPrecedence) {
|
3143
|
+
case "cli-override":
|
3144
|
+
return parseArgsToOptions(context, options);
|
3145
|
+
case "file-override":
|
3146
|
+
return { ...parseArgsToOptions(context), ...options };
|
3147
|
+
case "prefer-file":
|
3148
|
+
return options || parseArgsToOptions(context);
|
3149
|
+
}
|
3150
|
+
} catch (error) {
|
3151
|
+
context.logger.error(error.toString());
|
3152
|
+
process.exit(2);
|
3153
|
+
}
|
3154
|
+
}
|
3155
|
+
async function getOptionsForFile(context, filepath) {
|
3156
|
+
const options = await getOptionsOrDie(context, filepath);
|
3157
|
+
const hasPlugins = options == null ? void 0 : options.plugins;
|
3158
|
+
if (hasPlugins) {
|
3159
|
+
await context.pushContextPlugins(options.plugins);
|
3160
|
+
}
|
3161
|
+
const appliedOptions = {
|
3162
|
+
filepath,
|
3163
|
+
...applyConfigPrecedence(
|
3164
|
+
context,
|
3165
|
+
options && normalizeOptions(options, context.supportOptions, {
|
3166
|
+
logger: context.logger
|
3167
|
+
})
|
3168
|
+
)
|
3169
|
+
};
|
3170
|
+
context.logger.debug(
|
3171
|
+
`applied config-precedence (${context.argv.configPrecedence}): ${JSON.stringify(appliedOptions)}`
|
3172
|
+
);
|
3173
|
+
if (hasPlugins) {
|
3174
|
+
context.popContextPlugins();
|
3175
|
+
}
|
3176
|
+
return appliedOptions;
|
3177
|
+
}
|
3178
|
+
var get_options_for_file_default = getOptionsForFile;
|
3179
|
+
|
3180
|
+
// src/cli/format.js
|
3181
|
+
var { getStdin, writeFormattedFile } = mockable;
|
3182
|
+
function diff(a, b) {
|
3183
|
+
return createTwoFilesPatch("", "", a, b, "", "", { context: 2 });
|
3184
|
+
}
|
3185
|
+
var DebugError = class extends Error {
|
3186
|
+
name = "DebugError";
|
3187
|
+
};
|
3188
|
+
function handleError(context, filename, error, printedFilename, ignoreUnknown) {
|
3189
|
+
ignoreUnknown || (ignoreUnknown = context.argv.ignoreUnknown);
|
3190
|
+
const errorIsUndefinedParseError = error instanceof errors.UndefinedParserError;
|
3191
|
+
if (printedFilename) {
|
3192
|
+
if ((context.argv.write || ignoreUnknown) && errorIsUndefinedParseError) {
|
3193
|
+
printedFilename.clear();
|
3194
|
+
} else {
|
3195
|
+
process.stdout.write("\n");
|
3196
|
+
}
|
3197
|
+
}
|
3198
|
+
if (errorIsUndefinedParseError) {
|
3199
|
+
if (ignoreUnknown) {
|
3200
|
+
return;
|
3201
|
+
}
|
3202
|
+
if (!context.argv.check && !context.argv.listDifferent) {
|
3203
|
+
process.exitCode = 2;
|
3204
|
+
}
|
3205
|
+
context.logger.error(error.message);
|
3206
|
+
return;
|
3207
|
+
}
|
3208
|
+
const isParseError = Boolean(error == null ? void 0 : error.loc);
|
3209
|
+
const isValidationError = /^Invalid \S+ value\./u.test(error == null ? void 0 : error.message);
|
3210
|
+
if (isParseError) {
|
3211
|
+
context.logger.error(`${filename}: ${String(error)}`);
|
3212
|
+
} else if (isValidationError || error instanceof errors.ConfigError) {
|
3213
|
+
context.logger.error(error.message);
|
3214
|
+
process.exit(1);
|
3215
|
+
} else if (error instanceof DebugError) {
|
3216
|
+
context.logger.error(`${filename}: ${error.message}`);
|
3217
|
+
} else {
|
3218
|
+
context.logger.error(filename + ": " + (error.stack || error));
|
3219
|
+
}
|
3220
|
+
process.exitCode = 2;
|
3221
|
+
}
|
3222
|
+
function writeOutput(context, result, options) {
|
3223
|
+
process.stdout.write(
|
3224
|
+
context.argv.debugCheck ? result.filepath : result.formatted
|
3225
|
+
);
|
3226
|
+
if (options && options.cursorOffset >= 0) {
|
3227
|
+
process.stderr.write(result.cursorOffset + "\n");
|
3228
|
+
}
|
3229
|
+
}
|
3230
|
+
async function listDifferent(context, input, options, filename) {
|
3231
|
+
if (!context.argv.check && !context.argv.listDifferent) {
|
3232
|
+
return;
|
3233
|
+
}
|
3234
|
+
try {
|
3235
|
+
if (!await prettier.check(input, options) && !context.argv.write) {
|
3236
|
+
context.logger.log(filename);
|
3237
|
+
process.exitCode = 1;
|
3238
|
+
}
|
3239
|
+
} catch (error) {
|
3240
|
+
context.logger.error(error.message);
|
3241
|
+
}
|
3242
|
+
return true;
|
3243
|
+
}
|
3244
|
+
async function format3(context, input, opt) {
|
3245
|
+
if (context.argv.debugPrintDoc) {
|
3246
|
+
const doc = await prettier.__debug.printToDoc(input, opt);
|
3247
|
+
return { formatted: await prettier.__debug.formatDoc(doc) + "\n" };
|
3248
|
+
}
|
3249
|
+
if (context.argv.debugPrintComments) {
|
3250
|
+
return {
|
3251
|
+
formatted: await prettier.format(
|
3252
|
+
JSON.stringify(
|
3253
|
+
(await prettier.formatWithCursor(input, opt)).comments || []
|
3254
|
+
),
|
3255
|
+
{ parser: "json" }
|
3256
|
+
)
|
3257
|
+
};
|
3258
|
+
}
|
3259
|
+
if (context.argv.debugPrintAst) {
|
3260
|
+
const { ast } = await prettier.__debug.parse(input, opt);
|
3261
|
+
return {
|
3262
|
+
formatted: JSON.stringify(ast)
|
3263
|
+
};
|
3264
|
+
}
|
3265
|
+
if (context.argv.debugCheck) {
|
3266
|
+
const pp = await prettier.format(input, opt);
|
3267
|
+
const pppp = await prettier.format(pp, opt);
|
3268
|
+
if (pp !== pppp) {
|
3269
|
+
throw new DebugError(
|
3270
|
+
"prettier(input) !== prettier(prettier(input))\n" + diff(pp, pppp)
|
3271
|
+
);
|
3272
|
+
} else {
|
3273
|
+
const stringify4 = (obj) => JSON.stringify(obj, null, 2);
|
3274
|
+
const ast = stringify4(
|
3275
|
+
(await prettier.__debug.parse(input, opt, { massage: true })).ast
|
3276
|
+
);
|
3277
|
+
const past = stringify4(
|
3278
|
+
(await prettier.__debug.parse(pp, opt, { massage: true })).ast
|
3279
|
+
);
|
3280
|
+
if (ast !== past) {
|
3281
|
+
const MAX_AST_SIZE = 2097152;
|
3282
|
+
const astDiff = ast.length > MAX_AST_SIZE || past.length > MAX_AST_SIZE ? "AST diff too large to render" : diff(ast, past);
|
3283
|
+
throw new DebugError(
|
3284
|
+
"ast(input) !== ast(prettier(input))\n" + astDiff + "\n" + diff(input, pp)
|
3285
|
+
);
|
3286
|
+
}
|
3287
|
+
}
|
3288
|
+
return { formatted: pp, filepath: opt.filepath || "(stdin)\n" };
|
3289
|
+
}
|
3290
|
+
const { performanceTestFlag } = context;
|
3291
|
+
if (performanceTestFlag == null ? void 0 : performanceTestFlag.debugBenchmark) {
|
3292
|
+
let benchmark;
|
3293
|
+
try {
|
3294
|
+
({ default: benchmark } = await import("benchmark"));
|
3295
|
+
} catch {
|
3296
|
+
context.logger.debug(
|
3297
|
+
"'--debug-benchmark' requires the 'benchmark' package to be installed."
|
3298
|
+
);
|
3299
|
+
process.exit(2);
|
3300
|
+
}
|
3301
|
+
context.logger.debug(
|
3302
|
+
"'--debug-benchmark' option found, measuring formatWithCursor with 'benchmark' module."
|
3303
|
+
);
|
3304
|
+
const suite = new benchmark.Suite();
|
3305
|
+
suite.add("format", {
|
3306
|
+
defer: true,
|
3307
|
+
async fn(deferred) {
|
3308
|
+
await prettier.formatWithCursor(input, opt);
|
3309
|
+
deferred.resolve();
|
3310
|
+
}
|
3311
|
+
});
|
3312
|
+
const result = await new Promise((resolve) => {
|
3313
|
+
suite.on("complete", (event) => {
|
3314
|
+
resolve({
|
3315
|
+
benchmark: String(event.target),
|
3316
|
+
hz: event.target.hz,
|
3317
|
+
ms: event.target.times.cycle * 1e3
|
3318
|
+
});
|
3319
|
+
}).run({ async: false });
|
3320
|
+
});
|
3321
|
+
context.logger.debug(
|
3322
|
+
"'--debug-benchmark' measurements for formatWithCursor: " + JSON.stringify(result, null, 2)
|
3323
|
+
);
|
3324
|
+
} else if (performanceTestFlag == null ? void 0 : performanceTestFlag.debugRepeat) {
|
3325
|
+
const repeat = performanceTestFlag.debugRepeat;
|
3326
|
+
context.logger.debug(
|
3327
|
+
`'${performanceTestFlag.name}' found, running formatWithCursor ${repeat} times.`
|
3328
|
+
);
|
3329
|
+
let totalMs = 0;
|
3330
|
+
for (let i = 0; i < repeat; ++i) {
|
3331
|
+
const startMs = Date.now();
|
3332
|
+
await prettier.formatWithCursor(input, opt);
|
3333
|
+
totalMs += Date.now() - startMs;
|
3334
|
+
}
|
3335
|
+
const averageMs = totalMs / repeat;
|
3336
|
+
const results = {
|
3337
|
+
repeat,
|
3338
|
+
hz: 1e3 / averageMs,
|
3339
|
+
ms: averageMs
|
3340
|
+
};
|
3341
|
+
context.logger.debug(
|
3342
|
+
`'${performanceTestFlag.name}' measurements for formatWithCursor: ${JSON.stringify(
|
3343
|
+
results,
|
3344
|
+
null,
|
3345
|
+
2
|
3346
|
+
)}`
|
3347
|
+
);
|
3348
|
+
}
|
3349
|
+
return prettier.formatWithCursor(input, opt);
|
3350
|
+
}
|
3351
|
+
async function createIsIgnoredFromContextOrDie(context) {
|
3352
|
+
try {
|
3353
|
+
return await createIsIgnoredFunction(
|
3354
|
+
context.argv.ignorePath,
|
3355
|
+
context.argv.withNodeModules
|
3356
|
+
);
|
3357
|
+
} catch (e) {
|
3358
|
+
context.logger.error(e.message);
|
3359
|
+
process.exit(2);
|
3360
|
+
}
|
3361
|
+
}
|
3362
|
+
async function formatStdin(context) {
|
3363
|
+
const { filepath } = context.argv;
|
3364
|
+
try {
|
3365
|
+
const input = await getStdin();
|
3366
|
+
let isFileIgnored = false;
|
3367
|
+
if (filepath) {
|
3368
|
+
const isIgnored = await createIsIgnoredFromContextOrDie(context);
|
3369
|
+
isFileIgnored = isIgnored(filepath);
|
3370
|
+
}
|
3371
|
+
if (isFileIgnored) {
|
3372
|
+
writeOutput(context, { formatted: input });
|
3373
|
+
return;
|
3374
|
+
}
|
3375
|
+
const options = await get_options_for_file_default(
|
3376
|
+
context,
|
3377
|
+
filepath ? path9.resolve(filepath) : void 0
|
3378
|
+
);
|
3379
|
+
if (await listDifferent(context, input, options, "(stdin)")) {
|
3380
|
+
return;
|
3381
|
+
}
|
3382
|
+
const formatted = await format3(context, input, options);
|
3383
|
+
const { performanceTestFlag } = context;
|
3384
|
+
if (performanceTestFlag) {
|
3385
|
+
context.logger.log(
|
3386
|
+
`'${performanceTestFlag.name}' option found, skipped print code to screen.`
|
3387
|
+
);
|
3388
|
+
return;
|
3389
|
+
}
|
3390
|
+
writeOutput(context, formatted, options);
|
3391
|
+
} catch (error) {
|
3392
|
+
handleError(context, filepath || "stdin", error);
|
3393
|
+
}
|
3394
|
+
}
|
3395
|
+
async function formatFiles(context) {
|
3396
|
+
const isIgnored = await createIsIgnoredFromContextOrDie(context);
|
3397
|
+
const cwd2 = process.cwd();
|
3398
|
+
let numberOfUnformattedFilesFound = 0;
|
3399
|
+
const { performanceTestFlag } = context;
|
3400
|
+
if (context.argv.check && !performanceTestFlag) {
|
3401
|
+
context.logger.log("Checking formatting...");
|
3402
|
+
}
|
3403
|
+
let formatResultsCache;
|
3404
|
+
const cacheFilePath = await find_cache_file_default(context.argv.cacheLocation);
|
3405
|
+
if (context.argv.cache) {
|
3406
|
+
formatResultsCache = new format_results_cache_default(
|
3407
|
+
cacheFilePath,
|
3408
|
+
context.argv.cacheStrategy || "content"
|
3409
|
+
);
|
3410
|
+
} else if (!context.argv.cacheLocation) {
|
3411
|
+
const stat = await statSafe(cacheFilePath);
|
3412
|
+
if (stat) {
|
3413
|
+
await fs5.unlink(cacheFilePath);
|
3414
|
+
}
|
3415
|
+
}
|
3416
|
+
for await (const { error, filename, ignoreUnknown } of expandPatterns(
|
3417
|
+
context
|
3418
|
+
)) {
|
3419
|
+
if (error) {
|
3420
|
+
context.logger.error(error);
|
3421
|
+
process.exitCode = 2;
|
3422
|
+
continue;
|
3423
|
+
}
|
3424
|
+
const isFileIgnored = isIgnored(filename);
|
3425
|
+
if (isFileIgnored && (context.argv.debugCheck || context.argv.write || context.argv.check || context.argv.listDifferent)) {
|
3426
|
+
continue;
|
3427
|
+
}
|
3428
|
+
const options = {
|
3429
|
+
...await get_options_for_file_default(context, filename),
|
3430
|
+
filepath: filename
|
3431
|
+
};
|
3432
|
+
const fileNameToDisplay = normalizeToPosix(path9.relative(cwd2, filename));
|
3433
|
+
let printedFilename;
|
3434
|
+
if (isTTY()) {
|
3435
|
+
printedFilename = context.logger.log(fileNameToDisplay, {
|
3436
|
+
newline: false,
|
3437
|
+
clearable: true
|
3438
|
+
});
|
3439
|
+
}
|
3440
|
+
let input;
|
3441
|
+
try {
|
3442
|
+
input = await fs5.readFile(filename, "utf8");
|
3443
|
+
} catch (error2) {
|
3444
|
+
context.logger.log("");
|
3445
|
+
context.logger.error(
|
3446
|
+
`Unable to read file "${fileNameToDisplay}":
|
3447
|
+
${error2.message}`
|
3448
|
+
);
|
3449
|
+
process.exitCode = 2;
|
3450
|
+
continue;
|
3451
|
+
}
|
3452
|
+
if (isFileIgnored) {
|
3453
|
+
printedFilename == null ? void 0 : printedFilename.clear();
|
3454
|
+
writeOutput(context, { formatted: input }, options);
|
3455
|
+
continue;
|
3456
|
+
}
|
3457
|
+
const start = Date.now();
|
3458
|
+
const isCacheExists = formatResultsCache == null ? void 0 : formatResultsCache.existsAvailableFormatResultsCache(
|
3459
|
+
filename,
|
3460
|
+
options
|
3461
|
+
);
|
3462
|
+
let result;
|
3463
|
+
let output;
|
3464
|
+
try {
|
3465
|
+
if (isCacheExists) {
|
3466
|
+
result = { formatted: input };
|
3467
|
+
} else {
|
3468
|
+
result = await format3(context, input, options);
|
3469
|
+
}
|
3470
|
+
output = result.formatted;
|
3471
|
+
} catch (error2) {
|
3472
|
+
handleError(
|
3473
|
+
context,
|
3474
|
+
fileNameToDisplay,
|
3475
|
+
error2,
|
3476
|
+
printedFilename,
|
3477
|
+
ignoreUnknown
|
3478
|
+
);
|
3479
|
+
continue;
|
3480
|
+
}
|
3481
|
+
const isDifferent = output !== input;
|
3482
|
+
let shouldSetCache = !isDifferent;
|
3483
|
+
printedFilename == null ? void 0 : printedFilename.clear();
|
3484
|
+
if (performanceTestFlag) {
|
3485
|
+
context.logger.log(
|
3486
|
+
`'${performanceTestFlag.name}' option found, skipped print code or write files.`
|
3487
|
+
);
|
3488
|
+
return;
|
3489
|
+
}
|
3490
|
+
if (context.argv.write) {
|
3491
|
+
if (isDifferent) {
|
3492
|
+
if (!context.argv.check && !context.argv.listDifferent) {
|
3493
|
+
context.logger.log(`${fileNameToDisplay} ${Date.now() - start}ms`);
|
3494
|
+
}
|
3495
|
+
try {
|
3496
|
+
await writeFormattedFile(filename, output);
|
3497
|
+
shouldSetCache = true;
|
3498
|
+
} catch (error2) {
|
3499
|
+
context.logger.error(
|
3500
|
+
`Unable to write file "${fileNameToDisplay}":
|
3501
|
+
${error2.message}`
|
3502
|
+
);
|
3503
|
+
process.exitCode = 2;
|
3504
|
+
}
|
3505
|
+
} else if (!context.argv.check && !context.argv.listDifferent) {
|
3506
|
+
const message = `${source_default.grey(fileNameToDisplay)} ${Date.now() - start}ms (unchanged)`;
|
3507
|
+
if (isCacheExists) {
|
3508
|
+
context.logger.log(`${message} (cached)`);
|
3509
|
+
} else {
|
3510
|
+
context.logger.log(message);
|
3511
|
+
}
|
3512
|
+
}
|
3513
|
+
} else if (context.argv.debugCheck) {
|
3514
|
+
if (result.filepath) {
|
3515
|
+
context.logger.log(fileNameToDisplay);
|
3516
|
+
} else {
|
3517
|
+
process.exitCode = 2;
|
3518
|
+
}
|
3519
|
+
} else if (!context.argv.check && !context.argv.listDifferent) {
|
3520
|
+
writeOutput(context, result, options);
|
3521
|
+
}
|
3522
|
+
if (shouldSetCache) {
|
3523
|
+
formatResultsCache == null ? void 0 : formatResultsCache.setFormatResultsCache(filename, options);
|
3524
|
+
} else {
|
3525
|
+
formatResultsCache == null ? void 0 : formatResultsCache.removeFormatResultsCache(filename);
|
3526
|
+
}
|
3527
|
+
if (isDifferent) {
|
3528
|
+
if (context.argv.check) {
|
3529
|
+
context.logger.warn(fileNameToDisplay);
|
3530
|
+
} else if (context.argv.listDifferent) {
|
3531
|
+
context.logger.log(fileNameToDisplay);
|
3532
|
+
}
|
3533
|
+
numberOfUnformattedFilesFound += 1;
|
3534
|
+
}
|
3535
|
+
}
|
3536
|
+
formatResultsCache == null ? void 0 : formatResultsCache.reconcile();
|
3537
|
+
if (context.argv.check) {
|
3538
|
+
if (numberOfUnformattedFilesFound === 0) {
|
3539
|
+
context.logger.log("All matched files use Prettier code style!");
|
3540
|
+
} else {
|
3541
|
+
const files = numberOfUnformattedFilesFound === 1 ? "the above file" : `${numberOfUnformattedFilesFound} files`;
|
3542
|
+
context.logger.warn(
|
3543
|
+
context.argv.write ? `Code style issues fixed in ${files}.` : `Code style issues found in ${files}. Run Prettier with --write to fix.`
|
3544
|
+
);
|
3545
|
+
}
|
3546
|
+
}
|
3547
|
+
if ((context.argv.check || context.argv.listDifferent) && numberOfUnformattedFilesFound > 0 && !process.exitCode && !context.argv.write) {
|
3548
|
+
process.exitCode = 1;
|
3549
|
+
}
|
3550
|
+
}
|
3551
|
+
|
3552
|
+
// src/cli/logger.js
|
3553
|
+
import readline from "readline";
|
3554
|
+
|
3555
|
+
// node_modules/ansi-regex/index.js
|
3556
|
+
function ansiRegex({ onlyFirst = false } = {}) {
|
3557
|
+
const pattern = [
|
3558
|
+
"[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
|
3559
|
+
"(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))"
|
3560
|
+
].join("|");
|
3561
|
+
return new RegExp(pattern, onlyFirst ? void 0 : "g");
|
3562
|
+
}
|
3563
|
+
|
3564
|
+
// node_modules/strip-ansi/index.js
|
3565
|
+
var regex = ansiRegex();
|
3566
|
+
function stripAnsi(string) {
|
3567
|
+
if (typeof string !== "string") {
|
3568
|
+
throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
|
3569
|
+
}
|
3570
|
+
return string.replace(regex, "");
|
3571
|
+
}
|
3572
|
+
|
3573
|
+
// src/cli/logger.js
|
3574
|
+
var import_wcwidth = __toESM(require_wcwidth(), 1);
|
3575
|
+
var countLines = (stream, text) => {
|
3576
|
+
const columns = stream.columns || 80;
|
3577
|
+
let lineCount = 0;
|
3578
|
+
for (const line of stripAnsi(text).split("\n")) {
|
3579
|
+
lineCount += Math.max(1, Math.ceil((0, import_wcwidth.default)(line) / columns));
|
3580
|
+
}
|
3581
|
+
return lineCount;
|
3582
|
+
};
|
3583
|
+
var clear = (stream, text) => () => {
|
3584
|
+
const lineCount = countLines(stream, text);
|
3585
|
+
for (let line = 0; line < lineCount; line++) {
|
3586
|
+
if (line > 0) {
|
3587
|
+
readline.moveCursor(stream, 0, -1);
|
3588
|
+
}
|
3589
|
+
readline.clearLine(stream, 0);
|
3590
|
+
readline.cursorTo(stream, 0);
|
3591
|
+
}
|
3592
|
+
};
|
3593
|
+
var emptyLogResult = {
|
3594
|
+
clear() {
|
3595
|
+
}
|
3596
|
+
};
|
3597
|
+
function createLogger(logLevel = "log") {
|
3598
|
+
return {
|
3599
|
+
logLevel,
|
3600
|
+
warn: createLogFunc("warn", "yellow"),
|
3601
|
+
error: createLogFunc("error", "red"),
|
3602
|
+
debug: createLogFunc("debug", "blue"),
|
3603
|
+
log: createLogFunc("log")
|
3604
|
+
};
|
3605
|
+
function createLogFunc(loggerName, color) {
|
3606
|
+
if (!shouldLog(loggerName)) {
|
3607
|
+
return () => emptyLogResult;
|
3608
|
+
}
|
3609
|
+
const stream = process[loggerName === "log" ? "stdout" : "stderr"];
|
3610
|
+
const chalkInstance = loggerName === "log" ? source_default : chalkStderr;
|
3611
|
+
const prefix = color ? `[${chalkInstance[color](loggerName)}] ` : "";
|
3612
|
+
return (message, options) => {
|
3613
|
+
options = {
|
3614
|
+
newline: true,
|
3615
|
+
clearable: false,
|
3616
|
+
...options
|
3617
|
+
};
|
3618
|
+
message = string_replace_all_default(
|
3619
|
+
/* isOptionalObject */
|
3620
|
+
false,
|
3621
|
+
message,
|
3622
|
+
/^/gmu,
|
3623
|
+
prefix
|
3624
|
+
) + (options.newline ? "\n" : "");
|
3625
|
+
stream.write(message);
|
3626
|
+
if (options.clearable) {
|
3627
|
+
return {
|
3628
|
+
clear: clear(stream, message)
|
3629
|
+
};
|
3630
|
+
}
|
3631
|
+
};
|
3632
|
+
}
|
3633
|
+
function shouldLog(loggerName) {
|
3634
|
+
switch (logLevel) {
|
3635
|
+
case "silent":
|
3636
|
+
return false;
|
3637
|
+
case "debug":
|
3638
|
+
if (loggerName === "debug") {
|
3639
|
+
return true;
|
3640
|
+
}
|
3641
|
+
case "log":
|
3642
|
+
if (loggerName === "log") {
|
3643
|
+
return true;
|
3644
|
+
}
|
3645
|
+
case "warn":
|
3646
|
+
if (loggerName === "warn") {
|
3647
|
+
return true;
|
3648
|
+
}
|
3649
|
+
case "error":
|
3650
|
+
return loggerName === "error";
|
3651
|
+
}
|
3652
|
+
}
|
3653
|
+
}
|
3654
|
+
var logger_default = createLogger;
|
3655
|
+
|
3656
|
+
// src/cli/print-support-info.js
|
3657
|
+
var import_fast_json_stable_stringify3 = __toESM(require_fast_json_stable_stringify(), 1);
|
3658
|
+
import { format as format4, getSupportInfo as getSupportInfo2 } from "../index.mjs";
|
3659
|
+
var sortByName = (array2) => array2.sort((a, b) => a.name.localeCompare(b.name));
|
3660
|
+
async function printSupportInfo() {
|
3661
|
+
const { languages, options } = await getSupportInfo2();
|
3662
|
+
const supportInfo = {
|
3663
|
+
languages: sortByName(languages),
|
3664
|
+
options: sortByName(options).map(
|
3665
|
+
(option) => omit(option, ["cliName", "cliCategory", "cliDescription"])
|
3666
|
+
)
|
3667
|
+
};
|
3668
|
+
printToScreen(await format4((0, import_fast_json_stable_stringify3.default)(supportInfo), { parser: "json" }));
|
3669
|
+
}
|
3670
|
+
var print_support_info_default = printSupportInfo;
|
3671
|
+
|
3672
|
+
// src/cli/constants.evaluate.js
|
3673
|
+
var categoryOrder = [
|
3674
|
+
"Output",
|
3675
|
+
"Format",
|
3676
|
+
"Config",
|
3677
|
+
"Editor",
|
3678
|
+
"Other"
|
3679
|
+
];
|
3680
|
+
var usageSummary = "Usage: prettier [options] [file/dir/glob ...]\n\nBy default, output is written to stdout.\nStdin is read if it is piped to Prettier and no files are given.";
|
3681
|
+
|
3682
|
+
// src/cli/usage.js
|
3683
|
+
var OPTION_USAGE_THRESHOLD = 25;
|
3684
|
+
var CHOICE_USAGE_MARGIN = 3;
|
3685
|
+
var CHOICE_USAGE_INDENTATION = 2;
|
3686
|
+
function indent(str, spaces) {
|
3687
|
+
return string_replace_all_default(
|
3688
|
+
/* isOptionalObject */
|
3689
|
+
false,
|
3690
|
+
str,
|
3691
|
+
/^/gmu,
|
3692
|
+
" ".repeat(spaces)
|
3693
|
+
);
|
3694
|
+
}
|
3695
|
+
function createDefaultValueDisplay(value) {
|
3696
|
+
return Array.isArray(value) ? `[${value.map(createDefaultValueDisplay).join(", ")}]` : value;
|
3697
|
+
}
|
3698
|
+
function getOptionDefaultValue(context, optionName) {
|
3699
|
+
var _a;
|
3700
|
+
const option = context.detailedOptions.find(({
|
3701
|
+
name
|
3702
|
+
}) => name === optionName);
|
3703
|
+
if ((option == null ? void 0 : option.default) !== void 0) {
|
3704
|
+
return option.default;
|
3705
|
+
}
|
3706
|
+
const optionCamelName = camelCase(optionName);
|
3707
|
+
return formatOptionsHiddenDefaults[optionCamelName] ?? ((_a = context.supportOptions.find((option2) => !option2.deprecated && option2.name === optionCamelName)) == null ? void 0 : _a.default);
|
3708
|
+
}
|
3709
|
+
function createOptionUsageHeader(option) {
|
3710
|
+
const name = `--${option.name}`;
|
3711
|
+
const alias = option.alias ? `-${option.alias},` : null;
|
3712
|
+
const type = createOptionUsageType(option);
|
3713
|
+
return [alias, name, type].filter(Boolean).join(" ");
|
3714
|
+
}
|
3715
|
+
function createOptionUsageRow(header, content, threshold) {
|
3716
|
+
const separator = header.length >= threshold ? `
|
3717
|
+
${" ".repeat(threshold)}` : " ".repeat(threshold - header.length);
|
3718
|
+
const description = string_replace_all_default(
|
3719
|
+
/* isOptionalObject */
|
3720
|
+
false,
|
3721
|
+
content,
|
3722
|
+
"\n",
|
3723
|
+
`
|
3724
|
+
${" ".repeat(threshold)}`
|
3725
|
+
);
|
3726
|
+
return `${header}${separator}${description}`;
|
3727
|
+
}
|
3728
|
+
function createOptionUsageType(option) {
|
3729
|
+
switch (option.type) {
|
3730
|
+
case "boolean":
|
3731
|
+
return null;
|
3732
|
+
case "choice":
|
3733
|
+
return `<${option.choices.filter((choice) => !choice.deprecated).map((choice) => choice.value).join("|")}>`;
|
3734
|
+
default:
|
3735
|
+
return `<${option.type}>`;
|
3736
|
+
}
|
3737
|
+
}
|
3738
|
+
function createChoiceUsages(choices, margin, indentation) {
|
3739
|
+
const activeChoices = choices.filter((choice) => !choice.deprecated);
|
3740
|
+
const threshold = Math.max(0, ...activeChoices.map((choice) => choice.value.length)) + margin;
|
3741
|
+
return activeChoices.map((choice) => indent(createOptionUsageRow(choice.value, choice.description, threshold), indentation));
|
3742
|
+
}
|
3743
|
+
function createOptionUsage(context, option, threshold) {
|
3744
|
+
const header = createOptionUsageHeader(option);
|
3745
|
+
const optionDefaultValue = getOptionDefaultValue(context, option.name);
|
3746
|
+
return createOptionUsageRow(header, `${option.description}${optionDefaultValue === void 0 ? "" : `
|
3747
|
+
Defaults to ${createDefaultValueDisplay(optionDefaultValue)}.`}`, threshold);
|
3748
|
+
}
|
3749
|
+
function getOptionsWithOpposites(options) {
|
3750
|
+
const optionsWithOpposites = options.map((option) => [option.description ? option : null, option.oppositeDescription ? {
|
3751
|
+
...option,
|
3752
|
+
name: `no-${option.name}`,
|
3753
|
+
type: "boolean",
|
3754
|
+
description: option.oppositeDescription
|
3755
|
+
} : null]);
|
3756
|
+
return optionsWithOpposites.flat().filter(Boolean);
|
3757
|
+
}
|
3758
|
+
function createUsage(context) {
|
3759
|
+
const sortedOptions = context.detailedOptions.sort((optionA, optionB) => optionA.name.localeCompare(optionB.name));
|
3760
|
+
const options = getOptionsWithOpposites(sortedOptions).filter(
|
3761
|
+
// remove unnecessary option (e.g. `semi`, `color`, etc.), which is only used for --help <flag>
|
3762
|
+
(option) => !(option.type === "boolean" && option.oppositeDescription && !option.name.startsWith("no-"))
|
3763
|
+
);
|
3764
|
+
const groupedOptions = groupBy(options, (option) => option.category);
|
3765
|
+
const firstCategories = categoryOrder.slice(0, -1);
|
3766
|
+
const lastCategories = categoryOrder.slice(-1);
|
3767
|
+
const restCategories = Object.keys(groupedOptions).filter((category) => !categoryOrder.includes(category));
|
3768
|
+
const allCategories = [...firstCategories, ...restCategories, ...lastCategories];
|
3769
|
+
const optionsUsage = allCategories.map((category) => {
|
3770
|
+
const categoryOptions = groupedOptions[category].map((option) => createOptionUsage(context, option, OPTION_USAGE_THRESHOLD)).join("\n");
|
3771
|
+
return `${category} options:
|
3772
|
+
|
3773
|
+
${indent(categoryOptions, 2)}`;
|
3774
|
+
});
|
3775
|
+
return [usageSummary, ...optionsUsage, ""].join("\n\n");
|
3776
|
+
}
|
3777
|
+
function createPluginDefaults(pluginDefaults) {
|
3778
|
+
if (!pluginDefaults || Object.keys(pluginDefaults).length === 0) {
|
3779
|
+
return "";
|
3780
|
+
}
|
3781
|
+
const defaults = Object.entries(pluginDefaults).sort(([pluginNameA], [pluginNameB]) => pluginNameA.localeCompare(pluginNameB)).map(([plugin, value]) => `* ${plugin}: ${createDefaultValueDisplay(value)}`).join("\n");
|
3782
|
+
return `
|
3783
|
+
Plugin defaults:
|
3784
|
+
${defaults}`;
|
3785
|
+
}
|
3786
|
+
function createDetailedUsage(context, flag) {
|
3787
|
+
const option = getOptionsWithOpposites(context.detailedOptions).find((option2) => option2.name === flag || option2.alias === flag);
|
3788
|
+
const header = createOptionUsageHeader(option);
|
3789
|
+
const description = `
|
3790
|
+
|
3791
|
+
${indent(option.description, 2)}`;
|
3792
|
+
const choices = option.type !== "choice" ? "" : `
|
3793
|
+
|
3794
|
+
Valid options:
|
3795
|
+
|
3796
|
+
${createChoiceUsages(option.choices, CHOICE_USAGE_MARGIN, CHOICE_USAGE_INDENTATION).join("\n")}`;
|
3797
|
+
const optionDefaultValue = getOptionDefaultValue(context, option.name);
|
3798
|
+
const defaults = optionDefaultValue !== void 0 ? `
|
3799
|
+
|
3800
|
+
Default: ${createDefaultValueDisplay(optionDefaultValue)}` : "";
|
3801
|
+
const pluginDefaults = createPluginDefaults(option.pluginDefaults);
|
3802
|
+
return `${header}${description}${choices}${defaults}${pluginDefaults}`;
|
3803
|
+
}
|
3804
|
+
|
3805
|
+
// src/cli/index.js
|
3806
|
+
async function run(rawArguments = process.argv.slice(2)) {
|
3807
|
+
let logger = logger_default();
|
3808
|
+
try {
|
3809
|
+
const { logLevel } = parseArgvWithoutPlugins(
|
3810
|
+
rawArguments,
|
3811
|
+
logger,
|
3812
|
+
"log-level"
|
3813
|
+
);
|
3814
|
+
if (logLevel !== logger.logLevel) {
|
3815
|
+
logger = logger_default(logLevel);
|
3816
|
+
}
|
3817
|
+
const context = new context_default({ rawArguments, logger });
|
3818
|
+
await context.init();
|
3819
|
+
if (logger.logLevel !== "debug" && context.performanceTestFlag) {
|
3820
|
+
context.logger = logger_default("debug");
|
3821
|
+
}
|
3822
|
+
await main(context);
|
3823
|
+
} catch (error) {
|
3824
|
+
logger.error(error.message);
|
3825
|
+
process.exitCode = 1;
|
3826
|
+
}
|
3827
|
+
}
|
3828
|
+
async function main(context) {
|
3829
|
+
context.logger.debug(`normalized argv: ${JSON.stringify(context.argv)}`);
|
3830
|
+
if (context.argv.check && context.argv.listDifferent) {
|
3831
|
+
throw new Error("Cannot use --check and --list-different together.");
|
3832
|
+
}
|
3833
|
+
if (context.argv.write && context.argv.debugCheck) {
|
3834
|
+
throw new Error("Cannot use --write and --debug-check together.");
|
3835
|
+
}
|
3836
|
+
if (context.argv.findConfigPath && context.filePatterns.length > 0) {
|
3837
|
+
throw new Error("Cannot use --find-config-path with multiple files");
|
3838
|
+
}
|
3839
|
+
if (context.argv.fileInfo && context.filePatterns.length > 0) {
|
3840
|
+
throw new Error("Cannot use --file-info with multiple files");
|
3841
|
+
}
|
3842
|
+
if (!context.argv.cache && context.argv.cacheStrategy) {
|
3843
|
+
throw new Error("`--cache-strategy` cannot be used without `--cache`.");
|
3844
|
+
}
|
3845
|
+
if (context.argv.version) {
|
3846
|
+
printToScreen(prettier2.version);
|
3847
|
+
return;
|
3848
|
+
}
|
3849
|
+
if (context.argv.help !== void 0) {
|
3850
|
+
printToScreen(
|
3851
|
+
typeof context.argv.help === "string" && context.argv.help !== "" ? createDetailedUsage(context, context.argv.help) : createUsage(context)
|
3852
|
+
);
|
3853
|
+
return;
|
3854
|
+
}
|
3855
|
+
if (context.argv.supportInfo) {
|
3856
|
+
return print_support_info_default();
|
3857
|
+
}
|
3858
|
+
if (context.argv.findConfigPath) {
|
3859
|
+
await find_config_path_default(context);
|
3860
|
+
return;
|
3861
|
+
}
|
3862
|
+
if (context.argv.fileInfo) {
|
3863
|
+
await file_info_default(context);
|
3864
|
+
return;
|
3865
|
+
}
|
3866
|
+
const hasFilePatterns = context.filePatterns.length > 0;
|
3867
|
+
const useStdin = !hasFilePatterns && (!process.stdin.isTTY || context.argv.filepath);
|
3868
|
+
if (useStdin) {
|
3869
|
+
if (context.argv.cache) {
|
3870
|
+
throw new Error("`--cache` cannot be used when formatting stdin.");
|
3871
|
+
}
|
3872
|
+
await formatStdin(context);
|
3873
|
+
return;
|
3874
|
+
}
|
3875
|
+
if (hasFilePatterns) {
|
3876
|
+
await formatFiles(context);
|
3877
|
+
return;
|
3878
|
+
}
|
3879
|
+
process.exitCode = 1;
|
3880
|
+
printToScreen(createUsage(context));
|
3881
|
+
}
|
3882
|
+
export {
|
3883
|
+
run
|
3884
|
+
};
|