Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix pacquet executer #41

Merged
merged 2 commits into from Jul 31, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/cli/src/commands.rs
Expand Up @@ -87,6 +87,10 @@ impl AddArgs {
pub struct RunArgs {
/// A pre-defined package script.
pub command: String,

/// Any additional arguments passed after the script name
pub args: Vec<String>,

/// You can use the --if-present flag to avoid exiting with a non-zero exit code when the
/// script is undefined. This lets you run potentially undefined scripts without breaking the
/// execution chain.
Expand Down
7 changes: 6 additions & 1 deletion crates/cli/src/lib.rs
Expand Up @@ -70,7 +70,12 @@ async fn run_commands(cli: Cli) -> Result<()> {
Subcommands::Run(args) => {
let package_json = PackageJson::from_path(&package_json_path)?;
if let Some(script) = package_json.get_script(&args.command, args.if_present)? {
execute_shell(script)?;
let mut command = script.to_string();
// append an empty space between script and additional args
command.push(' ');
// then append the additional args
command.push_str(args.args.join(" ").as_str());
execute_shell(command.trim())?;
}
}
Subcommands::Start => {
Expand Down
2 changes: 1 addition & 1 deletion crates/executor/src/lib.rs
Expand Up @@ -12,7 +12,7 @@ pub enum ExecutorError {
}

pub fn execute_shell(command: &str) -> Result<(), ExecutorError> {
let mut cmd = Command::new(command).spawn()?;
let mut cmd = Command::new("sh").arg("-c").arg(command).spawn()?;

cmd.wait()?;

Expand Down