Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support ESM builds #6131

Merged
merged 18 commits into from
May 31, 2023
5 changes: 5 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ module.exports = {
sourceType: 'module',
},
extends: ['web3-base/ts'],
settings: {
'import/resolver': {
typescript: {}, // this loads tsconfig.json to eslint
},
},
};
20 changes: 18 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ jobs:
with:
name: web3-${{ matrix.node }}.js.tar.gz
path: /tmp/web3-${{ matrix.node }}.js.tar.gz
build-esm-types:
name: Build ESM & Types
build-esm:
name: Build ESM
needs: build
runs-on: ubuntu-latest
strategy:
Expand All @@ -48,6 +48,22 @@ jobs:
path: /tmp
- run: tar -xf /tmp/web3-${{ matrix.node }}.js.tar.gz -C ./
- run: yarn build:esm
build-types:
name: Build Types
needs: build
runs-on: ubuntu-latest
strategy:
matrix:
node: [ 18, 16 ]
steps:
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- uses: actions/download-artifact@v3
with:
name: web3-${{ matrix.node }}.js.tar.gz
path: /tmp
- run: tar -xf /tmp/web3-${{ matrix.node }}.js.tar.gz -C ./
- run: yarn build:types
lint:
name: Lint
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1488,6 +1488,7 @@ should use 4.0.1-alpha.0 for testing.
#### web3-eth-accounts

