mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Add env var support for home dir
This commit is contained in:
parent
698a12082d
commit
a0fb8d6b3d
4 changed files with 125 additions and 3 deletions
|
|
@ -55,3 +55,14 @@ export function getMinimumPackageAgeExclusions() {
|
|||
export function getMalwareListBaseUrl() {
|
||||
return process.env.SAFE_CHAIN_MALWARE_LIST_BASE_URL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the safe-chain base directory from environment variable.
|
||||
* When set, all safe-chain data (bin, shims, scripts) will be placed under this directory
|
||||
* instead of the default ~/.safe-chain, enabling system-wide installations.
|
||||
* Example: "/usr/local/.safe-chain"
|
||||
* @returns {string | undefined}
|
||||
*/
|
||||
export function getSafeChainDir() {
|
||||
return process.env.SAFE_CHAIN_DIR;
|
||||
}
|
||||
|
|
|
|||
30
packages/safe-chain/src/config/environmentVariables.spec.js
Normal file
30
packages/safe-chain/src/config/environmentVariables.spec.js
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import { describe, it, beforeEach, afterEach } from "node:test";
|
||||
import assert from "node:assert";
|
||||
|
||||
const { getSafeChainDir } = await import("./environmentVariables.js");
|
||||
|
||||
describe("getSafeChainDir", () => {
|
||||
let original;
|
||||
|
||||
beforeEach(() => {
|
||||
original = process.env.SAFE_CHAIN_DIR;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
if (original !== undefined) {
|
||||
process.env.SAFE_CHAIN_DIR = original;
|
||||
} else {
|
||||
delete process.env.SAFE_CHAIN_DIR;
|
||||
}
|
||||
});
|
||||
|
||||
it("returns undefined when SAFE_CHAIN_DIR is not set", () => {
|
||||
delete process.env.SAFE_CHAIN_DIR;
|
||||
assert.strictEqual(getSafeChainDir(), undefined);
|
||||
});
|
||||
|
||||
it("returns the value of SAFE_CHAIN_DIR when set", () => {
|
||||
process.env.SAFE_CHAIN_DIR = "/usr/local/.safe-chain";
|
||||
assert.strictEqual(getSafeChainDir(), "/usr/local/.safe-chain");
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue