From 89621bf3ada0df8dd44c140991008d5d9e598fb6 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Sat, 8 Jun 2024 10:11:27 +0900 Subject: [PATCH] fix(esm): resolve .ts extension in imports map fixes https://github.com/privatenumber/tsx/issues/579 --- src/esm/hook/resolve.ts | 7 +++++-- tests/fixtures.ts | 6 +++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/esm/hook/resolve.ts b/src/esm/hook/resolve.ts index 7a1959b81..2f6ca4ee1 100644 --- a/src/esm/hook/resolve.ts +++ b/src/esm/hook/resolve.ts @@ -161,8 +161,11 @@ export const resolve: resolve = async ( // If `allowJs` is set in `tsconfig.json`, then we'll apply the same resolution logic // to files without a TypeScript extension. if ( - // Ignore if it's a bare package name and there's no subpath - !isBarePackageName.test(specifier) + ( + specifier.startsWith('#') + // Ignore if it's a bare package name and there's no subpath + || !isBarePackageName.test(specifier) + ) && ( tsExtensionsPattern.test(context.parentURL!) || allowJs diff --git a/tests/fixtures.ts b/tests/fixtures.ts index 3afa2e5da..90acdcbd9 100644 --- a/tests/fixtures.ts +++ b/tests/fixtures.ts @@ -272,10 +272,14 @@ export const files = { 'package.json': createPackageJson({ type: 'module', main: './index.js', + imports: { + '#*': './*', + }, }), 'index.js': `${syntaxLowering}\nexport * from "./empty-export"`, - 'ts.ts': syntaxLowering, 'empty-export/index.js': 'export {}', + 'ts.ts': `${syntaxLowering}\nexport * from "#empty.js"`, + 'empty.ts': 'export {}', }, }, };