From ebd276f853fca65890e3af2b839b798cd853e820 Mon Sep 17 00:00:00 2001 From: yifancong Date: Thu, 4 Jul 2024 11:48:54 +0800 Subject: [PATCH] perf: optimize the package graph algorithm (#412) --- packages/graph/src/graph/package-graph/package.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/graph/src/graph/package-graph/package.ts b/packages/graph/src/graph/package-graph/package.ts index 074b3b6c..6511a0ee 100644 --- a/packages/graph/src/graph/package-graph/package.ts +++ b/packages/graph/src/graph/package-graph/package.ts @@ -91,13 +91,15 @@ export class Package implements SDK.PackageInstance { } contain(file: string) { - const subPath = relative(this.root, file); + const ifCotain = file.includes(this.root); // Non-identical directories. - if (subPath.startsWith('..')) { + if (!ifCotain) { return false; } + const subPath = relative(this.root, file); + // Some modules will be in the node_modules of the current module, and another judgment needs to be made here. return !isPackagePath(subPath); }