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

Fixes #7767: Updated bun upgrade to return error when used with cmd arguments #7784

Merged
merged 20 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
d92dddf
Updated `upgrade` to return error when used with cmd arguments
BrookJeynes Dec 22, 2023
ddbf571
added test
BrookJeynes Dec 22, 2023
1010d66
Merge branch 'main' into 7767-better-upgrade-dx
BrookJeynes Dec 22, 2023
4729379
Merge branch 'main' into 7767-better-upgrade-dx
BrookJeynes Dec 23, 2023
ac6ab24
Merge branch 'main' into 7767-better-upgrade-dx
BrookJeynes Dec 23, 2023
cf53e60
updated condition to allow
BrookJeynes Dec 23, 2023
205c13e
Upgrade argument check now only checks if all arguments contain `--`
BrookJeynes Dec 23, 2023
d1d964b
Merge branch 'main' into 7767-better-upgrade-dx
BrookJeynes Dec 24, 2023
8882e0d
Merge branch 'main' into 7767-better-upgrade-dx
BrookJeynes Jan 4, 2024
1703cfa
Merge branch 'main' into 7767-better-upgrade-dx
BrookJeynes Jan 9, 2024
d333ea5
Using `cpSync` in the following context results in an "Is a directory…
BrookJeynes Jan 21, 2024
b2fa82c
Update message displayed back to user
BrookJeynes Jan 22, 2024
5279915
moved args check to upgrade_command.zig
BrookJeynes Jan 22, 2024
e0e76c4
fixed broken tests
BrookJeynes Jan 22, 2024
5284fbc
changing string interpolation to join() for paths
BrookJeynes Jan 22, 2024
48e2277
Merge branch 'main' into 7767-better-upgrade-dx
BrookJeynes Jan 22, 2024
3d03d49
[autofix.ci] apply automated fixes
autofix-ci[bot] Feb 13, 2024
aa94735
Merge branch 'main' into 7767-better-upgrade-dx
BrookJeynes Feb 13, 2024
221c874
Fixed build errors
BrookJeynes Feb 13, 2024
0ce015f
Merge branch 'main' into 7767-better-upgrade-dx
paperclover Mar 4, 2024
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
17 changes: 17 additions & 0 deletions src/cli/upgrade_command.zig
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,23 @@ pub const UpgradeCommand = struct {
pub fn exec(ctx: Command.Context) !void {
@setCold(true);

const args = bun.argv();
if (args.len > 2) {
for (args[2..]) |arg| {
if (!strings.contains(arg, "--")) {
Output.prettyError(
\\<r><red>error<r><d>:<r> This command updates Bun itself, and does not take package names.
\\<blue>note<r><d>:<r> Use `bun update
, .{});
for (args[2..]) |arg_err| {
Output.prettyError(" {s}", .{arg_err});
}
Output.prettyErrorln("` instead.", .{});
Global.exit(1);
}
}
}

_exec(ctx) catch |err| {
Output.prettyErrorln(
\\<r>Bun upgrade failed with error: <red><b>{s}<r>
Expand Down
112 changes: 112 additions & 0 deletions test/cli/install/bun-upgrade.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { spawn } from "bun";
import { afterEach, beforeEach, expect, it } from "bun:test";
import { bunExe, bunEnv as env } from "harness";
import { mkdtemp, realpath, rm } from "fs/promises";
import { tmpdir } from "os";
import { join } from "path";
import { copyFileSync } from "js/node/fs/export-star-from";

let run_dir: string;
let exe_name: string = "bun-debug";

beforeEach(async () => {
run_dir = await realpath(
await mkdtemp(join(tmpdir(), "bun-upgrade.test." + Math.trunc(Math.random() * 9999999).toString(32))),
);
copyFileSync(bunExe(), join(run_dir, exe_name));
});
afterEach(async () => {
await rm(run_dir, { force: true, recursive: true });
});

it("two invalid arguments, should display error message and suggest command", async () => {
const { stderr } = spawn({
cmd: [join(run_dir, exe_name), "upgrade", "bun-types", "--dev"],
cwd: run_dir,
stdout: null,
stdin: "pipe",
stderr: "pipe",
env,
});

const err = await new Response(stderr).text();
expect(err.split(/\r?\n/)).toContain("error: This command updates Bun itself, and does not take package names.");
expect(err.split(/\r?\n/)).toContain("note: Use `bun update bun-types --dev` instead.");
});

it("two invalid arguments flipped, should display error message and suggest command", async () => {
const { stderr } = spawn({
cmd: [join(run_dir, exe_name), "upgrade", "--dev", "bun-types"],
cwd: run_dir,
stdout: null,
stdin: "pipe",
stderr: "pipe",
env,
});

const err = await new Response(stderr).text();
expect(err.split(/\r?\n/)).toContain("error: This command updates Bun itself, and does not take package names.");
expect(err.split(/\r?\n/)).toContain("note: Use `bun update --dev bun-types` instead.");
});

it("one invalid argument, should display error message and suggest command", async () => {
const { stderr } = spawn({
cmd: [join(run_dir, exe_name), "upgrade", "bun-types"],
cwd: run_dir,
stdout: null,
stdin: "pipe",
stderr: "pipe",
env,
});

const err = await new Response(stderr).text();
expect(err.split(/\r?\n/)).toContain("error: This command updates Bun itself, and does not take package names.");
expect(err.split(/\r?\n/)).toContain("note: Use `bun update bun-types` instead.");
});

it("one valid argument, should succeed", async () => {
const { stderr } = spawn({
cmd: [join(run_dir, exe_name), "upgrade", "--help"],
cwd: run_dir,
stdout: null,
stdin: "pipe",
stderr: "pipe",
env,
});

const err = await new Response(stderr).text();
// Should not contain error message
expect(err.split(/\r?\n/)).not.toContain("error: This command updates bun itself, and does not take package names.");
expect(err.split(/\r?\n/)).not.toContain("note: Use `bun update --help` instead.");
});

it("two valid argument, should succeed", async () => {
const { stderr } = spawn({
cmd: [join(run_dir, exe_name), "upgrade", "--stable", "--profile"],
cwd: run_dir,
stdout: null,
stdin: "pipe",
stderr: "pipe",
env,
});

const err = await new Response(stderr).text();
// Should not contain error message
expect(err.split(/\r?\n/)).not.toContain("error: This command updates Bun itself, and does not take package names.");
expect(err.split(/\r?\n/)).not.toContain("note: Use `bun update --stable --profile` instead.");
});

it("zero arguments, should succeed", async () => {
const { stderr } = spawn({
cmd: [join(run_dir, exe_name), "upgrade"],
cwd: run_dir,
stdout: null,
stdin: "pipe",
stderr: "pipe",
env,
});

const err = await new Response(stderr).text();
// Should not contain error message
expect(err.split(/\r?\n/)).not.toContain("error: This command updates Bun itself, and does not take package names.");
});
Loading