Skip to content

Commit 3d711d0

Browse files
committed
fix(cli): pack runnable ranking requires a pack block or the tsdown default entry
A Vite config without a pack block does not make bare vp pack succeed, so it no longer counts as pack-runnable; document the per-command runnable rules normatively in the RFC and docs.
1 parent 4c6ed97 commit 3d711d0

3 files changed

Lines changed: 28 additions & 5 deletions

File tree

docs/guide/monorepo.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ error: `vp build` at the workspace root needs a target package.
197197
Or run every package's build script: vp run -r build
198198
```
199199

200-
Packages that look runnable for the command (an `index.html` or `vite.config.*` for `dev` / `build` / `preview`, a library entry for `pack`) are ranked first in both the picker and the listing.
200+
Packages that look runnable for the command are ranked first in both the picker and the listing: a `vite.config.*` or root `index.html` for `dev` / `build` / `preview`, and a `pack` config block or tsdown's default `src/index.ts` entry for `pack`.
201201

202202
### Targeting a package with `-C`
203203

packages/cli/binding/src/cli/app_target.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,18 @@ fn is_bare(args: &[String]) -> bool {
5656

5757
/// Heuristic ranking signal: does `dir` look runnable for `command`?
5858
/// Used for ordering and single-candidate auto-selection, never for hiding.
59+
/// The rules are documented in rfcs/cwd-flag.md ("The likely-runnable
60+
/// heuristic"); keep both in sync.
5961
fn looks_runnable(dir: &AbsolutePathBuf, command: &str) -> bool {
60-
let has_vite_config = vite_static_config::has_config_file(dir);
6162
match command {
62-
"pack" => has_vite_config || dir.as_path().join("src/index.ts").is_file(),
63-
_ => has_vite_config || dir.as_path().join("index.html").is_file(),
63+
// Bare `vp pack` succeeds when the config declares a `pack` block or
64+
// tsdown's default entry exists; a Vite config without `pack` does
65+
// not make a package packable.
66+
"pack" => {
67+
vite_static_config::resolve_static_config(dir).get("pack").is_some()
68+
|| dir.as_path().join("src/index.ts").is_file()
69+
}
70+
_ => vite_static_config::has_config_file(dir) || dir.as_path().join("index.html").is_file(),
6471
}
6572
}
6673

rfcs/cwd-flag.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,27 @@ The global binary also resolves the local `vite-plus` install from `<dir>`, matc
276276

277277
### Picker contents
278278

279-
- One row per workspace package: name plus relative path. Nothing is filtered out; packages that look runnable for the command (`vite.config.*` or `index.html` for `dev`/`build`/`preview`, a pack config or library entry for `pack`) rank first, then by path, so apps surface at the top while everything stays searchable.
279+
- One row per workspace package: name plus relative path. Nothing is filtered out; likely-runnable packages (rules below) rank first, then by path, so apps surface at the top while everything stays searchable.
280280
- Fuzzy search over name and path via `vite_select::fuzzy_match`, paging identical to the task picker.
281281
- A runnable workspace root appears as a `(workspace root)` entry, keeping today's "run at root" behavior one keystroke away.
282282
- With exactly one likely-runnable package, the picker auto-selects it, printing only the `Selected package:` line and the tip.
283283

284+
### The likely-runnable heuristic
285+
286+
Used only for ranking and single-candidate auto-select, never to hide a package: a misjudged package still appears in the picker and listing, just lower. Judged per package directory from file existence and static config extraction; nothing is executed, and parent directories never count.
287+
288+
| Command | A package is likely runnable when |
289+
| --------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
290+
| `dev` / `build` / `preview` | its directory directly contains one of Vite's config file names (`vite.config.{js,mjs,ts,cjs,mts,cts}`, the exact list Vite probes), **or** an `index.html` at the package root (Vite's default app entry) |
291+
| `pack` | its `vite.config.*` declares a `pack` block (read via static extraction; a Vite config without `pack` does not count), **or** `src/index.ts` exists (tsdown's only default entry) |
292+
293+
"Exactly one likely-runnable package" means: after sorting rows runnable-first, the first row is runnable and the second is not. Auto-select additionally requires an interactive terminal.
294+
295+
Accepted trade-offs, tolerable because the signal never hides anything and a wrong auto-select is immediately visible (the `Selected package:` line, with the `Tip:` line showing the explicit `-C` form):
296+
297+
- A library whose `vite.config.*` exists only for Vitest or lint settings ranks as runnable for `dev`/`build`/`preview`. A refinement could demote configs whose only top-level keys are tool blocks, via the same static extraction; deferred until it bites in practice.
298+
- An app whose `index.html` lives outside the package root (custom Vite `root`) or whose config is inherited from a parent directory is not ranked first, and never auto-selects.
299+
284300
### `defaultPackage` config
285301

286302
```ts

0 commit comments

Comments
 (0)