Skip to content

Commit

Permalink
Introduce @ensdomains/ensjs-react
Browse files Browse the repository at this point in the history
  • Loading branch information
lucemans committed Sep 4, 2024
1 parent 62914db commit 5bb43d1
Show file tree
Hide file tree
Showing 12 changed files with 427 additions and 26 deletions.
50 changes: 50 additions & 0 deletions packages/react/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"parserOptions": {
"project": "./tsconfig.json"
},
"rules": {
"no-restricted-syntax": ["off"],
"consistent-return": ["off"],
"import/no-named-as-default": ["off"],
"func-names": ["off"],
"no-param-reassign": ["off"],
"no-underscore-dangle": ["off"],
"@typescript-eslint/naming-convention": [
"error",
{
"selector": "default",
"format": ["camelCase"],
"leadingUnderscore": "allowSingleOrDouble",
"trailingUnderscore": "allowSingleOrDouble"
},
{
"selector": "memberLike",
"format": ["camelCase", "UPPER_CASE", "PascalCase"],
"leadingUnderscore": "allowSingleOrDouble",
"trailingUnderscore": "allowSingleOrDouble"
},
{
"selector": "objectLiteralProperty",
"filter": { "regex": "\\d+", "match": true },
"format": null
},
{
"selector": "variable",
"format": ["camelCase", "UPPER_CASE"],
"leadingUnderscore": "allowSingleOrDouble",
"trailingUnderscore": "allowSingleOrDouble"
},
{
"selector": "typeLike",
"format": ["PascalCase"]
}
],
"no-useless-return": ["off"],
"radix": ["error", "as-needed"],
"no-bitwise": ["off"],
"import/no-extraneous-dependencies": ["off"],
"no-empty": ["error", { "allowEmptyCatch": true }]
},
"ignorePatterns": ["node_modules", "dist", "data", "cache", "esbuild.js"]
}

8 changes: 8 additions & 0 deletions packages/react/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# hardhat
/cache
/artifacts
/coverage
README.md
LICENSE

