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

Monorepo: Set "type": "module" in package.json files (default ESM internally) #3494

Merged
merged 14 commits into from
Jul 11, 2024
Merged
4 changes: 2 additions & 2 deletions config/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"sourceMap": true,
"declaration": true,
"declarationMap": true,
"module": "Node16",
"moduleResolution": "node",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"esModuleInterop": false,
Expand Down
6 changes: 5 additions & 1 deletion config/tsconfig.prod.cjs.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"extends": "./tsconfig.json"
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "Node16",
"moduleResolution": "node"
}
}
5 changes: 1 addition & 4 deletions config/tsconfig.prod.esm.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "esnext"
}
"extends": "./tsconfig.json"
}
2 changes: 1 addition & 1 deletion packages/block/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"license": "MPL-2.0",
"author": "mjbecze ([email protected])",
"type": "commonjs",
"type": "module",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"exports": {
Expand Down
2 changes: 1 addition & 1 deletion packages/blockchain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"license": "MPL-2.0",
"author": "mjbecze <[email protected]>",
"type": "commonjs",
"type": "module",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"exports": {
Expand Down
3 changes: 1 addition & 2 deletions packages/blockchain/src/consensus/clique.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ import type { Blockchain } from '../index.js'
import type { Consensus, ConsensusOptions } from '../types.js'
import type { Block, BlockHeader } from '@ethereumjs/block'
import type { CliqueConfig } from '@ethereumjs/common'
const { debug: createDebugLogger } = debugDefault

const debug = createDebugLogger('blockchain:clique')
const debug = debugDefault('blockchain:clique')

// Magic nonce number to vote on adding a new signer
export const CLIQUE_NONCE_AUTH = hexToBytes('0xffffffffffffffff')
Expand Down
2 changes: 1 addition & 1 deletion packages/blockchain/src/consensus/ethash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class EthashConsensus implements Consensus {
public async genesisInit(): Promise<void> {}
public async setup({ blockchain }: ConsensusOptions): Promise<void> {
this.blockchain = blockchain
this._ethash = new Ethash(this.blockchain.db as any)
this._ethash = new Ethash(this.blockchain!.db as any)
}
public async newBlock(): Promise<void> {}
}
2 changes: 1 addition & 1 deletion packages/blockchain/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Blockchain } from '.'
import type { Blockchain } from './index.js'
import type { Block, BlockHeader } from '@ethereumjs/block'
import type { Common, ConsensusAlgorithm } from '@ethereumjs/common'
import type { AsyncEventEmitter, DB, DBObject, GenesisState } from '@ethereumjs/util'
Expand Down
1 change: 0 additions & 1 deletion packages/blockchain/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"extends": "../../config/tsconfig.json",
"include": ["src/**/*.ts", "src/**/*.json", "test/**/*.ts"],
"compilerOptions": {
"types": ["node"],
"typeRoots": ["node_modules/@types"]
}
}
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
},
"license": "MPL-2.0",
"author": "Vinay Pulim ([email protected])",
"type": "module",
"main": "dist/esm/bin/cli.js",
"types": "dist/esm/src/index.d.ts",
"type": "module",
"bin": {
"ethereumjs": "dist/esm/bin/cli.js"
},
Expand Down
3 changes: 1 addition & 2 deletions packages/client/src/sync/fetcher/accountfetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import type { FetcherOptions } from './fetcher.js'
import type { StorageRequest } from './storagefetcher.js'
import type { Job, SnapFetcherDoneFlags } from './types.js'
import type { Debugger } from 'debug'
const { debug: createDebugLogger } = debugDefault

type AccountDataResponse = AccountData[] & { completed?: boolean }

Expand Down Expand Up @@ -99,7 +98,7 @@ export class AccountFetcher extends Fetcher<JobTask, AccountData[], AccountData>
this.stateManager = options.stateManager ?? new DefaultStateManager()
this.accountTrie = this.stateManager['_getAccountTrie']()

this.debug = createDebugLogger('client:AccountFetcher')
this.debug = debugDefault('client:AccountFetcher')

