Skip to content

Commit

Permalink
feat: make packages usable locally (#984)
Browse files Browse the repository at this point in the history
  • Loading branch information
arboleya committed May 30, 2023
1 parent 98f244a commit 59d5c65
Show file tree
Hide file tree
Showing 70 changed files with 778 additions and 890 deletions.
30 changes: 30 additions & 0 deletions .changeset/slimy-drinks-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
"@fuel-ts/abi-coder": minor
"@fuel-ts/abi-typegen": minor
"@fuel-ts/address": minor
"@fuel-ts/contract": minor
"forc-bin": minor
"fuels": minor
"@fuel-ts/hasher": minor
"@fuel-ts/hdwallet": minor
"@fuel-ts/interfaces": minor
"@fuel-ts/keystore": minor
"@fuel-ts/math": minor
"@fuel-ts/merkle": minor
"@fuel-ts/merkle-shared": minor
"@fuel-ts/merklesum": minor
"@fuel-ts/mnemonic": minor
"@fuel-ts/predicate": minor
"@fuel-ts/program": minor
"@fuel-ts/providers": minor
"@fuel-ts/script": minor
"@fuel-ts/signer": minor
"@fuel-ts/sparsemerkle": minor
"@fuel-ts/transactions": minor
"@fuel-ts/versions": minor
"@fuel-ts/wallet": minor
"@fuel-ts/wallet-manager": minor
"@fuel-ts/wordlists": minor
---

Revamping all packages configs, enabling local installation
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = {
'plugin:@typescript-eslint/recommended',
],
settings: {
'import/core-modules': ['@internal/tsup'],
jsdoc: {
mode: 'typescript',
},
Expand Down
161 changes: 100 additions & 61 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
## πŸ’š Contributing To Fuel TypeScript SDK
# Contributing To Fuel TypeScript SDK

Thanks for your interest in contributing to the Fuel TypeScript SDK! This document outlines the process for installing dependencies, setting up for development, and conventions for contributing.
Thanks for your interest in contributing to the Fuel TypeScript SDK!

## Finding Something to Work On
This document outlines the process for installing dependencies, setting up for development and conventions for contributing.

# Finding Something to Work On

There are many ways in which you may contribute to the project, some of which involve coding knowledge and some which do not. A few examples include:

Expand All @@ -14,7 +16,7 @@ Check out our [Help Wanted](https://github.com/FuelLabs/fuels-ts/issues?q=is%3Ao

If you are planning something big, for example, changes related to multiple components or changes to current behaviors, make sure to [open an issue](https://github.com/FuelLabs/fuels-ts/issues/new) to discuss with us before starting on the implementation.

### Setup
# Setting up

```sh
git clone git@github.com:FuelLabs/fuels-ts.git
Expand All @@ -23,9 +25,76 @@ pnpm install
pnpm build
```

## Testing
# Developing

For building everything in watch-mode, run:

```sh
# build all projects in watch-mode
pnpm dev
```

File watching is done by `nodemon` for increased performance.

Check `nodemon.config.json` for all settings.

> **Note**: You can `pnpm dev` a single package:
>
> ```sh
> cd packages/abi-coder
> pnpm dev
> ```
# Using local sym-linked packages

First, we need to link our `fuels` package globally in our local `global pnpm store`:

```sh
cd fuels-ts/packages/fuels
pnpm link --global
```

Let's check it out:

```sh
pnpm list --global
```

Cool, now on the root directory of `my-local-project`:

```sh
cd my-local-project
pnpm link --global fuels
```

That's it β€” `my-local-project` is now using our local version of `fuels`.

The same can be done with all other packages:

```sh
cd fuels-ts/packages/wallet
pnpm link --global

# ...

pnpm list --global # validating

# ...

cd my-local-project
pnpm link --global @fuel-ts/wallet
```

> **Warning** When using local symlinked `fuels-ts` in `your-local-project`, remember to `pnpm build` the SDK whenever you change a source file to reflect the changes on `your-local-project`. To automate this, you can use `pnpm dev`, which will keep watching and compiling everything automatically while developing.
See also:

- [Developing](#Developing)

# Testing

In order to run tests locally, you need `fuel-core` running as a docker container.

To do that run this command in your terminal:

```sh
Expand All @@ -37,10 +106,15 @@ And then run the tests in another terminal tab:
```sh
# run all tests
pnpm test
# run tests and get coverage
pnpm test -- --coverage

# run tests while passing other flags to sub-program
pnpm test -- --coverage --my-other-flag

# run tests for a specific package
pnpm --filter @fuel-ts/contract run test
pnpm test packages/my-desired-package

# run tests for a specific file
pnpm test packages/my-desired-package/src/my.test.ts
```

Or if you want to run docker and all tests serially you can do:
Expand All @@ -51,10 +125,10 @@ pnpm ci:test

This will run `services:run`, `test` and then `services:clean`

> The tests may break if you are running your tests locally using`services:run` in a separate terminal.
> The tests may break if you are running your tests locally using `services:run` in a separate terminal.
> To fix this run `services:clean` to clean docker containers and volumes.
## Commit Convention
# Commit Convention

Before you create a Pull Request, please check whether your commits comply with
the commit conventions used in this repository.
Expand All @@ -79,7 +153,7 @@ the following categories:
- `chore`: all changes to the repository that do not fit into any of the above
categories

## Steps to PR
# Steps to PR

1. Fork the fuels-ts repository and clone your fork

Expand All @@ -100,74 +174,39 @@ the following categories:
> `pnpm changeset add --empty` to generate an empty changeset file to document
> your changes.
## Git Hooks
# Git Hooks

The SDK utilizes a pre-push git hook to validate your contribution before review. This is a script that will run automatically before changes are pushed to the remote repository. Within the SDK, the pre-push script will run code linting.

> This can be overridden using the `--no-verify` flag when pushing.
## Build and watch all packages

If you want to work locally using realtime builds, open in one terminal tab build in watch mode
on all packages from the root directory:

```sh
pnpm build:watch
```

This command will run `tsup --watch` on all packages using Turborepo

## Using linked packages

This will link all packages inside our monorepo in your `global pnpm store`, enabling you to use `fuels-ts` packages via links in
your local projects.

### On `fuels-ts` root directory

```sh
pnpm -r exec pnpm link --global --dir ./
```

You can use [build watch](#build-and-watch-all-packages).

### On `your project` root directory

```sh
pnpm link --global fuels
```
# Updating Forc version

Or for specfic packages just use `pnpm link @fuel-ts/<pkg-name>`, ex;
The following script will upgrade Forc to the latest version on GitHub, remove all lockfiles so the latest stdlib can be used, and rebuild all projects:

```sh
pnpm link --global @fuel-ts/wallet
pnpm forc:update
```

### Troubleshooting

If you're linking for the first time, you might need:
After this you should run tests and fix any incompatibilities.

```sh
pnpm setup
```
# Updating Fuel Core version

If it still have problems, you might need to setup again (As `pnpm` releases new version, the global folder structure may change)
Manually edit the `.docker/fuel-core/Dockerfile` file, add the right version, and then:

```sh
pnpm setup
pnpm services:clean # causes rebuilding of the Docker image
pnpm test:ci
```

## Updating Forc version
If all tests pass, that's it.

The following script will upgrade Forc to the latest version on GitHub, remove all lockfiles so the latest stdlib can be used, and rebuild all projects:
Otherwise, you have work to do.

```sh
pnpm forc:update
```

After this you should run tests and fix any incompatibilities.

## FAQ
# FAQ

### Why is the prefix `fuels` and not `fuel`?

In order to make the SDK for Fuel feel familiar with those coming from the [ethers.js](https://github.com/ethers-io/ethers.js) ecosystem, this project opted for an `s` at the end. The `fuels-*` family of SDKs is inspired by The Ethers Project.
In order to make the SDK for Fuel feel familiar with those coming from the [ethers.js](https://github.com/ethers-io/ethers.js) ecosystem, this project opted for an `s` at the end.

The `fuels-*` family of SDKs is inspired by The Ethers Project.
75 changes: 31 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,56 +10,30 @@
[![docs](https://img.shields.io/badge/docs-fuels.ts-brightgreen.svg?style=flat)](https://fuellabs.github.io/fuels-ts/)
[![discord](https://img.shields.io/badge/chat%20on-discord-orange?&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.gg/xfpK4Pe)

## Table of contents
# Resources

The [documentation](https://fuellabs.github.io/fuels-ts) site is your main stop for resources.

- [Quickstart](https://fuellabs.github.io/fuel-docs/master/quickstart/developer-quickstart.html)
- [Documentation](https://fuellabs.github.io/fuels-ts)
- [Install](#install)
- [Import](#import)
- [Interacting with Contracts](https://fuellabs.github.io/fuels-ts/guide/contracts/managing-deployed-contracts.html)
- [Generate Types from ABI](https://fuellabs.github.io/fuels-ts/guide/abi-typegen/generating-types-from-abi.html)
- [Using Generated Types](https://fuellabs.github.io/fuels-ts/guide/abi-typegen/using-generated-types.html)
- [Deploying Contracts](https://fuellabs.github.io/fuels-ts/guide/contracts/deploying-contracts)
- [CLI](#cli)
- [Wallets](https://fuellabs.github.io/fuels-ts/guide/wallets/)
- [Contracts](https://fuellabs.github.io/fuels-ts/guide/contracts/)
- [Scripts](https://fuellabs.github.io/fuels-ts/guide/scripts/)
- [Predicates](https://fuellabs.github.io/fuels-ts/guide/predicates/)
- [ABI Typegen](https://fuellabs.github.io/fuels-ts/guide/abi-typegen/)
- [Contributing](https://github.com/FuelLabs/fuels-ts/blob/master/CONTRIBUTING.md)
- [License](#license)

## Quickstart

We recommend starting with the [Quickstart](https://fuellabs.github.io/fuel-docs/master/quickstart/developer-quickstart.html) to speed-up and build your first DApp using Fuel.

- [Other example projects](https://github.com/FuelLabs/sway-applications)

## Documentation

You can find in-depth [usage and examples in our Guide](https://fuellabs.github.io/fuels-ts/guide), or deep-dive into the internals with our detailed [SDK Documentation](https://fuellabs.github.io/fuels-ts).

## The Fuel Ecosystem

Learn more about the Fuel Ecosystem.

- [🌴 Sway](https://fuellabs.github.io/sway/) the new language. Empowering everyone to build reliable and efficient smart contracts.
- [🧰 Forc](https://fuellabs.github.io/sway/v0.30.1/forc/index.html) the Fuel toolbox. Build, deploy and manage your sway projects.
- [βš™οΈ Fuel Core](https://github.com/FuelLabs/fuel-core) the new FuelVM, a blazingly fast blockchain VM.
- [πŸ”— Fuel Specs](https://github.com/FuelLabs/fuel-specs) the Fuel protocol specifications.
- [πŸ¦€ RUST SDK](https://github.com/FuelLabs/fuels-rs) a robust SDK in rust.
- [⚑ Fuel Network](https://fuel.network/) the project.
- [The Fuel Forum](https://forum.fuel.network/)
- [The Fuel Ecosystem](#the-fuel-ecosystem)

## Install

#### YARN

```sh
yarn add fuels
```

#### NPM
# Install

```sh
npm install fuels --save
```

## Import
# Import

Simple example usages.

```ts
import { Wallet } from "fuels";
Expand All @@ -71,13 +45,13 @@ console.log(Wallet.generate());
console.log(new Wallet("0x0000...0000"));
```

## CLI
# CLI

Fuels include some utility commands via built-in CLI tool.

```console
$ yarn add fuels
$ yarn exec fuels -h
$ npm add fuels
$ npx fuels --help
Usage: fuels [options] [command]

Options:
Expand All @@ -90,6 +64,19 @@ Commands:
help [command] display help for command
```

## License
# The Fuel Ecosystem

Learn more about the Fuel Ecosystem.

- [🌴 Sway](https://fuellabs.github.io/sway/) β€” The new language, empowering everyone to build reliable and efficient smart contracts
- [🧰 Forc](https://fuellabs.github.io/sway/v0.30.1/forc/index.html) β€” The Fuel toolbox: _Build, deploy and manage your sway projects_
- [βš™οΈ Fuel Core](https://github.com/FuelLabs/fuel-core) β€” The new FuelVM, a blazingly fast blockchain VM
- [πŸ”— Fuel Specs](https://github.com/FuelLabs/fuel-specs) β€” The Fuel protocol specifications
- [πŸ’Ό Fuels Wallet](https://github.com/FuelLabs/fuels-wallet) β€” The Official Fuels Wallet
- [πŸ¦€ Rust SDK](https://github.com/FuelLabs/fuels-rs) β€” A robust SDK in rust
- [⚑ Fuel Network](https://fuel.network/) β€” The project
- [πŸ“š The Fuel Forum](https://forum.fuel.network/) β€” Ask questions, get updates, and contribute to a modular future

# License

The primary license for this repo is `Apache 2.0`, see [`LICENSE`](https://github.com/FuelLabs/fuels-ts/blob/master/LICENSE).
Loading

0 comments on commit 59d5c65

Please sign in to comment.