Skip to content

Commit 7ec47a3

Browse files
holgerd77acolytec3
andauthored
Monorepo: Set "type": "module" in package.json files (default ESM internally) (#3494)
* Do a simple test and see what happens (Util) (npm i works, test:node works, lint works, docs do not work (maybe unrelated), examples work) * Switch all other libraries over * Move view specialized debug functionality out of trie src since debug module causes too much problem in this intense usage setup (not ESM ready) * Trie import fixes * VM example file extension renaming * Fix VM examples * Import fix * Make the switch-over in tsconfig files * Fix some new lint failures * Bugfix (wrong import extension) * Import file extension fixes * Fix benchmarks * Fix various import issues * Remove duplicative node types and clean up references --------- Co-authored-by: acolytec3 <[email protected]>
1 parent c6ff99a commit 7ec47a3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+127
-150
lines changed

config/tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"sourceMap": true,
44
"declaration": true,
55
"declarationMap": true,
6-
"module": "Node16",
7-
"moduleResolution": "node",
6+
"module": "NodeNext",
7+
"moduleResolution": "NodeNext",
88
"emitDecoratorMetadata": true,
99
"experimentalDecorators": true,
1010
"esModuleInterop": false,

config/tsconfig.prod.cjs.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
{
2-
"extends": "./tsconfig.json"
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"module": "Node16",
5+
"moduleResolution": "node"
6+
}
37
}

config/tsconfig.prod.esm.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
{
2-
"extends": "./tsconfig.json",
3-
"compilerOptions": {
4-
"module": "esnext"
5-
}
2+
"extends": "./tsconfig.json"
63
}

packages/block/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
},
1717
"license": "MPL-2.0",
1818
"author": "mjbecze ([email protected])",
19-
"type": "commonjs",
19+
"type": "module",
2020
"main": "dist/cjs/index.js",
2121
"module": "dist/esm/index.js",
2222
"exports": {

packages/blockchain/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
},
1717
"license": "MPL-2.0",
1818
"author": "mjbecze <[email protected]>",
19-
"type": "commonjs",
19+
"type": "module",
2020
"main": "dist/cjs/index.js",
2121
"module": "dist/esm/index.js",
2222
"exports": {

packages/blockchain/src/consensus/clique.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ import type { Blockchain } from '../index.js'
1818
import type { Consensus, ConsensusOptions } from '../types.js'
1919
import type { Block, BlockHeader } from '@ethereumjs/block'
2020
import type { CliqueConfig } from '@ethereumjs/common'
21-
const { debug: createDebugLogger } = debugDefault
2221

23-
const debug = createDebugLogger('blockchain:clique')
22+
const debug = debugDefault('blockchain:clique')
2423

2524
// Magic nonce number to vote on adding a new signer
2625
export const CLIQUE_NONCE_AUTH = hexToBytes('0xffffffffffffffff')

packages/blockchain/src/consensus/ethash.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class EthashConsensus implements Consensus {
4444
public async genesisInit(): Promise<void> {}
4545
public async setup({ blockchain }: ConsensusOptions): Promise<void> {
4646
this.blockchain = blockchain
47-
this._ethash = new Ethash(this.blockchain.db as any)
47+
this._ethash = new Ethash(this.blockchain!.db as any)
4848
}
4949
public async newBlock(): Promise<void> {}
5050
}

packages/blockchain/src/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Blockchain } from '.'
1+
import type { Blockchain } from './index.js'
22
import type { Block, BlockHeader } from '@ethereumjs/block'
33
import type { Common, ConsensusAlgorithm } from '@ethereumjs/common'
44
import type { AsyncEventEmitter, DB, DBObject, GenesisState } from '@ethereumjs/util'

packages/blockchain/tsconfig.json

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"extends": "../../config/tsconfig.json",
33
"include": ["src/**/*.ts", "src/**/*.json", "test/**/*.ts"],
44
"compilerOptions": {
5-
"types": ["node"],
65
"typeRoots": ["node_modules/@types"]
76
}
87
}

