Skip to content
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

Merged
merged 16 commits into from
May 2, 2022
Merged

Conversation

mcmire
Copy link
Contributor

@mcmire mcmire commented Apr 1, 2022

  • (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

@mcmire mcmire requested a review from a team as a code owner April 1, 2022 22:29
@mcmire mcmire force-pushed the convert-to-typescript branch 2 times, most recently from af9e092 to a431ba3 Compare April 1, 2022 22:36
typedoc.json Outdated Show resolved Hide resolved
* 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 =
Copy link
Contributor Author

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.

@@ -0,0 +1,31 @@
import type { JsonRpcRequest } from 'json-rpc-engine';
Copy link
Contributor Author

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.

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

@mcmire mcmire force-pushed the convert-to-jest branch 2 times, most recently from a5d8aa0 to 49a7466 Compare April 6, 2022 16:55
Base automatically changed from convert-to-jest to main April 6, 2022 20:26
* **(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
@mcmire
Copy link
Contributor Author

mcmire commented Apr 8, 2022

This is now rebased and ready for re-review.

.eslintrc.js Outdated Show resolved Hide resolved
@Gudahtt
Copy link
Member

Gudahtt commented Apr 13, 2022

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.

@mcmire
Copy link
Contributor Author

mcmire commented Apr 14, 2022

@Gudahtt Sure, I can extract the TypeDoc stuff.

@mcmire mcmire self-assigned this Apr 21, 2022
@mcmire
Copy link
Contributor Author

mcmire commented Apr 26, 2022

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",
Copy link
Member

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

Suggested change
"typedoc": "^0.22.13",

Copy link
Contributor Author

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 Show resolved Hide resolved
tsconfig.json Outdated
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"allowJs": true,
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

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.

tsconfig.json Outdated Show resolved Hide resolved
tsconfig.build.json Outdated Show resolved Hide resolved
src/types.ts Outdated Show resolved Hide resolved
Copy link
Member

@Gudahtt Gudahtt left a 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.

@mcmire
Copy link
Contributor Author

mcmire commented Apr 27, 2022

@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.

@mcmire
Copy link
Contributor Author

mcmire commented Apr 27, 2022

Right, kebab case. I knew what you meant :)

@mcmire
Copy link
Contributor Author

mcmire commented Apr 27, 2022

Files changed to kebab case in 253fce8.

src/fetchConfigFromReq.ts Outdated Show resolved Hide resolved
src/create-infura-middleware.ts Outdated Show resolved Hide resolved
@@ -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';
Copy link
Member

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.

Copy link
Contributor Author

@mcmire mcmire Apr 27, 2022

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@Gudahtt
Copy link
Member

Gudahtt commented Apr 28, 2022

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>
@mcmire
Copy link
Contributor Author

mcmire commented May 2, 2022

Ready for review again.

Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

LGTM!

@mcmire mcmire merged commit ec3e88e into main May 2, 2022
@mcmire mcmire deleted the convert-to-typescript branch May 2, 2022 15:43
This was referenced May 2, 2022
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.

2 participants