Skip to content

Commit

Permalink
Revert "fix(resolve): Don't run findFiles if we can already see an ex…
Browse files Browse the repository at this point in the history
…tension."

This reverts commit a00c446.
  • Loading branch information
EntraptaJ committed May 12, 2020
1 parent 044da67 commit 3050146
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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), {
Expand Down

0 comments on commit 3050146

Please sign in to comment.