react-native-builder-bob
Version:
CLI to build JavaScript files for React Native libraries
57 lines (54 loc) • 3.41 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getCodegenCLISourceSupport = getCodegenCLISourceSupport;
exports.removeCodegenAppLevelCode = removeCodegenAppLevelCode;
var _fsExtra = _interopRequireDefault(require("fs-extra"));
var _path = _interopRequireDefault(require("path"));
var _patchCodegenAndroidPackage = require("./patchCodegenAndroidPackage");
var _spawn = require("../../../utils/spawn");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const FILES_TO_REMOVE = ['RCTAppDependencyProvider.h', 'RCTAppDependencyProvider.mm', 'RCTModulesConformingToProtocolsProvider.h', 'RCTModulesConformingToProtocolsProvider.mm', 'RCTThirdPartyComponentsProvider.h', 'RCTThirdPartyComponentsProvider.mm', 'ReactAppDependencyProvider.podspec'];
/**
* With React Native 0.77, calling `@react-native-community/cli codegen` generates
* some app level source files such as `RCTAppDependencyProvider.mm`.
* These files are supposed to be only generated for apps
* but the cli misbehaves and generates them for all sorts of projects.
* You can find the relevant PR here: https://github.com/facebook/react-native/pull/47650
* This patch can be removed when this gets fixed in React Native.
*/
async function removeCodegenAppLevelCode(projectPath,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
packageJson) {
const codegenAndroidPathSetting = packageJson.codegenConfig?.outputDir?.android;
if (!codegenAndroidPathSetting) {
throw new Error(`Your package.json doesn't contain codegenConfig.outputDir.android. Please see ${_patchCodegenAndroidPackage.CODEGEN_DOCS}`);
}
const codegenAndroidPath = _path.default.resolve(projectPath, codegenAndroidPathSetting);
if (!(await _fsExtra.default.pathExists(codegenAndroidPath))) {
throw new Error(`The codegen android path defined in your package.json: ${codegenAndroidPath} doesnt' exist.`);
}
const codegenIosPathSetting = packageJson.codegenConfig?.outputDir?.ios;
if (!codegenIosPathSetting) {
throw new Error(`Your package.json doesn't contain codegenConfig.outputDir.ios. Please see ${_patchCodegenAndroidPackage.CODEGEN_DOCS}`);
}
const codegenIosPath = _path.default.resolve(projectPath, codegenIosPathSetting);
if (!(await _fsExtra.default.pathExists(codegenAndroidPath))) {
throw new Error(`The codegen iOS path defined in your package.json: ${codegenIosPathSetting} doesnt' exist.`);
}
const androidPromises = FILES_TO_REMOVE.map(async fileName => _fsExtra.default.rm(_path.default.join(codegenAndroidPath, fileName)));
const iosPromises = FILES_TO_REMOVE.map(async fileName => _fsExtra.default.rm(_path.default.join(codegenIosPath, fileName)));
await Promise.allSettled([...androidPromises, ...iosPromises]);
}
/**
* Codegen generates a different set of files if the target is an app instead.
* The following commit adds support for a --source argument to support calling codegen as a library:
* https://github.com/facebook/react-native/commit/98b8f178110472e5fed97de80766c03b0b5e988c
* Here we just check if the --source argument is supported.
*/
async function getCodegenCLISourceSupport() {
const codegenCLIHelpOutput = await (0, _spawn.spawn)('npx', ['@react-native-community/cli', 'codegen', '--help']);
return codegenCLIHelpOutput.includes('--source');
}
//# sourceMappingURL=removeCodegenAppLevelCode.js.map