hardhat-deploy
Advanced tools
Comparing version 0.7.0-beta.0 to 0.7.0-beta.1
@@ -26,10 +26,7 @@ "use strict"; | ||
require("./type-extensions"); | ||
const chalk_1 = __importDefault(require("chalk")); | ||
const path_1 = __importDefault(require("path")); | ||
const config_1 = require("hardhat/config"); | ||
const errors_1 = require("hardhat/internal/core/errors"); | ||
const server_1 = require("hardhat/internal/hardhat-network/jsonrpc/server"); | ||
const constants_1 = require("hardhat/internal/constants"); | ||
const types = __importStar(require("hardhat/internal/core/params/argumentTypes")); | ||
const errors_list_1 = require("hardhat/internal/core/errors-list"); | ||
const chalk_1 = __importDefault(require("chalk")); | ||
const task_names_1 = require("hardhat/builtin-tasks/task-names"); | ||
@@ -42,10 +39,5 @@ const debug_1 = __importDefault(require("debug")); | ||
function isHardhatEVM(hre) { | ||
const { network, hardhatArguments, config } = hre; | ||
const { network, hardhatArguments } = hre; | ||
return !(network.name !== constants_1.HARDHAT_NETWORK_NAME && | ||
// We normally set the default network as hardhatArguments.network, | ||
// so this check isn't enough, and we add the next one. This has the | ||
// effect of `--network <defaultNetwork>` being a false negative, but | ||
// not a big deal. | ||
hardhatArguments.network !== undefined && | ||
hardhatArguments.network !== config.defaultNetwork); | ||
hardhatArguments.network !== undefined); | ||
} | ||
@@ -142,3 +134,3 @@ function normalizePath(config, userPath, defaultPath) { | ||
} | ||
config_1.internalTask(task_names_1.TASK_COMPILE_SOLIDITY_GET_COMPILER_INPUT).setAction(async (_, __, runSuper) => { | ||
config_1.subtask(task_names_1.TASK_COMPILE_SOLIDITY_GET_COMPILER_INPUT).setAction(async (_, __, runSuper) => { | ||
const input = await runSuper(); | ||
@@ -148,3 +140,3 @@ setupExtraSolcSettings(input.settings); | ||
}); | ||
config_1.internalTask("deploy:run", "deploy ") | ||
config_1.subtask("deploy:run", "deploy ") | ||
.addOptionalParam("export", "export current network deployments") | ||
@@ -287,2 +279,9 @@ .addOptionalParam("exportAll", "export all deployments into one file") | ||
}); | ||
async function enableProviderLogging(provider, enabled) { | ||
await provider.request({ | ||
method: "hardhat_setLoggingEnabled", | ||
params: [enabled] | ||
}); | ||
} | ||
let nodeTaskArgs; | ||
config_1.task(task_names_1.TASK_NODE, "Starts a JSON-RPC server on top of Hardhat EVM") | ||
@@ -297,97 +296,39 @@ .addOptionalParam("export", "export current network deployments") | ||
.addFlag("noDeploy", "do not deploy") | ||
.addFlag("showAccounts", "display account addresses and private keys") | ||
.addFlag("watch", "redeploy on every change of contract or deploy script") | ||
.setAction(async (args, hre, runSuper) => { | ||
if (args.noDeploy) { | ||
await runSuper(args); | ||
return; | ||
.setAction(async (args, _, runSuper) => { | ||
nodeTaskArgs = args; | ||
console.log("node", args); | ||
await runSuper(args); | ||
}); | ||
config_1.subtask(task_names_1.TASK_NODE_GET_PROVIDER).setAction(async (args, hre, runSuper) => { | ||
const provider = await runSuper(args); | ||
if (nodeTaskArgs.noDeploy) { | ||
console.log("skip"); | ||
return provider; | ||
} | ||
if (!isHardhatEVM(hre)) { | ||
throw new errors_1.HardhatError(errors_list_1.ERRORS.BUILTIN_TASKS.JSONRPC_UNSUPPORTED_NETWORK); | ||
console.log("enabling logging"); | ||
await enableProviderLogging(provider, false); | ||
if (isHardhatEVM(hre)) { | ||
hre.network.name = "localhost"; // Ensure deployments can be fetched with console | ||
} | ||
const { config } = hre; | ||
hre.network.name = "localhost"; // Ensure deployments can be fetched with console | ||
// TODO use localhost config ? // Or post an issue on hardhat | ||
const watch = args.watch; | ||
args.watch = false; | ||
args.log = !args.silent; | ||
delete args.silent; | ||
args.pendingtx = false; | ||
await hre.run("deploy:run", args); | ||
// enable logging | ||
// TODO fix this when there's a proper mechanism for doing this | ||
let provider = hre.network.provider; | ||
let i = 0; | ||
while (provider._loggingEnabled === undefined) { | ||
if (provider._provider !== undefined) { | ||
provider = provider._provider; | ||
} | ||
else if (provider._wrappedProvider !== undefined) { | ||
provider = provider._wrappedProvider; | ||
} | ||
else { | ||
throw new Error("should not happen"); | ||
} | ||
// a HardhatEVMProvider should eventually be found, but | ||
// just in case we add a max number of iterations here | ||
// to avoid and endless loop | ||
i++; | ||
if (i > 100) { | ||
throw new Error("should not happen"); | ||
} | ||
nodeTaskArgs.watch = false; | ||
nodeTaskArgs.log = !nodeTaskArgs.silent; | ||
delete nodeTaskArgs.silent; | ||
nodeTaskArgs.pendingtx = false; | ||
await hre.run("deploy:run", nodeTaskArgs); | ||
await enableProviderLogging(provider, true); | ||
return provider; | ||
}); | ||
config_1.subtask(task_names_1.TASK_NODE_SERVER_READY).setAction(async (args, hre, runSuper) => { | ||
if (nodeTaskArgs.showAccounts) { | ||
await runSuper(args); | ||
} | ||
provider._loggingEnabled = true; | ||
provider._ethModule._logger = provider._logger; | ||
const { hostname, port } = args; | ||
let server; | ||
try { | ||
const serverConfig = { | ||
hostname, | ||
port, | ||
provider: hre.network.provider | ||
}; | ||
server = new server_1.JsonRpcServer(serverConfig); | ||
const { port: actualPort, address } = await server.listen(); | ||
console.log(chalk_1.default.green(`Started HTTP and WebSocket JSON-RPC server at http://${address}:${actualPort}/`)); | ||
else { | ||
console.log(chalk_1.default.green(`Started HTTP and WebSocket JSON-RPC server at http://${args.address}:${args.port}/`)); | ||
console.log(); | ||
let watchRequired; | ||
try { | ||
watchRequired = require("hardhat/builtin-tasks/utils/watch"); | ||
} | ||
catch (e) { } | ||
let reporterRequired; | ||
try { | ||
reporterRequired = require("hardhat/internal/sentry/reporter"); | ||
} | ||
catch (e) { } | ||
if (watchRequired) { | ||
try { | ||
const { watchCompilerOutput } = watchRequired; | ||
await watchCompilerOutput(server.getProvider(), config.paths); | ||
} | ||
catch (error) { | ||
console.warn(chalk_1.default.yellow("There was a problem watching the compiler output, changes in the contracts won't be reflected in the Hardhat EVM. Run Hardhat with --verbose to learn more.")); | ||
log("Compilation output can't be watched. Please report this to help us improve Hardhat.\n", error); | ||
if (reporterRequired) { | ||
const { Reporter } = reporterRequired; | ||
Reporter.reportError(error); | ||
} | ||
} | ||
} | ||
// const networkConfig = config.networks[ | ||
// HARDHAT_NETWORK_NAME | ||
// ] as HardhatNetworkConfig; | ||
// logHardhatEvmAccounts(networkConfig); | ||
} | ||
catch (error) { | ||
if (errors_1.HardhatError.isHardhatError(error)) { | ||
throw error; | ||
} | ||
throw new errors_1.HardhatError(errors_list_1.ERRORS.BUILTIN_TASKS.JSONRPC_SERVER_ERROR, { | ||
error: error.message | ||
}, error); | ||
if (nodeTaskArgs.watch) { | ||
await hre.run("deploy:run", Object.assign(Object.assign({}, nodeTaskArgs), { watchOnly: true })); | ||
} | ||
if (watch) { | ||
await hre.run("deploy:run", Object.assign(Object.assign({}, args), { watchOnly: true })); | ||
} | ||
await server.waitUntilClosed(); | ||
}); | ||
@@ -394,0 +335,0 @@ config_1.task("etherscan-verify", "submit contract source code to etherscan") |
{ | ||
"name": "hardhat-deploy", | ||
"version": "0.7.0-beta.0", | ||
"version": "0.7.0-beta.1", | ||
"description": "Hardhat Plugin For Replicable Deployments And Tests", | ||
@@ -5,0 +5,0 @@ "repository": "github:wighawag/hardhat-deploy", |
198
src/index.ts
import "./type-extensions"; | ||
import chalk from "chalk"; | ||
import path from "path"; | ||
@@ -7,23 +8,14 @@ import { | ||
HardhatConfig, | ||
HardhatUserConfig | ||
HardhatUserConfig, | ||
EthereumProvider | ||
} from "hardhat/types"; | ||
import { | ||
extendEnvironment, | ||
task, | ||
internalTask, | ||
extendConfig | ||
} from "hardhat/config"; | ||
import { HardhatError } from "hardhat/internal/core/errors"; | ||
import { | ||
JsonRpcServer, | ||
JsonRpcServerConfig | ||
} from "hardhat/internal/hardhat-network/jsonrpc/server"; | ||
import { extendEnvironment, task, subtask, extendConfig } from "hardhat/config"; | ||
import { HARDHAT_NETWORK_NAME } from "hardhat/internal/constants"; | ||
import * as types from "hardhat/internal/core/params/argumentTypes"; | ||
import { ERRORS } from "hardhat/internal/core/errors-list"; | ||
import chalk from "chalk"; | ||
import { | ||
TASK_NODE, | ||
TASK_COMPILE_SOLIDITY_GET_COMPILER_INPUT, | ||
TASK_TEST | ||
TASK_TEST, | ||
TASK_NODE_GET_PROVIDER, | ||
TASK_NODE_SERVER_READY | ||
} from "hardhat/builtin-tasks/task-names"; | ||
@@ -39,11 +31,6 @@ | ||
function isHardhatEVM(hre: HardhatRuntimeEnvironment): boolean { | ||
const { network, hardhatArguments, config } = hre; | ||
const { network, hardhatArguments } = hre; | ||
return !( | ||
network.name !== HARDHAT_NETWORK_NAME && | ||
// We normally set the default network as hardhatArguments.network, | ||
// so this check isn't enough, and we add the next one. This has the | ||
// effect of `--network <defaultNetwork>` being a false negative, but | ||
// not a big deal. | ||
hardhatArguments.network !== undefined && | ||
hardhatArguments.network !== config.defaultNetwork | ||
hardhatArguments.network !== undefined | ||
); | ||
@@ -176,3 +163,3 @@ } | ||
internalTask(TASK_COMPILE_SOLIDITY_GET_COMPILER_INPUT).setAction( | ||
subtask(TASK_COMPILE_SOLIDITY_GET_COMPILER_INPUT).setAction( | ||
async (_, __, runSuper) => { | ||
@@ -186,3 +173,3 @@ const input = await runSuper(); | ||
internalTask("deploy:run", "deploy ") | ||
subtask("deploy:run", "deploy ") | ||
.addOptionalParam("export", "export current network deployments") | ||
@@ -364,2 +351,13 @@ .addOptionalParam("exportAll", "export all deployments into one file") | ||
async function enableProviderLogging( | ||
provider: EthereumProvider, | ||
enabled: boolean | ||
) { | ||
await provider.request({ | ||
method: "hardhat_setLoggingEnabled", | ||
params: [enabled] | ||
}); | ||
} | ||
let nodeTaskArgs: any; | ||
task(TASK_NODE, "Starts a JSON-RPC server on top of Hardhat EVM") | ||
@@ -384,124 +382,52 @@ .addOptionalParam("export", "export current network deployments") | ||
.addFlag("noDeploy", "do not deploy") | ||
.addFlag("showAccounts", "display account addresses and private keys") | ||
.addFlag("watch", "redeploy on every change of contract or deploy script") | ||
.setAction(async (args, hre, runSuper) => { | ||
if (args.noDeploy) { | ||
await runSuper(args); | ||
return; | ||
} | ||
.setAction(async (args, _, runSuper) => { | ||
nodeTaskArgs = args; | ||
console.log("node", args); | ||
await runSuper(args); | ||
}); | ||
if (!isHardhatEVM(hre)) { | ||
throw new HardhatError(ERRORS.BUILTIN_TASKS.JSONRPC_UNSUPPORTED_NETWORK); | ||
subtask(TASK_NODE_GET_PROVIDER).setAction( | ||
async (args, hre, runSuper): Promise<EthereumProvider> => { | ||
const provider = await runSuper(args); | ||
if (nodeTaskArgs.noDeploy) { | ||
console.log("skip"); | ||
return provider; | ||
} | ||
console.log("enabling logging"); | ||
await enableProviderLogging(provider, false); | ||
const { config } = hre; | ||
hre.network.name = "localhost"; // Ensure deployments can be fetched with console | ||
// TODO use localhost config ? // Or post an issue on hardhat | ||
const watch = args.watch; | ||
args.watch = false; | ||
args.log = !args.silent; | ||
delete args.silent; | ||
args.pendingtx = false; | ||
await hre.run("deploy:run", args); | ||
// enable logging | ||
// TODO fix this when there's a proper mechanism for doing this | ||
let provider = hre.network.provider as any; | ||
let i = 0; | ||
while (provider._loggingEnabled === undefined) { | ||
if (provider._provider !== undefined) { | ||
provider = provider._provider; | ||
} else if (provider._wrappedProvider !== undefined) { | ||
provider = provider._wrappedProvider; | ||
} else { | ||
throw new Error("should not happen"); | ||
} | ||
// a HardhatEVMProvider should eventually be found, but | ||
// just in case we add a max number of iterations here | ||
// to avoid and endless loop | ||
i++; | ||
if (i > 100) { | ||
throw new Error("should not happen"); | ||
} | ||
if (isHardhatEVM(hre)) { | ||
hre.network.name = "localhost"; // Ensure deployments can be fetched with console | ||
} | ||
provider._loggingEnabled = true; | ||
provider._ethModule._logger = provider._logger; | ||
nodeTaskArgs.watch = false; | ||
nodeTaskArgs.log = !nodeTaskArgs.silent; | ||
delete nodeTaskArgs.silent; | ||
nodeTaskArgs.pendingtx = false; | ||
await hre.run("deploy:run", nodeTaskArgs); | ||
const { hostname, port } = args; | ||
let server; | ||
try { | ||
const serverConfig: JsonRpcServerConfig = { | ||
hostname, | ||
port, | ||
provider: hre.network.provider | ||
}; | ||
await enableProviderLogging(provider, true); | ||
server = new JsonRpcServer(serverConfig); | ||
return provider; | ||
} | ||
); | ||
const { port: actualPort, address } = await server.listen(); | ||
subtask(TASK_NODE_SERVER_READY).setAction(async (args, hre, runSuper) => { | ||
if (nodeTaskArgs.showAccounts) { | ||
await runSuper(args); | ||
} else { | ||
console.log( | ||
chalk.green( | ||
`Started HTTP and WebSocket JSON-RPC server at http://${args.address}:${args.port}/` | ||
) | ||
); | ||
console.log(); | ||
} | ||
console.log( | ||
chalk.green( | ||
`Started HTTP and WebSocket JSON-RPC server at http://${address}:${actualPort}/` | ||
) | ||
); | ||
if (nodeTaskArgs.watch) { | ||
await hre.run("deploy:run", { ...nodeTaskArgs, watchOnly: true }); | ||
} | ||
}); | ||
console.log(); | ||
let watchRequired; | ||
try { | ||
watchRequired = require("hardhat/builtin-tasks/utils/watch"); | ||
} catch (e) {} | ||
let reporterRequired; | ||
try { | ||
reporterRequired = require("hardhat/internal/sentry/reporter"); | ||
} catch (e) {} | ||
if (watchRequired) { | ||
try { | ||
const { watchCompilerOutput } = watchRequired; | ||
await watchCompilerOutput(server.getProvider(), config.paths); | ||
} catch (error) { | ||
console.warn( | ||
chalk.yellow( | ||
"There was a problem watching the compiler output, changes in the contracts won't be reflected in the Hardhat EVM. Run Hardhat with --verbose to learn more." | ||
) | ||
); | ||
log( | ||
"Compilation output can't be watched. Please report this to help us improve Hardhat.\n", | ||
error | ||
); | ||
if (reporterRequired) { | ||
const { Reporter } = reporterRequired; | ||
Reporter.reportError(error); | ||
} | ||
} | ||
} | ||
// const networkConfig = config.networks[ | ||
// HARDHAT_NETWORK_NAME | ||
// ] as HardhatNetworkConfig; | ||
// logHardhatEvmAccounts(networkConfig); | ||
} catch (error) { | ||
if (HardhatError.isHardhatError(error)) { | ||
throw error; | ||
} | ||
throw new HardhatError( | ||
ERRORS.BUILTIN_TASKS.JSONRPC_SERVER_ERROR, | ||
{ | ||
error: error.message | ||
}, | ||
error | ||
); | ||
} | ||
if (watch) { | ||
await hre.run("deploy:run", { ...args, watchOnly: true }); | ||
} | ||
await server.waitUntilClosed(); | ||
}); | ||
task("etherscan-verify", "submit contract source code to etherscan") | ||
@@ -508,0 +434,0 @@ .addOptionalParam("apiKey", "etherscan api key", undefined, types.string) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
790001
9699