From 6628e1d4fd30eea169dece4479458fd6ac25295b Mon Sep 17 00:00:00 2001 From: Reinier Criel Date: Fri, 10 Apr 2026 14:57:45 -0700 Subject: [PATCH] Some cleanup --- .../path-wrappers/templates/unix-wrapper.template.sh | 2 +- .../templates/windows-wrapper.template.cmd | 6 +----- .../safe-chain/src/shell-integration/setup-ci.js | 6 ++++-- .../src/shell-integration/setup-ci.spec.js | 12 ++++++++---- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/packages/safe-chain/src/shell-integration/path-wrappers/templates/unix-wrapper.template.sh b/packages/safe-chain/src/shell-integration/path-wrappers/templates/unix-wrapper.template.sh index 94ed364..5635b1a 100644 --- a/packages/safe-chain/src/shell-integration/path-wrappers/templates/unix-wrapper.template.sh +++ b/packages/safe-chain/src/shell-integration/path-wrappers/templates/unix-wrapper.template.sh @@ -4,7 +4,7 @@ # Function to remove shim from PATH (POSIX-compliant) 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" } diff --git a/packages/safe-chain/src/shell-integration/path-wrappers/templates/windows-wrapper.template.cmd b/packages/safe-chain/src/shell-integration/path-wrappers/templates/windows-wrapper.template.cmd index 959b700..89f538f 100644 --- a/packages/safe-chain/src/shell-integration/path-wrappers/templates/windows-wrapper.template.cmd +++ b/packages/safe-chain/src/shell-integration/path-wrappers/templates/windows-wrapper.template.cmd @@ -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 Remove shim directory from PATH to prevent infinite loops -if defined SAFE_CHAIN_DIR ( - set "SHIM_DIR=%SAFE_CHAIN_DIR%\shims" -) else ( - set "SHIM_DIR=%USERPROFILE%\.safe-chain\shims" -) +set "SHIM_DIR={{SHIMS_DIR}}" call set "CLEAN_PATH=%%PATH:%SHIM_DIR%;=%%" REM Check if aikido command is available with clean PATH diff --git a/packages/safe-chain/src/shell-integration/setup-ci.js b/packages/safe-chain/src/shell-integration/setup-ci.js index 1986bba..0dc32cf 100644 --- a/packages/safe-chain/src/shell-integration/setup-ci.js +++ b/packages/safe-chain/src/shell-integration/setup-ci.js @@ -69,7 +69,8 @@ function createUnixShims(shimsDir) { for (const toolInfo of getToolsToSetup()) { const shimContent = template .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); fs.writeFileSync(shimPath, shimContent, "utf-8"); @@ -108,7 +109,8 @@ function createWindowsShims(shimsDir) { for (const toolInfo of getToolsToSetup()) { const shimContent = template .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`; fs.writeFileSync(shimPath, shimContent, "utf-8"); diff --git a/packages/safe-chain/src/shell-integration/setup-ci.spec.js b/packages/safe-chain/src/shell-integration/setup-ci.spec.js index 1156173..7d092ab 100644 --- a/packages/safe-chain/src/shell-integration/setup-ci.spec.js +++ b/packages/safe-chain/src/shell-integration/setup-ci.spec.js @@ -22,12 +22,12 @@ describe("Setup CI shell integration", () => { fs.mkdirSync(path.join(mockTemplateDir, "path-wrappers", "templates"), { recursive: true }); fs.writeFileSync( 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" ); fs.writeFileSync( 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" ); @@ -120,6 +120,10 @@ describe("Setup CI shell integration", () => { const npmShimContent = fs.readFileSync(npmShimPath, "utf-8"); 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(`SHIM_DIR="${mockShimsDir}"`), + "npm shim should embed the generated shims directory", + ); }); 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("%*"), "npm.cmd should use Windows argument passing"); assert.ok( - npmShimContent.includes("if defined SAFE_CHAIN_DIR"), - "npm.cmd should honor SAFE_CHAIN_DIR when removing shim dir from PATH", + npmShimContent.includes(`set "SHIM_DIR=${mockShimsDir}"`), + "npm.cmd should embed the generated shims directory", ); // Verify Unix shims were NOT created