Skip to content

Commit

Permalink
fix: vanilla example codegen fails (#665)
Browse files Browse the repository at this point in the history
### Summary

Fixes #662

### Test plan

1. Create a vanilla example library
2. Make sure `@react-native-community/cli` is added as a dependency
3. make sure `yarn prepare` doesn't throw
  • Loading branch information
atlj authored Oct 26, 2024
1 parent aa4c63b commit a9546fb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
20 changes: 18 additions & 2 deletions packages/create-react-native-library/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -790,8 +791,23 @@ async function create(_argv: yargs.Arguments<any>) {
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);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-builder-bob/src/targets/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});

Expand Down

0 comments on commit a9546fb

Please sign in to comment.