Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## 2025-05-15 - [Performance] Optimize copyDirectoryContents using glob cwd

**Learning:** Using the `cwd` option in `glob` is more efficient than passing an absolute path and then manually stripping the source directory string to calculate relative destination paths. It reduces manual string manipulation and allows the globbing engine to work with shorter paths.

**Action:** Prefer `cwd` option in `glob` calls when relative paths from a base directory are needed.
9 changes: 5 additions & 4 deletions packages/cli-kit/src/public/node/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -728,15 +728,16 @@ export async function copyDirectoryContents(srcDir: string, destDir: string): Pr
}

// Get all files and directories in the source directory
const items = await glob(joinPath(srcDir, '**/*'))
// Optimization: Using the `cwd` option in `glob` is more efficient than passing an absolute path
// and then manually stripping the source directory string to calculate relative destination paths.
const items = await glob('**/*', {cwd: srcDir})

const filesToCopy = []

for (const item of items) {
const relativePath = item.replace(srcDir, '').replace(/^[/\\]/, '')
const destPath = joinPath(destDir, relativePath)
const destPath = joinPath(destDir, item)

filesToCopy.push(copyFile(item, destPath))
filesToCopy.push(copyFile(joinPath(srcDir, item), destPath))
}

await Promise.all(filesToCopy)
Expand Down
Loading