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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Changelog

- **Added** Tasks now run with `VP_RUN=1` set, so tools can tell they are running under `vp run` instead of being invoked directly ([#570](https://github.com/voidzero-dev/vite-task/pull/570)).
- **Fixed** The task cache now supports much larger automatically tracked input sets without hitting wincode's default 4 MiB sequence preallocation limit ([#554](https://github.com/voidzero-dev/vite-task/pull/554)).
- **Fixed** npm workspace patterns beginning with `./` now discover matching packages correctly ([vite-plus#2201](https://github.com/voidzero-dev/vite-plus/issues/2201), [#547](https://github.com/voidzero-dev/vite-task/pull/547)).
- **Fixed** Failures while forwarding output from a started task process no longer incorrectly say the process failed to spawn ([#506](https://github.com/voidzero-dev/vite-task/issues/506)).
Expand Down
2 changes: 1 addition & 1 deletion crates/vite_task/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ pub use vite_task_graph::{
};
/// Re-exports useful for `CommandHandler` implementations.
pub use vite_task_plan::get_path_env;
pub use vite_task_plan::{plan_request, plan_request::ScriptCommand};
pub use vite_task_plan::{MARKER_ENV_NAME, plan_request, plan_request::ScriptCommand};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "vp-run-env",
"private": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[[e2e]]
name = "vp_run_env_marks_every_spawned_task"
comment = """
Every process a task spawns gets `VP_RUN=1`, so a tool can tell it was started by `vp run` instead of being typed directly.

The parent shell sets `VP_RUN=0` in both steps to show the marker is forced rather than inherited. The cached task also restricts passthrough to `env: ["NODE_ENV"]`, which filters the parent's value out entirely; the marker is set after that filtering, so it survives either way.
"""
steps = [
{ argv = [
"vt",
"run",
"print-marker-cached",
], envs = [
[
"VP_RUN",
"0",
],
], comment = "cached task: env passthrough cannot drop the marker" },
{ argv = [
"vt",
"run",
"print-marker-uncached",
], envs = [
[
"VP_RUN",
"0",
],
], comment = "uncached task: the parent environment flows through, but the marker still wins" },
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# vp_run_env_marks_every_spawned_task

Every process a task spawns gets `VP_RUN=1`, so a tool can tell it was started by `vp run` instead of being typed directly.

The parent shell sets `VP_RUN=0` in both steps to show the marker is forced rather than inherited. The cached task also restricts passthrough to `env: ["NODE_ENV"]`, which filters the parent's value out entirely; the marker is set after that filtering, so it survives either way.

## `VP_RUN=0 vt run print-marker-cached`

cached task: env passthrough cannot drop the marker

```
$ vtt print-env VP_RUN
1
```

## `VP_RUN=0 vt run print-marker-uncached`

uncached task: the parent environment flows through, but the marker still wins

```
$ vtt print-env VP_RUN ⊘ cache disabled
1
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"tasks": {
"print-marker-cached": {
"command": "vtt print-env VP_RUN",
"cache": true,
"env": ["NODE_ENV"],
"input": ["package.json"],
"output": []
},
"print-marker-uncached": {
"command": "vtt print-env VP_RUN",
"cache": false
}
}
}
6 changes: 6 additions & 0 deletions crates/vite_task_plan/src/envs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ use wincode::{SchemaRead, SchemaWrite};
const SHA256_DIGEST_LEN: usize = 32;
const SHA256_PREFIX: &str = "sha256:";

/// Name of the environment variable set to `1` in every process a task spawns.
///
/// Lets a tool tell that it is running as part of a task rather than having
/// been invoked directly.
pub const MARKER_ENV_NAME: &str = "VP_RUN";

/// SHA-256 digest of a fingerprinted environment variable value.
#[derive(SchemaWrite, SchemaRead, PartialEq, Eq, Clone, Copy)]
pub struct EnvValueHash([u8; SHA256_DIGEST_LEN]);
Expand Down
1 change: 1 addition & 0 deletions crates/vite_task_plan/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod ps1_shim;
use std::{collections::BTreeMap, ffi::OsStr, fmt::Debug, sync::Arc};

use context::PlanContext;
pub use envs::MARKER_ENV_NAME;
pub use error::Error;
pub use execution_graph::{DEFAULT_CONCURRENCY_LIMIT, ExecutionGraph};
pub use in_process::InProcessExecution;
Expand Down
9 changes: 8 additions & 1 deletion crates/vite_task_plan/src/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use crate::{
ExecutionItem, ExecutionItemDisplay, ExecutionItemKind, LeafExecutionKind, PlanContext,
SpawnCommand, SpawnExecution, TaskExecution,
cache_metadata::{CacheMetadata, ExecutionCacheKey, ProgramFingerprint, SpawnFingerprint},
envs::{EnvFingerprints, EnvValueHash},
envs::{EnvFingerprints, EnvValueHash, MARKER_ENV_NAME},
error::{CdCommandError, Error, PathFingerprintError, PathFingerprintErrorKind, PathType},
execution_graph::{ExecutionGraph, ExecutionNodeIndex, InnerExecutionGraph},
in_process::InProcessExecution,
Expand Down Expand Up @@ -680,6 +680,13 @@ fn plan_spawn_execution(
}
}

// Mark the child as task-spawned. Set after `EnvFingerprints::resolve` has
// filtered `spawn_envs`, so a task's `env`/`untrackedEnv` patterns cannot
// drop it, and always to `1`, so a stale value in the parent environment
// cannot make a task look like it was invoked directly. A prefix
// assignment (`VP_RUN=… command`) still wins: those are applied below.
spawn_envs.insert(OsStr::new(MARKER_ENV_NAME).into(), OsStr::new("1").into());
Comment thread
wan9chi marked this conversation as resolved.
Comment thread
wan9chi marked this conversation as resolved.

// Add prefix envs to spawn envs.
spawn_envs.extend(prefix_envs.iter().map(|(name, value)| {
(OsStr::new(name.as_str()).into(), OsStr::new(value.as_str()).into())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@
"spawn_envs": {
"FORCE_COLOR": "1",
"PATH": "<workspace>/node_modules/.bin:<tools>",
"TEST_VAR": "hello_world"
"TEST_VAR": "hello_world",
"VP_RUN": "1"
},
"cwd": "<workspace>/"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
],
"spawn_envs": {
"NO_COLOR": "1",
"PATH": "<workspace>/node_modules/.bin:<tools>"
"PATH": "<workspace>/node_modules/.bin:<tools>",
"VP_RUN": "1"
},
"cwd": "<workspace>/"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
],
"spawn_envs": {
"FORCE_COLOR": "1",
"PATH": "<workspace>/node_modules/.bin:<tools>"
"PATH": "<workspace>/node_modules/.bin:<tools>",
"VP_RUN": "1"
},
"cwd": "<workspace>/"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
],
"spawn_envs": {
"FORCE_COLOR": "1",
"PATH": "<workspace>/node_modules/.bin:<tools>"
"PATH": "<workspace>/node_modules/.bin:<tools>",
"VP_RUN": "1"
},
"cwd": "<workspace>/"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
],
"spawn_envs": {
"FORCE_COLOR": "1",
"PATH": "<workspace>/node_modules/.bin:<tools>"
"PATH": "<workspace>/node_modules/.bin:<tools>",
"VP_RUN": "1"
},
"cwd": "<workspace>/"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
],
"spawn_envs": {
"NO_COLOR": "1",
"PATH": "<workspace>/node_modules/.bin:<tools>"
"PATH": "<workspace>/node_modules/.bin:<tools>",
"VP_RUN": "1"
},
"cwd": "<workspace>/"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
],
"spawn_envs": {
"NO_COLOR": "1",
"PATH": "<workspace>/node_modules/.bin:<tools>"
"PATH": "<workspace>/node_modules/.bin:<tools>",
"VP_RUN": "1"
},
"cwd": "<workspace>/"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
],
"spawn_envs": {
"NO_COLOR": "1",
"PATH": "<workspace>/node_modules/.bin:<tools>"
"PATH": "<workspace>/node_modules/.bin:<tools>",
"VP_RUN": "1"
},
"cwd": "<workspace>/"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@
],
"spawn_envs": {
"FORCE_COLOR": "1",
"PATH": "<workspace>/node_modules/.bin:<tools>"
"PATH": "<workspace>/node_modules/.bin:<tools>",
"VP_RUN": "1"
},
"cwd": "<workspace>/"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
],
"spawn_envs": {
"FORCE_COLOR": "1",
"PATH": "<workspace>/node_modules/.bin:<tools>"
"PATH": "<workspace>/node_modules/.bin:<tools>",
"VP_RUN": "1"
},
"cwd": "<workspace>/"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@
],
"spawn_envs": {
"FORCE_COLOR": "1",
"PATH": "<workspace>/node_modules/.bin:<tools>"
"PATH": "<workspace>/node_modules/.bin:<tools>",
"VP_RUN": "1"
},
"cwd": "<workspace>/"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
],
"spawn_envs": {
"FORCE_COLOR": "1",
"PATH": "<workspace>/node_modules/.bin:<tools>"
"PATH": "<workspace>/node_modules/.bin:<tools>",
"VP_RUN": "1"
},
"cwd": "<workspace>/"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
],
"spawn_envs": {
"FORCE_COLOR": "1",
"PATH": "<workspace>/node_modules/.bin:<tools>"
"PATH": "<workspace>/node_modules/.bin:<tools>",
"VP_RUN": "1"
},
"cwd": "<workspace>/"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@
],
"spawn_envs": {
"FORCE_COLOR": "1",
"PATH": "<workspace>/node_modules/.bin:<tools>"
"PATH": "<workspace>/node_modules/.bin:<tools>",
"VP_RUN": "1"
},
"cwd": "<workspace>/"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
],
"spawn_envs": {
"NO_COLOR": "1",
"PATH": "<workspace>/node_modules/.bin:<tools>"
"PATH": "<workspace>/node_modules/.bin:<tools>",
"VP_RUN": "1"
},
"cwd": "<workspace>/"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
],
"spawn_envs": {
"FORCE_COLOR": "1",
"PATH": "<workspace>/node_modules/.bin:<tools>"
"PATH": "<workspace>/node_modules/.bin:<tools>",
"VP_RUN": "1"
},
"cwd": "<workspace>/"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
],
"spawn_envs": {
"NO_COLOR": "1",
"PATH": "<workspace>/node_modules/.bin:<tools>"
"PATH": "<workspace>/node_modules/.bin:<tools>",
"VP_RUN": "1"
},
"cwd": "<workspace>/"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
],
"spawn_envs": {
"FORCE_COLOR": "1",
"PATH": "<workspace>/node_modules/.bin:<tools>"
"PATH": "<workspace>/node_modules/.bin:<tools>",
"VP_RUN": "1"
},
"cwd": "<workspace>/"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
],
"spawn_envs": {
"NO_COLOR": "1",
"PATH": "<workspace>/node_modules/.bin:<tools>"
"PATH": "<workspace>/node_modules/.bin:<tools>",
"VP_RUN": "1"
},
"cwd": "<workspace>/"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
],
"spawn_envs": {
"NO_COLOR": "1",
"PATH": "<workspace>/node_modules/.bin:<tools>"
"PATH": "<workspace>/node_modules/.bin:<tools>",
"VP_RUN": "1"
},
"cwd": "<workspace>/"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
],
"spawn_envs": {
"NO_COLOR": "1",
"PATH": "<workspace>/node_modules/.bin:<tools>"
"PATH": "<workspace>/node_modules/.bin:<tools>",
"VP_RUN": "1"
},
"cwd": "<workspace>/"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
],
"spawn_envs": {
"NO_COLOR": "1",
"PATH": "<workspace>/node_modules/.bin:<tools>"
"PATH": "<workspace>/node_modules/.bin:<tools>",
"VP_RUN": "1"
},
"cwd": "<workspace>/"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
],
"spawn_envs": {
"FORCE_COLOR": "1",
"PATH": "<workspace>/node_modules/.bin:<tools>"
"PATH": "<workspace>/node_modules/.bin:<tools>",
"VP_RUN": "1"
},
"cwd": "<workspace>/"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
],
"spawn_envs": {
"FORCE_COLOR": "1",
"PATH": "<workspace>/node_modules/.bin:<tools>"
"PATH": "<workspace>/node_modules/.bin:<tools>",
"VP_RUN": "1"
},
"cwd": "<workspace>/"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
],
"spawn_envs": {
"NO_COLOR": "1",
"PATH": "<workspace>/node_modules/.bin:<tools>"
"PATH": "<workspace>/node_modules/.bin:<tools>",
"VP_RUN": "1"
},
"cwd": "<workspace>/"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
],
"spawn_envs": {
"FORCE_COLOR": "1",
"PATH": "<workspace>/node_modules/.bin:<tools>"
"PATH": "<workspace>/node_modules/.bin:<tools>",
"VP_RUN": "1"
},
"cwd": "<workspace>/src"
}
Expand Down
Loading
Loading