[Performance] Optimize copyDirectoryContents with glob cwd#7452
[Performance] Optimize copyDirectoryContents with glob cwd#7452gonzaloriestra wants to merge 1 commit into
Conversation
Optimized `copyDirectoryContents` in `@shopify/cli-kit` by using the `cwd` option in `glob` to retrieve relative paths directly. This eliminates the need for manual absolute-to-relative path transformation using string replacement and regex on every file, which is more efficient and robust across different platforms.
Key changes:
- Updated `glob` call to use `{cwd: srcDir}`.
- Removed `item.replace(srcDir, '')` logic.
- Simplified path construction in the copy loop.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
What was improved
Optimized the
copyDirectoryContentsfunction in@shopify/cli-kitto be faster and more robust by using thecwdoption inglob.Why it was improved
The previous implementation fetched absolute paths and then used string replacement and regex to strip the source directory prefix for every item found. This is inefficient, especially for directories with many files, and can be brittle due to path separator differences. Using
cwdallows the globbing engine to provide relative paths directly, which is faster and more reliable.How to test your changes?
You can verify that directory copying still works correctly by running the existing unit tests:
cd packages/cli-kit pnpm vitest run src/public/node/fs.test.tsThe tests
copyDirectoryContents > copies the contents of source directory to destination directoryand its variations confirm that files and nested directories are still copied as expected.PR created automatically by Jules for task 3559203706858836990 started by @gonzaloriestra