Commit 880c4f4

Anton Golub <antongolub@antongolub.com>
2024-11-08 14:33:26
refactor: relax ext normalize (#937) tag: 8.2.1
1 parent 8ae13f5
Changed files (2)
src/cli.ts
@@ -305,7 +305,5 @@ export function isMain(
 }
 
 export function normalizeExt(ext?: string) {
-  if (!ext) return
-  if (!/^\.?\w+(\.\w+)*$/.test(ext)) throw new Error(`Invalid extension ${ext}`)
-  return ext[0] === '.' ? ext : `.${ext}`
+  return ext ? path.parse(`foo.${ext}`).ext : ext
 }
test/cli.test.js
@@ -271,7 +271,7 @@ describe('cli', () => {
   test('normalizeExt()', () => {
     assert.equal(normalizeExt('.ts'), '.ts')
     assert.equal(normalizeExt('ts'), '.ts')
+    assert.equal(normalizeExt('.'), '.')
     assert.equal(normalizeExt(), undefined)
-    assert.throws(() => normalizeExt('.'))
   })
 })