From 2779e0cbf27266addc4a304d841d4bcebe655c5a Mon Sep 17 00:00:00 2001 From: userquin Date: Sat, 18 May 2024 16:06:22 +0200 Subject: [PATCH 1/2] feat(tsx): fallback to jiti when missing tsconfig.json --- src/import.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/import.ts b/src/import.ts index 5ff42b8..918081d 100644 --- a/src/import.ts +++ b/src/import.ts @@ -89,6 +89,16 @@ export async function importx(_specifier: string | URL, _options: strin case 'tsx': { return import('./loaders/tsx') .then(r => r.loader(info, options)) + .catch((e) => { + if ('message' in e && /tsconfig\.json['"] not found/.test(e.message)) { + console.warn('WARNING: tsconfig.json not found, fallback to jiti loader:') + console.error(e) + return import('./loaders/jiti') + .then(r => r.loader(info, options)) + } + + return Promise.reject(e) + }) } case 'jiti': { From 11a54a8ef77a164d13b256e4da9384afb08e82f8 Mon Sep 17 00:00:00 2001 From: userquin Date: Sat, 18 May 2024 16:07:33 +0200 Subject: [PATCH 2/2] chore: remove redundant WARNING --- src/import.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/import.ts b/src/import.ts index 918081d..41f7929 100644 --- a/src/import.ts +++ b/src/import.ts @@ -91,7 +91,7 @@ export async function importx(_specifier: string | URL, _options: strin .then(r => r.loader(info, options)) .catch((e) => { if ('message' in e && /tsconfig\.json['"] not found/.test(e.message)) { - console.warn('WARNING: tsconfig.json not found, fallback to jiti loader:') + console.warn('tsconfig.json not found, fallback to jiti loader:') console.error(e) return import('./loaders/jiti') .then(r => r.loader(info, options))