Skip to content

Conversation

JounQin
Copy link
Member

@JounQin JounQin commented Jul 2, 2025

close #35


Important

Add fallback function for package loading in constrained environments, update documentation, tests, and CI workflow.

  • New Features:
    • Add fallback function in src/fallback.ts for package loading in constrained environments.
    • Export fallback module in package.json.
  • Documentation:
    • Update README.md with TypeScript declarations and usage examples for fallback.
  • Tests:
    • Add test/fallback.spec.ts to test fallback functionality.
  • CI:
    • Update ci.yml to include pnpm setup.
  • Style:
    • Use type-only imports in src/constants.ts, src/helpers.ts, and src/target.ts.

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


Summary by CodeRabbit

  • New Features

    • Introduced a new fallback function for enhanced package loading in constrained environments.
    • Added a new export path for the fallback module.
  • Documentation

    • Expanded the README with TypeScript declarations and usage examples for the new fallback function.
  • Tests

    • Added tests to verify the behavior of the new fallback functionality.
  • Style

    • Updated import statements to use type-only imports for improved code clarity.
  • Chores

    • Updated CI workflow to include pnpm setup for improved package management.

@JounQin JounQin requested a review from Copilot July 2, 2025 16:20
@JounQin JounQin self-assigned this Jul 2, 2025
@JounQin JounQin added enhancement New feature or request feature New feature labels Jul 2, 2025
Copy link

changeset-bot bot commented Jul 2, 2025

🦋 Changeset detected

Latest commit: 5171e16

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 Minor

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

Copy link

coderabbitai bot commented Jul 2, 2025

Warning

Rate limit exceeded

@JounQin has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 19 minutes and 33 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between ea9bf46 and 5171e16.

📒 Files selected for processing (1)
  • test/fallback.spec.ts (1 hunks)

Walkthrough

A new fallback function was introduced to support package loading in constrained environments like webcontainers and Docker. The function is exported as a subpath module, with updated documentation, type declarations, and tests. Additional changes include type-only imports for clarity and a new path alias in the TypeScript configuration.

Changes

File(s) Change Summary
README.md Added documentation, usage examples, and TypeScript declarations for the new fallback function.
package.json Added ./fallback subpath export mapping to type and JS files.
src/fallback.ts Introduced fallback function for runtime package loading and environment-specific handling.
test/fallback.spec.ts Added tests for the new fallback function, covering standard and webcontainer scenarios.
tsconfig.json Added path alias for napi-postinstall/fallback.
src/constants.ts, src/helpers.ts, src/target.ts Changed imports to type-only (import type) for type annotation clarity.
.github/workflows/ci.yml Added pnpm setup step to CI workflow.
.changeset/wet-hounds-sneeze.md Added changeset documenting the feature addition.

Sequence Diagram(s)

