Change type extensions handling#8191
Conversation
🦋 Changeset detectedLatest commit: 2a4ae8e The changes in this PR will be included in the next version bump. This PR includes changesets to release 17 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Pull request overview
Refactors Hardhat and its official plugins to load TypeScript type extensions via export type * re-exports instead of runtime imports, so compiled JavaScript no longer executes unnecessary type-extension imports.
Changes:
- Replace runtime
import "./type-extensions.js"patterns withexport type * from "./type-extensions.js"across built-in and external plugins. - Remove side-effect-only imports inside type-extension files, relying on module augmentation without runtime loading.
- Update the shared TS config to force module detection (
moduleDetection: "force") to support augmentation-only modules.
Reviewed changes
Copilot reviewed 54 out of 56 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/hardhat/src/types/plugins.ts | Switches built-in type-extension loading to a type-only re-export. |
| packages/hardhat/src/types/config.ts | Removes built-in plugin import from the hardhat/types/config entry point. |
| packages/hardhat/src/internal/builtin-plugins/test/type-extensions.ts | Removes side-effect import from test plugin type extensions. |
| packages/hardhat/src/internal/builtin-plugins/test/index.ts | Uses type-only re-export to load type extensions without runtime import. |
| packages/hardhat/src/internal/builtin-plugins/solidity/type-extensions.ts | Removes multiple side-effect imports; relies on module augmentation. |
| packages/hardhat/src/internal/builtin-plugins/solidity/index.ts | Uses type-only re-export to load type extensions without runtime import. |
| packages/hardhat/src/internal/builtin-plugins/solidity-test/type-extensions.ts | Removes side-effect import from solidity-test plugin type extensions. |
| packages/hardhat/src/internal/builtin-plugins/solidity-test/index.ts | Uses type-only re-export to load type extensions without runtime import. |
| packages/hardhat/src/internal/builtin-plugins/network-manager/type-extensions/hre.ts | Removes side-effect import from HRE type extension. |
| packages/hardhat/src/internal/builtin-plugins/network-manager/type-extensions/hooks.ts | Removes side-effect import from hooks type extension. |
| packages/hardhat/src/internal/builtin-plugins/network-manager/type-extensions/global-options.ts | Removes side-effect import from global-options type extension. |
| packages/hardhat/src/internal/builtin-plugins/network-manager/type-extensions/config.ts | Removes side-effect import from config type extension. |
| packages/hardhat/src/internal/builtin-plugins/network-manager/index.ts | Uses type-only re-exports for each type-extension module. |
| packages/hardhat/src/internal/builtin-plugins/index.ts | Centralizes type-only re-exports to ensure built-in type extensions are reachable. |
| packages/hardhat/src/internal/builtin-plugins/gas-analytics/type-extensions.ts | Removes side-effect import from gas-analytics type extensions. |
| packages/hardhat/src/internal/builtin-plugins/gas-analytics/index.ts | Uses type-only re-export to load type extensions without runtime import. |
| packages/hardhat/src/internal/builtin-plugins/coverage/type-extensions.ts | Removes side-effect import from coverage type extensions. |
| packages/hardhat/src/internal/builtin-plugins/coverage/index.ts | Uses type-only re-export to load type extensions without runtime import. |
| packages/hardhat/src/internal/builtin-plugins/clean/type-extensions.ts | Removes side-effect import from clean type extensions. |
| packages/hardhat/src/internal/builtin-plugins/clean/index.ts | Uses type-only re-export to load type extensions without runtime import. |
| packages/hardhat/src/internal/builtin-plugins/artifacts/index.ts | Uses type-only re-export to load type extensions without runtime import. |
| packages/hardhat/src/index.ts | Loads built-in type extensions via type-only re-export instead of runtime import. |
| packages/hardhat/src/hre.ts | Loads built-in type extensions via type-only re-export instead of runtime import. |
| packages/hardhat/src/config.ts | Loads built-in type extensions via type-only re-export instead of runtime import. |
| packages/hardhat-viem/src/type-extensions.ts | Removes side-effect import from type extensions. |
| packages/hardhat-viem/src/index.ts | Uses type-only re-export to load type extensions without runtime import. |
| packages/hardhat-viem-assertions/src/type-extensions.ts | Replaces runtime dependency import with type-only re-export. |
| packages/hardhat-viem-assertions/src/index.ts | Uses type-only re-export to load type extensions without runtime import. |
| packages/hardhat-verify/src/type-extensions.ts | Removes side-effect imports from type extensions. |
| packages/hardhat-verify/src/index.ts | Uses type-only re-export to load type extensions without runtime import. |
| packages/hardhat-typechain/src/type-extensions.ts | Adds type-only re-export of dependency and removes side-effect imports. |
| packages/hardhat-typechain/src/index.ts | Uses type-only re-export to load type extensions without runtime import. |
| packages/hardhat-toolbox-viem/src/index.ts | Uses type-only re-export to load type extensions without runtime import. |
| packages/hardhat-toolbox-mocha-ethers/src/index.ts | Uses type-only re-export to load type extensions without runtime import. |
| packages/hardhat-solx/src/type-extensions.ts | Removes side-effect import from type extensions. |
| packages/hardhat-solx/src/index.ts | Uses type-only re-export to load type extensions without runtime import. |
| packages/hardhat-node-test-runner/src/type-extensions.ts | Removes side-effect import from type extensions. |
| packages/hardhat-node-test-runner/src/index.ts | Uses type-only re-export to load type extensions without runtime import. |
| packages/hardhat-network-helpers/src/type-extensions.ts | Removes side-effect import from type extensions. |
| packages/hardhat-network-helpers/src/index.ts | Uses type-only re-export to load type extensions without runtime import. |
| packages/hardhat-mocha/src/type-extensions.ts | Removes side-effect imports from type extensions. |
| packages/hardhat-mocha/src/index.ts | Uses type-only re-export to load type extensions without runtime import. |
| packages/hardhat-ledger/src/type-extensions.ts | Removes side-effect import from type extensions. |
| packages/hardhat-ledger/src/index.ts | Uses type-only re-export to load type extensions without runtime import. |
| packages/hardhat-keystore/src/internal/type-extensions.ts | Removes side-effect import from type extensions. |
| packages/hardhat-keystore/src/index.ts | Uses type-only re-export to load type extensions without runtime import. |
| packages/hardhat-ignition/src/type-extensions.ts | Removes side-effect import and adds type-only dependency re-export. |
| packages/hardhat-ignition/src/index.ts | Uses type-only re-export to load type extensions without runtime import. |
| packages/hardhat-ignition-viem/src/index.ts | Uses type-only re-export to load type extensions without runtime import. |
| packages/hardhat-ignition-ethers/src/internal/ethers-ignition-helper.ts | Removes runtime-only dependency imports from helper implementation. |
| packages/hardhat-ignition-ethers/src/index.ts | Uses type-only re-export to load type extensions without runtime import. |
| packages/hardhat-ethers/src/type-extensions.ts | Removes side-effect import from type extensions. |
| packages/hardhat-ethers/src/index.ts | Uses type-only re-export to load type extensions without runtime import. |
| packages/hardhat-ethers-chai-matchers/src/type-extensions.ts | Adds type-only dependency re-export to ensure dependent augmentations load. |
| packages/hardhat-ethers-chai-matchers/src/index.ts | Uses type-only re-export to load type extensions without runtime import. |
| packages/config/tsconfig.base.json | Forces module detection to support augmentation-only modules. |
Comments suppressed due to low confidence (1)
packages/hardhat/src/types/config.ts:5
hardhat/types/configno longer references the built-in plugins, so importing this entry point will stop applying the built-in type extensions (e.g. thesolidity,network, etc config augmentations). Since./types/configis a published export (seepackages/hardhat/package.json), this looks like a breaking change for users who importHardhatUserConfigfromhardhat/types/config. Consider adding a type-only re-export (similar totypes/plugins.ts) so built-in config extensions are still loaded without introducing runtime imports, or otherwise ensurehardhat/types/configcontinues to include built-in augmentations.
|
Added 'no docs needed", the docs chnges are in the plugin development guide, and tracked by an issue. |
Previously, we recommended users to import 'hardhat/types/config' directly in their config, so that was the place where we loaded the built-in plugin types. Now we recommend importing `hardhat/config`'s `defineConfig` function, so we need to load the built-in plugin's type extensions there. We removed the `export type *` from `types/config`, because otherwise we have a circular dependency between it and the built-in plugin extensions, which breaks them.
fe35923 to
e2bc2e3
Compare
e2bc2e3 to
2a4ae8e
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 71 out of 73 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
packages/hardhat/src/types/config.ts:5
hardhat/types/configno longer ensures that built-in plugin type-extensions are part of the type graph (previously done via importing../internal/builtin-plugins/index.js). This can regress users that only doimport type { HardhatUserConfig } from "hardhat/types/config"(e.g. inhardhat.config.ts) because built-in config fields likesolidity,networks,plugins, etc. may disappear unless they also importhardhat/configorhardhat/types/plugins. Consider adding a type-only re-export here (e.g.export type * from "../internal/builtin-plugins/index.js";) to preserve the old behavior without introducing runtime imports.
This is the first change to complete this:
It reworked how we handle type-extensions preventing Hardhat from importing every single type files. It currently only imports the ones with
enums.