Skip to content

fix(create-app): preserve existing arg list when patching Podfile#703

Open
TomKalina wants to merge 1 commit into
callstackincubator:mainfrom
TomKalina:fix/expo-podfile-patch
Open

fix(create-app): preserve existing arg list when patching Podfile#703
TomKalina wants to merge 1 commit into
callstackincubator:mainfrom
TomKalina:fix/expo-podfile-patch

Conversation

@TomKalina
Copy link
Copy Markdown

Summary

Fixes #702npm create rock produces an invalid ios/Podfile on Expo prebuild projects.

updatePodfile in packages/create-app/src/lib/utils/initInExistingProject.ts ran a regex that matched config = use_native_modules! plus the whitespace after !, but not any existing argument list. That worked for the Community-CLI Podfile template (which calls use_native_modules! with no arguments), but Expo's prebuild template calls it with config_command as the argument. The patch then inserted Rock's array right before the existing (config_command), leaving two consecutive call expressions on the same line — invalid Ruby:

config = use_native_modules!(['npx', 'rock', 'config', '-p', 'ios'])(config_command)
                                                                    ^ unexpected '('

Every subsequent pod install (and therefore every rock run:ios) failed on Expo projects after npm create rock.

Fix

Extend the regex to also consume any existing parenthesized argument list, so it gets replaced in full:

- /(config\s*=\s*use_native_modules!)(\s*)/g,
- "$1(['npx', 'rock', 'config', '-p', 'ios'])$2",
+ /(config\s*=\s*use_native_modules!)(\s*\([^)]*\))?/g,
+ "$1(['npx', 'rock', 'config', '-p', 'ios'])",

On Community-CLI Podfiles the optional group matches nothing — behaviour is unchanged. On Expo prebuild Podfiles the existing (config_command) is now consumed and replaced cleanly.

Tests

Added four updatePodfile cases to packages/create-app/src/lib/utils/__tests__/initInExistingProject.test.ts:

updatePodfile is now exported, mirroring the existing updateAndroidBuildGradle export used by neighbouring tests.

 ✓ src/lib/utils/__tests__/initInExistingProject.test.ts (9 tests) 11ms

 Test Files  1 passed (1)
      Tests  9 passed (9)

Verified manually

In a fresh Expo SDK 55 / RN 0.83 project with prebuilt ios/:

  1. With the unpatched Rock 0.13.0: npm create rock → broken Podfile → pnpm rock run:ios fails with unexpected '(' in pod install.
  2. With this patch applied locally: npm create rock → Podfile line is config = use_native_modules!(['npx', 'rock', 'config', '-p', 'ios'])pod install proceeds normally.

Notes

  • The trailing-whitespace capture ($2 (\s*)$2) in the old regex was unnecessary — whitespace following the match was not being consumed by the regex anyway, so dropping the second capture has no behavioural impact beyond simpler substitution.
  • The Expo prebuild template has shipped use_native_modules!(config_command) for a long time; this fix unlocks migration for every Expo-CNG project, not just SDK 55.

`updatePodfile` ran a regex that matched `config = use_native_modules!`
plus the whitespace after `!`, but not any existing argument tuple.
That works for Community-CLI Podfile templates (call has no argument),
but Expo's prebuild template calls it with `config_command` as the
argument. The patch then inserted Rock's array right before the
existing `(config_command)`, leaving two consecutive call expressions
on the same line — invalid Ruby:

    config = use_native_modules!(['npx', 'rock', 'config', '-p', 'ios'])(config_command)
                                                                        ^ unexpected '('

Every subsequent `pod install` (and `rock run:ios`) failed on Expo
projects after `npm create rock`.

Fix: extend the regex to also consume any existing parenthesized
argument list, so it gets replaced in full. On Community-CLI Podfiles
the optional group matches nothing — behaviour is unchanged. On Expo
prebuild Podfiles the existing `(config_command)` is now consumed and
replaced cleanly.

Adds four `updatePodfile` test cases:
  - Community-CLI template (bare `use_native_modules!`)
  - Expo prebuild template (`use_native_modules!(config_command)`)
  - Idempotency on an already-patched Podfile
  - Missing Podfile is a no-op

The `updatePodfile` function is now exported for testability, mirroring
the existing `updateAndroidBuildGradle` export.

Fixes callstackincubator#702
@vercel
Copy link
Copy Markdown

vercel Bot commented May 11, 2026

Someone is attempting to deploy a commit to the Callstack Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown
Member

@thymikee thymikee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks you @TomKalina! 🙌🏼

@thymikee
Copy link
Copy Markdown
Member

Mind adding a changeset with "patch" change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

create-app: Podfile patch leaves invalid Ruby on Expo prebuild projects

2 participants