Skip to content

Commit

Permalink
refactor: dev updates (#198)
Browse files Browse the repository at this point in the history
* wip: dev updates

* wip: refactor

* refactor: register

* fix: path

* docs: update

* ci: update workflows

* fix: tests

* fix: script

* fix: publint

* chore: changes

* chore: fix knip

* chore: knip

* test: boost coverage

* chore: symlink readme

* chore: readme

* chore: readme

* chore: tweak

* chore: changeset

* chore: update keywords
  • Loading branch information
tmm committed Oct 11, 2023
1 parent e2797ef commit a12abfd
Show file tree
Hide file tree
Showing 158 changed files with 2,250 additions and 1,639 deletions.
35 changes: 35 additions & 0 deletions .changeset/angry-walls-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
"abitype": minor
---

**Breaking**: Renamed `'abitype/test`' entrypoint to `'abitype/abis'`.

```diff
- import { erc20Abi } from 'abitype/test'
+ import { erc20Abi } from 'abitype/abis'
```

**Breaking**: Removed `zeroAddress` export from `'abitype/abis'`. You can copy it directly into your project if you still need to use it.

```diff
- import { zeroAddress } from 'abitype/abis'
+ export const zeroAddress = '0x0000000000000000000000000000000000000000' as const
```

**Breaking**: Renamed `Config`, `DefaultConfig`, and `ResolvedConfig` to `Register`, `DefaultRegister`, and `ResolvedRegister` respectively.

```diff
- import { Config, DefaultConfig, ResolvedConfig } from 'abitype'
+ import { Register, DefaultRegister, ResolvedRegister } from 'abitype'
```

To configure ABIType, target `Register` instead of `Config`:

```diff
declare module 'abitype' {
- export interface Config {
+ export interface Register {
BigIntType: bigint & { foo: 'bar' }
}
}
```
9 changes: 4 additions & 5 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
{
"$schema": "https://unpkg.com/@changesets/config@1.6.3/schema.json",
"$schema": "https://unpkg.com/@changesets/config@2.1.0/schema.json",
"access": "public",
"baseBranch": "main",
"changelog": [
"@changesets/changelog-github",
{ "repo": "wagmi-dev/abitype" }
],
"commit": false,
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": {
"onlyUpdatePeerDependentsWhenOutOfRange": true
},
"ignore": ["docs", "examples", "playground"]
}
}
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ Edit the `playground/trace.ts` file to include whatever code you want to test an
pnpm trace
```

This outputs a `trace/trace.json` file. You can open that file in a trace analysis app, like [Perfetto](https://ui.perfetto.dev) or `chrome://tracing`.
This outputs a `playgrounds/performance/out/trace.json` file. You can open that file in a trace analysis app, like [Perfetto](https://ui.perfetto.dev) or `chrome://tracing`.

<div align="right">
<a href="#advanced-guide">&uarr; back to top</a></b>
Expand Down
2 changes: 0 additions & 2 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,3 @@ body:
required: true
- label: Followed the [Code of Conduct](https://github.com/wagmi-dev/.github/blob/main/CODE_OF_CONDUCT.md).
required: true
- label: Read the [Contributing Guide](https://github.com/wagmi-dev/abitype/blob/main/.github/CONTRIBUTING.md).
required: true
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ contact_links:
about: Ask questions and discuss with other community members.
- name: Feature Request
url: https://github.com/wagmi-dev/abitype/discussions/new?category=ideas
about: Requests features or brainstorm ideas for new functionality.
about: Requests features or brainstorm ideas for new functionality.
2 changes: 1 addition & 1 deletion .github/actions/install-dependencies/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ runs:

- name: Install dependencies
shell: bash
run: pnpm install --ignore-scripts
run: pnpm install
8 changes: 4 additions & 4 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ What changes are made in this PR? Is it a feature or a bug fix?

## Additional Information

- [ ] I read the [contributing guide](https://github.com/wagmi-dev/abitype/blob/main/.github/CONTRIBUTING.md)
- [ ] I added documentation related to the changes made.
- [ ] I added or updated tests related to the changes made.
Before submitting this issue, please make sure you do the following.

Your ENS/address:
- [ ] Read the [contributing guide](https://github.com/wagmi-dev/abitype/blob/main/.github/CONTRIBUTING.md)
- [ ] Added documentation related to the changes made.
- [ ] Added or updated tests (and snapshots) related to the changes made.
37 changes: 37 additions & 0 deletions .github/workflows/canary.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Release (Canary)
on:
push:
branches: [main]
workflow_dispatch:

jobs:
canary:
name: Release canary
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- name: Clone repository
uses: actions/checkout@v4

- name: Install dependencies
uses: ./.github/actions/install-dependencies

- name: Setup .npmrc file
uses: actions/setup-node@v3
with:
registry-url: 'https://registry.npmjs.org'

- name: Set version
run: |
npm --no-git-tag-version version 0.0.0
npm --no-git-tag-version version $(npm pkg get version | sed 's/"//g')-$(git branch --show-current | tr -cs '[:alnum:]-' '-' | tr '[:upper:]' '[:lower:]' | sed 's/-$//').$(date +'%Y%m%dT%H%M%S')
pnpm bun .scripts/updateVersion.ts
- name: Build
run: pnpm build

- name: Publish to npm
run: npm publish --tag $(git branch --show-current | tr -cs '[:alnum:]-' '-' | tr '[:upper:]' '[:lower:]' | sed 's/-$//')
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Main
name: Changesets
on:
push:
branches: [main]
Expand All @@ -13,41 +13,10 @@ jobs:
uses: ./.github/workflows/verify.yml
secrets: inherit

canary:
name: Release canary
needs: verify
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- name: Clone repository
uses: actions/checkout@v4

- name: Install dependencies
uses: ./.github/actions/install-dependencies

- name: Setup .npmrc file
uses: actions/setup-node@v3
with:
registry-url: 'https://registry.npmjs.org'

- name: Set version
run: |
npm --no-git-tag-version version minor
npm --no-git-tag-version version $(npm pkg get version | sed 's/"//g')-canary.$(date +'%Y%m%dT%H%M%S')
pnpm bun scripts/updateVersion.ts
- name: Build
run: pnpm build

- name: Publish to npm
run: npm publish --tag canary
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

changesets:
name: Changesets
name: Create pull request or publish
needs: verify
permissions: write-all
runs-on: ubuntu-latest
timeout-minutes: 5

Expand All @@ -66,7 +35,8 @@ jobs:
with:
title: 'chore: version packages'
commit: 'chore: version packages'
publish: pnpm changeset:release
createGithubReleases: ${{ github.ref == 'refs/heads/main' }}
publish: pnpm changeset:publish
version: pnpm changeset:version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Pull request
name: Pull Request
on:
pull_request:
types: [opened, reopened, synchronize, ready_for_review]
Expand Down Expand Up @@ -43,4 +43,5 @@ jobs:
- name: Report build size
uses: preactjs/compressed-size-action@v2
with:
pattern: 'packages/**/dist/**'
repo-token: ${{ secrets.GITHUB_TOKEN }}
22 changes: 0 additions & 22 deletions .github/workflows/snapshot.yml

This file was deleted.

42 changes: 27 additions & 15 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Verify
on:
workflow_call:
workflow_dispatch:

jobs:
lint:
Expand All @@ -16,7 +17,18 @@ jobs:
uses: ./.github/actions/install-dependencies

- name: Lint code
run: pnpm lint
run: pnpm format && pnpm lint:fix

- name: Update package versions
run: pnpm version:update

- uses: stefanzweifel/git-auto-commit-action@v4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
commit_message: 'chore: format'
commit_user_name: 'github-actions[bot]'
commit_user_email: 'github-actions[bot]@users.noreply.github.com'

build:
name: Build
Expand All @@ -33,13 +45,19 @@ jobs:
- name: Build
run: pnpm build

- name: Publint
run: pnpm test:build

- name: Check for unused files, dependencies, and exports
run: pnpm knip --production --ignore-internal

types:
name: Types
runs-on: ubuntu-latest
timeout-minutes: 5
strategy:
matrix:
version: ['5.0.4', '5.1.3', 'latest']
version: ['5.0.4', '5.1.3', '5.2.2', 'latest']

steps:
- name: Clone repository
Expand All @@ -51,25 +69,24 @@ jobs:
- name: Use `typescript@${{ matrix.version }}`
run: pnpm add -D -w typescript@${{ matrix.version }}

- name: Build
run: pnpm build
- name: Link packages
run: pnpm preconstruct

- name: Check types
run: pnpm typecheck

- name: Check types (--exactOptionalPropertyTypes false)
run: pnpm typecheck:propertyTypes

- name: Test types
run: pnpm test:typecheck

# Redundant with `pnpm typecheck`
# If Vitest adds special features in the future, e.g. type coverage, can add this back!
# - name: Test types
# run: pnpm test:typecheck

test:
name: Test
runs-on: ubuntu-latest
timeout-minutes: 5
strategy:
matrix:
version: ['5.0.4', '5.1.3', 'latest']

steps:
- name: Clone repository
Expand All @@ -78,13 +95,8 @@ jobs:
- name: Install dependencies
uses: ./.github/actions/install-dependencies

- name: Use `typescript@${{ matrix.version }}`
run: pnpm add -D -w typescript@${{ matrix.version }}

- name: Run tests
run: pnpm test:cov

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ coverage
dist
node_modules
tsconfig*.tsbuildinfo
trace
bench
!examples/trace
playgrounds/performance/out

# local env files
.env
Expand All @@ -18,3 +17,7 @@ bench
.env.test.local
.env.production.local
.envrc

# proxy packages
packages/abitype/abis
packages/abitype/zod
5 changes: 5 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
auto-install-peers=false
enable-pre-post-scripts=true
link-workspace-packages=deep
provenance=true
strict-peer-dependencies=false
37 changes: 37 additions & 0 deletions .scripts/formatPackageJson.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import path from 'node:path'
import { glob } from 'glob'

// Generates package.json files to be published to NPM with only the necessary fields.

console.log('Formatting package.json files.')

// Get all package.json files
const packagePaths = await glob('packages/**/package.json', {
ignore: ['**/dist/**', '**/node_modules/**'],
})

let count = 0
for (const packagePath of packagePaths) {
type Package = Record<string, unknown> & {
name?: string | undefined
private?: boolean | undefined
}
const file = Bun.file(packagePath)
const packageJson = (await file.json()) as Package

// Skip private packages
if (packageJson.private) continue

count += 1
console.log(`${packageJson.name}${path.dirname(packagePath)}`)

await Bun.write(
`${packagePath}.tmp`,
`${JSON.stringify(packageJson, undefined, 2)}\n`,
)

const { devDependencies: _dD, scripts: _s, ...rest } = packageJson
await Bun.write(packagePath, `${JSON.stringify(rest, undefined, 2)}\n`)
}

console.log(`Done. Formatted ${count} ${count === 1 ? 'file' : 'files'}.`)
Loading

1 comment on commit a12abfd

@vercel
Copy link

@vercel vercel bot commented on a12abfd Oct 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

abitype – ./

abitype.vercel.app
abitype-git-main-wagmi-dev.vercel.app
abitype-wagmi-dev.vercel.app
abitype.dev

Please sign in to comment.