Skip to content

Commit

Permalink
US-236: Adding PNPM workspaces to publish to npm (#127)
Browse files Browse the repository at this point in the history
* Updating Zilliqa JS

* Renaming workspace file

* Updating bazel workspace

* Adding code 429 (rate limiting error) as acceptable for markdown URL checking

* Updating packages.json

* Removing referrer

* Silencing unused variable warning

* Settting release candidate to 0

* Updating README

* Updating package.json

* Updating config

* Updates

* Package update

* Fixing build

* Fixing build

* Adding commonjs

* Fixing distribution

* Finalising rc-3

* Formatting README
  • Loading branch information
troelsfr authored May 26, 2023
1 parent 14b0daf commit 8b29e07
Show file tree
Hide file tree
Showing 66 changed files with 10,066 additions and 6,410 deletions.
13 changes: 12 additions & 1 deletion .bazelignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,15 @@ pixy
node_modules
**/node_modules
products/developer-portal/node_modules
products/developer-portal-ng/node_modules
products/developer-portal-ng/node_modules

zilliqa/js/account/node_modules
zilliqa/js/blockchain/node_modules
zilliqa/js/contract/node_modules
zilliqa/js/core/node_modules
zilliqa/js/crypto/node_modules
zilliqa/js/proto/node_modules
zilliqa/js/subscriptions/node_modules
zilliqa/js/util/node_modules
zilliqa/js/zilliqa/node_modules
examples/zilliqa-js/latest-block/node_modules
37 changes: 30 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ following table is a place holder:

## Building

To disable our git queries on build, set the
`DISABLE_WORKSPACE_STATUS` environment variable. This loses version
information, but speeds builds and stops you having to touch your
security key on every bazel run.
To disable our git queries on build, set the `DISABLE_WORKSPACE_STATUS`
environment variable. This loses version information, but speeds builds and
stops you having to touch your security key on every bazel run.

### Prerequisites

Expand Down Expand Up @@ -119,6 +118,29 @@ which is served on port `80`.

#### Building libraries

#### Building and publishing `zilliqa-js`

Checkout out the repository. First ensure that tests are passing:

```sh
bazelisk test //zilliqa/js/...
```

Next navigate to the `zilliqa/js` folder and build all libraries:

```sh
pnpm -r build
```

Finally, publish:

```sh
pnpm -r publish
```

Add `--dry-run` in the event you want to test publish without publishing
anything.

#### Building and running Docker images

For the purpose of building Docker images, you do not need Docker installed
Expand Down Expand Up @@ -235,9 +257,10 @@ previous builds: `bazel clean --expunge`

To get information about your current Bazel setup run `bazelisk info`.

If you get bored with bazel constantly asking you for your password/to authenticate via your key, add
`--workspace_status_command=echo` to your command line. Use `DISABLE_WORKSPACE_STATUS` with `ibazel`
(since `ibazel` doesn't pass command line options on to `bazel`).
If you get bored with bazel constantly asking you for your password/to
authenticate via your key, add `--workspace_status_command=echo` to your command
line. Use `DISABLE_WORKSPACE_STATUS` with `ibazel` (since `ibazel` doesn't pass
command line options on to `bazel`).

## Reasoning Behind Repository Organisation

Expand Down
6 changes: 3 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ install_deps()
# ================================================================
http_archive(
name = "aspect_rules_js",
sha256 = "c3b5fd40ec19f3260094321380169abe86dd89e3506c4e44a515a50c1626629b",
strip_prefix = "rules_js-1.6.6",
url = "https://github.com/aspect-build/rules_js/archive/refs/tags/v1.6.6.tar.gz",
sha256 = "08061ba5e5e7f4b1074538323576dac819f9337a0c7d75aee43afc8ae7cb6e18",
strip_prefix = "rules_js-1.26.1",
url = "https://github.com/aspect-build/rules_js/releases/download/v1.26.1/rules_js-v1.26.1.tar.gz",
)

http_archive(
Expand Down
85 changes: 85 additions & 0 deletions examples/zilliqa-js/latest-block/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Example: Get latest block

## Quickstart: Use boilerplate project

1. Make sure that the library was build. From the repository root go to
`zilliqa/js`. Then run

```sh
pnpm i -r
pnpm -r build
```

2. Change directory to the `latest-block` directory and install the
dependencies:

```sh
pnpm i
```

3. Build and run the script:

```sh
npx tsc
node dist/index.js
```

## Project from scratch

1. Create a new directory to work in

```sh
mkdir zilliqa-latest-block
cd zilliqa-latest-block
```

2. Initialise the directory with npm and typescript

```sh
npm init
npm install --save-dev typescript @types/node
npx tsc --init
```

3. Update `tsconfig.json`. It should look like:

```json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"outDir": "dist",
"strict": true,
"esModuleInterop": true
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules"]
}
```

4. Create the source directory and `index.ts`:

```sh
mkdir src
touch src/index.ts
```

5. Update `index.ts` with:

```ts
import { Zilliqa } from "@zilliqa-js/zilliqa";

async function main() {
const provider = new Zilliqa("https://api.zilliqa.com/");
const latestBlock = await provider.blockchain.getLatestTxBlock();
console.log(latestBlock);
}
main();
```

6. Compile and run:

```sh
npx tsc
node dist/index.js
```
24 changes: 24 additions & 0 deletions examples/zilliqa-js/latest-block/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "latest-block",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@types/node": "^20.2.4",
"typescript": "^5.0.4"
},
"dependencies": {
"@zilliqa-js/account": "workspace:*",
"@zilliqa-js/blockchain": "workspace:*",
"@zilliqa-js/contract": "workspace:*",
"@zilliqa-js/core": "workspace:*",
"@zilliqa-js/crypto": "workspace:*",
"@zilliqa-js/util": "workspace:*",
"@zilliqa-js/zilliqa": "workspace:*"
}
}
8 changes: 8 additions & 0 deletions examples/zilliqa-js/latest-block/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Zilliqa } from "@zilliqa-js/zilliqa";

async function main() {
const provider = new Zilliqa("https://api.zilliqa.com/");
const latestBlock = await provider.blockchain.getLatestTxBlock();
console.log(latestBlock);
}
main();
11 changes: 11 additions & 0 deletions examples/zilliqa-js/latest-block/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"outDir": "dist",
"strict": true,
"esModuleInterop": true
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules"]
}
2 changes: 1 addition & 1 deletion mlc_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"retryOn429": true,
"retryCount": 5,
"fallbackRetryDelay": "30s",
"aliveStatusCodes": [200],
"aliveStatusCodes": [200, 429],
"httpHeaders": [
{
"urls": [
Expand Down
Loading

0 comments on commit 8b29e07

Please sign in to comment.