-
-
Notifications
You must be signed in to change notification settings - Fork 291
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
refactor: reuse command types/utils across packages #6441
Conversation
@@ -49,6 +49,7 @@ | |||
"devDependencies": { | |||
"@types/js-yaml": "^4.0.5", | |||
"@types/triple-beam": "^1.3.2", | |||
"@types/yargs": "^17.0.24", |
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.
I added yargs types as dev dependency to the package as I want to avoid having this as a dependency but this might lead to the case where yargs types result in any
if the consuming project does not install them.
e.g. something like this would not throw an type error
registerCommandToYargs({}, { command: "", describe: "" });
but if you install @types/yargs
as dependency in that project it will complain that first param is not correct
Argument of type '{}' is not assignable to parameter of type 'Argv<{}>'.
Type '{}' is missing the following properties from type 'Argv<{}>': alias, argv, array, boolean, and 66 more.ts(2345
Since this is just an edge use case and all our packages have the types installed, I opted for not adding types as a dependency.
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.
It's find to add types as dev dependency. If we are reexporting the types from this package then we may try duplicating those for now in our source.
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.
I don't think duplicating types for this use case makes sense, and consumers can always install the types if they want to.
@@ -2,6 +2,7 @@ export * from "./yaml/index.js"; | |||
export * from "./assert.js"; | |||
export * from "./base64.js"; | |||
export * from "./bytes.js"; | |||
export * from "./command.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.
The @lodestar/utils
package is integral to be used in lightclient
and prover
. So would be nice if it remains browser compatible and adding yargs
and CLI utils may break the bundlers.
We should try to export Node.js specific utils from a different names export and avoid from default export. May be @lodestar/utils/cli
could be an option.
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.
These are just types, and a utils function which takes in yargs as an argument. I don't see a reason why we would have to export this separately
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 should try to export Node.js specific utils from a different names export and avoid from default export. May be @lodestar/utils/cli could be an option.
I do agree that this is something we should consider, we already use this pattern in the api package.
But for the changes in this PR it is not relevant as it only adds shared types, there is no risk of breaking browser compatibility
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## unstable #6441 +/- ##
============================================
+ Coverage 61.70% 61.72% +0.01%
============================================
Files 553 554 +1
Lines 57848 57939 +91
Branches 1829 1829
============================================
+ Hits 35696 35763 +67
- Misses 22115 22139 +24
Partials 37 37 |
@@ -51,7 +52,6 @@ export const exportCmd: CliCommand<ExportArgs, ISlashingProtectionArgs & Account | |||
|
|||
handler: async (args) => { | |||
const {file} = args; | |||
if (!file) throw new YargsError("must provide file arg"); |
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.
demandOption: true
already ensures that a file arg is provided
demandOption: true, |
@@ -49,6 +49,7 @@ | |||
"devDependencies": { | |||
"@types/js-yaml": "^4.0.5", | |||
"@types/triple-beam": "^1.3.2", | |||
"@types/yargs": "^17.0.24", |
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.
I don't think duplicating types for this use case makes sense, and consumers can always install the types if they want to.
@@ -2,6 +2,7 @@ export * from "./yaml/index.js"; | |||
export * from "./assert.js"; | |||
export * from "./base64.js"; | |||
export * from "./bytes.js"; | |||
export * from "./command.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.
We should try to export Node.js specific utils from a different names export and avoid from default export. May be @lodestar/utils/cli could be an option.
I do agree that this is something we should consider, we already use this pattern in the api package.
But for the changes in this PR it is not relevant as it only adds shared types, there is no risk of breaking browser compatibility
Performance Report✔️ no performance regression detected Full benchmark results
|
🎉 This PR is included in v1.17.0 🎉 |
Motivation
Noticed we copy-pasted command types/utils in different packages but we only really maintain the ones in the CLI package.
This PR aims to consolidate types by moving those into the utils package to improve consistency and reduce future maintenance.
Description
@lodestar/utils
packagedemandOption: true
) if arg must be provided instead of checking separately