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: determine duplicate function precedence based on extension #5623

Merged
merged 11 commits into from
Apr 13, 2023

Conversation

khendrikse
Copy link
Contributor

🎉 Thanks for submitting a pull request! 🎉

Summary

This again implements function precedence based on extension by reversing the functions array so it behaves similar to how production works. I also had to reverse the way our sourcedirectories are passed.


For us to review and ship your PR efficiently, please perform the following steps:

  • Open a bug/issue before writing your code 🧑‍💻. This ensures we can discuss the changes and get feedback from everyone that should be involved. If you`re fixing a typo or something that`s on fire 🔥 (e.g. incident related), you can skip this step.
  • Read the contribution guidelines 📖. This ensures your code follows our style guide and
    passes our tests.
  • Update or add tests (if any source code was changed or added) 🧪
  • Update or add documentation (if features were changed or added) 📝
  • Make sure the status checks below are successful ✅

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

@khendrikse khendrikse added the type: feature code contributing to the implementation of a feature and/or user facing functionality label Apr 13, 2023
@khendrikse khendrikse self-assigned this Apr 13, 2023
@github-actions
Copy link

github-actions bot commented Apr 13, 2023

📊 Benchmark results

Comparing with 17605fc

Package size: 313 MB

⬆️ 0.00% increase vs. 17605fc

^                                  306 MB  306 MB  306 MB  306 MB  313 MB  313 MB  313 MB  313 MB  313 MB 
│                          302 MB   ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐  
│ ──────────────────────────┌──┐────┼──┼────┼──┼────┼──┼────┼──┼────┼──┼────┼──┼────┼──┼────┼──┼────|▒▒|──
│  264 MB  271 MB  271 MB   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   ┌──┐    ┌──┐    ┌──┐    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
└───┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴──>
    T-12    T-11    T-10    T-9     T-8     T-7     T-6     T-5     T-4     T-3     T-2     T-1      T    
Legend

@khendrikse khendrikse marked this pull request as ready for review April 13, 2023 10:25
@khendrikse khendrikse requested a review from a team April 13, 2023 10:25
src/lib/functions/registry.mjs Outdated Show resolved Hide resolved
src/lib/functions/registry.mjs Outdated Show resolved Hide resolved
@@ -222,9 +222,9 @@ export const startFunctionsServer = async (options) => {
functionsDirectories.push(distPath)
}
} else {
// The order of the function directories matters. Leftmost directories take
// The order of the function directories matters. Rightmost directories take
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, this feels unrelated to the extension precedence. Is this a separate problem you've identified?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is actually related. In zip-it-and-ship-it we have defined that the rightmost directory takes precedence. Since me reversing the array in this PR is mimicking ZISI behavior, it meant that we had to also use that same logic here in the CLI.

Copy link
Member

Choose a reason for hiding this comment

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

But we're reversing the array of the functions that come out, not the list of directories going in?

(Sorry if I'm missing the point.)

Copy link
Contributor Author

@khendrikse khendrikse Apr 13, 2023

Choose a reason for hiding this comment

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

No worries! I'll try to explain it better.

Previously:

In the CLI we were passing the following to ZISI:
directories: [user-func-dir, internal-func-dir]

This meant that zisi returns a list of functions with the following precedence:

  • user-func-dir/hello.ts
  • user-func-dir/hello.js
  • internal-func-dir/hello.js

This is because ZISI will let functions from the rightmost directory take precedence. (fun fact: we pass the internal folder first in netlify/build as well)

That wasn't a problem before in the CLI, as we'd register the first function we'd encounter (in this case user-func-dir/hello.ts), making the user function take precedence, just like we do in netlify/build.

Currently

To make sure we get the same precedence as ZISI passes on to us, I reversed the functions array we got from ZISI before we register functions. But to also make sure that user functions take precedence like they did before, and like they do because of the way we pass the internal-func folder first in netlify/build, I also had to change the way we pass the sourcedirectories.

Otherwise we'd first register the internal-func-dir/hello.js

khendrikse and others added 2 commits April 13, 2023 14:18
Co-authored-by: Eduardo Bouças <mail@eduardoboucas.com>
Co-authored-by: Eduardo Bouças <mail@eduardoboucas.com>
@khendrikse khendrikse merged commit 169ecad into main Apr 13, 2023
@khendrikse khendrikse deleted the feat-461/set-function-precedence-based-on-extension branch April 13, 2023 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature code contributing to the implementation of a feature and/or user facing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants