Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 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
75 changes: 0 additions & 75 deletions src/install/PackageManager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,81 +101,6 @@ pub mod options {
pub use super::package_manager_options::*;
}

// ──────────────────────────────────────────────────────────────────────────
// Only the `printHelp` text is needed by `CommandLineArguments::parse`. The
// `exec()` body remains in bun_cli (it depends on tier-6 ScanCommand /
// PackCommand etc. and is the *consumer* of install, not a dependency).
// ──────────────────────────────────────────────────────────────────────────
pub(crate) struct PackageManagerCommand;

impl PackageManagerCommand {
fn print_help() {
// the output of --help uses the following syntax highlighting
// template: <b>Usage<r>: <b><green>bun <command><r> <cyan>[flags]<r> <blue>[arguments]<r>
// use [foo] for multiple arguments or flags for foo.
// use <bar> to emphasize 'bar'

let intro_text = r"
<b>Usage<r>: <b><green>bun pm<r> <cyan>[flags]<r> <blue>[\<command\>]<r>

Run package manager utilities.
";
let outro_text = r"

<b>Commands:<r>

<b><green>bun pm<r> <blue>scan<r> scan all packages in lockfile for security vulnerabilities
<b><green>bun pm<r> <blue>pack<r> create a tarball of the current workspace
<d>├<r> <cyan>--dry-run<r> do everything except for writing the tarball to disk
<d>├<r> <cyan>--destination<r> the directory the tarball will be saved in
<d>├<r> <cyan>--filename<r> the name of the tarball
<d>├<r> <cyan>--ignore-scripts<r> don't run pre/postpack and prepare scripts
<d>├<r> <cyan>--gzip-level<r> specify a custom compression level for gzip (0-9, default is 9)
<d>└<r> <cyan>--quiet<r> only output the tarball filename
<b><green>bun pm<r> <blue>bin<r> print the path to bin folder
<d>└<r> <cyan>-g<r> print the <b>global<r> path to bin folder
<b><green>bun pm<r> <blue>ls<r> list the dependency tree according to the current lockfile
<d>├<r> <cyan>--all<r> list the entire dependency tree according to the current lockfile
<d>└<r> <cyan>--trusted<r> list only trusted dependencies
<b><green>bun pm<r> <blue>why<r> <d>\<pkg\><r> show dependency tree explaining why a package is installed
<b><green>bun pm<r> <blue>licenses<r> list installed packages grouped by license
<d>├<r> <cyan>--json<r> output as JSON
<d>├<r> <cyan>--prod<r> omit devDependencies
<d>├<r> <cyan>--dev<r> list only what devDependencies pull in
<d>├<r> <cyan>--long<r> also print author, description and homepage
<d>└<r> <cyan>--filter<r> <d>\<pattern\><r> list only the matching workspaces' dependencies
<b><green>bun pm<r> <blue>whoami<r> print the current npm username
<b><green>bun pm<r> <blue>view<r> <d>name[@version]<r> view package metadata from the registry <d>(use `bun info` instead)<r>
<b><green>bun pm<r> <blue>version<r> <d>[increment]<r> bump the version in package.json and create a git tag
<d>└<r> <cyan>increment<r> patch, minor, major, prepatch, preminor, premajor, prerelease, from-git, or a specific version
<b><green>bun pm<r> <blue>pkg<r> manage data in package.json
<d>├<r> <cyan>get<r> <d>[key ...]<r>
<d>├<r> <cyan>set<r> <d>key=value ...<r>
<d>├<r> <cyan>delete<r> <d>key ...<r>
<d>└<r> <cyan>fix<r> auto-correct common package.json errors
<b><green>bun pm<r> <blue>hash<r> generate & print the hash of the current lockfile
<b><green>bun pm<r> <blue>hash-string<r> print the string used to hash the lockfile
<b><green>bun pm<r> <blue>hash-print<r> print the hash stored in the current lockfile
<b><green>bun pm<r> <blue>cache<r> print the path to the cache folder
<b><green>bun pm<r> <blue>cache rm<r> clear the cache
<b><green>bun pm<r> <blue>migrate<r> migrate another package manager's lockfile without installing anything
<b><green>bun pm<r> <blue>untrusted<r> print current untrusted dependencies with scripts
<b><green>bun pm<r> <blue>trust<r> <d>names ...<r> run scripts for untrusted dependencies and add to `trustedDependencies`
<d>└<r> <cyan>--all<r> trust all untrusted dependencies
<b><green>bun pm<r> <blue>default-trusted<r> print the default trusted dependencies list

Learn more about these at <magenta>https://bun.com/docs/cli/pm<r>.
";

#[allow(clippy::disallowed_methods)]
// help-text consts contain <tag> markup that must be tag-walked
Output::pretty(format_args!("{}", intro_text));
#[allow(clippy::disallowed_methods)]
Output::pretty(format_args!("{}", outro_text));
Output::flush();
}
}

