Repository navigation
fix(javascript): unify package resolution and resolve exact exports subpaths - #1424
Conversation
Bare module specifiers with subpaths now resolve against the selected package's exports map instead of staying external. An exact subpath key selects its target through the existing condition, array, and null semantics, and the selected target resolves as one exact file with no extension or index fallback. A declared exports map encapsulates every other subpath lookup, and packages without an exports map keep legacy file and directory-index resolution. Package-private import aliases remain external pending a separate increment (morluto#1365). Verification: npm run check:fast; focused and full src/application/javascript source tests on Windows; verify:test-discovery; docs:check. Four pre-existing failures in JavaScriptFileUrlPaths and JavaScriptModuleSpecifierPaths reproduce on unmodified main on Windows because their fixtures write file names containing '?'.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
TL;DR: This fixes the TestsThe changed test file passes on three Node versions.
So the new tests do catch the old code. Ten of the 11 failures are new tests. The last one is the old test. The PR changed its expected message. Does REA match Node?I checked each name in real Node 22, 24 and 26. They all agreed. The #1365 fixtures:
I also tried 15 edge cases. Conditions, nested conditions, arrays, Two small gapsBoth come from REA's older file lists. They only hit packages with no
Base does the same for plain relative paths. What stays open in #1365
Not runEdit: results are in the follow-up. The suite and both checks pass, MCP matches the CLI, and
Thanks, AWUQAQ. The limit messages are clear. They name the keys a package declares, which helps a lot. All edge casesI ran the CLI graph on base and head. Then I checked each name in real Node. Node 22, 24 and 26 gave the same answer every time. For Then I added edge cases. Where two answers show, they are
Commandsgit -C rea.git fetch origin pull/1424/head:refs/pr/1424
git -C rea.git archive 4dcf30c8 | tar -x -C head
git -C rea.git archive 6875d4a6 | tar -x -C base
npm ci && npm run compile
T=src/application/javascript/JavaScriptArtifactPathResolution.test.ts
node node_modules/vitest/vitest.mjs run $T
node scripts/rea.mjs analyze-javascript-application <fixture> --format json
jq -r '.normalized_result.graph.edges[]
| select(.properties.module_link_kind != null
and .properties.specifier != null)
| [.evidence.location.value.source, .properties.specifier,
.properties.resolved_path, .properties.resolution_status] | join("\t")'Node checks ran from a probe file inside each fixture. It used Extra rowsNode's own
Relative control on base and head, no packages:
Test setup
🤖 Generated with Claude Code (Opus 5.5) 🦊 |
|
Thanks for the thorough cross-check, and for confirming Node 22/24/26 parity on the exact-subpath half. On the two legacy gaps: agreed they are inherited, not introduced. The legacy subpath lookup deliberately reuses the shared candidate lists ( The |
|
TL;DR: On ChecksAll on Node 24.18.0, from a clone at the PR head.
The 11 skipped files are all macOS-only. MCP and CLII started my own stdio server from this build. Then I called
"Same graph" means the full JSON matched. That covers digests, source ranges and limits. I only stripped IDs, local paths and times. The one field left over was the input
|
| Name | Node | Head |
|---|---|---|
ms (sync first) |
index-sync.mjs |
same |
ms/first (sync first) |
first-sync.mjs |
same |
ms/after (sync last) |
after-import.mjs / after-require.cjs |
same |
ms/only (sync and default) |
only-sync.mjs |
same |
Node walks the keys in order, and so does the PR. It matches the default on all three. The flag case is not modeled, which seems right for a static graph.
Edit: I ran some of these on main at 40f73f6 (#3735). Results are in my new comment. The CLI and MCP on Node 22 and 26 ran on main in my #1365 record. Still not run: the other verify:* lanes, the base suite and macOS or Windows.
Still not run
- Base suite or base checks. Head passed, so I did not split.
CLI and MCP on Node 22 or 26. The Node checks ran on all three.Ran on main, in the [Feature] Resolve exact package export subpaths in static application graphs #1365 record.and theformat:check,knip,jscpdverify:*scripts.format:check,knipandjscpdran on main, exit 0. Of theverify:*scripts onlyverify:architecture-guardsandverify:module-boundariesran, exit 0. The real-tool lanes did not.- macOS or Windows.
Thanks, AWUQAQ, for the clear reply on the legacy lists. Keeping them shared makes sense to me.
Commands
git clone --no-checkout rea.git repo
git -C repo checkout --detach 4dcf30c8
npm ci && npm run build && npm run test:prepare
node node_modules/vitest/vitest.mjs run
npm run check:fast
npm run docs:check
node scripts/rea.mjs analyze-javascript-application <fixture> --format json
node scripts/rea.mjs mcp # stdio server for the MCP clientThe MCP client used @modelcontextprotocol/client 2.3.1 from the build. It sent { input_path, format: "directory" }. Rows came from the same jq query as last time.
Node and module-sync fixture
{
"exports": {
".": { "module-sync": "./index-sync.mjs", "default": "./index.cjs" },
"./first": {
"module-sync": "./first-sync.mjs",
"import": "./first-import.mjs",
"require": "./first-require.cjs",
"default": "./first-default.cjs"
},
"./after": {
"import": "./after-import.mjs",
"require": "./after-require.cjs",
"module-sync": "./after-sync.mjs",
"default": "./after-default.cjs"
},
"./only": { "module-sync": "./only-sync.mjs", "default": "./only-default.cjs" }
}
}With --no-experimental-require-module, Node gave these instead.
| Name | Node with the flag |
|---|---|
ms |
index.cjs |
ms/first |
first-import.mjs / first-require.cjs |
ms/after |
no change |
ms/only |
only-default.cjs |
process.features.require_module was true by default on all three.
Test setup
- Box: Nobara 44 (Fedora 44 base), Linux 7.2.9
- CPU: AMD Ryzen 9 5900X, 12 cores / 24 threads
- RAM: 32 GB DDR4-3600
- Node: 22.23.1, 24.18.0, 26.11.1 (build, suite, CLI and MCP on 24.18.0)
- Head / base:
4dcf30c8/6875d4a6(merge base; main is now4e3d3354)
🤖 Generated with Claude Code (Opus 5.5) 🦊
…ubpaths (morluto#1424) * fix(javascript): resolve exact package export subpaths Bare module specifiers with subpaths now resolve against the selected package's exports map instead of staying external. An exact subpath key selects its target through the existing condition, array, and null semantics, and the selected target resolves as one exact file with no extension or index fallback. A declared exports map encapsulates every other subpath lookup, and packages without an exports map keep legacy file and directory-index resolution. Package-private import aliases remain external pending a separate increment (morluto#1365). Verification: npm run check:fast; focused and full src/application/javascript source tests on Windows; verify:test-discovery; docs:check. Four pre-existing failures in JavaScriptFileUrlPaths and JavaScriptModuleSpecifierPaths reproduce on unmodified main on Windows because their fixtures write file names containing '?'. * fix(javascript): unify package path resolution --------- Co-authored-by: morluto <[email protected]>
|
Welcome to the project, @AWUQAQ. Resolving |
|
Thank you for the welcome! The well-scoped issue and the audit trail in the thread made this straightforward — a good one to land as a first contribution. I've opened #1838 to track the |
|
TL;DR: The format check, knip and jscpd pass on main. So do the two repo guard scripts. The changed test file passes on Node 22, 24 and 26. The real-tool This pull request merged as 0e19db9 (#1424) on 2026-10-10. This comment is a record. It runs items from my follow-up comment that I had not run. I ran them on main at 40f73f6 (#3735). Checks on main
The test file had 52 tests at the pull request head. It has 162 on main. I checked the file for The jscpd figure is the report, not a limit I set. I did not compare it with an older commit. Not run
Thanks, AWUQAQ, for the fix and for the clear reply on the legacy lists. Commandsgit -C rea.git archive 40f73f62b | tar -x -C main
npm ci && npm run build && npm run test:prepare # Node 24
npm run format:check
npm run knip
npm run jscpd
npm run verify:architecture-guards
npm run verify:module-boundaries
node scripts/run-development-tests.mjs focused \
src/application/javascript/JavaScriptArtifactPathResolution.test.ts # Node 22, 24, 26Test setup
🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊 |
Summary
Resolve exact package exports subpaths and preserve the consumer's original declaration and Evidence. Package roots and subpaths now share one metadata reader, exports selector, and directory lookup. Fixes #1365.
Problem and expected behavior
An import of
fixture/parserremained external even when the inventoried package exported./parser. The initial implementation also replaced the caller's declaration/context with the selected target, skipped nearer packages without metadata, ignored directorymainentrypoints, and accepted trailing-slash exports keys that Node refuses.The graph now selects the nearest same-container package, resolves its exact exported file or directory entrypoint as appropriate, and retains the original declaration and source provenance. Missing, blocked, and unexported targets carry explicit outcomes without falling through to another package.
Change and scope
package.json.mainfields. Nested directory exports do not control a filesystem lookup.Wildcard expansion and package-private
#imports remain outside this change.Contract and boundary impact
Evidence and regression coverage
Tests added or updated: exact exports coverage plus same/foreign-container metadata-less packages, sibling-prefix decoys, malformed/unavailable nested metadata, and cycles. New public CLI and stdio MCP tests compare package selection with Node and verify source digests, source ranges, and Electron preload identity.
Base reproduction: the reviewed PR head
4dcf30c87exhibited all four additional failures; the added fixtures exercise their observable outcomes.User-visible CLI/MCP output:
exported/parserresolves tonode_modules/exported/parser.cjs; preload observations retaindeclared_path: "exported/parser"andresolution_context: "module-specifier". Unexported/trailing-slash keys stay external; a missing selected export stays not-found.Remaining proof gaps: final validation ran on macOS with Node 24.18.0; Windows was not rerun. Large inventories can incur additional scanning for packages without metadata; no global cache was introduced.
Observed, derived, and inferred claims remain distinguishable.
Artifact identity, source provenance, and failed attempts remain preserved.
Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.
Validation performed
npm run test:local -- <all 18 JavaScript application test files>— 284 passed.npm run test:focused -- tests/boundary/javascript/packageConditionalExports.test.ts— 44 passed, including real Node import/require comparisons.npm run test:focused -- tests/acceptance/applications/packageSubpathsCli.test.ts— 2 passed through the packaged CLI and stdio MCP server.npm run check— passed typecheck, lint, formatting, knip, metadata, module boundaries, and architecture guards; lint reported 485 warnings and zero errors.npm run verify:test-discovery— 701 test files discovered exactly once.git diff --check— passed.Compatibility, safety, and release
Review checklist
type(scope): outcome.