Skip to content

Commit e750e6c

Browse files
feat(ls): add package path to ls (#10079)
### Description Minor detail but sometimes I want to lookup where a package is located in the repo. ### Testing Instructions Existing `command-ls.t` test should work
1 parent 237b4b9 commit e750e6c

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

crates/turborepo-lib/src/commands/ls.rs

+12
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ struct PackageTask<'a> {
7979
struct PackageDetails<'a> {
8080
#[serde(skip)]
8181
color_config: ColorConfig,
82+
path: &'a AnchoredSystemPath,
8283
name: &'a str,
8384
tasks: Vec<PackageTask<'a>>,
8485
dependencies: Vec<&'a str>,
@@ -92,6 +93,7 @@ struct PackageDetailsList<'a> {
9293
#[derive(Serialize)]
9394
struct PackageDetailsDisplay<'a> {
9495
name: &'a str,
96+
path: &'a AnchoredSystemPath,
9597
tasks: ItemsWithCount<PackageTask<'a>>,
9698
dependencies: Vec<&'a str>,
9799
}
@@ -100,6 +102,7 @@ impl<'a> From<PackageDetails<'a>> for PackageDetailsDisplay<'a> {
100102
fn from(val: PackageDetails<'a>) -> Self {
101103
PackageDetailsDisplay {
102104
name: val.name,
105+
path: val.path,
103106
dependencies: val.dependencies,
104107
tasks: ItemsWithCount {
105108
count: val.tasks.len(),
@@ -232,6 +235,12 @@ impl<'a> PackageDetails<'a> {
232235
})?;
233236

234237
let transitive_dependencies = package_graph.transitive_closure(Some(&package_node));
238+
let package_path = package_graph
239+
.package_info(package_node.as_package_name())
240+
.ok_or_else(|| Error::PackageNotFound {
241+
package: package.to_string(),
242+
})?
243+
.package_path();
235244

236245
let mut package_dep_names: Vec<&str> = transitive_dependencies
237246
.into_iter()
@@ -245,6 +254,7 @@ impl<'a> PackageDetails<'a> {
245254

246255
Ok(Self {
247256
color_config,
257+
path: package_path,
248258
name: package,
249259
dependencies: package_dep_names,
250260
tasks: package_json
@@ -263,6 +273,8 @@ impl<'a> PackageDetails<'a> {
263273
} else {
264274
self.dependencies.join(", ")
265275
};
276+
277+
cprintln!(self.color_config, GREY, "{} ", self.path);
266278
println!(
267279
"{} {}: {}",
268280
name,

crates/turborepo/tests/snapshots/ls__basic_monorepo_get_info_for_package_`my-app`_([email protected]).snap

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ expression: query_output
66
"packages": [
77
{
88
"name": "my-app",
9+
"path": "apps/my-app",
910
"tasks": {
1011
"count": 2,
1112
"items": [

turborepo-tests/integration/tests/command-ls.t

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Run ls with filter
2121
Run ls on package `another`
2222
$ ${TURBO} ls another
2323
WARNING ls command is experimental and may change in the future
24+
packages[/\\]another (re)
2425
another depends on: <no packages>
2526
2627
tasks:
@@ -30,6 +31,7 @@ Run ls on package `another`
3031
Run ls on package `my-app`
3132
$ ${TURBO} ls my-app
3233
WARNING ls command is experimental and may change in the future
34+
apps[\/\\]my-app (re)
3335
my-app depends on: util
3436

3537
tasks:

0 commit comments

Comments
 (0)