Skip to content

Commit

Permalink
feat: only write functionConfig for functions that need it
Browse files Browse the repository at this point in the history
  • Loading branch information
Skn0tt committed Jan 3, 2023
1 parent 722fe87 commit 7c49753
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion node/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ test('Loads function paths from the in-source `config` function', async () => {
expect(postCacheRoutes.length).toBe(1)
expect(postCacheRoutes[0]).toEqual({ function: 'user-func4', pattern: '^/user-func4/?$' })

expect(Object.keys(functionConfig)).toHaveLength(7)
expect(Object.keys(functionConfig)).toHaveLength(1)
expect(functionConfig['user-func5']).toEqual({
excluded_patterns: ['^/user-func5/excluded/?$'],
})
Expand Down
13 changes: 8 additions & 5 deletions node/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,18 @@ const generateManifest = ({
}: GenerateManifestOptions) => {
const preCacheRoutes: Route[] = []
const postCacheRoutes: Route[] = []
const manifestFunctionConfig: Manifest['function_config'] = Object.fromEntries(
functions.map(({ name }) => [name, { excluded_patterns: [] }]),
)
const manifestFunctionConfig: Manifest['function_config'] = {}

const getFunctionConfig = (name: string) => {
if (!manifestFunctionConfig[name]) manifestFunctionConfig[name] = { excluded_patterns: [] }
return manifestFunctionConfig[name]
}

for (const [name, { excludedPath }] of Object.entries(functionConfig)) {
if (excludedPath) {
const paths = Array.isArray(excludedPath) ? excludedPath : [excludedPath]
const excludedPatterns = paths.map(pathToRegularExpression).map(serializePattern)
manifestFunctionConfig[name].excluded_patterns.push(...excludedPatterns)
getFunctionConfig(name).excluded_patterns.push(...excludedPatterns)
}
}

Expand All @@ -86,7 +89,7 @@ const generateManifest = ({
}
const excludedPattern = getExcludedRegularExpression(declaration)
if (excludedPattern) {
manifestFunctionConfig[func.name].excluded_patterns.push(serializePattern(excludedPattern))
getFunctionConfig(func.name).excluded_patterns.push(serializePattern(excludedPattern))
}

if (declaration.cache === Cache.Manual) {
Expand Down

0 comments on commit 7c49753

Please sign in to comment.