diff --git a/packages/create-react-native-library/CHANGELOG.md b/packages/create-react-native-library/CHANGELOG.md index 0802953b8..70b2a1da2 100644 --- a/packages/create-react-native-library/CHANGELOG.md +++ b/packages/create-react-native-library/CHANGELOG.md @@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [0.49.8](https://github.com/callstack/react-native-builder-bob/compare/create-react-native-library@0.49.7...create-react-native-library@0.49.8) (2025-04-11) + +### Bug Fixes + +* pass source flag to codegen cli when possible ([#815](https://github.com/callstack/react-native-builder-bob/issues/815)) ([7724e47](https://github.com/callstack/react-native-builder-bob/commit/7724e474d0b92d08a3a7b2946946114339acc19e)) - by @atlj + ## [0.49.7](https://github.com/callstack/react-native-builder-bob/compare/create-react-native-library@0.49.6...create-react-native-library@0.49.7) (2025-04-09) ### Bug Fixes diff --git a/packages/create-react-native-library/package.json b/packages/create-react-native-library/package.json index ca568a9af..ad0ede14c 100644 --- a/packages/create-react-native-library/package.json +++ b/packages/create-react-native-library/package.json @@ -1,6 +1,6 @@ { "name": "create-react-native-library", - "version": "0.49.7", + "version": "0.49.8", "description": "CLI to scaffold React Native libraries", "keywords": [ "react-native", diff --git a/packages/create-react-native-library/src/index.ts b/packages/create-react-native-library/src/index.ts index 322d910a3..cbe912091 100644 --- a/packages/create-react-native-library/src/index.ts +++ b/packages/create-react-native-library/src/index.ts @@ -20,7 +20,7 @@ import { createInitialGitCommit } from './utils/initialCommit'; import { prompt } from './utils/prompt'; import { resolveNpmPackageVersion } from './utils/resolveNpmPackageVersion'; -const FALLBACK_BOB_VERSION = '0.40.4'; +const FALLBACK_BOB_VERSION = '0.40.5'; const FALLBACK_NITRO_MODULES_VERSION = '0.22.1'; const SUPPORTED_REACT_NATIVE_VERSION = '0.78.2'; diff --git a/packages/react-native-builder-bob/CHANGELOG.md b/packages/react-native-builder-bob/CHANGELOG.md index 828fa6f7f..566d0bff6 100644 --- a/packages/react-native-builder-bob/CHANGELOG.md +++ b/packages/react-native-builder-bob/CHANGELOG.md @@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [0.40.6](https://github.com/callstack/react-native-builder-bob/compare/react-native-builder-bob@0.40.5...react-native-builder-bob@0.40.6) (2025-04-11) + +### Bug Fixes + +* pass source flag to codegen cli when possible ([#815](https://github.com/callstack/react-native-builder-bob/issues/815)) ([7724e47](https://github.com/callstack/react-native-builder-bob/commit/7724e474d0b92d08a3a7b2946946114339acc19e)) - by @atlj + ## [0.40.5](https://github.com/callstack/react-native-builder-bob/compare/react-native-builder-bob@0.40.4...react-native-builder-bob@0.40.5) (2025-04-09) ### Bug Fixes diff --git a/packages/react-native-builder-bob/package.json b/packages/react-native-builder-bob/package.json index 38b3a2484..77d24aee3 100644 --- a/packages/react-native-builder-bob/package.json +++ b/packages/react-native-builder-bob/package.json @@ -1,6 +1,6 @@ { "name": "react-native-builder-bob", - "version": "0.40.5", + "version": "0.40.6", "description": "CLI to build JavaScript files for React Native libraries", "keywords": [ "react-native", diff --git a/packages/react-native-builder-bob/src/targets/codegen/index.ts b/packages/react-native-builder-bob/src/targets/codegen/index.ts index 315424733..88dd2f6d6 100644 --- a/packages/react-native-builder-bob/src/targets/codegen/index.ts +++ b/packages/react-native-builder-bob/src/targets/codegen/index.ts @@ -4,7 +4,10 @@ import { patchCodegenAndroidPackage } from './patches/patchCodegenAndroidPackage import fs from 'fs-extra'; import path from 'path'; import del from 'del'; -import { removeCodegenAppLevelCode } from './patches/removeCodegenAppLevelCode'; +import { + getCodegenCLISourceSupport, + removeCodegenAppLevelCode, +} from './patches/removeCodegenAppLevelCode'; import { spawn } from '../../utils/spawn'; type Options = Omit; @@ -42,12 +45,21 @@ export default async function build({ root, report }: Options) { } try { - await spawn('npx', ['@react-native-community/cli', 'codegen']); + const codegenCLISupportsSource = await getCodegenCLISourceSupport(); + + await spawn('npx', [ + '@react-native-community/cli', + 'codegen', + ...(codegenCLISupportsSource ? ['--source', 'library'] : []), + ]); if (codegenType === 'modules' || codegenType === 'all') { await patchCodegenAndroidPackage(root, packageJson, report); } - await removeCodegenAppLevelCode(root, packageJson); + + if (!codegenCLISupportsSource) { + await removeCodegenAppLevelCode(root, packageJson); + } report.success('Generated native code with codegen'); } catch (e: unknown) { diff --git a/packages/react-native-builder-bob/src/targets/codegen/patches/removeCodegenAppLevelCode.ts b/packages/react-native-builder-bob/src/targets/codegen/patches/removeCodegenAppLevelCode.ts index cf2f1594d..1154496a9 100644 --- a/packages/react-native-builder-bob/src/targets/codegen/patches/removeCodegenAppLevelCode.ts +++ b/packages/react-native-builder-bob/src/targets/codegen/patches/removeCodegenAppLevelCode.ts @@ -1,6 +1,7 @@ import fs from 'fs-extra'; import path from 'path'; import { CODEGEN_DOCS } from './patchCodegenAndroidPackage'; +import { spawn } from '../../../utils/spawn'; const FILES_TO_REMOVE = [ 'RCTAppDependencyProvider.h', @@ -68,3 +69,18 @@ export async function removeCodegenAppLevelCode( 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. + */ +export async function getCodegenCLISourceSupport(): Promise { + const codegenCLIHelpOutput = await spawn('npx', [ + '@react-native-community/cli', + 'codegen', + '--help', + ]); + return codegenCLIHelpOutput.includes('--source'); +}