@pnpm/render-peer-issues
Advanced tools
Comparing version 4.0.6 to 4.1.0
@@ -1,4 +0,5 @@ | ||
import { type PeerDependencyIssuesByProjects } from '@pnpm/types'; | ||
import { type PeerDependencyIssuesByProjects, type PeerDependencyRules } from '@pnpm/types'; | ||
export declare function renderPeerIssues(peerDependencyIssuesByProjects: PeerDependencyIssuesByProjects, opts?: { | ||
rules?: PeerDependencyRules; | ||
width?: number; | ||
}): string; |
@@ -7,6 +7,15 @@ "use strict"; | ||
exports.renderPeerIssues = void 0; | ||
const error_1 = require("@pnpm/error"); | ||
const matcher_1 = require("@pnpm/matcher"); | ||
const parse_overrides_1 = require("@pnpm/parse-overrides"); | ||
const archy_1 = __importDefault(require("archy")); | ||
const chalk_1 = __importDefault(require("chalk")); | ||
const cli_columns_1 = __importDefault(require("cli-columns")); | ||
const semver_1 = __importDefault(require("semver")); | ||
function renderPeerIssues(peerDependencyIssuesByProjects, opts) { | ||
const ignoreMissingPatterns = [...new Set(opts?.rules?.ignoreMissing ?? [])]; | ||
const ignoreMissingMatcher = (0, matcher_1.createMatcher)(ignoreMissingPatterns); | ||
const allowAnyPatterns = [...new Set(opts?.rules?.allowAny ?? [])]; | ||
const allowAnyMatcher = (0, matcher_1.createMatcher)(allowAnyPatterns); | ||
const { allowedVersionsMatchAll, allowedVersionsByParentPkgName } = parseAllowedVersions(opts?.rules?.allowedVersions ?? {}); | ||
const projects = {}; | ||
@@ -17,3 +26,4 @@ for (const [projectId, { bad, missing, conflicts, intersections }] of Object.entries(peerDependencyIssuesByProjects)) { | ||
if (!conflicts.includes(peerName) && | ||
intersections[peerName] == null) { | ||
intersections[peerName] == null || | ||
ignoreMissingMatcher(peerName)) { | ||
continue; | ||
@@ -26,3 +36,20 @@ } | ||
for (const [peerName, issues] of Object.entries(bad)) { | ||
if (allowAnyMatcher(peerName)) | ||
continue; | ||
for (const issue of issues) { | ||
if (allowedVersionsMatchAll[peerName]?.some((range) => semver_1.default.satisfies(issue.foundVersion, range))) | ||
continue; | ||
const currentParentPkg = issue.parents.at(-1); | ||
if (currentParentPkg && allowedVersionsByParentPkgName[peerName]?.[currentParentPkg.name]) { | ||
const allowedVersionsByParent = allowedVersionsByParentPkgName[peerName][currentParentPkg.name] | ||
.reduce((acc, { targetPkg, parentPkg, ranges }) => { | ||
if (!parentPkg.pref || currentParentPkg.version && | ||
(isSubRange(parentPkg.pref, currentParentPkg.version) || semver_1.default.satisfies(currentParentPkg.version, parentPkg.pref))) { | ||
acc[targetPkg.name] = ranges; | ||
} | ||
return acc; | ||
}, {}); | ||
if (allowedVersionsByParent[peerName]?.some((range) => semver_1.default.satisfies(issue.foundVersion, range))) | ||
continue; | ||
} | ||
createTree(projects[projectId], issue.parents, formatUnmetPeerMessage({ | ||
@@ -98,2 +125,47 @@ peerName, | ||
} | ||
function parseAllowedVersions(allowedVersions) { | ||
const overrides = tryParseAllowedVersions(allowedVersions); | ||
const allowedVersionsMatchAll = {}; | ||
const allowedVersionsByParentPkgName = {}; | ||
for (const { parentPkg, targetPkg, newPref } of overrides) { | ||
const ranges = parseVersions(newPref); | ||
if (!parentPkg) { | ||
allowedVersionsMatchAll[targetPkg.name] = ranges; | ||
continue; | ||
} | ||
if (!allowedVersionsByParentPkgName[targetPkg.name]) { | ||
allowedVersionsByParentPkgName[targetPkg.name] = {}; | ||
} | ||
if (!allowedVersionsByParentPkgName[targetPkg.name][parentPkg.name]) { | ||
allowedVersionsByParentPkgName[targetPkg.name][parentPkg.name] = []; | ||
} | ||
allowedVersionsByParentPkgName[targetPkg.name][parentPkg.name].push({ | ||
parentPkg, | ||
targetPkg, | ||
ranges, | ||
}); | ||
} | ||
return { | ||
allowedVersionsMatchAll, | ||
allowedVersionsByParentPkgName, | ||
}; | ||
} | ||
function tryParseAllowedVersions(allowedVersions) { | ||
try { | ||
return (0, parse_overrides_1.parseOverrides)(allowedVersions ?? {}); | ||
} | ||
catch (err) { | ||
throw new error_1.PnpmError('INVALID_ALLOWED_VERSION_SELECTOR', `${err.message} in pnpm.peerDependencyRules.allowedVersions`); | ||
} | ||
} | ||
function parseVersions(versions) { | ||
return versions.split('||').map(v => v.trim()); | ||
} | ||
function isSubRange(superRange, subRange) { | ||
return !superRange || | ||
subRange === superRange || | ||
semver_1.default.validRange(subRange) != null && | ||
semver_1.default.validRange(superRange) != null && | ||
semver_1.default.subset(subRange, superRange); | ||
} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@pnpm/render-peer-issues", | ||
"description": "Visualizes peer dependency issues", | ||
"version": "4.0.6", | ||
"version": "4.1.0", | ||
"bugs": { | ||
@@ -28,8 +28,13 @@ "url": "https://github.com/pnpm/pnpm/issues" | ||
"cli-columns": "^4.0.0", | ||
"@pnpm/types": "9.4.2" | ||
"semver": "^7.6.0", | ||
"@pnpm/matcher": "5.0.0", | ||
"@pnpm/error": "5.0.3", | ||
"@pnpm/types": "9.4.2", | ||
"@pnpm/parse-overrides": "4.0.3" | ||
}, | ||
"devDependencies": { | ||
"@types/archy": "0.0.33", | ||
"@types/semver": "7.5.8", | ||
"strip-ansi": "^6.0.1", | ||
"@pnpm/render-peer-issues": "4.0.6" | ||
"@pnpm/render-peer-issues": "4.1.0" | ||
}, | ||
@@ -36,0 +41,0 @@ "exports": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
17559
171
8
4
+ Added@pnpm/error@5.0.3
+ Added@pnpm/matcher@5.0.0
+ Added@pnpm/parse-overrides@4.0.3
+ Addedsemver@^7.6.0
+ Added@pnpm/constants@7.1.1(transitive)
+ Added@pnpm/error@5.0.3(transitive)
+ Added@pnpm/matcher@5.0.0(transitive)
+ Added@pnpm/parse-overrides@4.0.3(transitive)
+ Added@pnpm/parse-wanted-dependency@5.0.0(transitive)
+ Addedbuiltins@5.1.0(transitive)
+ Addedescape-string-regexp@4.0.0(transitive)
+ Addedsemver@7.6.3(transitive)
+ Addedvalidate-npm-package-name@5.0.0(transitive)