feat: introduce Dirs for unified XDG-aware path resolution - #2346
Draft
forehalo wants to merge 1 commit into
Draft
feat: introduce Dirs for unified XDG-aware path resolution#2346forehalo wants to merge 1 commit into
forehalo wants to merge 1 commit into
Conversation
✅ Deploy Preview for viteplus-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
forehalo
force-pushed
the
feat/dirs-path-resolution
branch
2 times, most recently
from
August 5, 2026 14:38
f9b80b6 to
0df4587
Compare
Add vp_shared::Dirs as the single owner of on-disk placement decisions. An internal DirsInner enum selects the layout once per resolution (first match wins): - Home (legacy monolithic root): VP_HOME is set, the vp binary self-locates at <root>/current/bin/vp, a legacy layout is found on PATH, or ~/.vite-plus exists on disk. Existing installs keep working untouched, byte-identical paths. - Custom (split XDG layout, fresh installs): each category resolves through its own VP_*_DIR override -> XDG_* -> platform-default chain (bin: VP_BIN_DIR -> XDG_BIN_HOME -> XDG_DATA_HOME/../bin -> ~/.local/bin, mirroring uv). Only VP_BIN_DIR/VP_DATA_DIR/VP_CACHE_DIR exist as dedicated overrides; config and state rely on XDG_CONFIG_HOME / XDG_STATE_HOME. Relative values are ignored per the spec. XDG_* names are defined alongside vp's own variables in env_vars.rs, but only vp_* path overrides live in EnvConfig; Dirs reads XDG vars itself behind an injectable, parallel-safe resolution core (no env mutation or serial_test anywhere in Dirs tests; test helpers live in a #[cfg(test)] impl block, and cross-crate tests sandbox through EnvConfig::for_test_with_home). Migrate every Rust call site to Dirs category accessors and named helpers, delete get_vp_home() and the home.rs module (folded into dirs.rs), and drop per-crate wrapper helpers so Dirs is the sole path source. bins/*.json metadata moves to the data category. On the TS side, the global CLI injects the resolved VP_BIN_DIR / VP_DATA_DIR / VP_CACHE_DIR into JS child processes under the split layout only (never overriding user-set vars); org-tarball.ts prefers VP_CACHE_DIR; generated git hook scripts fall back through VP_BIN_DIR, VP_HOME/bin, ~/.vite-plus/bin, ~/.local/bin. VP_HOME, the installers, and the generated env* shell scripts are unchanged in behavior: fresh installs still land in ~/.vite-plus, so the split layout is opt-in via VP_*_DIR/XDG until the follow-up stack removes the legacy variables and switches installer defaults. Groundwork for voidzero-dev#827.
forehalo
force-pushed
the
feat/dirs-path-resolution
branch
from
August 5, 2026 15:54
0df4587 to
b8069a5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Groundwork for #827 (the env-var removal and installer cutover land in stacked follow-up PRs).
Summary
Introduces
vp_shared::Dirsas the single owner of every on-disk placement decision. All priority chains are internal details; call sites ask for a category root or a named path.Dirsis the sole path source —get_vp_home(),home.rs, and per-crate wrapper helpers are gone.This PR is behavior-preserving for every install flavor —
VP_HOME, the installers, and the generatedenv*scripts work exactly as before. Fresh installs still land in~/.vite-plus; the split XDG layout only activates via explicitVP_*_DIR/XDG_*configuration until the follow-up stack flips installer defaults.Layout selection happens once via an internal
DirsInnerenum (first match wins):VP_HOMEset → legacy monolithicHomelayout (highest priority, as today).Executable self-location —
current_exeis<root>/current/bin/vp→Home(root). Covers IDE/trampoline launches without PATH context.Legacy
PATHinference —<root>/binon PATH with the legacy layout →Home(root)(as today).~/.vite-plusexists →Home, grandfathered; nothing is moved.Custom(split XDG layout) — each category resolves independently:VP_BIN_DIR→XDG_BIN_HOME→XDG_DATA_HOME/../bin→~/.local/bin(uv's chain)XDG_CONFIG_HOME/vite-plus→~/.config/vite-plusbins/*.json)VP_DATA_DIR→XDG_DATA_HOME/vite-plus→~/.local/share/vite-plusXDG_STATE_HOME/vite-plus→~/.local/state/vite-plusVP_CACHE_DIR→XDG_CACHE_HOME/vite-plus→~/.cache/vite-plusOnly bin/data/cache get dedicated
VP_*_DIRoverrides (mirroring uv'sUV_TOOL_BIN_DIR/UV_PYTHON_INSTALL_DIR/UV_CACHE_DIR); config and state rely on the standard XDG vars. Relative values are ignored per the spec. Windows defaults live under%LOCALAPPDATA%\vite-plus\...(config under%APPDATA%\vite-plus).What changed
crates/vp_shared/src/dirs.rs(new, absorbshome.rs):Dirs+DirsInner, pure injectable resolution core (XDG/platform/PATH all injected — no env mutation orserial_testanywhere), 5 category accessors, 12 named helpers,is_legacy_layout(). Test helpers live in a#[cfg(test)] implblock; cross-crate tests sandbox viaEnvConfig::for_test_with_home(temp home → fully isolated layout).VP_BIN_DIR/VP_DATA_DIR/VP_CACHE_DIRand theXDG_*_HOMEnames are constants inenv_vars.rs;EnvConfigcarries onlyvp_*path overrides —Dirsreads the XDG vars itself.get_vp_home()uses and hand-rolled$VP_HOME/...constructions acrossvp_global_cli,vp_js_runtime,vp_pm_cli,vp_setup,vp_command,vp_installernow go throughDirs; wrapper helpers (get_js_runtime_dir,bins_dir, …) deleted;bins/*.jsonmoves to the data category (identical on disk underHome).VP_BIN_DIR/VP_DATA_DIR/VP_CACHE_DIRinto JS child processes under the split layout only (never overriding user-set vars);org-tarball.tsprefersVP_CACHE_DIR; generated git hook scripts fall back throughVP_BIN_DIR→VP_HOME/bin→~/.vite-plus/bin→~/.local/bin.installer-env-vars.mdgains the new variables and a full layout-resolution section;env.md/install.md/implode.md/CONTRIBUTING.md/AGENTS.mdupdated; supersede note added torfcs/env-command.md.Stacked follow-ups (not in this PR)
VP_HOMEand switch installer defaults so fresh installs land in the split XDG layout (including generatedenv*script content).vp imploderemoval of the split XDG dirs.Validation
cargo check --workspace --all-targets,cargo clippy --workspace --all-targets: zero warningscargo teston all touched crates: ~1500 tests pass (full-workspace failures are pre-existing vendored-rolldown fixture issues, unrelated)vp fmt --check/vp lintclean on changed files