@nomicfoundation/hardhat-utils 4.0.4 → 4.1.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 (42) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/src/debug.d.ts +40 -8
  3. package/dist/src/debug.d.ts.map +1 -1
  4. package/dist/src/debug.js +54 -18
  5. package/dist/src/debug.js.map +1 -1
  6. package/dist/src/fast-semver.d.ts +49 -0
  7. package/dist/src/fast-semver.d.ts.map +1 -0
  8. package/dist/src/fast-semver.js +73 -0
  9. package/dist/src/fast-semver.js.map +1 -0
  10. package/dist/src/fs.d.ts +57 -0
  11. package/dist/src/fs.d.ts.map +1 -1
  12. package/dist/src/fs.js +200 -25
  13. package/dist/src/fs.js.map +1 -1
  14. package/dist/src/internal/debug.d.ts +35 -0
  15. package/dist/src/internal/debug.d.ts.map +1 -0
  16. package/dist/src/internal/debug.js +91 -0
  17. package/dist/src/internal/debug.js.map +1 -0
  18. package/dist/src/internal/fs.d.ts +12 -0
  19. package/dist/src/internal/fs.d.ts.map +1 -0
  20. package/dist/src/internal/fs.js +42 -0
  21. package/dist/src/internal/fs.js.map +1 -0
  22. package/dist/src/runtime.d.ts +13 -0
  23. package/dist/src/runtime.d.ts.map +1 -0
  24. package/dist/src/runtime.js +34 -0
  25. package/dist/src/runtime.js.map +1 -0
  26. package/dist/src/subprocess.d.ts +2 -0
  27. package/dist/src/subprocess.d.ts.map +1 -1
  28. package/dist/src/subprocess.js +1 -0
  29. package/dist/src/subprocess.js.map +1 -1
  30. package/dist/src/synchronization.d.ts +97 -0
  31. package/dist/src/synchronization.d.ts.map +1 -1
  32. package/dist/src/synchronization.js +171 -2
  33. package/dist/src/synchronization.js.map +1 -1
  34. package/package.json +4 -4
  35. package/src/debug.ts +73 -28
  36. package/src/fast-semver.ts +95 -0
  37. package/src/fs.ts +272 -35
  38. package/src/internal/debug.ts +119 -0
  39. package/src/internal/fs.ts +57 -0
  40. package/src/runtime.ts +45 -0
  41. package/src/subprocess.ts +2 -0
  42. package/src/synchronization.ts +211 -3
package/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # @nomicfoundation/hardhat-utils
2
2
 
3
+ ## 4.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#8205](https://github.com/NomicFoundation/hardhat/pull/8205) [`99a4556`](https://github.com/NomicFoundation/hardhat/commit/99a4556698e1d0776951fb160641f5e2529b68ee) Thanks [@alcuadrado](https://github.com/alcuadrado)! - Introduce the SharedPromiseCache synchronization primitive
8
+
9
+ ### Patch Changes
10
+
11
+ - [#8219](https://github.com/NomicFoundation/hardhat/pull/8219) [`2cad309`](https://github.com/NomicFoundation/hardhat/commit/2cad309eb8d35fcc5d2aba5d75a5af4d63d50508) Thanks [@schaable](https://github.com/schaable)! - Improved performance by replacing the semver dependency with a lightweight in-tree implementation.
12
+
13
+ - [#8196](https://github.com/NomicFoundation/hardhat/pull/8196) [`73436aa`](https://github.com/NomicFoundation/hardhat/commit/73436aaa1ddac805f8d855627b5b40ad69cf7d2e) Thanks [@alcuadrado](https://github.com/alcuadrado)! - Export missing error types
14
+
15
+ - [#8207](https://github.com/NomicFoundation/hardhat/pull/8207) [`d594209`](https://github.com/NomicFoundation/hardhat/commit/d59420968bffca83e1ad2712c6881d19cc7e1a99) Thanks [@alcuadrado](https://github.com/alcuadrado)! - Improved performance by replacing the debug logging library with a lightweight in-tree implementation.
16
+
17
+ - [#8189](https://github.com/NomicFoundation/hardhat/pull/8189) [`b5ca1ae`](https://github.com/NomicFoundation/hardhat/commit/b5ca1aee1eb2571ec23f54ac8a9b2c39a90361c6) Thanks [@alcuadrado](https://github.com/alcuadrado)! - Introduce a TrueCasePathResolver class to optimize repeated filesystem casing resolution
18
+
19
+ ## 4.0.5
20
+
21
+ ### Patch Changes
22
+
23
+ - [#8187](https://github.com/NomicFoundation/hardhat/pull/8187) [`8f6a418`](https://github.com/NomicFoundation/hardhat/commit/8f6a418203e78b699ca1a4d9b498d13a428e71f6) Thanks [@ChristopherDedominici](https://github.com/ChristopherDedominici)! - Improved the logic for handling `Node.js` versions that fall below the minimum requirement.
24
+
25
+ - [#8180](https://github.com/NomicFoundation/hardhat/pull/8180) [`4122faa`](https://github.com/NomicFoundation/hardhat/commit/4122faa3da2b588d83f2c94574f04ae2abd2e723) Thanks [@alcuadrado](https://github.com/alcuadrado)! - Optimize file system traversal helpers
26
+
3
27
  ## 4.0.4
4
28
 
5
29
  ### Patch Changes
@@ -1,16 +1,48 @@
1
1
  /**
2
- * A simple decorator that adds debug logging for when a method is entered and exited.
2
+ * A logger function returned by {@link createDebug}.
3
+ * The `enabled` property is `true` when the logger will produce output.
4
+ */
5
+ export interface DebugLogger {
6
+ (format: unknown, ...args: unknown[]): void;
7
+ readonly enabled: boolean;
8
+ }
9
+ /**
10
+ * Creates a namespaced logger controlled by the `DEBUG` env var.
3
11
  *
4
- * This decorator is meant to be used for debugging purposes only. It should not be committed in runtime code.
12
+ * If `namespace` matches `DEBUG`, the logger writes to `process.stderr`;
13
+ * otherwise, it is a no-op. Additionally, `logger.enabled` is `true` when
14
+ * the namespace matches `DEBUG`, allowing you to conditionally run expensive
15
+ * diagnostics.
5
16
  *
6
- * Example usage:
17
+ * `DEBUG` should be a comma- or whitespace-separated list of patterns.
18
+ * `*` is a wildcard and a leading `-` negates a pattern (e.g.
19
+ * `hardhat:*,-hardhat:noisy`).
7
20
  *
8
- * ```
9
- * class MyClass {
10
- * @withDebugLogs("MyClass:exampleClassMethod")
11
- * public function exampleClassMethod(...)
21
+ * Messages are formatted using `node:util.format`, allowing you to use format
22
+ * specifiers like `%O`, `%o`, `%s`, `%d`, `%j`. Extra arguments without a
23
+ * matching specifier are inspected automatically.
24
+ *
25
+ * Output is colorized per namespace when `stderr` is a TTY. Set
26
+ * `DEBUG_COLORS=no` or `false` to disable colors.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * const log = createDebug("hardhat:utils:foo");
31
+ * log("Starting up");
32
+ * log("Received %O", payload);
33
+ * log("Saved data", id, filePath);
34
+ *
35
+ * if (log.enabled) {
36
+ * // expensive diagnostics that should only run while debugging
12
37
  * }
13
38
  * ```
39
+ *
40
+ * ```sh
41
+ * DEBUG="hardhat:*,-hardhat:noisy" DEBUG_COLORS=no pnpm hardhat run script.js
42
+ * ```
43
+ *
44
+ * @param namespace Namespace used for filtering and as the log prefix.
45
+ * @returns Logger function, or a shared no-op if disabled.
14
46
  */
15
- export declare function withDebugLogs<This, Args extends any[], Return>(tag?: string): (originalMethod: (this: This, ...args: Args) => Return, _context: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Return>) => (this: This, ...args: Args) => Return;
47
+ export declare function createDebug(namespace: string): DebugLogger;
16
48
  //# sourceMappingURL=debug.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../src/debug.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,SAAS,GAAG,EAAE,EAAE,MAAM,EAC5D,GAAG,GAAE,MAAW,IAGd,gBAAgB,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,EACrD,UAAU,2BAA2B,CACnC,IAAI,EACJ,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,CACtC,KACA,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,CAYzC"}
1
+ {"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../src/debug.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAC5C,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,WAAW,CA+B1D"}
package/dist/src/debug.js CHANGED
@@ -1,28 +1,64 @@
1
- import debugLib from "debug";
1
+ import { formatWithOptions } from "node:util";
2
+ import { NOOP, isEnabled, selectColor, useColors } from "./internal/debug.js";
2
3
  /**
3
- * A simple decorator that adds debug logging for when a method is entered and exited.
4
+ * Creates a namespaced logger controlled by the `DEBUG` env var.
4
5
  *
5
- * This decorator is meant to be used for debugging purposes only. It should not be committed in runtime code.
6
+ * If `namespace` matches `DEBUG`, the logger writes to `process.stderr`;
7
+ * otherwise, it is a no-op. Additionally, `logger.enabled` is `true` when
8
+ * the namespace matches `DEBUG`, allowing you to conditionally run expensive
9
+ * diagnostics.
6
10
  *
7
- * Example usage:
11
+ * `DEBUG` should be a comma- or whitespace-separated list of patterns.
12
+ * `*` is a wildcard and a leading `-` negates a pattern (e.g.
13
+ * `hardhat:*,-hardhat:noisy`).
8
14
  *
9
- * ```
10
- * class MyClass {
11
- * @withDebugLogs("MyClass:exampleClassMethod")
12
- * public function exampleClassMethod(...)
15
+ * Messages are formatted using `node:util.format`, allowing you to use format
16
+ * specifiers like `%O`, `%o`, `%s`, `%d`, `%j`. Extra arguments without a
17
+ * matching specifier are inspected automatically.
18
+ *
19
+ * Output is colorized per namespace when `stderr` is a TTY. Set
20
+ * `DEBUG_COLORS=no` or `false` to disable colors.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * const log = createDebug("hardhat:utils:foo");
25
+ * log("Starting up");
26
+ * log("Received %O", payload);
27
+ * log("Saved data", id, filePath);
28
+ *
29
+ * if (log.enabled) {
30
+ * // expensive diagnostics that should only run while debugging
13
31
  * }
14
32
  * ```
33
+ *
34
+ * ```sh
35
+ * DEBUG="hardhat:*,-hardhat:noisy" DEBUG_COLORS=no pnpm hardhat run script.js
36
+ * ```
37
+ *
38
+ * @param namespace Namespace used for filtering and as the log prefix.
39
+ * @returns Logger function, or a shared no-op if disabled.
15
40
  */
16
- export function withDebugLogs(tag = "") {
17
- return function actualDecorator(originalMethod, _context) {
18
- const log = debugLib(`hardhat:dev:core${tag === "" ? "" : `:${tag}`}`);
19
- function replacementMethod(...args) {
20
- log(`Entering method with args:`, args);
21
- const result = originalMethod.call(this, ...args);
22
- log(`Exiting method.`);
23
- return result;
24
- }
25
- return replacementMethod;
41
+ export function createDebug(namespace) {
42
+ if (!isEnabled(namespace, process.env.DEBUG ?? "")) {
43
+ return NOOP;
44
+ }
45
+ const colors = useColors();
46
+ const color = colors ? selectColor(namespace) : undefined;
47
+ const prefix = color !== undefined
48
+ ? `\x1b[38;5;${color};1m ${namespace}\x1b[0m`
49
+ : ` ${namespace}`;
50
+ const suffixOpen = color !== undefined ? `\x1b[38;5;${color}m` : "";
51
+ const suffixClose = color !== undefined ? `\x1b[0m` : "";
52
+ let prev = 0;
53
+ const logger = (format, ...args) => {
54
+ const now = Date.now();
55
+ const diff = prev === 0 ? 0 : now - prev;
56
+ prev = now;
57
+ const body = args.length === 0 && typeof format === "string"
58
+ ? format
59
+ : formatWithOptions({ colors }, format, ...args);
60
+ process.stderr.write(`${prefix} ${body} ${suffixOpen}+${diff}ms${suffixClose}\n`);
26
61
  };
62
+ return Object.assign(logger, { enabled: true });
27
63
  }
28
64
  //# sourceMappingURL=debug.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"debug.js","sourceRoot":"","sources":["../../src/debug.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,OAAO,CAAC;AAE7B;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,aAAa,CAC3B,MAAc,EAAE;IAEhB,OAAO,SAAS,eAAe,CAC7B,cAAqD,EACrD,QAGC;QAED,MAAM,GAAG,GAAG,QAAQ,CAAC,mBAAmB,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,EAAE,CAAC,CAAC;QAEvE,SAAS,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GAAG,CAAC,CAAC;IAEb,MAAM,MAAM,GAAG,CAAC,MAAe,EAAE,GAAG,IAAe,EAAQ,EAAE;QAC3D,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,MAAM,IAAI,GAAG,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC;QACzC,IAAI,GAAG,GAAG,CAAC;QAEX,MAAM,IAAI,GACR,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,MAAM,KAAK,QAAQ;YAC7C,CAAC,CAAC,MAAM;YACR,CAAC,CAAC,iBAAiB,CAAC,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;QAErD,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,GAAG,MAAM,IAAI,IAAI,IAAI,UAAU,IAAI,IAAI,KAAK,WAAW,IAAI,CAC5D,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;AAClD,CAAC"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * A small, fast subset of semver: strict `MAJOR.MINOR.PATCH` parsing and
3
+ * triple-wise comparison helpers.
4
+ *
5
+ * This module exists because the full `semver` package is slow to load and is
6
+ * overkill for the many call sites in Hardhat that compare against hard-coded
7
+ * `x.y.z` literals. For range grammar (caret/tilde, disjunctions, prerelease
8
+ * subset, etc.) keep using `semver`.
9
+ */
10
+ export type SemverVersion = [major: number, minor: number, patch: number];
11
+ /**
12
+ * Parses a strict `MAJOR.MINOR.PATCH` version string into a `SemverVersion`
13
+ * tuple.
14
+ *
15
+ * An optional `+build` suffix is accepted and stripped silently. A
16
+ * `-prerelease` suffix is rejected.
17
+ *
18
+ * @param version The version string to parse.
19
+ * @returns The parsed `SemverVersion`, or `undefined` if the input does not
20
+ * match the strict `\d+\.\d+\.\d+` shape.
21
+ */
22
+ export declare function parseVersion(version: string): SemverVersion | undefined;
23
+ /**
24
+ * `Array#sort`-style comparator for `SemverVersion` tuples: returns a negative
25
+ * number, zero, or a positive number depending on whether `a` is lower than,
26
+ * equal to, or greater than `b`.
27
+ */
28
+ export declare function compare(a: SemverVersion, b: SemverVersion): number;
29
+ /**
30
+ * Returns `true` if `a` and `b` represent the same `MAJOR.MINOR.PATCH`.
31
+ */
32
+ export declare function equals(a: SemverVersion, b: SemverVersion): boolean;
33
+ /**
34
+ * Returns `true` if `compared` is strictly lower than `comparator`.
35
+ */
36
+ export declare function lowerThan(compared: SemverVersion, comparator: SemverVersion): boolean;
37
+ /**
38
+ * Returns `true` if `compared` is lower than or equal to `comparator`.
39
+ */
40
+ export declare function lowerThanOrEqual(compared: SemverVersion, comparator: SemverVersion): boolean;
41
+ /**
42
+ * Returns `true` if `compared` is strictly greater than `comparator`.
43
+ */
44
+ export declare function greaterThan(compared: SemverVersion, comparator: SemverVersion): boolean;
45
+ /**
46
+ * Returns `true` if `compared` is greater than or equal to `comparator`.
47
+ */
48
+ export declare function greaterThanOrEqual(compared: SemverVersion, comparator: SemverVersion): boolean;
49
+ //# sourceMappingURL=fast-semver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fast-semver.d.ts","sourceRoot":"","sources":["../../src/fast-semver.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,MAAM,aAAa,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AAI1E;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAOvE;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,EAAE,aAAa,GAAG,MAAM,CAQlE;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,EAAE,aAAa,GAAG,OAAO,CAElE;AAED;;GAEG;AACH,wBAAgB,SAAS,CACvB,QAAQ,EAAE,aAAa,EACvB,UAAU,EAAE,aAAa,GACxB,OAAO,CAET;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,aAAa,EACvB,UAAU,EAAE,aAAa,GACxB,OAAO,CAET;AAED;;GAEG;AACH,wBAAgB,WAAW,CACzB,QAAQ,EAAE,aAAa,EACvB,UAAU,EAAE,aAAa,GACxB,OAAO,CAET;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,aAAa,EACvB,UAAU,EAAE,aAAa,GACxB,OAAO,CAET"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * A small, fast subset of semver: strict `MAJOR.MINOR.PATCH` parsing and
3
+ * triple-wise comparison helpers.
4
+ *
5
+ * This module exists because the full `semver` package is slow to load and is
6
+ * overkill for the many call sites in Hardhat that compare against hard-coded
7
+ * `x.y.z` literals. For range grammar (caret/tilde, disjunctions, prerelease
8
+ * subset, etc.) keep using `semver`.
9
+ */
10
+ const VERSION_REGEX = /^(\d+)\.(\d+)\.(\d+)(?:\+[0-9A-Za-z.-]+)?$/;
11
+ /**
12
+ * Parses a strict `MAJOR.MINOR.PATCH` version string into a `SemverVersion`
13
+ * tuple.
14
+ *
15
+ * An optional `+build` suffix is accepted and stripped silently. A
16
+ * `-prerelease` suffix is rejected.
17
+ *
18
+ * @param version The version string to parse.
19
+ * @returns The parsed `SemverVersion`, or `undefined` if the input does not
20
+ * match the strict `\d+\.\d+\.\d+` shape.
21
+ */
22
+ export function parseVersion(version) {
23
+ const match = VERSION_REGEX.exec(version);
24
+ if (match === null) {
25
+ return undefined;
26
+ }
27
+ return [Number(match[1]), Number(match[2]), Number(match[3])];
28
+ }
29
+ /**
30
+ * `Array#sort`-style comparator for `SemverVersion` tuples: returns a negative
31
+ * number, zero, or a positive number depending on whether `a` is lower than,
32
+ * equal to, or greater than `b`.
33
+ */
34
+ export function compare(a, b) {
35
+ if (a[0] !== b[0]) {
36
+ return a[0] - b[0];
37
+ }
38
+ if (a[1] !== b[1]) {
39
+ return a[1] - b[1];
40
+ }
41
+ return a[2] - b[2];
42
+ }
43
+ /**
44
+ * Returns `true` if `a` and `b` represent the same `MAJOR.MINOR.PATCH`.
45
+ */
46
+ export function equals(a, b) {
47
+ return a[0] === b[0] && a[1] === b[1] && a[2] === b[2];
48
+ }
49
+ /**
50
+ * Returns `true` if `compared` is strictly lower than `comparator`.
51
+ */
52
+ export function lowerThan(compared, comparator) {
53
+ return compare(compared, comparator) < 0;
54
+ }
55
+ /**
56
+ * Returns `true` if `compared` is lower than or equal to `comparator`.
57
+ */
58
+ export function lowerThanOrEqual(compared, comparator) {
59
+ return compare(compared, comparator) <= 0;
60
+ }
61
+ /**
62
+ * Returns `true` if `compared` is strictly greater than `comparator`.
63
+ */
64
+ export function greaterThan(compared, comparator) {
65
+ return compare(compared, comparator) > 0;
66
+ }
67
+ /**
68
+ * Returns `true` if `compared` is greater than or equal to `comparator`.
69
+ */
70
+ export function greaterThanOrEqual(compared, comparator) {
71
+ return compare(compared, comparator) >= 0;
72
+ }
73
+ //# sourceMappingURL=fast-semver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fast-semver.js","sourceRoot":"","sources":["../../src/fast-semver.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,MAAM,aAAa,GAAG,4CAA4C,CAAC;AAEnE;;;;;;;;;;GAUG;AACH,MAAM,UAAU,YAAY,CAAC,OAAe;IAC1C,MAAM,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC1C,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACnB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC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AC,CAAC;AAC3C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAChC,QAAuB,EACvB,UAAyB;IAEzB,OAAO,OAAO,CAAC,QAAQ,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;AAC5C,CAAC"}
package/dist/src/fs.d.ts CHANGED
@@ -1,3 +1,49 @@
1
+ /**
2
+ * Resolves paths to their true (on-disk) casing, caching directory listings
3
+ * and resolutions so repeated lookups against the same directories don't re-hit
4
+ * the filesystem.
5
+ *
6
+ * Intended to be used in hot paths where the same `from` directories are seen
7
+ * over and over.
8
+ *
9
+ * Does not resolve symbolic links.
10
+ *
11
+ * This class caches successful resolutions internally, and may do some
12
+ * duplicate work when multiple concurrent lookups for the same path are made
13
+ * before the first one finishes. It does not cache failed resolutions as
14
+ * negative result entries, but it does cache directory listings, so filesystem
15
+ * changes may not be observed until `clear()` is called. After `clear()`,
16
+ * previously cached directory and resolution data is discarded. If profiling
17
+ * shows that this work duplication is a problem, we can either cache in-flight
18
+ * operations, or add a mutex.
19
+ */
20
+ export declare class TrueCasePathResolver {
21
+ #private;
22
+ /**
23
+ * Determines the true-case path of a given relative path from a specified
24
+ * directory, without resolving symbolic links.
25
+ *
26
+ * Note that the casing of the `from` path is not checked against the
27
+ * filesystem, and is trusted as-is. This avoids unnecessary directory
28
+ * listings for every ancestor of `from`, which can result in permission
29
+ * errors for directories that are otherwise accessible.
30
+ *
31
+ * @param from The absolute path of the directory to start the search from.
32
+ * @param relativePath The relative path to get the true case of.
33
+ * @returns The true case of the relative path. Returns an empty string if
34
+ * relativePath points to from.
35
+ * @throws FileNotFoundError if the starting directory or the relative path
36
+ * doesn't exist or is ambiguous.
37
+ * @throws NotADirectoryError if the starting directory, or an intermediate
38
+ * segment, is not a directory.
39
+ * @throws FileSystemAccessError for any other error.
40
+ */
41
+ getFileTrueCase(from: string, relativePath: string): Promise<string>;
42
+ /**
43
+ * Clears all cached directory listings and resolutions.
44
+ */
45
+ clear(): void;
46
+ }
1
47
  /**
2
48
  * Determines the canonical pathname for a given path, resolving any symbolic
3
49
  * links, and returns it.
@@ -46,6 +92,7 @@ export declare function getAllDirectoriesMatching(dirFrom: string, matches?: (ab
46
92
  * @throws FileNotFoundError if the starting directory or the relative path doesn't exist.
47
93
  * @throws NotADirectoryError if the starting directory is not a directory.
48
94
  * @throws FileSystemAccessError for any other error.
95
+ * @deprecated Use {@link TrueCasePathResolver} instead.
49
96
  */
50
97
  export declare function getFileTrueCase(from: string, relativePath: string): Promise<string>;
51
98
  /**
@@ -143,6 +190,16 @@ export declare function readBinaryFile(absolutePathToFile: string): Promise<Uint
143
190
  * @throws FileSystemAccessError for any other error.
144
191
  */
145
192
  export declare function readdir(absolutePathToDir: string): Promise<string[]>;
193
+ /**
194
+ * Reads a directory and returns its content as an array of strings, returning
195
+ * an empty array if the directory doesn't exist.
196
+ *
197
+ * @param absolutePathToDir The path to the directory.
198
+ * @returns An array of strings with the names of the files and directories in the directory, and an empty array if the directory doesn't exist.
199
+ * @throws NotADirectoryError if the path is not a directory.
200
+ * @throws FileSystemAccessError for any other error.
201
+ */
202
+ export declare function readdirOrEmpty(absolutePathToDir: string): Promise<string[]>;
146
203
  /**
147
204
  * Creates a directory and any necessary directories along the way. If the directory already exists,
148
205
  * nothing is done.
@@ -1 +1 @@
1
- {"version":3,"file":"fs.d.ts","sourceRoot":"","sources":["../../src/fs.ts"],"names":[],"mappings":"AAuBA;;;;;;GAMG;AACH,wBAAsB,WAAW,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAWvE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,CAAC,kBAAkB,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,EACpE,eAAe,CAAC,EAAE,CAAC,iBAAiB,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,GAC1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