refactor: reuse command types/utils across packages - #6441
Conversation
| "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.
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(2345Since 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.
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.
I don't think duplicating types for this use case makes sense, and consumers can always install the types if they want to.
| export * from "./assert.js"; | ||
| export * from "./base64.js"; | ||
| export * from "./bytes.js"; | ||
| export * from "./command.js"; |
There was a problem hiding this comment.
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.
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.
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 |
|
|
||
| handler: async (args) => { | ||
| const {file} = args; | ||
| if (!file) throw new YargsError("must provide file arg"); |
There was a problem hiding this comment.
demandOption: true already ensures that a file arg is provided
| "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.
I don't think duplicating types for this use case makes sense, and consumers can always install the types if they want to.
| export * from "./assert.js"; | ||
| export * from "./base64.js"; | ||
| export * from "./bytes.js"; | ||
| export * from "./command.js"; |
There was a problem hiding this comment.
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/utilspackagedemandOption: true) if arg must be provided instead of checking separately