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
43 changes: 28 additions & 15 deletions packages/cli/binding/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,13 +332,7 @@ impl SubcommandResolver {
cache_config: UserCacheConfig::with_config(EnabledCacheConfig {
env: Some(Box::new([Str::from("VITE_*")])),
untracked_env: None,
input: Some(vec![
UserInputEntry::Auto(AutoInput { auto: true }),
UserInputEntry::GlobWithBase(GlobWithBase {
pattern: Str::from("!node_modules/.vite-temp/**"),
base: InputBase::Workspace,
}),
]),
input: Some(build_pack_cache_inputs()),
}),
envs: merge_resolved_envs_with_version(envs, resolved.envs),
})
Expand Down Expand Up @@ -366,7 +360,14 @@ impl SubcommandResolver {
cache_config: UserCacheConfig::with_config(EnabledCacheConfig {
env: None,
untracked_env: None,
input: None,
input: Some(vec![
UserInputEntry::Auto(AutoInput { auto: true }),
exclude_glob("!node_modules/.vite-temp/**", InputBase::Package),
exclude_glob(
"!node_modules/.vite/vitest/**/results.json",
InputBase::Package,
),
]),
}),
envs: merge_resolved_envs_with_version(envs, resolved.envs),
})
Expand All @@ -390,13 +391,7 @@ impl SubcommandResolver {
cache_config: UserCacheConfig::with_config(EnabledCacheConfig {
env: None,
untracked_env: None,
input: Some(vec![
UserInputEntry::Auto(AutoInput { auto: true }),
UserInputEntry::GlobWithBase(GlobWithBase {
pattern: Str::from("!node_modules/.vite-temp/**"),
base: InputBase::Workspace,
}),
]),
input: Some(build_pack_cache_inputs()),
}),
envs: merge_resolved_envs(envs, resolved.envs),
})
Expand Down Expand Up @@ -504,6 +499,24 @@ impl SubcommandResolver {

/// Merge resolved environment variables from JS resolver into existing envs.
/// Does not override existing entries.
/// Create a negative glob entry to exclude a pattern from cache fingerprinting.
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.
/// 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<UserInputEntry> {
vec![
UserInputEntry::Auto(AutoInput { auto: true }),
exclude_glob("!node_modules/.vite-temp/**", InputBase::Workspace),
exclude_glob("!node_modules/.vite-temp/**", InputBase::Package),
exclude_glob("!dist/**", InputBase::Package),
]
}

fn merge_resolved_envs(
envs: &Arc<FxHashMap<Arc<OsStr>, Arc<OsStr>>>,
resolved_envs: Vec<(String, String)>,
Expand Down
2 changes: 0 additions & 2 deletions packages/cli/snap-tests/build-vite-env/snap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,3 @@ dist/assets/index-BnIqjoTZ.js <variable> kB │ gzip: <variable> kB

✓ built in <variable>ms

---
vp run: build-vite-env-test#build not cached because it modified its input. (Run `vp run --last-details` for full details)
11 changes: 11 additions & 0 deletions packages/cli/snap-tests/vp-cache-monorepo-missing/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "cache-monorepo-missing",
"private": true,
"workspaces": [
"packages/*"
],
"scripts": {
"ready": "vp run -r build"
},
"packageManager": "pnpm@10.32.1"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "lib",
"private": true,
"scripts": {
"build": "vp pack"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function add(a: number, b: number): number {
return a + b;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { defineConfig } from 'vite-plus';

export default defineConfig({});
4 changes: 4 additions & 0 deletions packages/cli/snap-tests/vp-cache-monorepo-missing/snap.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
> vp run --cache ready # first run
> vp run --cache ready 2>&1 | grep -E 'cache hit|modified' # second run should all hit cache
~/packages/lib$ vp pack ◉ cache hit, replaying
vp run: cache hit, <variable>ms saved.
9 changes: 9 additions & 0 deletions packages/cli/snap-tests/vp-cache-monorepo-missing/steps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"commands": [
{
"command": "vp run --cache ready # first run",
"ignoreOutput": true
},
"vp run --cache ready 2>&1 | grep -E 'cache hit|modified' # second run should all hit cache"
]
}
Loading