cli icon indicating copy to clipboard operation
cli copied to clipboard

feat(arborist)(reify): add an ability to add a hook

Open fritzy opened this issue 2 years ago • 0 comments

THIS PR HAS BEEN MIGRATED

Originally from https://github.com/npm/arborist/pull/342 Originally By @ylemkimon

This PR adds the ability to add a hook via options.hook. It adds a single hook options.hook[Symbol.for('beforeReify')](Arborist), that runs after this[_loadTrees]() but before this[_reifyPackages](options). Other hook can be added later, with backward compatability.

Sometimes in a project, there is a need to enforce some policies on dependencies used in the project or mutate the tree. However, npm or Arborist doesn't provide a way to hook into its process.

References

Related to https://github.com/npm/rfcs/issues/460

Other package managers

  • Yarn 1: undocumented hooks can wrap each step (https://github.com/yarnpkg/yarn/pull/7557)
  • Yarn 2: hooks can be added via a plugin (https://yarnpkg.com/advanced/plugin-tutorial#using-hooks)
  • pnpm: hooks can be added via configuration (https://pnpm.io/pnpmfile)

fritzy avatar Jan 19 '22 00:01 fritzy