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

Merged
merged 22 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
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
18 changes: 12 additions & 6 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
{
"presets": ["es2015"],
"plugins": [
["babel-plugin-transform-builtin-extend", {
"globals": ["Error"]
}]
]
"comments": true,
"presets": [
"@babel/preset-env",
"@babel/typescript"
],
"env": {
"development": {
"plugins": [
"istanbul"
]
}
}
}
10 changes: 6 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
module.exports = {
env: {
node: true
es6: true,
},
extends: ['eslint:recommended', 'plugin:node/recommended'],
extends: ["airbnb-base", "prettier"],
plugins: ["@babel", "prettier", "prefer-import"],
parser: "@babel/eslint-parser",
rules: {
'node/no-unpublished-require': 0
}
"node/no-unpublished-require": 0,
},
};
2 changes: 2 additions & 0 deletions .github/codeql-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
paths-ignore:
- 'test/**/*.{js}'
10 changes: 6 additions & 4 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}

- name: Autobuild
uses: github/codeql-action/autobuild@v1
uses: github/codeql-action/autobuild@v2

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v2
with:
config-file: .github/codeql-config.yml
10 changes: 5 additions & 5 deletions .github/workflows/gh_pages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout SDK
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Checkout Base
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
repository: stellar/js-stellar-base
path: js-stellar-base

- name: Install Node (14.x)
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: '14.x'

- name: Install Dependencies
run: yarn install

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

- name: Checkout GH pages
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
repository: stellar/js-stellar-sdk
ref: gh-pages
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/npm_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Install Node
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: '14.x'
registry-url: 'https://registry.npmjs.org'

- name: Install Depencencies
run: yarn
run: yarn install

- name: Build
run: yarn version
- name: Build, Test, and Package
run: yarn preversion

- name: Publish npm package
run: yarn publish
Expand Down
24 changes: 13 additions & 11 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,32 @@ jobs:

strategy:
fail-fast: false
max-parallel: 2
max-parallel: 4
matrix:
node-version: [14, 16]
node-version: [14, 16, 18]

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

# Workaround for some `yarn` nonsense, see:
# https://github.com/yarnpkg/yarn/issues/6312#issuecomment-429685210
- name: Install Dependencies
run: yarn install
run: yarn install --network-concurrency 1

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

- name: Unit Tests
run: gulp test:unit

- name: Browser Tests
run: gulp test:browser
run: yarn test:node

- name: Integration Tests
run: gulp test:integration
run: yarn test:integration

- name: Browser Tests
run: yarn test:browser
4 changes: 0 additions & 4 deletions .jshintrc

This file was deleted.

1 change: 0 additions & 1 deletion .nvmrc

This file was deleted.

47 changes: 25 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

<p align="center">
<a href="https://badge.fury.io/js/stellar-sdk"><img src="https://badge.fury.io/js/stellar-sdk.svg" alt="npm version" height="18"></a>
<a href="https://www.npmjs.com/package/stellar-sdk">
<img alt="Weekly Downloads" src="https://img.shields.io/npm/dw/stellar-sdk" />
</a>
<a href="https://github.com/stellar/js-stellar-sdk/actions/workflows/tests.yml"><img alt="Test Status" src="https://github.com/stellar/js-stellar-sdk/actions/workflows/tests.yml/badge.svg" /></a>
<a href="https://coveralls.io/github/stellar/js-stellar-sdk?branch=master"><img alt="Coverage Status" src="https://coveralls.io/repos/stellar/js-stellar-sdk/badge.svg?branch=master&service=github" /></a>
</p>

js-stellar-sdk is a Javascript library for communicating with a
Expand Down Expand Up @@ -134,7 +136,7 @@ npm install

3. Install Node 14

Because we support the latest maintenance version of Node, please install and develop on Node 14 so you don't get surprised when your code works locally but breaks in CI.
Because we support the oldest maintenance version of Node, please install and develop on Node 14 so you don't get surprised when your code works locally but breaks in CI.

Here's how to install `nvm` if you haven't: https://github.com/creationix/nvm

Expand All @@ -156,15 +158,25 @@ While you're making changes, make sure to run the linter-watcher to catch any

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


### How to use with React-Native
## Usage

For information on how to use js-stellar-sdk, take a look at [the
documentation](https://stellar.github.io/js-stellar-sdk/), or [the
examples](https://github.com/stellar/js-stellar-sdk/tree/master/docs/reference).

There is also Horizon REST API Documentation
[here](https://developers.stellar.org/api/introduction/).

1. Add the following postinstall script:
### Usage with React-Native

1. Install `yarn add --dev rn-nodeify`
2. Add the following postinstall script:
```
yarn rn-nodeify --install url,events,https,http,util,stream,crypto,vm,buffer --hack --yarn
```
2. `yarn add -D rn-nodeify`
3. Uncomment `require('crypto')` on shim.js
4. `react-native link react-native-randombytes`
5. Create file `rn-cli.config.js`
Expand All @@ -182,16 +194,16 @@ There is also a [sample](https://github.com/fnando/rn-stellar-sdk-sample) that y

#### Using in an Expo managed workflow

1. Add the following postinstall script:
1. Install `yarn add --dev rn-nodeify`
2. Add the following postinstall script:
```
yarn rn-nodeify --install process,url,events,https,http,util,stream,crypto,vm,buffer --hack --yarn
```
2. `yarn add -D rn-nodeify`
3. Add `import "./shim";` to the your app's entry point (by default `./App.js`)
4. `yarn add stellar-sdk`
5. `expo install expo-random`

At this point, the stellar SDK will work, except that `StellarSdk.Keypair.random()` will throw an error. So to work around this you can create your own method to generate a random keypair like this:
At this point, the Stellar SDK will work, except that `StellarSdk.Keypair.random()` will throw an error. To work around this, you can create your own method to generate a random keypair like this:

```javascript
import * as Random from 'expo-random';
Expand All @@ -204,28 +216,19 @@ const generateRandomKeypair = () => {
};
```

## Usage

For information on how to use js-stellar-sdk, take a look at [the
documentation](https://stellar.github.io/js-stellar-sdk/), or [the
examples](https://github.com/stellar/js-stellar-sdk/tree/master/docs/reference).

There is also Horizon REST API Documentation
[here](https://developers.stellar.org/api/introduction/).

## Testing

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
```

To generate and check the documentation site:
Expand All @@ -235,7 +238,7 @@ To generate and check the documentation site:
npm install -g serve

# generate the docs files
npm run docs
yarn docs

# get these files working in a browser
cd jsdoc && serve .
Expand Down
6 changes: 3 additions & 3 deletions .jsdoc.json → config/.jsdoc.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"source": {
"include": ["libdocs", "js-stellar-base/src"],
"include": ["lib/", "js-stellar-base/src"],
"exclude": "js-stellar-base/src/generated"
},
"opts": {
"destination": "./jsdoc/",
"destination": "jsdoc/",
"recurse": true,
"template": "node_modules/minami",
"readme": "./README.md"
"readme": "README.md"
},
"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"
}
File renamed without changes.
38 changes: 38 additions & 0 deletions config/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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-sdk.js", // webpack should build this first
"../test/test-browser.js",
"../test/unit/**/*.js"
],

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

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

colors: true,
singleRun: true,

reporters: ["dots", "coverage"],
coverageReporter: {
type: "text-summary",
instrumenterOptions: {
istanbul: { noCompact: true }
}
}
});
};
13 changes: 13 additions & 0 deletions config/prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
arrowParens: "always",
bracketSpacing: true,
bracketSameLine: false,
printWidth: 80,
proseWrap: "always",
semi: true,
singleQuote: false,
tabWidth: 2,
parser: "babel",
trailingComma: "none",
useTabs: false
};
8 changes: 4 additions & 4 deletions tsconfig.json → config/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"extends": "@stellar/tsconfig",
"compilerOptions": {
"declaration": true,
"declarationDir": "lib",
"declarationDir": "../lib",
"lib": ["es2015"],
"moduleResolution": "node",
"rootDir": "src",
"outDir": "lib",
"rootDir": "../src",
"outDir": "../lib",
"target": "es5"
},
"include": ["src"]
"include": ["../src"]
}
Loading