react-native-app-auth
Version:
React Native bridge for AppAuth for supporting any OAuth 2 provider
102 lines (101 loc) • 4.27 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (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 () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.withXcodeBuildSettings = exports.withBridgingHeader = void 0;
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const config_plugins_1 = require("@expo/config-plugins");
const expo_version_1 = require("../expo-version");
const BRIDGING_HEADER_NAME = 'AppDelegate+RNAppAuth.h';
const BRIDGING_HEADER_CONTENT = '#import "RNAppAuthAuthorizationFlowManager.h"\n';
const findBridgingHeader = (dir) => {
const files = fs.readdirSync(dir);
// First check current directory
const headerInCurrentDir = files.find(f => f.endsWith('-Bridging-Header.h') || f.endsWith('.h'));
if (headerInCurrentDir) {
return path.join(dir, headerInCurrentDir);
}
// Then check subdirectories
for (const file of files) {
const fullPath = path.join(dir, file);
if (fs.statSync(fullPath).isDirectory()) {
const found = findBridgingHeader(fullPath);
if (found) {
return found;
}
}
}
return null;
};
const withBridgingHeader = rootConfig => {
if (!(0, expo_version_1.isExpo53OrLater)(rootConfig)) {
return rootConfig;
}
return (0, config_plugins_1.withDangerousMod)(rootConfig, [
'ios',
config => {
const iosPath = path.join(config.modRequest.projectRoot, 'ios');
// Search for existing bridging header in the project and subfolders
const existingHeaderPath = findBridgingHeader(iosPath);
const importLine = BRIDGING_HEADER_CONTENT;
let headerPath;
if (existingHeaderPath) {
headerPath = existingHeaderPath;
const content = fs.readFileSync(headerPath, 'utf8');
if (!content.includes(importLine)) {
fs.writeFileSync(headerPath, `${importLine}\n${content}`);
}
}
else {
// Default to new file if none found
headerPath = path.join(iosPath, BRIDGING_HEADER_NAME);
fs.writeFileSync(headerPath, `${importLine}\n`);
config._createdBridgingHeader = BRIDGING_HEADER_NAME;
}
return config;
},
]);
};
exports.withBridgingHeader = withBridgingHeader;
const withXcodeBuildSettings = rootConfig => (0, config_plugins_1.withXcodeProject)(rootConfig, config => {
const project = config.modResults;
const target = project.getFirstTarget().uuid;
const currentSetting = project.getBuildProperty('SWIFT_OBJC_BRIDGING_HEADER', target);
if (!currentSetting && config._createdBridgingHeader) {
project.addBuildProperty('SWIFT_OBJC_BRIDGING_HEADER', `$(SRCROOT)/${config._createdBridgingHeader}`, target);
}
return config;
});
exports.withXcodeBuildSettings = withXcodeBuildSettings;