From 93955e699b0b5d4189ee0d70b89205fc176e5443 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Thu, 9 Nov 2023 12:02:50 +0900 Subject: [PATCH] feat(resolver): support tsx,jsx extensions (#367) --- src/cjs/index.ts | 30 ++++++++++++++++-------------- tests/specs/smoke.ts | 6 +++--- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/cjs/index.ts b/src/cjs/index.ts index e119ec7d6..ca3e07c3f 100644 --- a/src/cjs/index.ts +++ b/src/cjs/index.ts @@ -197,20 +197,22 @@ const resolveTsFilename = ( && isTsFilePatten.test(parent.filename) && tsPath ) { - try { - return defaultResolveFilename( - tsPath[0], - parent, - isMain, - options, - ); - } catch (error) { - const { code } = error as NodeError; - if ( - code !== 'MODULE_NOT_FOUND' - && code !== 'ERR_PACKAGE_PATH_NOT_EXPORTED' - ) { - throw error; + for (const tryTsPath of tsPath) { + try { + return defaultResolveFilename( + tryTsPath, + parent, + isMain, + options, + ); + } catch (error) { + const { code } = error as NodeError; + if ( + code !== 'MODULE_NOT_FOUND' + && code !== 'ERR_PACKAGE_PATH_NOT_EXPORTED' + ) { + throw error; + } } } } diff --git a/tests/specs/smoke.ts b/tests/specs/smoke.ts index cfa786255..f4dba0a6b 100644 --- a/tests/specs/smoke.ts +++ b/tests/specs/smoke.ts @@ -515,19 +515,19 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { // .ts import './ts/index.ts'; import './ts/index.js'; - // import './ts/index.jsx'; + import './ts/index.jsx'; import './ts/index'; import './ts/'; // .jsx import * as jsx from './jsx/index.jsx'; - // import './jsx/index.js'; + import './jsx/index.js'; import './jsx/index'; import './jsx/'; // .tsx import './tsx/index.tsx'; - // import './tsx/index.js'; + import './tsx/index.js'; import './tsx/index.jsx'; import './tsx/index'; import './tsx/';