.env.local
114 changes: 114 additions & 0 deletions packages/react/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
{
"name": "@ensdomains/ensjs-react",
"version": "4.0.1-alpha.0",
"description": "ENS javascript library for contract interaction",
"type": "module",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/types/index.d.ts",
"typings": "./dist/types/index.d.ts",
"sideEffects": false,
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"import": "./dist/esm/index.js",
"default": "./dist/cjs/index.js"
},
"./hooks": {
"types": "./dist/types/hooks.d.ts",
"import": "./dist/esm/hooks.js",
"default": "./dist/cjs/hooks.js"
},
"./package.json": "./package.json"
},
"typesVersions": {
"*": {
"hooks": [
"./dist/types/hooks/index.d.ts"
]
}
},
"files": [
"dist/",
"src/",
"!src/**/*.test.ts",
"!src/test"
],
"repository": "[email protected]:ensdomains/ensjs.git",
"author": "Lucemans <[email protected]>",
"license": "MIT",
"scripts": {
"tenv": "ens-test-env -c ./ens-test-env.config.cjs -a",
"denv": "pnpm tenv start -ns -nb --extra-time 11368000 --verbosity 1",
"anvil": "pnpm denv --no-graph",
"start": "ts-node --files src/index.test.ts",
"test": "vitest --no-file-parallelism",
"test:watch": "vitest --watch --no-file-parallelism",
"clean": "rm -rf ./dist ./README.md ./LICENSE",
"lint": "eslint ./src/* --no-error-on-unmatched-pattern",
"build:cjs": "tsc --project tsconfig.build.json --module commonjs --outDir ./dist/cjs --removeComments --verbatimModuleSyntax false && echo > ./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
"build:esm": "tsc --project tsconfig.build.json --module es2022 --outDir ./dist/esm && echo > ./dist/esm/package.json '{\"type\":\"module\",\"sideEffects\":false}'",
"build:types": "tsc --project tsconfig.build.json --module esnext --declarationDir ./dist/types --emitDeclarationOnly --declaration --declarationMap",
"build": "pnpm run clean && pnpm run build:cjs && pnpm run build:esm && pnpm run build:types",
"tsn": "TS_NODE_PROJECT=tsconfig.node.json node --loader ts-node/esm",
"prepublish": "pnpm build && cp ../../README.md ../../LICENSE ./",
"prepack": "pnpm tsn ./scripts/prepack.ts",
"ver": "pnpm tsn ./scripts/updateVersion.ts",
"generateDocs": "pnpm tsn ./scripts/generateDocs.ts",
"rcBranchVersion": "pnpm tsn ./scripts/rcBranchVersion.ts"
},
"dependencies": {
"@adraffy/ens-normalize": "1.10.1",
"@ensdomains/address-encoder": "1.1.1",
"@ensdomains/content-hash": "3.1.0-rc.1",
"@ensdomains/dnsprovejs": "^0.5.1",
"@ensdomains/ensjs": "workspace:*",
"abitype": "^1.0.0",
"dns-packet": "^5.3.1",
"graphql": "^16.3.0",
"graphql-request": "6.1.0",
"pako": "^2.1.0"
},
"devDependencies": {
"@ensdomains/buffer": "^0.0.13",
"@ensdomains/ens-contracts": "1.0.0",
"@ensdomains/ens-test-env": "workspace:*",
"@nomiclabs/hardhat-ethers": "npm:hardhat-deploy-ethers",
"@openzeppelin/contracts": "^4.5.0",
"@openzeppelin/test-helpers": "^0.5.16",
"@swc/core": "^1.3.61",
"@types/bn.js": "^5.1.0",
"@types/jsonfile": "^6.1.4",
"@types/node": "^20.3.3",
"@types/pako": "^2.0.0",
"@vitest/coverage-v8": "^1.3.1",
"cbor": "^8.1.0",
"dotenv": "^16.0.0",
"esbuild": "^0.15.6",
"ethers": "^5.7.2",
"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",
"typedoc": "^0.24.8",
"typedoc-plugin-markdown": "^4.0.0-next.16",
"typescript": "5.3.2",
"viem": "2.9.2",
"vitest": "^1.3.1",
"wait-on": "^6.0.1",
"tslib": "^2.7.0"
},
"peerDependencies": {
"@tanstack/react-query": "^5.54",
"viem": "2.9.2",
"wagmi": "2"
},
"engines": {
"node": ">=18"
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {
useQuery,
type UseQueryResult,
} from '@tanstack/react-query'
import type { ClientWithEns } from '../contracts/consts.js'
import { getAvailable } from '../public.js'
import type { ClientWithEns } from '@ensdomains/ensjs/contracts'
import { getAvailable } from '@ensdomains/ensjs/public'

export type UseEnsAvailableParams = {
name: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import type { Address } from 'viem'
import {
getNamesForAddress,
type GetNamesForAddressReturnType,
} from '../subgraph.js'
import type { ClientWithEns } from '../contracts/consts.js'
} from '@ensdomains/ensjs/subgraph'
import type { ClientWithEns } from '@ensdomains/ensjs/contracts'

export type UseNamesParams = {
address: Address
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './hooks.js'
46 changes: 46 additions & 0 deletions packages/react/tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
// This tsconfig file contains the shared config for the build (tsconfig.build.json) and type checking (tsconfig.json) config.
"include": [],
"compilerOptions": {
// Incremental builds
// NOTE: Enabling incremental builds speeds up `tsc`. Keep in mind though that it does not reliably bust the cache when the `tsconfig.json` file changes.
"incremental": false,

// Type checking
"strict": true,
"useDefineForClassFields": true, // Not enabled by default in `strict` mode unless we bump `target` to ES2022.
"noFallthroughCasesInSwitch": true, // Not enabled by default in `strict` mode.
"noImplicitReturns": true, // Not enabled by default in `strict` mode.
"useUnknownInCatchVariables": true, // TODO: This would normally be enabled in `strict` mode but would require some adjustments to the codebase.
"noImplicitOverride": true, // Not enabled by default in `strict` mode.
"noUnusedLocals": true, // Not enabled by default in `strict` mode.
"noUnusedParameters": true, // Not enabled by default in `strict` mode.
// TODO: The following options are also not enabled by default in `strict` mode and would be nice to have but would require some adjustments to the codebase.
// "exactOptionalPropertyTypes": true,
// "noUncheckedIndexedAccess": true,

// JavaScript support
"allowJs": false,
"checkJs": false,

// Interop constraints
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"verbatimModuleSyntax": true,
"importHelpers": true, // This is only used for build validation. Since we do not have `tslib` installed, this will fail if we accidentally make use of anything that'd require injection of helpers.

// Language and environment
"moduleResolution": "NodeNext",
"module": "NodeNext",
"target": "ES2021", // Setting this to `ES2021` enables native support for `Node v16+`: https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping.
"lib": [
"ES2022", // By using ES2022 we get access to the `.cause` property on `Error` instances.
"DOM" // We are adding `DOM` here to get the `fetch`, etc. types. This should be removed once these types are available via DefinitelyTyped.
],

// Skip type checking for node modules
"skipLibCheck": true
}
}

13 changes: 13 additions & 0 deletions packages/react/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "./tsconfig.json",
"include": ["./src"],
"exclude": ["src/**/*.test.ts", "src/test/**/*", "./src/ABIs/**/*"],
"compilerOptions": {
"moduleResolution": "node",
"sourceMap": true,
"rootDir": "./src",
"paths": {
"abitype": ["../node_modules/abitype/dist"]
}
}
}
17 changes: 17 additions & 0 deletions packages/react/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// This configuration is used for local development and type checking.
"extends": "./tsconfig.base.json",
"ts-node": {
"compilerOptions": {
"esModuleInterop": true,
"module": "CommonJS",
"allowSyntheticDefaultImports": true
}
},
"include": ["src", "../react/src/hooks"],
"exclude": [],
"references": [{ "path": "./tsconfig.node.json" }],
"compilerOptions": {
"resolveJsonModule": true
}
}
11 changes: 11 additions & 0 deletions packages/react/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
// This configuration is used for local development and type checking of configuration and script files that are not part of the build.
"include": ["vitest.config.ts", "scripts", "hardhat.config.cjs", "deploy"],
"compilerOptions": {
"strict": true,
"composite": true,
"module": "ESNext",
"moduleResolution": "Node",
"allowSyntheticDefaultImports": true
}
}
Loading

0 comments on commit 5bb43d1

Please sign in to comment.