From 607bf625105b254555d7ab18cbeb8beaa83be005 Mon Sep 17 00:00:00 2001 From: Konstantin Kai Date: Sun, 20 Oct 2024 12:52:37 +0300 Subject: [PATCH] fix(vite): use replace only once per function call use replace only once per function in nx-tsconfig-paths-find-file --- packages/vite/src/utils/nx-tsconfig-paths-find-file.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/vite/src/utils/nx-tsconfig-paths-find-file.ts b/packages/vite/src/utils/nx-tsconfig-paths-find-file.ts index 64c1121f4a46c..0f46228dda892 100644 --- a/packages/vite/src/utils/nx-tsconfig-paths-find-file.ts +++ b/packages/vite/src/utils/nx-tsconfig-paths-find-file.ts @@ -6,12 +6,12 @@ export function findFile( extensions: string[], existsSyncImpl: typeof existsSync = existsSync ): string { + const queryLessPath = path.replace(/\?\S*$/, ''); + for (const ext of extensions) { + const dir = dirname(path); // Support file extensions such as .css and .js in the import path. - const [dir, name] = [ - dirname(path), - basename(path.replace(/\?\S*$/, ''), ext), - ]; + const name = basename(queryLessPath, ext); const resolvedPath = resolve(dir, name + ext); if (existsSyncImpl(resolvedPath)) {