MCPcopy
hub / github.com/TypeStrong/ts-node / entrypointFallback

Function entrypointFallback

src/esm.ts:164–195  ·  view source on GitHub ↗
(
      cb: () => ReturnType<typeof resolve> | Awaited<ReturnType<typeof resolve>>
    )

Source from the content-addressed store, hash-verified

162 // See: https://github.com/nodejs/node/discussions/41711
163 // nodejs will likely implement a similar fallback. Till then, we can do our users a favor and fallback today.
164 async function entrypointFallback(
165 cb: () => ReturnType<typeof resolve> | Awaited<ReturnType<typeof resolve>>
166 ): ReturnType<typeof resolve> {
167 try {
168 const resolution = await cb();
169 if (
170 resolution?.url &&
171 isProbablyEntrypoint(specifier, context.parentURL)
172 )
173 rememberIsProbablyEntrypoint.add(resolution.url);
174 return resolution;
175 } catch (esmResolverError) {
176 if (!isProbablyEntrypoint(specifier, context.parentURL))
177 throw esmResolverError;
178 try {
179 let cjsSpecifier = specifier;
180 // Attempt to convert from ESM file:// to CommonJS path
181 try {
182 if (specifier.startsWith('file://'))
183 cjsSpecifier = fileURLToPath(specifier);
184 } catch {}
185 const resolution = pathToFileURL(
186 createRequire(process.cwd()).resolve(cjsSpecifier)
187 ).toString();
188 rememberIsProbablyEntrypoint.add(resolution);
189 rememberResolvedViaCommonjsFallback.add(resolution);
190 return { url: resolution, format: 'commonjs' };
191 } catch (commonjsResolverError) {
192 throw esmResolverError;
193 }
194 }
195 }
196
197 return addShortCircuitFlag(async () => {
198 const parsed = parseUrl(specifier);

Callers 2

resolveFunction · 0.85
getFormatFunction · 0.85

Calls 4

createRequireFunction · 0.90
isProbablyEntrypointFunction · 0.85
addMethod · 0.80
toStringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…