Skip to content

Commit

Permalink
perf: reduce maximum depth to search for global CSS files
Browse files Browse the repository at this point in the history
  • Loading branch information
fwouts committed Jun 6, 2023
1 parent 3f225ef commit 349b5b1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
11 changes: 9 additions & 2 deletions core/src/find-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion core/src/previewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 349b5b1

Please sign in to comment.