Skip to content

Commit 622a257

Browse files
committed
move macOS mods to separate file
1 parent 90ae790 commit 622a257

File tree

3 files changed

+86
-48
lines changed

3 files changed

+86
-48
lines changed

plugins/index.js

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,57 +3,10 @@ const { withMod } = require("@expo/config-plugins");
33

44
/**
55
* @typedef {import("@expo/config-plugins").ExportedConfig} ExportedConfig
6-
* @typedef {import("@expo/config-plugins").ExportedConfigWithProps} ExportedConfigWithProps
76
* @typedef {import("@expo/config-plugins").Mod} Mod
87
* @typedef {import("@expo/config-plugins").ModConfig} ModConfig
9-
* @typedef {ExportedConfigWithProps & { macos?: { infoPlist?: Record<string, unknown> }}} ExportedConfigWithPropsMac
108
*/
119

12-
const macosPlatform = /** @type {keyof ModConfig} */ ("macos");
13-
14-
/** @type {Record<string, (config: ExportedConfig, mod: Mod) => ExportedConfig>} */
15-
const macos = {
16-
withReactNativeHost: (config, action) => {
17-
return withMod(config, {
18-
platform: macosPlatform,
19-
mod: "reactNativeHost",
20-
action,
21-
});
22-
},
23-
// https://github.com/expo/expo/blob/sdk-51/packages/%40expo/config-plugins/src/plugins/ios-plugins.ts#L101
24-
withAppDelegate: (config, action) => {
25-
return withMod(config, {
26-
platform: macosPlatform,
27-
mod: "appDelegate",
28-
action,
29-
});
30-
},
31-
// https://github.com/expo/expo/blob/sdk-51/packages/%40expo/config-plugins/src/plugins/ios-plugins.ts#L116
32-
withInfoPlist: (config, action) => {
33-
return withMod(config, {
34-
platform: macosPlatform,
35-
mod: "infoPlist",
36-
async action(cfg) {
37-
/** @type {ExportedConfigWithPropsMac} */
38-
const config = await action(cfg);
39-
if (!config.macos) {
40-
config.macos = {};
41-
}
42-
config.macos.infoPlist = config.modResults;
43-
return config;
44-
},
45-
});
46-
},
47-
// https://github.com/expo/expo/blob/sdk-51/packages/%40expo/config-plugins/src/plugins/ios-plugins.ts#L173
48-
withXcodeProject: (config, action) => {
49-
return withMod(config, {
50-
platform: macosPlatform,
51-
mod: "xcodeproj",
52-
action,
53-
});
54-
},
55-
};
56-
5710
/**
5811
* Provides the `ReactNativeHost` file for modification.
5912
* @param {ExportedConfig} config Exported config
@@ -82,6 +35,6 @@ function withSceneDelegate(config, action) {
8235
});
8336
}
8437

85-
exports.macos = macos;
38+
exports.macos = require("./macos");
8639
exports.withReactNativeHost = withReactNativeHost;
8740
exports.withSceneDelegate = withSceneDelegate;

plugins/macos.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// @ts-check
2+
const { withMod } = require("@expo/config-plugins");
3+
4+
/**
5+
* @typedef {import("@expo/config-plugins").ExportedConfig} ExportedConfig
6+
* @typedef {import("@expo/config-plugins").ExportedConfigWithProps} ExportedConfigWithProps
7+
* @typedef {import("@expo/config-plugins").Mod} Mod
8+
* @typedef {import("@expo/config-plugins").ModConfig} ModConfig
9+
* @typedef {ExportedConfigWithProps & { macos?: { infoPlist?: Record<string, unknown> }}} ExportedConfigWithPropsMac
10+
*/
11+
12+
const macosPlatform = /** @type {keyof ModConfig} */ ("macos");
13+
14+
/**
15+
* Provides the `ReactNativeHost` file for modification.
16+
* @param {ExportedConfig} config Exported config
17+
* @param {Mod} action Method to run on the mod when the config is compiled
18+
* @returns {ExportedConfig} Modified config
19+
*/
20+
function withReactNativeHost(config, action) {
21+
return withMod(config, {
22+
platform: macosPlatform,
23+
mod: "reactNativeHost",
24+
action,
25+
});
26+
}
27+
28+
/**
29+
* Provides the `AppDelegate` file for modification.
30+
* @see {@link https://github.com/expo/expo/blob/sdk-51/packages/%40expo/config-plugins/src/plugins/ios-plugins.ts#L101}
31+
* @param {ExportedConfig} config Exported config
32+
* @param {Mod} action Method to run on the mod when the config is compiled
33+
* @returns {ExportedConfig} Modified config
34+
*/
35+
function withAppDelegate(config, action) {
36+
return withMod(config, {
37+
platform: macosPlatform,
38+
mod: "appDelegate",
39+
action,
40+
});
41+
}
42+
43+
/**
44+
* Provides the `Info.plist` file for modification.
45+
* @see {@link https://github.com/expo/expo/blob/sdk-51/packages/%40expo/config-plugins/src/plugins/ios-plugins.ts#L116}
46+
* @param {ExportedConfig} config Exported config
47+
* @param {Mod} action Method to run on the mod when the config is compiled
48+
* @returns {ExportedConfig} Modified config
49+
*/
50+
function withInfoPlist(config, action) {
51+
return withMod(config, {
52+
platform: macosPlatform,
53+
mod: "infoPlist",
54+
async action(cfg) {
55+
/** @type {ExportedConfigWithPropsMac} */
56+
const config = await action(cfg);
57+
if (!config.macos) {
58+
config.macos = {};
59+
}
60+
config.macos.infoPlist = config.modResults;
61+
return config;
62+
},
63+
});
64+
}
65+
66+
/**
67+
* Provides the main `.xcodeproj` for modification.
68+
* @see {@link https://github.com/expo/expo/blob/sdk-51/packages/%40expo/config-plugins/src/plugins/ios-plugins.ts#L173}
69+
* @param {ExportedConfig} config Exported config
70+
* @param {Mod} action Method to run on the mod when the config is compiled
71+
* @returns {ExportedConfig} Modified config
72+
*/
73+
function withXcodeProject(config, action) {
74+
return withMod(config, {
75+
platform: macosPlatform,
76+
mod: "xcodeproj",
77+
action,
78+
});
79+
}
80+
81+
exports.withAppDelegate = withAppDelegate;
82+
exports.withInfoPlist = withInfoPlist;
83+
exports.withXcodeProject = withXcodeProject;
84+
exports.withReactNativeHost = withReactNativeHost;

test/pack.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ describe("npm pack", () => {
176176
"macos/test_app.rb",
177177
"package.json",
178178
"plugins/index.js",
179+
"plugins/macos.js",
179180
"plugins/reanimated.js",
180181
"react-native.config.js",
181182
"schema.json",

0 commit comments

Comments
 (0)