Skip to content

Commit 1e9cb11

Browse files
authored
fix(plan): extend the command's env context with prefix envs before interpreting it
1 parent b01df20 commit 1e9cb11

9 files changed

Lines changed: 69 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Changelog
22

3+
- **Fixed** Prefix environment assignments like `PATH=... command` now affect executable lookup during task planning, so tools provided only by the prefixed `PATH` can be resolved correctly ([#440](https://github.com/voidzero-dev/vite-task/pull/440))
34
- **Changed** Cache misses caused by a tracked env var now name the env var inline, for example `cache miss: env 'NODE_ENV' changed`, instead of the generic `envs changed` message ([#438](https://github.com/voidzero-dev/vite-task/pull/438))
45
- **Fixed** The task cache is now stored in a per-schema-version subdirectory (e.g. `node_modules/.vite/task-cache/v13/`), so switching between branches that pin different Vite+ versions no longer fails with `Unrecognized database version`. Each version keeps its own cache directory; a cache from a different version is ignored rather than aborting the run ([#433](https://github.com/voidzero-dev/vite-task/pull/433))
56
- **Added** A task's `env` and `untrackedEnv` glob patterns now support `!` negation: a `!`-prefixed pattern excludes matching variables (e.g. `["VITE_*", "!VITE_SECRET"]` tracks every `VITE_*` except `VITE_SECRET`) ([#425](https://github.com/voidzero-dev/vite-task/pull/425))

crates/vite_task_plan/src/plan.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,15 @@ async fn plan_task_as_execution_node(
141141
let mut context = context.duplicate();
142142
context.push_stack_frame(task_node_index, add_item_span.clone());
143143

144+
// This command's env context: extend the planning context with
145+
// the command's prefix envs (`FOO=1 tool ...`). Everything that
146+
// interprets the command reads this one context — program
147+
// lookup, plan-request callbacks, and nested-run planning. The
148+
// per-and-item duplicate above scopes the extension to this
149+
// command, matching shell semantics (`FOO=1 a && b` does not
150+
// set `FOO` for `b`).
151+
context.add_envs(and_item.envs.iter());
152+
144153
let mut args = and_item.args;
145154
let extra_args = if is_last_command && and_item_index == and_item_count - 1 {
146155
// For the last and_item of the last command, append extra args from the plan context
@@ -247,8 +256,6 @@ async fn plan_task_as_execution_node(
247256

248257
// Save task name before consuming the request
249258
let task_name = query_plan_request.query.task_name.clone();
250-
// Add prefix envs to the context
251-
context.add_envs(and_item.envs.iter());
252259
let QueryPlanRequest { query, plan_options } = query_plan_request;
253260
let query = Arc::new(query);
254261
let nested_plan =
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"scripts": {
3+
"check": "PATH= vtt"
4+
}
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[[plan]]
2+
name = "prefix_path_hides_tool_binary"
3+
args = ["run", "check"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Failed to find executable vtt under cwd <workspace>/ with PATH: : cannot find binary path
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// task graph
2+
[
3+
{
4+
"key": [
5+
"<workspace>/",
6+
"check"
7+
],
8+
"node": {
9+
"task_display": {
10+
"package_name": "",
11+
"task_name": "check",
12+
"package_path": "<workspace>/"
13+
},
14+
"resolved_config": {
15+
"commands": [
16+
"PATH= vtt"
17+
],
18+
"resolved_options": {
19+
"cwd": "<workspace>/",
20+
"cache_config": {
21+
"env_config": {
22+
"fingerprinted_envs": [],
23+
"untracked_env": [
24+
"<default untracked envs>"
25+
]
26+
},
27+
"input_config": {
28+
"includes_auto": true,
29+
"positive_globs": [],
30+
"negative_globs": []
31+
},
32+
"output_config": {
33+
"includes_auto": false,
34+
"positive_globs": [],
35+
"negative_globs": []
36+
}
37+
}
38+
}
39+
},
40+
"source": "PackageJsonScript"
41+
},
42+
"neighbors": []
43+
}
44+
]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"cache": true
3+
}

crates/vite_task_plan/tests/plan_snapshots/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ fn run_case_inner(
193193
"folder '{fixture_name}' should be a workspace root"
194194
);
195195

196-
let fake_bin_dir = std::path::PathBuf::from(std::env::var_os("CARGO_MANIFEST_DIR").unwrap())
197-
.join("tests/plan_snapshots/fake-bin");
196+
let manifest_dir = std::path::PathBuf::from(std::env::var_os("CARGO_MANIFEST_DIR").unwrap());
197+
let fake_bin_dir = manifest_dir.join("tests/plan_snapshots/fake-bin");
198198
let combined_path =
199199
Arc::<OsStr>::from(std::ffi::OsString::from(fake_bin_dir.to_str().unwrap()));
200200

crates/vite_task_plan/tests/plan_snapshots/redact.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ pub fn redact_snapshot(value: &impl Serialize, workspace_root: &str) -> serde_js
105105
.to_owned();
106106
let mut json_value = serde_json::to_value(value).unwrap();
107107

108-
// On Windows, paths might use either backslashes or forward slashes
109-
// Try both variants for workspace_root, manifest_dir, and tools_dir
108+
// On Windows, paths might use either backslashes or forward slashes.
110109
let workspace_root_forward = workspace_root.cow_replace('\\', "/");
111110
let manifest_dir_forward = manifest_dir.as_str().cow_replace('\\', "/");
112111
let tools_dir_forward = tools_dir_str.as_str().cow_replace('\\', "/");

0 commit comments

Comments
 (0)