11import { resolve } from 'path'
22
3- import { zipFunctions } from '@netlify/zip-it-and-ship-it'
3+ import { NodeBundlerType , RuntimeType , zipFunctions } from '@netlify/zip-it-and-ship-it'
44import { pathExists } from 'path-exists'
55
66import { log } from '../../log/logger.js'
@@ -10,10 +10,14 @@ import { getZipError } from './error.js'
1010import { getUserAndInternalFunctions , validateFunctionsSrc } from './utils.js'
1111import { getZisiParameters } from './zisi.js'
1212
13- // Returns `true` if at least one of the functions has been configured to use
14- // esbuild.
15- const isUsingEsbuild = ( functionsConfig = { } ) =>
16- Object . values ( functionsConfig ) . some ( ( configObject ) => configObject . node_bundler === 'esbuild' )
13+ // Get a list of all unique bundlers in this run
14+ const getBundlers = ( results : Awaited < ReturnType < typeof zipFunctions > > = [ ] ) =>
15+ // using a Set to filter duplicates
16+ new Set (
17+ results
18+ . map ( ( bundle ) => ( bundle . runtime === RuntimeType . JAVASCRIPT ? bundle . bundler : null ) )
19+ . filter ( Boolean ) as NodeBundlerType [ ] ,
20+ )
1721
1822const zipFunctionsAndLogResults = async ( {
1923 buildDir,
@@ -37,7 +41,6 @@ const zipFunctionsAndLogResults = async ({
3741 isRunningLocally,
3842 repositoryRoot,
3943 } )
40- const bundler = isUsingEsbuild ( functionsConfig ) ? 'esbuild' : 'zisi'
4144
4245 try {
4346 // Printing an empty line before bundling output.
@@ -46,9 +49,11 @@ const zipFunctionsAndLogResults = async ({
4649 const sourceDirectories = [ internalFunctionsSrc , functionsSrc ] . filter ( Boolean )
4750 const results = await zipItAndShipIt . zipFunctions ( sourceDirectories , functionsDist , zisiParameters )
4851
52+ const bundlers = Array . from ( getBundlers ( results ) )
53+
4954 logBundleResults ( { logs, results } )
5055
51- return { bundler }
56+ return { bundlers }
5257 } catch ( error ) {
5358 throw await getZipError ( error , functionsSrc )
5459 }
@@ -74,7 +79,7 @@ const coreStep = async function ({
7479 const functionsDist = resolve ( buildDir , relativeFunctionsDist )
7580 const internalFunctionsSrc = resolve ( buildDir , relativeInternalFunctionsSrc )
7681 const internalFunctionsSrcExists = await pathExists ( internalFunctionsSrc )
77- const functionsSrcExists = await validateFunctionsSrc ( { functionsSrc, logs , relativeFunctionsSrc } )
82+ const functionsSrcExists = await validateFunctionsSrc ( { functionsSrc, relativeFunctionsSrc } )
7883 const [ userFunctions = [ ] , internalFunctions = [ ] ] = await getUserAndInternalFunctions ( {
7984 featureFlags,
8085 functionsSrc,
@@ -104,7 +109,7 @@ const coreStep = async function ({
104109 return { }
105110 }
106111
107- const { bundler } = await zipFunctionsAndLogResults ( {
112+ const { bundlers } = await zipFunctionsAndLogResults ( {
108113 buildDir,
109114 childEnv,
110115 featureFlags,
@@ -119,7 +124,7 @@ const coreStep = async function ({
119124
120125 return {
121126 tags : {
122- bundler,
127+ bundler : bundlers ,
123128 } ,
124129 }
125130}
@@ -155,7 +160,7 @@ export const bundleFunctions = {
155160// `zip-it-and-ship-it` methods. Therefore, we need to use an intermediary
156161// function and export them so tests can use it.
157162export const zipItAndShipIt = {
158- async zipFunctions ( ...args ) {
163+ async zipFunctions ( ...args : Parameters < typeof zipFunctions > ) {
159164 return await zipFunctions ( ...args )
160165 } ,
161166}
0 commit comments