Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/function-builder-detectors/zisi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down Expand Up @@ -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
}

Expand Down
31 changes: 31 additions & 0 deletions tests/command.dev.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down