Skip to content

Commit

Permalink
fix: map over declarations and add generator field per declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
khendrikse committed Mar 6, 2023
1 parent daffd78 commit 3726a1d
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions node/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ const bundle = async (

// If any declarations are autogenerated and are missing the generator field
// add a default string.
const declarations = addGeneratorFieldIfMissing(declarationsFromConfig, functions, internalFunctionsPath)
const declarations = internalFunctionsPath
? declarationsFromConfig.map((declaration) =>
addGeneratorFieldIfMissing(declaration, functions, internalFunctionsPath),
)
: declarationsFromConfig

const manifest = await writeManifest({
bundles: [functionBundle],
Expand Down Expand Up @@ -168,21 +172,18 @@ const getBasePath = (sourceDirectories: string[], inputBasePath?: string) => {
}

export const addGeneratorFieldIfMissing = (
declarations: Declaration[],
declaration: Declaration,
functions: EdgeFunction[],
internalFunctionsPath?: string,
) =>
declarations.map((declaration) => {
const fullFuncPath = functions?.find((func) => func.name === declaration.function)?.path
) => {
const fullFuncPath = functions?.find((func) => func.name === declaration.function)?.path

// If function path is in the internalFunctionsPath, we assume it is autogenerated.
const isInternal = Boolean(
internalFunctionsPath && fullFuncPath && isPathInside(fullFuncPath, internalFunctionsPath),
)
// If function path is in the internalFunctionsPath, we assume it is autogenerated.
const isInternal = Boolean(internalFunctionsPath && fullFuncPath && isPathInside(fullFuncPath, internalFunctionsPath))

const generatorFallback = isInternal ? 'internalFunc' : undefined
return { ...declaration, generator: declaration.generator || generatorFallback }
})
const generatorFallback = isInternal ? 'internalFunc' : undefined
return { ...declaration, generator: declaration.generator || generatorFallback }
}

export { bundle }
export type { BundleOptions }

0 comments on commit 3726a1d

Please sign in to comment.