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 #585

Merged
merged 25 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8319913
WIP: Massive modernization of the entire SDK
Shaptic Apr 4, 2023
2dbcc25
Remove unnecessary files + changes
Shaptic Apr 4, 2023
000ffdf
Universal prettier-ification
Shaptic Apr 4, 2023
9d5e339
Update GHA to new commands
Shaptic Apr 4, 2023
947a699
Upgrade *all* the things, drop unused sauce
Shaptic Apr 4, 2023
82315bd
Update library to conform to the new BigNumber API
Shaptic Apr 4, 2023
f565717
Fixups: JSDoc generating, CI testing steps, unused libs, etc.
Shaptic Apr 4, 2023
6d687b9
Add typescript+linter 'fixes'
Shaptic Apr 4, 2023
fe9a525
Fix linting parser
Shaptic Apr 4, 2023
7197fc5
Add proper code coverage to node/browser
Shaptic Apr 4, 2023
67d10ad
Fixup the prettier support/workflow
Shaptic Apr 4, 2023
b413b53
Run prettier on the whole codebase
Shaptic Apr 4, 2023
b6583c2
Dropping unneeded rule till I learn why it was there
Shaptic Apr 4, 2023
15fcb6d
Add prod-specific build script
Shaptic Apr 4, 2023
2b0108e
Undo version bump: there may be more PRs later
Shaptic Apr 4, 2023
7a4d6df
Generate the node package via Babel not Webpack
Shaptic Apr 4, 2023
15f13d3
Add build scripts for proper CI
Shaptic Apr 4, 2023
738ccb8
Shuffle around dependencies
Shaptic Apr 4, 2023
0860f74
Temporarily add lib folder
Shaptic Apr 4, 2023
0aa2cdd
Set BigNumber debugging globally
Shaptic Apr 6, 2023
3f894e2
Clean up yarn scripts to make more sense
Shaptic Apr 6, 2023
7abe525
Undo XDR changes as they should be irrelevant
Shaptic Apr 10, 2023
8a8a731
Only generate code coverage in dev mode
Shaptic Apr 11, 2023
b5ad486
Update README with new yarn scripts
Shaptic Apr 11, 2023
95e8d25
Fixup commit hook
Shaptic Apr 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"presets": [
["env", {
"targets": {
"ie": "11"
"@babel/preset-env"
],
"env": {
"development": {
"plugins": [
"istanbul"
]
}
}]
]
}
}
9 changes: 0 additions & 9 deletions .eslintrc.js

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/gh_pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ jobs:
- name: Install Dependencies
run: yarn install

- name: Build
run: gulp
- name: Build & Test
run: yarn preversion

- name: Checkout GH pages
uses: actions/checkout@v2
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/npm_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ jobs:
- name: Install Depencencies
run: yarn

- name: Build
run: gulp
- name: Test & Build
run: yarn preversion

- name: Publish npm package
run: yarn publish
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
fail-fast: false
max-parallel: 2
matrix:
node-version: [14, 16]
node-version: [14, 16, 18]

steps:
- uses: actions/checkout@v2
Expand All @@ -26,14 +26,14 @@ jobs:
- name: Install Dependencies
run: yarn install

- name: Build
run: gulp
- name: Build All
run: yarn build:prod

- name: Run Node Tests
run: yarn test
run: yarn test:node

- name: Run Browser Tests
run: gulp test:browser
run: yarn build:browser:prod && yarn test:browser

- name: Run Linter
run: yarn dtslint
run: yarn lint
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
.nvmrc
.nyc_output/
/node_modules/
/tmp/
/lib/
/dist/
/config/dist/
/coverage/
/jsdoc/
.DS_Store
4 changes: 0 additions & 4 deletions .jshintrc

This file was deleted.

1 change: 0 additions & 1 deletion .nvmrc

This file was deleted.

7 changes: 0 additions & 7 deletions .prettierignore

This file was deleted.

1 change: 0 additions & 1 deletion .tool-versions

This file was deleted.

