-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Changes Flipper includes for React Native 0.69.2+
* fix: Changes SDK46 podfile to use new URN args * refactor: Removes old sdk43 tests * docs: Adds changelog notes * fix: Removes linking checks for sdk46 * fix: Changes env check to an explicit hard-check to mirror the production check code * refactor: Rebuilds plugin\ Closes #18. Closes #19
- Loading branch information
Showing
29 changed files
with
571 additions
and
907 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
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,12 @@ | ||
/** Base expo tag for dangerous mods */ | ||
export declare const EXPO_FLIPPER_TAG = "expo-community-flipper"; | ||
/** The gradle property containing flipper version info */ | ||
export declare const ANDROID_FLIPPER_KEY = "FLIPPER_VERSION"; | ||
/** If all else fails, try this flipper version */ | ||
export declare const FLIPPER_FALLBACK = "0.125.0"; | ||
/** In iOS, this is the line we anchor to for adding args to use_react_native!() */ | ||
export declare const IOS_URN_ARG_ANCHOR: RegExp; | ||
/** In a Podfile, this regex tells us the :production arg is already there */ | ||
export declare const IOS_HAS_PRODUCTION_ARG: RegExp; | ||
/** In a Podfile, this regex tells us the :flipper_configuration arg is already there */ | ||
export declare const IOS_HAS_FLIPPER_ARG: RegExp; |
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,15 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.IOS_HAS_FLIPPER_ARG = exports.IOS_HAS_PRODUCTION_ARG = exports.IOS_URN_ARG_ANCHOR = exports.FLIPPER_FALLBACK = exports.ANDROID_FLIPPER_KEY = exports.EXPO_FLIPPER_TAG = void 0; | ||
/** Base expo tag for dangerous mods */ | ||
exports.EXPO_FLIPPER_TAG = "expo-community-flipper"; | ||
/** The gradle property containing flipper version info */ | ||
exports.ANDROID_FLIPPER_KEY = "FLIPPER_VERSION"; | ||
/** If all else fails, try this flipper version */ | ||
exports.FLIPPER_FALLBACK = "0.125.0"; | ||
/** In iOS, this is the line we anchor to for adding args to use_react_native!() */ | ||
exports.IOS_URN_ARG_ANCHOR = /:fabric_enabled => flags\[:fabric_enabled\],/; | ||
/** In a Podfile, this regex tells us the :production arg is already there */ | ||
exports.IOS_HAS_PRODUCTION_ARG = /use_react_native!\([\s\S]*:production\s+=>/gm; | ||
/** In a Podfile, this regex tells us the :flipper_configuration arg is already there */ | ||
exports.IOS_HAS_FLIPPER_ARG = /use_react_native!\([\s\S]*:flipper_configuration\s+=>/gm; |
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,8 @@ | ||
export declare type FlipperConfig = { | ||
version: string | undefined; | ||
}; | ||
export declare type WithFlipperOptions = FlipperOptions | string; | ||
declare type FlipperOptions = { | ||
version: string; | ||
}; | ||
export {}; |
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,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
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,2 @@ | ||
import { FlipperConfig, WithFlipperOptions } from "./types"; | ||
export declare function getConfiguration(options?: WithFlipperOptions): FlipperConfig; |
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,18 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getConfiguration = void 0; | ||
function getConfiguration(options) { | ||
let flipperVersion; | ||
if (typeof options === "string") { | ||
flipperVersion = options; | ||
} | ||
else if (typeof options === "object") { | ||
if (options.version) { | ||
flipperVersion = options.version; | ||
} | ||
} | ||
return { | ||
version: flipperVersion, | ||
}; | ||
} | ||
exports.getConfiguration = getConfiguration; |
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,3 @@ | ||
import { ExpoConfig } from "@expo/config-types"; | ||
import { FlipperConfig } from "./types"; | ||
export declare function withFlipperAndroid(config: ExpoConfig, cfg: FlipperConfig): ExpoConfig; |
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,32 @@ | ||
"use strict"; | ||
/* | ||
Exports functions to make a set of changes to enable flipper | ||
withFlipper | ||
(1) gradle.properties | ||
Set FLIPPER_VERSION if required | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.withFlipperAndroid = void 0; | ||
const config_plugins_1 = require("@expo/config-plugins"); | ||
const constants_1 = require("./constants"); | ||
function withFlipperAndroid(config, cfg) { | ||
return (0, config_plugins_1.withGradleProperties)(config, (c) => { | ||
var _a, _b, _c; | ||
// check for flipper version in package. If set, use that | ||
let existing; | ||
const found = (_a = c.modResults.filter((item) => item.type === "property" && item.key === constants_1.ANDROID_FLIPPER_KEY)) === null || _a === void 0 ? void 0 : _a[0]; | ||
if (found && found.type === "property") { | ||
existing = found.value; | ||
} | ||
// strip flipper key and re-add | ||
c.modResults = c.modResults.filter((item) => !(item.type === "property" && item.key === constants_1.ANDROID_FLIPPER_KEY)); | ||
c.modResults.push({ | ||
type: "property", | ||
key: constants_1.ANDROID_FLIPPER_KEY, | ||
value: (_c = (_b = cfg.version) !== null && _b !== void 0 ? _b : existing) !== null && _c !== void 0 ? _c : constants_1.FLIPPER_FALLBACK, | ||
}); | ||
return c; | ||
}); | ||
} | ||
exports.withFlipperAndroid = withFlipperAndroid; |
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,24 +1,5 @@ | ||
import { ConfigPlugin } from "@expo/config-plugins"; | ||
export declare type withFlipperOptions = flipperOptions | string; | ||
declare type flipperOptions = { | ||
Flipper?: string; | ||
ios?: { | ||
"Flipper-Folly": string; | ||
"Flipper-RSocket": string; | ||
"Flipper-DoubleConversion": string; | ||
"Flipper-Glog": string; | ||
"Flipper-PeerTalk": string; | ||
}; | ||
}; | ||
export declare type flipperConfig = { | ||
ios: { | ||
[key: string]: string | null; | ||
Flipper: string | null; | ||
}; | ||
android: string | null; | ||
}; | ||
/** Adds the flipper lines to the podfile */ | ||
export declare function addFlipperToPodfile(contents: string, options: flipperConfig): string; | ||
import { WithFlipperOptions } from "./types"; | ||
/** Enable flipper on this application */ | ||
export declare const withFlipper: ConfigPlugin<withFlipperOptions>; | ||
export declare const withFlipper: ConfigPlugin<WithFlipperOptions>; | ||
export default withFlipper; |
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,3 @@ | ||
import { ExpoConfig } from "@expo/config-types"; | ||
import { FlipperConfig } from "./types"; | ||
export declare function withFlipperIOS(config: ExpoConfig, cfg: FlipperConfig): ExpoConfig; |
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,114 @@ | ||
"use strict"; | ||
/* | ||
exports the following config file changes for iOS Apps | ||
withFlipper | ||
(1) Inside use_react_native, after :fabric_enabled => flags[:fabric_enabled], | ||
:flipper_configuration => FlipperConfiguration.enabled, | ||
:flipper_configuration => FlipperConfiguration.disabled, | ||
Depending on the ENV variable | ||
withProductionEnv | ||
(1) BEFORE target line | ||
production = ENV["PRODUCTION"] == "1" | ||
(2) Inside use_react_native, after :path => config[:reactNativePath], | ||
:production => production, | ||
*/ | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.withFlipperIOS = void 0; | ||
const config_plugins_1 = require("@expo/config-plugins"); | ||
const generateCode_1 = require("@expo/config-plugins/build/utils/generateCode"); | ||
const constants_1 = require("./constants"); | ||
const path_1 = __importDefault(require("path")); | ||
const fs_1 = __importDefault(require("fs")); | ||
/** Create a namepaced tag */ | ||
const tag = (s) => `${constants_1.EXPO_FLIPPER_TAG}-${s}`; | ||
/** Return the flipper enabling line for use inside of use_react_native */ | ||
const createFlipperArgument = (version) => { | ||
const active = version | ||
? `FlipperConfiguration.enabled(["Debug"], { 'Flipper' => '${version}' }),` | ||
: `FlipperConfiguration.enabled,`; | ||
const inactive = `FlipperConfiguration.disabled`; | ||
return `:flipper_configuration => ENV['FLIPPER_DISABLE'] == "1" ? ${inactive} : ${active}`; | ||
}; | ||
/** Removes content by its tag */ | ||
const removeTaggedContent = (contents, ns) => { | ||
return (0, generateCode_1.removeContents)({ src: contents, tag: tag(ns) }); | ||
}; | ||
/** Add the production arg to the use_react_native block */ | ||
function withEnvProductionPodfile(config) { | ||
config = (0, config_plugins_1.withDangerousMod)(config, [ | ||
"ios", | ||
async (c) => { | ||
const filePath = path_1.default.join(c.modRequest.platformProjectRoot, "Podfile"); | ||
const contents = fs_1.default.readFileSync(filePath, "utf-8"); | ||
// #3 We cannot tell if a merge failed because of a malformed podfile or it was a noop | ||
// so instead, remove the content first, then attempt the insert | ||
let result = removeTaggedContent(contents, "isprod"); | ||
const preexisting = constants_1.IOS_HAS_PRODUCTION_ARG.test(result.contents); | ||
if (!preexisting) { | ||
result = (0, generateCode_1.mergeContents)({ | ||
tag: tag("isprod"), | ||
src: result.contents, | ||
newSrc: ` | ||
# https://www.npmjs.com/package/expo-community-flipper | ||
:production => ENV["PRODUCTION"] == "1" ? true : false,`, | ||
anchor: constants_1.IOS_URN_ARG_ANCHOR, | ||
offset: -1, | ||
comment: "#", | ||
}); | ||
// couldn't remove and couldn't add. Treat the operation as failed | ||
if (!result.didMerge) { | ||
throw new Error("Cannot add use_flipper to the project's ios/Podfile. Please report this with a copy of your project Podfile. You can generate this with the `expo prebuild` command."); | ||
} | ||
} | ||
fs_1.default.writeFileSync(filePath, result.contents); | ||
return c; | ||
}, | ||
]); | ||
return config; | ||
} | ||
/** Add flipper to the podfile, behind an ENV flag */ | ||
function withFlipperPodfile(config, cfg) { | ||
config = (0, config_plugins_1.withDangerousMod)(config, [ | ||
"ios", | ||
async (c) => { | ||
const filePath = path_1.default.join(c.modRequest.platformProjectRoot, "Podfile"); | ||
const contents = fs_1.default.readFileSync(filePath, "utf-8"); | ||
// #3 We cannot tell if a merge failed because of a malformed podfile or it was a noop | ||
// so instead, remove the content first, then attempt the insert | ||
let result = removeTaggedContent(contents, "urn"); | ||
const preexisting = constants_1.IOS_HAS_FLIPPER_ARG.test(result.contents); | ||
if (!preexisting) { | ||
result = (0, generateCode_1.mergeContents)({ | ||
tag: tag("urn"), | ||
src: result.contents, | ||
newSrc: ` | ||
# https://www.npmjs.com/package/expo-community-flipper | ||
${createFlipperArgument(cfg.version)}`, | ||
anchor: constants_1.IOS_URN_ARG_ANCHOR, | ||
offset: 1, | ||
comment: "#", | ||
}); | ||
// couldn't remove and couldn't add. Treat the operation as failed | ||
if (!result.didMerge) { | ||
throw new Error("Cannot add use_flipper to the project's ios/Podfile. Please report this with a copy of your project Podfile. You can generate this with the `expo prebuild` command."); | ||
} | ||
} | ||
fs_1.default.writeFileSync(filePath, result.contents); | ||
return c; | ||
}, | ||
]); | ||
return config; | ||
} | ||
function withFlipperIOS(config, cfg) { | ||
config = withEnvProductionPodfile(config); | ||
config = withFlipperPodfile(config, cfg); | ||
return config; | ||
} | ||
exports.withFlipperIOS = withFlipperIOS; |
Oops, something went wrong.