Skip to content

Commit 63d415b

Browse files
authored
feat: send functions_config during deploy (#5428)
* feat: send functions_config along with deploy * fix: simplify reduce for fnConfig
1 parent cfcee54 commit 63d415b

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/utils/deploy/deploy-site.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export const deploySite = async (
5656
})
5757

5858
const edgeFunctionsDistPath = await getDistPathIfExists({ rootDir })
59-
const [{ files, filesShaMap }, { fnShaMap, functionSchedules, functions, functionsWithNativeModules }] =
59+
const [{ files, filesShaMap }, { fnConfig, fnShaMap, functionSchedules, functions, functionsWithNativeModules }] =
6060
await Promise.all([
6161
hashFiles({
6262
assetType,
@@ -125,6 +125,7 @@ For more information, visit https://ntl.fyi/cli-native-modules.`)
125125
files,
126126
functions,
127127
function_schedules: functionSchedules,
128+
functions_config: fnConfig,
128129
async: Object.keys(files).length > syncFileLimit,
129130
branch,
130131
draft,

src/utils/deploy/hash-fns.mjs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { readFile } from 'fs/promises'
2-
import path from 'path'
2+
import path, { join } from 'path'
33
import { promisify } from 'util'
44

55
import fromArray from 'from2-array'
66
import pumpModule from 'pump'
77

8+
import { INTERNAL_FUNCTIONS_FOLDER } from '../functions/functions.mjs'
9+
810
import { hasherCtor, manifestCollectorCtor } from './hasher-segments.mjs'
911

1012
const pump = promisify(pumpModule)
@@ -65,7 +67,12 @@ const getFunctionZips = async ({
6567

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

68-
return await zipFunctions(directories, tmpDir, { basePath: rootDir, config: functionsConfig })
70+
return await zipFunctions(directories, tmpDir, {
71+
featureFlags: { project_deploy_configuration_api_use_per_function_configuration_files: true },
72+
basePath: rootDir,
73+
configFileDirectories: [join('.netlify', INTERNAL_FUNCTIONS_FOLDER)],
74+
config: functionsConfig,
75+
})
6976
}
7077

7178
const hashFns = async (
@@ -100,7 +107,7 @@ const hashFns = async (
100107
statusCb,
101108
tmpDir,
102109
})
103-
const fileObjs = functionZips.map(({ path: functionPath, runtime }) => ({
110+
const fileObjs = functionZips.map(({ displayName, path: functionPath, runtime }) => ({
104111
filepath: functionPath,
105112
root: tmpDir,
106113
relname: path.relative(tmpDir, functionPath),
@@ -110,7 +117,11 @@ const hashFns = async (
110117
assetType: 'function',
111118
normalizedPath: path.basename(functionPath, path.extname(functionPath)),
112119
runtime,
120+
displayName,
113121
}))
122+
const fnConfig = functionZips
123+
.filter((func) => Boolean(func.displayName))
124+
.reduce((funcs, curr) => ({ ...funcs, [curr.name]: { display_name: curr.displayName } }), {})
114125
const functionSchedules = functionZips
115126
.map(({ name, schedule }) => schedule && { name, cron: schedule })
116127
.filter(Boolean)
@@ -130,8 +141,7 @@ const hashFns = async (
130141
const manifestCollector = manifestCollectorCtor(functions, fnShaMap, { statusCb, assetType })
131142

132143
await pump(functionStream, hasher, manifestCollector)
133-
134-
return { functionSchedules, functions, functionsWithNativeModules, fnShaMap }
144+
return { functionSchedules, functions, functionsWithNativeModules, fnShaMap, fnConfig }
135145
}
136146

137147
export default hashFns

0 commit comments

Comments
 (0)