File tree Expand file tree Collapse file tree 4 files changed +34
-12
lines changed
Expand file tree Collapse file tree 4 files changed +34
-12
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,12 @@ const config: CliCommandConfig = {
1515 description : 'Fix "fixable" Socket alerts' ,
1616 hidden : true ,
1717 flags : {
18- ...commonFlags
18+ ...commonFlags ,
19+ testScript : {
20+ type : 'string' ,
21+ default : 'test' ,
22+ description : 'The test script to run for each fix attempt'
23+ }
1924 } ,
2025 help : ( command , config ) => `
2126 Usage
@@ -49,5 +54,7 @@ async function run(
4954 return
5055 }
5156
52- await runFix ( )
57+ await runFix ( {
58+ testScript : cli . flags [ 'testScript' ] as string | undefined
59+ } )
5360}
Original file line number Diff line number Diff line change @@ -29,15 +29,20 @@ function isTopLevel(tree: SafeNode, node: SafeNode): boolean {
2929}
3030
3131type NpmFixOptions = {
32+ cwd ?: string | undefined
3233 spinner ?: Spinner | undefined
34+ testScript ?: string | undefined
3335}
3436
3537export async function npmFix (
3638 _pkgEnvDetails : EnvDetails ,
37- cwd : string ,
3839 options ?: NpmFixOptions | undefined
3940) {
40- const { spinner } = { __proto__ : null , ...options } as NpmFixOptions
41+ const {
42+ cwd = process . cwd ( ) ,
43+ spinner,
44+ testScript = 'test'
45+ } = { __proto__ : null , ...options } as NpmFixOptions
4146
4247 spinner ?. start ( )
4348
@@ -113,7 +118,7 @@ export async function npmFix(
113118 ) {
114119 try {
115120 // eslint-disable-next-line no-await-in-loop
116- await runScript ( 'test' , [ ] , { spinner, stdio : 'ignore' } )
121+ await runScript ( testScript , [ ] , { spinner, stdio : 'ignore' } )
117122
118123 spinner ?. info ( `Patched ${ name } ${ oldVersion } -> ${ node . version } ` )
119124
Original file line number Diff line number Diff line change 11import { readWantedLockfile } from '@pnpm/lockfile.fs'
22
33import { getManifestData } from '@socketsecurity/registry'
4+ import { runScript } from '@socketsecurity/registry/lib/npm'
45import {
56 fetchPackagePackument ,
67 readPackageJson
@@ -25,15 +26,20 @@ import type { Spinner } from '@socketsecurity/registry/lib/spinner'
2526const { NPM , OVERRIDES , PNPM } = constants
2627
2728type PnpmFixOptions = {
29+ cwd ?: string | undefined
2830 spinner ?: Spinner | undefined
31+ testScript ?: string | undefined
2932}
3033
3134export async function pnpmFix (
3235 pkgEnvDetails : EnvDetails ,
33- cwd : string ,
3436 options ?: PnpmFixOptions | undefined
3537) {
36- const { spinner } = { __proto__ : null , ...options } as PnpmFixOptions
38+ const {
39+ cwd = process . cwd ( ) ,
40+ spinner,
41+ testScript = 'test'
42+ } = { __proto__ : null , ...options } as PnpmFixOptions
3743
3844 spinner ?. start ( )
3945
@@ -125,6 +131,8 @@ export async function pnpmFix(
125131 }
126132 }
127133 } )
134+ // eslint-disable-next-line no-await-in-loop
135+ await runScript ( testScript , [ ] , { spinner, stdio : 'ignore' } )
128136
129137 spinner ?. info ( `Patched ${ name } ${ oldVersion } -> ${ node . version } ` )
130138
Original file line number Diff line number Diff line change @@ -9,14 +9,12 @@ const { NPM, PNPM } = constants
99
1010const CMD_NAME = 'socket fix'
1111
12- export async function runFix ( ) {
12+ export async function runFix ( { cwd = process . cwd ( ) , testScript = 'test' } ) {
1313 // Lazily access constants.spinner.
1414 const { spinner } = constants
1515
1616 spinner . start ( )
1717
18- const cwd = process . cwd ( )
19-
2018 const pkgEnvDetails = await detectAndValidatePackageEnvironment ( cwd , {
2119 cmdName : CMD_NAME ,
2220 logger
@@ -28,11 +26,15 @@ export async function runFix() {
2826
2927 switch ( pkgEnvDetails . agent ) {
3028 case NPM : {
31- await npmFix ( pkgEnvDetails , cwd )
29+ await npmFix ( pkgEnvDetails , {
30+ testScript
31+ } )
3232 break
3333 }
3434 case PNPM : {
35- await pnpmFix ( pkgEnvDetails , cwd )
35+ await pnpmFix ( pkgEnvDetails , {
36+ testScript
37+ } )
3638 break
3739 }
3840 }
You can’t perform that action at this time.
0 commit comments