Skip to content

Commit f3a5773

Browse files
committed
fix(types): only strip extensions that ts retries
1 parent 2052e89 commit f3a5773

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/core/build/types.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,7 @@ declare module "nitropack/types" {
294294
.catch(() => null /* file does not exist */);
295295
return relativeWithDot(
296296
tsconfigDir,
297-
stats?.isFile()
298-
? path.replace(/(?<=\w)\.\w+$/g, "") /* remove extension */
299-
: path
297+
stats?.isFile() ? stripPathsExt(path) : path
300298
);
301299
})
302300
);
@@ -346,3 +344,11 @@ export function relativeWithDot(from: string, to: string) {
346344
const rel = relative(from, to);
347345
return RELATIVE_RE.test(rel) ? rel : "./" + rel;
348346
}
347+
348+
// Strip only the extensions TS retries from a bare `paths` candidate.
349+
// https://github.com/microsoft/TypeScript/blob/main/src/compiler/moduleNameResolver.ts
350+
const PATHS_STRIPPABLE_EXT_RE = /\.(?:tsx?|jsx?|[cm]js)$/;
351+
352+
export function stripPathsExt(path: string) {
353+
return path.replace(PATHS_STRIPPABLE_EXT_RE, "");
354+
}

0 commit comments

Comments
 (0)