Skip to content

refactor: reuse napi-postinstall/fallback instead - #173

Merged
JounQin merged 1 commit into
mainfrom
feat/napi-postinstall/fallback
Jul 2, 2025
Merged

JounQin merged 1 commit into
mainfrom
feat/napi-postinstall/fallback

Conversation

@JounQin

@JounQin JounQin commented Jul 2, 2025 •

Copy link
Copy Markdown
Member

Important

Refactor to use napi-postinstall/fallback instead of custom fallback logic, removing fallback.js and updating dependencies.

  • Refactor:
    • Replace custom fallback logic in napi/index.js and napi/patch.mjs with napi-postinstall/fallback.
    • Remove fallback.js as it is no longer needed.
  • Dependencies:
    • Update napi-postinstall version to ^0.3.0 in package.json.
  • Misc:
    • Remove fallback.js from files array in package.json.

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

Summary by CodeRabbit

  • Refactor
    • Updated the fallback mechanism for loading native bindings to use an external package, streamlining the process and removing internal fallback logic.
  • Chores
    • Removed the fallback script from the package and excluded it from published files.
    • Upgraded the dependency on the fallback handler package to a newer version.

@JounQin
JounQin requested a review from Copilot July 2, 2025 17:26
@JounQin JounQin self-assigned this Jul 2, 2025
@JounQin JounQin added the dependencies Pull requests that update a dependency file label Jul 2, 2025
@coderabbitai

coderabbitai Bot commented Jul 2, 2025 •

Copy link
Copy Markdown

Walkthrough

The local fallback mechanism for loading native bindings was removed and replaced with a call to the external napi-postinstall/fallback module. The fallback.js file was deleted, references to it were updated, and the napi-postinstall dependency was updated in package.json, which also no longer includes fallback.js in its published files.

Changes

File(s) Change Summary
napi/fallback.js Deleted; removed the local fallback logic for native binding loading.
napi/index.js, napi/patch.mjs Updated fallback logic to use napi-postinstall/fallback instead of the deleted local module.
package.json Removed fallback.js from "files" and updated napi-postinstall dependency version.

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant NativeBinding
    participant NapiPostinstallFallback

    App->>NativeBinding: try to require native binding
    alt Native binding loads successfully
        NativeBinding-->>App: Native binding loaded
    else Native binding fails and SKIP_UNRS_RESOLVER_FALLBACK != '1'
        App->>NapiPostinstallFallback: call fallback(package.json, true)
        NapiPostinstallFallback-->>App: Attempt fallback installation and load
    end
Loading

Possibly related PRs

Suggested labels

enhancement

Poem

A hop, a skip, the fallback's gone,
No more local patch at dawn!
Now with napi-postinstall in the lead,
Our bindings load with greater speed.
The package trimmed, the code more neat—
This bunny’s work is quite the treat! 🐇✨


📜 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 80cc228 and 1663eed.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (4)
  • napi/fallback.js (0 hunks)
  • napi/index.js (1 hunks)
  • napi/patch.mjs (1 hunks)
  • package.json (1 hunks)
