Repository navigation
rn: simplify src/ and bin/rn-cli.js - #387
Merged
Merged
Conversation
metro-options: merge inlineRequiresOf and forcedInliningOf into one inliningsOf, called once per config path, and drop the unreachable null branch from inliningOf. Combine errorsOf and joined into refusalOf. exports: narrow the targets in one pass, with no early-exit loop, and use iterator helpers instead of copying keys. metro-config: one walk loop for both arrays and nodes. resolve: smaller type checks and one join in resolveFile. Trim comments that restate the code; keep Metro notes and attributions. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01M1K1MwBwvz2fxsHzWHnvrM
rn-config.js: drop the modeOf() and sourceOf() helpers for inline expressions, check the underlying refusal before reading the flag, and cut the header and doc comments to their constraints. rn-bundle.js: one esmOf()/inliningOf() each, shared by withInlineRequires() and the no-Babel-config checks, instead of repeating the flagOf() calls; drop comments that restate the code. bin/rn-cli.js: translate() resolves --config against the cwd itself, and --bundle-encoding is always a string. cli.js: shorter projectBabel() comments. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01M1K1MwBwvz2fxsHzWHnvrM
….js, jsval.js assetRecord() picks the platform's files or else the generic ones by direct filtering instead of grouping under string keys; isAssetFile() checks each dot-suffix by splitting the name. lookups() shares one entry() between typed lookups and its API, calling the dirent's own method. load.js's lower() runs the plain transform once for both TSX-without-JSX and other loaders. An empty SVG unit is a table entry. Comments that restated code are gone, others are shorter; loadCached()'s if/else takes braces. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01M1K1MwBwvz2fxsHzWHnvrM
…liases, module-resolver, es-module, esm-imports, worklets
- babel-aliases: a plain alias key is matched by the plugin's own
`^key(/.*|)$` RegExp instead of a hand-rolled exec duck type;
aliasing() returns early when memoized.
- babel-switches: loaded() becomes a closure returning the plugin and
pushing its error, instead of a { plugin, error } pair threaded through
four parameters.
- babel-transformer: one loadPlugin() for the inlining and syntax-only
plugins; memoized() inlined; block-scoping lookup over one list; early
return for the fingerprint; brace style for if/else.
- babel-worker: any worker message marks it ready (READY comes first).
- module-resolver: aliasesOf() returns a predicate used directly by
filter()/some(); inline-requires reuses sameFor().
- es-module, esm-imports: TSModuleDeclaration joins the value
declarations; RegExp.escape replaces a local escaper; the seen Set
doubles as the export * work queue.
- Comments shortened where they restated code.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01M1K1MwBwvz2fxsHzWHnvrM
… of a getTransformOptions giving inlineRequires null The if/else pairs left without braces (metro-config.js, resolve.js) have them, and image-size.js's two single-statement ifs have none. Inline requires turned on (--inline-requires, rn.config.json's inlineRequires) where the Metro config's getTransformOptions gave inlineRequires null threw: typeof null is 'object', and its blockList was read. The blockList is now read through optional chaining, of none there as of true or false. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01M1K1MwBwvz2fxsHzWHnvrM
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
This simplifies
rn/src/andrn/bin/rn-cli.js. Behaviour is the same: exported names and signatures, every message text, and every generated output are unchanged, and no existing test had to change.src/plusbin/rn-cli.jsgoes from 3,834 to 3,738 lines. That's a modest cut, because most of the remaining comments explain why, for example Metro, Babel or react-native compatibility, and those are kept. Comments that only restated the code are removed and others are shortened.ifstatements follow one style:elsehas no braces:if (cond) statement;ifwith anelsealways has braces and line breaks.Code changes
Resolution and config
metro-options.js:inliningsOf(), sofallback()takes one fewer parameter;exports.js: targets are narrowed in one pass, and iterator helpers replace key arrays.metro-config.js: one walk loop covers both arrays and nodes.resolve.js: smaller type checks, and one path join inresolveFile().Command line
rn-config.js: themodeOf()andsourceOf()helpers are inlined.rn-bundle.js: oneesmOf()and oneinliningOf()replace repeatedflagOf()calls.bin/rn-cli.js:translate()resolves--configitself.Bundling
assets.js:assetRecord()filters an asset's files and takes the platform's own over the generic ones, instead of grouping under"name : platform"keys;isAssetFile()is two lines instead of a backwards character loop.build-host.js: a duplicated directory-entry lookup is now oneentry().load.js: the TSX case falls through to the plain transform.image-size.js: an SVG unit table replaces a nested ternary.Babel
babel-aliases.js: a plain alias key uses the same^key(/.*|)$RegExp the module-resolver plugin builds, instead of a hand-written matcher. Compared on about 1.1 million random keys and specifiers, they always matched.babel-switches.js:loaded()is a closure instead of returning{ plugin, error }pairs.babel-transformer.js:loadPlugin()replaces two copies of the same call;memoized()helper is inlined;module-resolver.js:aliasesOf()returns a match function, removing two duplicated loops.es-module.js: TypeScript namespaces join the other value declarations under one check.esm-imports.js: the built-inRegExp.escapereplaces a local helper, and one set serves as both the seen set and the queue forexport *.babel-worker.js: any message from a worker marks it ready. A worker always sendsreadybefore it can answer anything.Unchanged:
self-test.js,assets-dest.js,serializer.js,source-map.js,defaults.jsandbabelrc.jshad nothing worth removing.A bug found on the way
If a Metro config's
getTransformOptionsgaveinlineRequires: null, turning inline requires on with--inline-requiresor rn.config.json'sinlineRequiresthrew aTypeError, becausetypeof nullis'object'. TheblockListis now read with optional chaining. A new assertion inrn-bundle.test.jscovers it and fails without the fix.Checks
node --run lintpasses. All rn tests pass: 686, plus one skippedplutiltest that only runs on macOS.Generated by Claude Code