Skip to content

Commit

Permalink
Merge main into renovate/glob-11.x
Browse files Browse the repository at this point in the history
  • Loading branch information
reviewflow[bot] authored Jul 17, 2024
2 parents 9a78e9a + 310347a commit 62c2f67
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 62 deletions.
2 changes: 1 addition & 1 deletion dist/definitions/checks/checkExactVersions.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/definitions/checks/checkPeerDependencies.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/definitions/utils/semverUtils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export declare function getOperator(range: string): string | null;
export declare function changeOperator(range: string, operator: string | null): string | null;
export declare function isExactParsedRange(parsedRange: ReturnType<typeof semverUtils.parseRange>): boolean;
export declare function isExactRange(range: string): boolean;
export declare function getRealVersion(version: string): string;
//# sourceMappingURL=semverUtils.d.ts.map
2 changes: 1 addition & 1 deletion dist/definitions/utils/semverUtils.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

96 changes: 50 additions & 46 deletions dist/index-node18.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,52 @@ async function checkDirectDuplicateDependencies(pkg, pkgPathName, isPackageALibr
reportNotWarnedForMapping(reportError, onlyWarnsForCheck);
}

semverUtils.parse;
const parseRange = semverUtils.parseRange;
function stringify(semver) {
let str = "";
if (semver.operator) {
str += semver.operator;
}
str += semver.major || "0";
str += ".";
str += semver.minor || "0";
str += ".";
str += semver.patch || "0";
if (semver.release) {
str += `-${semver.release}`;
}
if (semver.build) {
str += `+${semver.build}`;
}
return str;
}
function getOperator(range) {
const parsedRange = parseRange(range);
if (parsedRange.length !== 1) return null;
return parsedRange[0].operator || "";
}
function changeOperator(range, operator) {
if (operator === null) return range;
const parsedRange = parseRange(range);
if (parsedRange.length !== 1) return null;
const parsed = parsedRange[0];
parsed.operator = operator === "" ? void 0 : operator;
return stringify(parsed);
}
function getRealVersion(version) {
if (version.startsWith("npm:")) {
const match = /^npm:.*@(.*)$/.exec(version);
if (!match) throw new Error(`Invalid version match: ${version}`);
const [, realVersion] = match;
return realVersion;
}
if (version.startsWith("workspace:")) {
return version.slice("workspace:".length);
}
return version;
}

