From 0781d8a95d0a1beae213fefaf234a6efed93b64e Mon Sep 17 00:00:00 2001 From: Junaid <86780488+jdevcs@users.noreply.github.com> Date: Tue, 28 Mar 2023 10:54:03 +0200 Subject: [PATCH] ESM CJS builds (#5904) * base tsconfig * build specific tsconfig * build scripts for esm and cjs * tsconfig fix for tests * integration test fix * webpack custom tsconf to ts-loader * doc pointing to conf * linter ts config * docs config * explicitly override module type in build outputs * tsconf update * fix ethereumjs/tx import issue for pure ESM * changelog andpackage.json updates * types at first * updated build script * change log sync --- .eslintrc.js | 2 +- .eslintrc.test.js | 2 +- CHANGELOG.md | 69 +++++++++++++++++++ docs/tsconfig.docs.json | 6 +- package.json | 2 +- packages/web3-core/.eslintrc.js | 2 +- packages/web3-core/CHANGELOG.md | 4 ++ packages/web3-core/package.json | 15 +++- packages/web3-core/test/tsconfig.json | 2 +- packages/web3-core/tsconfig.cjs.json | 9 +++ packages/web3-core/tsconfig.esm.json | 8 +++ packages/web3-core/tsconfig.json | 7 -- packages/web3-core/tsconfig.types.json | 10 +++ packages/web3-errors/.eslintrc.js | 2 +- packages/web3-errors/CHANGELOG.md | 4 ++ packages/web3-errors/package.json | 15 +++- packages/web3-errors/tsconfig.cjs.json | 10 +++ packages/web3-errors/tsconfig.esm.json | 9 +++ packages/web3-errors/tsconfig.json | 1 - packages/web3-errors/tsconfig.types.json | 10 +++ packages/web3-eth-abi/.eslintrc.js | 2 +- packages/web3-eth-abi/CHANGELOG.md | 4 ++ packages/web3-eth-abi/package.json | 15 +++- packages/web3-eth-abi/test/tsconfig.json | 2 +- packages/web3-eth-abi/tsconfig.cjs.json | 10 +++ packages/web3-eth-abi/tsconfig.esm.json | 9 +++ packages/web3-eth-abi/tsconfig.json | 7 -- packages/web3-eth-abi/tsconfig.types.json | 10 +++ packages/web3-eth-accounts/.eslintrc.js | 2 +- packages/web3-eth-accounts/CHANGELOG.md | 4 ++ packages/web3-eth-accounts/package.json | 15 +++- packages/web3-eth-accounts/src/account.ts | 5 +- .../test/integration/account.test.ts | 4 +- .../test/unit/account.test.ts | 4 +- packages/web3-eth-accounts/tsconfig.cjs.json | 10 +++ packages/web3-eth-accounts/tsconfig.esm.json | 9 +++ packages/web3-eth-accounts/tsconfig.json | 8 --- .../web3-eth-accounts/tsconfig.types.json | 10 +++ packages/web3-eth-contract/.eslintrc.js | 2 +- packages/web3-eth-contract/CHANGELOG.md | 1 + packages/web3-eth-contract/package.json | 15 +++- packages/web3-eth-contract/test/tsconfig.json | 2 +- packages/web3-eth-contract/tsconfig.cjs.json | 10 +++ packages/web3-eth-contract/tsconfig.esm.json | 9 +++ packages/web3-eth-contract/tsconfig.json | 8 --- .../web3-eth-contract/tsconfig.types.json | 10 +++ packages/web3-eth-ens/.eslintrc.js | 2 +- packages/web3-eth-ens/CHANGELOG.md | 4 ++ packages/web3-eth-ens/package.json | 15 +++- packages/web3-eth-ens/tsconfig.cjs.json | 10 +++ packages/web3-eth-ens/tsconfig.esm.json | 9 +++ packages/web3-eth-ens/tsconfig.json | 1 - packages/web3-eth-ens/tsconfig.types.json | 10 +++ packages/web3-eth-iban/.eslintrc.js | 2 +- packages/web3-eth-iban/CHANGELOG.md | 4 ++ packages/web3-eth-iban/package.json | 15 +++- packages/web3-eth-iban/tsconfig.cjs.json | 10 +++ packages/web3-eth-iban/tsconfig.esm.json | 9 +++ packages/web3-eth-iban/tsconfig.json | 1 - packages/web3-eth-iban/tsconfig.types.json | 10 +++ packages/web3-eth-personal/.eslintrc.js | 2 +- packages/web3-eth-personal/CHANGELOG.md | 4 ++ packages/web3-eth-personal/package.json | 15 +++- packages/web3-eth-personal/test/tsconfig.json | 2 +- packages/web3-eth-personal/tsconfig.cjs.json | 10 +++ packages/web3-eth-personal/tsconfig.esm.json | 9 +++ packages/web3-eth-personal/tsconfig.json | 8 --- .../web3-eth-personal/tsconfig.types.json | 10 +++ packages/web3-eth/.eslintrc.js | 2 +- packages/web3-eth/CHANGELOG.md | 4 ++ packages/web3-eth/package.json | 15 +++- packages/web3-eth/src/rpc_method_wrappers.ts | 4 +- .../src/utils/decode_signed_transaction.ts | 4 +- .../utils/prepare_transaction_for_signing.ts | 5 +- .../web3-eth/test/integration/rpc.test.ts | 2 +- packages/web3-eth/tsconfig.cjs.json | 10 +++ packages/web3-eth/tsconfig.esm.json | 9 +++ packages/web3-eth/tsconfig.json | 8 --- packages/web3-eth/tsconfig.types.json | 10 +++ packages/web3-net/.eslintrc.js | 2 +- packages/web3-net/CHANGELOG.md | 4 ++ packages/web3-net/package.json | 15 +++- packages/web3-net/test/tsconfig.json | 2 +- packages/web3-net/tsconfig.cjs.json | 9 +++ packages/web3-net/tsconfig.esm.json | 8 +++ packages/web3-net/tsconfig.json | 7 -- packages/web3-net/tsconfig.types.json | 10 +++ packages/web3-providers-http/.eslintrc.js | 2 +- packages/web3-providers-http/CHANGELOG.md | 4 ++ packages/web3-providers-http/package.json | 15 +++- .../web3-providers-http/tsconfig.cjs.json | 10 +++ .../web3-providers-http/tsconfig.esm.json | 9 +++ packages/web3-providers-http/tsconfig.json | 1 - .../web3-providers-http/tsconfig.types.json | 10 +++ packages/web3-providers-ipc/.eslintrc.js | 2 +- packages/web3-providers-ipc/CHANGELOG.md | 4 ++ packages/web3-providers-ipc/package.json | 15 +++- .../web3-providers-ipc/test/tsconfig.json | 2 +- packages/web3-providers-ipc/tsconfig.cjs.json | 9 +++ packages/web3-providers-ipc/tsconfig.esm.json | 8 +++ packages/web3-providers-ipc/tsconfig.json | 7 -- .../web3-providers-ipc/tsconfig.types.json | 10 +++ packages/web3-providers-ws/.eslintrc.js | 2 +- packages/web3-providers-ws/CHANGELOG.md | 4 ++ packages/web3-providers-ws/package.json | 15 +++- packages/web3-providers-ws/tsconfig.cjs.json | 10 +++ packages/web3-providers-ws/tsconfig.esm.json | 9 +++ packages/web3-providers-ws/tsconfig.json | 1 - .../web3-providers-ws/tsconfig.types.json | 10 +++ packages/web3-rpc-methods/.eslintrc.js | 2 +- packages/web3-rpc-methods/CHANGELOG.md | 4 ++ packages/web3-rpc-methods/package.json | 15 +++- packages/web3-rpc-methods/tsconfig.cjs.json | 10 +++ packages/web3-rpc-methods/tsconfig.esm.json | 9 +++ packages/web3-rpc-methods/tsconfig.json | 1 - packages/web3-rpc-methods/tsconfig.types.json | 10 +++ packages/web3-types/.eslintrc.js | 2 +- packages/web3-types/CHANGELOG.md | 4 ++ packages/web3-types/package.json | 15 +++- packages/web3-types/test/tsconfig.json | 2 +- packages/web3-types/tsconfig.cjs.json | 9 +++ packages/web3-types/tsconfig.esm.json | 8 +++ packages/web3-types/tsconfig.json | 7 -- packages/web3-types/tsconfig.types.json | 10 +++ packages/web3-utils/.eslintrc.js | 2 +- packages/web3-utils/CHANGELOG.md | 4 ++ packages/web3-utils/package.json | 15 +++- packages/web3-utils/test/tsconfig.json | 2 +- packages/web3-utils/tsconfig.cjs.json | 9 +++ packages/web3-utils/tsconfig.esm.json | 8 +++ packages/web3-utils/tsconfig.json | 7 -- packages/web3-utils/tsconfig.types.json | 10 +++ packages/web3-validator/.eslintrc.js | 2 +- packages/web3-validator/CHANGELOG.md | 4 ++ packages/web3-validator/package.json | 15 +++- packages/web3-validator/test/tsconfig.json | 2 +- packages/web3-validator/tsconfig.cjs.json | 9 +++ packages/web3-validator/tsconfig.esm.json | 8 +++ packages/web3-validator/tsconfig.json | 7 -- packages/web3-validator/tsconfig.types.json | 10 +++ packages/web3-validator/webpack.config.js | 1 + packages/web3/.eslintrc.js | 2 +- packages/web3/CHANGELOG.md | 4 ++ packages/web3/package.json | 15 +++- packages/web3/test/tsconfig.json | 2 +- packages/web3/tsconfig.cjs.json | 10 +++ packages/web3/tsconfig.esm.json | 9 +++ packages/web3/tsconfig.json | 8 --- packages/web3/tsconfig.types.json | 10 +++ packages/web3/webpack.analyze.js | 8 ++- packages/web3/webpack.config.js | 8 ++- scripts/changelog/tsconfig.json | 10 +++ scripts/jest.config.js | 5 ++ templates/test/tsconfig.json.tmpl | 2 +- tools/web3-packagetemplate/.eslintrc.js | 2 +- tools/web3-packagetemplate/CHANGELOG.md | 4 ++ tools/web3-packagetemplate/package.json | 5 +- tools/web3-packagetemplate/tsconfig.cjs.json | 10 +++ tools/web3-packagetemplate/tsconfig.esm.json | 9 +++ tools/web3-packagetemplate/tsconfig.json | 1 - .../web3-packagetemplate/tsconfig.types.json | 10 +++ tools/web3-plugin-example/tsconfig.json | 7 +- tsconfig.json => tsconfig.base.json | 6 +- webpack.base.config.js | 5 +- 164 files changed, 1018 insertions(+), 184 deletions(-) create mode 100644 packages/web3-core/tsconfig.cjs.json create mode 100644 packages/web3-core/tsconfig.esm.json delete mode 100644 packages/web3-core/tsconfig.json create mode 100644 packages/web3-core/tsconfig.types.json create mode 100644 packages/web3-errors/tsconfig.cjs.json create mode 100644 packages/web3-errors/tsconfig.esm.json delete mode 120000 packages/web3-errors/tsconfig.json create mode 100644 packages/web3-errors/tsconfig.types.json create mode 100644 packages/web3-eth-abi/tsconfig.cjs.json create mode 100644 packages/web3-eth-abi/tsconfig.esm.json delete mode 100644 packages/web3-eth-abi/tsconfig.json create mode 100644 packages/web3-eth-abi/tsconfig.types.json create mode 100644 packages/web3-eth-accounts/tsconfig.cjs.json create mode 100644 packages/web3-eth-accounts/tsconfig.esm.json delete mode 100644 packages/web3-eth-accounts/tsconfig.json create mode 100644 packages/web3-eth-accounts/tsconfig.types.json create mode 100644 packages/web3-eth-contract/tsconfig.cjs.json create mode 100644 packages/web3-eth-contract/tsconfig.esm.json delete mode 100644 packages/web3-eth-contract/tsconfig.json create mode 100644 packages/web3-eth-contract/tsconfig.types.json create mode 100644 packages/web3-eth-ens/tsconfig.cjs.json create mode 100644 packages/web3-eth-ens/tsconfig.esm.json delete mode 120000 packages/web3-eth-ens/tsconfig.json create mode 100644 packages/web3-eth-ens/tsconfig.types.json create mode 100644 packages/web3-eth-iban/tsconfig.cjs.json create mode 100644 packages/web3-eth-iban/tsconfig.esm.json delete mode 120000 packages/web3-eth-iban/tsconfig.json create mode 100644 packages/web3-eth-iban/tsconfig.types.json create mode 100644 packages/web3-eth-personal/tsconfig.cjs.json create mode 100644 packages/web3-eth-personal/tsconfig.esm.json delete mode 100644 packages/web3-eth-personal/tsconfig.json create mode 100644 packages/web3-eth-personal/tsconfig.types.json create mode 100644 packages/web3-eth/tsconfig.cjs.json create mode 100644 packages/web3-eth/tsconfig.esm.json delete mode 100644 packages/web3-eth/tsconfig.json create mode 100644 packages/web3-eth/tsconfig.types.json create mode 100644 packages/web3-net/tsconfig.cjs.json create mode 100644 packages/web3-net/tsconfig.esm.json delete mode 100644 packages/web3-net/tsconfig.json create mode 100644 packages/web3-net/tsconfig.types.json create mode 100644 packages/web3-providers-http/tsconfig.cjs.json create mode 100644 packages/web3-providers-http/tsconfig.esm.json delete mode 120000 packages/web3-providers-http/tsconfig.json create mode 100644 packages/web3-providers-http/tsconfig.types.json create mode 100644 packages/web3-providers-ipc/tsconfig.cjs.json create mode 100644 packages/web3-providers-ipc/tsconfig.esm.json delete mode 100644 packages/web3-providers-ipc/tsconfig.json create mode 100644 packages/web3-providers-ipc/tsconfig.types.json create mode 100644 packages/web3-providers-ws/tsconfig.cjs.json create mode 100644 packages/web3-providers-ws/tsconfig.esm.json delete mode 120000 packages/web3-providers-ws/tsconfig.json create mode 100644 packages/web3-providers-ws/tsconfig.types.json create mode 100644 packages/web3-rpc-methods/tsconfig.cjs.json create mode 100644 packages/web3-rpc-methods/tsconfig.esm.json delete mode 120000 packages/web3-rpc-methods/tsconfig.json create mode 100644 packages/web3-rpc-methods/tsconfig.types.json create mode 100644 packages/web3-types/tsconfig.cjs.json create mode 100644 packages/web3-types/tsconfig.esm.json delete mode 100644 packages/web3-types/tsconfig.json create mode 100644 packages/web3-types/tsconfig.types.json create mode 100644 packages/web3-utils/tsconfig.cjs.json create mode 100644 packages/web3-utils/tsconfig.esm.json delete mode 100644 packages/web3-utils/tsconfig.json create mode 100644 packages/web3-utils/tsconfig.types.json create mode 100644 packages/web3-validator/tsconfig.cjs.json create mode 100644 packages/web3-validator/tsconfig.esm.json delete mode 100644 packages/web3-validator/tsconfig.json create mode 100644 packages/web3-validator/tsconfig.types.json create mode 100644 packages/web3/tsconfig.cjs.json create mode 100644 packages/web3/tsconfig.esm.json delete mode 100644 packages/web3/tsconfig.json create mode 100644 packages/web3/tsconfig.types.json create mode 100644 scripts/changelog/tsconfig.json create mode 100644 tools/web3-packagetemplate/tsconfig.cjs.json create mode 100644 tools/web3-packagetemplate/tsconfig.esm.json delete mode 120000 tools/web3-packagetemplate/tsconfig.json create mode 100644 tools/web3-packagetemplate/tsconfig.types.json rename tsconfig.json => tsconfig.base.json (80%) diff --git a/.eslintrc.js b/.eslintrc.js index e9a13140da7..2c25537ce8f 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -6,7 +6,7 @@ module.exports = { }, parserOptions: { ecmaVersion: 2016, - project: './tsconfig.json', + project: './tsconfig.base.json', tsconfigRootDir: __dirname, sourceType: 'module', }, diff --git a/.eslintrc.test.js b/.eslintrc.test.js index aa7494dfd8d..191e33c996b 100644 --- a/.eslintrc.test.js +++ b/.eslintrc.test.js @@ -1,6 +1,6 @@ module.exports = { parserOptions: { - project: './tsconfig.json', + project: './tsconfig.base.json', tsconfigRootDir: __dirname, }, extends: ['web3-base/ts-jest'], diff --git a/CHANGELOG.md b/CHANGELOG.md index aef2fe85a1e..3a69cf34b82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1319,10 +1319,79 @@ should use 4.0.1-alpha.0 for testing. ### Added +#### web3 + +- Added hybrid build (ESM and CJS) of library (#5904) + +#### web3-core + +- Added hybrid build (ESM and CJS) of library (#5904) + +#### web3-errors + +- Added hybrid build (ESM and CJS) of library (#5904) + +#### web3-eth + +- Added hybrid build (ESM and CJS) of library (#5904) + +#### web3-eth-abi + +- Added hybrid build (ESM and CJS) of library (#5904) + +#### web3-eth-accounts + +- Added hybrid build (ESM and CJS) of library (#5904) + #### web3-eth-contract +- Added hybrid build (ESM and CJS) of library (#5904) - `input` is now an acceptable property for `ContractInitOptions` in place of `data` (either can be used, but `input` is used withing the +#### web3-eth-ens + +- Added hybrid build (ESM and CJS) of library (#5904) + +#### web3-eth-iban + +- Added hybrid build (ESM and CJS) of library (#5904) + +#### web3-eth-personal + +- Added hybrid build (ESM and CJS) of library (#5904) + +#### web3-net + +- Added hybrid build (ESM and CJS) of library (#5904) + +#### web3-providers-http + +- Added hybrid build (ESM and CJS) of library (#5904) + +#### web3-providers-ipc + +- Added hybrid build (ESM and CJS) of library (#5904) + +#### web3-providers-ws + +- Added hybrid build (ESM and CJS) of library (#5904) + +#### web3-rpc-methods + +- Added hybrid build (ESM and CJS) of library (#5904) + +#### web3-types + +- Added hybrid build (ESM and CJS) of library (#5904) + +#### web3-utils + +- Added hybrid build (ESM and CJS) of library (#5904) + +#### web3-validator + +- Added hybrid build (ESM and CJS) of library (#5904) + ### Removed #### web3-core diff --git a/docs/tsconfig.docs.json b/docs/tsconfig.docs.json index 9ea50364cb1..b11eca77af2 100644 --- a/docs/tsconfig.docs.json +++ b/docs/tsconfig.docs.json @@ -1,8 +1,10 @@ { - "extends": "../tsconfig.json", + "extends": "../tsconfig.base.json", "compilerOptions": { "declarationDir": "dts", - "outDir": "dts" + "outDir": "dts", + "declaration": true, + "declarationMap": true }, "include": ["../packages/*/src/**/*", "../packages/*/types/**/*"] } diff --git a/package.json b/package.json index 0e9af4f1bcb..bcce41a23aa 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "build:web": "lerna run build:web --stream", "build:web:analyze": "lerna run build:web:analyze --stream", "build:docs": "cd docs && yarn install && yarn build", - "changelog": "ts-node scripts/changelog/src/index.ts", + "changelog": "ts-node -P scripts/changelog/tsconfig.json scripts/changelog/src/index.ts", "clean": "lerna run clean --stream --parallel", "ganache:start": "WEB3_SYSTEM_TEST_BACKEND=ganache && ./scripts/ganache.sh start", "ganache:start:background": "WEB3_SYSTEM_TEST_BACKEND=ganache && ./scripts/ganache.sh start 1", diff --git a/packages/web3-core/.eslintrc.js b/packages/web3-core/.eslintrc.js index 8b7fd410b8d..12a507e5126 100644 --- a/packages/web3-core/.eslintrc.js +++ b/packages/web3-core/.eslintrc.js @@ -1,7 +1,7 @@ module.exports = { extends: '../../.eslintrc.js', parserOptions: { - project: './tsconfig.json', + project: './tsconfig.esm.json', tsconfigRootDir: __dirname, }, }; diff --git a/packages/web3-core/CHANGELOG.md b/packages/web3-core/CHANGELOG.md index 6470ab42fd9..6c384fd245b 100644 --- a/packages/web3-core/CHANGELOG.md +++ b/packages/web3-core/CHANGELOG.md @@ -85,6 +85,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Added hybrid build (ESM and CJS) of library (#5904) + ### Changed - If a transaction object with a `data` property is passed to `txInputOptionsFormatter`, it will now be replaced with `input` (#5915) diff --git a/packages/web3-core/package.json b/packages/web3-core/package.json index b67b31acc53..b970a202dea 100644 --- a/packages/web3-core/package.json +++ b/packages/web3-core/package.json @@ -2,7 +2,15 @@ "name": "web3-core", "version": "4.0.1-rc.0", "description": "Web3 core tools for sub-packages. This is an internal package.", - "main": "lib/index.js", + "main": "./lib/commonjs/index.js", + "module": "./lib/esm/index.js", + "exports": { + ".": { + "types": "./lib/types/index.d.ts", + "import": "./lib/esm/index.js", + "require": "./lib/commonjs/index.js" + } + }, "repository": "https://github.com/ChainSafe/web3.js", "author": "ChainSafe Systems", "license": "LGPL-3.0", @@ -16,7 +24,10 @@ "scripts": { "clean": "rimraf dist && rimraf lib", "prebuild": "yarn clean", - "build": "tsc --build", + "build": "yarn build:cjs & yarn build:esm & yarn build:types", + "build:cjs": "tsc --build tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > ./lib/commonjs/package.json", + "build:esm": "tsc --build tsconfig.esm.json && echo '{\"type\": \"module\"}' > ./lib/esm/package.json", + "build:types": "tsc --build tsconfig.types.json", "build:check": "node -e \"require('./lib')\"", "lint": "eslint --ext .js,.ts .", "lint:fix": "eslint --fix --ext .js,.ts .", diff --git a/packages/web3-core/test/tsconfig.json b/packages/web3-core/test/tsconfig.json index 7b7b1624905..831ffc02b5d 100644 --- a/packages/web3-core/test/tsconfig.json +++ b/packages/web3-core/test/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../tsconfig", + "extends": "../tsconfig.cjs.json", "compilerOptions": { "declaration": false, "declarationMap": false diff --git a/packages/web3-core/tsconfig.cjs.json b/packages/web3-core/tsconfig.cjs.json new file mode 100644 index 00000000000..a44e4adc15d --- /dev/null +++ b/packages/web3-core/tsconfig.cjs.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./lib/commonjs", + "declaration": true, + "module": "commonjs" + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-core/tsconfig.esm.json b/packages/web3-core/tsconfig.esm.json new file mode 100644 index 00000000000..5c975a932da --- /dev/null +++ b/packages/web3-core/tsconfig.esm.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./lib/esm", + "module": "es2020" + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-core/tsconfig.json b/packages/web3-core/tsconfig.json deleted file mode 100644 index fb299296e1f..00000000000 --- a/packages/web3-core/tsconfig.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "../../tsconfig", - "compilerOptions": { - "outDir": "lib" - }, - "include": ["src/**/*"] -} diff --git a/packages/web3-core/tsconfig.types.json b/packages/web3-core/tsconfig.types.json new file mode 100644 index 00000000000..4f71bd3a4ba --- /dev/null +++ b/packages/web3-core/tsconfig.types.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "declarationDir": "./lib/types", + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-errors/.eslintrc.js b/packages/web3-errors/.eslintrc.js index 8b7fd410b8d..12a507e5126 100644 --- a/packages/web3-errors/.eslintrc.js +++ b/packages/web3-errors/.eslintrc.js @@ -1,7 +1,7 @@ module.exports = { extends: '../../.eslintrc.js', parserOptions: { - project: './tsconfig.json', + project: './tsconfig.esm.json', tsconfigRootDir: __dirname, }, }; diff --git a/packages/web3-errors/CHANGELOG.md b/packages/web3-errors/CHANGELOG.md index ec4ccb461a8..4fd25db8e80 100644 --- a/packages/web3-errors/CHANGELOG.md +++ b/packages/web3-errors/CHANGELOG.md @@ -88,6 +88,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Added hybrid build (ESM and CJS) of library (#5904) + ### Changed - `gasLimit` is no longer accepted as a parameter for `MissingGasError` and `TransactionGasMismatchError, and is also no longer included in error message (#5915) diff --git a/packages/web3-errors/package.json b/packages/web3-errors/package.json index c6f3bf4e9af..d54b407050c 100644 --- a/packages/web3-errors/package.json +++ b/packages/web3-errors/package.json @@ -2,7 +2,15 @@ "name": "web3-errors", "version": "1.0.0-rc.0", "description": "This package has web3 error classes", - "main": "lib/index.js", + "main": "./lib/commonjs/index.js", + "module": "./lib/esm/index.js", + "exports": { + ".": { + "types": "./lib/types/index.d.ts", + "import": "./lib/esm/index.js", + "require": "./lib/commonjs/index.js" + } + }, "repository": "https://github.com/ChainSafe/web3.js", "author": "ChainSafe Systems", "license": "LGPL-3.0", @@ -16,7 +24,10 @@ "scripts": { "clean": "rimraf dist && rimraf lib", "prebuild": "yarn clean", - "build": "tsc --build", + "build": "yarn build:cjs & yarn build:esm & yarn build:types", + "build:cjs": "tsc --build tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > ./lib/commonjs/package.json", + "build:esm": "tsc --build tsconfig.esm.json && echo '{\"type\": \"module\"}' > ./lib/esm/package.json", + "build:types": "tsc --build tsconfig.types.json", "build:check": "node -e \"require('./lib')\"", "lint": "eslint --ext .js,.ts .", "lint:fix": "eslint --fix --ext .js,.ts .", diff --git a/packages/web3-errors/tsconfig.cjs.json b/packages/web3-errors/tsconfig.cjs.json new file mode 100644 index 00000000000..675976cf375 --- /dev/null +++ b/packages/web3-errors/tsconfig.cjs.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./lib/commonjs", + "esModuleInterop": true, + "declaration": true, + "module": "commonjs" + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-errors/tsconfig.esm.json b/packages/web3-errors/tsconfig.esm.json new file mode 100644 index 00000000000..c8e53463a6e --- /dev/null +++ b/packages/web3-errors/tsconfig.esm.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./lib/esm", + "esModuleInterop": true, + "module": "es2020" + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-errors/tsconfig.json b/packages/web3-errors/tsconfig.json deleted file mode 120000 index 900bb05c680..00000000000 --- a/packages/web3-errors/tsconfig.json +++ /dev/null @@ -1 +0,0 @@ -../../templates/tsconfig.json.tmpl \ No newline at end of file diff --git a/packages/web3-errors/tsconfig.types.json b/packages/web3-errors/tsconfig.types.json new file mode 100644 index 00000000000..4f71bd3a4ba --- /dev/null +++ b/packages/web3-errors/tsconfig.types.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "declarationDir": "./lib/types", + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-eth-abi/.eslintrc.js b/packages/web3-eth-abi/.eslintrc.js index 8b7fd410b8d..12a507e5126 100644 --- a/packages/web3-eth-abi/.eslintrc.js +++ b/packages/web3-eth-abi/.eslintrc.js @@ -1,7 +1,7 @@ module.exports = { extends: '../../.eslintrc.js', parserOptions: { - project: './tsconfig.json', + project: './tsconfig.esm.json', tsconfigRootDir: __dirname, }, }; diff --git a/packages/web3-eth-abi/CHANGELOG.md b/packages/web3-eth-abi/CHANGELOG.md index 3237aba303e..c3a685c794d 100644 --- a/packages/web3-eth-abi/CHANGELOG.md +++ b/packages/web3-eth-abi/CHANGELOG.md @@ -90,6 +90,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Added hybrid build (ESM and CJS) of library (#5904) + ### Removed - Removed `formatDecodedObject` function (#5934) diff --git a/packages/web3-eth-abi/package.json b/packages/web3-eth-abi/package.json index b5c71bd98eb..6d0df4c5e61 100644 --- a/packages/web3-eth-abi/package.json +++ b/packages/web3-eth-abi/package.json @@ -2,7 +2,15 @@ "name": "web3-eth-abi", "version": "4.0.1-rc.0", "description": "Web3 module encode and decode EVM in/output.", - "main": "lib/index.js", + "main": "./lib/commonjs/index.js", + "module": "./lib/esm/index.js", + "exports": { + ".": { + "types": "./lib/types/index.d.ts", + "import": "./lib/esm/index.js", + "require": "./lib/commonjs/index.js" + } + }, "repository": "https://github.com/ethereum/web3.js/tree/4.x/packages/web3-eth-abi", "author": "ChainSafe Systems", "license": "LGPL-3.0", @@ -16,7 +24,10 @@ "scripts": { "clean": "rimraf dist && rimraf lib", "prebuild": "yarn clean", - "build": "tsc --build", + "build": "yarn build:cjs & yarn build:esm & yarn build:types", + "build:cjs": "tsc --build tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > ./lib/commonjs/package.json", + "build:esm": "tsc --build tsconfig.esm.json && echo '{\"type\": \"module\"}' > ./lib/esm/package.json", + "build:types": "tsc --build tsconfig.types.json", "build:check": "node -e \"require('./lib')\"", "lint": "eslint --ext .js,.ts .", "lint:fix": "eslint --fix --ext .js,.ts .", diff --git a/packages/web3-eth-abi/test/tsconfig.json b/packages/web3-eth-abi/test/tsconfig.json index 7b7b1624905..831ffc02b5d 100644 --- a/packages/web3-eth-abi/test/tsconfig.json +++ b/packages/web3-eth-abi/test/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../tsconfig", + "extends": "../tsconfig.cjs.json", "compilerOptions": { "declaration": false, "declarationMap": false diff --git a/packages/web3-eth-abi/tsconfig.cjs.json b/packages/web3-eth-abi/tsconfig.cjs.json new file mode 100644 index 00000000000..675976cf375 --- /dev/null +++ b/packages/web3-eth-abi/tsconfig.cjs.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./lib/commonjs", + "esModuleInterop": true, + "declaration": true, + "module": "commonjs" + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-eth-abi/tsconfig.esm.json b/packages/web3-eth-abi/tsconfig.esm.json new file mode 100644 index 00000000000..c8e53463a6e --- /dev/null +++ b/packages/web3-eth-abi/tsconfig.esm.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./lib/esm", + "esModuleInterop": true, + "module": "es2020" + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-eth-abi/tsconfig.json b/packages/web3-eth-abi/tsconfig.json deleted file mode 100644 index fb299296e1f..00000000000 --- a/packages/web3-eth-abi/tsconfig.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "../../tsconfig", - "compilerOptions": { - "outDir": "lib" - }, - "include": ["src/**/*"] -} diff --git a/packages/web3-eth-abi/tsconfig.types.json b/packages/web3-eth-abi/tsconfig.types.json new file mode 100644 index 00000000000..4f71bd3a4ba --- /dev/null +++ b/packages/web3-eth-abi/tsconfig.types.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "declarationDir": "./lib/types", + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-eth-accounts/.eslintrc.js b/packages/web3-eth-accounts/.eslintrc.js index 8b7fd410b8d..12a507e5126 100644 --- a/packages/web3-eth-accounts/.eslintrc.js +++ b/packages/web3-eth-accounts/.eslintrc.js @@ -1,7 +1,7 @@ module.exports = { extends: '../../.eslintrc.js', parserOptions: { - project: './tsconfig.json', + project: './tsconfig.esm.json', tsconfigRootDir: __dirname, }, }; diff --git a/packages/web3-eth-accounts/CHANGELOG.md b/packages/web3-eth-accounts/CHANGELOG.md index a8805e0820c..934f884c92e 100644 --- a/packages/web3-eth-accounts/CHANGELOG.md +++ b/packages/web3-eth-accounts/CHANGELOG.md @@ -72,3 +72,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Updated dependencies (#5912) ## [Unreleased] + +### Added + +- Added hybrid build (ESM and CJS) of library (#5904) diff --git a/packages/web3-eth-accounts/package.json b/packages/web3-eth-accounts/package.json index 87119ce23d6..b3db6f47e3d 100644 --- a/packages/web3-eth-accounts/package.json +++ b/packages/web3-eth-accounts/package.json @@ -2,7 +2,15 @@ "name": "web3-eth-accounts", "version": "4.0.1-rc.0", "description": "Package for managing Ethereum accounts and signing", - "main": "lib/index.js", + "main": "./lib/commonjs/index.js", + "module": "./lib/esm/index.js", + "exports": { + ".": { + "types": "./lib/types/index.d.ts", + "import": "./lib/esm/index.js", + "require": "./lib/commonjs/index.js" + } + }, "repository": "https://github.com/ChainSafe/web3.js", "author": "ChainSafe Systems", "license": "LGPL-3.0", @@ -16,7 +24,10 @@ "scripts": { "clean": "rimraf dist && rimraf lib", "prebuild": "yarn clean", - "build": "tsc --build", + "build": "yarn build:cjs & yarn build:esm & yarn build:types", + "build:cjs": "tsc --build tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > ./lib/commonjs/package.json", + "build:esm": "tsc --build tsconfig.esm.json && echo '{\"type\": \"module\"}' > ./lib/esm/package.json", + "build:types": "tsc --build tsconfig.types.json", "build:check": "node -e \"require('./lib')\"", "lint": "eslint --ext .js,.ts .", "lint:fix": "eslint --fix --ext .js,.ts .", diff --git a/packages/web3-eth-accounts/src/account.ts b/packages/web3-eth-accounts/src/account.ts index 60ce6ebd2e9..1991e1c14bf 100644 --- a/packages/web3-eth-accounts/src/account.ts +++ b/packages/web3-eth-accounts/src/account.ts @@ -15,7 +15,8 @@ You should have received a copy of the GNU Lesser General Public License along with web3.js. If not, see . */ -import { TransactionFactory, TypedTransaction } from '@ethereumjs/tx'; +import { TypedTransaction } from '@ethereumjs/tx'; +import defaultImport, * as fullImport from '@ethereumjs/tx'; import { decrypt as createDecipheriv, encrypt as createCipheriv } from 'ethereum-cryptography/aes'; import { pbkdf2Sync } from 'ethereum-cryptography/pbkdf2'; import { scryptSync } from 'ethereum-cryptography/scrypt'; @@ -58,6 +59,8 @@ import { isBuffer, isNullish, isString, validator } from 'web3-validator'; import { keyStoreSchema } from './schemas'; import { SignatureObject, SignResult, SignTransactionResult, Web3Account } from './types'; +const { TransactionFactory } = defaultImport || fullImport; + /** * Get the private key buffer after the validation */ diff --git a/packages/web3-eth-accounts/test/integration/account.test.ts b/packages/web3-eth-accounts/test/integration/account.test.ts index 005f1a2acf7..c748db6ae63 100644 --- a/packages/web3-eth-accounts/test/integration/account.test.ts +++ b/packages/web3-eth-accounts/test/integration/account.test.ts @@ -15,7 +15,7 @@ You should have received a copy of the GNU Lesser General Public License along with web3.js. If not, see . */ -import { TransactionFactory } from '@ethereumjs/tx'; +import defaultImport, * as fullImport from '@ethereumjs/tx'; import { Address } from 'web3-types'; import { isHexStrict } from 'web3-utils'; import { Web3ValidatorError } from 'web3-validator'; @@ -46,6 +46,8 @@ import { validPrivateKeyToAddressData, } from '../fixtures/account'; +const { TransactionFactory } = defaultImport || fullImport; + describe('accounts', () => { describe('create', () => { describe('valid cases', () => { diff --git a/packages/web3-eth-accounts/test/unit/account.test.ts b/packages/web3-eth-accounts/test/unit/account.test.ts index ddb6d6ce9d0..8ffa52d52cf 100644 --- a/packages/web3-eth-accounts/test/unit/account.test.ts +++ b/packages/web3-eth-accounts/test/unit/account.test.ts @@ -15,7 +15,7 @@ You should have received a copy of the GNU Lesser General Public License along with web3.js. If not, see . */ -import { TransactionFactory } from '@ethereumjs/tx'; +import defaultImport, * as fullImport from '@ethereumjs/tx'; import { Address } from 'web3-types'; import { isHexStrict } from 'web3-utils'; import { Web3ValidatorError } from 'web3-validator'; @@ -46,6 +46,8 @@ import { validPrivateKeyToAddressData, } from '../fixtures/account'; +const { TransactionFactory } = defaultImport || fullImport; + describe('accounts', () => { describe('create', () => { describe('valid cases', () => { diff --git a/packages/web3-eth-accounts/tsconfig.cjs.json b/packages/web3-eth-accounts/tsconfig.cjs.json new file mode 100644 index 00000000000..675976cf375 --- /dev/null +++ b/packages/web3-eth-accounts/tsconfig.cjs.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./lib/commonjs", + "esModuleInterop": true, + "declaration": true, + "module": "commonjs" + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-eth-accounts/tsconfig.esm.json b/packages/web3-eth-accounts/tsconfig.esm.json new file mode 100644 index 00000000000..c8e53463a6e --- /dev/null +++ b/packages/web3-eth-accounts/tsconfig.esm.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./lib/esm", + "esModuleInterop": true, + "module": "es2020" + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-eth-accounts/tsconfig.json b/packages/web3-eth-accounts/tsconfig.json deleted file mode 100644 index 7af3885edd9..00000000000 --- a/packages/web3-eth-accounts/tsconfig.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "extends": "../../tsconfig", - "compilerOptions": { - "outDir": "lib", - "esModuleInterop": true - }, - "include": ["src/**/*"] -} diff --git a/packages/web3-eth-accounts/tsconfig.types.json b/packages/web3-eth-accounts/tsconfig.types.json new file mode 100644 index 00000000000..4f71bd3a4ba --- /dev/null +++ b/packages/web3-eth-accounts/tsconfig.types.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "declarationDir": "./lib/types", + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-eth-contract/.eslintrc.js b/packages/web3-eth-contract/.eslintrc.js index 8b7fd410b8d..12a507e5126 100644 --- a/packages/web3-eth-contract/.eslintrc.js +++ b/packages/web3-eth-contract/.eslintrc.js @@ -1,7 +1,7 @@ module.exports = { extends: '../../.eslintrc.js', parserOptions: { - project: './tsconfig.json', + project: './tsconfig.esm.json', tsconfigRootDir: __dirname, }, }; diff --git a/packages/web3-eth-contract/CHANGELOG.md b/packages/web3-eth-contract/CHANGELOG.md index 65e1fc40f76..cda7efbed03 100644 --- a/packages/web3-eth-contract/CHANGELOG.md +++ b/packages/web3-eth-contract/CHANGELOG.md @@ -239,6 +239,7 @@ const transactionHash = receipt.transactionHash; ### Added +- Added hybrid build (ESM and CJS) of library (#5904) - `input` is now an acceptable property for `ContractInitOptions` in place of `data` (either can be used, but `input` is used withing the `Contract` class) (#5915) diff --git a/packages/web3-eth-contract/package.json b/packages/web3-eth-contract/package.json index 741471bee84..d09fb662a60 100644 --- a/packages/web3-eth-contract/package.json +++ b/packages/web3-eth-contract/package.json @@ -2,7 +2,15 @@ "name": "web3-eth-contract", "version": "4.0.1-rc.0", "description": "Web3 module to interact with Ethereum smart contracts.", - "main": "lib/index.js", + "main": "./lib/commonjs/index.js", + "module": "./lib/esm/index.js", + "exports": { + ".": { + "types": "./lib/types/index.d.ts", + "import": "./lib/esm/index.js", + "require": "./lib/commonjs/index.js" + } + }, "repository": "https://github.com/ethereum/web3.js/tree/4.x/packages/web3-eth-contract", "author": "ChainSafe Systems", "license": "LGPL-3.0", @@ -16,7 +24,10 @@ "scripts": { "clean": "rimraf dist && rimraf lib", "prebuild": "yarn clean", - "build": "tsc --build", + "build": "yarn build:cjs & yarn build:esm & yarn build:types", + "build:cjs": "tsc --build tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > ./lib/commonjs/package.json", + "build:esm": "tsc --build tsconfig.esm.json && echo '{\"type\": \"module\"}' > ./lib/esm/package.json", + "build:types": "tsc --build tsconfig.types.json", "build:check": "node -e \"require('./lib')\"", "lint": "eslint --ext .js,.ts .", "lint:fix": "eslint --fix --ext .js,.ts .", diff --git a/packages/web3-eth-contract/test/tsconfig.json b/packages/web3-eth-contract/test/tsconfig.json index 7b7b1624905..831ffc02b5d 100644 --- a/packages/web3-eth-contract/test/tsconfig.json +++ b/packages/web3-eth-contract/test/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../tsconfig", + "extends": "../tsconfig.cjs.json", "compilerOptions": { "declaration": false, "declarationMap": false diff --git a/packages/web3-eth-contract/tsconfig.cjs.json b/packages/web3-eth-contract/tsconfig.cjs.json new file mode 100644 index 00000000000..675976cf375 --- /dev/null +++ b/packages/web3-eth-contract/tsconfig.cjs.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./lib/commonjs", + "esModuleInterop": true, + "declaration": true, + "module": "commonjs" + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-eth-contract/tsconfig.esm.json b/packages/web3-eth-contract/tsconfig.esm.json new file mode 100644 index 00000000000..c8e53463a6e --- /dev/null +++ b/packages/web3-eth-contract/tsconfig.esm.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./lib/esm", + "esModuleInterop": true, + "module": "es2020" + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-eth-contract/tsconfig.json b/packages/web3-eth-contract/tsconfig.json deleted file mode 100644 index 7af3885edd9..00000000000 --- a/packages/web3-eth-contract/tsconfig.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "extends": "../../tsconfig", - "compilerOptions": { - "outDir": "lib", - "esModuleInterop": true - }, - "include": ["src/**/*"] -} diff --git a/packages/web3-eth-contract/tsconfig.types.json b/packages/web3-eth-contract/tsconfig.types.json new file mode 100644 index 00000000000..4f71bd3a4ba --- /dev/null +++ b/packages/web3-eth-contract/tsconfig.types.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "declarationDir": "./lib/types", + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-eth-ens/.eslintrc.js b/packages/web3-eth-ens/.eslintrc.js index 8b7fd410b8d..12a507e5126 100644 --- a/packages/web3-eth-ens/.eslintrc.js +++ b/packages/web3-eth-ens/.eslintrc.js @@ -1,7 +1,7 @@ module.exports = { extends: '../../.eslintrc.js', parserOptions: { - project: './tsconfig.json', + project: './tsconfig.esm.json', tsconfigRootDir: __dirname, }, }; diff --git a/packages/web3-eth-ens/CHANGELOG.md b/packages/web3-eth-ens/CHANGELOG.md index 26b2328ebab..26e7dae9edb 100644 --- a/packages/web3-eth-ens/CHANGELOG.md +++ b/packages/web3-eth-ens/CHANGELOG.md @@ -72,3 +72,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Updated dependencies (#5912) ## [Unreleased] + +### Added + +- Added hybrid build (ESM and CJS) of library (#5904) diff --git a/packages/web3-eth-ens/package.json b/packages/web3-eth-ens/package.json index 1eb1cd896fe..4ff12899b2d 100644 --- a/packages/web3-eth-ens/package.json +++ b/packages/web3-eth-ens/package.json @@ -2,7 +2,15 @@ "name": "web3-eth-ens", "version": "4.0.1-rc.0", "description": "This package has ENS functions for interacting with Ethereum Name Service.", - "main": "lib/index.js", + "main": "./lib/commonjs/index.js", + "module": "./lib/esm/index.js", + "exports": { + ".": { + "types": "./lib/types/index.d.ts", + "import": "./lib/esm/index.js", + "require": "./lib/commonjs/index.js" + } + }, "repository": "https://github.com/ChainSafe/web3.js", "author": "ChainSafe Systems", "license": "LGPL-3.0", @@ -16,7 +24,10 @@ "scripts": { "clean": "rimraf dist && rimraf lib", "prebuild": "yarn clean", - "build": "tsc --build", + "build": "yarn build:cjs & yarn build:esm & yarn build:types", + "build:cjs": "tsc --build tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > ./lib/commonjs/package.json", + "build:esm": "tsc --build tsconfig.esm.json && echo '{\"type\": \"module\"}' > ./lib/esm/package.json", + "build:types": "tsc --build tsconfig.types.json", "build:check": "node -e \"require('./lib')\"", "lint": "eslint --ext .js,.ts .", "lint:fix": "eslint --fix --ext .js,.ts .", diff --git a/packages/web3-eth-ens/tsconfig.cjs.json b/packages/web3-eth-ens/tsconfig.cjs.json new file mode 100644 index 00000000000..675976cf375 --- /dev/null +++ b/packages/web3-eth-ens/tsconfig.cjs.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./lib/commonjs", + "esModuleInterop": true, + "declaration": true, + "module": "commonjs" + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-eth-ens/tsconfig.esm.json b/packages/web3-eth-ens/tsconfig.esm.json new file mode 100644 index 00000000000..c8e53463a6e --- /dev/null +++ b/packages/web3-eth-ens/tsconfig.esm.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./lib/esm", + "esModuleInterop": true, + "module": "es2020" + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-eth-ens/tsconfig.json b/packages/web3-eth-ens/tsconfig.json deleted file mode 120000 index 900bb05c680..00000000000 --- a/packages/web3-eth-ens/tsconfig.json +++ /dev/null @@ -1 +0,0 @@ -../../templates/tsconfig.json.tmpl \ No newline at end of file diff --git a/packages/web3-eth-ens/tsconfig.types.json b/packages/web3-eth-ens/tsconfig.types.json new file mode 100644 index 00000000000..4f71bd3a4ba --- /dev/null +++ b/packages/web3-eth-ens/tsconfig.types.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "declarationDir": "./lib/types", + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-eth-iban/.eslintrc.js b/packages/web3-eth-iban/.eslintrc.js index 8b7fd410b8d..12a507e5126 100644 --- a/packages/web3-eth-iban/.eslintrc.js +++ b/packages/web3-eth-iban/.eslintrc.js @@ -1,7 +1,7 @@ module.exports = { extends: '../../.eslintrc.js', parserOptions: { - project: './tsconfig.json', + project: './tsconfig.esm.json', tsconfigRootDir: __dirname, }, }; diff --git a/packages/web3-eth-iban/CHANGELOG.md b/packages/web3-eth-iban/CHANGELOG.md index 0bdb3ac9195..0e14a002ae2 100644 --- a/packages/web3-eth-iban/CHANGELOG.md +++ b/packages/web3-eth-iban/CHANGELOG.md @@ -66,3 +66,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Updated dependencies (#5912) ## [Unreleased] + +### Added + +- Added hybrid build (ESM and CJS) of library (#5904) diff --git a/packages/web3-eth-iban/package.json b/packages/web3-eth-iban/package.json index 57b110a38c2..7455ac3ac2d 100644 --- a/packages/web3-eth-iban/package.json +++ b/packages/web3-eth-iban/package.json @@ -2,7 +2,15 @@ "name": "web3-eth-iban", "version": "4.0.1-rc.0", "description": "This package converts Ethereum addresses to IBAN addresses and vice versa.", - "main": "lib/index.js", + "main": "./lib/commonjs/index.js", + "module": "./lib/esm/index.js", + "exports": { + ".": { + "types": "./lib/types/index.d.ts", + "import": "./lib/esm/index.js", + "require": "./lib/commonjs/index.js" + } + }, "repository": "https://github.com/ChainSafe/web3.js", "author": "ChainSafe Systems", "license": "LGPL-3.0", @@ -16,7 +24,10 @@ "scripts": { "clean": "rimraf dist && rimraf lib", "prebuild": "yarn clean", - "build": "tsc --build", + "build": "yarn build:cjs & yarn build:esm & yarn build:types", + "build:cjs": "tsc --build tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > ./lib/commonjs/package.json", + "build:esm": "tsc --build tsconfig.esm.json && echo '{\"type\": \"module\"}' > ./lib/esm/package.json", + "build:types": "tsc --build tsconfig.types.json", "build:check": "node -e \"require('./lib')\"", "lint": "eslint --ext .js,.ts .", "lint:fix": "eslint --fix --ext .js,.ts .", diff --git a/packages/web3-eth-iban/tsconfig.cjs.json b/packages/web3-eth-iban/tsconfig.cjs.json new file mode 100644 index 00000000000..675976cf375 --- /dev/null +++ b/packages/web3-eth-iban/tsconfig.cjs.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./lib/commonjs", + "esModuleInterop": true, + "declaration": true, + "module": "commonjs" + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-eth-iban/tsconfig.esm.json b/packages/web3-eth-iban/tsconfig.esm.json new file mode 100644 index 00000000000..c8e53463a6e --- /dev/null +++ b/packages/web3-eth-iban/tsconfig.esm.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./lib/esm", + "esModuleInterop": true, + "module": "es2020" + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-eth-iban/tsconfig.json b/packages/web3-eth-iban/tsconfig.json deleted file mode 120000 index 900bb05c680..00000000000 --- a/packages/web3-eth-iban/tsconfig.json +++ /dev/null @@ -1 +0,0 @@ -../../templates/tsconfig.json.tmpl \ No newline at end of file diff --git a/packages/web3-eth-iban/tsconfig.types.json b/packages/web3-eth-iban/tsconfig.types.json new file mode 100644 index 00000000000..4f71bd3a4ba --- /dev/null +++ b/packages/web3-eth-iban/tsconfig.types.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "declarationDir": "./lib/types", + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-eth-personal/.eslintrc.js b/packages/web3-eth-personal/.eslintrc.js index 8b7fd410b8d..12a507e5126 100644 --- a/packages/web3-eth-personal/.eslintrc.js +++ b/packages/web3-eth-personal/.eslintrc.js @@ -1,7 +1,7 @@ module.exports = { extends: '../../.eslintrc.js', parserOptions: { - project: './tsconfig.json', + project: './tsconfig.esm.json', tsconfigRootDir: __dirname, }, }; diff --git a/packages/web3-eth-personal/CHANGELOG.md b/packages/web3-eth-personal/CHANGELOG.md index 6c70f09f0fe..792534aae0b 100644 --- a/packages/web3-eth-personal/CHANGELOG.md +++ b/packages/web3-eth-personal/CHANGELOG.md @@ -82,3 +82,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Updated dependencies (#5912) ## [Unreleased] + +### Added + +- Added hybrid build (ESM and CJS) of library (#5904) diff --git a/packages/web3-eth-personal/package.json b/packages/web3-eth-personal/package.json index b6ddc07e288..0753939b6cc 100644 --- a/packages/web3-eth-personal/package.json +++ b/packages/web3-eth-personal/package.json @@ -2,7 +2,15 @@ "name": "web3-eth-personal", "version": "4.0.1-rc.0", "description": "Web3 module to interact with the Ethereum blockchain accounts stored in the node.", - "main": "lib/index.js", + "main": "./lib/commonjs/index.js", + "module": "./lib/esm/index.js", + "exports": { + ".": { + "types": "./lib/types/index.d.ts", + "import": "./lib/esm/index.js", + "require": "./lib/commonjs/index.js" + } + }, "repository": "https://github.com/ChainSafe/web3.js", "author": "ChainSafe Systems", "license": "LGPL-3.0", @@ -16,7 +24,10 @@ "scripts": { "clean": "rimraf dist && rimraf lib", "prebuild": "yarn clean", - "build": "tsc --build", + "build": "yarn build:cjs & yarn build:esm & yarn build:types", + "build:cjs": "tsc --build tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > ./lib/commonjs/package.json", + "build:esm": "tsc --build tsconfig.esm.json && echo '{\"type\": \"module\"}' > ./lib/esm/package.json", + "build:types": "tsc --build tsconfig.types.json", "build:check": "node -e \"require('./lib')\"", "lint": "eslint --ext .js,.ts .", "lint:fix": "eslint --fix --ext .js,.ts .", diff --git a/packages/web3-eth-personal/test/tsconfig.json b/packages/web3-eth-personal/test/tsconfig.json index 7b7b1624905..831ffc02b5d 100644 --- a/packages/web3-eth-personal/test/tsconfig.json +++ b/packages/web3-eth-personal/test/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../tsconfig", + "extends": "../tsconfig.cjs.json", "compilerOptions": { "declaration": false, "declarationMap": false diff --git a/packages/web3-eth-personal/tsconfig.cjs.json b/packages/web3-eth-personal/tsconfig.cjs.json new file mode 100644 index 00000000000..675976cf375 --- /dev/null +++ b/packages/web3-eth-personal/tsconfig.cjs.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./lib/commonjs", + "esModuleInterop": true, + "declaration": true, + "module": "commonjs" + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-eth-personal/tsconfig.esm.json b/packages/web3-eth-personal/tsconfig.esm.json new file mode 100644 index 00000000000..c8e53463a6e --- /dev/null +++ b/packages/web3-eth-personal/tsconfig.esm.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./lib/esm", + "esModuleInterop": true, + "module": "es2020" + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-eth-personal/tsconfig.json b/packages/web3-eth-personal/tsconfig.json deleted file mode 100644 index 7af3885edd9..00000000000 --- a/packages/web3-eth-personal/tsconfig.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "extends": "../../tsconfig", - "compilerOptions": { - "outDir": "lib", - "esModuleInterop": true - }, - "include": ["src/**/*"] -} diff --git a/packages/web3-eth-personal/tsconfig.types.json b/packages/web3-eth-personal/tsconfig.types.json new file mode 100644 index 00000000000..4f71bd3a4ba --- /dev/null +++ b/packages/web3-eth-personal/tsconfig.types.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "declarationDir": "./lib/types", + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-eth/.eslintrc.js b/packages/web3-eth/.eslintrc.js index 8b7fd410b8d..12a507e5126 100644 --- a/packages/web3-eth/.eslintrc.js +++ b/packages/web3-eth/.eslintrc.js @@ -1,7 +1,7 @@ module.exports = { extends: '../../.eslintrc.js', parserOptions: { - project: './tsconfig.json', + project: './tsconfig.esm.json', tsconfigRootDir: __dirname, }, }; diff --git a/packages/web3-eth/CHANGELOG.md b/packages/web3-eth/CHANGELOG.md index f0cd5c85ad6..3ac7b5f517c 100644 --- a/packages/web3-eth/CHANGELOG.md +++ b/packages/web3-eth/CHANGELOG.md @@ -108,6 +108,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Added hybrid build (ESM and CJS) of library (#5904) + ### Changed - `signTransaction` will now return `gas` instead of `gasLimit` for returned transaction object regardless of what property name the provider uses (#5915) diff --git a/packages/web3-eth/package.json b/packages/web3-eth/package.json index c5956cc7d3c..f37409a19b9 100644 --- a/packages/web3-eth/package.json +++ b/packages/web3-eth/package.json @@ -2,7 +2,15 @@ "name": "web3-eth", "version": "4.0.1-rc.0", "description": "Web3 module to interact with the Ethereum blockchain and smart contracts.", - "main": "lib/index.js", + "main": "./lib/commonjs/index.js", + "module": "./lib/esm/index.js", + "exports": { + ".": { + "types": "./lib/types/index.d.ts", + "import": "./lib/esm/index.js", + "require": "./lib/commonjs/index.js" + } + }, "repository": "https://github.com/ChainSafe/web3.js", "author": "ChainSafe Systems", "license": "LGPL-3.0", @@ -16,7 +24,10 @@ "scripts": { "clean": "rimraf dist && rimraf lib", "prebuild": "yarn clean", - "build": "tsc --build", + "build": "yarn build:cjs & yarn build:esm & yarn build:types", + "build:cjs": "tsc --build tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > ./lib/commonjs/package.json", + "build:esm": "tsc --build tsconfig.esm.json && echo '{\"type\": \"module\"}' > ./lib/esm/package.json", + "build:types": "tsc --build tsconfig.types.json", "build:check": "node -e \"require('./lib')\"", "lint": "eslint --ext .js,.ts .", "lint:fix": "eslint --fix --ext .js,.ts .", diff --git a/packages/web3-eth/src/rpc_method_wrappers.ts b/packages/web3-eth/src/rpc_method_wrappers.ts index e9c96af56a5..a84e795328d 100644 --- a/packages/web3-eth/src/rpc_method_wrappers.ts +++ b/packages/web3-eth/src/rpc_method_wrappers.ts @@ -64,7 +64,7 @@ import { TransactionRevertWithCustomError, } from 'web3-errors'; import { ethRpcMethods } from 'web3-rpc-methods'; -import { TransactionFactory } from '@ethereumjs/tx'; +import defaultImport, * as fullImport from '@ethereumjs/tx'; import { decodeSignedTransaction } from './utils/decode_signed_transaction'; import { @@ -98,6 +98,8 @@ import { getTransactionError } from './utils/get_transaction_error'; // eslint-disable-next-line import/no-cycle import { getRevertReason } from './utils/get_revert_reason'; +const { TransactionFactory } = defaultImport || fullImport; + /** * * @param web3Context ({@link Web3Context}) Web3 configuration object that contains things such as the provider, request manager, wallet, etc. diff --git a/packages/web3-eth/src/utils/decode_signed_transaction.ts b/packages/web3-eth/src/utils/decode_signed_transaction.ts index d714682822c..a36879fc255 100644 --- a/packages/web3-eth/src/utils/decode_signed_transaction.ts +++ b/packages/web3-eth/src/utils/decode_signed_transaction.ts @@ -14,12 +14,14 @@ GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with web3.js. If not, see . */ -import { TransactionFactory } from '@ethereumjs/tx'; +import defaultImport, * as fullImport from '@ethereumjs/tx'; import { HexStringBytes, SignedTransactionInfoAPI, TransactionSignedAPI } from 'web3-types'; import { bytesToHex, DataFormat, format, hexToBytes, keccak256 } from 'web3-utils'; import { detectRawTransactionType } from './detect_transaction_type'; import { formatTransaction } from './format_transaction'; +const { TransactionFactory } = defaultImport || fullImport; + /** * Decodes an [RLP](https://ethereum.org/en/developers/docs/data-structures-and-encoding/rlp/#top) encoded transaction. * diff --git a/packages/web3-eth/src/utils/prepare_transaction_for_signing.ts b/packages/web3-eth/src/utils/prepare_transaction_for_signing.ts index 77d0df3880b..2aa99552246 100644 --- a/packages/web3-eth/src/utils/prepare_transaction_for_signing.ts +++ b/packages/web3-eth/src/utils/prepare_transaction_for_signing.ts @@ -16,7 +16,8 @@ along with web3.js. If not, see . */ import Common from '@ethereumjs/common'; -import { TransactionFactory, TxOptions } from '@ethereumjs/tx'; +import defaultImport, * as fullImport from '@ethereumjs/tx'; +import { TxOptions } from '@ethereumjs/tx'; import { EthExecutionAPI, HexString, @@ -33,6 +34,8 @@ import { validateTransactionForSigning } from '../validation'; import { formatTransaction } from './format_transaction'; import { transactionBuilder } from './transaction_builder'; +const { TransactionFactory } = defaultImport || fullImport; + const getEthereumjsTxDataFromTransaction = ( transaction: FormatType, ) => ({ diff --git a/packages/web3-eth/test/integration/rpc.test.ts b/packages/web3-eth/test/integration/rpc.test.ts index 406d22f6270..cdaadc4050e 100644 --- a/packages/web3-eth/test/integration/rpc.test.ts +++ b/packages/web3-eth/test/integration/rpc.test.ts @@ -19,7 +19,7 @@ import { AbiEventFragment, TransactionReceipt, TransactionInfo } from 'web3-type // eslint-disable-next-line import/no-extraneous-dependencies import { Contract, decodeEventABI } from 'web3-eth-contract'; import { hexToNumber, hexToString, numberToHex, FMT_BYTES, FMT_NUMBER } from 'web3-utils'; -import { getStorageSlotNumForLongString } from 'web3-utils/src'; +import { getStorageSlotNumForLongString } from 'web3-utils'; // eslint-disable-next-line import/no-extraneous-dependencies import { Web3Eth } from '../../src'; diff --git a/packages/web3-eth/tsconfig.cjs.json b/packages/web3-eth/tsconfig.cjs.json new file mode 100644 index 00000000000..675976cf375 --- /dev/null +++ b/packages/web3-eth/tsconfig.cjs.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./lib/commonjs", + "esModuleInterop": true, + "declaration": true, + "module": "commonjs" + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-eth/tsconfig.esm.json b/packages/web3-eth/tsconfig.esm.json new file mode 100644 index 00000000000..c8e53463a6e --- /dev/null +++ b/packages/web3-eth/tsconfig.esm.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./lib/esm", + "esModuleInterop": true, + "module": "es2020" + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-eth/tsconfig.json b/packages/web3-eth/tsconfig.json deleted file mode 100644 index 7af3885edd9..00000000000 --- a/packages/web3-eth/tsconfig.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "extends": "../../tsconfig", - "compilerOptions": { - "outDir": "lib", - "esModuleInterop": true - }, - "include": ["src/**/*"] -} diff --git a/packages/web3-eth/tsconfig.types.json b/packages/web3-eth/tsconfig.types.json new file mode 100644 index 00000000000..4f71bd3a4ba --- /dev/null +++ b/packages/web3-eth/tsconfig.types.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "declarationDir": "./lib/types", + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-net/.eslintrc.js b/packages/web3-net/.eslintrc.js index 8b7fd410b8d..12a507e5126 100644 --- a/packages/web3-net/.eslintrc.js +++ b/packages/web3-net/.eslintrc.js @@ -1,7 +1,7 @@ module.exports = { extends: '../../.eslintrc.js', parserOptions: { - project: './tsconfig.json', + project: './tsconfig.esm.json', tsconfigRootDir: __dirname, }, }; diff --git a/packages/web3-net/CHANGELOG.md b/packages/web3-net/CHANGELOG.md index 5e2d2d5d284..c4e1b4335db 100644 --- a/packages/web3-net/CHANGELOG.md +++ b/packages/web3-net/CHANGELOG.md @@ -82,3 +82,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Updated dependencies (#5912) ## [Unreleased] + +### Added + +- Added hybrid build (ESM and CJS) of library (#5904) diff --git a/packages/web3-net/package.json b/packages/web3-net/package.json index f1ce0523523..f79267ea374 100644 --- a/packages/web3-net/package.json +++ b/packages/web3-net/package.json @@ -2,7 +2,15 @@ "name": "web3-net", "version": "4.0.1-rc.0", "description": "Web3 module to interact with the Ethereum nodes networking properties.", - "main": "lib/index.js", + "main": "./lib/commonjs/index.js", + "module": "./lib/esm/index.js", + "exports": { + ".": { + "types": "./lib/types/index.d.ts", + "import": "./lib/esm/index.js", + "require": "./lib/commonjs/index.js" + } + }, "repository": "https://github.com/ChainSafe/web3.js", "author": "ChainSafe Systems", "license": "LGPL-3.0", @@ -16,7 +24,10 @@ "scripts": { "clean": "rimraf dist && rimraf lib", "prebuild": "yarn clean", - "build": "tsc --build", + "build": "yarn build:cjs & yarn build:esm & yarn build:types", + "build:cjs": "tsc --build tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > ./lib/commonjs/package.json", + "build:esm": "tsc --build tsconfig.esm.json && echo '{\"type\": \"module\"}' > ./lib/esm/package.json", + "build:types": "tsc --build tsconfig.types.json", "build:check": "node -e \"require('./lib')\"", "lint": "eslint --ext .js,.ts .", "lint:fix": "eslint --fix --ext .js,.ts .", diff --git a/packages/web3-net/test/tsconfig.json b/packages/web3-net/test/tsconfig.json index 7b7b1624905..831ffc02b5d 100644 --- a/packages/web3-net/test/tsconfig.json +++ b/packages/web3-net/test/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../tsconfig", + "extends": "../tsconfig.cjs.json", "compilerOptions": { "declaration": false, "declarationMap": false diff --git a/packages/web3-net/tsconfig.cjs.json b/packages/web3-net/tsconfig.cjs.json new file mode 100644 index 00000000000..a44e4adc15d --- /dev/null +++ b/packages/web3-net/tsconfig.cjs.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./lib/commonjs", + "declaration": true, + "module": "commonjs" + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-net/tsconfig.esm.json b/packages/web3-net/tsconfig.esm.json new file mode 100644 index 00000000000..5c975a932da --- /dev/null +++ b/packages/web3-net/tsconfig.esm.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./lib/esm", + "module": "es2020" + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-net/tsconfig.json b/packages/web3-net/tsconfig.json deleted file mode 100644 index fb299296e1f..00000000000 --- a/packages/web3-net/tsconfig.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "../../tsconfig", - "compilerOptions": { - "outDir": "lib" - }, - "include": ["src/**/*"] -} diff --git a/packages/web3-net/tsconfig.types.json b/packages/web3-net/tsconfig.types.json new file mode 100644 index 00000000000..4f71bd3a4ba --- /dev/null +++ b/packages/web3-net/tsconfig.types.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "declarationDir": "./lib/types", + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-providers-http/.eslintrc.js b/packages/web3-providers-http/.eslintrc.js index 8b7fd410b8d..12a507e5126 100644 --- a/packages/web3-providers-http/.eslintrc.js +++ b/packages/web3-providers-http/.eslintrc.js @@ -1,7 +1,7 @@ module.exports = { extends: '../../.eslintrc.js', parserOptions: { - project: './tsconfig.json', + project: './tsconfig.esm.json', tsconfigRootDir: __dirname, }, }; diff --git a/packages/web3-providers-http/CHANGELOG.md b/packages/web3-providers-http/CHANGELOG.md index e302ca090f0..3a7e9bb2d8b 100644 --- a/packages/web3-providers-http/CHANGELOG.md +++ b/packages/web3-providers-http/CHANGELOG.md @@ -66,3 +66,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added named export for `HttpProvider` (#5771) ## [Unreleased] + +### Added + +- Added hybrid build (ESM and CJS) of library (#5904) diff --git a/packages/web3-providers-http/package.json b/packages/web3-providers-http/package.json index 9c44e34d641..6fb2693ef3b 100644 --- a/packages/web3-providers-http/package.json +++ b/packages/web3-providers-http/package.json @@ -2,7 +2,15 @@ "name": "web3-providers-http", "version": "4.0.1-rc.0", "description": "HTTP provider for Web3 4.x.x", - "main": "lib/index.js", + "main": "./lib/commonjs/index.js", + "module": "./lib/esm/index.js", + "exports": { + ".": { + "types": "./lib/types/index.d.ts", + "import": "./lib/esm/index.js", + "require": "./lib/commonjs/index.js" + } + }, "repository": "https://github.com/ChainSafe/web3.js", "author": "ChainSafe Systems", "license": "LGPL-3.0", @@ -16,7 +24,10 @@ "scripts": { "clean": "rimraf dist && rimraf lib", "prebuild": "yarn clean", - "build": "tsc --build", + "build": "yarn build:cjs & yarn build:esm & yarn build:types", + "build:cjs": "tsc --build tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > ./lib/commonjs/package.json", + "build:esm": "tsc --build tsconfig.esm.json && echo '{\"type\": \"module\"}' > ./lib/esm/package.json", + "build:types": "tsc --build tsconfig.types.json", "build:check": "node -e \"require('./lib')\"", "lint": "eslint --ext .js,.ts .", "lint:fix": "eslint --fix --ext .js,.ts .", diff --git a/packages/web3-providers-http/tsconfig.cjs.json b/packages/web3-providers-http/tsconfig.cjs.json new file mode 100644 index 00000000000..675976cf375 --- /dev/null +++ b/packages/web3-providers-http/tsconfig.cjs.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./lib/commonjs", + "esModuleInterop": true, + "declaration": true, + "module": "commonjs" + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-providers-http/tsconfig.esm.json b/packages/web3-providers-http/tsconfig.esm.json new file mode 100644 index 00000000000..c8e53463a6e --- /dev/null +++ b/packages/web3-providers-http/tsconfig.esm.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./lib/esm", + "esModuleInterop": true, + "module": "es2020" + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-providers-http/tsconfig.json b/packages/web3-providers-http/tsconfig.json deleted file mode 120000 index 900bb05c680..00000000000 --- a/packages/web3-providers-http/tsconfig.json +++ /dev/null @@ -1 +0,0 @@ -../../templates/tsconfig.json.tmpl \ No newline at end of file diff --git a/packages/web3-providers-http/tsconfig.types.json b/packages/web3-providers-http/tsconfig.types.json new file mode 100644 index 00000000000..4f71bd3a4ba --- /dev/null +++ b/packages/web3-providers-http/tsconfig.types.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "declarationDir": "./lib/types", + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-providers-ipc/.eslintrc.js b/packages/web3-providers-ipc/.eslintrc.js index 8b7fd410b8d..12a507e5126 100644 --- a/packages/web3-providers-ipc/.eslintrc.js +++ b/packages/web3-providers-ipc/.eslintrc.js @@ -1,7 +1,7 @@ module.exports = { extends: '../../.eslintrc.js', parserOptions: { - project: './tsconfig.json', + project: './tsconfig.esm.json', tsconfigRootDir: __dirname, }, }; diff --git a/packages/web3-providers-ipc/CHANGELOG.md b/packages/web3-providers-ipc/CHANGELOG.md index e789c5d0013..7e1f132472e 100644 --- a/packages/web3-providers-ipc/CHANGELOG.md +++ b/packages/web3-providers-ipc/CHANGELOG.md @@ -76,3 +76,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - The getter of `SocketConnection` in `IpcProvider` (inherited from `SocketProvider`) returns `net.Socket` (#5891) ## [Unreleased] + +### Added + +- Added hybrid build (ESM and CJS) of library (#5904) diff --git a/packages/web3-providers-ipc/package.json b/packages/web3-providers-ipc/package.json index f7d6149b5e9..aa68bf6aedc 100644 --- a/packages/web3-providers-ipc/package.json +++ b/packages/web3-providers-ipc/package.json @@ -2,7 +2,15 @@ "name": "web3-providers-ipc", "version": "4.0.1-rc.0", "description": "IPC provider for Web3 4.x.x", - "main": "lib/index.js", + "main": "./lib/commonjs/index.js", + "module": "./lib/esm/index.js", + "exports": { + ".": { + "types": "./lib/types/index.d.ts", + "import": "./lib/esm/index.js", + "require": "./lib/commonjs/index.js" + } + }, "repository": "https://github.com/ChainSafe/web3.js", "author": "ChainSafe Systems", "license": "LGPL-3.0", @@ -16,7 +24,10 @@ "scripts": { "clean": "rimraf dist && rimraf lib", "prebuild": "yarn clean", - "build": "tsc --build", + "build": "yarn build:cjs & yarn build:esm & yarn build:types", + "build:cjs": "tsc --build tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > ./lib/commonjs/package.json", + "build:esm": "tsc --build tsconfig.esm.json && echo '{\"type\": \"module\"}' > ./lib/esm/package.json", + "build:types": "tsc --build tsconfig.types.json", "build:check": "node -e \"require('./lib')\"", "lint": "eslint --ext .js,.ts .", "lint:fix": "eslint --fix --ext .js,.ts .", diff --git a/packages/web3-providers-ipc/test/tsconfig.json b/packages/web3-providers-ipc/test/tsconfig.json index 7b7b1624905..831ffc02b5d 100644 --- a/packages/web3-providers-ipc/test/tsconfig.json +++ b/packages/web3-providers-ipc/test/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../tsconfig", + "extends": "../tsconfig.cjs.json", "compilerOptions": { "declaration": false, "declarationMap": false diff --git a/packages/web3-providers-ipc/tsconfig.cjs.json b/packages/web3-providers-ipc/tsconfig.cjs.json new file mode 100644 index 00000000000..a44e4adc15d --- /dev/null +++ b/packages/web3-providers-ipc/tsconfig.cjs.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./lib/commonjs", + "declaration": true, + "module": "commonjs" + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-providers-ipc/tsconfig.esm.json b/packages/web3-providers-ipc/tsconfig.esm.json new file mode 100644 index 00000000000..5c975a932da --- /dev/null +++ b/packages/web3-providers-ipc/tsconfig.esm.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./lib/esm", + "module": "es2020" + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-providers-ipc/tsconfig.json b/packages/web3-providers-ipc/tsconfig.json deleted file mode 100644 index fb299296e1f..00000000000 --- a/packages/web3-providers-ipc/tsconfig.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "../../tsconfig", - "compilerOptions": { - "outDir": "lib" - }, - "include": ["src/**/*"] -} diff --git a/packages/web3-providers-ipc/tsconfig.types.json b/packages/web3-providers-ipc/tsconfig.types.json new file mode 100644 index 00000000000..4f71bd3a4ba --- /dev/null +++ b/packages/web3-providers-ipc/tsconfig.types.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "declarationDir": "./lib/types", + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-providers-ws/.eslintrc.js b/packages/web3-providers-ws/.eslintrc.js index 8b7fd410b8d..12a507e5126 100644 --- a/packages/web3-providers-ws/.eslintrc.js +++ b/packages/web3-providers-ws/.eslintrc.js @@ -1,7 +1,7 @@ module.exports = { extends: '../../.eslintrc.js', parserOptions: { - project: './tsconfig.json', + project: './tsconfig.esm.json', tsconfigRootDir: __dirname, }, }; diff --git a/packages/web3-providers-ws/CHANGELOG.md b/packages/web3-providers-ws/CHANGELOG.md index d2fcd72285e..44f8223a07d 100644 --- a/packages/web3-providers-ws/CHANGELOG.md +++ b/packages/web3-providers-ws/CHANGELOG.md @@ -69,3 +69,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - The getter of `SocketConnection` in `WebSocketProvider` (inherited from `SocketProvider`) returns isomorphic `WebSocket` (#5891) ## [Unreleased] + +### Added + +- Added hybrid build (ESM and CJS) of library (#5904) diff --git a/packages/web3-providers-ws/package.json b/packages/web3-providers-ws/package.json index 5a90c8bed1b..ef529005c17 100644 --- a/packages/web3-providers-ws/package.json +++ b/packages/web3-providers-ws/package.json @@ -2,7 +2,15 @@ "name": "web3-providers-ws", "version": "4.0.1-rc.0", "description": "Websocket provider for Web3 4.x.x", - "main": "lib/index.js", + "main": "./lib/commonjs/index.js", + "module": "./lib/esm/index.js", + "exports": { + ".": { + "types": "./lib/types/index.d.ts", + "import": "./lib/esm/index.js", + "require": "./lib/commonjs/index.js" + } + }, "repository": "https://github.com/ChainSafe/web3.js", "author": "ChainSafe Systems", "license": "LGPL-3.0", @@ -16,7 +24,10 @@ "scripts": { "clean": "rimraf dist && rimraf lib", "prebuild": "yarn clean", - "build": "tsc --build", + "build": "yarn build:cjs & yarn build:esm & yarn build:types", + "build:cjs": "tsc --build tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > ./lib/commonjs/package.json", + "build:esm": "tsc --build tsconfig.esm.json && echo '{\"type\": \"module\"}' > ./lib/esm/package.json", + "build:types": "tsc --build tsconfig.types.json", "build:check": "node -e \"require('./lib')\"", "lint": "eslint --ext .js,.ts .", "lint:fix": "eslint --fix --ext .js,.ts .", diff --git a/packages/web3-providers-ws/tsconfig.cjs.json b/packages/web3-providers-ws/tsconfig.cjs.json new file mode 100644 index 00000000000..675976cf375 --- /dev/null +++ b/packages/web3-providers-ws/tsconfig.cjs.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./lib/commonjs", + "esModuleInterop": true, + "declaration": true, + "module": "commonjs" + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-providers-ws/tsconfig.esm.json b/packages/web3-providers-ws/tsconfig.esm.json new file mode 100644 index 00000000000..c8e53463a6e --- /dev/null +++ b/packages/web3-providers-ws/tsconfig.esm.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./lib/esm", + "esModuleInterop": true, + "module": "es2020" + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-providers-ws/tsconfig.json b/packages/web3-providers-ws/tsconfig.json deleted file mode 120000 index 900bb05c680..00000000000 --- a/packages/web3-providers-ws/tsconfig.json +++ /dev/null @@ -1 +0,0 @@ -../../templates/tsconfig.json.tmpl \ No newline at end of file diff --git a/packages/web3-providers-ws/tsconfig.types.json b/packages/web3-providers-ws/tsconfig.types.json new file mode 100644 index 00000000000..4f71bd3a4ba --- /dev/null +++ b/packages/web3-providers-ws/tsconfig.types.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "declarationDir": "./lib/types", + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-rpc-methods/.eslintrc.js b/packages/web3-rpc-methods/.eslintrc.js index 8b7fd410b8d..12a507e5126 100644 --- a/packages/web3-rpc-methods/.eslintrc.js +++ b/packages/web3-rpc-methods/.eslintrc.js @@ -1,7 +1,7 @@ module.exports = { extends: '../../.eslintrc.js', parserOptions: { - project: './tsconfig.json', + project: './tsconfig.esm.json', tsconfigRootDir: __dirname, }, }; diff --git a/packages/web3-rpc-methods/CHANGELOG.md b/packages/web3-rpc-methods/CHANGELOG.md index 069585d2004..d61a7b06d63 100644 --- a/packages/web3-rpc-methods/CHANGELOG.md +++ b/packages/web3-rpc-methods/CHANGELOG.md @@ -67,3 +67,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added support of `safe` and `finalized` block tags (#5823) ## [Unreleased] + +### Added + +- Added hybrid build (ESM and CJS) of library (#5904) diff --git a/packages/web3-rpc-methods/package.json b/packages/web3-rpc-methods/package.json index de4f79a2b78..d8bc9717240 100644 --- a/packages/web3-rpc-methods/package.json +++ b/packages/web3-rpc-methods/package.json @@ -2,7 +2,15 @@ "name": "web3-rpc-methods", "version": "1.0.0-rc.0", "description": "Ethereum RPC methods for Web3 4.x.x", - "main": "lib/index.js", + "main": "./lib/commonjs/index.js", + "module": "./lib/esm/index.js", + "exports": { + ".": { + "types": "./lib/types/index.d.ts", + "import": "./lib/esm/index.js", + "require": "./lib/commonjs/index.js" + } + }, "repository": "https://github.com/ChainSafe/web3.js", "author": "ChainSafe Systems", "license": "LGPL-3.0", @@ -16,7 +24,10 @@ "scripts": { "clean": "rimraf dist && rimraf lib", "prebuild": "yarn clean", - "build": "tsc --build", + "build": "yarn build:cjs & yarn build:esm & yarn build:types", + "build:cjs": "tsc --build tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > ./lib/commonjs/package.json", + "build:esm": "tsc --build tsconfig.esm.json && echo '{\"type\": \"module\"}' > ./lib/esm/package.json", + "build:types": "tsc --build tsconfig.types.json", "build:check": "node -e \"require('./lib')\"", "lint": "eslint --ext .js,.ts .", "lint:fix": "eslint --fix --ext .js,.ts .", diff --git a/packages/web3-rpc-methods/tsconfig.cjs.json b/packages/web3-rpc-methods/tsconfig.cjs.json new file mode 100644 index 00000000000..675976cf375 --- /dev/null +++ b/packages/web3-rpc-methods/tsconfig.cjs.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./lib/commonjs", + "esModuleInterop": true, + "declaration": true, + "module": "commonjs" + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-rpc-methods/tsconfig.esm.json b/packages/web3-rpc-methods/tsconfig.esm.json new file mode 100644 index 00000000000..c8e53463a6e --- /dev/null +++ b/packages/web3-rpc-methods/tsconfig.esm.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./lib/esm", + "esModuleInterop": true, + "module": "es2020" + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-rpc-methods/tsconfig.json b/packages/web3-rpc-methods/tsconfig.json deleted file mode 120000 index 900bb05c680..00000000000 --- a/packages/web3-rpc-methods/tsconfig.json +++ /dev/null @@ -1 +0,0 @@ -../../templates/tsconfig.json.tmpl \ No newline at end of file diff --git a/packages/web3-rpc-methods/tsconfig.types.json b/packages/web3-rpc-methods/tsconfig.types.json new file mode 100644 index 00000000000..4f71bd3a4ba --- /dev/null +++ b/packages/web3-rpc-methods/tsconfig.types.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "declarationDir": "./lib/types", + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-types/.eslintrc.js b/packages/web3-types/.eslintrc.js index 8b7fd410b8d..12a507e5126 100644 --- a/packages/web3-types/.eslintrc.js +++ b/packages/web3-types/.eslintrc.js @@ -1,7 +1,7 @@ module.exports = { extends: '../../.eslintrc.js', parserOptions: { - project: './tsconfig.json', + project: './tsconfig.esm.json', tsconfigRootDir: __dirname, }, }; diff --git a/packages/web3-types/CHANGELOG.md b/packages/web3-types/CHANGELOG.md index 675596642a1..6e7148d5fe8 100644 --- a/packages/web3-types/CHANGELOG.md +++ b/packages/web3-types/CHANGELOG.md @@ -80,6 +80,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Added hybrid build (ESM and CJS) of library (#5904) + ### Changed - `data` property in `TransactionOutput` was renamed to `input` (#5915) diff --git a/packages/web3-types/package.json b/packages/web3-types/package.json index 8507ab4c3eb..e2d3d5dc82a 100644 --- a/packages/web3-types/package.json +++ b/packages/web3-types/package.json @@ -2,7 +2,15 @@ "name": "web3-types", "version": "1.0.0-rc.0", "description": "Provide the common data structures and interfaces for web3 modules.", - "main": "lib/index.js", + "main": "./lib/commonjs/index.js", + "module": "./lib/esm/index.js", + "exports": { + ".": { + "types": "./lib/types/index.d.ts", + "import": "./lib/esm/index.js", + "require": "./lib/commonjs/index.js" + } + }, "repository": "https://github.com/ChainSafe/web3.js", "author": "ChainSafe Systems", "license": "LGPL-3.0", @@ -16,7 +24,10 @@ "scripts": { "clean": "rimraf dist && rimraf lib", "prebuild": "yarn clean", - "build": "tsc --build", + "build": "yarn build:cjs & yarn build:esm & yarn build:types", + "build:cjs": "tsc --build tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > ./lib/commonjs/package.json", + "build:esm": "tsc --build tsconfig.esm.json && echo '{\"type\": \"module\"}' > ./lib/esm/package.json", + "build:types": "tsc --build tsconfig.types.json", "build:check": "node -e \"require('./lib')\"", "lint": "eslint --ext .js,.ts .", "lint:fix": "eslint --fix --ext .js,.ts .", diff --git a/packages/web3-types/test/tsconfig.json b/packages/web3-types/test/tsconfig.json index 7b7b1624905..831ffc02b5d 100644 --- a/packages/web3-types/test/tsconfig.json +++ b/packages/web3-types/test/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../tsconfig", + "extends": "../tsconfig.cjs.json", "compilerOptions": { "declaration": false, "declarationMap": false diff --git a/packages/web3-types/tsconfig.cjs.json b/packages/web3-types/tsconfig.cjs.json new file mode 100644 index 00000000000..a44e4adc15d --- /dev/null +++ b/packages/web3-types/tsconfig.cjs.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./lib/commonjs", + "declaration": true, + "module": "commonjs" + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-types/tsconfig.esm.json b/packages/web3-types/tsconfig.esm.json new file mode 100644 index 00000000000..5c975a932da --- /dev/null +++ b/packages/web3-types/tsconfig.esm.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./lib/esm", + "module": "es2020" + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-types/tsconfig.json b/packages/web3-types/tsconfig.json deleted file mode 100644 index fb299296e1f..00000000000 --- a/packages/web3-types/tsconfig.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "../../tsconfig", - "compilerOptions": { - "outDir": "lib" - }, - "include": ["src/**/*"] -} diff --git a/packages/web3-types/tsconfig.types.json b/packages/web3-types/tsconfig.types.json new file mode 100644 index 00000000000..4f71bd3a4ba --- /dev/null +++ b/packages/web3-types/tsconfig.types.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "declarationDir": "./lib/types", + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-utils/.eslintrc.js b/packages/web3-utils/.eslintrc.js index 8b7fd410b8d..12a507e5126 100644 --- a/packages/web3-utils/.eslintrc.js +++ b/packages/web3-utils/.eslintrc.js @@ -1,7 +1,7 @@ module.exports = { extends: '../../.eslintrc.js', parserOptions: { - project: './tsconfig.json', + project: './tsconfig.esm.json', tsconfigRootDir: __dirname, }, }; diff --git a/packages/web3-utils/CHANGELOG.md b/packages/web3-utils/CHANGELOG.md index 00a86adef5f..1ea85963aa3 100644 --- a/packages/web3-utils/CHANGELOG.md +++ b/packages/web3-utils/CHANGELOG.md @@ -90,3 +90,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Exposes the getter of `SocketConnection` in `SocketProvider` (#5891) ## [Unreleased] + +### Added + +- Added hybrid build (ESM and CJS) of library (#5904) diff --git a/packages/web3-utils/package.json b/packages/web3-utils/package.json index 3c1a270af1e..001bde9fa4f 100644 --- a/packages/web3-utils/package.json +++ b/packages/web3-utils/package.json @@ -3,7 +3,15 @@ "sideEffects": false, "version": "4.0.1-rc.0", "description": "Collection of utility functions used in web3.js.", - "main": "lib/index.js", + "main": "./lib/commonjs/index.js", + "module": "./lib/esm/index.js", + "exports": { + ".": { + "types": "./lib/types/index.d.ts", + "import": "./lib/esm/index.js", + "require": "./lib/commonjs/index.js" + } + }, "repository": "https://github.com/ChainSafe/web3.js", "author": "ChainSafe Systems", "license": "LGPL-3.0", @@ -17,7 +25,10 @@ "scripts": { "clean": "rimraf dist && rimraf lib", "prebuild": "yarn clean", - "build": "tsc --build", + "build": "yarn build:cjs & yarn build:esm & yarn build:types", + "build:cjs": "tsc --build tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > ./lib/commonjs/package.json", + "build:esm": "tsc --build tsconfig.esm.json && echo '{\"type\": \"module\"}' > ./lib/esm/package.json", + "build:types": "tsc --build tsconfig.types.json", "build:check": "node -e \"require('./lib')\"", "lint": "eslint --ext .js,.ts .", "lint:fix": "eslint --fix --ext .js,.ts .", diff --git a/packages/web3-utils/test/tsconfig.json b/packages/web3-utils/test/tsconfig.json index 7b7b1624905..831ffc02b5d 100644 --- a/packages/web3-utils/test/tsconfig.json +++ b/packages/web3-utils/test/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../tsconfig", + "extends": "../tsconfig.cjs.json", "compilerOptions": { "declaration": false, "declarationMap": false diff --git a/packages/web3-utils/tsconfig.cjs.json b/packages/web3-utils/tsconfig.cjs.json new file mode 100644 index 00000000000..a44e4adc15d --- /dev/null +++ b/packages/web3-utils/tsconfig.cjs.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./lib/commonjs", + "declaration": true, + "module": "commonjs" + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-utils/tsconfig.esm.json b/packages/web3-utils/tsconfig.esm.json new file mode 100644 index 00000000000..5c975a932da --- /dev/null +++ b/packages/web3-utils/tsconfig.esm.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./lib/esm", + "module": "es2020" + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-utils/tsconfig.json b/packages/web3-utils/tsconfig.json deleted file mode 100644 index fb299296e1f..00000000000 --- a/packages/web3-utils/tsconfig.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "../../tsconfig", - "compilerOptions": { - "outDir": "lib" - }, - "include": ["src/**/*"] -} diff --git a/packages/web3-utils/tsconfig.types.json b/packages/web3-utils/tsconfig.types.json new file mode 100644 index 00000000000..4f71bd3a4ba --- /dev/null +++ b/packages/web3-utils/tsconfig.types.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "declarationDir": "./lib/types", + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-validator/.eslintrc.js b/packages/web3-validator/.eslintrc.js index 8b7fd410b8d..12a507e5126 100644 --- a/packages/web3-validator/.eslintrc.js +++ b/packages/web3-validator/.eslintrc.js @@ -1,7 +1,7 @@ module.exports = { extends: '../../.eslintrc.js', parserOptions: { - project: './tsconfig.json', + project: './tsconfig.esm.json', tsconfigRootDir: __dirname, }, }; diff --git a/packages/web3-validator/CHANGELOG.md b/packages/web3-validator/CHANGELOG.md index 9a9f2153edc..345339f53b7 100644 --- a/packages/web3-validator/CHANGELOG.md +++ b/packages/web3-validator/CHANGELOG.md @@ -80,3 +80,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added support of `safe` and `finalized` block tags in `isBlockTag` method (#5823) ## [Unreleased] + +### Added + +- Added hybrid build (ESM and CJS) of library (#5904) diff --git a/packages/web3-validator/package.json b/packages/web3-validator/package.json index 71a43ff79c8..d923a23d055 100644 --- a/packages/web3-validator/package.json +++ b/packages/web3-validator/package.json @@ -2,7 +2,15 @@ "name": "web3-validator", "version": "1.0.0-rc.0", "description": "JSON-Schema compatible validator for web3", - "main": "lib/index.js", + "main": "./lib/commonjs/index.js", + "module": "./lib/esm/index.js", + "exports": { + ".": { + "types": "./lib/types/index.d.ts", + "import": "./lib/esm/index.js", + "require": "./lib/commonjs/index.js" + } + }, "repository": "https://github.com/ChainSafe/web3.js", "author": "ChainSafe Systems", "license": "LGPL-3.0", @@ -17,7 +25,10 @@ "scripts": { "clean": "rimraf dist && rimraf lib", "prebuild": "yarn clean", - "build": "tsc --build", + "build": "yarn build:cjs & yarn build:esm & yarn build:types", + "build:cjs": "tsc --build tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > ./lib/commonjs/package.json", + "build:esm": "tsc --build tsconfig.esm.json && echo '{\"type\": \"module\"}' > ./lib/esm/package.json", + "build:types": "tsc --build tsconfig.types.json", "build:web": "npx webpack", "build:check": "node -e \"require('./lib')\"", "lint": "eslint --ext .js,.ts .", diff --git a/packages/web3-validator/test/tsconfig.json b/packages/web3-validator/test/tsconfig.json index 7b7b1624905..831ffc02b5d 100644 --- a/packages/web3-validator/test/tsconfig.json +++ b/packages/web3-validator/test/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../tsconfig", + "extends": "../tsconfig.cjs.json", "compilerOptions": { "declaration": false, "declarationMap": false diff --git a/packages/web3-validator/tsconfig.cjs.json b/packages/web3-validator/tsconfig.cjs.json new file mode 100644 index 00000000000..a44e4adc15d --- /dev/null +++ b/packages/web3-validator/tsconfig.cjs.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./lib/commonjs", + "declaration": true, + "module": "commonjs" + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-validator/tsconfig.esm.json b/packages/web3-validator/tsconfig.esm.json new file mode 100644 index 00000000000..5c975a932da --- /dev/null +++ b/packages/web3-validator/tsconfig.esm.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./lib/esm", + "module": "es2020" + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-validator/tsconfig.json b/packages/web3-validator/tsconfig.json deleted file mode 100644 index fb299296e1f..00000000000 --- a/packages/web3-validator/tsconfig.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "../../tsconfig", - "compilerOptions": { - "outDir": "lib" - }, - "include": ["src/**/*"] -} diff --git a/packages/web3-validator/tsconfig.types.json b/packages/web3-validator/tsconfig.types.json new file mode 100644 index 00000000000..4f71bd3a4ba --- /dev/null +++ b/packages/web3-validator/tsconfig.types.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "declarationDir": "./lib/types", + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true + }, + "include": ["src/**/*"] +} diff --git a/packages/web3-validator/webpack.config.js b/packages/web3-validator/webpack.config.js index 391d083b5dd..59864af0ee2 100644 --- a/packages/web3-validator/webpack.config.js +++ b/packages/web3-validator/webpack.config.js @@ -22,4 +22,5 @@ module.exports = getWebPackConfig( 'web3-validator.min.js', 'web3-validator', 'src/index.ts', + 'tsconfig.cjs.json', ); diff --git a/packages/web3/.eslintrc.js b/packages/web3/.eslintrc.js index 8b7fd410b8d..12a507e5126 100644 --- a/packages/web3/.eslintrc.js +++ b/packages/web3/.eslintrc.js @@ -1,7 +1,7 @@ module.exports = { extends: '../../.eslintrc.js', parserOptions: { - project: './tsconfig.json', + project: './tsconfig.esm.json', tsconfigRootDir: __dirname, }, }; diff --git a/packages/web3/CHANGELOG.md b/packages/web3/CHANGELOG.md index ba3ce5944bf..7737dca85be 100644 --- a/packages/web3/CHANGELOG.md +++ b/packages/web3/CHANGELOG.md @@ -84,3 +84,7 @@ web3.currentProvider.disconnect(); - Private static `_contracts:Contract[]` and static `setProvider` function was removed (#5792) ## [Unreleased] + +### Added + +- Added hybrid build (ESM and CJS) of library (#5904) diff --git a/packages/web3/package.json b/packages/web3/package.json index 2e115d0c812..ae942501244 100644 --- a/packages/web3/package.json +++ b/packages/web3/package.json @@ -2,7 +2,15 @@ "name": "web3", "version": "4.0.1-rc.0", "description": "Ethereum JavaScript API", - "main": "lib/index.js", + "main": "./lib/commonjs/index.js", + "module": "./lib/esm/index.js", + "exports": { + ".": { + "types": "./lib/types/index.d.ts", + "import": "./lib/esm/index.js", + "require": "./lib/commonjs/index.js" + } + }, "repository": "https://github.com/ChainSafe/web3.js", "engines": { "node": ">=14.0.0", @@ -22,8 +30,11 @@ "scripts": { "clean": "rimraf dist && rimraf lib", "prebuild": "yarn clean", - "build": "yarn version:output && tsc --build", "version:output": "[ -z $npm_package_version ] && rm ./src/version.ts || echo \"/* eslint-disable header/header */ export const Web3PkgInfo = { version: '$npm_package_version' };\" > ./src/version.ts", + "build": "yarn version:output && yarn build:cjs & yarn build:esm & yarn build:types", + "build:cjs": "tsc --build tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > ./lib/commonjs/package.json", + "build:esm": "tsc --build tsconfig.esm.json && echo '{\"type\": \"module\"}' > ./lib/esm/package.json", + "build:types": "tsc --build tsconfig.types.json", "build:web": "npx webpack", "build:web:analyze": "npx webpack --config ./webpack.analyze.js", "build:check": "node -e \"require('./lib')\"", diff --git a/packages/web3/test/tsconfig.json b/packages/web3/test/tsconfig.json index 7b7b1624905..831ffc02b5d 100644 --- a/packages/web3/test/tsconfig.json +++ b/packages/web3/test/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../tsconfig", + "extends": "../tsconfig.cjs.json", "compilerOptions": { "declaration": false, "declarationMap": false diff --git a/packages/web3/tsconfig.cjs.json b/packages/web3/tsconfig.cjs.json new file mode 100644 index 00000000000..675976cf375 --- /dev/null +++ b/packages/web3/tsconfig.cjs.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./lib/commonjs", + "esModuleInterop": true, + "declaration": true, + "module": "commonjs" + }, + "include": ["src/**/*"] +} diff --git a/packages/web3/tsconfig.esm.json b/packages/web3/tsconfig.esm.json new file mode 100644 index 00000000000..c8e53463a6e --- /dev/null +++ b/packages/web3/tsconfig.esm.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./lib/esm", + "esModuleInterop": true, + "module": "es2020" + }, + "include": ["src/**/*"] +} diff --git a/packages/web3/tsconfig.json b/packages/web3/tsconfig.json deleted file mode 100644 index 7af3885edd9..00000000000 --- a/packages/web3/tsconfig.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "extends": "../../tsconfig", - "compilerOptions": { - "outDir": "lib", - "esModuleInterop": true - }, - "include": ["src/**/*"] -} diff --git a/packages/web3/tsconfig.types.json b/packages/web3/tsconfig.types.json new file mode 100644 index 00000000000..4f71bd3a4ba --- /dev/null +++ b/packages/web3/tsconfig.types.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "declarationDir": "./lib/types", + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true + }, + "include": ["src/**/*"] +} diff --git a/packages/web3/webpack.analyze.js b/packages/web3/webpack.analyze.js index bcf6bdd5910..24d91808c6f 100644 --- a/packages/web3/webpack.analyze.js +++ b/packages/web3/webpack.analyze.js @@ -17,7 +17,13 @@ along with web3.js. If not, see . const { getWebPackConfig } = require('../../webpack.base.config'); -const config = getWebPackConfig(__dirname, 'web3.min.js', 'Web3', 'src/web3.ts'); +const config = getWebPackConfig( + __dirname, + 'web3.min.js', + 'Web3', + 'src/web3.ts', + 'tsconfig.cjs.json', +); const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer'); module.exports = { diff --git a/packages/web3/webpack.config.js b/packages/web3/webpack.config.js index b6304def921..b2b1ae8050b 100644 --- a/packages/web3/webpack.config.js +++ b/packages/web3/webpack.config.js @@ -17,4 +17,10 @@ along with web3.js. If not, see . const { getWebPackConfig } = require('../../webpack.base.config'); -module.exports = getWebPackConfig(__dirname, 'web3.min.js', 'Web3', 'src/web3.ts'); +module.exports = getWebPackConfig( + __dirname, + 'web3.min.js', + 'Web3', + 'src/web3.ts', + 'tsconfig.cjs.json', +); diff --git a/scripts/changelog/tsconfig.json b/scripts/changelog/tsconfig.json new file mode 100644 index 00000000000..205930ac6db --- /dev/null +++ b/scripts/changelog/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "esModuleInterop": true, + "module": "commonjs", + "declaration": false, + "declarationMap": false + }, + "include": ["src/**/*"] +} diff --git a/scripts/jest.config.js b/scripts/jest.config.js index 2bdf6529d4c..a4f84339593 100644 --- a/scripts/jest.config.js +++ b/scripts/jest.config.js @@ -17,4 +17,9 @@ along with web3.js. If not, see . module.exports = { preset: 'ts-jest', testEnvironment: 'node', + globals: { + 'ts-jest': { + tsconfig: './scripts/changelog/tsconfig.json', + }, + }, }; diff --git a/templates/test/tsconfig.json.tmpl b/templates/test/tsconfig.json.tmpl index 7b7b1624905..831ffc02b5d 100644 --- a/templates/test/tsconfig.json.tmpl +++ b/templates/test/tsconfig.json.tmpl @@ -1,5 +1,5 @@ { - "extends": "../tsconfig", + "extends": "../tsconfig.cjs.json", "compilerOptions": { "declaration": false, "declarationMap": false diff --git a/tools/web3-packagetemplate/.eslintrc.js b/tools/web3-packagetemplate/.eslintrc.js index 8b7fd410b8d..12a507e5126 100644 --- a/tools/web3-packagetemplate/.eslintrc.js +++ b/tools/web3-packagetemplate/.eslintrc.js @@ -1,7 +1,7 @@ module.exports = { extends: '../../.eslintrc.js', parserOptions: { - project: './tsconfig.json', + project: './tsconfig.esm.json', tsconfigRootDir: __dirname, }, }; diff --git a/tools/web3-packagetemplate/CHANGELOG.md b/tools/web3-packagetemplate/CHANGELOG.md index 87f56484e8e..5d4061ac678 100644 --- a/tools/web3-packagetemplate/CHANGELOG.md +++ b/tools/web3-packagetemplate/CHANGELOG.md @@ -36,3 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 --> ## [Unreleased] + +### Added + +- Added hybrid build (ESM and CJS) of library (#5904) diff --git a/tools/web3-packagetemplate/package.json b/tools/web3-packagetemplate/package.json index 3de9fc0c5dc..db13479a13a 100644 --- a/tools/web3-packagetemplate/package.json +++ b/tools/web3-packagetemplate/package.json @@ -16,7 +16,10 @@ "scripts": { "clean": "rimraf dist && rimraf lib", "prebuild": "yarn clean", - "build": "tsc --build", + "build": "yarn build:cjs & yarn build:esm & yarn build:types", + "build:cjs": "tsc --build tsconfig.cjs.json", + "build:esm": "tsc --build tsconfig.esm.json", + "build:types": "tsc --build tsconfig.types.json", "build:check": "node -e \"require('./lib')\"", "lint": "eslint --ext .js,.ts .", "lint:fix": "eslint --fix --ext .js,.ts .", diff --git a/tools/web3-packagetemplate/tsconfig.cjs.json b/tools/web3-packagetemplate/tsconfig.cjs.json new file mode 100644 index 00000000000..675976cf375 --- /dev/null +++ b/tools/web3-packagetemplate/tsconfig.cjs.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./lib/commonjs", + "esModuleInterop": true, + "declaration": true, + "module": "commonjs" + }, + "include": ["src/**/*"] +} diff --git a/tools/web3-packagetemplate/tsconfig.esm.json b/tools/web3-packagetemplate/tsconfig.esm.json new file mode 100644 index 00000000000..c8e53463a6e --- /dev/null +++ b/tools/web3-packagetemplate/tsconfig.esm.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./lib/esm", + "esModuleInterop": true, + "module": "es2020" + }, + "include": ["src/**/*"] +} diff --git a/tools/web3-packagetemplate/tsconfig.json b/tools/web3-packagetemplate/tsconfig.json deleted file mode 120000 index 900bb05c680..00000000000 --- a/tools/web3-packagetemplate/tsconfig.json +++ /dev/null @@ -1 +0,0 @@ -../../templates/tsconfig.json.tmpl \ No newline at end of file diff --git a/tools/web3-packagetemplate/tsconfig.types.json b/tools/web3-packagetemplate/tsconfig.types.json new file mode 100644 index 00000000000..4f71bd3a4ba --- /dev/null +++ b/tools/web3-packagetemplate/tsconfig.types.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "declarationDir": "./lib/types", + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true + }, + "include": ["src/**/*"] +} diff --git a/tools/web3-plugin-example/tsconfig.json b/tools/web3-plugin-example/tsconfig.json index 7af3885edd9..d0a348ec5ad 100644 --- a/tools/web3-plugin-example/tsconfig.json +++ b/tools/web3-plugin-example/tsconfig.json @@ -1,8 +1,11 @@ { - "extends": "../../tsconfig", + "extends": "../../tsconfig.base.json", "compilerOptions": { "outDir": "lib", - "esModuleInterop": true + "esModuleInterop": true, + "module": "commonjs", + "declaration": true, + "declarationMap": true }, "include": ["src/**/*"] } diff --git a/tsconfig.json b/tsconfig.base.json similarity index 80% rename from tsconfig.json rename to tsconfig.base.json index e3559535a51..acdac558e23 100644 --- a/tsconfig.json +++ b/tsconfig.base.json @@ -3,8 +3,6 @@ "resolveJsonModule": true, "forceConsistentCasingInFileNames": true, "target": "es2016", - "module": "commonjs", - "declaration": true, "moduleResolution": "node", "newLine": "lf", "noFallthroughCasesInSwitch": true, @@ -14,9 +12,9 @@ "pretty": true, "removeComments": true, "sourceMap": true, - "declarationMap": true, "strict": true, "strictNullChecks": true, - "esModuleInterop": true + "esModuleInterop": true, + "allowSyntheticDefaultImports": true } } diff --git a/webpack.base.config.js b/webpack.base.config.js index df69ed6d616..a18a2abae24 100644 --- a/webpack.base.config.js +++ b/webpack.base.config.js @@ -21,7 +21,7 @@ const path = require('path'); /** * Shared webpack configuration for all packages */ -function getWebPackConfig(packagePath, filename, library, entry) { +function getWebPackConfig(packagePath, filename, library, entry, tsconf) { return { mode: 'production', entry: path.resolve(packagePath, entry), @@ -39,6 +39,9 @@ function getWebPackConfig(packagePath, filename, library, entry) { { test: /\.ts$/, loader: 'ts-loader', + options: { + configFile: path.resolve(packagePath, tsconf), + }, exclude: ['/node_modules/', '/test/'], }, ],