Skip to content
Merged
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
7 changes: 5 additions & 2 deletions src/install/PackageManager/install_with_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ pub fn install_with_manager(
if bun_core::handle_oom(Lockfile::eql(
&manager.lockfile,
&lockfile_before_clean,
packages_len_before_install,
lockfile_before_clean.loaded_package_count as usize,
)) {
break 'frozen_lockfile;
}
Expand Down Expand Up @@ -944,7 +944,10 @@ pub fn install_with_manager(
// If the lockfile was frozen, we already checked it
!manager.options.enable.frozen_lockfile()
&& if load_result.loaded_from_text_lockfile() {
!manager.lockfile.eql(&lockfile_before_clean, packages_len_before_install)?
!manager.lockfile.eql(
&lockfile_before_clean,
lockfile_before_clean.loaded_package_count as usize,
)?
} else {
manager.lockfile.has_meta_hash_changed(
PackageManager::verbose_install() || manager.options.do_.print_meta_hash_string(),
Expand Down
15 changes: 11 additions & 4 deletions src/install/lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2664,8 +2664,12 @@ impl<'a> EqlSorter<'a> {
}

impl Lockfile {
/// `cut_off_pkg_id` should be removed when we stop appending packages to lockfile during install step
pub(crate) fn eql(&self, r: &Lockfile, cut_off_pkg_id: usize) -> Result<bool, AllocError> {
/// A placement of `r` bound past `r_loaded_package_count` was rebound after loading: a change.
pub(crate) fn eql(
&self,
r: &Lockfile,
r_loaded_package_count: usize,
) -> Result<bool, AllocError> {
let l: &Lockfile = self;
let l_hoisted_deps = l.buffers.hoisted_dependencies.as_slice();
let r_hoisted_deps = r.buffers.hoisted_dependencies.as_slice();
Expand Down Expand Up @@ -2704,7 +2708,7 @@ impl Lockfile {
continue;
}
let l_pkg_id = l.buffers.resolutions[l_dep_id as usize];
if l_pkg_id == invalid_package_id || l_pkg_id as usize >= cut_off_pkg_id {
if l_pkg_id == invalid_package_id {
continue;
}
sort_buf.push(PathToId {
Expand Down Expand Up @@ -2732,9 +2736,12 @@ impl Lockfile {
continue;
}
let r_pkg_id = r.buffers.resolutions[r_dep_id as usize];
if r_pkg_id == invalid_package_id || r_pkg_id as usize >= cut_off_pkg_id {
if r_pkg_id == invalid_package_id {
continue;
}
if r_pkg_id as usize >= r_loaded_package_count {
return Ok(false);
}
sort_buf.push(PathToId {
pkg_id: r_pkg_id,
tree_path: tree_path_ptr,
Expand Down
42 changes: 42 additions & 0 deletions test/cli/install/bun-lock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,48 @@ it("escapes double quotes in npm registry tarball URLs when saving bun.lock", as
expect(await exited).toBe(0);
});

// --frozen-lockfile compares the tree built from bun.lock with the tree a clean install
// builds, so an entry nothing depends on (the clean drops it) must not change the
// outcome, wherever it sits in the file. The comparison used to skip the loaded side's
// highest package ids once the clean had dropped an entry, so the entries listed after
// the unused one went missing from the comparison.
it("--frozen-lockfile accepts a bun.lock with an entry nothing depends on, wherever it is listed", async () => {
const noDeps = { "no-deps": ["no-deps@1.0.0", "", {}, ""] };
const unused = { "a-dep": ["a-dep@1.0.1", "", {}, ""] };
for (const packages of [
{ ...unused, ...noDeps },
{ ...noDeps, ...unused },
]) {
const { packageDir, packageJson } = await registry.createTestDir();
await write(packageJson, JSON.stringify({ name: "foo", dependencies: { "no-deps": "1.0.0" } }));
const lockfile = JSON.stringify({
lockfileVersion: 1,
configVersion: 1,
workspaces: { "": { name: "foo", dependencies: { "no-deps": "1.0.0" } } },
packages,
});
await write(join(packageDir, "bun.lock"), lockfile);

await using proc = spawn({
cmd: [bunExe(), "install", "--frozen-lockfile"],
cwd: packageDir,
env,
stdout: "pipe",
stderr: "pipe",
});
const [out, err, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);
expect({ order: Object.keys(packages), err, exitCode }).toEqual({
order: Object.keys(packages),
err: expect.not.stringContaining("lockfile had changes"),
exitCode: 0,
});
expect(out).toContain("no-deps@1.0.0");
expect(await exists(join(packageDir, "node_modules", "no-deps", "package.json"))).toBeTrue();
expect(await exists(join(packageDir, "node_modules", "a-dep"))).toBeFalse();
expect(await file(join(packageDir, "bun.lock")).text()).toBe(lockfile);
}
});

it("escapes quotes and newlines in requested version literals when writing yarn.lock", async () => {
const { packageDir, packageJson } = await registry.createTestDir();

Expand Down
Loading