Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/lib/functions/netlify-function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,23 @@ export default class NetlifyFunction<BuildResult extends BaseBuildResult> {
// main file.
public readonly srcPath: string

// Determines whether this is a background function based on the function
// name.
public readonly isBackground: boolean
// Determines whether this is a background function. Checks (in order):
// 1. ZISI build data — `invocationMode === 'background'` captures the
// filename suffix AND the in-source `config.background: true`.
// 2. The TOML config — `[functions.<name>] background = true`.
// 3. The filename suffix as a last-resort fallback (used pre-build and for
// non-ZISI runtimes like Go).
Comment on lines +67 to +72
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.

🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Remove explanatory behavior comments in this getter.

Line 67 to Line 72 adds descriptive comments about behavior in a TypeScript file; please remove these and keep intent in naming/structure.

Suggested diff
-  // Determines whether this is a background function. Checks (in order):
-  //  1. ZISI build data — `invocationMode === 'background'` captures the
-  //     filename suffix AND the in-source `config.background: true`.
-  //  2. The TOML config — `[functions.<name>] background = true`.
-  //  3. The filename suffix as a last-resort fallback (used pre-build and for
-  //     non-ZISI runtimes like Go).
   get isBackground(): boolean {

As per coding guidelines, **/*.{ts,tsx,js,jsx}: Never write comments on what the code does; make the code clean and self-explanatory instead.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Determines whether this is a background function. Checks (in order):
// 1. ZISI build data — `invocationMode === 'background'` captures the
// filename suffix AND the in-source `config.background: true`.
// 2. The TOML config — `[functions.<name>] background = true`.
// 3. The filename suffix as a last-resort fallback (used pre-build and for
// non-ZISI runtimes like Go).
get isBackground(): boolean {
🤖 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 `@src/lib/functions/netlify-function.ts` around lines 67 - 72, Remove the
multi-line explanatory comment above the getter that determines background
functions (the getter that checks ZISI build data / TOML config / filename
suffix — e.g., isBackground or isBackgroundFunction) so the implementation
stands self-explanatory; delete the 3-4 line descriptive block (the comment
describing the three checks) and rely on clear naming/structure instead, leaving
the getter code unchanged.

get isBackground(): boolean {
if (this.buildData?.invocationMode === 'background') {
return true
}

// @ts-expect-error TODO; Update the type and cut a new version of `@netlify/config`.
if (this.config.functions?.[this.name]?.background === true) {
return true
}
return this.name.endsWith(BACKGROUND)
}

private buildQueue?: Promise<BuildResult> | undefined
public buildData?: MappedOmit<BuildResult, 'includedFiles' | 'schedule' | 'srcFiles'> | undefined
Expand Down Expand Up @@ -123,8 +137,6 @@ export default class NetlifyFunction<BuildResult extends BaseBuildResult> {
this.settings = settings
this.srcPath = srcPath

this.isBackground = name.endsWith(BACKGROUND)

const functionConfig = config.functions?.[name]
// @ts-expect-error -- XXX(serhalp): fixed in stack PR (bumps to https://github.com/netlify/build/pull/6165)
this.schedule = functionConfig && functionConfig.schedule
Expand Down
1 change: 1 addition & 0 deletions src/lib/functions/runtimes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type BaseBuildResult = {
// TODO(serhalp): This module and type shouldn't know about these zisi types. Refactor to allow the JS runtime's zisi
// builder to define this on its extended base build result type.
excludedRoutes?: Route[] | undefined
invocationMode?: string | undefined
routes?: ExtendedRoute[] | undefined
runtimeAPIVersion?: number | undefined
}
Expand Down
3 changes: 3 additions & 0 deletions src/lib/functions/runtimes/js/builders/zisi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const require = createRequire(import.meta.url)
export type ZisiBuildResult = BaseBuildResult & {
buildPath: string
includedFiles: FunctionResult['includedFiles']
invocationMode: FunctionResult['invocationMode']
outputModuleFormat: FunctionResult['outputModuleFormat']
mainFile: FunctionResult['mainFile']
runtimeAPIVersion: FunctionResult['runtimeAPIVersion']
Expand Down Expand Up @@ -66,6 +67,7 @@ const buildFunction = async ({
excludedRoutes,
includedFiles,
inputs,
invocationMode,
mainFile,
outputModuleFormat,
path: functionPath,
Expand Down Expand Up @@ -103,6 +105,7 @@ const buildFunction = async ({
buildPath,
excludedRoutes,
includedFiles,
invocationMode,
outputModuleFormat,
mainFile,
routes,
Expand Down
13 changes: 12 additions & 1 deletion src/utils/deploy/hash-fns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,15 @@ const hashFns = async (
const fnConfig = functionZips
.filter((func) =>
Boolean(
func.displayName || func.generator || func.routes || func.buildData || func.priority || func.trafficRules,
func.displayName ||
func.generator ||
func.routes ||
func.buildData ||
func.priority ||
func.trafficRules ||
func.region ||
func.memory ||
func.vcpu,
),
)
.reduce(
Expand All @@ -197,10 +205,13 @@ const hashFns = async (
display_name: curr.displayName,
excluded_routes: curr.excludedRoutes,
generator: curr.generator,
memory: curr.memory,
region: curr.region,
routes: curr.routes,
build_data: curr.buildData,
priority: curr.priority,
traffic_rules: trafficRulesConfig(curr.trafficRules),
vcpu: curr.vcpu,
},
}),
{},
Expand Down
Loading