You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

@nomicfoundation/hardhat-utils

Package Overview
Dependencies
Maintainers
0
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nomicfoundation/hardhat-utils - npm Package Compare versions

Comparing version
3.0.6
to
4.0.0
+29
dist/src/errors/synchronization.d.ts
import { CustomError } from "../error.js";
export declare class BaseMultiProcessMutexError extends CustomError {
constructor(message: string, cause?: Error);
}
export declare class InvalidMultiProcessMutexPathError extends BaseMultiProcessMutexError {
constructor(mutexPath: string);
}
export declare class MultiProcessMutexError extends BaseMultiProcessMutexError {
constructor(lockPath: string, cause: Error);
}
export declare class MultiProcessMutexTimeoutError extends BaseMultiProcessMutexError {
constructor(lockPath: string, timeoutMs: number);
}
export declare class StaleMultiProcessMutexError extends BaseMultiProcessMutexError {
constructor(lockPath: string, ownerUid: number | undefined, cause: Error);
}
export declare class IncompatibleMultiProcessMutexError extends BaseMultiProcessMutexError {
constructor(message: string);
}
export declare class IncompatibleHostnameMultiProcessMutexError extends IncompatibleMultiProcessMutexError {
constructor(lockPath: string, foreignHostname: string, currentHostname: string);
}
export declare class IncompatiblePlatformMultiProcessMutexError extends IncompatibleMultiProcessMutexError {
constructor(lockPath: string, foreignPlatform: string, currentPlatform: string);
}
export declare class IncompatibleUidMultiProcessMutexError extends IncompatibleMultiProcessMutexError {
constructor(lockPath: string, foreignUid: number, currentUid: number);
}
//# sourceMappingURL=synchronization.d.ts.map
{"version":3,"file":"synchronization.d.ts","sourceRoot":"","sources":["../../../src/errors/synchronization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,qBAAa,0BAA2B,SAAQ,WAAW;gBAC7C,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAG3C;AAED,qBAAa,iCAAkC,SAAQ,0BAA0B;gBACnE,SAAS,EAAE,MAAM;CAG9B;AAED,qBAAa,sBAAuB,SAAQ,0BAA0B;gBACxD,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK;CAG3C;AAED,qBAAa,6BAA8B,SAAQ,0BAA0B;gBAC/D,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;CAKhD;AAED,qBAAa,2BAA4B,SAAQ,0BAA0B;gBAC7D,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,KAAK;CAOzE;AAED,qBAAa,kCAAmC,SAAQ,0BAA0B;gBACpE,OAAO,EAAE,MAAM;CAG5B;AAED,qBAAa,0CAA2C,SAAQ,kCAAkC;gBAE9F,QAAQ,EAAE,MAAM,EAChB,eAAe,EAAE,MAAM,EACvB,eAAe,EAAE,MAAM;CAM1B;AAED,qBAAa,0CAA2C,SAAQ,kCAAkC;gBAE9F,QAAQ,EAAE,MAAM,EAChB,eAAe,EAAE,MAAM,EACvB,eAAe,EAAE,MAAM;CAM1B;AAED,qBAAa,qCAAsC,SAAQ,kCAAkC;gBAC/E,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;CAKrE"}
import { CustomError } from "../error.js";
export class BaseMultiProcessMutexError extends CustomError {
constructor(message, cause) {
super(message, cause);
}
}
export class InvalidMultiProcessMutexPathError extends BaseMultiProcessMutexError {
constructor(mutexPath) {
super(`The path ${mutexPath} is not a valid absolute path.`);
}
}
export class MultiProcessMutexError extends BaseMultiProcessMutexError {
constructor(lockPath, cause) {
super(`Unexpected error with lock at ${lockPath}: ${cause.message}`, cause);
}
}
export class MultiProcessMutexTimeoutError extends BaseMultiProcessMutexError {
constructor(lockPath, timeoutMs) {
super(`Timed out waiting to acquire lock at ${lockPath} after ${timeoutMs}ms`);
}
}
export class StaleMultiProcessMutexError extends BaseMultiProcessMutexError {
constructor(lockPath, ownerUid, cause) {
const uidInfo = ownerUid !== undefined ? ` (uid: ${ownerUid})` : "";
super(`Lock at ${lockPath} appears stale but cannot be removed due to insufficient permissions${uidInfo}. Please remove it manually: ${lockPath}`, cause);
}
}
export class IncompatibleMultiProcessMutexError extends BaseMultiProcessMutexError {
constructor(message) {
super(message);
}
}
export class IncompatibleHostnameMultiProcessMutexError extends IncompatibleMultiProcessMutexError {
constructor(lockPath, foreignHostname, currentHostname) {
super(`Lock at ${lockPath} was created by a different host (${foreignHostname}, current: ${currentHostname}). It cannot be verified or removed automatically. Please remove it manually: ${lockPath}`);
}
}
export class IncompatiblePlatformMultiProcessMutexError extends IncompatibleMultiProcessMutexError {
constructor(lockPath, foreignPlatform, currentPlatform) {
super(`Lock at ${lockPath} was created on a different platform (${foreignPlatform}, current: ${currentPlatform}). It cannot be verified or removed automatically. Please remove it manually: ${lockPath}`);
}
}
export class IncompatibleUidMultiProcessMutexError extends IncompatibleMultiProcessMutexError {
constructor(lockPath, foreignUid, currentUid) {
super(`Lock at ${lockPath} is owned by a different user (uid: ${foreignUid}, current: ${currentUid}). It cannot be removed automatically. Please remove it manually: ${lockPath}`);
}
}
//# sourceMappingURL=synchronization.js.map
{"version":3,"file":"synchronization.js","sourceRoot":"","sources":["../../../src/errors/synchronization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,MAAM,OAAO,0BAA2B,SAAQ,WAAW;IACzD,YAAY,OAAe,EAAE,KAAa;QACxC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACxB,CAAC;CACF;AAED,MAAM,OAAO,iCAAkC,SAAQ,0BAA0B;IAC/E,YAAY,SAAiB;QAC3B,KAAK,CAAC,YAAY,SAAS,gCAAgC,CAAC,CAAC;IAC/D,CAAC;CACF;AAED,MAAM,OAAO,sBAAuB,SAAQ,0BAA0B;IACpE,YAAY,QAAgB,EAAE,KAAY;QACxC,KAAK,CAAC,iCAAiC,QAAQ,KAAK,KAAK,CAAC,OAAO,EAAE,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exError extends CustomError {
constructor(message: string, cause?: Error) {
super(message, cause);
}
}
export class InvalidMultiProcessMutexPathError extends BaseMultiProcessMutexError {
constructor(mutexPath: string) {
super(`The path ${mutexPath} is not a valid absolute path.`);
}
}
export class MultiProcessMutexError extends BaseMultiProcessMutexError {
constructor(lockPath: string, cause: Error) {
super(`Unexpected error with lock at ${lockPath}: ${cause.message}`, cause);
}
}
export class MultiProcessMutexTimeoutError extends BaseMultiProcessMutexError {
constructor(lockPath: string, timeoutMs: number) {
super(
`Timed out waiting to acquire lock at ${lockPath} after ${timeoutMs}ms`,
);
}
}
export class StaleMultiProcessMutexError extends BaseMultiProcessMutexError {
constructor(lockPath: string, ownerUid: number | undefined, cause: Error) {
const uidInfo = ownerUid !== undefined ? ` (uid: ${ownerUid})` : "";
super(
`Lock at ${lockPath} appears stale but cannot be removed due to insufficient permissions${uidInfo}. Please remove it manually: ${lockPath}`,
cause,
);
}
}
export class IncompatibleMultiProcessMutexError extends BaseMultiProcessMutexError {
constructor(message: string) {
super(message);
}
}
export class IncompatibleHostnameMultiProcessMutexError extends IncompatibleMultiProcessMutexError {
constructor(
lockPath: string,
foreignHostname: string,
currentHostname: string,
) {
super(
`Lock at ${lockPath} was created by a different host (${foreignHostname}, current: ${currentHostname}). It cannot be verified or removed automatically. Please remove it manually: ${lockPath}`,
);
}
}
export class IncompatiblePlatformMultiProcessMutexError extends IncompatibleMultiProcessMutexError {
constructor(
lockPath: string,
foreignPlatform: string,
currentPlatform: string,
) {
super(
`Lock at ${lockPath} was created on a different platform (${foreignPlatform}, current: ${currentPlatform}). It cannot be verified or removed automatically. Please remove it manually: ${lockPath}`,
);
}
}
export class IncompatibleUidMultiProcessMutexError extends IncompatibleMultiProcessMutexError {
constructor(lockPath: string, foreignUid: number, currentUid: number) {
super(
`Lock at ${lockPath} is owned by a different user (uid: ${foreignUid}, current: ${currentUid}). It cannot be removed automatically. Please remove it manually: ${lockPath}`,
);
}
}
+11
-0
# @nomicfoundation/hardhat-utils
## 4.0.0
### Major Changes
- 87623db: Introduce new inter-process mutex implementation ([7942](https://github.com/NomicFoundation/hardhat/pull/7942)).
- 726ff37: Update the `--coverage` table output to match the style used by `--gas-stats`. Thanks @jose-blockchain! ([#7733](https://github.com/NomicFoundation/hardhat/issues/7733))
### Patch Changes
- 87623db: Fix two issues in the `download` function ([7942](https://github.com/NomicFoundation/hardhat/pull/7942)).
## 3.0.6

@@ -4,0 +15,0 @@

+7
-41

@@ -1,52 +0,18 @@

export type TableRow = string[];
export interface TableDivider {
type: "divider";
}
export type TableItem = TableRow | TableDivider;
export declare const divider: TableDivider;
/**
* Formats an array of rows and dividers into a table string.
*
* @param items An array of table rows (string arrays) and dividers.
* Dividers are objects with type: "divider" and will be rendered as table dividers.
* @returns The formatted table as a string, ready to be rendered.
*
* @example
* ```ts
* formatTable([
* ["Name", "Age"],
* divider,
* ["Alice", "30"],
* ["Bob", "25"],
* divider,
* ["Average", "27.5"]
* ]);
*
* // =>
* // | Name | Age |
* // | ------- | ---- |
* // | Alice | 30 |
* // | Bob | 25 |
* // | ------- | ---- |
* // | Average | 27.5 |
* ```
*/
export declare function formatTable(items: TableItem[]): string;
export interface TableTitleV2 {
export interface TableTitle {
type: "title";
text: string;
}
export interface TableSectionHeaderV2 {
export interface TableSectionHeader {
type: "section-header";
text: string;
}
export interface TableHeaderV2 {
export interface TableHeader {
type: "header";
cells: string[];
}
export interface TableRowV2 {
export interface TableRow {
type: "row";
cells: string[];
}
export type TableItemV2 = TableTitleV2 | TableSectionHeaderV2 | TableHeaderV2 | TableRowV2;
export type TableItem = TableTitle | TableSectionHeader | TableHeader | TableRow;
/**

@@ -69,3 +35,3 @@ * Formats an array of titles, section headers, headers, and rows into a table

* ```ts
* formatTableV2([
* formatTable([
* { type: "title", text: "My Table" },

@@ -103,3 +69,3 @@ * { type: "section-header", text: "User Data" },

*/
export declare function formatTableV2(items: TableItemV2[]): string;
export declare function formatTable(items: TableItem[]): string;
//# sourceMappingURL=format.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/format.ts"],"names":[],"mappings":"AAWA,MAAM,MAAM,QAAQ,GAAG,MAAM,EAAE,CAAC;AAChC,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,SAAS,CAAC;CACjB;AACD,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,YAAY,CAAC;AAEhD,eAAO,MAAM,OAAO,EAAE,YAAkC,CAAC;AAEzD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,MAAM,CA8CtD;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,gBAAgB,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,KAAK,CAAC;IACZ,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,MAAM,MAAM,WAAW,GACnB,YAAY,GACZ,oBAAoB,GACpB,aAAa,GACb,UAAU,CAAC;AAEf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,MAAM,CAgG1D"}
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/format.ts"],"names":[],"mappings":"AAWA,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,gBAAgB,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,KAAK,CAAC;IACZ,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,MAAM,MAAM,SAAS,GACjB,UAAU,GACV,kBAAkB,GAClB,WAAW,GACX,QAAQ,CAAC;AAEb;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,MAAM,CAgGtD"}
import { getColumnWidths, getContentWidth, getHeadingWidth, getStringWidth, renderContentLine, renderHeaderOpen, renderRowSeparator, renderSectionClose, } from "./internal/format.js";
export const divider = { type: "divider" };
/**
* Formats an array of rows and dividers into a table string.
*
* @param items An array of table rows (string arrays) and dividers.
* Dividers are objects with type: "divider" and will be rendered as table dividers.
* @returns The formatted table as a string, ready to be rendered.
*
* @example
* ```ts
* formatTable([
* ["Name", "Age"],
* divider,
* ["Alice", "30"],
* ["Bob", "25"],
* divider,
* ["Average", "27.5"]
* ]);
*
* // =>
* // | Name | Age |
* // | ------- | ---- |
* // | Alice | 30 |
* // | Bob | 25 |
* // | ------- | ---- |
* // | Average | 27.5 |
* ```
*/
export function formatTable(items) {
const widths = [];
const dataRows = [];
for (const item of items) {
if (Array.isArray(item)) {
dataRows.push([...item]);
}
}
// Calculate maximum width for each column
for (const row of dataRows) {
for (let i = 0; i < row.length; i++) {
while (i >= widths.length) {
widths.push(0);
}
widths[i] = Math.max(widths[i], getStringWidth(row[i]));
}
}
const dividerRow = widths.map((width) => "-".repeat(width));
const outputRows = [];
for (const item of items) {
if (Array.isArray(item)) {
const row = [...item];
// Pad the row to match the number of columns
while (row.length < widths.length) {
row.push("");
}
outputRows.push(row);
}
else {
outputRows.push([...dividerRow]);
}
}
outputRows.forEach((row) => {
for (let i = 0; i < row.length; i++) {
const displayWidth = getStringWidth(row[i]);
const actualLength = row[i].length;
// Adjust padding to account for difference between display width and actual length
row[i] = row[i].padEnd(widths[i] + actualLength - displayWidth);
}
});
return outputRows.map((row) => `| ${row.join(" | ")} |`).join("\n");
}
/**
* Formats an array of titles, section headers, headers, and rows into a table

@@ -89,3 +19,3 @@ * string with box-drawing characters.

* ```ts
* formatTableV2([
* formatTable([
* { type: "title", text: "My Table" },

@@ -123,3 +53,3 @@ * { type: "section-header", text: "User Data" },

*/
export function formatTableV2(items) {
export function formatTable(items) {
if (items.length === 0) {

@@ -126,0 +56,0 @@ return "";

@@ -1,1 +0,1 @@

{"version":3,"file":"format.js","sourceRoot":"","sources":["../../src/format.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,eAAe,EACf,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,sBAAsB,CAAC;AAQ9B,MAAM,CAAC,MAAM,OAAO,GAAiB,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;AAEzD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,WAAW,CAAC,KAAkB;IAC5C,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,QAAQ,GAAe,EAAE,CAAC;IAEhC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YACxB,QAAQ,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;IAED,0CAA0C;IAC1C,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;QAC3B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACpC,OAAO,CAAC,IAAI,MAAM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C;YACF,KAAK,CAAC,IAAI,CACR,iBAAiB,CAAC,OAAO,CAAC,KAAK,EAAE,YAAY,EAAE,gBAAgB,CAAC,CACjE,CAAC;YACF,iBAAiB,GAAG,gBAAgB,CAAC;QACvC,CAAC;aAAM,IAAI,OAAO,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;YAClC,MAAM,gBAAgB,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC;YAE9C,8CAA8C;YAC9C,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;gBACtD,KAAK,CAAC,IAAI,CAAC,kBAAkB,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAC,CAAC;YACjE,CAAC;YACD,KAAK,CAAC,IAAI,CACR,iBAAiB,CAAC,OAAO,CAAC,KAAK,EAAE,YAAY,EAAE,gBAAgB,CAAC,CACjE,CAAC;YACF,iBAAiB,GAAG,gBAAgB,CAAC;QACvC,CAAC;IACH,CAAC;IAED,IAAI,SAAS,EAAE,CAAC;QACd,KAAK,CAAC,IAAI,CAAC,kBAAkB,CAAC,YAAY,EAAE,iBAAiB,CAAC,CAAC,CAAC;IAClE,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
/**
* Sets a mock cache directory for getCacheDir. This is intended for testing
* purposes only, to isolate tests from the real global cache.
*
* @param dir The directory path to use as the mock cache directory.
*/
export declare function setMockCacheDir(dir: string): void;
/**
* Resets the mock cache directory set by setMockCacheDir.
* Call this in test cleanup to restore normal behavior.
*/
export declare function resetMockCacheDir(): void;
/**
* Returns the configuration directory path for a given package (defaults to "hardhat").

@@ -14,2 +26,6 @@ * Ensures that the directory exists before returning the path.

*
* For testing purposes, the cache directory can be overridden using
* setMockCacheDir(). This is intended to isolate tests from the real
* global cache.
*
* @param packageName The name of the package for which to generate paths. Defaults to "hardhat" if no package name is provided.

@@ -16,0 +32,0 @@ * @returns The path to the hardhat cache directory.

@@ -1,1 +0,1 @@

{"version":3,"file":"global-dir.d.ts","sourceRoot":"","sources":["../../src/global-dir.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAChC,WAAW,GAAE,MAA6B,GACzC,OAAO,CAAC,MAAM,CAAC,CAIjB;AAED;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAC/B,WAAW,GAAE,MAA6B,GACzC,OAAO,CAAC,MAAM,CAAC,CAIjB;AAED;;;;;;;GAOG;AACH,wBAAsB,eAAe,CACnC,WAAW,GAAE,MAA6B,GACzC,OAAO,CAAC,MAAM,CAAC,CAIjB"}
{"version":3,"file":"global-dir.d.ts","sourceRoot":"","sources":["../../src/global-dir.ts"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAEjD;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CAExC;AAED;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAChC,WAAW,GAAE,MAA6B,GACzC,OAAO,CAAC,MAAM,CAAC,CAIjB;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,WAAW,CAC/B,WAAW,GAAE,MAA6B,GACzC,OAAO,CAAC,MAAM,CAAC,CAUjB;AAED;;;;;;;GAOG;AACH,wBAAsB,eAAe,CACnC,WAAW,GAAE,MAA6B,GACzC,OAAO,CAAC,MAAM,CAAC,CAIjB"}
import { ensureDir } from "./fs.js";
import { generatePaths, HARDHAT_PACKAGE_NAME } from "./internal/global-dir.js";
// Internal override for testing purposes
let _cacheDirOverride;
/**
* Sets a mock cache directory for getCacheDir. This is intended for testing
* purposes only, to isolate tests from the real global cache.
*
* @param dir The directory path to use as the mock cache directory.
*/
export function setMockCacheDir(dir) {
_cacheDirOverride = dir;
}
/**
* Resets the mock cache directory set by setMockCacheDir.
* Call this in test cleanup to restore normal behavior.
*/
export function resetMockCacheDir() {
_cacheDirOverride = undefined;
}
/**
* Returns the configuration directory path for a given package (defaults to "hardhat").

@@ -20,2 +38,6 @@ * Ensures that the directory exists before returning the path.

*
* For testing purposes, the cache directory can be overridden using
* setMockCacheDir(). This is intended to isolate tests from the real
* global cache.
*
* @param packageName The name of the package for which to generate paths. Defaults to "hardhat" if no package name is provided.

@@ -26,2 +48,7 @@ * @returns The path to the hardhat cache directory.

export async function getCacheDir(packageName = HARDHAT_PACKAGE_NAME) {
// Allow override for testing purposes
if (_cacheDirOverride !== undefined) {
await ensureDir(_cacheDirOverride);
return _cacheDirOverride;
}
const { cache } = await generatePaths(packageName);

@@ -28,0 +55,0 @@ await ensureDir(cache);

@@ -1,1 +0,1 @@

{"version":3,"file":"global-dir.js","sourceRoot":"","sources":["../../src/global-dir.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAE/E;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,cAAsB,oBAAoB;IAE1C,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,aAAa,CAAC,WAAW,CAAC,CAAC;IACpD,MAAM,SAAS,CAAC,MAAM,CAAC,CAAC;IACxB,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,cAAsB,oBAAoB;IAE1C,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,aAAa,CAAC,WAAW,CAAC,CAAC;IACnD,MAAM,SAAS,CAAC,KAAK,CAAC,CAAC;IACvB,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,cAAsB,oBAAoB;IAE1C,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,aAAa,CAAC,WAAW,CAAC,CAAC;IAClD,MAAM,SAAS,CAAC,I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I,CAAC,CAAC;IACtB,OAAO,IAAI,CAAC;AACd,CAAC"}

@@ -1,2 +0,2 @@

import type { TableItemV2 } from "../format.js";
import type { TableItem } from "../format.js";
/**

@@ -14,3 +14,3 @@ * Calculate the display width of a string by removing ANSI escape codes.

*/
export declare function getColumnWidths(items: TableItemV2[]): number[];
export declare function getColumnWidths(items: TableItem[]): number[];
/**

@@ -31,3 +31,3 @@ * Calculates the inner width needed to fit the rows and headers

*/
export declare function getHeadingWidth(items: TableItemV2[]): number;
export declare function getHeadingWidth(items: TableItem[]): number;
/**

@@ -34,0 +34,0 @@ * Calculates the width needed for unused columns when a row/header has fewer

@@ -1,1 +0,1 @@

{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../../src/internal/format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAIlD;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,MAAM,EAAE,CAY9D;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,MAAM,CAM9D;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,MAAM,CAQ5D;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,YAAY,EAAE,MAAM,EAAE,EACtB,iBAAiB,EAAE,MAAM,GACxB,MAAM,CAGR;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,YAAY,EAAE,MAAM,EAAE,EACtB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GACb,MAAM,CAER;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,EAAE,EACtB,IAAI,EAAE,MAAM,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Y,EAAE,MAAM,EAAE,EACtB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GACb,MAAM,CAER;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,EAAE,EACtB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,GAClB,MAAM,CAIR;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,MAAM,EAAE,EACf,YAAY,EAAE,MAAM,EAAE,EACtB,gBAAgB,EAAE,MAAM,GACvB,MAAM,CAmCR;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAC9B,YAAY,EAAE,MAAM,EAAE,EACtB,gBAAgB,EAAE,MAAM,EACxB,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,OAAO,GACvB,MAAM,CA2BR;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAChC,YAAY,EAAE,MAAM,EAAE,EACtB,gBAAgB,EAAE,MAAM,GACvB,MAAM,CAkBR;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,YAAY,EAAE,MAAM,EAAE,EACtB,iBAAiB,EAAE,MAAM,GACxB,MAAM,CAcR"}

@@ -1,1 +0,1 @@

{"version":3,"file":"format.js","sourceRoot":"","sources":["../../../src/internal/format.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,GAAW;IACxC,sCAAsC;IACtC,MAAM,QAAQ,GAAG,GAAG,CAAC,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC,CAAC;IACtD,OAAO,QAAQ,CAAC,MAAM,CAAC;AACzB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,KAAoB;IAClD,MAAM,YAAY,GAAa,EAAE,CAAC;IAElC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,I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I,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,EAAE,KAAK,CAAC,GAC/C,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAO7B;AAED,wBAAsB,iBAAiB,CACrC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,OAAO,GAC5B,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAKvB;AAED,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,OAAO,GAC7B,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAIxB;AAED,wBAAgB,wBAAwB,CACtC,OAAO,GAAE,MAAwC,EACjD,gBAAgB,GAAE,OAAe,GAChC,OAAO,CAAC,MAAM,CAAC,OAAO,CAcxB;AAED,wBAAgB,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAItD;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAsB9D"}

@@ -0,1 +1,2 @@

import crypto from "node:crypto";
import path from "node:path";

@@ -11,3 +12,3 @@ import { mkdir } from "../fs.js";

ext,
name: `tmp-${name}`,
name: `tmp-${name}-${crypto.randomBytes(8).toString("hex")}`,
});

@@ -14,0 +15,0 @@ }

@@ -1,1 +0,1 @@

{"version":3,"file":"request.js","sourceRoot":"","sources":["../../../src/internal/request.ts"],"names":[],"mappings":"AAIA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,+BAA+B,EAC/B,kBAAkB,EAClB,aAAa,EACb,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,eAAe,CAAC;AAEvB,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,QAAgB;IACzD,MAAM,EAAE,G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M,EACX,WAAW,EAAE,MAAM,EACnB,cAAc,GAAE,cAAmB,EACnC,6BAA6B,CAAC,EAAE,OAAO,CAAC,UAAU,GAAG,iBAAiB,GACrE,OAAO,CAAC,IAAI,CAAC,CAsDf;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,aAAa,CACjC,GAAG,EAAE,MAAM,EACX,EACE,OAAO,EACP,KAAK,EACL,IAAI,EACJ,cAAc,EACd,gBAAgB,GACjB,GAAE,iBAAsB,GACxB,OAAO,CAAC,UAAU,CAAC,CAyBrB;AAED,wBAAsB,iBAAiB,CACrC,OAAO,GAAE;IACP,OAAO,CAAC,EAAE,MAAM,CAAC;CACb,GACL,OAAO,CAAC,cAAc,CAAC,CAKzB;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAiBnD;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAO/C;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAoB3D;AAED,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,aAAa,EACb,YAAY,EACZ,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,qBAAqB,CAAC"}

@@ -1,2 +0,2 @@

import fs from "node:fs";
import { open } from "node:fs/promises";
import querystring from "node:querystring";

@@ -6,3 +6,3 @@ import stream from "node:stream/promises";

import { DownloadError, RequestError, DispatcherError, } from "./errors/request.js";
import { move } from "./fs.js";
import { move, remove } from "./fs.js";
import { generateTempFilePath, getBaseDispatcherOptions, getBaseRequestOptions, getBasicDispatcher, getPoolDispatcher, getProxyDispatcher, handleError, } from "./internal/request.js";

@@ -120,6 +120,7 @@ export const DEFAULT_TIMEOUT_IN_MILLISECONDS = 300_000; // Aligned with unidici

let statusCode;
let tempFilePath;
try {
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions
-- We need the full Dispatcher.ResponseData here for stream.pipeline,
but HttpResponse doesn’t expose the raw ReadableStream.
but HttpResponse doesn't expose the raw ReadableStream.
TODO: wrap undici's request so we can keep the public API

@@ -133,5 +134,14 @@ strictly typed without falling back to Undici types. */

}
const tempFilePath = await generateTempFilePath(destination);
const fileStream = fs.createWriteStream(tempFilePath);
await stream.pipeline(body, fileStream);
tempFilePath = await generateTempFilePath(destination);
let fileHandle;
try {
fileHandle = await open(tempFilePath, "w");
const fileStream = fileHandle.createWriteStream();
await stream.pipeline(body, fileStream);
}
finally {
// NOTE: Historically, not closing the file handle caused issues on Windows,
// for example, when trying to move the file previously written to by this function
await fileHandle?.close();
}
await move(tempFilePath, destination);

@@ -141,2 +151,10 @@ }

ensureError(e);
if (tempFilePath !== undefined) {
try {
await remove(tempFilePath);
}
catch {
// Best-effort: file may not exist or may have already been moved
}
}
handleError(e, url);

@@ -143,0 +161,0 @@ throw new DownloadError(url, e);

@@ -1,1 +0,1 @@

{"version":3,"file":"request.js","sourceRoot":"","sources":["../../src/request.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAC3C,OAAO,MAAM,MAAM,sBAAsB,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EACL,aAAa,EACb,YAAY,EACZ,eAAe,GAChB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACxB,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,WAAW,GACZ,MAAM,uBAAuB,CAAC;AAE/B,MAAM,CAAC,MAAM,+BAA+B,GAAG,OAAO,CAAC,CAAC,uBAAuB;AAC/E,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,CAAC;AACxC,MAAM,CAAC,MAAM,4BAA4B,GA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AAQ,EAAE,CAAC;QAC1B,OAAO,CACL,OAAO,CAAC,GAAG,CAAC,WAAW;YACvB,OAAO,CAAC,GAAG,CAAC,WAAW;YACvB,OAAO,CAAC,GAAG,CAAC,UAAU;YACtB,OAAO,CAAC,GAAG,CAAC,UAAU,CACvB,CAAC;IACJ,CAAC;SAAM,IAAI,QAAQ,KAAK,OAAO,EAAE,CAAC;QAChC,OAAO,CACL,OAAO,CAAC,GAAG,CAAC,UAAU;YACtB,OAAO,CAAC,GAAG,CAAC,UAAU;YACtB,OAAO,CAAC,GAAG,CAAC,WAAW;YACvB,OAAO,CAAC,GAAG,CAAC,WAAW,CACxB,CAAC;IACJ,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,aAAa,EACb,YAAY,EACZ,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,qBAAqB,CAAC"}

@@ -0,5 +1,103 @@

export { IncompatibleHostnameMultiProcessMutexError, IncompatibleMultiProcessMutexError, IncompatiblePlatformMultiProcessMutexError, IncompatibleUidMultiProcessMutexError, InvalidMultiProcessMutexPathError, MultiProcessMutexError, MultiProcessMutexTimeoutError, StaleMultiProcessMutexError, } from "./errors/synchronization.js";
/**
* A class that implements an inter-process mutex.
*
* This Mutex is implemented using hard-link-based atomic file creation. A
* temporary file containing JSON metadata (PID, hostname, platform, uid,
* session ID, and creation timestamp) is written first, then hard-linked to
* the lock path via `fs.linkSync`. `linkSync` fails atomically with `EEXIST`
* if the lock already exists, ensuring only one process can hold the lock at
* a time.
*
* Staleness is determined by PID liveness only — timestamps are stored for
* debugging purposes but are never used to determine staleness. This avoids the
* clock-skew and long-running-task problems that time-based staleness detection
* has (where a second process can break into a lock that's still legitimately
* held).
*
* Incompatible locks — those created by a different hostname, platform, or
* uid — are rejected immediately with specific subclasses of
* `IncompatibleMultiProcessMutexError`
* (`IncompatibleHostnameMultiProcessMutexError`,
* `IncompatiblePlatformMultiProcessMutexError`, or
* `IncompatibleUidMultiProcessMutexError`) because their PID liveness cannot
* be verified or their lock file cannot be removed. These must be removed
* manually.
*
* When the lock is held by a live process, the caller polls with exponential
* backoff (default: 5ms → 10ms → ... → 160ms → 200ms cap) until the lock is
* released or a timeout (default: 60s) is reached.
*
* If the filesystem does not support hard links (e.g., certain network
* filesystems), acquisition fails fast with a `MultiProcessMutexError` rather
* than degrading into timeout-based retries.
*
* ## Performance characteristics
*
* - **Uncontended acquisition:** One temp file write + one `linkSync` — takes
* less than 1ms on most systems.
* - **Stale lock recovery:** One `readFileSync` to read metadata, one
* `process.kill(pid, 0)` liveness check, and one `unlinkSync` to remove the
* stale lock file before retrying acquisition. The retry is immediate (no
* sleep), so recovery adds sub-millisecond overhead.
* - **Contended (live holder):** Polls with exponential backoff starting at
* 5ms and doubling each iteration until capped at 200ms. Worst-case latency
* after the lock is released is up to `MAX_POLL_INTERVAL_MS` (200ms).
* - **Release:** A single `unlinkSync` call.
*
* ## Limitations
*
* - **Polling-based:** There is no filesystem notification; callers discover
* that the lock is free only on the next poll, so there can be up to 200ms
* of wasted wait time after the lock is released.
* - **Not reentrant:** The same process (or even the same `MultiProcessMutex`
* instance) calling `use()` while already holding the lock will deadlock
* until the timeout fires.
* - **Single-host, single-user only:** Encountering a lock from a different
* hostname throws `IncompatibleHostnameMultiProcessMutexError`, a different
* platform throws `IncompatiblePlatformMultiProcessMutexError`, and a
* different uid throws `IncompatibleUidMultiProcessMutexError`. All extend
* `IncompatibleMultiProcessMutexError`. This means the lock is not safe to
* use on shared/networked filesystems (e.g., NFS) where multiple hosts or
* users may access the same path.
* - **Requires hard-link support:** The underlying filesystem must support
* `linkSync`. If hard links are unsupported, acquisition fails immediately
* with `MultiProcessMutexError`.
* - **PID recycling:** If a process dies and the OS reassigns its PID to a new
* unrelated process before the stale check runs, the lock is incorrectly
* considered live. This is extremely unlikely in practice due to the large
* PID space on modern systems.
* - **No fairness guarantee:** Multiple waiters polling concurrently have no
* guaranteed ordering — whichever one succeeds at `linkSync` first after the
* lock is released wins.
*/
export declare class MultiProcessMutex {
#private;
constructor(mutexName: string, maxMutexLifespanInMs?: number);
/**
* Creates an inter-process mutex given an absolute path.
*
* @param absolutePathToLock The absolute path of the mutex.
* @param timeout The max amount of time to spend trying to acquire the lock
* in milliseconds. Defaults to 60000.
* @param initialPollInterval The initial poll interval in milliseconds.
* Defaults to 5.
*/
constructor(absolutePathToLock: string, timeout?: number, initialPollInterval?: number);
/**
* Runs the function f while holding the mutex, returning its result.
*
* @param f The function to run.
* @returns The result of the function.
*/
use<T>(f: () => Promise<T>): Promise<T>;
/**
* Acquires the mutex, returning an async function to release it.
* The function MUST be called after using the mutex.
*
* If this function throws, no cleanup is necessary — the lock was never
* acquired.
*
* @returns The mutex's release function.
*/
acquire(): Promise<() => Promise<void>>;
}

@@ -6,0 +104,0 @@ /**

@@ -1,1 +0,1 @@

{"version":3,"file":"synchronization.d.ts","sourceRoot":"","sources":["../../src/synchronization.ts"],"names":[],"mappings":"AAwBA,qBAAa,iBAAiB;;gBAIhB,SAAS,EAAE,MAAM,EAAE,oBAAoB,CAAC,EAAE,MAAM;IAQ/C,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CA8HrD;AAED;;;;;GAKG;AACH,qBAAa,UAAU;;IAIrB;;;;;;OAMG;IACU,YAAY,CAAC,OAAO,EAC/B,CAAC,EAAE,MAAM,OAAO,GACf,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;CA+B7B"}
{"version":3,"file":"synchronization.d.ts","sourceRoot":"","sources":["../../src/synchronization.ts"],"names":[],"mappings":"AAqBA,OAAO,EACL,0CAA0C,EAC1C,kCAAkC,EAClC,0CAA0C,EAC1C,qCAAqC,EACrC,iCAAiC,EACjC,sBAAsB,EACtB,6BAA6B,EAC7B,2BAA2B,GAC5B,MAAM,6BAA6B,CAAC;AAgCrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuEG;AACH,qBAAa,iBAAiB;;IAK5B;;;;;;;;OAQG;gBAED,kBAAkB,EAAE,MAAM,EAC1B,OAAO,CAAC,EAAE,MAAM,EAChB,mBAAmB,CAAC,EAAE,MAAM;IAY9B;;;;;OAKG;IACU,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAUpD;;;;;;;;OAQG;IACU,OAAO,IAAI,OAAO,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CA+XrD;AAED;;;;;GAKG;AACH,qBAAa,UAAU;;IAIrB;;;;;;OAMG;IACU,YAAY,CAAC,OAAO,EAC/B,CAAC,EAAE,MAAM,OAAO,GACf,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;CA+B7B"}

@@ -1,105 +0,328 @@

// Logic explanation: the fs.writeFile function, when used with the wx+ flag, performs an atomic operation to create a file.
// If multiple processes try to create the same file simultaneously, only one will succeed.
// This logic can be utilized to implement a mutex.
// ATTENTION: in the current implementation, there's still a risk of two processes running simultaneously.
// For example, if processA has locked the mutex and is running, processB will wait.
// During this wait, processB continuously checks the elapsed time since the mutex lock file was created.
// If an excessive amount of time has passed, processB will assume ownership of the mutex to prevent stale locks, even if processA is still running.
// As a result, two processes will be running simultaneously in what is theoretically a mutex-locked section.
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { randomUUID } from "node:crypto";
import * as fs from "node:fs";
import * as os from "node:os";
import * as path from "node:path";
import debug from "debug";
import { ensureNodeErrnoExceptionError } from "./error.js";
import { FileSystemAccessError } from "./errors/fs.js";
import { readUtf8File } from "./fs.js";
import { ensureError, ensureNodeErrnoExceptionError } from "./error.js";
import { BaseMultiProcessMutexError, IncompatibleHostnameMultiProcessMutexError, IncompatiblePlatformMultiProcessMutexError, IncompatibleUidMultiProcessMutexError, InvalidMultiProcessMutexPathError, MultiProcessMutexError, MultiProcessMutexTimeoutError, StaleMultiProcessMutexError, } from "./errors/synchronization.js";
import { ensureDir } from "./fs.js";
import { sleep } from "./lang.js";
export { IncompatibleHostnameMultiProcessMutexError, IncompatibleMultiProcessMutexError, IncompatiblePlatformMultiProcessMutexError, IncompatibleUidMultiProcessMutexError, InvalidMultiProcessMutexPathError, MultiProcessMutexError, MultiProcessMutexTimeoutError, StaleMultiProcessMutexError, } from "./errors/synchronization.js";
const log = debug("hardhat:util:multi-process-mutex");
const DEFAULT_MAX_MUTEX_LIFESPAN_IN_MS = 60000;
const MUTEX_LOOP_WAITING_TIME_IN_MS = 100;
const PROCESS_SESSION_ID = randomUUID();
const DEFAULT_TIMEOUT_MS = 60_000;
const DEFAULT_INITIAL_POLL_INTERVAL_MS = 5;
const MAX_POLL_INTERVAL_MS = 200;
/**
* Error codes indicating hard links are definitively unsupported on the
* target filesystem. These cause immediate failure rather than retries.
*/
const HARD_LINK_UNSUPPORTED_CODES = new Set(["EOPNOTSUPP", "ENOTSUP", "EXDEV"]);
/**
* A class that implements an inter-process mutex.
*
* This Mutex is implemented using hard-link-based atomic file creation. A
* temporary file containing JSON metadata (PID, hostname, platform, uid,
* session ID, and creation timestamp) is written first, then hard-linked to
* the lock path via `fs.linkSync`. `linkSync` fails atomically with `EEXIST`
* if the lock already exists, ensuring only one process can hold the lock at
* a time.
*
* Staleness is determined by PID liveness only — timestamps are stored for
* debugging purposes but are never used to determine staleness. This avoids the
* clock-skew and long-running-task problems that time-based staleness detection
* has (where a second process can break into a lock that's still legitimately
* held).
*
* Incompatible locks — those created by a different hostname, platform, or
* uid — are rejected immediately with specific subclasses of
* `IncompatibleMultiProcessMutexError`
* (`IncompatibleHostnameMultiProcessMutexError`,
* `IncompatiblePlatformMultiProcessMutexError`, or
* `IncompatibleUidMultiProcessMutexError`) because their PID liveness cannot
* be verified or their lock file cannot be removed. These must be removed
* manually.
*
* When the lock is held by a live process, the caller polls with exponential
* backoff (default: 5ms → 10ms → ... → 160ms → 200ms cap) until the lock is
* released or a timeout (default: 60s) is reached.
*
* If the filesystem does not support hard links (e.g., certain network
* filesystems), acquisition fails fast with a `MultiProcessMutexError` rather
* than degrading into timeout-based retries.
*
* ## Performance characteristics
*
* - **Uncontended acquisition:** One temp file write + one `linkSync` — takes
* less than 1ms on most systems.
* - **Stale lock recovery:** One `readFileSync` to read metadata, one
* `process.kill(pid, 0)` liveness check, and one `unlinkSync` to remove the
* stale lock file before retrying acquisition. The retry is immediate (no
* sleep), so recovery adds sub-millisecond overhead.
* - **Contended (live holder):** Polls with exponential backoff starting at
* 5ms and doubling each iteration until capped at 200ms. Worst-case latency
* after the lock is released is up to `MAX_POLL_INTERVAL_MS` (200ms).
* - **Release:** A single `unlinkSync` call.
*
* ## Limitations
*
* - **Polling-based:** There is no filesystem notification; callers discover
* that the lock is free only on the next poll, so there can be up to 200ms
* of wasted wait time after the lock is released.
* - **Not reentrant:** The same process (or even the same `MultiProcessMutex`
* instance) calling `use()` while already holding the lock will deadlock
* until the timeout fires.
* - **Single-host, single-user only:** Encountering a lock from a different
* hostname throws `IncompatibleHostnameMultiProcessMutexError`, a different
* platform throws `IncompatiblePlatformMultiProcessMutexError`, and a
* different uid throws `IncompatibleUidMultiProcessMutexError`. All extend
* `IncompatibleMultiProcessMutexError`. This means the lock is not safe to
* use on shared/networked filesystems (e.g., NFS) where multiple hosts or
* users may access the same path.
* - **Requires hard-link support:** The underlying filesystem must support
* `linkSync`. If hard links are unsupported, acquisition fails immediately
* with `MultiProcessMutexError`.
* - **PID recycling:** If a process dies and the OS reassigns its PID to a new
* unrelated process before the stale check runs, the lock is incorrectly
* considered live. This is extremely unlikely in practice due to the large
* PID space on modern systems.
* - **No fairness guarantee:** Multiple waiters polling concurrently have no
* guaranteed ordering — whichever one succeeds at `linkSync` first after the
* lock is released wins.
*/
export class MultiProcessMutex {
#mutexFilePath;
#mutexLifespanInMs;
constructor(mutexName, maxMutexLifespanInMs) {
log(`Creating mutex with name '${mutexName}'`);
this.#mutexFilePath = path.join(os.tmpdir(), `${mutexName}.txt`);
this.#mutexLifespanInMs =
maxMutexLifespanInMs ?? DEFAULT_MAX_MUTEX_LIFESPAN_IN_MS;
#lockFilePath;
#timeout;
#initialPollInterval;
/**
* Creates an inter-process mutex given an absolute path.
*
* @param absolutePathToLock The absolute path of the mutex.
* @param timeout The max amount of time to spend trying to acquire the lock
* in milliseconds. Defaults to 60000.
* @param initialPollInterval The initial poll interval in milliseconds.
* Defaults to 5.
*/
constructor(absolutePathToLock, timeout, initialPollInterval) {
if (!path.isAbsolute(absolutePathToLock)) {
throw new InvalidMultiProcessMutexPathError(absolutePathToLock);
}
this.#lockFilePath = absolutePathToLock;
this.#timeout = timeout ?? DEFAULT_TIMEOUT_MS;
this.#initialPollInterval =
initialPollInterval ?? DEFAULT_INITIAL_POLL_INTERVAL_MS;
}
/**
* Runs the function f while holding the mutex, returning its result.
*
* @param f The function to run.
* @returns The result of the function.
*/
async use(f) {
log(`Starting mutex process with mutex file '${this.#mutexFilePath}'`);
const release = await this.acquire();
try {
return await f();
}
finally {
await release();
}
}
/**
* Acquires the mutex, returning an async function to release it.
* The function MUST be called after using the mutex.
*
* If this function throws, no cleanup is necessary — the lock was never
* acquired.
*
* @returns The mutex's release function.
*/
async acquire() {
log(`Starting mutex process with lock file '${this.#lockFilePath}'`);
try {
await this.#acquireLock();
}
catch (e) {
ensureError(e);
if (e instanceof BaseMultiProcessMutexError) {
throw e;
}
throw new MultiProcessMutexError(this.#lockFilePath, e);
}
let released = false;
return async () => {
if (released) {
return;
}
this.#releaseLock();
released = true;
};
}
async #acquireLock() {
const startTime = Date.now();
let pollInterval = this.#initialPollInterval;
await ensureDir(path.dirname(this.#lockFilePath));
while (true) {
if (await this.#tryToAcquireMutex()) {
// Mutex has been acquired
return this.#executeFunctionAndReleaseMutex(f);
const result = this.#tryAcquire();
if (result.acquired) {
return;
}
// Mutex not acquired
if (this.#isMutexFileTooOld()) {
// If the mutex file is too old, it likely indicates a stale lock, so the file should be removed
log(`Current mutex file is too old, removing it at path '${this.#mutexFilePath}'`);
this.#deleteMutexFile();
// Check timeout
const elapsed = Date.now() - startTime;
if (elapsed >= this.#timeout) {
throw new MultiProcessMutexTimeoutError(this.#lockFilePath, this.#timeout);
}
else if (await this.#isMutexProcessOwnerDead()) {
log(`The process owning the mutex file no longer exists. Removing mutex file at '${this.#mutexFilePath}'.`);
this.#deleteMutexFile();
// Skip sleep after reclaiming a stale lock — retry immediately
if (result.reclaimedStaleLock) {
continue;
}
else {
// wait
await sleep(MUTEX_LOOP_WAITING_TIME_IN_MS / 1000);
}
// Wait with exponential backoff
log(`Lock at ${this.#lockFilePath} is busy, waiting ${pollInterval}ms`);
await sleep(pollInterval / 1000);
// Exponential backoff, capped
pollInterval = Math.min(pollInterval * 2, MAX_POLL_INTERVAL_MS);
}
}
async #tryToAcquireMutex() {
#releaseLock() {
try {
// Create a file only if it does not exist
fs.writeFileSync(this.#mutexFilePath, process.pid.toString(), {
flag: "wx+",
});
return true;
fs.unlinkSync(this.#lockFilePath);
log(`Released lock at ${this.#lockFilePath}`);
}
catch (e) {
ensureNodeErrnoExceptionError(e);
if (e.code === "EEXIST") {
// File already exists, so the mutex is already acquired
return false;
if (e.code === "ENOENT") {
log(`Lock at ${this.#lockFilePath} already removed`);
return;
}
throw new FileSystemAccessError(e.message, e);
throw new MultiProcessMutexError(this.#lockFilePath, e);
}
}
async #executeFunctionAndReleaseMutex(f) {
log(`Mutex acquired at path '${this.#mutexFilePath}'`);
#tryAcquire() {
const lockPath = this.#lockFilePath;
// Fast path: if the lock file already exists, check staleness directly
// without creating temp files. This is both an optimization for the
// common contended case and is required for correct behavior when the
// parent directory is read-only (stale locks can still be detected via
// readFileSync even when file creation in the directory is blocked).
//
// Note: handleExistingLock() must be called outside the try/catch so
// that errors like StaleMultiProcessMutexError propagate correctly.
let lockExists = false;
try {
return await f();
fs.accessSync(lockPath, fs.constants.F_OK);
lockExists = true;
}
finally {
// Release the mutex
// Note: if a process dies, its `finally` block never executes, and the process hangs indefinitely since no response is received.
// To handle this, we use the function `isMutexProcessOwnerDead`.
log(`Mutex released at path '${this.#mutexFilePath}'`);
this.#deleteMutexFile();
log(`Mutex released at path '${this.#mutexFilePath}'`);
catch {
// Lock doesn't exist (or can't be checked) — proceed to acquire
}
}
#isMutexFileTooOld() {
let fileStat;
if (lockExists) {
return this.#handleExistingLock();
}
// Lock doesn't appear to exist — try to acquire via temp file + hard link
const metadata = this.#buildMetadata();
const contents = JSON.stringify(metadata, null, 2);
const randomSuffix = Math.random().toString(16).slice(2);
const tempPath = `${lockPath}.tmp-${process.pid}-${PROCESS_SESSION_ID}-${Date.now()}-${randomSuffix}`;
let tempFd;
try {
fileStat = fs.statSync(this.#mutexFilePath);
// Create temp file with exclusive flag to prevent collisions
tempFd = fs.openSync(tempPath, "wx");
fs.writeFileSync(tempFd, contents, "utf8");
fs.closeSync(tempFd);
tempFd = undefined;
// Attempt atomic hard link to the lock path
fs.linkSync(tempPath, lockPath);
log(`Acquired lock at ${lockPath}`);
// Best-effort cleanup of temp files left by dead processes.
// We hold the lock, so only one process runs this at a time.
this.#cleanupDeadProcessTempFiles();
return { acquired: true };
}
catch (e) {
ensureNodeErrnoExceptionError(e);
if (e.code === "EEXIST") {
// Lock was created between our accessSync and linkSync
return this.#handleExistingLock();
}
if (e.code === "ENOENT") {
// The file might have been deleted by another process while this function was trying to access it.
return false;
// Parent directory doesn't exist. Create it and retry.
const parentDir = path.dirname(lockPath);
log(`Parent directory ${parentDir} does not exist, creating it`);
fs.mkdirSync(parentDir, { recursive: true });
return { acquired: false, reclaimedStaleLock: false };
}
throw new FileSystemAccessError(e.message, e);
// Hard links definitively unsupported — fail fast
if (HARD_LINK_UNSUPPORTED_CODES.has(e.code ?? "")) {
throw new MultiProcessMutexError(lockPath, e);
}
// We retry on permission errors, as this is a common transient failure
// on Windows.
if (e.code === "EPERM" || e.code === "EACCES") {
log("Failed to acquire lock, retrying due to permission error");
return { acquired: false, reclaimedStaleLock: false };
}
// Any other error (ENAMETOOLONG, ENOSPC, etc.)
throw new MultiProcessMutexError(lockPath, e);
}
const now = new Date();
const fileDate = new Date(fileStat.ctime);
const diff = now.getTime() - fileDate.getTime();
return diff > this.#mutexLifespanInMs;
finally {
// Close fd if still open (write or close failed)
if (tempFd !== undefined) {
try {
fs.closeSync(tempFd);
}
catch {
// Best effort
}
}
// Always clean up the temp file
try {
fs.unlinkSync(tempPath);
}
catch {
// Best effort — file may not exist if openSync failed
}
}
}
#deleteMutexFile() {
#handleExistingLock() {
const staleness = this.#checkStaleness();
if (staleness.isStale) {
const reclaimed = this.#tryUnlockingStaleLock(staleness.metadata);
return { acquired: false, reclaimedStaleLock: reclaimed };
}
return { acquired: false, reclaimedStaleLock: false };
}
#checkStaleness() {
const lockPath = this.#lockFilePath;
const metadata = this.#readMetadata();
if (metadata === undefined) {
log(`Lock at ${lockPath} has missing/corrupt metadata, treating as stale`);
return { isStale: true, metadata: undefined };
}
// Different hostname — can't verify PID remotely
if (metadata.hostname !== os.hostname()) {
throw new IncompatibleHostnameMultiProcessMutexError(lockPath, metadata.hostname, os.hostname());
}
// Different platform — can't verify PID across platforms
if (metadata.platform !== process.platform) {
throw new IncompatiblePlatformMultiProcessMutexError(lockPath, metadata.platform, process.platform);
}
// Different uid — can't remove a lock owned by another user
const currentUid = process.getuid?.();
if (metadata.uid !== undefined &&
currentUid !== undefined &&
metadata.uid !== currentUid) {
throw new IncompatibleUidMultiProcessMutexError(lockPath, metadata.uid, currentUid);
}
// PID liveness check
if (!this.#isProcessAlive(metadata.pid)) {
log(`Lock at ${lockPath} owned by dead process PID=${metadata.pid}`);
return { isStale: true, metadata };
}
// Process is alive, lock is not stale
return { isStale: false };
}
#tryUnlockingStaleLock(metadata) {
const lockPath = this.#lockFilePath;
try {
log(`Deleting mutex file at path '${this.#mutexFilePath}'`);
fs.unlinkSync(this.#mutexFilePath);
fs.unlinkSync(lockPath);
log(`Removed stale lock at ${lockPath}`);
}

@@ -109,29 +332,124 @@ catch (e) {

if (e.code === "ENOENT") {
// The file might have been deleted by another process while this function was trying to access it.
return;
// Already removed by another process — safe to retry acquisition
log(`Stale lock at ${lockPath} already removed by another process`);
return true;
}
throw new FileSystemAccessError(e.message, e);
if (e.code === "EACCES" || e.code === "EPERM" || e.code === "EBUSY") {
throw new StaleMultiProcessMutexError(lockPath, metadata?.uid, e);
}
throw new MultiProcessMutexError(lockPath, e);
}
// Best-effort cleanup of orphaned temp files from dead processes
this.#cleanupDeadProcessTempFiles();
return true;
}
async #isMutexProcessOwnerDead() {
let mutexPid;
/**
* Checks if a process with the given PID is alive using signal 0, which is
* a platform-independent existence check supported on both POSIX and Windows.
*
* `ESRCH` means the process doesn't exist. `EPERM` means it exists but
* belongs to another user — still alive.
*/
#isProcessAlive(pid) {
try {
// If the file doesn't exist, it means the owning process deleted it
mutexPid = await readUtf8File(this.#mutexFilePath);
process.kill(pid, 0);
return true;
}
catch (_e) {
return false;
}
try {
process.kill(parseInt(mutexPid, 10), 0);
}
catch (e) {
ensureNodeErrnoExceptionError(e);
if (e.code === "ESRCH") {
// The process owning the mutex no longer exists
return true;
return false; // Process does not exist
}
// EPERM means the process exists but we don't have permission to signal it
return true;
}
return false;
}
#buildMetadata() {
return {
pid: process.pid,
hostname: os.hostname(),
createdAt: Date.now(),
...(process.getuid !== undefined ? { uid: process.getuid() } : {}),
platform: process.platform,
sessionId: PROCESS_SESSION_ID,
};
}
#readMetadata() {
try {
const content = fs.readFileSync(this.#lockFilePath, "utf8");
const parsed = JSON.parse(content);
if (typeof parsed !== "object" ||
parsed === null ||
!("pid" in parsed) ||
!("hostname" in parsed) ||
!("createdAt" in parsed) ||
!("platform" in parsed) ||
typeof parsed.pid !== "number" ||
typeof parsed.hostname !== "string" ||
typeof parsed.createdAt !== "number" ||
typeof parsed.platform !== "string" ||
Number.isSafeInteger(parsed.pid) === false ||
parsed.pid < 1 ||
Number.isSafeInteger(parsed.createdAt) === false ||
parsed.createdAt < 1 ||
("uid" in parsed &&
parsed.uid !== undefined &&
(typeof parsed.uid !== "number" ||
Number.isSafeInteger(parsed.uid) === false)) ||
("sessionId" in parsed && typeof parsed.sessionId !== "string")) {
return undefined;
}
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- We just validated it
return parsed;
}
catch {
// Missing file, corrupt JSON, permission error — all treated as "no valid metadata"
return undefined;
}
}
/**
* Best-effort cleanup of orphaned temp files left by dead processes.
*
* Scans the parent directory for all temp files matching this lock's naming
* pattern (`{baseName}.tmp-{pid}-...`), parses the PID from each filename,
* and removes files whose PID is no longer alive. Files with unparseable
* PIDs are left untouched (conservative — don't delete what we can't verify).
*
* This is safe because the class is single-host-only (cross-host usage
* throws `IncompatibleHostnameMultiProcessMutexError`).
*/
#cleanupDeadProcessTempFiles() {
const parentDir = path.dirname(this.#lockFilePath);
const baseName = path.basename(this.#lockFilePath);
const prefix = `${baseName}.tmp-`;
try {
const entries = fs.readdirSync(parentDir);
for (const entry of entries) {
if (!entry.startsWith(prefix)) {
continue;
}
// Parse PID from filename: {baseName}.tmp-{pid}-{sessionId}-{ts}-{rand}
const afterPrefix = entry.slice(prefix.length);
const pidStr = afterPrefix.split("-")[0];
const pid = Number(pidStr);
if (!Number.isSafeInteger(pid) || pid < 1) {
// Can't verify liveness — leave file alone
continue;
}
if (this.#isProcessAlive(pid)) {
continue;
}
try {
fs.unlinkSync(path.join(parentDir, entry));
log(`Cleaned up orphaned temp file: ${entry}`);
}
catch {
// Best effort
}
}
}
catch {
// Best effort — parent directory may not be readable
}
}
}

@@ -138,0 +456,0 @@ /**

@@ -1,1 +0,1 @@

{"version":3,"file":"synchronization.js","sourceRoot":"","sources":["../../src/synchronization.ts"],"names":[],"mappings":"AAAA,4HAA4H;AAC5H,2FAA2F;AAC3F,mDAAmD;AACnD,0GAA0G;AAC1G,oFAAoF;AACpF,yGAAyG;AACzG,oJAAoJ;AACpJ,6GAA6G;AAE7G,OAAO,EAAE,MAAM,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EAAE;YAClD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE;gBACpB,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;YAC3B,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
{
"name": "@nomicfoundation/hardhat-utils",
"version": "3.0.6",
"version": "4.0.0",
"description": "Utilities for Hardhat and its plugins",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/nomicfoundation/hardhat/tree/v-next/v-next/hardhat-utils",

@@ -12,86 +12,3 @@ import {

export type TableRow = string[];
export interface TableDivider {
type: "divider";
}
export type TableItem = TableRow | TableDivider;
export const divider: TableDivider = { type: "divider" };
/**
* Formats an array of rows and dividers into a table string.
*
* @param items An array of table rows (string arrays) and dividers.
* Dividers are objects with type: "divider" and will be rendered as table dividers.
* @returns The formatted table as a string, ready to be rendered.
*
* @example
* ```ts
* formatTable([
* ["Name", "Age"],
* divider,
* ["Alice", "30"],
* ["Bob", "25"],
* divider,
* ["Average", "27.5"]
* ]);
*
* // =>
* // | Name | Age |
* // | ------- | ---- |
* // | Alice | 30 |
* // | Bob | 25 |
* // | ------- | ---- |
* // | Average | 27.5 |
* ```
*/
export function formatTable(items: TableItem[]): string {
const widths: number[] = [];
const dataRows: string[][] = [];
for (const item of items) {
if (Array.isArray(item)) {
dataRows.push([...item]);
}
}
// Calculate maximum width for each column
for (const row of dataRows) {
for (let i = 0; i < row.length; i++) {
while (i >= widths.length) {
widths.push(0);
}
widths[i] = Math.max(widths[i], getStringWidth(row[i]));
}
}
const dividerRow = widths.map((width) => "-".repeat(width));
const outputRows: string[][] = [];
for (const item of items) {
if (Array.isArray(item)) {
const row = [...item];
// Pad the row to match the number of columns
while (row.length < widths.length) {
row.push("");
}
outputRows.push(row);
} else {
outputRows.push([...dividerRow]);
}
}
outputRows.forEach((row) => {
for (let i = 0; i < row.length; i++) {
const displayWidth = getStringWidth(row[i]);
const actualLength = row[i].length;
// Adjust padding to account for difference between display width and actual length
row[i] = row[i].padEnd(widths[i] + actualLength - displayWidth);
}
});
return outputRows.map((row) => `| ${row.join(" | ")} |`).join("\n");
}
export interface TableTitleV2 {
export interface TableTitle {
type: "title";

@@ -101,3 +18,3 @@ text: string;

export interface TableSectionHeaderV2 {
export interface TableSectionHeader {
type: "section-header";

@@ -107,3 +24,3 @@ text: string;

export interface TableHeaderV2 {
export interface TableHeader {
type: "header";

@@ -113,3 +30,3 @@ cells: string[];

export interface TableRowV2 {
export interface TableRow {
type: "row";

@@ -119,7 +36,7 @@ cells: string[];

export type TableItemV2 =
| TableTitleV2
| TableSectionHeaderV2
| TableHeaderV2
| TableRowV2;
export type TableItem =
| TableTitle
| TableSectionHeader
| TableHeader
| TableRow;

@@ -143,3 +60,3 @@ /**

* ```ts
* formatTableV2([
* formatTable([
* { type: "title", text: "My Table" },

@@ -177,3 +94,3 @@ * { type: "section-header", text: "User Data" },

*/
export function formatTableV2(items: TableItemV2[]): string {
export function formatTable(items: TableItem[]): string {
if (items.length === 0) {

@@ -180,0 +97,0 @@ return "";

import { ensureDir } from "./fs.js";
import { generatePaths, HARDHAT_PACKAGE_NAME } from "./internal/global-dir.js";
// Internal override for testing purposes
let _cacheDirOverride: string | undefined;
/**
* Sets a mock cache directory for getCacheDir. This is intended for testing
* purposes only, to isolate tests from the real global cache.
*
* @param dir The directory path to use as the mock cache directory.
*/
export function setMockCacheDir(dir: string): void {
_cacheDirOverride = dir;
}
/**
* Resets the mock cache directory set by setMockCacheDir.
* Call this in test cleanup to restore normal behavior.
*/
export function resetMockCacheDir(): void {
_cacheDirOverride = undefined;
}
/**
* Returns the configuration directory path for a given package (defaults to "hardhat").

@@ -24,2 +45,6 @@ * Ensures that the directory exists before returning the path.

*
* For testing purposes, the cache directory can be overridden using
* setMockCacheDir(). This is intended to isolate tests from the real
* global cache.
*
* @param packageName The name of the package for which to generate paths. Defaults to "hardhat" if no package name is provided.

@@ -32,2 +57,8 @@ * @returns The path to the hardhat cache directory.

): Promise<string> {
// Allow override for testing purposes
if (_cacheDirOverride !== undefined) {
await ensureDir(_cacheDirOverride);
return _cacheDirOverride;
}
const { cache } = await generatePaths(packageName);

@@ -34,0 +65,0 @@ await ensureDir(cache);

@@ -1,2 +0,2 @@

import type { TableItemV2 } from "../format.js";
import type { TableItem } from "../format.js";

@@ -20,3 +20,3 @@ /**

*/
export function getColumnWidths(items: TableItemV2[]): number[] {
export function getColumnWidths(items: TableItem[]): number[] {
const columnWidths: number[] = [];

@@ -57,3 +57,3 @@

*/
export function getHeadingWidth(items: TableItemV2[]): number {
export function getHeadingWidth(items: TableItem[]): number {
let headingWidth = 0;

@@ -60,0 +60,0 @@ for (const item of items) {

@@ -5,2 +5,3 @@ import type { DispatcherOptions, RequestOptions } from "../request.js";

import crypto from "node:crypto";
import path from "node:path";

@@ -28,3 +29,3 @@

ext,
name: `tmp-${name}`,
name: `tmp-${name}-${crypto.randomBytes(8).toString("hex")}`,
});

@@ -31,0 +32,0 @@ }

import type EventEmitter from "node:events";
import type { FileHandle } from "node:fs/promises";
import type { ParsedUrlQueryInput } from "node:querystring";
import type UndiciT from "undici";
import fs from "node:fs";
import { open } from "node:fs/promises";
import querystring from "node:querystring";

@@ -15,3 +16,3 @@ import stream from "node:stream/promises";

} from "./errors/request.js";
import { move } from "./fs.js";
import { move, remove } from "./fs.js";
import {

@@ -221,2 +222,3 @@ generateTempFilePath,

let statusCode: number | undefined;
let tempFilePath: string | undefined;

@@ -226,3 +228,3 @@ try {

-- We need the full Dispatcher.ResponseData here for stream.pipeline,
but HttpResponse doesn’t expose the raw ReadableStream.
but HttpResponse doesn't expose the raw ReadableStream.
TODO: wrap undici's request so we can keep the public API

@@ -242,5 +244,18 @@ strictly typed without falling back to Undici types. */

const tempFilePath = await generateTempFilePath(destination);
const fileStream = fs.createWriteStream(tempFilePath);
await stream.pipeline(body, fileStream);
tempFilePath = await generateTempFilePath(destination);
let fileHandle: FileHandle | undefined;
try {
fileHandle = await open(tempFilePath, "w");
const fileStream = fileHandle.createWriteStream();
await stream.pipeline(body, fileStream);
} finally {
// NOTE: Historically, not closing the file handle caused issues on Windows,
// for example, when trying to move the file previously written to by this function
await fileHandle?.close();
}
await move(tempFilePath, destination);

@@ -250,2 +265,10 @@ } catch (e) {

if (tempFilePath !== undefined) {
try {
await remove(tempFilePath);
} catch {
// Best-effort: file may not exist or may have already been moved
}
}
handleError(e, url);

@@ -252,0 +275,0 @@

@@ -1,75 +0,314 @@

// Logic explanation: the fs.writeFile function, when used with the wx+ flag, performs an atomic operation to create a file.
// If multiple processes try to create the same file simultaneously, only one will succeed.
// This logic can be utilized to implement a mutex.
// ATTENTION: in the current implementation, there's still a risk of two processes running simultaneously.
// For example, if processA has locked the mutex and is running, processB will wait.
// During this wait, processB continuously checks the elapsed time since the mutex lock file was created.
// If an excessive amount of time has passed, processB will assume ownership of the mutex to prevent stale locks, even if processA is still running.
// As a result, two processes will be running simultaneously in what is theoretically a mutex-locked section.
import { randomUUID } from "node:crypto";
import * as fs from "node:fs";
import * as os from "node:os";
import * as path from "node:path";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import debug from "debug";
import { ensureNodeErrnoExceptionError } from "./error.js";
import { FileSystemAccessError } from "./errors/fs.js";
import { readUtf8File } from "./fs.js";
import { ensureError, ensureNodeErrnoExceptionError } from "./error.js";
import {
BaseMultiProcessMutexError,
IncompatibleHostnameMultiProcessMutexError,
IncompatiblePlatformMultiProcessMutexError,
IncompatibleUidMultiProcessMutexError,
InvalidMultiProcessMutexPathError,
MultiProcessMutexError,
MultiProcessMutexTimeoutError,
StaleMultiProcessMutexError,
} from "./errors/synchronization.js";
import { ensureDir } from "./fs.js";
import { sleep } from "./lang.js";
export {
IncompatibleHostnameMultiProcessMutexError,
IncompatibleMultiProcessMutexError,
IncompatiblePlatformMultiProcessMutexError,
IncompatibleUidMultiProcessMutexError,
InvalidMultiProcessMutexPathError,
MultiProcessMutexError,
MultiProcessMutexTimeoutError,
StaleMultiProcessMutexError,
} from "./errors/synchronization.js";
const log = debug("hardhat:util:multi-process-mutex");
const DEFAULT_MAX_MUTEX_LIFESPAN_IN_MS = 60000;
const MUTEX_LOOP_WAITING_TIME_IN_MS = 100;
const PROCESS_SESSION_ID = randomUUID();
const DEFAULT_TIMEOUT_MS = 60_000;
const DEFAULT_INITIAL_POLL_INTERVAL_MS = 5;
const MAX_POLL_INTERVAL_MS = 200;
/**
* Error codes indicating hard links are definitively unsupported on the
* target filesystem. These cause immediate failure rather than retries.
*/
const HARD_LINK_UNSUPPORTED_CODES = new Set(["EOPNOTSUPP", "ENOTSUP", "EXDEV"]);
interface LockMetadata {
pid: number;
hostname: string;
createdAt: number;
uid?: number;
platform: string;
sessionId: string;
}
type StalenessResult =
| { isStale: true; metadata: LockMetadata | undefined }
| { isStale: false };
type AcquireResult =
| { acquired: true }
| { acquired: false; reclaimedStaleLock: boolean };
/**
* A class that implements an inter-process mutex.
*
* This Mutex is implemented using hard-link-based atomic file creation. A
* temporary file containing JSON metadata (PID, hostname, platform, uid,
* session ID, and creation timestamp) is written first, then hard-linked to
* the lock path via `fs.linkSync`. `linkSync` fails atomically with `EEXIST`
* if the lock already exists, ensuring only one process can hold the lock at
* a time.
*
* Staleness is determined by PID liveness only — timestamps are stored for
* debugging purposes but are never used to determine staleness. This avoids the
* clock-skew and long-running-task problems that time-based staleness detection
* has (where a second process can break into a lock that's still legitimately
* held).
*
* Incompatible locks — those created by a different hostname, platform, or
* uid — are rejected immediately with specific subclasses of
* `IncompatibleMultiProcessMutexError`
* (`IncompatibleHostnameMultiProcessMutexError`,
* `IncompatiblePlatformMultiProcessMutexError`, or
* `IncompatibleUidMultiProcessMutexError`) because their PID liveness cannot
* be verified or their lock file cannot be removed. These must be removed
* manually.
*
* When the lock is held by a live process, the caller polls with exponential
* backoff (default: 5ms → 10ms → ... → 160ms → 200ms cap) until the lock is
* released or a timeout (default: 60s) is reached.
*
* If the filesystem does not support hard links (e.g., certain network
* filesystems), acquisition fails fast with a `MultiProcessMutexError` rather
* than degrading into timeout-based retries.
*
* ## Performance characteristics
*
* - **Uncontended acquisition:** One temp file write + one `linkSync` — takes
* less than 1ms on most systems.
* - **Stale lock recovery:** One `readFileSync` to read metadata, one
* `process.kill(pid, 0)` liveness check, and one `unlinkSync` to remove the
* stale lock file before retrying acquisition. The retry is immediate (no
* sleep), so recovery adds sub-millisecond overhead.
* - **Contended (live holder):** Polls with exponential backoff starting at
* 5ms and doubling each iteration until capped at 200ms. Worst-case latency
* after the lock is released is up to `MAX_POLL_INTERVAL_MS` (200ms).
* - **Release:** A single `unlinkSync` call.
*
* ## Limitations
*
* - **Polling-based:** There is no filesystem notification; callers discover
* that the lock is free only on the next poll, so there can be up to 200ms
* of wasted wait time after the lock is released.
* - **Not reentrant:** The same process (or even the same `MultiProcessMutex`
* instance) calling `use()` while already holding the lock will deadlock
* until the timeout fires.
* - **Single-host, single-user only:** Encountering a lock from a different
* hostname throws `IncompatibleHostnameMultiProcessMutexError`, a different
* platform throws `IncompatiblePlatformMultiProcessMutexError`, and a
* different uid throws `IncompatibleUidMultiProcessMutexError`. All extend
* `IncompatibleMultiProcessMutexError`. This means the lock is not safe to
* use on shared/networked filesystems (e.g., NFS) where multiple hosts or
* users may access the same path.
* - **Requires hard-link support:** The underlying filesystem must support
* `linkSync`. If hard links are unsupported, acquisition fails immediately
* with `MultiProcessMutexError`.
* - **PID recycling:** If a process dies and the OS reassigns its PID to a new
* unrelated process before the stale check runs, the lock is incorrectly
* considered live. This is extremely unlikely in practice due to the large
* PID space on modern systems.
* - **No fairness guarantee:** Multiple waiters polling concurrently have no
* guaranteed ordering — whichever one succeeds at `linkSync` first after the
* lock is released wins.
*/
export class MultiProcessMutex {
readonly #mutexFilePath: string;
readonly #mutexLifespanInMs: number;
readonly #lockFilePath: string;
readonly #timeout: number;
readonly #initialPollInterval: number;
constructor(mutexName: string, maxMutexLifespanInMs?: number) {
log(`Creating mutex with name '${mutexName}'`);
/**
* Creates an inter-process mutex given an absolute path.
*
* @param absolutePathToLock The absolute path of the mutex.
* @param timeout The max amount of time to spend trying to acquire the lock
* in milliseconds. Defaults to 60000.
* @param initialPollInterval The initial poll interval in milliseconds.
* Defaults to 5.
*/
constructor(
absolutePathToLock: string,
timeout?: number,
initialPollInterval?: number,
) {
if (!path.isAbsolute(absolutePathToLock)) {
throw new InvalidMultiProcessMutexPathError(absolutePathToLock);
}
this.#lockFilePath = absolutePathToLock;
this.#mutexFilePath = path.join(os.tmpdir(), `${mutexName}.txt`);
this.#mutexLifespanInMs =
maxMutexLifespanInMs ?? DEFAULT_MAX_MUTEX_LIFESPAN_IN_MS;
this.#timeout = timeout ?? DEFAULT_TIMEOUT_MS;
this.#initialPollInterval =
initialPollInterval ?? DEFAULT_INITIAL_POLL_INTERVAL_MS;
}
/**
* Runs the function f while holding the mutex, returning its result.
*
* @param f The function to run.
* @returns The result of the function.
*/
public async use<T>(f: () => Promise<T>): Promise<T> {
log(`Starting mutex process with mutex file '${this.#mutexFilePath}'`);
const release = await this.acquire();
try {
return await f();
} finally {
await release();
}
}
/**
* Acquires the mutex, returning an async function to release it.
* The function MUST be called after using the mutex.
*
* If this function throws, no cleanup is necessary — the lock was never
* acquired.
*
* @returns The mutex's release function.
*/
public async acquire(): Promise<() => Promise<void>> {
log(`Starting mutex process with lock file '${this.#lockFilePath}'`);
try {
await this.#acquireLock();
} catch (e) {
ensureError(e);
if (e instanceof BaseMultiProcessMutexError) {
throw e;
}
throw new MultiProcessMutexError(this.#lockFilePath, e);
}
let released = false;
return async () => {
if (released) {
return;
}
this.#releaseLock();
released = true;
};
}
async #acquireLock(): Promise<void> {
const startTime = Date.now();
let pollInterval = this.#initialPollInterval;
await ensureDir(path.dirname(this.#lockFilePath));
while (true) {
if (await this.#tryToAcquireMutex()) {
// Mutex has been acquired
return this.#executeFunctionAndReleaseMutex(f);
const result = this.#tryAcquire();
if (result.acquired) {
return;
}
// Mutex not acquired
if (this.#isMutexFileTooOld()) {
// If the mutex file is too old, it likely indicates a stale lock, so the file should be removed
log(
`Current mutex file is too old, removing it at path '${this.#mutexFilePath}'`,
// Check timeout
const elapsed = Date.now() - startTime;
if (elapsed >= this.#timeout) {
throw new MultiProcessMutexTimeoutError(
this.#lockFilePath,
this.#timeout,
);
}
this.#deleteMutexFile();
} else if (await this.#isMutexProcessOwnerDead()) {
log(
`The process owning the mutex file no longer exists. Removing mutex file at '${this.#mutexFilePath}'.`,
);
// Skip sleep after reclaiming a stale lock — retry immediately
if (result.reclaimedStaleLock) {
continue;
}
this.#deleteMutexFile();
} else {
// wait
await sleep(MUTEX_LOOP_WAITING_TIME_IN_MS / 1000);
// Wait with exponential backoff
log(`Lock at ${this.#lockFilePath} is busy, waiting ${pollInterval}ms`);
await sleep(pollInterval / 1000);
// Exponential backoff, capped
pollInterval = Math.min(pollInterval * 2, MAX_POLL_INTERVAL_MS);
}
}
#releaseLock(): void {
try {
fs.unlinkSync(this.#lockFilePath);
log(`Released lock at ${this.#lockFilePath}`);
} catch (e) {
ensureNodeErrnoExceptionError(e);
if (e.code === "ENOENT") {
log(`Lock at ${this.#lockFilePath} already removed`);
return;
}
throw new MultiProcessMutexError(this.#lockFilePath, e);
}
}
async #tryToAcquireMutex() {
#tryAcquire(): AcquireResult {
const lockPath = this.#lockFilePath;
// Fast path: if the lock file already exists, check staleness directly
// without creating temp files. This is both an optimization for the
// common contended case and is required for correct behavior when the
// parent directory is read-only (stale locks can still be detected via
// readFileSync even when file creation in the directory is blocked).
//
// Note: handleExistingLock() must be called outside the try/catch so
// that errors like StaleMultiProcessMutexError propagate correctly.
let lockExists = false;
try {
// Create a file only if it does not exist
fs.writeFileSync(this.#mutexFilePath, process.pid.toString(), {
flag: "wx+",
});
fs.accessSync(lockPath, fs.constants.F_OK);
lockExists = true;
} catch {
// Lock doesn't exist (or can't be checked) — proceed to acquire
}
return true;
if (lockExists) {
return this.#handleExistingLock();
}
// Lock doesn't appear to exist — try to acquire via temp file + hard link
const metadata = this.#buildMetadata();
const contents = JSON.stringify(metadata, null, 2);
const randomSuffix = Math.random().toString(16).slice(2);
const tempPath = `${lockPath}.tmp-${process.pid}-${PROCESS_SESSION_ID}-${Date.now()}-${randomSuffix}`;
let tempFd: number | undefined;
try {
// Create temp file with exclusive flag to prevent collisions
tempFd = fs.openSync(tempPath, "wx");
fs.writeFileSync(tempFd, contents, "utf8");
fs.closeSync(tempFd);
tempFd = undefined;
// Attempt atomic hard link to the lock path
fs.linkSync(tempPath, lockPath);
log(`Acquired lock at ${lockPath}`);
// Best-effort cleanup of temp files left by dead processes.
// We hold the lock, so only one process runs this at a time.
this.#cleanupDeadProcessTempFiles();
return { acquired: true };
} catch (e) {

@@ -79,29 +318,117 @@ ensureNodeErrnoExceptionError(e);

if (e.code === "EEXIST") {
// File already exists, so the mutex is already acquired
return false;
// Lock was created between our accessSync and linkSync
return this.#handleExistingLock();
}
throw new FileSystemAccessError(e.message, e);
if (e.code === "ENOENT") {
// Parent directory doesn't exist. Create it and retry.
const parentDir = path.dirname(lockPath);
log(`Parent directory ${parentDir} does not exist, creating it`);
fs.mkdirSync(parentDir, { recursive: true });
return { acquired: false, reclaimedStaleLock: false };
}
// Hard links definitively unsupported — fail fast
if (HARD_LINK_UNSUPPORTED_CODES.has(e.code ?? "")) {
throw new MultiProcessMutexError(lockPath, e);
}
// We retry on permission errors, as this is a common transient failure
// on Windows.
if (e.code === "EPERM" || e.code === "EACCES") {
log("Failed to acquire lock, retrying due to permission error");
return { acquired: false, reclaimedStaleLock: false };
}
// Any other error (ENAMETOOLONG, ENOSPC, etc.)
throw new MultiProcessMutexError(lockPath, e);
} finally {
// Close fd if still open (write or close failed)
if (tempFd !== undefined) {
try {
fs.closeSync(tempFd);
} catch {
// Best effort
}
}
// Always clean up the temp file
try {
fs.unlinkSync(tempPath);
} catch {
// Best effort — file may not exist if openSync failed
}
}
}
async #executeFunctionAndReleaseMutex<T>(f: () => Promise<T>): Promise<T> {
log(`Mutex acquired at path '${this.#mutexFilePath}'`);
#handleExistingLock(): AcquireResult {
const staleness = this.#checkStaleness();
try {
return await f();
} finally {
// Release the mutex
// Note: if a process dies, its `finally` block never executes, and the process hangs indefinitely since no response is received.
// To handle this, we use the function `isMutexProcessOwnerDead`.
log(`Mutex released at path '${this.#mutexFilePath}'`);
this.#deleteMutexFile();
log(`Mutex released at path '${this.#mutexFilePath}'`);
if (staleness.isStale) {
const reclaimed = this.#tryUnlockingStaleLock(staleness.metadata);
return { acquired: false, reclaimedStaleLock: reclaimed };
}
return { acquired: false, reclaimedStaleLock: false };
}
#isMutexFileTooOld(): boolean {
let fileStat;
#checkStaleness(): StalenessResult {
const lockPath = this.#lockFilePath;
const metadata = this.#readMetadata();
if (metadata === undefined) {
log(
`Lock at ${lockPath} has missing/corrupt metadata, treating as stale`,
);
return { isStale: true, metadata: undefined };
}
// Different hostname — can't verify PID remotely
if (metadata.hostname !== os.hostname()) {
throw new IncompatibleHostnameMultiProcessMutexError(
lockPath,
metadata.hostname,
os.hostname(),
);
}
// Different platform — can't verify PID across platforms
if (metadata.platform !== process.platform) {
throw new IncompatiblePlatformMultiProcessMutexError(
lockPath,
metadata.platform,
process.platform,
);
}
// Different uid — can't remove a lock owned by another user
const currentUid = process.getuid?.();
if (
metadata.uid !== undefined &&
currentUid !== undefined &&
metadata.uid !== currentUid
) {
throw new IncompatibleUidMultiProcessMutexError(
lockPath,
metadata.uid,
currentUid,
);
}
// PID liveness check
if (!this.#isProcessAlive(metadata.pid)) {
log(`Lock at ${lockPath} owned by dead process PID=${metadata.pid}`);
return { isStale: true, metadata };
}
// Process is alive, lock is not stale
return { isStale: false };
}
#tryUnlockingStaleLock(metadata: LockMetadata | undefined): boolean {
const lockPath = this.#lockFilePath;
try {
fileStat = fs.statSync(this.#mutexFilePath);
fs.unlinkSync(lockPath);
log(`Removed stale lock at ${lockPath}`);
} catch (e) {

@@ -111,54 +438,136 @@ ensureNodeErrnoExceptionError(e);

if (e.code === "ENOENT") {
// The file might have been deleted by another process while this function was trying to access it.
return false;
// Already removed by another process — safe to retry acquisition
log(`Stale lock at ${lockPath} already removed by another process`);
return true;
}
throw new FileSystemAccessError(e.message, e);
if (e.code === "EACCES" || e.code === "EPERM" || e.code === "EBUSY") {
throw new StaleMultiProcessMutexError(lockPath, metadata?.uid, e);
}
throw new MultiProcessMutexError(lockPath, e);
}
const now = new Date();
const fileDate = new Date(fileStat.ctime);
const diff = now.getTime() - fileDate.getTime();
// Best-effort cleanup of orphaned temp files from dead processes
this.#cleanupDeadProcessTempFiles();
return diff > this.#mutexLifespanInMs;
return true;
}
#deleteMutexFile() {
/**
* Checks if a process with the given PID is alive using signal 0, which is
* a platform-independent existence check supported on both POSIX and Windows.
*
* `ESRCH` means the process doesn't exist. `EPERM` means it exists but
* belongs to another user — still alive.
*/
#isProcessAlive(pid: number): boolean {
try {
log(`Deleting mutex file at path '${this.#mutexFilePath}'`);
fs.unlinkSync(this.#mutexFilePath);
process.kill(pid, 0);
return true;
} catch (e) {
ensureNodeErrnoExceptionError(e);
if (e.code === "ENOENT") {
// The file might have been deleted by another process while this function was trying to access it.
return;
if (e.code === "ESRCH") {
return false; // Process does not exist
}
throw new FileSystemAccessError(e.message, e);
// EPERM means the process exists but we don't have permission to signal it
return true;
}
}
async #isMutexProcessOwnerDead(): Promise<boolean> {
let mutexPid: string;
#buildMetadata(): LockMetadata {
return {
pid: process.pid,
hostname: os.hostname(),
createdAt: Date.now(),
...(process.getuid !== undefined ? { uid: process.getuid() } : {}),
platform: process.platform,
sessionId: PROCESS_SESSION_ID,
};
}
#readMetadata(): LockMetadata | undefined {
try {
// If the file doesn't exist, it means the owning process deleted it
mutexPid = await readUtf8File(this.#mutexFilePath);
} catch (_e) {
return false;
const content = fs.readFileSync(this.#lockFilePath, "utf8");
const parsed: unknown = JSON.parse(content);
if (
typeof parsed !== "object" ||
parsed === null ||
!("pid" in parsed) ||
!("hostname" in parsed) ||
!("createdAt" in parsed) ||
!("platform" in parsed) ||
typeof parsed.pid !== "number" ||
typeof parsed.hostname !== "string" ||
typeof parsed.createdAt !== "number" ||
typeof parsed.platform !== "string" ||
Number.isSafeInteger(parsed.pid) === false ||
parsed.pid < 1 ||
Number.isSafeInteger(parsed.createdAt) === false ||
parsed.createdAt < 1 ||
("uid" in parsed &&
parsed.uid !== undefined &&
(typeof parsed.uid !== "number" ||
Number.isSafeInteger(parsed.uid) === false)) ||
("sessionId" in parsed && typeof parsed.sessionId !== "string")
) {
return undefined;
}
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- We just validated it
return parsed as LockMetadata;
} catch {
// Missing file, corrupt JSON, permission error — all treated as "no valid metadata"
return undefined;
}
}
/**
* Best-effort cleanup of orphaned temp files left by dead processes.
*
* Scans the parent directory for all temp files matching this lock's naming
* pattern (`{baseName}.tmp-{pid}-...`), parses the PID from each filename,
* and removes files whose PID is no longer alive. Files with unparseable
* PIDs are left untouched (conservative — don't delete what we can't verify).
*
* This is safe because the class is single-host-only (cross-host usage
* throws `IncompatibleHostnameMultiProcessMutexError`).
*/
#cleanupDeadProcessTempFiles(): void {
const parentDir = path.dirname(this.#lockFilePath);
const baseName = path.basename(this.#lockFilePath);
const prefix = `${baseName}.tmp-`;
try {
process.kill(parseInt(mutexPid, 10), 0);
} catch (e) {
ensureNodeErrnoExceptionError(e);
const entries = fs.readdirSync(parentDir);
for (const entry of entries) {
if (!entry.startsWith(prefix)) {
continue;
}
if (e.code === "ESRCH") {
// The process owning the mutex no longer exists
return true;
// Parse PID from filename: {baseName}.tmp-{pid}-{sessionId}-{ts}-{rand}
const afterPrefix = entry.slice(prefix.length);
const pidStr = afterPrefix.split("-")[0];
const pid = Number(pidStr);
if (!Number.isSafeInteger(pid) || pid < 1) {
// Can't verify liveness — leave file alone
continue;
}
if (this.#isProcessAlive(pid)) {
continue;
}
try {
fs.unlinkSync(path.join(parentDir, entry));
log(`Cleaned up orphaned temp file: ${entry}`);
} catch {
// Best effort
}
}
} catch {
// Best effort — parent directory may not be readable
}
return false;
}

@@ -165,0 +574,0 @@ }