use crate::lockfile_real::package as Package;
use crate::package_manager_task as Task;
use crate::resolvers::folder_resolver::{Entry as FolderResolutionEntry, FolderResolution};
Expand Down
62 changes: 60 additions & 2 deletions src/install/PackageManager/CommandLineArguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
//! - bun audit

use crate::package_install;
use crate::package_manager_real::PackageManagerCommand;
use crate::package_manager_real::Subcommand;
use bun_clap as clap;
use bun_core::strings;
Expand Down Expand Up @@ -876,7 +875,66 @@ Full documentation is available at <magenta>https://bun.com/docs/install/patch<r
Output::flush();
}
Subcommand::Pm => {
PackageManagerCommand::print_help();
let intro_text = r"
<b>Usage<r>: <b><green>bun pm<r> <cyan>[flags]<r> <blue>[\<command\>]<r>

Run package manager utilities.";
let outro_text = r"

<b>Commands:<r>

<b><green>bun pm<r> <blue>scan<r> scan all packages in lockfile for security vulnerabilities
<b><green>bun pm<r> <blue>pack<r> create a tarball of the current workspace
<d>├<r> <cyan>--dry-run<r> do everything except for writing the tarball to disk
<d>├<r> <cyan>--destination<r> the directory the tarball will be saved in
<d>├<r> <cyan>--filename<r> the name of the tarball
<d>├<r> <cyan>--ignore-scripts<r> don't run pre/postpack and prepare scripts
<d>├<r> <cyan>--gzip-level<r> specify a custom compression level for gzip (0-9, default is 9)
<d>└<r> <cyan>--quiet<r> only output the tarball filename
<b><green>bun pm<r> <blue>bin<r> print the path to bin folder
<d>└<r> <cyan>-g<r> print the <b>global<r> path to bin folder
<b><green>bun pm<r> <blue>ls<r> list the dependency tree according to the current lockfile
<d>├<r> <cyan>--all<r> list the entire dependency tree according to the current lockfile
<d>└<r> <cyan>--trusted<r> list only trusted dependencies
<b><green>bun pm<r> <blue>why<r> <d>\<pkg\><r> show dependency tree explaining why a package is installed
<b><green>bun pm<r> <blue>diff<r> <d>[a] [b]<r> show what changed between two versions of a package (or vs a folder/tarball)
<d>├<r> <d>bun pm diff react<r> installed version → latest
<d>├<r> <d>bun pm diff react@18.2.0 19.0.0<r>
<d>├<r> <d>bun pm diff axios@1.6.0:lib 1.6.1<r> only files under lib/ <d>(also<r> <d>:file.js<r><d>, or paths after the two sides)<r>
<d>├<r> <cyan>--stat<r>, <cyan>--name-only<r> summarize instead of printing hunks
<d>├<r> <cyan>-U<r> <d>n<r> lines of context (default 3)
<d>└<r> <cyan>--json<r> one JSON document (files, patch text, notes, totals)
<b><green>bun pm<r> <blue>licenses<r> list installed packages grouped by license
<d>├<r> <cyan>--json<r> output as JSON
<d>├<r> <cyan>--prod<r> omit devDependencies
<d>├<r> <cyan>--dev<r> list only what devDependencies pull in
<d>├<r> <cyan>--long<r> also print author, description and homepage
<d>└<r> <cyan>--filter<r> <d>\<pattern\><r> list only the matching workspaces' dependencies
<b><green>bun pm<r> <blue>whoami<r> print the current npm username
<b><green>bun pm<r> <blue>view<r> <d>name[@version]<r> view package metadata from the registry <d>(use `bun info` instead)<r>
<b><green>bun pm<r> <blue>version<r> <d>[increment]<r> bump the version in package.json and create a git tag
<d>└<r> <cyan>increment<r> patch, minor, major, prepatch, preminor, premajor, prerelease, from-git, or a specific version
<b><green>bun pm<r> <blue>pkg<r> manage data in package.json
<d>├<r> <cyan>get<r> <d>[key ...]<r>
<d>├<r> <cyan>set<r> <d>key=value ...<r>
<d>├<r> <cyan>delete<r> <d>key ...<r>
<d>└<r> <cyan>fix<r> auto-correct common package.json errors
<b><green>bun pm<r> <blue>hash<r> generate & print the hash of the current lockfile
<b><green>bun pm<r> <blue>hash-string<r> print the string used to hash the lockfile
<b><green>bun pm<r> <blue>hash-print<r> print the hash stored in the current lockfile
<b><green>bun pm<r> <blue>cache<r> print the path to the cache folder
<b><green>bun pm<r> <blue>cache rm<r> clear the cache
<b><green>bun pm<r> <blue>migrate<r> migrate another package manager's lockfile without installing anything
<b><green>bun pm<r> <blue>untrusted<r> print current untrusted dependencies with scripts
<b><green>bun pm<r> <blue>trust<r> <d>names ...<r> run scripts for untrusted dependencies and add to `trustedDependencies`
<d>└<r> <cyan>--all<r> trust all untrusted dependencies
<b><green>bun pm<r> <blue>default-trusted<r> print the default trusted dependencies list

Learn more about these at <magenta>https://bun.com/docs/cli/pm<r>.
";
pretty_help(intro_text);
pretty_help(outro_text);
Output::flush();
}
Subcommand::Add => {
let intro_text = r"
Expand Down
46 changes: 5 additions & 41 deletions src/runtime/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1848,9 +1848,9 @@ pub mod command {
"The \"react\" template has been deprecated.\n\
It is recommended to use \"react-app\" or \"vite\" instead.\n\n\
To create a project using Create React App, run\n\n\
<d>bun create react-app<r>\n\n\
\x20 <d>bun create react-app<r>\n\n\
To create a React project using Vite, run\n\n\
<d>bun create vite<r>\n\n\
\x20 <d>bun create vite<r>\n\n\
Then select \"React\" from the list of frameworks.\n"
);
Global::exit(1);
Expand All @@ -1861,7 +1861,7 @@ Then select \"React\" from the list of frameworks.\n"
pretty_errorln!(
"<yellow>warn: No template <b>create-next<r> found.\n\
To create a project with the official Next.js scaffolding tool, run\n\
<b>bun create next-app <cyan>[destination]<r>"
\x20 <b>bun create next-app <cyan>[destination]<r>"
);
Global::exit(1);
}
Expand Down Expand Up @@ -2187,27 +2187,7 @@ Execute a shell script directly from Bun.
pm_print_help(PmSubcommand::Prune);
}
Tag::InfoCommand => {
pretty!(
"\
<b>Usage<r>: <b><green>bun info<r> <cyan>[flags]<r> <blue>\\<package\\><r><d>\\<@version\\><r> <blue>[property path]<r>
Display package metadata from the registry.

<b>Examples:<r>
<d>View basic information about a package<r>
<b><green>bun info<r> <blue>react<r>

<d>View specific version<r>
<b><green>bun info<r> <blue>react@18.0.0<r>

<d>View specific property<r>
<b><green>bun info<r> <blue>react<r> version
<b><green>bun info<r> <blue>react<r> dependencies
<b><green>bun info<r> <blue>react<r> versions

Full documentation is available at <magenta>https://bun.com/docs/cli/info<r>
"
);
Output::flush();
pm_print_help(PmSubcommand::Info);
}
Tag::WhyCommand => {
pretty!(
Expand Down Expand Up @@ -2265,23 +2245,7 @@ Full documentation is available at <magenta>https://bun.com/docs/cli/why<r>
Output::flush();
}
Tag::PackageManagerCommand => {
pretty!(
"\
<b>Usage<r>: <b><green>bun pm<r> <cyan>[flags]<r> <blue>[\\<command\\>]<r>
Run package manager utilities.

<b>Commands:<r>
<b><green>bun pm<r> <blue>bin<r> print the path to bin folder
<b><green>bun pm<r> <blue>ls<r> list the dependency tree according to the current lockfile
<b><green>bun pm<r> <blue>whoami<r> print the current npm username
<b><green>bun pm<r> <blue>hash<r> generate & print the hash of the current lockfile
<b><green>bun pm<r> <blue>cache<r> print the path to the cache folder
<b><green>bun pm<r> <blue>cache rm<r> clear the cache

Learn more about these at <magenta>https://bun.com/docs/cli/pm<r>
"
);
Output::flush();
pm_print_help(PmSubcommand::Pm);
}
_ => HelpCommand::print_with_reason(HelpCommand::Reason::Explicit, false),
}
Expand Down
74 changes: 1 addition & 73 deletions src/runtime/cli/package_manager_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,78 +161,6 @@ impl PackageManagerCommand {
subcommand
}

