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 all 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 @@ -7562,6 +7562,7 @@ pub const PackageManager = struct {
if (cli.no_save) {
this.do.save_lockfile = false;
this.do.write_package_json = false;
this.enable.frozen_lockfile = true;
}

if (cli.dry_run) {
Expand Down Expand Up @@ -15254,6 +15255,8 @@ pub const PackageManager = struct {

// It's unnecessary work to re-save the lockfile if there are no changes
const should_save_lockfile =
// never save if frozen
!manager.options.enable.frozen_lockfile and
(load_result == .ok and ((load_result.ok.format == .binary and save_format == .text) or

// make sure old versions are updated
Expand Down
58 changes: 58 additions & 0 deletions test/regression/issue/16646/16646.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { expect, test } from "bun:test";
import fs from "fs";
import { bunEnv, bunExe, tmpdirSync } from "harness";
import { join } from "path";

test("bun install does create a new lockfile", async () => {
const testDir = tmpdirSync();
fs.cpSync(join(import.meta.dir), testDir, {
recursive: true,
});
const { exitCode, stderr } = Bun.spawnSync([bunExe(), "install"], {
env: bunEnv,
cwd: testDir,
});
const err = stderr.toString();
expect(err).toContain("Saved lockfile");

const bunLock = Bun.file(join(testDir, "bun.lock"));
expect(await bunLock.exists()).toBeTrue();

expect(exitCode).toBe(0);
});

test("bun install --frozen-lockfile does not create a new lockfile", async () => {
const testDir = tmpdirSync();
fs.cpSync(join(import.meta.dir), testDir, {
recursive: true,
});
const { exitCode, stderr } = Bun.spawnSync([bunExe(), "install", "--frozen-lockfile"], {
env: bunEnv,
cwd: testDir,
});
const err = stderr.toString();
expect(err).not.toContain("Saved lockfile");

const bunLock = Bun.file(join(testDir, "bun.lock"));
expect(await bunLock.exists()).toBeFalse();

expect(exitCode).toBe(0);
});

test("bun install --no-save does not create a new lockfile", async () => {
const testDir = tmpdirSync();
fs.cpSync(join(import.meta.dir), testDir, {
recursive: true,
});
const { exitCode, stderr } = Bun.spawnSync([bunExe(), "install", "--no-save"], {
env: bunEnv,
cwd: testDir,
});
const err = stderr.toString();
expect(err).not.toContain("Saved lockfile");

const bunLock = Bun.file(join(testDir, "bun.lock"));
expect(await bunLock.exists()).toBeFalse();

expect(exitCode).toBe(0);
});
Loading