Skip to content

fix(javascript): unify package resolution and resolve exact exports subpaths - #1424

Merged
morluto merged 3 commits into
morluto:mainfrom
AWUQAQ:fix/javascript-resolve-package-export-subpaths
Oct 10, 2026
Merged

morluto merged 3 commits into
morluto:mainfrom
AWUQAQ:fix/javascript-resolve-package-export-subpaths

Conversation

@AWUQAQ

@AWUQAQ AWUQAQ commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

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/parser remained 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 directory main entrypoints, 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

  • Unify package-root and subpath metadata/exports resolution. Remove duplicate parsers, selectors, mode flags, conversion wrappers, and the separate subpath fallback implementation; no compatibility shims remain.
  • Detect package directories from same-container inventory descendants, including packages without package.json.
  • Use shared file/directory lookup when exports are absent, including nested directory main fields. Nested directory exports do not control a filesystem lookup.
  • Resolve exports targets as exact URL paths without extension/index fallback. Exact matching excludes trailing-slash and wildcard keys.
  • Attach the original declaration and context once at the public resolution boundary.

Wildcard expansion and package-private # imports remain outside this change.

Contract and boundary impact

  • Semantic owner and earliest changed stage: application-layer static JavaScript artifact path resolution, before graph relationship and Electron role construction.
  • CLI and MCP/tool-catalog contract: existing schemas and tool names remain unchanged; both adapters expose corrected resolution and provenance.
  • Provider, bridge, target-format, or platform compatibility: static JavaScript artifacts; no native provider changes.
  • Evidence, artifact, provenance, or reconstruction contract: preserve source declaration/context, artifact digest, source range, and container identity through target selection.
  • Process execution, authorization, cleanup, or containment impact: production resolution reads the inventoried map only; artifact-root confinement remains enforced.
  • Generated metadata, package, or installation impact: none.

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 4dcf30c87 exhibited all four additional failures; the added fixtures exercise their observable outcomes.

  • User-visible CLI/MCP output: exported/parser resolves to node_modules/exported/parser.cjs; preload observations retain declared_path: "exported/parser" and resolution_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

  • Breaking changes or migration steps: none; the existing public result contract is retained. Superseded internal implementations are removed.
  • Real Hopper/Ghidra, browser, or OS coverage: macOS CLI/MCP and Node resolver validation; native providers and browser runtime execution are outside this static analysis change.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: caller input and source evidence remain intact; same-container checks and path confinement are preserved.

Review checklist

  • This PR addresses a concrete problem or an agreed enhancement.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

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 '?'.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@CassieFox23

CassieFox23 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: This fixes the exports half of #1365. Every exact subpath I tried now matches Node. The # imports half is still open. The PR says so too. Wildcards are not covered either.

Tests

The changed test file passes on three Node versions.

Run Node 22.23.1 Node 24.18.0 Node 26.11.1
Head tests on head 52/52 52/52 52/52
Head tests on base 11 fail, 41 pass
Base tests on base 42/42

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:

Name Node Base Head
fixture/parser fixture/parser.cjs external fixture/parser.cjs
scoped pkg/feature lib/feature.cjs external lib/feature.cjs
#config config.cjs (app root) external external
root and relative names resolved same same

I also tried 15 edge cases. Conditions, nested conditions, arrays, null and bad targets all match Node now. Base left all of them external. Two small gaps remain, below. The full table is in a fold-out.

Two small gaps

Both come from REA's older file lists. They only hit packages with no exports.

  1. legacy/direct finds direct.cjs in REA. Node does not. Node's require never adds .cjs. Its import adds no extension at all.
  2. legacy/folder finds index.js for import in REA. Node refuses folder imports in ESM.

Base does the same for plain relative paths. ./helper finds helper.cjs there, and ./dir finds dir/index.js for import. So the PR reuses the old lists. The new legacy test expects fixture/direct to give direct.cjs. That bakes the wider list into this path. It is a note, not a blocker.

