From 349b5b14c649641ea7ab8f132b5ab84aa3f92238 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Wouts?= Date: Tue, 6 Jun 2023 23:02:04 +1000 Subject: [PATCH] perf: reduce maximum depth to search for global CSS files --- core/src/find-files.ts | 11 +++++++++-- core/src/previewer.ts | 5 ++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/core/src/find-files.ts b/core/src/find-files.ts index 69e7392045e..99f20a5e4e5 100644 --- a/core/src/find-files.ts +++ b/core/src/find-files.ts @@ -2,17 +2,24 @@ import fs from "fs-extra"; import { globby } from "globby"; import path from "path"; -export async function findFiles(rootDirPath: string, pattern: string) { +export async function findFiles( + rootDirPath: string, + pattern: string, + options: { + maxDepth?: number; + } = {} +) { const gitRootPath = await findGitRoot(rootDirPath); const relativePath = path.relative(gitRootPath, rootDirPath); const relativePrefix = relativePath ? relativePath + path.sep : ""; const files: string[] = await globby(relativePrefix + pattern, { gitignore: true, - ignore: ["**/node_modules/**"], + ignore: ["**/node_mo ddules/**"], cwd: gitRootPath, absolute: true, followSymbolicLinks: false, suppressErrors: true, + deep: options.maxDepth, }); // Note: in some cases, presumably because of yarn using link diff --git a/core/src/previewer.ts b/core/src/previewer.ts index 2d7de89193d..54eeccca428 100644 --- a/core/src/previewer.ts +++ b/core/src/previewer.ts @@ -169,7 +169,10 @@ export class Previewer { this.options.rootDirPath, `**/@(${GLOBAL_CSS_FILE_NAMES_WITHOUT_EXT.join( "|" - )}).@(${GLOBAL_CSS_EXTS.join("|")})` + )}).@(${GLOBAL_CSS_EXTS.join("|")})`, + { + maxDepth: 3, + } ); const router = express.Router(); router.get(/^\/preview\/.*:[^/]+\/$/, async (req, res) => {