Skip to content

feat: add new config properties to FunctionsObject#7079

Merged
eduardoboucas merged 1 commit into
mainfrom
feat/function-type-updates
May 29, 2026
Merged

feat: add new config properties to FunctionsObject#7079
eduardoboucas merged 1 commit into
mainfrom
feat/function-type-updates

Conversation

@eduardoboucas
Copy link
Copy Markdown
Member

Pairs with netlify/cli#8278.

@eduardoboucas eduardoboucas requested a review from a team as a code owner May 29, 2026 10:29
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 29, 2026

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

Release Notes

  • New Features
    • Expanded Netlify Functions configuration options with support for background execution mode, memory allocation, region selection, and vCPU settings, providing enhanced control over function deployment and resource management.

Walkthrough

This PR extends the FunctionsObject type in the build configuration to support four new optional Netlify Function configuration fields: background (boolean), memory (number or string), region (string), and vcpu (number). The change adds type definitions and inline documentation for these properties while preserving the existing included_files configuration.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

  • netlify/build#7067: Extends the public Functions type to add background?: boolean and related config fields like memory, region, and vcpu, directly matching this PR's type definition updates.
  • netlify/build#7064: Extends Netlify function configuration to support functions.*.memory and functions.*.region through config property allowlisting and runtime manifest updates alongside type definitions.

Suggested labels

Adds or modifies js files

Suggested reviewers

  • paulo
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request description is minimal and does not follow the provided template structure. It lacks required sections including summary, motivation, issue reference, and confirmation of testing and documentation updates. Expand the description to follow the template: include issue reference, explain motivation for the changes, confirm tests and documentation were updated, and verify status checks pass.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding new configuration properties to the FunctionsObject type. It is specific, concise, and clearly communicates the primary modification.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/function-type-updates

Comment @coderabbitai help to get the list of available commands and usage tips.

@eduardoboucas eduardoboucas enabled auto-merge (squash) May 29, 2026 10:32
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/build/src/types/config/functions.ts`:
- Around line 12-23: The exported FunctionsObject type currently defines
memory?: number|string and vcpu?: number independently (the existing & (...)
only constrains node_bundler), so TypeScript still allows both to be specified;
change the FunctionsObject export to encode mutual exclusivity between memory
and vcpu by replacing the single object with a union (or discriminated union)
that expresses either { memory?: number|string; vcpu?: never } or { vcpu?:
number; memory?: never } and then intersect/merge that union with the existing
common properties (including the node_bundler & (...) constraint) so the type
system rejects objects that include both memory and vcpu simultaneously.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c2d53a77-c775-43da-b2a7-088d1c7f1ec3

📥 Commits

Reviewing files that changed from the base of the PR and between 42d439a and 1763621.

📒 Files selected for processing (1)
  • packages/build/src/types/config/functions.ts

Comment on lines +12 to +23
/**
* the amount of memory allocated to the function, expressed either as a number of MB or as a string with a unit (e.g. `"2gb"`). Mutually exclusive with `vcpu`.
*/
memory?: number | string
/**
* the [region](https://docs.netlify.com/functions/optional-configuration/#region) the function should run in, identified by its airport code (e.g. `"cmh"`).
*/
region?: string
/**
* the number of vCPUs allocated to the function (between `0.5` and `2`). Mutually exclusive with `memory`.
*/
vcpu?: number
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify whether runtime/schema validation already enforces memory/vcpu exclusivity.
# Expected: either an explicit exclusivity rule exists, or this type should enforce it.

rg -n --type=ts -C3 '\b(memory|vcpu)\b'
rg -n --type=ts -C3 'mutual|exclusive|oneOf|xor|cannot.*(memory|vcpu)|invalid.*(memory|vcpu)'

Repository: netlify/build

Length of output: 35759


🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE="packages/build/src/types/config/functions.ts"

echo "== File: $FILE (lines 1-120) =="
nl -ba "$FILE" | sed -n '1,120p'

echo
echo "== Lines containing memory/vcpu in $FILE =="
rg -n '\b(memory|vcpu)\b' "$FILE" || true

echo
echo "== Any XOR/xor/mutual/exclusive/oneOf patterns in $FILE =="
rg -n 'mutual|exclusive|oneOf|xor|cannot.*(memory|vcpu)|invalid.*(memory|vcpu)' "$FILE" || true

Repository: netlify/build

Length of output: 189


🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE="packages/build/src/types/config/functions.ts"

echo "== File: $FILE (first 180 lines) =="
cat -n "$FILE" | sed -n '1,180p'

echo
echo "== Lines containing memory/vcpu in $FILE =="
rg -n '\b(memory|vcpu)\b' "$FILE" || true

echo
echo "== Any XOR/mutual/exclusive/oneOf patterns in $FILE =="
rg -n 'mutual|exclusive|oneOf|xor|cannot.*(memory|vcpu)|invalid.*(memory|vcpu)' "$FILE" || true

echo
echo "== Dump FunctionsObject block (best-effort) =="
# Print from FunctionsObject until the next top-level export/type ends (heuristic)
awk '
  $0 ~ /export (type|interface) FunctionsObject/ {inblk=1}
  inblk {print}
  inblk && NR>1 && $0 ~ /^}/ {# may end early; still ok
    # stop after a few lines past closing brace if we detect it
  }
' "$FILE" | sed -n '1,220p'

Repository: netlify/build

Length of output: 3527


Enforce memory/vcpu mutual exclusivity in FunctionsObject’s exported type

packages/build/src/types/config/functions.ts defines memory?: number | string and vcpu?: number as independent optional fields, while the existing & ( ... ) only constrains node_bundler—so the exported FunctionsObject type still allows both at once (even though the docs claim they’re mutually exclusive). Runtime validation appears to reject the invalid combination, but the TS contract remains too weak.

💡 Suggested type-level fix
 type FunctionsObject = {
@@
-  /**
-   * the amount of memory allocated to the function, expressed either as a number of MB or as a string with a unit (e.g. `"2gb"`). Mutually exclusive with `vcpu`.
-   */
-  memory?: number | string
@@
-  /**
-   * the number of vCPUs allocated to the function (between `0.5` and `2`). Mutually exclusive with `memory`.
-   */
-  vcpu?: number
-} & (
+} & (
+  | {
+      /**
+       * the amount of memory allocated to the function, expressed either as a number of MB or as a string with a unit (e.g. `"2gb"`). Mutually exclusive with `vcpu`.
+       */
+      memory?: number | string
+      vcpu?: never
+    }
+  | {
+      memory?: never
+      /**
+       * the number of vCPUs allocated to the function (between `0.5` and `2`). Mutually exclusive with `memory`.
+       */
+      vcpu?: number
+    }
+  | {
+      memory?: undefined
+      vcpu?: undefined
+    }
+) & (
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/build/src/types/config/functions.ts` around lines 12 - 23, The
exported FunctionsObject type currently defines memory?: number|string and
vcpu?: number independently (the existing & (...) only constrains node_bundler),
so TypeScript still allows both to be specified; change the FunctionsObject
export to encode mutual exclusivity between memory and vcpu by replacing the
single object with a union (or discriminated union) that expresses either {
memory?: number|string; vcpu?: never } or { vcpu?: number; memory?: never } and
then intersect/merge that union with the existing common properties (including
the node_bundler & (...) constraint) so the type system rejects objects that
include both memory and vcpu simultaneously.

@eduardoboucas eduardoboucas merged commit 9bfb608 into main May 29, 2026
31 checks passed
@eduardoboucas eduardoboucas deleted the feat/function-type-updates branch May 29, 2026 10:40
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.

2 participants