Skip to content

Refactor getAncestorDirs to iterate instead of recurse - #526

Merged
RyanZim merged 1 commit into
masterfrom
ryan/recursive-ancestor-dirs
Aug 20, 2026
Merged

Refactor getAncestorDirs to iterate instead of recurse#526
RyanZim merged 1 commit into
masterfrom
ryan/recursive-ancestor-dirs

Conversation

@RyanZim

@RyanZim RyanZim commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@RyanZim
RyanZim requested a lite review from Copilot August 20, 2026 15:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors getAncestorDirs in index.js to use an iterative loop rather than recursion, aligning with the goal of avoiding recursive call overhead/stack growth while generating ancestor directory paths.

Changes:

  • Replaced the recursive implementation of getAncestorDirs with a while-loop implementation.
  • Preserved the function’s documented output ordering for absolute paths (e.g., ['/imports/components', '/imports', '/']).

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread index.js
Comment on lines +357 to 360
while (current !== root) {
current = path.dirname(current)
ancestors.push(current)
}
@RyanZim
RyanZim merged commit 43e707e into master Aug 20, 2026
7 checks passed
@RyanZim
RyanZim deleted the ryan/recursive-ancestor-dirs branch August 20, 2026 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants