Skip to content

SDK Modernization - #584

Merged
Shaptic merged 26 commits into
sorobanfrom
modernize
Apr 13, 2023
Merged

Shaptic merged 26 commits into
sorobanfrom
modernize

Conversation

@Shaptic

@Shaptic Shaptic commented Apr 4, 2023 •

Copy link
Copy Markdown
Contributor

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

Shaptic commented Apr 4, 2023

Copy link
Copy Markdown
Contributor Author

@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

@paulbellamy paulbellamy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Outstanding work! 💯 🚀

Couple questions...

Comment thread lib/account.js Resolved
Comment thread package.json Resolved
Comment thread package.json Resolved
Comment thread package.json Resolved
Comment thread src/util/continued_fraction.js Resolved
Add 'prepare' script instead of lib/ folder
Fix GHAs to match build scripts
Comment thread Makefile

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
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.

@silence48 silence48 left a comment

Copy link
Copy Markdown
Contributor

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.

@silence48 silence48 left a comment

Copy link
Copy Markdown
Contributor

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.

@paulbellamy paulbellamy left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread package.json Resolved
Comment thread package.json Resolved
@paulbellamy

Copy link
Copy Markdown
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