Skip to content

Commit

Permalink
refactor: put Lambda compat log behind flag
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoboucas committed Oct 9, 2023
1 parent 2a09755 commit b442b73
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
20 changes: 18 additions & 2 deletions src/lib/functions/registry.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,16 @@ const ZIP_EXTENSION = '.zip'
*/

export class FunctionsRegistry {
constructor({ capabilities, config, debug = false, isConnected = false, projectRoot, settings, timeouts }) {
constructor({
capabilities,
config,
debug = false,
isConnected = false,
logLambdaCompat,
projectRoot,
settings,
timeouts,
}) {
this.capabilities = capabilities
this.config = config
this.debug = debug
Expand Down Expand Up @@ -80,6 +89,13 @@ export class FunctionsRegistry {
* installed.
*/
this.hasCheckedTypesPackage = false

/**
* Whether to log V1 functions as using the "Lambda compatibility mode"
*
* @type {boolean}
*/
this.logLambdaCompat = Boolean(logLambdaCompat)
}

checkTypesPackage() {
Expand Down Expand Up @@ -295,7 +311,7 @@ export class FunctionsRegistry {
const icon = warningsText ? NETLIFYDEVWARN : NETLIFYDEVLOG
const color = warningsText ? chalk.yellow : chalk.green
const mode =
func?.runtimeAPIVersion === 1
func?.runtimeAPIVersion === 1 && this.logLambdaCompat
? ` in ${getTerminalLink('Lambda compatibility mode', 'https://ntl.fyi/lambda-compat')}`
: ''

Expand Down
6 changes: 5 additions & 1 deletion src/lib/functions/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import expressLogging from 'express-logging'
import jwtDecode from 'jwt-decode'

import { NETLIFYDEVERR, NETLIFYDEVLOG, error as errorExit, log } from '../../utils/command-helpers.mjs'
import { isFeatureFlagEnabled } from '../../utils/feature-flags.mjs'
import {
CLOCKWORK_USERAGENT,
getFunctionsDistPath,
Expand Down Expand Up @@ -250,12 +251,14 @@ const getFunctionsServer = (options) => {
* @param {*} options.loadDistFunctions
* @param {*} options.settings
* @param {*} options.site
* @param {*} options.siteInfo
* @param {string} options.siteUrl
* @param {*} options.timeouts
* @returns {Promise<import('./registry.mjs').FunctionsRegistry | undefined>}
*/
export const startFunctionsServer = async (options) => {
const { capabilities, command, config, debug, loadDistFunctions, settings, site, siteUrl, timeouts } = options
const { capabilities, command, config, debug, loadDistFunctions, settings, site, siteInfo, siteUrl, timeouts } =
options
const internalFunctionsDir = await getInternalFunctionsDir({ base: site.root })
const functionsDirectories = []

Expand Down Expand Up @@ -293,6 +296,7 @@ export const startFunctionsServer = async (options) => {
config,
debug,
isConnected: Boolean(siteUrl),
logLambdaCompat: isFeatureFlagEnabled('cli_log_lambda_compat', siteInfo),
// functions always need to be inside the packagePath if set inside a monorepo
projectRoot: command.workingDir,
settings,
Expand Down

0 comments on commit b442b73

Please sign in to comment.