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

SDK Modernization #584

Merged
merged 26 commits into from
Apr 13, 2023
Merged

SDK Modernization #584

merged 26 commits into from
Apr 13, 2023

Conversation

Shaptic
Copy link
Contributor

@Shaptic Shaptic commented Apr 4, 2023

Epic: stellar/js-stellar-sdk#792

This is an overhaul to bring the stellar-base package to the modern JavaScript world.

Summary

This involves a large set of changes, but I will do my best to summarize them to expedite review.

Main Changes

  • Webpack 5 + Babel is now the main build system
  • GulpJS is no longer used for any build pipelines
  • All dependencies have either been upgraded to their latest versions OR replaced with maintained equivalents.
    • This involved code changes to bring the library up to compatibility with BigNumber.js.

Cascading Changes

These main changes motivate a cascade of other changes, broken down into a handful of categories:

  • Building: Packaging is done via Webpack for the browser and Babel for Node
  • Linting: ESLint is updated, JS/TS linting is better
  • Testing: Libraries are updated + modernized
  • Running: yarn scripts are different

Building

Webpack 5 support is here!

  • the node package is built using Babel via yarn build:node
  • the browser bundle is built using Webpack via yarn build:browser
    • this is configured in cfg/webpack.config.browser.js
    • its accessible after including the script via the StellarBase variable
    • it adds a handful of important polyfills
    • it does linting via ESLint

Linting

ESLint, Prettier, and DTSLint are all updated:

  • ESLint works with Babel via the @babel/eslint-parser in each .eslintrc.js file and is implicitly part of building via Webpack (see above)
  • DTSLint is part of the @definitelytyped project and has additional configuration implicitly as part of the types/.eslintrc.js file which uses @typescript-eslint/parser, instead
  • Prettier is configured in cfg/prettier.config.js (and cfg/.prettierignore) and runs on all files now. It's also (still) a pre-commit hook.

Just run yarn pretty && yarn lint to format your files and check that everything is up to par.

Testing

Istanbul: Istanbul is unmaintained and superceded by the nyc package.

  • the istanbul plugin in .babelrc tells Babel about it
  • cfg/.nycrc extends a Babel-compatible configuration file (docs)
  • the nyc key in package.json configures instrumentation behavior
  • the coverage is actually provided by babel-plugin-istanbul (docs), which is why "instrument": false in the above

Node Testing: Mocha (and its helper friends Sinon and Chai) has been updated.

  • the mocha key in package.json configures Mocha (replacing mocha.opts)
  • this does Babel transpiling and hooks in the helper script
  • code coverage is provided by nyc (see above)

Browser Testing: Karma has been updated.

  • the SauceLabs Karma configuration has been removed entirely because it wasn't being used
  • Karma has been updated with a code coverage integration with nyc (docs, see above)
  • It relies on the Webpack configuration but makes some minor changes

Run yarn test to run both suites.

Scripts

Development has a slightly different workflow now:

  • build+test locally with yarn test:node
  • this will only run node tests (which are faster/simpler)
  • you can yarn build && yarn test:all to get the both test suites (note that building first is required)
  • run yarn preversion when you want a thorough, clean test of the whole system in "production" mode

@Shaptic Shaptic marked this pull request as ready for review April 4, 2023 19:22
@Shaptic Shaptic requested a review from paulbellamy April 4, 2023 19:23
@Shaptic
Copy link
Contributor Author

Shaptic commented Apr 4, 2023

@BenRacicot would appreciate your review as well

@Shaptic Shaptic changed the title [DRAFT] SDK modernization SDK Modernization Apr 4, 2023
@Shaptic Shaptic linked an issue Apr 4, 2023 that may be closed by this pull request
Copy link
Contributor

@paulbellamy paulbellamy left a comment

Choose a reason for hiding this comment

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

Outstanding work! 💯 🚀

Couple questions...

lib/account.js Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
src/util/continued_fraction.js Outdated Show resolved Hide resolved
Add 'prepare' script instead of lib/ folder
Fix GHAs to match build scripts
Makefile Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

The main xdr repository has moved out of core to https://github.com/stellar/stellar-xdr repo, curr and next branches respectively.

Copy link
Contributor

@silence48 silence48 left a comment

Choose a reason for hiding this comment

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

I only came across one questionable thing which was the address to the xdr library...

Many of these changes are code linting, which is fine, but I'd prefer to see those broken into a separate commit to be able to quickly find the substantive changes.

Otherwise it looks good.

Copy link
Contributor

@silence48 silence48 left a comment

Choose a reason for hiding this comment

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

that works, /generated after all.

Copy link
Contributor

@paulbellamy paulbellamy left a comment

Choose a reason for hiding this comment

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

LGTM, but I'm not an expert here.

package.json Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved
@paulbellamy
Copy link
Contributor

Also, if you could merge these changes into the soroban branch, after they are merged into main. 🙏

@Shaptic Shaptic changed the base branch from master to soroban April 13, 2023 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Update dependencies for a modern SDK
3 participants