-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Feat: Add support for json configs (#757)
## Description Added support for tevm.json configs for configuring tevm ## 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: <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced a new configuration option `cacheDir` to specify the directory for build cache storage. - Added support for JSON configurations in Tevm. - **Bug Fixes** - Fixed a bug in the `parseJson` function to return type `unknown` for more flexible JSON parsing. - **Documentation** - Updated documentation to reflect the new `cacheDir` option and error class renaming. - **Refactor** - Renamed error class `NoPluginFoundError` to `NoPluginInTsConfigFoundError` for clearer error messaging. - Enhanced `loadConfig` function to support loading JSON configurations. - Adjusted `mergeConfigs` function to handle `debug` and `cacheDir` properties. - **Style** - Updated `vitest.config.ts` to refine the `branches` threshold value for code coverage. - **Tests** - Modified test cases to account for new `cacheDir` property and error class renaming. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Will Cory <[email protected]> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
- Loading branch information
1 parent
a9be500
commit d1affad
Showing
31 changed files
with
242 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@tevm/config": minor | ||
--- | ||
|
||
Added support for json configs in Tevm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@tevm/effect": patch | ||
--- | ||
|
||
Fixed bug in @tevm/effect where return type of parseJson was hardcoded instead of unknown |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"cacheDir": ".cache", | ||
"libs": ["mylib"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
["invalid", "tsconfig.json"] |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"extends": "@tevm/tsconfig/base.json", | ||
"compilerOptions": { | ||
"composite": true, | ||
"outDir": "types", | ||
"skipLibCheck": true, | ||
"plugins": [ | ||
{ | ||
"name": "@tevm/ts-plugin", | ||
"cacheDir": ".cache", | ||
"libs": [ | ||
"mylib" | ||
] | ||
} | ||
], | ||
"paths": { | ||
"@/*": [ | ||
"./*" | ||
] | ||
} | ||
}, | ||
"include": [ | ||
"src", | ||
"src/**/*.json" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
// should load the remappings | ||
"foundryProject": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { | ||
InvalidConfigError, | ||
validateUserConfig, | ||
} from '../config/validateUserConfig.js' | ||
import { parseJson } from '@tevm/effect' | ||
import { | ||
catchTag, | ||
die, | ||
fail, | ||
flatMap, | ||
logDebug, | ||
tap, | ||
try as tryEffect, | ||
} from 'effect/Effect' | ||
import { readFileSync } from 'fs' | ||
import * as path from 'path' | ||
|
||
export class FailedToReadConfigError extends Error { | ||
/** | ||
* @type {'FailedToReadConfigError'} | ||
*/ | ||
_tag = 'FailedToReadConfigError' | ||
/** | ||
* @param {string} configFilePath | ||
* @param {object} [options] | ||
* @param {unknown} [options.cause] | ||
*/ | ||
constructor(configFilePath, options) { | ||
super(`Failed to find ${configFilePath}/tevm.json`, options) | ||
} | ||
} | ||
|
||
/** | ||
* TypeError thrown when the user provided config factory is incorrectly typed | ||
* @internal | ||
*/ | ||
export class InvalidJsonConfigError extends TypeError { | ||
/** | ||
* @type {'InvalidJsonConfigError'} | ||
* @override | ||
*/ | ||
name = 'InvalidJsonConfigError' | ||
/** | ||
* @type {'InvalidJsonConfigError'} | ||
*/ | ||
_tag = 'InvalidJsonConfigError' | ||
/** | ||
* @param {object} [options] | ||
* @param {unknown} [options.cause] | ||
*/ | ||
constructor(options) { | ||
super('Invalid tsconfig.json detected', options) | ||
} | ||
} | ||
|
||
/** | ||
* @typedef {import("@tevm/effect").ParseJsonError | FailedToReadConfigError | InvalidJsonConfigError | InvalidConfigError} LoadJsonConfigError | ||
* @internal | ||
*/ | ||
|
||
/** | ||
* Synchronously loads a Tevm config from the given path | ||
* @param {string} configFilePath | ||
* @returns {import("effect/Effect").Effect<never, LoadJsonConfigError, import('../types.js').CompilerConfig>} the contents of the tsconfig.json file | ||
* @internal | ||
*/ | ||
export const loadJsonConfig = (configFilePath) => { | ||
const tevmConfigPath = path.join(configFilePath, 'tevm.json') | ||
return tryEffect({ | ||
try: () => readFileSync(tevmConfigPath, 'utf8'), | ||
catch: (cause) => new FailedToReadConfigError(configFilePath, { cause }), | ||
}).pipe( | ||
flatMap(parseJson), | ||
catchTag('ParseJsonError', (cause) => | ||
fail(new InvalidJsonConfigError({ cause })), | ||
), | ||
flatMap((cfg) => | ||
validateUserConfig( | ||
() => /** @type {import('../types.js').CompilerConfig}*/ (cfg), | ||
), | ||
), | ||
// it can't throw. Could clean this up via making validateUserConfig take a config instead of a factory | ||
catchTag('ConfigFnThrowError', (e) => die(e)), | ||
tap((tsConfig) => | ||
logDebug( | ||
`loading tsconfig from ${configFilePath}: ${JSON.stringify(tsConfig)}`, | ||
), | ||
), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
d1affad
There was a problem hiding this comment.
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