1- import { basename , resolve } from 'path'
1+ import { resolve } from 'path'
22
33import { type NodeBundlerName , RUNTIME , zipFunctions , type FunctionResult } from '@netlify/zip-it-and-ship-it'
44import { pathExists } from 'path-exists'
55
66import { addErrorInfo } from '../../error/info.js'
77import { log } from '../../log/logger.js'
8- import type { ReturnValue } from '../../types/step .js'
8+ import { type GeneratedFunction , getGeneratedFunctions } from '../../steps/return_values .js'
99import { logBundleResults , logFunctionsNonExistingDir , logFunctionsToBundle } from '../../log/messages/core_steps.js'
1010import { FRAMEWORKS_API_FUNCTIONS_ENDPOINT } from '../../utils/frameworks_api.js'
1111
@@ -168,7 +168,7 @@ const coreStep = async function ({
168168 }
169169 }
170170
171- const generatedFunctions = getGeneratedFunctionPaths ( returnValues )
171+ const generatedFunctions = getGeneratedFunctions ( returnValues )
172172
173173 logFunctionsToBundle ( {
174174 logs,
@@ -178,7 +178,7 @@ const coreStep = async function ({
178178 internalFunctions,
179179 internalFunctionsSrc : relativeInternalFunctionsSrc ,
180180 frameworkFunctions,
181- generatedFunctions : getGeneratedFunctionsByGenerator ( returnValues ) ,
181+ generatedFunctions : getGeneratedFunctionsByGenerator ( generatedFunctions ) ,
182182 } )
183183
184184 if (
@@ -205,7 +205,7 @@ const coreStep = async function ({
205205 repositoryRoot,
206206 userNodeVersion,
207207 systemLog,
208- generatedFunctions,
208+ generatedFunctions : generatedFunctions . map ( ( func ) => func . path ) ,
209209 } )
210210
211211 const metrics = getMetrics ( internalFunctions , userFunctions )
@@ -257,31 +257,17 @@ const hasFunctionsDirectories = async function ({
257257 return false
258258}
259259
260- // Takes a list of return values and produces an array with the paths of all
261- // generated functions.
262- const getGeneratedFunctionPaths = ( returnValues : Record < string , ReturnValue > ) => {
263- return Object . values ( returnValues ) . flatMap (
264- ( returnValue ) => returnValue . generatedFunctions ?. map ( ( func ) => func . path ) || [ ] ,
265- )
266- }
267-
268260// Takes a list of return values and produces an object with the names of the
269261// generated functions for each generator. This is used for printing logs only.
270- const getGeneratedFunctionsByGenerator = ( returnValues : Record < string , ReturnValue > ) => {
271- const result : Record < string , { displayName : string ; generatorType : string ; functionNames : string [ ] } > = { }
272-
273- for ( const id in returnValues ) {
274- const { displayName, generatedFunctions, generatorType } = returnValues [ id ]
275-
276- if ( ! generatedFunctions || generatedFunctions . length === 0 ) {
277- continue
278- }
279-
280- result [ id ] = {
281- displayName,
282- generatorType,
283- functionNames : generatedFunctions . map ( ( func ) => basename ( func . path ) ) ,
284- }
262+ const getGeneratedFunctionsByGenerator = (
263+ generatedFunctions : GeneratedFunction [ ] ,
264+ ) : Record < string , GeneratedFunction [ ] > => {
265+ const result : Record < string , GeneratedFunction [ ] > = { }
266+
267+ for ( const func of generatedFunctions ) {
268+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
269+ result [ func . generator . name ] = result [ func . generator . name ] || [ ]
270+ result [ func . generator . name ] . push ( func )
285271 }
286272
287273 return result
0 commit comments