Skip to content

Commit

Permalink
feat(query-graph): Remove figgy-pudding
Browse files Browse the repository at this point in the history
  • Loading branch information
evocateur committed Nov 24, 2020
1 parent 69d4704 commit 3b0e2fe
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 30 deletions.
6 changes: 2 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions utils/query-graph/package.json
Expand Up @@ -31,7 +31,6 @@
"test": "echo \"Run tests from root\" && exit 1"
},
"dependencies": {
"@lerna/package-graph": "file:../../core/package-graph",
"figgy-pudding": "^3.5.1"
"@lerna/package-graph": "file:../../core/package-graph"
}
}
42 changes: 18 additions & 24 deletions utils/query-graph/query-graph.js
@@ -1,32 +1,28 @@
"use strict";

const figgyPudding = require("figgy-pudding");
const PackageGraph = require("@lerna/package-graph");

const QueryGraphConfig = figgyPudding({
"graph-type": {},
graphType: "graph-type",
"reject-cycles": {},
rejectCycles: "reject-cycles",
});
/**
* @typedef {object} QueryGraphConfig
* @property {'allDependencies'|'dependencies'} [graphType] "dependencies" excludes devDependencies from graph
* @property {boolean} [rejectCycles] Whether or not to reject dependency cycles
*/

/**
* A mutable PackageGraph used to query for next available packages.
*/
class QueryGraph {
/**
* A mutable PackageGraph used to query for next available packages.
*
* @param {Array<Package>} packages An array of Packages to build the graph out of
* @param {String} [opts.graphType="allDependencies"] "dependencies" excludes devDependencies from graph
* @param {Boolean} [opts.rejectCycles] Whether or not to reject cycles
* @param {import("@lerna/package")[]} packages An array of Packages to build the graph out of
* @param {QueryGraphConfig} [options]
* @constructor
*/
constructor(packages, opts) {
const options = QueryGraphConfig(opts);

constructor(packages, { graphType = "allDependencies", rejectCycles } = {}) {
// Create dependency graph
this.graph = new PackageGraph(packages, options.graphType);
this.graph = new PackageGraph(packages, graphType);

// Evaluate cycles
this.cycles = this.graph.collapseCycles(options.rejectCycles);
this.cycles = this.graph.collapseCycles(rejectCycles);
}

_getNextLeaf() {
Expand Down Expand Up @@ -75,15 +71,13 @@ module.exports.toposort = toposort;
/**
* Sort the input list topologically.
*
* @param {!Array.<Package>} packages An array of Packages to build the list out of
* @param {Object} [options]
* @param {Boolean} options.graphType "allDependencies" or "dependencies", which excludes devDependencies
* @param {Boolean} options.rejectCycles Whether or not to reject cycles
* @param {import("@lerna/package")[]} packages An array of Packages to build the list out of
* @param {QueryGraphConfig} [options]
*
* @returns {Array<Package>} a list of Package instances in topological order
* @returns {import("@lerna/package")[]} A list of Package instances in topological order
*/
function toposort(packages, opts) {
const graph = new QueryGraph(packages, opts);
function toposort(packages, options) {
const graph = new QueryGraph(packages, options);
const result = [];

let batch = graph.getAvailablePackages();
Expand Down

0 comments on commit 3b0e2fe

Please sign in to comment.