Skip to content

Commit

Permalink
Repo improvements (FuelLabs#68)
Browse files Browse the repository at this point in the history
* Make `typechain-target-fuels` publishable

* Combine tests

* Fix ESLint warnings

* Combine builds
  • Loading branch information
AlicanC authored Nov 29, 2021
1 parent 1e1e3d2 commit ef0f3c6
Show file tree
Hide file tree
Showing 51 changed files with 246 additions and 307 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
**/coverage/
**/dist/
/packages/example-contract/src/MyContract-types/
/packages/example-contract/scripts/typechain-target.js
/packages/providers/src/operations.ts
/packages/typechain-target-fuels/static/
/packages/typechain-target-fuels/example/
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"parserOptions": {
"project": ["./tsconfig.eslint.json", "./packages/*/tsconfig.json"]
},
"plugins": ["@typescript-eslint"],
"extends": [
"airbnb-base",
"airbnb-typescript/base",
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ jobs:
cache: "npm"
- run: npm i npm@8 -g # we need a version of npm that supports workspaces
- run: npm ci
- run: npm run build
- run: npm run lint
- uses: docker/login-action@v1
with:
Expand Down
5 changes: 5 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"spec": "packages/**/*.test.ts",
"extension": ["ts", "cts", "mts", "js", "cjs", "mjs"],
"require": "ts-node/register"
}
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Fuel v2 TypeScript SDK
git clone [email protected]:FuelLabs/fuels-ts.git
cd fuels-ts
npm install
npm run build
```

## Test
Expand Down
109 changes: 52 additions & 57 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 7 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,18 @@
"npm": ">=8.0.0"
},
"workspaces": [
"./packages/abi-coder",
"./packages/merkle-shared",
"./packages/transactions",
"./packages/merkle",
"./packages/providers",
"./packages/contract",
"./packages/typechain-target-fuels",
"./packages/*"
],
"scripts": {
"build": "npm run build --workspaces --if-present",
"test": "npm run test --workspaces --if-present",
"test:coverage": "npm run test:coverage --workspaces --if-present",
"postinstall": "npm run build",
"build": "tsc --build && npm -w @fuel-ts/example-contract run build",
"test": "mocha",
"test:coverage": "nyc --reporter=text mocha",
"lint": "npx eslint . --ext .ts && npx prettier --check packages",
"eslint-fix": "npx eslint . --ext .ts --fix",
"prettier-format": "prettier --config .prettierrc 'packages/**/*.ts' --write",
"run-services": "docker compose up"
"prettier-format": "prettier --write packages",
"run-services": "docker compose up",
"fix-ts-references": "npx @monorepo-utils/workspaces-to-typescript-project-references"
},
"repository": {
"type": "git",
Expand Down
5 changes: 0 additions & 5 deletions packages/abi-coder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
"files": [
"dist"
],
"scripts": {
"build": "tsc -b tsconfig.build.json",
"test": "mocha -r ts-node/register 'src/**/**.test.ts'",
"test:coverage": "nyc --reporter=text mocha -r ts-node/register 'src/**/**.test.ts'"
},
"license": "UNLICENSED",
"devDependencies": {
"chai": "^4.3.4"
Expand Down
10 changes: 0 additions & 10 deletions packages/abi-coder/tsconfig.build.json

This file was deleted.

10 changes: 6 additions & 4 deletions packages/abi-coder/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"extends": "./tsconfig.build.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"composite": false,
"rootDir": "."
"composite": true,
"outDir": "./dist",
"rootDir": "./src"
},
"include": ["src"]
"include": ["src"],
"references": []
}
5 changes: 1 addition & 4 deletions packages/contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
"dist"
],
"scripts": {
"build": "tsc -b tsconfig.build.json",
"test": "mocha -r ts-node/register 'src/**/**.test.ts'",
"test:coverage": "nyc --reporter=text mocha -r ts-node/register 'src/**/**.test.ts'",
"build-test-contract": "forc build -p src/test-contract -o src/test-contract/out.bin --print-finalized-asm"
"build-test-contract": "exec scripts/build-test-contract.sh"
},
"license": "UNLICENSED",
"dependencies": {
Expand Down
10 changes: 0 additions & 10 deletions packages/contract/tsconfig.build.json

This file was deleted.

20 changes: 16 additions & 4 deletions packages/contract/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
{
"extends": "./tsconfig.build.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"composite": false,
"rootDir": "."
"composite": true,
"outDir": "./dist",
"rootDir": "./src"
},
"include": ["src"]
"include": ["src"],
"references": [
{
"path": "../abi-coder"
},
{
"path": "../providers"
},
{
"path": "../transactions"
}
]
}
8 changes: 3 additions & 5 deletions packages/example-contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@
"version": "0.0.1",
"description": "",
"scripts": {
"build": "exec ./scripts/build.sh",
"test": "mocha -r ts-node/register 'src/**/**.test.ts'",
"test:coverage": "nyc --reporter=text mocha -r ts-node/register 'src/**/**.test.ts'"
"build": "exec ./scripts/build.sh"
},
"license": "UNLICENSED",
"dependencies": {
"@ethersproject/bytes": "^5.5.0",
"@fuel-ts/fuels": "^0.0.1"
},
"devDependencies": {
"@fuel-ts/typechain-target-fuels": "^0.0.1",
"chai": "^4.3.4",
"prettier": "^2.4.1",
"typechain": "^6.0.2",
"typechain-target-fuels": "^0.0.1"
"typechain": "^6.0.2"
}
}
2 changes: 1 addition & 1 deletion packages/example-contract/scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

# forc build -o src/MyContract.bin
# forc json-abi | npx prettier --parser json | jq 'del(.[].inputs[0], .[].inputs[1], .[].inputs[2])' > src/MyContract.json
typechain --target=fuels --out-dir=src/MyContract-types src/MyContract.json
npx typechain --target=scripts/typechain-target.js --out-dir=src/MyContract-types src/MyContract.json
# forc parse-bytecode src/MyContract.bin > src/MyContract.txt
2 changes: 2 additions & 0 deletions packages/example-contract/scripts/typechain-target.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// We need this proxy file because TypeChain doesn't support scoped packages
module.exports = require('@fuel-ts/typechain-target-fuels');
7 changes: 5 additions & 2 deletions packages/example-contract/src/MyContract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { hexlify } from '@ethersproject/bytes';
import { Provider, Contract } from '@fuel-ts/fuels';
import { expect } from 'chai';
import fs from 'fs';
import path from 'path';

import type { MyContract } from './MyContract-types';
import MyContractAbi from './MyContract.json';

const genSalt = () => hexlify(new Uint8Array(32).map(() => Math.floor(Math.random() * 256)));

Expand All @@ -13,9 +13,12 @@ describe('MyContract', () => {
const provider = new Provider('http://127.0.0.1:4000/graphql');

// Deploy
const bytecode = fs.readFileSync('./src/MyContract.bin');
const bytecode = fs.readFileSync(path.join(__dirname, './MyContract.bin'));
const salt = genSalt();
const { contractId } = await provider.submitContract(bytecode, salt);
const MyContractAbi = JSON.parse(
fs.readFileSync(path.join(__dirname, './MyContract.json'), 'utf-8')
);
const contract = new Contract(contractId, MyContractAbi as any, provider) as MyContract;

// Call
Expand Down
10 changes: 0 additions & 10 deletions packages/example-contract/tsconfig.build.json

This file was deleted.

Loading

0 comments on commit ef0f3c6

Please sign in to comment.