Skip to content

Commit 880c4f4

Browse files
authored
refactor: relax ext normalize (#937)
1 parent 8ae13f5 commit 880c4f4

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

src/cli.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,5 @@ export function isMain(
305305
}
306306

307307
export function normalizeExt(ext?: string) {
308-
if (!ext) return
309-
if (!/^\.?\w+(\.\w+)*$/.test(ext)) throw new Error(`Invalid extension ${ext}`)
310-
return ext[0] === '.' ? ext : `.${ext}`
308+
return ext ? path.parse(`foo.${ext}`).ext : ext
311309
}

test/cli.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ describe('cli', () => {
271271
test('normalizeExt()', () => {
272272
assert.equal(normalizeExt('.ts'), '.ts')
273273
assert.equal(normalizeExt('ts'), '.ts')
274+
assert.equal(normalizeExt('.'), '.')
274275
assert.equal(normalizeExt(), undefined)
275-
assert.throws(() => normalizeExt('.'))
276276
})
277277
})

0 commit comments

Comments
 (0)