-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(deps): remove @lerna/collect-updates dependency
- Loading branch information
Showing
9 changed files
with
862 additions
and
311 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,41 @@ | ||
/** | ||
* Build a set of nodes that are dependents of the input set. | ||
*/ | ||
export function collectDependents(nodes) { | ||
const collected = new Set(); | ||
|
||
nodes.forEach((currentNode) => { | ||
if (currentNode.localDependents.size === 0) { | ||
// no point diving into a non-existent tree | ||
return; | ||
} | ||
|
||
// breadth-first search | ||
const queue = [currentNode]; | ||
const seen = new Set(); | ||
|
||
const visit = (dependentNode, dependentName, siblingDependents) => { | ||
if (seen.has(dependentNode)) { | ||
return; | ||
} | ||
|
||
seen.add(dependentNode); | ||
|
||
if (dependentNode === currentNode || siblingDependents.has(currentNode.name)) { | ||
// a direct or transitive cycle, skip it | ||
return; | ||
} | ||
|
||
collected.add(dependentNode); | ||
queue.push(dependentNode); | ||
}; | ||
|
||
while (queue.length) { | ||
const node = queue.shift(); | ||
|
||
node.localDependents.forEach(visit); | ||
} | ||
}); | ||
|
||
return collected; | ||
} |
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,35 @@ | ||
import { collectDependents } from "./collect-dependents.js"; | ||
|
||
/** | ||
* Build a list of graph nodes, possibly including dependents, using predicate if available. | ||
*/ | ||
export function collectPackages( | ||
packages, | ||
{ isCandidate = () => true, onInclude, excludeDependents } = {}, | ||
) { | ||
const candidates = new Set(); | ||
|
||
packages.forEach((node, name) => { | ||
if (isCandidate(node, name)) { | ||
candidates.add(node); | ||
} | ||
}); | ||
|
||
if (!excludeDependents) { | ||
collectDependents(candidates).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; | ||
} |
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,22 @@ | ||
import { execaSync } from "execa"; | ||
import log from "npmlog"; | ||
|
||
/** | ||
* Determine if any git tags are reachable. | ||
* @param {import("execa").SyncOptions} [opts] | ||
*/ | ||
export function hasTags(opts) { | ||
log.silly("hasTags"); | ||
let result = false; | ||
|
||
try { | ||
result = !!execaSync("git", ["tag"], opts); | ||
} catch (err) { | ||
log.warn("ENOTAGS", "No git tags were reachable from this branch!"); | ||
log.verbose("hasTags error", err); | ||
} | ||
|
||
log.verbose("hasTags", result); | ||
|
||
return result; | ||
} |
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,3 @@ | ||
export { collectPackages } from "./collect-packages.js"; | ||
export { hasTags } from "./has-tags.js"; | ||
export { makeDiffPredicate } from "./make-diff-predicate.js"; |
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,69 @@ | ||
import path from "node:path/posix"; | ||
import { execaSync } from "execa"; | ||
import log from "npmlog"; | ||
import minimatch from "minimatch"; | ||
|
||
/** | ||
* @param {string} committish | ||
* @param {import("execa").SyncOptions} [execOpts] | ||
* @param {string[]} ignorePatterns | ||
*/ | ||
export function makeDiffPredicate(committish, execOpts, ignorePatterns = []) { | ||
const ignoreFilters = new Set( | ||
ignorePatterns.map((p) => | ||
minimatch.filter(`!${p}`, { | ||
matchBase: true, | ||
// dotfiles inside ignored directories should also match | ||
dot: true, | ||
}), | ||
), | ||
); | ||
|
||
if (ignoreFilters.size) { | ||
log.info("ignoring diff in paths matching", ignorePatterns); | ||
} | ||
|
||
return function hasDiffSinceThatIsntIgnored(node) { | ||
const diff = diffSinceIn(committish, node.location, execOpts); | ||
|
||
if (diff === "") { | ||
log.silly("", "no diff found in %s", node.name); | ||
return false; | ||
} | ||
|
||
log.silly("found diff in", diff); | ||
let changedFiles = diff.split("\n"); | ||
|
||
if (ignoreFilters.size) { | ||
for (const ignored of ignoreFilters) { | ||
changedFiles = changedFiles.filter(ignored); | ||
} | ||
} | ||
|
||
if (changedFiles.length) { | ||
log.verbose("filtered diff", changedFiles); | ||
} else { | ||
log.verbose("", "no diff found in %s (after filtering)", node.name); | ||
} | ||
|
||
return changedFiles.length > 0; | ||
}; | ||
} | ||
|
||
/** | ||
* @param {string} committish | ||
* @param {string} location | ||
* @param {import("execa").SyncOptions} [opts] | ||
*/ | ||
function diffSinceIn(committish, location, opts) { | ||
const args = ["diff", "--name-only", committish]; | ||
const formattedLocation = path.relative(opts.cwd, location); | ||
|
||
if (formattedLocation) { | ||
// avoid same-directory path.relative() === "" | ||
args.push("--", formattedLocation); | ||
} | ||
|
||
log.silly("checking diff", formattedLocation); | ||
return execaSync("git", args, opts); | ||
} |
Oops, something went wrong.