Skip to content

feat: try reading package.json from cwd#51

Merged
JounQin merged 2 commits intoun-ts:mainfrom
mrginglymus:read-from-cwd-cli
Aug 9, 2025
Merged

feat: try reading package.json from cwd#51
JounQin merged 2 commits intoun-ts:mainfrom
mrginglymus:read-from-cwd-cli

Conversation

@mrginglymus
Copy link
Contributor

@mrginglymus mrginglymus commented Aug 9, 2025

Alternative approach that only runs on the cli variant


Important

Adds readCwdPackage in src/cli.ts to read package.json from the current directory, addressing specific issues.

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

Summary by CodeRabbit

  • New Features

    • The CLI now attempts to use information from the local package manifest when available, enabling more seamless integration with local projects.
  • Bug Fixes

    • Improved handling of package information by preferring local data when it matches the specified package, reducing potential mismatches.

@changeset-bot
Copy link

changeset-bot bot commented Aug 9, 2025

🦋 Changeset detected

Latest commit: 25f06a8

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

This PR includes changesets to release 1 package
Name Type
napi-postinstall 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 Aug 9, 2025

Walkthrough

The CLI entry point was updated to first attempt reading and parsing the local package.json from the current working directory. If the package name and version match the provided arguments, it passes the parsed manifest to checkAndPreparePackage; otherwise, it falls back to the previous behavior using the original arguments.

Changes

Cohort / File(s) Change Summary
CLI logic update
src/cli.ts
Added logic to read and parse local package.json from process.cwd(). If its name and version match CLI arguments, call checkAndPreparePackage with the parsed object and check flag; otherwise, fallback to original call. No changes to exported/public entities.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI (cli.ts)
    participant FS
    participant checkAndPreparePackage

    User->>CLI (cli.ts): Run CLI with arguments (name, version, check)
    CLI (cli.ts)->>FS: Attempt to read ./package.json
    alt package.json exists and name & version match
        FS-->>CLI (cli.ts): Return parsed package.json
        CLI (cli.ts)->>checkAndPreparePackage: Call with packageJson and check flag
    else package.json missing or name/version mismatch
        FS-->>CLI (cli.ts): Return null
        CLI (cli.ts)->>checkAndPreparePackage: Call with name, version, check flag
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Assessment against linked issues

Objective Addressed Explanation
Attempt to read package.json from process.cwd() as first fallback (#49)
Avoid unnecessary network requests, especially in offline/CI environments (#49, #184)
Improve Yarn PnP/CI compatibility by preferring local manifest (#49, #184)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Suggested labels

enhancement, feature

Poem

A rabbit hopped to the CLI,
Sniffed out package.json nearby.
If the name was just right,
And the version in sight,
It skipped the net's bite—offline delight! 🐇✨

Note

🔌 MCP (Model Context Protocol) integration is now available in Early Access!

Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 82dc9ed and 25f06a8.

📒 Files selected for processing (1)
  • .changeset/early-buttons-appear.md (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .changeset/early-buttons-appear.md
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: Lint and Test with Node.js 24 on windows-latest
  • GitHub Check: Lint and Test with Node.js 20 on windows-latest
  • GitHub Check: Lint and Test with Node.js 22 on windows-latest
  • GitHub Check: Lint and Test with Node.js 18 on windows-latest
  • GitHub Check: Codacy Static Code Analysis
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.
  • 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.

Support

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

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 generate unit tests to generate unit tests for 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.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Aug 9, 2025

Open in StackBlitz

npm i https://pkg.pr.new/napi-postinstall@51

commit: 25f06a8

Copy link

@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 everything up to c76b429 in 1 minute and 18 seconds. Click for details.
  • Reviewed 41 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 3 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. src/cli.ts:17
  • Draft comment:
    Empty catch block: consider logging or handling the error to aid debugging when reading/parsing package.json fails.
  • 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 function is clearly designed to gracefully handle the case where the package.json doesn't exist or can't be parsed by returning undefined. The empty catch is intentional - errors here aren't exceptional conditions that need logging, they're expected possibilities. The code handles the undefined return appropriately on line 26. Maybe error logging would help developers debug issues if their package.json exists but is malformed? The error information could be valuable. In this case, the function is explicitly designed to handle missing/invalid package.json by returning undefined. Adding error logging would be noisy since this is an expected case, not an error condition. The empty catch block is intentional and appropriate here - this is a valid pattern for optional configuration reading where failure is an expected case.
2. src/cli.ts:12
  • Draft comment:
    Consider using an explicit path resolution (e.g., path.join(process.cwd(), PACKAGE_JSON)) for clarity on where package.json is read from.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
3. src/cli.ts:27
  • Draft comment:
    Ensure that checkAndPreparePackage correctly handles both overloads (one accepting a PackageJson object and one with package name/version).
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None

Workflow ID: wflow_kwH7ffXzrEcmBpCq

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

Copy link
Member

@JounQin JounQin left a comment

Choose a reason for hiding this comment

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

Great job, thanks!

@JounQin JounQin merged commit 1d9c7d5 into un-ts:main Aug 9, 2025
22 checks passed
@mrginglymus mrginglymus deleted the read-from-cwd-cli branch August 9, 2025 13:34
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.

Consider reading package.json from process.cwd() Unable to install on CI - 401 http error [Yarn PnP]

2 participants