From 4122b646c1894d7f74785278ba4396f38c5be3f2 Mon Sep 17 00:00:00 2001 From: aiirvizionz Date: Fri, 10 Jul 2026 08:02:37 -0600 Subject: [PATCH] Use real home directory for global installer paths --- packages/cli/src/installer.test.ts | 24 ++++++++++++++++++++++++ packages/cli/src/installer.ts | 3 ++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 packages/cli/src/installer.test.ts diff --git a/packages/cli/src/installer.test.ts b/packages/cli/src/installer.test.ts new file mode 100644 index 00000000..8e708d3e --- /dev/null +++ b/packages/cli/src/installer.test.ts @@ -0,0 +1,24 @@ +import { join } from 'node:path'; +import { afterEach, describe, expect, it } from 'vitest'; +import { globalNodeModulesDir } from './installer.js'; + +const ORIGINAL_HOME = process.env.HOME; +const ORIGINAL_USERPROFILE = process.env.USERPROFILE; + +describe('globalNodeModulesDir', () => { + afterEach(() => { + if (ORIGINAL_HOME === undefined) delete process.env.HOME; + else process.env.HOME = ORIGINAL_HOME; + + if (ORIGINAL_USERPROFILE === undefined) delete process.env.USERPROFILE; + else process.env.USERPROFILE = ORIGINAL_USERPROFILE; + }); + + it('uses USERPROFILE for global package paths when HOME is not set', () => { + delete process.env.HOME; + process.env.USERPROFILE = join('tmp', 'windows-home'); + + expect(globalNodeModulesDir('bun')).toBe(join('tmp', 'windows-home', '.bun/install/global/node_modules')); + expect(globalNodeModulesDir('aube')).toBe(join('tmp', 'windows-home', '.aube/install/global/node_modules')); + }); +}); diff --git a/packages/cli/src/installer.ts b/packages/cli/src/installer.ts index fe3704c4..944c96b9 100644 --- a/packages/cli/src/installer.ts +++ b/packages/cli/src/installer.ts @@ -23,6 +23,7 @@ import { spawnSync } from 'node:child_process'; import { existsSync, readFileSync } from 'node:fs'; +import { homedir } from 'node:os'; import { dirname, join } from 'node:path'; import { fileURLToPath, pathToFileURL } from 'node:url'; import kleur from 'kleur'; @@ -50,7 +51,7 @@ export function detectPackageManager(): PM { // Where the PM keeps globally-installed packages. Returns null if we // can't determine the path (e.g. deno; or a PM we couldn't probe). export function globalNodeModulesDir(pm: PM): string | null { - const home = process.env.HOME ?? '~'; + const home = process.env.HOME ?? process.env.USERPROFILE ?? homedir(); try { switch (pm) { case 'pnpm': {