@lerna/query-graph
Advanced tools
Comparing version 3.18.5 to 4.0.0
@@ -6,2 +6,34 @@ # Change Log | ||
# [4.0.0](https://github.com/lerna/lerna/compare/v3.22.1...v4.0.0) (2021-02-10) | ||
### Bug Fixes | ||
* Improve accuracy of JSDoc type annotations ([1ec69f0](https://github.com/lerna/lerna/commit/1ec69f0e0f7a3f1e0c74dbacb17fab2d7b7a8a44)) | ||
### Features | ||
* Consume named exports of sibling modules ([63499e3](https://github.com/lerna/lerna/commit/63499e33652bc78fe23751875d74017e2f16a689)) | ||
* Drop support for Node v6.x & v8.x ([ff4bb4d](https://github.com/lerna/lerna/commit/ff4bb4da215555e3bb136f5af09b5cbc631e57bb)) | ||
* Expose named export ([c1303f1](https://github.com/lerna/lerna/commit/c1303f13adc4cf15f96ff25889b52149f8224c0e)) | ||
* Remove default export ([e2f1ec3](https://github.com/lerna/lerna/commit/e2f1ec3dd049d2a89880029908a2aa7c66f15082)) | ||
* **query-graph:** Remove figgy-pudding ([3b0e2fe](https://github.com/lerna/lerna/commit/3b0e2fec7c274bc93627404295b51638cb7d7e60)) | ||
### BREAKING CHANGES | ||
* The default export has been removed, please use a named export instead. | ||
* Node v6.x & v8.x are no longer supported. Please upgrade to the latest LTS release. | ||
Here's the gnarly one-liner I used to make these changes: | ||
``` | ||
npx lerna exec --concurrency 1 --stream -- 'json -I -f package.json -e '"'"'this.engines=this.engines||{};this.engines.node=">= 10.18.0"'"'" | ||
``` | ||
(requires `npm i -g json` beforehand) | ||
## [3.18.5](https://github.com/lerna/lerna/compare/v3.18.4...v3.18.5) (2019-11-20) | ||
@@ -8,0 +40,0 @@ |
{ | ||
"name": "@lerna/query-graph", | ||
"version": "3.18.5", | ||
"version": "4.0.0", | ||
"description": "An internal Lerna tool", | ||
@@ -20,3 +20,3 @@ "keywords": [ | ||
"engines": { | ||
"node": ">= 6.9.0" | ||
"node": ">= 10.18.0" | ||
}, | ||
@@ -35,6 +35,5 @@ "publishConfig": { | ||
"dependencies": { | ||
"@lerna/package-graph": "3.18.5", | ||
"figgy-pudding": "^3.5.1" | ||
"@lerna/package-graph": "4.0.0" | ||
}, | ||
"gitHead": "2612f51e7eecec58eacf0571724e6989e4b8e42d" | ||
"gitHead": "4582c476e07dddddd6b2e3ab6e7f52c1f9eed59a" | ||
} |
"use strict"; | ||
const figgyPudding = require("figgy-pudding"); | ||
const PackageGraph = require("@lerna/package-graph"); | ||
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. | ||
* Sort a list of Packages topologically. | ||
* | ||
* @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 | ||
* @constructor | ||
* @param {import("@lerna/package").Package[]} packages An array of Packages to build the list out of | ||
* @param {QueryGraphConfig} [options] | ||
* | ||
* @returns {import("@lerna/package").Package[]} A list of Package instances in topological order | ||
*/ | ||
constructor(packages, opts) { | ||
const options = QueryGraphConfig(opts); | ||
static toposort(packages, options) { | ||
const graph = new QueryGraph(packages, options); | ||
const result = []; | ||
let batch = graph.getAvailablePackages(); | ||
while (batch.length) { | ||
for (const node of batch) { | ||
// no need to take() in synchronous loop | ||
result.push(node.pkg); | ||
graph.markAsDone(node); | ||
} | ||
batch = graph.getAvailablePackages(); | ||
} | ||
return result; | ||
} | ||
/** | ||
* @param {import("@lerna/package").Package[]} packages An array of Packages to build the graph out of | ||
* @param {QueryGraphConfig} [options] | ||
*/ | ||
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() { | ||
return Array.from(this.graph.values()).filter(node => node.localDependencies.size === 0); | ||
return Array.from(this.graph.values()).filter((node) => node.localDependencies.size === 0); | ||
} | ||
_getNextCycle() { | ||
const cycle = Array.from(this.cycles).find(cycleNode => cycleNode.localDependencies.size === 0); | ||
const cycle = Array.from(this.cycles).find((cycleNode) => cycleNode.localDependencies.size === 0); | ||
@@ -59,2 +81,5 @@ if (!cycle) { | ||
/** | ||
* @param {string} name | ||
*/ | ||
markAsTaken(name) { | ||
@@ -64,2 +89,5 @@ this.graph.delete(name); | ||
/** | ||
* @param {import("@lerna/package-graph").PackageGraphNode} candidateNode | ||
*/ | ||
markAsDone(candidateNode) { | ||
@@ -74,32 +102,3 @@ this.graph.remove(candidateNode); | ||
module.exports = QueryGraph; | ||
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 | ||
* | ||
* @returns {Array<Package>} a list of Package instances in topological order | ||
*/ | ||
function toposort(packages, opts) { | ||
const graph = new QueryGraph(packages, opts); | ||
const result = []; | ||
let batch = graph.getAvailablePackages(); | ||
while (batch.length) { | ||
for (const node of batch) { | ||
// no need to take() in synchronous loop | ||
result.push(node.pkg); | ||
graph.markAsDone(node); | ||
} | ||
batch = graph.getAvailablePackages(); | ||
} | ||
return result; | ||
} | ||
module.exports.QueryGraph = QueryGraph; | ||
module.exports.toposort = QueryGraph.toposort; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7066
1
+ Added@lerna/package-graph@4.0.0(transitive)
+ Added@lerna/prerelease-id-from-version@4.0.0(transitive)
+ Added@lerna/validation-error@4.0.0(transitive)
+ Addedhosted-git-info@4.1.0(transitive)
+ Addedlru-cache@6.0.0(transitive)
+ Addednpm-package-arg@8.1.5(transitive)
+ Addedsemver@7.6.3(transitive)
+ Addedyallist@4.0.0(transitive)
- Removedfiggy-pudding@^3.5.1
- Removed@lerna/package-graph@3.18.5(transitive)
- Removed@lerna/prerelease-id-from-version@3.16.0(transitive)
- Removed@lerna/validation-error@3.13.0(transitive)
- Removedfiggy-pudding@3.5.2(transitive)
- Removedhosted-git-info@2.8.9(transitive)
- Removednpm-package-arg@6.1.1(transitive)
- Removedos-homedir@1.0.2(transitive)
- Removedos-tmpdir@1.0.2(transitive)
- Removedosenv@0.1.5(transitive)
- Removedsemver@5.7.26.3.1(transitive)
Updated@lerna/package-graph@4.0.0