diff --git a/src/filesystem.ts b/src/filesystem.ts index a6773a7..f97747f 100644 --- a/src/filesystem.ts +++ b/src/filesystem.ts @@ -81,7 +81,3 @@ export function fileExistsAsync( callback2(undefined, stats ? stats.isFile() : false); }); } - -export function removeExtension(path: string): string { - return path.substring(0, path.lastIndexOf(".")) || path; -} diff --git a/src/match-path-async.ts b/src/match-path-async.ts index f3e94c2..9673f2a 100644 --- a/src/match-path-async.ts +++ b/src/match-path-async.ts @@ -148,7 +148,6 @@ function findFirstExistingPath( return doneCallback(err); } if (exists) { - // Not sure why we don't just return the full path? Why strip it? return doneCallback(undefined, TryPath.getStrippedPath(tryPath)); } if (index === tryPaths.length - 1) { @@ -180,11 +179,7 @@ function findFirstExistingPath( return doneCallback(mainFieldErr); } if (mainFieldMappedFile) { - // Not sure why we don't just return the full path? Why strip it? - return doneCallback( - undefined, - Filesystem.removeExtension(mainFieldMappedFile) - ); + return doneCallback(undefined, mainFieldMappedFile); } // No field in package json was a valid option. Continue with the next path. diff --git a/src/match-path-sync.ts b/src/match-path-sync.ts index 2c644cf..d7f5bcc 100644 --- a/src/match-path-sync.ts +++ b/src/match-path-sync.ts @@ -118,7 +118,6 @@ function findFirstExistingPath( tryPath.type === "index" ) { if (fileExists(tryPath.path)) { - // Not sure why we don't just return the full path? Why strip it? return TryPath.getStrippedPath(tryPath); } } else if (tryPath.type === "package") { @@ -131,8 +130,7 @@ function findFirstExistingPath( fileExists ); if (mainFieldMappedFile) { - // Not sure why we don't just return the full path? Why strip it? - return Filesystem.removeExtension(mainFieldMappedFile); + return mainFieldMappedFile; } } } else { diff --git a/src/try-path.ts b/src/try-path.ts index d483968..b232417 100644 --- a/src/try-path.ts +++ b/src/try-path.ts @@ -1,7 +1,6 @@ import * as path from "path"; import { MappingEntry } from "./mapping-entry"; import { dirname } from "path"; -import { removeExtension } from "./filesystem"; export interface TryPath { readonly type: "file" | "extension" | "index" | "package"; @@ -60,17 +59,14 @@ export function getPathsToTry( return pathsToTry.length === 0 ? undefined : pathsToTry; } -// Not sure why we don't just return the full found path? export function getStrippedPath(tryPath: TryPath): string { return tryPath.type === "index" ? dirname(tryPath.path) - : tryPath.type === "file" + : tryPath.type === "file" || + tryPath.type === "extension" || + tryPath.type === "package" ? tryPath.path - : tryPath.type === "extension" - ? removeExtension(tryPath.path) - : tryPath.type === "package" - ? tryPath.path - : exhaustiveTypeException(tryPath.type); + : exhaustiveTypeException(tryPath.type); } export function exhaustiveTypeException(check: never): never {