Skip to content

Commit 447f844

Browse files
RiskyMHclaudeautofix-ci[bot]
authored
followup #21833 (bun audit more filtering options) (#21873)
### What does this PR do? followup #21833 ### How did you verify your code works? --------- Co-authored-by: Claude <[email protected]> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 0845231 commit 447f844

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

src/cli/audit_command.zig

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ fn buildProductionPackageSet(allocator: std.mem.Allocator, pm: *PackageManager,
198198
const resolutions = pm.lockfile.buffers.resolutions.items;
199199
const root_id = pm.root_package_id.get(pm.lockfile, pm.workspace_name_hash);
200200

201-
var queue = std.ArrayList(u32).init(allocator);
201+
var queue = std.fifo.LinearFifo(u32, .Dynamic).init(allocator);
202202
defer queue.deinit();
203203

204204
const root_deps = pkg_dependencies[root_id];
@@ -207,19 +207,14 @@ fn buildProductionPackageSet(allocator: std.mem.Allocator, pm: *PackageManager,
207207
const res_slice = root_resolutions.get(resolutions);
208208

209209
for (dep_slice, res_slice) |dep, resolved_pkg_id| {
210-
if (!dep.behavior.isDev()) {
211-
if (resolved_pkg_id < pkg_names.len) {
212-
const pkg_name = pkg_names[resolved_pkg_id].slice(buf);
213-
try prod_set.put(pkg_name, {});
214-
try queue.append(resolved_pkg_id);
215-
}
210+
if (!dep.behavior.isDev() and resolved_pkg_id < packages.len) {
211+
const pkg_name = pkg_names[resolved_pkg_id].slice(buf);
212+
try prod_set.put(pkg_name, {});
213+
try queue.writeItem(resolved_pkg_id);
216214
}
217215
}
218216

219-
while (queue.items.len > 0) {
220-
const current_pkg_id = queue.orderedRemove(0);
221-
if (current_pkg_id >= pkg_names.len) continue;
222-
217+
while (queue.readItem()) |current_pkg_id| {
223218
const current_deps = pkg_dependencies[current_pkg_id];
224219
const current_resolutions = pkg_resolutions[current_pkg_id];
225220
const current_dep_slice = current_deps.get(dependencies);
@@ -231,7 +226,7 @@ fn buildProductionPackageSet(allocator: std.mem.Allocator, pm: *PackageManager,
231226
const pkg_name = pkg_names[resolved_pkg_id].slice(buf);
232227
if (!prod_set.contains(pkg_name)) {
233228
try prod_set.put(pkg_name, {});
234-
try queue.append(resolved_pkg_id);
229+
try queue.writeItem(resolved_pkg_id);
235230
}
236231
}
237232
}

src/install/PackageManager/CommandLineArguments.zig

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,15 @@ pub const AuditLevel = enum {
247247
high,
248248
critical,
249249

250+
const Map = bun.ComptimeStringMap(AuditLevel, .{
251+
.{ "low", .low },
252+
.{ "moderate", .moderate },
253+
.{ "high", .high },
254+
.{ "critical", .critical },
255+
});
256+
250257
pub fn fromString(str: []const u8) ?AuditLevel {
251-
if (bun.strings.eqlComptime(str, "low")) return .low;
252-
if (bun.strings.eqlComptime(str, "moderate")) return .moderate;
253-
if (bun.strings.eqlComptime(str, "high")) return .high;
254-
if (bun.strings.eqlComptime(str, "critical")) return .critical;
255-
return null;
258+
return Map.get(str);
256259
}
257260

258261
pub fn shouldIncludeSeverity(self: AuditLevel, severity: []const u8) bool {

0 commit comments

Comments
 (0)