refactor(pacquet/config): inline default_store_dir's SmartDefault wiring

Reviewer pointed out that the args-less `default_store_dir_host`
wrapper could be inlined into the `#[default(_code = ...)]`
expression on `Config::store_dir` — the SmartDefault macro accepts
the turbofish form `default_store_dir::<Host, _, _, _>(home::home_dir,
env::current_dir)` verbatim, and once the wrapper is gone there's
nothing for the indirection to earn.

Dropping the wrapper also removes a small motivation for the
`Host` import inside `defaults.rs` — adjust the doc comment on
`default_store_dir` to cite `crate::Host` by full path instead.

The `#[cfg(windows)] Error: std::fmt::Debug` bound that the same
reviewer asked about is not feasible: attributes on where-clause
predicates are still unstable (rust-lang/rust#115590), so the bound
stays unconditional with a comment explaining why.

---
Written by an agent (Claude Code, claude-opus-4-7).
This commit is contained in:
Claude
2026-05-18 14:16:55 +00:00
parent 73ede0b1b1
commit 49c690c99d
2 changed files with 13 additions and 17 deletions

View File

@@ -1,4 +1,4 @@
use crate::api::{EnvVar, Host};
use crate::api::EnvVar;
use pacquet_store_dir::StoreDir;
use std::{env, path::PathBuf};
@@ -65,9 +65,10 @@ fn default_store_dir_windows(home_dir: &Path, current_dir: &Path) -> PathBuf {
/// mutating the process environment. Mirrors the seam established
/// in pnpm/pacquet#339 and consolidated in
/// [pnpm/pnpm#11708](https://github.com/pnpm/pnpm/pull/11708).
/// Production callers pass [`Host`] for `Sys` together with
/// `home::home_dir` and `env::current_dir` for the closures (see
/// [`default_store_dir_host`]).
/// Production callers pass [`crate::Host`] for `Sys` together
/// with `home::home_dir` and `env::current_dir` for the
/// closures — see the `SmartDefault` expression on
/// [`crate::Config::store_dir`].
pub fn default_store_dir<Sys, HomeDir, CurrentDir, Error>(
home_dir: HomeDir,
current_dir: CurrentDir,
@@ -81,6 +82,11 @@ where
// `env::current_dir` (Error = `io::Error`, which has `Debug`);
// test fakes that don't drive the Windows branch pin
// `Error = std::io::Error` via turbofish for the same reason.
// The bound would ideally be gated `#[cfg(windows)]` so non-Windows
// callers stayed free of the `Debug` requirement, but
// `#[cfg(...)]` on where-clause predicates is still unstable
// (rust-lang/rust#115590) — keep the bound unconditional until
// that stabilises.
Error: std::fmt::Debug,
{
// TODO: If env variables start with ~, make sure to resolve it into home_dir.
@@ -112,15 +118,6 @@ where
}
}
/// `SmartDefault` entry-point for [`crate::Config::store_dir`]: thin
/// wrapper around [`default_store_dir`] that wires the production
/// [`Host`] provider together with the real `home::home_dir` and
/// `env::current_dir` lookups. Kept args-less so the
/// `#[default(_code = ...)]` expression on the field stays short.
pub fn default_store_dir_host() -> StoreDir {
default_store_dir::<Host, _, _, _>(home::home_dir, env::current_dir)
}
pub fn default_modules_dir() -> PathBuf {
// TODO: find directory with package.json
env::current_dir().expect("current directory is unavailable").join("node_modules")

View File

@@ -15,7 +15,7 @@ use serde::Deserialize;
use smart_default::SmartDefault;
use std::{
collections::{BTreeMap, BTreeSet, HashMap},
fs,
env, fs,
path::PathBuf,
};
@@ -27,8 +27,7 @@ use crate::defaults::{
default_child_concurrency, default_enable_global_virtual_store, default_fetch_retries,
default_fetch_retry_factor, default_fetch_retry_maxtimeout, default_fetch_retry_mintimeout,
default_hoist_pattern, default_modules_cache_max_age, default_modules_dir,
default_public_hoist_pattern, default_registry, default_store_dir_host,
default_virtual_store_dir,
default_public_hoist_pattern, default_registry, default_store_dir, default_virtual_store_dir,
};
pub use workspace_yaml::{
LoadWorkspaceYamlError, WORKSPACE_MANIFEST_FILENAME, WorkspaceSettings, workspace_root_or,
@@ -185,7 +184,7 @@ pub struct Config {
pub shamefully_hoist: bool,
/// The location where all the packages are saved on the disk.
#[default(_code = "default_store_dir_host()")]
#[default(_code = "default_store_dir::<Host, _, _, _>(home::home_dir, env::current_dir)")]
pub store_dir: StoreDir,
/// The directory in which dependencies will be installed (instead of node_modules).