Build: Pass `packageJson` as argument to event handlers

Created on 28 Oct 2020  路  4Comments  路  Source: netlify/build

Some plugins have needed to access the site's package.json content. Since this is a common use case, we should pass this information to plugin event handlers. Also, Netlify Build is already parsing the site's package.json, so there is no need to do it twice.

As a bonus, we can normalize the package.json fields using normalize-package-data (which is used by read-pkg-up), to prevent bugs in plugins due to package.json fields having several possible shapes.

We could pass this information as a packageJson argument. That argument would be an empty object if the site has no package.json.

This feature could directly benefit our Next.js plugin.

needs docs prononext-on-netlify-enterprise feature

All 4 comments

This makes sense to me. The CLI also reads the package.json https://github.com/netlify/cli/blob/9429642af5e425e58b8f26da6dab2eb9dab80052/src/detectors/utils/jsdetect.js#L19 so maybe we can apply the same logic there too.

Makes sense to me. Let's make sure to coordinate with @rstavchansky to make sure she has capacity for the associated docs change (admittedly small).

Yes, I should be able to work on the docs change for this.

Done at #2022.

Was this page helpful?
0 / 5 - 0 ratings