Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public async registerPlugins(pluginNames: readonly string[]): Promise {
const plugins = pluginNames.map((pluginName) =>
pluginsUtil.getPlugin({
logger: this.logger,
pluginName,
}),
);
const graph = plugins.reduce>(
(acc, plugin) => acc.concat(plugin.dependencies.map<[string, string]>((dep) => [plugin.name, dep])),
[],
);
const sorted = _.reverse(toposort(graph));
const pluginNameToPlugin = plugins.reduce<{ [pluginName: string]: Plugin }>(
(acc, plugin) => ({
...acc,
[plugin.name]: plugin,
}),
{},
);
const noDepPlugins = plugins.filter((plugin) => plugin.dependencies.length === 0);
await Promise.all(noDepPlugins.map(async (plugin) => this.registerPlugin(plugin)));
// tslint:disable-next-line no-loop-statement
for (const pluginName of sorted) {
const plugin = pluginNameToPlugin[pluginName] as Plugin | undefined;
// The later plugins will fail with missing dependency
if (plugin !== undefined) {
private _getAllSolidityLibNames(contractNames: string[]): string[] {
const graph: string[][] = [];
const nodes: string[] = [];
contractNames.forEach(contractName => {
this._populateDependencyGraph(contractName, nodes, graph);
});
// exclude original contracts
return [...difference(toposort(graph), contractNames).reverse()];
}
async registerPlugins(pluginNames: Array): Promise {
const plugins = pluginNames.map((pluginName) =>
pluginsUtil.getPlugin({
monitor: this._monitor,
pluginName,
}),
);
const graph = plugins.reduce(
(acc, plugin) =>
acc.concat(plugin.dependencies.map((dep) => [plugin.name, dep])),
[],
);
const sorted = toposort(graph).reverse();
const pluginNameToPlugin = plugins.reduce((acc, plugin) => {
acc[plugin.name] = plugin;
return acc;
}, {});
const noDepPlugins = plugins.filter(
(plugin) => plugin.dependencies.length === 0,
);
await Promise.all(
noDepPlugins.map((plugin) => this._registerPlugin(plugin)),
);
for (const pluginName of sorted) {
const plugin = pluginNameToPlugin[pluginName];
// The later plugins will fail with missing dependency
if (plugin != null) {
// eslint-disable-next-line
await this._registerPlugin(pluginNameToPlugin[pluginName]);
nodes.push([moduleId, null])
if (hmrAccepted === 'direct') return
const { parents } = oldModules[moduleId]
parents.forEach(parent => {
nodes.push([moduleId, parent])
iterate(parent)
})
}
moduleIds.forEach(iterate)
if (rejected) {
throw new Error(`HMR not applied because some modules rejected/did not accept it`)
}
// Remove null at the end
return toposort(nodes).slice(0, -1)
}
symbols: Symbols,
childMap: ChildMap,
onlyTheseAndChildren: ?(Set | Array) = null
): {
evalOrder: Array,
cycles: { [nodeName: string]: Array }
} {
// construct dependency graph as array of nodes
const nodesToInclude = onlyTheseAndChildren
? [...getDescendants(onlyTheseAndChildren, childMap)]
: Object.keys(childMap)
let sorted, isolated, edges, cycles, withoutCycles
try {
( { edges, isolated } = getSubgraphEdges(childMap, nodesToInclude))
sorted = toposort(edges)
cycles = {}
}
catch (error) {
if (error.message.startsWith('Cyclic dependency')) {
( { withoutCycles, cycles } = removeCycles(childMap));
( { edges, isolated } = getSubgraphEdges(withoutCycles,
nodesToInclude.filter(node => !cycles.hasOwnProperty(node))
))
sorted = toposort(edges)
}
else {
throw error
}
}
const evalOrder = [...sorted, ...isolated]
? [...getDescendants(onlyTheseAndChildren, childMap)]
: Object.keys(childMap)
let sorted, isolated, edges, cycles, withoutCycles
try {
( { edges, isolated } = getSubgraphEdges(childMap, nodesToInclude))
sorted = toposort(edges)
cycles = {}
}
catch (error) {
if (error.message.startsWith('Cyclic dependency')) {
( { withoutCycles, cycles } = removeCycles(childMap));
( { edges, isolated } = getSubgraphEdges(withoutCycles,
nodesToInclude.filter(node => !cycles.hasOwnProperty(node))
))
sorted = toposort(edges)
}
else {
throw error
}
}
const evalOrder = [...sorted, ...isolated]
return { evalOrder, cycles }
}
function get_overlap_graph(boxes) {
const nodes = [];
boxes.forEach((box, i) => nodes.push(i));
const edges = [];
boxes.forEach((b1, i) => {
boxes.forEach((b2, j) => {
if (overlaps(b1, b2)) edges.push([i, j, b1, b2]);
});
});
const overlapping = toposort(edges);
return overlapping.reverse().map(i => boxes[i]);
}
private getAllSourceFiles(sourceFile: ts.SourceFile): readonly ts.SourceFile[] {
const sourceFilesMap = this.getAllSourceFilesWorker(sourceFile);
const graph = _.flatten(
[...sourceFilesMap.entries()].map(([file, files]) =>
files.map<[string, string]>((upstreamFile) => [file.fileName, upstreamFile.fileName]),
),
);
const sorted = _.reverse(toposort(graph));
const filePathToSourceFile = new Map(
[...sourceFilesMap.keys()].map((file) => [file.fileName, file] as const),
);
return sorted.map((filePath) => filePathToSourceFile.get(filePath)).filter(utils.notNull);
}