💤 Files with no reviewable changes (1)
  • napi/fallback.js
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: JounQin
PR: unrs/unrs-resolver#144
File: napi/patch.mjs:5-5
Timestamp: 2025-06-10T13:53:02.983Z
Learning: Build-time scripts in napi/patch.mjs and similar build pipeline contexts don't require error handling for reading expected files like index.js, as these files are guaranteed to be present during the build process.
Learnt from: JounQin
PR: unrs/unrs-resolver#72
File: fixtures/tsconfig/cases/dot-alias/tsconfigs/tsconfig.base.json:0-0
Timestamp: 2025-04-21T06:11:46.964Z
Learning: JounQin's fix for the dot alias issue in PR #72 addresses the problem by correctly normalizing paths in the `extend_tsconfig` method, ensuring that base URLs are properly resolved as absolute paths when extending tsconfigs, rather than adding special case handling for dot aliases in the resolver.
Learnt from: JounQin
PR: unrs/unrs-resolver#75
File: fixtures/pnp/package.json:11-14
Timestamp: 2025-04-21T08:11:41.469Z
Learning: The project uses a justfile with an `install` task that includes running yarn in the fixtures/pnp directory to install dependencies with the command: `cd fixtures/pnp && yarn`.
package.json (6)
Learnt from: JounQin
PR: unrs/unrs-resolver#144
File: napi/patch.mjs:5-5
Timestamp: 2025-06-10T13:53:02.983Z
Learning: Build-time scripts in napi/patch.mjs and similar build pipeline contexts don't require error handling for reading expected files like index.js, as these files are guaranteed to be present during the build process.
Learnt from: JounQin
PR: unrs/unrs-resolver#75
File: fixtures/pnp/package.json:11-14
Timestamp: 2025-04-21T08:11:41.469Z
Learning: The project uses a justfile with an `install` task that includes running yarn in the fixtures/pnp directory to install dependencies with the command: `cd fixtures/pnp && yarn`.
Learnt from: JounQin
PR: unrs/unrs-resolver#136
File: src/tests/extension_alias.rs:36-46
Timestamp: 2025-06-05T18:52:30.363Z
Learning: The fixtures/yarn directory in the unrs-resolver project requires running `yarn install` to install TypeScript dependencies before tests can run, similar to other fixture directories like fixtures/pnp. The test in src/tests/extension_alias.rs depends on the installed TypeScript package providing lib/typescript.d.ts and related files.
Learnt from: JounQin
PR: unrs/unrs-resolver#136
File: src/tests/extension_alias.rs:36-46
Timestamp: 2025-06-05T18:52:30.363Z
Learning: The fixtures/yarn directory in the unrs-resolver project requires running `yarn install` to install TypeScript dependencies before tests can run, similar to other fixture directories like fixtures/pnp. The test in src/tests/extension_alias.rs depends on the installed TypeScript package providing lib/typescript.d.ts and related files.
Learnt from: JounQin
PR: unrs/unrs-resolver#40
File: src/tests/resolve.rs:121-136
Timestamp: 2025-03-29T04:14:03.715Z
Learning: For tests involving npm/yarn package resolution in the unrs-resolver project, dependencies must be installed first using the appropriate package manager commands (pnpm i, yarn) in both the root directory and fixture directories like fixtures/pnp and fixtures/misc/nested-package-json.
Learnt from: JounQin
PR: unrs/unrs-resolver#115
File: tests/resolve_test.rs:251-263
Timestamp: 2025-05-28T02:21:41.547Z
Learning: In pnpm workspaces, `pnpm install` must be run first to initialize dependencies and create the proper node_modules/.pnpm structure before tests can pass. Tests that rely on resolving packages will fail if dependencies haven't been installed yet.
napi/patch.mjs (5)
Learnt from: JounQin
PR: unrs/unrs-resolver#144
File: napi/patch.mjs:5-5
Timestamp: 2025-06-10T13:53:02.983Z
Learning: Build-time scripts in napi/patch.mjs and similar build pipeline contexts don't require error handling for reading expected files like index.js, as these files are guaranteed to be present during the build process.
Learnt from: JounQin
PR: unrs/unrs-resolver#75
File: src/tests/pnp.rs:116-133
Timestamp: 2025-04-21T09:52:45.840Z
Learning: In Yarn PnP environments, some packages use nested package.json files for subpaths instead of the exports field. The resolver should check for these nested package.json files when resolving subpaths like `@atlaskit/pragmatic-drag-and-drop/combine` to correctly handle packages with this structure.
Learnt from: JounQin
PR: unrs/unrs-resolver#136
File: src/tests/extension_alias.rs:36-46
Timestamp: 2025-06-05T18:52:30.363Z
Learning: The fixtures/yarn directory in the unrs-resolver project requires running `yarn install` to install TypeScript dependencies before tests can run, similar to other fixture directories like fixtures/pnp. The test in src/tests/extension_alias.rs depends on the installed TypeScript package providing lib/typescript.d.ts and related files.
Learnt from: JounQin
PR: unrs/unrs-resolver#136
File: src/tests/extension_alias.rs:36-46
Timestamp: 2025-06-05T18:52:30.363Z
Learning: The fixtures/yarn directory in the unrs-resolver project requires running `yarn install` to install TypeScript dependencies before tests can run, similar to other fixture directories like fixtures/pnp. The test in src/tests/extension_alias.rs depends on the installed TypeScript package providing lib/typescript.d.ts and related files.
Learnt from: JounQin
PR: unrs/unrs-resolver#40
File: src/tests/resolve.rs:121-136
Timestamp: 2025-03-29T04:14:03.715Z
Learning: For tests involving npm/yarn package resolution in the unrs-resolver project, dependencies must be installed first using the appropriate package manager commands (pnpm i, yarn) in both the root directory and fixture directories like fixtures/pnp and fixtures/misc/nested-package-json.
napi/index.js (5)
Learnt from: JounQin
PR: unrs/unrs-resolver#144
File: napi/patch.mjs:5-5
Timestamp: 2025-06-10T13:53:02.983Z
Learning: Build-time scripts in napi/patch.mjs and similar build pipeline contexts don't require error handling for reading expected files like index.js, as these files are guaranteed to be present during the build process.
Learnt from: JounQin
PR: unrs/unrs-resolver#75
File: src/tests/pnp.rs:116-133
Timestamp: 2025-04-21T09:52:45.840Z
Learning: In Yarn PnP environments, some packages use nested package.json files for subpaths instead of the exports field. The resolver should check for these nested package.json files when resolving subpaths like `@atlaskit/pragmatic-drag-and-drop/combine` to correctly handle packages with this structure.
Learnt from: JounQin
PR: unrs/unrs-resolver#40
File: src/tests/resolve.rs:121-136
Timestamp: 2025-03-29T04:14:03.715Z
Learning: For tests involving npm/yarn package resolution in the unrs-resolver project, dependencies must be installed first using the appropriate package manager commands (pnpm i, yarn) in both the root directory and fixture directories like fixtures/pnp and fixtures/misc/nested-package-json.
Learnt from: JounQin
PR: unrs/unrs-resolver#136
File: src/tests/extension_alias.rs:36-46
Timestamp: 2025-06-05T18:52:30.363Z
Learning: The fixtures/yarn directory in the unrs-resolver project requires running `yarn install` to install TypeScript dependencies before tests can run, similar to other fixture directories like fixtures/pnp. The test in src/tests/extension_alias.rs depends on the installed TypeScript package providing lib/typescript.d.ts and related files.
Learnt from: JounQin
PR: unrs/unrs-resolver#136
File: src/tests/extension_alias.rs:36-46
Timestamp: 2025-06-05T18:52:30.363Z
Learning: The fixtures/yarn directory in the unrs-resolver project requires running `yarn install` to install TypeScript dependencies before tests can run, similar to other fixture directories like fixtures/pnp. The test in src/tests/extension_alias.rs depends on the installed TypeScript package providing lib/typescript.d.ts and related files.
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: Socket Security: Pull Request Alerts
  • GitHub Check: Test (windows-latest)
  • GitHub Check: Lint
  • GitHub Check: Test wasi target
  • GitHub Check: Test (macos-14)
  • GitHub Check: Test (ubuntu-latest)
  • GitHub Check: Analyze (actions)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (3)
