Skip to content

fix: various napi build fix#1667

Merged
HerringtonDarkholme merged 6 commits into
mainfrom
feat-improve-napi-type
Dec 15, 2024
Merged

fix: various napi build fix#1667
HerringtonDarkholme merged 6 commits into
mainfrom
feat-improve-napi-type

Conversation

@HerringtonDarkholme

@HerringtonDarkholme HerringtonDarkholme commented Dec 15, 2024

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features

    • Expanded build configurations to support multiple host and target combinations, enhancing compatibility across macOS, Windows, and Ubuntu.
  • Bug Fixes

    • Updated the prepublishOnly script to streamline the publishing process by removing unnecessary commands.
  • Refactor

    • Modified output format for TypeScript definition files to improve clarity and maintainability.
  • Chores

    • Added compiler option to improve TypeScript compilation speed by skipping type checks on declaration files.

@coderabbitai

coderabbitai Bot commented Dec 15, 2024

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@HerringtonDarkholme has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 17 minutes and 31 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 fe5f9db and b60b5e6.

📒 Files selected for processing (1)
  • crates/napi/scripts/generateTypes.ts (1 hunks)

Walkthrough

This pull request focuses on enhancing the build and type generation workflow for the NAPI (Node-API) package. The changes include expanding the GitHub Actions workflow to support multiple build targets across macOS, Windows, and Linux architectures. Additionally, the type generation script for the NAPI package has been modified to change how language node types are exported, and the package.json script for prepublishing has been simplified by removing the type generation step.

Changes

File Change Summary
.github/workflows/napi.yml Expanded build matrix to include multiple architectures for macOS, Windows, and Linux (x86_64, aarch64, i686) with specific Docker images and build configurations.
crates/napi/package.json Removed yarn typegen from prepublishOnly script, now directly calling napi prepublish. Modified test script to include TypeScript compilation check before running tests.
crates/napi/scripts/generateTypes.ts Modified type generation to export a default type with a new format, including an auto-generated comment.
crates/napi/tsconfig.json Added compiler option "skipLibCheck": true to improve compilation speed by skipping type checks on declaration files.

Sequence Diagram

sequenceDiagram
    participant GHA as GitHub Actions
    participant Build as Build Job
    participant Publish as Publish Job
    
    GHA->>Build: Trigger build matrix
    Build->>Build: Build for multiple architectures
    alt Build Successful
        Build-->>Publish: Trigger publish
        Publish->>Publish: Prepare artifacts
    else Build Failed
        Build--xPublish: Halt publication
    end
Loading

Possibly related PRs

Poem

🐰 Builds hopping far and wide,
Architectures multiplied with pride.
Workflows dancing, targets clear,
NAPI's reach now spans everywhere.
Rabbit's build magic takes its flight! 🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
.github/workflows/napi.yml (1)

62-77: Consider adding tests for ARM64 builds

The ARM64 builds (aarch64-unknown-linux-musl and aarch64-unknown-linux-gnu) don't include test execution. While cross-architecture testing can be challenging, consider adding tests if possible.

Options to consider:

  1. Use QEMU for ARM64 emulation during tests
  2. Set up dedicated ARM64 runners
  3. Add architecture-specific test skip logic
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2b56ed2 and f55ca9b.

📒 Files selected for processing (3)
  • .github/workflows/napi.yml (2 hunks)
  • crates/napi/package.json (1 hunks)
  • crates/napi/scripts/generateTypes.ts (1 hunks)
🧰 Additional context used
📓 Learnings (1)
crates/napi/scripts/generateTypes.ts (2)
Learnt from: HerringtonDarkholme
PR: ast-grep/ast-grep#1662
File: crates/napi/scripts/generate-types.ts:49-49
Timestamp: 2024-12-14T18:57:37.142Z
Learning: In `crates/napi/scripts/generate-types.ts`, it's expected to assign the output of `JSON.stringify(nodeTypeMap, null, 2)` directly to a TypeScript type alias using `export type` syntax.
Learnt from: HerringtonDarkholme
PR: ast-grep/ast-grep#1662
File: crates/napi/scripts/generate-types.ts:128-129
Timestamp: 2024-12-14T18:57:47.685Z
Learning: In `crates/napi/scripts/generate-types.ts`, when re-exporting modules that only export types (e.g., `./types/${lang}-node-types`), use `export type { ... }` to correctly re-export the types in TypeScript.
🔇 Additional comments (5)
crates/napi/scripts/generateTypes.ts (1)

