

























@@ -32,6 +32,7 @@ type MinimalServicePathOptions = {
3232cwd?: string;
3333env?: Record<string, string | undefined>;
3434existsSync?: (candidate: string) => boolean;
35+includeMissingUserBinDefaults?: boolean;
3536};
36373738type BuildServicePathOptions = MinimalServicePathOptions & {
@@ -168,10 +169,14 @@ function addCommonUserBinDirs(
168169dirs: string[],
169170home: string,
170171existsSync: (candidate: string) => boolean,
172+includeMissingDefaults: boolean,
171173): void {
172-dirs.push(`${home}/.local/bin`);
173-dirs.push(`${home}/.npm-global/bin`);
174-dirs.push(`${home}/bin`);
174+const addDefault = includeMissingDefaults
175+ ? (candidate: string) => dirs.push(candidate)
176+ : (candidate: string) => addExistingDir(dirs, candidate, existsSync);
177+addDefault(`${home}/.local/bin`);
178+addDefault(`${home}/.npm-global/bin`);
179+addDefault(`${home}/bin`);
175180addExistingDir(dirs, `${home}/.volta/bin`, existsSync);
176181addExistingDir(dirs, `${home}/.asdf/shims`, existsSync);
177182addExistingDir(dirs, `${home}/.bun/bin`, existsSync);
@@ -196,14 +201,21 @@ function addNixProfileBinDirs(
196201home: string,
197202env: Record<string, string | undefined> | undefined,
198203options: Pick<MinimalServicePathOptions, "cwd" | "home">,
204+includeMissingDefault: boolean,
205+existsSync: (candidate: string) => boolean,
199206): void {
200207const nixProfiles = env?.NIX_PROFILES?.trim();
201208if (nixProfiles) {
202209for (const profile of nixProfiles.split(/\s+/).toReversed()) {
203210addEnvConfiguredBinDir(dirs, appendSubdir(profile, "bin"), options);
204211}
205212} else {
206-dirs.push(`${home}/.nix-profile/bin`);
213+const defaultProfileBin = `${home}/.nix-profile/bin`;
214+if (includeMissingDefault) {
215+dirs.push(defaultProfileBin);
216+} else {
217+addExistingDir(dirs, defaultProfileBin, existsSync);
218+}
207219}
208220}
209221@@ -229,14 +241,15 @@ function resolveDarwinUserBinDirs(
229241home: string | undefined,
230242env?: Record<string, string | undefined>,
231243existsSync: (candidate: string) => boolean = fs.existsSync,
232-options: Pick<MinimalServicePathOptions, "cwd" | "home"> = {},
244+options: Pick<MinimalServicePathOptions, "cwd" | "home" | "includeMissingUserBinDefaults"> = {},
233245): string[] {
234246if (!home) {
235247return [];
236248}
237249238250const dirs: string[] = [];
239251const pathOptions = { ...options, home };
252+const includeMissingUserBinDefaults = options.includeMissingUserBinDefaults ?? true;
240253241254// Env-configured bin roots (override defaults when present).
242255// Note: FNM_DIR on macOS defaults to ~/Library/Application Support/fnm
@@ -250,10 +263,10 @@ function resolveDarwinUserBinDirs(
250263// pnpm: binary is directly in PNPM_HOME (not in bin subdirectory)
251264252265// Common user bin directories
253-addCommonUserBinDirs(dirs, home, existsSync);
266+addCommonUserBinDirs(dirs, home, existsSync, includeMissingUserBinDefaults);
254267255268// Nix Home Manager (cross-platform)
256-addNixProfileBinDirs(dirs, home, env, pathOptions);
269+addNixProfileBinDirs(dirs, home, env, pathOptions, includeMissingUserBinDefaults, existsSync);
257270258271// Node version managers - macOS specific paths
259272// nvm: no stable default path, depends on user's shell configuration
@@ -275,14 +288,15 @@ function resolveLinuxUserBinDirs(
275288home: string | undefined,
276289env?: Record<string, string | undefined>,
277290existsSync: (candidate: string) => boolean = fs.existsSync,
278-options: Pick<MinimalServicePathOptions, "cwd" | "home"> = {},
291+options: Pick<MinimalServicePathOptions, "cwd" | "home" | "includeMissingUserBinDefaults"> = {},
279292): string[] {
280293if (!home) {
281294return [];
282295}
283296284297const dirs: string[] = [];
285298const pathOptions = { ...options, home };
299+const includeMissingUserBinDefaults = options.includeMissingUserBinDefaults ?? true;
286300287301// Env-configured bin roots (override defaults when present).
288302addCommonEnvConfiguredBinDirs(dirs, env, pathOptions);
@@ -291,10 +305,10 @@ function resolveLinuxUserBinDirs(
291305addEnvConfiguredBinDir(dirs, appendSubdir(env?.FNM_DIR, "current/bin"), pathOptions);
292306293307// Common user bin directories
294-addCommonUserBinDirs(dirs, home, existsSync);
308+addCommonUserBinDirs(dirs, home, existsSync, includeMissingUserBinDefaults);
295309296310// Nix Home Manager (cross-platform)
297-addNixProfileBinDirs(dirs, home, env, pathOptions);
311+addNixProfileBinDirs(dirs, home, env, pathOptions, includeMissingUserBinDefaults, existsSync);
298312299313// Node version managers
300314addExistingDir(dirs, `${home}/.nvm/current/bin`, existsSync); // nvm with current symlink
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。