forked from lerna/lerna
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(conventional-commits): Add conventional prerelease/graduation (l…
…erna#1991) Fixes lerna#1433 Fixes lerna#1675
- Loading branch information
Showing
9 changed files
with
285 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
"use strict"; | ||
|
||
// helpers | ||
const buildGraph = require("../__helpers__/build-graph"); | ||
|
||
// file under test | ||
const collectPackages = require("../lib/collect-packages"); | ||
|
||
const toNamesList = collection => Array.from(collection).map(pkg => pkg.name); | ||
|
||
test("returns all packages", () => { | ||
const graph = buildGraph(); | ||
const result = collectPackages(graph); | ||
|
||
expect(toNamesList(result)).toMatchInlineSnapshot(` | ||
Array [ | ||
"package-cycle-1", | ||
"package-cycle-2", | ||
"package-cycle-extraneous", | ||
"package-dag-1", | ||
"package-dag-2a", | ||
"package-dag-2b", | ||
"package-dag-3", | ||
"package-standalone", | ||
] | ||
`); | ||
}); | ||
|
||
test("filters packages through isCandidate, passing node and name", () => { | ||
const graph = buildGraph(); | ||
const packagesToInclude = ["package-cycle-1"]; | ||
const isCandidate = (node, name) => { | ||
return packagesToInclude.includes(node.name) && node.name === name; | ||
}; | ||
const result = collectPackages(graph, { isCandidate }); | ||
|
||
expect(toNamesList(result)).toMatchInlineSnapshot(` | ||
Array [ | ||
"package-cycle-1", | ||
"package-cycle-2", | ||
"package-cycle-extraneous", | ||
] | ||
`); | ||
}); | ||
|
||
test("calls onInclude with included package name", () => { | ||
const graph = buildGraph(); | ||
const packagesToInclude = ["package-standalone"]; | ||
const isCandidate = (node, name) => packagesToInclude.includes(name); | ||
const onInclude = jest.fn(); | ||
collectPackages(graph, { isCandidate, onInclude }); | ||
|
||
expect(onInclude).toHaveBeenCalledWith(packagesToInclude[0]); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"use strict"; | ||
|
||
// file under test | ||
const getPackagesForOption = require("../lib/get-packages-for-option"); | ||
|
||
test("no argument", () => { | ||
const result = getPackagesForOption(); | ||
|
||
expect(Array.from(result)).toEqual([]); | ||
}); | ||
|
||
test("--config-option", () => { | ||
const result = getPackagesForOption(true); | ||
|
||
expect(Array.from(result)).toEqual(["*"]); | ||
}); | ||
|
||
test("--config-option *", () => { | ||
const result = getPackagesForOption("*"); | ||
|
||
expect(Array.from(result)).toEqual(["*"]); | ||
}); | ||
|
||
test("--config-option foo", () => { | ||
const result = getPackagesForOption("foo"); | ||
|
||
expect(Array.from(result)).toEqual(["foo"]); | ||
}); | ||
|
||
test("--config-option foo,bar", () => { | ||
const result = getPackagesForOption("foo,bar"); | ||
|
||
expect(Array.from(result)).toEqual(["foo", "bar"]); | ||
}); | ||
|
||
test("--config-option foo --config-option bar", () => { | ||
const result = getPackagesForOption(["foo", "bar"]); | ||
|
||
expect(Array.from(result)).toEqual(["foo", "bar"]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"use strict"; | ||
|
||
const collectDependents = require("./collect-dependents"); | ||
|
||
module.exports = collectPackages; | ||
|
||
function collectPackages(packages, { isCandidate = () => true, onInclude } = {}) { | ||
const candidates = new Set(); | ||
|
||
packages.forEach((node, name) => { | ||
if (isCandidate(node, name)) { | ||
candidates.add(node); | ||
} | ||
}); | ||
|
||
const dependents = collectDependents(candidates); | ||
dependents.forEach(node => candidates.add(node)); | ||
|
||
// The result should always be in the same order as the input | ||
const updates = []; | ||
|
||
packages.forEach((node, name) => { | ||
if (candidates.has(node)) { | ||
if (onInclude) { | ||
onInclude(name); | ||
} | ||
updates.push(node); | ||
} | ||
}); | ||
|
||
return updates; | ||
} |
Oops, something went wrong.