MCPcopy Create free account
hub / github.com/vercel/vercel / findEntrypoint

Function findEntrypoint

packages/backends/src/find-entrypoint.ts:38–106  ·  view source on GitHub ↗
(
  cwd: string
)

Source from the content-addressed store, hash-verified

36 );
37
38export const findEntrypoint = async (
39 cwd: string
40): Promise<string | undefined> => {
41 let packageJsonObject: {
42 main?: string;
43 dependencies?: Record<string, string>;
44 } | null = null;
45 try {
46 const packageJson = await readFile(join(cwd, 'package.json'), 'utf-8');
47 packageJsonObject = JSON.parse(packageJson);
48 } catch (_) {
49 // ignore
50 }
51
52 if (packageJsonObject) {
53 const main =
54 typeof packageJsonObject.main === 'string'
55 ? packageJsonObject.main.trim()
56 : '';
57 if (main) {
58 const abs = resolve(cwd, main);
59 const rel = relative(cwd, abs);
60 if (!rel.startsWith('..') && rel !== '') {
61 try {
62 await readFile(abs, 'utf-8');
63 return rel.split(sep).join('/');
64 } catch {
65 // main missing or unreadable; fall through to filename heuristics
66 }
67 }
68 }
69 }
70
71 let framework: string | undefined;
72 if (packageJsonObject) {
73 framework = frameworks.find(
74 framework => packageJsonObject!.dependencies?.[framework]
75 );
76 }
77
78 if (!framework) {
79 for (const entrypoint of entrypoints) {
80 const entrypointPath = join(cwd, entrypoint);
81 try {
82 await readFile(entrypointPath, 'utf-8');
83 return entrypoint;
84 } catch (_) {
85 // ignore
86 }
87 }
88 }
89
90 const regex = framework ? createFrameworkRegex(framework) : undefined;
91
92 for (const entrypoint of entrypoints) {
93 const entrypointPath = join(cwd, entrypoint);
94 try {
95 const content = await readFile(entrypointPath, 'utf-8');

Callers 4

findEntrypointOrThrowFunction · 0.70
detectEntrypointFunction · 0.70

Calls 9

relativeFunction · 0.85
splitMethod · 0.80
testMethod · 0.80
createFrameworkRegexFunction · 0.70
readFileFunction · 0.50
resolveFunction · 0.50
parseMethod · 0.45
joinMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected