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

Commit

Permalink
fix: add feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
danez committed Jul 22, 2022
1 parent 417cdf8 commit dbb03b9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { basename, extname, dirname, join } from 'path'

import mergeOptions from 'merge-options'

import type { FeatureFlags } from './feature_flags.js'
import { FunctionSource } from './function.js'
import type { NodeBundlerName } from './runtimes/node/bundlers/types.js'
import type { NodeVersionString } from './runtimes/node/index.js'
Expand Down Expand Up @@ -36,16 +37,20 @@ const getConfigForFunction = async ({
config,
configFileDirectories,
func,
featureFlags,
}: {
config?: Config
configFileDirectories?: string[]
func: FunctionWithoutConfig
featureFlags: FeatureFlags
}): Promise<FunctionConfig> => {
const fromConfig = getFromMainConfig({ config, func })

// We try to read from a function config file if the function directory is
// inside one of `configFileDirectories`.
const shouldReadConfigFile = configFileDirectories?.some((directory) => func.srcDir.startsWith(directory))
const shouldReadConfigFile =
featureFlags.project_deploy_configuration_api_use_per_function_configuration_files &&
configFileDirectories?.some((directory) => func.srcDir.startsWith(directory))

if (!shouldReadConfigFile) {
return fromConfig
Expand Down
1 change: 1 addition & 0 deletions src/feature_flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const defaultFlags: Record<string, boolean> = {
parseWithEsbuild: false,
traceWithNft: false,
zisi_pure_esm: false,
project_deploy_configuration_api_use_per_function_configuration_files: false,
}

export type FeatureFlag = keyof typeof defaultFlags
Expand Down
4 changes: 2 additions & 2 deletions src/runtimes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export const getFunctionsFromPaths = async (
}
}, Promise.resolve({ functions: [], remainingPaths: paths } as { functions: FunctionTupleWithoutConfig[]; remainingPaths: string[] }))
const functionConfigs = await Promise.all(
functions.map(([, func]) => getConfigForFunction({ config, configFileDirectories, func })),
functions.map(([, func]) => getConfigForFunction({ config, configFileDirectories, func, featureFlags })),
)
const functionsWithConfig: FunctionTuple[] = functions.map(([name, func], index) => [
name,
Expand All @@ -129,7 +129,7 @@ export const getFunctionFromPath = async (
const func = await runtime.findFunctionInPath({ path, fsCache, featureFlags })

if (func) {
const functionConfig = await getConfigForFunction({ config, func: { ...func, runtime } })
const functionConfig = await getConfigForFunction({ config, func: { ...func, runtime }, featureFlags })

return {
...func,
Expand Down
2 changes: 1 addition & 1 deletion tests/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2791,7 +2791,7 @@ testMany(
const opts = merge(options, {
basePath: join(FIXTURES_DIR, fixtureName),
configFileDirectories: [join(FIXTURES_DIR, pathInternal)],
featureFlags: { zisi_detect_esm: true },
featureFlags: { project_deploy_configuration_api_use_per_function_configuration_files: true },
})
const { files, tmpDir } = await zipFixture(t, [pathInternal, pathUser], {
length: 2,
Expand Down

0 comments on commit dbb03b9

Please sign in to comment.