From 3f2b3a40317e8c7e27c9060d9c9a7cc7f9f18539 Mon Sep 17 00:00:00 2001 From: gonzaloriestra <14979109+gonzaloriestra@users.noreply.github.com> Date: Mon, 4 May 2026 00:31:45 +0000 Subject: [PATCH] [Refactor] Optimize copyDirectoryContents and clean up knip config This PR introduces a small performance and robustness improvement to the `copyDirectoryContents` utility in `@shopify/cli-kit`. By using the `cwd` option in `glob`, we avoid manual string manipulation to calculate relative paths, which is safer and more efficient. Additionally, I've cleaned up the `knip` configuration by removing unused `ignoreDependencies` for `@graphql-typed-document-node/core`, as flagged by `knip`'s configuration hints. ### WHAT is this pull request doing? - Refactors `copyDirectoryContents` in `packages/cli-kit/src/public/node/fs.ts` to use `glob` with the `cwd` option. - Replaces a `for...of` loop with `.map()` for cleaner asynchronous parallel execution. - Removes unused `ignoreDependencies` from `package.json` for `packages/app` and `packages/cli-kit`. ### How to test your changes? 1. Use a service that relies on asset copying, like `shopify app build`. 2. Verify that assets are correctly copied to the build directory. --- package.json | 5 +---- packages/cli-kit/src/public/node/fs.ts | 14 +++++--------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 0ffe1bf61d1..79e28af6656 100644 --- a/package.json +++ b/package.json @@ -199,7 +199,6 @@ "**/graphql/**/generated/*.ts" ], "ignoreDependencies": [ - "@graphql-typed-document-node/core", "@shopify/plugin-cloudflare" ], "vite": { @@ -292,9 +291,7 @@ "ignoreBinaries": [ "open" ], - "ignoreDependencies": [ - "@graphql-typed-document-node/core" - ], + "ignoreDependencies": [], "vite": { "config": [ "vite.config.ts" diff --git a/packages/cli-kit/src/public/node/fs.ts b/packages/cli-kit/src/public/node/fs.ts index 698edd44992..db528192d35 100644 --- a/packages/cli-kit/src/public/node/fs.ts +++ b/packages/cli-kit/src/public/node/fs.ts @@ -728,16 +728,12 @@ 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((item) => { + const destPath = joinPath(destDir, item) + return copyFile(joinPath(srcDir, item), destPath) + }) await Promise.all(filesToCopy) }