Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document why repoDirectory is using XDG_STATE_HOME #8

Merged
merged 3 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 0 additions & 41 deletions bin/index.js

This file was deleted.

1 change: 0 additions & 1 deletion bin/localnet.d.ts

This file was deleted.

143 changes: 0 additions & 143 deletions bin/localnet.js

This file was deleted.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions src/localnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,35 @@ function runCommand(command: string, options?: ExecSyncOptions): string {
return execSync(command, unifiedOptions).toString();
}

/**
* Returns the path where the `zksync-cli/local-setup` repository, used
* internally to manage localnet deployments, should be located.
*
* **Why follow the XDG Base Directory Specification?**
*
* This function follows the XDG Base Directory Specification
* (https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html)
* to determine the parent directory location:
*
* The XDG Base Directory Specification is widely accepted as a standard.
* The decision to place the files under `$XDG_STATE_HOME` is based on considering the
* presence or absence of this repository as part of the CLI tool's state.
*
* Alternative locations within the XDG Base Directory Specification were
* considered and ruled out for the following reasons:
*
* - `$XDG_DATA_HOME` was not chosen because these files aren't user-specific
* data files.
*
* - `$XDG_CACHE_HOME` was not chosen because these files aren't considered
* non-essential cached data files.
*
* @returns {string} The path where the `zksync-cli/local-setup` repository should be
* placed.
*/
function repoDirectory(): string {
// From the XDG Base Directory Specification:
// `$XDG_STATE_HOME` defines the base directory relative to which user-specific state files should be stored. If `$XDG_STATE_HOME` is either not set or empty, a default equal to `$HOME/.local/state` should be used.
const xdgStateHome = process.env.XDG_STATE_HOME || path.join(os.homedir(), ".local/state");
return path.join(xdgStateHome, "zksync-cli/local-setup");
}
Expand Down