Skip to content

Commit

Permalink
chore: improve build and create dev scripts 🔨 (#29)
Browse files Browse the repository at this point in the history
* chore: improve build and create dev scripts
fix eslint for RFC usage for handlers
export commonjs & esm builds
added declarationMap in tsconfig to fix go-to-definition in the monorepo
bring back the pre-commit hook
updated all dependencies

* chore(ci): comment doc task
  • Loading branch information
Justkant authored Oct 31, 2022
1 parent 4f188a3 commit e961b09
Show file tree
Hide file tree
Showing 32 changed files with 598 additions and 1,516 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
# run: npx codecov
# env:
# CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: run doc
run: pnpm doc
- name: check if diff
run: git diff --exit-code || exit 1
# - name: run doc
# run: pnpm doc
# - name: check if diff
# run: git diff --exit-code || exit 1
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ yarn-error.log*

# build folder
dist/
lib/
lib-es/

# eslint cache
.eslintcache
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

pnpm lint-staged
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"clean": "git clean -fdX",
"changelog": "changeset add",
"build": "turbo run build",
"dev": "turbo run dev --parallel",
"dev": "turbo run dev",
"lint": "turbo run lint",
"lint:fix": "turbo run lint:fix",
"test": "turbo run test",
Expand All @@ -23,13 +23,13 @@
"*.ts": "eslint --fix"
},
"devDependencies": {
"@changesets/changelog-github": "^0.4.6",
"@changesets/cli": "^2.24.4",
"eslint": "^8.24.0",
"@changesets/changelog-github": "^0.4.7",
"@changesets/cli": "^2.25.1",
"eslint": "^8.26.0",
"eslint-config-custom": "workspace:*",
"husky": "^8.0.0",
"lint-staged": ">=13",
"turbo": "^1.5.4"
"turbo": "^1.6.2"
},
"engines": {
"npm": ">=7.0.0",
Expand Down
26 changes: 14 additions & 12 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
"version": "0.3.0",
"repository": "[email protected]:LedgerHQ/wallet-api.git",
"license": "Apache-2.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"main": "lib/index.js",
"module": "lib-es/index.js",
"types": "lib/index.d.ts",
"files": [
"/dist"
"/lib",
"/lib-es"
],
"scripts": {
"format:check": "prettier --check \"src\" \"tests\"",
"format:fix": "prettier --write \"src\" \"tests\"",
"lint": "eslint --cache --ext .ts \"src\" \"tests\"",
"lint:fix": "eslint --cache --fix --ext .ts \"src\" \"tests\"",
"build": "tsup src/index.ts --dts --format esm,cjs,iife",
"dev": "tsc -p prod.tsconfig.json --watch",
"build": "rm -rf lib/* lib-es/* && tsc -p prod.tsconfig.json && tsc -p prod-esm.tsconfig.json",
"test": "nyc mocha",
"doc": "typedoc --gitRevision main --out docs/reference src/index.ts",
"doc:html": "typedoc --gitRevision main --out docs/html --plugin typedoc-plugin-rename-defaults src/index.ts"
Expand All @@ -24,21 +27,20 @@
"json-rpc-2.0": "^1.1.0"
},
"devDependencies": {
"@tsconfig/node16-strictest-esm": "^1.0.3",
"@tsconfig/node18-strictest": "^1.0.0",
"@types/chai": "^4.3.3",
"@types/chai-spies": "^1.0.3",
"@types/mocha": "^9.1.0",
"@types/node": "^18.7.18",
"@types/mocha": "^10.0.0",
"@types/node": "^18.11.8",
"chai": "^4.3.6",
"chai-spies": "^1.0.0",
"eslint": "^8.23.1",
"mocha": "^9.2.2",
"eslint": "^8.26.0",
"mocha": "^10.1.0",
"nyc": "^15.1.0",
"prettier": "^2.7.1",
"ts-node": "^10.9.1",
"tsup": "^6.2.3",
"typedoc": "^0.23.15",
"typedoc": "^0.23.19",
"typedoc-plugin-rename-defaults": "^0.6.4",
"typescript": "^4.8.3"
"typescript": "^4.8.4"
}
}
8 changes: 8 additions & 0 deletions packages/client/prod-esm.tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "es2022",
"outDir": "./lib-es"
},
"include": ["src/**/*"]
}
8 changes: 8 additions & 0 deletions packages/client/prod.tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "./lib"
},
"include": ["src/**/*"]
}
5 changes: 3 additions & 2 deletions packages/client/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"extends": "@tsconfig/node16-strictest-esm/tsconfig.json",
"extends": "@tsconfig/node18-strictest/tsconfig.json",
"compilerOptions": {
"declaration": true,
"outDir": "./dist",
"declarationMap": true,
"outDir": "./lib",
"exactOptionalPropertyTypes": false
},
"include": ["src/**/*", "tests/**/*"]
Expand Down
4 changes: 0 additions & 4 deletions packages/client/tsconfig.prod.json

