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/refactor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## 2025-05-14 - Use `relativePath` utility for path manipulation

**Learning:** Manual string manipulation for calculating relative paths (e.g., `.replace()`) is brittle and error-prone across different platforms. Using a dedicated `relativePath` utility is safer and more idiomatic.

**Action:** Prefer `relativePath` from `@shopify/cli-kit/node/path` over manual `.replace()` calls when calculating paths relative to a source directory. Use it to avoid variable shadowing and naming collisions (e.g., use `relPath` if `relativePath` is imported).
15 changes: 6 additions & 9 deletions packages/cli-kit/src/public/node/fs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {outputContent, outputToken, outputDebug} from './output.js'
import {joinPath, normalizePath, resolvePath} from './path.js'
import {joinPath, normalizePath, resolvePath, relativePath} from './path.js'
import {OverloadParameters} from '../../private/common/ts/overloaded-parameters.js'
import {getRandomName, RandomNameFamily} from '../common/string.js'
import {systemTempDir} from '../../private/node/temp-dir.js'
Expand Down Expand Up @@ -730,14 +730,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 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 relPath = relativePath(srcDir, item)
const destPath = joinPath(destDir, relPath)
return copyFile(item, destPath)
})

await Promise.all(filesToCopy)
}
Loading