11use clap:: Args ;
2- use socket_patch_core:: package_json:: find:: { find_package_json_files, WorkspaceType } ;
2+ use socket_patch_core:: package_json:: detect:: PackageManager ;
3+ use socket_patch_core:: package_json:: find:: {
4+ detect_package_manager, find_package_json_files, WorkspaceType ,
5+ } ;
36use socket_patch_core:: package_json:: update:: { update_package_json, UpdateStatus } ;
47use std:: io:: { self , Write } ;
58use std:: path:: { Path , PathBuf } ;
@@ -62,14 +65,20 @@ pub async fn run(args: SetupArgs) -> i32 {
6265 return 0 ;
6366 }
6467
68+ // Detect package manager from lockfiles in the project root.
69+ let pm = detect_package_manager ( & args. cwd ) . await ;
70+
6571 if !args. json {
6672 println ! ( "Found {} package.json file(s)" , package_json_files. len( ) ) ;
73+ if pm == PackageManager :: Pnpm {
74+ println ! ( "Detected pnpm project (using pnpm dlx)" ) ;
75+ }
6776 }
6877
6978 // Preview changes (always preview first)
7079 let mut preview_results = Vec :: new ( ) ;
7180 for loc in & package_json_files {
72- let result = update_package_json ( & loc. path , true ) . await ;
81+ let result = update_package_json ( & loc. path , true , pm ) . await ;
7382 preview_results. push ( result) ;
7483 }
7584
@@ -96,11 +105,20 @@ pub async fn run(args: SetupArgs) -> i32 {
96105 let rel_path = pathdiff ( & result. path , & args. cwd ) ;
97106 println ! ( " + {rel_path}" ) ;
98107 if result. old_script . is_empty ( ) {
99- println ! ( " Current: (no postinstall script)" ) ;
108+ println ! ( " postinstall: (no script)" ) ;
109+ } else {
110+ println ! ( " postinstall: \" {}\" " , result. old_script) ;
111+ }
112+ println ! ( " -> postinstall: \" {}\" " , result. new_script) ;
113+ if result. old_dependencies_script . is_empty ( ) {
114+ println ! ( " dependencies: (no script)" ) ;
100115 } else {
101- println ! ( " Current : \" {}\" " , result. old_script ) ;
116+ println ! ( " dependencies : \" {}\" " , result. old_dependencies_script ) ;
102117 }
103- println ! ( " New: \" {}\" " , result. new_script) ;
118+ println ! (
119+ " -> dependencies: \" {}\" " ,
120+ result. new_dependencies_script
121+ ) ;
104122 }
105123 println ! ( ) ;
106124 }
@@ -177,7 +195,7 @@ pub async fn run(args: SetupArgs) -> i32 {
177195 }
178196 let mut results = Vec :: new ( ) ;
179197 for loc in & package_json_files {
180- let result = update_package_json ( & loc. path , false ) . await ;
198+ let result = update_package_json ( & loc. path , false , pm ) . await ;
181199 results. push ( result) ;
182200 }
183201
@@ -191,6 +209,10 @@ pub async fn run(args: SetupArgs) -> i32 {
191209 "updated" : updated,
192210 "alreadyConfigured" : already,
193211 "errors" : errs,
212+ "packageManager" : match pm {
213+ PackageManager :: Npm => "npm" ,
214+ PackageManager :: Pnpm => "pnpm" ,
215+ } ,
194216 "files" : results. iter( ) . map( |r| {
195217 serde_json:: json!( {
196218 "path" : r. path,
@@ -225,6 +247,10 @@ pub async fn run(args: SetupArgs) -> i32 {
225247 "alreadyConfigured" : already,
226248 "errors" : errs,
227249 "dryRun" : true ,
250+ "packageManager" : match pm {
251+ PackageManager :: Npm => "npm" ,
252+ PackageManager :: Pnpm => "pnpm" ,
253+ } ,
228254 "files" : preview_results. iter( ) . map( |r| {
229255 serde_json:: json!( {
230256 "path" : r. path,
@@ -235,6 +261,8 @@ pub async fn run(args: SetupArgs) -> i32 {
235261 } ,
236262 "oldScript" : r. old_script,
237263 "newScript" : r. new_script,
264+ "oldDependenciesScript" : r. old_dependencies_script,
265+ "newDependenciesScript" : r. new_dependencies_script,
238266 "error" : r. error,
239267 } )
240268 } ) . collect:: <Vec <_>>( ) ,
0 commit comments