40-46: Consider impact of default export on type consumers

While the new type export format is cleaner, changing from named exports to default exports might require updates in consuming code. Additionally, consider adding more metadata in the auto-generated comment.

Let's verify the impact on type consumers:

Consider enhancing the auto-generated comment with:

-// This file is auto-generated by ast-grep script
+// This file is auto-generated by ast-grep
+// Generated from tree-sitter grammar version: ${tag}
+// DO NOT EDIT
crates/napi/package.json (1)

47-47: LGTM! Script simplified as types are generated in CI

The removal of typegen from prepublishOnly is correct since type generation is now handled in the CI workflow (see .github/workflows/napi.yml).

.github/workflows/napi.yml (3)

53-61: LGTM! Comprehensive musl target configuration

The Linux musl target configuration is well-structured with proper build steps and test execution.


78-83: LGTM! Well-configured Apple Silicon support

The aarch64-apple-darwin target is properly configured with both build and test steps.


25-30: Verify test coverage for macOS x86_64 target

The macOS x86_64 build is missing test execution. Consider adding tests for consistency with other targets.

Let's check if tests are compatible with this target:

✅ Verification successful

Tests can be safely added for macOS x86_64 target

The test suite uses the ava test framework and consists of platform-agnostic tests that verify core functionality like parsing, finding nodes, and code transformations. There are no platform-specific test cases or dependencies that would prevent the tests from running on macOS x86_64. The tests should be added to maintain consistency with other targets and ensure reliability across all supported platforms.

  • Add test execution for macOS x86_64 target in .github/workflows/napi.yml similar to other targets
  • Example addition:
build: |
  yarn build --target x86_64-apple-darwin
  strip -x *.node
  yarn test
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for platform-specific test code
rg -l "process\.platform.*darwin" crates/napi/test/

Length of output: 111


Script:

#!/bin/bash
# Let's first find the test directory structure
fd test --type d

# Then check for any platform-specific test code in all test files
rg -l "process\.platform.*darwin"

Length of output: 131


Script:

#!/bin/bash
# Check test files in the NAPI directory for any platform-specific tests
rg -l "test" crates/napi/__test__/

# Look for any test configuration or setup files
fd -t f . crates/napi/__test__/

# Check if there are any test scripts in package.json
rg "test.*script" package.json

Length of output: 254


Script:

#!/bin/bash
# Let's examine the test file content to understand the test structure
cat crates/napi/__test__/index.spec.ts

# Also check if there's any platform-specific configuration in the test.vue file
cat crates/napi/__test__/test.vue

Length of output: 11552

@codecov

codecov Bot commented Dec 15, 2024

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.13%. Comparing base (2b56ed2) to head (b60b5e6).
Report is 6 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1667   +/-   ##
=======================================
  Coverage   87.13%   87.13%           
=======================================
  Files          96       96           
  Lines       15476    15476           
=======================================
  Hits        13485    13485           
  Misses       1991     1991           

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

@HerringtonDarkholme HerringtonDarkholme added this pull request to the merge queue Dec 15, 2024
Merged via the queue into main with commit da4f680 Dec 15, 2024
@HerringtonDarkholme HerringtonDarkholme deleted the feat-improve-napi-type branch December 15, 2024 01:23
@HerringtonDarkholme HerringtonDarkholme restored the feat-improve-napi-type branch December 15, 2024 01:25
@coderabbitai coderabbitai Bot mentioned this pull request Mar 29, 2026
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.

1 participant