Repository navigation
Bundle native builds with Re.Pack + OXC transform pipeline #99407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
roryabraham
merged 51 commits into
Expensify:main
from
callstack-internal:eliran/2733-dotlottie-hermes-parse
Sep 20, 2026
Merged
Changes from all commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
fa35b70
chore: add repack
OlimpiaZurek 07b2f00
fix: sign in not working under repack
OlimpiaZurek c90d413
fix: CI checks
OlimpiaZurek 2aaa1f6
chore: add OXC parser for mobile
OlimpiaZurek c1b3c1a
Merge branch 'main' into ft/repack-poc
OlimpiaZurek 4bc297b
Merge branch 'main' into ft/repack-poc
OlimpiaZurek 6073a74
fix config
OlimpiaZurek 7f2076e
fix profiling aliases
OlimpiaZurek ec46b09
fix: Hermes loop var capture
OlimpiaZurek 553baae
Merge branch 'main' into ft/repack-poc
OlimpiaZurek 10edc2e
Merge branch 'main' into ft/repack-poc
OlimpiaZurek e4de033
fix lint
OlimpiaZurek 9010cb7
Merge branch 'main' into ft/repack-poc
OlimpiaZurek f73a534
Merge branch 'main' into ft/repack-poc
OlimpiaZurek 7cafdb3
Merge branch 'main' into ft/repack-poc
OlimpiaZurek de7d01d
move rspack config
OlimpiaZurek b494849
fix(repack): enable production JS bundle minification
OlimpiaZurek b5ce702
Merge branch 'main' into ft/repack-poc
OlimpiaZurek 0534679
fix persistent cache and worklets crashes
OlimpiaZurek 6b73156
spell check fix
OlimpiaZurek abbbb11
fix ts
OlimpiaZurek caea815
fix: defer imports via inline-requires instead of SWC lazy mode
OlimpiaZurek 7fa2e2a
fix spellcheck
OlimpiaZurek 81bc961
Exclude dotlottie-react prebuilt bundle from babel-swc loader
elirangoshen 50ec572
Route non-babel node_modules through the OXC pipeline
elirangoshen 842920a
Shorten config comments
elirangoshen 8b41085
Merge remote-tracking branch 'upstream/main' into eliran/2733-dotlott…
elirangoshen 9f1f584
Remove comments that restate the code
elirangoshen d7aafb9
Merge remote-tracking branch 'upstream/main' into eliran/2733-dotlott…
elirangoshen dbfc762
Fix tsconfig formatting
elirangoshen 2b86082
Match Metro's @flow pragma gate in the Re.Pack babel lane
elirangoshen 6b89eff
Merge remote-tracking branch 'upstream/main' into eliran/2733-dotlott…
elirangoshen 4b193c6
Declare hermes-parser as a direct devDependency
elirangoshen b7bd9f5
Rewrite Re.Pack config comments as plain sentences
elirangoshen ecc1f5b
Select the native bundler with a BUNDLER env var
elirangoshen 26e7f45
Stamp Sentry Debug IDs into native release bundles
elirangoshen 75a92b1
Ignore the Sentry debug-id marker in cspell
elirangoshen 62c60ba
Route @fullstory/react-native through the babel lane
elirangoshen e4d06c4
Merge remote-tracking branch 'upstream/main' into eliran/2733-dotlott…
elirangoshen db3a016
Merge remote-tracking branch 'upstream/main' into eliran/2733-dotlott…
kacper-mikolajczak bd74fa7
fix: re-hydrate package-lock against main and restore patched action …
kacper-mikolajczak 3ffa1eb
fix: address Re.Pack dev-server review feedback
kacper-mikolajczak 1b89f9d
fix: clamp Re.Pack dev server progress so it never runs backwards
kacper-mikolajczak 5b03a65
fix double platform loaders
kacper-mikolajczak 10a63af
drop comment-only churn from the review-feedback commits
kacper-mikolajczak 1a8378d
docs: add details.md for the Re.Pack progress patch
kacper-mikolajczak 7b582b7
Merge remote-tracking branch 'upstream/main' into eliran/2733-dotlott…
kacper-mikolajczak d94e95e
Share one React Compiler config and compile native platforms on demand
kacper-mikolajczak d2c7b46
Merge remote-tracking branch 'upstream/main' into eliran/2733-dotlott…
elirangoshen e029c2c
Merge remote-tracking branch 'upstream/main' into eliran/2733-dotlott…
elirangoshen 45e1fb5
Restore --verbose on rock run:ios and run:android
elirangoshen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /** CJS implementation in `oxcReactCompilerConfig.js`, typed so the Rsbuild TS configs can import it. */ | ||
| declare function oxcReactCompilerConfig(overrides?: Record<string, unknown>): Record<string, unknown>; | ||
|
|
||
| export = oxcReactCompilerConfig; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /** | ||
| * The React Compiler options OXC compiles with, in one place: Re.Pack native, Rsbuild web, the Jest | ||
| * transform and the react-compiler checker. Each used to spell out its own. The native build ended up | ||
| * without two of them, so components carrying `react-hooks` suppressions shipped with no memoization | ||
| * while the web build and the checker memoized the same files. | ||
| */ | ||
| const BaseReactCompilerConfig = require('./reactCompilerConfig'); | ||
|
|
||
| /** | ||
| * `eslintSuppressionRules: []` matches the Babel/Metro lane. Without it OXC treats a `react-hooks` | ||
| * suppression as an opt-out of compilation. `isDev` is absent because OXC has no such option, so | ||
| * passing it changes nothing. | ||
| * | ||
| * Overrides are limited to `sources` (web compiles node_modules too) and `panicThreshold` (the checker | ||
| * needs diagnostics). Two lanes differing any other way is a bug. | ||
| * | ||
| * @param {Record<string, unknown>} [overrides] applied last | ||
| * @returns {Record<string, unknown>} | ||
| */ | ||
| function oxcReactCompilerConfig(overrides = {}) { | ||
| return { | ||
| ...BaseReactCompilerConfig, | ||
| eslintSuppressionRules: [], | ||
| panicThreshold: 'none', | ||
| ...overrides, | ||
| }; | ||
| } | ||
|
|
||
| module.exports = oxcReactCompilerConfig; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| /** | ||
| * Lowers ES modules to CommonJS and defers each `require()` to its first use site. This gives the | ||
| * same import-cycle tolerance Metro gets from `inlineRequires` (see metro.config.js), which this | ||
| * app relies on to boot. | ||
| * | ||
| * Uses Metro's own `inlineRequiresPlugin` rather than SWC's `module.lazy`. Both defer ~100% of | ||
| * imports, but SWC's lazy mode emits a memoizing wrapper function per imported module. That is | ||
| * about 103k extra functions here, worth about 7MB of Hermes bytecode. Inlining the require at | ||
| * the use site defers identically and emits no wrapper. | ||
| * | ||
| * Needed as a separate stage because OXC transpiles only and has no CJS lowering. | ||
| */ | ||
| import babel from '@babel/core'; | ||
| import remapping from '@jridgewell/remapping'; | ||
| import {rspack} from '@rspack/core'; | ||
| // CommonJS with lazy getters, so named ESM imports are not statically detectable. | ||
| import metroTransformPlugins from 'metro-transform-plugins'; | ||
|
|
||
| const {inlineRequiresPlugin} = metroTransformPlugins; | ||
|
|
||
| /** SWC's interop wrappers for `import x from` and `import * as x from`. */ | ||
| const INTEROP_HELPERS = new Set(['_interop_require_default', '_interop_require_wildcard']); | ||
|
|
||
| /** | ||
| * Extends inline-requires to SWC's interop-wrapped imports, which Metro's plugin alone cannot | ||
| * defer: it requires `arguments[0]` to be a string literal (SWC passes a `require()` call) and | ||
| * skips any call whose function is bound locally (SWC declares the helper in-file). Without this, | ||
| * default and namespace imports stay hoisted and eager. That is about half of all imports here, | ||
| * and exactly the cycle tolerance the loader exists to provide. | ||
| * | ||
| * Metro sidesteps the problem with a global `_$$_IMPORT_DEFAULT('x')` helper that resolves the | ||
| * module id at runtime. That is not portable to webpack, which must see a literal `require('x')` | ||
| * to add the module to the graph at all. So instead of hoisting the helper, we inline the whole | ||
| * initializer (the interop call and the literal require together) down to each use site. | ||
| * | ||
| * Repeating the interop call per use site is cheap: `_interop_require_wildcard` early-returns for | ||
| * `__esModule` objects and memoizes the rest in a WeakMap, and `_interop_require_default` is a | ||
| * single object literal on the non-ESM path. | ||
| */ | ||
| function inlineInteropRequiresPlugin({types: t}) { | ||
| const isInteropRequire = (node) => | ||
| t.isCallExpression(node) && | ||
| t.isIdentifier(node.callee) && | ||
| INTEROP_HELPERS.has(node.callee.name) && | ||
| node.arguments.length >= 1 && | ||
| t.isCallExpression(node.arguments[0]) && | ||
| t.isIdentifier(node.arguments[0].callee, {name: 'require'}) && | ||
| node.arguments[0].arguments.length === 1 && | ||
| t.isStringLiteral(node.arguments[0].arguments[0]); | ||
|
|
||
| return { | ||
| visitor: { | ||
| Program(programPath) { | ||
| for (const binding of Object.values(programPath.scope.bindings)) { | ||
| if (!binding.path.isVariableDeclarator() || !isInteropRequire(binding.path.node.init)) { | ||
| continue; | ||
| } | ||
| // Reassignment would make the inlined copies diverge from the original binding. | ||
| if (!binding.constant) { | ||
| continue; | ||
| } | ||
| // With no references there is nothing to inline into, and dropping the | ||
| // declaration would stop the module loading at all, since side-effect imports | ||
| // rely on it. Metro's plugin does remove these, but we stay conservative here. | ||
| if (binding.referencePaths.length === 0) { | ||
| continue; | ||
| } | ||
| for (const reference of binding.referencePaths) { | ||
| reference.replaceWith(t.cloneNode(binding.path.node.init, true)); | ||
| } | ||
| binding.path.remove(); | ||
| } | ||
| }, | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| export default async function cjsInlineRequiresLoader(source, inputSourceMap) { | ||
| const callback = this.async(); | ||
| try { | ||
| const options = this.getOptions() || {}; | ||
| // On prebuilt bundles SWC can emit a multi-source map, which remapping() below rejects. | ||
| // The node_modules rule passes `sourcemap: false` to skip maps entirely. | ||
| const sourceMaps = options.sourcemap !== undefined ? options.sourcemap : !!this.sourceMap; | ||
|
|
||
| // App source only needs block-scoping (Hermes shares one binding across loop iterations). | ||
| // node_modules also ship async generators, which Hermes cannot parse, so the node_modules | ||
| // rule opts into lowering those too. Everything else modern Hermes handles natively. | ||
| const envInclude = options.hermesLowering ? ['transform-block-scoping', 'transform-async-to-generator', 'transform-async-generator-functions'] : ['transform-block-scoping']; | ||
|
|
||
| const swcResult = await rspack.experiments.swc.transform(source, { | ||
| filename: this.resourcePath, | ||
| isModule: true, | ||
| env: { | ||
| targets: {node: 24}, | ||
| include: envInclude, | ||
| }, | ||
| jsc: options.hermesLowering | ||
| ? { | ||
| // Loose-mode class lowering, same as the babel config's {loose: true} plugins. | ||
| assumptions: {setPublicClassFields: true, privateFieldsAsProperties: true}, | ||
| } | ||
| : undefined, | ||
| module: {type: 'commonjs', lazy: false}, | ||
| sourceMaps, | ||
| inputSourceMap: inputSourceMap ? JSON.stringify(inputSourceMap) : undefined, | ||
| }); | ||
|
|
||
| const babelResult = await babel.transformAsync(swcResult.code, { | ||
| babelrc: false, | ||
| configFile: false, | ||
| filename: this.resourcePath, | ||
| // Interop-wrapped imports first, then Metro's plugin for the bare `require` form. | ||
| plugins: [inlineInteropRequiresPlugin, inlineRequiresPlugin], | ||
| sourceMaps, | ||
| // The minifier handles formatting; keeping newlines makes build output readable. | ||
| compact: false, | ||
| }); | ||
|
|
||
| if (!sourceMaps || !babelResult.map) { | ||
| callback(null, babelResult.code); | ||
| return; | ||
| } | ||
|
|
||
| // swcResult.map already folds in inputSourceMap (passed above), so composing the Babel map | ||
| // onto it is enough to keep stack traces pointing at original sources. | ||
| const map = swcResult.map ? remapping([babelResult.map, swcResult.map], () => null) : babelResult.map; | ||
| callback(null, babelResult.code, map); | ||
| } catch (error) { | ||
| callback(error); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| /** | ||
| * Replacement for `expo/virtual/env` when bundling natively with Re.Pack (see rspack.config.mjs). | ||
| * | ||
| * Expo's own module is `export const env = process.env` and relies on Expo's Metro integration to | ||
| * populate EXPO_PUBLIC_* values at runtime. That integration does not exist under Re.Pack, leaving | ||
| * them undefined. Most importantly, `expo/src/winter/runtime.native` checks EXPO_PUBLIC_USE_RN_FETCH | ||
| * and, when falsy, replaces global fetch with expo/fetch. That needs ReadableStream, absent in | ||
| * Hermes, and breaks every API request. Keep React Native's built-in fetch, same as Metro builds | ||
| * (see metro.config.js / babel.config.js). | ||
| */ | ||
| const env: Record<string, string> = { | ||
| EXPO_PUBLIC_USE_RN_FETCH: '1', | ||
| }; | ||
|
|
||
| // Must be a named export: expo's compiled code imports it as `import {env} from 'expo/virtual/env'`. | ||
| // eslint-disable-next-line import/prefer-default-export | ||
| export {env}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /** | ||
| * Parser for Re.Pack's babel lane, mirroring what `babel-plugin-syntax-hermes-parser` does for | ||
| * Metro: hermes-parser only for files that opt into Flow with an `@flow` pragma, @babel/parser for | ||
| * everything else. Re.Pack calls hermes-parser unconditionally, which is 4x slower across this | ||
| * lane and pathological (95s) on prebuilt minified single-line bundles. | ||
| * | ||
| * Wired in via the babel-swc-loader's `hermesParserPath` option, which Re.Pack imports with | ||
| * `importDefaultESM` and then calls as `parser.parse(source, options)`. | ||
| */ | ||
|
|
||
| import {parse as babelParse} from '@babel/parser'; | ||
| import * as hermesParser from 'hermes-parser'; | ||
|
|
||
| // Matches @react-native/babel-preset's `parseLangTypes: 'flow'` gate. | ||
| const FLOW_PRAGMA = /@flow/; | ||
|
|
||
| const BABEL_PARSER_PLUGINS = ['flow', 'jsx']; | ||
|
|
||
| export default { | ||
| parse(code, options) { | ||
| if (FLOW_PRAGMA.test(code)) { | ||
| return hermesParser.parse(code, options); | ||
| } | ||
| return babelParse(code, {sourceType: options?.sourceType ?? 'unambiguous', plugins: BABEL_PARSER_PLUGINS}); | ||
| }, | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.