Skip to content

Commit

Permalink
pm: print command name to stdout (#14266)
Browse files Browse the repository at this point in the history
  • Loading branch information
nektro authored Oct 2, 2024
1 parent 8742439 commit 25083a4
Show file tree
Hide file tree
Showing 24 changed files with 781 additions and 240 deletions.
6 changes: 6 additions & 0 deletions packages/bun-types/bun.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5260,6 +5260,12 @@ declare module "bun" {
*/
const version: string;

/**
* The current version of Bun with the shortened commit sha of the build
* @example "v1.1.30 (d09df1af)"
*/
const version_with_sha: string;

/**
* The git sha at the time the currently-running version of Bun was compiled
* @example
Expand Down
6 changes: 6 additions & 0 deletions src/bun.js/bindings/BunObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ static JSValue constructBunRevision(VM& vm, JSObject*)
return JSC::jsString(vm, makeString(ASCIILiteral::fromLiteralUnsafe(Bun__version_sha)));
}

static JSValue constructBunVersionWithSha(VM& vm, JSObject*)
{
return JSC::jsString(vm, makeString(ASCIILiteral::fromLiteralUnsafe(Bun__version_with_sha)));
}

static JSValue constructIsMainThread(VM&, JSObject* object)
{
return jsBoolean(jsCast<Zig::GlobalObject*>(object->globalObject())->scriptExecutionContext()->isMainThread());
Expand Down Expand Up @@ -608,6 +613,7 @@ JSC_DEFINE_HOST_FUNCTION(functionFileURLToPath, (JSC::JSGlobalObject * globalObj
nanoseconds functionBunNanoseconds DontDelete|Function 0
openInEditor BunObject_callback_openInEditor DontDelete|Function 1
origin BunObject_getter_wrap_origin DontDelete|PropertyCallback
version_with_sha constructBunVersionWithSha ReadOnly|DontDelete|PropertyCallback
password constructPasswordObject DontDelete|PropertyCallback
pathToFileURL functionPathToFileURL DontDelete|Function 1
peek constructBunPeekObject DontDelete|PropertyCallback
Expand Down
1 change: 1 addition & 0 deletions src/bun.js/bindings/headers-handwritten.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ extern "C" bool Bun__fetchBuiltinModule(

// Used in process.version
extern "C" const char* Bun__version;
extern "C" const char* Bun__version_with_sha;

// Used in process.versions
extern "C" const char* Bun__versions_boringssl;
Expand Down
1 change: 1 addition & 0 deletions src/bun.js/node/types.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2116,6 +2116,7 @@ pub const Process = struct {
}

pub export const Bun__version: [*:0]const u8 = "v" ++ bun.Global.package_json_version;
pub export const Bun__version_with_sha: [*:0]const u8 = "v" ++ bun.Global.package_json_version_with_sha;
pub export const Bun__versions_boringssl: [*:0]const u8 = bun.Global.versions.boringssl;
pub export const Bun__versions_libarchive: [*:0]const u8 = bun.Global.versions.libarchive;
pub export const Bun__versions_mimalloc: [*:0]const u8 = bun.Global.versions.mimalloc;
Expand Down
4 changes: 2 additions & 2 deletions src/cli.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1014,8 +1014,8 @@ pub const Arguments = struct {

if (cmd == .BuildCommand) {
if (opts.entry_points.len == 0) {
Output.prettyErrorln("<r><b>bun build <r><d>v" ++ Global.package_json_version_with_sha ++ "<r>", .{});
Output.prettyError("<r><red>error: Missing entrypoints. What would you like to bundle?<r>\n\n", .{});
Output.prettyln("<r><b>bun build <r><d>v" ++ Global.package_json_version_with_sha ++ "<r>", .{});
Output.pretty("<r><red>error: Missing entrypoints. What would you like to bundle?<r>\n\n", .{});
Output.flush();
Output.pretty("Usage:\n <d>$<r> <b><green>bun build<r> \\<entrypoint\\> [...\\<entrypoints\\>] <cyan>[...flags]<r> \n", .{});
Output.pretty("\nTo see full documentation:\n <d>$<r> <b><green>bun build<r> --help\n", .{});
Expand Down
2 changes: 1 addition & 1 deletion src/cli/outdated_command.zig
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const Table = bun.fmt.Table;

pub const OutdatedCommand = struct {
pub fn exec(ctx: Command.Context) !void {
Output.prettyErrorln("<r><b>bun outdated <r><d>v" ++ Global.package_json_version_with_sha ++ "<r>", .{});
Output.prettyln("<r><b>bun outdated <r><d>v" ++ Global.package_json_version_with_sha ++ "<r>", .{});
Output.flush();

const cli = try PackageManager.CommandLineArguments.parse(ctx.allocator, .outdated);
Expand Down
2 changes: 1 addition & 1 deletion src/cli/pack_command.zig
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub const PackCommand = struct {
};

pub fn execWithManager(ctx: Command.Context, manager: *PackageManager) !void {
Output.prettyErrorln("<r><b>bun pack <r><d>v" ++ Global.package_json_version_with_sha ++ "<r>", .{});
Output.prettyln("<r><b>bun pack <r><d>v" ++ Global.package_json_version_with_sha ++ "<r>", .{});
Output.flush();

var lockfile: Lockfile = undefined;
Expand Down
2 changes: 1 addition & 1 deletion src/cli/test_command.zig
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ pub const TestCommand = struct {
Output.is_github_action = Output.isGithubAction();

// print the version so you know its doing stuff if it takes a sec
Output.prettyErrorln("<r><b>bun test <r><d>v" ++ Global.package_json_version_with_sha ++ "<r>", .{});
Output.prettyln("<r><b>bun test <r><d>v" ++ Global.package_json_version_with_sha ++ "<r>", .{});
Output.flush();

var env_loader = brk: {
Expand Down
10 changes: 5 additions & 5 deletions src/install/install.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8838,7 +8838,7 @@ pub const PackageManager = struct {
defer ctx.allocator.free(original_cwd);

if (manager.options.shouldPrintCommandName()) {
Output.prettyErrorln("<r><b>bun link <r><d>v" ++ Global.package_json_version_with_sha ++ "<r>\n", .{});
Output.prettyln("<r><b>bun link <r><d>v" ++ Global.package_json_version_with_sha ++ "<r>\n", .{});
Output.flush();
}

Expand Down Expand Up @@ -9021,7 +9021,7 @@ pub const PackageManager = struct {
defer ctx.allocator.free(original_cwd);

if (manager.options.shouldPrintCommandName()) {
Output.prettyErrorln("<r><b>bun unlink <r><d>v" ++ Global.package_json_version_with_sha ++ "<r>\n", .{});
Output.prettyln("<r><b>bun unlink <r><d>v" ++ Global.package_json_version_with_sha ++ "<r>\n", .{});
Output.flush();
}

Expand Down Expand Up @@ -9985,7 +9985,7 @@ pub const PackageManager = struct {
defer ctx.allocator.free(original_cwd);

if (manager.options.shouldPrintCommandName()) {
Output.prettyErrorln("<r><b>bun {s} <r><d>v" ++ Global.package_json_version_with_sha ++ "<r>\n", .{@tagName(subcommand)});
Output.prettyln("<r><b>bun {s} <r><d>v" ++ Global.package_json_version_with_sha ++ "<r>\n", .{@tagName(subcommand)});
Output.flush();
}

Expand Down Expand Up @@ -11724,7 +11724,7 @@ pub const PackageManager = struct {
// switch to `bun add <package>`
if (manager.options.positionals.len > 1) {
if (manager.options.shouldPrintCommandName()) {
Output.prettyErrorln("<r><b>bun add <r><d>v" ++ Global.package_json_version_with_sha ++ "<r>\n", .{});
Output.prettyln("<r><b>bun add <r><d>v" ++ Global.package_json_version_with_sha ++ "<r>\n", .{});
Output.flush();
}
manager.subcommand = .add;
Expand All @@ -11734,7 +11734,7 @@ pub const PackageManager = struct {
}

if (manager.options.shouldPrintCommandName()) {
Output.prettyErrorln("<r><b>bun install <r><d>v" ++ Global.package_json_version_with_sha ++ "<r>\n", .{});
Output.prettyln("<r><b>bun install <r><d>v" ++ Global.package_json_version_with_sha ++ "<r>\n", .{});
Output.flush();
}

Expand Down
15 changes: 5 additions & 10 deletions test/cli/install/__snapshots__/bun-install.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Bun Snapshot v1, https://goo.gl/fbAQLP

exports[`should report error on invalid format for package.json 1`] = `
"bun install
1 | foo
"1 | foo
^
error: Unexpected foo
at [dir]/package.json:1:1
Expand All @@ -11,8 +10,7 @@ ParserError parsing package.json in "[dir]/"
`;

exports[`should report error on invalid format for dependencies 1`] = `
"bun install
1 | {"name":"foo","version":"0.0.1","dependencies":[]}
"1 | {"name":"foo","version":"0.0.1","dependencies":[]}
^
error: dependencies expects a map of specifiers, e.g.
"dependencies": {
Expand All @@ -23,8 +21,7 @@ error: dependencies expects a map of specifiers, e.g.
`;
exports[`should report error on invalid format for optionalDependencies 1`] = `
"bun install
1 | {"name":"foo","version":"0.0.1","optionalDependencies":"bar"}
"1 | {"name":"foo","version":"0.0.1","optionalDependencies":"bar"}
^
error: optionalDependencies expects a map of specifiers, e.g.
"optionalDependencies": {
Expand All @@ -35,8 +32,7 @@ error: optionalDependencies expects a map of specifiers, e.g.
`;
exports[`should report error on invalid format for workspaces 1`] = `
"bun install
1 | {"name":"foo","version":"0.0.1","workspaces":{"packages":{"bar":true}}}
"1 | {"name":"foo","version":"0.0.1","workspaces":{"packages":{"bar":true}}}
^
error: Workspaces expects an array of strings, e.g.
"workspaces": [
Expand All @@ -47,8 +43,7 @@ error: Workspaces expects an array of strings, e.g.
`;
exports[`should report error on duplicated workspace packages 1`] = `
"bun install
1 | {"name":"moo","version":"0.0.3"}
"1 | {"name":"moo","version":"0.0.3"}
^
error: Workspace name "moo" already exists
at [dir]/baz/package.json:1:9
Expand Down
Loading

0 comments on commit 25083a4

Please sign in to comment.