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

fix: omit duplicates from list of bundled functions #3795

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

eduardoboucas
Copy link
Member

Summary

When printing the list of bundled functions, Netlify Build uses zip-it-and-ship-it's listFunctions method, which includes functions that have not been bundled due to a naming conflict (e.g. when both function.js and function.ts are found). Because of this, Netlify Build was incorrectly reporting that both functions were bundled, when in fact only function.js was.

This PR removes those duplicate functions from the list.

Fixes #3974.

A picture of a cute animal (not mandatory, but encouraged)

110918_n13-baby-sloth-brevard-zoo

@eduardoboucas eduardoboucas added the type: bug code to address defects in shipped code label Nov 1, 2021
@@ -21,7 +21,10 @@ const getRelativeFunctionMainFiles = async function ({ featureFlags, functionsSr

const zisiFeatureFlags = getZisiFeatureFlags(featureFlags)
const functions = await listFunctions(functionsSrc, { featureFlags: zisiFeatureFlags })
return functions.map(({ mainFile }) => relative(functionsSrc, mainFile))
const dedupedFunctions = new Map(functions.map((func) => [func.name, func]))
Copy link
Contributor

Choose a reason for hiding this comment

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

Just wondering, any reason you are not going with Set? Set ensures no duplicates exist by design :)

Copy link
Member Author

Choose a reason for hiding this comment

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

We might have different functions with the same name. By passing an array of entries to Map, we guarantee that the last function with the same name takes precedence, which is the order in which zip-it-and-ship-it outputs the files.

Does that answer the question?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, thanks for the explanation :)

@ehmicky
Copy link
Contributor

ehmicky commented Mar 2, 2022

@eduardoboucas What's the latest status of this PR? Should it be closed?

@eduardoboucas
Copy link
Member Author

Sorry, my bad. This fell between the cracks. I'm updating the branch and will merge this later today.

@github-actions github-actions bot added the stale label Dec 17, 2022
@eduardoboucas eduardoboucas requested review from a team as code owners April 23, 2024 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants