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

Force non-zero exit code whenever bun install has any packages which failed to install #10041

Merged
merged 4 commits into from
Apr 7, 2024
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
2 changes: 1 addition & 1 deletion packages/bun-types/bun.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3000,7 +3000,7 @@ declare module "bun" {
*
* Due to this limitation, while the internal counter may continue beyond this point,
* the precision of the returned value will degrade after 14.8 weeks of uptime (when the nanosecond
* count exceeds Number.MAX_SAFE_INTEGER). Beyond this point, the function will continue to count but
* count exceeds Number.MAX_SAFE_INTEGER). Beyond this point, the function will continue to count but
* with reduced precision, which might affect time calculations and comparisons in long-running applications.
*
* @returns {number} The number of nanoseconds since the process was started, with precise values up to
Expand Down
14 changes: 14 additions & 0 deletions src/install/install.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2194,6 +2194,8 @@ pub const PackageManager = struct {
// actually have scripts to run, and we add them to this list
trusted_deps_to_add_to_package_json: std.ArrayListUnmanaged(string) = .{},

any_failed_to_install: bool = false,

const PreallocatedNetworkTasks = std.BoundedArray(NetworkTask, 1024);
const NetworkTaskQueue = std.HashMapUnmanaged(u64, void, IdentityContext(u64), 80);
pub var verbose_install = false;
Expand Down Expand Up @@ -8011,6 +8013,10 @@ pub const PackageManager = struct {
switch (manager.options.log_level) {
inline else => |log_level| try manager.updatePackageJSONAndInstallWithManager(ctx, op, log_level),
}

if (manager.any_failed_to_install) {
Global.exit(1);
}
}

fn updatePackageJSONAndInstallWithManager(
Expand Down Expand Up @@ -8383,6 +8389,10 @@ pub const PackageManager = struct {
try switch (manager.options.log_level) {
inline else => |log_level| manager.installWithManager(ctx, package_json_contents, log_level),
};

if (manager.any_failed_to_install) {
Global.exit(1);
}
}

pub const PackageInstaller = struct {
Expand Down Expand Up @@ -10466,6 +10476,10 @@ pub const PackageManager = struct {
}
}

if (install_summary.fail > 0) {
manager.any_failed_to_install = true;
}

Output.flush();
}

Expand Down
4 changes: 3 additions & 1 deletion test/cli/install/bun-link.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,5 +512,7 @@ it("should link dependency without crashing", async () => {
"[] done",
"",
]);
expect(await exited4).toBe(0);

// This should fail with a non-zero exit code.
expect(await exited4).toBe(1);
});
Loading