From eff66e8fb1ca04760c1502ab0cc2b7b647122e7f Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Wed, 28 Oct 2026 12:30:50 +0000 Subject: [PATCH] Make Xcode regex more flexible --- lib/entry-points.js | 2 +- src/platform.test.ts | 29 +++++++++++++++++++++++++++++ src/platform.ts | 2 +- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/lib/entry-points.js b/lib/entry-points.js index 46736e51e..7f5c3b447 100644 --- a/lib/entry-points.js +++ b/lib/entry-points.js @@ -183441,7 +183441,7 @@ function darwinVersion(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 e3a3b7783..d6439226e 100644 --- a/src/platform.test.ts +++ b/src/platform.test.ts @@ -251,3 +251,32 @@ test.serial("xcodeVersion returns major version from resolved path", (t) => { t.is(readlinkSync.callCount, 1); t.deepEqual(readlinkSync.args[0], [XCODE_SELECT_LINK_PATH]); }); + +test.serial( + "xcodeVersion allows more version components in 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.5.9.app/Contents/Developer"); + + const result = xcodeVersion(logger); + + if (t.truthy(result)) { + t.is(result.major, 16); + t.is(result.minor, 5); + } + + 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 22df77c1a..4d17b33e9 100644 --- a/src/platform.ts +++ b/src/platform.ts @@ -63,7 +63,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)/, ); /**