diff --git a/CHANGELOG.md b/CHANGELOG.md index 267b050f7..761142744 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # Changelog +- **Fixed** `vp run ` in a package that doesn't define the task now reports `Task "" not found` when another package's `vite.config.*` fails to load, instead of failing with that package's error. Showing the tasks to choose from loads every package's config, so the task selector or task list is skipped then ([#987](https://github.com/voidzero-dev/vite-task/pull/987)). - **Fixed** A task specifier like `vp run nope#build`, where no workspace package is named `nope`, now fails with `Package 'nope' not found in the workspace` and exits 1, including from a task's command, instead of running nothing and exiting 0. A short name that auto-completes to several scoped packages, like `app` for `@a/app` and `@b/app`, now fails as ambiguous. `--filter nope` still only warns and exits 0, unless `--fail-if-no-match` is set ([#984](https://github.com/voidzero-dev/vite-task/pull/984)). - **Added** `vp run -vv` also lists what each cached run depends on, changed or not, and the output files a hit restores: in the detailed summary, under `Unchanged:` and `Outputs:`, and with `--dry-run --json`, as each step's `baseline.fingerprint` and `baseline.outputs`. It shows, for an unexpected hit, whether an edited file is an input at all. `-v` is now a counted flag, so `-vv` is the same as `--verbose --verbose` ([#969](https://github.com/voidzero-dev/vite-task/pull/969)). - **Added** `vp run --dry-run --json` prints what a run would do as one JSON document for scripts, CI and coding agents: each task the run would run, the tasks it waits for, and each step's program, arguments and directory, with whether it would hit the cache and, if not, every change found. Like `vp run --json`, it's indented in a terminal and on one line when captured, and its `$schema` field points to a JSON Schema that describes each field. A task that runs `vp run` shows that run's own plan as its step. A step that waits on one that would write files first, by running or by restoring outputs, is `unknown`, since its files may change before it starts. `--json` with a task requires `--dry-run` ([#966](https://github.com/voidzero-dev/vite-task/pull/966), [#967](https://github.com/voidzero-dev/vite-task/pull/967), [#968](https://github.com/voidzero-dev/vite-task/pull/968)). diff --git a/crates/vt/src/session/mod.rs b/crates/vt/src/session/mod.rs index 4700b9c3e..16a8d596d 100644 --- a/crates/vt/src/session/mod.rs +++ b/crates/vt/src/session/mod.rs @@ -491,7 +491,19 @@ impl<'a> Session<'a> { let cwd = Arc::clone(&self.cwd); let task_graph = self.task_graph().await?; let current_package_path = task_graph.get_package_path_from_cwd(&cwd).cloned(); - let mut entries = task_graph.list_tasks().await?; + // Listing loads every package's config, including ones the run never + // reached. When one fails to load, a run that named a task reports the + // task as not found, as it would without the fallback, instead of an + // unrelated package's error. + let mut entries = match task_graph.list_tasks().await { + Ok(entries) => entries, + Err(error) => { + return Err(run_command.task_specifier.as_ref().map_or_else( + || error.into(), + |task_specifier| vt_plan::Error::NoTasksMatched(task_specifier.clone()).into(), + )); + } + }; entries.sort_unstable_by(|a, b| { a.task_display .package_name diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/lazy_config_task_not_found/package.json b/crates/vt_bin/tests/e2e_snapshots/fixtures/lazy_config_task_not_found/package.json new file mode 100644 index 000000000..06ec03a51 --- /dev/null +++ b/crates/vt_bin/tests/e2e_snapshots/fixtures/lazy_config_task_not_found/package.json @@ -0,0 +1,4 @@ +{ + "name": "lazy-config-task-not-found", + "private": true +} diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/lazy_config_task_not_found/packages/app/package.json b/crates/vt_bin/tests/e2e_snapshots/fixtures/lazy_config_task_not_found/packages/app/package.json new file mode 100644 index 000000000..b2499ff82 --- /dev/null +++ b/crates/vt_bin/tests/e2e_snapshots/fixtures/lazy_config_task_not_found/packages/app/package.json @@ -0,0 +1,6 @@ +{ + "name": "@test/app", + "scripts": { + "build": "echo 'Building app'" + } +} diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/lazy_config_task_not_found/packages/broken/package.json b/crates/vt_bin/tests/e2e_snapshots/fixtures/lazy_config_task_not_found/packages/broken/package.json new file mode 100644 index 000000000..48a1d059a --- /dev/null +++ b/crates/vt_bin/tests/e2e_snapshots/fixtures/lazy_config_task_not_found/packages/broken/package.json @@ -0,0 +1,6 @@ +{ + "name": "@test/broken", + "scripts": { + "build": "echo 'Building broken'" + } +} diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/lazy_config_task_not_found/packages/broken/vite-task.json b/crates/vt_bin/tests/e2e_snapshots/fixtures/lazy_config_task_not_found/packages/broken/vite-task.json new file mode 100644 index 000000000..d548edfac --- /dev/null +++ b/crates/vt_bin/tests/e2e_snapshots/fixtures/lazy_config_task_not_found/packages/broken/vite-task.json @@ -0,0 +1,3 @@ +{ + "cache": true +} diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/lazy_config_task_not_found/pnpm-workspace.yaml b/crates/vt_bin/tests/e2e_snapshots/fixtures/lazy_config_task_not_found/pnpm-workspace.yaml new file mode 100644 index 000000000..924b55f42 --- /dev/null +++ b/crates/vt_bin/tests/e2e_snapshots/fixtures/lazy_config_task_not_found/pnpm-workspace.yaml @@ -0,0 +1,2 @@ +packages: + - packages/* diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/lazy_config_task_not_found/snapshots.toml b/crates/vt_bin/tests/e2e_snapshots/fixtures/lazy_config_task_not_found/snapshots.toml new file mode 100644 index 000000000..b6014e555 --- /dev/null +++ b/crates/vt_bin/tests/e2e_snapshots/fixtures/lazy_config_task_not_found/snapshots.toml @@ -0,0 +1,32 @@ +[[e2e]] +name = "missing_task_with_unreached_broken_config" +comment = """ +`packages/broken/vite-task.json` sets `cache`, which only the workspace root config may set. `vt run build` in `packages/app` never reads `@test/broken`'s config. `vt run ship`, a task `@test/app` doesn't define, falls back to listing every task, which loads `@test/broken`'s config. When that fails, it reports `Task "ship" not found`, as `--parallel`, which skips the fallback, does, instead of `@test/broken`'s error. +""" +cwd = "packages/app" +steps = [ + { argv = [ + "vt", + "run", + "build", + ], comment = "never reads @test/broken's config" }, + { argv = [ + "vtt", + "pipe-stdout", + "--", + "vt", + "run", + "ship", + ], comment = "not found, without @test/broken's error" }, + { argv = [ + "vt", + "run", + "ship", + ], comment = "in a terminal, also not found, without the task selector" }, + { argv = [ + "vt", + "run", + "--parallel", + "ship", + ], comment = "without the fallback, also not found" }, +] diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/lazy_config_task_not_found/snapshots/missing_task_with_unreached_broken_config.md b/crates/vt_bin/tests/e2e_snapshots/fixtures/lazy_config_task_not_found/snapshots/missing_task_with_unreached_broken_config.md new file mode 100644 index 000000000..9e2369a80 --- /dev/null +++ b/crates/vt_bin/tests/e2e_snapshots/fixtures/lazy_config_task_not_found/snapshots/missing_task_with_unreached_broken_config.md @@ -0,0 +1,43 @@ +# missing_task_with_unreached_broken_config + +`packages/broken/vite-task.json` sets `cache`, which only the workspace root config may set. `vt run build` in `packages/app` never reads `@test/broken`'s config. `vt run ship`, a task `@test/app` doesn't define, falls back to listing every task, which loads `@test/broken`'s config. When that fails, it reports `Task "ship" not found`, as `--parallel`, which skips the fallback, does, instead of `@test/broken`'s error. + +## `vt run build` + +never reads @test/broken's config + +``` +~/packages/app$ echo 'Building app' ⊘ cache disabled +Building app +``` + +## `vtt pipe-stdout -- vt run ship` + +not found, without @test/broken's error + +**Exit code:** 1 + +``` +error: Task "ship" not found +--- stdout --- +``` + +## `vt run ship` + +in a terminal, also not found, without the task selector + +**Exit code:** 1 + +``` +error: Task "ship" not found +``` + +## `vt run --parallel ship` + +without the fallback, also not found + +**Exit code:** 1 + +``` +error: Task "ship" not found +```