Skip to content

Commit

Permalink
♻️ chore: Refactor bundler into smaller packages (#598)
Browse files Browse the repository at this point in the history
## Description

Break up bundler into smaller packages so it can build more
incrementally and be easier to navigate. Bundler is currently the
biggest package and the only package I struggle finding stuff in.

- [x] keep bundler specific code in @evmts/bundler
- [x] move runtime generation code to @evmts/runtime
- [x] move solc compiler code and solidity resolution code to
@evmts/solc
- [ ] move unplugin to a seperate package from bundler

## Testing

Explain the quality checks that have been done on the code changes

## Additional Information

- [ ] I read the [contributing docs](../docs/contributing.md) (if this
is your first contribution)

Your ENS/address:

---------

Co-authored-by: Will Cory <[email protected]>
  • Loading branch information
roninjin10 and Will Cory committed Oct 24, 2023
1 parent fda19bf commit b610ae3
Show file tree
Hide file tree
Showing 122 changed files with 2,285 additions and 790 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 2 additions & 0 deletions bundlers/bundler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
},
"dependencies": {
"@evmts/config": "workspace:^",
"@evmts/runtime": "workspace:^",
"@evmts/solc": "workspace:^",
"@evmts/tsconfig": "workspace:^",
"@types/node": "^20.7.2",
"@types/resolve": "^1.20.3",
Expand Down
13 changes: 6 additions & 7 deletions bundlers/bundler/src/bundler.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { generateDtsBody } from './runtime/generateEvmtsBodyDts.js'
import { generateRuntime } from './runtime/generateRuntime.js'
import { generateRuntimeSync } from './runtime/generateRuntimeSync.js'
import { resolveArtifacts, resolveArtifactsSync } from './solc/index.js'
// TODO wrap this in a typesafe version
// @ts-ignore
import solc from 'solc'
import {
generateDtsBody,
generateRuntime,
generateRuntimeSync,
} from '@evmts/runtime'
import { resolveArtifacts, resolveArtifactsSync } from '@evmts/solc'

/**
* @type {import('./types.js').Bundler}
Expand Down
13 changes: 9 additions & 4 deletions bundlers/bundler/src/bundler.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { bundler } from './bundler.js'
import { resolveArtifacts, resolveArtifactsSync } from './solc/index.js'
import type { SolcInputDescription, SolcOutput } from './solc/solcTypes.js'
import type { Bundler, FileAccessObject, Logger, ModuleInfo } from './types.js'
import type { Bundler, FileAccessObject, Logger } from './types.js'
import {
type ModuleInfo,
type SolcInputDescription,
type SolcOutput,
resolveArtifacts,
resolveArtifactsSync,
} from '@evmts/solc'
import type { Node } from 'solidity-ast/node.js'
import {
type Mock,
Expand Down Expand Up @@ -57,7 +62,7 @@ describe(bundler.name, () => {
}

resolver = bundler(config as any, logger, fao)
vi.mock('./solc', () => {
vi.mock('@evmts/solc', () => {
return {
resolveArtifacts: vi.fn(),
resolveArtifactsSync: vi.fn(),
Expand Down
12 changes: 0 additions & 12 deletions bundlers/bundler/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
* @typedef {import('./types.js').AsyncBundlerResult} AsyncBundlerResult
* @typedef {import('./types.js').Bundler} Bundler
* @typedef {import('./types.js').BundlerResult} BundlerResult
* @typedef {import('./types.js').CompiledContracts} CompiledContracts
* @typedef {import('./types.js').FileAccessObject} FileAccessObject
* @typedef {import('./types.js').Logger} Logger
* @typedef {import('./types.js').ModuleInfo} ModuleInfo
* @typedef {import('./types.js').SolidityResolver} SolidityResolver
* @typedef {import('./types.js').SyncBundlerResult} SyncBundlerResult
*
Expand All @@ -15,13 +13,3 @@
*/
export { bundler } from './bundler.js'
export { createCache } from './createCache.js'
export { resolveArtifacts, resolveArtifactsSync } from './solc/index.js'
export {
vitePluginEvmts,
rollupPluginEvmts,
rspackPluginEvmts,
esbuildPluginEvmts,
webpackPluginEvmts,
} from './unplugin.js'
// export * from './runtime/index.js'
// export * from './utils/index.js'
2 changes: 0 additions & 2 deletions bundlers/bundler/src/solc/index.js

This file was deleted.

21 changes: 1 addition & 20 deletions bundlers/bundler/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Cache } from './createCache.js'
import type { SolcInputDescription, SolcOutput } from './solc/solcTypes.js'
import type { ResolvedCompilerConfig } from '@evmts/config'
import type { ModuleInfo, SolcInputDescription, SolcOutput } from '@evmts/solc'
import type { Node } from 'solidity-ast/node.js'

export type BundlerResult = {
Expand Down Expand Up @@ -85,17 +85,6 @@ export type Logger = {
warn: (...message: string[]) => void
log: (...message: string[]) => void
}
/**
* Copied from rollup (kinda)
* @see https://rollupjs.org/plugin-development/#this-getmoduleinfo
*/
export interface ModuleInfo {
id: string // the id of the module, for convenience
rawCode: string | null // the source code of the module, `null` if external or not yet available
code: string | null // the code after transformed to correctly resolve remappings and node_module imports
importedIds: string[] // the module ids statically imported by this module
resolutions: ModuleInfo[] // how statically imported ids were resolved, for use with this.load
}

export type SolidityResolver = (
config: ResolvedCompilerConfig,
Expand Down Expand Up @@ -144,11 +133,3 @@ export type SolidityResolver = (
*/
resolveEsmModuleSync: (module: string, basedir: string) => BundlerResult
}

export type CompiledContracts<TIncludeAsts extends boolean = boolean> = {
artifacts: SolcOutput['contracts'][string] | undefined
modules: Record<'string', ModuleInfo>
asts: TIncludeAsts extends true ? Record<string, Node> : undefined
solcInput: SolcInputDescription
solcOutput: SolcOutput
}
8 changes: 4 additions & 4 deletions bundlers/bundler/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ export default defineConfig({
environment: 'node',
coverage: {
reporter: ['text', 'json-summary', 'json'],
lines: 99.53,
functions: 97.43,
branches: 97.18,
statements: 99.53,
lines: 100,
functions: 100,
branches: 100,
statements: 100,
thresholdAutoUpdate: true,
},
},
Expand Down
2 changes: 1 addition & 1 deletion bundlers/esbuild/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"test:ui": "vitest --ui"
},
"dependencies": {
"@evmts/bundler": "workspace:^"
"@evmts/unplugin": "workspace:^"
},
"devDependencies": {
"@evmts/tsconfig": "workspace:^",
Expand Down
4 changes: 3 additions & 1 deletion bundlers/esbuild/src/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export { esbuildPluginEvmts } from '@evmts/bundler'
import { createUnplugin, evmtsUnplugin } from '@evmts/unplugin'

export const { esbuild: esbuildPluginEvmts } = createUnplugin(evmtsUnplugin)
2 changes: 1 addition & 1 deletion bundlers/esbuild/src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { esbuildPluginEvmts } from './index.js'
import { describe, expect, it, vi } from 'vitest'

describe(esbuildPluginEvmts.name, () => {
describe('esbuildPluginEvmts', () => {
it('should properly export the unplugin bundler from @evmts/bundler', async () => {
const plugin = esbuildPluginEvmts()

Expand Down
2 changes: 1 addition & 1 deletion bundlers/rollup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"lint:check": "rome check . --verbose"
},
"dependencies": {
"@evmts/bundler": "workspace:^"
"@evmts/unplugin": "workspace:^"
},
"devDependencies": {
"@evmts/tsconfig": "workspace:^",
Expand Down
4 changes: 3 additions & 1 deletion bundlers/rollup/src/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export { rollupPluginEvmts } from '@evmts/bundler'
import { createUnplugin, evmtsUnplugin } from '@evmts/unplugin'

export const { rollup: rollupPluginEvmts } = createUnplugin(evmtsUnplugin)
2 changes: 1 addition & 1 deletion bundlers/rspack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"test:ui": "vitest --ui"
},
"dependencies": {
"@evmts/bundler": "workspace:^"
"@evmts/unplugin": "workspace:^"
},
"devDependencies": {
"@evmts/tsconfig": "workspace:^",
Expand Down
4 changes: 3 additions & 1 deletion bundlers/rspack/src/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export { rspackPluginEvmts } from '@evmts/bundler'
import { createUnplugin, evmtsUnplugin } from '@evmts/unplugin'

export const { rspack: rspackPluginEvmts } = createUnplugin(evmtsUnplugin)
50 changes: 50 additions & 0 deletions bundlers/unplugin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
.env

cache
forge-artifacts
broadcast
types

# compiled output
dist
packages/*/dist
tmp
/out-tsc
**/tsconfig.tsbuildinfo

# dependencies
node_modules

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

**/lcov.info

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# misc
/.sass-cache
/connect.lock
/coverage
/libpeerconnection.log
npm-debug.log
testem.log
/typings

# System Files
.DS_Store
Thumbs.db

# My personal files
.zshrc
22 changes: 22 additions & 0 deletions bundlers/unplugin/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(The MIT License)

Copyright 2020-2022

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 changes: 37 additions & 0 deletions bundlers/unplugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<p align="center">
<a href="https://evmts.dev/">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/35039927/218812217-92f0f784-cb85-43b9-9ca6-e2b9effd9eb2.png">
<img alt="wagmi logo" src="https://user-images.githubusercontent.com/35039927/218812217-92f0f784-cb85-43b9-9ca6-e2b9effd9eb2.png" width="auto" height="300">
</picture>
</a>
</p>

<p align="center">
Execute solidity scripts in browser
</p>

[![CI](https://github.com/evmts/evmts-monorepo/actions/workflows/e2e.yml/badge.svg)](https://github.com/evmts/evmts-monorepo/actions/workflows/e2e.yml)
[![CI](https://github.com/evmts/evmts-monorepo/actions/workflows/unit.yml/badge.svg)](https://github.com/evmts/evmts-monorepo/actions/workflows/unit.yml)
<a href="https://www.npmjs.com/package/@evmts/core" target="\_parent">
<img alt="" src="https://img.shields.io/npm/dm/@evmts/core.svg" />
</a>
<a href="https://bundlephobia.com/package/@evmts/core@latest" target="\_parent">
<img alt="" src="https://badgen.net/bundlephobia/minzip/@evmts/core" />
</a>

# @evmts/unplugin

[unplugin](https://github.com/unjs/unplugin) plugin for EVMts. Unplugin allows us to build a rollup plugin once and reuse it for many different bundlers.

Used in following packages

- [@evmts/esbuild](https://github.com/evmts/evmts-monorepo/tree/main/bundlers/esbuild)
- [@evmts/rollup](https://github.com/evmts/evmts-monorepo/tree/main/bundlers/rollup)
- [@evmts/rspack](https://github.com/evmts/evmts-monorepo/tree/main/bundlers/rspack)
- [@evmts/vite](https://github.com/evmts/evmts-monorepo/tree/main/bundlers/vite)
- [@evmts/webpack](https://github.com/evmts/evmts-monorepo/tree/main/bundlers/webpack)

## License 📄

<a href="./LICENSE"><img src="https://user-images.githubusercontent.com/35039927/231030761-66f5ce58-a4e9-4695-b1fe-255b1bceac92.png" width="200" /></a>
86 changes: 86 additions & 0 deletions bundlers/unplugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"name": "@evmts/unplugin",
"version": "0.11.2",
"private": false,
"description": "Internal unplugin for Evmts",
"keywords": [
"solidity",
"forge",
"foundry",
"sol",
"typescript",
"web3",
"blockchain"
],
"repository": {
"type": "git",
"url": "https://github.com/evmts/evmts-monorepo.git",
"directory": "bundlers/unplugin"
},
"license": "MIT",
"contributors": ["Will Cory <[email protected]>"],
"type": "module",
"main": "dist/index.cjs",
"module": "src/index.js",
"types": "types/src/index.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"import": "./src/index.js",
"require": "./dist/index.cjs",
"types": "./types/src/index.d.ts",
"default": "./dist/index.cjs"
}
},
"files": ["dist", "types", "src"],
"scripts": {
"build": "nx run-many --targets=build:dist,build:types --projects=@evmts/unplugin ",
"build:dist": "bun run tsup",
"build:types": "bun run tsc --emitDeclarationOnly",
"clean": "rm -rf node_modules && rm -rf artifacts && rm -rf dist && rm -rf cache",
"format": "rome format . --write",
"format:check": "rome format .",
"generate:docs": "bun run typedoc",
"lint": "rome check . --apply-unsafe",
"lint:check": "rome check . --verbose",
"test": "vitest --coverage",
"test:coverage": "vitest run --coverage",
"test:run": "vitest run",
"test:ui": "vitest --ui"
},
"dependencies": {
"@evmts/config": "workspace:^",
"@evmts/runtime": "workspace:^",
"@evmts/solc": "workspace:^",
"@evmts/tsconfig": "workspace:^",
"@types/node": "^20.7.2",
"@types/resolve": "^1.20.3",
"effect": "2.0.0-next.50",
"glob": "^10.3.10",
"resolve": "^1.22.6",
"solidity-ast": "^0.4.52",
"unplugin": "^1.5.0"
},
"devDependencies": {
"@vitest/coverage-v8": "^0.34.6",
"@vitest/ui": "^0.34.6",
"@evmts/core": "workspace:^",
"@evmts/bundler": "workspace:^",
"abitype": "^0.9.8",
"rome": "^12.1.3",
"solc": "0.8.21",
"tsup": "^7.2.0",
"typedoc": "^0.25.2",
"typedoc-plugin-markdown": "^3.16.0",
"typescript": "^5.2.2",
"vitest": "^0.34.6",
"wagmi": "^1.4.2",
"zod": "^3.22.2"
},
"peerDependencies": {
"solc": ">0.8.10"
},
"publishConfig": {
"access": "public"
}
}
Loading

1 comment on commit b610ae3

@vercel
Copy link

@vercel vercel bot commented on b610ae3 Oct 24, 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:

evmts-docs – ./

evmts-docs-evmts.vercel.app
evmts.dev
evmts-docs-git-main-evmts.vercel.app

Please sign in to comment.