mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Cleanup
This commit is contained in:
parent
1cf8fd1241
commit
d064d46668
32 changed files with 429 additions and 400 deletions
|
|
@ -3,7 +3,7 @@ import path from "path";
|
|||
import os from "os";
|
||||
import { ui } from "../environment/userInteraction.js";
|
||||
import { getEcoSystem } from "./settings.js";
|
||||
import { getSafeChainDir } from "./environmentVariables.js";
|
||||
import { getSafeChainBaseDir } from "./safeChainDir.js";
|
||||
|
||||
/**
|
||||
* @typedef {Object} SafeChainConfig
|
||||
|
|
@ -305,7 +305,7 @@ function getConfigFilePath() {
|
|||
* @returns {string}
|
||||
*/
|
||||
export function getSafeChainDirectory() {
|
||||
const safeChainDir = getSafeChainDir() ?? path.join(os.homedir(), ".safe-chain");
|
||||
const safeChainDir = getSafeChainBaseDir();
|
||||
|
||||
if (!fs.existsSync(safeChainDir)) {
|
||||
fs.mkdirSync(safeChainDir, { recursive: true });
|
||||
|
|
|
|||
|
|
@ -55,14 +55,3 @@ 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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,30 +0,0 @@
|
|||
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");
|
||||
});
|
||||
});
|
||||
10
packages/safe-chain/src/config/safeChainDir.js
Normal file
10
packages/safe-chain/src/config/safeChainDir.js
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import os from "os";
|
||||
import path from "path";
|
||||
import { getInstalledSafeChainDir } from "../installLocation.js";
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
export function getSafeChainBaseDir() {
|
||||
return getInstalledSafeChainDir() ?? path.join(os.homedir(), ".safe-chain");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue