Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Commit

Permalink
feat: add invocation mode to manifest (#1421)
Browse files Browse the repository at this point in the history
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
eduardoboucas and kodiakhq[bot] authored May 11, 2023
1 parent fd7225f commit 90ff319
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ import { Stats } from 'fs'

import type { FunctionConfig } from './config.js'
import type { Runtime, ZipFunctionResult } from './runtimes/runtime.js'
import { ObjectValues } from './types/utils.js'

export const INVOCATION_MODE = {
Buffer: 'buffer',
Stream: 'stream',
} as const

export type InvocationMode = ObjectValues<typeof INVOCATION_MODE>

// A function that has been processed and turned into an archive.
export type FunctionArchive = ZipFunctionResult & {
Expand Down
16 changes: 15 additions & 1 deletion src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import { resolve } from 'path'
import { arch, platform } from 'process'

import type { FeatureFlags } from './feature_flags.js'
import type { InvocationMode } from './function.js'
import type { FunctionResult } from './utils/format_result.js'

interface ManifestFunction {
invocationMode?: InvocationMode
mainFile: string
name: string
path: string
Expand Down Expand Up @@ -50,12 +52,24 @@ export const createManifest = async ({
}

const formatFunctionForManifest = (
{ bundler, displayName, generator, mainFile, name, path, runtime, runtimeVersion, schedule }: FunctionResult,
{
bundler,
displayName,
generator,
invocationMode,
mainFile,
name,
path,
runtime,
runtimeVersion,
schedule,
}: FunctionResult,
featureFlags: FeatureFlags,
): ManifestFunction => ({
bundler,
displayName,
generator,
invocationMode,
mainFile,
name,
runtimeVersion: featureFlags.functions_inherit_build_nodejs_version ? runtimeVersion : undefined,
Expand Down
4 changes: 4 additions & 0 deletions src/runtimes/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { join } from 'path'

import { copyFile } from 'cp-file'

import { INVOCATION_MODE } from '../../function.js'
import getInternalValue from '../../utils/get_internal_value.js'
import { GetSrcFilesFunction, Runtime, RUNTIME, ZipFunction } from '../runtime.js'

Expand Down Expand Up @@ -117,13 +118,16 @@ const zipFunction: ZipFunction = async function ({

await cleanupFunction?.()

const invocationMode = featureFlags.zisi_functions_api_v2 ? INVOCATION_MODE.Stream : INVOCATION_MODE.Buffer

return {
bundler: bundlerName,
bundlerWarnings,
config,
inputs,
includedFiles,
inSourceConfig,
invocationMode,
nativeNodeModules,
nodeModulesWithDynamicImports,
path: zipPath,
Expand Down
3 changes: 2 additions & 1 deletion src/runtimes/runtime.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ArchiveFormat } from '../archive.js'
import type { FunctionConfig } from '../config.js'
import type { FeatureFlags } from '../feature_flags.js'
import type { FunctionSource, SourceFile } from '../function.js'
import type { FunctionSource, InvocationMode, SourceFile } from '../function.js'
import { ObjectValues } from '../types/utils.js'
import type { RuntimeCache } from '../utils/cache.js'

Expand Down Expand Up @@ -47,6 +47,7 @@ export interface ZipFunctionResult {
inputs?: string[]
includedFiles?: string[]
inSourceConfig?: ISCValues
invocationMode?: InvocationMode
nativeNodeModules?: object
nodeModulesWithDynamicImports?: string[]
path: string
Expand Down

1 comment on commit 90ff319

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⏱ Benchmark results

  • largeDepsEsbuild: 2.1s
  • largeDepsNft: 7.6s
  • largeDepsZisi: 14.9s

Please sign in to comment.