Skip to content

feat!: update signature of zipFunctions #6524

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

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

Conversation

eduardoboucas
Copy link
Member

@eduardoboucas eduardoboucas commented Jul 4, 2025

Summary

In #6481 we made it possible for zipFunctions to receive both directory and file paths. The idea is that we could accept both directories of functions and individual functions, interchangeably.

This works for the most part, but becomes a bit challenging when the individual functions live in their own sub-directory.

For example, given the following tree:

my-functions/
  func1/
    index.js
    util.js

If I pass my-functions to zipFunctions, zip-it-and-ship-it will understand that func1 is a function in a sub-directory and will handle it correctly, which means naming the function func1 (not index) and understanding that util.js is a supporting file and not an entry file for another function.

This understanding breaks down if we pass my-functions/func1/index.js directly, because zip-it-and-ship-it has no way of knowing that the function is actually called func1, not index.

So this PR updates the signature of zipFunctions to accept an object (which I've called FunctionsBag) with two properties that separate the input into:

  • directories: Paths that can contain multiple functions (which in the tree above would be my-functions)
  • functions: Paths that point to individual functions, whether they live in their own sub-directory or not (which in the tree above would be my-functions/func-1)

zipFunctions continues to accept a string or array of strings as before, but I marked this as a breaking change because we no longer accept specific files on those strings. This was the change introduced in #6481, and even though no part of our system is relying on that yet, it's technically a breaking change so I'm doing a major bump.

Update

I'm rolling another breaking change into this PR by removing the internalSrcFolder parameter in favour of making the new FunctionsBag object accept user and generated top-level properties.

We currently have an issue where functions produced with the Frameworks API are not marked as generated (or internal, in zip-it-and-ship-it's terminology). This is because internalSrcFolder accepts one single directory, which is currently set by Netlify Build to .netlify/functions-internal.

With this change, Netlify Build sends an object that looks something like this:

{
  generated: {
    directories: [".netlify/functions-internal", ".netlify/v1/functions"],
    functions: [ ... functions generated by the `functions.generate` util ]
  },
  user: {
    directories: ["netlify/functions"]
  }
}

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

🐖

@eduardoboucas eduardoboucas requested a review from a team as a code owner July 4, 2025 09:47
@eduardoboucas eduardoboucas changed the title feat!: update signature zipFunctions feat!: update signature of zipFunctions Jul 4, 2025
Copy link
Contributor

github-actions bot commented Jul 4, 2025

This pull request adds or modifies JavaScript (.js, .cjs, .mjs) files.
Consider converting them to TypeScript.

@@ -71,11 +113,12 @@ export const zipFunctions = async function (
const logger = getLogger(systemLog, debug)
const cache = new RuntimeCache()
const featureFlags = getFlags(inputFeatureFlags)
const srcFolders = resolveFunctionsDirectories(relativeSrcFolders)
const bag = getFunctionsBag(input)
const srcFolders = resolveFunctionsDirectories(bag.directories)
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 use directories to go find functions.

const internalFunctionsPath = internalSrcFolder && resolve(internalSrcFolder)

const [paths] = await Promise.all([listFunctionsDirectories(srcFolders), fs.mkdir(destFolder, { recursive: true })])
const functions = await getFunctionsFromPaths(paths, {
const functions = await getFunctionsFromPaths([...paths, ...bag.functions], {
Copy link
Member Author

Choose a reason for hiding this comment

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

And we use functions to pass directly to getFunctionsFromPaths, which filters the paths that can actually be functions.

Copy link
Contributor

github-actions bot commented Jul 4, 2025

This pull request adds or modifies JavaScript (.js, .cjs, .mjs) files.
Consider converting them to TypeScript.

serhalp
serhalp previously approved these changes Jul 4, 2025
Copy link
Member

@serhalp serhalp left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

github-actions bot commented Jul 5, 2025

This pull request adds or modifies JavaScript (.js, .cjs, .mjs) files.
Consider converting them to TypeScript.

Copy link
Contributor

github-actions bot commented Jul 5, 2025

This pull request adds or modifies JavaScript (.js, .cjs, .mjs) files.
Consider converting them to TypeScript.

Copy link
Contributor

github-actions bot commented Jul 5, 2025

This pull request adds or modifies JavaScript (.js, .cjs, .mjs) files.
Consider converting them to TypeScript.

Copy link
Contributor

github-actions bot commented Jul 5, 2025

This pull request adds or modifies JavaScript (.js, .cjs, .mjs) files.
Consider converting them to TypeScript.

@eduardoboucas eduardoboucas requested a review from serhalp July 5, 2025 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants