-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
577 additions
and
122 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { | ||
calculateVersionsForEachDependency, | ||
calculateMismatchingVersions, | ||
filterOutIgnoredDependencies, | ||
fixMismatchingVersions, | ||
} from './dependency-versions.js'; | ||
import { getPackages } from './workspace.js'; | ||
|
||
/** | ||
* Checks for inconsistencies across a workspace. Optionally fixes them. | ||
* @param path - path to the workspace root | ||
* @param options | ||
* @param options.fix - Whether to autofix inconsistencies (using latest version present) | ||
* @param options.ignoreDep - Dependency(s) to ignore mismatches for | ||
* @param options.ignoreDepPattern - RegExp(s) of dependency names to ignore mismatches for | ||
* @param options.ignorePackage - Workspace package(s) to ignore mismatches for | ||
* @param options.ignorePackagePattern - RegExp(s) of package names to ignore mismatches for | ||
* @param options.ignorePath - Workspace-relative path(s) of packages to ignore mismatches for | ||
* @param options.ignorePathPattern - RegExp(s) of workspace-relative path of packages to ignore mismatches for | ||
* @returns an object with the following properties: | ||
* - `mismatchingVersions`: All the mismatching versions found. | ||
* - `mismatchingVersionsFixable`: The mismatching versions that are fixable (these will be fixed in `fix` mode) | ||
* - `mismatchingVersionsNotFixable`: The mismatching versions that are not fixable (these will be skipped in `fix` mode). | ||
*/ | ||
export function check( | ||
path: string, | ||
options?: { | ||
fix?: boolean; | ||
ignoreDep?: string[]; | ||
ignoreDepPattern?: string[]; | ||
ignorePackage?: string[]; | ||
ignorePackagePattern?: string[]; | ||
ignorePath?: string[]; | ||
ignorePathPattern?: string[]; | ||
} | ||
) { | ||
const optionsWithDefaults = { | ||
fix: false, | ||
ignoreDep: [], | ||
ignoreDepPattern: [], | ||
ignorePackage: [], | ||
ignorePackagePattern: [], | ||
ignorePath: [], | ||
ignorePathPattern: [], | ||
...options, | ||
}; | ||
|
||
// Calculate. | ||
const packages = getPackages( | ||
path, | ||
optionsWithDefaults.ignorePackage, | ||
optionsWithDefaults.ignorePackagePattern.map((s) => new RegExp(s)), | ||
optionsWithDefaults.ignorePath, | ||
optionsWithDefaults.ignorePathPattern.map((s) => new RegExp(s)) | ||
); | ||
|
||
const dependencyVersions = calculateVersionsForEachDependency(packages); | ||
|
||
const mismatchingVersions = filterOutIgnoredDependencies( | ||
calculateMismatchingVersions(dependencyVersions), | ||
optionsWithDefaults.ignoreDep, | ||
optionsWithDefaults.ignoreDepPattern.map((s) => new RegExp(s)) | ||
); | ||
|
||
const resultsAfterFix = fixMismatchingVersions( | ||
packages, | ||
mismatchingVersions, | ||
!optionsWithDefaults.fix // Do dry-run if not fixing. | ||
); | ||
const mismatchingVersionsFixable = resultsAfterFix.fixable; | ||
const mismatchingVersionsNotFixable = resultsAfterFix.notFixable; | ||
|
||
return { | ||
mismatchingVersions, | ||
mismatchingVersionsFixable, | ||
mismatchingVersionsNotFixable, | ||
}; | ||
} |
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,7 @@ | ||
// Public Node API. | ||
|
||
export { check } from './check.js'; | ||
export { | ||
mismatchingVersionsToDetailedSummary, | ||
mismatchingVersionsToFixedSummary, | ||
} from './output.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
Oops, something went wrong.