Skip to content

Commit 2d380bf

Browse files
wan9chiclaude
andcommitted
feat: integrate vite-task runner-aware tools (auto output + tracked envs)
Vite reports its inputs/outputs/envs to the `vp` runner via `@voidzero-dev/vite-task-client`, so `vp build` no longer needs a hand-synthesized cache config. - Bump vite-task git deps to 6e634c65 (runner-aware IPC server/client + embedded napi addon); regenerate the napi binding (RunnerClient/load) and run-config.ts. - Point the vite behind vp build/vp dev to latest vitejs/vite (c13a37b53), which carries the vite-task-client integration. - Bundle @voidzero-dev/vite-task-client into core: vite lists it external via its declared deps; it is a tiny pure-JS wrapper that loads the napi addon by absolute path from VP_RUN_NODE_CLIENT_PATH (no-op when absent), so inlining it avoids a separate runtime dependency. - Remove vp build's synthetic cache config (env: [VITE_*], manual input excludes). All-None EnabledCacheConfig keeps caching enabled with auto input/output inference (output restoration); vp dev stays disabled. - Snap tests: vp-build-auto-output-restoration, vp-build-auto-tracked-env. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 52a9999 commit 2d380bf

22 files changed

Lines changed: 296 additions & 60 deletions

File tree

Cargo.lock

Lines changed: 100 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ dunce = "1.0.5"
192192
fast-glob = "1.0.0"
193193
flate2 = { version = "=1.1.9", features = ["zlib-rs"] }
194194
form_urlencoded = "1.2.1"
195-
fspy = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "5833b374c6edb05c2f2f8e133ff8c796b378472a" }
195+
fspy = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "6e634c6550777fc2bc922b86be52fe8fc9142594" }
196196
futures = "0.3.31"
197197
futures-util = "0.3.31"
198198
glob = "0.3.2"
@@ -302,11 +302,11 @@ vite_pm_cli = { path = "crates/vite_pm_cli" }
302302
vite_setup = { path = "crates/vite_setup" }
303303
vite_shared = { path = "crates/vite_shared" }
304304
vite_static_config = { path = "crates/vite_static_config" }
305-
vite_path = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "5833b374c6edb05c2f2f8e133ff8c796b378472a" }
306-
vite_powershell = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "5833b374c6edb05c2f2f8e133ff8c796b378472a" }
307-
vite_str = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "5833b374c6edb05c2f2f8e133ff8c796b378472a" }
308-
vite_task = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "5833b374c6edb05c2f2f8e133ff8c796b378472a" }
309-
vite_workspace = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "5833b374c6edb05c2f2f8e133ff8c796b378472a" }
305+
vite_path = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "6e634c6550777fc2bc922b86be52fe8fc9142594" }
306+
vite_powershell = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "6e634c6550777fc2bc922b86be52fe8fc9142594" }
307+
vite_str = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "6e634c6550777fc2bc922b86be52fe8fc9142594" }
308+
vite_task = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "6e634c6550777fc2bc922b86be52fe8fc9142594" }
309+
vite_workspace = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "6e634c6550777fc2bc922b86be52fe8fc9142594" }
310310
walkdir = "2.5.0"
311311
wax = "0.6.0"
312312
which = "8.0.0"

packages/cli/binding/index.cjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,3 +846,5 @@ module.exports.runCommand = nativeBinding.runCommand;
846846
module.exports.shouldPrintVitePlusHeader = nativeBinding.shouldPrintVitePlusHeader;
847847
module.exports.vitePlusHeader = nativeBinding.vitePlusHeader;
848848
module.exports.wrapLazyPlugins = nativeBinding.wrapLazyPlugins;
849+
module.exports.RunnerClient = nativeBinding.RunnerClient;
850+
module.exports.load = nativeBinding.load;

packages/cli/binding/index.d.cts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3622,3 +3622,40 @@ export declare function vitePlusHeader(): string;
36223622
* `vite-plus` when needed.
36233623
*/
36243624
export declare function wrapLazyPlugins(viteConfigPath: string): MergeJsonConfigResult;
3625+
/**
3626+
* Handle returned by [`load`]. Holds the IPC connection and exposes the
3627+
* runner-side operations as instance methods.
3628+
*/
3629+
export declare class RunnerClient {
3630+
ignoreInput(path: string): void;
3631+
ignoreOutput(path: string): void;
3632+
disableCache(): void;
3633+
getEnv(name: string, options?: GetEnvOptions | undefined | null): string | null;
3634+
getEnvs(pattern: string, options?: GetEnvOptions | undefined | null): Record<string, string>;
3635+
}
3636+
3637+
/**
3638+
* Options for [`RunnerClient::get_env`] and [`RunnerClient::get_envs`].
3639+
*
3640+
* Modeled as a JS plain object rather than a positional boolean so future
3641+
* knobs (e.g. a `default` value) can be added without an ABI break on the
3642+
* JS wrapper side.
3643+
*
3644+
* Every field is optional so the napi addon — the cross-version API
3645+
* stability boundary between the runner-shipped `.node` and the
3646+
* separately-npm-published JS wrapper — can fill in defaults and let old
3647+
* wrappers keep working against new runners (and vice versa).
3648+
*/
3649+
export interface GetEnvOptions {
3650+
/**
3651+
* Whether the runner should record this env as a cache-key dependency.
3652+
* Defaults to `true`.
3653+
*/
3654+
tracked?: boolean;
3655+
}
3656+
3657+
/**
3658+
* Connect to the runner and return a [`RunnerClient`]. Throws when the
3659+
* IPC env is missing or the connection fails.
3660+
*/
3661+
export declare function load(): RunnerClient;

packages/cli/binding/src/cli/resolver.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,16 @@ impl SubcommandResolver {
171171
.chain(iter::once(Str::from("build")))
172172
.chain(args.into_iter().map(Str::from))
173173
.collect(),
174+
// No synthetic cache config: vite reports its inputs/outputs/
175+
// envs to the runner via `@voidzero-dev/vite-task-client`.
176+
// All fields `None` keep caching enabled with auto input and
177+
// auto output inference (the latter drives output restoration);
178+
// vite's `ignoreInput`/`ignoreOutput`/`getEnv`/`getEnvs` refine
179+
// the fingerprint at runtime.
174180
cache_config: UserCacheConfig::with_config(EnabledCacheConfig {
175-
env: Some(Box::new([Str::from("VITE_*")])),
181+
env: None,
176182
untracked_env: None,
177-
input: Some(build_pack_cache_inputs()),
183+
input: None,
178184
output: None,
179185
}),
180186
envs: merge_resolved_envs_with_version(envs, resolved.envs),

packages/cli/snap-tests/build-vite-env/snap.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ dist/assets/index-Dra_-aT4.js <variable> kB │ gzip: <variable> kB
2525
vp run: cache hit, <variable>ms saved.
2626

2727
> VITE_MY_VAR=2 vp run build # env changed, should miss cache
28-
$ vp build ○ cache miss: envs changed, executing
28+
$ vp build ○ cache miss: tracked env glob 'VITE_*' changed, executing
2929
vite v<semver> building client environment for production...
3030
transforming...✓ <variable> modules transformed.
3131
rendering chunks...

packages/cli/snap-tests/plain-terminal-ui-nested/snap.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ Found 0 warnings and 0 errors.
88
Finished in <variable>ms on 3 files with <variable> rules using <variable> threads.
99

1010
---
11-
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)
11+
vp run: 0/2 cache hit (0%). (Run `vp run --last-details` for full details)
1212

1313
> echo 'console.log(123)' > a.ts
1414
> vp run hello # report cache status from the inner runner
15-
$ vp lint ./src
15+
$ vp lint ./src ◉ cache hit, replaying
1616
Found 0 warnings and 0 errors.
1717
Finished in <variable>ms on 1 file with <variable> rules using <variable> threads.
1818

19-
$ vp lint
19+
$ vp lint ○ cache miss: 'a.ts' modified, executing
2020
Found 0 warnings and 0 errors.
2121
Finished in <variable>ms on 3 files with <variable> rules using <variable> threads.
2222

2323
---
24-
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)
24+
vp run: 1/2 cache hit (50%), <variable>ms saved. (Run `vp run --last-details` for full details)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!doctype html>
2+
<html>
3+
<body>
4+
<script type="module">
5+
console.log('hello');
6+
</script>
7+
</body>
8+
</html>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "vp-build-auto-output-restoration-test",
3+
"private": true
4+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
> vp run build # first build populates the cache
2+
> ls dist # build output exists
3+
assets
4+
index.html
5+
6+
> rm -rf dist # remove the build output
7+
> vp run build 2>&1 | grep 'cache hit' # rebuild hits cache
8+
$ vp build ◉ cache hit, replaying
9+
vp run: cache hit, <variable>ms saved.
10+
11+
> ls dist # dist auto-restored on cache hit (no synthetic output config)
12+
assets
13+
index.html

0 commit comments

Comments
 (0)