Repository navigation
fix(doctor): resolve Android runtime versions from pnpm catalogs - #6212
aleclarson wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
NathanWalker
left a comment
There was a problem hiding this comment.
Thanks! The fix is correct, and the test is a good one: a real installed runtime, plus a check that no dist-tag lookup happens.
One suggestion: catalog: is only one of several specifiers that doctor still rejects. workspace:*, workspace:^8.1.0, file:../android, link:../android, npm:@nativescript/android@8.1.0 and github:… all fail semver.validRange, go to the dist-tag lookup, find nothing, and throw "The determined Android runtime version … is not valid". workspace: in particular is as common as catalog: in pnpm monorepos.
The CLI already handles all of these in ProjectDataService (lib/services/project-data-service.ts, around line 648). It reads the installed runtime's package.json for anything that isn't an exact version (tgz, ranges and tags), and only falls back when the runtime isn't installed. Doctor could follow the same rule:
let version = content.devDependencies[foundRuntime];
if (!semver.valid(version)) {
try {
const packagePath = require.resolve(`${foundRuntime}/package.json`, { paths: [projectDir] });
version = require(packagePath).version;
} catch (err) {
// Not installed: ranges and dist-tags still resolve below;
// protocol specifiers and tgz paths can't be checked.
if (!semver.validRange(version) && /[:/]|tgz/.test(version)) {
version = "*";
}
}
}This covers every protocol specifier without a list to maintain, and it means doctor checks the runtime that is actually installed rather than whatever next points to on npm today. It does change behavior for installed ranges and tags (they now read the installed version), so I'm fine keeping this PR to catalog: if you'd rather not widen it. In that case a follow-up for the rest would be great. If you do generalize it, extending your it.each with workspace:* and file:../android would cover it.
PR Checklist
What is the current behavior?
An app that pins
@nativescript/androidwithcatalog:orcatalog:mobilecan install its runtime successfully, then fail the Android toolchain check. Doctor treats the literal catalog specifier as an npm dist-tag and reports that the Android runtime version is invalid.What is the new behavior?
Doctor reads the installed runtime version for catalog specifiers using the same lookup as tarball installs. Registry versions and dist-tags use the existing paths.
Validation
npm testinpackages/doctorpassed all 89 tests. The two new cases create an installed runtime with a fixed version and verify that Doctor selects its supported targets without a dist-tag lookup.Summary by CodeRabbit
catalog:versions now have their installed runtime version recognized when determining supported Android targets.