Skip to content

Commit

Permalink
feat: send functions_config during deploy (#5428)
Browse files Browse the repository at this point in the history
* feat: send functions_config along with deploy

* fix: simplify reduce for fnConfig
  • Loading branch information
khendrikse committed Jan 25, 2023
1 parent cfcee54 commit 63d415b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/utils/deploy/deploy-site.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const deploySite = async (
})

const edgeFunctionsDistPath = await getDistPathIfExists({ rootDir })
const [{ files, filesShaMap }, { fnShaMap, functionSchedules, functions, functionsWithNativeModules }] =
const [{ files, filesShaMap }, { fnConfig, fnShaMap, functionSchedules, functions, functionsWithNativeModules }] =
await Promise.all([
hashFiles({
assetType,
Expand Down Expand Up @@ -125,6 +125,7 @@ For more information, visit https://ntl.fyi/cli-native-modules.`)
files,
functions,
function_schedules: functionSchedules,
functions_config: fnConfig,
async: Object.keys(files).length > syncFileLimit,
branch,
draft,
Expand Down
20 changes: 15 additions & 5 deletions src/utils/deploy/hash-fns.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { readFile } from 'fs/promises'
import path from 'path'
import path, { join } from 'path'
import { promisify } from 'util'

import fromArray from 'from2-array'
import pumpModule from 'pump'

import { INTERNAL_FUNCTIONS_FOLDER } from '../functions/functions.mjs'

import { hasherCtor, manifestCollectorCtor } from './hasher-segments.mjs'

const pump = promisify(pumpModule)
Expand Down Expand Up @@ -65,7 +67,12 @@ const getFunctionZips = async ({

const { zipFunctions } = await import('@netlify/zip-it-and-ship-it')

return await zipFunctions(directories, tmpDir, { basePath: rootDir, config: functionsConfig })
return await zipFunctions(directories, tmpDir, {
featureFlags: { project_deploy_configuration_api_use_per_function_configuration_files: true },
basePath: rootDir,
configFileDirectories: [join('.netlify', INTERNAL_FUNCTIONS_FOLDER)],
config: functionsConfig,
})
}

const hashFns = async (
Expand Down Expand Up @@ -100,7 +107,7 @@ const hashFns = async (
statusCb,
tmpDir,
})
const fileObjs = functionZips.map(({ path: functionPath, runtime }) => ({
const fileObjs = functionZips.map(({ displayName, path: functionPath, runtime }) => ({
filepath: functionPath,
root: tmpDir,
relname: path.relative(tmpDir, functionPath),
Expand All @@ -110,7 +117,11 @@ const hashFns = async (
assetType: 'function',
normalizedPath: path.basename(functionPath, path.extname(functionPath)),
runtime,
displayName,
}))
const fnConfig = functionZips
.filter((func) => Boolean(func.displayName))
.reduce((funcs, curr) => ({ ...funcs, [curr.name]: { display_name: curr.displayName } }), {})
const functionSchedules = functionZips
.map(({ name, schedule }) => schedule && { name, cron: schedule })
.filter(Boolean)
Expand All @@ -130,8 +141,7 @@ const hashFns = async (
const manifestCollector = manifestCollectorCtor(functions, fnShaMap, { statusCb, assetType })

await pump(functionStream, hasher, manifestCollector)

return { functionSchedules, functions, functionsWithNativeModules, fnShaMap }
return { functionSchedules, functions, functionsWithNativeModules, fnShaMap, fnConfig }
}

export default hashFns

1 comment on commit 63d415b

@github-actions
Copy link

Choose a reason for hiding this comment

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

📊 Benchmark results

  • Package size: 265 MB

Please sign in to comment.