6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Then please [sign the Contributor License Agreement](https://docs.google.com/for


# Releasing
SDK maintainers should follow [semantic versioning](https://semver.org/) best practices for releasing the SDK.
SDK maintainers should follow [semantic versioning](https://semver.org/) best practices for releasing the SDK.

Use your best judgement when deciding on when to craft a release: maybe enough changes have accumulated to warrant a release, maybe there's a high-urgency fix that needs to be published immediately, or maybe you can put it off for a particular feature. It's all dependent on what else is going on.

Expand All @@ -22,9 +22,9 @@ Once all of the PRs for a particular release are in, it's time to actually publi

- [ ] Ensure that all of the PRs in this delta are accurately reflected in the [CHANGELOG](./CHANGELOG.md), broken down by impact and linking to the corresponding PRs. Update the file if necessary.

- [ ] Update the top-level `"version"` field in the [package.json](./package.json) file to reflect the new version.
- [ ] Run `yarn preversion` to build and test an optimized bundle and ensure Typescript compatibility (one of the most common sources of bugs, since this library is written purely in JS but must be usable from TS).

- [ ] Run the final sanity check to ensure the builds pass: `yarn dtslint && yarn test && yarn preversion`. The first command checks that you have Typescript compatibility (one of the most common sources of bugs, since this library is written purely in JS but must be usable from TS).
- [ ] Run `yarn version` to update the version number in the package.json (or modify the `"version"` field manually).

- [ ] Commit & push your branch, then [create a PR](https://github.com/stellar/js-stellar-base/compare).

Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
XDR_BASE_URL_CURR=https://github.com/stellar/stellar-core/raw/master/src/protocol-curr/xdr
XDR_BASE_URL_CURR=https://github.com/stellar/stellar-xdr/raw/curr
XDR_BASE_LOCAL_CURR=xdr/curr
XDR_FILES_CURR= \
Stellar-SCP.x \
Expand All @@ -9,7 +9,7 @@ XDR_FILES_CURR= \
Stellar-types.x
XDR_FILES_LOCAL_CURR=$(addprefix xdr/curr/,$(XDR_FILES_CURR))

XDR_BASE_URL_NEXT=https://github.com/stellar/stellar-xdr-next/raw/main
XDR_BASE_URL_NEXT=https://github.com/stellar/stellar-xdr/raw/next
XDR_BASE_LOCAL_NEXT=xdr/next
XDR_FILES_NEXT= \
Stellar-SCP.x \
Expand Down
35 changes: 19 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ implementation in JavaScript that can be used on either Node.js or web browsers.

> **Warning!** The Node version of this package uses the [`sodium-native`](https://www.npmjs.com/package/sodium-native) package, a native implementation of [Ed25519](https://ed25519.cr.yp.to/) in Node.js, as an [optional dependency](https://docs.npmjs.com/files/package.json#optionaldependencies).
> This means that if for any reason installation of this package fails, `stellar-base` will fallback to the much slower implementation contained in [`tweetnacl`](https://www.npmjs.com/package/tweetnacl).
>
>
> If you'd explicitly prefer **not** to install the `sodium-native` package, pass the appropriate flag to skip optional dependencies when installing this package (e.g. `--no-optional` if using `npm install` or `--without-optional` using `yarn install`).
>
>
> If you are using `stellar-base` in a browser you can ignore this. However, for production backend deployments you should most likely be using `sodium-native`.
> If `sodium-native` is successfully installed and working,
> `StellarBase.FastSigning` variable will be equal `true`. Otherwise it will be
Expand Down Expand Up @@ -102,11 +102,11 @@ Make sure that you are using the latest version number. They can be found on the

We support the oldest LTS release of Node, which is [currently 14.x](https://nodejs.org/en/about/releases/). Please likewise install and develop on Node 14 so you don't get surprised when your code works locally but breaks in CI.

If you work on several projects that use different Node versions, you might find helpful to install a nodejs version manager.
If you work on several projects that use different Node versions, you might find helpful to install a NodeJS version manager:

- https://github.com/creationix/nvm
- https://github.com/wbyoung/avn
- https://github.com/asdf-vm/asdf
- https://github.com/creationix/nvm
- https://github.com/wbyoung/avn
- https://github.com/asdf-vm/asdf

2. Install Yarn

Expand All @@ -127,17 +127,22 @@ yarn

5. Observe the project's code style

While you're making changes, make sure to run the linter-watcher to catch any
While you're making changes, make sure to regularly run the linter to catch any
linting errors (in addition to making sure your text editor supports ESLint)

```shell
node_modules/.bin/gulp watch
yarn lint
```

as well as fixing any formatting errors with

```shell
yarn fmt
```

If you're working on a file not in `src`, limit your code to Node 6.16 ES! See
what's supported here: https://node.green/ (The reason is that our npm library
must support earlier versions of Node, so the tests need to run on those
versions.)
what's supported here: https://node.green/. (Our npm library must support
earlier versions of Node, so the tests need to run on those versions.)

#### Updating XDR definitions

Expand All @@ -154,18 +159,16 @@ For information on how to use js-stellar-base, take a look at the docs in the
To run all tests:

```shell
gulp test
yarn test
```

To run a specific set of tests:

```shell
gulp test:node
gulp test:browser
yarn test:node
yarn test:browser
```

You can also run `yarn test` for a simpler subset of the test cases.

Tests are also run automatically in Github Actions for every master commit and
pull request.

Expand Down
6 changes: 3 additions & 3 deletions src/.eslintrc.js → config/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ module.exports = {
es6: true
},
extends: ['airbnb-base', 'prettier'],
plugins: ['prettier', 'prefer-import'],
plugins: ['@babel', 'prettier', 'prefer-import'],
parser: '@babel/eslint-parser',
rules: {
// OFF
'import/prefer-default-export': 0,
Expand Down Expand Up @@ -37,6 +38,5 @@ module.exports = {

// ERROR
'no-unused-expressions': [2, { allowTaggedTemplates: true }]
},
parser: 'babel-eslint'
}
};
6 changes: 2 additions & 4 deletions .jsdoc.json → config/.jsdoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
"destination": "./jsdoc/",
"recurse": true,
"template": "node_modules/minami",
"readme": "./README.md"
"readme": "README.md"
},
"plugins": [
"plugins/markdown"
]
"plugins": ["plugins/markdown"]
}
3 changes: 3 additions & 0 deletions config/.nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@istanbuljs/nyc-config-babel"
}
7 changes: 7 additions & 0 deletions config/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
../package.json
../node_modules
../lib
../dist
../src/generated
../src/vendor
../docs
37 changes: 37 additions & 0 deletions config/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const webpackConfig = require('./webpack.config.browser.js');

delete webpackConfig.output;
webpackConfig.entry = {}; // karma fills these in
webpackConfig.plugins.shift(); // drop eslinter plugin

module.exports = function (config) {
config.set({
frameworks: ['mocha', 'sinon-chai'],
browsers: ['FirefoxHeadless', 'ChromeHeadless'],

files: [
'../dist/stellar-base.js', // webpack should build this first
'../test/unit/**/*.js'
],

preprocessors: {
'../test/unit/**/*.js': ['webpack']
},

webpack: webpackConfig,
webpackMiddleware: {
noInfo: true
},

colors: true,
singleRun: true,

reporters: ['dots', 'coverage'],
coverageReporter: {
type: 'text-summary',
instrumenterOptions: {
istanbul: { noCompact: true }
}
}
});
};
3 changes: 2 additions & 1 deletion prettier.config.js → config/prettier.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
module.exports = {
arrowParens: 'always',
bracketSpacing: true,
jsxBracketSameLine: false,
bracketSameLine: false,
printWidth: 80,
proseWrap: 'always',
semi: true,
singleQuote: true,
tabWidth: 2,
parser: 'babel',
trailingComma: 'none',
useTabs: false
};
75 changes: 75 additions & 0 deletions config/webpack.config.browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
var path = require('path');
var webpack = require('webpack');

var ESLintPlugin = require('eslint-webpack-plugin');
var TerserPlugin = require('terser-webpack-plugin');
var NodePolyfillPlugin = require('node-polyfill-webpack-plugin');

const config = {
target: 'web',
// https://stackoverflow.com/a/34018909
entry: {
'stellar-base': path.resolve(__dirname, '../src/index.js'),
'stellar-base.min': path.resolve(__dirname, '../src/index.js')
},
resolve: {
fallback: {
crypto: require.resolve('crypto-browserify'),
stream: require.resolve('stream-browserify'),
buffer: require.resolve('buffer')
},
extensions: ['.ts', '.js']
},
output: {
clean: true,
library: 'StellarBase',
compareBeforeEmit: true,
path: path.resolve(__dirname, '../dist')
},
mode: process.env.NODE_ENV ?? 'development',
devtool: process.env.NODE_ENV === 'production' ? false : 'inline-source-map',
module: {
rules: [
{
test: /\.m?js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
cacheDirectory: true
}
}
}
]
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
include: /\.min\.js$/,
terserOptions: {
format: {
ascii_only: true
}
}
})
]
},
plugins: [
// this must be first for karma to work (see line 5 of karma.conf.js)
new ESLintPlugin({
overrideConfigFile: path.resolve(__dirname, './.eslintrc.js')
}),
// Ignore native modules (sodium-native)
new webpack.IgnorePlugin({ resourceRegExp: /sodium-native/ }),
new NodePolyfillPlugin(),
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer']
})
],
watchOptions: {
ignored: /(node_modules|coverage|lib|dist)/
}
};

module.exports = config;
Loading