diff --git a/packages/create-react-native-library/src/index.ts b/packages/create-react-native-library/src/index.ts index 5bb76e579..b9a1ff865 100644 --- a/packages/create-react-native-library/src/index.ts +++ b/packages/create-react-native-library/src/index.ts @@ -5,6 +5,7 @@ import dedent from 'dedent'; import kleur from 'kleur'; import yargs from 'yargs'; import ora from 'ora'; +import assert from 'node:assert'; import validateNpmPackage from 'validate-npm-package-name'; import githubUsername from 'github-username'; import prompts, { type PromptObject } from './utils/prompts'; @@ -790,8 +791,23 @@ async function create(_argv: yargs.Arguments) { examplePackageJson.dependencies['react-native']; } - if (arch !== 'legacy' && example === 'vanilla') { - addCodegenBuildScript(folder, options.project.name); + if (example === 'vanilla') { + // React Native doesn't provide the community CLI as a dependency. + // We have to get read the version from the example app and put to the root package json + const exampleCommunityCLIVersion = + examplePackageJson.devDependencies['@react-native-community/cli']; + assert( + exampleCommunityCLIVersion !== undefined, + "The generated example app doesn't have community CLI installed" + ); + + rootPackageJson.devDependencies = rootPackageJson.devDependencies || {}; + rootPackageJson.devDependencies['@react-native-community/cli'] = + exampleCommunityCLIVersion; + + if (arch !== 'legacy') { + addCodegenBuildScript(folder, options.project.name); + } } } diff --git a/packages/create-react-native-library/templates/common/$package.json b/packages/create-react-native-library/templates/common/$package.json index e93ddd723..a01a6ae94 100644 --- a/packages/create-react-native-library/templates/common/$package.json +++ b/packages/create-react-native-library/templates/common/$package.json @@ -72,6 +72,9 @@ "devDependencies": { "@commitlint/config-conventional": "^17.0.2", "@evilmartians/lefthook": "^1.5.0", +<% if (example === 'vanilla') { -%> + "@react-native-community/cli": "15.0.0-alpha.2", +<% } -%> "@react-native/eslint-config": "^0.73.1", "@release-it/conventional-changelog": "^5.0.0", "@types/jest": "^29.5.5", diff --git a/packages/react-native-builder-bob/src/targets/codegen.ts b/packages/react-native-builder-bob/src/targets/codegen.ts index cff50a9e3..ecb1c04b2 100644 --- a/packages/react-native-builder-bob/src/targets/codegen.ts +++ b/packages/react-native-builder-bob/src/targets/codegen.ts @@ -33,7 +33,7 @@ export default async function build({ root, report }: Options) { } try { - await spawn('npx', ['react-native', 'codegen'], { + await spawn('npx', ['@react-native-community/cli', 'codegen'], { stdio: 'ignore', });