safeinstall-cli 0.1.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/CHANGELOG.md +34 -0
- package/LICENSE +21 -0
- package/README.md +305 -0
- package/SUPPORT.md +42 -0
- package/dist/async.js +26 -0
- package/dist/check-flow.js +160 -0
- package/dist/cli-options.js +15 -0
- package/dist/cli.js +97 -0
- package/dist/config.js +129 -0
- package/dist/disk-cache.js +67 -0
- package/dist/evaluations.js +27 -0
- package/dist/init-flow.js +55 -0
- package/dist/install-flow.js +274 -0
- package/dist/output.js +93 -0
- package/dist/package-managers.js +98 -0
- package/dist/policy.js +83 -0
- package/dist/project-discovery.js +90 -0
- package/dist/project-installs/npm.js +93 -0
- package/dist/project-installs/pnpm.js +166 -0
- package/dist/project-installs/shared.js +62 -0
- package/dist/project-installs/types.js +2 -0
- package/dist/project-installs.js +60 -0
- package/dist/project-state.js +101 -0
- package/dist/registry.js +239 -0
- package/dist/signals.js +55 -0
- package/dist/specs.js +185 -0
- package/dist/types.js +2 -0
- package/package.json +60 -0
- package/safeinstall.config.example.json +21 -0
package/dist/specs.js
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
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.extractRequestedSpecs = extractRequestedSpecs;
|
|
7
|
+
exports.buildInstallPlan = buildInstallPlan;
|
|
8
|
+
exports.parseManifestDependency = parseManifestDependency;
|
|
9
|
+
const npm_package_arg_1 = __importDefault(require("npm-package-arg"));
|
|
10
|
+
const FLAGS_WITH_VALUES = new Set([
|
|
11
|
+
"-C",
|
|
12
|
+
"-c",
|
|
13
|
+
"-w",
|
|
14
|
+
"--cache",
|
|
15
|
+
"--config",
|
|
16
|
+
"--cwd",
|
|
17
|
+
"--filter",
|
|
18
|
+
"--global-dir",
|
|
19
|
+
"--prefix",
|
|
20
|
+
"--registry",
|
|
21
|
+
"--save-prefix",
|
|
22
|
+
"--store-dir",
|
|
23
|
+
"--tag",
|
|
24
|
+
"--userconfig"
|
|
25
|
+
]);
|
|
26
|
+
function classifySourceType(result) {
|
|
27
|
+
switch (result.type) {
|
|
28
|
+
case "git":
|
|
29
|
+
return "git";
|
|
30
|
+
case "remote":
|
|
31
|
+
return result.fetchSpec?.endsWith(".tgz") || result.fetchSpec?.endsWith(".tar.gz") ? "tarball" : "url";
|
|
32
|
+
case "file":
|
|
33
|
+
return "file";
|
|
34
|
+
case "directory":
|
|
35
|
+
return "directory";
|
|
36
|
+
case "tag":
|
|
37
|
+
case "range":
|
|
38
|
+
case "version":
|
|
39
|
+
case "alias":
|
|
40
|
+
return "registry";
|
|
41
|
+
default:
|
|
42
|
+
return "unknown";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function classifyRegistrySpecKind(result) {
|
|
46
|
+
switch (result.type) {
|
|
47
|
+
case "tag":
|
|
48
|
+
return "tag";
|
|
49
|
+
case "version":
|
|
50
|
+
return "version";
|
|
51
|
+
case "range":
|
|
52
|
+
case "alias":
|
|
53
|
+
return "range";
|
|
54
|
+
default:
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function isFlag(token) {
|
|
59
|
+
return token.startsWith("-");
|
|
60
|
+
}
|
|
61
|
+
function extractRequestedSpecs(args) {
|
|
62
|
+
const specs = [];
|
|
63
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
64
|
+
const token = args[index];
|
|
65
|
+
if (token === "--") {
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
if (!isFlag(token)) {
|
|
69
|
+
specs.push(token);
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (token.includes("=")) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (FLAGS_WITH_VALUES.has(token)) {
|
|
76
|
+
index += 1;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return specs;
|
|
80
|
+
}
|
|
81
|
+
function parseRequestedPackage(raw) {
|
|
82
|
+
if (raw.startsWith("github:") ||
|
|
83
|
+
raw.startsWith("git+ssh://") ||
|
|
84
|
+
raw.startsWith("git+https://") ||
|
|
85
|
+
raw.startsWith("git@")) {
|
|
86
|
+
return {
|
|
87
|
+
name: raw,
|
|
88
|
+
raw,
|
|
89
|
+
requested: raw,
|
|
90
|
+
sourceType: "git"
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
const parsed = raw.startsWith("workspace:")
|
|
94
|
+
? {
|
|
95
|
+
name: raw.replace(/^workspace:/, ""),
|
|
96
|
+
rawSpec: raw,
|
|
97
|
+
type: "directory"
|
|
98
|
+
}
|
|
99
|
+
: (0, npm_package_arg_1.default)(raw);
|
|
100
|
+
const sourceType = raw.startsWith("workspace:") ? "workspace" : classifySourceType(parsed);
|
|
101
|
+
const name = parsed.name ?? raw;
|
|
102
|
+
const requested = raw.startsWith("workspace:")
|
|
103
|
+
? raw
|
|
104
|
+
: parsed.type === "version" || parsed.type === "range" || parsed.type === "tag"
|
|
105
|
+
? parsed.rawSpec ?? "latest"
|
|
106
|
+
: raw;
|
|
107
|
+
return {
|
|
108
|
+
name,
|
|
109
|
+
raw,
|
|
110
|
+
requested,
|
|
111
|
+
sourceType,
|
|
112
|
+
registrySpecKind: raw.startsWith("workspace:")
|
|
113
|
+
? undefined
|
|
114
|
+
: classifyRegistrySpecKind(parsed)
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function isSupportedInstallCommand(manager, command) {
|
|
118
|
+
const normalized = command.toLowerCase();
|
|
119
|
+
if (manager === "npm") {
|
|
120
|
+
return normalized === "install" || normalized === "ci";
|
|
121
|
+
}
|
|
122
|
+
if (manager === "pnpm") {
|
|
123
|
+
return normalized === "install" || normalized === "add";
|
|
124
|
+
}
|
|
125
|
+
return normalized === "install" || normalized === "add";
|
|
126
|
+
}
|
|
127
|
+
function splitManagerArgsAndCommand(argv) {
|
|
128
|
+
const [managerRaw, ...rest] = argv;
|
|
129
|
+
const manager = managerRaw;
|
|
130
|
+
if (!manager || (manager !== "npm" && manager !== "pnpm" && manager !== "bun")) {
|
|
131
|
+
throw new Error("Usage: safeinstall <npm|pnpm|bun> <install-command> [...args]");
|
|
132
|
+
}
|
|
133
|
+
const preCommandArgs = [];
|
|
134
|
+
for (let index = 0; index < rest.length; index += 1) {
|
|
135
|
+
const token = rest[index];
|
|
136
|
+
if (!isFlag(token)) {
|
|
137
|
+
return {
|
|
138
|
+
manager,
|
|
139
|
+
managerArgs: preCommandArgs,
|
|
140
|
+
command: token,
|
|
141
|
+
forwardedArgs: rest.slice(index + 1)
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
preCommandArgs.push(token);
|
|
145
|
+
if (!token.includes("=") && FLAGS_WITH_VALUES.has(token) && rest[index + 1]) {
|
|
146
|
+
preCommandArgs.push(rest[index + 1]);
|
|
147
|
+
index += 1;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
throw new Error(`Missing command for ${manager}.`);
|
|
151
|
+
}
|
|
152
|
+
function buildInstallPlan(argv) {
|
|
153
|
+
const { manager, managerArgs, command, forwardedArgs } = splitManagerArgsAndCommand(argv);
|
|
154
|
+
if (!isSupportedInstallCommand(manager, command)) {
|
|
155
|
+
throw new Error(`Unsupported command: ${manager} ${command}. SafeInstall supports install/add flows only.`);
|
|
156
|
+
}
|
|
157
|
+
const requestedSpecs = extractRequestedSpecs(forwardedArgs);
|
|
158
|
+
const packages = requestedSpecs.map(parseRequestedPackage);
|
|
159
|
+
return {
|
|
160
|
+
manager,
|
|
161
|
+
command,
|
|
162
|
+
managerArgs,
|
|
163
|
+
forwardedArgs,
|
|
164
|
+
packages,
|
|
165
|
+
projectInstall: packages.length === 0
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
function parseManifestDependency(name, spec) {
|
|
169
|
+
if (spec.startsWith("workspace:")) {
|
|
170
|
+
return {
|
|
171
|
+
name,
|
|
172
|
+
raw: `${name}@${spec}`,
|
|
173
|
+
requested: spec,
|
|
174
|
+
sourceType: "workspace"
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
const parsed = npm_package_arg_1.default.resolve(name, spec);
|
|
178
|
+
return {
|
|
179
|
+
name,
|
|
180
|
+
raw: `${name}@${spec}`,
|
|
181
|
+
requested: parsed.rawSpec ?? spec,
|
|
182
|
+
sourceType: spec.startsWith("workspace:") ? "workspace" : classifySourceType(parsed),
|
|
183
|
+
registrySpecKind: spec.startsWith("workspace:") ? undefined : classifyRegistrySpecKind(parsed)
|
|
184
|
+
};
|
|
185
|
+
}
|
package/dist/types.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "safeinstall-cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Local-first CLI that blocks risky npm, pnpm, and bun installs before they run. Open source.",
|
|
5
|
+
"packageManager": "pnpm@10.17.0",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"security",
|
|
9
|
+
"supply-chain",
|
|
10
|
+
"npm",
|
|
11
|
+
"pnpm",
|
|
12
|
+
"bun",
|
|
13
|
+
"cli",
|
|
14
|
+
"vibe-coding",
|
|
15
|
+
"ai-coding"
|
|
16
|
+
],
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"README.md",
|
|
20
|
+
"LICENSE",
|
|
21
|
+
"CHANGELOG.md",
|
|
22
|
+
"SUPPORT.md",
|
|
23
|
+
"safeinstall.config.example.json"
|
|
24
|
+
],
|
|
25
|
+
"bin": {
|
|
26
|
+
"safeinstall": "dist/cli.js"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/Mickdownunder/SafeInstall.git"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://safeinstall.dev",
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc -p tsconfig.build.json",
|
|
38
|
+
"dev": "pnpm build && node dist/cli.js",
|
|
39
|
+
"prepack": "pnpm build",
|
|
40
|
+
"pack:smoke": "node scripts/pack-smoke.mjs",
|
|
41
|
+
"release:check": "pnpm typecheck && pnpm test && pnpm build && pnpm pack:smoke",
|
|
42
|
+
"test": "vitest run",
|
|
43
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
44
|
+
},
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=20.0.0"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"npm-package-arg": "^12.0.2",
|
|
50
|
+
"semver": "^7.7.2",
|
|
51
|
+
"yaml": "^2.8.3"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@types/node": "^24.6.0",
|
|
55
|
+
"@types/npm-package-arg": "^6.1.4",
|
|
56
|
+
"@types/semver": "^7.7.1",
|
|
57
|
+
"typescript": "^5.9.3",
|
|
58
|
+
"vitest": "^3.2.4"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"minimumReleaseAgeHours": 72,
|
|
3
|
+
"registryUrl": "https://registry.npmjs.org",
|
|
4
|
+
"allowedScripts": {
|
|
5
|
+
"esbuild": ["postinstall"]
|
|
6
|
+
},
|
|
7
|
+
"allowedSources": ["registry", "workspace", "file", "directory"],
|
|
8
|
+
"allowedPackages": [],
|
|
9
|
+
"ciMode": true,
|
|
10
|
+
"packageManagerDefaults": {
|
|
11
|
+
"npm": {
|
|
12
|
+
"ignoreScripts": true
|
|
13
|
+
},
|
|
14
|
+
"pnpm": {
|
|
15
|
+
"ignoreScripts": true
|
|
16
|
+
},
|
|
17
|
+
"bun": {
|
|
18
|
+
"ignoreScripts": true
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|