Skip to content

Commit f7da1a9

Browse files
committed
fix(doctor): read the installed Android runtime for any non-exact version
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.
1 parent 7da94fd commit f7da1a9

2 files changed

Lines changed: 50 additions & 31 deletions

File tree

‎packages/doctor/src/android-tools-info.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ export class AndroidToolsInfo implements NativeScriptDoctor.IAndroidToolsInfo {
606606
if (foundRuntime) {
607607
let version = content.devDependencies[foundRuntime];
608608

609-
if (version.includes("tgz") || version.startsWith("catalog:")) {
609+
if (!semver.valid(version)) {
610610
try {
611611
const packagePath = require.resolve(
612612
`${foundRuntime}/package.json`,
@@ -616,7 +616,11 @@ export class AndroidToolsInfo implements NativeScriptDoctor.IAndroidToolsInfo {
616616
);
617617
version = require(packagePath).version;
618618
} catch (err) {
619-
version = "*";
619+
// Not installed: ranges and dist-tags still resolve below, but
620+
// protocol specifiers (catalog:, workspace:, file:) and tarballs can't.
621+
if (!semver.validRange(version) && /[:/]|tgz/.test(version)) {
622+
version = "*";
623+
}
620624
}
621625
}
622626

‎packages/doctor/test/android-tools-info.ts‎

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -157,35 +157,50 @@ describe("androidToolsInfo", () => {
157157
assert.deepEqual(supportedTargets, expectedTargets);
158158
};
159159

160-
it.each(["catalog:", "catalog:mobile"])(
161-
"reads the installed Android runtime for %s",
162-
(specifier) => {
163-
const projectDir = mkdtempSync(join(tmpdir(), "doctor-catalog-"));
164-
try {
165-
const runtimeDir = join(projectDir, "node_modules", "@nativescript", "android");
166-
mkdirSync(runtimeDir, { recursive: true });
167-
writeFileSync(
168-
join(projectDir, "package.json"),
169-
JSON.stringify({ devDependencies: { "@nativescript/android": specifier } }),
170-
);
171-
writeFileSync(join(runtimeDir, "package.json"), JSON.stringify({ version: "8.1.0" }));
172-
const childProcess = new ChildProcess();
173-
const distTags = vi.spyOn(childProcess, "execSync").mockReturnValue("{}");
174-
const hostInfo = new HostInfo(new WinReg());
175-
const info = new AndroidToolsInfo(
176-
childProcess,
177-
new FileSystem(),
178-
hostInfo,
179-
new Helpers(hostInfo),
180-
);
181-
const targets = info.getSupportedTargets(projectDir);
182-
assert.equal(targets[targets.length - 1], "android-30");
183-
assert.lengthOf(distTags.mock.calls, 0);
184-
} finally {
185-
rmSync(projectDir, { recursive: true, force: true });
186-
}
187-
},
188-
);
160+
it.each([
161+
"catalog:",
162+
"catalog:mobile",
163+
"workspace:*",
164+
"file:../android",
165+
"^8.0.0",
166+
])("reads the installed Android runtime for %s", (specifier) => {
167+
const projectDir = mkdtempSync(join(tmpdir(), "doctor-runtime-"));
168+
try {
169+
const runtimeDir = join(
170+
projectDir,
171+
"node_modules",
172+
"@nativescript",
173+
"android",
174+
);
175+
mkdirSync(runtimeDir, { recursive: true });
176+
writeFileSync(
177+
join(projectDir, "package.json"),
178+
JSON.stringify({
179+
devDependencies: { "@nativescript/android": specifier },
180+
}),
181+
);
182+
writeFileSync(
183+
join(runtimeDir, "package.json"),
184+
JSON.stringify({ version: "8.1.0" }),
185+
);
186+
const childProcess = new ChildProcess();
187+
const distTags = vi
188+
.spyOn(childProcess, "execSync")
189+
.mockReturnValue("{}");
190+
const hostInfo = new HostInfo(new WinReg());
191+
const info = new AndroidToolsInfo(
192+
childProcess,
193+
new FileSystem(),
194+
hostInfo,
195+
new Helpers(hostInfo),
196+
);
197+
const targets = info.getSupportedTargets(projectDir);
198+
assert.equal(targets[targets.length - 1], "android-30");
199+
assert.lengthOf(distTags.mock.calls, 0);
200+
} finally {
201+
rmSync(projectDir, { recursive: true, force: true });
202+
}
203+
});
189204

190205
it("runtime 6.0.0 should support android-17 - android-28", () => {
191206
assertSupportedTargets(

0 commit comments

Comments
 (0)