Skip to content

Commit

Permalink
Merge pull request #185 from ensdomains/dep-cleanup
Browse files Browse the repository at this point in the history
Dep cleanup
  • Loading branch information
talentlessguy authored Jun 27, 2024
2 parents c42dc04 + 01e6c27 commit 597421e
Show file tree
Hide file tree
Showing 14 changed files with 6,665 additions and 5,508 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ jobs:
matrix:
node-version: [18]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ github.event.release.target_commitish }}

- uses: pnpm/action-setup@v2.2.2
- uses: pnpm/action-setup@v4
with:
version: 8.14.0
version: 9.4.0

- name: Install Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ jobs:
matrix:
node-version: [18]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v2.2.2
- uses: pnpm/action-setup@v4
with:
version: 8.14.0
version: 9.4.0

- name: Install Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'
Expand All @@ -30,14 +30,14 @@ jobs:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v2.2.2
- uses: pnpm/action-setup@v4
with:
version: 8.14.0
version: 9.4.0

- name: Install Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 18
cache: 'pnpm'
Expand Down
8 changes: 4 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"search.exclude": {
"**/.yarn": true,
"**/.pnp.*": true
"prettier.enable": true,
"eslint.enable": true,
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"prettier.prettierPath": "node_modules/prettier/index.js",
"typescript.tsdk": "node_modules/typescript/lib",
"typescript.enablePromptUseWorkspaceTsdk": true
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@
"built": false,
"unplugged": true
}
}
},
"packageManager": "[email protected]"
}
8 changes: 4 additions & 4 deletions packages/ens-test-env/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@ensdomains/ens-test-env",
"type": "module",
"version": "0.5.0-beta.0",
"version": "0.5.0-beta.1",
"files": [
"src"
],
Expand All @@ -10,6 +10,9 @@
"prepublish": "cp ../../LICENSE ./",
"ver": "pnpm version --no-workspaces-update"
},
"engines": {
"node": ">=18"
},
"dependencies": {
"@ethersproject/wallet": "^5.6.0",
"ansi-colors": "^4.1.1",
Expand All @@ -18,12 +21,9 @@
"concurrently": "^7.1.0",
"docker-compose": "^0.24.7",
"dotenv": "^16.0.1",
"fs-extra": "^10.0.1",
"ganache": "^7.0.4",
"got": "^12.0.2",
"js-yaml": "^4.1.0",
"lz4": "^0.6.5",
"node-fetch": "^3.2.3",
"progress-stream": "^2.0.0",
"tar-fs": "^2.1.1",
"wait-on": "^6.0.1"
Expand Down
10 changes: 5 additions & 5 deletions packages/ens-test-env/src/fetch-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import colors from 'ansi-colors'
import cliProgress from 'cli-progress'
import 'dotenv/config'
import fs from 'fs-extra'
import fs from 'node:fs'
import lz4 from 'lz4'
import progress from 'progress-stream'
import { pipeline } from 'stream'
Expand Down Expand Up @@ -86,7 +86,7 @@ async function compressToArchive() {
async function decompressToOutput() {
return new Promise(async (resolve, reject) => {
if (fs.existsSync(dataPath))
await fs.rm(dataPath, { recursive: true, force: true })
await fs.promises.rm(dataPath, { recursive: true, force: true })

const archiveSize = fs.statSync(localPath + '.tar.lz4').size
const unarchiver = tar.extract(dataPath)
Expand Down Expand Up @@ -116,7 +116,7 @@ async function decompressToOutput() {

const readMePath = `${dataPath}/ipfs/blocks/_README`
if (fs.existsSync(readMePath)) {
await fs.rm(readMePath, {force: true})
await fs.promises.rm(readMePath, {force: true})
}
})
}
Expand Down Expand Up @@ -144,8 +144,8 @@ export const main = async (arg, config) => {
}
case 'clean': {
console.log('Cleaning data directory...')
await fs.rm(dataPath, { force: true, recursive: true })
await fs.mkdir(dataPath)
await fs.promises.rm(dataPath, { force: true, recursive: true })
await fs.promises.mkdir(dataPath)
return
}
}
Expand Down
1 change: 0 additions & 1 deletion packages/ens-test-env/src/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { spawn } from 'child_process'
import concurrently from 'concurrently'
import composev1 from 'docker-compose'
import composev2 from 'docker-compose/dist/v2.js'
import fetch from 'node-fetch'
import { Transform } from 'stream'
import waitOn from 'wait-on'
import { main as fetchData } from './fetch-data.js'
Expand Down
2 changes: 1 addition & 1 deletion packages/ens-test-env/src/subgraph.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { config } from 'dotenv'
import fs from 'fs'
import fs from 'node:fs'
import yaml from 'js-yaml'
import path from 'path'

Expand Down
13 changes: 7 additions & 6 deletions packages/ensjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ensdomains/ensjs",
"version": "3.7.0",
"version": "4.0.0",
"description": "ENS javascript library for contract interaction",
"type": "module",
"main": "./dist/cjs/index.js",
Expand Down Expand Up @@ -106,8 +106,7 @@
"dns-packet": "^5.3.1",
"graphql": "^16.3.0",
"graphql-request": "6.1.0",
"pako": "^2.1.0",
"traverse": "^0.6.8"
"pako": "^2.1.0"
},
"devDependencies": {
"@ensdomains/buffer": "^0.0.13",
Expand All @@ -118,21 +117,20 @@
"@openzeppelin/test-helpers": "^0.5.16",
"@swc/core": "^1.3.61",
"@types/bn.js": "^5.1.0",
"@types/fs-extra": "^11.0.1",
"@types/jsonfile": "^6.1.4",
"@types/node": "^20.3.3",
"@types/pako": "^2.0.0",
"@types/traverse": "^0.6.36",
"@vitest/coverage-v8": "^1.3.1",
"cbor": "^8.1.0",
"dotenv": "^16.0.0",
"esbuild": "^0.15.6",
"ethers": "^5.7.2",
"fs-extra": "^10.0.1",
"glob": "^8.0.3",
"happy-dom": "^13.3.8",
"hardhat": "2.16.1",
"hardhat-abi-exporter": "^2.8.0",
"hardhat-deploy": "^0.11.12",
"jsonfile": "^6.1.0",
"multiformats": "^12.0.1",
"solc": "^0.8.13",
"ts-node": "^10.9.2",
Expand All @@ -145,5 +143,8 @@
},
"peerDependencies": {
"viem": "^2.9.2"
},
"engines": {
"node": ">=18"
}
}
11 changes: 6 additions & 5 deletions packages/ensjs/scripts/prepack.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// from https://github.com/wagmi-dev/viem/blob/main/scripts/prepublishOnly.ts

