Skip to content
Open
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
6 changes: 6 additions & 0 deletions eslint_temporary_suppressions.js
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,12 @@ export default [
'n/no-missing-import': 'off',
},
},
{
files: ['packages/build/src/log/messages/lambda_compat_deprecation.ts'],
rules: {
'n/no-missing-import': 'off',
},
},
{
files: ['packages/build/src/log/messages/mutations.js'],
rules: {
Expand Down
1 change: 1 addition & 0 deletions packages/build/src/core/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@ const runBuild = async function ({
explicitSecretKeys,
enhancedSecretScan,
edgeFunctionsBootstrapURL,
pluginsOptions,
})

return {
Expand Down
87 changes: 87 additions & 0 deletions packages/build/src/log/messages/lambda_compat_deprecation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import path from 'path'

import type { FunctionResult } from '@netlify/zip-it-and-ship-it'
import semver from 'semver'

import type { PluginsOptions } from '../../plugins/node_version.js'
import { isRuntime } from '../../utils/runtime.js'
import { log, logArray, logWarningSubHeader, type Logs } from '../logger.js'

const LEGACY_NEXTJS_RUNTIME_RANGE = '4.x'

interface LegacyNextjsRuntime {
name: string
version: string
}

const detectLegacyNextjsRuntime = (pluginsOptions: PluginsOptions[] | undefined): LegacyNextjsRuntime | null => {
const runtime = pluginsOptions?.find(isRuntime)
const version: unknown = runtime?.pluginPackageJson?.version

if (runtime && typeof version === 'string' && semver.satisfies(version, LEGACY_NEXTJS_RUNTIME_RANGE)) {
return { name: runtime.packageName, version }
}

return null
}

interface LogLambdaCompatibilityDeprecationOptions {
logs: Logs | undefined
results: FunctionResult[]
functionsSrc: string | undefined
pluginsOptions: PluginsOptions[] | undefined
}

/**
* Warns about JavaScript/TypeScript functions still using Lambda compatibility
* mode (V1) after bundling.
*/
export const logLambdaCompatibilityDeprecation = ({
logs,
results,
functionsSrc,
pluginsOptions,
}: LogLambdaCompatibilityDeprecationOptions): void => {
const v1JsFunctions = results.filter((result) => result.runtime === 'js' && result.runtimeAPIVersion !== 2)

if (v1JsFunctions.length === 0) {
return
}

const userFns: string[] = []
const generatedFns: string[] = []

for (const fn of v1JsFunctions) {
if (functionsSrc && fn.mainFile.startsWith(`${functionsSrc}${path.sep}`)) {
userFns.push(fn.name)
} else {
generatedFns.push(fn.name)
}
}

logWarningSubHeader(
logs,
'Lambda compatibility mode is deprecated and will be removed on June 1, 2027. Refer to https://ntl.fyi/lambda-deprecate for details.',
)

if (userFns.length > 0) {
log(logs, '\n These functions in your project use Lambda compatibility mode:')
logArray(logs, userFns)
log(logs, '\n Migrate them to the modern Netlify Functions API. Refer to https://ntl.fyi/functions-migrate.')
}

if (generatedFns.length > 0) {
log(logs, '\n These functions were generated by a framework adapter and use Lambda compatibility mode:')
logArray(logs, generatedFns)

const legacyNextjsRuntime = detectLegacyNextjsRuntime(pluginsOptions)
if (legacyNextjsRuntime) {
log(
logs,
`\n Your project is using ${legacyNextjsRuntime.name} v${legacyNextjsRuntime.version}. Upgrade to the latest Netlify Next.js Adapter to emit modern Netlify Functions. Refer to https://ntl.fyi/nextjs-adapter-upgrade for upgrade guidance.`,
)
} else {
log(logs, '\n Update the framework adapter to a version that emits modern Netlify Functions.')
}
}
}
10 changes: 10 additions & 0 deletions packages/build/src/plugins_core/functions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { addErrorInfo } from '../../error/info.js'
import { log } from '../../log/logger.js'
import { type GeneratedFunction, getGeneratedFunctions } from '../../steps/return_values.js'
import { logBundleResults, logFunctionsNonExistingDir, logFunctionsToBundle } from '../../log/messages/core_steps.js'
import { logLambdaCompatibilityDeprecation } from '../../log/messages/lambda_compat_deprecation.js'
import { FRAMEWORKS_API_FUNCTIONS_PATH } from '../../utils/frameworks_api.js'

import { getZipError } from './error.js'
Expand Down Expand Up @@ -77,6 +78,7 @@ const zipFunctionsAndLogResults = async ({
repositoryRoot,
userNodeVersion,
systemLog,
pluginsOptions,
}) => {
const zisiParameters = getZisiParameters({
branch,
Expand Down Expand Up @@ -115,6 +117,12 @@ const zipFunctionsAndLogResults = async ({
const bundlers = Array.from(getBundlers(results))

logBundleResults({ logs, results })
logLambdaCompatibilityDeprecation({
logs,
results,
functionsSrc,
pluginsOptions,
})

return { bundlers }
} catch (error) {
Expand Down Expand Up @@ -142,6 +150,7 @@ const coreStep = async function ({
userNodeVersion,
systemLog,
returnValues,
pluginsOptions,
}) {
const functionsSrc = relativeFunctionsSrc === undefined ? undefined : resolve(buildDir, relativeFunctionsSrc)
const functionsDist = resolve(buildDir, relativeFunctionsDist)
Expand Down Expand Up @@ -206,6 +215,7 @@ const coreStep = async function ({
userNodeVersion,
systemLog,
generatedFunctions: generatedFunctions.map((func) => func.path),
pluginsOptions,
})

const metrics = getMetrics(internalFunctions, userFunctions)
Expand Down
2 changes: 2 additions & 0 deletions packages/build/src/steps/core_step.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const fireCoreStep = async function ({
outputFlusher,
api,
returnValues,
pluginsOptions,
}) {
const logsA = outputFlusher ? addOutputFlusher(logs, outputFlusher) : logs

Expand Down Expand Up @@ -87,6 +88,7 @@ export const fireCoreStep = async function ({
edgeFunctionsBootstrapURL,
deployId,
returnValues,
pluginsOptions,
})
const {
netlifyConfig: netlifyConfigA,
Expand Down
4 changes: 4 additions & 0 deletions packages/build/src/steps/run_step.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export const runStep = async function ({
edgeFunctionsBootstrapURL,
extensionMetadata,
returnValues,
pluginsOptions,
}) {
// Add relevant attributes to the upcoming span context
const attributes: StepExecutionAttributes = {
Expand Down Expand Up @@ -195,6 +196,7 @@ export const runStep = async function ({
api,
returnValues,
deployEnvVars,
pluginsOptions,
})

const newValues = await getStepReturn({
Expand Down Expand Up @@ -367,6 +369,7 @@ const tFireStep = function ({
extensionMetadata,
api,
returnValues,
pluginsOptions,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}) {
if (coreStep !== undefined) {
return fireCoreStep({
Expand Down Expand Up @@ -408,6 +411,7 @@ const tFireStep = function ({
deployId,
api,
returnValues,
pluginsOptions,
})
}

Expand Down
2 changes: 2 additions & 0 deletions packages/build/src/steps/run_steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const runSteps = async function ({
explicitSecretKeys,
enhancedSecretScan,
edgeFunctionsBootstrapURL,
pluginsOptions,
}) {
const {
index: stepsCount,
Expand Down Expand Up @@ -164,6 +165,7 @@ export const runSteps = async function ({
explicitSecretKeys,
enhancedSecretScan,
edgeFunctionsBootstrapURL,
pluginsOptions,
})

const statusesA = addStatus({ newStatus, statuses, event, packageName, pluginPackageJson })
Expand Down
38 changes: 38 additions & 0 deletions packages/build/tests/core/snapshots/tests.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,13 @@ Generated by [AVA](https://avajs.dev).
- test.js␊
> Lambda compatibility mode is deprecated and will be removed on June 1, 2027. Refer to https://ntl.fyi/lambda-deprecate for details.␊
These functions in your project use Lambda compatibility mode:␊
- test␊
Migrate them to the modern Netlify Functions API. Refer to https://ntl.fyi/functions-migrate.␊
(Functions bundling completed in 1ms)␊
Build step duration: Functions bundling completed in 1ms␊
Expand Down Expand Up @@ -1761,6 +1768,14 @@ Generated by [AVA](https://avajs.dev).
- function_two.js␊
> Lambda compatibility mode is deprecated and will be removed on June 1, 2027. Refer to https://ntl.fyi/lambda-deprecate for details.␊
These functions in your project use Lambda compatibility mode:␊
- function_one␊
- function_two␊
Migrate them to the modern Netlify Functions API. Refer to https://ntl.fyi/functions-migrate.␊
(Functions bundling completed in 1ms)␊
Build step duration: Functions bundling completed in 1ms␊
Expand Down Expand Up @@ -1827,6 +1842,13 @@ Generated by [AVA](https://avajs.dev).
- function_one.js␊
> Lambda compatibility mode is deprecated and will be removed on June 1, 2027. Refer to https://ntl.fyi/lambda-deprecate for details.␊
These functions in your project use Lambda compatibility mode:␊
- function_one␊
Migrate them to the modern Netlify Functions API. Refer to https://ntl.fyi/functions-migrate.␊
(Functions bundling completed in 1ms)␊
Build step duration: Functions bundling completed in 1ms␊
Expand Down Expand Up @@ -1966,6 +1988,15 @@ Generated by [AVA](https://avajs.dev).
- function_with_dynamic_require.zip␊
- function_with_native.zip␊
> Lambda compatibility mode is deprecated and will be removed on June 1, 2027. Refer to https://ntl.fyi/lambda-deprecate for details.␊
These functions in your project use Lambda compatibility mode:␊
- function_simple␊
- function_with_dynamic_require␊
- function_with_native␊
Migrate them to the modern Netlify Functions API. Refer to https://ntl.fyi/functions-migrate.␊
(Functions bundling completed in 1ms)␊
Build step duration: Functions bundling completed in 1ms␊
Expand Down Expand Up @@ -2021,6 +2052,13 @@ Generated by [AVA](https://avajs.dev).
> Failed to bundle functions with selected bundler (fallback used):␊
- function_with_module.zip␊
> Lambda compatibility mode is deprecated and will be removed on June 1, 2027. Refer to https://ntl.fyi/lambda-deprecate for details.␊
These functions in your project use Lambda compatibility mode:␊
- function_with_module␊
Migrate them to the modern Netlify Functions API. Refer to https://ntl.fyi/functions-migrate.␊
(Functions bundling completed in 1ms)␊
Build step duration: Functions bundling completed in 1ms␊
Expand Down
Binary file modified packages/build/tests/core/snapshots/tests.js.snap
Binary file not shown.
21 changes: 21 additions & 0 deletions packages/build/tests/functions/snapshots/tests.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ Generated by [AVA](https://avajs.dev).
- test.js␊
> Lambda compatibility mode is deprecated and will be removed on June 1, 2027. Refer to https://ntl.fyi/lambda-deprecate for details.␊
These functions in your project use Lambda compatibility mode:␊
- test␊
Migrate them to the modern Netlify Functions API. Refer to https://ntl.fyi/functions-migrate.␊
(Functions bundling completed in 1ms)␊
Build step duration: Functions bundling completed in 1ms␊
Expand Down Expand Up @@ -223,6 +230,13 @@ Generated by [AVA](https://avajs.dev).
- test.js␊
> Lambda compatibility mode is deprecated and will be removed on June 1, 2027. Refer to https://ntl.fyi/lambda-deprecate for details.␊
These functions in your project use Lambda compatibility mode:␊
- test␊
Migrate them to the modern Netlify Functions API. Refer to https://ntl.fyi/functions-migrate.␊
(Functions bundling completed in 1ms)␊
Build step duration: Functions bundling completed in 1ms␊
Expand Down Expand Up @@ -321,6 +335,13 @@ Generated by [AVA](https://avajs.dev).
- test.js␊
> Lambda compatibility mode is deprecated and will be removed on June 1, 2027. Refer to https://ntl.fyi/lambda-deprecate for details.␊
These functions in your project use Lambda compatibility mode:␊
- test␊
Migrate them to the modern Netlify Functions API. Refer to https://ntl.fyi/functions-migrate.␊
(Functions bundling completed in 1ms)␊
Build step duration: Functions bundling completed in 1ms␊
Expand Down
Binary file modified packages/build/tests/functions/snapshots/tests.js.snap
Binary file not shown.
Loading
Loading