@guardinstall/cli 0.1.4 → 0.1.6
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/dist/index.js +1 -1
- package/dist/installer.js +20 -2
- package/package.json +3 -3
- package/src/index.ts +1 -1
- package/src/installer.ts +20 -2
- package/dist/ink-reporter.js +0 -49
package/dist/index.js
CHANGED
|
@@ -39,7 +39,7 @@ const program = new commander_1.Command();
|
|
|
39
39
|
program
|
|
40
40
|
.name('guardinstall')
|
|
41
41
|
.description('A kernel-level behavioral sandbox for npm/pnpm/bun install scripts')
|
|
42
|
-
.version('0.1.
|
|
42
|
+
.version('0.1.6');
|
|
43
43
|
program
|
|
44
44
|
.command('install')
|
|
45
45
|
.description('Run npm install with sandbox protection')
|
package/dist/installer.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.runPackageManager = void 0;
|
|
7
7
|
const child_process_1 = require("child_process");
|
|
8
8
|
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const child_process_2 = require("child_process");
|
|
9
10
|
async function runPackageManager(pm, args) {
|
|
10
11
|
const pmMap = {
|
|
11
12
|
npm: 'npm',
|
|
@@ -21,16 +22,33 @@ async function runPackageManager(pm, args) {
|
|
|
21
22
|
// Add --ignore-scripts flag
|
|
22
23
|
args.push('--ignore-scripts');
|
|
23
24
|
}
|
|
24
|
-
|
|
25
|
+
// Remove --ignore-scripts from display (it's expected)
|
|
26
|
+
const displayArgs = args.filter(a => a !== '--ignore-scripts');
|
|
27
|
+
console.log(chalk_1.default.gray(`\n📦 Running: ${command} ${displayArgs.join(' ')} (with --ignore-scripts)\n`));
|
|
25
28
|
return new Promise((resolve) => {
|
|
29
|
+
// Use spawn without shell to avoid npm arborist bug triggered by shell escaping
|
|
26
30
|
const proc = (0, child_process_1.spawn)(command, args, {
|
|
27
31
|
stdio: 'inherit',
|
|
28
|
-
shell:
|
|
32
|
+
shell: false
|
|
29
33
|
});
|
|
30
34
|
let output = '';
|
|
31
35
|
proc.stdout?.on('data', (d) => { output += d.toString(); });
|
|
32
36
|
proc.stderr?.on('data', (d) => { output += d.toString(); });
|
|
33
37
|
proc.on('close', (code) => {
|
|
38
|
+
// If npm fails with arborist error, try alternative approach
|
|
39
|
+
if (code !== 0 && command === 'npm') {
|
|
40
|
+
console.log(chalk_1.default.yellow('\n⚠️ npm encountered an error, trying with --no-audit --no-fund...\n'));
|
|
41
|
+
try {
|
|
42
|
+
// Try running npm without audit/fund which sometimes triggers arborist issues
|
|
43
|
+
const fallbackArgs = ['install', '--ignore-scripts', '--no-audit', '--no-fund', ...args.filter(a => a !== 'install' && a !== 'add' && a !== '--ignore-scripts')];
|
|
44
|
+
const result = (0, child_process_2.execSync)(`npm ${fallbackArgs.join(' ')}`, { stdio: 'inherit', encoding: 'utf-8' });
|
|
45
|
+
resolve({ success: true, output: result || '' });
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
catch (e) {
|
|
49
|
+
// Fallback failed too
|
|
50
|
+
}
|
|
51
|
+
}
|
|
34
52
|
resolve({
|
|
35
53
|
success: code === 0,
|
|
36
54
|
output
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guardinstall/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "CLI wrapper for guardinstall - intercepts and sandboxes install scripts",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"test": "jest"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@guardinstall/policy-engine": "0.1.
|
|
17
|
-
"@guardinstall/sandbox": "0.1.
|
|
16
|
+
"@guardinstall/policy-engine": "0.1.6",
|
|
17
|
+
"@guardinstall/sandbox": "0.1.6",
|
|
18
18
|
"@npmcli/arborist": "7.5.4",
|
|
19
19
|
"chalk": "4.1.2",
|
|
20
20
|
"commander": "12.1.0"
|
package/src/index.ts
CHANGED
package/src/installer.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { spawn } from 'child_process'
|
|
2
2
|
import chalk from 'chalk'
|
|
3
|
+
import { execSync } from 'child_process'
|
|
3
4
|
|
|
4
5
|
export async function runPackageManager(
|
|
5
6
|
pm: string,
|
|
@@ -23,12 +24,15 @@ export async function runPackageManager(
|
|
|
23
24
|
args.push('--ignore-scripts')
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
|
|
27
|
+
// Remove --ignore-scripts from display (it's expected)
|
|
28
|
+
const displayArgs = args.filter(a => a !== '--ignore-scripts')
|
|
29
|
+
console.log(chalk.gray(`\n📦 Running: ${command} ${displayArgs.join(' ')} (with --ignore-scripts)\n`))
|
|
27
30
|
|
|
28
31
|
return new Promise((resolve) => {
|
|
32
|
+
// Use spawn without shell to avoid npm arborist bug triggered by shell escaping
|
|
29
33
|
const proc = spawn(command, args, {
|
|
30
34
|
stdio: 'inherit',
|
|
31
|
-
shell:
|
|
35
|
+
shell: false
|
|
32
36
|
})
|
|
33
37
|
|
|
34
38
|
let output = ''
|
|
@@ -36,6 +40,20 @@ export async function runPackageManager(
|
|
|
36
40
|
proc.stderr?.on('data', (d: Buffer) => { output += d.toString() })
|
|
37
41
|
|
|
38
42
|
proc.on('close', (code) => {
|
|
43
|
+
// If npm fails with arborist error, try alternative approach
|
|
44
|
+
if (code !== 0 && command === 'npm') {
|
|
45
|
+
console.log(chalk.yellow('\n⚠️ npm encountered an error, trying with --no-audit --no-fund...\n'))
|
|
46
|
+
try {
|
|
47
|
+
// Try running npm without audit/fund which sometimes triggers arborist issues
|
|
48
|
+
const fallbackArgs = ['install', '--ignore-scripts', '--no-audit', '--no-fund', ...args.filter(a => a !== 'install' && a !== 'add' && a !== '--ignore-scripts')]
|
|
49
|
+
const result = execSync(`npm ${fallbackArgs.join(' ')}`, { stdio: 'inherit', encoding: 'utf-8' })
|
|
50
|
+
resolve({ success: true, output: result || '' })
|
|
51
|
+
return
|
|
52
|
+
} catch (e) {
|
|
53
|
+
// Fallback failed too
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
39
57
|
resolve({
|
|
40
58
|
success: code === 0,
|
|
41
59
|
output
|
package/dist/ink-reporter.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.InkReporter = void 0;
|
|
7
|
-
const react_1 = __importDefault(require("react"));
|
|
8
|
-
const ink_1 = require("ink");
|
|
9
|
-
function InkReporter({ results, verdicts }) {
|
|
10
|
-
const blocked = verdicts.filter(v => v.severity === 'CRITICAL' || v.severity === 'HIGH');
|
|
11
|
-
const warned = verdicts.filter(v => v.severity === 'WARN');
|
|
12
|
-
const clean = results.filter(r => r.events.length === 0);
|
|
13
|
-
return (<ink_1.Box flexDirection="column">
|
|
14
|
-
<ink_1.Box borderStyle="bold" borderColor="blue">
|
|
15
|
-
<ink_1.Text bold blue> guardinstall — Security Report </ink_1.Text>
|
|
16
|
-
</ink_1.Box>
|
|
17
|
-
|
|
18
|
-
<ink_1.Newline />
|
|
19
|
-
|
|
20
|
-
{blocked.length > 0 && (<ink_1.Box flexDirection="column">
|
|
21
|
-
<ink_1.Text bold color="red">🚨 BLOCKED ({blocked.length} packages):</ink_1.Text>
|
|
22
|
-
{blocked.map(v => (<ink_1.Box flexDirection="column" key={v.package}>
|
|
23
|
-
<ink_1.Text color="red"> ⚠ {v.package}</ink_1.Text>
|
|
24
|
-
{v.findings.map((f, i) => (<ink_1.Text key={i} color="red"> [{f.severity}] {f.message}</ink_1.Text>))}
|
|
25
|
-
</ink_1.Box>))}
|
|
26
|
-
<ink_1.Newline />
|
|
27
|
-
</ink_1.Box>)}
|
|
28
|
-
|
|
29
|
-
{warned.length > 0 && (<ink_1.Box flexDirection="column">
|
|
30
|
-
<ink_1.Text bold color="yellow">⚠️ WARNINGS ({warned.length} packages):</ink_1.Text>
|
|
31
|
-
{warned.map(v => (<ink_1.Box flexDirection="column" key={v.package}>
|
|
32
|
-
<ink_1.Text color="yellow"> {v.package}</ink_1.Text>
|
|
33
|
-
{v.findings.map((f, i) => (<ink_1.Text key={i} color="yellow"> [{f.severity}] {f.message}</ink_1.Text>))}
|
|
34
|
-
</ink_1.Box>))}
|
|
35
|
-
<ink_1.Newline />
|
|
36
|
-
</ink_1.Box>)}
|
|
37
|
-
|
|
38
|
-
{clean.length > 0 && (<ink_1.Box flexDirection="column">
|
|
39
|
-
<ink_1.Text bold color="green">✓ CLEAN ({clean.length} packages):</ink_1.Text>
|
|
40
|
-
{clean.map(r => (<ink_1.Text key={r.package} color="green"> ✓ {r.package}</ink_1.Text>))}
|
|
41
|
-
<ink_1.Newline />
|
|
42
|
-
</ink_1.Box>)}
|
|
43
|
-
|
|
44
|
-
<ink_1.Box borderStyle="bold" borderColor="blue">
|
|
45
|
-
<ink_1.Text bold blue> End of Report </ink_1.Text>
|
|
46
|
-
</ink_1.Box>
|
|
47
|
-
</ink_1.Box>);
|
|
48
|
-
}
|
|
49
|
-
exports.InkReporter = InkReporter;
|