Repository navigation
feat(javascript): inventory Expo Router require.context route keys - #10624
Conversation
Problem: Expo Router (Metro) web exports register file routes through a
bundled require.context map whose keys are literal route filenames such as
"./(app)/<section>/[id]/edit.tsx", "./_layout.tsx" and "./+not-found.tsx".
The route scan did not recognise that map, so the javascript-routes view of
analyze_javascript_application returned an empty inventory for these apps.
Fix: the route scan owner recognises Metro's context template,
Object.defineProperties({}, {"./file.tsx": getter, ...}). When every key is a
./-relative .js/.jsx/.ts/.tsx file and the map holds at least one _layout or
"+" file, each other key becomes a candidate with the new
expo-router-context-key mechanism, located at the key literal, with low
confidence and inferred derivation. The route-path owner converts keys with
Expo Router file conventions: groups (including group arrays) contribute no
segment, [id] -> :id, [...rest] -> :rest+, a trailing index names its
directory, platform extensions select the same route, and +api files keep
their API path. Layouts and other "+" files are not URL patterns.
Classification stays unknown; a bundled key does not establish platform,
navigator, server or reachability. A file map without a layout or "+" file
retains an interpretation unknown instead of becoming routes. Other
defineProperties calls are not read. The route inventory guide documents this.
Validation: new scan, inventory and CLI acceptance cases with a synthetic
Metro-style module. On the base, the scan and inventory cases failed with
empty candidates and routes; they pass now. Ran test:local for the route
scan, inventory, view, delivery-contract, result-budget and advertised
schema tests (378 passed), test:focused for
tests/acceptance/javascriptRoutesCli.test.ts (13 passed), docs:check and
check:fast. The conventions were checked against the published metro 0.88.0
context template and expo-router 58.0.31 matchers, not a real Expo export.
Refs morluto#7510
Codex Review Summary: ❌ FailedThis 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. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
[Medium impact] No blocking failure was found; two narrow cases can add false route candidates. FindingsFix with agent prompt### Issue 1
src/domain/javascript/javascriptRouteScan.ts:908-915
`#expoRouterContextSteps` checks filenames but never checks their property descriptors. `Object.defineProperties({}, {'./_layout.tsx': {value: 0}, './ordinary.tsx': {value: 1}})` therefore adds `/ordinary` as an Expo route, even though it contains no Metro getters. These false candidates can also admit unrelated path constants with the same root.
Require getter descriptors before accepting the map, and add an ordinary data-property map as a negative control.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
### Issue 2
src/domain/javascript/javascriptRouteScan.ts:661-668
The new branch identifies `Object.defineProperties` by spelling alone. A function parameter, import, or local variable named `Object` passes the same check. Its file-shaped arguments then become Expo routes even when that helper returns no such files, adding false routes to the inventory.
Use the existing `globalReferenceNamespace` check with `this.index.bindings` before queuing the map, and add a shadowed-`Object` control.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.SummaryAdds Expo Router filename candidates from Metro-style
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["Object.defineProperties call"] --> B{"Empty target and literal map?"}
B -- No --> X["Skip Expo detector"]
B -- Yes --> C{"Every key is a route-shaped filename?"}
C -- No --> X
C -- Yes --> D{"Layout or special file present?"}
D -- No --> U["Record interpretation unknown"]
D -- Yes --> E["Convert and admit one route key at a time"]
E --> F["Shared inventory retains source and key location"]
F --> G["CLI and MCP route views"]
Reviews (6) · Last reviewed commit: "Merge origin/main into claude/expo-route..." · Reviewed by Greptile |
Review follow-up for Expo Router route keys. The context-map reader converted every key and kept each derived path in a local array before emission. Only a location per property was charged, so a map with many long filenames retained route text beyond the fact budget, including text later discarded at capacity. The reader now establishes applicability in a first pass without keeping derived paths. A second pass converts and admits one key at a time through the budgeted fact owner. Emitted facts and their order are unchanged. The route inventory guide said Expo keys stay classified unknown, but the existing path-name heuristic still applies: ./login.tsx becomes /login, classified system by path-name-heuristic. The guide now says a bundled key adds no classification of its own. Tests: a budgeted case with 80 long keys admits a key-ordered prefix and stays within the limit. The route scan and inventory tests (355) and the routes CLI acceptance tests (13) pass. check:fast and docs:check pass.
Davmunrey
left a comment
There was a problem hiding this comment.
Status since opening:
- Greptile findings fixed in 2930bb8:
- route keys are admitted one at a time through the fact budget;
- the guide now says the path-name heuristic still classifies Expo keys (
./login.tsxbecomes/login,system).
- Validation: route scan and inventory tests (355), routes CLI acceptance (13), check:fast and docs:check.
- architecture-guards, format:check and check:ci:fast also pass with the branch merged into current main.
|
Ready to merge: full CI is green on this head, Greptile's latest review is 5/5 with no open threads, and it merges into main 42cab26 without conflicts. |
main consolidated the JavaScript route tests: the getter cases in the scanner tests became one test, and the Next filename delimiter cases in the inventory tests became two. Take those consolidated tests and keep the Expo Router tests this branch adds after them.
The documentation guide asks each feature for a spec.md, plan.md and tasks.md under docs/specs/. Add the record for reading Expo Router require.context keys in the JavaScript route inventory, and index it.
|
Added in 3ae22e0: |
Main removed the tracked planning records under docs/specs (morluto#12856), so this branch's Expo Router plan, spec and task files are dropped with it. Co-Authored-By: gensokyo-dev <[email protected]>
|
I merged current main into this branch ( |
gensokyo-dev
left a comment
There was a problem hiding this comment.
Verified on current main after merging it in: 228 route-scan, inventory and CLI acceptance tests pass, with lint, typecheck and docs checks clean. Classification follows Expo Router's matchers (groups, [id], [...rest], index, platform variants, +api; _layout and other + files produce no route), and a map counts as Expo routes only when every key is a route file and a convention file is present. The planning files under docs/specs were dropped, since main removed that directory. Fresh CI is green. Thanks.
| if ( | ||
| !this.#queue(property) || | ||
| !t.isObjectProperty(property) || | ||
| property.computed || | ||
| !t.isStringLiteral(property.key) | ||
| ) | ||
| return; | ||
| const file = classifyExpoRouterContextKey(property.key.value); |
There was a problem hiding this comment.
#expoRouterContextSteps checks filenames but never checks their property descriptors. Object.defineProperties({}, {'./_layout.tsx': {value: 0}, './ordinary.tsx': {value: 1}}) therefore adds /ordinary as an Expo route, even though it contains no Metro getters. These false candidates can also admit unrelated path constants with the same root.
Require getter descriptors before accepting the map, and add an ordinary data-property map as a negative control.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/javascript/javascriptRouteScan.ts
Line: 908-915
Comment:
**Data files become routes**
`#expoRouterContextSteps` checks filenames but never checks their property descriptors. `Object.defineProperties({}, {'./_layout.tsx': {value: 0}, './ordinary.tsx': {value: 1}})` therefore adds `/ordinary` as an Expo route, even though it contains no Metro getters. These false candidates can also admit unrelated path constants with the same root.
Require getter descriptors before accepting the map, and add an ordinary data-property map as a negative control.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| if (fullName === "Object.defineProperties") { | ||
| // Metro compiles each `require.context` into getters on a fresh object. | ||
| const [target, map] = node.arguments; | ||
| if ( | ||
| node.arguments.length === 2 && | ||
| t.isObjectExpression(target) && | ||
| target.properties.length === 0 && | ||
| t.isObjectExpression(map) && |
There was a problem hiding this comment.
Local helpers become Expo contexts
The new branch identifies Object.defineProperties by spelling alone. A function parameter, import, or local variable named Object passes the same check. Its file-shaped arguments then become Expo routes even when that helper returns no such files, adding false routes to the inventory.
Use the existing globalReferenceNamespace check with this.index.bindings before queuing the map, and add a shadowed-Object control.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/javascript/javascriptRouteScan.ts
Line: 661-668
Comment:
**Local helpers become Expo contexts**
The new branch identifies `Object.defineProperties` by spelling alone. A function parameter, import, or local variable named `Object` passes the same check. Its file-shaped arguments then become Expo routes even when that helper returns no such files, adding false routes to the inventory.
Use the existing `globalReferenceNamespace` check with `this.index.bindings` before queuing the map, and add a shadowed-`Object` control.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Summary
Refs #7510. This covers only the separate route gap, not the timeout. Expo Router (Metro) web exports register file routes in a bundled
require.contextmap,Object.defineProperties({}, {"./(app)/[id]/edit.tsx": …}). The route scan ignored that map, sojavascript-routescame back empty.Change and scope
JavaScriptRouteScanrecognises Metro's context template.classifyExpoRouterContextKeyapplies Expo Router conventions:(group)segments are dropped;[id]becomes:id;[...rest]becomes:rest+;index, platform extensions and+apifollow Expo's rules;_layoutand other+files produce no route../*.[jt]sx?and it has a_layoutor+file. Otherwise it records a single unknown.low/inferredand their classification isunknown. The mechanism enum gains one value,expo-router-context-key, which is an additive output change.Evidence and regression coverage
definePropertiescontrols stay negative.expo exportrun. The conventions were checked against the metro 0.88.0 and expo-router 58.0.31 sources.Reviewer notes
Object.definePropertiesbranch returns early even for maps it does not accept.Validation performed
npm run test:localon the route test files: 378 passed.npm run test:focused -- tests/acceptance/javascriptRoutesCli.test.ts: 13 passed.npm run docs:checkandnpm run check:fastpassed.Author readiness
Human owner: @Davmunrey
Before merge
type(scope): outcome.