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

fix(deps): bump execa to the latest version (5.x) #3440

Merged
merged 3 commits into from Aug 12, 2021
Merged

Conversation

JGAntunes
Copy link
Member

Which problem is this pull request solving?

Follow up of #3321, we can now bump execa to 5.x. see - https://github.com/sindresorhus/execa/releases. I figure @ehmicky probably has some useful input to give here 👀

Checklist

Please add a x inside each checkbox:

  • I have read the contribution guidelines.
  • The status checks are successful (continuous integration). Those can be seen below.

@JGAntunes JGAntunes requested a review from ehmicky August 12, 2021 14:09
Comment on lines 41 to 44
// The child process `error.message` includes stderr and stdout output which most of the times contains duplicate
// information. We rely on `error.shortMessage` instead.
error.message = error.shortMessage
Copy link
Member Author

Choose a reason for hiding this comment

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

Related with sindresorhus/execa#397 which I imagine you're familiar with @ehmicky 😅

Keeping the current behaviour resulted in extra output in our snapshots, usually with the same kind of information reproduced twice. Wondering what you think?

Copy link
Contributor

@ehmicky ehmicky Aug 12, 2021

Choose a reason for hiding this comment

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

Yes, this makes sense 👍
I answered below at #3440 (comment)

const { stdout } = execa.sync('git', args, { cwd: cwdA })
return stdout
// The child process `error.message` includes stderr and stdout output which most of the times contains duplicate
// information. We rely on `error.shortMessage` instead.
Copy link
Contributor

Choose a reason for hiding this comment

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

In this instance, wouldn't the git output be useful for debugging purpose?

Copy link
Member Author

Choose a reason for hiding this comment

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

The message we're getting contains the exact same input twice. Sharing the snippet so you can see:

## Git utils fails if no root

> Snapshot 1

    `␊
    ────────────────────────────────────────────────────────────────␊
      Netlify Build                                                 ␊
    ────────────────────────────────────────────────────────────────␊
    
    > Version␊
      @netlify/build 1.0.0␊
    
    > Flags␊
      debug: true␊
      repositoryRoot: /tmp-dir␊
      testOpts:␊
        pluginsListUrl: test␊
        silentLingeringProcesses: true␊
    
    > Current directory␊
      /tmp-dir␊
    
    > Config file␊
      /tmp-dir/netlify.toml␊
    
    > Resolved config␊
      build:␊
        publish: /tmp-dir␊
        publishOrigin: default␊
      plugins:␊
        - inputs: {}␊
          origin: config␊
          package: ./plugin␊
    
    > Context␊
      production␊
    
    > Loading plugins␊
       - ./plugin from netlify.toml␊
    
    ────────────────────────────────────────────────────────────────␊
      1. onPreBuild command from ./plugin                           ␊
    ────────────────────────────────────────────────────────────────␊
    
    
    ────────────────────────────────────────────────────────────────␊
      Plugin "./plugin" internal error                              ␊
    ────────────────────────────────────────────────────────────────␊
    
      Error message␊
      Error: Invalid head commit HEAD␊
      Command failed with exit code 128: git rev-parse HEAD␊
      fatal: not a git repository (or any of the parent directories): .git␊
      fatal: not a git repository (or any of the parent directories): .git␊
    
      Error location␊
      In "onPreBuild" event in "./plugin" from netlify.toml␊
    STACK TRACE␊
    
      Resolved config␊
      build:␊
        publish: /tmp-dir␊
        publishOrigin: default␊
      plugins:␊
        - inputs: {}␊
          origin: config␊
          package: ./plugin`

My understanding is that in order to keep the current behaviour we'll need to rely on shortMessage as the error message has the same input contained in stdout/stderr?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, yes. Makes sense 👍

@@ -38,6 +38,9 @@ const coreCommand = async function ({
handleBuildCommandOutput(buildCommandOutput, logs)
return {}
} catch (error) {
// The child process `error.message` includes stderr and stdout output which most of the times contains duplicate
// information. We rely on `error.shortMessage` instead.
Copy link
Contributor

@ehmicky ehmicky Aug 12, 2021

Choose a reason for hiding this comment

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

I am wondering whether we should mention instead that the build command stdout/stderr is:

  • Streamed in production, i.e. message === shortMessage then (since stdout/stderr cannot be directly buffered when streamed)
  • Buffered in logs in tests, but we already print logs so we don't need to re-print them

Copy link
Member Author

Choose a reason for hiding this comment

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

Is it a matter of streaming? 🤔 I just assumed this was related with the message field contents, which we always log(?). Anyway happy to rephrase the comment to something that makes more sense 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

In production (i.e. when buffer: false CLI flag is used), we use stdio: 'inherit' on the build command. This prevents Node.js child_process from being able to buffer stdout/stderr and as a consequence, error.message should not contain stdout/stderr and be equal to error.shortMessage.

In tests, we pass buffer: true so that logs are concatenated to a logs array instead of being printed on stdout/stderr. We also then pass stdio: 'pipe' on the build command, which allows buffering. At the end of each test, we print the contents of those logs. I.e. without error.shortMessage, we would end up printing the build command output twice.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah makes perfect sense, thanks for taking the time to explain it. I've updated the comment with what you've just shared in 75fbf28 🙌

@JGAntunes JGAntunes added automerge type: bug code to address defects in shipped code and removed automerge labels Aug 12, 2021
@JGAntunes JGAntunes merged commit 3e8bd01 into main Aug 12, 2021
@JGAntunes JGAntunes deleted the chore/update-execa branch August 12, 2021 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants