Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

feat(resolver): support new typescript extensions #51

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions src/resolve-ts-path.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
import path from 'path';

const tsExtensions: Record<string, string> = Object.create(null);
tsExtensions['.js'] = '.ts';
tsExtensions['.cjs'] = '.cts';
tsExtensions['.mjs'] = '.mts';
const tsExtensions: Record<string, string[]> = Object.create(null);
tsExtensions['.js'] = ['.ts', '.tsx', '.js', '.jsx'];
tsExtensions['.jsx'] = ['.tsx', '.ts', '.jsx', '.js'];
tsExtensions['.cjs'] = ['.cts'];
tsExtensions['.mjs'] = ['.mts'];

export const resolveTsPath = (
filePath: string,
) => {
const extension = path.extname(filePath);
const [extensionNoQuery, query] = path.extname(filePath).split('?');
const tsExtension = tsExtensions[extensionNoQuery];
const possibleExtensions = tsExtensions[extensionNoQuery];

if (tsExtension) {
return (
filePath.slice(0, -extension.length)
+ tsExtension
+ (query ? `?${query}` : '')
if (possibleExtensions) {
const extensionlessPath = filePath.slice(0, -extension.length);
return possibleExtensions.map(
tsExtension => (
extensionlessPath
+ tsExtension
+ (query ? `?${query}` : '')
),
);
}
};
Loading