diff --git a/src/runtimes/node/utils/zip.ts b/src/runtimes/node/utils/zip.ts index 11c2cce57..5991d062c 100644 --- a/src/runtimes/node/utils/zip.ts +++ b/src/runtimes/node/utils/zip.ts @@ -53,6 +53,16 @@ interface ZipNodeParameters { srcFiles: string[] } +const addBootstrapFile = function (srcFiles: string[], aliases: Map) { + // This is the path to the file that contains all the code for the v2 + // functions API. We add it to the list of source files and create an + // alias so that it's written as `BOOTSTRAP_FILE_NAME` in the ZIP/Directory. + const v2APIPath = getV2APIPath() + + srcFiles.push(v2APIPath) + aliases.set(v2APIPath, BOOTSTRAP_FILE_NAME) +} + const createDirectory = async function ({ aliases = new Map(), basePath, @@ -84,6 +94,10 @@ const createDirectory = async function ({ // Writing entry file. await writeFile(join(functionFolder, entryFilename), entryContents) + if (runtimeAPIVersion === 2) { + addBootstrapFile(srcFiles, aliases) + } + // Copying source files. await pMap( srcFiles, @@ -164,13 +178,7 @@ const createZipArchive = async function ({ } if (runtimeAPIVersion === 2) { - // This is the path to the file that contains all the code for the v2 - // functions API. We add it to the list of source files and create an - // alias so that it's written as `BOOTSTRAP_FILE_NAME` in the ZIP. - const v2APIPath = getV2APIPath() - - srcFiles.push(v2APIPath) - aliases.set(v2APIPath, BOOTSTRAP_FILE_NAME) + addBootstrapFile(srcFiles, aliases) } const srcFilesInfos = await Promise.all(srcFiles.map((file) => addStat(cache, file))) diff --git a/tests/v2api.test.ts b/tests/v2api.test.ts index 9dfecb9d9..279cd5a23 100644 --- a/tests/v2api.test.ts +++ b/tests/v2api.test.ts @@ -4,6 +4,7 @@ import merge from 'deepmerge' import semver from 'semver' import { afterEach, describe, expect, vi } from 'vitest' +import { ARCHIVE_FORMAT } from '../src/archive.js' import { ENTRY_FILE_NAME } from '../src/runtimes/node/utils/entry_file.js' import { invokeLambda, readAsBuffer } from './helpers/lambda.js' @@ -35,4 +36,25 @@ describe.runIf(semver.gte(nodeVersion, '18.13.0'))('V2 functions API', () => { expect(statusCode).toBe(200) }, ) + + testMany( + 'Handles a basic JavaScript function with archiveFormat set to `none`', + ['bundler_default', 'todo:bundler_esbuild', 'todo:bundler_esbuild_zisi', 'bundler_default_nft', 'bundler_nft'], + async (options) => { + const { files, tmpDir } = await zipFixture('v2-api', { + opts: merge(options, { + archiveFormat: ARCHIVE_FORMAT.NONE, + featureFlags: { zisi_functions_api_v2: true }, + }), + }) + + const func = await importFunctionFile(`${tmpDir}/${files[0].name}/${ENTRY_FILE_NAME}.mjs`) + const { body: bodyStream, headers = {}, statusCode } = await invokeLambda(func) + const body = await readAsBuffer(bodyStream) + + expect(body).toBe('

Hello world

') + expect(headers['content-type']).toBe('text/html') + expect(statusCode).toBe(200) + }, + ) })