Files
bun.sh/test/cli/install/bad-workspace.test.ts
Claude Bot 08d7426fd0 fix(install): silently ignore missing literal workspace paths
Previously, `bun install` would error with "Workspace not found" when a
literal workspace path (e.g. "terraform") didn't exist, but silently
succeed when a glob pattern (e.g. "terraform*") matched nothing. This
inconsistency differed from npm, which treats both cases identically
with silent success.

Now both literal and glob workspace paths that don't resolve to a valid
package.json are silently skipped, matching npm behavior.

Closes #26970

Co-Authored-By: Claude <noreply@anthropic.com>
2026-02-12 14:52:29 +00:00

127 lines
2.7 KiB
TypeScript

import { spawnSync } from "bun";
import { beforeAll, beforeEach, expect, setDefaultTimeout, test } from "bun:test";
import { mkdirSync, writeFileSync } from "fs";
import { bunEnv, bunExe, tmpdirSync } from "harness";
let cwd: string;
beforeAll(() => {
setDefaultTimeout(1000 * 60 * 5);
});
beforeEach(() => {
cwd = tmpdirSync();
});
test("bad workspace path", () => {
writeFileSync(
`${cwd}/package.json`,
JSON.stringify(
{
name: "hey",
workspaces: ["i-dont-exist"],
},
null,
2,
),
);
const { stderr, exitCode } = spawnSync({
cmd: [bunExe(), "install"],
cwd,
env: bunEnv,
stderr: "pipe",
stdout: "pipe",
});
const text = stderr!.toString();
// Missing workspace paths are silently ignored, matching npm behavior
expect(text).not.toContain('Workspace not found "i-dont-exist"');
expect(exitCode).toBe(0);
});
test("workspace with ./ should not crash", () => {
writeFileSync(
`${cwd}/package.json`,
JSON.stringify(
{
name: "my-app",
version: "1.0.0",
workspaces: ["./", "some-workspace"],
devDependencies: {
"@eslint/js": "^9.28.0",
},
},
null,
2,
),
);
mkdirSync(`${cwd}/some-workspace`);
writeFileSync(
`${cwd}/some-workspace/package.json`,
JSON.stringify(
{
name: "some-workspace",
version: "1.0.0",
},
null,
2,
),
);
const { stderr, exitCode } = spawnSync({
cmd: [bunExe(), "install"],
cwd,
env: bunEnv,
stderr: "pipe",
stdout: "pipe",
});
const text = stderr!.toString();
// Should not crash, should succeed
expect(exitCode).toBe(0);
expect(text).not.toContain("panic");
expect(text).not.toContain("Internal assertion failure");
});
test("workspace with .\\ should not crash", () => {
writeFileSync(
`${cwd}/package.json`,
JSON.stringify(
{
name: "my-app",
version: "1.0.0",
workspaces: [".\\", "some-workspace"],
devDependencies: {
"@eslint/js": "^9.28.0",
},
},
null,
2,
),
);
mkdirSync(`${cwd}/some-workspace`);
writeFileSync(
`${cwd}/some-workspace/package.json`,
JSON.stringify(
{
name: "some-workspace",
version: "1.0.0",
},
null,
2,
),
);
const { stderr, exitCode } = spawnSync({
cmd: [bunExe(), "install"],
cwd,
env: bunEnv,
stderr: "pipe",
stdout: "pipe",
});
const text = stderr!.toString();
// Should not crash, should succeed
expect(exitCode).toBe(0);
expect(text).not.toContain("panic");
expect(text).not.toContain("Internal assertion failure");
});