Skip to content

Commit 7da94fd

Browse files
committed
fix(doctor): resolve Android runtime versions from pnpm catalogs
1 parent 8a55b3e commit 7da94fd

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
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")) {
609+
if (version.includes("tgz") || version.startsWith("catalog:")) {
610610
try {
611611
const packagePath = require.resolve(
612612
`${foundRuntime}/package.json`,

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import { AndroidToolsInfo } from "../src/android-tools-info";
2-
import { EOL } from "os";
2+
import { EOL, tmpdir } from "os";
3+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "fs";
4+
import { join } from "path";
35
import { assert } from "chai";
46
import { ChildProcess } from "../src/wrappers/child-process";
57
import { FileSystem } from "../src/wrappers/file-system";
68
import { HostInfo } from "../src/host-info";
79
import { Helpers } from "../src/helpers";
810
import { Constants } from "../src/constants";
11+
import { WinReg } from "../src/winreg";
912

1013
interface ITestData {
1114
javacVersion: string;
@@ -154,6 +157,36 @@ describe("androidToolsInfo", () => {
154157
assert.deepEqual(supportedTargets, expectedTargets);
155158
};
156159

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+
);
189+
157190
it("runtime 6.0.0 should support android-17 - android-28", () => {
158191
assertSupportedTargets(
159192
"6.0.0",

0 commit comments

Comments
 (0)