-
-
Notifications
You must be signed in to change notification settings - Fork 414
feat: add pattern for runtime specific package dependencies #8320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @nazarhussain, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request focuses on enhancing the Lodestar project's compatibility with the Bun JavaScript runtime. It involves significant updates to module resolution, dependency handling, and TypeScript configurations to ensure the application can successfully initialize and run in a Bun environment. The changes are foundational for broader multi-runtime support, allowing the project to leverage the performance and features of different JavaScript runtimes.
Highlights
- Bun Runtime Compatibility: The primary goal of this pull request is to enable Lodestar to run correctly within the Bun JavaScript runtime environment, addressing compatibility issues.
- Subpath Imports for Runtime Specificity: Introduced a new
importsfield inpackage.jsonto allow for runtime-specific package resolutions, specifically forprometheus-gc-stats, enabling a Bun-specific wrapper. - TypeScript Configuration Updates: Modified
tsconfig.jsonandtsconfig.build.jsonfiles to setmoduleandmoduleResolutiontonode16, which is crucial for modern module resolution in Node.js and Bun environments. - Dependency Import Path Adjustments: Updated import paths for several internal and external dependencies, including
@chainsafe/libp2p-gossipsuband@chainsafe/discv5, to ensure correct module resolution. - Type Assertions and Explicit Typing: Added explicit type assertions (
as any) and type annotations in various files to resolve TypeScript compilation issues, particularly related tomoduleResolution: node16and third-party library types. - New Bun-Specific GC Stats Wrapper: A new file
packages/beacon-node/src/bun-wrappers/prometheus-gc-stats.tswas added, providing a no-opgcStatsfunction specifically for the Bun runtime, to avoid issues with the Node.js-specificprometheus-gc-stats. - Custom Type Declarations for Threads: A new type declaration file
types/@chainsafe/threads/index.d.tswas added to provide correct type definitions for the@chainsafe/threadslibrary, improving type checking and compatibility. - New Type Export: The
ExecutionAddressTypehas been exported frompackages/types/src/index.ts, making it available for broader use within the project.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces support for the Bun runtime by leveraging conditional imports in package.json. This allows for runtime-specific dependencies, demonstrated by providing a mock for prometheus-gc-stats which is not compatible with Bun. A significant part of this change involves updating the TypeScript configuration to use module: "node16" and moduleResolution: "node16", which is a good step towards modernizing the codebase for native ES modules. The subsequent changes across various files are mostly necessary adjustments to satisfy the stricter type checking that comes with this new configuration. My review found one area in the thread pool implementation where a type cast seems incorrect and could hide potential issues.
packages/cli/src/cmds/validator/keymanager/decryptKeystores/threadPool.ts
Outdated
Show resolved
Hide resolved
| "./fulu": { | ||
| "import": "./lib/fulu/index.js" | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Module resolution node16 does not check for directories if subpath exports are available.
Performance Report✔️ no performance regression detected Full benchmark results
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## unstable #8320 +/- ##
============================================
- Coverage 52.27% 52.26% -0.01%
============================================
Files 853 853
Lines 64742 64780 +38
Branches 4765 4766 +1
============================================
+ Hits 33842 33858 +16
- Misses 30830 30852 +22
Partials 70 70 🚀 New features to boost your workflow:
|
wemeetagain
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me now :)
**Motivation** Upgrade typescript to latest version. **Description** - Upgrade typescript to latest version. - Need this version upgrade to be used in #8320 to allow `module: node20>` **Steps to test or reproduce** Run all tests
61e1cdd to
46bcd80
Compare
**Motivation** Use latest `module` and `moduleResolution` for TS. **Description** - To use [subpath imports](https://nodejs.org/api/packages.html#subpath-imports) in the PR #8320 we need to update the module solution strategy for TS. - That requires to change the `module` for the TS as well. - Earlier tried to stay with `node18` or `node20`, but the `ts-node` does not work with that. - Maintaining different tsconfig for ts-node is more of hassle on wrong run. - So decided to stick with `nodenext` strategy for `moduleResolution` **Steps to test or reproduce** Run all tests --------- Co-authored-by: Cayman <caymannava@gmail.com>
087533b to
8b2eb16
Compare
| } as ConstructorParameters<typeof Worker>[1]); | ||
| // Bun does not support resourceLimits | ||
| const workerOptions = ( | ||
| "bun" in process.versions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use globalThis.Bun check instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't safely use that because in some context we get
Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature
We have to define type signature fo globalThis. Let's do that in a separate PR and update all occurrences of "bun" in process.versions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then this specific diff can be removed (it doesn't have anything to do with the internal package import pattern)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok removed from this PR.
|
this pattern doesn't work with bun 😂 |
|
Nevermind, this pattern does work with bun! The problem I'd seen had to do with the referenced import file not being found (not being built) |
**Motivation** - #7280 **Description** - update `@types/node` to the latest node v22 version - add `@lodestar/bun` dependency using git+https (for now! so that we don't have to republish a bazillion times) - keep in mind that this requires a manual build/rebuild of the so (via `cd node_modules/@lodestar/bun && zig build`) - Add a bun-specific `LevelDbController` which uses [`@lodestar/bun`](https://github.com/ChainSafe/lodestar-bun) - Only expose the leveldb controller via a subpath export (and for tests, as a custom import, like in #8320 ) - add bun bun global override types
|
🎉 This PR is included in v1.35.0 🎉 |
Motivation
Make sure the Lodestar starts running in Bun runtime.
Description
Steps to test or reproduce
Run all tests
Note
The CLI finally starts to run, next go with command by command to see what's breaking, starting the
beaconcmd.