Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't save lockfile if --frozen-lockfile or --no-save #17481

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions src/install/install.zig
Original file line number Diff line number Diff line change
Expand Up @@ -15439,6 +15439,9 @@ pub const PackageManager = struct {
packages_len_before_install: usize,
log_level: Options.LogLevel,
) OOM!void {
if (!this.options.do.save_lockfile) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check for this flag before calling this function. The bug exists in the long chain of or's and and's used to create should_save_lockfile. this.options.do.save_lockfile is already checked, so likely it's not checked early enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved there: eb649a4

return;
}
if (this.lockfile.isEmpty()) {
if (!this.options.dry_run) delete: {
const delete_format = switch (load_result.*) {
Expand Down
40 changes: 40 additions & 0 deletions test/regression/issue/16646/16646.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { expect, test } from "bun:test";
import fs from "fs";
import { bunEnv, bunExe, tmpdirSync } from "harness";
import { join } from "path";

test("bun install --frozen-lockfile does not create a new lockfile", async () => {
const testDir = tmpdirSync();
console.log(join(import.meta.dir), testDir, {
recursive: true,
});
fs.cpSync(join(import.meta.dir), testDir, {
recursive: true,
});
const { exitCode } = Bun.spawnSync([bunExe(), "install", "--frozen-lockfile"], {
env: bunEnv,
cwd: testDir,
});
const bunLock = Bun.file(join(testDir, "bun.lock"));

expect(await bunLock.exists()).toBeFalse();
expect(exitCode).toBe(0);
});

test("bun install does create a new lockfile", async () => {
const testDir = tmpdirSync();
console.log(join(import.meta.dir), testDir, {
recursive: true,
});
fs.cpSync(join(import.meta.dir), testDir, {
recursive: true,
});
const { exitCode } = Bun.spawnSync([bunExe(), "install"], {
env: bunEnv,
cwd: testDir,
});
const bunLock = Bun.file(join(testDir, "bun.lock"));

expect(await bunLock.exists()).toBeTrue();
expect(exitCode).toBe(0);
});
Loading