UNPKG

hardhat

Version:

Hardhat is an extensible developer tool that helps smart contract developers increase productivity by reliably bringing together the tools they want.

37 lines (28 loc) 1 kB
import type { NewTaskActionFunction } from "../../../types/tasks.js"; import { pathToFileURL } from "node:url"; import { HardhatError } from "@nomicfoundation/hardhat-errors"; import { exists } from "@nomicfoundation/hardhat-utils/fs"; import { resolveFromRoot } from "@nomicfoundation/hardhat-utils/path"; interface RunActionArguments { script: string; noCompile: boolean; } const runScriptWithHardhat: NewTaskActionFunction<RunActionArguments> = async ( { script, noCompile }, hre, ) => { const normalizedPath = resolveFromRoot(process.cwd(), script); if (!(await exists(normalizedPath))) { throw new HardhatError( HardhatError.ERRORS.CORE.BUILTIN_TASKS.RUN_FILE_NOT_FOUND, { script }, ); } if (!noCompile) { const noTests = hre.config.solidity.splitTestsCompilation; await hre.tasks.getTask("build").run({ quiet: true, noTests }); console.log(); } await import(pathToFileURL(normalizedPath).href); }; export default runScriptWithHardhat;