dorian 2.3.0 → 2.5.0

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