Skip to content

Commit

Permalink
Ensure long outputs are written to stdout before exiting process (#6359)
Browse files Browse the repository at this point in the history
* Ensure long outputs are written to stdout before exiting process

* Cleaning up old approach

* format

* formats changelog
  • Loading branch information
joehan authored Sep 12, 2023
1 parent ee093d9 commit 5d291fd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Released Firestore emulator v1.18.2.
- Removed nano precision in timestamp used in Firestore emulator (#5893)
- Fixed a bug where query behaves differently from production.
- Fixed an issue where very long command outputs would be cut off. (#3286)
1 change: 1 addition & 0 deletions scripts/clean-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function cleanup() {

trap cleanup EXIT

rm -rf ./clean || true
echo "Running clean-publish --without-publish, as we would before publishing to npm..."
npx clean-publish --without-publish --before-script ./scripts/clean-shrinkwrap.sh --temp-dir clean
echo "Ran clean-publish --without-publish."
Expand Down
50 changes: 28 additions & 22 deletions src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export class Command {
}

/**
* Registers the command with the client. This is used to inisially set up
* Registers the command with the client. This is used to initially set up
* all the commands and wraps their functionality with analytics and error
* handling.
* @param client the client object (from src/index.js).
Expand Down Expand Up @@ -190,16 +190,19 @@ export class Command {
runner(...args)
.then(async (result) => {
if (getInheritedOption(options, "json")) {
console.log(
JSON.stringify(
{
status: "success",
result: result,
},
null,
2
)
);
await new Promise((resolve) => {
process.stdout.write(
JSON.stringify(
{
status: "success",
result: result,
},
null,
2
),
resolve
);
});
}
const duration = Math.floor((process.uptime() - start) * 1000);
const trackSuccess = trackGA4("command_execution", {
Expand All @@ -226,16 +229,19 @@ export class Command {
})
.catch(async (err) => {
if (getInheritedOption(options, "json")) {
console.log(
JSON.stringify(
{
status: "error",
error: err.message,
},
null,
2
)
);
await new Promise((resolve) => {
process.stdout.write(
JSON.stringify(
{
status: "error",
error: err.message,
},
null,
2
),
resolve
);
});
}
const duration = Math.floor((process.uptime() - start) * 1000);
await withTimeout(
Expand Down Expand Up @@ -371,7 +377,7 @@ export class Command {
* @return an async function that executes the command.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
runner(): (...a: any[]) => Promise<void> {
runner(): (...a: any[]) => Promise<any> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return async (...args: any[]) => {
// Make sure the last argument is an object for options, add {} if none
Expand Down

0 comments on commit 5d291fd

Please sign in to comment.