Skip to content

Commit

Permalink
refactor(cjs): resolveTsFilename
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed Jun 4, 2024
1 parent 4ef6632 commit a33c96a
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions src/cjs/api/module-resolve-filename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,33 @@ const resolveTsFilename = (
isMain: boolean,
options?: Record<PropertyKey, unknown>,
) => {
const tsPath = resolveTsPath(request);

if (
parent?.filename
&& (
tsExtensionsPattern.test(parent.filename)
|| allowJs
)
&& tsPath
!(parent?.filename && tsExtensionsPattern.test(parent.filename))
&& !allowJs
) {
for (const tryTsPath of tsPath) {
try {
return defaultResolver(
tryTsPath,
parent,
isMain,
options,
);
} catch (error) {
const { code } = error as NodeError;
if (
code !== 'MODULE_NOT_FOUND'
&& code !== 'ERR_PACKAGE_PATH_NOT_EXPORTED'
) {
throw error;
}
return;
}

const tsPath = resolveTsPath(request);
if (!tsPath) {
return;
}

for (const tryTsPath of tsPath) {
try {
return defaultResolver(
tryTsPath,
parent,
isMain,
options,
);
} catch (error) {
const { code } = error as NodeError;
if (
code !== 'MODULE_NOT_FOUND'
&& code !== 'ERR_PACKAGE_PATH_NOT_EXPORTED'
) {
throw error;
}
}
}
Expand All @@ -69,6 +70,7 @@ export const resolveFilename: ResolveFilename = (
request = fileURLToPath(request);
}

// Resolve TS path alias
if (
tsconfigPathsMatcher

Expand Down

0 comments on commit a33c96a

Please sign in to comment.