[Feature] Lifecycle precompile hook to support package.json comments via external package #4342
Open
2 tasks done
Labels
enhancement
New feature or request
Describe the user story
I need to document our dependencies: why each is added, what it does, when it could be removed. I also need to document pinned versions: why is it pinned, and when can that change?
To do this, I'd like to add comments, which normal JSON does not support. Direct JSON5 support by yarn is not going to happen unless Node adds it, and Node is not going to add it.
I'd like to build a simple package that adds support for comments via JSON5. It would use a
package.json5
file, and compile that first topackage.json
before running the yarn command. I already have a very basic MVP in my project.What I've already found in my use of that MVP is that having to manually run a command to compile JSON5 -> JSON after every change is annoying, and it's easy to get confused and make mistakes. Ideally, there would be a way to automatically run this precompilation automatically before any yarn operation that reads package.json. Node maintainers have directly suggested that this is the best path forward.
There is no suitable lifecycle hook for such an operation. I've tried the
yarn prepack
hook, which seems the most common and fundamental, and that doesn't seem to run unless there are certain types of changes in thepackage.json
(I think?). Of course, with this JSON5 plugin, there won't be any changes topackage.json
until it's compiled.I know this approach wouldn't support
yarn add
, but since this is the only way I can get my dependencies documented, I'll have to take that loss. (If someone has a viable way to do this, though, I'd love to hear it!)Describe the solution you'd like
As above: a lifecycle hook that runs before any operation that relies on
package.json
-- and ideally one that I can link into as a plugin.Describe the drawbacks of your solution
Given there are already some lifecycle hooks, I'm guessing that the basic infrastructure/architecture for this is already in place. The main risk is that the hook may not be added to all the places where it's needed. To mitigate that, I'd be more than happy if the hooks were added for just install, update, and update-interactive to start. Could initial support be added as a limited, undocumented, beta feature? This would limit maintenance and I'd be happy to help flesh it out over time.
Describe alternatives you've considered
I've also considered writing a wrapper script that simply calls the compilation before proxying the command to yarn, but creating a wrapper of yarn for every single yarn command doesn't sound fun. And expecting people to use another executable over
yarn
would also be annoying and complicated.Could someone help me understand the capabilities of a contrib plugin? Would adding a lifecycle hook be possible in one? (My gut feel says "no," at least without adding some hard-to-maintain monkey patches.)
The text was updated successfully, but these errors were encountered: