From 880c4f4c651b3a4fbd3ce58c8cdad5f2890614d8 Mon Sep 17 00:00:00 2001 From: Anton Golub Date: Fri, 8 Nov 2024 16:33:26 +0300 Subject: [PATCH] refactor: relax ext normalize (#937) --- src/cli.ts | 4 +--- test/cli.test.js | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/cli.ts b/src/cli.ts index be53189a90..6e3ae5cc91 100644 --- a/src/cli.ts +++ b/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 } diff --git a/test/cli.test.js b/test/cli.test.js index 27201dbf67..98b3f08aec 100644 --- a/test/cli.test.js +++ b/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('.')) }) })