UNPKG

hardhat

Version:

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

53 lines 2.05 kB
import { HardhatError } from "@nomicfoundation/hardhat-errors"; import { ensureError } from "@nomicfoundation/hardhat-utils/error"; import { detectPluginNpmDependencyProblems } from "./detect-plugin-npm-dependency-problems.js"; /** * Resolves the plugin list, returning them in the right order. */ export async function resolvePluginList(projectRoot, userConfigPluginList = []) { return reverseTopologicalSort(projectRoot, userConfigPluginList); } /** * Returns an array of reverse topological order of the plugins and their dependencies. * * If two plugins have no order between them, their relative order should be that of the input array. * * @param plugins The plugins. * @returns The ordered plugins. */ async function reverseTopologicalSort(projectRoot, plugins) { const visitedPlugins = new Map(); const result = []; async function dfs(plugin) { const visited = visitedPlugins.get(plugin.id); if (visited !== undefined) { if (visited !== plugin) { throw new HardhatError(HardhatError.ERRORS.CORE.GENERAL.DUPLICATED_PLUGIN_ID, { id: plugin.id }); } return; } visitedPlugins.set(plugin.id, plugin); if (plugin.dependencies !== undefined) { let dependencyModules; try { dependencyModules = await Promise.all(plugin.dependencies()); } catch (error) { ensureError(error); await detectPluginNpmDependencyProblems(projectRoot, plugin); throw new HardhatError(HardhatError.ERRORS.CORE.PLUGINS.PLUGIN_DEPENDENCY_FAILED_LOAD, { pluginId: plugin.id, }, error); } for (const dependencyModule of dependencyModules) { await dfs(dependencyModule.default); } } result.push(plugin); } for (const plugin of plugins) { await dfs(plugin); } return result; } //# sourceMappingURL=resolve-plugin-list.js.map