From e94e57ad5e8473db83610a84c7bf862417462b9b Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Sat, 3 Apr 2021 19:14:34 +0300 Subject: [PATCH] Allow Xcode paths with different patterns (#19) --- __tests__/xcode-utils.test.ts | 3 +++ src/xcode-utils.ts | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/__tests__/xcode-utils.test.ts b/__tests__/xcode-utils.test.ts index afb472d..84411fd 100644 --- a/__tests__/xcode-utils.test.ts +++ b/__tests__/xcode-utils.test.ts @@ -22,6 +22,7 @@ const buildFsDirentItem = (name: string, opt: { isSymbolicLink: boolean; isDirec const fakeReadDirResults = [ buildFsDirentItem("Xcode_2.app", { isSymbolicLink: true, isDirectory: false }), buildFsDirentItem("Xcode.app", { isSymbolicLink: false, isDirectory: true }), + buildFsDirentItem("Xcode12.4.app", { isSymbolicLink: false, isDirectory: true }), buildFsDirentItem("Xcode_11.1.app", { isSymbolicLink: false, isDirectory: true }), buildFsDirentItem("Xcode_11.1_beta.app", { isSymbolicLink: true, isDirectory: false }), buildFsDirentItem("Xcode_11.2.1.app", { isSymbolicLink: false, isDirectory: true }), @@ -40,6 +41,8 @@ describe("getInstalledXcodeApps", () => { it("versions are filtered correctly", () => { readdirSyncSpy.mockImplementation(() => fakeReadDirResults); const expectedVersions: string[] = [ + "/Applications/Xcode.app", + "/Applications/Xcode12.4.app", "/Applications/Xcode_11.1.app", "/Applications/Xcode_11.2.1.app", "/Applications/Xcode_11.4_beta.app", diff --git a/src/xcode-utils.ts b/src/xcode-utils.ts index 4b4b4bc..da2f218 100644 --- a/src/xcode-utils.ts +++ b/src/xcode-utils.ts @@ -26,7 +26,7 @@ export const parsePlistFile = (plistPath: string): plist.PlistObject | null => { export const getInstalledXcodeApps = (): string[] => { const applicationsDirectory = "/Applications"; - const xcodeAppFilenameRegex = /Xcode_([\d.]+)(_beta)?\.app/; + const xcodeAppFilenameRegex = /^Xcode.*\.app$/; const allApplicationsChildItems = fs.readdirSync(applicationsDirectory, { encoding: "utf8", withFileTypes: true }); const allApplicationsRealItems = allApplicationsChildItems.filter(child => !child.isSymbolicLink() && child.isDirectory());