-
Notifications
You must be signed in to change notification settings - Fork 70
feat: add functions configuration API to @netlify/config #2390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -149,6 +156,22 @@ const POST_NORMALIZE_VALIDATIONS = [ | |||
...insideRootCheck, | |||
example: (edgeHandlers) => ({ build: { edge_handlers: removeParentDots(edgeHandlers) } }), | |||
}, | |||
{ | |||
property: 'functions.*.externalModules', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add a "pre-normalize" validation to ensure that functions.{key}
is an plain object?
(except when key
is either externalModules
or ignoredModules
, where it can also be an array of strings)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we do this, I think we'll end up duplicating validation logic for each key in two places: once in this pre-normalisation step, and the other for the individual keys after normalisation.
If you do specify a functions.{key}
that is not a plain object, it'll be inferred as a configuration property of the top-level object, which is valid syntax. If the goal is to prevent unknown configuration keys (e.g. something other than externalModules
or ignoredModules
), wouldn't it be better to do it after normalisation, so that we can validate both the top-level and function-level objects?
I did consider this, but my understanding is that we allow unknown properties to get through elsewhere in the application?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about doing it in the post-normalization steps, checking that any functions.*
is a plain object?
The downside of doing it in the post-normalization is that the normalization logic would not be able to rely on the assumption that functions.*
is a plain object. However, it looks like the current normalization logic would work without that assumption.
The main reason would be to validate against users using something like:
[functions]
my_function = "/functions/my_function.js"
Syntax like this might break @netlify/config
because of the assumption that functions.*
is a plain object. For example, the functions.*.js_external_modules
validation might rely on that assumption.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good point! I've done it in the post-normalisation step and, as you say, it works fine. I've added a test for the specific example you shared. It's in 7e33c07.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Let me know if that looks okay to you.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good! 👍
In 91b6138 I've updated the property names, so that We're now using snake case, in line with other configuration properties, and we're prefixing the properties with |
It just occurred to me that since we're introducing support for TypeScript, the Would (cc @verythorough) |
Considering the term |
That feels more human-friendly, for sure! I'm okay with that if everyone else is. |
Which problem is this pull request solving?
This PR adds an initial implementation of the functions configuration API, including support for two properties:
js_external_modules
andignoredModules
.These can be defined at the top-level [1], target a specific function by name [2], or target multiple functions by name with a glob [3].
@netlify/config
is responsible for reading these values and normalising them. The configuration above will be returned as following:It is then up to the consumers, like
zip-it-and-ship-it
, to apply the globs to a list of functions and apply the configuration parameters accordingly.Checklist
Please add a
x
inside each checkbox: