From d0154e1bc8ae69602a92197f4c110c70011ebeee Mon Sep 17 00:00:00 2001 From: SukkaW Date: Thu, 15 Aug 2024 03:58:38 +0800 Subject: [PATCH] Perf: record relative dir instead of calc --- Build/lib/tree-dir.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Build/lib/tree-dir.ts b/Build/lib/tree-dir.ts index 6a17b7d0..7fdc948b 100644 --- a/Build/lib/tree-dir.ts +++ b/Build/lib/tree-dir.ts @@ -1,5 +1,5 @@ import fsp from 'fs/promises'; -import { sep, relative } from 'path'; +import { sep } from 'path'; interface TreeFileType { type: 'file', @@ -22,11 +22,11 @@ type VoidOrVoidArray = void | VoidOrVoidArray[]; export const treeDir = async (rootPath: string): Promise => { const tree: TreeTypeArray = []; - const walk = async (dir: string, node: TreeTypeArray): Promise => { + const walk = async (dir: string, node: TreeTypeArray, dirRelativeToRoot = ''): Promise => { const promises: Array> = []; for await (const child of await fsp.opendir(dir)) { const childFullPath = child.parentPath + sep + child.name; - const childRelativeToRoot = relative(rootPath, childFullPath); + const childRelativeToRoot = dirRelativeToRoot + sep + child.name; if (child.isDirectory()) { const newNode: TreeDirectoryType = { @@ -36,7 +36,7 @@ export const treeDir = async (rootPath: string): Promise => { children: [] }; node.push(newNode); - promises.push(walk(childFullPath, newNode.children)); + promises.push(walk(childFullPath, newNode.children, childRelativeToRoot)); continue; } if (child.isFile()) {