npm / rfcs

Public change requests/proposals & ideation
Other
727 stars 238 forks source link

[RRFC] Development lifecycle scripts (hooks) #460

Open ylemkimon opened 3 years ago

ylemkimon commented 3 years ago

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:

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

Desired Behaviour

References

Other package managers

everett1992 commented 2 years ago

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