Skip to content

Commit 93c7f10

Browse files
author
Gavin Sharp
committed
use path.extname instead of custom getExt helper for determining loader to use
1 parent 320216a commit 93c7f10

File tree

2 files changed

+2
-13
lines changed

2 files changed

+2
-13
lines changed

src/utils.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,8 @@ import { Format, Loader, TransformOptions } from 'esbuild'
33

44
const loaders = ['js', 'jsx', 'ts', 'tsx', 'json']
55

6-
const getExt = (str: string) => {
7-
const basename = path.basename(str);
8-
const firstDot = basename.indexOf('.');
9-
const lastDot = basename.lastIndexOf('.');
10-
const extname = path.extname(basename).replace(/(\.[a-z0-9]+).*/i, '$1');
11-
12-
if (firstDot === lastDot) return extname
13-
14-
return basename.slice(firstDot, lastDot) + extname
15-
}
16-
176
export const getEsbuildConfig = (options, filename) => {
18-
const ext = getExt(filename),
7+
const ext = path.extname(filename),
198
extName = path.extname(filename).slice(1)
209
const loader = (options?.loaders && options?.loaders[ext]
2110
? options.loaders[ext]

tests/utils.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('getEsbuildConfig', () => {
2828
});
2929
});
3030

31-
xtest('.js loader returns correct config with compound extension', () => {
31+
test('.js loader returns correct config with compound extension', () => {
3232
const config = getEsbuildConfig(
3333
{ loaders: { '.js': 'jsx' } },
3434
'filename.test.js'

0 commit comments

Comments
 (0)