diff options
Diffstat (limited to 'cli/tools')
-rw-r--r-- | cli/tools/task.rs | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/cli/tools/task.rs b/cli/tools/task.rs index 37a1aa1c9..7dd7e7bc4 100644 --- a/cli/tools/task.rs +++ b/cli/tools/task.rs @@ -65,7 +65,7 @@ pub async fn execute_script( deno_task_shell::execute(seq_list, env_vars, &cwd, Default::default()); let exit_code = local.run_until(future).await; Ok(exit_code) - } else if let Some(script) = package_json_scripts.get(task_name) { + } else if package_json_scripts.contains_key(task_name) { let package_json_deps_provider = factory.package_json_deps_provider(); let package_json_deps_installer = factory.package_json_deps_installer().await?; @@ -105,17 +105,34 @@ pub async fn execute_script( .unwrap() .to_owned(), }; - let script = get_script_with_args(script, cli_options); - output_task(task_name, &script); - let seq_list = deno_task_shell::parser::parse(&script) - .with_context(|| format!("Error parsing script '{task_name}'."))?; - let npx_commands = resolve_npm_commands(npm_resolver, node_resolver)?; - let env_vars = collect_env_vars(); - let local = LocalSet::new(); - let future = - deno_task_shell::execute(seq_list, env_vars, &cwd, npx_commands); - let exit_code = local.run_until(future).await; - Ok(exit_code) + + // At this point we already checked if the task name exists in package.json. + // We can therefore check for "pre" and "post" scripts too, since we're only + // dealing with package.json here and not deno.json + let task_names = vec![ + format!("pre{}", task_name), + task_name.clone(), + format!("post{}", task_name), + ]; + for task_name in task_names { + if let Some(script) = package_json_scripts.get(&task_name) { + let script = get_script_with_args(script, cli_options); + output_task(&task_name, &script); + let seq_list = deno_task_shell::parser::parse(&script) + .with_context(|| format!("Error parsing script '{task_name}'."))?; + let npx_commands = resolve_npm_commands(npm_resolver, node_resolver)?; + let env_vars = collect_env_vars(); + let local = LocalSet::new(); + let future = + deno_task_shell::execute(seq_list, env_vars, &cwd, npx_commands); + let exit_code = local.run_until(future).await; + if exit_code > 0 { + return Ok(exit_code); + } + } + } + + Ok(0) } else { eprintln!("Task not found: {task_name}"); print_available_tasks(&tasks_config, &package_json_scripts); |