hardhat 3.1.9 → 3.1.11
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 +33 -0
- package/dist/src/config.d.ts +20 -0
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +31 -0
- package/dist/src/config.js.map +1 -1
- package/dist/src/internal/builtin-plugins/artifacts/artifact-manager.d.ts +2 -2
- package/dist/src/internal/builtin-plugins/artifacts/artifact-manager.d.ts.map +1 -1
- 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.map +1 -1
- package/dist/src/internal/builtin-plugins/coverage/coverage-manager.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/coverage/coverage-manager.js +33 -21
- package/dist/src/internal/builtin-plugins/coverage/coverage-manager.js.map +1 -1
- package/dist/src/internal/builtin-plugins/coverage/helpers.d.ts +3 -5
- package/dist/src/internal/builtin-plugins/coverage/helpers.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/coverage/helpers.js +7 -19
- package/dist/src/internal/builtin-plugins/coverage/helpers.js.map +1 -1
- package/dist/src/internal/builtin-plugins/coverage/hook-handlers/test.d.ts +7 -0
- package/dist/src/internal/builtin-plugins/coverage/hook-handlers/test.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/coverage/hook-handlers/test.js +42 -0
- package/dist/src/internal/builtin-plugins/coverage/hook-handlers/test.js.map +1 -0
- package/dist/src/internal/builtin-plugins/coverage/index.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/coverage/index.js +1 -0
- package/dist/src/internal/builtin-plugins/coverage/index.js.map +1 -1
- package/dist/src/internal/builtin-plugins/flatten/task-action.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/flatten/task-action.js +1 -1
- package/dist/src/internal/builtin-plugins/flatten/task-action.js.map +1 -1
- package/dist/src/internal/builtin-plugins/gas-analytics/gas-analytics-manager.js +2 -2
- package/dist/src/internal/builtin-plugins/gas-analytics/gas-analytics-manager.js.map +1 -1
- package/dist/src/internal/builtin-plugins/gas-analytics/helpers.d.ts +3 -5
- package/dist/src/internal/builtin-plugins/gas-analytics/helpers.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/gas-analytics/helpers.js +7 -19
- package/dist/src/internal/builtin-plugins/gas-analytics/helpers.js.map +1 -1
- package/dist/src/internal/builtin-plugins/gas-analytics/hook-handlers/test.d.ts +7 -0
- package/dist/src/internal/builtin-plugins/gas-analytics/hook-handlers/test.d.ts.map +1 -0
- package/dist/src/internal/builtin-plugins/gas-analytics/hook-handlers/test.js +42 -0
- package/dist/src/internal/builtin-plugins/gas-analytics/hook-handlers/test.js.map +1 -0
- package/dist/src/internal/builtin-plugins/gas-analytics/index.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/gas-analytics/index.js +1 -0
- package/dist/src/internal/builtin-plugins/gas-analytics/index.js.map +1 -1
- 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 +17 -20
- package/dist/src/internal/builtin-plugins/network-manager/edr/edr-provider.js.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/edr/stack-traces/stack-trace-generation-errors.d.ts +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/edr/stack-traces/stack-trace-generation-errors.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/edr/stack-traces/stack-trace-generation-errors.js +2 -2
- package/dist/src/internal/builtin-plugins/network-manager/edr/stack-traces/stack-trace-generation-errors.js.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/edr/type-validation.d.ts +0 -2
- package/dist/src/internal/builtin-plugins/network-manager/edr/type-validation.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/edr/type-validation.js +0 -6
- package/dist/src/internal/builtin-plugins/network-manager/edr/type-validation.js.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/edr/utils/convert-to-edr.d.ts +1 -3
- package/dist/src/internal/builtin-plugins/network-manager/edr/utils/convert-to-edr.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/edr/utils/convert-to-edr.js +0 -49
- 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/config.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/hook-handlers/config.js +58 -20
- package/dist/src/internal/builtin-plugins/network-manager/hook-handlers/config.js.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/type-validation.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/type-validation.js +8 -0
- package/dist/src/internal/builtin-plugins/network-manager/type-validation.js.map +1 -1
- package/dist/src/internal/builtin-plugins/node/task-action.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/node/task-action.js +1 -2
- package/dist/src/internal/builtin-plugins/node/task-action.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-results.d.ts +2 -2
- package/dist/src/internal/builtin-plugins/solidity/build-results.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-results.js +2 -2
- package/dist/src/internal/builtin-plugins/solidity/build-results.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/build-system.d.ts +1 -0
- 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 +14 -6
- package/dist/src/internal/builtin-plugins/solidity/build-system/build-system.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/compiler/compiler.js +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/compiler/compiler.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/compiler/downloader.d.ts +0 -3
- package/dist/src/internal/builtin-plugins/solidity/build-system/compiler/downloader.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/compiler/downloader.js +3 -5
- package/dist/src/internal/builtin-plugins/solidity/build-system/compiler/downloader.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/dependency-graph-building.d.ts +2 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/dependency-graph-building.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/dependency-graph-building.js +4 -2
- 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/dependency-graph.d.ts +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/dependency-graph.js +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/dependency-resolver.d.ts +5 -2
- package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/dependency-resolver.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/dependency-resolver.js +8 -2
- 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/error-messages.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/error-messages.js +19 -5
- package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/error-messages.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/remapped-npm-packages-graph.d.ts +21 -2
- package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/remapped-npm-packages-graph.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/remapped-npm-packages-graph.js +84 -25
- 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/build-system/resolver/types.d.ts +3 -12
- package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/types.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/types.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/utils.d.ts +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/resolver/utils.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/solc-config-selection.d.ts +8 -6
- package/dist/src/internal/builtin-plugins/solidity/build-system/solc-config-selection.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/build-system/solc-config-selection.js +103 -27
- package/dist/src/internal/builtin-plugins/solidity/build-system/solc-config-selection.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/config.js +2 -2
- package/dist/src/internal/builtin-plugins/solidity/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 +5 -0
- package/dist/src/internal/builtin-plugins/solidity/hook-handlers/hre.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/tasks/build.js +1 -1
- package/dist/src/internal/builtin-plugins/solidity/tasks/build.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity/type-extensions.d.ts +22 -0
- package/dist/src/internal/builtin-plugins/solidity/type-extensions.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/config.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/config.js +1 -0
- package/dist/src/internal/builtin-plugins/solidity-test/config.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/edr-artifacts.d.ts +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/edr-artifacts.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/edr-artifacts.js +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/edr-artifacts.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/runner.d.ts +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/runner.js +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/task-action.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/task-action.js +16 -27
- package/dist/src/internal/builtin-plugins/solidity-test/task-action.js.map +1 -1
- package/dist/src/internal/builtin-plugins/solidity-test/type-extensions.d.ts +1 -0
- package/dist/src/internal/builtin-plugins/solidity-test/type-extensions.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/telemetry/task-action.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/telemetry/task-action.js +3 -2
- package/dist/src/internal/builtin-plugins/telemetry/task-action.js.map +1 -1
- package/dist/src/internal/builtin-plugins/test/task-action.d.ts.map +1 -1
- package/dist/src/internal/builtin-plugins/test/task-action.js +40 -13
- package/dist/src/internal/builtin-plugins/test/task-action.js.map +1 -1
- package/dist/src/internal/builtin-plugins/test/type-extensions.d.ts +27 -0
- package/dist/src/internal/builtin-plugins/test/type-extensions.d.ts.map +1 -1
- package/dist/src/internal/cli/banner-manager.d.ts +26 -0
- package/dist/src/internal/cli/banner-manager.d.ts.map +1 -0
- package/dist/src/internal/cli/banner-manager.js +146 -0
- package/dist/src/internal/cli/banner-manager.js.map +1 -0
- package/dist/src/internal/cli/error-handler.d.ts.map +1 -1
- package/dist/src/internal/cli/error-handler.js +15 -0
- package/dist/src/internal/cli/error-handler.js.map +1 -1
- package/dist/src/internal/cli/init/init.d.ts.map +1 -1
- package/dist/src/internal/cli/init/init.js +8 -0
- package/dist/src/internal/cli/init/init.js.map +1 -1
- package/dist/src/internal/cli/main.d.ts.map +1 -1
- package/dist/src/internal/cli/main.js +18 -1
- package/dist/src/internal/cli/main.js.map +1 -1
- package/dist/src/internal/cli/telemetry/analytics/subprocess.js +2 -0
- package/dist/src/internal/cli/telemetry/analytics/subprocess.js.map +1 -1
- package/dist/src/internal/cli/telemetry/sentry/anonymize-paths.js +1 -1
- package/dist/src/internal/cli/telemetry/sentry/reporter.d.ts.map +1 -1
- package/dist/src/internal/cli/telemetry/sentry/reporter.js +4 -0
- package/dist/src/internal/cli/telemetry/sentry/reporter.js.map +1 -1
- package/dist/src/internal/cli/telemetry/sentry/vendor/integrations/contextlines.d.ts +1 -1
- package/dist/src/internal/cli/telemetry/sentry/vendor/integrations/contextlines.d.ts.map +1 -1
- package/dist/src/internal/cli/telemetry/sentry/vendor/integrations/contextlines.js +47 -38
- package/dist/src/internal/cli/telemetry/sentry/vendor/integrations/contextlines.js.map +1 -1
- package/dist/src/internal/core/config-validation.d.ts +3 -3
- package/dist/src/internal/core/config-validation.d.ts.map +1 -1
- package/dist/src/internal/core/config-validation.js +48 -18
- package/dist/src/internal/core/config-validation.js.map +1 -1
- package/dist/src/internal/core/tasks/builders.d.ts +26 -16
- package/dist/src/internal/core/tasks/builders.d.ts.map +1 -1
- package/dist/src/internal/core/tasks/builders.js +65 -6
- package/dist/src/internal/core/tasks/builders.js.map +1 -1
- package/dist/src/internal/core/tasks/resolved-task.d.ts +2 -2
- package/dist/src/internal/core/tasks/resolved-task.d.ts.map +1 -1
- package/dist/src/internal/core/tasks/resolved-task.js +23 -9
- package/dist/src/internal/core/tasks/resolved-task.js.map +1 -1
- package/dist/src/internal/core/tasks/task-manager.d.ts.map +1 -1
- package/dist/src/internal/core/tasks/task-manager.js +14 -6
- package/dist/src/internal/core/tasks/task-manager.js.map +1 -1
- package/dist/src/internal/core/tasks/validations.d.ts +2 -0
- package/dist/src/internal/core/tasks/validations.d.ts.map +1 -1
- package/dist/src/internal/core/tasks/validations.js +11 -0
- package/dist/src/internal/core/tasks/validations.js.map +1 -1
- package/dist/src/internal/core/user-interruptions.js +1 -1
- package/dist/src/internal/deprecated-module-imported-from-hardhat2-plugin.d.ts +2 -0
- package/dist/src/internal/deprecated-module-imported-from-hardhat2-plugin.d.ts.map +1 -0
- package/dist/src/internal/deprecated-module-imported-from-hardhat2-plugin.js +12 -0
- package/dist/src/internal/deprecated-module-imported-from-hardhat2-plugin.js.map +1 -0
- package/dist/src/internal/using-hardhat2-plugin-errors.d.ts +35 -0
- package/dist/src/internal/using-hardhat2-plugin-errors.d.ts.map +1 -0
- package/dist/src/internal/using-hardhat2-plugin-errors.js +98 -0
- package/dist/src/internal/using-hardhat2-plugin-errors.js.map +1 -0
- package/dist/src/plugins.d.ts +8 -0
- package/dist/src/plugins.d.ts.map +1 -1
- package/dist/src/plugins.js +13 -0
- package/dist/src/plugins.js.map +1 -1
- package/dist/src/types/artifacts.d.ts +32 -3
- package/dist/src/types/artifacts.d.ts.map +1 -1
- package/dist/src/types/index.d.ts +15 -0
- package/dist/src/types/index.d.ts.map +1 -0
- package/dist/src/types/index.js +15 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/types/network.d.ts +1 -1
- package/dist/src/types/plugins.d.ts +2 -2
- package/dist/src/types/solidity/build-system.d.ts +56 -10
- package/dist/src/types/solidity/build-system.d.ts.map +1 -1
- package/dist/src/types/solidity/build-system.js +26 -2
- package/dist/src/types/solidity/build-system.js.map +1 -1
- package/dist/src/types/solidity/errors.d.ts +18 -0
- package/dist/src/types/solidity/errors.d.ts.map +1 -1
- package/dist/src/types/solidity/errors.js.map +1 -1
- package/dist/src/types/solidity/resolved-file.d.ts +2 -2
- package/dist/src/types/tasks.d.ts +103 -34
- package/dist/src/types/tasks.d.ts.map +1 -1
- package/dist/src/types/tasks.js.map +1 -1
- package/dist/src/types/test.d.ts +11 -0
- package/dist/src/types/test.d.ts.map +1 -1
- package/dist/src/types/utils.d.ts +16 -0
- package/dist/src/types/utils.d.ts.map +1 -1
- package/dist/src/utils/result.d.ts +33 -0
- package/dist/src/utils/result.d.ts.map +1 -0
- package/dist/src/utils/result.js +43 -0
- package/dist/src/utils/result.js.map +1 -0
- package/package.json +12 -7
- package/src/config.ts +37 -0
- package/src/internal/builtin-plugins/artifacts/artifact-manager.ts +4 -1
- package/src/internal/builtin-plugins/artifacts/hook-handlers/hre.ts +4 -1
- package/src/internal/builtin-plugins/coverage/coverage-manager.ts +57 -50
- package/src/internal/builtin-plugins/coverage/helpers.ts +11 -29
- package/src/internal/builtin-plugins/coverage/hook-handlers/test.ts +68 -0
- package/src/internal/builtin-plugins/coverage/index.ts +1 -0
- package/src/internal/builtin-plugins/flatten/task-action.ts +1 -0
- package/src/internal/builtin-plugins/gas-analytics/gas-analytics-manager.ts +4 -4
- package/src/internal/builtin-plugins/gas-analytics/helpers.ts +11 -29
- package/src/internal/builtin-plugins/gas-analytics/hook-handlers/test.ts +68 -0
- package/src/internal/builtin-plugins/gas-analytics/index.ts +1 -0
- package/src/internal/builtin-plugins/network-manager/edr/edr-provider.ts +21 -28
- package/src/internal/builtin-plugins/network-manager/edr/stack-traces/stack-trace-generation-errors.ts +5 -2
- package/src/internal/builtin-plugins/network-manager/edr/type-validation.ts +0 -13
- package/src/internal/builtin-plugins/network-manager/edr/utils/convert-to-edr.ts +0 -64
- package/src/internal/builtin-plugins/network-manager/hook-handlers/config.ts +65 -21
- package/src/internal/builtin-plugins/network-manager/type-validation.ts +9 -0
- package/src/internal/builtin-plugins/node/task-action.ts +2 -2
- package/src/internal/builtin-plugins/solidity/build-results.ts +3 -1
- package/src/internal/builtin-plugins/solidity/build-system/build-system.ts +16 -5
- package/src/internal/builtin-plugins/solidity/build-system/compiler/compiler.ts +1 -1
- package/src/internal/builtin-plugins/solidity/build-system/compiler/downloader.ts +7 -6
- package/src/internal/builtin-plugins/solidity/build-system/dependency-graph-building.ts +23 -1
- package/src/internal/builtin-plugins/solidity/build-system/dependency-graph.ts +1 -1
- package/src/internal/builtin-plugins/solidity/build-system/resolver/dependency-resolver.ts +17 -3
- package/src/internal/builtin-plugins/solidity/build-system/resolver/error-messages.ts +19 -5
- package/src/internal/builtin-plugins/solidity/build-system/resolver/remapped-npm-packages-graph.ts +139 -35
- package/src/internal/builtin-plugins/solidity/build-system/resolver/types.ts +3 -9
- package/src/internal/builtin-plugins/solidity/build-system/resolver/utils.ts +1 -1
- package/src/internal/builtin-plugins/solidity/build-system/solc-config-selection.ts +125 -28
- package/src/internal/builtin-plugins/solidity/config.ts +2 -2
- package/src/internal/builtin-plugins/solidity/hook-handlers/hre.ts +8 -0
- package/src/internal/builtin-plugins/solidity/tasks/build.ts +1 -1
- package/src/internal/builtin-plugins/solidity/type-extensions.ts +28 -0
- package/src/internal/builtin-plugins/solidity-test/config.ts +1 -0
- package/src/internal/builtin-plugins/solidity-test/edr-artifacts.ts +2 -2
- package/src/internal/builtin-plugins/solidity-test/runner.ts +1 -1
- package/src/internal/builtin-plugins/solidity-test/task-action.ts +36 -38
- package/src/internal/builtin-plugins/solidity-test/type-extensions.ts +1 -0
- package/src/internal/builtin-plugins/telemetry/task-action.ts +4 -2
- package/src/internal/builtin-plugins/test/task-action.ts +71 -25
- package/src/internal/builtin-plugins/test/type-extensions.ts +42 -0
- package/src/internal/cli/banner-manager.ts +234 -0
- package/src/internal/cli/error-handler.ts +18 -0
- package/src/internal/cli/init/init.ts +8 -0
- package/src/internal/cli/main.ts +19 -1
- package/src/internal/cli/telemetry/analytics/subprocess.ts +2 -0
- package/src/internal/cli/telemetry/sentry/anonymize-paths.ts +1 -1
- package/src/internal/cli/telemetry/sentry/reporter.ts +5 -0
- package/src/internal/cli/telemetry/sentry/vendor/integrations/contextlines.ts +98 -50
- package/src/internal/core/config-validation.ts +67 -18
- package/src/internal/core/tasks/builders.ts +174 -30
- package/src/internal/core/tasks/resolved-task.ts +31 -13
- package/src/internal/core/tasks/task-manager.ts +23 -5
- package/src/internal/core/tasks/validations.ts +40 -0
- package/src/internal/core/user-interruptions.ts +1 -1
- package/src/internal/deprecated-module-imported-from-hardhat2-plugin.ts +12 -0
- package/src/internal/using-hardhat2-plugin-errors.ts +108 -0
- package/src/plugins.ts +16 -0
- package/src/types/artifacts.ts +40 -3
- package/src/types/hre.ts +1 -1
- package/src/types/index.ts +14 -0
- package/src/types/network.ts +1 -1
- package/src/types/plugins.ts +2 -2
- package/src/types/solidity/build-system.ts +75 -14
- package/src/types/solidity/errors.ts +22 -0
- package/src/types/solidity/resolved-file.ts +2 -2
- package/src/types/tasks.ts +143 -36
- package/src/types/test.ts +12 -0
- package/src/types/utils.ts +14 -0
- package/src/utils/result.ts +57 -0
- package/templates/hardhat-3/01-node-test-runner-viem/package.json +11 -11
- package/templates/hardhat-3/02-mocha-ethers/package.json +16 -16
- package/templates/hardhat-3/03-minimal/package.json +1 -1
- package/dist/src/internal/builtin-plugins/network-manager/edr/types/output.d.ts +0 -19
- package/dist/src/internal/builtin-plugins/network-manager/edr/types/output.d.ts.map +0 -1
- package/dist/src/internal/builtin-plugins/network-manager/edr/types/output.js +0 -2
- package/dist/src/internal/builtin-plugins/network-manager/edr/types/output.js.map +0 -1
- package/src/internal/builtin-plugins/network-manager/edr/types/output.ts +0 -19
|
@@ -38,7 +38,7 @@ export interface RunOptions {
|
|
|
38
38
|
* Despite the changes, the signature of the function should still be considered
|
|
39
39
|
* a draft that may change in the future.
|
|
40
40
|
*
|
|
41
|
-
* TODO: Once the signature is
|
|
41
|
+
* TODO: Once the signature is finalized, give feedback to the EDR team.
|
|
42
42
|
*/
|
|
43
43
|
export function run(
|
|
44
44
|
chainType: ChainType,
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { RunOptions } from "./runner.js";
|
|
2
2
|
import type { TestEvent } from "./types.js";
|
|
3
3
|
import type { NewTaskActionFunction } from "../../../types/tasks.js";
|
|
4
|
+
import type { TestSummary } from "../../../types/test.js";
|
|
5
|
+
import type { Result } from "../../../types/utils.js";
|
|
4
6
|
import type {
|
|
5
7
|
Artifact as EdrArtifact,
|
|
6
8
|
BuildInfoAndOutput,
|
|
@@ -19,19 +21,10 @@ import { resolveFromRoot } from "@nomicfoundation/hardhat-utils/path";
|
|
|
19
21
|
import { createNonClosingWriter } from "@nomicfoundation/hardhat-utils/stream";
|
|
20
22
|
|
|
21
23
|
import { getFullyQualifiedName } from "../../../utils/contract-names.js";
|
|
24
|
+
import { errorResult, successfulResult } from "../../../utils/result.js";
|
|
22
25
|
import { HardhatRuntimeEnvironmentImplementation } from "../../core/hre.js";
|
|
23
26
|
import { isSupportedChainType } from "../../edr/chain-type.js";
|
|
24
27
|
import { ArtifactManagerImplementation } from "../artifacts/artifact-manager.js";
|
|
25
|
-
import {
|
|
26
|
-
markTestRunStart as initCoverage,
|
|
27
|
-
markTestWorkerDone as saveCoverageData,
|
|
28
|
-
markTestRunDone as reportCoverage,
|
|
29
|
-
} from "../coverage/helpers.js";
|
|
30
|
-
import {
|
|
31
|
-
markTestRunStart as initGasStats,
|
|
32
|
-
markTestWorkerDone as saveGasStatsData,
|
|
33
|
-
markTestRunDone as reportGasStats,
|
|
34
|
-
} from "../gas-analytics/helpers.js";
|
|
35
28
|
import { edrGasReportToHardhatGasMeasurements } from "../network-manager/edr/utils/convert-to-edr.js";
|
|
36
29
|
|
|
37
30
|
import { getEdrArtifacts, getBuildInfos } from "./edr-artifacts.js";
|
|
@@ -56,7 +49,7 @@ interface TestActionArguments {
|
|
|
56
49
|
const runSolidityTests: NewTaskActionFunction<TestActionArguments> = async (
|
|
57
50
|
{ testFiles, chainType, grep, noCompile, verbosity, testSummaryIndex },
|
|
58
51
|
hre,
|
|
59
|
-
) => {
|
|
52
|
+
): Promise<Result<TestSummary, TestSummary>> => {
|
|
60
53
|
assertHardhatInvariant(
|
|
61
54
|
hre instanceof HardhatRuntimeEnvironmentImplementation,
|
|
62
55
|
"Expected HRE to be an instance of HardhatRuntimeEnvironmentImplementation",
|
|
@@ -98,7 +91,7 @@ const runSolidityTests: NewTaskActionFunction<TestActionArguments> = async (
|
|
|
98
91
|
|
|
99
92
|
// EDR needs all artifacts (contracts + tests)
|
|
100
93
|
const edrArtifacts: Array<{
|
|
101
|
-
|
|
94
|
+
edrArtifact: EdrArtifact;
|
|
102
95
|
userSourceName: string;
|
|
103
96
|
}> = [];
|
|
104
97
|
const buildInfos: BuildInfoAndOutput[] = [];
|
|
@@ -110,20 +103,20 @@ const runSolidityTests: NewTaskActionFunction<TestActionArguments> = async (
|
|
|
110
103
|
}
|
|
111
104
|
|
|
112
105
|
const sourceNameToUserSourceName = new Map(
|
|
113
|
-
edrArtifacts.map(({ userSourceName,
|
|
114
|
-
|
|
106
|
+
edrArtifacts.map(({ userSourceName, edrArtifact }) => [
|
|
107
|
+
edrArtifact.id.source,
|
|
115
108
|
userSourceName,
|
|
116
109
|
]),
|
|
117
110
|
);
|
|
118
111
|
|
|
119
|
-
edrArtifacts.forEach(({ userSourceName,
|
|
112
|
+
edrArtifacts.forEach(({ userSourceName, edrArtifact }) => {
|
|
120
113
|
if (
|
|
121
114
|
testRootPaths.includes(
|
|
122
115
|
resolveFromRoot(hre.config.paths.root, userSourceName),
|
|
123
116
|
) &&
|
|
124
|
-
isTestSuiteArtifact(
|
|
117
|
+
isTestSuiteArtifact(edrArtifact)
|
|
125
118
|
) {
|
|
126
|
-
warnDeprecatedTestFail(
|
|
119
|
+
warnDeprecatedTestFail(edrArtifact, sourceNameToUserSourceName);
|
|
127
120
|
}
|
|
128
121
|
});
|
|
129
122
|
|
|
@@ -133,8 +126,8 @@ const runSolidityTests: NewTaskActionFunction<TestActionArguments> = async (
|
|
|
133
126
|
resolveFromRoot(hre.config.paths.root, userSourceName),
|
|
134
127
|
),
|
|
135
128
|
)
|
|
136
|
-
.filter(({
|
|
137
|
-
.map(({
|
|
129
|
+
.filter(({ edrArtifact }) => isTestSuiteArtifact(edrArtifact))
|
|
130
|
+
.map(({ edrArtifact }) => edrArtifact.id);
|
|
138
131
|
|
|
139
132
|
console.log("Running Solidity tests");
|
|
140
133
|
console.log();
|
|
@@ -186,12 +179,16 @@ const runSolidityTests: NewTaskActionFunction<TestActionArguments> = async (
|
|
|
186
179
|
const options: RunOptions =
|
|
187
180
|
solidityTestConfigToRunOptions(solidityTestConfig);
|
|
188
181
|
|
|
189
|
-
await
|
|
190
|
-
|
|
182
|
+
await hre.hooks.runHandlerChain(
|
|
183
|
+
"test",
|
|
184
|
+
"onTestRunStart",
|
|
185
|
+
["solidity"],
|
|
186
|
+
async () => {},
|
|
187
|
+
);
|
|
191
188
|
|
|
192
189
|
const runStream = run(
|
|
193
190
|
chainType,
|
|
194
|
-
edrArtifacts.map(({
|
|
191
|
+
edrArtifacts.map(({ edrArtifact }) => edrArtifact),
|
|
195
192
|
testSuiteIds,
|
|
196
193
|
config,
|
|
197
194
|
tracingConfig,
|
|
@@ -271,26 +268,27 @@ const runSolidityTests: NewTaskActionFunction<TestActionArguments> = async (
|
|
|
271
268
|
includesErrors = true;
|
|
272
269
|
}
|
|
273
270
|
|
|
274
|
-
await
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
271
|
+
await hre.hooks.runHandlerChain(
|
|
272
|
+
"test",
|
|
273
|
+
"onTestWorkerDone",
|
|
274
|
+
["solidity"],
|
|
275
|
+
async () => {},
|
|
276
|
+
);
|
|
280
277
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
278
|
+
await hre.hooks.runHandlerChain(
|
|
279
|
+
"test",
|
|
280
|
+
"onTestRunDone",
|
|
281
|
+
["solidity"],
|
|
282
|
+
async () => {},
|
|
283
|
+
);
|
|
284
284
|
|
|
285
285
|
console.log();
|
|
286
286
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
failureOutput,
|
|
293
|
-
};
|
|
287
|
+
const summary = { failed, passed, skipped, todo: 0, failureOutput };
|
|
288
|
+
|
|
289
|
+
return includesFailures || includesErrors
|
|
290
|
+
? errorResult(summary)
|
|
291
|
+
: successfulResult(summary);
|
|
294
292
|
};
|
|
295
293
|
|
|
296
294
|
export default runSolidityTests;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { NewTaskActionFunction } from "../../../types/tasks.js";
|
|
2
2
|
|
|
3
|
+
import { errorResult, successfulResult } from "../../../utils/result.js";
|
|
3
4
|
import {
|
|
4
5
|
isTelemetryAllowed,
|
|
5
6
|
setTelemetryEnabled,
|
|
@@ -15,8 +16,7 @@ const configureTelemetry: NewTaskActionFunction<
|
|
|
15
16
|
> = async ({ enable, disable }) => {
|
|
16
17
|
if (enable && disable) {
|
|
17
18
|
console.error("Cannot enable and disable telemetry at the same time");
|
|
18
|
-
|
|
19
|
-
return;
|
|
19
|
+
return errorResult();
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
if (enable) {
|
|
@@ -40,6 +40,8 @@ const configureTelemetry: NewTaskActionFunction<
|
|
|
40
40
|
"Telemetry is disabled, to enable it run `npx hardhat telemetry --enable`",
|
|
41
41
|
);
|
|
42
42
|
}
|
|
43
|
+
|
|
44
|
+
return successfulResult();
|
|
43
45
|
};
|
|
44
46
|
|
|
45
47
|
export default configureTelemetry;
|
|
@@ -4,13 +4,21 @@ import type {
|
|
|
4
4
|
Task,
|
|
5
5
|
TaskArguments,
|
|
6
6
|
} from "../../../types/tasks.js";
|
|
7
|
+
import type { TestSummary } from "../../../types/test.js";
|
|
8
|
+
import type { Result } from "../../../types/utils.js";
|
|
7
9
|
|
|
8
10
|
import {
|
|
9
11
|
assertHardhatInvariant,
|
|
10
12
|
HardhatError,
|
|
11
13
|
} from "@nomicfoundation/hardhat-errors";
|
|
14
|
+
import { isObject } from "@nomicfoundation/hardhat-utils/lang";
|
|
12
15
|
import chalk, { type ChalkInstance } from "chalk";
|
|
13
16
|
|
|
17
|
+
import {
|
|
18
|
+
errorResult,
|
|
19
|
+
isResult,
|
|
20
|
+
successfulResult,
|
|
21
|
+
} from "../../../utils/result.js";
|
|
14
22
|
import { HardhatRuntimeEnvironmentImplementation } from "../../core/hre.js";
|
|
15
23
|
|
|
16
24
|
interface TestActionArguments {
|
|
@@ -21,10 +29,27 @@ interface TestActionArguments {
|
|
|
21
29
|
verbosity: number;
|
|
22
30
|
}
|
|
23
31
|
|
|
32
|
+
// Old plugins may only return { failed, passed } without skipped/todo,
|
|
33
|
+
// so we accept a partial shape and fill defaults in the coordinator.
|
|
34
|
+
interface PartialTestSummary extends Omit<TestSummary, "skipped" | "todo"> {
|
|
35
|
+
skipped?: number;
|
|
36
|
+
todo?: number;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function isTestSummary(value: unknown): value is PartialTestSummary {
|
|
40
|
+
return (
|
|
41
|
+
isObject(value) &&
|
|
42
|
+
typeof value.failed === "number" &&
|
|
43
|
+
typeof value.passed === "number" &&
|
|
44
|
+
(value.skipped === undefined || typeof value.skipped === "number") &&
|
|
45
|
+
(value.todo === undefined || typeof value.todo === "number")
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
24
49
|
const runAllTests: NewTaskActionFunction<TestActionArguments> = async (
|
|
25
50
|
{ testFiles, chainType, grep, noCompile, verbosity },
|
|
26
51
|
hre,
|
|
27
|
-
) => {
|
|
52
|
+
): Promise<Result<void, void>> => {
|
|
28
53
|
// If this code is executed, it means the user has not specified a test runner.
|
|
29
54
|
// If file paths are specified, we need to determine which test runner applies to each test file.
|
|
30
55
|
// If no file paths are specified, each test runner will execute all tests located under its configured path in the Hardhat configuration.
|
|
@@ -49,18 +74,10 @@ const runAllTests: NewTaskActionFunction<TestActionArguments> = async (
|
|
|
49
74
|
hre._coverage.disableReport();
|
|
50
75
|
}
|
|
51
76
|
|
|
52
|
-
const testSummaries: Record<
|
|
53
|
-
string,
|
|
54
|
-
{
|
|
55
|
-
failed?: number;
|
|
56
|
-
passed?: number;
|
|
57
|
-
skipped?: number;
|
|
58
|
-
todo?: number;
|
|
59
|
-
failureOutput?: string;
|
|
60
|
-
}
|
|
61
|
-
> = {};
|
|
77
|
+
const testSummaries: Record<string, TestSummary> = {};
|
|
62
78
|
|
|
63
79
|
let failureIndex = 1;
|
|
80
|
+
let hasFailures = false;
|
|
64
81
|
for (const subtask of thisTask.subtasks.values()) {
|
|
65
82
|
const files = getTestFilesForSubtask(subtask, testFiles, subtasksToFiles);
|
|
66
83
|
|
|
@@ -84,18 +101,45 @@ const runAllTests: NewTaskActionFunction<TestActionArguments> = async (
|
|
|
84
101
|
args.verbosity = verbosity;
|
|
85
102
|
}
|
|
86
103
|
|
|
87
|
-
const summaryId = subtask.id[subtask.id.length - 1];
|
|
88
|
-
|
|
89
104
|
if (subtask.options.has("testSummaryIndex")) {
|
|
90
105
|
args.testSummaryIndex = failureIndex;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const subtaskResult = await subtask.run(args);
|
|
91
109
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
110
|
+
const isSubtaskResult = isResult(
|
|
111
|
+
subtaskResult,
|
|
112
|
+
isTestSummary,
|
|
113
|
+
isTestSummary,
|
|
114
|
+
);
|
|
115
|
+
const summary = isSubtaskResult
|
|
116
|
+
? subtaskResult.success
|
|
117
|
+
? subtaskResult.value
|
|
118
|
+
: subtaskResult.error
|
|
119
|
+
: isTestSummary(subtaskResult)
|
|
120
|
+
? subtaskResult
|
|
121
|
+
: undefined;
|
|
122
|
+
|
|
123
|
+
if (summary !== undefined) {
|
|
124
|
+
const summaryId = subtask.id[subtask.id.length - 1];
|
|
125
|
+
testSummaries[summaryId] = {
|
|
126
|
+
skipped: 0,
|
|
127
|
+
todo: 0,
|
|
128
|
+
...summary,
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
if (subtask.options.has("testSummaryIndex")) {
|
|
132
|
+
failureIndex += summary.failed;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (
|
|
137
|
+
(isSubtaskResult && !subtaskResult.success) ||
|
|
138
|
+
// Backwards compatibility: old plugins may not return a Result, so fall
|
|
139
|
+
// back to the process exit code to detect failures
|
|
140
|
+
(process.exitCode !== undefined && process.exitCode !== 0)
|
|
141
|
+
) {
|
|
142
|
+
hasFailures = true;
|
|
99
143
|
}
|
|
100
144
|
}
|
|
101
145
|
|
|
@@ -106,19 +150,19 @@ const runAllTests: NewTaskActionFunction<TestActionArguments> = async (
|
|
|
106
150
|
const outputLines: string[] = [];
|
|
107
151
|
|
|
108
152
|
for (const [subtaskName, results] of Object.entries(testSummaries)) {
|
|
109
|
-
if (results.passed
|
|
153
|
+
if (results.passed > 0) {
|
|
110
154
|
passed.push([subtaskName, results.passed]);
|
|
111
155
|
}
|
|
112
156
|
|
|
113
|
-
if (results.failed
|
|
157
|
+
if (results.failed > 0) {
|
|
114
158
|
failed.push([subtaskName, results.failed]);
|
|
115
159
|
}
|
|
116
160
|
|
|
117
|
-
if (results.skipped
|
|
161
|
+
if (results.skipped > 0) {
|
|
118
162
|
skipped.push([subtaskName, results.skipped]);
|
|
119
163
|
}
|
|
120
164
|
|
|
121
|
-
if (results.todo
|
|
165
|
+
if (results.todo > 0) {
|
|
122
166
|
todo.push([subtaskName, results.todo]);
|
|
123
167
|
}
|
|
124
168
|
|
|
@@ -176,9 +220,11 @@ const runAllTests: NewTaskActionFunction<TestActionArguments> = async (
|
|
|
176
220
|
console.log();
|
|
177
221
|
}
|
|
178
222
|
|
|
179
|
-
if (
|
|
223
|
+
if (hasFailures) {
|
|
180
224
|
console.error("Test run failed");
|
|
181
225
|
}
|
|
226
|
+
|
|
227
|
+
return hasFailures ? errorResult() : successfulResult();
|
|
182
228
|
};
|
|
183
229
|
|
|
184
230
|
function logSummaryLine(
|
|
@@ -39,5 +39,47 @@ declare module "../../../types/hooks.js" {
|
|
|
39
39
|
filePath: string,
|
|
40
40
|
) => Promise<string | undefined>,
|
|
41
41
|
) => Promise<string | undefined>;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* This hook is triggered at the start of a test run, before tests execute.
|
|
45
|
+
*
|
|
46
|
+
* @param context The hook context.
|
|
47
|
+
* @param id A string identifier for the test runner (e.g., "solidity", "nodejs", "mocha").
|
|
48
|
+
* @param next A function to call the next handler for this hook, or the
|
|
49
|
+
* default implementation if no more handlers exist.
|
|
50
|
+
*/
|
|
51
|
+
onTestRunStart: (
|
|
52
|
+
context: HookContext,
|
|
53
|
+
id: string,
|
|
54
|
+
next: (nextContext: HookContext, id: string) => Promise<void>,
|
|
55
|
+
) => Promise<void>;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* This hook is triggered when a test worker has finished executing.
|
|
59
|
+
*
|
|
60
|
+
* @param context The hook context.
|
|
61
|
+
* @param id A string identifier for the test runner (e.g., "solidity", "nodejs", "mocha").
|
|
62
|
+
* @param next A function to call the next handler for this hook, or the
|
|
63
|
+
* default implementation if no more handlers exist.
|
|
64
|
+
*/
|
|
65
|
+
onTestWorkerDone: (
|
|
66
|
+
context: HookContext,
|
|
67
|
+
id: string,
|
|
68
|
+
next: (nextContext: HookContext, id: string) => Promise<void>,
|
|
69
|
+
) => Promise<void>;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* This hook is triggered at the end of a test run, after all tests have completed.
|
|
73
|
+
*
|
|
74
|
+
* @param context The hook context.
|
|
75
|
+
* @param id A string identifier for the test runner (e.g., "solidity", "nodejs", "mocha").
|
|
76
|
+
* @param next A function to call the next handler for this hook, or the
|
|
77
|
+
* default implementation if no more handlers exist.
|
|
78
|
+
*/
|
|
79
|
+
onTestRunDone: (
|
|
80
|
+
context: HookContext,
|
|
81
|
+
id: string,
|
|
82
|
+
next: (nextContext: HookContext, id: string) => Promise<void>,
|
|
83
|
+
) => Promise<void>;
|
|
42
84
|
}
|
|
43
85
|
}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import type { Dispatcher } from "@nomicfoundation/hardhat-utils/request";
|
|
2
|
+
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
readJsonFile,
|
|
7
|
+
writeJsonFile,
|
|
8
|
+
FileNotFoundError,
|
|
9
|
+
} from "@nomicfoundation/hardhat-utils/fs";
|
|
10
|
+
import { getCacheDir } from "@nomicfoundation/hardhat-utils/global-dir";
|
|
11
|
+
import { isObject } from "@nomicfoundation/hardhat-utils/lang";
|
|
12
|
+
import { getRequest } from "@nomicfoundation/hardhat-utils/request";
|
|
13
|
+
import debug from "debug";
|
|
14
|
+
|
|
15
|
+
const log = debug("hardhat:util:banner-manager");
|
|
16
|
+
|
|
17
|
+
interface BannerConfig {
|
|
18
|
+
enabled: boolean;
|
|
19
|
+
formattedMessages: string[];
|
|
20
|
+
minSecondsBetweenDisplays: number;
|
|
21
|
+
minSecondsBetweenRequests: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const BANNER_CONFIG_URL =
|
|
25
|
+
"https://raw.githubusercontent.com/NomicFoundation/hardhat/refs/heads/main/banner-config-v3.json";
|
|
26
|
+
|
|
27
|
+
export const BANNER_CACHE_FILE_NAME = "banner-config-v3.json";
|
|
28
|
+
|
|
29
|
+
export class BannerManager {
|
|
30
|
+
static #instance: BannerManager | undefined;
|
|
31
|
+
|
|
32
|
+
#bannerConfig: BannerConfig | undefined;
|
|
33
|
+
#lastDisplayTime: number;
|
|
34
|
+
#lastRequestTime: number;
|
|
35
|
+
readonly #dispatcher: Dispatcher | undefined;
|
|
36
|
+
readonly #print: (message: string) => void;
|
|
37
|
+
|
|
38
|
+
private constructor(
|
|
39
|
+
bannerConfig: BannerConfig | undefined,
|
|
40
|
+
lastDisplayTime: number,
|
|
41
|
+
lastRequestTime: number,
|
|
42
|
+
dispatcher: Dispatcher | undefined,
|
|
43
|
+
print: (message: string) => void,
|
|
44
|
+
) {
|
|
45
|
+
this.#bannerConfig = bannerConfig;
|
|
46
|
+
this.#lastDisplayTime = lastDisplayTime;
|
|
47
|
+
this.#lastRequestTime = lastRequestTime;
|
|
48
|
+
this.#dispatcher = dispatcher;
|
|
49
|
+
this.#print = print;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Returns a global instance of BannerManager.
|
|
54
|
+
*
|
|
55
|
+
* @param options Options used for testing purposes. Only used in the first
|
|
56
|
+
* invocation of this function, or after calling `resetInstance`.
|
|
57
|
+
* @returns The current global instance of BannerManager.
|
|
58
|
+
*/
|
|
59
|
+
public static async getInstance(options?: {
|
|
60
|
+
testDispatcher?: Dispatcher;
|
|
61
|
+
print?: (message: string) => void;
|
|
62
|
+
}): Promise<BannerManager> {
|
|
63
|
+
if (this.#instance === undefined) {
|
|
64
|
+
log("Initializing BannerManager");
|
|
65
|
+
const { bannerConfig, lastDisplayTime, lastRequestTime } =
|
|
66
|
+
await readCache();
|
|
67
|
+
this.#instance = new BannerManager(
|
|
68
|
+
bannerConfig,
|
|
69
|
+
lastDisplayTime,
|
|
70
|
+
lastRequestTime,
|
|
71
|
+
options?.testDispatcher,
|
|
72
|
+
options?.print ?? console.log,
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return this.#instance;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public static resetInstance(): void {
|
|
80
|
+
this.#instance = undefined;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Displays a banner message, if any.
|
|
85
|
+
*
|
|
86
|
+
* @param timeout The timeout in milliseconds to wait for the banner display.
|
|
87
|
+
*/
|
|
88
|
+
public async showBanner(timeout?: number): Promise<void> {
|
|
89
|
+
await this.#requestBannerConfig(timeout);
|
|
90
|
+
|
|
91
|
+
if (
|
|
92
|
+
this.#bannerConfig === undefined ||
|
|
93
|
+
!this.#bannerConfig.enabled ||
|
|
94
|
+
this.#bannerConfig.formattedMessages.length === 0
|
|
95
|
+
) {
|
|
96
|
+
log("Banner is disabled or no messages available.");
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const { formattedMessages, minSecondsBetweenDisplays } = this.#bannerConfig;
|
|
101
|
+
|
|
102
|
+
const timeSinceLastDisplay = Date.now() - this.#lastDisplayTime;
|
|
103
|
+
if (timeSinceLastDisplay < minSecondsBetweenDisplays * 1000) {
|
|
104
|
+
log(
|
|
105
|
+
`Skipping banner display. Time since last display: ${timeSinceLastDisplay}ms`,
|
|
106
|
+
);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// select a random message from the formattedMessages array
|
|
111
|
+
const randomIndex = Math.floor(Math.random() * formattedMessages.length);
|
|
112
|
+
const message = formattedMessages[randomIndex];
|
|
113
|
+
|
|
114
|
+
this.#print(message);
|
|
115
|
+
this.#lastDisplayTime = Date.now();
|
|
116
|
+
await writeCache({
|
|
117
|
+
bannerConfig: this.#bannerConfig,
|
|
118
|
+
lastDisplayTime: this.#lastDisplayTime,
|
|
119
|
+
lastRequestTime: this.#lastRequestTime,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async #requestBannerConfig(timeout?: number): Promise<void> {
|
|
124
|
+
if (this.#bannerConfig !== undefined) {
|
|
125
|
+
const timeSinceLastRequest = Date.now() - this.#lastRequestTime;
|
|
126
|
+
if (
|
|
127
|
+
timeSinceLastRequest <
|
|
128
|
+
this.#bannerConfig.minSecondsBetweenRequests * 1000
|
|
129
|
+
) {
|
|
130
|
+
log(
|
|
131
|
+
`Skipping banner config request. Time since last request: ${timeSinceLastRequest}ms`,
|
|
132
|
+
);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
try {
|
|
138
|
+
const response = await getRequest(
|
|
139
|
+
BANNER_CONFIG_URL,
|
|
140
|
+
undefined,
|
|
141
|
+
this.#dispatcher ?? { timeout },
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
const bannerConfig: unknown = await response.body.json();
|
|
145
|
+
|
|
146
|
+
if (!this.#isBannerConfig(bannerConfig)) {
|
|
147
|
+
log(`Invalid banner config received:`, bannerConfig);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
this.#bannerConfig = bannerConfig;
|
|
152
|
+
this.#lastRequestTime = Date.now();
|
|
153
|
+
|
|
154
|
+
await writeCache({
|
|
155
|
+
bannerConfig: this.#bannerConfig,
|
|
156
|
+
lastDisplayTime: this.#lastDisplayTime,
|
|
157
|
+
lastRequestTime: this.#lastRequestTime,
|
|
158
|
+
});
|
|
159
|
+
} catch (error) {
|
|
160
|
+
log(
|
|
161
|
+
`Error requesting banner config: ${
|
|
162
|
+
error instanceof Error ? error.message : JSON.stringify(error)
|
|
163
|
+
}`,
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
#isBannerConfig(value: unknown): value is BannerConfig {
|
|
169
|
+
if (!isObject(value)) {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return (
|
|
174
|
+
Object.getOwnPropertyNames(value).length === 4 &&
|
|
175
|
+
"enabled" in value &&
|
|
176
|
+
typeof value.enabled === "boolean" &&
|
|
177
|
+
"formattedMessages" in value &&
|
|
178
|
+
Array.isArray(value.formattedMessages) &&
|
|
179
|
+
value.formattedMessages.every(
|
|
180
|
+
(message: unknown) => typeof message === "string",
|
|
181
|
+
) &&
|
|
182
|
+
"minSecondsBetweenDisplays" in value &&
|
|
183
|
+
typeof value.minSecondsBetweenDisplays === "number" &&
|
|
184
|
+
"minSecondsBetweenRequests" in value &&
|
|
185
|
+
typeof value.minSecondsBetweenRequests === "number"
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
interface BannerCache {
|
|
191
|
+
bannerConfig: BannerConfig | undefined;
|
|
192
|
+
lastDisplayTime: number;
|
|
193
|
+
lastRequestTime: number;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
async function readCache(): Promise<BannerCache> {
|
|
197
|
+
const cacheDir = await getCacheDir();
|
|
198
|
+
const bannerCacheFilePath = path.join(cacheDir, BANNER_CACHE_FILE_NAME);
|
|
199
|
+
|
|
200
|
+
try {
|
|
201
|
+
return await readJsonFile<BannerCache>(bannerCacheFilePath);
|
|
202
|
+
} catch (error) {
|
|
203
|
+
if (error instanceof FileNotFoundError) {
|
|
204
|
+
log("No banner cache file found, using defaults");
|
|
205
|
+
} else {
|
|
206
|
+
log(
|
|
207
|
+
`Error reading cache file: ${
|
|
208
|
+
error instanceof Error ? error.message : JSON.stringify(error)
|
|
209
|
+
}`,
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return {
|
|
214
|
+
bannerConfig: undefined,
|
|
215
|
+
lastDisplayTime: 0,
|
|
216
|
+
lastRequestTime: 0,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
async function writeCache(cache: BannerCache): Promise<void> {
|
|
222
|
+
const cacheDir = await getCacheDir();
|
|
223
|
+
const bannerCacheFilePath = path.join(cacheDir, BANNER_CACHE_FILE_NAME);
|
|
224
|
+
|
|
225
|
+
try {
|
|
226
|
+
await writeJsonFile(bannerCacheFilePath, cache);
|
|
227
|
+
} catch (error) {
|
|
228
|
+
log(
|
|
229
|
+
`Error writing cache file: ${
|
|
230
|
+
error instanceof Error ? error.message : JSON.stringify(error)
|
|
231
|
+
}`,
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
import chalk from "chalk";
|
|
6
6
|
|
|
7
7
|
import { HARDHAT_NAME, HARDHAT_WEBSITE_URL } from "../constants.js";
|
|
8
|
+
import { UsingHardhat2PluginError } from "../using-hardhat2-plugin-errors.js";
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* The different categories of errors that can be handled by hardhat cli.
|
|
@@ -69,6 +70,11 @@ export function printErrorMessages(
|
|
|
69
70
|
shouldShowStackTraces: boolean = false,
|
|
70
71
|
print: (message: string | Error) => void = console.error,
|
|
71
72
|
): void {
|
|
73
|
+
if (error instanceof UsingHardhat2PluginError) {
|
|
74
|
+
printUsingHardhat2Error(error, print);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
72
78
|
const showStackTraces =
|
|
73
79
|
shouldShowStackTraces ||
|
|
74
80
|
getErrorWithCategory(error).category === ErrorCategory.OTHER;
|
|
@@ -146,3 +152,15 @@ function getErrorMessages(error: Error): ErrorMessages {
|
|
|
146
152
|
};
|
|
147
153
|
}
|
|
148
154
|
}
|
|
155
|
+
function printUsingHardhat2Error(
|
|
156
|
+
error: UsingHardhat2PluginError,
|
|
157
|
+
print: (message: string | Error) => void = console.error,
|
|
158
|
+
): void {
|
|
159
|
+
print(chalk.red.bold(`Hardhat 3 installation error:`));
|
|
160
|
+
print("");
|
|
161
|
+
if (error.callerRelativePath !== undefined) {
|
|
162
|
+
print(error.message);
|
|
163
|
+
} else {
|
|
164
|
+
print(error.stack);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
@@ -131,6 +131,14 @@ export async function initHardhat(options?: InitHardhatOptions): Promise<void> {
|
|
|
131
131
|
]);
|
|
132
132
|
|
|
133
133
|
showStarOnGitHubMessage();
|
|
134
|
+
|
|
135
|
+
try {
|
|
136
|
+
const { BannerManager } = await import("../banner-manager.js");
|
|
137
|
+
const bannerManager = await BannerManager.getInstance();
|
|
138
|
+
await bannerManager.showBanner();
|
|
139
|
+
} catch (bannerError) {
|
|
140
|
+
log("Error showing banner", bannerError);
|
|
141
|
+
}
|
|
134
142
|
} catch (e) {
|
|
135
143
|
if (e === "") {
|
|
136
144
|
// If the user cancels any prompt, we quit silently
|