mirror of
https://github.com/expo/config-plugins.git
synced 2026-11-13 20:28:07 -10:00
fix: removed proguard-rules.pro edit step
This commit is contained in:
3 files changed
+4
-171
No files matched your search
+1
-2
@@ -1,8 +1,7 @@
|
||||
import { AndroidConfig } from "@expo/config-plugins";
|
||||
import type { ConfigPlugin, ExportedConfigWithProps } from "@expo/config-plugins";
|
||||
import type { ConfigPlugin } from "@expo/config-plugins";
|
||||
import type { ExpoConfig } from "@expo/config-types";
|
||||
import type { MergeResults } from "@expo/config-plugins/build/utils/generateCode";
|
||||
export declare function editProguardRules(config: ExportedConfigWithProps, action: (mainApplication: string) => string): Promise<void>;
|
||||
export declare function modifyMainApplication(mainApplication: string, language: "java" | "kt"): string;
|
||||
export declare function addBranchInitSession(src: string): MergeResults;
|
||||
export declare function addBranchOnNewIntent(src: string): MergeResults;
|
||||
|
||||
+1
-76
@@ -1,71 +1,11 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.withBranchAndroid = exports.modifyMainActivity = exports.setBranchApiKey = exports.getBranchApiKey = exports.addBranchOnNewIntent = exports.addBranchInitSession = exports.modifyMainApplication = exports.editProguardRules = void 0;
|
||||
exports.withBranchAndroid = exports.modifyMainActivity = exports.setBranchApiKey = exports.getBranchApiKey = exports.addBranchOnNewIntent = exports.addBranchInitSession = exports.modifyMainApplication = void 0;
|
||||
const config_plugins_1 = require("@expo/config-plugins");
|
||||
const codeMod_1 = require("@expo/config-plugins/build/android/codeMod");
|
||||
const generateCode_1 = require("@expo/config-plugins/build/utils/generateCode");
|
||||
const fs = __importStar(require("fs"));
|
||||
const path = __importStar(require("path"));
|
||||
const { addMetaDataItemToMainApplication, getMainApplicationOrThrow, removeMetaDataItemFromMainApplication, } = config_plugins_1.AndroidConfig.Manifest;
|
||||
const META_BRANCH_KEY = "io.branch.sdk.BranchKey";
|
||||
async function readFileAsync(path) {
|
||||
return fs.promises.readFile(path, "utf8");
|
||||
}
|
||||
async function saveFileAsync(path, content) {
|
||||
return fs.promises.writeFile(path, content, "utf8");
|
||||
}
|
||||
// Fork of config-plugins mergeContents, but appends the contents to the end of the file.
|
||||
function appendContents({ src, newSrc, tag, comment, }) {
|
||||
const header = generateCode_1.createGeneratedHeaderComment(newSrc, tag, comment);
|
||||
if (!src.includes(header)) {
|
||||
// Ensure the old generated contents are removed.
|
||||
const sanitizedTarget = generateCode_1.removeGeneratedContents(src, tag);
|
||||
const contentsToAdd = [
|
||||
// @something
|
||||
header,
|
||||
// contents
|
||||
newSrc,
|
||||
// @end
|
||||
`${comment} @generated end ${tag}`,
|
||||
].join("\n");
|
||||
return {
|
||||
contents: (sanitizedTarget !== null && sanitizedTarget !== void 0 ? sanitizedTarget : src) + contentsToAdd,
|
||||
didMerge: true,
|
||||
didClear: !!sanitizedTarget,
|
||||
};
|
||||
}
|
||||
return { contents: src, didClear: false, didMerge: false };
|
||||
}
|
||||
async function editProguardRules(config, action) {
|
||||
const proguardRulesPath = path.join(config.modRequest.platformProjectRoot, "app", "proguard-rules.pro");
|
||||
try {
|
||||
const proguardRules = action(await readFileAsync(proguardRulesPath));
|
||||
return await saveFileAsync(proguardRulesPath, proguardRules);
|
||||
}
|
||||
catch (e) {
|
||||
config_plugins_1.WarningAggregator.addWarningAndroid("@config-plugins/react-native-branch", `Couldn't modify proguard-rules.pro - ${e}.`);
|
||||
}
|
||||
}
|
||||
exports.editProguardRules = editProguardRules;
|
||||
function addGetAutoInstanceIfNeeded(mainApplication, isJava) {
|
||||
if (mainApplication.match(/\s+RNBranchModule\.getAutoInstance\(/m)) {
|
||||
return mainApplication;
|
||||
@@ -196,21 +136,6 @@ const withBranchAndroid = (config, data) => {
|
||||
config.modResults.contents = exports.modifyMainActivity(config.modResults.contents, config.modResults.language);
|
||||
return config;
|
||||
});
|
||||
// Update proguard rules directly
|
||||
config = config_plugins_1.withDangerousMod(config, [
|
||||
"android",
|
||||
async (config) => {
|
||||
await editProguardRules(config, (proguardRules) => {
|
||||
return appendContents({
|
||||
tag: "react-native-branch-dont-warn",
|
||||
src: proguardRules,
|
||||
newSrc: ["-dontwarn io.branch.**"].join("\n"),
|
||||
comment: "#",
|
||||
}).contents;
|
||||
});
|
||||
return config;
|
||||
},
|
||||
]);
|
||||
return config;
|
||||
};
|
||||
exports.withBranchAndroid = withBranchAndroid;
|
||||
@@ -1,8 +1,6 @@
|
||||
import {
|
||||
AndroidConfig,
|
||||
WarningAggregator,
|
||||
withAndroidManifest,
|
||||
withDangerousMod,
|
||||
withMainActivity,
|
||||
withMainApplication,
|
||||
} from "@expo/config-plugins";
|
||||
@@ -10,19 +8,10 @@ import {
|
||||
addImports,
|
||||
appendContentsInsideDeclarationBlock,
|
||||
} from "@expo/config-plugins/build/android/codeMod";
|
||||
import type {
|
||||
ConfigPlugin,
|
||||
ExportedConfigWithProps,
|
||||
} from "@expo/config-plugins";
|
||||
import type { ConfigPlugin } from "@expo/config-plugins";
|
||||
import type { ExpoConfig } from "@expo/config-types";
|
||||
import {
|
||||
createGeneratedHeaderComment,
|
||||
mergeContents,
|
||||
removeGeneratedContents,
|
||||
} from "@expo/config-plugins/build/utils/generateCode";
|
||||
import { mergeContents } from "@expo/config-plugins/build/utils/generateCode";
|
||||
import type { MergeResults } from "@expo/config-plugins/build/utils/generateCode";
|
||||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
|
||||
const {
|
||||
addMetaDataItemToMainApplication,
|
||||
@@ -32,69 +21,6 @@ const {
|
||||
|
||||
const META_BRANCH_KEY = "io.branch.sdk.BranchKey";
|
||||
|
||||
async function readFileAsync(path: string) {
|
||||
return fs.promises.readFile(path, "utf8");
|
||||
}
|
||||
|
||||
async function saveFileAsync(path: string, content: string) {
|
||||
return fs.promises.writeFile(path, content, "utf8");
|
||||
}
|
||||
|
||||
// Fork of config-plugins mergeContents, but appends the contents to the end of the file.
|
||||
function appendContents({
|
||||
src,
|
||||
newSrc,
|
||||
tag,
|
||||
comment,
|
||||
}: {
|
||||
src: string;
|
||||
newSrc: string;
|
||||
tag: string;
|
||||
comment: string;
|
||||
}): MergeResults {
|
||||
const header = createGeneratedHeaderComment(newSrc, tag, comment);
|
||||
if (!src.includes(header)) {
|
||||
// Ensure the old generated contents are removed.
|
||||
const sanitizedTarget = removeGeneratedContents(src, tag);
|
||||
const contentsToAdd = [
|
||||
// @something
|
||||
header,
|
||||
// contents
|
||||
newSrc,
|
||||
// @end
|
||||
`${comment} @generated end ${tag}`,
|
||||
].join("\n");
|
||||
|
||||
return {
|
||||
contents: (sanitizedTarget ?? src) + contentsToAdd,
|
||||
didMerge: true,
|
||||
didClear: !!sanitizedTarget,
|
||||
};
|
||||
}
|
||||
|
||||
return { contents: src, didClear: false, didMerge: false };
|
||||
}
|
||||
|
||||
export async function editProguardRules(
|
||||
config: ExportedConfigWithProps,
|
||||
action: (mainApplication: string) => string
|
||||
) {
|
||||
const proguardRulesPath = path.join(
|
||||
config.modRequest.platformProjectRoot,
|
||||
"app",
|
||||
"proguard-rules.pro"
|
||||
);
|
||||
try {
|
||||
const proguardRules = action(await readFileAsync(proguardRulesPath));
|
||||
return await saveFileAsync(proguardRulesPath, proguardRules);
|
||||
} catch (e) {
|
||||
WarningAggregator.addWarningAndroid(
|
||||
"@config-plugins/react-native-branch",
|
||||
`Couldn't modify proguard-rules.pro - ${e}.`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function addGetAutoInstanceIfNeeded(
|
||||
mainApplication: string,
|
||||
isJava: boolean
|
||||
@@ -273,22 +199,5 @@ export const withBranchAndroid: ConfigPlugin<{ apiKey?: string }> = (
|
||||
return config;
|
||||
});
|
||||
|
||||
// Update proguard rules directly
|
||||
config = withDangerousMod(config, [
|
||||
"android",
|
||||
async (config) => {
|
||||
await editProguardRules(config, (proguardRules) => {
|
||||
return appendContents({
|
||||
tag: "react-native-branch-dont-warn",
|
||||
src: proguardRules,
|
||||
newSrc: ["-dontwarn io.branch.**"].join("\n"),
|
||||
comment: "#",
|
||||
}).contents;
|
||||
});
|
||||
|
||||
return config;
|
||||
},
|
||||
]);
|
||||
|
||||
return config;
|
||||
};
|
||||
Reference in new issue
Block a user