packages/client/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
},
2121
"license": "MPL-2.0",
2222
"author": "Vinay Pulim ([email protected])",
23+
"type": "module",
2324
"main": "dist/esm/bin/cli.js",
2425
"types": "dist/esm/src/index.d.ts",
25-
"type": "module",
2626
"bin": {
2727
"ethereumjs": "dist/esm/bin/cli.js"
2828
},

packages/client/src/sync/fetcher/accountfetcher.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import type { FetcherOptions } from './fetcher.js'
3434
import type { StorageRequest } from './storagefetcher.js'
3535
import type { Job, SnapFetcherDoneFlags } from './types.js'
3636
import type { Debugger } from 'debug'
37-
const { debug: createDebugLogger } = debugDefault
3837

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

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

102-
this.debug = createDebugLogger('client:AccountFetcher')
101+
this.debug = debugDefault('client:AccountFetcher')
103102

104103
this.storageFetcher = new StorageFetcher({
105104
config: this.config,

packages/client/src/sync/fetcher/bytecodefetcher.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
concatBytes,
77
equalsBytes,
88
} from '@ethereumjs/util'
9-
import debugDefault from 'debug'
9+
import debug from 'debug'
1010
import { keccak256 } from 'ethereum-cryptography/keccak'
1111

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

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

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

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

65-
this.debug = createDebugLogger('client:ByteCodeFetcher')
64+
this.debug = debug('client:ByteCodeFetcher')
6665
if (this.hashes.length > 0) {
6766
const fullJob = { task: { hashes: this.hashes } } as Job<JobTask, Uint8Array[], Uint8Array>
6867
this.debug(

packages/client/src/sync/fetcher/fetcher.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import debugDefault from 'debug'
1+
import debug from 'debug'
22
import { Readable, Writable } from 'stream'
33

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

15-
const { debug: createDebugLogger } = debugDefault
16-
1715
export interface FetcherOptions {
1816
/* Common chain config*/
1917
config: Config
@@ -80,7 +78,7 @@ export abstract class Fetcher<JobTask, JobResult, StorageItem> extends Readable
8078
super({ ...options, objectMode: true })
8179

8280
this.config = options.config
83-
this.debug = createDebugLogger('client:fetcher')
81+
this.debug = debug('client:fetcher')
8482

8583
this.pool = options.pool
8684
this.timeout = options.timeout ?? 8000

packages/client/src/sync/fetcher/storagefetcher.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import type { StorageData } from '../../net/protocol/snapprotocol.js'
2424
import type { FetcherOptions } from './fetcher.js'
2525
import type { Job, SnapFetcherDoneFlags } from './types.js'
2626
import type { Debugger } from 'debug'
27-
const { debug: createDebugLogger } = debugDefault
2827

2928
const TOTAL_RANGE_END = BIGINT_2 ** BIGINT_256 - BIGINT_1
3029

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

9796
this.accountToHighestKnownHash = new Map<String, Uint8Array>()
98-
this.debug = createDebugLogger('client:StorageFetcher')
97+
this.debug = debugDefault('client:StorageFetcher')
9998
if (this.storageRequests.length > 0) {
10099
const fullJob = {
101100
task: { storageRequests: this.storageRequests },

packages/client/src/sync/fetcher/trienodefetcher.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
KECCAK256_RLP,
1616
unprefixedHexToBytes,
1717
} from '@ethereumjs/util'
18-
import debugPkg from 'debug'
18+
import debug from 'debug'
1919
import { keccak256 } from 'ethereum-cryptography/keccak.js'
2020
import { bytesToHex, equalsBytes, hexToBytes } from 'ethereum-cryptography/utils'
2121
import { OrderedMap } from 'js-sdsl'
@@ -28,7 +28,6 @@ import type { FetcherOptions } from './fetcher.js'
2828
import type { Job, SnapFetcherDoneFlags } from './types.js'
2929
import type { BatchDBOp, DB } from '@ethereumjs/util'
3030
import type { Debugger } from 'debug'
31-
const { debug: createDebugLogger } = debugPkg
3231

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

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

113112
this.nodeCount = 0
114-
this.debug = createDebugLogger('client:TrieNodeFetcher')
113+
this.debug = debug('client:TrieNodeFetcher')
115114

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

packages/client/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
"include": ["bin", "src", "test", "package.json"],
44
"compilerOptions": {
55
"typeRoots": ["node_modules/@types", "src/@types"],
6-
"moduleResolution": "Node16"
6+
"allowSyntheticDefaultImports": true
77
}
88
}

packages/client/tsconfig.prod.esm.json

+11-10
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@
44
"compilerOptions": {
55
"outDir": "dist/esm",
66
"typeRoots": ["node_modules/@types", "src/@types"],
7-
"composite": true
7+
"composite": true,
8+
"allowSyntheticDefaultImports": true
89
},
910
"references": [
10-
{ "path": "../block/tsconfig.prod.cjs.json" },
11-
{ "path": "../blockchain/tsconfig.prod.cjs.json" },
12-
{ "path": "../common/tsconfig.prod.cjs.json" },
13-
{ "path": "../devp2p/tsconfig.prod.cjs.json" },
14-
{ "path": "../rlp/tsconfig.prod.cjs.json" },
15-
{ "path": "../trie/tsconfig.prod.cjs.json" },
16-
{ "path": "../tx/tsconfig.prod.cjs.json" },
17-
{ "path": "../util/tsconfig.prod.cjs.json" },
18-
{ "path": "../vm/tsconfig.prod.cjs.json" }
11+
{ "path": "../block/tsconfig.prod.esm.json" },
12+
{ "path": "../blockchain/tsconfig.prod.esm.json" },
13+
{ "path": "../common/tsconfig.prod.esm.json" },
14+
{ "path": "../devp2p/tsconfig.prod.esm.json" },
15+
{ "path": "../rlp/tsconfig.prod.esm.json" },
16+
{ "path": "../trie/tsconfig.prod.esm.json" },
17+
{ "path": "../tx/tsconfig.prod.esm.json" },
18+
{ "path": "../util/tsconfig.prod.esm.json" },
19+
{ "path": "../vm/tsconfig.prod.esm.json" }
1920
]
2021
}

packages/common/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"email": "[email protected]"
2727
}
2828
],
29-
"type": "commonjs",
29+
"type": "module",
3030
"main": "dist/cjs/index.js",
3131
"module": "dist/esm/index.js",
3232
"exports": {

packages/devp2p/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
"Martin Becze <[email protected]>",
3030
"Holger Drewes <[email protected]>"
3131
],
32-
"main": "dist/cjs/index.js",
3332
"type": "module",
33+
"main": "dist/cjs/index.js",
3434
"module": "dist/esm/index.js",
3535
"exports": {
3636
".": {

packages/devp2p/src/dns/dns.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ import { ENR } from './enr.js'
55

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

10-
const debug = createDebugLogger('devp2p:dns:dns')
9+
const debug = debugDefault('devp2p:dns:dns')
1110

1211
type SearchContext = {
1312
domain: string

packages/devp2p/src/dpt/ban-list.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ import { formatLogId } from '../util.js'
66
import { KBucket } from './kbucket.js'
77

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

11-
const debug = createDebugLogger('devp2p:dpt:ban-list')
12-
const verbose = createDebugLogger('verbose').enabled
10+
const debug = debugDefault('devp2p:dpt:ban-list')
11+
const verbose = debugDefault('verbose').enabled
1312

1413
export class BanList {
1514
private _lru: LRUCache<string, boolean>

packages/devp2p/src/dpt/message.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ import { assertEq, ipToBytes, ipToString, isV4Format, isV6Format, unstrictDecode
88

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

13-
const debug = createDebugLogger('devp2p:dpt:server')
12+
const debug = debugDefault('devp2p:dpt:server')
1413

1514
function getTimestamp() {
1615
return (Date.now() / 1000) | 0

packages/devp2p/src/dpt/server.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ import type { DPT } from './dpt.js'
1313
import type { Common } from '@ethereumjs/common'
1414
import type { Debugger } from 'debug'
1515
import type { Socket as DgramSocket, RemoteInfo } from 'dgram'
16-
const { debug: createDebugLogger } = debugDefault
1716

1817
const DEBUG_BASE_NAME = 'dpt:server'
19-
const verbose = createDebugLogger('verbose').enabled
18+
const verbose = debugDefault('verbose').enabled
2019

2120
const VERSION = 0x04
2221

packages/devp2p/src/protocol/protocol.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { devp2pDebug } from '../util.js'
77
import type { Peer } from '../rlpx/peer.js'
88
import type { SendMethod } from '../types.js'
99
import type { Debugger } from 'debug'
10-
const { debug: createDebugLogger } = debugDefault
1110

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

@@ -50,7 +49,7 @@ export abstract class Protocol {
5049
: undefined
5150

5251
this._debug = devp2pDebug.extend(protocol)
53-
this._verbose = createDebugLogger('verbose').enabled
52+
this._verbose = debugDefault('verbose').enabled
5453
this.initMsgDebuggers(protocol)
5554
}
5655

packages/devp2p/src/rlpx/ecies.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ import { assertEq, genPrivateKey, id2pk, pk2id, unstrictDecode, xor, zfill } fro
1212
import { MAC } from './mac.js'
1313

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

18-
const debug = createDebugLogger('devp2p:rlpx:peer')
17+
const debug = debugDefault('devp2p:rlpx:peer')
1918

2019
function ecdhX(publicKey: Uint8Array, privateKey: Uint8Array) {
2120
// return (publicKey * privateKey).x

packages/devp2p/src/rlpx/peer.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ import type { Capabilities, PeerOptions } from '../types.js'
2323
import type { Common } from '@ethereumjs/common'
2424
import type { Debugger } from 'debug'
2525
import type { Socket } from 'net'
26-
const { debug: createDebugLogger } = debugDefault
2726

2827
const DEBUG_BASE_NAME = 'rlpx:peer'
29-
const verbose = createDebugLogger('verbose').enabled
28+
const verbose = debugDefault('verbose').enabled
3029

3130
const BASE_PROTOCOL_VERSION = 5
3231
const BASE_PROTOCOL_LENGTH = 16

packages/devp2p/src/rlpx/rlpx.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@ import type { DPT } from '../dpt/index.js'
2222
import type { Capabilities, PeerInfo, RLPxOptions } from '../types.js'
2323
import type { Common } from '@ethereumjs/common'
2424
import type { Debugger } from 'debug'
25-
const { debug: createDebugLogger } = debugDefault
2625

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

2928
const DEBUG_BASE_NAME = 'rlpx'
30-
const verbose = createDebugLogger('verbose').enabled
29+
const verbose = debugDefault('verbose').enabled
3130

3231
export class RLPx {
3332
public events: EventEmitter

packages/devp2p/src/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { DPT } from './dpt'
2-
import type { Protocol } from './protocol/protocol'
1+
import type { DPT } from './dpt/index.js'
2+
import type { Protocol } from './protocol/protocol.js'
33
import type { Common } from '@ethereumjs/common'
44
import type { Socket } from 'net'
55

packages/devp2p/src/util.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import { RLP } from '@ethereumjs/rlp'
22
import { bytesToHex, bytesToUnprefixedHex, concatBytes, equalsBytes } from '@ethereumjs/util'
3-
import debugDefault from 'debug'
3+
import debug from 'debug'
44
import { publicKeyConvert } from 'ethereum-cryptography/secp256k1-compat.js'
55
import { secp256k1 } from 'ethereum-cryptography/secp256k1.js'
66

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

11-
export const devp2pDebug = createDebugLogger('devp2p')
10+
export const devp2pDebug = debug('devp2p')
1211

1312
export function genPrivateKey(): Uint8Array {
1413
const privateKey = secp256k1.utils.randomPrivateKey()

packages/evm/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"contributors": [
2222
"Alex Beregszaszi <[email protected]>"
2323
],
24+
"type": "module",
2425
"main": "dist/cjs/index.js",
2526
"module": "dist/esm/index.js",
2627
"exports": {

0 commit comments

Comments
 (0)