Compare commits

...

2 Commits

Author SHA1 Message Date
autofix-ci[bot]
99ab5a5946 [autofix.ci] apply automated fixes 2023-12-27 09:33:48 +00:00
Jarred Sumner
d309a1eaa4 Update lockfile.zig 2023-12-27 01:31:53 -08:00
2 changed files with 39 additions and 24 deletions

View File

@@ -3482,32 +3482,47 @@ pub const Package = extern struct {
if (comptime features.check_for_duplicate_dependencies and !group.behavior.isPeer()) {
const entry = lockfile.scratch.duplicate_checker_map.getOrPutAssumeCapacity(external_alias.hash);
if (entry.found_existing) {
// duplicate dependencies are allowed in optionalDependencies
if (comptime group.behavior.isOptional()) {
for (package_dependencies[0..dependencies_count]) |*package_dep| {
if (package_dep.name_hash == this_dep.name_hash) {
// the last one wins
// this means:
// "devDependencies": { "lodash": "latest" },
// "dependencies": { "lodash": "1.0.0" }
//
// "latest" is what will be chosen, unless they did --production.
var is_other_one_workspace = this_dep.behavior.isWorkspace();
for (package_dependencies[0..dependencies_count]) |*package_dep| {
if (package_dep.name_hash == this_dep.name_hash) {
// workspace always wins
if (!package_dep.behavior.isWorkspace()) {
package_dep.* = this_dep;
break;
is_other_one_workspace = true;
}
break;
}
return null;
} else {
var notes = try allocator.alloc(logger.Data, 1);
notes[0] = .{
.text = try std.fmt.allocPrint(lockfile.allocator, "\"{s}\" originally specified here", .{external_alias.slice(buf)}),
.location = logger.Location.initOrNull(&source, source.rangeOfString(entry.value_ptr.*)),
};
try log.addRangeWarningFmtWithNotes(
&source,
source.rangeOfString(key_loc),
lockfile.allocator,
notes,
"Duplicate dependency: \"{s}\" specified in package.json",
.{external_alias.slice(buf)},
);
}
// duplicate dependencies are allowed in optionalDependencies
if (comptime !group.behavior.isOptional()) {
if (!is_other_one_workspace) {
var notes = try allocator.alloc(logger.Data, 1);
notes[0] = .{
.text = try std.fmt.allocPrint(lockfile.allocator, "\"{s}\" originally specified here", .{external_alias.slice(buf)}),
.location = logger.Location.initOrNull(&source, source.rangeOfString(entry.value_ptr.*)),
};
try log.addRangeWarningFmtWithNotes(
&source,
source.rangeOfString(key_loc),
lockfile.allocator,
notes,
"Duplicate dependency: \"{s}\" specified in package.json",
.{external_alias.slice(buf)},
);
}
}
return null;
}
entry.value_ptr.* = value_loc;

View File

@@ -5,10 +5,10 @@ import { tempDirWithFiles } from "harness";
it("duplicate dependencies should warn instead of error", () => {
const package_json = JSON.stringify({
devDependencies: {
"empty-package-for-bun-test-runner": "1.0.0"
"empty-package-for-bun-test-runner": "1.0.0",
},
dependencies: {
"empty-package-for-bun-test-runner": "1.0.0"
"empty-package-for-bun-test-runner": "1.0.0",
},
});