Skip to content

Commit

Permalink
Force non-zero exit code whenever bun install has any packages whic…
Browse files Browse the repository at this point in the history
…h failed to install (#10041)

* If any failed to install, always exit with non-zero

* [autofix.ci] apply automated fixes

* This test should fail

* Update bun-link.test.ts

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
Jarred-Sumner and autofix-ci[bot] authored Apr 7, 2024
1 parent 3679f69 commit d615c11
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
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);
});

0 comments on commit d615c11

Please sign in to comment.