Skip to content

Commit

Permalink
fix: Fix moon query projects --affected hanging. (#629)
Browse files Browse the repository at this point in the history
* Fix stdin.

* Add checks.

* Bump version.
  • Loading branch information
milesj authored Feb 18, 2023
1 parent 2b2085b commit 9c2d79b
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 4 deletions.
9 changes: 9 additions & 0 deletions .yarn/versions/4b71d12a.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
releases:
"@moonrepo/cli": patch
"@moonrepo/core-linux-arm64-gnu": patch
"@moonrepo/core-linux-arm64-musl": patch
"@moonrepo/core-linux-x64-gnu": patch
"@moonrepo/core-linux-x64-musl": patch
"@moonrepo/core-macos-arm64": patch
"@moonrepo/core-macos-x64": patch
"@moonrepo/core-windows-x64-msvc": patch
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ moon_typescript_lang = { path = "../typescript/lang" }
moon_utils = { path = "../core/utils" }
moon_vcs = { path = "../core/vcs" }
moon_workspace = { path = "../core/workspace" }
atty = "0.2.14"
bytes = "1.4.0"
clap = { workspace = true, features = ["derive", "env", "wrap_help"] }
clap_complete = { workspace = true }
Expand Down
6 changes: 3 additions & 3 deletions crates/cli/src/commands/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub async fn projects(options: &QueryProjectsOptions) -> Result<(), AnyError> {
};

writeln!(stdout, "{}", serde_json::to_string_pretty(&result)?)?;
} else {
} else if !projects.is_empty() {
writeln!(
stdout,
"{}",
Expand Down Expand Up @@ -55,7 +55,7 @@ pub async fn touched_files(options: &mut QueryTouchedFilesOptions) -> Result<(),
};

writeln!(stdout, "{}", serde_json::to_string_pretty(&result)?)?;
} else {
} else if !files.is_empty() {
writeln!(
stdout,
"{}",
Expand Down Expand Up @@ -84,7 +84,7 @@ pub async fn tasks(options: &QueryProjectsOptions) -> Result<(), AnyError> {
};

writeln!(stdout, "{}", serde_json::to_string_pretty(&result)?)?;
} else {
} else if !projects.is_empty() {
for project in projects {
if project.tasks.is_empty() {
continue;
Expand Down
6 changes: 5 additions & 1 deletion crates/cli/src/queries/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ fn convert_to_regex(field: &str, value: &Option<String>) -> Result<Option<regex:
async fn load_touched_files(workspace: &Workspace) -> Result<TouchedFilePaths, WorkspaceError> {
let mut buffer = String::new();

stdin().read_to_string(&mut buffer).map_err(MoonError::Io)?;
// Only read piped data when stdin is not a TTY,
// otherwise the process will hang indefinitely waiting for EOF.
if atty::isnt(atty::Stream::Stdin) {
stdin().read_to_string(&mut buffer).map_err(MoonError::Io)?;
}

// If piped via stdin, parse and use it
if !buffer.is_empty() {
Expand Down
6 changes: 6 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

#### 🐞 Fixes

- Fixed an issue where `moon query projects --affected` would hang indefinitely waiting for stdin.

## 0.24.2

#### 🚀 Updates
Expand Down

0 comments on commit 9c2d79b

Please sign in to comment.