-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(macos): add macOS support for config plugins (#2160)
- Loading branch information
Showing
12 changed files
with
175 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// @ts-check | ||
const { withMod } = require("@expo/config-plugins"); | ||
|
||
/** | ||
* @typedef {import("@expo/config-plugins").ExportedConfig} ExportedConfig | ||
* @typedef {import("@expo/config-plugins").ExportedConfigWithProps} ExportedConfigWithProps | ||
* @typedef {import("@expo/config-plugins").Mod} Mod | ||
* @typedef {import("@expo/config-plugins").ModConfig} ModConfig | ||
* @typedef {ExportedConfigWithProps & { macos?: { infoPlist?: Record<string, unknown> }}} ExportedConfigWithPropsMac | ||
*/ | ||
|
||
const macosPlatform = /** @type {keyof ModConfig} */ ("macos"); | ||
|
||
/** | ||
* Provides the `ReactNativeHost` file for modification. | ||
* @param {ExportedConfig} config Exported config | ||
* @param {Mod} action Method to run on the mod when the config is compiled | ||
* @returns {ExportedConfig} Modified config | ||
*/ | ||
function withReactNativeHost(config, action) { | ||
return withMod(config, { | ||
platform: macosPlatform, | ||
mod: "reactNativeHost", | ||
action, | ||
}); | ||
} | ||
|
||
/** | ||
* Provides the `AppDelegate` file for modification. | ||
* @see {@link https://github.com/expo/expo/blob/sdk-51/packages/%40expo/config-plugins/src/plugins/ios-plugins.ts#L101} | ||
* @param {ExportedConfig} config Exported config | ||
* @param {Mod} action Method to run on the mod when the config is compiled | ||
* @returns {ExportedConfig} Modified config | ||
*/ | ||
function withAppDelegate(config, action) { | ||
return withMod(config, { | ||
platform: macosPlatform, | ||
mod: "appDelegate", | ||
action, | ||
}); | ||
} | ||
|
||
/** | ||
* Provides the `Info.plist` file for modification. | ||
* @see {@link https://github.com/expo/expo/blob/sdk-51/packages/%40expo/config-plugins/src/plugins/ios-plugins.ts#L116} | ||
* @param {ExportedConfig} config Exported config | ||
* @param {Mod} action Method to run on the mod when the config is compiled | ||
* @returns {ExportedConfig} Modified config | ||
*/ | ||
function withInfoPlist(config, action) { | ||
return withMod(config, { | ||
platform: macosPlatform, | ||
mod: "infoPlist", | ||
async action(cfg) { | ||
/** @type {ExportedConfigWithPropsMac} */ | ||
const config = await action(cfg); | ||
if (!config.macos) { | ||
config.macos = {}; | ||
} | ||
config.macos.infoPlist = config.modResults; | ||
return config; | ||
}, | ||
}); | ||
} | ||
|
||
/** | ||
* Provides the main `.xcodeproj` for modification. | ||
* @see {@link https://github.com/expo/expo/blob/sdk-51/packages/%40expo/config-plugins/src/plugins/ios-plugins.ts#L173} | ||
* @param {ExportedConfig} config Exported config | ||
* @param {Mod} action Method to run on the mod when the config is compiled | ||
* @returns {ExportedConfig} Modified config | ||
*/ | ||
function withXcodeProject(config, action) { | ||
return withMod(config, { | ||
platform: macosPlatform, | ||
mod: "xcodeproj", | ||
action, | ||
}); | ||
} | ||
|
||
exports.withAppDelegate = withAppDelegate; | ||
exports.withInfoPlist = withInfoPlist; | ||
exports.withXcodeProject = withXcodeProject; | ||
exports.withReactNativeHost = withReactNativeHost; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// @ts-check | ||
import { createRequire } from "node:module"; | ||
import * as path from "node:path"; | ||
import { BaseMods } from "../ExpoConfigPlugins.mjs"; | ||
import { makeFilePathModifier, makeNullProvider } from "../provider.mjs"; | ||
|
||
const require = createRequire(import.meta.url); | ||
|
||
/** | ||
* @param {import("../types.js").CustomModProvider} modifyFilePath | ||
* @returns {import("../types.js").IosModFileProviders} | ||
*/ | ||
export function createModFileProviders(modifyFilePath) { | ||
const modifyReactNativeHostFilePath = makeFilePathModifier( | ||
path.dirname(require.resolve("@rnx-kit/react-native-host/package.json")) | ||
); | ||
|
||
const nullProvider = makeNullProvider(); | ||
|
||
// https://github.com/expo/expo/blob/sdk-51/packages/%40expo/config-plugins/src/plugins/withIosBaseMods.ts | ||
const expoProviders = BaseMods.getIosModFileProviders(); | ||
|
||
/** @type {import("../types.js").IosModFileProviders} */ | ||
const defaultProviders = { | ||
dangerous: expoProviders.dangerous, | ||
finalized: expoProviders.finalized, | ||
appDelegate: modifyFilePath( | ||
expoProviders.appDelegate, | ||
"ReactTestApp/AppDelegate.swift" | ||
), | ||
expoPlist: nullProvider, | ||
xcodeproj: modifyFilePath( | ||
expoProviders.xcodeproj, | ||
"ReactTestApp.xcodeproj/project.pbxproj" | ||
), | ||
infoPlist: modifyFilePath(expoProviders.infoPlist, "Info.plist"), | ||
entitlements: nullProvider, | ||
podfile: makeNullProvider({ | ||
path: "", | ||
language: /** @type {const} */ ("rb"), | ||
contents: "", | ||
}), | ||
podfileProperties: makeNullProvider(), | ||
}; | ||
|
||
// `@rnx-kit/react-native-host` files | ||
defaultProviders["reactNativeHost"] = modifyReactNativeHostFilePath( | ||
expoProviders.appDelegate, | ||
"cocoa/ReactNativeHost.mm" | ||
); | ||
|
||
return defaultProviders; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,17 @@ | ||
// @ts-check | ||
import { createRequire } from "node:module"; | ||
import * as path from "node:path"; | ||
import { createModFileProviders } from "./cocoaBaseMods.mjs"; | ||
import { BaseMods } from "../ExpoConfigPlugins.mjs"; | ||
import { makeFilePathModifier, makeNullProvider } from "../provider.mjs"; | ||
import { makeFilePathModifier } from "../provider.mjs"; | ||
|
||
const modifyFilePath = makeFilePathModifier("node_modules/.generated/ios"); | ||
|
||
const require = createRequire(import.meta.url); | ||
const modifyReactNativeHostFilePath = makeFilePathModifier( | ||
path.dirname(require.resolve("@rnx-kit/react-native-host/package.json")) | ||
); | ||
|
||
const nullProvider = makeNullProvider(); | ||
|
||
// https://github.com/expo/expo/blob/93cd0503117d5a25f8b80ed7b30ec5bed3a67c24/packages/@expo/config-plugins/src/plugins/withIosBaseMods.ts | ||
const expoProviders = BaseMods.getIosModFileProviders(); | ||
|
||
/** @type {typeof expoProviders & Record<string, unknown>} */ | ||
const defaultProviders = { | ||
dangerous: expoProviders.dangerous, | ||
finalized: expoProviders.finalized, | ||
appDelegate: modifyFilePath( | ||
expoProviders.appDelegate, | ||
"ReactTestApp/AppDelegate.swift" | ||
), | ||
expoPlist: nullProvider, | ||
xcodeproj: modifyFilePath( | ||
expoProviders.xcodeproj, | ||
"ReactTestApp.xcodeproj/project.pbxproj" | ||
), | ||
infoPlist: modifyFilePath(expoProviders.infoPlist, "Info.plist"), | ||
entitlements: nullProvider, | ||
podfile: makeNullProvider({ | ||
path: "", | ||
language: /** @type {const} */ ("rb"), | ||
contents: "", | ||
}), | ||
podfileProperties: makeNullProvider(), | ||
}; | ||
const defaultProviders = createModFileProviders(modifyFilePath); | ||
|
||
// `react-native-test-app` files | ||
defaultProviders["sceneDelegate"] = modifyFilePath( | ||
expoProviders.appDelegate, | ||
BaseMods.getIosModFileProviders().appDelegate, | ||
"ReactTestApp/SceneDelegate.swift" | ||
); | ||
|
||
// `@rnx-kit/react-native-host` files | ||
defaultProviders["reactNativeHost"] = modifyReactNativeHostFilePath( | ||
expoProviders.appDelegate, | ||
"cocoa/ReactNativeHost.mm" | ||
); | ||
|
||
export function getIosModFileProviders() { | ||
return defaultProviders; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// @ts-check | ||
import { createModFileProviders } from "./cocoaBaseMods.mjs"; | ||
import { makeFilePathModifier } from "../provider.mjs"; | ||
|
||
const modifyFilePath = makeFilePathModifier("node_modules/.generated/macos"); | ||
const defaultProviders = createModFileProviders(modifyFilePath); | ||
|
||
export function getMacOsModFileProviders() { | ||
return defaultProviders; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters