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

Proof-of-concept: Rewrite to ts #212

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

ole-martin
Copy link
Contributor

Proof of concept for rewriting SDK to TS.
This PR contains the following changes:

  • Refactor Babel to include TS-support
  • Refactor Webpack config to accept .ts (And also greatly speed up build by using separate config instead of cli)
  • Rewrite Cache.js -> Cache.ts | Preserving JSDoc formatting
  • Rewrite Identity.js -> Identity.ts | Switching to TSDoc formatting

What needs to be done?

  • Are we OK with TS? I'm going to assume yes.
  • Drop or keep JSDoc? Personally I would prefer removing it and switching to TSDoc https://github.com/microsoft/tsdoc but it will require setting this up as well instead of keeping the current JSDoc site generation.

The following has not been done and should be fixed after the above has been decided:

  • Add ts-jest for running jest on TS-files.
  • Upgrade to webpack v5 (shouldn't be too hard since it is in a separate config file now)
  • Upgrade other dependencies as well since the there are quite a few old packages in there.

Co-authored-by: @PAkerstrand

Copy link
Contributor

@filipprasalek filipprasalek left a comment

Choose a reason for hiding this comment

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

First of all I would like you thank you for this contribution, it is great progress in terms of TS integration 🙇

I had a few rather small comments regarding structuring of the project etc. but other than that it looks really good and reasonable 👌

We can discuss on priv how to move forward with that.

Comment on lines +1 to +3
#!/bin/bash

rm -rf es5
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this file is not used 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's the folder webpack use to output es5 into, so at least for now it is still used and should be cleaned I think. (This was the only non-webpack command from the old build.sh)

"prebuild": "npm run clean",
"build": "npm run build:types && npm run build:js",
"build:types": "tsc --emitDeclarationOnly",
"build:js": "webpack"
Copy link
Contributor

Choose a reason for hiding this comment

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

By default it could build only prod and prodGlobal configs (e.g. could be done by specifying config name and using config-name flag)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, I was mainly concerned with migrating existing functionality 1:1, but lets note that as an improvement. With the new setup webpack runs all the tasks in parallell tho, so it won't make that much of a difference.

@@ -0,0 +1,12 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably it would make sense to specify outDir to the same one as in webpack config as ideally we would release only dist directory to reduce bundle size.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Once everything is converted to TS then that would make sense, but for this partial rewrite to work we cannot do that just yet.

@@ -3,3 +3,4 @@
coverage
Copy link
Contributor

Choose a reason for hiding this comment

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

Note to myself: we need to add eslint typescript plugin

@@ -2,175 +2,126 @@
* See LICENSE.md in the project root.
Copy link
Contributor

Choose a reason for hiding this comment

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

Just 2 general thoughts regarding this file:

  • small thing, you've changed strings from this notation '' to "" 😅
  • in some cases (e.g. IdentityOptions) you've introduced duplicate declarations, both in identity.d.ts and identity.ts file - is there any reason for that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry about the first, I guess lack of ts-lint and/or prettier config made " my formatting default. Will ofc fix this!
Regarding duplicates in identity.d.ts & identity.ts those are expected since identity.d.ts is now generated from identity.ts then all exported members should be present in both files. (Unless I misunderstood something).

@ole-martin
Copy link
Contributor Author

@filipprasalek thank you for reviewing this!
Do you have any thoughts regarding migrating from JSDocs -> TSDocs as well or not? (Since that would also simplify things a lot)

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