pub(crate) fn print_help() {
// the output of --help uses the following syntax highlighting
// template: <b>Usage<r>: <b><green>bun <command><r> <cyan>[flags]<r> <blue>[arguments]<r>
// use [foo] for multiple arguments or flags for foo.
// use <bar> to emphasize 'bar'

const INTRO_TEXT: &str = "\n\
<b>Usage<r>: <b><green>bun pm<r> <cyan>[flags]<r> <blue>[\\<command\\>]<r>\n\
\n\
Run package manager utilities.";

const OUTRO_TEXT: &str = "\n\
\n\
<b>Commands:<r>\n\
\n\
<b><green>bun pm<r> <blue>scan<r> scan all packages in lockfile for security vulnerabilities\n\
<b><green>bun pm<r> <blue>pack<r> create a tarball of the current workspace\n\
<d>├<r> <cyan>--dry-run<r> do everything except for writing the tarball to disk\n\
<d>├<r> <cyan>--destination<r> the directory the tarball will be saved in\n\
<d>├<r> <cyan>--filename<r> the name of the tarball\n\
<d>├<r> <cyan>--ignore-scripts<r> don't run pre/postpack and prepare scripts\n\
<d>├<r> <cyan>--gzip-level<r> specify a custom compression level for gzip (0-9, default is 9)\n\
<d>└<r> <cyan>--quiet<r> only output the tarball filename\n\
<b><green>bun pm<r> <blue>bin<r> print the path to bin folder\n\
<d>└<r> <cyan>-g<r> print the <b>global<r> path to bin folder\n\
<b><green>bun pm<r> <blue>ls<r> list the dependency tree according to the current lockfile\n\
<d>├<r> <cyan>--all<r> list the entire dependency tree according to the current lockfile\n\
<d>└<r> <cyan>--trusted<r> list only trusted dependencies\n\
<b><green>bun pm<r> <blue>why<r> <d>\\<pkg\\><r> show dependency tree explaining why a package is installed\n\
<b><green>bun pm<r> <blue>diff<r> <d>[a] [b]<r> show what changed between two versions of a package (or vs a folder/tarball)\n\
<d>├<r> <d>bun pm diff react<r> installed version → latest\n\
<d>├<r> <d>bun pm diff react@18.2.0 19.0.0<r>\n\
<d>├<r> <d>bun pm diff axios@1.6.0:lib 1.6.1<r> only files under lib/ <d>(also<r> <d>:file.js<r><d>, or paths after the two sides)<r>\n\
<d>├<r> <cyan>--stat<r>, <cyan>--name-only<r> summarize instead of printing hunks\n\
<d>├<r> <cyan>-U<r> <d>n<r> lines of context (default 3)\n\
<d>└<r> <cyan>--json<r> one JSON document (files, patch text, notes, totals)\n\
<b><green>bun pm<r> <blue>licenses<r> list installed packages grouped by license\n\
<d>├<r> <cyan>--json<r> output as JSON\n\
<d>├<r> <cyan>--prod<r> omit devDependencies\n\
<d>├<r> <cyan>--dev<r> list only what devDependencies pull in\n\
<d>├<r> <cyan>--long<r> also print author, description and homepage\n\
<d>└<r> <cyan>--filter<r> <d>\\<pattern\\><r> list only the matching workspaces' dependencies\n\
<b><green>bun pm<r> <blue>whoami<r> print the current npm username\n\
<b><green>bun pm<r> <blue>view<r> <d>name[@version]<r> view package metadata from the registry <d>(use `bun info` instead)<r>\n\
<b><green>bun pm<r> <blue>version<r> <d>[increment]<r> bump the version in package.json and create a git tag\n\
<d>└<r> <cyan>increment<r> patch, minor, major, prepatch, preminor, premajor, prerelease, from-git, or a specific version\n\
<b><green>bun pm<r> <blue>pkg<r> manage data in package.json\n\
<d>├<r> <cyan>get<r> <d>[key ...]<r>\n\
<d>├<r> <cyan>set<r> <d>key=value ...<r>\n\
<d>├<r> <cyan>delete<r> <d>key ...<r>\n\
<d>└<r> <cyan>fix<r> auto-correct common package.json errors\n\
<b><green>bun pm<r> <blue>hash<r> generate & print the hash of the current lockfile\n\
<b><green>bun pm<r> <blue>hash-string<r> print the string used to hash the lockfile\n\
<b><green>bun pm<r> <blue>hash-print<r> print the hash stored in the current lockfile\n\
<b><green>bun pm<r> <blue>cache<r> print the path to the cache folder\n\
<b><green>bun pm<r> <blue>cache rm<r> clear the cache\n\
<b><green>bun pm<r> <blue>migrate<r> migrate another package manager's lockfile without installing anything\n\
<b><green>bun pm<r> <blue>untrusted<r> print current untrusted dependencies with scripts\n\
<b><green>bun pm<r> <blue>trust<r> <d>names ...<r> run scripts for untrusted dependencies and add to `trustedDependencies`\n\
<d>└<r> <cyan>--all<r> trust all untrusted dependencies\n\
<b><green>bun pm<r> <blue>default-trusted<r> print the default trusted dependencies list\n\
\n\
Learn more about these at <magenta>https://bun.com/docs/cli/pm<r>.\n";

#[allow(clippy::disallowed_methods)]
// help-text consts contain <tag> markup that must be tag-walked
Output::pretty(format_args!("{}", INTRO_TEXT));
#[allow(clippy::disallowed_methods)]
Output::pretty(format_args!("{}", OUTRO_TEXT));
Output::flush();
}

pub(crate) fn exec(ctx: Command::Context) -> crate::Result<()> {
// `bun_core::argv()` includes argv[0]; skip it and collect into a
// borrowed-slice Vec so `&[&[u8]]` callers (TrustCommand/UntrustedCommand,
Expand Down Expand Up @@ -782,7 +710,7 @@ Learn more about these at <magenta>https://bun.com/docs/cli/pm<r>.\n";
Global::exit(0);
}

Self::print_help();
CommandLineArguments::print_help(Subcommand::Pm);

if !subcommand.is_empty() {
bun_core::pretty_errorln!(
Expand Down
Loading
Loading