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: return non 0 exit code if an error occurred #774

Closed
wants to merge 2 commits into from

Conversation

andreialecu
Copy link

Was originally fixed in #633 but it doesn't seem to have survived the update to v5.

Non 0 exit code is required, otherwise Yarn 2 users may not see what went wrong.

@typicode
Copy link
Owner

Hi,

Thanks for the PR. Not sure it's still needed.

// index.js
throw new Error('foo')
{
 "scripts": {
    "postinstall": "node index.js"
  }
}
❯ yarn -v && yarn run postinstall
2.3.3
/tmp/test/index.js:1
throw new Error('foo')
^

Error: foo
    at Object.<anonymous> (/tmp/test/index.js:1:7)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.external_module_.Module._load (/tmp/test/.pnp.js:4738:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47

That said, I think that Yarn v2 doesn't run automatically "postinstall", you can check with "postinstall": "touch foo".

@andreialecu
Copy link
Author

andreialecu commented Oct 17, 2020

Yarn 2 does run postinstall but only when changes are detected, and it suppresses the output by default.

Try CI=true yarn rebuild and you can test it with

{
 "scripts": {
    "postinstall": "echo hello"
  }
}

Regarding why the PR is needed. It runs postinstall on yarn install, but it will not report any error unless you run it manually like in your example.

Note for Yarn 2 users postinstall won't run automatically, please run yarn run postinstall manually to enable hooks.

This mention in the documentation is not accurate, considering the above.

@typicode
Copy link
Owner

typicode commented Nov 5, 2020

Yarn 2 does run postinstall but only when changes are detected, and it suppresses the output by default.

Thanks for the explanation, I've updated docs.

@typicode
Copy link
Owner

Closing as I think it's redundant, node index.js in the example above already exits with 1. But thanks for spotting the issue in the docs.

@typicode typicode closed this Nov 11, 2020
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.

None yet

2 participants