Skip to content
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

onSuccess & Watch Fix #1253

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

methompson
Copy link

@methompson methompson commented Nov 25, 2024

fixes #1245

Removed an await line for tinyexec-based binary executation command.
Watch commands would not trigger if an onSuccess command was provided.

…Watch commands would not trigger if an onSuccess command was provided.
Copy link

codesandbox bot commented Nov 25, 2024

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link

vercel bot commented Nov 25, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
tsup ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 2, 2024 4:02pm

@laat
Copy link

laat commented Nov 28, 2024

-                  await onSuccessProcess
-                  if (
-                    onSuccessProcess.exitCode &&
-                    onSuccessProcess.exitCode !== 0
-                  ) {
-                    process.exitCode = onSuccessProcess.exitCode
-                  }
+                  onSuccessProcess.process?.on('exit', (code) => {
+                    if (code && code !== 0) {
+                      process.exitCode = code
+                    }
+                  })

In stead of only removing the await we should probably reflect the behaviour it had before it broke.

@methompson
Copy link
Author

-                  await onSuccessProcess
-                  if (
-                    onSuccessProcess.exitCode &&
-                    onSuccessProcess.exitCode !== 0
-                  ) {
-                    process.exitCode = onSuccessProcess.exitCode
-                  }
+                  onSuccessProcess.process?.on('exit', (code) => {
+                    if (code && code !== 0) {
+                      process.exitCode = code
+                    }
+                  })

In stead of only removing the await we should probably reflect the behaviour it had before it broke.

I'd agree: unfortunately, it appears the previous commit wasn't quite as interested in doing the same: 4dd5bfe#diff-a2a171449d862fe29692ce031981047d7ab755ae7f84c707aef80701b3ea0c80

Note that the await statement was added. By removing it, we're getting closer to the original intention. Unfortunately, tinyexec does not appear to be using standard promises. When I attempted to add .catch to onSuccessProcess, I was confronted with an error indicating that it's not a function.

If we're to go back to previous functionality, we should probably move back to execa (or just use Node's built-in exec)

@laat
Copy link

laat commented Nov 28, 2024

when we do not await we will not capture the exit code ever. The .on('exit', ...) listener will capture the exit code as it was originally done with execa.

@methompson
Copy link
Author

when we do not await we will not capture the exit code ever. The .on('exit', ...) listener will capture the exit code as it was originally done with execa.

And when we do await, we completely break use of onSuccess. I think removing the await line is a good compromise of allowing onSuccess to function correctly before someone else figures out why tinyexec was used in the first place and either excising it in lieu of a better exec function (like Node's built in ChildProcess).

@methompson
Copy link
Author

methompson commented Dec 2, 2024

@laat I've revised the code in this PR to now show errors on save, while also retaining the onSuccess function and watch function.

I tested this in another project of mine where 8.3.5 did not function correctly. Watching/onSuccess worked as intended and errors were shown in the CLI.

@laat
Copy link

laat commented Dec 2, 2024

We should probably not produce promises that we do not catch or await (by way of a async processExitHandler), as this will very often lead to unhandledRejection errors resulting in the watch process exiting. It's unlikely in this scenario, but still a code smell to be avoided.

This is the proper fix #1256

@methompson
Copy link
Author

We should probably not produce promises that we do not catch or await (by way of a async processExitHandler), as this will very often lead to unhandledRejection errors resulting in the watch process exiting. It's unlikely in this scenario, but still a code smell to be avoided.

This is the proper fix #1256

The problem is that processExitHandler doesn't actually throw. It's a PromiseLike and has no catch function, only then.

@laat
Copy link

laat commented Dec 2, 2024

the processExitHandler result is a real promise. tinyexec is promiselike

@methompson
Copy link
Author

the processExitHandler result is a real promise. tinyexec is promiselike

if onSuccessProcess never throws, processExitHandler won't throw.

@laat
Copy link

laat commented Dec 2, 2024

if onSuccessProcess never throws, processExitHandler won't throw.

I've addressed this, read my comment again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Watch mode not working on v8.3.4 / v8.3.5
2 participants