Home / Function/ getFallbackEntrypointPath() — supabase Function Reference

getFallbackEntrypointPath() — supabase Function Reference

Architecture documentation for the getFallbackEntrypointPath() function in EdgeFunctions.utils.ts from the supabase codebase.

Entity Profile

Relationship Graph

Source Code

apps/studio/components/interfaces/EdgeFunctions/EdgeFunctions.utils.ts lines 12–32

export const getFallbackEntrypointPath = (files: Omit<FileData, 'id' | 'content' | 'state'>[]) => {
  // when there's no matching entrypoint path is set,
  // we use few heuristics to find an entrypoint file
  // 1. If the function has only a single TS / JS file, if so set it as entrypoint
  const jsFiles = files.filter(
    ({ name }) =>
      name.endsWith('.js') || name.endsWith('.ts') || name.endsWith('.jsx') || name.endsWith('.tsx')
  )
  if (jsFiles.length === 1) {
    return jsFiles[0].name
  } else if (jsFiles.length) {
    // 2. If function has a `index` or `main` file use it as the entrypoint
    const regex = /^.*?(index|main).*$/i
    const matchingFile = jsFiles.find(({ name }) => regex.test(name))
    // 3. if no valid index / main file found, we set the entrypoint expliclty to first JS file
    return matchingFile ? matchingFile.name : jsFiles[0].name
  } else {
    // no potential entrypoint files found, this will most likely result in an error on deploy
    return 'index.ts'
  }
}

Subdomains

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free