Skip to content

Commit

Permalink
Merge pull request #5742 from NomicFoundation/bootstrap-optimizations
Browse files Browse the repository at this point in the history
Bootstrap time optimizations
  • Loading branch information
alcuadrado authored Sep 12, 2024
2 parents bb64e38 + 7c6674c commit 873d07e
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 24 deletions.
11 changes: 6 additions & 5 deletions v-next/example-project/viem-scketch-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@ import { HardhatPlugin } from "@ignored/hardhat-vnext/types/plugins";
import { ChainType } from "@ignored/hardhat-vnext/types/config";
import { HookContext } from "@ignored/hardhat-vnext/types/hooks";

import { NetworkConnection } from "@ignored/hardhat-vnext/types/network";
import type { NetworkConnection } from "@ignored/hardhat-vnext/types/network";

import "@ignored/hardhat-vnext/types/network";

import {
import type {
Client,
createPublicClient,
custom,
CustomTransport,
PublicActions,
PublicClient,
PublicRpcSchema,
} from "viem";
import { PublicActionsL2, publicActionsL2 } from "viem/op-stack";

import type { PublicActionsL2 } from "viem/op-stack";

export type ViemPublicClient<ChainTypeT extends ChainType | string> =
ChainTypeT extends "optimism"
Expand Down Expand Up @@ -47,6 +46,8 @@ export const viemScketchPlugin: HardhatPlugin = {
nextContext: HookContext,
) => Promise<NetworkConnection<ChainTypeT>>,
) {
const { createPublicClient, custom } = await import("viem");
const { publicActionsL2 } = await import("viem/op-stack");
const connection: NetworkConnection<ChainTypeT> = await next(context);

const transport = custom(connection.provider);
Expand Down
4 changes: 3 additions & 1 deletion v-next/hardhat-node-test-runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@
"typescript-eslint": "7.7.1"
},
"dependencies": {
"@ignored/hardhat-vnext": "workspace:^3.0.0-next.2",
"@ignored/hardhat-vnext-errors": "workspace:^3.0.0-next.2",
"@ignored/hardhat-vnext-node-test-reporter": "workspace:^3.0.0-next.2",
"@ignored/hardhat-vnext-utils": "workspace:^3.0.0-next.2",
"@ignored/hardhat-vnext-zod-utils": "workspace:^3.0.0-next.2",
"tsx": "^4.11.0",
"zod": "^3.23.8"
},
"peerDependencies": {
"@ignored/hardhat-vnext": "workspace:^3.0.0-next.2"
}
}
7 changes: 1 addition & 6 deletions v-next/hardhat/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import { register } from "tsx/esm/api";

// We enable the sourcemaps before loading main, so that everything except this
// small file is loaded with sourcemaps enabled.
process.setSourceMapsEnabled(true);

// Register tsx
const _unregister = register();

// eslint-disable-next-line no-restricted-syntax -- Allow top-level await here
const { main } = await import("./internal/cli/main.js");

main(process.argv.slice(2)).catch(() => {
main(process.argv.slice(2), undefined, true).catch(() => {
process.exitCode = 1;
});
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
import type { HardhatRuntimeEnvironmentHooks } from "../../../../types/hooks.js";

import { NetworkManagerImplementation } from "../network-manager.js";
import type { NetworkManager } from "../../../../types/network.js";

export default async (): Promise<Partial<HardhatRuntimeEnvironmentHooks>> => ({
created: async (context, hre) => {
hre.network = new NetworkManagerImplementation(
hre.globalOptions.network !== ""
? hre.globalOptions.network
: hre.config.defaultNetwork,
hre.config.defaultChainType,
hre.config.networks,
context.hooks,
);
let networkManager: NetworkManager | undefined;

hre.network = {
async connect(networkName, chainType, networkConfigOverride) {
if (networkManager === undefined) {
const { NetworkManagerImplementation } = await import(
"../network-manager.js"
);

networkManager = new NetworkManagerImplementation(
hre.globalOptions.network !== ""
? hre.globalOptions.network
: hre.config.defaultNetwork,
hre.config.defaultChainType,
hre.config.networks,
context.hooks,
);
}

return networkManager.connect(
networkName,
chainType,
networkConfigOverride,
);
},
};
},
});
7 changes: 7 additions & 0 deletions v-next/hardhat/src/internal/cli/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { isCi } from "@ignored/hardhat-vnext-utils/ci";
import { kebabToCamelCase } from "@ignored/hardhat-vnext-utils/string";
import debug from "debug";
import { register } from "tsx/esm/api";

import {
ArgumentType,
Expand Down Expand Up @@ -41,6 +42,7 @@ import { printVersionMessage } from "./version.js";
export async function main(
cliArguments: string[],
print: (message: string) => void = console.log,
registerTsx = false,
): Promise<void> {
const log = debug("hardhat:core:cli:main");

Expand Down Expand Up @@ -78,6 +80,11 @@ export async function main(

const projectRoot = await resolveProjectRoot(configPath);

// Register tsx
if (registerTsx) {
register();
}

const userConfig = await importUserConfig(configPath);

log("User config imported");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { createRequire } from "node:module";
import path from "node:path";

import { HardhatError } from "@ignored/hardhat-vnext-errors";
import semver from "semver";

/**
* Validate that a plugin is installed and that its peer dependencies are
Expand Down Expand Up @@ -66,7 +65,9 @@ export async function detectPluginNpmDependencyProblems(

const installedVersion = dependencyPackageJsonResult.packageJson.version;

if (!semver.satisfies(installedVersion, versionSpec)) {
const { satisfies } = await import("semver");

if (!satisfies(installedVersion, versionSpec)) {
throw new HardhatError(
HardhatError.ERRORS.PLUGINS.DEPENDENCY_VERSION_MISMATCH,
{
Expand Down

0 comments on commit 873d07e

Please sign in to comment.