Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions packages/cli/src/installer.test.ts
Original file line number Diff line number Diff line change
@@ -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'));
});
});
3 changes: 2 additions & 1 deletion packages/cli/src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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': {
Expand Down
Loading