@gkiely/safe-install 0.1.5 → 0.1.7
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 +13 -1
- package/dist/index.d.ts +14 -0
- package/dist/index.js +33 -10
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -38,7 +38,7 @@ ignore-scripts=true
|
|
|
38
38
|
4. Find dependencies that declare install-time scripts:
|
|
39
39
|
|
|
40
40
|
```sh
|
|
41
|
-
npm run safe-install review-deps
|
|
41
|
+
npm run safe-install -- review-deps
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
5. Review the output, then add trusted packages to `package.json`. You can also
|
|
@@ -62,6 +62,18 @@ specifiers.
|
|
|
62
62
|
npm run safe-install
|
|
63
63
|
```
|
|
64
64
|
|
|
65
|
+
You can pass npm install args through:
|
|
66
|
+
|
|
67
|
+
```sh
|
|
68
|
+
npm run safe-install left-pad@latest
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
You can run npm update through the same command:
|
|
72
|
+
|
|
73
|
+
```sh
|
|
74
|
+
npm run safe-install -- update
|
|
75
|
+
```
|
|
76
|
+
|
|
65
77
|
## What `safe-install` does
|
|
66
78
|
|
|
67
79
|
`safe-install` runs npm install with scripts blocked, then runs install scripts only for packages listed in
|
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,17 @@ type LockPackage = {
|
|
|
13
13
|
type PackageLock = {
|
|
14
14
|
packages?: Record<string, LockPackage>;
|
|
15
15
|
};
|
|
16
|
+
type ParsedCommand = {
|
|
17
|
+
kind: "install";
|
|
18
|
+
args: string[];
|
|
19
|
+
} | {
|
|
20
|
+
kind: "update";
|
|
21
|
+
args: string[];
|
|
22
|
+
} | {
|
|
23
|
+
kind: "review-deps";
|
|
24
|
+
} | {
|
|
25
|
+
kind: "help";
|
|
26
|
+
};
|
|
16
27
|
export declare function getTrustedDependencies(pkg: PackageJson): string[];
|
|
17
28
|
export declare function findInstallScriptDependencies(packageLock: PackageLock, trustedDependencies?: readonly string[]): string[];
|
|
18
29
|
type SafeInstallConfig = {
|
|
@@ -21,7 +32,10 @@ type SafeInstallConfig = {
|
|
|
21
32
|
export declare function getSafeInstallConfig(pkg: PackageJson): SafeInstallConfig;
|
|
22
33
|
export declare function assertNoBlockedExoticSubdeps(config: SafeInstallConfig, packageLock: PackageLock): void;
|
|
23
34
|
export declare function getInstallArgs(args?: readonly string[]): string[];
|
|
35
|
+
export declare function getUpdateArgs(args?: readonly string[]): string[];
|
|
36
|
+
export declare function parseCommand(args: readonly string[]): ParsedCommand;
|
|
24
37
|
export declare function reviewDepsCommand(): void;
|
|
25
38
|
export declare function installCommand(args?: readonly string[]): void;
|
|
39
|
+
export declare function updateCommand(args?: readonly string[]): void;
|
|
26
40
|
export declare function main(args?: string[]): void;
|
|
27
41
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -118,14 +118,31 @@ function run(command, args) {
|
|
|
118
118
|
export function getInstallArgs(args = []) {
|
|
119
119
|
return ["install", "--ignore-scripts", ...args];
|
|
120
120
|
}
|
|
121
|
+
export function getUpdateArgs(args = []) {
|
|
122
|
+
return ["update", "--ignore-scripts", ...args];
|
|
123
|
+
}
|
|
124
|
+
export function parseCommand(args) {
|
|
125
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
126
|
+
return { kind: "help" };
|
|
127
|
+
}
|
|
128
|
+
if (args[0] === "--" && args[1] === "review-deps") {
|
|
129
|
+
return { kind: "review-deps" };
|
|
130
|
+
}
|
|
131
|
+
if (args[0] === "--" && args[1] === "update") {
|
|
132
|
+
return { kind: "update", args: args.slice(2) };
|
|
133
|
+
}
|
|
134
|
+
return { kind: "install", args: args.filter((arg) => arg !== "--") };
|
|
135
|
+
}
|
|
121
136
|
function printHelp() {
|
|
122
137
|
console.log(`safe-install
|
|
123
138
|
|
|
124
139
|
Usage:
|
|
125
|
-
safe-install [npm install
|
|
140
|
+
safe-install [npm install args]
|
|
126
141
|
Run npm install with scripts disabled, then rebuild trusted dependencies
|
|
127
|
-
safe-install review-deps
|
|
142
|
+
safe-install -- review-deps
|
|
128
143
|
List dependencies that declare install-time scripts
|
|
144
|
+
safe-install -- update [npm update args]
|
|
145
|
+
Run npm update with scripts disabled, then rebuild trusted dependencies
|
|
129
146
|
`);
|
|
130
147
|
}
|
|
131
148
|
export function reviewDepsCommand() {
|
|
@@ -142,10 +159,16 @@ export function reviewDepsCommand() {
|
|
|
142
159
|
console.log("Review these packages before adding them to trustedDependencies.");
|
|
143
160
|
}
|
|
144
161
|
export function installCommand(args = []) {
|
|
162
|
+
runPackageManagerThenRebuild(getInstallArgs(args));
|
|
163
|
+
}
|
|
164
|
+
export function updateCommand(args = []) {
|
|
165
|
+
runPackageManagerThenRebuild(getUpdateArgs(args));
|
|
166
|
+
}
|
|
167
|
+
function runPackageManagerThenRebuild(npmArgs) {
|
|
145
168
|
const pkg = readPackageJson();
|
|
146
169
|
const config = getSafeInstallConfig(pkg);
|
|
147
170
|
const trustedDependencies = getTrustedDependencies(pkg);
|
|
148
|
-
run("npm",
|
|
171
|
+
run("npm", [...npmArgs]);
|
|
149
172
|
if (existsSync("package-lock.json")) {
|
|
150
173
|
assertNoBlockedExoticSubdeps(config, readPackageLock());
|
|
151
174
|
}
|
|
@@ -154,20 +177,20 @@ export function installCommand(args = []) {
|
|
|
154
177
|
}
|
|
155
178
|
}
|
|
156
179
|
export function main(args = process.argv.slice(2)) {
|
|
157
|
-
|
|
180
|
+
const command = parseCommand(args);
|
|
181
|
+
if (command.kind === "help") {
|
|
158
182
|
printHelp();
|
|
159
183
|
return;
|
|
160
184
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
installCommand(args.filter((arg) => arg !== "--"));
|
|
185
|
+
if (command.kind === "review-deps") {
|
|
186
|
+
reviewDepsCommand();
|
|
164
187
|
return;
|
|
165
188
|
}
|
|
166
|
-
if (command === "
|
|
167
|
-
|
|
189
|
+
if (command.kind === "update") {
|
|
190
|
+
updateCommand(command.args);
|
|
168
191
|
return;
|
|
169
192
|
}
|
|
170
|
-
|
|
193
|
+
installCommand(command.args);
|
|
171
194
|
}
|
|
172
195
|
if (process.argv[1] && realpathSync(fileURLToPath(import.meta.url)) === realpathSync(process.argv[1])) {
|
|
173
196
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gkiely/safe-install",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "Run npm installs with lifecycle scripts disabled, then rebuild explicitly trusted dependencies.",
|
|
5
5
|
"author": "Grant Kiely <grant@youneedawiki.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"prepublishOnly": "npm run typecheck && npm test",
|
|
48
48
|
"release": "npm run typecheck && npm test && npm version patch && npm publish --access public && git push --follow-tags",
|
|
49
49
|
"safe-install": "node dist/index.js",
|
|
50
|
-
"test": "node --test",
|
|
50
|
+
"test": "npm run build && node --test",
|
|
51
51
|
"typecheck": "tsc --noEmit"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|