Skip to content

Commit

Permalink
fix: handle pnpm workspace: version range
Browse files Browse the repository at this point in the history
  • Loading branch information
voxpelli committed Apr 4, 2024
1 parent 3c432bf commit 01ff126
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lib/check-package-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export function checkPackageVersions (pkg, installedDependencies) {
}

targetVersion = version;
} else if (targetVersion.startsWith('workspace:')) {
continue;
}

if (!semver.validRange(targetVersion)) {
Expand Down
28 changes: 24 additions & 4 deletions lib/check-version-range.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export function checkVersionRange (pkg, key, installed, options) {
const ignoreMatcher = ignore && !Array.isArray(ignore) ? ignore : undefined;

const rawReferenceRange = getStringValueByPath(pkg, key);
const referenceRange = rawReferenceRange || '*';
const invalidReferenceRange = rawReferenceRange && !validRange(rawReferenceRange);
const referenceRange = (!rawReferenceRange || invalidReferenceRange) ? '*' : rawReferenceRange;

/** @type {Array<VersionRangeItem & { name: string }>} */
const packageNotes = [];
Expand All @@ -57,6 +58,9 @@ export function checkVersionRange (pkg, key, installed, options) {
if (ignoreMatcher && ignoreMatcher(dependency)) {
continue;
}
if (dependency === pkg.name) {
continue;
}

const dependencyPackage = installed instanceof Map ? installed.get(dependency) : installed[dependency];
const isOptional = !!optionalDependencies[dependency];
Expand All @@ -78,15 +82,24 @@ export function checkVersionRange (pkg, key, installed, options) {

const valid = intersection !== false && validRange(intersection) === validRange(referenceRange);

/** @type {string|undefined} */
let note;

if (rawReferenceRange === false) {
note = `Invalid "${key}" in main package`;
} else if (!rawReferenceRange) {
note = `Missing "${key}" in main package`;
} else if (invalidReferenceRange && !rawReferenceRange.startsWith('workspace:')) {
note = `Invalid "${key}" range in main package: "${rawReferenceRange}"`;
}

return {
valid: valid
? true
: ((rawReferenceRange || strict) ? false : undefined),
suggested: valid ? undefined : (intersection || undefined),
packageNotes,
note: rawReferenceRange === false
? `Invalid "${key}" in main package`
: (rawReferenceRange ? undefined : `Missing "${key}" in main package`),
note,
};
}

Expand Down Expand Up @@ -157,6 +170,13 @@ export function checkDependencyRange (referenceRange, key, dependencyPackage, is
: { valid: undefined, note: `Missing "${key}"` };
}

if (!validRange(range)) {
if (range.startsWith('workspace:')) {
return;
}
return { valid: strict ? false : undefined, note: `Invalid "${key}" range: "${range}"` };
}

const intersection = semverIntersect(referenceRange, range);

if (!intersection) {
Expand Down

0 comments on commit 01ff126

Please sign in to comment.