cli: tiny bit of logic to optimize repo lint order

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2022-02-13 22:05:18 +01:00
parent 92f90d552a
commit 99d975cd3e
2 changed files with 18 additions and 2 deletions
+13 -1
View File
@@ -17,10 +17,18 @@
import chalk from 'chalk';
import { Command } from 'commander';
import { relative as relativePath } from 'path';
import { PackageGraph } from '../../lib/monorepo';
import { PackageGraph, ExtendedPackageJSON } from '../../lib/monorepo';
import { runWorkerQueueThreads } from '../../lib/parallel';
import { paths } from '../../lib/paths';
function depCount(pkg: ExtendedPackageJSON) {
const deps = pkg.dependencies ? Object.keys(pkg.dependencies).length : 0;
const devDeps = pkg.devDependencies
? Object.keys(pkg.devDependencies).length
: 0;
return deps + devDeps;
}
export async function command(cmd: Command): Promise<void> {
let packages = await PackageGraph.listTargetPackages();
@@ -29,6 +37,10 @@ export async function command(cmd: Command): Promise<void> {
packages = await graph.listChangedPackages({ ref: cmd.since });
}
// Packages are ordered from most to least number of dependencies, as a
// very cheap way of guessing which packages are more likely to be larger.
packages.sort((a, b) => depCount(b.packageJson) - depCount(a.packageJson));
// This formatter uses the cwd to format file paths, so let's have that happen from the root instead
if (cmd.format === 'eslint-formatter-friendly') {
process.chdir(paths.targetRoot);
+5 -1
View File
@@ -15,4 +15,8 @@
*/
export { PackageGraph } from './PackageGraph';
export type { PackageGraphNode } from './PackageGraph';
export type {
PackageGraphNode,
ExtendedPackage,
ExtendedPackageJSON,
} from './PackageGraph';