sequenceDiagram
    participant UserApp
    participant fallback
    participant FS
    participant Env
    participant ChildProcess

    UserApp->>fallback: call fallback(packageJsonPath, checkVersion?)
    fallback->>FS: read package.json
    fallback->>Env: check if webcontainer
    alt In webcontainer
        fallback->>FS: check WASI binding presence
        alt WASI binding missing
            fallback->>FS: clean/create temp dir
            fallback->>ChildProcess: run pnpm install for WASI binding
        end
        fallback->>UserApp: require and return WASI binding
    else Not in webcontainer
        fallback->>Env: detect package manager
        alt Supported package manager
            fallback->>ChildProcess: run napi-postinstall
            fallback->>Env: set SKIP_*_FALLBACK env variable
            fallback->>FS: clear require cache
            fallback->>UserApp: require and return package
        else
            fallback->>UserApp: throw error (unsupported manager)
        end
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
Support webcontainer by runtime check/fallback (#35)
Provide fallback mechanism for constrained environments (#35)
Export fallback as subpath module and update documentation (#35)
Add tests for fallback functionality in various environments (#35)

Poem

A rabbit hops in code’s delight,
With fallback magic, day or night.
Webcontainers, Docker too—
The package loads, the tests run through!
Subpath exports, docs anew,
Type-only imports, crisp and true.
🐇✨ The future’s bright for all the crew!

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

Copy link

socket-security bot commented Jul 2, 2025

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

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​esbuild/​aix-ppc64@​0.25.51001003688100
Added@​esbuild/​android-arm64@​0.25.51001003688100
Added@​esbuild/​darwin-arm64@​0.25.51001003688100
Added@​esbuild/​darwin-x64@​0.25.51001003688100
Added@​esbuild/​freebsd-arm64@​0.25.51001003688100
Added@​esbuild/​freebsd-x64@​0.25.51001003688100
Added@​esbuild/​linux-arm@​0.25.51001003688100
Added@​esbuild/​linux-arm64@​0.25.51001003688100
Added@​esbuild/​linux-ia32@​0.25.51001003688100
Added@​esbuild/​linux-loong64@​0.25.51001003688100
Added@​esbuild/​linux-mips64el@​0.25.51001003688100
Added@​esbuild/​linux-ppc64@​0.25.51001003688100
Added@​esbuild/​linux-riscv64@​0.25.51001003688100
Added@​esbuild/​linux-s390x@​0.25.51001003688100
Added@​esbuild/​linux-x64@​0.25.51001003688100
Added@​esbuild/​openbsd-arm64@​0.25.51001003687100
Added@​esbuild/​openbsd-x64@​0.25.51001003688100
Added@​esbuild/​sunos-x64@​0.25.51001003688100
Added@​esbuild/​win32-arm64@​0.25.51001003688100
Added@​esbuild/​win32-ia32@​0.25.51001003688100
Added@​esbuild/​win32-x64@​0.25.51001003688100
Added@​esbuild/​netbsd-arm64@​0.25.51001003787100
Added@​esbuild/​netbsd-x64@​0.25.51001003788100
Added@​rollup/​rollup-darwin-arm64@​4.44.11001003799100
Added@​rollup/​rollup-android-arm64@​4.44.11001003799100
Added@​rollup/​rollup-win32-arm64-msvc@​4.44.11001003799100
Added@​rollup/​rollup-freebsd-arm64@​4.44.11001003799100
Added@​rollup/​rollup-linux-arm64-gnu@​4.44.11001003799100
Added@​rollup/​rollup-linux-arm64-musl@​4.44.11001003799100
Added@​rollup/​rollup-android-arm-eabi@​4.44.11001003799100
Added@​rollup/​rollup-linux-arm-gnueabihf@​4.44.11001003799100
Added@​rollup/​rollup-linux-arm-musleabihf@​4.44.11001003799100
Added@​rollup/​rollup-win32-ia32-msvc@​4.44.11001003799100
See 241 more rows in the dashboard

View full report

Copy link

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
-4.95% (target: -1.00%) 0.00%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (c610659) 586 199 33.96%
Head commit (494c8e3) 686 (+100) 199 (+0) 29.01% (-4.95%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#40) 100 0 0.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

1 similar comment
Copy link

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
-4.95% (target: -1.00%) 0.00%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (c610659) 586 199 33.96%
Head commit (494c8e3) 686 (+100) 199 (+0) 29.01% (-4.95%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#40) 100 0 0.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Copy link

@Copilot 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 PR introduces a runtime fallback mechanism for N-API packages, adds support for WebContainer environments, and updates related tests and documentation.

  • Implement fallback function with WebContainer and generic package-manager fallback in src/fallback.ts
  • Add tests for fallback behavior in test/fallback.spec.ts
  • Update exports, type‐only imports, and README to expose and document the new fallback entry point

Reviewed Changes

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

Show a summary per file
File Description
test/fallback.spec.ts Add tests for normal and WebContainer fallback flows
src/target.ts Switch some imports to import type for cleaner TS
src/helpers.ts Convert imports to type‐only
src/fallback.ts New fallback logic for WebContainer and CLI fallback
src/constants.ts Convert import to type‐only
package.json Export fallback entry under "./fallback"
README.md Document fallback API and provide usage examples
Comments suppressed due to low confidence (2)

src/fallback.ts:53

  • There’s no test covering the version-mismatch branch when checkVersion is true; consider adding a spec that triggers this error path.
  if (checkVersion && pkgVersion !== version) {

src/fallback.ts:34

  • [nitpick] The JSDoc summary only mentions WebContainer and Docker; it could also briefly describe the general package-manager fallback behavior.
 * Fallback for webcontainer and docker environments like

Copy link
Contributor

github-actions bot commented Jul 2, 2025

📊 Package size report   13%↑

File Before After
lib/constants.d.ts 412 B 1%↑417 B
lib/fallback.d.ts 111 B
lib/fallback.js 3.2 kB
lib/fallback.js.map 3.1 kB
lib/helpers.d.ts 841 B 0.6%↑846 B
lib/target.d.ts 101 B 5%↑106 B
package.json 3.5 kB 3%↑3.6 kB
README.md 6.4 kB 6%↑6.7 kB
Total (Includes all files) 52.2 kB 13%↑59.1 kB
Tarball size 14.4 kB 12%↑16.1 kB
Unchanged files
File Size
lib/cli.d.ts 31 B
lib/cli.js 306 B
lib/cli.js.map 317 B
lib/constants.js 703 B
lib/constants.js.map 519 B
lib/helpers.js 7.4 kB
lib/helpers.js.map 6.6 kB
lib/index.d.ts 415 B
lib/index.js 10.4 kB
lib/index.js.map 9.0 kB
lib/target.js 1.6 kB
lib/target.js.map 1.5 kB
lib/types.d.ts 825 B
lib/types.js 110 B
lib/types.js.map 102 B
LICENSE 1.1 kB

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

Copy link
Contributor

github-actions bot commented Jul 2, 2025

size-limit report 📦

Path Size
lib/index.js 2.43 KB (0%)

Copy link

pkg-pr-new bot commented Jul 2, 2025

Open in StackBlitz

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

commit: 5171e16

Copy link
Contributor

github-actions bot commented Jul 2, 2025

Deploy preview for napi-postinstall ready!

✅ Preview
https://napi-postinstall-7oy6mka9o-1stg.vercel.app

Built with commit 5171e16.
This pull request is being automatically deployed with vercel-action

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.

Caution

Changes requested ❌

Reviewed everything up to 494c8e3 in 2 minutes and 9 seconds. Click for details.
  • Reviewed 273 lines of code in 7 files
  • Skipped 1 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. test/fallback.spec.ts:19
  • Draft comment:
    Directly assigning 'process.versions.webcontainer' may not work in all Node versions; consider using Object.defineProperty in tests for better reliability.
  • 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% This is a test file, not production code. The current approach works fine for testing - we set the value and clean it up in afterEach. While Object.defineProperty might be more robust, this level of perfectionism in test code seems unnecessary. The current code is simple and clear. The comment does raise a valid point about Node.js version compatibility. Some versions might have process.versions as read-only. However, if this was actually a problem, the tests would fail. Since this is test code and there's a cleanup step, the simpler approach is fine. Delete the comment. The current code is sufficiently clear and functional for test purposes, and the suggested change adds unnecessary complexity.
2. src/fallback.ts:38
  • Draft comment:
    Typo: In the JSDoc comment, "Wether" should be "Whether".
  • Reason this comment was not posted:
    Marked as duplicate.
3. src/fallback.ts:67
  • Draft comment:
    Typographical error in the error message: "target is not unavailable" should likely be "target is unavailable".
  • Reason this comment was not posted:
    Marked as duplicate.

Workflow ID: wflow_JdCwa0xg5JqJuK9a

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

🧹 Nitpick comments (1)
test/fallback.spec.ts (1)

6-9: Consider using undefined assignment instead of delete operator.

While the performance impact in test cleanup is negligible, using undefined assignment is cleaner and avoids the static analysis warning.

 afterEach(() => {
-  delete process.env.SKIP_UNRS_RESOLVER_FALLBACK
-  delete process.versions.webcontainer
+  process.env.SKIP_UNRS_RESOLVER_FALLBACK = undefined
+  process.versions.webcontainer = undefined
 })
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c610659 and 494c8e3.

📒 Files selected for processing (8)
  • README.md (2 hunks)
  • package.json (1 hunks)
  • src/constants.ts (1 hunks)
  • src/fallback.ts (1 hunks)
  • src/helpers.ts (1 hunks)
  • src/target.ts (1 hunks)
  • test/fallback.spec.ts (1 hunks)
  • tsconfig.json (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: JounQin
PR: un-ts/napi-postinstall#3
File: test/basic.spec.ts:10-14
Timestamp: 2025-04-19T17:37:36.119Z
Learning: JounQin prefers using `resolves.not.toThrow()` for testing Promise<void> functions to verify successful resolution, rather than explicitly checking for `undefined` with `resolves.toBeUndefined()`.
test/fallback.spec.ts (1)
Learnt from: JounQin
PR: un-ts/napi-postinstall#3
File: test/basic.spec.ts:10-14
Timestamp: 2025-04-19T17:37:36.119Z
Learning: JounQin prefers using `resolves.not.toThrow()` for testing Promise<void> functions to verify successful resolution, rather than explicitly checking for `undefined` with `resolves.toBeUndefined()`.
🧬 Code Graph Analysis (1)
src/fallback.ts (3)
src/types.ts (1)
  • PackageJson (28-33)
src/helpers.ts (2)
  • getNapiInfoFromPackageJson (51-109)
  • errorMessage (280-282)
src/constants.ts (1)
  • WASM32_WASI (17-17)
🪛 Biome (1.9.4)
test/fallback.spec.ts

[error] 7-7: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 8-8: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

🪛 GitHub Check: Lint and Test with Node.js 18 on windows-latest
src/fallback.ts

[failure] 89-89: test/fallback.spec.ts > fallback > should support webcontainer
Error: spawnSync pnpm ENOENT
❯ fallback src/fallback.ts:89:19
❯ test/fallback.spec.ts:20:22

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Serialized Error: { errno: -4058, code: 'ENOENT', syscall: 'spawnSync pnpm', path: 'pnpm', spawnargs: [ 'i', '@unrs/resolver-binding-wasm32-wasi@1.9.2' ], error: { stack: 'Error: spawnSync pnpm ENOENT\n at Object.spawnSync (node:internal/child_process:1117:20)\n at spawnSync (node:child_process:876:24)\n at execFileSync (node:child_process:919:15)\n at fallback (D:\a\napi-postinstall\napi-postinstall\src\fallback.ts:89:19)\n at D:\a\napi-postinstall\napi-postinstall\test\fallback.spec.ts:20:22\n at file:///D:/a/napi-postinstall/napi-postinstall/node_modules/@vitest/runner/dist/chunk-hooks.js:155:11\n at file:///D:/a/napi-postinstall/napi-postinstall/node_modules/@vitest/runner/dist/chunk-hooks.js:752:26\n at file:///D:/a/napi-postinstall/napi-postinstall/node_modules/@vitest/runner/dist/chunk-hooks.js:1897:20\n at new Promise ()\n at runWithTimeout (file:///D:/a/napi-postinstall/napi-postinstall/node_modules/@vitest/runner/dist/chunk-hooks.js:1863:10)', message: 'spawnSync pnpm ENOENT', errno: -4058, code: 'ENOENT', syscall: 'spawnSync pnpm', path: 'pnpm', spawnargs: [ 'i', '@unrs/resolver-binding-wasm32-wasi@1.9.2' ], error: [Circular], status: null, signal: null, output: null, pid: +0, stdout: null, stderr: null, constructor: 'Function', name: 'Error', toString: 'Function', stacks: [ { method: 'fallback', file: 'D:/a/napi-postinstall/napi-postinstall/src/fallback.ts', line: 89, column: 19 }, { method: '', file: 'D:/a/napi-postinstall/napi-postinstall/test/fallback.spec.ts', line: 20, column: 22 } ] }, status: null, signal: null, output: null, pid: +0, stdout: null, stderr: null }


[failure] 122-122: test/fallback.spec.ts > fallback > should resolve napi package successfully and set skip env after processing
Error: spawnSync yarn ENOENT
❯ fallback src/fallback.ts:122:15
❯ test/fallback.spec.ts:12:12

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Serialized Error: { errno: -4058, code: 'ENOENT', syscall: 'spawnSync yarn', path: 'yarn', spawnargs: [ 'napi-postinstall', 'unrs-resolver', '1.9.2', '0' ], error: { stack: 'Error: spawnSync yarn ENOENT\n at Object.spawnSync (node:internal/child_process:1117:20)\n at spawnSync (node:child_process:876:24)\n at execFileSync (node:child_process:919:15)\n at fallback (D:\a\napi-postinstall\napi-postinstall\src\fallback.ts:122:15)\n at D:\a\napi-postinstall\napi-postinstall\test\fallback.spec.ts:12:12\n at file:///D:/a/napi-postinstall/napi-postinstall/node_modules/@vitest/runner/dist/chunk-hooks.js:155:11\n at file:///D:/a/napi-postinstall/napi-postinstall/node_modules/@vitest/runner/dist/chunk-hooks.js:752:26\n at file:///D:/a/napi-postinstall/napi-postinstall/node_modules/@vitest/runner/dist/chunk-hooks.js:1897:20\n at new Promise ()\n at runWithTimeout (file:///D:/a/napi-postinstall/napi-postinstall/node_modules/@vitest/runner/dist/chunk-hooks.js:1863:10)', message: 'spawnSync yarn ENOENT', errno: -4058, code: 'ENOENT', syscall: 'spawnSync yarn', path: 'yarn', spawnargs: [ 'napi-postinstall', 'unrs-resolver', '1.9.2', '0' ], error: [Circular], status: null, signal: null, output: null, pid: +0, stdout: null, stderr: null, constructor: 'Function', name: 'Error', toString: 'Function', stacks: [ { method: 'fallback', file: 'D:/a/napi-postinstall/napi-postinstall/src/fallback.ts', line: 122, column: 15 }, { method: '', file: 'D:/a/napi-postinstall/napi-postinstall/test/fallback.spec.ts', line: 12, column: 12 } ] }, status: null, signal: null, output: null, pid: +0, stdout: null, stderr: null }

⏰ Context from checks skipped due to timeout of 90000ms (17)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: publish
  • GitHub Check: deploy
  • GitHub Check: size-limit
  • GitHub Check: Lint and Test with Node.js 24 on windows-latest
  • GitHub Check: Lint and Test with Node.js 24 on ubuntu-latest
  • GitHub Check: Lint and Test with Node.js 22 on ubuntu-latest
  • GitHub Check: Lint and Test with Node.js 22 on windows-latest
  • GitHub Check: Lint and Test with Node.js 24 on macos-latest
  • GitHub Check: Lint and Test with Node.js 20 on windows-latest
  • GitHub Check: Lint and Test with Node.js 18 on macos-latest
  • GitHub Check: Lint and Test with Node.js 22 on macos-latest
  • GitHub Check: Lint and Test with Node.js 20 on macos-latest
  • GitHub Check: Lint and Test with Node.js 18 on windows-latest
  • GitHub Check: Lint and Test with Node.js 24 on windows-latest
  • GitHub Check: Lint and Test with Node.js 22 on windows-latest
  • GitHub Check: Lint and Test with Node.js 20 on windows-latest
🔇 Additional comments (13)
src/target.ts (1)

3-5: 👍 Switched to import type – good call

Clear separation of type-only imports reduces emitted JS and prevents accidental circular requires.

src/constants.ts (1)

3-4: 👍 Type-only import keeps runtime clean

Same benefit here – nothing else to flag.

src/helpers.ts (1)

7-8: 👍 Consistent import type usage

Keeps the helpers free of dead runtime requires.

tsconfig.json (1)

8-10: Path alias verification complete

  • ✅ Confirmed src/fallback.ts exists and will be compiled into lib/fallback.{js,d.ts}
    No further action needed; the "napi-postinstall/fallback" alias resolves correctly.
package.json (1)

22-25: Ensure build outputs match the new export

The export maps to ./lib/fallback.{js,d.ts}. If fallback.ts isn’t compiled (e.g. left out of the tsc -b project) consumers will hit MODULE_NOT_FOUND. Double-check that the build pipeline copies/compiles the file into lib/ before publishing.

test/fallback.spec.ts (2)

11-16: LGTM!

The test correctly validates the fallback function behavior and environment variable setting.


18-25: Test implementation looks good.

The test correctly simulates a webcontainer environment and validates the expected behavior. Note that pipeline failures indicate this test requires pnpm to be available in the test environment.

README.md (2)

79-96: Documentation accurately reflects the new API.

The TypeScript declarations and export pattern correctly document the fallback function signature.


101-113: Clear and helpful usage examples.

The examples effectively demonstrate both the main module usage and the new fallback functionality with appropriate comments.

src/fallback.ts (4)

10-16: Executor mapping looks correct.

The mapping appropriately handles common package managers, with special handling for Deno's npm compatibility layer.


18-31: Helper function implementation is solid.

The function correctly handles both function-based and string/array-based executors.


127-134: Post-processing logic is well implemented.

The environment variable naming convention and require cache clearing ensure proper fallback behavior.


98-125: Package manager execution is cross-platform compatible

Node’s execFileSync automatically resolves .cmd/.exe on Windows, and your EXECUTORS map covers npm, pnpm, yarn, bun, and deno. The detection via npm_config_user_agent plus the fallback to 'npm' will work on all major platforms without changes here.

– execFileSync handles Windows extensions
EXECUTORS includes Yarn (resolved to yarn.cmd on Windows)
– No adjustments needed in src/fallback.ts for cross-platform support

Copy link

codecov bot commented Jul 2, 2025

Codecov Report

Attention: Patch coverage is 79.00000% with 21 lines in your changes missing coverage. Please review.

Project coverage is 40.98%. Comparing base (c610659) to head (5171e16).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/fallback.ts 79.00% 21 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #40      +/-   ##
==========================================
+ Coverage   34.52%   40.98%   +6.46%     
==========================================
  Files           6        7       +1     
  Lines         588      688     +100     
  Branches       59       67       +8     
==========================================
+ Hits          203      282      +79     
- Misses        385      406      +21     

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

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.

Caution

Changes requested ❌

Reviewed 2a33fc0 in 2 minutes and 12 seconds. Click for details.
  • Reviewed 299 lines of code in 9 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. src/fallback.ts:80
  • Draft comment:
    Using fs.rmSync may break on older Node versions; ensure compatibility or provide a fallback (e.g. fs.rmdirSync with recursive) for Node versions below v14.
  • 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 in a new file, so we can set version requirements. The code is using modern Node.js features like node: imports which already requires Node.js 14+. The package is also using TypeScript and seems modern. The comment suggests a workaround but it's likely unnecessary given the apparent modern Node.js requirements. I might be wrong about the Node.js version requirements. There could be users trying to run this on older Node versions. The use of node: protocol imports on L1-4 is a strong signal this code requires Node 14+. Adding backwards compatibility would add complexity for likely no benefit. Delete the comment since the code already has implicit Node 14+ requirements through its use of node: imports.
2. src/fallback.ts:128
  • Draft comment:
    Verify that require.resolve(pkgDir) yields the intended module; using the package directory for cache deletion might be ambiguous. Consider using the package.json path instead for clarity.
  • Reason this comment was not posted:
    Confidence changes required: 50% <= threshold 50% None
3. test/fallback.spec.ts:7
  • Draft comment:
    Directly modifying process.versions (and deleting properties on it) is non-standard; consider using proper mocks to simulate the webcontainer environment.
  • 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% While directly modifying process.versions is unconventional, this is a test file and the modification is cleaned up in afterEach. The test is specifically testing webcontainer behavior and needs to simulate that environment. Using mocks might be cleaner but the current approach works and is contained within tests. The comment raises a valid point about test best practices. Direct modification of process objects could lead to test pollution or unexpected behavior. However, this is an isolated test case with proper cleanup, and the current approach is simple and functional. The suggested change would add complexity without clear benefits. The comment should be deleted as it suggests a style preference rather than a necessary change, and the current implementation is acceptable for testing purposes.
4. test/fallback.spec.ts:19
  • Draft comment:
    This test branch may trigger an actual package installation via execFileSync. Consider mocking filesystem and child process calls to isolate tests.
  • 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 comment is speculative - it says "may trigger" installation, but doesn't show clear evidence that it actually does. The test appears to be testing the fallback functionality which likely needs to interact with real packages. Mocking could make the test less valuable by not testing real behavior. Without seeing the implementation of 'fallback', we can't be certain if execFileSync is even used. I might be underestimating the importance of test isolation. Real filesystem/process operations could make tests slower and less reliable. While test isolation is important, we don't have strong evidence that this test actually performs problematic operations, and mocking could hide real issues we want to catch. Delete the comment as it's speculative ("may trigger") and we don't have strong evidence that mocking is necessary or beneficial here.

Workflow ID: wflow_iwZu0vl70vKjOnlI

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

🧹 Nitpick comments (1)
test/fallback.spec.ts (1)

1-3: Prefer ES-module style imports to preserve type information

import = require() erases generics (e.g. on fallback). With esModuleInterop enabled you can keep full typings and align with the rest of the codebase:

-import unrsResolver = require('unrs-resolver')
-import fallback = require('napi-postinstall/fallback')
+import unrsResolver from 'unrs-resolver'
+import fallback from 'napi-postinstall/fallback'
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 494c8e3 and 2a33fc0.

📒 Files selected for processing (10)
  • .changeset/wet-hounds-sneeze.md (1 hunks)
  • .github/workflows/ci.yml (1 hunks)
  • README.md (2 hunks)
  • package.json (1 hunks)
  • src/constants.ts (1 hunks)
  • src/fallback.ts (1 hunks)
  • src/helpers.ts (1 hunks)
  • src/target.ts (1 hunks)
  • test/fallback.spec.ts (1 hunks)
  • tsconfig.json (1 hunks)
✅ Files skipped from review due to trivial changes (4)
  • .changeset/wet-hounds-sneeze.md
  • src/target.ts
  • src/helpers.ts
  • .github/workflows/ci.yml
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/constants.ts
  • tsconfig.json
  • package.json
  • README.md
  • src/fallback.ts
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: JounQin
PR: un-ts/napi-postinstall#3
File: test/basic.spec.ts:10-14
Timestamp: 2025-04-19T17:37:36.119Z
Learning: JounQin prefers using `resolves.not.toThrow()` for testing Promise<void> functions to verify successful resolution, rather than explicitly checking for `undefined` with `resolves.toBeUndefined()`.
test/fallback.spec.ts (1)
Learnt from: JounQin
PR: un-ts/napi-postinstall#3
File: test/basic.spec.ts:10-14
Timestamp: 2025-04-19T17:37:36.119Z
Learning: JounQin prefers using `resolves.not.toThrow()` for testing Promise<void> functions to verify successful resolution, rather than explicitly checking for `undefined` with `resolves.toBeUndefined()`.
🪛 Biome (1.9.4)
test/fallback.spec.ts

[error] 7-7: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 8-8: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Codacy Static Code Analysis

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 f5c0584 in 53 seconds. Click for details.
  • Reviewed 296 lines of code in 9 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. .github/workflows/ci.yml:41
  • Draft comment:
    Global installation of 'pnpm' is added here. Ensure this aligns with environments that may already have pnpm or restrict global installs.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
2. src/fallback.ts:89
  • Draft comment:
    Using execFileSync('pnpm', …) assumes a global pnpm is available. Consider adding error handling or fallback logic if 'pnpm' is not found.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
3. src/fallback.ts:128
  • Draft comment:
    Cache invalidation with delete require.cache[...] using require.resolve(pkgDir) might not clear all submodules. Confirm this meets your intended reload behavior.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
4. README.md:90
  • Draft comment:
    The new fallback API example is clear; ensure that the declared TypeScript signature matches the CommonJS export behavior.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None

Workflow ID: wflow_LeE17pumHNToO1TN

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

Copy link

codacy-production bot commented Jul 2, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
+6.42% (target: -1.00%) 78.00%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (c610659) 586 199 33.96%
Head commit (5171e16) 686 (+100) 277 (+78) 40.38% (+6.42%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#40) 100 78 78.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

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 d135cf6 in 1 minute and 46 seconds. Click for details.
  • Reviewed 296 lines of code in 9 files
  • Skipped 1 files when reviewing.
  • Skipped posting 7 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/ci.yml:39
  • Draft comment:
    Global install of pnpm ensures its availability in CI. Verify that this version is compatible with project requirements.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
2. README.md:90
  • Draft comment:
    Document that the fallback function is synchronous and blocking, so users know its runtime implications.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
3. package.json:22
  • Draft comment:
    Fallback module export has been correctly added. Ensure the paths to generated type and JS files are valid.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
4. src/fallback.ts:61
  • Draft comment:
    The use of 'process.versions.webcontainer' to detect WebContainer environments is acceptable but may be fragile; ensure all target environments set this flag appropriately.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
5. src/fallback.ts:89
  • Draft comment:
    Direct use of 'pnpm' via execFileSync assumes it's globally available. Consider adding error handling if pnpm is missing or version is incompatible.
  • 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 initially seems reasonable, but looking deeper: 1) This code only runs in webcontainer environments 2) Webcontainers typically have pnpm pre-installed 3) The non-webcontainer path already handles package manager selection properly through userAgent detection and EXECUTORS mapping 4) If pnpm fails, execFileSync will throw an error naturally which will bubble up. I might be making assumptions about webcontainer environments always having pnpm. Also, execFileSync's error might not be as user-friendly as a custom error. While those are valid concerns, the code is specifically for webcontainer environments where pnpm is standard, and the existing error handling through execFileSync is sufficient for this use case. The comment should be deleted as it raises concerns about a non-issue - pnpm usage here is intentional and appropriately scoped to webcontainer environments.
6. src/fallback.ts:128
  • Draft comment:
    Clearing the require cache ensures a fresh module load but may have side effects. Confirm this behavior aligns with the intended fallback mechanism.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
7. test/fallback.spec.ts:19
  • Draft comment:
    The webcontainer test triggers a pnpm install via execFileSync. Consider mocking or stubbing this call to avoid side effects and network dependency during tests.
  • 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 makes claims about implementation details (pnpm install, execFileSync) that aren't visible in the diff or file. Without seeing the implementation of fallback(), I can't verify if this claim is true. The test looks like a standard unit test with no obvious side effects. The comment could be correct - maybe the fallback() function does make system calls that should be mocked. I don't have enough context to definitively say it's wrong. However, per the rules, I should delete comments unless there is STRONG EVIDENCE they are correct. The implementation details mentioned aren't visible in this code. Delete this comment since it makes claims about implementation details that aren't visible in the changed code, and we don't have strong evidence it's correct.

Workflow ID: wflow_rhPC9BbnRGzO59xx

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

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 ea9bf46 in 1 minute and 38 seconds. Click for details.
  • Reviewed 299 lines of code in 9 files
  • Skipped 1 files when reviewing.
  • Skipped posting 6 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/ci.yml:39
  • Draft comment:
    Global install of pnpm is added here. Consider pinning/caching the pnpm version to avoid possible version mismatches.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
2. README.md:90
  • Draft comment:
    The fallback usage example is clear. Consider adding a brief note explaining how behavior differs between webcontainer and non‑webcontainer environments.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
3. src/fallback.ts:89
  • Draft comment:
    The webcontainer branch invokes 'pnpm' via execFileSync. Ensure that pnpm is reliably available in these environments and consider adding error handling or a clearer error message if not.
  • 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 comment raises a valid concern about error handling, but there are several issues: 1) It's speculative - we don't know if pnpm availability is actually a problem in webcontainers 2) execFileSync already throws errors that would be caught by the environment 3) The code already has error messages for other cases 4) This is infrastructure code that likely has its own error handling I might be underestimating the importance of explicit error handling. Missing pnpm could cause confusing errors. While explicit error handling could be nice, the comment is too speculative without evidence that this is a real issue in webcontainers. The existing error handling is likely sufficient. Delete the comment as it's speculative and asks for verification without strong evidence that missing error handling is actually a problem.
4. src/fallback.ts:130
  • Draft comment:
    After running execFileSync in the non‑webcontainer branch, the require cache is cleared via require.resolve(pkgDir). Verify that pkgDir reliably resolves to the module's entry point in all cases.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
5. src/fallback.ts:98
  • Draft comment:
    Defaulting to 'npm' when npm_config_user_agent is missing is reasonable. Ensure that this fallback covers all expected package managers or update EXECUTORS accordingly if needed.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
6. test/fallback.spec.ts:10
  • Draft comment:
    The test resets process.env and process.versions.webcontainer in afterEach. Consider checking for any temporary file cleanup in the webcontainer branch to avoid side effects.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None

Workflow ID: wflow_gt2q5q70s28Vc4UY

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

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 5171e16 in 1 minute and 16 seconds. Click for details.
  • Reviewed 21 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 2 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. test/fallback.spec.ts:8
  • Draft comment:
    Clarify why tests are skipped for Windows; ensure that 'skipIf' is supported in your test framework for consistency.
  • Reason this comment was not posted:
    Confidence changes required: 50% <= threshold 50% None
2. test/fallback.spec.ts:25
  • Draft comment:
    Add an inline comment for the boolean 'true' argument to explain its role in enabling webcontainer fallback behavior.
  • 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 boolean parameter's purpose is somewhat unclear from context alone. However, the test case name 'should support webcontainer' and the setting of process.versions.webcontainer right before the call provides decent context. The suggestion to add an inline comment is more about documentation preference than a required code change. The comment might be helpful for future maintainers who are unfamiliar with the codebase. Not having parameter documentation could make the code harder to understand. While documentation is good, this is a test file where the context is clear from the test name and setup. The comment is more of a style suggestion than a necessary code change. Delete the comment as it violates the rule about not making purely informative comments. The test context already makes the parameter's purpose clear enough.

Workflow ID: wflow_SFfHdoYDXeczndIW

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

@JounQin JounQin merged commit d4719ff into main Jul 2, 2025
42 checks passed
@JounQin JounQin deleted the feat/fallback branch July 2, 2025 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature New feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: support webcontainer by runtime check/fallback
1 participant