Skip to content
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

feat: move excluded_patterns into function_config #274

Merged
merged 8 commits into from Jan 6, 2023

Conversation

Skn0tt
Copy link
Member

@Skn0tt Skn0tt commented Dec 28, 2022

Which problem is this pull request solving?

Accompanies https://github.com/netlify/stargate/pull/1343. We found that having excluded_patterns inside of routes doesn't cut it, so we're moving it into a new function_config field.

List other issues or pull requests related to this problem

node/bundler.test.ts Show resolved Hide resolved
@@ -24,6 +24,22 @@ const routesSchema = {
additionalProperties: false,
}

const functionConfigSchema = {
type: 'object',
required: ['excluded_patterns'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it required?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷 I don't remember. Removed it in 0fa20a9.

@Skn0tt Skn0tt marked this pull request as ready for review January 3, 2023 15:51
@Skn0tt Skn0tt requested a review from a team January 3, 2023 15:51
importMap,
layers = [],
}: GenerateManifestOptions) => {
const preCacheRoutes: Route[] = []
const postCacheRoutes: Route[] = []
const manifestFunctionConfig: Manifest['function_config'] = Object.fromEntries(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this means that there will be an entry in function_config for every function, even if the object is empty. Is that intended? Could we simply omit a function from the object if it doesn't have any configuration properties?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought the same when I wrote this first. Then I replaced it with 7c49753, found that to be too much indirection, and went back. Committed it again, let me know what you think ^^

@@ -44,13 +44,13 @@ export const getDeclarationsFromConfig = (
const paths = Array.isArray(config.path) ? config.path : [config.path]

paths.forEach((path) => {
declarations.push({ ...declaration, ...config, path })
declarations.push({ ...declaration, cache: config.cache, path })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand this bit. Why are we suddenly setting the cache property specifically rather than all of config? And does it mean that if we add more configuration properties to ISC, will we have to add them here in addition to config.ts?

Copy link
Member Author

@Skn0tt Skn0tt Jan 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is necessary because config now not only contains cache and path, but also excludedPatterns, which should not be part of the declaration. This means that we'll have to manually add all declaration-specific ISC properties here, yes.

Now that I think about it, should preCache / postCache be part of functions config as well? Are there cases where the same edge function sometimes should run before, and sometimes after cache? (this is out of scope for this PR)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is necessary because config now not only contains cache and path, but also excludedPatterns, which should not be part of the declaration.

I guess you could push to the declaration everything except excludedPatterns, which you know shouldn't be there. If we add more properties to ISC we wouldn't need to manually include them here?

Happy to defer to you though.

node/manifest.ts Outdated
importMap,
layers = [],
}: GenerateManifestOptions) => {
const preCacheRoutes: Route[] = []
const postCacheRoutes: Route[] = []
const manifestFunctionConfig: Manifest['function_config'] = {}

const getFunctionConfig = (name: string) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this a bit confusing. We have a nested function that mutates an object in the outer scope but its name says it's a getter.

If I understand this correctly, the goal of this function is to prime manifestFunctionConfig with blank entries that you can safely mutate? Perhaps it would be nicer to make this function explicitly about that, by both changing the name and removing the return value so that it's explicitly a setter.

Then further below you could access manifestFunctionConfig directly rather than the return value of getFunctionConfig?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried this out, and having a function called primeFunctionConfig also looked weird and added indirection. I tried a different approach where the config is filled up at the start, and then reduced before saving it: 520a241 How do you like that?

eduardoboucas
eduardoboucas previously approved these changes Jan 5, 2023
node/manifest.ts Outdated

for (const [name, functionConfig] of Object.entries(newConfig)) {
if (functionConfig.excluded_patterns.length === 0) {
delete newConfig[name]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally not a big fan of using delete here. I would rather start with an empty object for newConfig and then add the individual properties if excluded_patterns.length !== 0.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in 699a053

@Skn0tt Skn0tt merged commit 98ccb6f into main Jan 6, 2023
@Skn0tt Skn0tt deleted the excluded-patterns-new-manifest branch January 6, 2023 09:37
Skn0tt added a commit to netlify/build that referenced this pull request Apr 23, 2024
…er#274)

* feat: move excluded_patterns into function_config

* feat: isc-defined excluded_patterns

* feat: remove "excluded_patterns" from required fields

* feat: only write functionConfig for functions that need it

* refactor: sanitize function config before saving

* fix: use right object to build config map

* refactor: add instead of delete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants