Skip to content

Commit

Permalink
Allow Xcode paths with different patterns (#19)
Browse files Browse the repository at this point in the history
maxim-lobanov authored Apr 3, 2021
1 parent 6e6790d commit e94e57a
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions __tests__/xcode-utils.test.ts
Original file line number Diff line number Diff line change
@@ -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",
2 changes: 1 addition & 1 deletion src/xcode-utils.ts
Original file line number Diff line number Diff line change
@@ -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());

0 comments on commit e94e57a

Please sign in to comment.