From 1becbc277385d655a06d8f4c220f120feff05d49 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Mon, 19 Oct 2026 12:45:28 +0100 Subject: [PATCH] Accept paths containing only major version Also fix unescaped dot patterns in regex --- lib/entry-points.js | 2 +- src/platform.test.ts | 26 ++++++++++++++++++++++++++ src/platform.ts | 2 +- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/entry-points.js b/lib/entry-points.js index 024343857..d1c485b48 100644 --- a/lib/entry-points.js +++ b/lib/entry-points.js @@ -175728,7 +175728,7 @@ function macOSVersion(action) { } var XCODE_SELECT_LINK_PATH = "/private/var/db/xcode_select_link"; var XCODE_APP_FILENAME_PATTERN = new RegExp( - /(?Xcode_(?\d+.\d+).app)/ + /(?Xcode_(?\d+(\.\d+)?)\.app)/ ); function xcodeVersion(logger2) { try { diff --git a/src/platform.test.ts b/src/platform.test.ts index 7ccb53da3..6688f66af 100644 --- a/src/platform.test.ts +++ b/src/platform.test.ts @@ -225,3 +225,29 @@ test.serial("xcodeVersion returns version from resolved path", (t) => { t.is(readlinkSync.callCount, 1); t.deepEqual(readlinkSync.args[0], [XCODE_SELECT_LINK_PATH]); }); + +test.serial("xcodeVersion returns major version from resolved path", (t) => { + const logger = new RecordingLogger(); + + const lstatSync = sinon + .stub(fs, "lstatSync") + .returns({ isSymbolicLink: () => true } as fs.Stats); + const readlinkSync = sinon + .stub(fs, "readlinkSync") + .returns("/Applications/Xcode_16.app/Contents/Developer"); + + const result = xcodeVersion(logger); + + if (t.truthy(result)) { + t.is(result.major, 16); + t.is(result.minor, 0); + } + + t.is(lstatSync.callCount, 1); + t.deepEqual(lstatSync.args[0], [ + XCODE_SELECT_LINK_PATH, + { throwIfNoEntry: false }, + ]); + t.is(readlinkSync.callCount, 1); + t.deepEqual(readlinkSync.args[0], [XCODE_SELECT_LINK_PATH]); +}); diff --git a/src/platform.ts b/src/platform.ts index 01725c4cc..9492dff19 100644 --- a/src/platform.ts +++ b/src/platform.ts @@ -62,7 +62,7 @@ export const XCODE_SELECT_LINK_PATH = "/private/var/db/xcode_select_link"; /** The pattern we expect to find in the Xcode path. */ export const XCODE_APP_FILENAME_PATTERN = new RegExp( - /(?Xcode_(?\d+.\d+).app)/, + /(?Xcode_(?\d+(\.\d+)?)\.app)/, ); /**