this.storageFetcher = new StorageFetcher({
config: this.config,
Expand Down
5 changes: 2 additions & 3 deletions packages/client/src/sync/fetcher/bytecodefetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
concatBytes,
equalsBytes,
} from '@ethereumjs/util'
import debugDefault from 'debug'
import debug from 'debug'
import { keccak256 } from 'ethereum-cryptography/keccak'

import { Fetcher } from './fetcher.js'
Expand All @@ -17,7 +17,6 @@ import type { FetcherOptions } from './fetcher.js'
import type { Job, SnapFetcherDoneFlags } from './types.js'
import type { BatchDBOp, DB } from '@ethereumjs/util'
import type { Debugger } from 'debug'
const { debug: createDebugLogger } = debugDefault

type ByteCodeDataResponse = Uint8Array[] & { completed?: boolean }

Expand Down Expand Up @@ -62,7 +61,7 @@ export class ByteCodeFetcher extends Fetcher<JobTask, Uint8Array[], Uint8Array>

this.keccakFunction = this.config.chainCommon.customCrypto.keccak256 ?? keccak256

this.debug = createDebugLogger('client:ByteCodeFetcher')
this.debug = debug('client:ByteCodeFetcher')
if (this.hashes.length > 0) {
const fullJob = { task: { hashes: this.hashes } } as Job<JobTask, Uint8Array[], Uint8Array>
this.debug(
Expand Down
6 changes: 2 additions & 4 deletions packages/client/src/sync/fetcher/fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import debugDefault from 'debug'
import debug from 'debug'
import { Readable, Writable } from 'stream'

import { Heap } from '../../ext/qheap.js'
Expand All @@ -12,8 +12,6 @@ import type { JobTask as BlockFetcherJobTask } from './blockfetcherbase.js'
import type { Job } from './types.js'
import type { Debugger } from 'debug'

const { debug: createDebugLogger } = debugDefault

export interface FetcherOptions {
/* Common chain config*/
config: Config
Expand Down Expand Up @@ -80,7 +78,7 @@ export abstract class Fetcher<JobTask, JobResult, StorageItem> extends Readable
super({ ...options, objectMode: true })

this.config = options.config
this.debug = createDebugLogger('client:fetcher')
this.debug = debug('client:fetcher')

this.pool = options.pool
this.timeout = options.timeout ?? 8000
Expand Down
3 changes: 1 addition & 2 deletions packages/client/src/sync/fetcher/storagefetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import type { StorageData } from '../../net/protocol/snapprotocol.js'
import type { FetcherOptions } from './fetcher.js'
import type { Job, SnapFetcherDoneFlags } from './types.js'
import type { Debugger } from 'debug'
const { debug: createDebugLogger } = debugDefault

const TOTAL_RANGE_END = BIGINT_2 ** BIGINT_256 - BIGINT_1

Expand Down Expand Up @@ -95,7 +94,7 @@ export class StorageFetcher extends Fetcher<JobTask, StorageData[][], StorageDat
this.fetcherDoneFlags.storageFetcher.count = BigInt(this.storageRequests.length)

this.accountToHighestKnownHash = new Map<String, Uint8Array>()
this.debug = createDebugLogger('client:StorageFetcher')
this.debug = debugDefault('client:StorageFetcher')
if (this.storageRequests.length > 0) {
const fullJob = {
task: { storageRequests: this.storageRequests },
Expand Down
5 changes: 2 additions & 3 deletions packages/client/src/sync/fetcher/trienodefetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
KECCAK256_RLP,
unprefixedHexToBytes,
} from '@ethereumjs/util'
import debugPkg from 'debug'
import debug from 'debug'
import { keccak256 } from 'ethereum-cryptography/keccak.js'
import { bytesToHex, equalsBytes, hexToBytes } from 'ethereum-cryptography/utils'
import { OrderedMap } from 'js-sdsl'
Expand All @@ -28,7 +28,6 @@ import type { FetcherOptions } from './fetcher.js'
import type { Job, SnapFetcherDoneFlags } from './types.js'
import type { BatchDBOp, DB } from '@ethereumjs/util'
import type { Debugger } from 'debug'
const { debug: createDebugLogger } = debugPkg

type TrieNodesResponse = Uint8Array[] & { completed?: boolean }

Expand Down Expand Up @@ -111,7 +110,7 @@ export class TrieNodeFetcher extends Fetcher<JobTask, Uint8Array[], Uint8Array>
this.codeDB = this.stateManager['_getCodeDB']()

this.nodeCount = 0
this.debug = createDebugLogger('client:TrieNodeFetcher')
this.debug = debug('client:TrieNodeFetcher')

this.keccakFunction = this.config.chainCommon.customCrypto.keccak256 ?? keccak256

Expand Down
2 changes: 1 addition & 1 deletion packages/client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"include": ["bin", "src", "test", "package.json"],
"compilerOptions": {
"typeRoots": ["node_modules/@types", "src/@types"],
"moduleResolution": "Node16"
"allowSyntheticDefaultImports": true
}
}
21 changes: 11 additions & 10 deletions packages/client/tsconfig.prod.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
"compilerOptions": {
"outDir": "dist/esm",
"typeRoots": ["node_modules/@types", "src/@types"],
"composite": true
"composite": true,
"allowSyntheticDefaultImports": true
},
"references": [
{ "path": "../block/tsconfig.prod.cjs.json" },
{ "path": "../blockchain/tsconfig.prod.cjs.json" },
{ "path": "../common/tsconfig.prod.cjs.json" },
{ "path": "../devp2p/tsconfig.prod.cjs.json" },
{ "path": "../rlp/tsconfig.prod.cjs.json" },
{ "path": "../trie/tsconfig.prod.cjs.json" },
{ "path": "../tx/tsconfig.prod.cjs.json" },
{ "path": "../util/tsconfig.prod.cjs.json" },
{ "path": "../vm/tsconfig.prod.cjs.json" }
{ "path": "../block/tsconfig.prod.esm.json" },
{ "path": "../blockchain/tsconfig.prod.esm.json" },
{ "path": "../common/tsconfig.prod.esm.json" },
{ "path": "../devp2p/tsconfig.prod.esm.json" },
{ "path": "../rlp/tsconfig.prod.esm.json" },
{ "path": "../trie/tsconfig.prod.esm.json" },
{ "path": "../tx/tsconfig.prod.esm.json" },
{ "path": "../util/tsconfig.prod.esm.json" },
{ "path": "../vm/tsconfig.prod.esm.json" }
]
}
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"email": "[email protected]"
}
],
"type": "commonjs",
"type": "module",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"exports": {
Expand Down
2 changes: 1 addition & 1 deletion packages/devp2p/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"Martin Becze <[email protected]>",
"Holger Drewes <[email protected]>"
],
"main": "dist/cjs/index.js",
"type": "module",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"exports": {
".": {
Expand Down
3 changes: 1 addition & 2 deletions packages/devp2p/src/dns/dns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import { ENR } from './enr.js'

import type { DNSOptions, PeerInfo } from '../types.js'
import type { Common } from '@ethereumjs/common'
const { debug: createDebugLogger } = debugDefault

const debug = createDebugLogger('devp2p:dns:dns')
const debug = debugDefault('devp2p:dns:dns')

type SearchContext = {
domain: string
Expand Down
5 changes: 2 additions & 3 deletions packages/devp2p/src/dpt/ban-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import { formatLogId } from '../util.js'
import { KBucket } from './kbucket.js'

import type { PeerInfo } from '../types.js'
const { debug: createDebugLogger } = debugDefault

const debug = createDebugLogger('devp2p:dpt:ban-list')
const verbose = createDebugLogger('verbose').enabled
const debug = debugDefault('devp2p:dpt:ban-list')
const verbose = debugDefault('verbose').enabled

export class BanList {
private _lru: LRUCache<string, boolean>
Expand Down
3 changes: 1 addition & 2 deletions packages/devp2p/src/dpt/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import { assertEq, ipToBytes, ipToString, isV4Format, isV6Format, unstrictDecode

import type { PeerInfo } from '../types.js'
import type { Common } from '@ethereumjs/common'
const { debug: createDebugLogger } = debugDefault

const debug = createDebugLogger('devp2p:dpt:server')
const debug = debugDefault('devp2p:dpt:server')

function getTimestamp() {
return (Date.now() / 1000) | 0
Expand Down
3 changes: 1 addition & 2 deletions packages/devp2p/src/dpt/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ import type { DPT } from './dpt.js'
import type { Common } from '@ethereumjs/common'
import type { Debugger } from 'debug'
import type { Socket as DgramSocket, RemoteInfo } from 'dgram'
const { debug: createDebugLogger } = debugDefault

const DEBUG_BASE_NAME = 'dpt:server'
const verbose = createDebugLogger('verbose').enabled
const verbose = debugDefault('verbose').enabled

const VERSION = 0x04

Expand Down
3 changes: 1 addition & 2 deletions packages/devp2p/src/protocol/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { devp2pDebug } from '../util.js'
import type { Peer } from '../rlpx/peer.js'
import type { SendMethod } from '../types.js'
import type { Debugger } from 'debug'
const { debug: createDebugLogger } = debugDefault

type MessageCodes = { [key: number | string]: number | string }

Expand Down Expand Up @@ -50,7 +49,7 @@ export abstract class Protocol {
: undefined

this._debug = devp2pDebug.extend(protocol)
this._verbose = createDebugLogger('verbose').enabled
this._verbose = debugDefault('verbose').enabled
this.initMsgDebuggers(protocol)
}

Expand Down
3 changes: 1 addition & 2 deletions packages/devp2p/src/rlpx/ecies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ import { assertEq, genPrivateKey, id2pk, pk2id, unstrictDecode, xor, zfill } fro
import { MAC } from './mac.js'

import type { Common } from '@ethereumjs/common'
const { debug: createDebugLogger } = debugDefault
type Decipher = crypto.Decipher

const debug = createDebugLogger('devp2p:rlpx:peer')
const debug = debugDefault('devp2p:rlpx:peer')

function ecdhX(publicKey: Uint8Array, privateKey: Uint8Array) {
// return (publicKey * privateKey).x
Expand Down
3 changes: 1 addition & 2 deletions packages/devp2p/src/rlpx/peer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ import type { Capabilities, PeerOptions } from '../types.js'
import type { Common } from '@ethereumjs/common'
import type { Debugger } from 'debug'
import type { Socket } from 'net'
const { debug: createDebugLogger } = debugDefault

const DEBUG_BASE_NAME = 'rlpx:peer'
const verbose = createDebugLogger('verbose').enabled
const verbose = debugDefault('verbose').enabled

const BASE_PROTOCOL_VERSION = 5
const BASE_PROTOCOL_LENGTH = 16
Expand Down
3 changes: 1 addition & 2 deletions packages/devp2p/src/rlpx/rlpx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ import type { DPT } from '../dpt/index.js'
import type { Capabilities, PeerInfo, RLPxOptions } from '../types.js'
import type { Common } from '@ethereumjs/common'
import type { Debugger } from 'debug'
const { debug: createDebugLogger } = debugDefault

// note: relative path only valid in .js file in dist

const DEBUG_BASE_NAME = 'rlpx'
const verbose = createDebugLogger('verbose').enabled
const verbose = debugDefault('verbose').enabled

export class RLPx {
public events: EventEmitter
Expand Down
4 changes: 2 additions & 2 deletions packages/devp2p/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { DPT } from './dpt'
import type { Protocol } from './protocol/protocol'
import type { DPT } from './dpt/index.js'
import type { Protocol } from './protocol/protocol.js'
import type { Common } from '@ethereumjs/common'
import type { Socket } from 'net'

Expand Down
5 changes: 2 additions & 3 deletions packages/devp2p/src/util.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { RLP } from '@ethereumjs/rlp'
import { bytesToHex, bytesToUnprefixedHex, concatBytes, equalsBytes } from '@ethereumjs/util'
import debugDefault from 'debug'
import debug from 'debug'
import { publicKeyConvert } from 'ethereum-cryptography/secp256k1-compat.js'
import { secp256k1 } from 'ethereum-cryptography/secp256k1.js'

import type { ETH } from './protocol/eth.js'
import type { LES } from './protocol/les.js'
const { debug: createDebugLogger } = debugDefault

export const devp2pDebug = createDebugLogger('devp2p')
export const devp2pDebug = debug('devp2p')

export function genPrivateKey(): Uint8Array {
const privateKey = secp256k1.utils.randomPrivateKey()
Expand Down
1 change: 1 addition & 0 deletions packages/evm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"contributors": [
"Alex Beregszaszi <[email protected]>"
],
"type": "module",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"exports": {
Expand Down
Loading
Loading