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

docs: postinstall runs for any change #3428

Merged
merged 4 commits into from
Sep 16, 2021
Merged

Conversation

mrienstra
Copy link
Contributor

As per yarnpkg/yarn#8498 (comment)

I also tested locally ("packageManager": "yarn@3.0.2") and verified that postinstall runs in all of the following cases:

  • yarn add (new)
  • yarn remove
  • yarn add (upgrade existing)
  • yarn add (downgrade existing)
  • remove manually from package.json then run yarn
  • add manually to package.json then run yarn
  • upgrade manually in package.json then run yarn
  • downgrade manually in package.json then run yarn
  • yarn up (upgrade)

Also pondering adding a note about a potential "gotcha" someone may encounter when attempting to debug postinstall: output from echo is not shown. When running the script below:

"scripts": {
  "postinstall": "touch \"./postinstall_script_ran_$(date +\"%Y-%m-%d_%I-%M-%S-%p\")\" && echo 'postinstall script ran'"
},

... Running via yarn postinstall will echo "postinstall script ran" (and create a file), but when run as a side effect (e.g. yarn add foo), a file will be created but "postinstall script ran" is not shown (echo output).

@@ -15,7 +15,7 @@ Packages can define in the `scripts` field of their manifest various actions tha

- **prepublish** is called before `yarn npm publish` and similar commands (even before the package has been packed). This is the place where you'll want to check that the project is in an ok state. Because it's only called on prepublish, **the prepublish hook shouldn't have side effects.** In particular don't transpile the package sources in prepublish, as people consuming directly your repository (such as through the [`git:` protocol](/features/protocols#git)) wouldn't be able to use your project.

- **postinstall** is called after a package got successfully installed on the disk. It is guaranteed to be called in topological order (in other words, your dependencies' postinstalls will always run before yours). For backwards compatibility, **preinstall** and **install** are called as part of **postinstall**.
- **postinstall** is called whenever the dependency tree of your workspace changes -- e.g. when any package is added, removed or changed. It is guaranteed to be called in topological order (in other words, your dependencies' postinstalls will always run before yours). For backwards compatibility, **preinstall** and **install** are called as part of **postinstall**.
Copy link
Member

Choose a reason for hiding this comment

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

It's not limited to workspaces, if the dependency tree of a Package changes its postinstall will be run anew

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@merceyz: How about:

is called whenever a dependency tree within the project changes -- e.g. when any package is added, removed or changed.

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or just:

is called whenever a dependency changes -- e.g. when any package is added, removed or changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(Skimming https://yarnpkg.com/advanced/architecture for helpful language, but nothing is jumping out yet)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(Skimming https://yarnpkg.com/advanced/architecture for helpful language, but nothing is jumping out yet)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

is called after dependency tree changes are written to the disk -- e.g. after a package is added, removed or changed.

Based on https://yarnpkg.com/cli/install#details & https://yarnpkg.com/features/workspaces

@mrienstra mrienstra requested a review from merceyz September 13, 2021 23:36
@arcanis
Copy link
Member

arcanis commented Sep 16, 2021

I've slightly updated this text to make it clearer that this only affects individual subtrees (ie if you depend on foo and bar, updating bar won't cause the foo postinstall to trigger anew because its own dependency tree will remain the same).

@arcanis arcanis merged commit f2eb00d into yarnpkg:master Sep 16, 2021
@mrienstra mrienstra deleted the patch-2 branch September 16, 2021 22:55
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.

3 participants