Skip to content

Commit

Permalink
@ethersproject/* pkgs + fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TateB committed Jan 20, 2023
1 parent 9cee622 commit 80d1372
Show file tree
Hide file tree
Showing 55 changed files with 275 additions and 195 deletions.
4 changes: 2 additions & 2 deletions .yalc/@ensdomains/ensjs/dist/cjs/utils/normalise.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .yalc/@ensdomains/ensjs/dist/esm/utils/normalise.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .yalc/@ensdomains/ensjs/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .yalc/@ensdomains/ensjs/src/utils/normalise.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .yalc/@ensdomains/ensjs/yalc.sig

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion deploy/00_deploy_bulk_renewal.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/* eslint-disable import/no-extraneous-dependencies */
import { namehash } from 'ethers/lib/utils'
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

import { namehash } from '@ensdomains/ensjs/utils/normalise'

const labelHash = (label: string) => ethers.utils.keccak256(ethers.utils.toUtf8Bytes(label))

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
Expand Down
3 changes: 2 additions & 1 deletion deploy/00_get_registration_gas_values.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* eslint-disable import/no-extraneous-dependencies */

/* eslint-disable no-await-in-loop */
import { namehash } from 'ethers/lib/utils'
import fs from 'fs/promises'
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

import { namehash } from '@ensdomains/ensjs/utils/normalise'

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
if (!hre.network.tags.generate) {
return true
Expand Down
2 changes: 1 addition & 1 deletion deploy/00_legacy_registry.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable import/no-extraneous-dependencies, import/extensions */
import { namehash } from 'ethers/lib/utils'
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

import { labelhash } from '@ensdomains/ensjs/utils/labels'
import { namehash } from '@ensdomains/ensjs/utils/normalise'

const ZERO_HASH = '0x0000000000000000000000000000000000000000000000000000000000000000'

Expand Down
3 changes: 2 additions & 1 deletion deploy/00_migrate_legacy_records.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/* eslint-disable import/no-extraneous-dependencies */

/* eslint-disable no-await-in-loop */
import { namehash } from 'ethers/lib/utils'
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

import { namehash } from '@ensdomains/ensjs/utils/normalise'

const names = [
{
label: 'migrated-resolver-to-be-updated',
Expand Down
3 changes: 2 additions & 1 deletion deploy/00_register_contracts.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/* eslint-disable import/no-extraneous-dependencies */

/* eslint-disable no-await-in-loop */
import { namehash } from 'ethers/lib/utils'
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

import { namehash } from '@ensdomains/ensjs/utils/normalise'

const names = [
{
label: 'data',
Expand Down
2 changes: 1 addition & 1 deletion deploy/00_register_legacy.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* eslint-disable import/no-extraneous-dependencies */

/* eslint-disable no-await-in-loop */
import { namehash } from 'ethers/lib/utils'
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

import { labelhash } from '@ensdomains/ensjs/utils/labels'
import { namehash } from '@ensdomains/ensjs/utils/normalise'

type Name = {
label: string
Expand Down
2 changes: 1 addition & 1 deletion deploy/00_register_wrapped.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* eslint-disable import/no-extraneous-dependencies */

/* eslint-disable no-await-in-loop */
import { namehash } from 'ethers/lib/utils'
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

import { PublicResolver__factory } from '@ensdomains/ensjs/generated/factories/PublicResolver__factory'
import { namehash } from '@ensdomains/ensjs/utils/normalise'
import { RecordOptions } from '@ensdomains/ensjs/utils/recordHelpers'
import {
RegistrationParams,
Expand Down
74 changes: 74 additions & 0 deletions loaders/ethers-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
const { readdirSync, statSync } = require('fs')
const { join, basename } = require('path')

const requireAll = (dir) =>
readdirSync(dir).reduce((modules, file) => {
const fPath = join(dir, file)
const fPathAsModule = fPath.replace(/.*\/node_modules\//, '')
if (fPath.includes('esm') || fPath.includes('src')) return modules
if (statSync(fPath).isDirectory()) {
return { ...modules, ...requireAll(fPath) }
}
if (file.endsWith('.js')) {
const imported = require(fPath)
let keyMap = Object.keys(imported).map((k) => [k, fPathAsModule])
if (file === 'index.js') {
keyMap = keyMap.filter(([k]) => !modules[k])
if (dir.match(/.*\/lib$/g)) {
const [modName] = dir.match(/@ethersproject\/[a-z\-]*/)
return {
...modules,
...Object.fromEntries(keyMap),
[modName.replace('@ethersproject/', '')]: modName,
}
}
}
return { ...modules, ...Object.fromEntries(keyMap) }
}
return modules
}, {})

const modules = requireAll(join(__dirname, '../node_modules/@ethersproject'))

exports.default = function (source) {
const newModules = {}

source = source.replace(
/(?<=\n|^)import {(.*?)} from ["']ethers(\/lib\/((ethers)|(utils)))?["'];\n/gm,
(m, p1) => {
const items = p1.split(',').map((i) => i.trim())
for (const item of items) {
const original = item.split(' as ')[0]
const importRef = modules[original]
if (importRef) {
if (!importRef.endsWith('js')) {
newModules[importRef] = item
} else {
const arr = newModules[importRef]
if (!arr) newModules[importRef] = [item]
else if (!arr.includes(item)) arr.push(item)
}
} else {
throw new Error(`Could not find module for ${original}`)
}
}
return ''
},
)

let newImports = ''
for (const [k, v] of Object.entries(newModules)) {
if (v === 'logger') {
if (!newModules['@ethersproject/logger/lib/index.js']) {
newImports += `import { Logger } from '${k}';\n`
}
newImports += `const logger = new Logger('ethers');\n`
} else if (typeof v === 'object') {
newImports += `import { ${v.join(', ')} } from '${k}';\n`
} else {
newImports += `import * as ${v} from '${k}';\n`
}
}

return newImports + source
}
8 changes: 8 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ let nextConfig = {
return hash
},
webpack: (config, options) => {
config.module.rules.push({
// test for .js or .mjs
test: /(?<!@ethersproject\/.*)\.m?js$/,
use: {
loader: path.resolve(__dirname, './loaders/ethers-loader.js'),
options: {},
},
})
config.module.rules.push({
test: /ens.+\.json$/,
use: {
Expand Down
19 changes: 18 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,22 @@
"@ensdomains/ensjs": "file:.yalc/@ensdomains/ensjs",
"@ensdomains/eth-ens-namehash": "^2.0.15",
"@ensdomains/thorin": "^0.6.23-alpha-4",
"@ethersproject/abi": "^5.6.4",
"@ethersproject/abstract-provider": "^5.7.0",
"@ethersproject/abstract-signer": "^5.7.0",
"@ethersproject/address": "^5.7.0",
"@ethersproject/bignumber": "^5.7.0",
"@ethersproject/bytes": "^5.7.0",
"@ethersproject/contracts": "^5.7.0",
"@ethersproject/keccak256": "^5.7.0",
"@ethersproject/logger": "^5.7.0",
"@ethersproject/providers": "^5.6.8",
"@ethersproject/sha2": "^5.7.0",
"@ethersproject/solidity": "^5.7.0",
"@ethersproject/strings": "^5.7.0",
"@ethersproject/transactions": "^5.7.0",
"@ethersproject/units": "^5.7.0",
"@ethersproject/web": "^5.7.1",
"@rainbow-me/rainbowkit": "0.4.8",
"@sentry/nextjs": "^7.11.1",
"@svgr/webpack": "^6.3.1",
Expand All @@ -66,7 +82,6 @@
"@wagmi/core": "^0.5.8",
"calendar-link": "^2.2.0",
"dns-packet": "^5.4.0",
"ethers": "^5.7.0",
"glob": "^8.0.3",
"i18next": "^21.9.1",
"i18next-browser-languagedetector": "^6.1.5",
Expand Down Expand Up @@ -104,6 +119,7 @@
"@ensdomains/buffer": "^0.1.0",
"@ensdomains/ens-test-env": "^0.3.6",
"@ethersproject/providers": "^5.7.0",
"@ethersproject/wallet": "^5.7.0",
"@next/bundle-analyzer": "^12.2.5",
"@next/swc-linux-x64-gnu": "12.1.4",
"@nomiclabs/hardhat-ethers": "npm:hardhat-deploy-ethers@^0.3.0-beta.13",
Expand Down Expand Up @@ -151,6 +167,7 @@
"eslint-plugin-react": "^7.31.1",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-testing-library": "^4.12.4",
"ethers": "^5.7.2",
"ganache": "^7.4.1",
"graphql-request": "next",
"hardhat": "^2.10.2",
Expand Down
Loading

0 comments on commit 80d1372

Please sign in to comment.