fix bun path for one-shot review workspaces
This commit is contained in:
@@ -218,6 +218,24 @@ describe('workspace package manager helpers', () => {
|
|||||||
expect(execFileSyncMock).not.toHaveBeenCalled();
|
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', () => {
|
it('disables corepack project specs only for lockfile-selected pnpm workspaces under a conflicting ancestor', () => {
|
||||||
const parentDir = path.join(tempRoot, 'parent');
|
const parentDir = path.join(tempRoot, 'parent');
|
||||||
fs.mkdirSync(parentDir, { recursive: true });
|
fs.mkdirSync(parentDir, { recursive: true });
|
||||||
|
|||||||
@@ -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(
|
function findNearestAncestorPackageManager(
|
||||||
repoDir: string,
|
repoDir: string,
|
||||||
): WorkspacePackageManager | null {
|
): WorkspacePackageManager | null {
|
||||||
@@ -144,6 +174,10 @@ export function buildWorkspaceCommandEnvironment(
|
|||||||
packageManager: WorkspacePackageManager,
|
packageManager: WorkspacePackageManager,
|
||||||
baseEnv: NodeJS.ProcessEnv = process.env,
|
baseEnv: NodeJS.ProcessEnv = process.env,
|
||||||
): NodeJS.ProcessEnv {
|
): NodeJS.ProcessEnv {
|
||||||
|
if (packageManager === 'bun') {
|
||||||
|
return prependPathEntry(baseEnv, resolveCurrentBunBinDir());
|
||||||
|
}
|
||||||
|
|
||||||
if (packageManager !== 'pnpm') {
|
if (packageManager !== 'pnpm') {
|
||||||
return baseEnv;
|
return baseEnv;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user