这是indexloc提供的服务,不要输入任何密码
Skip to content

feat(ls): add package path to ls #10079

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

Merged
merged 3 commits into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 12 additions & 0 deletions crates/turborepo-lib/src/commands/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ struct PackageTask<'a> {
struct PackageDetails<'a> {
#[serde(skip)]
color_config: ColorConfig,
path: &'a AnchoredSystemPath,
name: &'a str,
tasks: Vec<PackageTask<'a>>,
dependencies: Vec<&'a str>,
Expand All @@ -92,6 +93,7 @@ struct PackageDetailsList<'a> {
#[derive(Serialize)]
struct PackageDetailsDisplay<'a> {
name: &'a str,
path: &'a AnchoredSystemPath,
tasks: ItemsWithCount<PackageTask<'a>>,
dependencies: Vec<&'a str>,
}
Expand All @@ -100,6 +102,7 @@ impl<'a> From<PackageDetails<'a>> for PackageDetailsDisplay<'a> {
fn from(val: PackageDetails<'a>) -> Self {
PackageDetailsDisplay {
name: val.name,
path: val.path,
dependencies: val.dependencies,
tasks: ItemsWithCount {
count: val.tasks.len(),
Expand Down Expand Up @@ -232,6 +235,12 @@ impl<'a> PackageDetails<'a> {
})?;

let transitive_dependencies = package_graph.transitive_closure(Some(&package_node));
let package_path = package_graph
.package_info(package_node.as_package_name())
.ok_or_else(|| Error::PackageNotFound {
package: package.to_string(),
})?
.package_path();

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

Ok(Self {
color_config,
path: package_path,
name: package,
dependencies: package_dep_names,
tasks: package_json
Expand All @@ -263,6 +273,8 @@ impl<'a> PackageDetails<'a> {
} else {
self.dependencies.join(", ")
};

cprintln!(self.color_config, GREY, "{} ", self.path);
println!(
"{} {}: {}",
name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ expression: query_output
"packages": [
{
"name": "my-app",
"path": "apps/my-app",
"tasks": {
"count": 2,
"items": [
Expand Down
2 changes: 2 additions & 0 deletions turborepo-tests/integration/tests/command-ls.t
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Run ls with filter
Run ls on package `another`
$ ${TURBO} ls another
WARNING ls command is experimental and may change in the future
packages[/\\]another (re)
another depends on: <no packages>

tasks:
Expand All @@ -30,6 +31,7 @@ Run ls on package `another`
Run ls on package `my-app`
$ ${TURBO} ls my-app
WARNING ls command is experimental and may change in the future
apps[\/\\]my-app (re)
my-app depends on: util

tasks:
Expand Down
Loading