This file was deleted.

21 changes: 13 additions & 8 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
{
"name": "@ledgerhq/wallet-api-core",
"version": "0.3.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"license": "MIT",
"main": "lib/index.js",
"module": "lib-es/index.js",
"types": "lib/index.d.ts",
"files": [
"/lib",
"/lib-es"
],
"scripts": {
"format:check": "prettier --check \"src\"",
"format:fix": "prettier --write \"src\"",
"lint": "eslint --cache --ext .ts \"src\"",
"lint:fix": "eslint --cache --fix --ext .ts \"src\"",
"build": "tsup src/index.ts --dts --format esm,cjs,iife"
"dev": "tsc -p prod.tsconfig.json --watch",
"build": "rm -rf lib/* lib-es/* && tsc -p prod.tsconfig.json && tsc -p prod-esm.tsconfig.json"
},
"devDependencies": {
"@tsconfig/node16-strictest-esm": "^1.0.3",
"@types/node": "^18.7.18",
"@tsconfig/node18-strictest": "^1.0.0",
"@types/node": "^18.11.8",
"@types/uuid": "^8.3.4",
"eslint": "^7.32.0",
"tsup": "^6.2.3",
"typescript": "^4.5.2"
"eslint": "^8.26.0",
"typescript": "^4.8.4"
},
"dependencies": {
"@altostra/type-validations": "^2.6.5",
Expand Down
8 changes: 8 additions & 0 deletions packages/core/prod-esm.tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "es2022",
"outDir": "./lib-es"
},
"include": ["src/**/*"]
}
8 changes: 8 additions & 0 deletions packages/core/prod.tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "./lib"
},
"include": ["src/**/*"]
}
4 changes: 2 additions & 2 deletions packages/core/src/JSONRPC/RpcNode.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { v4 as uuidv4 } from "uuid";
import type { Transport } from "../transports";
import type { MethodId } from "../types/RFC";
import { createRpcRequest, parseRPCCall, createRpcResponse } from "./helpers";
import { createRpcRequest, createRpcResponse, parseRPCCall } from "./helpers";
import { RpcError } from "./RPCError";
import type { RpcResponse, RpcRequest } from "./types";
import type { RpcRequest, RpcResponse } from "./types";

type Resolver = (response: RpcResponse) => void;

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/JSONRPC/validation.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
anyOf,
enumOf,
maybe,
objectOf,
primitives,
anyOf,
enumOf,
} from "@altostra/type-validations";
import type { MethodId } from "../types/RFC";
import type { RpcRequest, RpcResponse, RpcResponseError } from "./types";
Expand Down
4 changes: 1 addition & 3 deletions packages/core/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import * as RFC from "./RFC";

export { RFC };
export * as RFC from "./RFC";

export type Promisable<T> = T | PromiseLike<T>;

