@aikidosec/safe-chain 1.1.9 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +117 -51
- package/bin/aikido-bun.js +4 -2
- package/bin/aikido-bunx.js +4 -2
- package/bin/aikido-npm.js +4 -2
- package/bin/aikido-npx.js +4 -2
- package/bin/aikido-pip.js +5 -3
- package/bin/aikido-pip3.js +5 -3
- package/bin/aikido-pnpm.js +4 -2
- package/bin/aikido-pnpx.js +4 -2
- package/bin/aikido-python.js +15 -13
- package/bin/aikido-python3.js +15 -13
- package/bin/aikido-uv.js +16 -0
- package/bin/aikido-yarn.js +4 -2
- package/bin/safe-chain.js +106 -10
- package/docs/banner.svg +151 -0
- package/docs/npm-to-binary-migration.md +89 -0
- package/package.json +10 -9
- package/src/config/cliArguments.js +24 -1
- package/src/config/configFile.js +33 -1
- package/src/config/environmentVariables.js +7 -0
- package/src/config/settings.js +46 -0
- package/src/environment/userInteraction.js +0 -57
- package/src/packagemanager/currentPackageManager.js +3 -0
- package/src/packagemanager/pip/runPipCommand.js +25 -0
- package/src/packagemanager/uv/createUvPackageManager.js +18 -0
- package/src/packagemanager/uv/runUvCommand.js +71 -0
- package/src/registryProxy/mitmRequestHandler.js +8 -4
- package/src/scanning/index.js +11 -30
- package/src/shell-integration/helpers.js +73 -11
- package/src/shell-integration/path-wrappers/templates/unix-wrapper.template.sh +2 -2
- package/src/shell-integration/path-wrappers/templates/windows-wrapper.template.cmd +2 -2
- package/src/shell-integration/setup-ci.js +26 -9
- package/src/shell-integration/setup.js +17 -5
- package/src/shell-integration/startup-scripts/include-python/init-fish.fish +48 -42
- package/src/shell-integration/startup-scripts/include-python/init-posix.sh +39 -38
- package/src/shell-integration/startup-scripts/include-python/init-pwsh.ps1 +65 -57
- package/src/shell-integration/startup-scripts/init-fish.fish +39 -38
- package/src/shell-integration/startup-scripts/init-posix.sh +30 -34
- package/src/shell-integration/startup-scripts/init-pwsh.ps1 +42 -38
package/README.md
CHANGED
|
@@ -1,48 +1,71 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
1
3
|
# Aikido Safe Chain
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
[](https://www.npmjs.com/package/@aikidosec/safe-chain)
|
|
6
|
+
[](https://www.npmjs.com/package/@aikidosec/safe-chain)
|
|
4
7
|
|
|
5
|
-
|
|
8
|
+
- ✅ **Block malware on developer laptops and CI/CD**
|
|
9
|
+
- ✅ **Supports npm and PyPI** more package managers coming
|
|
10
|
+
- ✅ **Blocks packages newer than 24 hours** without breaking your build
|
|
11
|
+
- ✅ **Tokenless, free, no build data shared**
|
|
6
12
|
|
|
7
13
|
Aikido Safe Chain works on Node.js version 16 and above and supports the following package managers:
|
|
8
14
|
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
15
|
+
- 📦 **npm**
|
|
16
|
+
- 📦 **npx**
|
|
17
|
+
- 📦 **yarn**
|
|
18
|
+
- 📦 **pnpm**
|
|
19
|
+
- 📦 **pnpx**
|
|
20
|
+
- 📦 **bun**
|
|
21
|
+
- 📦 **bunx**
|
|
22
|
+
- 📦 **pip** (beta)
|
|
23
|
+
- 📦 **pip3** (beta)
|
|
24
|
+
- 📦 **uv** (beta)
|
|
18
25
|
|
|
19
26
|
# Usage
|
|
20
27
|
|
|
21
28
|
## Installation
|
|
22
29
|
|
|
23
|
-
Installing the Aikido Safe Chain is easy
|
|
30
|
+
Installing the Aikido Safe Chain is easy with our one-line installer.
|
|
24
31
|
|
|
25
|
-
|
|
26
|
-
```shell
|
|
27
|
-
npm install -g @aikidosec/safe-chain
|
|
28
|
-
```
|
|
29
|
-
2. **Setup the shell integration** by running:
|
|
32
|
+
> ⚠️ **Already installed via npm?** See the [migration guide](docs/npm-to-binary-migration.md) to switch to the binary version.
|
|
30
33
|
|
|
31
|
-
|
|
32
|
-
safe-chain setup
|
|
33
|
-
```
|
|
34
|
+
### Unix/Linux/macOS
|
|
34
35
|
|
|
35
|
-
|
|
36
|
+
**Default installation (JavaScript packages only):**
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
```shell
|
|
39
|
+
curl -fsSL https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/install-safe-chain.sh | sh
|
|
40
|
+
```
|
|
40
41
|
|
|
41
|
-
|
|
42
|
+
**Include Python support (pip/pip3/uv):**
|
|
43
|
+
|
|
44
|
+
```shell
|
|
45
|
+
curl -fsSL https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/install-safe-chain.sh | sh -s -- --include-python
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Windows (PowerShell)
|
|
49
|
+
|
|
50
|
+
**Default installation (JavaScript packages only):**
|
|
51
|
+
|
|
52
|
+
```powershell
|
|
53
|
+
iex (iwr "https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/install-safe-chain.ps1" -UseBasicParsing)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**Include Python support (pip/pip3/uv):**
|
|
57
|
+
|
|
58
|
+
```powershell
|
|
59
|
+
iex "& { $(iwr 'https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/install-safe-chain.ps1' -UseBasicParsing) } -includepython"
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Verify the installation
|
|
63
|
+
|
|
64
|
+
1. **❗Restart your terminal** to start using the Aikido Safe Chain.
|
|
42
65
|
|
|
43
66
|
- This step is crucial as it ensures that the shell aliases for npm, npx, yarn, pnpm, pnpx, bun, bunx, and pip/pip3 are loaded correctly. If you do not restart your terminal, the aliases will not be available.
|
|
44
67
|
|
|
45
|
-
|
|
68
|
+
2. **Verify the installation** by running one of the following commands:
|
|
46
69
|
|
|
47
70
|
For JavaScript/Node.js:
|
|
48
71
|
|
|
@@ -50,7 +73,7 @@ Installing the Aikido Safe Chain is easy. You just need 3 simple steps:
|
|
|
50
73
|
npm install safe-chain-test
|
|
51
74
|
```
|
|
52
75
|
|
|
53
|
-
For Python (
|
|
76
|
+
For Python (if you enabled Python support):
|
|
54
77
|
|
|
55
78
|
```shell
|
|
56
79
|
pip3 install safe-chain-pi-test
|
|
@@ -58,7 +81,7 @@ Installing the Aikido Safe Chain is easy. You just need 3 simple steps:
|
|
|
58
81
|
|
|
59
82
|
- The output should show that Aikido Safe Chain is blocking the installation of these test packages as they are flagged as malware.
|
|
60
83
|
|
|
61
|
-
When running `npm`, `npx`, `yarn`, `pnpm`, `pnpx`, `bun`, `bunx`, `pip`, or `pip3` commands, the Aikido Safe Chain will automatically check for malware in the packages you are trying to install. It also intercepts Python module invocations for pip when available (e.g., `python -m pip install ...`, `python3 -m pip download ...`). If any malware is detected, it will prompt you to exit the command.
|
|
84
|
+
When running `npm`, `npx`, `yarn`, `pnpm`, `pnpx`, `bun`, `bunx`, `uv`, `pip`, or `pip3` commands, the Aikido Safe Chain will automatically check for malware in the packages you are trying to install. It also intercepts Python module invocations for pip when available (e.g., `python -m pip install ...`, `python3 -m pip download ...`). If any malware is detected, it will prompt you to exit the command.
|
|
62
85
|
|
|
63
86
|
You can check the installed version by running:
|
|
64
87
|
|
|
@@ -70,17 +93,17 @@ safe-chain --version
|
|
|
70
93
|
|
|
71
94
|
### Malware Blocking
|
|
72
95
|
|
|
73
|
-
The Aikido Safe Chain works by running a lightweight proxy server that intercepts package downloads from the npm registry and PyPI. When you run npm, npx, yarn, pnpm, pnpx, bun, bunx, `pip`, or `pip3` commands, all package downloads are routed through this local proxy, which verifies packages in real-time against **[Aikido Intel - Open Sources Threat Intelligence](https://intel.aikido.dev/?tab=malware)**. If malware is detected in any package (including deep dependencies), the proxy blocks the download before the malicious code reaches your machine.
|
|
96
|
+
The Aikido Safe Chain works by running a lightweight proxy server that intercepts package downloads from the npm registry and PyPI. When you run npm, npx, yarn, pnpm, pnpx, bun, bunx, uv, `pip`, or `pip3` commands, all package downloads are routed through this local proxy, which verifies packages in real-time against **[Aikido Intel - Open Sources Threat Intelligence](https://intel.aikido.dev/?tab=malware)**. If malware is detected in any package (including deep dependencies), the proxy blocks the download before the malicious code reaches your machine.
|
|
74
97
|
|
|
75
98
|
### Minimum package age (npm only)
|
|
76
99
|
|
|
77
|
-
For npm packages, Safe Chain temporarily suppresses packages published within the last 24 hours until they have been validated against malware. This provides an additional security layer during the critical period when newly published packages are most vulnerable to containing undetected threats. You can bypass this protection
|
|
100
|
+
For npm packages, Safe Chain temporarily suppresses packages published within the last 24 hours (by default) until they have been validated against malware. This provides an additional security layer during the critical period when newly published packages are most vulnerable to containing undetected threats. You can configure this threshold or bypass this protection entirely - see the [Minimum Package Age Configuration](#minimum-package-age) section below.
|
|
78
101
|
|
|
79
|
-
⚠️ This feature **only applies to npm-based package managers** (npm, npx, yarn, pnpm, pnpx, bun, bunx) and does not apply to
|
|
102
|
+
⚠️ This feature **only applies to npm-based package managers** (npm, npx, yarn, pnpm, pnpx, bun, bunx) and does not apply to Python package managers (uv, pip, pip3).
|
|
80
103
|
|
|
81
104
|
### Shell Integration
|
|
82
105
|
|
|
83
|
-
The Aikido Safe Chain integrates with your shell to provide a seamless experience when using npm, npx, yarn, pnpm, pnpx, bun, bunx, and pip
|
|
106
|
+
The Aikido Safe Chain integrates with your shell to provide a seamless experience when using npm, npx, yarn, pnpm, pnpx, bun, bunx, and Python package managers (uv, pip). It sets up aliases for these commands so that they are wrapped by the Aikido Safe Chain commands, which manage the proxy server before executing the original commands. We currently support:
|
|
84
107
|
|
|
85
108
|
- ✅ **Bash**
|
|
86
109
|
- ✅ **Zsh**
|
|
@@ -126,27 +149,72 @@ You can control the output from Aikido Safe Chain using the `--safe-chain-loggin
|
|
|
126
149
|
npm install express --safe-chain-logging=verbose
|
|
127
150
|
```
|
|
128
151
|
|
|
152
|
+
## Minimum Package Age
|
|
153
|
+
|
|
154
|
+
You can configure how long packages must exist before Safe Chain allows their installation. By default, packages must be at least 24 hours old before they can be installed through npm-based package managers.
|
|
155
|
+
|
|
156
|
+
### Configuration Options
|
|
157
|
+
|
|
158
|
+
You can set the minimum package age through multiple sources (in order of priority):
|
|
159
|
+
|
|
160
|
+
1. **CLI Argument** (highest priority):
|
|
161
|
+
|
|
162
|
+
```shell
|
|
163
|
+
npm install express --safe-chain-minimum-package-age-hours=48
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
2. **Environment Variable**:
|
|
167
|
+
|
|
168
|
+
```shell
|
|
169
|
+
export SAFE_CHAIN_MINIMUM_PACKAGE_AGE_HOURS=48
|
|
170
|
+
npm install express
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
3. **Config File** (`~/.aikido/config.json`):
|
|
174
|
+
|
|
175
|
+
```json
|
|
176
|
+
{
|
|
177
|
+
"minimumPackageAgeHours": 48
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
129
181
|
# Usage in CI/CD
|
|
130
182
|
|
|
131
183
|
You can protect your CI/CD pipelines from malicious packages by integrating Aikido Safe Chain into your build process. This ensures that any packages installed during your automated builds are checked for malware before installation.
|
|
132
184
|
|
|
133
185
|
For optimal protection in CI/CD environments, we recommend using **npm >= 10.4.0** as it provides full dependency tree scanning. Other package managers currently offer limited scanning of install command arguments only.
|
|
134
186
|
|
|
135
|
-
##
|
|
187
|
+
## Installation for CI/CD
|
|
188
|
+
|
|
189
|
+
Use the `--ci` flag to automatically configure Aikido Safe Chain for CI/CD environments. This sets up executable shims in the PATH instead of shell aliases.
|
|
190
|
+
|
|
191
|
+
### Unix/Linux/macOS (GitHub Actions, Azure Pipelines, etc.)
|
|
136
192
|
|
|
137
|
-
|
|
193
|
+
**JavaScript only:**
|
|
138
194
|
|
|
139
195
|
```shell
|
|
140
|
-
safe-chain
|
|
196
|
+
curl -fsSL https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/install-safe-chain.sh | sh -s -- --ci
|
|
141
197
|
```
|
|
142
198
|
|
|
143
|
-
|
|
199
|
+
**With Python support:**
|
|
144
200
|
|
|
145
201
|
```shell
|
|
146
|
-
safe-chain
|
|
202
|
+
curl -fsSL https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/install-safe-chain.sh | sh -s -- --ci --include-python
|
|
147
203
|
```
|
|
148
204
|
|
|
149
|
-
|
|
205
|
+
### Windows (Azure Pipelines, etc.)
|
|
206
|
+
|
|
207
|
+
**JavaScript only:**
|
|
208
|
+
|
|
209
|
+
```powershell
|
|
210
|
+
iex "& { $(iwr 'https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/install-safe-chain.ps1' -UseBasicParsing) } -ci"
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
**With Python support:**
|
|
214
|
+
|
|
215
|
+
```powershell
|
|
216
|
+
iex "& { $(iwr 'https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/install-safe-chain.ps1' -UseBasicParsing) } -ci -includepython"
|
|
217
|
+
```
|
|
150
218
|
|
|
151
219
|
## Supported Platforms
|
|
152
220
|
|
|
@@ -162,16 +230,15 @@ This automatically configures your CI environment to use Aikido Safe Chain for a
|
|
|
162
230
|
node-version: "22"
|
|
163
231
|
cache: "npm"
|
|
164
232
|
|
|
165
|
-
- name:
|
|
166
|
-
run: |
|
|
167
|
-
npm i -g @aikidosec/safe-chain
|
|
168
|
-
safe-chain setup-ci
|
|
233
|
+
- name: Install safe-chain
|
|
234
|
+
run: curl -fsSL https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/install-safe-chain.sh | sh -s -- --ci --include-python
|
|
169
235
|
|
|
170
236
|
- name: Install dependencies
|
|
171
|
-
run:
|
|
172
|
-
npm ci
|
|
237
|
+
run: npm ci
|
|
173
238
|
```
|
|
174
239
|
|
|
240
|
+
> **Note:** Remove `--include-python` if you don't need Python (pip/pip3/uv) support.
|
|
241
|
+
|
|
175
242
|
## Azure DevOps Example
|
|
176
243
|
|
|
177
244
|
```yaml
|
|
@@ -180,14 +247,13 @@ This automatically configures your CI environment to use Aikido Safe Chain for a
|
|
|
180
247
|
versionSpec: "22.x"
|
|
181
248
|
displayName: "Install Node.js"
|
|
182
249
|
|
|
183
|
-
- script: |
|
|
184
|
-
|
|
185
|
-
safe-chain setup-ci
|
|
186
|
-
displayName: "Install safe chain"
|
|
250
|
+
- script: curl -fsSL https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/install-safe-chain.sh | sh -s -- --ci --include-python
|
|
251
|
+
displayName: "Install safe-chain"
|
|
187
252
|
|
|
188
|
-
- script:
|
|
189
|
-
|
|
190
|
-
displayName: "npm install and build"
|
|
253
|
+
- script: npm ci
|
|
254
|
+
displayName: "Install dependencies"
|
|
191
255
|
```
|
|
192
256
|
|
|
257
|
+
> **Note:** Remove `--include-python` if you don't need Python (pip/pip3/uv) support.
|
|
258
|
+
|
|
193
259
|
After setup, all subsequent package manager commands in your CI pipeline will automatically be protected by Aikido Safe Chain's malware detection.
|
package/bin/aikido-bun.js
CHANGED
|
@@ -7,6 +7,8 @@ import { setEcoSystem, ECOSYSTEM_JS } from "../src/config/settings.js";
|
|
|
7
7
|
setEcoSystem(ECOSYSTEM_JS);
|
|
8
8
|
const packageManagerName = "bun";
|
|
9
9
|
initializePackageManager(packageManagerName);
|
|
10
|
-
var exitCode = await main(process.argv.slice(2));
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
(async () => {
|
|
12
|
+
var exitCode = await main(process.argv.slice(2));
|
|
13
|
+
process.exit(exitCode);
|
|
14
|
+
})();
|
package/bin/aikido-bunx.js
CHANGED
|
@@ -7,6 +7,8 @@ import { setEcoSystem, ECOSYSTEM_JS } from "../src/config/settings.js";
|
|
|
7
7
|
setEcoSystem(ECOSYSTEM_JS);
|
|
8
8
|
const packageManagerName = "bunx";
|
|
9
9
|
initializePackageManager(packageManagerName);
|
|
10
|
-
var exitCode = await main(process.argv.slice(2));
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
(async () => {
|
|
12
|
+
var exitCode = await main(process.argv.slice(2));
|
|
13
|
+
process.exit(exitCode);
|
|
14
|
+
})();
|
package/bin/aikido-npm.js
CHANGED
|
@@ -7,6 +7,8 @@ import { setEcoSystem, ECOSYSTEM_JS } from "../src/config/settings.js";
|
|
|
7
7
|
setEcoSystem(ECOSYSTEM_JS);
|
|
8
8
|
const packageManagerName = "npm";
|
|
9
9
|
initializePackageManager(packageManagerName);
|
|
10
|
-
var exitCode = await main(process.argv.slice(2));
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
(async () => {
|
|
12
|
+
var exitCode = await main(process.argv.slice(2));
|
|
13
|
+
process.exit(exitCode);
|
|
14
|
+
})();
|
package/bin/aikido-npx.js
CHANGED
|
@@ -7,6 +7,8 @@ import { setEcoSystem, ECOSYSTEM_JS } from "../src/config/settings.js";
|
|
|
7
7
|
setEcoSystem(ECOSYSTEM_JS);
|
|
8
8
|
const packageManagerName = "npx";
|
|
9
9
|
initializePackageManager(packageManagerName);
|
|
10
|
-
var exitCode = await main(process.argv.slice(2));
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
(async () => {
|
|
12
|
+
var exitCode = await main(process.argv.slice(2));
|
|
13
|
+
process.exit(exitCode);
|
|
14
|
+
})();
|
package/bin/aikido-pip.js
CHANGED
|
@@ -13,6 +13,8 @@ setCurrentPipInvocation(PIP_INVOCATIONS.PIP);
|
|
|
13
13
|
|
|
14
14
|
initializePackageManager(PIP_PACKAGE_MANAGER);
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
process.
|
|
16
|
+
(async () => {
|
|
17
|
+
// Pass through only user-supplied pip args
|
|
18
|
+
var exitCode = await main(process.argv.slice(2));
|
|
19
|
+
process.exit(exitCode);
|
|
20
|
+
})();
|
package/bin/aikido-pip3.js
CHANGED
|
@@ -14,6 +14,8 @@ setCurrentPipInvocation(PIP_INVOCATIONS.PIP3);
|
|
|
14
14
|
// Create package manager
|
|
15
15
|
initializePackageManager(PIP_PACKAGE_MANAGER);
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
process.
|
|
17
|
+
(async () => {
|
|
18
|
+
// Pass through only user-supplied pip args
|
|
19
|
+
var exitCode = await main(process.argv.slice(2));
|
|
20
|
+
process.exit(exitCode);
|
|
21
|
+
})();
|
package/bin/aikido-pnpm.js
CHANGED
|
@@ -7,6 +7,8 @@ import { setEcoSystem, ECOSYSTEM_JS } from "../src/config/settings.js";
|
|
|
7
7
|
setEcoSystem(ECOSYSTEM_JS);
|
|
8
8
|
const packageManagerName = "pnpm";
|
|
9
9
|
initializePackageManager(packageManagerName);
|
|
10
|
-
var exitCode = await main(process.argv.slice(2));
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
(async () => {
|
|
12
|
+
var exitCode = await main(process.argv.slice(2));
|
|
13
|
+
process.exit(exitCode);
|
|
14
|
+
})();
|
package/bin/aikido-pnpx.js
CHANGED
|
@@ -7,6 +7,8 @@ import { setEcoSystem, ECOSYSTEM_JS } from "../src/config/settings.js";
|
|
|
7
7
|
setEcoSystem(ECOSYSTEM_JS);
|
|
8
8
|
const packageManagerName = "pnpx";
|
|
9
9
|
initializePackageManager(packageManagerName);
|
|
10
|
-
var exitCode = await main(process.argv.slice(2));
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
(async () => {
|
|
12
|
+
var exitCode = await main(process.argv.slice(2));
|
|
13
|
+
process.exit(exitCode);
|
|
14
|
+
})();
|
package/bin/aikido-python.js
CHANGED
|
@@ -11,18 +11,20 @@ setEcoSystem(ECOSYSTEM_PY);
|
|
|
11
11
|
// Strip nodejs and wrapper script from args
|
|
12
12
|
let argv = process.argv.slice(2);
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
(async () => {
|
|
15
|
+
if (argv[0] === '-m' && (argv[1] === 'pip' || argv[1] === 'pip3')) {
|
|
16
|
+
setEcoSystem(ECOSYSTEM_PY);
|
|
17
|
+
setCurrentPipInvocation(argv[1] === 'pip3' ? PIP_INVOCATIONS.PY_PIP3 : PIP_INVOCATIONS.PY_PIP);
|
|
18
|
+
initializePackageManager(PIP_PACKAGE_MANAGER);
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
// Strip off the '-m pip' or '-m pip3' from the args
|
|
21
|
+
argv = argv.slice(2);
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
} else {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
23
|
+
var exitCode = await main(argv);
|
|
24
|
+
process.exit(exitCode);
|
|
25
|
+
} else {
|
|
26
|
+
// Forward to real python binary for non-pip flows
|
|
27
|
+
const { spawn } = await import('child_process');
|
|
28
|
+
spawn('python', argv, { stdio: 'inherit' });
|
|
29
|
+
}
|
|
30
|
+
})();
|
package/bin/aikido-python3.js
CHANGED
|
@@ -11,18 +11,20 @@ setEcoSystem(ECOSYSTEM_PY);
|
|
|
11
11
|
// Strip nodejs and wrapper script from args
|
|
12
12
|
let argv = process.argv.slice(2);
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
(async () => {
|
|
15
|
+
if (argv[0] === '-m' && (argv[1] === 'pip' || argv[1] === 'pip3')) {
|
|
16
|
+
setEcoSystem(ECOSYSTEM_PY);
|
|
17
|
+
setCurrentPipInvocation(argv[1] === 'pip3' ? PIP_INVOCATIONS.PY3_PIP3 : PIP_INVOCATIONS.PY3_PIP);
|
|
18
|
+
initializePackageManager(PIP_PACKAGE_MANAGER);
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
// Strip off the '-m pip' or '-m pip3' from the args
|
|
21
|
+
argv = argv.slice(2);
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
} else {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
23
|
+
var exitCode = await main(argv);
|
|
24
|
+
process.exit(exitCode);
|
|
25
|
+
} else {
|
|
26
|
+
// Forward to real python3 binary for non-pip flows
|
|
27
|
+
const { spawn } = await import('child_process');
|
|
28
|
+
spawn('python3', argv, { stdio: 'inherit' });
|
|
29
|
+
}
|
|
30
|
+
})();
|
package/bin/aikido-uv.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { main } from "../src/main.js";
|
|
4
|
+
import { initializePackageManager } from "../src/packagemanager/currentPackageManager.js";
|
|
5
|
+
import { setEcoSystem, ECOSYSTEM_PY } from "../src/config/settings.js";
|
|
6
|
+
|
|
7
|
+
// Set eco system
|
|
8
|
+
setEcoSystem(ECOSYSTEM_PY);
|
|
9
|
+
|
|
10
|
+
initializePackageManager("uv");
|
|
11
|
+
|
|
12
|
+
(async () => {
|
|
13
|
+
// Pass through only user-supplied uv args
|
|
14
|
+
var exitCode = await main(process.argv.slice(2));
|
|
15
|
+
process.exit(exitCode);
|
|
16
|
+
})();
|
package/bin/aikido-yarn.js
CHANGED
|
@@ -7,6 +7,8 @@ import { setEcoSystem, ECOSYSTEM_JS } from "../src/config/settings.js";
|
|
|
7
7
|
setEcoSystem(ECOSYSTEM_JS);
|
|
8
8
|
const packageManagerName = "yarn";
|
|
9
9
|
initializePackageManager(packageManagerName);
|
|
10
|
-
var exitCode = await main(process.argv.slice(2));
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
(async () => {
|
|
12
|
+
var exitCode = await main(process.argv.slice(2));
|
|
13
|
+
process.exit(exitCode);
|
|
14
|
+
})();
|
package/bin/safe-chain.js
CHANGED
|
@@ -1,12 +1,37 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import chalk from "chalk";
|
|
4
|
-
import { createRequire } from "module";
|
|
5
4
|
import { ui } from "../src/environment/userInteraction.js";
|
|
6
5
|
import { setup } from "../src/shell-integration/setup.js";
|
|
7
6
|
import { teardown } from "../src/shell-integration/teardown.js";
|
|
8
7
|
import { setupCi } from "../src/shell-integration/setup-ci.js";
|
|
9
8
|
import { initializeCliArguments } from "../src/config/cliArguments.js";
|
|
9
|
+
import { setEcoSystem } from "../src/config/settings.js";
|
|
10
|
+
import { initializePackageManager } from "../src/packagemanager/currentPackageManager.js";
|
|
11
|
+
import { main } from "../src/main.js";
|
|
12
|
+
import path from "path";
|
|
13
|
+
import { fileURLToPath } from "url";
|
|
14
|
+
import fs from "fs";
|
|
15
|
+
import { knownAikidoTools } from "../src/shell-integration/helpers.js";
|
|
16
|
+
import {
|
|
17
|
+
PIP_INVOCATIONS,
|
|
18
|
+
PIP_PACKAGE_MANAGER,
|
|
19
|
+
setCurrentPipInvocation,
|
|
20
|
+
} from "../src/packagemanager/pip/pipSettings.js";
|
|
21
|
+
|
|
22
|
+
/** @type {string} */
|
|
23
|
+
// This checks the current file's dirname in a way that's compatible with:
|
|
24
|
+
// - Modulejs (import.meta.url)
|
|
25
|
+
// - ES modules (__dirname)
|
|
26
|
+
// This is needed because safe-chain's npm package is built using ES modules,
|
|
27
|
+
// but building the binaries requires commonjs.
|
|
28
|
+
let dirname;
|
|
29
|
+
if (import.meta.url) {
|
|
30
|
+
const filename = fileURLToPath(import.meta.url);
|
|
31
|
+
dirname = path.dirname(filename);
|
|
32
|
+
} else {
|
|
33
|
+
dirname = __dirname;
|
|
34
|
+
}
|
|
10
35
|
|
|
11
36
|
if (process.argv.length < 3) {
|
|
12
37
|
ui.writeError("No command provided. Please provide a command to execute.");
|
|
@@ -19,19 +44,35 @@ initializeCliArguments(process.argv);
|
|
|
19
44
|
|
|
20
45
|
const command = process.argv[2];
|
|
21
46
|
|
|
22
|
-
|
|
47
|
+
const tool = knownAikidoTools.find((tool) => tool.tool === command);
|
|
48
|
+
|
|
49
|
+
if (tool && tool.internalPackageManagerName === PIP_PACKAGE_MANAGER) {
|
|
50
|
+
(async function () {
|
|
51
|
+
await executePip(tool);
|
|
52
|
+
})();
|
|
53
|
+
} else if (tool) {
|
|
54
|
+
const args = process.argv.slice(3);
|
|
55
|
+
|
|
56
|
+
setEcoSystem(tool.ecoSystem);
|
|
57
|
+
initializePackageManager(tool.internalPackageManagerName);
|
|
58
|
+
|
|
59
|
+
(async () => {
|
|
60
|
+
var exitCode = await main(args);
|
|
61
|
+
process.exit(exitCode);
|
|
62
|
+
})();
|
|
63
|
+
} else if (command === "help" || command === "--help" || command === "-h") {
|
|
23
64
|
writeHelp();
|
|
24
65
|
process.exit(0);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (command === "setup") {
|
|
66
|
+
} else if (command === "setup") {
|
|
28
67
|
setup();
|
|
29
68
|
} else if (command === "teardown") {
|
|
30
69
|
teardown();
|
|
31
70
|
} else if (command === "setup-ci") {
|
|
32
71
|
setupCi();
|
|
33
72
|
} else if (command === "--version" || command === "-v" || command === "-v") {
|
|
34
|
-
|
|
73
|
+
(async () => {
|
|
74
|
+
ui.writeInformation(`Current safe-chain version: ${await getVersion()}`);
|
|
75
|
+
})();
|
|
35
76
|
} else {
|
|
36
77
|
ui.writeError(`Unknown command: ${command}.`);
|
|
37
78
|
ui.emptyLine();
|
|
@@ -87,8 +128,63 @@ function writeHelp() {
|
|
|
87
128
|
ui.emptyLine();
|
|
88
129
|
}
|
|
89
130
|
|
|
90
|
-
function getVersion() {
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
131
|
+
async function getVersion() {
|
|
132
|
+
const packageJsonPath = path.join(dirname, "..", "package.json");
|
|
133
|
+
|
|
134
|
+
const data = await fs.promises.readFile(packageJsonPath);
|
|
135
|
+
const json = JSON.parse(data.toString("utf8"));
|
|
136
|
+
|
|
137
|
+
if (json && json.version) {
|
|
138
|
+
return json.version;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return "0.0.0";
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* @param {import("../src/shell-integration/helpers.js").AikidoTool} tool
|
|
146
|
+
*/
|
|
147
|
+
async function executePip(tool) {
|
|
148
|
+
// Scanners for pip / pip3 / python / python3 use a slightly different approach:
|
|
149
|
+
// - They all use the same PIP_PACKAGE_MANAGER internally, but need some setup to be able to do so
|
|
150
|
+
// - It needs to set which tool to run (pip / pip3 / python / python3)
|
|
151
|
+
// - For python and python3, the -m pip/pip3 args are removed and later added again by the package manager
|
|
152
|
+
// - Python / python3 skips safe-chain if not being run with -m pip or -m pip3
|
|
153
|
+
|
|
154
|
+
let args = process.argv.slice(3);
|
|
155
|
+
setEcoSystem(tool.ecoSystem);
|
|
156
|
+
initializePackageManager(PIP_PACKAGE_MANAGER);
|
|
157
|
+
|
|
158
|
+
let shouldSkip = false;
|
|
159
|
+
if (tool.tool === "pip") {
|
|
160
|
+
setCurrentPipInvocation(PIP_INVOCATIONS.PIP);
|
|
161
|
+
} else if (tool.tool === "pip3") {
|
|
162
|
+
setCurrentPipInvocation(PIP_INVOCATIONS.PIP3);
|
|
163
|
+
} else if (tool.tool === "python") {
|
|
164
|
+
if (args[0] === "-m" && (args[1] === "pip" || args[1] === "pip3")) {
|
|
165
|
+
setCurrentPipInvocation(
|
|
166
|
+
args[1] === "pip3" ? PIP_INVOCATIONS.PY_PIP3 : PIP_INVOCATIONS.PY_PIP
|
|
167
|
+
);
|
|
168
|
+
args = args.slice(2);
|
|
169
|
+
} else {
|
|
170
|
+
shouldSkip = true;
|
|
171
|
+
}
|
|
172
|
+
} else if (tool.tool === "python3") {
|
|
173
|
+
if (args[0] === "-m" && (args[1] === "pip" || args[1] === "pip3")) {
|
|
174
|
+
setCurrentPipInvocation(
|
|
175
|
+
args[1] === "pip3" ? PIP_INVOCATIONS.PY3_PIP3 : PIP_INVOCATIONS.PY3_PIP
|
|
176
|
+
);
|
|
177
|
+
args = args.slice(2);
|
|
178
|
+
} else {
|
|
179
|
+
shouldSkip = true;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (shouldSkip) {
|
|
184
|
+
const { spawn } = await import("child_process");
|
|
185
|
+
spawn(tool.tool, args, { stdio: "inherit" });
|
|
186
|
+
} else {
|
|
187
|
+
var exitCode = await main(args);
|
|
188
|
+
process.exit(exitCode);
|
|
189
|
+
}
|
|
94
190
|
}
|