What stays open in #1365

  • # imports like #config. The PR leaves them for later.
  • Wildcard keys like ./*. The issue left these out on purpose.

Not run

Edit: results are in the follow-up. The suite and both checks pass, MCP matches the CLI, and module-sync matches Node. Still not run: macOS, Windows and the Windows failures.

  • The full test suite, check:fast, or docs checks.
  • The stdio MCP graph tool. The issue named it.
  • The module-sync condition.
  • macOS or Windows.
  • The four Windows failures the commit names. They live in other test files.

Thanks, AWUQAQ. The limit messages are clear. They name the keys a package declares, which helps a lot.

All edge cases

I 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 import I loaded the module, since import.meta.resolve skips the file check.

Then I added edge cases. Where two answers show, they are import / require. Base left every subpath external.

Name Node Head
cond/parser (conditions) parser.mjs / parser.cjs same
nested/feat (nested node) feat.mjs / feat.cjs same
arr/parser (array) parser.mjs / parser.cjs same
nul/internal (null) not exported external
sugar/parser (string exports) not exported external
pj/package.json not exported external
folder/features/x.cjs (./features/) not exported external
missing/parser not found not-found
escape/x (../ target) invalid target rejected
bad/parser (bad JSON) bad config unavailable
near/x from sub/ sub/node_modules/near/sub-x.cjs same
pat/util (./*) lib/util.cjs external
patext/util.js (./*.js) dist/util.js external
legacy/direct (no exports) not found direct.cjs
legacy/folder (no exports) ERR_UNSUPPORTED_DIR_IMPORT / index.js index.js
Commands
git -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 require.resolve, require, import.meta.resolve and import().

Extra rows

Node's own .. handling, checked both ways. Base left both external.

Name Node Head
legacy/../cond/parser.cjs cond/parser.cjs cond/parser.cjs
cond/../legacy/direct.cjs not exported external

Relative control on base and head, no packages:

Name Node require Node import Base and head
./helper not found not found helper.cjs
./dir dir/index.js ERR_UNSUPPORTED_DIR_IMPORT dir/index.js
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 (builds and CLI runs on 24.18.0)
  • Head / base: 4dcf30c8 / 6875d4a6 (merge base; main is now 81cdafc1)

🤖 Generated with Claude Code (Opus 5.5) 🦊

@AWUQAQ

AWUQAQ commented Oct 10, 2026

Copy link
Copy Markdown
Contributor Author

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 (EXTENSIONS plus index candidates) so subpaths behave the same as relative declarations and bare package names already do on base — ./helper → helper.cjs and ./dir → dir/index.js, as your relative control shows. I kept that consistency rather than narrowing only this path: loader-exact extension and directory rules differ between import and require and would be a cross-cutting change to the shared lists affecting every context. If maintainers prefer Node-exact legacy semantics, I'm happy to take that as a separate increment.

The # alias increment and wildcards stay out of scope here as noted.

@CassieFox23

CassieFox23 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: On 4dcf30c8, the full suite, check:fast and the docs check all pass. The stdio MCP tool gives the same graph as the CLI on six fixtures. The module-sync picks match Node 22, 24 and 26.

Checks

All on Node 24.18.0, from a clone at the PR head.

Check Result
Full suite (vitest run) 6,301 pass, 89 skip, 0 fail
npm run check:fast pass
npm run docs:check pass

The 11 skipped files are all macOS-only.

MCP and CLI

I started my own stdio server from this build. Then I called analyze_javascript_application on six fixtures. These are the five from my last comment, plus one new one.

Fixture Links Same rows Same graph
#1365 require 6 yes yes
#1365 import 6 yes yes
Edge cases 40 yes yes
.. names 4 yes yes
Relative control 4 yes yes
New edge cases 28 yes yes

"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 format. I passed directory to MCP and let the CLI pick.

module-sync

Node turns this condition on by default in 22, 24 and 26. It drops out with --no-experimental-require-module. Both answers show as import / require when they differ.

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.
  • format:check, knip, jscpd and the verify:* scripts. format:check, knip and jscpd ran on main, exit 0. Of the verify:* scripts only verify:architecture-guards and verify:module-boundaries ran, 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 client

The 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 now 4e3d3354)

🤖 Generated with Claude Code (Opus 5.5) 🦊

@morluto morluto changed the title fix(javascript): resolve exact package export subpaths fix(javascript): unify package resolution and resolve exact exports subpaths Oct 10, 2026
@morluto
morluto merged commit 0e19db9 into morluto:main Oct 10, 2026
9 checks passed
darsrc pushed a commit to darsrc/rea that referenced this pull request Oct 10, 2026
…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]>
@morluto

morluto commented Oct 11, 2026

Copy link
Copy Markdown
Owner

Welcome to the project, @AWUQAQ. Resolving fixture/parser to its exact exported file makes the application's module graph easier to follow, and retaining the original import declaration keeps that trail inspectable. Thank you for working through both parts of this fix.

@AWUQAQ

AWUQAQ commented Oct 11, 2026

Copy link
Copy Markdown
Contributor Author

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 # package-private aliases half, following the boundary sketched in #1365 — happy to start on it whenever that's useful.

@CassieFox23

Copy link
Copy Markdown
Contributor

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 verify:* lanes are still not run for this check, and neither are macOS and Windows.

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

Check Result
npm run format:check Exit 0. 3,651 files pass.
npm run knip Exit 0.
npm run jscpd Exit 0. It reports 3.18 percent duplicated lines.
npm run verify:architecture-guards Exit 0. 1,439 source files pass.
npm run verify:module-boundaries Exit 0. 1,944 source files pass.
JavaScriptArtifactPathResolution.test.ts, Node 22.23.1 162 of 162 pass
Same file, Node 24.18.0 162 of 162 pass
Same file, Node 26.11.1 162 of 162 pass

The test file had 52 tests at the pull request head. It has 162 on main. I checked the file for doctor first. It has none.

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.

Commands
git -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, 26
Test setup

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: build Build, CI, packaging, and publishing bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Resolve exact package export subpaths in static application graphs

3 participants