How to use the toposort.array function in toposort

To help you get started, we’ve selected a few toposort examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github michalkvasnicak / create-js-app / packages / js-app-plugin-universal-webpack / src / webpack / AssetsPlugin.js View on Github external
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)) {
github xivanalysis / xivanalysis / src / analyser / Analyser.tsx View on Github external
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,
			}))
		})
	}
github fossasia / susper.com / node_modules / html-webpack-plugin / lib / chunksorter.js View on Github external
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);
};
github jake-101 / bael-template / node_modules / html-webpack-plugin / lib / chunksorter.js View on Github external
// 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 => {
github wilsonjackson / karma-angular-filesort / lib / sort.js View on Github external
// 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;
};
github jake-101 / bael-template / node_modules / html-webpack-plugin / lib / chunksorter.js View on Github external
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);
  }
};
github LuvDaSun / sqlpatch / src / sqlpatch.js View on Github external
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;
github jquense / yup / src / util / sortFields.js View on Github external
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();
}
github magda-io / magda / scripts / build-changed.js View on Github external
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 =
github bokeh / bokeh / bokehjs / make / task.ts View on Github external
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)
}

toposort

Topological sort of directed ascyclic graphs (like dependecy lists)

MIT
Latest version published 7 years ago

Package Health Score

67 / 100
Full package analysis

Popular toposort functions