Skip to content

Commit cd758d8

Browse files
committed
feat: support yarn/pnpm via -p flag
1 parent 591acbe commit cd758d8

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

src/lib.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,16 @@ pub struct Script {
4646
pub package_name: String,
4747
config: CommandConfig,
4848
pub dir: PathBuf,
49+
package_manager: String,
4950
}
5051

5152
impl Script {
52-
pub fn new(config: CommandConfig, dir: &PathBuf, package_name: &str) -> Self {
53+
pub fn new(
54+
config: CommandConfig,
55+
dir: &PathBuf,
56+
package_name: &str,
57+
package_manager: String,
58+
) -> Self {
5359
let name = config.command.clone();
5460

5561
let mut status = ScriptStatus::Ready;
@@ -63,13 +69,14 @@ impl Script {
6369
dir: dir.into(),
6470
command: name.to_string(),
6571
status,
72+
package_manager,
6673
}
6774
}
6875

6976
pub fn execute(&mut self) -> Child {
7077
self.status = ScriptStatus::Running;
7178

72-
let mut command = Command::new("npm");
79+
let mut command = Command::new(self.package_manager.clone());
7380

7481
let mut child = command
7582
.current_dir(&self.dir)

src/main.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use hasty::{self, make_script_id, Engine, Script, TOPOLOGICAL_DEP_PREFIX};
44
#[tokio::main]
55
async fn main() {
66
let options = hasty::options::HastyOptions::parse();
7+
println!("Using package manager: {}", options.package_manager.clone());
78

89
if let Some(ref dir) = options.dir {
910
println!("dir: {}", dir.display());
@@ -25,6 +26,7 @@ async fn main() {
2526
config.pipeline.get(&opts_script).unwrap().clone(),
2627
dir,
2728
"__ROOT__",
29+
options.package_manager.clone(),
2830
);
2931

3032
engine.add_script(&script);
@@ -49,7 +51,12 @@ async fn main() {
4951
continue;
5052
}
5153

52-
let s = Script::new(config.pipeline.get(&s).unwrap().clone(), dir, "__ROOT__");
54+
let s = Script::new(
55+
config.pipeline.get(&s).unwrap().clone(),
56+
dir,
57+
"__ROOT__",
58+
options.package_manager.clone(),
59+
);
5360
engine.add_script(&s);
5461

5562
if s.has_dependencies() {

src/options.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,18 @@ use serde::Deserialize;
77
#[clap(author, version, about, long_about = None)]
88
#[derive(Deserialize)]
99
pub struct HastyOptions {
10-
// The directory of the project
10+
/// The directory of the project
1111
#[arg(short, long)]
1212
pub dir: Option<PathBuf>,
1313

14-
// The script to execute
14+
/// The script to execute
1515
pub script: Option<String>,
16+
17+
/// Package manager
18+
///
19+
/// Valid options are "npm", "yarn", "pnpm"
20+
///
21+
/// Default: "npm"
22+
#[arg(short, long, default_value_t = String::from("npm"))]
23+
pub package_manager: String,
1624
}

0 commit comments

Comments
 (0)