Skip to content

Commit

Permalink
Build lib with different options (gnosis/gp-v2-contracts#508)
Browse files Browse the repository at this point in the history
Closes #506 

This PR adds additional TypeScript configuration files for targeting both CommonJS and ES modules. Additionally, it produces `es5` output in order to be more compatible with the FE. Additionally, and ESM build is included so that it can work better with tools like Babel and take better advantage of things like tree shaking to reduce bundle sizes.

### Test Plan

Deploy this package and make sure it works with the FE.
  • Loading branch information
nlordell authored Mar 11, 2021
1 parent 520a561 commit 1e7568e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 13 deletions.
17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
"version": "0.0.1-alpha.13",
"license": "LGPL-3.0-or-later",
"scripts": {
"build": "tsc && hardhat compile",
"deploy": "hardhat deploy",
"verify:etherscan": "hardhat etherscan-verify --license LGPL-3.0 --force-license",
"verify:tenderly": "hardhat tenderly",
"solvers": "hardhat solvers",
"build": "yarn build:sol && yarn build:ts",
"build:sol": "hardhat compile",
"build:ts": "tsc && tsc -p tsconfig.lib.esm.json && tsc -p tsconfig.lib.commonjs.json",
"lint": "yarn lint:sol && yarn lint:ts",
"lint:sol": "solhint 'src/contracts/**/*.sol'",
"lint:ts": "eslint --max-warnings 0 .",
"test": "hardhat test",
"test:ignored-in-coverage": "MOCHA_CONF='ignored in coverage' hardhat test",
"coverage": "MOCHA_CONF='coverage' hardhat coverage",
Expand All @@ -16,9 +21,6 @@
"bench:single": "hardhat run bench/single.ts",
"bench:trace": "hardhat run bench/trace/index.ts",
"bench:uniswap": "hardhat run bench/uniswap/index.ts",
"lint": "yarn lint:sol && yarn lint:ts",
"lint:sol": "solhint 'src/contracts/**/*.sol'",
"lint:ts": "eslint --max-warnings 0 .",
"fmt:sol": "prettier 'src/contracts/**/*.sol' -w",
"prepack": "yarn build"
},
Expand Down Expand Up @@ -65,12 +67,13 @@
"typescript": "^4.2.3",
"yargs": "^16.2.0"
},
"main": "lib/src/ts/index.js",
"types": "lib/src/ts/index.d.ts",
"main": "lib/commonjs/index.js",
"module": "lib/esm/index.js",
"types": "lib/esm/index.d.ts",
"files": [
"build/",
"deployments/",
"lib/src/",
"lib/",
"networks.json",
"src/"
]
Expand Down
11 changes: 5 additions & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
"compilerOptions": {
"declaration": true,
"esModuleInterop": true,
"target": "es2020",
"module": "commonjs",
"moduleResolution": "node",
"outDir": "lib",
"resolveJsonModule": true,
"skipLibCheck": true,
"noEmit": true,
"strict": true,
"target": "es2020"
"esModuleInterop": true,
"resolveJsonModule": true,
"skipLibCheck": true
}
}
9 changes: 9 additions & 0 deletions tsconfig.lib.commonjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.lib.esm.json",
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"outDir": "lib/commonjs/",
"declaration": false
}
}
13 changes: 13 additions & 0 deletions tsconfig.lib.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"target": "es2020",
"module": "es2020",
"outDir": "lib/esm/",
"declaration": true,
"sourceMap": true,
"rootDir": "src/ts/",
"noEmit": false
},
"include": ["src/ts/**/*"]
}

0 comments on commit 1e7568e

Please sign in to comment.