package.json (1)

28-28: Approve napi-postinstall update after successful verification

  • Confirmed [email protected] exists on npm.
  • No security advisories found for this version.

This dependency bump is safe and aligns with the refactoring to delegate fallback logic externally.

napi/patch.mjs (1)

13-13: Clean refactoring to delegate fallback logic.

The change from local './fallback.js' to external napi-postinstall/fallback function call is well-implemented. The arguments (require.resolve('../package.json'), true) properly provide the package location and configuration flag to the external fallback handler.

napi/index.js (1)

368-368: Consistent fallback refactoring maintains proper error handling.

The change matches the patch.mjs implementation, correctly delegating to napi-postinstall/fallback with appropriate arguments. The existing error handling structure is preserved, ensuring failed fallback attempts are properly tracked in loadErrors.

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

@sonarqubecloud

sonarqubecloud Bot commented Jul 2, 2025

Copy link
Copy Markdown

@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatednapi-postinstall@​0.2.5 ⏵ 0.3.0100 +1100100 +190 +1100

View full report

@ellipsis-dev ellipsis-dev Bot left a comment

Copy link
Copy Markdown

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 1663eed in 1 minute and 14 seconds. Click for details.
  • Reviewed 142 lines of code in 4 files
  • Skipped 1 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. napi/index.js:367
  • Draft comment:
    Refactored fallback usage: Ensure that passing require.resolve('../package.json') and 'true' to napi-postinstall/fallback correctly replicates the original behavior. Verify that error handling and the use of SKIP_UNRS_RESOLVER_FALLBACK remain consistent.
  • 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 the refactored code replicates the original behavior and to verify error handling consistency. This falls under the category of asking the author to double-check things, which is against the rules.
