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
111 changes: 52 additions & 59 deletions Cargo.lock

Large diffs are not rendered by default.

22 changes: 12 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,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 = "790b15282344e00f508e74bc0e10ad0feffcbbf2" }
fspy = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "7d69d6577ecf6bd83deee32186de59918a712873" }
futures = "0.3.31"
futures-util = "0.3.31"
glob = "0.3.2"
Expand Down Expand Up @@ -246,8 +246,8 @@ pretty_assertions = "1.4.1"
phf = "0.14.0"
prettyplease = "0.2.32"
proc-macro2 = "1"
pty_terminal_test = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "790b15282344e00f508e74bc0e10ad0feffcbbf2" }
pty_terminal_test_client = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "790b15282344e00f508e74bc0e10ad0feffcbbf2" }
pty_terminal_test = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "7d69d6577ecf6bd83deee32186de59918a712873" }
pty_terminal_test_client = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "7d69d6577ecf6bd83deee32186de59918a712873" }
quote = "1"
rayon = "1.10.0"
regex = "1.11.1"
Expand All @@ -271,7 +271,7 @@ sha2 = "0.10.9"
shell-escape = "0.1.5"
simdutf8 = "0.1.5"
smallvec = { version = "1.16.0", features = ["union"] }
snapshot_test = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "790b15282344e00f508e74bc0e10ad0feffcbbf2" }
snapshot_test = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "7d69d6577ecf6bd83deee32186de59918a712873" }
string_cache = "0.9.0"
sugar_path = { version = "3", features = ["cached_current_dir"] }
supports-color = "3"
Expand Down Expand Up @@ -305,12 +305,13 @@ vp_setup = { path = "crates/vp_setup" }
vp_shared = { path = "crates/vp_shared" }
vp_static_config = { path = "crates/vp_static_config" }
vp_toolchain = { path = "crates/vp_toolchain" }
vt = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "790b15282344e00f508e74bc0e10ad0feffcbbf2" }
vt_path = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "790b15282344e00f508e74bc0e10ad0feffcbbf2" }
vt_powershell = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "790b15282344e00f508e74bc0e10ad0feffcbbf2" }
vt_select = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "790b15282344e00f508e74bc0e10ad0feffcbbf2" }
vt_str = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "790b15282344e00f508e74bc0e10ad0feffcbbf2" }
vt_workspace = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "790b15282344e00f508e74bc0e10ad0feffcbbf2" }
vt = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "7d69d6577ecf6bd83deee32186de59918a712873" }
vt_casefold = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "7d69d6577ecf6bd83deee32186de59918a712873" }
vt_path = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "7d69d6577ecf6bd83deee32186de59918a712873" }
vt_powershell = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "7d69d6577ecf6bd83deee32186de59918a712873" }
vt_select = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "7d69d6577ecf6bd83deee32186de59918a712873" }
vt_str = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "7d69d6577ecf6bd83deee32186de59918a712873" }
vt_workspace = { git = "https://github.com/voidzero-dev/vite-task.git", rev = "7d69d6577ecf6bd83deee32186de59918a712873" }
walkdir = "2.5.0"
webpki-root-certs = "1.0.9"
which = "8.0.6"
Expand Down Expand Up @@ -416,6 +417,7 @@ string_wizard = { path = "./rolldown/crates/string_wizard", features = ["serde"]
# pty_terminal_test_client = { path = "../vite-task/crates/pty_terminal_test_client" }
# snapshot_test = { path = "../vite-task/crates/snapshot_test" }
# vt = { path = "../vite-task/crates/vt" }
# vt_casefold = { path = "../vite-task/crates/vt_casefold" }
# vt_path = { path = "../vite-task/crates/vt_path" }
# vt_powershell = { path = "../vite-task/crates/vt_powershell" }
# vt_select = { path = "../vite-task/crates/vt_select" }
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ export default defineConfig({
tasks: {
'generate:icons': {
command: 'node scripts/generate-icons.js',
env: ['ICON_THEME'],
cache: {
env: ['ICON_THEME'],
},
},
},
},
Expand Down
15 changes: 8 additions & 7 deletions bench/benches/workspace_load.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(clippy::allow_attributes, clippy::disallowed_types)]

use std::{ffi::OsStr, hint::black_box, path::PathBuf, sync::Arc};
use std::{hint::black_box, path::PathBuf};

use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
use rustc_hash::FxHashMap;
Expand Down Expand Up @@ -70,9 +70,8 @@ fn bench_workspace_load(c: &mut Criterion) {
b.iter(|| {
runtime.block_on(async {
let mut owned_callbacks = BenchSessionConfig::default();
let envs: FxHashMap<Arc<OsStr>, Arc<OsStr>> = FxHashMap::default();
let mut session = Session::init_with(
envs,
FxHashMap::default(),
fixture_path.clone().into(),
owned_callbacks.as_callbacks(),
)
Expand All @@ -88,10 +87,12 @@ fn bench_workspace_load(c: &mut Criterion) {
b.iter(|| {
runtime.block_on(async {
let mut owned_callbacks = BenchSessionConfig::default();
let envs: FxHashMap<Arc<OsStr>, Arc<OsStr>> = FxHashMap::default();
let mut session =
Session::init_with(envs, path.clone().into(), owned_callbacks.as_callbacks())
.expect("Failed to create session");
let mut session = Session::init_with(
FxHashMap::default(),
path.clone().into(),
owned_callbacks.as_callbacks(),
)
.expect("Failed to create session");
black_box(
session.ensure_task_graph_loaded().await.expect("Failed to load task graph"),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ export default {
tasks: {
hello: {
command: 'node -p process.env.MY_ENV',
untrackedEnv,
cache: true,
cache: { untrackedEnv },
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ export default {
tasks: {
install: {
command: 'vp install --prod --silent',
input: [{ auto: true }, '!node_modules/**', '!package-lock.json'],
cache: {
input: [{ auto: true }, '!node_modules/**', '!package-lock.json'],
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ export default {
tasks: {
hello: {
command: 'node hello.mjs',
env: ['FOO', 'BAR'],
cache: true,
...(untrackedEnv && { untrackedEnv }),
cache: {
env: ['FOO', 'BAR'],
...(untrackedEnv && { untrackedEnv }),
},
...(cwd && { cwd }),
},
},
Expand Down
10 changes: 6 additions & 4 deletions crates/vp_static_config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1371,8 +1371,9 @@ mod tests {
tasks: {
hello: {
command: 'node hello.mjs',
envs: ['FOO', 'BAR'],
cache: true,
cache: {
env: ['FOO', 'BAR'],
},
},
},
},
Expand All @@ -1385,8 +1386,9 @@ mod tests {
"tasks": {
"hello": {
"command": "node hello.mjs",
"envs": ["FOO", "BAR"],
"cache": true,
"cache": {
"env": ["FOO", "BAR"],
},
}
}
}),
Expand Down
86 changes: 61 additions & 25 deletions docs/config/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ tasks: {
}
```

Use the object form when a task needs other fields like `cache`, `dependsOn`, `env`, or `input`.
Use the object form when a task needs other fields like `cache`, `dependsOn`, or `cwd`.

### `command`

Expand Down Expand Up @@ -156,10 +156,26 @@ See [Task Dependencies](/guide/run#task-dependencies) for details on how explici

### `cache`

- **Type:** `boolean`
- **Type:** `boolean | { env?: string[], untrackedEnv?: string[], input?: Array<...>, output?: Array<...> }`
- **Default:** `true`

Whether to cache this task's output. Set to `false` for tasks that should never be cached, like dev servers:
Whether and how to cache this task. Caching is enabled with default settings when `cache` is omitted, `true`, or `{}`.

Use an object to configure how the task is cached with [`cache.env`](#cache-env), [`cache.untrackedEnv`](#cache-untrackedenv), [`cache.input`](#cache-input), and [`cache.output`](#cache-output):

```ts [vite.config.ts]
tasks: {
build: {
command: 'node build.mjs',
cache: {
env: ['NODE_ENV'],
input: [{ auto: true }, '!dist/**'],
},
},
}
```

Set `cache` to `false` for tasks that should never be cached, like dev servers:

```ts [vite.config.ts]
tasks: {
Expand All @@ -170,7 +186,7 @@ tasks: {
}
```

### `env`
### `cache.env`

- **Type:** `string[]`
- **Default:** `[]`
Expand All @@ -181,7 +197,9 @@ Environment variables included in the cache fingerprint. When any listed variabl
tasks: {
build: {
command: 'node build.mjs',
env: ['NODE_ENV'],
cache: {
env: ['NODE_ENV'],
},
},
}
```
Expand All @@ -195,7 +213,7 @@ $ NODE_ENV=development vp run build # first run
$ NODE_ENV=production vp run build # cache miss: env 'NODE_ENV' changed
```

### `untrackedEnv`
### `cache.untrackedEnv`

- **Type:** `string[]`
- **Default:** see below
Expand All @@ -206,12 +224,14 @@ Environment variables passed to the task process but **not** included in the cac
tasks: {
build: {
command: 'node build.mjs',
untrackedEnv: ['CI', 'GITHUB_ACTIONS'],
cache: {
untrackedEnv: ['CI', 'GITHUB_ACTIONS'],
},
},
}
```

`untrackedEnv` accepts the same wildcard and `!` exclusion patterns as [`env`](#env).
`untrackedEnv` accepts the same wildcard and `!` exclusion patterns as [`env`](#cache-env).

Do not put a variable in `untrackedEnv` if its value changes the task result. If a cache-reporting tool covers the variable through [automatic tracking](/guide/automatic-data-tracking#cooperative-tracking), leave it out of both `env` and `untrackedEnv`.

Expand All @@ -222,7 +242,7 @@ Vite Task passes a set of common environment variables to all tasks:
- **CI/CD:** `CI`, `VERCEL_*`, `NEXT_*`, `GITHUB_*`, `RUNNER_*`, `ACTIONS_ID_TOKEN_REQUEST_URL`, `ACTIONS_ID_TOKEN_REQUEST_TOKEN`
- **Terminal:** Color variables (`FORCE_COLOR`, `NO_COLOR`, `COLORTERM`, `TERM`, `TERM_PROGRAM`) aren't passed to tasks unless you list them under `env` (the value gets fingerprinted, so changing it invalidates the cache) or `untrackedEnv` (passed without fingerprinting). If `FORCE_COLOR` isn't in either list, the child gets `FORCE_COLOR=1` so cached logs stay colored. Colors get stripped on display when the terminal can't render them.

### `input`
### `cache.input`

- **Type:** `Array<string | { auto: boolean } | { pattern: string, base: "workspace" | "package" }>`
- **Default:** `[{ auto: true }]` (auto-inferred)
Expand All @@ -235,8 +255,10 @@ Vite Task automatically detects which files a command uses. See [Automatic Data
tasks: {
build: {
command: 'vp build',
// Use `{ auto: true }` to use automatic fingerprinting (default).
input: [{ auto: true }, '!**/*.tsbuildinfo', '!dist/**'],
cache: {
// Use `{ auto: true }` to use automatic fingerprinting (default).
input: [{ auto: true }, '!**/*.tsbuildinfo', '!dist/**'],
},
},
}
```
Expand All @@ -247,7 +269,9 @@ tasks: {
tasks: {
build: {
command: 'vp build',
input: ['src/**/*.ts', 'vite.config.ts'],
cache: {
input: ['src/**/*.ts', 'vite.config.ts'],
},
},
}
```
Expand All @@ -258,10 +282,12 @@ tasks: {
tasks: {
build: {
command: 'vp build',
input: [
{ auto: true },
{ pattern: 'shared-config/**', base: 'workspace' },
],
cache: {
input: [
{ auto: true },
{ pattern: 'shared-config/**', base: 'workspace' },
],
},
},
}
```
Expand All @@ -277,7 +303,9 @@ The `base` field is required and controls how the glob pattern is resolved:
tasks: {
greet: {
command: 'node greet.mjs',
input: [],
cache: {
input: [],
},
},
}
```
Expand All @@ -286,7 +314,7 @@ tasks: {
String glob patterns are resolved relative to the package directory by default. Use the object form with `base: "workspace"` to resolve relative to the workspace root.
:::

### `output`
### `cache.output`

- **Type:** `Array<string | { auto: boolean } | { pattern: string, base: "workspace" | "package" }>`
- **Default:** automatic write tracking
Expand All @@ -299,7 +327,9 @@ If you omit `output`, Vite Task uses automatic write tracking to choose those fi
tasks: {
build: {
command: 'node build.mjs',
output: ['dist/**', '!dist/cache/**'],
cache: {
output: ['dist/**', '!dist/cache/**'],
},
},
}
```
Expand All @@ -312,7 +342,9 @@ This is useful when a task writes files that should not be restored from the cac
tasks: {
typecheck: {
command: 'tsc --build',
output: [{ auto: true }, '!*.tsbuildinfo'],
cache: {
output: [{ auto: true }, '!*.tsbuildinfo'],
},
},
}
```
Expand All @@ -323,10 +355,12 @@ If a task writes outside its own package, use the object form with `base: "works
tasks: {
build: {
command: 'node build.mjs',
output: [
'dist/**',
{ pattern: 'shared-artifacts/**', base: 'workspace' },
],
cache: {
output: [
'dist/**',
{ pattern: 'shared-artifacts/**', base: 'workspace' },
],
},
},
}
```
Expand All @@ -337,7 +371,9 @@ Set `output: []` to disable output restoration for a cached task:
tasks: {
report: {
command: 'node scripts/report.mjs',
output: [],
cache: {
output: [],
},
},
}
```
Expand Down
Loading
Loading