function checkPeerDependencies(pkg, reportError, type, allowedPeerIn, allowMissing, providedDependencies, depPkg, missingOnlyWarnsForCheck, invalidOnlyWarnsForCheck) {
const { peerDependencies, peerDependenciesMeta } = depPkg;
if (!peerDependencies) return;
Expand Down Expand Up @@ -208,10 +254,8 @@ function checkPeerDependencies(pkg, reportError, type, allowedPeerIn, allowMissi
const versions = versionsIn.map(
(versionsInType) => pkg[versionsInType][peerDepName]
);
versions.forEach((version, index) => {
if (version.startsWith("npm:")) {
return;
}
versions.forEach((versionValue, index) => {
const version = getRealVersion(versionValue);
if (version === "*") {
return;
}
Expand Down Expand Up @@ -310,16 +354,10 @@ async function checkExactVersions(pkg, pkgPathName, types, {
for (const type of types) {
const pkgDependencies = pkg[type];
if (!pkgDependencies) continue;
for (const [dependencyName, versionConst] of Object.entries(
for (const [dependencyName, versionValue] of Object.entries(
pkgDependencies
)) {
let version = versionConst;
if (version.startsWith("npm:")) {
const match = /^npm:.*@(.*)$/.exec(version);
if (!match) throw new Error(`Invalid version match: ${version}`);
const [, realVersion] = match;
version = realVersion;
}
const version = getRealVersion(versionValue);
if (isVersionRange(version)) {
if (internalExactVersionsIgnore?.includes(dependencyName)) {
continue;
Expand Down Expand Up @@ -603,40 +641,6 @@ function checkSatisfiesVersions(pkg, pkgPathName, type, dependenciesRanges, only
});
}

semverUtils.parse;
const parseRange = semverUtils.parseRange;
function stringify(semver) {
let str = "";
if (semver.operator) {
str += semver.operator;
}
str += semver.major || "0";
str += ".";
str += semver.minor || "0";
str += ".";
str += semver.patch || "0";
if (semver.release) {
str += `-${semver.release}`;
}
if (semver.build) {
str += `+${semver.build}`;
}
return str;
}
function getOperator(range) {
const parsedRange = parseRange(range);
if (parsedRange.length !== 1) return null;
return parsedRange[0].operator || "";
}
function changeOperator(range, operator) {
if (operator === null) return range;
const parsedRange = parseRange(range);
if (parsedRange.length !== 1) return null;
const parsed = parsedRange[0];
parsed.operator = operator === "" ? void 0 : operator;
return stringify(parsed);
}

function checkSatisfiesVersionsFromDependency(pkg, pkgPathName, type, depKeys, depPkg, depType, {
tryToAutoFix,
shouldHaveExactVersions,
Expand Down
2 changes: 1 addition & 1 deletion dist/index-node18.mjs.map

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions src/checks/checkDirectPeerDependencies.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,4 +436,28 @@ describe("checkDirectPeerDependencies", () => {
false,
);
});

it("should not report error when dependency is workspace:*", async () => {
await checkDirectPeerDependencies(
false,
{
name: "test",
devDependencies: {
"alouette-icons": "workspace:*",
},
peerDependencies: {
"lib-using-alouette-icons": "*",
},
},
"path",
vi.fn().mockImplementationOnce(() => ({
name: "alouette-icons",
peerDependencies: { "alouette-icons": "^1.0.0" },
})),
createOnlyWarnsForMappingCheck("test", []),
createOnlyWarnsForMappingCheck("test", []),
createReportError,
);
expect(mockReportError).not.toHaveBeenCalled();
});
});
11 changes: 3 additions & 8 deletions src/checks/checkExactVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
reportNotWarnedFor,
} from "../utils/createReportError";
import type { PackageJson, DependencyTypes } from "../utils/packageTypes";
import { getRealVersion } from "../utils/semverUtils";
import type { OnlyWarnsFor, OnlyWarnsForCheck } from "../utils/warnForUtils";

export interface CheckExactVersionsOptions {
Expand Down Expand Up @@ -40,16 +41,10 @@ export async function checkExactVersions(
const pkgDependencies = pkg[type];
if (!pkgDependencies) continue;

for (const [dependencyName, versionConst] of Object.entries(
for (const [dependencyName, versionValue] of Object.entries(
pkgDependencies,
)) {
let version = versionConst;
if (version.startsWith("npm:")) {
const match = /^npm:.*@(.*)$/.exec(version);
if (!match) throw new Error(`Invalid version match: ${version}`);
const [, realVersion] = match;
version = realVersion;
}
const version = getRealVersion(versionValue);

if (isVersionRange(version)) {
if (internalExactVersionsIgnore?.includes(dependencyName)) {
Expand Down
7 changes: 3 additions & 4 deletions src/checks/checkPeerDependencies.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import semver from "semver";
import type { ReportError } from "../utils/createReportError";
import type { PackageJson, DependencyTypes } from "../utils/packageTypes";
import { getRealVersion } from "../utils/semverUtils";
import type { OnlyWarnsForCheck } from "../utils/warnForUtils";

export function checkPeerDependencies(
Expand Down Expand Up @@ -66,10 +67,8 @@ export function checkPeerDependencies(
(versionsInType) => pkg[versionsInType]![peerDepName],
);

versions.forEach((version, index) => {
if (version.startsWith("npm:")) {
return;
}
versions.forEach((versionValue, index) => {
const version = getRealVersion(versionValue);

if (version === "*") {
return;
Expand Down
14 changes: 14 additions & 0 deletions src/utils/semverUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,17 @@ export function isExactParsedRange(
export function isExactRange(range: string): boolean {
return isExactParsedRange(parseRange(range));
}

export function getRealVersion(version: string): string {
if (version.startsWith("npm:")) {
const match = /^npm:.*@(.*)$/.exec(version);
if (!match) throw new Error(`Invalid version match: ${version}`);
const [, realVersion] = match;
return realVersion;
}
if (version.startsWith("workspace:")) {
return version.slice("workspace:".length);
}

return version;
}

0 comments on commit 62c2f67

Please sign in to comment.