Expand Down
5 changes: 3 additions & 2 deletions packages/core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"extends": "@tsconfig/node16-strictest-esm/tsconfig.json",
"extends": "@tsconfig/node18-strictest/tsconfig.json",
"compilerOptions": {
"declaration": true,
"outDir": "./dist",
"declarationMap": true,
"outDir": "./lib",
"exactOptionalPropertyTypes": false,
"lib": ["DOM"]
},
Expand Down
11 changes: 5 additions & 6 deletions packages/eslint-config-custom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@
"main": "index.js",
"license": "MIT",
"dependencies": {
"@typescript-eslint/eslint-plugin": "^5.37.0",
"@typescript-eslint/parser": "^5.37.0",
"eslint": "^8.23.1",
"@typescript-eslint/eslint-plugin": "^5.41.0",
"@typescript-eslint/parser": "^5.41.0",
"eslint": "^8.26.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^17.0.0",
"eslint-config-next": "^12.0.8",
"eslint-config-prettier": "^8.5.0",
"eslint-config-turbo": "latest",
"eslint-config-turbo": "^0.0.4",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4.0.0",
"prettier": "^2.7.1",
"typescript": "^4.8.3"
"typescript": "^4.8.4"
},
"publishConfig": {
"access": "public"
Expand Down
21 changes: 13 additions & 8 deletions packages/server/package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
{
"name": "@ledgerhq/wallet-api-server",
"version": "0.3.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"license": "MIT",
"main": "lib/index.js",
"module": "lib-es/index.js",
"types": "lib/index.d.ts",
"files": [
"/lib",
"/lib-es"
],
"scripts": {
"format:check": "prettier --check \"src\"",
"format:fix": "prettier --write \"src\"",
"lint": "eslint --cache --ext .ts \"src\"",
"lint:fix": "eslint --cache --fix --ext .ts \"src\"",
"build": "tsup src/index.ts --dts --format esm,cjs,iife"
"dev": "tsc -p prod.tsconfig.json --watch",
"build": "rm -rf lib/* lib-es/* && tsc -p prod.tsconfig.json && tsc -p prod-esm.tsconfig.json"
},
"devDependencies": {
"@tsconfig/node16-strictest-esm": "^1.0.3",
"@types/node": "^18.7.18",
"eslint": "^7.32.0",
"tsup": "^6.2.3",
"typescript": "^4.5.2"
"@tsconfig/node18-strictest": "^1.0.0",
"@types/node": "^18.11.8",
"eslint": "^8.26.0",
"typescript": "^4.8.4"
},
"dependencies": {
"@altostra/type-validations": "^2.6.5",
Expand Down
8 changes: 8 additions & 0 deletions packages/server/prod-esm.tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "es2022",
"outDir": "./lib-es"
},
"include": ["src/**/*"]
}
8 changes: 8 additions & 0 deletions packages/server/prod.tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "./lib"
},
"include": ["src/**/*"]
}
4 changes: 2 additions & 2 deletions packages/server/src/internalHandlers/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const request: RPCHandler<RFC.AccountRequestResult> = async (

const { currencyIds } = req.params;

const walletHandler = handlers[RFC.MethodId.ACCOUNT_REQUEST];
const walletHandler = handlers["account.request"];

if (!walletHandler) {
throw new RpcError(NOT_IMPLEMENTED_BY_WALLET);
Expand Down Expand Up @@ -122,7 +122,7 @@ export const receive: RPCHandler<RFC.AccountReceiveResult> = async (
throw new RpcError(ACCOUNT_NOT_FOUND);
}

const walletHandler = handlers[RFC.MethodId.ACCOUNT_RECEIVE];
const walletHandler = handlers["account.receive"];

if (!walletHandler) {
throw new RpcError(NOT_IMPLEMENTED_BY_WALLET);
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/internalHandlers/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const sign: RPCHandler<RFC.MessageSignResult> = async (
context,
handlers
) => {
const walletHandler = handlers[RFC.MethodId.MESSAGE_SIGN];
const walletHandler = handlers["message.sign"];

if (!walletHandler) {
throw new RpcError(NOT_IMPLEMENTED_BY_WALLET);
Expand Down
8 changes: 4 additions & 4 deletions packages/server/src/internalHandlers/transaction.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { maybe, objectOf, primitives } from "@altostra/type-validations";
import {
RFC,
isRawTransaction,
deserializeTransaction,
isRawTransaction,
RFC,
RpcError,
RpcErrorCode,
} from "@ledgerhq/wallet-api-core";
Expand Down Expand Up @@ -42,7 +42,7 @@ export const sign: RPCHandler<RFC.TransactionSignResult> = async (
throw new RpcError(ACCOUNT_NOT_FOUND);
}

const walletHandler = handlers[RFC.MethodId.TRANSACTION_SIGN];
const walletHandler = handlers["transaction.sign"];

if (!walletHandler) {
throw new RpcError(NOT_IMPLEMENTED_BY_WALLET);
Expand All @@ -69,7 +69,7 @@ const validateTransactionSignAndBroadcast =
export const signAndBroadcast: RPCHandler<
RFC.TransactionSignAndBroadcastResult
> = async (req, context, handlers) => {
const walletHandler = handlers[RFC.MethodId.TRANSACTION_SIGN_AND_BROADCAST];
const walletHandler = handlers["transaction.signAndBroadcast"];

if (!walletHandler) {
throw new RpcError(NOT_IMPLEMENTED_BY_WALLET);
Expand Down
Loading

0 comments on commit e961b09

Please sign in to comment.