Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 34 additions & 6 deletions crates/socket-patch-cli/src/commands/setup.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use clap::Args;
use socket_patch_core::package_json::find::{find_package_json_files, WorkspaceType};
use socket_patch_core::package_json::detect::PackageManager;
use socket_patch_core::package_json::find::{
detect_package_manager, find_package_json_files, WorkspaceType,
};
use socket_patch_core::package_json::update::{update_package_json, UpdateStatus};
use std::io::{self, Write};
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -62,14 +65,20 @@ pub async fn run(args: SetupArgs) -> i32 {
return 0;
}

// Detect package manager from lockfiles in the project root.
let pm = detect_package_manager(&args.cwd).await;

if !args.json {
println!("Found {} package.json file(s)", package_json_files.len());
if pm == PackageManager::Pnpm {
println!("Detected pnpm project (using pnpm dlx)");
}
}

// Preview changes (always preview first)
let mut preview_results = Vec::new();
for loc in &package_json_files {
let result = update_package_json(&loc.path, true).await;
let result = update_package_json(&loc.path, true, pm).await;
preview_results.push(result);
}

Expand All @@ -96,11 +105,20 @@ pub async fn run(args: SetupArgs) -> i32 {
let rel_path = pathdiff(&result.path, &args.cwd);
println!(" + {rel_path}");
if result.old_script.is_empty() {
println!(" Current: (no postinstall script)");
println!(" postinstall: (no script)");
} else {
println!(" postinstall: \"{}\"", result.old_script);
}
println!(" -> postinstall: \"{}\"", result.new_script);
if result.old_dependencies_script.is_empty() {
println!(" dependencies: (no script)");
} else {
println!(" Current: \"{}\"", result.old_script);
println!(" dependencies: \"{}\"", result.old_dependencies_script);
}
println!(" New: \"{}\"", result.new_script);
println!(
" -> dependencies: \"{}\"",
result.new_dependencies_script
);
}
println!();
}
Expand Down Expand Up @@ -177,7 +195,7 @@ pub async fn run(args: SetupArgs) -> i32 {
}
let mut results = Vec::new();
for loc in &package_json_files {
let result = update_package_json(&loc.path, false).await;
let result = update_package_json(&loc.path, false, pm).await;
results.push(result);
}

Expand All @@ -191,6 +209,10 @@ pub async fn run(args: SetupArgs) -> i32 {
"updated": updated,
"alreadyConfigured": already,
"errors": errs,
"packageManager": match pm {
PackageManager::Npm => "npm",
PackageManager::Pnpm => "pnpm",
},
"files": results.iter().map(|r| {
serde_json::json!({
"path": r.path,
Expand Down Expand Up @@ -225,6 +247,10 @@ pub async fn run(args: SetupArgs) -> i32 {
"alreadyConfigured": already,
"errors": errs,
"dryRun": true,
"packageManager": match pm {
PackageManager::Npm => "npm",
PackageManager::Pnpm => "pnpm",
},
"files": preview_results.iter().map(|r| {
serde_json::json!({
"path": r.path,
Expand All @@ -235,6 +261,8 @@ pub async fn run(args: SetupArgs) -> i32 {
},
"oldScript": r.old_script,
"newScript": r.new_script,
"oldDependenciesScript": r.old_dependencies_script,
"newDependenciesScript": r.new_dependencies_script,
"error": r.error,
})
}).collect::<Vec<_>>(),
Expand Down
Loading
Loading