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
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion crates/vite_task/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ derive_more = { workspace = true, features = ["from"] }
diff-struct = { workspace = true }
fspy = { workspace = true }
futures-util = { workspace = true }
monostate = { workspace = true }
once_cell = { workspace = true }
owo-colors = { workspace = true }
petgraph = { workspace = true }
Expand Down
9 changes: 2 additions & 7 deletions crates/vite_task/src/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ use std::{ffi::OsStr, fmt::Debug, sync::Arc};
use cache::ExecutionCache;
pub use cache::{CacheMiss, FingerprintMismatch};
pub use event::ExecutionEvent;
use monostate::MustBe;
use once_cell::sync::OnceCell;
pub use reporter::ExitStatus;
use reporter::LabeledReporter;
use vite_path::{AbsolutePath, AbsolutePathBuf};
use vite_str::Str;
use vite_task_graph::{
IndexedTaskGraph, TaskGraph, TaskGraphLoadError,
config::user::{UserCacheConfig, UserTaskOptions},
IndexedTaskGraph, TaskGraph, TaskGraphLoadError, config::user::UserCacheConfig,
loader::UserConfigLoader,
};
use vite_task_plan::{
Expand Down Expand Up @@ -105,10 +103,7 @@ impl vite_task_plan::PlanRequestParser for PlanRequestParser<'_> {
Command::Cache { .. } => Ok(Some(PlanRequest::Synthetic(SyntheticPlanRequest {
program: Arc::from(OsStr::new(command.program.as_str())),
args: Arc::clone(&command.args),
task_options: UserTaskOptions {
cache_config: UserCacheConfig::Disabled { cache: MustBe!(false) },
..Default::default()
},
cache_config: UserCacheConfig::disabled(),
envs: Arc::clone(&command.envs),
}))),
Command::Run(run_command) => Ok(Some(run_command.into_plan_request(&command.cwd)?)),
Expand Down
20 changes: 8 additions & 12 deletions crates/vite_task_bin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use vite_path::AbsolutePath;
use vite_str::Str;
use vite_task::{
Command, EnabledCacheConfig, HandledCommand, ScriptCommand, SessionCallbacks, UserCacheConfig,
UserTaskOptions, get_path_env, plan_request::SyntheticPlanRequest,
get_path_env, plan_request::SyntheticPlanRequest,
};

#[derive(Debug, Default)]
Expand Down Expand Up @@ -48,7 +48,10 @@ fn synthesize_node_modules_bin_task(
Ok(SyntheticPlanRequest {
program: find_executable(get_path_env(envs), &*cwd, executable_name)?,
args: args.into(),
task_options: Default::default(),
cache_config: UserCacheConfig::with_config(EnabledCacheConfig {
envs: None,
pass_through_envs: None,
}),
envs: Arc::clone(envs),
})
}
Expand Down Expand Up @@ -108,16 +111,9 @@ impl vite_task::CommandHandler for CommandHandler {
Ok(HandledCommand::Synthesized(SyntheticPlanRequest {
program: find_executable(get_path_env(&envs), &*command.cwd, "print-env")?,
args: [name.clone()].into(),
task_options: UserTaskOptions {
cache_config: UserCacheConfig::Enabled {
cache: None,
enabled_cache_config: EnabledCacheConfig {
envs: None,
pass_through_envs: Some(vec![name]),
},
},
..Default::default()
},
cache_config: UserCacheConfig::with_config({
EnabledCacheConfig { envs: None, pass_through_envs: Some(vec![name]) }
}),
envs: Arc::new(envs),
}))
}
Expand Down
18 changes: 7 additions & 11 deletions crates/vite_task_bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{process::ExitCode, sync::Arc};
use clap::Parser;
use vite_str::Str;
use vite_task::{
EnabledCacheConfig, ExitStatus, Session, UserCacheConfig, UserTaskOptions, get_path_env,
EnabledCacheConfig, ExitStatus, Session, UserCacheConfig, get_path_env,
plan_request::SyntheticPlanRequest,
};
use vite_task_bin::{Args, OwnedSessionCallbacks, find_executable};
Expand All @@ -29,16 +29,12 @@ async fn run() -> anyhow::Result<ExitStatus> {
let request = SyntheticPlanRequest {
program,
args: [Str::from("FOO")].into(),
task_options: UserTaskOptions {
cache_config: UserCacheConfig::Enabled {
cache: None,
enabled_cache_config: EnabledCacheConfig {
envs: Some(Box::from([Str::from("FOO")])),
pass_through_envs: None,
},
},
..Default::default()
},
cache_config: UserCacheConfig::with_config({
EnabledCacheConfig {
envs: Some(Box::from([Str::from("FOO")])),
pass_through_envs: None,
}
}),
envs: Arc::clone(envs),
};
let cache_key: Arc<[Str]> = Arc::from([Str::from("print-env-foo")]);
Expand Down
2 changes: 2 additions & 0 deletions crates/vite_task_graph/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ pub struct ResolvedTaskOptions {

impl ResolvedTaskOptions {
/// Resolves from user-defined options and the directory path where the options are defined.
/// For user-defined tasks or scripts in package.json, `dir` is the package directory
/// For synthetic tasks, `dir` is the cwd of the original command (e.g. the cwd of `vp lint`).
pub fn resolve(user_options: UserTaskOptions, dir: &Arc<AbsolutePath>) -> Self {
let cwd: Arc<AbsolutePath> = match user_options.cwd_relative_to_package {
Some(ref cwd) if !cwd.as_str().is_empty() => dir.join(cwd).into(),
Expand Down
12 changes: 12 additions & 0 deletions crates/vite_task_graph/src/config/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ pub enum UserCacheConfig {
},
}

impl UserCacheConfig {
/// Create an enabled cache config with the given `EnabledCacheConfig`.
pub fn with_config(config: EnabledCacheConfig) -> Self {
UserCacheConfig::Enabled { cache: Some(MustBe!(true)), enabled_cache_config: config }
}

/// Create a disabled cache config.
pub fn disabled() -> Self {
UserCacheConfig::Disabled { cache: MustBe!(false) }
}
}

/// Cache configuration fields when caching is enabled
#[derive(Debug, Deserialize, PartialEq, Eq)]
#[cfg_attr(test, derive(TS), ts(optional_fields))]
Expand Down
17 changes: 14 additions & 3 deletions crates/vite_task_plan/src/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ use futures_util::FutureExt;
use vite_path::{AbsolutePath, AbsolutePathBuf, RelativePathBuf, relative::InvalidPathDataError};
use vite_shell::try_parse_as_and_list;
use vite_str::Str;
use vite_task_graph::{TaskNodeIndex, config::ResolvedTaskOptions};
use vite_task_graph::{
TaskNodeIndex,
config::{ResolvedTaskOptions, user::UserTaskOptions},
};

use crate::{
ExecutionItem, ExecutionItemDisplay, ExecutionItemKind, LeafExecutionKind, PlanContext,
Expand Down Expand Up @@ -290,10 +293,18 @@ pub fn plan_synthetic_request(
execution_cache_key: Option<ExecutionCacheKey>,
cwd: &Arc<AbsolutePath>,
) -> Result<SpawnExecution, TaskPlanErrorKind> {
let SyntheticPlanRequest { program, args, task_options, envs } = synthetic_plan_request;
let SyntheticPlanRequest { program, args, cache_config, envs } = synthetic_plan_request;

let program_path = which(&program, &envs, cwd).map_err(TaskPlanErrorKind::ProgramNotFound)?;
let resolved_options = ResolvedTaskOptions::resolve(task_options, &cwd);
let resolved_options = ResolvedTaskOptions::resolve(
UserTaskOptions {
cache_config,
// cwd_relative_to_package and depends_on don't make sense for synthetic tasks.
cwd_relative_to_package: None,
depends_on: None,
},
&cwd,
);

plan_spawn_execution(
workspace_path,
Expand Down
6 changes: 3 additions & 3 deletions crates/vite_task_plan/src/plan_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{collections::HashMap, ffi::OsStr, sync::Arc};

use vite_path::AbsolutePath;
use vite_str::Str;
use vite_task_graph::{config::user::UserTaskOptions, query::TaskQuery};
use vite_task_graph::{config::UserCacheConfig, query::TaskQuery};

/// A parsed command from a task script, passed to [`super::PlanRequestParser::get_plan_request`].
///
Expand Down Expand Up @@ -43,8 +43,8 @@ pub struct SyntheticPlanRequest {
/// The arguments to pass to the program
pub args: Arc<[Str]>,

/// The task options as if it's defined in `vite.config.*`
pub task_options: UserTaskOptions,
/// The cache config as if it's defined in `vite.config.*`
pub cache_config: UserCacheConfig,

/// All environment variables to set for the synthetic task.
///
Expand Down