Skip to content

Commit

Permalink
fix: import ts from node_modules (#744)
Browse files Browse the repository at this point in the history
  • Loading branch information
yeliex authored Feb 1, 2024
1 parent b845be9 commit c4485ca
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 c4485ca

Please sign in to comment.