npm / npm/rfcs

[RRFC] Development lifecycle scripts (hooks)

Open
#460 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
777
Forks
267
PR merge metrics
No merged PRs in 30d

Description

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
  • Old RFC #34 exists but seems stalled
  • Alternative to #325
  • Related to #437
Other package managers

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No implementation files or tests are identified in the issue. Start by reviewing the Current Behaviour, Desired Behaviour, and referenced RFCs #34, #325, and #437; the work is complete when a specific lifecycle-hook design has been agreed and documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.