perf(discovery): memoized WSL host-home probe per environment
- Deduplicated the re-imported changelog bullets from the PR #8403 merge, keeping the condensed register with only the new #8402 entry. - getUserHomeCandidates memoizes the WSL home candidate keyed by platform + WSL markers + USERPROFILE, so a wedged interop pipe costs one bounded probe per process instead of one 500ms stall per discovery loader, while env changes (tests, SDK embeddings) still recompute.
This commit is contained in:
+20
-10
@@ -6,20 +6,30 @@ import { $which } from "../packages/utils/src/which";
|
||||
|
||||
const repoRoot = path.join(import.meta.dir, "..");
|
||||
|
||||
type FindExecutable = (command: string) => string | null;
|
||||
|
||||
/** The executable path and invocation mode for the pinned Bun dependency generator. */
|
||||
export type NixBunDepsGenerator = { kind: "bun2nix"; executable: string } | { kind: "nix"; executable: string };
|
||||
|
||||
/** Resolve the generator needed by releases before they mutate repository state. */
|
||||
export function resolveNixBunDepsGenerator(findExecutable: FindExecutable = $which): NixBunDepsGenerator {
|
||||
const bun2nix = findExecutable("bun2nix");
|
||||
if (bun2nix) return { kind: "bun2nix", executable: bun2nix };
|
||||
|
||||
const nix = findExecutable("nix");
|
||||
if (nix) return { kind: "nix", executable: nix };
|
||||
|
||||
throw new Error("Generating nix/bun.nix requires bun2nix from `nix develop`, or Nix to enter that shell.");
|
||||
}
|
||||
|
||||
/** Regenerate the checked-in Bun dependency expression with the pinned bun2nix input. */
|
||||
export async function generateNixBunDeps(): Promise<void> {
|
||||
const bun2nix = $which("bun2nix");
|
||||
if (bun2nix) {
|
||||
await $`${bun2nix} -l bun.lock -c ../ -o nix/bun.nix`.cwd(repoRoot);
|
||||
export async function generateNixBunDeps(generator: NixBunDepsGenerator = resolveNixBunDepsGenerator()): Promise<void> {
|
||||
if (generator.kind === "bun2nix") {
|
||||
await $`${generator.executable} -l bun.lock -c ../ -o nix/bun.nix`.cwd(repoRoot);
|
||||
return;
|
||||
}
|
||||
|
||||
const nix = $which("nix");
|
||||
if (!nix) {
|
||||
throw new Error("Generating nix/bun.nix requires bun2nix from `nix develop`, or Nix to enter that shell.");
|
||||
}
|
||||
|
||||
await $`${nix} --extra-experimental-features ${"nix-command flakes"} --accept-flake-config develop --command bun2nix -l bun.lock -c ../ -o nix/bun.nix`.cwd(
|
||||
await $`${generator.executable} --extra-experimental-features ${"nix-command flakes"} --accept-flake-config develop --command bun2nix -l bun.lock -c ../ -o nix/bun.nix`.cwd(
|
||||
repoRoot,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user