feat: add new config properties to FunctionsObject#7079
Conversation
📝 WalkthroughSummary by CodeRabbitRelease Notes
WalkthroughThis PR extends the Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (1)
packages/build/src/types/config/functions.ts
| /** | ||
| * 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 |
There was a problem hiding this comment.
🧩 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" || trueRepository: 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.
Pairs with netlify/cli#8278.