Files
bun.sh/test/cli/install/lockfile-only.test.ts
Dylan Conway 0601eb0007 Make --linker=isolated the default for bun install (#23311)
### What does this PR do?
Makes isolated installs the default install strategy for projects with
workspaces in Bun v1.3.

Also fixes creating patches with `bun patch` and `--linker isolated`

Fixes #22693

### How did you verify your code works?
Added tests for node_modules renaming `bun patch` with isolated install.

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Claude Bot <claude-bot@bun.sh>
Co-authored-by: Claude <noreply@anthropic.com>
2025-10-08 18:00:38 -07:00

84 lines
2.0 KiB
TypeScript

import { spawn } from "bun";
import { afterAll, afterEach, beforeAll, beforeEach, expect, it } from "bun:test";
import { access, writeFile } from "fs/promises";
import { bunExe, bunEnv as env } from "harness";
import { join } from "path";
import {
dummyAfterAll,
dummyAfterEach,
dummyBeforeAll,
dummyBeforeEach,
dummyRegistry,
package_dir,
requested,
root_url,
setHandler,
} from "./dummy.registry.js";
beforeAll(dummyBeforeAll);
afterAll(dummyAfterAll);
beforeEach(async () => {
await dummyBeforeEach();
});
afterEach(dummyAfterEach);
it.each(["bun.lockb", "bun.lock"])("should not download tarballs with --lockfile-only using %s", async lockfile => {
const isLockb = lockfile === "bun.lockb";
const urls: string[] = [];
const registry = { "0.0.1": { as: "0.0.1" }, latest: "0.0.1" };
setHandler(dummyRegistry(urls, registry));
await writeFile(
join(package_dir, "package.json"),
JSON.stringify({
name: "foo",
dependencies: {
baz: "0.0.1",
},
}),
);
const cmd = [bunExe(), "install", "--lockfile-only"];
if (!isLockb) {
// the default beforeEach disables --save-text-lockfile in the dummy registry, so we should restore
// default behaviour
await writeFile(
join(package_dir, "bunfig.toml"),
`
[install]
cache = false
registry = "${root_url}/"
`,
);
}
const { stdout, stderr, exited } = spawn({
cmd,
cwd: package_dir,
stdout: "pipe",
stderr: "pipe",
env,
});
expect(await exited).toBe(0);
const err = await stderr.text();
expect(err).not.toContain("error:");
expect(err).toContain("Saved lockfile");
const out = await stdout.text();
expect(out.replace(/\s*\[[0-9\.]+m?s\]\s*$/, "").split(/\r?\n/)).toEqual([
expect.stringContaining("bun install v1."),
"",
expect.stringContaining(`Saved ${lockfile}`),
]);
expect(urls.sort()).toEqual([`${root_url}/baz`]);
expect(requested).toBe(1);
await access(join(package_dir, lockfile));
});