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

Commit 5d9f24f

Browse files
fix: support query in specifier (#50)
1 parent e013ed6 commit 5d9f24f

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/resolve-ts-path.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
import path from 'path';
22

3-
const tsExtensions: Record<string, string> = {
4-
'.js': '.ts',
5-
'.cjs': '.cts',
6-
'.mjs': '.mts',
7-
};
3+
const tsExtensions: Record<string, string> = Object.create(null);
4+
tsExtensions['.js'] = '.ts';
5+
tsExtensions['.cjs'] = '.cts';
6+
tsExtensions['.mjs'] = '.mts';
87

9-
export function resolveTsPath(filePath: string) {
8+
export const resolveTsPath = (
9+
filePath: string,
10+
) => {
1011
const extension = path.extname(filePath);
11-
const tsExtension = tsExtensions[extension];
12+
const [extensionNoQuery, query] = path.extname(filePath).split('?');
13+
const tsExtension = tsExtensions[extensionNoQuery];
1214

1315
if (tsExtension) {
14-
return filePath.slice(0, -extension.length) + tsExtension;
16+
return (
17+
filePath.slice(0, -extension.length)
18+
+ tsExtension
19+
+ (query ? `?${query}` : '')
20+
);
1521
}
16-
}
22+
};

0 commit comments

Comments
 (0)