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

[RRFC] Development lifecycle scripts (hooks) #460

Open
ylemkimon opened this issue Sep 17, 2021 · 1 comment
Open

[RRFC] Development lifecycle scripts (hooks) #460

ylemkimon opened this issue Sep 17, 2021 · 1 comment

Comments

@ylemkimon
Copy link

ylemkimon commented Sep 17, 2021

Motivation ("The Why")

Sometimes in a project, there is a need to setup the development environment or enforce some policies on dependencies used in the project. However, npm doesn't provide a way to hook into its process and lifecycle scripts such as postinstall are (ab)used:

  • husky uses postinstall to autoinstall Git hooks and pinst to disable them in the production
  • postinstall-postinstall runs the app's postinstall script during its postinstall script
  • TBA

Furthermore, there is no way to run a script if the dependency tree of the pakcage has changed, i.e., a dependency is added or removed.

Example

As mentioned above, it can be used to setup the development environment or enforce some policies on dependencies used in the project.

How

Current Behaviour

  • postinstall script runs after npm install, but also runs when the package is installed as a dependency
  • prepare script runs after npm install, but also before the pakcage is packed
  • Both scripts don't run when the dependency tree is changed and there is no way to trigger a script in this case

Desired Behaviour

  • A new lifecycle, such as preinstalldep and postinstalldep
  • or, hook scripts that run before and after the dependency tree has changed (reify)

References

Other package managers

@everett1992
Copy link

everett1992 commented Nov 3, 2021

A post-reify script would be useful. We try to run a script to remove the resolved key from package-lock after any modifications because we build packages against different registries. We have some wrappers that 'know' which npm commands update the lock file, but if the wrapper is wrong or not used the lock file ends up in a dirty state. #486

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

No branches or pull requests

2 participants