- Fixed ESM import bugs reported in (#6032) and (#6034)
- ESM projects will not need to run --experimental-specifier-resolution=node (#6127)

### Changed

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
"cypress-jest-adapter": "^0.1.1",
"declaration-bundler-webpack-plugin": "^1.0.3",
"eslint": "^8.20.0",
"eslint-import-resolver-typescript": "^3.5.5",
"http-browserify": "^1.7.0",
"https-browserify": "^1.0.0",
"husky": "^8.0.1",
Expand Down
24 changes: 12 additions & 12 deletions packages/web3-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/

export * from './web3_config';
export * from './web3_request_manager';
export * from './web3_subscription_manager';
export * from './web3_subscriptions';
export * from './web3_context';
export * from './web3_batch_request';
export * from './utils';
export * from './types';
export * from './formatters';
export * from './web3_promi_event';
export * from './web3_event_emitter';
export * from './web3_config.js';
Copy link
Contributor

@jdevcs jdevcs May 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @luu-alex , could you run blackbox tests on this branch ( locally or in github ) for looking blackbox is also passing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 https://github.com/web3/web3.js/actions/runs/5134874349/jobs/9239775016 all other ci tests were run in a previous commit and it passed

export * from './web3_request_manager.js';
export * from './web3_subscription_manager.js';
export * from './web3_subscriptions.js';
export * from './web3_context.js';
export * from './web3_batch_request.js';
export * from './utils.js';
export * from './types.js';
export * from './formatters.js';
export * from './web3_promi_event.js';
export * from './web3_event_emitter.js';

// For backward usability export as namespace
export * as formatters from './formatters';
export * as formatters from './formatters.js';
2 changes: 1 addition & 1 deletion packages/web3-core/src/web3_batch_request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
import { JsonRpcBatchResponse, JsonRpcOptionalRequest, JsonRpcRequest } from 'web3-types';
import { jsonRpc, Web3DeferredPromise } from 'web3-utils';
import { OperationAbortError, OperationTimeoutError, ResponseError } from 'web3-errors';
import { Web3RequestManager } from './web3_request_manager';
import { Web3RequestManager } from './web3_request_manager.js';

export const DEFAULT_BATCH_REQUEST_TIMEOUT = 1000;

Expand Down
6 changes: 3 additions & 3 deletions packages/web3-core/src/web3_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
import { Numbers, HexString, BlockNumberOrTag, Common } from 'web3-types';
import { ConfigHardforkMismatchError, ConfigChainMismatchError } from 'web3-errors';
import { isNullish, toHex } from 'web3-utils';
import { TransactionTypeParser } from './types';
import { TransactionTypeParser } from './types.js';
// eslint-disable-next-line import/no-cycle
import { TransactionBuilder } from './web3_context';
import { Web3EventEmitter } from './web3_event_emitter';
import { TransactionBuilder } from './web3_context.js';
import { Web3EventEmitter } from './web3_event_emitter.js';

// To avoid cycle dependency declare this
export interface Web3ConfigOptions {
Expand Down
12 changes: 6 additions & 6 deletions packages/web3-core/src/web3_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ import {
import { isNullish } from 'web3-utils';
import { ExistingPluginNamespaceError } from 'web3-errors';

import { isSupportedProvider } from './utils';
import { isSupportedProvider } from './utils.js';
// eslint-disable-next-line import/no-cycle
import { Web3Config, Web3ConfigEvent, Web3ConfigOptions } from './web3_config';
import { Web3RequestManager } from './web3_request_manager';
import { Web3SubscriptionConstructor } from './web3_subscriptions';
import { Web3SubscriptionManager } from './web3_subscription_manager';
import { Web3BatchRequest } from './web3_batch_request';
import { Web3Config, Web3ConfigEvent, Web3ConfigOptions } from './web3_config.js';
import { Web3RequestManager } from './web3_request_manager.js';
import { Web3SubscriptionConstructor } from './web3_subscriptions.js';
import { Web3SubscriptionManager } from './web3_subscription_manager.js';
import { Web3BatchRequest } from './web3_batch_request.js';

// To avoid circular dependencies, we need to export type from here.
export type Web3ContextObject<
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-core/src/web3_promi_event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
Web3EventEmitter,
Web3EventKey,
Web3EventMap,
} from './web3_event_emitter';
} from './web3_event_emitter.js';

export type PromiseExecutor<T> = (
resolve: (data: T) => void,
Expand Down
4 changes: 2 additions & 2 deletions packages/web3-core/src/web3_request_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ import {
isLegacySendAsyncProvider,
isLegacySendProvider,
isWeb3Provider,
} from './utils';
import { Web3EventEmitter } from './web3_event_emitter';
} from './utils.js';
import { Web3EventEmitter } from './web3_event_emitter.js';

export enum Web3RequestManagerEvent {
PROVIDER_CHANGED = 'PROVIDER_CHANGED',
Expand Down
6 changes: 3 additions & 3 deletions packages/web3-core/src/web3_subscription_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
import { DataFormat, DEFAULT_RETURN_FORMAT, Web3APISpec } from 'web3-types';
import { ProviderError, SubscriptionError } from 'web3-errors';
import { isNullish } from 'web3-utils';
import { isSupportSubscriptions } from './utils';
import { Web3RequestManager, Web3RequestManagerEvent } from './web3_request_manager';
import { Web3SubscriptionConstructor } from './web3_subscriptions';
import { isSupportSubscriptions } from './utils.js';
import { Web3RequestManager, Web3RequestManagerEvent } from './web3_request_manager.js';
import { Web3SubscriptionConstructor } from './web3_subscriptions.js';

type ShouldUnsubscribeCondition = ({
id,
Expand Down
4 changes: 2 additions & 2 deletions packages/web3-core/src/web3_subscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ import {
EIP1193Provider,
} from 'web3-types';
import { jsonRpc } from 'web3-utils';
import { Web3EventEmitter, Web3EventMap } from './web3_event_emitter';
import { Web3EventEmitter, Web3EventMap } from './web3_event_emitter.js';

import { Web3RequestManager } from './web3_request_manager';
import { Web3RequestManager } from './web3_request_manager.js';

export abstract class Web3Subscription<
EventMap extends Web3EventMap,
Expand Down
3 changes: 3 additions & 0 deletions packages/web3-core/test/config/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ module.exports = {
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
},
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
verbose: false,
collectCoverage: false,
coverageReporters: ['json'],
Expand Down
4 changes: 2 additions & 2 deletions packages/web3-errors/src/errors/account_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import {
ERR_INVALID_PASSWORD,
ERR_IV_LENGTH,
ERR_PBKDF2_ITERATIONS,
} from '../error_codes';
import { BaseWeb3Error } from '../web3_error_base';
} from '../error_codes.js';
import { BaseWeb3Error } from '../web3_error_base.js';

export class PrivateKeyLengthError extends BaseWeb3Error {
public code = ERR_PRIVATE_KEY_LENGTH;
Expand Down
4 changes: 2 additions & 2 deletions packages/web3-errors/src/errors/connection_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import {
ERR_CONN_MAX_ATTEMPTS,
ERR_CONN_PENDING_REQUESTS,
ERR_REQ_ALREADY_SENT,
} from '../error_codes';
import { BaseWeb3Error } from '../web3_error_base';
} from '../error_codes.js';
import { BaseWeb3Error } from '../web3_error_base.js';

export class ConnectionError extends BaseWeb3Error {
public code = ERR_CONN;
Expand Down
4 changes: 2 additions & 2 deletions packages/web3-errors/src/errors/contract_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import {
ERR_CONTRACT_RESERVED_EVENT,
ERR_CONTRACT_RESOLVER_MISSING,
ERR_CONTRACT_TX_DATA_AND_INPUT,
} from '../error_codes';
import { BaseWeb3Error, InvalidValueError } from '../web3_error_base';
} from '../error_codes.js';
import { BaseWeb3Error, InvalidValueError } from '../web3_error_base.js';

export class Web3ContractError extends BaseWeb3Error {
public code = ERR_CONTRACT;
Expand Down
4 changes: 2 additions & 2 deletions packages/web3-errors/src/errors/core_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.

/* eslint-disable max-classes-per-file */

import { BaseWeb3Error } from '../web3_error_base';
import { ERR_CORE_HARDFORK_MISMATCH } from '../error_codes';
import { BaseWeb3Error } from '../web3_error_base.js';
import { ERR_CORE_HARDFORK_MISMATCH } from '../error_codes.js';

export class ConfigHardforkMismatchError extends BaseWeb3Error {
public code = ERR_CORE_HARDFORK_MISMATCH;
Expand Down
4 changes: 2 additions & 2 deletions packages/web3-errors/src/errors/ens_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import {
ERR_ENS_CHECK_INTERFACE_SUPPORT,
ERR_ENS_NETWORK_NOT_SYNCED,
ERR_ENS_UNSUPPORTED_NETWORK,
} from '../error_codes';
import { BaseWeb3Error } from '../web3_error_base';
} from '../error_codes.js';
import { BaseWeb3Error } from '../web3_error_base.js';

export class ENSCheckInterfaceSupportError extends BaseWeb3Error {
public code = ERR_ENS_CHECK_INTERFACE_SUPPORT;
Expand Down
4 changes: 2 additions & 2 deletions packages/web3-errors/src/errors/generic_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import {
ERR_PARAM,
ERR_EXISTING_PLUGIN_NAMESPACE,
ERR_INVALID_METHOD_PARAMS,
} from '../error_codes';
import { BaseWeb3Error } from '../web3_error_base';
} from '../error_codes.js';
import { BaseWeb3Error } from '../web3_error_base.js';

export class InvalidNumberOfParamsError extends BaseWeb3Error {
public code = ERR_PARAM;
Expand Down
4 changes: 2 additions & 2 deletions packages/web3-errors/src/errors/provider_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import {
ERR_INVALID_CLIENT,
ERR_SUBSCRIPTION,
ERR_WS_PROVIDER,
} from '../error_codes';
import { BaseWeb3Error } from '../web3_error_base';
} from '../error_codes.js';
import { BaseWeb3Error } from '../web3_error_base.js';

export class ProviderError extends BaseWeb3Error {
public code = ERR_PROVIDER;
Expand Down
4 changes: 2 additions & 2 deletions packages/web3-errors/src/errors/response_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import {
JsonRpcResponse,
JsonRpcResponseWithError,
} from 'web3-types';
import { BaseWeb3Error } from '../web3_error_base';
import { ERR_INVALID_RESPONSE, ERR_RESPONSE } from '../error_codes';
import { BaseWeb3Error } from '../web3_error_base.js';
import { ERR_INVALID_RESPONSE, ERR_RESPONSE } from '../error_codes.js';

// To avoid circular package dependency, copied to code here. If you update this please update same function in `json_rpc.ts`
const isResponseWithError = <Error = unknown, Result = unknown>(
Expand Down
4 changes: 2 additions & 2 deletions packages/web3-errors/src/errors/rpc_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
/* eslint-disable max-classes-per-file */

import { JsonRpcResponseWithError, JsonRpcId, JsonRpcError } from 'web3-types';
import { BaseWeb3Error } from '../web3_error_base';
import { BaseWeb3Error } from '../web3_error_base.js';
import {
ERR_RPC_INTERNAL_ERROR,
ERR_RPC_INVALID_INPUT,
Expand All @@ -32,7 +32,7 @@ import {
ERR_RPC_TRANSACTION_REJECTED,
ERR_RPC_UNAVAILABLE_RESOURCE,
ERR_RPC_UNSUPPORTED_METHOD,
} from '../error_codes';
} from '../error_codes.js';

export class RpcError extends BaseWeb3Error {
public code: number;
Expand Down
4 changes: 2 additions & 2 deletions packages/web3-errors/src/errors/signature_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/

import { ERR_SIGNATURE_FAILED } from '../error_codes';
import { InvalidValueError } from '../web3_error_base';
import { ERR_SIGNATURE_FAILED } from '../error_codes.js';
import { InvalidValueError } from '../web3_error_base.js';

export class SignatureError extends InvalidValueError {
public code = ERR_SIGNATURE_FAILED;
Expand Down
4 changes: 2 additions & 2 deletions packages/web3-errors/src/errors/transaction_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ import {
ERR_TX_UNSUPPORTED_TYPE,
ERR_TX_REVERT_TRANSACTION_CUSTOM_ERROR,
ERR_TX_INVALID_PROPERTIES_FOR_TYPE,
} from '../error_codes';
import { InvalidValueError, BaseWeb3Error } from '../web3_error_base';
} from '../error_codes.js';
import { InvalidValueError, BaseWeb3Error } from '../web3_error_base.js';

export class TransactionError<ReceiptType = TransactionReceipt> extends BaseWeb3Error {
public code = ERR_TX;
Expand Down
4 changes: 2 additions & 2 deletions packages/web3-errors/src/errors/utils_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import {
ERR_INVALID_TYPE_ABI,
ERR_INVALID_UNIT,
ERR_INVALID_UNSIGNED_INTEGER,
} from '../error_codes';
import { InvalidValueError } from '../web3_error_base';
} from '../error_codes.js';
import { InvalidValueError } from '../web3_error_base.js';

export class InvalidBytesError extends InvalidValueError {
public code = ERR_INVALID_BYTES;
Expand Down
28 changes: 14 additions & 14 deletions packages/web3-errors/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/

export * from './error_codes';
export * from './web3_error_base';
export * from './errors/account_errors';
export * from './errors/connection_errors';
export * from './errors/contract_errors';
export * from './errors/ens_errors';
export * from './errors/generic_errors';
export * from './errors/provider_errors';
export * from './errors/signature_errors';
export * from './errors/transaction_errors';
export * from './errors/utils_errors';
export * from './errors/response_errors';
export * from './errors/core_errors';
export * from './errors/rpc_errors';
export * from './error_codes.js';
export * from './web3_error_base.js';
export * from './errors/account_errors.js';
export * from './errors/connection_errors.js';
export * from './errors/contract_errors.js';
export * from './errors/ens_errors.js';
export * from './errors/generic_errors.js';
export * from './errors/provider_errors.js';
export * from './errors/signature_errors.js';
export * from './errors/transaction_errors.js';
export * from './errors/utils_errors.js';
export * from './errors/response_errors.js';
export * from './errors/core_errors.js';
export * from './errors/rpc_errors.js';
2 changes: 1 addition & 1 deletion packages/web3-eth-abi/src/api/errors_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
import { sha3Raw } from 'web3-utils';
import { AbiError } from 'web3-errors';
import { AbiErrorFragment } from 'web3-types';
import { jsonInterfaceMethodToString, isAbiErrorFragment } from '../utils';
import { jsonInterfaceMethodToString, isAbiErrorFragment } from '../utils.js';

/**
* Encodes the error name to its ABI signature, which are the sha3 hash of the error name including input types.
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-eth-abi/src/api/events_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
import { sha3Raw } from 'web3-utils';
import { AbiError } from 'web3-errors';
import { AbiEventFragment } from 'web3-types';
import { jsonInterfaceMethodToString, isAbiEventFragment } from '../utils';
import { jsonInterfaceMethodToString, isAbiEventFragment } from '../utils.js';

/**
* Encodes the event name to its ABI signature, which are the sha3 hash of the event name including input types.
Expand Down
4 changes: 2 additions & 2 deletions packages/web3-eth-abi/src/api/functions_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
import { AbiError } from 'web3-errors';
import { sha3Raw } from 'web3-utils';
import { AbiFunctionFragment } from 'web3-types';
import { isAbiFunctionFragment, jsonInterfaceMethodToString } from '../utils';
import { encodeParameters } from './parameters_api';
import { isAbiFunctionFragment, jsonInterfaceMethodToString } from '../utils.js';
import { encodeParameters } from './parameters_api.js';

// todo Add link to JSON interface documentation
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-eth-abi/src/api/logs_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/

import { HexString, AbiParameter, DecodedParams } from 'web3-types';
import { decodeParameter, decodeParametersWith } from './parameters_api';
import { decodeParameter, decodeParametersWith } from './parameters_api.js';

const STATIC_TYPES = ['bool', 'string', 'int', 'uint', 'address', 'fixed', 'ufixed'];

Expand Down
Loading