diff --git a/Cargo.lock b/Cargo.lock index d1e34dc7d6..ea75bfef1d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2299,7 +2299,7 @@ dependencies = [ [[package]] name = "fspy" version = "0.1.0" -source = "git+https://github.com/voidzero-dev/vite-task.git?rev=5833b374c6edb05c2f2f8e133ff8c796b378472a#5833b374c6edb05c2f2f8e133ff8c796b378472a" +source = "git+https://github.com/voidzero-dev/vite-task.git?rev=8daa9bb72faa89b745cb58c087b416b15d3bddc5#8daa9bb72faa89b745cb58c087b416b15d3bddc5" dependencies = [ "anyhow", "bstr", @@ -2334,7 +2334,7 @@ dependencies = [ [[package]] name = "fspy_detours_sys" version = "0.0.0" -source = "git+https://github.com/voidzero-dev/vite-task.git?rev=5833b374c6edb05c2f2f8e133ff8c796b378472a#5833b374c6edb05c2f2f8e133ff8c796b378472a" +source = "git+https://github.com/voidzero-dev/vite-task.git?rev=8daa9bb72faa89b745cb58c087b416b15d3bddc5#8daa9bb72faa89b745cb58c087b416b15d3bddc5" dependencies = [ "cc", "winapi", @@ -2343,7 +2343,7 @@ dependencies = [ [[package]] name = "fspy_preload_unix" version = "0.0.0" -source = "git+https://github.com/voidzero-dev/vite-task.git?rev=5833b374c6edb05c2f2f8e133ff8c796b378472a#5833b374c6edb05c2f2f8e133ff8c796b378472a" +source = "git+https://github.com/voidzero-dev/vite-task.git?rev=8daa9bb72faa89b745cb58c087b416b15d3bddc5#8daa9bb72faa89b745cb58c087b416b15d3bddc5" dependencies = [ "anyhow", "bstr", @@ -2358,7 +2358,7 @@ dependencies = [ [[package]] name = "fspy_preload_windows" version = "0.1.0" -source = "git+https://github.com/voidzero-dev/vite-task.git?rev=5833b374c6edb05c2f2f8e133ff8c796b378472a#5833b374c6edb05c2f2f8e133ff8c796b378472a" +source = "git+https://github.com/voidzero-dev/vite-task.git?rev=8daa9bb72faa89b745cb58c087b416b15d3bddc5#8daa9bb72faa89b745cb58c087b416b15d3bddc5" dependencies = [ "constcat", "fspy_detours_sys", @@ -2374,7 +2374,7 @@ dependencies = [ [[package]] name = "fspy_seccomp_unotify" version = "0.1.0" -source = "git+https://github.com/voidzero-dev/vite-task.git?rev=5833b374c6edb05c2f2f8e133ff8c796b378472a#5833b374c6edb05c2f2f8e133ff8c796b378472a" +source = "git+https://github.com/voidzero-dev/vite-task.git?rev=8daa9bb72faa89b745cb58c087b416b15d3bddc5#8daa9bb72faa89b745cb58c087b416b15d3bddc5" dependencies = [ "futures-util", "libc", @@ -2391,18 +2391,18 @@ dependencies = [ [[package]] name = "fspy_shared" version = "0.0.0" -source = "git+https://github.com/voidzero-dev/vite-task.git?rev=5833b374c6edb05c2f2f8e133ff8c796b378472a#5833b374c6edb05c2f2f8e133ff8c796b378472a" +source = "git+https://github.com/voidzero-dev/vite-task.git?rev=8daa9bb72faa89b745cb58c087b416b15d3bddc5#8daa9bb72faa89b745cb58c087b416b15d3bddc5" dependencies = [ "bitflags 2.11.0", "bstr", "bumpalo", "bytemuck", "native_str", - "os_str_bytes", "shared_memory", "thiserror 2.0.18", "tracing", "uuid", + "vite_path", "winapi", "wincode", ] @@ -2410,7 +2410,7 @@ dependencies = [ [[package]] name = "fspy_shared_unix" version = "0.0.0" -source = "git+https://github.com/voidzero-dev/vite-task.git?rev=5833b374c6edb05c2f2f8e133ff8c796b378472a#5833b374c6edb05c2f2f8e133ff8c796b378472a" +source = "git+https://github.com/voidzero-dev/vite-task.git?rev=8daa9bb72faa89b745cb58c087b416b15d3bddc5#8daa9bb72faa89b745cb58c087b416b15d3bddc5" dependencies = [ "anyhow", "base64 0.22.1", @@ -2946,7 +2946,7 @@ dependencies = [ "libc", "percent-encoding", "pin-project-lite", - "socket2 0.6.3", + "socket2 0.5.10", "system-configuration", "tokio", "tower-service", @@ -3552,7 +3552,7 @@ dependencies = [ [[package]] name = "materialized_artifact" version = "0.0.0" -source = "git+https://github.com/voidzero-dev/vite-task.git?rev=5833b374c6edb05c2f2f8e133ff8c796b378472a#5833b374c6edb05c2f2f8e133ff8c796b378472a" +source = "git+https://github.com/voidzero-dev/vite-task.git?rev=8daa9bb72faa89b745cb58c087b416b15d3bddc5#8daa9bb72faa89b745cb58c087b416b15d3bddc5" dependencies = [ "tempfile", ] @@ -3560,7 +3560,7 @@ dependencies = [ [[package]] name = "materialized_artifact_build" version = "0.0.0" -source = "git+https://github.com/voidzero-dev/vite-task.git?rev=5833b374c6edb05c2f2f8e133ff8c796b378472a#5833b374c6edb05c2f2f8e133ff8c796b378472a" +source = "git+https://github.com/voidzero-dev/vite-task.git?rev=8daa9bb72faa89b745cb58c087b416b15d3bddc5#8daa9bb72faa89b745cb58c087b416b15d3bddc5" dependencies = [ "xxhash-rust", ] @@ -3784,7 +3784,7 @@ dependencies = [ [[package]] name = "native_str" version = "0.0.0" -source = "git+https://github.com/voidzero-dev/vite-task.git?rev=5833b374c6edb05c2f2f8e133ff8c796b378472a#5833b374c6edb05c2f2f8e133ff8c796b378472a" +source = "git+https://github.com/voidzero-dev/vite-task.git?rev=8daa9bb72faa89b745cb58c087b416b15d3bddc5#8daa9bb72faa89b745cb58c087b416b15d3bddc5" dependencies = [ "bumpalo", "bytemuck", @@ -5460,7 +5460,7 @@ dependencies = [ [[package]] name = "pty_terminal_test_client" version = "0.0.0" -source = "git+https://github.com/voidzero-dev/vite-task.git?rev=5833b374c6edb05c2f2f8e133ff8c796b378472a#5833b374c6edb05c2f2f8e133ff8c796b378472a" +source = "git+https://github.com/voidzero-dev/vite-task.git?rev=8daa9bb72faa89b745cb58c087b416b15d3bddc5#8daa9bb72faa89b745cb58c087b416b15d3bddc5" [[package]] name = "quote" @@ -8225,6 +8225,7 @@ version = "1.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eab68b56840f69efb0fefbe3ab6661499217ffdc58e2eef7c3f6f69835386322" dependencies = [ + "serde", "smallvec 1.15.1", ] @@ -8340,10 +8341,10 @@ dependencies = [ [[package]] name = "vite_glob" version = "0.0.0" -source = "git+https://github.com/voidzero-dev/vite-task.git?rev=5833b374c6edb05c2f2f8e133ff8c796b378472a#5833b374c6edb05c2f2f8e133ff8c796b378472a" +source = "git+https://github.com/voidzero-dev/vite-task.git?rev=8daa9bb72faa89b745cb58c087b416b15d3bddc5#8daa9bb72faa89b745cb58c087b416b15d3bddc5" dependencies = [ + "globset", "thiserror 2.0.18", - "vite_path", "wax 0.7.0", ] @@ -8387,7 +8388,7 @@ dependencies = [ [[package]] name = "vite_graph_ser" version = "0.1.0" -source = "git+https://github.com/voidzero-dev/vite-task.git?rev=5833b374c6edb05c2f2f8e133ff8c796b378472a#5833b374c6edb05c2f2f8e133ff8c796b378472a" +source = "git+https://github.com/voidzero-dev/vite-task.git?rev=8daa9bb72faa89b745cb58c087b416b15d3bddc5#8daa9bb72faa89b745cb58c087b416b15d3bddc5" dependencies = [ "petgraph 0.8.3", "serde", @@ -8487,9 +8488,10 @@ dependencies = [ [[package]] name = "vite_path" version = "0.1.0" -source = "git+https://github.com/voidzero-dev/vite-task.git?rev=5833b374c6edb05c2f2f8e133ff8c796b378472a#5833b374c6edb05c2f2f8e133ff8c796b378472a" +source = "git+https://github.com/voidzero-dev/vite-task.git?rev=8daa9bb72faa89b745cb58c087b416b15d3bddc5#8daa9bb72faa89b745cb58c087b416b15d3bddc5" dependencies = [ "diff-struct", + "os_str_bytes", "path-clean", "ref-cast", "serde", @@ -8518,7 +8520,7 @@ dependencies = [ [[package]] name = "vite_powershell" version = "0.1.0" -source = "git+https://github.com/voidzero-dev/vite-task.git?rev=5833b374c6edb05c2f2f8e133ff8c796b378472a#5833b374c6edb05c2f2f8e133ff8c796b378472a" +source = "git+https://github.com/voidzero-dev/vite-task.git?rev=8daa9bb72faa89b745cb58c087b416b15d3bddc5#8daa9bb72faa89b745cb58c087b416b15d3bddc5" dependencies = [ "vite_path", "which", @@ -8527,7 +8529,7 @@ dependencies = [ [[package]] name = "vite_select" version = "0.0.0" -source = "git+https://github.com/voidzero-dev/vite-task.git?rev=5833b374c6edb05c2f2f8e133ff8c796b378472a#5833b374c6edb05c2f2f8e133ff8c796b378472a" +source = "git+https://github.com/voidzero-dev/vite-task.git?rev=8daa9bb72faa89b745cb58c087b416b15d3bddc5#8daa9bb72faa89b745cb58c087b416b15d3bddc5" dependencies = [ "anyhow", "crossterm", @@ -8580,7 +8582,7 @@ dependencies = [ [[package]] name = "vite_shell" version = "0.0.0" -source = "git+https://github.com/voidzero-dev/vite-task.git?rev=5833b374c6edb05c2f2f8e133ff8c796b378472a#5833b374c6edb05c2f2f8e133ff8c796b378472a" +source = "git+https://github.com/voidzero-dev/vite-task.git?rev=8daa9bb72faa89b745cb58c087b416b15d3bddc5#8daa9bb72faa89b745cb58c087b416b15d3bddc5" dependencies = [ "brush-parser 0.4.0", "diff-struct", @@ -8607,7 +8609,7 @@ dependencies = [ [[package]] name = "vite_str" version = "0.1.0" -source = "git+https://github.com/voidzero-dev/vite-task.git?rev=5833b374c6edb05c2f2f8e133ff8c796b378472a#5833b374c6edb05c2f2f8e133ff8c796b378472a" +source = "git+https://github.com/voidzero-dev/vite-task.git?rev=8daa9bb72faa89b745cb58c087b416b15d3bddc5#8daa9bb72faa89b745cb58c087b416b15d3bddc5" dependencies = [ "compact_str", "diff-struct", @@ -8618,7 +8620,7 @@ dependencies = [ [[package]] name = "vite_task" version = "0.0.0" -source = "git+https://github.com/voidzero-dev/vite-task.git?rev=5833b374c6edb05c2f2f8e133ff8c796b378472a#5833b374c6edb05c2f2f8e133ff8c796b378472a" +source = "git+https://github.com/voidzero-dev/vite-task.git?rev=8daa9bb72faa89b745cb58c087b416b15d3bddc5#8daa9bb72faa89b745cb58c087b416b15d3bddc5" dependencies = [ "anstream", "anyhow", @@ -8628,6 +8630,8 @@ dependencies = [ "derive_more", "fspy", "futures-util", + "materialized_artifact", + "materialized_artifact_build", "nix 0.31.2", "once_cell", "owo-colors", @@ -8646,11 +8650,15 @@ dependencies = [ "tracing", "twox-hash", "uuid", + "vite_glob", "vite_path", "vite_select", "vite_str", + "vite_task_client_napi", "vite_task_graph", + "vite_task_ipc_shared", "vite_task_plan", + "vite_task_server", "vite_workspace", "wax 0.7.0", "winapi", @@ -8658,10 +8666,35 @@ dependencies = [ "zstd", ] +[[package]] +name = "vite_task_client" +version = "0.0.0" +source = "git+https://github.com/voidzero-dev/vite-task.git?rev=8daa9bb72faa89b745cb58c087b416b15d3bddc5#8daa9bb72faa89b745cb58c087b416b15d3bddc5" +dependencies = [ + "native_str", + "rustc-hash", + "vite_path", + "vite_task_ipc_shared", + "winapi", + "wincode", +] + +[[package]] +name = "vite_task_client_napi" +version = "0.1.0" +source = "git+https://github.com/voidzero-dev/vite-task.git?rev=8daa9bb72faa89b745cb58c087b416b15d3bddc5#8daa9bb72faa89b745cb58c087b416b15d3bddc5" +dependencies = [ + "napi", + "napi-build", + "napi-derive", + "vite_str", + "vite_task_client", +] + [[package]] name = "vite_task_graph" version = "0.1.0" -source = "git+https://github.com/voidzero-dev/vite-task.git?rev=5833b374c6edb05c2f2f8e133ff8c796b378472a#5833b374c6edb05c2f2f8e133ff8c796b378472a" +source = "git+https://github.com/voidzero-dev/vite-task.git?rev=8daa9bb72faa89b745cb58c087b416b15d3bddc5#8daa9bb72faa89b745cb58c087b416b15d3bddc5" dependencies = [ "anyhow", "async-trait", @@ -8672,7 +8705,7 @@ dependencies = [ "serde_json", "thiserror 2.0.18", "tracing", - "vite_graph_ser", + "vec1", "vite_path", "vite_str", "vite_workspace", @@ -8680,10 +8713,20 @@ dependencies = [ "wincode", ] +[[package]] +name = "vite_task_ipc_shared" +version = "0.0.0" +source = "git+https://github.com/voidzero-dev/vite-task.git?rev=8daa9bb72faa89b745cb58c087b416b15d3bddc5#8daa9bb72faa89b745cb58c087b416b15d3bddc5" +dependencies = [ + "native_str", + "rustc-hash", + "wincode", +] + [[package]] name = "vite_task_plan" version = "0.1.0" -source = "git+https://github.com/voidzero-dev/vite-task.git?rev=5833b374c6edb05c2f2f8e133ff8c796b378472a#5833b374c6edb05c2f2f8e133ff8c796b378472a" +source = "git+https://github.com/voidzero-dev/vite-task.git?rev=8daa9bb72faa89b745cb58c087b416b15d3bddc5#8daa9bb72faa89b745cb58c087b416b15d3bddc5" dependencies = [ "anyhow", "async-trait", @@ -8708,6 +8751,26 @@ dependencies = [ "wincode", ] +[[package]] +name = "vite_task_server" +version = "0.0.0" +source = "git+https://github.com/voidzero-dev/vite-task.git?rev=8daa9bb72faa89b745cb58c087b416b15d3bddc5#8daa9bb72faa89b745cb58c087b416b15d3bddc5" +dependencies = [ + "futures", + "native_str", + "rustc-hash", + "tempfile", + "thiserror 2.0.18", + "tokio", + "tokio-util", + "tracing", + "uuid", + "vite_glob", + "vite_path", + "vite_task_ipc_shared", + "wincode", +] + [[package]] name = "vite_trampoline" version = "0.0.0" @@ -8715,7 +8778,7 @@ version = "0.0.0" [[package]] name = "vite_workspace" version = "0.0.0" -source = "git+https://github.com/voidzero-dev/vite-task.git?rev=5833b374c6edb05c2f2f8e133ff8c796b378472a#5833b374c6edb05c2f2f8e133ff8c796b378472a" +source = "git+https://github.com/voidzero-dev/vite-task.git?rev=8daa9bb72faa89b745cb58c087b416b15d3bddc5#8daa9bb72faa89b745cb58c087b416b15d3bddc5" dependencies = [ "clap", "petgraph 0.8.3", diff --git a/Cargo.toml b/Cargo.toml index e123d62774..96ff8ef816 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -192,7 +192,7 @@ dunce = "1.0.5" fast-glob = "1.0.0" flate2 = { version = "=1.1.9", features = ["zlib-rs"] } form_urlencoded = "1.2.1" -fspy = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "5833b374c6edb05c2f2f8e133ff8c796b378472a" } +fspy = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "8daa9bb72faa89b745cb58c087b416b15d3bddc5" } futures = "0.3.31" futures-util = "0.3.31" glob = "0.3.2" @@ -304,11 +304,11 @@ vite_pm_cli = { path = "crates/vite_pm_cli" } vite_setup = { path = "crates/vite_setup" } vite_shared = { path = "crates/vite_shared" } vite_static_config = { path = "crates/vite_static_config" } -vite_path = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "5833b374c6edb05c2f2f8e133ff8c796b378472a" } -vite_powershell = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "5833b374c6edb05c2f2f8e133ff8c796b378472a" } -vite_str = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "5833b374c6edb05c2f2f8e133ff8c796b378472a" } -vite_task = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "5833b374c6edb05c2f2f8e133ff8c796b378472a" } -vite_workspace = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "5833b374c6edb05c2f2f8e133ff8c796b378472a" } +vite_path = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "8daa9bb72faa89b745cb58c087b416b15d3bddc5" } +vite_powershell = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "8daa9bb72faa89b745cb58c087b416b15d3bddc5" } +vite_str = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "8daa9bb72faa89b745cb58c087b416b15d3bddc5" } +vite_task = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "8daa9bb72faa89b745cb58c087b416b15d3bddc5" } +vite_workspace = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "8daa9bb72faa89b745cb58c087b416b15d3bddc5" } walkdir = "2.5.0" wax = "0.6.0" which = "8.0.0" diff --git a/packages/cli/binding/src/cli/resolver.rs b/packages/cli/binding/src/cli/resolver.rs index 0b6d05a4d9..c050801113 100644 --- a/packages/cli/binding/src/cli/resolver.rs +++ b/packages/cli/binding/src/cli/resolver.rs @@ -4,7 +4,7 @@ use rustc_hash::FxHashMap; use vite_path::AbsolutePath; use vite_str::Str; use vite_task::config::user::{ - AutoInput, EnabledCacheConfig, GlobWithBase, InputBase, UserCacheConfig, UserInputEntry, + AutoTracking, EnabledCacheConfig, GlobWithBase, InputBase, UserCacheConfig, UserInputEntry, }; use super::{ @@ -171,10 +171,16 @@ impl SubcommandResolver { .chain(iter::once(Str::from("build"))) .chain(args.into_iter().map(Str::from)) .collect(), + // No synthetic cache config: vite reports its inputs/outputs/ + // envs to the runner via `@voidzero-dev/vite-task-client`. + // All fields `None` keep caching enabled with auto input and + // auto output inference (the latter drives output restoration); + // vite's `ignoreInput`/`ignoreOutput`/`getEnv`/`getEnvs` refine + // the fingerprint at runtime. cache_config: UserCacheConfig::with_config(EnabledCacheConfig { - env: Some(Box::new([Str::from("VITE_*")])), + env: None, untracked_env: None, - input: Some(build_pack_cache_inputs()), + input: None, output: None, }), envs: merge_resolved_envs_with_version(envs, resolved.envs), @@ -201,8 +207,7 @@ impl SubcommandResolver { env: None, untracked_env: None, input: Some(vec![ - UserInputEntry::Auto(AutoInput { auto: true }), - exclude_glob("!node_modules/.vite-temp/**", InputBase::Package), + UserInputEntry::Auto(AutoTracking { auto: true }), exclude_glob( "!node_modules/.vite/vitest/**/results.json", InputBase::Package, @@ -307,15 +312,13 @@ fn exclude_glob(pattern: &str, base: InputBase) -> UserInputEntry { UserInputEntry::GlobWithBase(GlobWithBase { pattern: Str::from(pattern), base }) } -/// Common cache input entries for build/pack commands. -/// Excludes .vite-temp config files and dist output files that are both read and written. +/// Common cache input entries for the pack command. +/// Excludes dist output files that are both read and written. /// TODO: The hardcoded `!dist/**` exclusion is a temporary workaround. It will be replaced /// by a runner-aware approach that automatically excludes task output directories. fn build_pack_cache_inputs() -> Vec { vec![ - UserInputEntry::Auto(AutoInput { auto: true }), - exclude_glob("!node_modules/.vite-temp/**", InputBase::Workspace), - exclude_glob("!node_modules/.vite-temp/**", InputBase::Package), + UserInputEntry::Auto(AutoTracking { auto: true }), exclude_glob("!dist/**", InputBase::Package), ] } @@ -323,13 +326,10 @@ fn build_pack_cache_inputs() -> Vec { /// Cache input entries for the check command. /// The vp check subprocess is a full vp CLI process (not resolved to a binary like /// build/lint/fmt), so it accesses additional directories that must be excluded: -/// - `.vite-temp`: config compilation cache, read+written during vp CLI startup /// - `.vite/task-cache`: task runner state files that change after each run pub(super) fn check_cache_inputs() -> Vec { vec![ - UserInputEntry::Auto(AutoInput { auto: true }), - exclude_glob("!node_modules/.vite-temp/**", InputBase::Workspace), - exclude_glob("!node_modules/.vite-temp/**", InputBase::Package), + UserInputEntry::Auto(AutoTracking { auto: true }), exclude_glob("!node_modules/.vite/task-cache/**", InputBase::Workspace), exclude_glob("!node_modules/.vite/task-cache/**", InputBase::Package), ] diff --git a/packages/cli/snap-tests/build-vite-env/snap.txt b/packages/cli/snap-tests/build-vite-env/snap.txt index ff5a11ea04..54e5eb28ea 100644 --- a/packages/cli/snap-tests/build-vite-env/snap.txt +++ b/packages/cli/snap-tests/build-vite-env/snap.txt @@ -25,7 +25,7 @@ dist/assets/index-Dra_-aT4.js kB │ gzip: kB vp run: cache hit, ms saved. > VITE_MY_VAR=2 vp run build # env changed, should miss cache -$ vp build ○ cache miss: envs changed, executing +$ vp build ○ cache miss: env 'VITE_MY_VAR' changed, executing vite v building client environment for production... transforming...✓ modules transformed. rendering chunks... diff --git a/packages/cli/snap-tests/plain-terminal-ui-nested/snap.txt b/packages/cli/snap-tests/plain-terminal-ui-nested/snap.txt index afafa585f9..ffa975a06b 100644 --- a/packages/cli/snap-tests/plain-terminal-ui-nested/snap.txt +++ b/packages/cli/snap-tests/plain-terminal-ui-nested/snap.txt @@ -8,17 +8,17 @@ Found 0 warnings and 0 errors. Finished in ms on 3 files with rules using threads. --- -vp run: 0/2 cache hit (0%). root-package#hello (and 1 more) not cached because they modified their inputs. (Run `vp run --last-details` for full details) +vp run: 0/2 cache hit (0%). (Run `vp run --last-details` for full details) > echo 'console.log(123)' > a.ts > vp run hello # report cache status from the inner runner -$ vp lint ./src +$ vp lint ./src ◉ cache hit, replaying Found 0 warnings and 0 errors. Finished in ms on 1 file with rules using threads. -$ vp lint +$ vp lint ○ cache miss: 'a.ts' modified, executing Found 0 warnings and 0 errors. Finished in ms on 3 files with rules using threads. --- -vp run: 0/2 cache hit (0%). root-package#hello (and 1 more) not cached because they modified their inputs. (Run `vp run --last-details` for full details) +vp run: 1/2 cache hit (50%), ms saved. (Run `vp run --last-details` for full details) diff --git a/packages/cli/snap-tests/plain-terminal-ui/snap.txt b/packages/cli/snap-tests/plain-terminal-ui/snap.txt index 931e6e0d1e..e183790eff 100644 --- a/packages/cli/snap-tests/plain-terminal-ui/snap.txt +++ b/packages/cli/snap-tests/plain-terminal-ui/snap.txt @@ -11,17 +11,17 @@ input_content 1 vp run: cache hit, ms saved. > FOO=2 vp run hello # env changed -$ node hello.mjs ○ cache miss: envs changed, executing +$ node hello.mjs ○ cache miss: env 'FOO' changed, executing input_content 2 > FOO=2 BAR=1 vp run hello # env added -$ node hello.mjs ○ cache miss: envs changed, executing +$ node hello.mjs ○ cache miss: env 'BAR' changed, executing input_content 2 > vp run hello # env removed -$ node hello.mjs ○ cache miss: envs changed, executing +$ node hello.mjs ○ cache miss: envs 'BAR', 'FOO' changed, executing input_content undefined diff --git a/packages/cli/snap-tests/vp-build-auto-output-restoration/index.html b/packages/cli/snap-tests/vp-build-auto-output-restoration/index.html new file mode 100644 index 0000000000..7febab8c7e --- /dev/null +++ b/packages/cli/snap-tests/vp-build-auto-output-restoration/index.html @@ -0,0 +1,8 @@ + + + + + + diff --git a/packages/cli/snap-tests/vp-build-auto-output-restoration/package.json b/packages/cli/snap-tests/vp-build-auto-output-restoration/package.json new file mode 100644 index 0000000000..c73c0c479a --- /dev/null +++ b/packages/cli/snap-tests/vp-build-auto-output-restoration/package.json @@ -0,0 +1,4 @@ +{ + "name": "vp-build-auto-output-restoration-test", + "private": true +} diff --git a/packages/cli/snap-tests/vp-build-auto-output-restoration/snap.txt b/packages/cli/snap-tests/vp-build-auto-output-restoration/snap.txt new file mode 100644 index 0000000000..d1137efcc4 --- /dev/null +++ b/packages/cli/snap-tests/vp-build-auto-output-restoration/snap.txt @@ -0,0 +1,13 @@ +> vp run build # first build populates the cache +> ls dist # build output exists +assets +index.html + +> rm -rf dist # remove the build output +> vp run build 2>&1 | grep 'cache hit' # rebuild hits cache +$ vp build ◉ cache hit, replaying +vp run: cache hit, ms saved. + +> ls dist # dist auto-restored on cache hit (no synthetic output config) +assets +index.html diff --git a/packages/cli/snap-tests/vp-build-auto-output-restoration/steps.json b/packages/cli/snap-tests/vp-build-auto-output-restoration/steps.json new file mode 100644 index 0000000000..78a6f469b5 --- /dev/null +++ b/packages/cli/snap-tests/vp-build-auto-output-restoration/steps.json @@ -0,0 +1,12 @@ +{ + "commands": [ + { + "command": "vp run build # first build populates the cache", + "ignoreOutput": true + }, + "ls dist # build output exists", + "rm -rf dist # remove the build output", + "vp run build 2>&1 | grep 'cache hit' # rebuild hits cache", + "ls dist # dist auto-restored on cache hit (no synthetic output config)" + ] +} diff --git a/packages/cli/snap-tests/vp-build-auto-output-restoration/vite.config.ts b/packages/cli/snap-tests/vp-build-auto-output-restoration/vite.config.ts new file mode 100644 index 0000000000..1f066d0132 --- /dev/null +++ b/packages/cli/snap-tests/vp-build-auto-output-restoration/vite.config.ts @@ -0,0 +1,9 @@ +export default { + run: { + tasks: { + build: { + command: 'vp build', + }, + }, + }, +}; diff --git a/packages/cli/snap-tests/vp-build-auto-tracked-env/index.html b/packages/cli/snap-tests/vp-build-auto-tracked-env/index.html new file mode 100644 index 0000000000..7febab8c7e --- /dev/null +++ b/packages/cli/snap-tests/vp-build-auto-tracked-env/index.html @@ -0,0 +1,8 @@ + + + + + + diff --git a/packages/cli/snap-tests/vp-build-auto-tracked-env/package.json b/packages/cli/snap-tests/vp-build-auto-tracked-env/package.json new file mode 100644 index 0000000000..aaab903777 --- /dev/null +++ b/packages/cli/snap-tests/vp-build-auto-tracked-env/package.json @@ -0,0 +1,4 @@ +{ + "name": "vp-build-auto-tracked-env-test", + "private": true +} diff --git a/packages/cli/snap-tests/vp-build-auto-tracked-env/snap.txt b/packages/cli/snap-tests/vp-build-auto-tracked-env/snap.txt new file mode 100644 index 0000000000..6b69e65233 --- /dev/null +++ b/packages/cli/snap-tests/vp-build-auto-tracked-env/snap.txt @@ -0,0 +1,37 @@ +> VITE_GREETING=hello vp run build # first build +$ vp build +vite v building client environment for production... +transforming...✓ modules transformed. +rendering chunks... +computing gzip size... +dist/index.html kB │ gzip: kB +dist/assets/index-Dra_-aT4.js kB │ gzip: kB + +✓ built in ms + + +> VITE_GREETING=hello vp run build # same env, cache hit +$ vp build ◉ cache hit, replaying +vite v building client environment for production... +transforming...✓ modules transformed. +rendering chunks... +computing gzip size... +dist/index.html kB │ gzip: kB +dist/assets/index-Dra_-aT4.js kB │ gzip: kB + +✓ built in ms + +--- +vp run: cache hit, ms saved. + +> VITE_GREETING=world vp run build # VITE_ env changed, cache miss (tracked via vite-task-client) +$ vp build ○ cache miss: env 'VITE_GREETING' changed, executing +vite v building client environment for production... +transforming...✓ modules transformed. +rendering chunks... +computing gzip size... +dist/index.html kB │ gzip: kB +dist/assets/index-Dra_-aT4.js kB │ gzip: kB + +✓ built in ms + diff --git a/packages/cli/snap-tests/vp-build-auto-tracked-env/steps.json b/packages/cli/snap-tests/vp-build-auto-tracked-env/steps.json new file mode 100644 index 0000000000..57c9586df6 --- /dev/null +++ b/packages/cli/snap-tests/vp-build-auto-tracked-env/steps.json @@ -0,0 +1,7 @@ +{ + "commands": [ + "VITE_GREETING=hello vp run build # first build", + "VITE_GREETING=hello vp run build # same env, cache hit", + "VITE_GREETING=world vp run build # VITE_ env changed, cache miss (tracked via vite-task-client)" + ] +} diff --git a/packages/cli/snap-tests/vp-build-auto-tracked-env/vite.config.ts b/packages/cli/snap-tests/vp-build-auto-tracked-env/vite.config.ts new file mode 100644 index 0000000000..1f066d0132 --- /dev/null +++ b/packages/cli/snap-tests/vp-build-auto-tracked-env/vite.config.ts @@ -0,0 +1,9 @@ +export default { + run: { + tasks: { + build: { + command: 'vp build', + }, + }, + }, +}; diff --git a/packages/cli/snap-tests/vp-fmt-cache/package.json b/packages/cli/snap-tests/vp-fmt-cache/package.json new file mode 100644 index 0000000000..69fe3a241c --- /dev/null +++ b/packages/cli/snap-tests/vp-fmt-cache/package.json @@ -0,0 +1,7 @@ +{ + "name": "vp-fmt-cache-test", + "type": "module", + "scripts": { + "fmt": "vp fmt" + } +} diff --git a/packages/cli/snap-tests/vp-fmt-cache/snap.txt b/packages/cli/snap-tests/vp-fmt-cache/snap.txt new file mode 100644 index 0000000000..3493231da9 --- /dev/null +++ b/packages/cli/snap-tests/vp-fmt-cache/snap.txt @@ -0,0 +1,11 @@ +> vp run fmt # first run populates the cache +$ vp fmt +Finished in ms on 4 files using threads. + + +> vp run fmt # second run should be a cache hit +$ vp fmt ◉ cache hit, replaying +Finished in ms on 4 files using threads. + +--- +vp run: cache hit, ms saved. diff --git a/packages/cli/snap-tests/vp-fmt-cache/src/index.js b/packages/cli/snap-tests/vp-fmt-cache/src/index.js new file mode 100644 index 0000000000..7d658310b0 --- /dev/null +++ b/packages/cli/snap-tests/vp-fmt-cache/src/index.js @@ -0,0 +1,3 @@ +export function add(a, b) { + return a + b; +} diff --git a/packages/cli/snap-tests/vp-fmt-cache/steps.json b/packages/cli/snap-tests/vp-fmt-cache/steps.json new file mode 100644 index 0000000000..eff58ca91b --- /dev/null +++ b/packages/cli/snap-tests/vp-fmt-cache/steps.json @@ -0,0 +1,6 @@ +{ + "commands": [ + "vp run fmt # first run populates the cache", + "vp run fmt # second run should be a cache hit" + ] +} diff --git a/packages/cli/snap-tests/vp-fmt-cache/vite.config.ts b/packages/cli/snap-tests/vp-fmt-cache/vite.config.ts new file mode 100644 index 0000000000..188b4e6833 --- /dev/null +++ b/packages/cli/snap-tests/vp-fmt-cache/vite.config.ts @@ -0,0 +1,8 @@ +export default { + fmt: { + indentWidth: 2, + }, + run: { + cache: true, + }, +}; diff --git a/packages/cli/snap-tests/vp-lint-cache/.gitignore b/packages/cli/snap-tests/vp-lint-cache/.gitignore new file mode 100644 index 0000000000..231280dab9 --- /dev/null +++ b/packages/cli/snap-tests/vp-lint-cache/.gitignore @@ -0,0 +1,7 @@ +# Prevent oxlint from scanning node_modules. +# Without this, oxlint reads files in node_modules/.vite/task-cache, causing +# fspy to fingerprint the cache directory as an input. The cache directory +# changes between runs (DB writes, last-summary.json), producing flaky +# cache-miss reasons that alternate between '' and +# 'node_modules/.vite/task-cache'. +node_modules diff --git a/packages/cli/snap-tests/vp-lint-cache/package.json b/packages/cli/snap-tests/vp-lint-cache/package.json new file mode 100644 index 0000000000..ca8b9bb1ec --- /dev/null +++ b/packages/cli/snap-tests/vp-lint-cache/package.json @@ -0,0 +1,7 @@ +{ + "name": "vp-lint-cache-test", + "type": "module", + "scripts": { + "lint": "vp lint" + } +} diff --git a/packages/cli/snap-tests/vp-lint-cache/snap.txt b/packages/cli/snap-tests/vp-lint-cache/snap.txt new file mode 100644 index 0000000000..b20c6e3544 --- /dev/null +++ b/packages/cli/snap-tests/vp-lint-cache/snap.txt @@ -0,0 +1,13 @@ +> vp run lint # first run populates the cache +$ vp lint +Found 0 warnings and 0 errors. +Finished in ms on 2 files with rules using threads. + + +> vp run lint # second run should be a cache hit +$ vp lint ◉ cache hit, replaying +Found 0 warnings and 0 errors. +Finished in ms on 2 files with rules using threads. + +--- +vp run: cache hit, ms saved. diff --git a/packages/cli/snap-tests/vp-lint-cache/src/index.js b/packages/cli/snap-tests/vp-lint-cache/src/index.js new file mode 100644 index 0000000000..7d658310b0 --- /dev/null +++ b/packages/cli/snap-tests/vp-lint-cache/src/index.js @@ -0,0 +1,3 @@ +export function add(a, b) { + return a + b; +} diff --git a/packages/cli/snap-tests/vp-lint-cache/steps.json b/packages/cli/snap-tests/vp-lint-cache/steps.json new file mode 100644 index 0000000000..89cffd17e4 --- /dev/null +++ b/packages/cli/snap-tests/vp-lint-cache/steps.json @@ -0,0 +1,6 @@ +{ + "commands": [ + "vp run lint # first run populates the cache", + "vp run lint # second run should be a cache hit" + ] +} diff --git a/packages/cli/snap-tests/vp-lint-cache/vite.config.ts b/packages/cli/snap-tests/vp-lint-cache/vite.config.ts new file mode 100644 index 0000000000..5f95ceeb78 --- /dev/null +++ b/packages/cli/snap-tests/vp-lint-cache/vite.config.ts @@ -0,0 +1,5 @@ +export default { + run: { + cache: true, + }, +}; diff --git a/packages/cli/src/run-config.ts b/packages/cli/src/run-config.ts index 3a8477c6e8..cd780fce5b 100644 --- a/packages/cli/src/run-config.ts +++ b/packages/cli/src/run-config.ts @@ -1,18 +1,24 @@ // This file is auto-generated by `cargo test`. Do not edit manually. -export type AutoInput = { +export type AutoTracking = { /** - * Automatically track which files the task reads + * Enable automatic file tracking for this input or output list. */ auto: boolean, }; export type Command = string | Array; -export type GlobWithBase = { +export type DependencyType = "dependencies" | "devDependencies" | "peerDependencies"; + +export type DependsOnEntry = string | UserPackageDependency; + +export type DependsOnFrom = DependencyType | Array; + +export type GlobWithBase = { /** * The glob pattern (positive or negative starting with `!`) */ -pattern: string, +pattern: string, /** * The base directory for resolving the pattern */ @@ -20,31 +26,38 @@ base: InputBase, }; export type InputBase = "package" | "workspace"; -export type Task = { +export type Task = { /** * Command to run, or an array of commands to run in order. */ -command: Command, +command: Command, /** * The working directory for the task, relative to the package root (not workspace root). */ -cwd?: string, +cwd?: string, /** - * Dependencies of this task. Use `package-name#task-name` to refer to tasks in other packages. + * Tasks that must run before this task. + * + * - A string runs one named task, such as `"build"` in the same package or + * `"package-name#build"` in another package. + * - An object runs a task in direct workspace dependency packages selected + * from package.json fields. For example, + * `{ "task": "build", "from": "dependencies" }` runs `build` in each + * direct workspace dependency that defines a `build` task. */ -dependsOn?: Array, } & ({ +dependsOn?: Array, } & ({ /** * Whether to cache the task */ -cache?: true, +cache?: true, /** * Environment variable names to be fingerprinted and passed to the task. */ -env?: Array, +env?: Array, /** * Environment variable names to be passed to the task without fingerprinting. */ -untrackedEnv?: Array, +untrackedEnv?: Array, /** * Files to include in the cache fingerprint. * @@ -55,16 +68,18 @@ untrackedEnv?: Array, * - `{auto: true}` enables automatic file tracking * - Negative patterns (e.g. `"!dist/**"`) exclude matched files */ -input?: Array, +input?: Array, /** - * Output files to archive after a successful run and restore on cache hit. + * Output files to archive and restore on cache hit. * - * - Omitted or `[]` (empty): no output archiving (default) + * - Omitted: automatically tracks which files the task writes + * - `[]` (empty): disables output restoration entirely * - Glob patterns (e.g. `"dist/**"`) select specific output files, relative to the package directory * - `{pattern: "...", base: "workspace" | "package"}` specifies a glob with an explicit base directory + * - `{auto: true}` enables automatic output tracking * - Negative patterns (e.g. `"!dist/cache/**"`) exclude matched files */ -output?: Array, } | { +output?: Array, } | { /** * Whether to cache the task */ @@ -72,7 +87,7 @@ cache: false, }); export type TaskDefinition = Task | Command; -export type UserGlobalCacheConfig = boolean | { +export type UserGlobalCacheConfig = boolean | { /** * Enable caching for package.json scripts not defined in the `tasks` map. * @@ -81,7 +96,7 @@ export type UserGlobalCacheConfig = boolean | { * * Default: `false` */ -scripts?: boolean, +scripts?: boolean, /** * Global cache kill switch for task entries. * @@ -93,18 +108,28 @@ scripts?: boolean, */ tasks?: boolean, }; -export type RunConfig = { +export type UserPackageDependency = { +/** + * Task name to run in dependency packages. + */ +task: string, +/** + * Package.json dependency field or fields to use when selecting direct dependency packages. + */ +from: DependsOnFrom, }; + +export type RunConfig = { /** * Root-level cache configuration. * * This option can only be set in the workspace root's config file. * Setting it in a package's config will result in an error. */ -cache?: UserGlobalCacheConfig, +cache?: UserGlobalCacheConfig, /** * Task definitions: full task objects, command strings, or command string arrays. */ -tasks?: { [key in string]: TaskDefinition }, +tasks?: { [key in string]: TaskDefinition }, /** * Whether to automatically run `preX`/`postX` package.json scripts as * lifecycle hooks when script `X` is executed. @@ -115,4 +140,4 @@ tasks?: { [key in string]: TaskDefinition }, * This option can only be set in the workspace root's config file. * Setting it in a package's config will result in an error. */ -enablePrePostScripts?: boolean, }; \ No newline at end of file +enablePrePostScripts?: boolean, }; diff --git a/packages/core/build.ts b/packages/core/build.ts index c44383c9c9..c8a7df2e40 100644 --- a/packages/core/build.ts +++ b/packages/core/build.ts @@ -315,9 +315,27 @@ async function buildVite() { if (!existsSync(dir)) { await mkdir(dir, { recursive: true }); } - const rewrittenFile = rewriteModuleSpecifiers(file, srcDtsFile, { + let rewrittenFile = rewriteModuleSpecifiers(file, srcDtsFile, { rules: [...createViteRewriteRules(pkgJson.name), ...createRolldownRewriteRules(pkgJson.name)], }); + // Upstream bug (vitejs/vite#21863, commit cc39e5540): `node/index.ts` + // re-exports `KnownQueryTypeMap` from `#types/importGlob`, but the type is + // declared there without `export`. Bundling vite's types into a downstream + // project then fails with `[MISSING_EXPORT]`. Add the missing `export` here + // until it is fixed upstream (drop this once vite exports it). + if (relativePath === '/importGlob.d.ts') { + const knownQueryTypeMapPattern = /^type KnownQueryTypeMap\b/m; + if (!knownQueryTypeMapPattern.test(rewrittenFile)) { + throw new Error( + 'Expected vite types/importGlob.d.ts to declare non-exported KnownQueryTypeMap. ' + + 'Upstream may have fixed vitejs/vite#21863; remove the KnownQueryTypeMap export workaround from packages/core/build.ts.', + ); + } + rewrittenFile = rewrittenFile.replace( + knownQueryTypeMapPattern, + 'export type KnownQueryTypeMap', + ); + } await writeFile(dstFilePath, rewrittenFile); }