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);
}
};
var nameEdgeList = nameList.reduce(function(list, name) {
var fileInfoItem = fileInfoMap[name];
if ('require' in fileInfoItem.properties) {
fileInfoItem.properties.require.
filter(function(dependencyName) {
return ~nameList.indexOf(dependencyName);
}).
forEach(function(dependencyName) {
list.push([name, dependencyName]);
});
}
return list;
}, []);
var dependencyList = toposort.array(nameList, nameEdgeList);
dependencyList.reverse();
model.patches = dependencyList.map(function(name, index) {
var fileInfoItem = fileInfoMap[name];
return fileInfoItem;
}).
filter(function(item) {
return item;
}).
map(function(item, index) {
var number = index + 1;
item.number = number;
if (!~excludes.indexOf(`${key}-${node}`)) edges.push([key, node]);
}
for (var key in fields)
if (has(fields, key)) {
let value = fields[key];
if (!~nodes.indexOf(key)) nodes.push(key);
if (Ref.isRef(value) && value.isSibling) addNode(value.path, key);
else if (isSchema(value) && value._deps)
value._deps.forEach(path => addNode(path, key));
}
return toposort.array(nodes, edges).reverse();
}
const packageIndex = {};
packageList.forEach(package => {
packageIndex[package.packageJson.name] = package;
});
const edges = [];
packageList.forEach(package => {
Object.keys(package.allDependencies).forEach(dependency => {
const dependencyPackage = packageIndex[dependency];
if (dependencyPackage) {
edges.push([package, dependencyPackage]);
}
});
});
const sortedPackages = toposort.array(packageList, edges).reverse();
sortedPackages.forEach(package => {
const packagePath = package.packagePath;
const name = package.packageJson.name;
const dependencies = edges
.filter(edge => edge[0] === package)
.map(edge => edge[1]);
const lastModifiedFiles = dependencies.map(dependency =>
findLastModifiedFile(path.resolve(dependency.packagePath, "dist"))
);
const srcLastModified = findLastModifiedFile(
path.resolve(packagePath, "src")
);
const distLastModified =
if (selected.length != 0) {
for (const task of selected)
build_graph(task)
} else
throw new Error(`empty selection: ${name}`)
} else {
const task = tasks.get(name)
if (task != null)
build_graph(task)
else
throw new Error(`unknown task: ${name}`)
}
}
return toposort(Array.from(nodes), edges)
}