Skip to content

refactor!: change findUp signature, support search root#408

Merged
JounQin merged 1 commit intomasterfrom
refactor/find-up
Jun 1, 2025
Merged

refactor!: change findUp signature, support search root#408
JounQin merged 1 commit intomasterfrom
refactor/find-up

Conversation

@JounQin
Copy link
Member

@JounQin JounQin commented Jun 1, 2025

Important

Refactor findUp in helpers.ts for flexible file searching, update Node.js requirements, and modify workflows for specific action versions.

  • Refactor:
    • Change findUp function signature in helpers.ts to support FindUpOptions for more flexible file searching.
    • Add tryFileStats function in helpers.ts for detailed file stats retrieval.
    • Update tryFile to use tryFileStats in helpers.ts.
  • Node.js Version:
    • Remove support for Node.js 12 in package.json.
  • Workflows:
    • Update actions/checkout to use version v4.2.2 in multiple workflow files.

This description was created by Ellipsis for 0bc4a98. You can customize this summary. It will automatically update as commits are pushed.


Summary by CodeRabbit

  • New Features
    • Enhanced file and directory search functionality with more flexible options and improved type safety.
  • Refactor
    • Updated the file and directory search logic for greater flexibility and configurability.
  • Chores
    • Updated Node.js version requirements, removing support for Node.js 12.
    • Updated workflow configuration to use a more specific version tag for repository checkout actions.

@JounQin JounQin requested a review from Copilot June 1, 2025 05:35
@JounQin JounQin self-assigned this Jun 1, 2025
@JounQin JounQin added enhancement New feature or request breaking refactor labels Jun 1, 2025
@changeset-bot
Copy link

changeset-bot bot commented Jun 1, 2025

🦋 Changeset detected

Latest commit: 0bc4a98

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@pkgr/core Minor
@pkgr/utils Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link

coderabbitai bot commented Jun 1, 2025

Walkthrough

The update refactors the findUp function in the @pkgr/core package to support specifying a search root and improve file type checks. It introduces a new type-safe tryFileStats function, modifies Node.js engine requirements, and updates GitHub workflows to use a more specific checkout action version.

Changes

Files Change Summary
packages/core/src/helpers.ts Added tryFileStats function; refactored tryFile as wrapper; changed findUp signature and logic to support search root and enhanced type safety
packages/core/package.json Node.js engine requirement changed to exclude ^12.20.0, now `^14.18.0
.github/workflows/*.yml Updated actions/checkout version comment from v4 to v4.2.2 in all workflow files without other changes
.changeset/poor-walls-arrive.md Added changeset documenting the breaking change to findUp function signature

Error: Could not generate a valid Mermaid diagram after multiple attempts.

🐇
A root to seek, a path to find,
With types and checks now well-defined.
From workflows neat to core refined,
The code hops forward, swift and kind.

A checkout tag, precise and true,
Node versions trimmed, just for you.
In every line, a change anew—
The rabbit’s joy in code’s bright hue! 🥕✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/core/src/helpers.ts

Oops! Something went wrong! :(

ESLint: 9.28.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@1stg/eslint-config' imported from /eslint.config.js
at Object.getPackageJSONURL (node:internal/modules/package_json_reader:255:9)
at packageResolve (node:internal/modules/esm/resolve:767:81)
at moduleResolve (node:internal/modules/esm/resolve:853:18)
at defaultResolve (node:internal/modules/esm/resolve:983:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:799:12)
at #cachedDefaultResolve (node:internal/modules/esm/loader:723:25)
at ModuleLoader.resolve (node:internal/modules/esm/loader:706:38)
at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:307:38)
at #link (node:internal/modules/esm/module_job:170:49)

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jun 1, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request refactors the findUp function signature to support a custom search root and introduces new file type definitions while updating Node engine requirements and GitHub Actions versions.

  • Refactored the findUp signature to accept an options object with additional file search parameters.
  • Added new types and improved file lookup functions (tryFileStats and tryFile).
  • Updated Node.js engine requirements and GitHub Actions checkout versions.

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/core/src/helpers.ts Modified file lookup functions and refactored findUp to support a search root.
packages/core/package.json Updated Node engine version requirements.
.github/workflows/vercel.yml Updated checkout action version.
.github/workflows/release.yml Updated checkout action version.
.github/workflows/pkg-size.yml Updated checkout action version.
.github/workflows/pkg-pr-new.yml Updated checkout action version.
.github/workflows/ci.yml Updated checkout action version.
.github/workflows/autofix.yml Updated checkout action version.

@codecov
Copy link

codecov bot commented Jun 1, 2025

Codecov Report

Attention: Patch coverage is 0% with 61 lines in your changes missing coverage. Please review.

Project coverage is 9.13%. Comparing base (7f30c63) to head (0bc4a98).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
packages/core/src/helpers.ts 0.00% 61 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##           master    #408      +/-   ##
=========================================
- Coverage    9.85%   9.13%   -0.73%     
=========================================
  Files          12      12              
  Lines         426     460      +34     
  Branches      186     206      +20     
=========================================
  Hits           42      42              
- Misses        384     418      +34     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 1, 2025

📊 Package size report   No changes

File Before After
Total (Includes all files) 3.1 MB 3.1 MB
Tarball size 1.1 MB 1.1 MB
Unchanged files
File Size
.changeset/config.json 309 B
.changeset/README.md 510 B
.changeset/short-pets-beam.md 122 B
.codesandbox/ci.json 76 B
.editorconfig 145 B
.gitattributes 35 B
.github/workflows/autofix.yml 917 B
.github/workflows/ci.yml 1.7 kB
.github/workflows/pkg-pr-new.yml 641 B
.github/workflows/pkg-size.yml 723 B
.github/workflows/release.yml 1.5 kB
.github/workflows/vercel.yml 1.0 kB
.markuplintrc 43 B
.nano-staged.js 48 B
.nvmrc 6 B
.prettierignore 6 B
.remarkrc 42 B
.renovaterc 49 B
.simple-git-hooks.js 49 B
.stylelintignore 99 B
.stylelintrc 42 B
.yarn/plugins/plugin-prepare-lifecycle.cjs 202 B
.yarn/releases/yarn-4.9.1.cjs 3.0 MB
.yarnrc.yml 397 B
CHANGELOG.md 486 B
docs/App.tsx 1.2 kB
docs/global.css 321 B
docs/index.tsx 299 B
eslint.config.js 302 B
index.html 402 B
LICENSE 1.1 kB
package.json 3.0 kB
packages/browser/CHANGELOG.md 1.4 kB
packages/browser/index.d.cts 60 B
packages/browser/index.ts 4.7 kB
packages/browser/openChrome.applescript 2.5 kB
packages/browser/package.json 998 B
packages/browser/tsconfig.json 139 B
packages/core/CHANGELOG.md 2.5 kB
packages/core/index.d.cts 54 B
packages/core/package.json 957 B
packages/core/src/constants.ts 538 B
packages/core/src/helpers.ts 1.9 kB
packages/core/src/index.ts 60 B
packages/core/tsconfig.json 154 B
packages/es-modules/CHANGELOG.md 5.2 kB
packages/es-modules/index.d.cts 64 B
packages/es-modules/index.ts 1.4 kB
packages/es-modules/package.json 1.0 kB
packages/es-modules/README.md 3.7 kB
packages/es-modules/test/test.spec.ts 936 B
packages/es-modules/tsconfig.json 139 B
packages/imagemin/CHANGELOG.md 9.0 kB
packages/imagemin/index.d.cts 57 B
packages/imagemin/package.json 1.3 kB
packages/imagemin/src/cli.ts 508 B
packages/imagemin/src/index.ts 1.2 kB
packages/imagemin/tsconfig.json 154 B
packages/rollup/CHANGELOG.md 22.0 kB
packages/rollup/package.json 1.5 kB
packages/rollup/shim.d.ts 647 B
packages/rollup/src/cli.ts 4.0 kB
packages/rollup/src/config.ts 11.9 kB
packages/rollup/tsconfig.json 132 B
packages/umd-globals/CHANGELOG.md 6.2 kB
packages/umd-globals/index.d.cts 66 B
packages/umd-globals/index.ts 1.8 kB
packages/umd-globals/package.json 919 B
packages/umd-globals/README.md 3.4 kB
packages/umd-globals/test/test.spec.ts 1.9 kB
packages/umd-globals/tsconfig.json 139 B
packages/utils/CHANGELOG.md 12.2 kB
packages/utils/index.d.cts 51 B
packages/utils/package.json 961 B
packages/utils/src/constants.ts 497 B
packages/utils/src/helpers.ts 2.8 kB
packages/utils/src/index.ts 117 B
packages/utils/src/monorepo.ts 691 B
packages/utils/tsconfig.json 154 B
README.md 4.1 kB
test/global.d.ts 41 B
test/tsconfig.json 96 B
tsconfig.base.json 172 B
tsconfig.json 395 B
vercel.json 190 B
vite.config.ts 544 B
vitest.config.ts 342 B

🤖 This report was automatically generated by pkg-size-action

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jun 1, 2025

Open in StackBlitz

@pkgr/browser

npm i https://pkg.pr.new/@pkgr/browser@408

@pkgr/core

npm i https://pkg.pr.new/@pkgr/core@408

@pkgr/es-modules

npm i https://pkg.pr.new/@pkgr/es-modules@408

@pkgr/imagemin

npm i https://pkg.pr.new/@pkgr/imagemin@408

@pkgr/rollup

npm i https://pkg.pr.new/@pkgr/rollup@408

@pkgr/umd-globals

npm i https://pkg.pr.new/@pkgr/umd-globals@408

@pkgr/utils

npm i https://pkg.pr.new/@pkgr/utils@408

commit: 0bc4a98

@github-actions
Copy link
Contributor

github-actions bot commented Jun 1, 2025

Deploy preview for pkgr ready!

✅ Preview
https://pkgr-n621fk9br-1stg.vercel.app

Built with commit 0bc4a98.
This pull request is being automatically deployed with vercel-action

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Caution

Changes requested ❌

Reviewed everything up to 08ed60d in 2 minutes and 18 seconds. Click for details.
  • Reviewed 253 lines of code in 8 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. packages/core/package.json:11
  • Draft comment:
    Node engine support was changed by dropping Node 12. Confirm that this breaking change is intentional.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50% The comment violates the rule about not asking authors to confirm their intentions. The change is clear and deliberate - they specifically removed Node 12 from the engines field. This is a common type of breaking change when dropping support for older Node versions. There's no ambiguity here that needs confirmation. The comment does point out an important breaking change that could affect users. Maybe it's valuable to highlight this? While breaking changes are important, the rules explicitly state not to ask authors to confirm their intentions. The author clearly made this change deliberately. Delete the comment. Asking for confirmation of an intentional breaking change violates the review rules and adds no value.

Workflow ID: wflow_lciWVpm9vDz0bsAK

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@JounQin JounQin force-pushed the refactor/find-up branch from cc18c83 to 933debc Compare June 1, 2025 05:43
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Important

Looks good to me! 👍

Reviewed 933debc in 1 minute and 52 seconds. Click for details.
  • Reviewed 264 lines of code in 9 files
  • Skipped 0 files when reviewing.
  • Skipped posting 5 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. packages/core/package.json:11
  • Draft comment:
    Breaking: Node engine update drops Node 12 support. Ensure consumers are aware and documentation is updated.
  • Reason this comment was not posted:
    Comment did not seem useful. Confidence is useful = 20% <= threshold 50% The comment is informative and suggests ensuring that consumers are aware and documentation is updated. It doesn't provide a specific code suggestion or ask for a specific test to be written. It also doesn't ask for confirmation of intention in a specific way. Therefore, it seems to violate the rules.
2. packages/core/src/helpers.ts:37
  • Draft comment:
    Redundant check for 'type' since it's already defaulted to 'file' in the function signature.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50% While the default parameter prevents undefined, the check !type would also catch false and empty arrays, which are valid FileTypes values. This makes the check actually useful as a way to normalize falsy values to 'file'. The comment is incorrect in assuming the check is redundant just because of the default parameter. Am I sure that normalizing falsy values to 'file' is the intended behavior? Maybe this is actually a bug and falsy values should be handled differently? Given that 'file' is used as both the default parameter and the fallback value in the check, it seems this normalization is intentional design rather than a bug. The comment should be deleted because the check serves a purpose beyond just handling undefined - it normalizes any falsy FileTypes value to 'file'.
3. packages/core/src/helpers.ts:46
  • Draft comment:
    Dynamic property access on 'stats' may risk runtime errors if an invalid 'type' is passed. Consider validating supported types.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50% The code is actually well-typed and safe. FileTypeBase type ensures only valid values can be passed. The type casting ensures TypeScript knows it's safe. The capitalization logic matches the fs.Stats method names exactly. The isAnyFileType check provides an escape hatch. This is a common pattern for type-safe dynamic property access. I could be overlooking edge cases where the type parameter could be manipulated at runtime to contain invalid values despite the TypeScript types. Even with runtime manipulation, the code would still only access properties that match the pattern is[Type] where Type is capitalized - these correspond exactly to the fs.Stats methods. The comment should be deleted as the dynamic property access is actually type-safe and well-designed.
4. packages/core/src/helpers.ts:122
  • Draft comment:
    The loop termination condition in findUp is non-intuitive. Consider revising it (possibly using '&&' instead of '||') for clarity and correctness.
  • Reason this comment was not posted:
    Comment looked like it was already resolved.
5. packages/core/src/helpers.ts:81
  • Draft comment:
    Breaking change: 'findUp' signature now accepts an options object instead of a simple string. Ensure all consumers are updated and docs reflect the new API.
  • Reason this comment was not posted:
    Comment did not seem useful. Confidence is useful = 0% <= threshold 50% The comment is informative and suggests ensuring that all consumers are updated and documentation reflects the new API. It doesn't provide a specific code suggestion or ask for a test to be written. It violates the rule against making purely informative comments.

Workflow ID: wflow_aMMiArjuoMWIES98

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (3)
packages/core/src/helpers.ts (3)

74-79: Add documentation for the FindUpOptions interface.

Please add JSDoc comments to describe each property and their expected usage for better developer experience.

+/**
+ * Options for the findUp function
+ * @property {string} [entry] - The starting directory or file path for the search
+ * @property {string} [filename] - The filename to search for
+ * @property {FileType} [type] - The expected file type
+ * @property {string} [stop] - The directory path where the search should stop
+ */
 export interface FindUpOptions {
   entry?: string
   filename?: string
   type?: FileType
   stop?: string
 }

37-39: ⚠️ Potential issue

Check for undefined instead of falsy values.

Using !type may override an explicit false value. Consider checking specifically for undefined.

-  if (!type) {
-    type = 'file'
-  }
+  if (type === undefined) {
+    type = 'file'
+  }
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 38-38: packages/core/src/helpers.ts#L38
Added line #L38 was not covered by tests


122-122: ⚠️ Potential issue

Fix the while loop condition to prevent potential infinite loops.

The current condition has logical issues:

  • If stop is undefined, the loop continues indefinitely due to !stop
  • The condition continues when entry starts with the stop path, which seems backwards
-  } while (!stop || entry !== stop || entry.startsWith(stop + path.sep))
+  } while (!stop || (entry !== stop && entry.startsWith(stop + path.sep)))
🧹 Nitpick comments (1)
.changeset/poor-walls-arrive.md (1)

5-5: Include package scope in the summary.

To improve clarity in your changelog and align with Conventional Commits, consider adding the package scope in the summary. For example:

refactor(core)!: change `findUp` signature, support search root

This makes it explicit which package is affected.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7f30c63 and 933debc.

📒 Files selected for processing (9)
  • .changeset/poor-walls-arrive.md (1 hunks)
  • .github/workflows/autofix.yml (1 hunks)
  • .github/workflows/ci.yml (1 hunks)
  • .github/workflows/pkg-pr-new.yml (1 hunks)
  • .github/workflows/pkg-size.yml (1 hunks)
  • .github/workflows/release.yml (1 hunks)
  • .github/workflows/vercel.yml (1 hunks)
  • packages/core/package.json (1 hunks)
  • packages/core/src/helpers.ts (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/core/src/helpers.ts (1)
packages/core/src/constants.ts (2)
  • CWD (5-5)
  • EXTENSIONS (20-20)
🪛 GitHub Check: codecov/patch
packages/core/src/helpers.ts

[warning] 12-12: packages/core/src/helpers.ts#L12
Added line #L12 was not covered by tests


[warning] 27-27: packages/core/src/helpers.ts#L27
Added line #L27 was not covered by tests


[warning] 29-30: packages/core/src/helpers.ts#L29-L30
Added lines #L29 - L30 were not covered by tests


[warning] 32-32: packages/core/src/helpers.ts#L32
Added line #L32 was not covered by tests


[warning] 36-36: packages/core/src/helpers.ts#L36
Added line #L36 was not covered by tests


[warning] 38-38: packages/core/src/helpers.ts#L38
Added line #L38 was not covered by tests


[warning] 43-43: packages/core/src/helpers.ts#L43
Added line #L43 was not covered by tests


[warning] 45-45: packages/core/src/helpers.ts#L45
Added line #L45 was not covered by tests


[warning] 47-47: packages/core/src/helpers.ts#L47
Added line #L47 was not covered by tests


[warning] 51-52: packages/core/src/helpers.ts#L51-L52
Added lines #L51 - L52 were not covered by tests


[warning] 56-56: packages/core/src/helpers.ts#L56
Added line #L56 was not covered by tests


[warning] 58-58: packages/core/src/helpers.ts#L58
Added line #L58 was not covered by tests


[warning] 63-63: packages/core/src/helpers.ts#L63
Added line #L63 was not covered by tests


[warning] 86-86: packages/core/src/helpers.ts#L86
Added line #L86 was not covered by tests


[warning] 95-95: packages/core/src/helpers.ts#L95
Added line #L95 was not covered by tests


[warning] 98-98: packages/core/src/helpers.ts#L98
Added line #L98 was not covered by tests


[warning] 104-104: packages/core/src/helpers.ts#L104
Added line #L104 was not covered by tests


[warning] 107-107: packages/core/src/helpers.ts#L107
Added line #L107 was not covered by tests


[warning] 113-113: packages/core/src/helpers.ts#L113
Added line #L113 was not covered by tests


[warning] 117-118: packages/core/src/helpers.ts#L117-L118
Added lines #L117 - L118 were not covered by tests


[warning] 120-120: packages/core/src/helpers.ts#L120
Added line #L120 was not covered by tests

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (7)
.github/workflows/autofix.yml (1)

19-19: Consistent checkout action version pinning
The actions/checkout step now explicitly annotates v4.2.2, matching the pinned SHA and aligning with other workflows. Improves clarity on the exact version in use.

.github/workflows/pkg-size.yml (1)

19-19: Consistent checkout action version pinning
Updated the actions/checkout step to annotate v4.2.2 alongside the existing SHA, keeping it in sync with the other CI workflows.

.github/workflows/ci.yml (1)

28-28: Consistent checkout action version pinning
The actions/checkout step now includes the precise v4.2.2 tag comment, matching the SHA and other workflows for consistency.

.github/workflows/pkg-pr-new.yml (1)

16-16: Consistent checkout action version pinning
Changed the checkout step’s comment to v4.2.2 to reflect the exact sub-version being used, in line with the repository’s workflow standards.

.github/workflows/release.yml (1)

23-23: Consistent checkout action version pinning
The actions/checkout step now clearly references v4.2.2 in its comment, mirroring the pinned SHA and matching other workflows.

.github/workflows/vercel.yml (1)

18-18: LGTM! Documentation improvement.

Good practice to specify the exact version tag in the comment for better clarity and traceability.

packages/core/package.json (1)

11-12: Breaking change acknowledged - Node 12 support dropped.

This change drops support for Node.js 12.x, which aligns with the breaking refactor of the findUp function. Since Node 12 reached end-of-life in April 2022, this is a reasonable update.

Ensure this breaking change is properly documented in the changelog and release notes.

@JounQin JounQin force-pushed the refactor/find-up branch from 933debc to 52bbbaa Compare June 1, 2025 05:55
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Caution

Changes requested ❌

Reviewed 52bbbaa in 2 minutes and 2 seconds. Click for details.
  • Reviewed 261 lines of code in 9 files
  • Skipped 0 files when reviewing.
  • Skipped posting 4 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. .github/workflows/autofix.yml:19
  • Draft comment:
    Good update: the checkout action is now pinned to v4.2.2 for consistency.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
2. packages/core/package.json:11
  • Draft comment:
    Node v12 support was removed. Ensure that documentation and release notes clearly communicate this breaking change.
  • Reason this comment was not posted:
    Comment did not seem useful. Confidence is useful = 0% <= threshold 50% The comment is asking the PR author to ensure that documentation and release notes communicate a breaking change. This falls under the rule of not asking the author to update the PR description or ensure certain things are communicated, which is not allowed.
3. packages/core/src/helpers.ts:108
  • Draft comment:
    The while loop's termination condition 'while (!stop || entry !== stop)' in findUp is a bit unintuitive. Consider adding comments or refactoring for clarity when a 'stop' parameter is provided.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 20% vs. threshold = 50% The condition is actually logical - it continues while either there's no stop directory specified (!stop) OR we haven't reached the stop directory yet (entry !== stop). While not immediately obvious, it's a valid implementation. The comment suggests adding documentation but doesn't propose a specific better implementation. Comments requesting documentation without specific suggestions are generally not actionable enough. The condition could be confusing to future maintainers. The logic for handling the stop directory is a key part of the function's behavior. While the code could be more clear, the comment doesn't provide concrete suggestions for improvement. The logic, while terse, is correct and follows common patterns for directory traversal. Delete the comment as it doesn't provide specific, actionable feedback for improving the code. The logic, while compact, is correct and follows standard patterns.
4. packages/core/src/helpers.ts:81
  • Draft comment:
    Consider renaming the 'entry' parameter (and its derived variable) to something like 'startDir' for improved clarity in the findUp function.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None

Workflow ID: wflow_5gfnwef0BpoY1cWo

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@JounQin JounQin force-pushed the refactor/find-up branch from 52bbbaa to 0bc4a98 Compare June 1, 2025 06:12
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (3)
packages/core/src/helpers.ts (3)

37-39: Fix type checking logic to handle explicit boolean values correctly.

This issue was previously identified but remains unresolved. The current logic if (!type) will incorrectly treat an explicit false value as falsy and default to 'file', which may not be the intended behavior.

Apply this fix to handle undefined values explicitly:

-  if (!type) {
-    type = 'file'
-  }
+  if (type === undefined) {
+    type = 'file'
+  }
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 38-38: packages/core/src/helpers.ts#L38
Added line #L38 was not covered by tests


74-81: Add comprehensive documentation for the FindUpOptions interface.

The interface lacks documentation describing the purpose and expected usage of each property, making it difficult for consumers to understand the API.

Add JSDoc comments to document each property:

+/**
+ * Options for configuring the findUp function behavior
+ */
 export interface FindUpOptions {
+  /** Starting directory or file path for the search */
   entry?: string
+  /** Target filename or pattern to search for */
   search?: string
+  /** Expected file type (file, directory, etc.) */
   type?: FileType
+  /** Directory path where the search should stop */
   stop?: string
+  /** Whether to throw an error if the stop path is not found */
   throwOnStopNotFound?: boolean
+  /** Whether to throw an error if the stop path is invalid */
   throwOnInvalidStop?: boolean
 }

32-157: Critical: Add comprehensive test coverage for the refactored functions.

The static analysis shows extensive gaps in test coverage for the new and refactored functions. Given this is a breaking change with complex validation logic, comprehensive tests are essential.

Let me verify the current test coverage:

#!/bin/bash
# Check for existing tests related to the helper functions
rg -n "tryFileStats|tryFile|findUp" --glob "*.test.*" --glob "*.spec.*" -A 3 -B 3

# Check for test files in the core package
fd -e test.ts -e test.js -e spec.ts -e spec.js . packages/core/
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 32-32: packages/core/src/helpers.ts#L32
Added line #L32 was not covered by tests


[warning] 36-36: packages/core/src/helpers.ts#L36
Added line #L36 was not covered by tests


[warning] 38-38: packages/core/src/helpers.ts#L38
Added line #L38 was not covered by tests


[warning] 43-43: packages/core/src/helpers.ts#L43
Added line #L43 was not covered by tests


[warning] 45-45: packages/core/src/helpers.ts#L45
Added line #L45 was not covered by tests


[warning] 47-47: packages/core/src/helpers.ts#L47
Added line #L47 was not covered by tests


[warning] 51-52: packages/core/src/helpers.ts#L51-L52
Added lines #L51 - L52 were not covered by tests


[warning] 56-56: packages/core/src/helpers.ts#L56
Added line #L56 was not covered by tests


[warning] 58-58: packages/core/src/helpers.ts#L58
Added line #L58 was not covered by tests


[warning] 63-63: packages/core/src/helpers.ts#L63
Added line #L63 was not covered by tests


[warning] 89-89: packages/core/src/helpers.ts#L89
Added line #L89 was not covered by tests


[warning] 105-105: packages/core/src/helpers.ts#L105
Added line #L105 was not covered by tests


[warning] 109-109: packages/core/src/helpers.ts#L109
Added line #L109 was not covered by tests


[warning] 111-111: packages/core/src/helpers.ts#L111
Added line #L111 was not covered by tests


[warning] 113-113: packages/core/src/helpers.ts#L113
Added line #L113 was not covered by tests


[warning] 115-115: packages/core/src/helpers.ts#L115
Added line #L115 was not covered by tests


[warning] 117-117: packages/core/src/helpers.ts#L117
Added line #L117 was not covered by tests


[warning] 120-121: packages/core/src/helpers.ts#L120-L121
Added lines #L120 - L121 were not covered by tests


[warning] 124-124: packages/core/src/helpers.ts#L124
Added line #L124 was not covered by tests


[warning] 126-126: packages/core/src/helpers.ts#L126
Added line #L126 was not covered by tests


[warning] 128-128: packages/core/src/helpers.ts#L128
Added line #L128 was not covered by tests


[warning] 130-130: packages/core/src/helpers.ts#L130
Added line #L130 was not covered by tests


[warning] 134-134: packages/core/src/helpers.ts#L134
Added line #L134 was not covered by tests


[warning] 137-137: packages/core/src/helpers.ts#L137
Added line #L137 was not covered by tests


[warning] 141-142: packages/core/src/helpers.ts#L141-L142
Added lines #L141 - L142 were not covered by tests


[warning] 145-145: packages/core/src/helpers.ts#L145
Added line #L145 was not covered by tests


[warning] 149-150: packages/core/src/helpers.ts#L149-L150
Added lines #L149 - L150 were not covered by tests

🧹 Nitpick comments (2)
packages/core/src/helpers.ts (2)

45-52: Complex type checking logic needs simplification and documentation.

The nested ternary and type checking logic is hard to read and understand. Consider extracting this into a helper function for better maintainability.

Extract the type checking logic into a helper function:

+const isFileTypeMatch = (stats: Stats, type: FileTypes): boolean => {
+  if (isAnyFileType(type)) {
+    return true
+  }
+  const types = Array.isArray(type) ? type : [type]
+  return types.some(t => 
+    stats[`is${t[0].toUpperCase()}${t.slice(1)}` as `is${Capitalize<FileTypeBase>}`]()
+  )
+}

-    return stats &&
-      (isAnyFileType(type) ||
-        (Array.isArray(type) ? type : [type]).some(type =>
-          stats[
-            `is${type[0].toUpperCase()}${type.slice(1)}` as `is${Capitalize<FileTypeBase>}`
-          ](),
-        ))
-      ? { filepath, stats }
-      : undefined
+    return stats && isFileTypeMatch(stats, type)
+      ? { filepath, stats }
+      : undefined
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 45-45: packages/core/src/helpers.ts#L45
Added line #L45 was not covered by tests


[warning] 47-47: packages/core/src/helpers.ts#L47
Added line #L47 was not covered by tests


[warning] 51-52: packages/core/src/helpers.ts#L51-L52
Added lines #L51 - L52 were not covered by tests


108-132: Stop path validation logic is robust but could benefit from extracted functions.

The stop path validation logic is comprehensive and handles edge cases well, but the complexity makes it hard to follow. Consider extracting validation functions.

Extract validation logic into helper functions:

+const validateStopPath = (stop: string, throwOnNotFound?: boolean) => {
+  const stopStats = tryFileStats(stop, ['file', 'directory'])
+  if (!stopStats) {
+    const message = `Cannot find stop path: ${stop}`
+    if (throwOnNotFound) {
+      throw new Error(message)
+    } else if (throwOnNotFound !== false) {
+      console.warn(message)
+    }
+    return null
+  }
+  return stopStats.stats.isDirectory()
+    ? stopStats.filepath
+    : path.dirname(stopStats.filepath)
+}
+
+const validateStopIsParent = (entry: string, stop: string, throwOnInvalid?: boolean) => {
+  if (entry !== stop && !entry.startsWith(stop + path.sep)) {
+    const message = `Invalid stop path: ${stop} is not a parent of ${entry}`
+    if (throwOnInvalid) {
+      throw new Error(message)
+    } else if (throwOnInvalid !== false) {
+      console.warn(message)
+    }
+    return false
+  }
+  return true
+}
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 109-109: packages/core/src/helpers.ts#L109
Added line #L109 was not covered by tests


[warning] 111-111: packages/core/src/helpers.ts#L111
Added line #L111 was not covered by tests


[warning] 113-113: packages/core/src/helpers.ts#L113
Added line #L113 was not covered by tests


[warning] 115-115: packages/core/src/helpers.ts#L115
Added line #L115 was not covered by tests


[warning] 117-117: packages/core/src/helpers.ts#L117
Added line #L117 was not covered by tests


[warning] 120-121: packages/core/src/helpers.ts#L120-L121
Added lines #L120 - L121 were not covered by tests


[warning] 124-124: packages/core/src/helpers.ts#L124
Added line #L124 was not covered by tests


[warning] 126-126: packages/core/src/helpers.ts#L126
Added line #L126 was not covered by tests


[warning] 128-128: packages/core/src/helpers.ts#L128
Added line #L128 was not covered by tests


[warning] 130-130: packages/core/src/helpers.ts#L130
Added line #L130 was not covered by tests

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 933debc and 0bc4a98.

📒 Files selected for processing (9)
  • .changeset/poor-walls-arrive.md (1 hunks)
  • .github/workflows/autofix.yml (1 hunks)
  • .github/workflows/ci.yml (1 hunks)
  • .github/workflows/pkg-pr-new.yml (1 hunks)
  • .github/workflows/pkg-size.yml (1 hunks)
  • .github/workflows/release.yml (1 hunks)
  • .github/workflows/vercel.yml (1 hunks)
  • packages/core/package.json (1 hunks)
  • packages/core/src/helpers.ts (2 hunks)
✅ Files skipped from review due to trivial changes (5)
  • .github/workflows/ci.yml
  • .github/workflows/vercel.yml
  • .github/workflows/release.yml
  • packages/core/package.json
  • .github/workflows/pkg-size.yml
🚧 Files skipped from review as they are similar to previous changes (3)
  • .github/workflows/autofix.yml
  • .github/workflows/pkg-pr-new.yml
  • .changeset/poor-walls-arrive.md
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/core/src/helpers.ts (1)
packages/core/src/constants.ts (2)
  • CWD (5-5)
  • EXTENSIONS (20-20)
🪛 GitHub Check: codecov/patch
packages/core/src/helpers.ts

[warning] 12-12: packages/core/src/helpers.ts#L12
Added line #L12 was not covered by tests


[warning] 27-27: packages/core/src/helpers.ts#L27
Added line #L27 was not covered by tests


[warning] 29-30: packages/core/src/helpers.ts#L29-L30
Added lines #L29 - L30 were not covered by tests


[warning] 32-32: packages/core/src/helpers.ts#L32
Added line #L32 was not covered by tests


[warning] 36-36: packages/core/src/helpers.ts#L36
Added line #L36 was not covered by tests


[warning] 38-38: packages/core/src/helpers.ts#L38
Added line #L38 was not covered by tests


[warning] 43-43: packages/core/src/helpers.ts#L43
Added line #L43 was not covered by tests


[warning] 45-45: packages/core/src/helpers.ts#L45
Added line #L45 was not covered by tests


[warning] 47-47: packages/core/src/helpers.ts#L47
Added line #L47 was not covered by tests


[warning] 51-52: packages/core/src/helpers.ts#L51-L52
Added lines #L51 - L52 were not covered by tests


[warning] 56-56: packages/core/src/helpers.ts#L56
Added line #L56 was not covered by tests


[warning] 58-58: packages/core/src/helpers.ts#L58
Added line #L58 was not covered by tests


[warning] 63-63: packages/core/src/helpers.ts#L63
Added line #L63 was not covered by tests


[warning] 89-89: packages/core/src/helpers.ts#L89
Added line #L89 was not covered by tests


[warning] 105-105: packages/core/src/helpers.ts#L105
Added line #L105 was not covered by tests


[warning] 109-109: packages/core/src/helpers.ts#L109
Added line #L109 was not covered by tests


[warning] 111-111: packages/core/src/helpers.ts#L111
Added line #L111 was not covered by tests


[warning] 113-113: packages/core/src/helpers.ts#L113
Added line #L113 was not covered by tests


[warning] 115-115: packages/core/src/helpers.ts#L115
Added line #L115 was not covered by tests


[warning] 117-117: packages/core/src/helpers.ts#L117
Added line #L117 was not covered by tests


[warning] 120-121: packages/core/src/helpers.ts#L120-L121
Added lines #L120 - L121 were not covered by tests


[warning] 124-124: packages/core/src/helpers.ts#L124
Added line #L124 was not covered by tests


[warning] 126-126: packages/core/src/helpers.ts#L126
Added line #L126 was not covered by tests


[warning] 128-128: packages/core/src/helpers.ts#L128
Added line #L128 was not covered by tests


[warning] 130-130: packages/core/src/helpers.ts#L130
Added line #L130 was not covered by tests


[warning] 134-134: packages/core/src/helpers.ts#L134
Added line #L134 was not covered by tests


[warning] 137-137: packages/core/src/helpers.ts#L137
Added line #L137 was not covered by tests


[warning] 141-142: packages/core/src/helpers.ts#L141-L142
Added lines #L141 - L142 were not covered by tests


[warning] 145-145: packages/core/src/helpers.ts#L145
Added line #L145 was not covered by tests


[warning] 149-150: packages/core/src/helpers.ts#L149-L150
Added lines #L149 - L150 were not covered by tests

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (1)
packages/core/src/helpers.ts (1)

149-154: Improved loop termination logic prevents infinite loops.

The addition of lastEntry tracking and the break condition when entry === lastEntry is a good improvement that prevents infinite loops when reaching the filesystem root.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 149-150: packages/core/src/helpers.ts#L149-L150
Added lines #L149 - L150 were not covered by tests

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Caution

Changes requested ❌

Reviewed 0bc4a98 in 2 minutes and 9 seconds. Click for details.
  • Reviewed 297 lines of code in 9 files
  • Skipped 0 files when reviewing.
  • Skipped posting 5 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. packages/core/src/helpers.ts:46
  • Draft comment:
    Potential bug: if 'type' is boolean false, then wrapping it in an array causes false[0] and false.slice(1) to error. Consider constraining FileTypes to avoid false.
  • Reason this comment was not posted:
    Comment looked like it was already resolved.
2. packages/core/src/helpers.ts:95
  • Draft comment:
    Consider renaming the 'entry' parameter (and corresponding option) to a more descriptive name (e.g. 'startDir') to clarify its role as the search starting directory.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
3. packages/core/src/helpers.ts:144
  • Draft comment:
    The do-while loop termination condition (!stop || entry !== stop) is a bit non‐obvious. Consider refactoring or adding a comment to explain the exit logic.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
4. packages/core/src/helpers.ts:110
  • Draft comment:
    The error handling for the 'stop' option uses flags (throwOnStopNotFound/throwOnInvalidStop) in a non-explicit way. Consider defaulting these flags explicitly or clarifying their intended behavior.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
5. packages/core/package.json:11
  • Draft comment:
    Node.js engine version update: Dropping Node 12 support. Ensure documentation and changelogs clearly communicate this breaking change.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None

Workflow ID: wflow_BEDoDUoGr9thvFHW

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@JounQin JounQin merged commit a9eb417 into master Jun 1, 2025
34 of 36 checks passed
@JounQin JounQin deleted the refactor/find-up branch June 1, 2025 06:19
@JounQin JounQin mentioned this pull request Jun 1, 2025
@coderabbitai coderabbitai bot mentioned this pull request Jul 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants