Compare commits

...

4 Commits

Author SHA1 Message Date
Alistair Smith
562197f804 fix 2025-08-20 15:22:11 -07:00
Alistair Smith
35888fa2b2 deslop 2025-08-20 13:33:41 -07:00
autofix-ci[bot]
5ae3e9b519 [autofix.ci] apply automated fixes 2025-08-20 12:48:13 -07:00
Claude Bot
81bd5eab0c Improve output clarity for bun update command
When running `bun update` on packages that don't exist in package.json,
the output now shows "added" instead of "installed" to clearly distinguish
between packages that were:
- Updated from an existing version (shows "updated")
- Newly added because they didn't exist before (shows "added")

This prevents confusion when users mistype package names during updates,
as they'll now see "added package-name" instead of the generic "installed"
message that was identical to the update output.

Fixes the issue where `bun update zod-openapi` would install `openapi-zod`
and show "installed" without clearly indicating it was a new package.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-20 12:48:12 -07:00
3 changed files with 66 additions and 13 deletions

View File

@@ -400,11 +400,17 @@ pub fn print(
.none, .dir => {
printed_installed_update_request = true;
const fmt = comptime Output.prettyFmt("<r><green>installed<r> <b>{s}<r><d>@{}<r>\n", enable_ansi_colors);
const action_word = if (manager.subcommand == .update)
(if (manager.updating_packages.contains(package_name)) "updated" else "added")
else
"installed";
const fmt = comptime Output.prettyFmt("<r><green>{s}<r> <b>{s}<r><d>@{}<r>\n", enable_ansi_colors);
try writer.print(
fmt,
.{
action_word,
package_name,
resolved[package_id].fmt(string_buf, .posix),
},
@@ -421,11 +427,17 @@ pub fn print(
};
{
const fmt = comptime Output.prettyFmt("<r><green>installed<r> {s}<r><d>@{}<r> with binaries:\n", enable_ansi_colors);
const action_word = if (manager.subcommand == .update)
(if (manager.updating_packages.contains(package_name)) "updated" else "added")
else
"installed";
const fmt = comptime Output.prettyFmt("<r><green>{s}<r> {s}<r><d>@{}<r> with binaries:\n", enable_ansi_colors);
try writer.print(
fmt,
.{
action_word,
package_name,
resolved[package_id].fmt(string_buf, .posix),
},

View File

@@ -5210,7 +5210,7 @@ describe("update", () => {
expect(out).toEqual([
expect.stringContaining("bun update v1."),
"",
"installed no-deps@1.0.1",
"updated no-deps@1.0.1",
"",
expect.stringContaining("done"),
"",
@@ -5230,7 +5230,7 @@ describe("update", () => {
expect(out).toEqual([
expect.stringContaining("bun update v1."),
"",
"installed no-deps@2.0.0",
"updated no-deps@2.0.0",
"",
"1 package installed",
]);
@@ -5570,10 +5570,10 @@ describe("update", () => {
expect(out).toEqual([
expect.stringContaining("bun update v1."),
"",
"installed what-bin@1.5.0 with binaries:",
"updated what-bin@1.5.0 with binaries:",
" - what-bin",
"installed uses-what-bin@1.5.0",
"installed a-dep@1.0.5",
"updated uses-what-bin@1.5.0",
"updated a-dep@1.0.5",
"",
"3 packages installed",
]);
@@ -5617,7 +5617,7 @@ describe("update", () => {
expect(out).toEqual([
expect.stringContaining("bun update v1."),
"",
"installed a-dep@1.0.10",
"updated a-dep@1.0.10",
"",
expect.stringMatching(/(\[\d+\.\d+m?s\])/),
"",
@@ -5663,7 +5663,7 @@ describe("update", () => {
expect(out).toEqual([
expect.stringContaining("bun update v1."),
"",
args ? "installed a-dep@1.0.10" : expect.stringContaining("+ a-dep@1.0.10"),
args ? "updated a-dep@1.0.10" : expect.stringContaining("+ a-dep@1.0.10"),
"",
"1 package installed",
]);
@@ -5733,7 +5733,7 @@ describe("update", () => {
expect(out).toEqual([
expect.stringContaining("bun update v1."),
"",
"installed no-deps@1.0.0",
"updated no-deps@1.0.0",
"",
expect.stringMatching(/(\[\d+\.\d+m?s\])/),
"",
@@ -5749,7 +5749,7 @@ describe("update", () => {
expect(out).toEqual([
expect.stringContaining("bun update v1."),
"",
"installed no-deps@2.0.0",
"added no-deps@2.0.0",
"",
"1 package installed",
]);
@@ -5783,7 +5783,7 @@ describe("update", () => {
expect(out).toEqual([
expect.stringContaining("bun update v1."),
"",
"installed no-deps@1.1.0",
"updated no-deps@1.1.0",
"",
"1 package installed",
]);

View File

@@ -114,7 +114,7 @@ for (const { input } of [{ input: { baz: "~0.0.3", moo: "~0.1.0" } }, { input: {
expect(out2.replace(/\s*\[[0-9\.]+m?s\]\s*$/, "").split(/\r?\n/)).toEqual([
expect.stringContaining("bun update v1."),
"",
`installed baz@${tilde ? "0.0.5" : "0.0.3"} with binaries:`,
`updated baz@${tilde ? "0.0.5" : "0.0.3"} with binaries:`,
` - ${tilde ? "baz-exec" : "baz-run"}`,
"",
"1 package installed",
@@ -418,6 +418,47 @@ it("should support catalog versions in update", async () => {
expect(pkg.dependencies["no-deps"]).toBe("catalog:");
});
it("should show 'updated' for packages that existed and 'added' for new packages during update", async () => {
const urls: string[] = [];
// Test when running update on non-existent package (simulates the scenario from the issue)
const registry = {
"0.0.3": {},
latest: "0.0.3",
};
setHandler(dummyRegistry(urls, registry));
// Start with empty package.json
await writeFile(
join(package_dir, "package.json"),
JSON.stringify({
name: "foo",
dependencies: {},
}),
);
const {
stdout: stdout1,
stderr: stderr1,
exited: exited1,
} = spawn({
cmd: [bunExe(), "update", "baz"],
cwd: package_dir,
stdout: "pipe",
stderr: "pipe",
env,
});
expect(await exited1).toBe(0);
const out1 = await new Response(stdout1).text();
// When updating a package that doesn't exist, it should show "added"
expect(out1).toContain("added baz@0.0.3");
// Should NOT show "installed" or "updated"
expect(out1).not.toMatch(/installed baz@/);
expect(out1).not.toMatch(/updated baz@/);
});
it("should support --recursive flag", async () => {
// First verify the flag appears in help
const {