fix bun path for one-shot review workspaces

This commit is contained in:
Codex
2026-05-27 11:31:24 +09:00
parent 7ed0af98a2
commit 4e90e1d7ec
2 changed files with 52 additions and 0 deletions

View File

@@ -218,6 +218,24 @@ describe('workspace package manager helpers', () => {
expect(execFileSyncMock).not.toHaveBeenCalled();
});
it('prepends the current Bun binary directory for bun workspace commands', () => {
const repoDir = path.join(tempRoot, 'bun-workspace');
fs.mkdirSync(repoDir, { recursive: true });
fs.writeFileSync(
path.join(repoDir, 'package.json'),
JSON.stringify({ packageManager: 'bun@1.3.13' }),
);
const env = buildWorkspaceCommandEnvironment(repoDir, 'bun', {
PATH: '/tmp/bin',
});
const expectedBunBinDir = path.basename(process.execPath).startsWith('bun')
? path.dirname(process.execPath)
: path.join(os.homedir(), '.bun', 'bin');
expect(env.PATH?.split(path.delimiter)[0]).toBe(expectedBunBinDir);
});
it('disables corepack project specs only for lockfile-selected pnpm workspaces under a conflicting ancestor', () => {
const parentDir = path.join(tempRoot, 'parent');
fs.mkdirSync(parentDir, { recursive: true });

View File

@@ -118,6 +118,36 @@ function buildCorepackCommand(
};
}
function prependPathEntry(
baseEnv: NodeJS.ProcessEnv,
entry: string | null,
): NodeJS.ProcessEnv {
if (!entry) {
return baseEnv;
}
const currentPath = baseEnv.PATH ?? '';
const entries = currentPath.split(path.delimiter).filter(Boolean);
if (entries.includes(entry)) {
return baseEnv;
}
return {
...baseEnv,
PATH: [entry, ...entries].join(path.delimiter),
};
}
function resolveCurrentBunBinDir(): string | null {
if (path.basename(process.execPath).startsWith('bun')) {
return path.dirname(process.execPath);
}
const home = process.env.HOME;
if (!home) {
return null;
}
const candidate = path.join(home, '.bun', 'bin');
return fs.existsSync(path.join(candidate, 'bun')) ? candidate : null;
}
function findNearestAncestorPackageManager(
repoDir: string,
): WorkspacePackageManager | null {
@@ -144,6 +174,10 @@ export function buildWorkspaceCommandEnvironment(
packageManager: WorkspacePackageManager,
baseEnv: NodeJS.ProcessEnv = process.env,
): NodeJS.ProcessEnv {
if (packageManager === 'bun') {
return prependPathEntry(baseEnv, resolveCurrentBunBinDir());
}
if (packageManager !== 'pnpm') {
return baseEnv;
}