-
-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "chore: v1.15.1 release (#6379)"
This reverts commit 1857a49.
- Loading branch information
Showing
29 changed files
with
176 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,37 @@ | ||
import {lockSync, unlockSync} from "proper-lockfile"; | ||
export type Lockfile = { | ||
lockSync(path: string): void; | ||
unlockSync(path: string): void; | ||
}; | ||
|
||
const lockFile: Lockfile = (await import("lockfile")) as Lockfile; | ||
|
||
function getLockFilepath(filepath: string): string { | ||
return `${filepath}.lock`; | ||
} | ||
|
||
/** | ||
* When lockfile is imported, it registers listeners to process | ||
* Since it's only used by the validator client, require lazily to not pollute | ||
* beacon_node client context | ||
*/ | ||
function getLockFile(): Lockfile { | ||
return lockFile; | ||
} | ||
|
||
/** | ||
* Creates a .lock file for `filepath`, argument passed must not be the lock path | ||
* @param filepath File to lock, i.e. `keystore_0001.json` | ||
*/ | ||
export function lockFilepath(filepath: string): void { | ||
try { | ||
lockSync(filepath, { | ||
// Allows to lock files that do not exist | ||
realpath: false, | ||
}); | ||
} catch (e) { | ||
if (isLockfileError(e) && e.code === "ELOCKED") { | ||
e.message = `${filepath} is already in use by another process`; | ||
} | ||
throw e; | ||
} | ||
getLockFile().lockSync(getLockFilepath(filepath)); | ||
} | ||
|
||
/** | ||
* Deletes a .lock file for `filepath`, argument passed must not be the lock path | ||
* @param filepath File to unlock, i.e. `keystore_0001.json` | ||
*/ | ||
export function unlockFilepath(filepath: string): void { | ||
try { | ||
unlockSync(filepath, { | ||
// Allows to unlock files that do not exist | ||
realpath: false, | ||
}); | ||
} catch (e) { | ||
if (isLockfileError(e) && e.code === "ENOTACQUIRED") { | ||
// Do not throw if the lock file is already deleted | ||
return; | ||
} | ||
throw e; | ||
} | ||
} | ||
|
||
// https://github.com/moxystudio/node-proper-lockfile/blob/9f8c303c91998e8404a911dc11c54029812bca69/lib/lockfile.js#L53 | ||
export type LockfileError = Error & {code: "ELOCKED" | "ENOTACQUIRED"}; | ||
|
||
function isLockfileError(e: unknown): e is LockfileError { | ||
return e instanceof Error && (e as LockfileError).code !== undefined; | ||
// Does not throw if the lock file is already deleted | ||
// https://github.com/npm/lockfile/blob/6590779867ee9bdc5dbebddc962640759892bb91/lockfile.js#L68 | ||
getLockFile().unlockSync(getLockFilepath(filepath)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.