/* eslint-disable no-continue */
import fs from 'fs-extra'
import jsonFs from 'jsonfile'
import fs from 'node:fs'
import path from 'path'
import * as url from 'url'

Expand All @@ -14,9 +15,9 @@ type Exports = {
// Generates a package.json to be published to NPM with only the necessary fields.
function generatePackageJson() {
const packageJsonPath = path.join(__dirname, '../package.json')
const tmpPackageJson = fs.readJsonSync(packageJsonPath)
const tmpPackageJson = jsonFs.readFileSync(packageJsonPath)

fs.writeJsonSync(`${packageJsonPath}.tmp`, tmpPackageJson, { spaces: 2 })
jsonFs.writeFileSync(`${packageJsonPath}.tmp`, tmpPackageJson, { spaces: 2 })

const {
name,
Expand Down Expand Up @@ -49,7 +50,7 @@ function generatePackageJson() {
if (!value.default || !value.import)
throw new Error('`default` and `import` are required.')

fs.outputFileSync(
fs.writeFileSync(
`${key}/package.json`,
`{
${Object.entries(value)
Expand All @@ -68,7 +69,7 @@ function generatePackageJson() {
files_.push(key.replace('./', ''))
}

fs.writeJsonSync(
jsonFs.writeFileSync(
packageJsonPath,
{
name,
Expand Down
2 changes: 1 addition & 1 deletion packages/ensjs/scripts/rcBranchVersion.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { execSync } from 'child_process'
import fs from 'fs-extra'
import fs from 'node:fs'
import path from 'path'
import * as url from 'url'

Expand Down
2 changes: 1 addition & 1 deletion packages/ensjs/scripts/updateVersion.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { execSync } from 'child_process'
import fs from 'fs-extra'
import fs from 'node:fs'
import path from 'path'
import * as url from 'url'

Expand Down
58 changes: 36 additions & 22 deletions packages/ensjs/src/functions/subgraph/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { Kind, SelectionNode, SelectionSetNode } from 'graphql'
import type { RequestMiddleware, ResponseMiddleware } from 'graphql-request'
import { GraphQLClient } from 'graphql-request'
import { parse, print, visit } from 'graphql/language/index.js'
import traverse from 'traverse'
import type { ClientWithEns } from '../../contracts/consts.js'
import { namehash } from '../../utils/normalise.js'

Expand Down Expand Up @@ -57,30 +56,45 @@ export const requestMiddleware: RequestMiddleware = (request) => {
}

export const responseMiddleware: ResponseMiddleware = (response) => {
traverse(response).forEach(function (responseItem: unknown) {
if (
responseItem instanceof Object &&
'name' in responseItem &&
responseItem.name &&
typeof responseItem.name === 'string'
) {
// Name already in hashed form
if (responseItem.name && responseItem.name.includes('[')) {
return
}
const traverse = (obj: Record<string, any>) => {
if (obj && typeof obj === 'object') {
for (const key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
const value = obj[key]

let hashedName = '[Invalid ENS Name]'
try {
hashedName = namehash(responseItem.name)
} catch (e) {
this.update({ ...responseItem, name: hashedName, invalidName: true })
return
}
if ('id' in responseItem && responseItem.id !== hashedName) {
this.update({ ...responseItem, name: hashedName, invalidName: true })
if (value && typeof value === 'object') {
traverse(value)
}

if (
value instanceof Object &&
'name' in value &&
value.name &&
typeof value.name === 'string'
) {
// Name already in hashed form
if (value.name.includes('[')) {
// eslint-disable-next-line no-continue
continue
}

let hashedName = '[Invalid ENS Name]'
try {
hashedName = namehash(value.name)
} catch (e) {
obj[key] = { ...value, name: hashedName, invalidName: true }
}

if ('id' in value && value.id !== hashedName) {
obj[key] = { ...value, name: hashedName, invalidName: true }
}
}
}
}
}
})
}

traverse(response)
}

export const createSubgraphClient = ({ client }: { client: ClientWithEns }) =>
Expand Down
Loading

0 comments on commit 597421e

Please sign in to comment.