Skip to content

Commit

Permalink
fix: fix import ts from node_modules
Browse files Browse the repository at this point in the history
  • Loading branch information
yeliex committed Dec 2, 2023
1 parent df125c8 commit 29a1156
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/register/esm.mts
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,19 @@ const host: ts.ModuleResolutionHost = {
const EXTENSIONS: string[] = [ts.Extension.Ts, ts.Extension.Tsx, ts.Extension.Mts]

export const resolve: ResolveFn = async (specifier, context, nextResolve) => {
const isTS = EXTENSIONS.some((ext) => specifier.endsWith(ext))

// entrypoint
if (!context.parentURL) {
return {
format: EXTENSIONS.some((ext) => specifier.endsWith(ext)) ? 'ts' : undefined,
format: isTS ? 'ts' : undefined,
url: specifier,
shortCircuit: true,
}
}

// import/require from external library
if (context.parentURL.includes('/node_modules/')) {
if (context.parentURL.includes('/node_modules/') && !isTS) {
return nextResolve(specifier)
}

Expand Down

0 comments on commit 29a1156

Please sign in to comment.