diff --git a/Cargo.lock b/Cargo.lock index 304c5e47b7..d2915bc532 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4662,7 +4662,6 @@ dependencies = [ "bincode", "bstr", "nix 0.30.1", - "petgraph 0.8.3", "reqwest", "rusqlite", "semver 1.0.27", @@ -4672,6 +4671,8 @@ dependencies = [ "tokio", "vite_path", "vite_str", + "vite_task", + "vite_workspace", "wax", ] @@ -4679,7 +4680,7 @@ dependencies = [ name = "vite_glob" version = "0.0.0" dependencies = [ - "vite_error", + "thiserror 2.0.17", "vite_str", "wax", ] @@ -4764,11 +4765,11 @@ dependencies = [ "shell-escape", "supports-color", "tempfile", + "thiserror 2.0.17", "tokio", "tracing", "twox-hash", "uuid", - "vite_error", "vite_glob", "vite_path", "vite_str", @@ -4805,7 +4806,7 @@ dependencies = [ "serde_json", "serde_yml", "tempfile", - "vite_error", + "thiserror 2.0.17", "vite_glob", "vite_path", "vite_str", diff --git a/crates/vite_error/Cargo.toml b/crates/vite_error/Cargo.toml index 140b85a846..5e8ab60dca 100644 --- a/crates/vite_error/Cargo.toml +++ b/crates/vite_error/Cargo.toml @@ -12,7 +12,6 @@ anyhow = { workspace = true } bincode = { workspace = true } bstr = { workspace = true } nix = { workspace = true } -petgraph = { workspace = true } rusqlite = { workspace = true } semver = { workspace = true } serde_json = { workspace = true } @@ -21,6 +20,8 @@ thiserror = { workspace = true } tokio = { workspace = true } vite_path = { workspace = true } vite_str = { workspace = true } +vite_task = { workspace = true } +vite_workspace = { workspace = true } wax = { workspace = true } [target.'cfg(target_os = "windows")'.dependencies] diff --git a/crates/vite_error/src/lib.rs b/crates/vite_error/src/lib.rs index 113622acc2..0f6ed18b21 100644 --- a/crates/vite_error/src/lib.rs +++ b/crates/vite_error/src/lib.rs @@ -1,12 +1,7 @@ use std::{ffi::OsString, path::Path, sync::Arc}; -use petgraph::graph::NodeIndex; use thiserror::Error; -use vite_path::{ - AbsolutePath, AbsolutePathBuf, RelativePathBuf, - absolute::StripPrefixError, - relative::{FromPathError, InvalidPathDataError}, -}; +use vite_path::{AbsolutePath, AbsolutePathBuf, relative::FromPathError}; use vite_str::Str; #[derive(Error, Debug)] @@ -59,41 +54,14 @@ pub enum Error { #[error(transparent)] WaxWalk(#[from] wax::WalkError), - #[error("Duplicated task name: {0}")] - DuplicatedTask(Str), - - #[error("Duplicated package name: {name} at {path1} and {path2}")] - DuplicatedPackageName { name: Str, path1: RelativePathBuf, path2: RelativePathBuf }, - - #[error("Circular dependency found : {0:?}")] - CycleDependencies(petgraph::algo::Cycle), - - #[error("The package.json name is empty at {0:?}/package.json")] - EmptyPackageName(AbsolutePathBuf), - - #[error("Package {0} not found in workspace")] - PackageNotFound(Str), - - #[error("The package.json file is not found at {0:?}")] - PackageJsonNotFound(AbsolutePathBuf), - - #[error("Task '{task_request}' not found in workspace")] - TaskNotFound { task_request: Str }, - - #[error("Dependency Task '{name}' not found in package located at {package_path}")] - TaskDependencyNotFound { name: Str, package_path: RelativePathBuf }, - - #[error("{task_request} should not contain multiple '#'")] - AmbiguousTaskRequest { task_request: Str }, - - #[error("Only one task request is allowed when running in implicit mode: {0}")] - OnlyOneTaskRequest(Str), + #[error(transparent)] + SerdeYml(#[from] serde_yml::Error), - #[error("Recursive run is not allowed when task name contains '#': {0}")] - RecursiveRunWithScope(Str), + #[error(transparent)] + TaskError(#[from] vite_task::Error), #[error(transparent)] - SerdeYml(#[from] serde_yml::Error), + WorkspaceError(#[from] vite_workspace::Error), #[error("Lint failed, reason: {reason}")] LintFailed { status: Str, reason: Str }, @@ -116,17 +84,9 @@ pub enum Error { #[error("Resolve universal vite config failed")] ResolveUniversalViteConfigFailed { status: Str, reason: Str }, - #[error( - "The stripped path ({stripped_path:?}) is not a valid relative path because: {invalid_path_data_error}" - )] - StripPath { stripped_path: Box, invalid_path_data_error: InvalidPathDataError }, - #[error("The path ({path:?}) is not a valid relative path because: {reason}")] InvalidRelativePath { path: Box, reason: FromPathError }, - #[error("The package at {package_path:?} is outside the workspace at {workspace_root:?}")] - PackageOutsideWorkspace { package_path: AbsolutePathBuf, workspace_root: AbsolutePathBuf }, - #[error("Unsupported package manager: {0}")] UnsupportedPackageManager(Str), @@ -168,12 +128,3 @@ pub enum Error { #[error(transparent)] Anyhow(#[from] anyhow::Error), } - -impl From> for Error { - fn from(value: StripPrefixError<'_>) -> Self { - Self::StripPath { - stripped_path: Box::from(value.stripped_path), - invalid_path_data_error: value.invalid_path_data_error, - } - } -} diff --git a/crates/vite_glob/Cargo.toml b/crates/vite_glob/Cargo.toml index a4b04c59d0..491cfad65d 100644 --- a/crates/vite_glob/Cargo.toml +++ b/crates/vite_glob/Cargo.toml @@ -8,7 +8,7 @@ publish = false rust-version.workspace = true [dependencies] -vite_error = { workspace = true } +thiserror = { workspace = true } wax = { workspace = true } [dev-dependencies] diff --git a/crates/vite_glob/src/error.rs b/crates/vite_glob/src/error.rs new file mode 100644 index 0000000000..46ddda2560 --- /dev/null +++ b/crates/vite_glob/src/error.rs @@ -0,0 +1,7 @@ +use wax; + +#[derive(Debug, thiserror::Error)] +pub enum Error { + #[error(transparent)] + WaxBuild(#[from] wax::BuildError), +} diff --git a/crates/vite_glob/src/lib.rs b/crates/vite_glob/src/lib.rs index 9a7da4f25e..e04f65726f 100644 --- a/crates/vite_glob/src/lib.rs +++ b/crates/vite_glob/src/lib.rs @@ -1,6 +1,8 @@ +mod error; + use std::path::Path; -use vite_error::Error; +pub use error::Error; use wax::{Glob, Pattern}; /// If there are no negated patterns, it will follow the first match wins semantics. diff --git a/crates/vite_install/src/package_manager.rs b/crates/vite_install/src/package_manager.rs index 99afff7c62..d667598f49 100644 --- a/crates/vite_install/src/package_manager.rs +++ b/crates/vite_install/src/package_manager.rs @@ -616,7 +616,7 @@ mod tests { fs::create_dir_all(&root_dir).unwrap(); let found = find_package_root(&root_dir); let err = found.unwrap_err(); - assert!(matches!(err, Error::PackageJsonNotFound(_))); + assert!(matches!(err, vite_workspace::Error::PackageJsonNotFound(_))); } #[test] @@ -683,7 +683,7 @@ mod tests { // Should return PackageJsonNotFound error if no package.json found let found = find_workspace_root(&nested_dir); let err = found.unwrap_err(); - assert!(matches!(err, Error::PackageJsonNotFound(_))); + assert!(matches!(err, vite_workspace::Error::PackageJsonNotFound(_))); } #[test] diff --git a/crates/vite_task/Cargo.toml b/crates/vite_task/Cargo.toml index 9e8c46d9f3..06d4b0a9a9 100644 --- a/crates/vite_task/Cargo.toml +++ b/crates/vite_task/Cargo.toml @@ -33,11 +33,11 @@ sha2 = { workspace = true } shell-escape = { workspace = true } supports-color = { workspace = true } tempfile = { workspace = true } +thiserror = { workspace = true } tokio = { workspace = true, features = ["rt-multi-thread", "io-std", "macros"] } tracing = { workspace = true } twox-hash = { workspace = true } uuid = { workspace = true, features = ["v4"] } -vite_error = { workspace = true } vite_glob = { workspace = true } vite_path = { workspace = true } vite_str = { workspace = true } diff --git a/crates/vite_task/src/config/mod.rs b/crates/vite_task/src/config/mod.rs index 80611ec542..c7194d23d8 100644 --- a/crates/vite_task/src/config/mod.rs +++ b/crates/vite_task/src/config/mod.rs @@ -16,12 +16,12 @@ use diff::Diff; use serde::{Deserialize, Serialize}; pub use task_command::*; pub use task_graph_builder::*; -use vite_error::Error; use vite_path::{self, RelativePath, RelativePathBuf}; use vite_str::Str; pub use workspace::*; use crate::{ + Error, cmd::TaskParsedCommand, collections::{HashMap, HashSet}, config::name::TaskName, diff --git a/crates/vite_task/src/error.rs b/crates/vite_task/src/error.rs new file mode 100644 index 0000000000..03c9fc2085 --- /dev/null +++ b/crates/vite_task/src/error.rs @@ -0,0 +1,116 @@ +use std::{ffi::OsString, io, path::Path, sync::Arc}; + +use petgraph::algo::Cycle; +use vite_path::{ + AbsolutePath, RelativePathBuf, + absolute::StripPrefixError, + relative::{FromPathError, InvalidPathDataError}, +}; +use vite_str::Str; + +#[derive(Debug, thiserror::Error)] +pub enum Error { + // Task-specific errors (constructed in vite_task only) + #[error("Duplicate package name `{name}` found at `{path1}` and `{path2}`")] + DuplicatedPackageName { name: Str, path1: RelativePathBuf, path2: RelativePathBuf }, + + #[error("Package not found in workspace: `{0}`")] + PackageNotFound(Str), + + #[error("Duplicate task: `{0}`")] + DuplicatedTask(Str), + + #[error("Cycle dependencies detected: {0:?}")] + CycleDependencies(Cycle), + + #[error("Task not found: `{task_request}`")] + TaskNotFound { task_request: Str }, + + #[error("Task dependency `{name}` not found in package at `{package_path}`")] + TaskDependencyNotFound { name: Str, package_path: RelativePathBuf }, + + #[error("Ambiguous task request: `{task_request}` (contains multiple '#')")] + AmbiguousTaskRequest { task_request: Str }, + + #[error("Only one task is allowed in implicit mode (got: `{0}`)")] + OnlyOneTaskRequest(Str), + + #[error("Recursive run with scoped task name is not supported: `{0}`")] + RecursiveRunWithScope(Str), + + // Errors used by vite_task but not task-specific + #[error("Unrecognized db version: {0}")] + UnrecognizedDbVersion(u32), + + #[error("Env value is not valid unicode: {key} = {value:?}")] + EnvValueIsNotValidUnicode { key: Str, value: OsString }, + + #[error( + "The stripped path ({stripped_path:?}) is not a valid relative path because: {invalid_path_data_error}" + )] + StripPath { stripped_path: Box, invalid_path_data_error: InvalidPathDataError }, + + #[error("The path ({path:?}) is not a valid relative path because: {reason}")] + InvalidRelativePath { path: Box, reason: FromPathError }, + + #[error("IO error: {err} at {path:?}")] + IoWithPath { err: io::Error, path: Arc }, + + #[cfg(unix)] + #[error("Unsupported file type: {0:?}")] + UnsupportedFileType(nix::dir::Type), + + #[cfg(windows)] + #[error("Unsupported file type: {0:?}")] + UnsupportedFileType(std::fs::FileType), + + // External library errors + #[error(transparent)] + Io(#[from] io::Error), + + #[error(transparent)] + JoinPathsError(#[from] std::env::JoinPathsError), + + #[error(transparent)] + WaxBuild(#[from] wax::BuildError), + + #[error(transparent)] + WaxWalk(#[from] wax::WalkError), + + #[error(transparent)] + Utf8Error(#[from] bstr::Utf8Error), + + #[error(transparent)] + Serde(#[from] serde_json::Error), + + #[error(transparent)] + Sqlite(#[from] rusqlite::Error), + + #[error(transparent)] + BincodeEncode(#[from] bincode::error::EncodeError), + + #[error(transparent)] + BincodeDecode(#[from] bincode::error::DecodeError), + + #[error(transparent)] + Anyhow(#[from] anyhow::Error), + + #[error(transparent)] + Glob(#[from] vite_glob::Error), + + #[error(transparent)] + Workspace(#[from] vite_workspace::Error), + + #[cfg(unix)] + #[error(transparent)] + Nix(#[from] nix::Error), +} + +impl From> for Error { + fn from(value: StripPrefixError<'_>) -> Self { + Self::StripPath { + stripped_path: Box::from(value.stripped_path), + invalid_path_data_error: value.invalid_path_data_error, + } + } +} diff --git a/crates/vite_task/src/lib.rs b/crates/vite_task/src/lib.rs index 5f007f4640..4bc75d0cc7 100644 --- a/crates/vite_task/src/lib.rs +++ b/crates/vite_task/src/lib.rs @@ -2,6 +2,7 @@ mod cache; mod cmd; mod collections; mod config; +mod error; mod execute; mod fingerprint; mod fs; @@ -16,7 +17,7 @@ mod test_utils; // Public exports for vite-plus-cli to use pub use cache::TaskCache; pub use config::{ResolvedTask, Workspace}; +pub use error::Error; pub use execute::{CURRENT_EXECUTION_ID, EXECUTION_SUMMARY_DIR}; pub use schedule::{ExecutionPlan, ExecutionStatus, ExecutionSummary}; pub use types::ResolveCommandResult; -pub(crate) use vite_error::Error; diff --git a/crates/vite_workspace/Cargo.toml b/crates/vite_workspace/Cargo.toml index 9f1727df5d..e158dd70c2 100644 --- a/crates/vite_workspace/Cargo.toml +++ b/crates/vite_workspace/Cargo.toml @@ -14,7 +14,7 @@ serde = { workspace = true, features = ["derive"] } # use `preserve_order` feature to preserve the order of the fields in `package.json` serde_json = { workspace = true, features = ["preserve_order"] } serde_yml = { workspace = true } -vite_error = { workspace = true } +thiserror = { workspace = true } vite_glob = { workspace = true } vite_path = { workspace = true } vite_str = { workspace = true } diff --git a/crates/vite_workspace/src/error.rs b/crates/vite_workspace/src/error.rs new file mode 100644 index 0000000000..532c562357 --- /dev/null +++ b/crates/vite_workspace/src/error.rs @@ -0,0 +1,54 @@ +use std::{io, path::Path}; + +use serde_json; +use serde_yml; +use vite_path::{ + AbsolutePathBuf, RelativePathBuf, absolute::StripPrefixError, relative::InvalidPathDataError, +}; +use vite_str::Str; +use wax; + +#[derive(Debug, thiserror::Error)] +pub enum Error { + #[error("Duplicate package name `{name}` found at `{path1}` and `{path2}`")] + DuplicatedPackageName { name: Str, path1: RelativePathBuf, path2: RelativePathBuf }, + + #[error("Package not found in workspace: `{0:?}`")] + PackageJsonNotFound(AbsolutePathBuf), + + #[error("Package at `{package_path:?}` is outside workspace root `{workspace_root:?}`")] + PackageOutsideWorkspace { package_path: AbsolutePathBuf, workspace_root: AbsolutePathBuf }, + + #[error( + "The stripped path ({stripped_path:?}) is not a valid relative path because: {invalid_path_data_error}" + )] + StripPath { stripped_path: Box, invalid_path_data_error: InvalidPathDataError }, + + // External library errors + #[error(transparent)] + Io(#[from] io::Error), + + #[error(transparent)] + Serde(#[from] serde_json::Error), + + #[error(transparent)] + SerdeYml(#[from] serde_yml::Error), + + #[error(transparent)] + WaxBuild(#[from] wax::BuildError), + + #[error(transparent)] + WaxWalk(#[from] wax::WalkError), + + #[error(transparent)] + Glob(#[from] vite_glob::Error), +} + +impl From> for Error { + fn from(value: StripPrefixError<'_>) -> Self { + Self::StripPath { + stripped_path: Box::from(value.stripped_path), + invalid_path_data_error: value.invalid_path_data_error, + } + } +} diff --git a/crates/vite_workspace/src/lib.rs b/crates/vite_workspace/src/lib.rs index 5b25c90908..6c6f34e48e 100644 --- a/crates/vite_workspace/src/lib.rs +++ b/crates/vite_workspace/src/lib.rs @@ -1,3 +1,4 @@ +mod error; pub mod package; mod package_manager; @@ -6,13 +7,13 @@ use std::{fs, io}; use petgraph::{Graph, graph::NodeIndex}; use rustc_hash::{FxHashMap as HashMap, FxHashSet as HashSet}; use serde::{Deserialize, Serialize}; -use vite_error::Error; use vite_glob::GlobPatternSet; use vite_path::{AbsolutePath, AbsolutePathBuf, RelativePathBuf}; use vite_str::Str; use wax::Glob; pub use crate::{ + error::Error, package::{DependencyType, PackageJson}, package_manager::{WorkspaceFile, WorkspaceRoot, find_package_root, find_workspace_root}, }; @@ -515,7 +516,7 @@ mod tests { if let Err(Error::DuplicatedPackageName { name, .. }) = result { assert_eq!(name, "duplicate"); } else { - panic!("Expected DuplicatedPackageName error"); + panic!("Expected DuplicatedPackageName error, got: {:?}", result); } } diff --git a/crates/vite_workspace/src/package_manager.rs b/crates/vite_workspace/src/package_manager.rs index 133b7fae96..2be76d1f62 100644 --- a/crates/vite_workspace/src/package_manager.rs +++ b/crates/vite_workspace/src/package_manager.rs @@ -4,9 +4,10 @@ use std::{ path::Path, }; -use vite_error::Error; use vite_path::{AbsolutePath, RelativePathBuf}; +use crate::Error; + /// The package root directory and its package.json file. #[derive(Debug)] pub struct PackageRoot<'a> { diff --git a/packages/cli/binding/src/commands/doc.rs b/packages/cli/binding/src/commands/doc.rs index dc88dc8e45..2a7de7b623 100644 --- a/packages/cli/binding/src/commands/doc.rs +++ b/packages/cli/binding/src/commands/doc.rs @@ -1,17 +1,23 @@ use std::future::Future; use petgraph::stable_graph::StableGraph; -use vite_error::Error; -use vite_task::{ExecutionPlan, ExecutionSummary, ResolveCommandResult, ResolvedTask, Workspace}; +use vite_error::Error as ViteError; +use vite_task::{ + Error, ExecutionPlan, ExecutionSummary, ResolveCommandResult, ResolvedTask, Workspace, +}; -pub async fn doc>, DocFn: Fn() -> Doc>( +pub async fn doc< + Doc: Future>, + DocFn: Fn() -> Doc, +>( resolve_doc_command: DocFn, workspace: &Workspace, args: &Vec, ) -> Result { + let wrapped_command = + || async { resolve_doc_command().await.map_err(|e| Error::Anyhow(e.into())) }; let resolved_task = - ResolvedTask::resolve_from_builtin(workspace, resolve_doc_command, "doc", args.iter()) - .await?; + ResolvedTask::resolve_from_builtin(workspace, wrapped_command, "doc", args.iter()).await?; let mut task_graph: StableGraph = Default::default(); task_graph.add_node(resolved_task); ExecutionPlan::plan(task_graph, false)?.execute(workspace).await diff --git a/packages/cli/binding/src/commands/fmt.rs b/packages/cli/binding/src/commands/fmt.rs index e58a065827..13122e06d4 100644 --- a/packages/cli/binding/src/commands/fmt.rs +++ b/packages/cli/binding/src/commands/fmt.rs @@ -3,8 +3,10 @@ use std::{collections::HashMap, future::Future}; use petgraph::stable_graph::StableGraph; use serde::{Deserialize, Serialize}; use serde_json::Value; -use vite_error::Error; -use vite_task::{ExecutionPlan, ExecutionSummary, ResolveCommandResult, ResolvedTask, Workspace}; +use vite_error::Error as ViteError; +use vite_task::{ + Error, ExecutionPlan, ExecutionSummary, ResolveCommandResult, ResolvedTask, Workspace, +}; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct FmtConfig { @@ -12,14 +14,18 @@ pub struct FmtConfig { } #[tracing::instrument(skip(resolve_fmt_command, workspace))] -pub async fn fmt>, FmtFn: Fn() -> Fmt>( +pub async fn fmt< + Fmt: Future>, + FmtFn: Fn() -> Fmt, +>( resolve_fmt_command: FmtFn, workspace: &Workspace, args: &Vec, ) -> Result { + let wrapped_command = + || async { resolve_fmt_command().await.map_err(|e| Error::Anyhow(e.into())) }; let resolved_task = - ResolvedTask::resolve_from_builtin(workspace, resolve_fmt_command, "fmt", args.iter()) - .await?; + ResolvedTask::resolve_from_builtin(workspace, wrapped_command, "fmt", args.iter()).await?; let mut task_graph: StableGraph = Default::default(); task_graph.add_node(resolved_task); ExecutionPlan::plan(task_graph, false)?.execute(workspace).await diff --git a/packages/cli/binding/src/commands/install.rs b/packages/cli/binding/src/commands/install.rs index beb35670e4..781cf22d56 100644 --- a/packages/cli/binding/src/commands/install.rs +++ b/packages/cli/binding/src/commands/install.rs @@ -413,7 +413,8 @@ mod tests { let args = vec![]; let result = command.execute(&args).await; - assert!(matches!(result.unwrap_err(), Error::PackageJsonNotFound(_))); + let err = result.unwrap_err(); + assert!(matches!(err, Error::WorkspaceError(_))); } /// Test that in CI environment, we will use pnpm without prompting diff --git a/packages/cli/binding/src/commands/lib_cmd.rs b/packages/cli/binding/src/commands/lib_cmd.rs index a4f9a78c6d..f24045a6f4 100644 --- a/packages/cli/binding/src/commands/lib_cmd.rs +++ b/packages/cli/binding/src/commands/lib_cmd.rs @@ -1,18 +1,24 @@ use std::future::Future; use petgraph::stable_graph::StableGraph; -use vite_error::Error; -use vite_task::{ExecutionPlan, ExecutionSummary, ResolveCommandResult, ResolvedTask, Workspace}; +use vite_error::Error as ViteError; +use vite_task::{ + Error, ExecutionPlan, ExecutionSummary, ResolveCommandResult, ResolvedTask, Workspace, +}; #[tracing::instrument(skip(resolve_lib_command, workspace))] -pub async fn lib>, LibFn: Fn() -> Lib>( +pub async fn lib< + Lib: Future>, + LibFn: Fn() -> Lib, +>( resolve_lib_command: LibFn, workspace: &Workspace, args: &Vec, ) -> Result { + let wrapped_command = + || async { resolve_lib_command().await.map_err(|e| Error::Anyhow(e.into())) }; let resolved_task = - ResolvedTask::resolve_from_builtin(workspace, resolve_lib_command, "lib", args.iter()) - .await?; + ResolvedTask::resolve_from_builtin(workspace, wrapped_command, "lib", args.iter()).await?; let mut task_graph: StableGraph = Default::default(); task_graph.add_node(resolved_task); ExecutionPlan::plan(task_graph, false)?.execute(workspace).await diff --git a/packages/cli/binding/src/commands/lint.rs b/packages/cli/binding/src/commands/lint.rs index 2f3da1ffdc..4fca528937 100644 --- a/packages/cli/binding/src/commands/lint.rs +++ b/packages/cli/binding/src/commands/lint.rs @@ -2,8 +2,10 @@ use std::{collections::HashMap, future::Future}; use petgraph::stable_graph::StableGraph; use serde::{Deserialize, Serialize}; -use vite_error::Error; -use vite_task::{ExecutionPlan, ExecutionSummary, ResolveCommandResult, ResolvedTask, Workspace}; +use vite_error::Error as ViteError; +use vite_task::{ + Error, ExecutionPlan, ExecutionSummary, ResolveCommandResult, ResolvedTask, Workspace, +}; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct LintConfig { @@ -12,16 +14,17 @@ pub struct LintConfig { #[tracing::instrument(skip(resolve_lint_command, workspace))] pub async fn lint< - Lint: Future>, + Lint: Future>, LintFn: Fn() -> Lint, >( resolve_lint_command: LintFn, workspace: &Workspace, args: &Vec, ) -> Result { + let wrapped_command = + || async { resolve_lint_command().await.map_err(|e| Error::Anyhow(e.into())) }; let resolved_task = - ResolvedTask::resolve_from_builtin(workspace, resolve_lint_command, "lint", args.iter()) - .await?; + ResolvedTask::resolve_from_builtin(workspace, wrapped_command, "lint", args.iter()).await?; let mut task_graph: StableGraph = Default::default(); task_graph.add_node(resolved_task); ExecutionPlan::plan(task_graph, false)?.execute(workspace).await diff --git a/packages/cli/binding/src/commands/test.rs b/packages/cli/binding/src/commands/test.rs index 02a4a98992..6ee045ec01 100644 --- a/packages/cli/binding/src/commands/test.rs +++ b/packages/cli/binding/src/commands/test.rs @@ -1,20 +1,24 @@ use std::future::Future; use petgraph::stable_graph::StableGraph; -use vite_error::Error; -use vite_task::{ExecutionPlan, ExecutionSummary, ResolveCommandResult, ResolvedTask, Workspace}; +use vite_error::Error as ViteError; +use vite_task::{ + Error, ExecutionPlan, ExecutionSummary, ResolveCommandResult, ResolvedTask, Workspace, +}; pub async fn test< - Test: Future>, + Test: Future>, TestFn: Fn() -> Test, >( resolve_test_command: TestFn, workspace: &Workspace, args: &Vec, ) -> Result { + let wrapped_command = + || async { resolve_test_command().await.map_err(|e| Error::Anyhow(e.into())) }; let resolved_task = ResolvedTask::resolve_from_builtin( workspace, - resolve_test_command, + wrapped_command, "test", args.iter().map(std::string::String::as_str), ) diff --git a/packages/cli/binding/src/commands/vite.rs b/packages/cli/binding/src/commands/vite.rs index 1d444004cf..cf39a55d47 100644 --- a/packages/cli/binding/src/commands/vite.rs +++ b/packages/cli/binding/src/commands/vite.rs @@ -1,11 +1,13 @@ use std::{future::Future, iter}; use petgraph::stable_graph::StableGraph; -use vite_error::Error; -use vite_task::{ExecutionPlan, ExecutionSummary, ResolveCommandResult, ResolvedTask, Workspace}; +use vite_error::Error as ViteError; +use vite_task::{ + Error, ExecutionPlan, ExecutionSummary, ResolveCommandResult, ResolvedTask, Workspace, +}; pub async fn vite< - Vite: Future>, + Vite: Future>, ViteFn: Fn() -> Vite, >( arg_forward: &str, @@ -13,9 +15,11 @@ pub async fn vite< workspace: &Workspace, args: &Vec, ) -> Result { + let wrapped_command = + || async { resolve_vite_command().await.map_err(|e| Error::Anyhow(e.into())) }; let resolved_task = ResolvedTask::resolve_from_builtin( workspace, - resolve_vite_command, + wrapped_command, arg_forward, iter::once(arg_forward).chain(args.iter().map(std::string::String::as_str)), )