@gkiely/safe-install 0.1.6 → 0.1.8

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 CHANGED
@@ -68,6 +68,12 @@ You can pass npm install args through:
68
68
  npm run safe-install left-pad@latest
69
69
  ```
70
70
 
71
+ You can run npm update through the same command:
72
+
73
+ ```sh
74
+ npm run safe-install -- update
75
+ ```
76
+
71
77
  ## What `safe-install` does
72
78
 
73
79
  `safe-install` runs npm install with scripts blocked, then runs install scripts only for packages listed in
package/dist/index.d.ts CHANGED
@@ -16,6 +16,9 @@ type PackageLock = {
16
16
  type ParsedCommand = {
17
17
  kind: "install";
18
18
  args: string[];
19
+ } | {
20
+ kind: "update";
21
+ args: string[];
19
22
  } | {
20
23
  kind: "review-deps";
21
24
  } | {
@@ -29,8 +32,10 @@ type SafeInstallConfig = {
29
32
  export declare function getSafeInstallConfig(pkg: PackageJson): SafeInstallConfig;
30
33
  export declare function assertNoBlockedExoticSubdeps(config: SafeInstallConfig, packageLock: PackageLock): void;
31
34
  export declare function getInstallArgs(args?: readonly string[]): string[];
35
+ export declare function getUpdateArgs(args?: readonly string[]): string[];
32
36
  export declare function parseCommand(args: readonly string[]): ParsedCommand;
33
37
  export declare function reviewDepsCommand(): void;
34
38
  export declare function installCommand(args?: readonly string[]): void;
39
+ export declare function updateCommand(args?: readonly string[]): void;
35
40
  export declare function main(args?: string[]): void;
36
41
  export {};
package/dist/index.js CHANGED
@@ -118,13 +118,20 @@ 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
+ }
121
124
  export function parseCommand(args) {
122
125
  if (args.includes("--help") || args.includes("-h")) {
123
126
  return { kind: "help" };
124
127
  }
125
- if (args[0] === "--" && args[1] === "review-deps") {
128
+ if ((args[0] === "--" && args[1] === "review-deps") ||
129
+ args[0] === "review-deps") {
126
130
  return { kind: "review-deps" };
127
131
  }
132
+ if (args[0] === "--" && args[1] === "update") {
133
+ return { kind: "update", args: args.slice(2) };
134
+ }
128
135
  return { kind: "install", args: args.filter((arg) => arg !== "--") };
129
136
  }
130
137
  function printHelp() {
@@ -135,6 +142,8 @@ Usage:
135
142
  Run npm install with scripts disabled, then rebuild trusted dependencies
136
143
  safe-install -- review-deps
137
144
  List dependencies that declare install-time scripts
145
+ safe-install -- update [npm update args]
146
+ Run npm update with scripts disabled, then rebuild trusted dependencies
138
147
  `);
139
148
  }
140
149
  export function reviewDepsCommand() {
@@ -151,10 +160,16 @@ export function reviewDepsCommand() {
151
160
  console.log("Review these packages before adding them to trustedDependencies.");
152
161
  }
153
162
  export function installCommand(args = []) {
163
+ runPackageManagerThenRebuild(getInstallArgs(args));
164
+ }
165
+ export function updateCommand(args = []) {
166
+ runPackageManagerThenRebuild(getUpdateArgs(args));
167
+ }
168
+ function runPackageManagerThenRebuild(npmArgs) {
154
169
  const pkg = readPackageJson();
155
170
  const config = getSafeInstallConfig(pkg);
156
171
  const trustedDependencies = getTrustedDependencies(pkg);
157
- run("npm", getInstallArgs(args));
172
+ run("npm", [...npmArgs]);
158
173
  if (existsSync("package-lock.json")) {
159
174
  assertNoBlockedExoticSubdeps(config, readPackageLock());
160
175
  }
@@ -172,6 +187,10 @@ export function main(args = process.argv.slice(2)) {
172
187
  reviewDepsCommand();
173
188
  return;
174
189
  }
190
+ if (command.kind === "update") {
191
+ updateCommand(command.args);
192
+ return;
193
+ }
175
194
  installCommand(command.args);
176
195
  }
177
196
  if (process.argv[1] && realpathSync(fileURLToPath(import.meta.url)) === realpathSync(process.argv[1])) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gkiely/safe-install",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
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": {