From aa120fbcf7ecda973af6a58c68e824b6d0fc5a01 Mon Sep 17 00:00:00 2001 From: gonzaloriestra <14979109+gonzaloriestra@users.noreply.github.com> Date: Fri, 8 May 2026 00:16:21 +0000 Subject: [PATCH] [Refactor] Optimize copyDirectoryContents with glob cwd Optimizes the `copyDirectoryContents` function in `cli-kit` by using the `cwd` option in `glob` instead of manual path manipulation. This reduces overhead and makes the code more robust against platform-specific path issues. --- packages/cli-kit/src/public/node/fs.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/packages/cli-kit/src/public/node/fs.ts b/packages/cli-kit/src/public/node/fs.ts index 698edd44992..4d3c0e76974 100644 --- a/packages/cli-kit/src/public/node/fs.ts +++ b/packages/cli-kit/src/public/node/fs.ts @@ -728,16 +728,11 @@ export async function copyDirectoryContents(srcDir: string, destDir: string): Pr } // Get all files and directories in the source directory - const items = await glob(joinPath(srcDir, '**/*')) + const items = await glob('**/*', {cwd: srcDir}) - const filesToCopy = [] - - for (const item of items) { - const relativePath = item.replace(srcDir, '').replace(/^[/\\]/, '') - const destPath = joinPath(destDir, relativePath) - - filesToCopy.push(copyFile(item, destPath)) - } + const filesToCopy = items.map((relativePath) => { + return copyFile(joinPath(srcDir, relativePath), joinPath(destDir, relativePath)) + }) await Promise.all(filesToCopy) }