Repository navigation
fix(doctor): resolve Android runtime versions from pnpm catalogs - #6212
NathanWalker merged 2 commits 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.
…sion Extends the catalog: handling to workspace:, file:, link:, npm: and other protocol specifiers, plus ranges and dist-tags, so doctor checks the runtime that is actually installed. Falls back to the existing range/dist-tag resolution when the runtime isn't installed.
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 any specifier that isn't an exact version:
catalog:,workspace:,file:,link:,npm:and tarballs, plus ranges and dist-tags. This matchesProjectDataServicein the CLI. When the runtime isn't installed, ranges and dist-tags resolve as before, and protocol specifiers and tarballs fall back to*.Validation
npm testinpackages/doctorpassed all 92 tests. The new cases (catalog:,catalog:mobile,workspace:*,file:../android,^8.0.0) 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.