Skip to content

Commit

Permalink
refactor: relax ext normalize (#937)
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub authored Nov 8, 2024
1 parent 8ae13f5 commit 880c4f4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
4 changes: 1 addition & 3 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion test/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('.'))
})
})

0 comments on commit 880c4f4

Please sign in to comment.