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

[dependencies-replacement] Replace spawndamnit with tinyexec (8 fewer dependencies) #224

Merged
merged 1 commit into from
Oct 16, 2024

Conversation

VanTanev
Copy link
Contributor

@VanTanev VanTanev commented Oct 13, 2024

First PR addressing #221.

https://github.com/tinylibs/tinyexec is used by vitest, so it should be a fairy safe bet.

Copy link

changeset-bot bot commented Oct 13, 2024

🦋 Changeset detected

Latest commit: d9d1649

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@manypkg/cli Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@VanTanev VanTanev force-pushed the dependencies-replace-spawndamnit branch 5 times, most recently from 5ea95de to 09ddfc8 Compare October 14, 2024 15:32
let { code } = await spawn(args[0], args.slice(1), {
cwd: pkg.dir,
stdio: "inherit",
const proc = exec(args[0], args.slice(1), {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could u refactor the touched lines to this style (when possible)?

Suggested change
const proc = exec(args[0], args.slice(1), {
const { exitCode } = await exec(args[0], args.slice(1), {

or at least to this if the .exitCode! is problematic:

Suggested change
const proc = exec(args[0], args.slice(1), {
const result = await exec(args[0], args.slice(1), {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, the exec() constructor and the return type of the await proc are different types.

const proc = exec() is an object that holds a "prepared execution" that you can attach streams/events/whatever on. It is also .then()-able, but that returns a different object...
const result = await proc is a Result type that only has stdout and stderr. It doesn't have exitCode (though I think it really should, there is an issue upstream, will see if I can open a PR for it).

The proc.exictCode! should be correct, because exitCode should always be set if we have awaited the proc.

As weird as the code looks right now, it is the only way to write it as far as I can see.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's wait a little bit then before landing this. It would be great if exitCode thing would be improved upstream.

Copy link
Contributor Author

@VanTanev VanTanev Oct 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I was holding it wrong!

When the process has an non-zero exit code, an exception is thrown.

This means that if we don't read stdout/stderr, we can just do:

    await exec("yarn", args.slice(1), {
      nodeOptions: {
        cwd: matchingPackages[0].dir,
        stdio: "inherit",
      },
    });

And we can completely remove the ExitError class, as tinyexec throws its own NonZeroExitError.

I'll update the PR and ping you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merged the upstream change in tinyexec: tinylibs/tinyexec#38

The PR is now good for re-review.

@VanTanev VanTanev force-pushed the dependencies-replace-spawndamnit branch 3 times, most recently from 0d6ed8e to d9d1649 Compare October 16, 2024 08:51
});
highestExitCode = Math.max(code, highestExitCode);
highestExitCode = Math.max(exitCode ?? 1, highestExitCode);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need to treat a nullish exitCode as a failure here?

Copy link
Contributor Author

@VanTanev VanTanev Oct 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per node:child_proccess.spawn(), exitCode can be nullish in 2 cases:

  • The process failed to spawn.
  • The process was externally killed.

For our purpose, both of these mean that the underlying process never executed successfully, so we should treat a missing exit code as an error.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😍

@Andarist Andarist merged commit 3c3198a into Thinkmill:main Oct 16, 2024
4 checks passed
This was referenced Oct 14, 2024
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.

2 participants