Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
initialChunks.forEach((chunk) => {
if (chunk.parents) {
// Add an edge for each parent (parent -> child)
chunk.parents.forEach((parentId) => {
const parentChunk = chunks[parentId];
// If the parent chunk does not exist (e.g. because of an excluded chunk)
// we ignore that parent
if (parentChunk) {
edges.push([parentChunk, chunk]);
}
});
}
});
const sorted = toposort.array(initialChunks, edges);
sorted.forEach((chunk) => {
let map;
if (!entryPoints[chunk.names[0]]) {
map = entryPoints[chunk.names[0]] = { css: [], js: [] };
} else {
map = entryPoints[chunk.names[0]];
}
const files = Array.isArray(chunk.files) ? chunk.files : [chunk.files];
files.forEach((file) => {
const filePath = publicPath + file;
if (/\.js$/.test(file)) {
private buildModules(constructors: Record) {
// Build the values we need for the toposort
const nodes = Object.keys(constructors)
const edges: Array<[string, string]> = []
nodes.forEach(mod => constructors[mod].dependencies.forEach(dep => {
edges.push([mod, this.getDepHandle(dep)])
}))
// Sort modules to load dependencies first
// Reverse is required to switch it into depencency order instead of sequence
// This will naturally throw an error on cyclic deps
this.moduleOrder = toposort.array(nodes, edges).reverse()
// Initialise the modules
this.moduleOrder.forEach(mod => {
this.modules.set(mod, new constructors[mod]({
analyser: this,
modules: this.modules,
}))
})
}
chunks.forEach(function (chunk) {
if (chunk.parents) {
// Add an edge for each parent (parent -> child)
chunk.parents.forEach(function (parentId) {
// webpack2 chunk.parents are chunks instead of string id(s)
var parentChunk = _.isObject(parentId) ? parentId : nodeMap[parentId];
// If the parent chunk does not exist (e.g. because of an excluded chunk)
// we ignore that parent
if (parentChunk) {
edges.push([parentChunk, chunk]);
}
});
}
});
// We now perform a topological sorting on the input chunks and built edges
return toposort.array(chunks, edges);
};
// We build a map (chunk-id -> chunk) for faster access during graph building.
const nodeMap = {};
chunks.forEach(chunk => {
nodeMap[chunk.id] = chunk;
});
// Next, we add an edge for each parent relationship into the graph
let edges = [];
if (chunkGroups) {
// Add an edge for each parent (parent -> child)
edges = chunkGroups.reduce((result, chunkGroup) => result.concat(
Array.from(chunkGroup.parentsIterable, parentGroup => [parentGroup, chunkGroup])
), []);
const sortedGroups = toposort.array(chunkGroups, edges);
// flatten chunkGroup into chunks
const sortedChunks = sortedGroups
.reduce((result, chunkGroup) => result.concat(chunkGroup.chunks), [])
.map(chunk => // use the chunk from the list passed in, since it may be a filtered list
nodeMap[chunk.id])
.filter((chunk, index, self) => {
// make sure exists (ie excluded chunks not in nodeMap)
const exists = !!chunk;
// make sure we have a unique list
const unique = self.indexOf(chunk) === index;
return exists && unique;
});
return sortedChunks;
} else {
// before webpack 4 there was no chunkGroups
chunks.forEach(chunk => {
// Convert all module names to actual files with declarations:
for (var i = 0; i < sortEdges.length; i++) {
var moduleName = sortEdges[i][1];
var declarationFile = moduleFiles[moduleName];
if (declarationFile) {
sortEdges[i][1] = declarationFile;
} else {
// Depending on module outside list (possibly a 3rd party one),
// don't care when sorting:
sortEdges.splice(i--, 1);
}
}
// Sort `files` with `toSort` as dependency tree:
Array.prototype.splice.apply(files, [subsetStart, 0].concat(toposort.array(sortNodes, sortEdges).reverse()));
log.debug('Sorted files:' + os.EOL + files.map(function (file) {
return '\t' + file.path;
}).join(os.EOL));
return files;
};
chunks.forEach(chunk => {
if (chunk.parents) {
// Add an edge for each parent (parent -> child)
chunk.parents.forEach(parentId => {
// webpack2 chunk.parents are chunks instead of string id(s)
const parentChunk = _.isObject(parentId) ? parentId : nodeMap[parentId];
// If the parent chunk does not exist (e.g. because of an excluded chunk)
// we ignore that parent
if (parentChunk) {
edges.push([parentChunk, chunk]);
}
});
}
});
// We now perform a topological sorting on the input chunks and built edges
return toposort.array(chunks, edges);
}
};
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)
}