diff --git a/src/function-builder-detectors/zisi.js b/src/function-builder-detectors/zisi.js index c3112dec247..740e0a64e97 100644 --- a/src/function-builder-detectors/zisi.js +++ b/src/function-builder-detectors/zisi.js @@ -4,6 +4,7 @@ const { zipFunction, zipFunctions } = require('@netlify/zip-it-and-ship-it') const makeDir = require('make-dir') const { getPathInProject } = require('../lib/settings') +const { getFunctions } = require('../utils/get-functions') const { NETLIFYDEVERR } = require('../utils/logo') const bundleFunctions = ({ config, sourceDirectory, targetDirectory, updatedPath }) => { @@ -52,10 +53,12 @@ const getTargetDirectory = async ({ errorExit }) => { } module.exports = async function handler({ config, errorExit, functionsDirectory: sourceDirectory }) { + const functions = await getFunctions(sourceDirectory) + const hasTSFunction = functions.some(({ mainFile }) => path.extname(mainFile) === '.ts') const functionsConfig = normalizeFunctionsConfig(config.functions) const isUsingEsbuild = functionsConfig['*'] && functionsConfig['*'].nodeBundler === 'esbuild_zisi' - if (!isUsingEsbuild) { + if (!hasTSFunction && !isUsingEsbuild) { return false } diff --git a/tests/command.dev.test.js b/tests/command.dev.test.js index ffaae8d633d..a49259cec61 100644 --- a/tests/command.dev.test.js +++ b/tests/command.dev.test.js @@ -1565,6 +1565,37 @@ export const handler = async function () { }, ) + test( + testName('Should use the ZISI function bundler and serve TypeScript functions if not using esbuild', args), + async (t) => { + await withSiteBuilder('site-with-ts-function', async (builder) => { + builder.withNetlifyToml({ config: { functions: { directory: 'functions' } } }).withContentFile({ + path: path.join('functions', 'ts-function', 'ts-function.ts'), + content: ` +type CustomResponse = string; + +export const handler = async function () { + const response: CustomResponse = "ts"; + + return { + statusCode: 200, + body: response, + }; +}; + + `, + }) + + await builder.buildAsync() + + await withDevServer({ cwd: builder.directory, args }, async (server) => { + const response = await got(`${server.url}/.netlify/functions/ts-function`).text() + t.is(response, 'ts') + }) + }) + }, + ) + test(testName(`should start https server when https dev block is configured`, args), async (t) => { await withSiteBuilder('sites-with-https-certificate', async (builder) => { await builder