Skip to content

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.

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 [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
Copy link
Contributor

github-actions bot commented Jul 7, 2025

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

@eduardoboucas eduardoboucas enabled auto-merge (squash) July 7, 2025 09:48
@eduardoboucas eduardoboucas merged commit f719b07 into main Jul 7, 2025
61 of 62 checks passed
@eduardoboucas eduardoboucas deleted the feat/zisi-functions-bag branch July 7, 2025 10:06
This was referenced Sep 2, 2025
This was referenced Sep 24, 2025
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