Skip to content

Conversation

@HubertBer
Copy link
Collaborator

@HubertBer HubertBer commented Aug 7, 2025

Setup for local modules, the most important changes are in:

Changes

  1. packages/@expo/cli/src/start/server/metro/MetroBundlerDevServer.ts. Added and running startModuleGenerationAsync function (it's run on yarn start) in which we:
  • regenerate .expo/localModules directory which mirrors the whole project and has a file.js with requireNativeModule("file") inside and file.nativeModule.d.ts with any type (for now) for each file.kt / file.swift file in the project
  • regenerate android/localModules directory, which also mirrors the project and instead just has symlinks to .kt files
  • setup watcher so that any changes to .kt and .swift files in the project are reflected in the mirror .expo/localModules and android/localModules directories.
  1. metro.config.js Here we make sure that import X from '**/file.nativeModule' resolve to the same relative path as from projectRoot but on the mirror ./expo/localModules directory, i.e. they now point to file.nativeModule.js which has requireNativeModule("file")
  2. tsconfig.json Here added proper include paths and root dirs:
  3. packages/@expo/metro-config/src/ExpoMetroConfig.ts. Here we add ts and swift extensions so that the watcher can watch them.
"compilerOptions": {
    "rootDirs": ["./", "./.expo/localModules"]
},

Thanks to them ts looks for types generated int ./expo/localModules

Expected behaviour

To see the changes cd to apps/sandbox add some .kt files for example 'test.kt', 'app/nested/test2.swift'. Now when you run yarn start you should see a new directory .expo/localModules and you should see:

.expo/localModules/

.expo/localModules/test.js
.expo/localModules/test.nativeModule.d.ts

.expo/localModules/app/nested/test2.js
.expo/localModules/app/nested/test2.nativeModule.d.ts                        

after running the yarn start, when the watcher is active you can change these files and see the .expo/localModules directory update accordingly. For example:

adding app/test3.kt should create 2 new files .expo/localModules/app/test3.js and .expo/localModules/app/test3.nativeModule.d.ts

removing 'app/nested/test2.swift' should result in removal of whole ./.expo/localModules/app/nested directory as it was the only file in there.

You can also try adding test4.kt and test4.swift, second add shouldn't add any new files as the test4.d.ts and test4.js files are the same (for now) for both kotlin and swift. Also if you remove one of them, the test4 files in ./expo/localModules should not be removed

@HubertBer HubertBer changed the base branch from local-modules to @HubertBer/local-modules August 8, 2025 09:13
@HubertBer HubertBer changed the base branch from @HubertBer/local-modules to local-modules August 8, 2025 09:20
@HubertBer HubertBer closed this Sep 5, 2025
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.

2 participants