Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Commit

Permalink
fix: add feature flag for the inheritance of the Node.js version from…
Browse files Browse the repository at this point in the history
… build (#1394)

* fix: add feature flag for the inheritance of the Node.js version from build

* Update feature_flags.ts

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
danez and kodiakhq[bot] authored Apr 24, 2023
1 parent 3ba9b49 commit cf04b49
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 22 deletions.
10 changes: 6 additions & 4 deletions src/feature_flags.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { env } from 'process'

export const defaultFlags: Record<string, boolean> = {
export const defaultFlags = {
// Build Rust functions from source.
buildRustSource: Boolean(env.NETLIFY_EXPERIMENTAL_BUILD_RUST_SOURCE),

Expand All @@ -10,6 +10,9 @@ export const defaultFlags: Record<string, boolean> = {
// Use NFT as the default bundler.
traceWithNft: false,

// Should Lambda functions inherit the build Node.js version
functions_inherit_build_nodejs_version: false,

// Output pure (i.e. untranspiled) ESM files when the function file has ESM
// syntax and the parent `package.json` file has `{"type": "module"}`.
zisi_pure_esm: false,
Expand All @@ -26,10 +29,9 @@ export const defaultFlags: Record<string, boolean> = {

// Inject the compatibility layer required for the v2 runtime API to work.
zisi_functions_api_v2: false,
}
} as const

export type FeatureFlag = keyof typeof defaultFlags
export type FeatureFlags = Record<FeatureFlag, boolean>
export type FeatureFlags = Partial<Record<keyof typeof defaultFlags, boolean>>

// List of supported flags and their default value.

Expand Down
32 changes: 17 additions & 15 deletions src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { promises as fs } from 'fs'
import { resolve } from 'path'
import { arch, platform } from 'process'

import { FunctionResult } from './utils/format_result.js'
import type { FeatureFlags } from './feature_flags.js'
import type { FunctionResult } from './utils/format_result.js'

interface ManifestFunction {
mainFile: string
Expand All @@ -28,8 +29,16 @@ export interface Manifest {

const MANIFEST_VERSION = 1

export const createManifest = async ({ functions, path }: { functions: FunctionResult[]; path: string }) => {
const formattedFunctions = functions.map(formatFunctionForManifest)
export const createManifest = async ({
featureFlags,
functions,
path,
}: {
featureFlags: FeatureFlags
functions: FunctionResult[]
path: string
}) => {
const formattedFunctions = functions.map((func) => formatFunctionForManifest(func, featureFlags))
const payload: Manifest = {
functions: formattedFunctions,
system: { arch, platform },
Expand All @@ -40,23 +49,16 @@ export const createManifest = async ({ functions, path }: { functions: FunctionR
await fs.writeFile(path, JSON.stringify(payload))
}

const formatFunctionForManifest = ({
bundler,
displayName,
generator,
mainFile,
name,
path,
runtime,
runtimeVersion,
schedule,
}: FunctionResult): ManifestFunction => ({
const formatFunctionForManifest = (
{ bundler, displayName, generator, mainFile, name, path, runtime, runtimeVersion, schedule }: FunctionResult,
featureFlags: FeatureFlags,
): ManifestFunction => ({
bundler,
displayName,
generator,
mainFile,
name,
runtimeVersion,
runtimeVersion: featureFlags.functions_inherit_build_nodejs_version ? runtimeVersion : undefined,
path: resolve(path),
runtime,
schedule,
Expand Down
4 changes: 2 additions & 2 deletions src/runtimes/node/bundlers/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Message } from '@netlify/esbuild'

import type { FunctionConfig } from '../../../config.js'
import type { FeatureFlag, FeatureFlags } from '../../../feature_flags.js'
import type { FeatureFlags } from '../../../feature_flags.js'
import type { FunctionSource } from '../../../function.js'
import { ObjectValues } from '../../../types/utils.js'
import type { RuntimeCache } from '../../../utils/cache.js'
Expand Down Expand Up @@ -29,7 +29,7 @@ export type BundleFunction = (
basePath?: string
cache: RuntimeCache
config: FunctionConfig
featureFlags: Record<FeatureFlag, boolean>
featureFlags: FeatureFlags
pluginsModulesPath?: string
repositoryRoot?: string
} & FunctionSource,
Expand Down
2 changes: 1 addition & 1 deletion src/zip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export const zipFunctions = async function (
)

if (manifest !== undefined) {
await createManifest({ functions: formattedResults, path: resolve(manifest) })
await createManifest({ featureFlags, functions: formattedResults, path: resolve(manifest) })
}

return formattedResults
Expand Down

1 comment on commit cf04b49

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

⏱ Benchmark results

  • largeDepsEsbuild: 2.6s
  • largeDepsNft: 10.2s
  • largeDepsZisi: 19.7s

Please sign in to comment.