1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//! `aube bin` — print the path to `node_modules/.bin`.
//!
//! Mirrors `pnpm bin` / `npm bin`. Shell scripts use it to extend `$PATH`
//! (`export PATH="$(aube bin):$PATH"`). No filesystem mutation, no network,
//! and the directory doesn't have to exist yet — we just print the path.
//!
//! With `--global` / `-g`, prints the *global* bin directory (the one a
//! user is expected to have on `$PATH` so globally-installed packages are
//! callable). See [`super::global`] for the layout.
pub const AFTER_LONG_HELP: &str = "\
Examples:
$ aube bin
/home/user/project/node_modules/.bin
$ aube bin -g
/home/user/.local/share/aube/global/node_modules/.bin
# From a workspace package, -w prints the workspace-root bin directory
$ cd packages/app
$ aube bin
/home/user/project/packages/app/node_modules/.bin
$ aube bin -w
/home/user/project/node_modules/.bin
# Extend PATH with the project bin directory
$ export PATH=\"$(aube bin):$PATH\"
";
#[derive(Debug, usage_rs::Args)]
pub struct BinArgs {
/// Print the global bin directory instead of the project's
#[usage(short, long, conflicts = "--workspace-root")]
pub global: bool,
/// Print the workspace-root bin directory instead of the current
/// package's.
///
/// Mirrors `pnpm bin -w`: from a sub-package, resolves the enclosing
/// workspace root and prints its `node_modules/.bin`. No-op when no
/// workspace root exists above cwd (single-project install), so the
/// flag is safe to leave in shell aliases.
#[usage(short = 'w', long = "workspace-root", long = "workspace")]
pub workspace_root: bool,
}
pub async fn run(args: BinArgs) -> miette::Result<()> {
if args.global {
let layout = super::global::GlobalLayout::resolve()?;
println!("{}", layout.bin_dir.display());
return Ok(());
}
let mut cwd = crate::dirs::project_root_or_cwd()?;
if args.workspace_root
&& let Some(root) = crate::dirs::find_workspace_root(&cwd)
{
cwd = root;
}
println!(
"{}",
super::project_modules_dir(&cwd).join(".bin").display()
);
Ok(())
}