-
Notifications
You must be signed in to change notification settings - Fork 448
feat: log output to stderr on deploy --json --verbose
#8090
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -716,6 +716,19 @@ const handleBuild = async ({ | |||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const { configMutations, exitCode, newConfig, logs } = await runBuild(resolvedOptions) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // When --verbose is used with --json, pipe the build's stdout and stderr | ||||||||||||||||||||||||||||||||||
| // to the process stderr so that callers can see the full build output | ||||||||||||||||||||||||||||||||||
| // while still getting clean JSON on stdout. | ||||||||||||||||||||||||||||||||||
| if (options.verbose && options.json && logs) { | ||||||||||||||||||||||||||||||||||
| if (logs.stdout.length) { | ||||||||||||||||||||||||||||||||||
| process.stderr.write(logs.stdout.join('\n')) | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| if (logs.stderr.length) { | ||||||||||||||||||||||||||||||||||
| process.stderr.write(logs.stderr.join('\n')) | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+723
to
+730
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🌐 Web query:
💡 Result: The Citations:
🏁 Script executed: # First, let's check if the file exists and its size
wc -l src/commands/deploy/deploy.tsRepository: netlify/cli Length of output: 89 🏁 Script executed: # Read the specific section mentioned in the review (lines 715-745 for context)
sed -n '715,745p' src/commands/deploy/deploy.ts | cat -nRepository: netlify/cli Length of output: 1149 🏁 Script executed: # Look for the Logs type import and definition
rg "import.*Logs|type Logs|interface Logs" src/commands/deploy/deploy.ts -A 3 -B 3Repository: netlify/cli Length of output: 37 🏁 Script executed: # Check what `@netlify/build` exports for Logs type
rg "export.*Logs" --type ts --type tsxRepository: netlify/cli Length of output: 82 🏁 Script executed: # Search for runBuild function and Logs type definition
rg "runBuild|type Logs|interface Logs" src/commands/deploy/deploy.ts -B 2 -A 2Repository: netlify/cli Length of output: 1188 🏁 Script executed: # Look for imports in the file
head -50 src/commands/deploy/deploy.ts | grep -E "^import|^from"Repository: netlify/cli Length of output: 1745 🏁 Script executed: # Search for Logs type across the codebase
fd -e ts -e tsx . src | xargs rg "type Logs|interface Logs" -A 5 | head -50Repository: netlify/cli Length of output: 471 🏁 Script executed: # Now let's check the Logs type definition in src/lib/build.ts
sed -n '1,30p' src/lib/build.ts | cat -nRepository: netlify/cli Length of output: 1313 🏁 Script executed: # Check the actual Logs type from `@netlify/build` by examining how it's used elsewhere
rg "logs\." src/lib/build.ts -B 2 -A 2Repository: netlify/cli Length of output: 37 🏁 Script executed: # Look at the runBuild return type
rg "function runBuild|export.*runBuild" src/lib/build.ts -A 10Repository: netlify/cli Length of output: 430 🏁 Script executed: # Let's get more context on the Logs type usage and understand the pattern better
rg "logs\?" src/commands/deploy/deploy.ts -B 1 -A 1Repository: netlify/cli Length of output: 229 🏁 Script executed: # Check if there's type definition or any hints about stdout/stderr optionality
rg "stdout|stderr" src/lib/build.ts -B 2 -A 2 | head -40Repository: netlify/cli Length of output: 237 🏁 Script executed: # Get more precise line numbers for the exact code snippet
grep -n "When --verbose is used with --json" src/commands/deploy/deploy.tsRepository: netlify/cli Length of output: 134 🏁 Script executed: # Get the exact lines around the code in question
sed -n '715,750p' src/commands/deploy/deploy.ts | cat -nRepository: netlify/cli Length of output: 1370 Add optional chaining to The code at lines 736 and 740 uses optional chaining ( 🛡️ Proposed fix if (options.verbose && options.json && logs) {
- if (logs.stdout.length) {
+ if (logs.stdout?.length) {
process.stderr.write(logs.stdout.join('\n'))
}
- if (logs.stderr.length) {
+ if (logs.stderr?.length) {
process.stderr.write(logs.stderr.join('\n'))
}
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // Without this, the deploy command fails silently | ||||||||||||||||||||||||||||||||||
| if (exitCode !== 0) { | ||||||||||||||||||||||||||||||||||
| let message = '' | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
Remove explanatory comment per coding guidelines.
The comment describes what the code does rather than why. The function and flag names are self-documenting. As per coding guidelines: "Never write comments on what the code does; make the code clean and self-explanatory instead."
♻️ Proposed fix
const { configMutations, exitCode, newConfig, logs } = await runBuild(resolvedOptions) - // When --verbose is used with --json, pipe the build's stdout and stderr - // to the process stderr so that callers can see the full build output - // while still getting clean JSON on stdout. if (options.verbose && options.json && logs) {🤖 Prompt for AI Agents