prettier 3.8.4 → 3.9.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.
@@ -18,7 +18,11 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
18
18
  throw Error('Dynamic require of "' + x + '" is not supported');
19
19
  });
20
20
  var __commonJS = (cb, mod) => function __require2() {
21
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
21
+ try {
22
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
23
+ } catch (e) {
24
+ throw mod = 0, e;
25
+ }
22
26
  };
23
27
  var __copyProps = (to, from, except, desc) => {
24
28
  if (from && typeof from === "object" || typeof from === "function") {
@@ -368,6 +372,11 @@ var require_vendors = __commonJS({
368
372
  env: "AGOLA_GIT_REF",
369
373
  pr: "AGOLA_PULL_REQUEST_ID"
370
374
  },
375
+ {
376
+ name: "Alpic",
377
+ constant: "ALPIC",
378
+ env: "ALPIC_HOST"
379
+ },
371
380
  {
372
381
  name: "Appcircle",
373
382
  constant: "APPCIRCLE",
@@ -820,7 +829,7 @@ var createMethodShim = (methodName, getImplementation) => (flags, object2, ...ar
820
829
  function stringOrArrayAt(index) {
821
830
  return this[index < 0 ? this.length + index : index];
822
831
  }
823
- var at = createMethodShim("at", function() {
832
+ var at = /* @__PURE__ */ createMethodShim("at", function() {
824
833
  if (Array.isArray(this) || typeof this === "string") {
825
834
  return stringOrArrayAt;
826
835
  }
@@ -1083,7 +1092,7 @@ var stringReplaceAll = String.prototype.replaceAll ?? function(pattern, replacem
1083
1092
  }
1084
1093
  return this.split(pattern).join(replacement);
1085
1094
  };
1086
- var replaceAll = createMethodShim("replaceAll", function() {
1095
+ var replaceAll = /* @__PURE__ */ createMethodShim("replaceAll", function() {
1087
1096
  if (typeof this === "string") {
1088
1097
  return stringReplaceAll;
1089
1098
  }
@@ -1233,34 +1242,97 @@ function camelCase(input, options) {
1233
1242
  import fs from "fs/promises";
1234
1243
  import path from "path";
1235
1244
 
1236
- // node_modules/sdbm/index.js
1237
- var textEncoder = new TextEncoder();
1238
- function sdbmHash(input, options) {
1239
- if (typeof input === "string") {
1240
- if (options?.bytes) {
1241
- input = textEncoder.encode(input);
1242
- } else {
1243
- let hash3 = 0n;
1244
- for (let index = 0; index < input.length; index++) {
1245
- hash3 = BigInt(input.charCodeAt(index)) + (hash3 << 6n) + (hash3 << 16n) - hash3;
1246
- }
1247
- return hash3;
1245
+ // node_modules/imurmurhash-esm/index.js
1246
+ var cache;
1247
+ function MurmurHash3(key, seed) {
1248
+ var m = this;
1249
+ if (!(this instanceof MurmurHash3)) {
1250
+ if (!cache) {
1251
+ cache ?? (cache = new MurmurHash3());
1248
1252
  }
1249
- } else if (!(input instanceof Uint8Array)) {
1250
- throw new TypeError("Expected a string or Uint8Array");
1253
+ m = cache;
1251
1254
  }
1252
- let hash2 = 0n;
1253
- for (const byte of input) {
1254
- hash2 = BigInt(byte) + (hash2 << 6n) + (hash2 << 16n) - hash2;
1255
+ m.reset(seed);
1256
+ if (typeof key === "string" && key.length > 0) {
1257
+ m.hash(key);
1258
+ }
1259
+ if (m !== this) {
1260
+ return m;
1255
1261
  }
1256
- return hash2;
1257
- }
1258
- function sdbm(input, options) {
1259
- return Number(BigInt.asUintN(32, sdbmHash(input, options)));
1260
1262
  }
1261
- sdbm.bigint = function(input, options) {
1262
- return BigInt.asUintN(64, sdbmHash(input, options));
1263
+ MurmurHash3.prototype.hash = function(key) {
1264
+ var h1, k1, i, top, len;
1265
+ len = key.length;
1266
+ this.len += len;
1267
+ k1 = this.k1;
1268
+ i = 0;
1269
+ switch (this.rem) {
1270
+ case 0:
1271
+ k1 ^= len > i ? key.charCodeAt(i++) & 65535 : 0;
1272
+ case 1:
1273
+ k1 ^= len > i ? (key.charCodeAt(i++) & 65535) << 8 : 0;
1274
+ case 2:
1275
+ k1 ^= len > i ? (key.charCodeAt(i++) & 65535) << 16 : 0;
1276
+ case 3:
1277
+ k1 ^= len > i ? (key.charCodeAt(i) & 255) << 24 : 0;
1278
+ k1 ^= len > i ? (key.charCodeAt(i++) & 65280) >> 8 : 0;
1279
+ }
1280
+ this.rem = len + this.rem & 3;
1281
+ len -= this.rem;
1282
+ if (len > 0) {
1283
+ h1 = this.h1;
1284
+ while (1) {
1285
+ k1 = k1 * 11601 + (k1 & 65535) * 3432906752 & 4294967295;
1286
+ k1 = k1 << 15 | k1 >>> 17;
1287
+ k1 = k1 * 13715 + (k1 & 65535) * 461832192 & 4294967295;
1288
+ h1 ^= k1;
1289
+ h1 = h1 << 13 | h1 >>> 19;
1290
+ h1 = h1 * 5 + 3864292196 & 4294967295;
1291
+ if (i >= len) {
1292
+ break;
1293
+ }
1294
+ k1 = key.charCodeAt(i++) & 65535 ^ (key.charCodeAt(i++) & 65535) << 8 ^ (key.charCodeAt(i++) & 65535) << 16;
1295
+ top = key.charCodeAt(i++);
1296
+ k1 ^= (top & 255) << 24 ^ (top & 65280) >> 8;
1297
+ }
1298
+ k1 = 0;
1299
+ switch (this.rem) {
1300
+ case 3:
1301
+ k1 ^= (key.charCodeAt(i + 2) & 65535) << 16;
1302
+ case 2:
1303
+ k1 ^= (key.charCodeAt(i + 1) & 65535) << 8;
1304
+ case 1:
1305
+ k1 ^= key.charCodeAt(i) & 65535;
1306
+ }
1307
+ this.h1 = h1;
1308
+ }
1309
+ this.k1 = k1;
1310
+ return this;
1311
+ };
1312
+ MurmurHash3.prototype.result = function() {
1313
+ var k1, h1;
1314
+ k1 = this.k1;
1315
+ h1 = this.h1;
1316
+ if (k1 > 0) {
1317
+ k1 = k1 * 11601 + (k1 & 65535) * 3432906752 & 4294967295;
1318
+ k1 = k1 << 15 | k1 >>> 17;
1319
+ k1 = k1 * 13715 + (k1 & 65535) * 461832192 & 4294967295;
1320
+ h1 ^= k1;
1321
+ }
1322
+ h1 ^= this.len;
1323
+ h1 ^= h1 >>> 16;
1324
+ h1 = h1 * 51819 + (h1 & 65535) * 2246770688 & 4294967295;
1325
+ h1 ^= h1 >>> 13;
1326
+ h1 = h1 * 44597 + (h1 & 65535) * 3266445312 & 4294967295;
1327
+ h1 ^= h1 >>> 16;
1328
+ return h1 >>> 0;
1329
+ };
1330
+ MurmurHash3.prototype.reset = function(seed) {
1331
+ this.h1 = typeof seed === "number" ? seed : 0;
1332
+ this.rem = this.k1 = this.len = 0;
1333
+ return this;
1263
1334
  };
1335
+ var imurmurhash_esm_default = MurmurHash3;
1264
1336
 
1265
1337
  // src/cli/utilities.js
1266
1338
  import { __internal as sharedWithCli2 } from "../index.mjs";
@@ -1281,8 +1353,8 @@ function pick(object2, keys2) {
1281
1353
  const entries = keys2.map((key) => [key, object2[key]]);
1282
1354
  return Object.fromEntries(entries);
1283
1355
  }
1284
- function createHash(source) {
1285
- return String(sdbm(source));
1356
+ function createHash(string) {
1357
+ return imurmurhash_esm_default(string).result().toString(36);
1286
1358
  }
1287
1359
  async function statSafe(filePath) {
1288
1360
  try {
@@ -1318,13 +1390,14 @@ var normalizeToPosix = path.sep === "\\" ? (filepath) => method_replace_all_defa
1318
1390
  "/"
1319
1391
  ) : (filepath) => filepath;
1320
1392
  var {
1321
- omit
1393
+ omit,
1394
+ getOrInsertComputed
1322
1395
  } = sharedWithCli2.utilities;
1323
1396
 
1324
1397
  // src/cli/options/create-minimist-options.js
1325
1398
  function createMinimistOptions(detailedOptions) {
1326
1399
  const booleanNames = [];
1327
- const stringNames = [];
1400
+ const stringNames = ["_"];
1328
1401
  const defaultValues = {};
1329
1402
  for (const option of detailedOptions) {
1330
1403
  const { name, alias, type } = option;
@@ -1426,7 +1499,7 @@ function parseArgv(rawArguments, detailedOptions, logger, keys2) {
1426
1499
  return [option.forwardToApi || camelCase(key), value];
1427
1500
  })
1428
1501
  ),
1429
- _: normalized._?.map(String),
1502
+ _: normalized._,
1430
1503
  get __raw() {
1431
1504
  return argv2;
1432
1505
  }
@@ -1503,7 +1576,7 @@ var Context = class {
1503
1576
  const {
1504
1577
  PRETTIER_PERF_REPEAT
1505
1578
  } = process.env;
1506
- if (PRETTIER_PERF_REPEAT && /^\d+$/u.test(PRETTIER_PERF_REPEAT)) {
1579
+ if (PRETTIER_PERF_REPEAT && /^\d+$/.test(PRETTIER_PERF_REPEAT)) {
1507
1580
  return {
1508
1581
  name: "PRETTIER_PERF_REPEAT (environment variable)",
1509
1582
  debugRepeat: Number(PRETTIER_PERF_REPEAT)
@@ -1765,11 +1838,11 @@ function escapePathForGlob(path13) {
1765
1838
  )
1766
1839
  // Workaround for fast-glob#262 (part 1)
1767
1840
  ),
1768
- "\\!",
1769
- "@(!)"
1841
+ "\0",
1842
+ "@(\\\\)"
1770
1843
  ),
1771
- "\0",
1772
- "@(\\\\)"
1844
+ '"',
1845
+ '@(\\")'
1773
1846
  );
1774
1847
  }
1775
1848
  var fixWindowsSlashes = normalizeToPosix;
@@ -2135,6 +2208,7 @@ var Eventified = class {
2135
2208
  }
2136
2209
  }
2137
2210
  }
2211
+ this.sendLog(event, arguments_);
2138
2212
  return result;
2139
2213
  }
2140
2214
  /**
@@ -2182,6 +2256,54 @@ var Eventified = class {
2182
2256
  }
2183
2257
  return result;
2184
2258
  }
2259
+ /**
2260
+ * Sends a log message using the configured logger based on the event name
2261
+ * @param {string | symbol} eventName - The event name that determines the log level
2262
+ * @param {unknown} data - The data to log
2263
+ */
2264
+ sendLog(eventName, data) {
2265
+ if (!this._logger) {
2266
+ return;
2267
+ }
2268
+ let message;
2269
+ if (typeof data === "string") {
2270
+ message = data;
2271
+ } else if (Array.isArray(data) && data.length > 0 && data[0] instanceof Error) {
2272
+ message = data[0].message;
2273
+ } else if (data instanceof Error) {
2274
+ message = data.message;
2275
+ } else if (Array.isArray(data) && data.length > 0 && typeof data[0]?.message === "string") {
2276
+ message = data[0].message;
2277
+ } else {
2278
+ message = JSON.stringify(data);
2279
+ }
2280
+ switch (eventName) {
2281
+ case "error": {
2282
+ this._logger.error?.(message, { event: eventName, data });
2283
+ break;
2284
+ }
2285
+ case "warn": {
2286
+ this._logger.warn?.(message, { event: eventName, data });
2287
+ break;
2288
+ }
2289
+ case "trace": {
2290
+ this._logger.trace?.(message, { event: eventName, data });
2291
+ break;
2292
+ }
2293
+ case "debug": {
2294
+ this._logger.debug?.(message, { event: eventName, data });
2295
+ break;
2296
+ }
2297
+ case "fatal": {
2298
+ this._logger.fatal?.(message, { event: eventName, data });
2299
+ break;
2300
+ }
2301
+ default: {
2302
+ this._logger.info?.(message, { event: eventName, data });
2303
+ break;
2304
+ }
2305
+ }
2306
+ }
2185
2307
  };
2186
2308
  var Hookified = class extends Eventified {
2187
2309
  _hooks;
@@ -2314,9 +2436,6 @@ var Hookified = class extends Eventified {
2314
2436
  const message = this._deprecatedHooks.get(event);
2315
2437
  const warningMessage = `Hook "${event}" is deprecated${message ? `: ${message}` : ""}`;
2316
2438
  this.emit("warn", { hook: event, message: warningMessage });
2317
- if (this.logger?.warn) {
2318
- this.logger.warn(warningMessage);
2319
- }
2320
2439
  return this._allowDeprecated;
2321
2440
  }
2322
2441
  return true;
@@ -2328,24 +2447,24 @@ var Hookified = class extends Eventified {
2328
2447
  * @returns {void}
2329
2448
  */
2330
2449
  onHook(event, handler) {
2331
- this.validateHookName(event);
2332
- if (!this.checkDeprecatedHook(event)) {
2333
- return;
2334
- }
2335
- const eventHandlers = this._hooks.get(event);
2336
- if (eventHandlers) {
2337
- eventHandlers.push(handler);
2338
- } else {
2339
- this._hooks.set(event, [handler]);
2340
- }
2450
+ this.onHookEntry({ event, handler });
2341
2451
  }
2342
2452
  /**
2343
- * Adds a handler function for a specific event that runs before all other handlers
2453
+ * Adds a handler function for a specific event
2344
2454
  * @param {HookEntry} hookEntry
2345
2455
  * @returns {void}
2346
2456
  */
2347
2457
  onHookEntry(hookEntry) {
2348
- this.onHook(hookEntry.event, hookEntry.handler);
2458
+ this.validateHookName(hookEntry.event);
2459
+ if (!this.checkDeprecatedHook(hookEntry.event)) {
2460
+ return;
2461
+ }
2462
+ const eventHandlers = this._hooks.get(hookEntry.event);
2463
+ if (eventHandlers) {
2464
+ eventHandlers.push(hookEntry.handler);
2465
+ } else {
2466
+ this._hooks.set(hookEntry.event, [hookEntry.handler]);
2467
+ }
2349
2468
  }
2350
2469
  /**
2351
2470
  * Alias for onHook. This is provided for compatibility with other libraries that use the `addHook` method.
@@ -2354,7 +2473,7 @@ var Hookified = class extends Eventified {
2354
2473
  * @returns {void}
2355
2474
  */
2356
2475
  addHook(event, handler) {
2357
- this.onHook(event, handler);
2476
+ this.onHookEntry({ event, handler });
2358
2477
  }
2359
2478
  /**
2360
2479
  * Adds a handler function for a specific event
@@ -2464,9 +2583,39 @@ var Hookified = class extends Eventified {
2464
2583
  } catch (error) {
2465
2584
  const message = `${event}: ${error.message}`;
2466
2585
  this.emit("error", new Error(message));
2467
- if (this.logger) {
2468
- this.logger.error(message);
2586
+ if (this._throwOnHookError) {
2587
+ throw new Error(message);
2469
2588
  }
2589
+ }
2590
+ }
2591
+ }
2592
+ }
2593
+ /**
2594
+ * Calls all synchronous handlers for a specific event.
2595
+ * Async handlers (declared with `async` keyword) are silently skipped.
2596
+ *
2597
+ * Note: The `hook` method is preferred as it executes both sync and async functions.
2598
+ * Use `hookSync` only when you specifically need synchronous execution.
2599
+ * @param {string} event
2600
+ * @param {T[]} arguments_
2601
+ * @returns {void}
2602
+ */
2603
+ hookSync(event, ...arguments_) {
2604
+ this.validateHookName(event);
2605
+ if (!this.checkDeprecatedHook(event)) {
2606
+ return;
2607
+ }
2608
+ const eventHandlers = this._hooks.get(event);
2609
+ if (eventHandlers) {
2610
+ for (const handler of eventHandlers) {
2611
+ if (handler.constructor.name === "AsyncFunction") {
2612
+ continue;
2613
+ }
2614
+ try {
2615
+ handler(...arguments_);
2616
+ } catch (error) {
2617
+ const message = `${event}: ${error.message}`;
2618
+ this.emit("error", new Error(message));
2470
2619
  if (this._throwOnHookError) {
2471
2620
  throw new Error(message);
2472
2621
  }
@@ -2522,6 +2671,103 @@ var Hookified = class extends Eventified {
2522
2671
  };
2523
2672
 
2524
2673
  // node_modules/hashery/dist/node/index.js
2674
+ var Cache = class {
2675
+ _enabled = true;
2676
+ _maxSize = 4e3;
2677
+ _store = /* @__PURE__ */ new Map();
2678
+ _keys = [];
2679
+ constructor(options) {
2680
+ if (options?.enabled !== void 0) {
2681
+ this._enabled = options.enabled;
2682
+ }
2683
+ if (options?.maxSize !== void 0) {
2684
+ this._maxSize = options.maxSize;
2685
+ }
2686
+ }
2687
+ /**
2688
+ * Gets whether the cache is enabled.
2689
+ */
2690
+ get enabled() {
2691
+ return this._enabled;
2692
+ }
2693
+ /**
2694
+ * Sets whether the cache is enabled.
2695
+ */
2696
+ set enabled(value) {
2697
+ this._enabled = value;
2698
+ }
2699
+ /**
2700
+ * Gets the maximum number of items the cache can hold.
2701
+ */
2702
+ get maxSize() {
2703
+ return this._maxSize;
2704
+ }
2705
+ /**
2706
+ * Sets the maximum number of items the cache can hold.
2707
+ */
2708
+ set maxSize(value) {
2709
+ this._maxSize = value;
2710
+ }
2711
+ /**
2712
+ * Gets the underlying Map store.
2713
+ */
2714
+ get store() {
2715
+ return this._store;
2716
+ }
2717
+ /**
2718
+ * Gets the current number of items in the cache.
2719
+ */
2720
+ get size() {
2721
+ return this._store.size;
2722
+ }
2723
+ /**
2724
+ * Gets a value from the cache.
2725
+ * @param key - The cache key
2726
+ * @returns The cached value, or undefined if not found
2727
+ */
2728
+ get(key) {
2729
+ return this._store.get(key);
2730
+ }
2731
+ /**
2732
+ * Sets a value in the cache with FIFO eviction.
2733
+ * If the cache is disabled, this method does nothing.
2734
+ * If the cache is at capacity, the oldest entry is removed before adding the new one.
2735
+ * @param key - The cache key
2736
+ * @param value - The value to cache
2737
+ */
2738
+ set(key, value) {
2739
+ if (!this._enabled) {
2740
+ return;
2741
+ }
2742
+ if (this._store.has(key)) {
2743
+ this._store.set(key, value);
2744
+ return;
2745
+ }
2746
+ if (this._store.size >= this._maxSize) {
2747
+ const oldestKey = this._keys.shift();
2748
+ if (oldestKey) {
2749
+ this._store.delete(oldestKey);
2750
+ }
2751
+ }
2752
+ this._keys.push(key);
2753
+ this._store.set(key, value);
2754
+ }
2755
+ /**
2756
+ * Checks if a key exists in the cache.
2757
+ * @param key - The cache key
2758
+ * @returns True if the key exists, false otherwise
2759
+ */
2760
+ has(key) {
2761
+ return this._store.has(key);
2762
+ }
2763
+ /**
2764
+ * Clears all entries from the cache.
2765
+ */
2766
+ clear() {
2767
+ this._store.clear();
2768
+ this._keys = [];
2769
+ }
2770
+ };
2525
2771
  var CRC = class {
2526
2772
  get name() {
2527
2773
  return "crc32";
@@ -2676,10 +2922,10 @@ var FNV1 = class {
2676
2922
  return this.toHashSync(data);
2677
2923
  }
2678
2924
  };
2679
- var Murmer = class {
2925
+ var Murmur = class {
2680
2926
  _seed;
2681
2927
  /**
2682
- * Creates a new Murmer instance.
2928
+ * Creates a new Murmur instance.
2683
2929
  *
2684
2930
  * @param seed - Optional seed value for the hash (default: 0)
2685
2931
  */
@@ -2690,7 +2936,7 @@ var Murmer = class {
2690
2936
  * The name identifier for this hash provider.
2691
2937
  */
2692
2938
  get name() {
2693
- return "murmer";
2939
+ return "murmur";
2694
2940
  }
2695
2941
  /**
2696
2942
  * Gets the current seed value used for hashing.
@@ -2699,16 +2945,16 @@ var Murmer = class {
2699
2945
  return this._seed;
2700
2946
  }
2701
2947
  /**
2702
- * Computes the Murmer 32-bit hash of the provided data synchronously.
2948
+ * Computes the Murmur 32-bit hash of the provided data synchronously.
2703
2949
  *
2704
2950
  * @param data - The data to hash (Uint8Array, ArrayBuffer, or DataView)
2705
2951
  * @returns An 8-character lowercase hexadecimal string
2706
2952
  *
2707
2953
  * @example
2708
2954
  * ```typescript
2709
- * const murmer = new Murmer();
2955
+ * const murmur = new Murmur();
2710
2956
  * const data = new TextEncoder().encode('hello');
2711
- * const hash = murmer.toHashSync(data);
2957
+ * const hash = murmur.toHashSync(data);
2712
2958
  * console.log(hash); // "248bfa47"
2713
2959
  * ```
2714
2960
  */
@@ -2766,16 +3012,16 @@ var Murmer = class {
2766
3012
  return hashHex;
2767
3013
  }
2768
3014
  /**
2769
- * Computes the Murmer 32-bit hash of the provided data.
3015
+ * Computes the Murmur 32-bit hash of the provided data.
2770
3016
  *
2771
3017
  * @param data - The data to hash (Uint8Array, ArrayBuffer, or DataView)
2772
3018
  * @returns A Promise resolving to an 8-character lowercase hexadecimal string
2773
3019
  *
2774
3020
  * @example
2775
3021
  * ```typescript
2776
- * const murmer = new Murmer();
3022
+ * const murmur = new Murmur();
2777
3023
  * const data = new TextEncoder().encode('hello');
2778
- * const hash = await murmer.toHash(data);
3024
+ * const hash = await murmur.toHash(data);
2779
3025
  * console.log(hash); // "248bfa47"
2780
3026
  * ```
2781
3027
  */
@@ -2962,6 +3208,7 @@ var Hashery = class extends Hookified {
2962
3208
  _providers = new HashProviders();
2963
3209
  _defaultAlgorithm = "SHA-256";
2964
3210
  _defaultAlgorithmSync = "djb2";
3211
+ _cache;
2965
3212
  constructor(options) {
2966
3213
  super(options);
2967
3214
  if (options?.parse) {
@@ -2976,6 +3223,7 @@ var Hashery = class extends Hookified {
2976
3223
  if (options?.defaultAlgorithmSync) {
2977
3224
  this._defaultAlgorithmSync = options.defaultAlgorithmSync;
2978
3225
  }
3226
+ this._cache = new Cache(options?.cache);
2979
3227
  this.loadProviders(options?.providers, {
2980
3228
  includeBase: options?.includeBase ?? true
2981
3229
  });
@@ -3060,7 +3308,7 @@ var Hashery = class extends Hookified {
3060
3308
  }
3061
3309
  /**
3062
3310
  * Sets the default synchronous hash algorithm to use when none is specified.
3063
- * @param value - The default synchronous algorithm to use (e.g., 'djb2', 'fnv1', 'murmer', 'crc32')
3311
+ * @param value - The default synchronous algorithm to use (e.g., 'djb2', 'fnv1', 'murmur', 'crc32')
3064
3312
  * @example
3065
3313
  * ```ts
3066
3314
  * const hashery = new Hashery();
@@ -3072,10 +3320,32 @@ var Hashery = class extends Hookified {
3072
3320
  set defaultAlgorithmSync(value) {
3073
3321
  this._defaultAlgorithmSync = value;
3074
3322
  }
3323
+ /**
3324
+ * Gets the cache instance used to store computed hash values.
3325
+ * @returns The Cache instance
3326
+ * @example
3327
+ * ```ts
3328
+ * const hashery = new Hashery({ cache: { enabled: true } });
3329
+ *
3330
+ * // Access the cache
3331
+ * hashery.cache.enabled; // true
3332
+ * hashery.cache.size; // number of cached items
3333
+ * hashery.cache.clear(); // clear all cached items
3334
+ * ```
3335
+ */
3336
+ get cache() {
3337
+ return this._cache;
3338
+ }
3075
3339
  /**
3076
3340
  * Generates a cryptographic hash of the provided data using the Web Crypto API.
3077
3341
  * The data is first stringified using the configured stringify function, then hashed.
3078
3342
  *
3343
+ * If an invalid algorithm is provided, a 'warn' event is emitted and the method falls back
3344
+ * to the default algorithm. You can listen to these warnings:
3345
+ * ```ts
3346
+ * hashery.on('warn', (message) => console.log(message));
3347
+ * ```
3348
+ *
3079
3349
  * @param data - The data to hash (will be stringified before hashing)
3080
3350
  * @param options - Optional configuration object
3081
3351
  * @param options.algorithm - The hash algorithm to use (defaults to 'SHA-256')
@@ -3100,15 +3370,36 @@ var Hashery = class extends Hookified {
3100
3370
  };
3101
3371
  await this.beforeHook("toHash", context);
3102
3372
  const stringified = this._stringify(context.data);
3373
+ const cacheKey = `${context.algorithm}:${stringified}`;
3374
+ if (this._cache.enabled) {
3375
+ const cached = this._cache.get(cacheKey);
3376
+ if (cached !== void 0) {
3377
+ let cachedHash = cached;
3378
+ if (options?.maxLength && cachedHash.length > options.maxLength) {
3379
+ cachedHash = cachedHash.substring(0, options.maxLength);
3380
+ }
3381
+ const result2 = {
3382
+ hash: cachedHash,
3383
+ data: context.data,
3384
+ algorithm: context.algorithm
3385
+ };
3386
+ await this.afterHook("toHash", result2);
3387
+ return result2.hash;
3388
+ }
3389
+ }
3103
3390
  const encoder = new TextEncoder();
3104
3391
  const dataBuffer = encoder.encode(stringified);
3105
3392
  let provider = this._providers.get(context.algorithm);
3106
3393
  if (!provider) {
3394
+ this.emit("warn", `Invalid algorithm '${context.algorithm}' not found. Falling back to default algorithm '${this._defaultAlgorithm}'.`);
3107
3395
  provider = new WebCrypto({
3108
3396
  algorithm: this._defaultAlgorithm
3109
3397
  });
3110
3398
  }
3111
3399
  let hash2 = await provider.toHash(dataBuffer);
3400
+ if (this._cache.enabled) {
3401
+ this._cache.set(cacheKey, hash2);
3402
+ }
3112
3403
  if (options?.maxLength && hash2.length > options?.maxLength) {
3113
3404
  hash2 = hash2.substring(0, options.maxLength);
3114
3405
  }
@@ -3169,9 +3460,15 @@ var Hashery = class extends Hookified {
3169
3460
  * Generates a hash of the provided data synchronously using a non-cryptographic hash algorithm.
3170
3461
  * The data is first stringified using the configured stringify function, then hashed.
3171
3462
  *
3172
- * Note: This method only works with synchronous hash providers (djb2, fnv1, murmer, crc32).
3463
+ * Note: This method only works with synchronous hash providers (djb2, fnv1, murmur, crc32).
3173
3464
  * WebCrypto algorithms (SHA-256, SHA-384, SHA-512) are not supported and will throw an error.
3174
3465
  *
3466
+ * If an invalid algorithm is provided, a 'warn' event is emitted and the method falls back
3467
+ * to the default synchronous algorithm. You can listen to these warnings:
3468
+ * ```ts
3469
+ * hashery.on('warn', (message) => console.log(message));
3470
+ * ```
3471
+ *
3175
3472
  * @param data - The data to hash (will be stringified before hashing)
3176
3473
  * @param options - Optional configuration object
3177
3474
  * @param options.algorithm - The hash algorithm to use (defaults to 'djb2')
@@ -3179,6 +3476,7 @@ var Hashery = class extends Hookified {
3179
3476
  * @returns The hexadecimal string representation of the hash
3180
3477
  *
3181
3478
  * @throws {Error} If the specified algorithm does not support synchronous hashing
3479
+ * @throws {Error} If the default algorithm is not found
3182
3480
  *
3183
3481
  * @example
3184
3482
  * ```ts
@@ -3196,19 +3494,43 @@ var Hashery = class extends Hookified {
3196
3494
  algorithm: options?.algorithm ?? this._defaultAlgorithmSync,
3197
3495
  maxLength: options?.maxLength
3198
3496
  };
3199
- this.beforeHook("toHashSync", context);
3497
+ this.hookSync("before:toHashSync", context);
3200
3498
  const algorithm = context.algorithm;
3201
3499
  const stringified = this._stringify(context.data);
3500
+ const cacheKey = `${algorithm}:${stringified}`;
3501
+ if (this._cache.enabled) {
3502
+ const cached = this._cache.get(cacheKey);
3503
+ if (cached !== void 0) {
3504
+ let cachedHash = cached;
3505
+ if (options?.maxLength && cachedHash.length > options.maxLength) {
3506
+ cachedHash = cachedHash.substring(0, options.maxLength);
3507
+ }
3508
+ const result2 = {
3509
+ hash: cachedHash,
3510
+ data: context.data,
3511
+ algorithm
3512
+ };
3513
+ this.hookSync("after:toHashSync", result2);
3514
+ return result2.hash;
3515
+ }
3516
+ }
3202
3517
  const encoder = new TextEncoder();
3203
3518
  const dataBuffer = encoder.encode(stringified);
3204
- const provider = this._providers.get(algorithm);
3519
+ let provider = this._providers.get(algorithm);
3205
3520
  if (!provider) {
3206
- throw new Error(`Hash provider '${algorithm}' not found`);
3521
+ this.emit("warn", `Invalid algorithm '${algorithm}' not found. Falling back to default algorithm '${this._defaultAlgorithmSync}'.`);
3522
+ provider = this._providers.get(this._defaultAlgorithmSync);
3523
+ if (!provider) {
3524
+ throw new Error(`Hash provider '${this._defaultAlgorithmSync}' (default) not found`);
3525
+ }
3207
3526
  }
3208
3527
  if (!provider.toHashSync) {
3209
- throw new Error(`Hash provider '${algorithm}' does not support synchronous hashing. Use toHash() instead or choose a different algorithm (djb2, fnv1, murmer, crc32).`);
3528
+ throw new Error(`Hash provider '${algorithm}' does not support synchronous hashing. Use toHash() instead or choose a different algorithm (djb2, fnv1, murmur, crc32).`);
3210
3529
  }
3211
3530
  let hash2 = provider.toHashSync(dataBuffer);
3531
+ if (this._cache.enabled) {
3532
+ this._cache.set(cacheKey, hash2);
3533
+ }
3212
3534
  if (options?.maxLength && hash2.length > options?.maxLength) {
3213
3535
  hash2 = hash2.substring(0, options.maxLength);
3214
3536
  }
@@ -3217,7 +3539,7 @@ var Hashery = class extends Hookified {
3217
3539
  data: context.data,
3218
3540
  algorithm: context.algorithm
3219
3541
  };
3220
- this.afterHook("toHashSync", result);
3542
+ this.hookSync("after:toHashSync", result);
3221
3543
  return result.hash;
3222
3544
  }
3223
3545
  /**
@@ -3225,7 +3547,7 @@ var Hashery = class extends Hookified {
3225
3547
  * This method uses the toHashSync function to create a consistent hash, then maps it to a number
3226
3548
  * between min and max (inclusive).
3227
3549
  *
3228
- * Note: This method only works with synchronous hash providers (djb2, fnv1, murmer, crc32).
3550
+ * Note: This method only works with synchronous hash providers (djb2, fnv1, murmur, crc32).
3229
3551
  *
3230
3552
  * @param data - The data to hash (will be stringified before hashing)
3231
3553
  * @param options - Configuration options (optional, defaults to min: 0, max: 100)
@@ -3291,7 +3613,7 @@ var Hashery = class extends Hookified {
3291
3613
  this.providers.add(new CRC());
3292
3614
  this.providers.add(new DJB2());
3293
3615
  this.providers.add(new FNV1());
3294
- this.providers.add(new Murmer());
3616
+ this.providers.add(new Murmur());
3295
3617
  }
3296
3618
  }
3297
3619
  };
@@ -3409,7 +3731,7 @@ function hashToNumberSync(object2, options = {
3409
3731
  });
3410
3732
  }
3411
3733
  function wrapSync(function_, options) {
3412
- const { ttl, keyPrefix, cache, serialize } = options;
3734
+ const { ttl, keyPrefix, cache: cache2, serialize } = options;
3413
3735
  return (...arguments_) => {
3414
3736
  let cacheKey = createWrapKey(function_, arguments_, {
3415
3737
  keyPrefix,
@@ -3418,15 +3740,15 @@ function wrapSync(function_, options) {
3418
3740
  if (options.createKey) {
3419
3741
  cacheKey = options.createKey(function_, arguments_, options);
3420
3742
  }
3421
- let value = cache.get(cacheKey);
3743
+ let value = cache2.get(cacheKey);
3422
3744
  if (value === void 0) {
3423
3745
  try {
3424
3746
  value = function_(...arguments_);
3425
- cache.set(cacheKey, value, ttl);
3747
+ cache2.set(cacheKey, value, ttl);
3426
3748
  } catch (error) {
3427
- cache.emit("error", error);
3749
+ cache2.emit("error", error);
3428
3750
  if (options.cacheErrors) {
3429
- cache.set(cacheKey, error, ttl);
3751
+ cache2.set(cacheKey, error, ttl);
3430
3752
  }
3431
3753
  }
3432
3754
  }
@@ -3509,6 +3831,31 @@ var DoublyLinkedList = class {
3509
3831
  this.nodesMap.delete(oldValue);
3510
3832
  return oldValue;
3511
3833
  }
3834
+ // Remove a specific node by value
3835
+ remove(value) {
3836
+ const node = this.nodesMap.get(value);
3837
+ if (!node) {
3838
+ return false;
3839
+ }
3840
+ if (node.prev) {
3841
+ node.prev.next = node.next;
3842
+ } else {
3843
+ this.head = node.next;
3844
+ if (this.head) {
3845
+ this.head.prev = void 0;
3846
+ }
3847
+ }
3848
+ if (node.next) {
3849
+ node.next.prev = node.prev;
3850
+ } else {
3851
+ this.tail = node.prev;
3852
+ if (this.tail) {
3853
+ this.tail.next = void 0;
3854
+ }
3855
+ }
3856
+ this.nodesMap.delete(value);
3857
+ return true;
3858
+ }
3512
3859
  get size() {
3513
3860
  return this.nodesMap.size;
3514
3861
  }
@@ -3700,6 +4047,7 @@ var CacheableMemory = class extends Hookified {
3700
4047
  const item = store.get(key);
3701
4048
  if (item && this.hasExpired(item)) {
3702
4049
  store.delete(key);
4050
+ this.lruRemove(key);
3703
4051
  continue;
3704
4052
  }
3705
4053
  keys2.push(key);
@@ -3717,6 +4065,7 @@ var CacheableMemory = class extends Hookified {
3717
4065
  for (const item of store.values()) {
3718
4066
  if (this.hasExpired(item)) {
3719
4067
  store.delete(item.key);
4068
+ this.lruRemove(item.key);
3720
4069
  continue;
3721
4070
  }
3722
4071
  items.push(item);
@@ -3744,6 +4093,7 @@ var CacheableMemory = class extends Hookified {
3744
4093
  }
3745
4094
  if (item.expires && Date.now() > item.expires) {
3746
4095
  store.delete(key);
4096
+ this.lruRemove(key);
3747
4097
  return void 0;
3748
4098
  }
3749
4099
  this.lruMoveToFront(key);
@@ -3777,6 +4127,7 @@ var CacheableMemory = class extends Hookified {
3777
4127
  }
3778
4128
  if (item.expires && item.expires && Date.now() > item.expires) {
3779
4129
  store.delete(key);
4130
+ this.lruRemove(key);
3780
4131
  return void 0;
3781
4132
  }
3782
4133
  this.lruMoveToFront(key);
@@ -3906,6 +4257,7 @@ var CacheableMemory = class extends Hookified {
3906
4257
  delete(key) {
3907
4258
  const store = this.getStore(key);
3908
4259
  store.delete(key);
4260
+ this.lruRemove(key);
3909
4261
  }
3910
4262
  /**
3911
4263
  * Delete the keys
@@ -3994,6 +4346,17 @@ var CacheableMemory = class extends Hookified {
3994
4346
  }
3995
4347
  this._lru.moveToFront(key);
3996
4348
  }
4349
+ /**
4350
+ * Remove a key from the LRU cache. This is for internal use
4351
+ * @param {string} key - The key to remove
4352
+ * @returns {void}
4353
+ */
4354
+ lruRemove(key) {
4355
+ if (this._lruSize === 0) {
4356
+ return;
4357
+ }
4358
+ this._lru.remove(key);
4359
+ }
3997
4360
  /**
3998
4361
  * Resize the LRU cache. This is for internal use.
3999
4362
  * @returns {void}
@@ -4016,6 +4379,7 @@ var CacheableMemory = class extends Hookified {
4016
4379
  for (const item of store.values()) {
4017
4380
  if (item.expires && Date.now() > item.expires) {
4018
4381
  store.delete(item.key);
4382
+ this.lruRemove(item.key);
4019
4383
  }
4020
4384
  }
4021
4385
  }
@@ -4099,26 +4463,21 @@ var object = "object";
4099
4463
  var noop = (_2, value) => value;
4100
4464
  var primitives = (value) => value instanceof Primitive ? Primitive(value) : value;
4101
4465
  var Primitives = (_2, value) => typeof value === primitive ? new Primitive(value) : value;
4102
- var revive = (input, parsed, output, $) => {
4103
- const lazy = [];
4466
+ var resolver = (input, lazy, parsed, $) => (output) => {
4104
4467
  for (let ke = keys(output), { length } = ke, y = 0; y < length; y++) {
4105
4468
  const k = ke[y];
4106
4469
  const value = output[k];
4107
4470
  if (value instanceof Primitive) {
4108
- const tmp = input[value];
4471
+ const tmp = input[+value];
4109
4472
  if (typeof tmp === object && !parsed.has(tmp)) {
4110
4473
  parsed.add(tmp);
4111
4474
  output[k] = ignore;
4112
- lazy.push({ k, a: [input, parsed, tmp, $] });
4475
+ lazy.push({ o: output, k, r: tmp });
4113
4476
  } else
4114
4477
  output[k] = $.call(output, k, tmp);
4115
4478
  } else if (output[k] !== ignore)
4116
4479
  output[k] = $.call(output, k, value);
4117
4480
  }
4118
- for (let { length } = lazy, i = 0; i < length; i++) {
4119
- const { k, a } = lazy[i];
4120
- output[k] = $.call(output, k, revive.apply(null, a));
4121
- }
4122
4481
  return output;
4123
4482
  };
4124
4483
  var set = (known, input, value) => {
@@ -4128,10 +4487,19 @@ var set = (known, input, value) => {
4128
4487
  };
4129
4488
  var parse = (text, reviver) => {
4130
4489
  const input = $parse(text, Primitives).map(primitives);
4131
- const value = input[0];
4132
4490
  const $ = reviver || noop;
4133
- const tmp = typeof value === object && value ? revive(input, /* @__PURE__ */ new Set(), value, $) : value;
4134
- return $.call({ "": tmp }, "", tmp);
4491
+ let value = input[0];
4492
+ if (typeof value === object && value) {
4493
+ const lazy = [];
4494
+ const revive = resolver(input, lazy, /* @__PURE__ */ new Set(), $);
4495
+ value = revive(value);
4496
+ let i = 0;
4497
+ while (i < lazy.length) {
4498
+ const { o, k, r } = lazy[i++];
4499
+ o[k] = $.call(o, k, revive(r));
4500
+ }
4501
+ }
4502
+ return $.call({ "": value }, "", value);
4135
4503
  };
4136
4504
  var stringify2 = (value, replacer, space) => {
4137
4505
  const $ = replacer && typeof replacer === object ? (k, v) => k === "" || -1 < replacer.indexOf(k) ? v : void 0 : replacer || noop;
@@ -4581,9 +4949,9 @@ var FlatCache = class extends Hookified {
4581
4949
  }
4582
4950
  };
4583
4951
  function createFromFile(filePath, options) {
4584
- const cache = new FlatCache(options);
4585
- cache.loadFile(filePath);
4586
- return cache;
4952
+ const cache2 = new FlatCache(options);
4953
+ cache2.loadFile(filePath);
4954
+ return cache2;
4587
4955
  }
4588
4956
 
4589
4957
  // node_modules/file-entry-cache/dist/index.js
@@ -4663,8 +5031,8 @@ var FileEntryCache = class {
4663
5031
  * Set the cache
4664
5032
  * @param {FlatCache} cache - The cache to set
4665
5033
  */
4666
- set cache(cache) {
4667
- this._cache = cache;
5034
+ set cache(cache2) {
5035
+ this._cache = cache2;
4668
5036
  }
4669
5037
  /**
4670
5038
  * Get the logger
@@ -5103,14 +5471,11 @@ import { version as prettierVersion } from "../index.mjs";
5103
5471
  var optionsHashCache = /* @__PURE__ */ new WeakMap();
5104
5472
  var nodeVersion = process.version;
5105
5473
  function getHashOfOptions(options) {
5106
- if (optionsHashCache.has(options)) {
5107
- return optionsHashCache.get(options);
5108
- }
5109
- const hash2 = createHash(
5110
- `${prettierVersion}_${nodeVersion}_${(0, import_fast_json_stable_stringify2.default)(options)}`
5474
+ return getOrInsertComputed(
5475
+ optionsHashCache,
5476
+ options,
5477
+ (options2) => createHash(`${prettierVersion}_${nodeVersion}_${(0, import_fast_json_stable_stringify2.default)(options2)}`)
5111
5478
  );
5112
- optionsHashCache.set(options, hash2);
5113
- return hash2;
5114
5479
  }
5115
5480
  function getMetadataFromFileDescriptor(fileDescriptor) {
5116
5481
  return fileDescriptor.meta;
@@ -5122,10 +5487,10 @@ var FormatResultsCache = class {
5122
5487
  * @param {string} cacheStrategy
5123
5488
  */
5124
5489
  constructor(cacheFileLocation, cacheStrategy) {
5125
- const useChecksum = cacheStrategy === "content";
5490
+ const useCheckSum = cacheStrategy === "content";
5126
5491
  const fileEntryCacheOptions = {
5127
- useChecksum,
5128
- useModifiedTime: !useChecksum,
5492
+ useCheckSum,
5493
+ useModifiedTime: !useCheckSum,
5129
5494
  restrictAccessToCwd: false
5130
5495
  };
5131
5496
  try {
@@ -5207,6 +5572,9 @@ function stripAnsi(string) {
5207
5572
  if (typeof string !== "string") {
5208
5573
  throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
5209
5574
  }
5575
+ if (!string.includes("\x1B") && !string.includes("\x9B")) {
5576
+ return string;
5577
+ }
5210
5578
  return string.replace(regex, "");
5211
5579
  }
5212
5580
 
@@ -5580,7 +5948,7 @@ function handleError(context, filename, error, printedFilename, ignoreUnknown) {
5580
5948
  return;
5581
5949
  }
5582
5950
  const isParseError = Boolean(error?.loc);
5583
- const isValidationError = /^Invalid \S+ value\./u.test(error?.message);
5951
+ const isValidationError = /^Invalid \S+ value\./.test(error?.message);
5584
5952
  if (isParseError) {
5585
5953
  context.logger.error(`${filename}: ${String(error)}`);
5586
5954
  } else if (isValidationError || error instanceof errors.ConfigError) {
@@ -5643,21 +6011,20 @@ async function format3(context, input, opt) {
5643
6011
  throw new DebugError(
5644
6012
  "prettier(input) !== prettier(prettier(input))\n" + diff(pp, pppp)
5645
6013
  );
5646
- } else {
5647
- const stringify5 = (obj) => JSON.stringify(obj, null, 2);
5648
- const ast = stringify5(
5649
- (await prettier.__debug.parse(input, opt, { massage: true })).ast
5650
- );
5651
- const past = stringify5(
5652
- (await prettier.__debug.parse(pp, opt, { massage: true })).ast
6014
+ }
6015
+ const stringify5 = (obj) => JSON.stringify(obj, null, 2);
6016
+ const ast = stringify5(
6017
+ (await prettier.__debug.parse(input, opt, { massage: true })).ast
6018
+ );
6019
+ const past = stringify5(
6020
+ (await prettier.__debug.parse(pp, opt, { massage: true })).ast
6021
+ );
6022
+ if (ast !== past) {
6023
+ const MAX_AST_SIZE = 2097152;
6024
+ const astDiff = ast.length > MAX_AST_SIZE || past.length > MAX_AST_SIZE ? "AST diff too large to render" : diff(ast, past);
6025
+ throw new DebugError(
6026
+ "ast(input) !== ast(prettier(input))\n" + astDiff + "\n" + diff(input, pp)
5653
6027
  );
5654
- if (ast !== past) {
5655
- const MAX_AST_SIZE = 2097152;
5656
- const astDiff = ast.length > MAX_AST_SIZE || past.length > MAX_AST_SIZE ? "AST diff too large to render" : diff(ast, past);
5657
- throw new DebugError(
5658
- "ast(input) !== ast(prettier(input))\n" + astDiff + "\n" + diff(input, pp)
5659
- );
5660
- }
5661
6028
  }
5662
6029
  return { formatted: pp, filepath: opt.filepath || "(stdin)\n" };
5663
6030
  }
@@ -5786,6 +6153,7 @@ async function formatFiles(context) {
5786
6153
  }
5787
6154
  const isFileIgnored = isIgnored(filename);
5788
6155
  if (isFileIgnored && (context.argv.debugCheck || context.argv.write || context.argv.check || context.argv.listDifferent)) {
6156
+ formatResultsCache?.removeFormatResultsCache(filename);
5789
6157
  continue;
5790
6158
  }
5791
6159
  const options = {
@@ -5957,7 +6325,7 @@ function createLogger(logLevel = "log") {
5957
6325
  /* OPTIONAL_OBJECT: false */
5958
6326
  0,
5959
6327
  message,
5960
- /^/gmu,
6328
+ /^/gm,
5961
6329
  prefix
5962
6330
  ) + (options.newline ? "\n" : "");
5963
6331
  stream.write(message);
@@ -6030,7 +6398,7 @@ function indent(str, spaces) {
6030
6398
  /* OPTIONAL_OBJECT: false */
6031
6399
  0,
6032
6400
  str,
6033
- /^/gmu,
6401
+ /^/gm,
6034
6402
  " ".repeat(spaces)
6035
6403
  );
6036
6404
  }