From 132193aa0da843500e1423c2d33a5ebb333690a1 Mon Sep 17 00:00:00 2001 From: gonzaloriestra <14979109+gonzaloriestra@users.noreply.github.com> Date: Fri, 24 Jul 2026 00:31:36 +0000 Subject: [PATCH] [Refactor] Use early return and rename relativeComponents in relativizePath Refactored `relativizePath` in `packages/cli-kit/src/public/node/path.ts` to replace the imperative `if/else` block with an early return, improving readability and maintainability. Also renamed the variable `relativeComponents` to `upLevels` to better reveal its intent. --- packages/cli-kit/src/public/node/path.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/cli-kit/src/public/node/path.ts b/packages/cli-kit/src/public/node/path.ts index f3721780110..89ecf541e72 100644 --- a/packages/cli-kit/src/public/node/path.ts +++ b/packages/cli-kit/src/public/node/path.ts @@ -135,12 +135,11 @@ export function commonParentDirectory(first: string, second: string): string { export function relativizePath(path: string, dir: string = cwd()): string { const result = 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 (result === '/' || relativePath === '' || upLevels > 2) { return path - } else { - return relativePath } + return relativePath } /**