feat(hooks): project persistent hooks#5597
Conversation
|
A very humble thank you 🙏 |
rigor789
left a comment
There was a problem hiding this comment.
Awesome PR, thanks!
One small suggestion is to use the second parameter for defaultValue when using getValue (typings may be off - missing the second param, I pushed a fix to them yesterday).
The other one is to scope the hooks array under the cli object. This one I'm not 100% sure about, but in #5596 we added the packageManager option under the cli scope since we plan to extend this to more options in the near future - and it's nice to group CLI overrides/function under a single key. However, hooks are arguably a CLI thing, but also tightly coupled to a project, so it may be fine to leave it at the root level.
Thoughts on this are welcome! (now that I typed this, I'm leaning towards a root hooks array like you've done - reverted my suggestion)
PR Checklist
What is the current behavior?
Because the hooks folder in a NS project is not meant to be checked into source, and is cleared with
ns clean, there is no easy way to have project persistent hooks aside from creating a local node_module plugin that registers the hook.What is the new behavior?
These changes enable specifying project hooks in the
nativescript.config.(ts|js)file and the cli will detect the configuration during hook events (before/after). I borrowed the same hook config syntax that plugins specify in their package.json for simplicity.Just add the following config to enable project persistent hooks for your app.
Fixes/Implements/Closes #5576.
There is greater discussion in this issue regarding a better way to organize plugin hooks, but I only attempted to just permit project persistent hooks within the current hook flow.