From 3050146c5f454ecc277ca7a4b9b56dacfc5f14c7 Mon Sep 17 00:00:00 2001 From: Kristian Jones Date: Tue, 12 May 2020 17:37:09 -0500 Subject: [PATCH] Revert "fix(resolve): Don't run findFiles if we can already see an extension." This reverts commit a00c4464f5a863db33fdd84f2f4c1e26dac0af67. --- src/index.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index 11b52b3..00065bf 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,11 +18,10 @@ const rootModulePath = `${process.cwd()}/`; const baseURL = pathToFileURL(rootModulePath).href; const relativePathRegex = /^\.{1,2}[/]/; -const hasExtensionRegex = /\.\w+$/; // TODO: Allow customization of extensions const extensions = ['.ts', '.tsx']; -const extensionsRegex = new RegExp(`\\${extensions.join('|\\')}`); +const extensionsRegex = new RegExp(`\\${extensions.join('$|\\')}`); // Custom resolver to allow `.ts` and `.tsx` extensions, along with finding files if no extension is provided. export async function resolve( @@ -40,14 +39,14 @@ export async function resolve( // Node.js normally errors on unknown file extensions, so return a URL for // specifiers ending in the TypeScript file extensions. return { - url: resolvedUrl.href, + url: new URL(specifier, parentURL).href, }; } /** * If no extension is passed and is a relative import then let's try to find a `.ts` or `.tsx` file at the path */ - if (relativePathRegex.test(specifier) && !hasExtensionRegex.test(fileName)) { + if (relativePathRegex.test(specifier)) { const filePath = fileURLToPath(resolvedUrl); const file = await findFiles(dirname(filePath), {