Skip to content

Commit

Permalink
feat(expo): upgrade expo config plugin to v51 (#577)
Browse files Browse the repository at this point in the history
* build(expo): upgrade expo to v51
* fix(expo): update facebook plugin config
* fix(expo): update plugin build files
* chore: update Podfile.lock (latest fbsdk)
  • Loading branch information
LukeGu-web authored Nov 26, 2024
1 parent 6f1d772 commit a5b625c
Show file tree
Hide file tree
Showing 8 changed files with 1,584 additions and 946 deletions.
16 changes: 8 additions & 8 deletions RNFBSDKExample/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1251,18 +1251,18 @@ PODS:
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- react-native-fbsdk-next (13.1.3):
- react-native-fbsdk-next (13.1.4):
- React-Core
- react-native-fbsdk-next/Core (= 13.1.3)
- react-native-fbsdk-next/Login (= 13.1.3)
- react-native-fbsdk-next/Share (= 13.1.3)
- react-native-fbsdk-next/Core (13.1.3):
- react-native-fbsdk-next/Core (= 13.1.4)
- react-native-fbsdk-next/Login (= 13.1.4)
- react-native-fbsdk-next/Share (= 13.1.4)
- react-native-fbsdk-next/Core (13.1.4):
- FBSDKCoreKit (~> 17.4)
- React-Core
- react-native-fbsdk-next/Login (13.1.3):
- react-native-fbsdk-next/Login (13.1.4):
- FBSDKLoginKit (~> 17.4)
- React-Core
- react-native-fbsdk-next/Share (13.1.3):
- react-native-fbsdk-next/Share (13.1.4):
- FBSDKGamingServicesKit (~> 17.4)
- FBSDKShareKit (~> 17.4)
- React-Core
Expand Down Expand Up @@ -1777,7 +1777,7 @@ SPEC CHECKSUMS:
React-logger: 4072f39df335ca443932e0ccece41fbeb5ca8404
React-Mapbuffer: 714f2fae68edcabfc332b754e9fbaa8cfc68fdd4
React-microtasksnativemodule: 4943ad8f99be8ccf5a63329fa7d269816609df9e
react-native-fbsdk-next: eb441f2f641cf3066297d376a1df13dccf812317
react-native-fbsdk-next: de7d8792163c648b27ed853d0dab181cf928aa32
React-nativeconfig: 4a9543185905fe41014c06776bf126083795aed9
React-NativeModulesApple: 0506da59fc40d2e1e6e12a233db5e81c46face27
React-perflogger: 3bbb82f18e9ac29a1a6931568e99d6305ef4403b
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
}
},
"devDependencies": {
"@babel/core": "^7.23.9",
"@babel/core": "^7.24.0",
"@babel/runtime": "^7.23.9",
"@react-native-community/eslint-config": "^3.2.0",
"@semantic-release/commit-analyzer": "^11.1.0",
Expand All @@ -104,21 +104,21 @@
"@semantic-release/release-notes-generator": "^12.1.0",
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
"@tsconfig/node14": "^14.1.0",
"@types/react": "^18.2.48",
"@types/react": "^18.2.79",
"@types/xml2js": "^0.4.14",
"@typescript-eslint/eslint-plugin": "^6.19.1",
"@typescript-eslint/parser": "^6.19.1",
"babel-jest": "^29.7.0",
"babel-plugin-module-resolver": "^5.0.0",
"conventional-changelog-conventionalcommits": "^7.0.2",
"eslint": "^8.56.0",
"expo": "^47",
"expo": "^51.0.38",
"expo-module-scripts": "^3.4.0",
"jest": "^29.7.0",
"metro-react-native-babel-preset": "^0.77.0",
"prettier": "^3.2.4",
"react": "18.2.0",
"react-native": "^0.73.2",
"react-native": "^0.74.5",
"react-native-builder-bob": "^0.23.2",
"react-test-renderer": "18.2.0",
"semantic-release": "^23.0.0",
Expand Down
16 changes: 14 additions & 2 deletions plugin/build/config.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import { ExpoConfig } from '@expo/config-types';
export type ExpoConfigFacebook = Pick<ExpoConfig, 'facebookScheme' | 'facebookAdvertiserIDCollectionEnabled' | 'facebookAppId' | 'facebookAutoInitEnabled' | 'facebookAutoLogAppEventsEnabled' | 'facebookDisplayName'>;
type FacebookPluginConfig = {
scheme?: string;
advertiserIDCollectionEnabled?: boolean;
appId?: string;
autoInitEnabled?: boolean;
autoLogAppEventsEnabled?: boolean;
displayName?: string;
};
export type ExpoConfigFacebook = {
plugins: {
facebook: FacebookPluginConfig;
};
};
export type ConfigProps = {
/**
* Used for all Facebook libraries. Set up your Facebook App ID at https://developers.facebook.com.
Expand Down Expand Up @@ -39,3 +50,4 @@ export declare function getFacebookDisplayName(config: ConfigProps): string | nu
export declare function getFacebookAutoInitEnabled(config: ConfigProps): boolean | null;
export declare function getFacebookAutoLogAppEvents(config: ConfigProps): boolean | null;
export declare function getFacebookAdvertiserIDCollection(config: ConfigProps): boolean | null;
export {};
2 changes: 1 addition & 1 deletion plugin/build/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Object.defineProperty(exports, "__esModule", { value: true });
exports.getFacebookAdvertiserIDCollection = exports.getFacebookAutoLogAppEvents = exports.getFacebookAutoInitEnabled = exports.getFacebookDisplayName = exports.getFacebookScheme = exports.getFacebookClientToken = exports.getFacebookAppId = exports.getMergePropsWithConfig = void 0;
function getMergePropsWithConfig(config, props) {
const { facebookAppId, facebookDisplayName, facebookScheme, facebookAutoInitEnabled, facebookAutoLogAppEventsEnabled, facebookAdvertiserIDCollectionEnabled, } = config;
const { appId: facebookAppId, displayName: facebookDisplayName, scheme: facebookScheme, autoInitEnabled: facebookAutoInitEnabled, autoLogAppEventsEnabled: facebookAutoLogAppEventsEnabled, advertiserIDCollectionEnabled: facebookAdvertiserIDCollectionEnabled, } = config.plugins.facebook;
const { appID = facebookAppId, clientToken, displayName = facebookDisplayName, scheme = facebookScheme ?? (appID ? `fb${appID}` : undefined), isAutoInitEnabled = facebookAutoInitEnabled ?? false, autoLogAppEventsEnabled = facebookAutoLogAppEventsEnabled ?? false, advertiserIDCollectionEnabled = facebookAdvertiserIDCollectionEnabled ??
false, iosUserTrackingPermission, } = (props ?? {});
return {
Expand Down
26 changes: 25 additions & 1 deletion plugin/build/withFacebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,32 @@ const withSKAdNetworkIdentifiers_1 = require("./withSKAdNetworkIdentifiers");
const config_plugins_1 = require("@expo/config-plugins");
// eslint-disable-next-line @typescript-eslint/no-var-requires
const pkg = require('react-native-fbsdk-next/package.json');
function getExpoFacebookConfig(config) {
const facebookPlugin = config.plugins?.find((plugin) => {
if (Array.isArray(plugin) && plugin[0] === 'facebook') {
return true;
}
return false;
});
if (Array.isArray(facebookPlugin) && facebookPlugin.length > 1) {
return {
plugins: {
facebook: facebookPlugin[1],
},
};
}
return {
plugins: {
facebook: {},
},
};
}
const withFacebook = (config, props) => {
const newProps = (0, config_1.getMergePropsWithConfig)(config, props);
// Convert ExpoConfig to ExpoConfigFacebook format
const facebookConfig = getExpoFacebookConfig(config);
// Merge the configs
const newProps = (0, config_1.getMergePropsWithConfig)(facebookConfig, props);
// Validation
if (!newProps.appID) {
throw new Error('missing appID in the plugin properties');
}
Expand Down
37 changes: 20 additions & 17 deletions plugin/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import {ExpoConfig} from '@expo/config-types';
type FacebookPluginConfig = {
scheme?: string;
advertiserIDCollectionEnabled?: boolean;
appId?: string;
autoInitEnabled?: boolean;
autoLogAppEventsEnabled?: boolean;
displayName?: string;
};

export type ExpoConfigFacebook = Pick<
ExpoConfig,
| 'facebookScheme'
| 'facebookAdvertiserIDCollectionEnabled'
| 'facebookAppId'
| 'facebookAutoInitEnabled'
| 'facebookAutoLogAppEventsEnabled'
| 'facebookDisplayName'
>;
export type ExpoConfigFacebook = {
plugins: {
facebook: FacebookPluginConfig;
};
};

export type ConfigProps = {
/**
Expand Down Expand Up @@ -49,13 +52,13 @@ export function getMergePropsWithConfig(
props: ConfigProps | void,
): ConfigProps {
const {
facebookAppId,
facebookDisplayName,
facebookScheme,
facebookAutoInitEnabled,
facebookAutoLogAppEventsEnabled,
facebookAdvertiserIDCollectionEnabled,
} = config;
appId: facebookAppId,
displayName: facebookDisplayName,
scheme: facebookScheme,
autoInitEnabled: facebookAutoInitEnabled,
autoLogAppEventsEnabled: facebookAutoLogAppEventsEnabled,
advertiserIDCollectionEnabled: facebookAdvertiserIDCollectionEnabled,
} = config.plugins.facebook;
const {
appID = facebookAppId,
clientToken,
Expand Down
32 changes: 31 additions & 1 deletion plugin/src/withFacebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,43 @@ import {
} from './withFacebookAndroid';
import {withFacebookIOS, withUserTrackingPermission} from './withFacebookIOS';
import {withSKAdNetworkIdentifiers} from './withSKAdNetworkIdentifiers';
import {ExpoConfig} from '@expo/config-types';
import {ConfigPlugin, createRunOncePlugin} from '@expo/config-plugins';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const pkg = require('react-native-fbsdk-next/package.json');

function getExpoFacebookConfig(config: ExpoConfig) {
const facebookPlugin = config.plugins?.find((plugin) => {
if (Array.isArray(plugin) && plugin[0] === 'facebook') {
return true;
}
return false;
});

if (Array.isArray(facebookPlugin) && facebookPlugin.length > 1) {
return {
plugins: {
facebook: facebookPlugin[1],
},
};
}

return {
plugins: {
facebook: {},
},
};
}

const withFacebook: ConfigPlugin<ConfigProps | void> = (config, props) => {
const newProps = getMergePropsWithConfig(config, props);
// Convert ExpoConfig to ExpoConfigFacebook format
const facebookConfig = getExpoFacebookConfig(config);

// Merge the configs
const newProps = getMergePropsWithConfig(facebookConfig, props);

// Validation
if (!newProps.appID) {
throw new Error('missing appID in the plugin properties');
}
Expand Down
Loading

0 comments on commit a5b625c

Please sign in to comment.