2. napi/patch.mjs:11
  • Draft comment:
    Updated patch script to insert the new fallback invocation. Confirm that the inserted block matches the intended fallback behavior and maintains error logging consistency.
  • 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 confirm their intention and ensure behavior consistency, which violates the rules. It doesn't provide a specific suggestion or point out a clear issue.
3. package.json:15
  • Draft comment:
    Removed fallback.js from files and updated the napi-postinstall dependency to ^0.3.0. Ensure the new external fallback fully covers all use cases previously handled by the in-package fallback.
  • 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 the new external fallback covers all use cases previously handled by the in-package fallback. This is a request for confirmation and testing, which violates the rules.
4. napi/index.js:368
  • Draft comment:
    It looks like the semicolon at the end of the require('napi-postinstall/fallback')(..., true) call is missing compared to the original version. Please add a semicolon here for consistency.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 0% vs. threshold = 50% Looking at the file, it's auto-generated and the semicolon style is inconsistent throughout - some lines have them, some don't. The file starts with prettier-ignore and eslint-disable. This suggests that code style in this file is not important. Additionally, in JavaScript semicolons are optional in most cases due to ASI (automatic semicolon insertion). The comment is technically correct that it would make the line match the style of some other lines. Maybe consistent style is important even in auto-generated files? No - this is an auto-generated file with explicit style checking disabled. Making style suggestions on such files is not useful and could be actively harmful if the file gets regenerated. The comment about adding a semicolon should be deleted. Style suggestions on auto-generated files with disabled linting are not useful.

Workflow ID: wflow_jlVzqUd1yEpDdfRv

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

Copilot AI left a comment

Copy link
Copy Markdown

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 native binding fallback logic to use the external napi-postinstall/fallback module instead of a local fallback.js and updates the dependency accordingly.

  • Remove local napi/fallback.js and references to it.
  • Bump napi-postinstall dependency to ^0.3.0.
  • Update napi/patch.mjs and napi/index.js to call napi-postinstall/fallback.

Reviewed Changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.

File Description
package.json Removed fallback.js from packaged files and bumped the napi-postinstall version to ^0.3.0.
napi/patch.mjs Replaced local require('./fallback.js') with require('napi-postinstall/fallback').
napi/index.js Same replacement of local fallback with the external module.
napi/fallback.js Deleted local fallback implementation in favor of the external helper.
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (1)

napi/index.js:366

  • This new fallback path depends on external behavior; add unit or integration tests to cover both success and failure cases of the napi-postinstall/fallback invocation.
if (!nativeBinding && process.env.SKIP_UNRS_RESOLVER_FALLBACK !== '1') {

Comment thread napi/index.js Resolved
@JounQin
JounQin merged commit 77adf67 into main Jul 2, 2025
@JounQin
JounQin deleted the feat/napi-postinstall/fallback branch July 2, 2025 17:30
@coderabbitai coderabbitai Bot mentioned this pull request Jan 10, 2026
hanzo-dev pushed a commit to hanzoai/unrs-resolver that referenced this pull request Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants