hardhat 3.4.0 → 3.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -0
- package/dist/src/cli.js +5 -5
- package/dist/src/cli.js.map +1 -1
- package/dist/src/internal/builtin-plugins/artifacts/artifact-manager.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/artifacts/artifact-manager.js +11 -4
- package/dist/src/internal/builtin-plugins/artifacts/artifact-manager.js.map +1 -1
- package/dist/src/internal/builtin-plugins/artifacts/hook-handlers/hre.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/artifacts/hook-handlers/hre.js +10 -10
- package/dist/src/internal/builtin-plugins/artifacts/hook-handlers/hre.js.map +1 -1
- package/dist/src/internal/builtin-plugins/clean/index.js +1 -1
- package/dist/src/internal/builtin-plugins/clean/index.js.map +1 -1
- package/dist/src/internal/builtin-plugins/console/index.js +1 -1
- package/dist/src/internal/builtin-plugins/console/index.js.map +1 -1
- package/dist/src/internal/builtin-plugins/coverage/exports.d.ts +1 -1
- package/dist/src/internal/builtin-plugins/coverage/exports.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/coverage/exports.js +1 -1
- package/dist/src/internal/builtin-plugins/coverage/exports.js.map +1 -1
- package/dist/src/internal/builtin-plugins/coverage/helpers/accessors.d.ts +7 -0
- package/dist/src/internal/builtin-plugins/coverage/helpers/accessors.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/coverage/helpers/accessors.js +24 -0
- package/dist/src/internal/builtin-plugins/coverage/helpers/accessors.js.map +1 -0
- package/dist/src/internal/builtin-plugins/coverage/helpers/compat.d.ts +4 -0
- package/dist/src/internal/builtin-plugins/coverage/helpers/compat.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/coverage/helpers/compat.js +27 -0
- package/dist/src/internal/builtin-plugins/coverage/helpers/compat.js.map +1 -0
- package/dist/src/internal/builtin-plugins/coverage/hook-handlers/clean.js +1 -1
- package/dist/src/internal/builtin-plugins/coverage/hook-handlers/clean.js.map +1 -1
- package/dist/src/internal/builtin-plugins/coverage/hook-handlers/hre.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/coverage/hook-handlers/hre.js +18 -15
- package/dist/src/internal/builtin-plugins/coverage/hook-handlers/hre.js.map +1 -1
- package/dist/src/internal/builtin-plugins/coverage/hook-handlers/solidity.js +3 -3
- package/dist/src/internal/builtin-plugins/coverage/hook-handlers/solidity.js.map +1 -1
- package/dist/src/internal/builtin-plugins/coverage/hook-handlers/test.js +1 -1
- package/dist/src/internal/builtin-plugins/coverage/hook-handlers/test.js.map +1 -1
- package/dist/src/internal/builtin-plugins/flatten/index.js +1 -1
- package/dist/src/internal/builtin-plugins/flatten/index.js.map +1 -1
- package/dist/src/internal/builtin-plugins/gas-analytics/helpers/accessors.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/gas-analytics/helpers/accessors.js +10 -4
- package/dist/src/internal/builtin-plugins/gas-analytics/helpers/accessors.js.map +1 -1
- package/dist/src/internal/builtin-plugins/gas-analytics/hook-handlers/hre.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/gas-analytics/hook-handlers/hre.js +18 -14
- package/dist/src/internal/builtin-plugins/gas-analytics/hook-handlers/hre.js.map +1 -1
- package/dist/src/internal/builtin-plugins/gas-analytics/index.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/gas-analytics/index.js +2 -2
- package/dist/src/internal/builtin-plugins/gas-analytics/index.js.map +1 -1
- package/dist/src/internal/builtin-plugins/gas-analytics/snapshot-cheatcodes.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/gas-analytics/snapshot-cheatcodes.js +2 -7
- package/dist/src/internal/builtin-plugins/gas-analytics/snapshot-cheatcodes.js.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/config-resolution.js +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/config-resolution.js.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/edr/edr-constants.d.ts +14 -0
- package/dist/src/internal/builtin-plugins/network-manager/edr/edr-constants.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/network-manager/edr/edr-constants.js +40 -0
- package/dist/src/internal/builtin-plugins/network-manager/edr/edr-constants.js.map +1 -0
- package/dist/src/internal/builtin-plugins/network-manager/edr/edr-provider.d.ts +1 -12
- package/dist/src/internal/builtin-plugins/network-manager/edr/edr-provider.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/edr/edr-provider.js +3 -42
- package/dist/src/internal/builtin-plugins/network-manager/edr/edr-provider.js.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/edr/genesis-state.js +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/edr/genesis-state.js.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/edr/types/hardfork.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/edr/types/hardfork.js +2 -5
- package/dist/src/internal/builtin-plugins/network-manager/edr/types/hardfork.js.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/edr/utils/convert-to-edr.js +2 -2
- package/dist/src/internal/builtin-plugins/network-manager/edr/utils/convert-to-edr.js.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/hook-handlers/hre.js +4 -4
- package/dist/src/internal/builtin-plugins/network-manager/hook-handlers/hre.js.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/hook-handlers/network.js +2 -2
- package/dist/src/internal/builtin-plugins/network-manager/hook-handlers/network.js.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/http-provider.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/http-provider.js +2 -2
- package/dist/src/internal/builtin-plugins/network-manager/http-provider.js.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/network-manager.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/network-manager.js +7 -7
- package/dist/src/internal/builtin-plugins/network-manager/network-manager.js.map +1 -1
- package/dist/src/internal/builtin-plugins/node/helpers.js +2 -2
- package/dist/src/internal/builtin-plugins/node/helpers.js.map +1 -1
- package/dist/src/internal/builtin-plugins/node/index.js +1 -1
- package/dist/src/internal/builtin-plugins/node/index.js.map +1 -1
- package/dist/src/internal/builtin-plugins/run/index.js +1 -1
- package/dist/src/internal/builtin-plugins/run/index.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/build-system.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/build-system.js +61 -28
- package/dist/src/internal/builtin-plugins/solidity/build-system/build-system.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/compilation-job.js +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/compilation-job.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/compiler/downloader.js +4 -4
- package/dist/src/internal/builtin-plugins/solidity/build-system/compiler/downloader.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/compiler/index.js +2 -2
- package/dist/src/internal/builtin-plugins/solidity/build-system/compiler/index.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/compiler/solcjs-runner.js +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/compiler/solcjs-runner.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/dependency-graph-building.js +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/dependency-graph-building.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/read-source-file.js +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/read-source-file.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/dependency-resolver.js +10 -10
- package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/dependency-resolver.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/remapped-npm-packages-graph.js +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/remapped-npm-packages-graph.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/hook-handlers/config.js +1 -1
- package/dist/src/internal/builtin-plugins/solidity/hook-handlers/config.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/hook-handlers/hre.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/hook-handlers/hre.js +16 -11
- package/dist/src/internal/builtin-plugins/solidity/hook-handlers/hre.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/index.js +1 -1
- package/dist/src/internal/builtin-plugins/solidity/index.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/solidity-hooks.js +1 -1
- package/dist/src/internal/builtin-plugins/solidity/solidity-hooks.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/tasks/build.js +4 -4
- package/dist/src/internal/builtin-plugins/solidity/tasks/build.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/edr-artifacts.js +2 -2
- package/dist/src/internal/builtin-plugins/solidity-test/edr-artifacts.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/hook-handlers/config.js +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/hook-handlers/config.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/hook-handlers/test.js +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/hook-handlers/test.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/index.js +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/index.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/reporter.js +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/reporter.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/task-action.js +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/task-action.js.map +1 -1
- package/dist/src/internal/builtin-plugins/telemetry/index.js +1 -1
- package/dist/src/internal/builtin-plugins/telemetry/index.js.map +1 -1
- package/dist/src/internal/builtin-plugins/test/hook-handlers/config.js +1 -1
- package/dist/src/internal/builtin-plugins/test/hook-handlers/config.js.map +1 -1
- package/dist/src/internal/builtin-plugins/test/index.js +1 -1
- package/dist/src/internal/builtin-plugins/test/index.js.map +1 -1
- package/dist/src/internal/builtin-plugins/test/task-action.js +1 -1
- package/dist/src/internal/builtin-plugins/test/task-action.js.map +1 -1
- package/dist/src/internal/cli/init/init.d.ts.map +1 -1
- package/dist/src/internal/cli/init/init.js +18 -9
- package/dist/src/internal/cli/init/init.js.map +1 -1
- package/dist/src/internal/cli/init/template.d.ts.map +1 -1
- package/dist/src/internal/cli/init/template.js +5 -14
- package/dist/src/internal/cli/init/template.js.map +1 -1
- package/dist/src/internal/cli/main.d.ts.map +1 -1
- package/dist/src/internal/cli/main.js +4 -2
- package/dist/src/internal/cli/main.js.map +1 -1
- package/dist/src/internal/cli/node-version.d.ts +1 -1
- package/dist/src/internal/cli/node-version.d.ts.map +1 -1
- package/dist/src/internal/cli/node-version.js +18 -8
- package/dist/src/internal/cli/node-version.js.map +1 -1
- package/dist/src/internal/cli/telemetry/analytics/analytics.js +2 -2
- package/dist/src/internal/cli/telemetry/analytics/analytics.js.map +1 -1
- package/dist/src/internal/cli/telemetry/error-reporter/global-error-handlers.d.ts +6 -0
- package/dist/src/internal/cli/telemetry/error-reporter/global-error-handlers.d.ts.map +1 -0
- package/dist/src/internal/cli/telemetry/error-reporter/global-error-handlers.js +47 -0
- package/dist/src/internal/cli/telemetry/error-reporter/global-error-handlers.js.map +1 -0
- package/dist/src/internal/cli/telemetry/error-reporter/reporter.d.ts +27 -0
- package/dist/src/internal/cli/telemetry/error-reporter/reporter.d.ts.map +1 -0
- package/dist/src/internal/cli/telemetry/error-reporter/reporter.js +40 -0
- package/dist/src/internal/cli/telemetry/error-reporter/reporter.js.map +1 -0
- package/dist/src/internal/cli/telemetry/sentry/anonymizer.js +1 -1
- package/dist/src/internal/cli/telemetry/sentry/anonymizer.js.map +1 -1
- package/dist/src/internal/cli/telemetry/sentry/init.d.ts +0 -8
- package/dist/src/internal/cli/telemetry/sentry/init.d.ts.map +1 -1
- package/dist/src/internal/cli/telemetry/sentry/init.js +1 -37
- package/dist/src/internal/cli/telemetry/sentry/init.js.map +1 -1
- package/dist/src/internal/cli/telemetry/sentry/reporter.d.ts +8 -2
- package/dist/src/internal/cli/telemetry/sentry/reporter.d.ts.map +1 -1
- package/dist/src/internal/cli/telemetry/sentry/reporter.js +18 -12
- package/dist/src/internal/cli/telemetry/sentry/reporter.js.map +1 -1
- package/dist/src/internal/cli/telemetry/sentry/transport.js +1 -1
- package/dist/src/internal/cli/telemetry/sentry/transport.js.map +1 -1
- package/dist/src/internal/cli/telemetry/telemetry-permissions.js +1 -1
- package/dist/src/internal/cli/telemetry/telemetry-permissions.js.map +1 -1
- package/dist/src/internal/config-loading.js +3 -3
- package/dist/src/internal/config-loading.js.map +1 -1
- package/dist/src/internal/core/configuration-variables.d.ts.map +1 -1
- package/dist/src/internal/core/configuration-variables.js +1 -1
- package/dist/src/internal/core/configuration-variables.js.map +1 -1
- package/dist/src/internal/core/hook-manager.d.ts.map +1 -1
- package/dist/src/internal/core/hook-manager.js +196 -59
- package/dist/src/internal/core/hook-manager.js.map +1 -1
- package/dist/src/internal/core/hre.d.ts.map +1 -1
- package/dist/src/internal/core/hre.js +5 -5
- package/dist/src/internal/core/hre.js.map +1 -1
- package/dist/src/internal/core/lazy-user-interruptions.d.ts +11 -0
- package/dist/src/internal/core/lazy-user-interruptions.d.ts.map +1 -0
- package/dist/src/internal/core/lazy-user-interruptions.js +39 -0
- package/dist/src/internal/core/lazy-user-interruptions.js.map +1 -0
- package/dist/src/internal/core/plugins/resolve-plugin-list.js +1 -1
- package/dist/src/internal/core/plugins/resolve-plugin-list.js.map +1 -1
- package/dist/src/internal/core/tasks/resolved-task.js +4 -4
- package/dist/src/internal/core/tasks/resolved-task.js.map +1 -1
- package/dist/src/internal/core/user-interruptions.js +9 -9
- package/dist/src/internal/core/user-interruptions.js.map +1 -1
- package/dist/src/internal/hre-initialization.js +1 -1
- package/dist/src/internal/hre-initialization.js.map +1 -1
- package/package.json +4 -4
- package/src/cli.ts +5 -5
- package/src/internal/builtin-plugins/artifacts/artifact-manager.ts +13 -6
- package/src/internal/builtin-plugins/artifacts/hook-handlers/hre.ts +16 -10
- package/src/internal/builtin-plugins/clean/index.ts +1 -1
- package/src/internal/builtin-plugins/console/index.ts +1 -1
- package/src/internal/builtin-plugins/coverage/exports.ts +1 -1
- package/src/internal/builtin-plugins/coverage/helpers/accessors.ts +44 -0
- package/src/internal/builtin-plugins/coverage/helpers/compat.ts +37 -0
- package/src/internal/builtin-plugins/coverage/hook-handlers/clean.ts +1 -1
- package/src/internal/builtin-plugins/coverage/hook-handlers/hre.ts +26 -16
- package/src/internal/builtin-plugins/coverage/hook-handlers/solidity.ts +3 -3
- package/src/internal/builtin-plugins/coverage/hook-handlers/test.ts +1 -1
- package/src/internal/builtin-plugins/flatten/index.ts +1 -1
- package/src/internal/builtin-plugins/gas-analytics/helpers/accessors.ts +12 -5
- package/src/internal/builtin-plugins/gas-analytics/hook-handlers/hre.ts +29 -17
- package/src/internal/builtin-plugins/gas-analytics/index.ts +4 -2
- package/src/internal/builtin-plugins/gas-analytics/snapshot-cheatcodes.ts +2 -6
- package/src/internal/builtin-plugins/network-manager/config-resolution.ts +1 -1
- package/src/internal/builtin-plugins/network-manager/edr/edr-constants.ts +61 -0
- package/src/internal/builtin-plugins/network-manager/edr/edr-provider.ts +3 -62
- package/src/internal/builtin-plugins/network-manager/edr/genesis-state.ts +1 -1
- package/src/internal/builtin-plugins/network-manager/edr/types/hardfork.ts +3 -9
- package/src/internal/builtin-plugins/network-manager/edr/utils/convert-to-edr.ts +2 -2
- package/src/internal/builtin-plugins/network-manager/hook-handlers/hre.ts +4 -4
- package/src/internal/builtin-plugins/network-manager/hook-handlers/network.ts +2 -2
- package/src/internal/builtin-plugins/network-manager/http-provider.ts +6 -2
- package/src/internal/builtin-plugins/network-manager/network-manager.ts +11 -7
- package/src/internal/builtin-plugins/node/helpers.ts +2 -2
- package/src/internal/builtin-plugins/node/index.ts +1 -1
- package/src/internal/builtin-plugins/run/index.ts +1 -1
- package/src/internal/builtin-plugins/solidity/build-system/build-system.ts +84 -49
- package/src/internal/builtin-plugins/solidity/build-system/compilation-job.ts +1 -1
- package/src/internal/builtin-plugins/solidity/build-system/compiler/downloader.ts +4 -4
- package/src/internal/builtin-plugins/solidity/build-system/compiler/index.ts +2 -2
- package/src/internal/builtin-plugins/solidity/build-system/compiler/solcjs-runner.ts +1 -1
- package/src/internal/builtin-plugins/solidity/build-system/dependency-graph-building.ts +1 -1
- package/src/internal/builtin-plugins/solidity/build-system/read-source-file.ts +2 -2
- package/src/internal/builtin-plugins/solidity/build-system/resolver/dependency-resolver.ts +11 -11
- package/src/internal/builtin-plugins/solidity/build-system/resolver/remapped-npm-packages-graph.ts +1 -1
- package/src/internal/builtin-plugins/solidity/hook-handlers/config.ts +1 -1
- package/src/internal/builtin-plugins/solidity/hook-handlers/hre.ts +27 -14
- package/src/internal/builtin-plugins/solidity/index.ts +1 -1
- package/src/internal/builtin-plugins/solidity/solidity-hooks.ts +1 -1
- package/src/internal/builtin-plugins/solidity/tasks/build.ts +4 -4
- package/src/internal/builtin-plugins/solidity-test/edr-artifacts.ts +2 -2
- package/src/internal/builtin-plugins/solidity-test/hook-handlers/config.ts +1 -1
- package/src/internal/builtin-plugins/solidity-test/hook-handlers/test.ts +1 -1
- package/src/internal/builtin-plugins/solidity-test/index.ts +1 -1
- package/src/internal/builtin-plugins/solidity-test/reporter.ts +1 -1
- package/src/internal/builtin-plugins/solidity-test/task-action.ts +1 -1
- package/src/internal/builtin-plugins/telemetry/index.ts +1 -1
- package/src/internal/builtin-plugins/test/hook-handlers/config.ts +1 -1
- package/src/internal/builtin-plugins/test/index.ts +1 -1
- package/src/internal/builtin-plugins/test/task-action.ts +1 -1
- package/src/internal/cli/init/init.ts +32 -14
- package/src/internal/cli/init/template.ts +22 -27
- package/src/internal/cli/main.ts +5 -3
- package/src/internal/cli/node-version.ts +21 -10
- package/src/internal/cli/telemetry/analytics/analytics.ts +2 -2
- package/src/internal/cli/telemetry/error-reporter/global-error-handlers.ts +64 -0
- package/src/internal/cli/telemetry/error-reporter/reporter.ts +49 -0
- package/src/internal/cli/telemetry/sentry/anonymizer.ts +1 -1
- package/src/internal/cli/telemetry/sentry/init.ts +2 -62
- package/src/internal/cli/telemetry/sentry/reporter.ts +27 -15
- package/src/internal/cli/telemetry/sentry/transport.ts +1 -1
- package/src/internal/cli/telemetry/telemetry-permissions.ts +1 -1
- package/src/internal/config-loading.ts +3 -3
- package/src/internal/core/configuration-variables.ts +19 -18
- package/src/internal/core/hook-manager.ts +267 -103
- package/src/internal/core/hre.ts +7 -5
- package/src/internal/core/lazy-user-interruptions.ts +75 -0
- package/src/internal/core/plugins/resolve-plugin-list.ts +1 -1
- package/src/internal/core/tasks/resolved-task.ts +4 -4
- package/src/internal/core/user-interruptions.ts +9 -9
- package/src/internal/hre-initialization.ts +1 -1
- package/templates/hardhat-3/01-node-test-runner-viem/package.json +10 -10
- package/templates/hardhat-3/02-mocha-ethers/package.json +13 -13
- package/templates/hardhat-3/03-minimal/package.json +1 -1
- package/dist/src/internal/builtin-plugins/coverage/helpers.d.ts +0 -15
- package/dist/src/internal/builtin-plugins/coverage/helpers.d.ts.map +0 -1
- package/dist/src/internal/builtin-plugins/coverage/helpers.js +0 -35
- package/dist/src/internal/builtin-plugins/coverage/helpers.js.map +0 -1
- package/src/internal/builtin-plugins/coverage/helpers.ts +0 -63
|
@@ -23,35 +23,94 @@ export class HookManagerImplementation implements HookManager {
|
|
|
23
23
|
|
|
24
24
|
readonly #projectRoot: string;
|
|
25
25
|
|
|
26
|
-
readonly #pluginsInReverseOrder: HardhatPlugin[];
|
|
27
|
-
|
|
28
26
|
/**
|
|
27
|
+
* The context passed to hook handlers, except to the `config` ones, to break
|
|
28
|
+
* a circular dependency between the config and the hook handler.
|
|
29
|
+
*
|
|
29
30
|
* Initially `undefined` to be able to run the config hooks during
|
|
30
31
|
* initialization.
|
|
31
32
|
*/
|
|
32
33
|
#context: HookContext | undefined;
|
|
33
34
|
|
|
34
35
|
/**
|
|
35
|
-
*
|
|
36
|
+
* Plugins that provide hook handlers for each category, in reverse order.
|
|
37
|
+
*
|
|
38
|
+
* Precomputed from the plugin list at construction.
|
|
39
|
+
*/
|
|
40
|
+
readonly #pluginsByHookCategory: Map<keyof HardhatHooks, HardhatPlugin[]> =
|
|
41
|
+
new Map();
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Cached resolved category objects per hook category in reverse plugin
|
|
45
|
+
* order.
|
|
46
|
+
*
|
|
47
|
+
* Only written by #getStaticHookHandlerCategories, which uses a mutex to
|
|
48
|
+
* ensure that every Hook Category Factory is run once per HookManager
|
|
49
|
+
* instance.
|
|
36
50
|
*/
|
|
37
|
-
readonly #
|
|
38
|
-
|
|
39
|
-
|
|
51
|
+
readonly #resolvedStaticCategories: Map<
|
|
52
|
+
keyof HardhatHooks,
|
|
53
|
+
Array<Partial<HardhatHooks[keyof HardhatHooks]>>
|
|
40
54
|
> = new Map();
|
|
41
55
|
|
|
42
56
|
/**
|
|
43
57
|
* A map of the dynamically registered handler categories.
|
|
44
58
|
*
|
|
45
59
|
* Each array is a list of categories, in reverse order of registration.
|
|
60
|
+
*
|
|
61
|
+
* Written by registerHandlers and unregisterHandlers.
|
|
46
62
|
*/
|
|
47
63
|
readonly #dynamicHookHandlerCategories: Map<
|
|
48
64
|
keyof HardhatHooks,
|
|
49
65
|
Array<Partial<HardhatHooks[keyof HardhatHooks]>>
|
|
50
66
|
> = new Map();
|
|
51
67
|
|
|
68
|
+
/**
|
|
69
|
+
* Cached combined (dynamic + static) handlers per (category, hook name) in
|
|
70
|
+
* chained running order.
|
|
71
|
+
*
|
|
72
|
+
* Only written by #getHandlersInChainedRunningOrder, and invalidated
|
|
73
|
+
* per-category on dynamic handlers register/unregister.
|
|
74
|
+
*/
|
|
75
|
+
readonly #chainedHandlers: Map<keyof HardhatHooks, Map<string, any[]>> =
|
|
76
|
+
new Map();
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Cached combined handlers per (category, hook name) in sequential running
|
|
80
|
+
* order (reverse of chained).
|
|
81
|
+
*
|
|
82
|
+
* Only written by #getHandlersInSequentialRunningOrder, and invalidated
|
|
83
|
+
* per-category on dynamic handlers register/unregister.
|
|
84
|
+
*/
|
|
85
|
+
readonly #sequentialHandlers: Map<keyof HardhatHooks, Map<string, any[]>> =
|
|
86
|
+
new Map();
|
|
87
|
+
|
|
52
88
|
constructor(projectRoot: string, plugins: HardhatPlugin[]) {
|
|
53
89
|
this.#projectRoot = projectRoot;
|
|
54
|
-
|
|
90
|
+
|
|
91
|
+
for (const plugin of plugins.toReversed()) {
|
|
92
|
+
if (plugin.hookHandlers === undefined) {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
for (const hookCategoryName of Object.keys(plugin.hookHandlers) as Array<
|
|
97
|
+
keyof HardhatHooks
|
|
98
|
+
>) {
|
|
99
|
+
if (plugin.hookHandlers[hookCategoryName] === undefined) {
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
let pluginsForCategory =
|
|
104
|
+
this.#pluginsByHookCategory.get(hookCategoryName);
|
|
105
|
+
|
|
106
|
+
if (pluginsForCategory === undefined) {
|
|
107
|
+
pluginsForCategory = [];
|
|
108
|
+
this.#pluginsByHookCategory.set(hookCategoryName, pluginsForCategory);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
pluginsForCategory.push(plugin);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
55
114
|
}
|
|
56
115
|
|
|
57
116
|
public setContext(context: HookContext): void {
|
|
@@ -69,6 +128,8 @@ export class HookManagerImplementation implements HookManager {
|
|
|
69
128
|
}
|
|
70
129
|
|
|
71
130
|
categories.unshift(hookHandlerCategory);
|
|
131
|
+
|
|
132
|
+
this.#invalidateResolvedHandlersCache(hookCategoryName);
|
|
72
133
|
}
|
|
73
134
|
|
|
74
135
|
public unregisterHandlers<HookCategoryNameT extends keyof HardhatHooks>(
|
|
@@ -84,6 +145,8 @@ export class HookManagerImplementation implements HookManager {
|
|
|
84
145
|
hookCategoryName,
|
|
85
146
|
categories.filter((c) => c !== hookHandlerCategory),
|
|
86
147
|
);
|
|
148
|
+
|
|
149
|
+
this.#invalidateResolvedHandlersCache(hookCategoryName);
|
|
87
150
|
}
|
|
88
151
|
|
|
89
152
|
public async runHandlerChain<
|
|
@@ -96,10 +159,23 @@ export class HookManagerImplementation implements HookManager {
|
|
|
96
159
|
params: InitialChainedHookParams<HookCategoryNameT, HookT>,
|
|
97
160
|
defaultImplementation: LastParameter<HookT>,
|
|
98
161
|
): Promise<Awaited<Return<HardhatHooks[HookCategoryNameT][HookNameT]>>> {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
162
|
+
// Synchronous fast path for already cached handlers. This duplicates
|
|
163
|
+
// the check inside #getHandlersInChainedRunningOrder on purpose:
|
|
164
|
+
// calling that async method introduces a microtask tick even on a
|
|
165
|
+
// cache hit, whereas a direct Map lookup stays on the current tick.
|
|
166
|
+
// That tick matters here because runHandlerChain is on every hook's
|
|
167
|
+
// hot path, and this path pairs with the empty-handlers shortcut
|
|
168
|
+
// below to dispatch straight to defaultImplementation with no awaits.
|
|
169
|
+
const cachedHandlers = this.#chainedHandlers
|
|
170
|
+
.get(hookCategoryName)
|
|
171
|
+
?.get(hookName as string);
|
|
172
|
+
|
|
173
|
+
const handlers =
|
|
174
|
+
cachedHandlers ??
|
|
175
|
+
(await this.#getHandlersInChainedRunningOrder(
|
|
176
|
+
hookCategoryName,
|
|
177
|
+
hookName,
|
|
178
|
+
));
|
|
103
179
|
|
|
104
180
|
let handlerParams: Parameters<typeof defaultImplementation>;
|
|
105
181
|
if (hookCategoryName !== "config") {
|
|
@@ -113,6 +189,13 @@ export class HookManagerImplementation implements HookManager {
|
|
|
113
189
|
handlerParams = params as any;
|
|
114
190
|
}
|
|
115
191
|
|
|
192
|
+
// Fast path for the common case of no registered handlers: skip building
|
|
193
|
+
// handlerParams and the `next` closure, and call the default implementation
|
|
194
|
+
// directly.
|
|
195
|
+
if (handlers.length === 0) {
|
|
196
|
+
return (await defaultImplementation(...handlerParams)) as any;
|
|
197
|
+
}
|
|
198
|
+
|
|
116
199
|
const numberOfHandlers = handlers.length;
|
|
117
200
|
let index = 0;
|
|
118
201
|
const next = async (...nextParams: typeof handlerParams) => {
|
|
@@ -124,7 +207,7 @@ export class HookManagerImplementation implements HookManager {
|
|
|
124
207
|
return result;
|
|
125
208
|
};
|
|
126
209
|
|
|
127
|
-
return next(...handlerParams);
|
|
210
|
+
return await next(...handlerParams);
|
|
128
211
|
}
|
|
129
212
|
|
|
130
213
|
public async runSequentialHandlers<
|
|
@@ -192,7 +275,7 @@ export class HookManagerImplementation implements HookManager {
|
|
|
192
275
|
handlerParams = params;
|
|
193
276
|
}
|
|
194
277
|
|
|
195
|
-
return Promise.all(
|
|
278
|
+
return await Promise.all(
|
|
196
279
|
handlers.map((handler) => (handler as any)(...handlerParams)),
|
|
197
280
|
);
|
|
198
281
|
}
|
|
@@ -220,14 +303,48 @@ export class HookManagerImplementation implements HookManager {
|
|
|
220
303
|
hookCategoryName: HookCategoryNameT,
|
|
221
304
|
hookName: HookNameT,
|
|
222
305
|
): Promise<Array<HardhatHooks[HookCategoryNameT][HookNameT]>> {
|
|
223
|
-
|
|
306
|
+
let handlersByName = this.#chainedHandlers.get(hookCategoryName);
|
|
307
|
+
if (handlersByName === undefined) {
|
|
308
|
+
handlersByName = new Map();
|
|
309
|
+
this.#chainedHandlers.set(hookCategoryName, handlersByName);
|
|
310
|
+
}
|
|
224
311
|
|
|
225
|
-
const
|
|
312
|
+
const cached = handlersByName.get(hookName as string);
|
|
313
|
+
if (cached !== undefined) {
|
|
314
|
+
return cached;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
const staticCategories =
|
|
318
|
+
await this.#getStaticHookHandlerCategories(hookCategoryName);
|
|
319
|
+
|
|
320
|
+
// IMPORTANT NOTE: Accessing the dynamic hook handlers MUST happen
|
|
321
|
+
// after awaiting the static ones. See
|
|
322
|
+
// #invalidateResolvedHandlersCache for more info.
|
|
323
|
+
const dynamicCategories = this.#dynamicHookHandlerCategories.get(
|
|
226
324
|
hookCategoryName,
|
|
227
|
-
|
|
228
|
-
|
|
325
|
+
) as Array<Partial<HardhatHooks[HookCategoryNameT]>> | undefined;
|
|
326
|
+
|
|
327
|
+
const handlers: Array<HardhatHooks[HookCategoryNameT][HookNameT]> = [];
|
|
229
328
|
|
|
230
|
-
|
|
329
|
+
if (dynamicCategories !== undefined) {
|
|
330
|
+
for (const category of dynamicCategories) {
|
|
331
|
+
const handler = category[hookName];
|
|
332
|
+
if (handler !== undefined) {
|
|
333
|
+
handlers.push(handler as HardhatHooks[HookCategoryNameT][HookNameT]);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
for (const category of staticCategories) {
|
|
339
|
+
const handler = category[hookName];
|
|
340
|
+
if (handler !== undefined) {
|
|
341
|
+
handlers.push(handler as HardhatHooks[HookCategoryNameT][HookNameT]);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
handlersByName.set(hookName as string, handlers);
|
|
346
|
+
|
|
347
|
+
return handlers;
|
|
231
348
|
}
|
|
232
349
|
|
|
233
350
|
async #getHandlersInSequentialRunningOrder<
|
|
@@ -237,111 +354,158 @@ export class HookManagerImplementation implements HookManager {
|
|
|
237
354
|
hookCategoryName: HookCategoryNameT,
|
|
238
355
|
hookName: HookNameT,
|
|
239
356
|
): Promise<Array<HardhatHooks[HookCategoryNameT][HookNameT]>> {
|
|
240
|
-
|
|
357
|
+
let handlersByName = this.#sequentialHandlers.get(hookCategoryName);
|
|
358
|
+
if (handlersByName === undefined) {
|
|
359
|
+
handlersByName = new Map();
|
|
360
|
+
this.#sequentialHandlers.set(hookCategoryName, handlersByName);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
const cached = handlersByName.get(hookName as string);
|
|
364
|
+
if (cached !== undefined) {
|
|
365
|
+
return cached;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
const chained = await this.#getHandlersInChainedRunningOrder(
|
|
241
369
|
hookCategoryName,
|
|
242
370
|
hookName,
|
|
243
371
|
);
|
|
244
372
|
|
|
245
|
-
|
|
373
|
+
const sequential = chained.toReversed();
|
|
374
|
+
|
|
375
|
+
handlersByName.set(hookName as string, sequential);
|
|
376
|
+
|
|
377
|
+
return sequential;
|
|
246
378
|
}
|
|
247
379
|
|
|
248
|
-
async #
|
|
380
|
+
async #getStaticHookHandlerCategories<
|
|
249
381
|
HookCategoryNameT extends keyof HardhatHooks,
|
|
250
|
-
HookNameT extends keyof HardhatHooks[HookCategoryNameT],
|
|
251
382
|
>(
|
|
252
383
|
hookCategoryName: HookCategoryNameT,
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
) as Array<Partial<HardhatHooks[HookCategoryNameT]>> | undefined;
|
|
384
|
+
): Promise<Array<Partial<HardhatHooks[HookCategoryNameT]>>> {
|
|
385
|
+
const cached = this.#resolvedStaticCategories.get(hookCategoryName) as
|
|
386
|
+
| Array<Partial<HardhatHooks[HookCategoryNameT]>>
|
|
387
|
+
| undefined;
|
|
258
388
|
|
|
259
|
-
if (
|
|
389
|
+
if (cached !== undefined) {
|
|
390
|
+
return cached;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
const plugins = this.#pluginsByHookCategory.get(hookCategoryName);
|
|
394
|
+
|
|
395
|
+
// We don't need to get the mutex to resolve this case, as it will always
|
|
396
|
+
// be an empty array, and won't execute any factory.
|
|
397
|
+
if (plugins === undefined) {
|
|
398
|
+
this.#resolvedStaticCategories.set(hookCategoryName, []);
|
|
260
399
|
return [];
|
|
261
400
|
}
|
|
262
401
|
|
|
263
|
-
return
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
402
|
+
return await this.#mutex.exclusiveRun(async () => {
|
|
403
|
+
// Re-check under the mutex in case another caller just populated it.
|
|
404
|
+
const recheck = this.#resolvedStaticCategories.get(hookCategoryName) as
|
|
405
|
+
| Array<Partial<HardhatHooks[HookCategoryNameT]>>
|
|
406
|
+
| undefined;
|
|
407
|
+
|
|
408
|
+
if (recheck !== undefined) {
|
|
409
|
+
return recheck;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
const resolved = await Promise.all(
|
|
413
|
+
plugins.map(
|
|
414
|
+
async (plugin) =>
|
|
415
|
+
await this.#getPluginStaticHookCategory(plugin, hookCategoryName),
|
|
416
|
+
),
|
|
417
|
+
);
|
|
418
|
+
|
|
419
|
+
this.#resolvedStaticCategories.set(hookCategoryName, resolved);
|
|
420
|
+
|
|
421
|
+
return resolved;
|
|
267
422
|
});
|
|
268
423
|
}
|
|
269
424
|
|
|
270
|
-
|
|
425
|
+
/**
|
|
426
|
+
* Returns the hook category object for a plugin that has the hook category
|
|
427
|
+
* defined.
|
|
428
|
+
*
|
|
429
|
+
* @param plugin A plugin that MUST have the given hook category defined.
|
|
430
|
+
* @param hookCategoryName The name of the hook category.
|
|
431
|
+
* @returns The hook category object.
|
|
432
|
+
*/
|
|
433
|
+
async #getPluginStaticHookCategory<
|
|
271
434
|
HookCategoryNameT extends keyof HardhatHooks,
|
|
272
|
-
HookNameT extends keyof HardhatHooks[HookCategoryNameT],
|
|
273
435
|
>(
|
|
436
|
+
plugin: HardhatPlugin,
|
|
274
437
|
hookCategoryName: HookCategoryNameT,
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
const categories: Array<
|
|
278
|
-
Partial<HardhatHooks[HookCategoryNameT]> | undefined
|
|
279
|
-
> = await this.#mutex.exclusiveRun(async () => {
|
|
280
|
-
return Promise.all(
|
|
281
|
-
this.#pluginsInReverseOrder.map(async (plugin) => {
|
|
282
|
-
const existingCategory = this.#staticHookHandlerCategories
|
|
283
|
-
.get(plugin.id)
|
|
284
|
-
?.get(hookCategoryName);
|
|
285
|
-
|
|
286
|
-
if (existingCategory !== undefined) {
|
|
287
|
-
return existingCategory as Partial<HardhatHooks[HookCategoryNameT]>;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
const hookHandlerCategoryFactory =
|
|
291
|
-
plugin.hookHandlers?.[hookCategoryName];
|
|
292
|
-
|
|
293
|
-
if (hookHandlerCategoryFactory === undefined) {
|
|
294
|
-
return;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
let factory;
|
|
298
|
-
try {
|
|
299
|
-
factory = (await hookHandlerCategoryFactory()).default;
|
|
300
|
-
} catch (error) {
|
|
301
|
-
ensureError(error);
|
|
302
|
-
|
|
303
|
-
await detectPluginNpmDependencyProblems(
|
|
304
|
-
this.#projectRoot,
|
|
305
|
-
plugin,
|
|
306
|
-
error,
|
|
307
|
-
);
|
|
308
|
-
|
|
309
|
-
throw error;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
assertHardhatInvariant(
|
|
313
|
-
typeof factory === "function",
|
|
314
|
-
`Plugin ${plugin.id} doesn't export a hook factory for category ${hookCategoryName}`,
|
|
315
|
-
);
|
|
316
|
-
|
|
317
|
-
const hookCategory = await factory();
|
|
318
|
-
|
|
319
|
-
assertHardhatInvariant(
|
|
320
|
-
hookCategory !== null && typeof hookCategory === "object",
|
|
321
|
-
`Plugin ${plugin.id} doesn't export a valid factory for category ${hookCategoryName}, it didn't return an object`,
|
|
322
|
-
);
|
|
323
|
-
|
|
324
|
-
if (!this.#staticHookHandlerCategories.has(plugin.id)) {
|
|
325
|
-
this.#staticHookHandlerCategories.set(plugin.id, new Map());
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- Defined right above
|
|
329
|
-
this.#staticHookHandlerCategories
|
|
330
|
-
.get(plugin.id)!
|
|
331
|
-
.set(hookCategoryName, hookCategory);
|
|
332
|
-
|
|
333
|
-
return hookCategory;
|
|
334
|
-
}),
|
|
335
|
-
);
|
|
336
|
-
});
|
|
438
|
+
): Promise<Partial<HardhatHooks[HookCategoryNameT]>> {
|
|
439
|
+
const hookHandlerCategoryFactory = plugin.hookHandlers?.[hookCategoryName];
|
|
337
440
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
}
|
|
441
|
+
assertHardhatInvariant(
|
|
442
|
+
hookHandlerCategoryFactory !== undefined,
|
|
443
|
+
"#pluginsByHookCategory only contains plugins with this hook category",
|
|
444
|
+
);
|
|
343
445
|
|
|
344
|
-
|
|
345
|
-
|
|
446
|
+
let factory;
|
|
447
|
+
try {
|
|
448
|
+
factory = (await hookHandlerCategoryFactory()).default;
|
|
449
|
+
} catch (error) {
|
|
450
|
+
ensureError(error);
|
|
451
|
+
|
|
452
|
+
await detectPluginNpmDependencyProblems(this.#projectRoot, plugin, error);
|
|
453
|
+
|
|
454
|
+
throw error;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
assertHardhatInvariant(
|
|
458
|
+
typeof factory === "function",
|
|
459
|
+
`Plugin ${plugin.id} doesn't export a hook factory for category ${hookCategoryName}`,
|
|
460
|
+
);
|
|
461
|
+
|
|
462
|
+
const hookCategory = await factory();
|
|
463
|
+
|
|
464
|
+
assertHardhatInvariant(
|
|
465
|
+
hookCategory !== null && typeof hookCategory === "object",
|
|
466
|
+
`Plugin ${plugin.id} doesn't export a valid factory for category ${hookCategoryName}, it didn't return an object`,
|
|
467
|
+
);
|
|
468
|
+
|
|
469
|
+
return hookCategory;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
#invalidateResolvedHandlersCache<
|
|
473
|
+
HookCategoryNameT extends keyof HardhatHooks,
|
|
474
|
+
>(hookCategoryName: HookCategoryNameT) {
|
|
475
|
+
// Invalidation deletes the outer entry rather than clearing the inner
|
|
476
|
+
// map. This matters under concurrency.
|
|
477
|
+
//
|
|
478
|
+
// A reader of #getHandlersInChainedRunningOrder (or its sequential
|
|
479
|
+
// sibling) captures a reference to the inner map before awaiting the
|
|
480
|
+
// static categories, and writes its computed array back after the
|
|
481
|
+
// await. If invalidation runs during that await, deleting the outer
|
|
482
|
+
// entry leaves the reader's inner map orphaned: its write lands in a
|
|
483
|
+
// map no longer reachable from #chainedHandlers/#sequentialHandlers,
|
|
484
|
+
// so it cannot poison the shared cache. The next reader sees
|
|
485
|
+
// `undefined`, installs a fresh inner map, and rebuilds from the
|
|
486
|
+
// current dynamic state.
|
|
487
|
+
//
|
|
488
|
+
// Two distinct properties make this safe, guaranteed by two different
|
|
489
|
+
// things:
|
|
490
|
+
//
|
|
491
|
+
// 1. The in-flight reader's own return value is correct. This is
|
|
492
|
+
// because #getHandlersInChainedRunningOrder reads
|
|
493
|
+
// #dynamicHookHandlerCategories *after* awaiting the static
|
|
494
|
+
// categories. Any invalidation that happened during the await is
|
|
495
|
+
// visible to the reader when it resumes, so the array it builds
|
|
496
|
+
// reflects the current dynamic state.
|
|
497
|
+
//
|
|
498
|
+
// 2. The shared cache never holds a stale array. This is guaranteed
|
|
499
|
+
// by the orphaning-by-delete described above: a reader that
|
|
500
|
+
// started before the invalidation can only write into an
|
|
501
|
+
// unreachable inner map.
|
|
502
|
+
//
|
|
503
|
+
// Property 1 depends on the ordering of the dynamic handlers read relative
|
|
504
|
+
// to the await. If that read ever moved *before* the await, a reader
|
|
505
|
+
// could build a stale array and return it to its caller — the cache
|
|
506
|
+
// would still be protected by property 2, but the reader's caller
|
|
507
|
+
// would see the stale result.
|
|
508
|
+
this.#chainedHandlers.delete(hookCategoryName);
|
|
509
|
+
this.#sequentialHandlers.delete(hookCategoryName);
|
|
346
510
|
}
|
|
347
511
|
}
|
package/src/internal/core/hre.ts
CHANGED
|
@@ -40,9 +40,9 @@ import {
|
|
|
40
40
|
resolveGlobalOptions,
|
|
41
41
|
} from "./global-options.js";
|
|
42
42
|
import { HookManagerImplementation } from "./hook-manager.js";
|
|
43
|
+
import { LazyUserInterruptionManager } from "./lazy-user-interruptions.js";
|
|
43
44
|
import { resolvePluginList } from "./plugins/resolve-plugin-list.js";
|
|
44
45
|
import { TaskManagerImplementation } from "./tasks/task-manager.js";
|
|
45
|
-
import { UserInterruptionManagerImplementation } from "./user-interruptions.js";
|
|
46
46
|
|
|
47
47
|
export class HardhatRuntimeEnvironmentImplementation
|
|
48
48
|
implements HardhatRuntimeEnvironment
|
|
@@ -134,7 +134,7 @@ export class HardhatRuntimeEnvironmentImplementation
|
|
|
134
134
|
|
|
135
135
|
// Set the HookContext in the hook manager so that non-config hooks can
|
|
136
136
|
// use it
|
|
137
|
-
const interruptions = new
|
|
137
|
+
const interruptions = new LazyUserInterruptionManager(hooks);
|
|
138
138
|
|
|
139
139
|
const hre = new HardhatRuntimeEnvironmentImplementation(
|
|
140
140
|
extendedUserConfig,
|
|
@@ -193,7 +193,9 @@ export class HardhatRuntimeEnvironmentImplementation
|
|
|
193
193
|
export async function resolveProjectRoot(
|
|
194
194
|
absolutePathWithinProject: string | undefined,
|
|
195
195
|
): Promise<string> {
|
|
196
|
-
return findClosestPackageRoot(
|
|
196
|
+
return await findClosestPackageRoot(
|
|
197
|
+
absolutePathWithinProject ?? process.cwd(),
|
|
198
|
+
);
|
|
197
199
|
}
|
|
198
200
|
|
|
199
201
|
/**
|
|
@@ -292,7 +294,7 @@ async function runUserConfigExtensions(
|
|
|
292
294
|
hooks: HookManager,
|
|
293
295
|
config: HardhatUserConfig,
|
|
294
296
|
): Promise<HardhatUserConfig> {
|
|
295
|
-
return hooks.runHandlerChain(
|
|
297
|
+
return await hooks.runHandlerChain(
|
|
296
298
|
"config",
|
|
297
299
|
"extendUserConfig",
|
|
298
300
|
[config],
|
|
@@ -320,7 +322,7 @@ async function resolveUserConfig(
|
|
|
320
322
|
paths: resolvePaths(projectRoot, configPath, config.paths),
|
|
321
323
|
} as HardhatConfig;
|
|
322
324
|
|
|
323
|
-
return hooks.runHandlerChain(
|
|
325
|
+
return await hooks.runHandlerChain(
|
|
324
326
|
"config",
|
|
325
327
|
"resolveUserConfig",
|
|
326
328
|
[config, (variable) => resolveConfigurationVariable(hooks, variable)],
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { UserInterruptionManagerImplementation as UserInterruptionManagerImplementationT } from "./user-interruptions.js";
|
|
2
|
+
import type { HookManager } from "../../types/hooks.js";
|
|
3
|
+
import type { UserInterruptionManager } from "../../types/user-interruptions.js";
|
|
4
|
+
|
|
5
|
+
let UserInterruptionManagerImplementation:
|
|
6
|
+
| typeof UserInterruptionManagerImplementationT
|
|
7
|
+
| undefined;
|
|
8
|
+
|
|
9
|
+
export class LazyUserInterruptionManager implements UserInterruptionManager {
|
|
10
|
+
readonly #hooks: HookManager;
|
|
11
|
+
|
|
12
|
+
#userInterruptionManager: UserInterruptionManagerImplementationT | undefined;
|
|
13
|
+
|
|
14
|
+
constructor(hooks: HookManager) {
|
|
15
|
+
this.#hooks = hooks;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public async displayMessage(
|
|
19
|
+
interruptor: string,
|
|
20
|
+
message: string,
|
|
21
|
+
): Promise<void> {
|
|
22
|
+
const userInterruptionManager = await this.#getUserInterruptionManager();
|
|
23
|
+
return await userInterruptionManager.displayMessage(interruptor, message);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public async requestInput(
|
|
27
|
+
interruptor: string,
|
|
28
|
+
inputDescription: string,
|
|
29
|
+
): Promise<string> {
|
|
30
|
+
const userInterruptionManager = await this.#getUserInterruptionManager();
|
|
31
|
+
return await userInterruptionManager.requestInput(
|
|
32
|
+
interruptor,
|
|
33
|
+
inputDescription,
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public async requestSecretInput(
|
|
38
|
+
interruptor: string,
|
|
39
|
+
inputDescription: string,
|
|
40
|
+
): Promise<string> {
|
|
41
|
+
const userInterruptionManager = await this.#getUserInterruptionManager();
|
|
42
|
+
return await userInterruptionManager.requestSecretInput(
|
|
43
|
+
interruptor,
|
|
44
|
+
inputDescription,
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public async uninterrupted<ReturnT>(
|
|
49
|
+
f: () => ReturnT,
|
|
50
|
+
): Promise<Awaited<ReturnT>> {
|
|
51
|
+
const userInterruptionManager = await this.#getUserInterruptionManager();
|
|
52
|
+
return await userInterruptionManager.uninterrupted(f);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async #getUserInterruptionManager(): Promise<UserInterruptionManagerImplementationT> {
|
|
56
|
+
// Note: `await import` must run BEFORE the instance cache check so that
|
|
57
|
+
// concurrent callers share a single microtask-dedupe point — otherwise
|
|
58
|
+
// each suspended caller re-enters the branch and constructs its own
|
|
59
|
+
// impl, so callers end up holding different impl instances and state,
|
|
60
|
+
// which can cause concurrency issues.
|
|
61
|
+
if (UserInterruptionManagerImplementation === undefined) {
|
|
62
|
+
({ UserInterruptionManagerImplementation } = await import(
|
|
63
|
+
"./user-interruptions.js"
|
|
64
|
+
));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (this.#userInterruptionManager === undefined) {
|
|
68
|
+
this.#userInterruptionManager = new UserInterruptionManagerImplementation(
|
|
69
|
+
this.#hooks,
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return this.#userInterruptionManager;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -12,7 +12,7 @@ export async function resolvePluginList(
|
|
|
12
12
|
projectRoot: string,
|
|
13
13
|
userConfigPluginList: HardhatPlugin[] = [],
|
|
14
14
|
): Promise<HardhatPlugin[]> {
|
|
15
|
-
return reverseTopologicalSort(projectRoot, userConfigPluginList);
|
|
15
|
+
return await reverseTopologicalSort(projectRoot, userConfigPluginList);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/**
|
|
@@ -175,22 +175,22 @@ export class ResolvedTask implements Task {
|
|
|
175
175
|
if (currentIndex === 0) {
|
|
176
176
|
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions --
|
|
177
177
|
We know that the first action in the array is a NewTaskActionFunction */
|
|
178
|
-
return (actionFn as NewTaskActionFunction)(
|
|
178
|
+
return await (actionFn as NewTaskActionFunction)(
|
|
179
179
|
nextTaskArguments,
|
|
180
180
|
this.#hre,
|
|
181
181
|
);
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
-
return actionFn(
|
|
184
|
+
return await actionFn(
|
|
185
185
|
nextTaskArguments,
|
|
186
186
|
this.#hre,
|
|
187
187
|
async (newTaskArguments: TaskArguments) => {
|
|
188
|
-
return next(newTaskArguments, currentIndex - 1);
|
|
188
|
+
return await next(newTaskArguments, currentIndex - 1);
|
|
189
189
|
},
|
|
190
190
|
);
|
|
191
191
|
};
|
|
192
192
|
|
|
193
|
-
return next(validatedTaskArguments);
|
|
193
|
+
return await next(validatedTaskArguments);
|
|
194
194
|
}
|
|
195
195
|
|
|
196
196
|
/**
|