From a8bc5b7bd0ac58cd4d5eecbb63569072d1c85df4 Mon Sep 17 00:00:00 2001 From: gonzaloriestra <14979109+gonzaloriestra@users.noreply.github.com> Date: Sun, 12 Jul 2026 00:47:33 +0000 Subject: [PATCH] [Refactor] Improve readability of relativizePath - Use early returns to simplify logic. - Use descriptive variable names (commonParent, upLevels). - Preserve existing behavior and cross-platform compatibility. --- packages/cli-kit/src/public/node/path.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/cli-kit/src/public/node/path.ts b/packages/cli-kit/src/public/node/path.ts index f3721780110..ffaed935379 100644 --- a/packages/cli-kit/src/public/node/path.ts +++ b/packages/cli-kit/src/public/node/path.ts @@ -133,14 +133,15 @@ export function commonParentDirectory(first: string, second: string): string { * @returns Relativized path. */ export function relativizePath(path: string, dir: string = cwd()): string { - const result = commonParentDirectory(path, dir) + const commonParent = commonParentDirectory(path, dir) const relativePath = relative(dir, path) - const relativeComponents = relativePath.split('/').filter((component) => component === '..').length - if (result === '/' || relativePath === '' || relativeComponents > 2) { + const upLevels = relativePath.split('/').filter((component) => component === '..').length + + if (commonParent === '/' || relativePath === '' || upLevels > 2) { return path - } else { - return relativePath } + + return relativePath } /**