mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Some cleanup
This commit is contained in:
parent
32c95dbb9d
commit
6628e1d4fd
4 changed files with 14 additions and 12 deletions
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
# Function to remove shim from PATH (POSIX-compliant)
|
# Function to remove shim from PATH (POSIX-compliant)
|
||||||
remove_shim_from_path() {
|
remove_shim_from_path() {
|
||||||
_safe_chain_shims="${SAFE_CHAIN_DIR:-$HOME/.safe-chain}/shims"
|
_safe_chain_shims="{{SHIMS_DIR}}"
|
||||||
echo "$PATH" | sed "s|${_safe_chain_shims}:||g"
|
echo "$PATH" | sed "s|${_safe_chain_shims}:||g"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,7 @@ REM Generated wrapper for {{PACKAGE_MANAGER}} by safe-chain
|
||||||
REM This wrapper intercepts {{PACKAGE_MANAGER}} calls for non-interactive environments
|
REM This wrapper intercepts {{PACKAGE_MANAGER}} calls for non-interactive environments
|
||||||
|
|
||||||
REM Remove shim directory from PATH to prevent infinite loops
|
REM Remove shim directory from PATH to prevent infinite loops
|
||||||
if defined SAFE_CHAIN_DIR (
|
set "SHIM_DIR={{SHIMS_DIR}}"
|
||||||
set "SHIM_DIR=%SAFE_CHAIN_DIR%\shims"
|
|
||||||
) else (
|
|
||||||
set "SHIM_DIR=%USERPROFILE%\.safe-chain\shims"
|
|
||||||
)
|
|
||||||
call set "CLEAN_PATH=%%PATH:%SHIM_DIR%;=%%"
|
call set "CLEAN_PATH=%%PATH:%SHIM_DIR%;=%%"
|
||||||
|
|
||||||
REM Check if aikido command is available with clean PATH
|
REM Check if aikido command is available with clean PATH
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,8 @@ function createUnixShims(shimsDir) {
|
||||||
for (const toolInfo of getToolsToSetup()) {
|
for (const toolInfo of getToolsToSetup()) {
|
||||||
const shimContent = template
|
const shimContent = template
|
||||||
.replaceAll("{{PACKAGE_MANAGER}}", toolInfo.tool)
|
.replaceAll("{{PACKAGE_MANAGER}}", toolInfo.tool)
|
||||||
.replaceAll("{{AIKIDO_COMMAND}}", toolInfo.aikidoCommand);
|
.replaceAll("{{AIKIDO_COMMAND}}", toolInfo.aikidoCommand)
|
||||||
|
.replaceAll("{{SHIMS_DIR}}", shimsDir);
|
||||||
|
|
||||||
const shimPath = path.join(shimsDir, toolInfo.tool);
|
const shimPath = path.join(shimsDir, toolInfo.tool);
|
||||||
fs.writeFileSync(shimPath, shimContent, "utf-8");
|
fs.writeFileSync(shimPath, shimContent, "utf-8");
|
||||||
|
|
@ -108,7 +109,8 @@ function createWindowsShims(shimsDir) {
|
||||||
for (const toolInfo of getToolsToSetup()) {
|
for (const toolInfo of getToolsToSetup()) {
|
||||||
const shimContent = template
|
const shimContent = template
|
||||||
.replaceAll("{{PACKAGE_MANAGER}}", toolInfo.tool)
|
.replaceAll("{{PACKAGE_MANAGER}}", toolInfo.tool)
|
||||||
.replaceAll("{{AIKIDO_COMMAND}}", toolInfo.aikidoCommand);
|
.replaceAll("{{AIKIDO_COMMAND}}", toolInfo.aikidoCommand)
|
||||||
|
.replaceAll("{{SHIMS_DIR}}", shimsDir);
|
||||||
|
|
||||||
const shimPath = `${shimsDir}/${toolInfo.tool}.cmd`;
|
const shimPath = `${shimsDir}/${toolInfo.tool}.cmd`;
|
||||||
fs.writeFileSync(shimPath, shimContent, "utf-8");
|
fs.writeFileSync(shimPath, shimContent, "utf-8");
|
||||||
|
|
|
||||||
|
|
@ -22,12 +22,12 @@ describe("Setup CI shell integration", () => {
|
||||||
fs.mkdirSync(path.join(mockTemplateDir, "path-wrappers", "templates"), { recursive: true });
|
fs.mkdirSync(path.join(mockTemplateDir, "path-wrappers", "templates"), { recursive: true });
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
path.join(mockTemplateDir, "path-wrappers", "templates", "unix-wrapper.template.sh"),
|
path.join(mockTemplateDir, "path-wrappers", "templates", "unix-wrapper.template.sh"),
|
||||||
"#!/bin/bash\n# Template for {{PACKAGE_MANAGER}}\nexec {{AIKIDO_COMMAND}} \"$@\"\n",
|
"#!/bin/bash\n# Template for {{PACKAGE_MANAGER}}\nSHIM_DIR=\"{{SHIMS_DIR}}\"\nexec {{AIKIDO_COMMAND}} \"$@\"\n",
|
||||||
"utf-8"
|
"utf-8"
|
||||||
);
|
);
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
path.join(mockTemplateDir, "path-wrappers", "templates", "windows-wrapper.template.cmd"),
|
path.join(mockTemplateDir, "path-wrappers", "templates", "windows-wrapper.template.cmd"),
|
||||||
"@echo off\nif defined SAFE_CHAIN_DIR (\n set \"SHIM_DIR=%SAFE_CHAIN_DIR%\\shims\"\n) else (\n set \"SHIM_DIR=%USERPROFILE%\\.safe-chain\\shims\"\n)\n{{AIKIDO_COMMAND}} %*\n",
|
"@echo off\nset \"SHIM_DIR={{SHIMS_DIR}}\"\n{{AIKIDO_COMMAND}} %*\n",
|
||||||
"utf-8"
|
"utf-8"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -120,6 +120,10 @@ describe("Setup CI shell integration", () => {
|
||||||
const npmShimContent = fs.readFileSync(npmShimPath, "utf-8");
|
const npmShimContent = fs.readFileSync(npmShimPath, "utf-8");
|
||||||
assert.ok(npmShimContent.includes("aikido-npm"), "npm shim should contain aikido-npm");
|
assert.ok(npmShimContent.includes("aikido-npm"), "npm shim should contain aikido-npm");
|
||||||
assert.ok(npmShimContent.includes("#!/bin/bash"), "npm shim should have bash shebang");
|
assert.ok(npmShimContent.includes("#!/bin/bash"), "npm shim should have bash shebang");
|
||||||
|
assert.ok(
|
||||||
|
npmShimContent.includes(`SHIM_DIR="${mockShimsDir}"`),
|
||||||
|
"npm shim should embed the generated shims directory",
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should create Windows .cmd shims on win32 platform", async () => {
|
it("should create Windows .cmd shims on win32 platform", async () => {
|
||||||
|
|
@ -144,8 +148,8 @@ describe("Setup CI shell integration", () => {
|
||||||
assert.ok(npmShimContent.includes("@echo off"), "npm.cmd should have Windows batch header");
|
assert.ok(npmShimContent.includes("@echo off"), "npm.cmd should have Windows batch header");
|
||||||
assert.ok(npmShimContent.includes("%*"), "npm.cmd should use Windows argument passing");
|
assert.ok(npmShimContent.includes("%*"), "npm.cmd should use Windows argument passing");
|
||||||
assert.ok(
|
assert.ok(
|
||||||
npmShimContent.includes("if defined SAFE_CHAIN_DIR"),
|
npmShimContent.includes(`set "SHIM_DIR=${mockShimsDir}"`),
|
||||||
"npm.cmd should honor SAFE_CHAIN_DIR when removing shim dir from PATH",
|
"npm.cmd should embed the generated shims directory",
|
||||||
);
|
);
|
||||||
|
|
||||||
// Verify Unix shims were NOT created
|
// Verify Unix shims were NOT created
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue