diff options
-rw-r--r-- | src/install/lockfile.zig | 15 | ||||
-rw-r--r-- | test/bun.js/install/bun-install.test.ts | 47 |
2 files changed, 53 insertions, 9 deletions
diff --git a/src/install/lockfile.zig b/src/install/lockfile.zig index 70e14fb82..e96a7be80 100644 --- a/src/install/lockfile.zig +++ b/src/install/lockfile.zig @@ -983,11 +983,10 @@ pub const Printer = struct { var dep_id = resolutions_list[0].off; const dep_end = dep_id + resolutions_list[0].len; outer: while (dep_id < dep_end) : (dep_id += 1) { + const dependency = dependencies_buffer[dep_id]; + if (dependency.behavior.isPeer()) continue; const package_id = resolutions_buffer[dep_id]; if (package_id >= end) continue; - const is_new = installed.isSet(package_id); - - const dependency = dependencies_buffer[dep_id]; const package_name = dependency.name.slice(string_buf); if (this.updates.len > 0) { @@ -1004,7 +1003,7 @@ pub const Printer = struct { } } - if (!is_new) continue; + if (!installed.isSet(package_id)) continue; const fmt = comptime brk: { if (enable_ansi_colors) { @@ -1024,9 +1023,9 @@ pub const Printer = struct { } } else { outer: for (dependencies_buffer) |dependency, dep_id| { + if (dependency.behavior.isPeer()) continue; const package_id = resolutions_buffer[dep_id]; if (package_id >= end) continue; - const package_name = dependency.name.slice(string_buf); if (this.updates.len > 0) { @@ -1058,8 +1057,7 @@ pub const Printer = struct { try writer.writeAll("\n"); } - for (this.updates) |_, update_id| { - const dependency_id = id_map[update_id]; + for (id_map) |dependency_id| { if (dependency_id == invalid_package_id) continue; const name = dependencies_buffer[dependency_id].name; const package_id = resolutions_buffer[dependency_id]; @@ -2413,7 +2411,8 @@ pub const Package = extern struct { .version = dependency_version, }; - if (comptime features.check_for_duplicate_dependencies) { + // peerDependencies may be specified on on existing dependencies + if (comptime features.check_for_duplicate_dependencies and !group.behavior.isPeer()) { var entry = lockfile.scratch.duplicate_checker_map.getOrPutAssumeCapacity(external_name.hash); if (entry.found_existing) { // duplicate dependencies are allowed in optionalDependencies diff --git a/test/bun.js/install/bun-install.test.ts b/test/bun.js/install/bun-install.test.ts index 063cd3720..8cd826615 100644 --- a/test/bun.js/install/bun-install.test.ts +++ b/test/bun.js/install/bun-install.test.ts @@ -1685,7 +1685,6 @@ it("should consider peerDependencies during hoisting", async () => { expect(out.replace(/\s*\[[0-9\.]+m?s\]\s*$/, "").split(/\r?\n/)).toEqual([ " + bar@workspace:bar", " + moo@workspace:moo", - " + baz@0.0.5", "", " 4 packages installed", ]); @@ -1721,3 +1720,49 @@ it("should consider peerDependencies during hoisting", async () => { expect(await readdirSorted(join(package_dir, "moo"))).toEqual(["package.json"]); await access(join(package_dir, "bun.lockb")); }); + +it("should not regard peerDependencies declarations as duplicates", async () => { + const urls: string[] = []; + setHandler(dummyRegistry(urls)); + await writeFile( + join(package_dir, "package.json"), + JSON.stringify({ + name: "foo", + version: "0.0.1", + dependencies: { + bar: "*", + }, + peerDependencies: { + bar: "^0.0.2", + }, + }), + ); + const { stdout, stderr, exited } = spawn({ + cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"], + cwd: package_dir, + stdout: null, + stdin: "pipe", + stderr: "pipe", + env, + }); + expect(stderr).toBeDefined(); + const err = await new Response(stderr).text(); + expect(err).toContain("Saved lockfile"); + expect(stdout).toBeDefined(); + const out = await new Response(stdout).text(); + expect(out.replace(/\s*\[[0-9\.]+m?s\]\s*$/, "").split(/\r?\n/)).toEqual([ + " + bar@0.0.2", + "", + " 1 packages installed", + ]); + expect(await exited).toBe(0); + expect(urls.sort()).toEqual([`${root_url}/bar`, `${root_url}/bar-0.0.2.tgz`]); + expect(requested).toBe(2); + expect(await readdirSorted(join(package_dir, "node_modules"))).toEqual([".cache", "bar"]); + expect(await readdirSorted(join(package_dir, "node_modules", "bar"))).toEqual(["package.json"]); + expect(await file(join(package_dir, "node_modules", "bar", "package.json")).json()).toEqual({ + name: "bar", + version: "0.0.2", + }); + await access(join(package_dir, "bun.lockb")); +}); |