Read optimizeGraph and treeShaking from the app config experiments, not only from EXPO_UNSTABLE_* variables
Yevhenii Kotyrlo
Graph optimization and tree shaking turn on only through EXPO_UNSTABLE_METRO_OPTIMIZE_GRAPH and EXPO_UNSTABLE_TREE_SHAKING (https://docs.expo.dev/guides/tree-shaking/). Gradle's createBundleReleaseJsAndAssets runs expo export:embed without either unless every shell, IDE and CI job that builds the app exports both, so the same app ships a shaken bundle from one build path and the whole graph from another.
I'd like the CLI to read both from the app config, as it reads experiments.reactCompiler, and experiments.reactServerFunctions with EXPO_UNSTABLE_SERVER_FUNCTIONS as its fallback:
{ "expo": { "experiments": { "optimizeGraph": true, "treeShaking": true } } }
with the variables still turning them on as they do now, and @expo/config-types declaring the two keys.
Today app.json's experiments change nothing. https://gist.github.com/YevheniiKotyrlo/d98c063ebd72232bafb2694bd5d5cfb0 bundles a two-file app with expo export:embed, once with only app.json's experiments and once with the variables (npm install && node run.mjs):
expo 58.0.24, @expo/cli 58.1.20, node v26.12.1, win32 10.0.26300
--- app.json experiments only: expo export:embed --platform android --dev false --minify true --entry-file index.js
exit status 0
UNUSED_EXPORT_MARKER in the bundle: yes
--- EXPO_UNSTABLE_* variables: expo export:embed --platform android --dev false --minify true --entry-file index.js EXPO_UNSTABLE_METRO_OPTIMIZE_GRAPH=1 EXPO_UNSTABLE_TREE_SHAKING=1
Experimental bundle optimization is enabled.
Experimental tree shaking is enabled.
exit status 0
UNUSED_EXPORT_MARKER in the bundle: no
SUMMARY: defect shows: with only app.json's experiments the CLI announces 0 of 2 experiments and the bundle keeps UNUSED_EXPORT_MARKER; with the variables it announces 2 of 2 and drops it
On main (b08d46ec), both flags still come only from the environment: