-
-
Notifications
You must be signed in to change notification settings - Fork 54
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
Use TypeScript; update deps; refactor exports #58
Conversation
af9e092
to
a431ba3
Compare
* 1. for which Infura has released official, production support ({@see {@link https://docs.infura.io}}) | ||
* 2. which support the JSON-RPC 2.0 protocol | ||
*/ | ||
export type InfuraJsonRpcSupportedNetwork = |
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.
Not sure if it's worth listing all of the possible networks Infura takes, as we don't use them. However there shouldn't be anything in this list for which JSON-RPC is not supported.
a431ba3
to
6a510cf
Compare
@@ -0,0 +1,31 @@ | |||
import type { JsonRpcRequest } from 'json-rpc-engine'; |
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.
This file just has types in it. When yarn build
is run, a types.d.ts
file will be generated which has these types — all good — but a types.js
will also be generated which is empty. I feel like this is how it's supposed to work, but it seems a bit weird to me. Not sure if there's another way we would prefer doing this or we've done this sort of thing before.
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.
Also, Istanbul thinks that there is no test coverage for this file. At the moment this is not breaking anything because I've lowered the coverage thresholds, but in the future I guess we should tell Istanbul to ignore this whole file?
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.
Could we make this a .d.ts
file? That would get skipped by coverage steps, and would not generate an empty .js
file.
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.
Hmm, I don't think so. Then dist/createInfuraMiddleware.d.ts
tries to import ./types
, which is not included in the bundle, and I think that would cause errors for people.
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 meant in-place, like src/types.d.ts
. But I see that that also wouldn't get included in the output. Hmm. We could add a build step to copy it over to the dist
directory, but that seems a little janky. It would work though.
Otherwise, including this file as an empty JS module in the output, and skipping coverage for this file, seems OK to me. Not ideal but I don't see a great way of handling this right now.
a5d8aa0
to
49a7466
Compare
f15ddec
to
669f999
Compare
* **(BREAKING)** Change `index` so that it exports all public modules as named exports * **(BREAKING)** Update all dependencies so that we get TypeScript versions * Convert implementation code to TypeScript * Convert tests to TypeScript, and add tests to ensure that the JavaScript-only checks still work for as much backward compatibility as possible * Add a working TypeDoc configuration file in the event that we want to generate documentation
669f999
to
b405c0f
Compare
This is now rebased and ready for re-review. |
Lots going on in this PR. Maybe the TypeDoc change can be extracted to a separate PR? Seems pretty distinct from the TypeScript conversion - everything else here looks like it has closer ties. |
@Gudahtt Sure, I can extract the TypeDoc stuff. |
Ready for re-review. |
package.json
Outdated
"rimraf": "^3.0.2", | ||
"ts-jest": "^26.3.0", | ||
"ts-node": "^10.7.0", | ||
"typedoc": "^0.22.13", |
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.
Leftover from when typedoc
was extracted from this PR I assume
"typedoc": "^0.22.13", |
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.
Fixed in e7617b4.
tsconfig.json
Outdated
@@ -0,0 +1,17 @@ | |||
{ | |||
"compilerOptions": { | |||
"allowJs": true, |
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.
Is this still needed? And likewise for skipLibCheck
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.
Nope and nope. Removed in f045643.
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.
Actually, for skipLibCheck
, if I take that away, then when I run yarn build
, I get errors like:
node_modules/eth-json-rpc-middleware/dist/block-cache.d.ts:1:37 - error TS2307: Cannot find module 'eth-block-tracker' or its corresponding type declarations.
1 import { PollingBlockTracker } from 'eth-block-tracker';
~~~~~~~~~~~~~~~~~~~
node_modules/eth-json-rpc-middleware/dist/block-ref-rewrite.d.ts:1:37 - error TS2307: Cannot find module 'eth-block-tracker' or its corresponding type declarations.
1 import { PollingBlockTracker } from 'eth-block-tracker';
~~~~~~~~~~~~~~~~~~~
node_modules/eth-json-rpc-middleware/dist/block-ref.d.ts:1:37 - error TS2307: Cannot find module 'eth-block-tracker' or its corresponding type declarations.
1 import { PollingBlockTracker } from 'eth-block-tracker';
~~~~~~~~~~~~~~~~~~~
Looking at the dependencies for eth-json-rpc-middleware
, it doesn't seem that eth-block-tracker
is listed there. It's listed in devDependencies
instead, but I don't think that's right. So that would be need to be fixed first it seems.
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.
PR to fix this: MetaMask/eth-json-rpc-middleware#125
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.
Bumped eth-json-rpc-middleware
to 8.1.0 so build errors should no longer be present.
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 thought we settled on kebab-case.js
as the convention for filenames for our team. We haven't gone back to rename all older modules yet, but I was planning to at some point.
Edit: updated to fix the name of this convention - it's kebab-case not snake_case.
@Gudahtt Hmm, I wasn't aware there was a convention. I know there are some other modules that use snake case, but the controllers repo does not, so I thought snake case was an old convention borrowed from the extension. It also seems that (based on code I've seen) the JavaScript community prefers camelCase and PascalCase over snake-case. I'm happy to change this though if we want to use snake case. |
Right, kebab case. I knew what you meant :) |
Files changed to kebab case in 253fce8. |
src/create-provider.ts
Outdated
@@ -0,0 +1,25 @@ | |||
import { JsonRpcEngine } from 'json-rpc-engine'; | |||
import { providerFromEngine } from 'eth-json-rpc-middleware'; | |||
import { SafeEventEmitterProvider } from 'eth-json-rpc-middleware/dist/utils/cache'; |
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.
Hmm. Not ideal relying upon a type that isn't exported. We should probably update this library to export this.
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.
Good point. I'll work on this. Update: issue added here MetaMask/eth-json-rpc-middleware#126
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.
PR submitted to fix this here: MetaMask/eth-json-rpc-middleware#127
I'm pointing to the latest commit in 9cfa316 just to get the build to pass and will revert this when the above PR is merged.
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.
Bumped eth-json-rpc-middleware
to 8.1.0.
Looks good! Aside from the one outstanding suggestion and the dep update, this seems ready to go |
Co-authored-by: Mark Stacey <markjstacey@gmail.com>
This makes the build errors go away 🎉
Ready for review again. |
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.
LGTM!
index
so that it exports all public modules asnamed exports
versions
JavaScript-only checks still work for as much backward compatibility
as possible
Add a working TypeDoc configuration file in the event that we want togenerate documentation