Skip to content

Commit

Permalink
fix: viem/node esm/cjs conflict (#2298)
Browse files Browse the repository at this point in the history
* fix(node): esm export

* Create heavy-berries-watch.md

---------

Co-authored-by: jxom <jakemoxey@gmail.com>
  • Loading branch information
tmm and jxom authored May 23, 2024
1 parent 144d90e commit 601cb74
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/heavy-berries-watch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": patch
---

Fixed support for ESM for 4337 trusted setups.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ coverage
node_modules
tsconfig*.tsbuildinfo
wagmi
src/node/trustedSetups_esm.ts
**/trusted-setups/**/*.txt
.idea

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
"bench": "vitest bench",
"bench:ci": "CI=true vitest bench",
"build": "bun run clean && bun run build:cjs && bun run build:esm && bun run build:types",
"build:cjs": "tsc --project ./tsconfig.build.json --module commonjs --outDir ./src/_cjs --removeComments --verbatimModuleSyntax false && printf '{\"type\":\"commonjs\"}' > ./src/_cjs/package.json",
"build:cjs": "bun run build:trustedSetups:start && tsc --project ./tsconfig.build.json --module commonjs --outDir ./src/_cjs --removeComments --verbatimModuleSyntax false && printf '{\"type\":\"commonjs\"}' > ./src/_cjs/package.json && bun run build:trustedSetups:end",
"build:esm": "tsc --project ./tsconfig.build.json --module es2015 --outDir ./src/_esm && printf '{\"type\": \"module\",\"sideEffects\":false}' > ./src/_esm/package.json",
"build:trustedSetups:start": "mv src/node/trustedSetups.ts src/node/trustedSetups_esm.ts && mv src/node/trustedSetups_cjs.ts src/node/trustedSetups.ts",
"build:trustedSetups:end": "mv src/node/trustedSetups.ts src/node/trustedSetups_cjs.ts && mv src/node/trustedSetups_esm.ts src/node/trustedSetups.ts",
"build:types": "tsc --project ./tsconfig.build.json --module esnext --declarationDir ./src/_types --emitDeclarationOnly --declaration --declarationMap",
"chaincheck": "bun test test/chains/check.test.ts",
"changeset": "changeset",
Expand Down
10 changes: 9 additions & 1 deletion src/node/trustedSetups.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { resolve } from 'node:path'
import { dirname, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'

const __filename = fileURLToPath(
// import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'
// @ts-ignore
import.meta.url,
)
const __dirname = dirname(__filename)

export const mainnetTrustedSetupPath = resolve(
__dirname,
Expand Down
11 changes: 11 additions & 0 deletions src/node/trustedSetups_cjs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { resolve } from 'node:path'

export const mainnetTrustedSetupPath = resolve(
__dirname,
'../trusted-setups/mainnet.json',
)

export const minimalTrustedSetupPath = resolve(
__dirname,
'../trusted-setups/mainnet.json',
)
3 changes: 2 additions & 1 deletion tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"exclude": [
"src/**/*.test.ts",
"src/**/*.test-d.ts",
"src/**/*.bench.ts"
"src/**/*.bench.ts",
"src/node/trustedSetups_esm.ts"
],
"compilerOptions": {
"moduleResolution": "node",
Expand Down

0 comments on commit 601cb74

Please sign in to comment.