Skip to content

fix(javascript): prefer package entrypoints over directory indexes - #575

Merged
morluto merged 1 commit into
morluto:mainfrom
kaoru0822-kitauji:fix/javascript-package-entrypoint-precedence
Oct 5, 2026
Merged

morluto merged 1 commit into
morluto:mainfrom
kaoru0822-kitauji:fix/javascript-package-entrypoint-precedence

Conversation

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Summary

Resolve declared JavaScript package entrypoints before directory index fallbacks. A package containing both main: "actual.cjs" and index.js currently produces a high-confidence graph edge to index.js, while Node resolves actual.cjs.

Found during a repository audit; no existing issue describes this ordering error.

Change and scope

  • Preserve direct-file priority, then inspect admissible package metadata before directory indexes.
  • Apply package exports to bare package requests; relative directory requests use legacy main/index loading.
  • Try a legacy main target's files/index first, then the package-root index fallback.
  • Preserve main: ".", missing legacy-main fallback, cycle diagnostics when no fallback exists, and artifact-container isolation.
  • Keep malformed or unreadable metadata explicit and avoid substituting an index for a missing exports target.

The existing recursive artifact-package lookup remains as a compatibility heuristic after legacy file/index fallbacks are exhausted. This is a bounded precedence correction; parity with Node is established for the fixture cases rather than claimed for every loader feature.

Problem and evidence

Real filesystem fixtures compare REA's reconstructed require edges against Node's require.resolve. The matrix covers declared main and exports, bare versus relative requests, self-directory main, missing legacy main, nested-directory indexes, root-index fallback, and cycles with a root index. The expected ordering follows the CommonJS loader algorithm.

On unchanged base 52bf709bcefb17ab07e1f9c47c5fadf5eca9bd4e, the final regression matrix has 12 failures and 29 passing controls. The corrected matrix passes. Independent re-review also verified relative missing exports and foreign-container behavior.

Contract and boundary impact

  • Semantic owner: application-layer artifact-local path resolution, shared by CLI and MCP graph construction.
  • Public schemas and tool inventory: unchanged; resolved target identities and derived Evidence change where the old target was wrong.
  • Provider/format/platform support: unchanged.
  • Evidence: preserves explicit unavailable/rejected outcomes and source citations; avoids confident edges to an unrelated index.
  • Execution, authorization, filesystem containment, and cleanup: unchanged; production resolution remains inert over the inventoried file map.
  • Generated metadata/package dependencies: unchanged.

Validation performed

  • Path-resolution unit tests plus 13 real-filesystem Node-oracle cases: 41 passed.
  • Those suites plus JavaScript artifact reconstruction: 52 passed.
  • Independent re-review: clear after adding relative/bare and nested-directory controls.
  • npm run check:ci: all seven static tasks passed.
  • npm run docs:check: passed; TypeDoc reported 202 existing warnings and no errors.
  • npm run verify:package: Linux package/install, CLI, and MCP verifier passed.
  • npm pack --dry-run --json: passed.
  • git diff --check: passed.
  • npm run check:pr: static stages passed; final rebased full suite reported 1,812 passed, 40 failed, and 1 skipped. All 40 failures in the same seven native bridge suites reproduce on unchanged 52bf709. This environment rejects Unix-domain socket listeners with EPERM, causing startup failures/timeouts. No tests or permission checks were relaxed.

Compatibility and release

No schema migration. Node v24.19.0 was used for the real resolution oracle; target modules were not executed for graph construction. No real Hopper/Ghidra verification was performed because native providers are unchanged. Broader conditional-export, package-subpath, and loader-equivalence work remains outside this change.

Review checklist

  • Focused Conventional Commit outcome.
  • Baseline regressions reproduced.
  • Node-backed positive and fallback controls.
  • Container and unavailable-outcome behavior preserved.
  • Independent findings addressed and re-reviewed.
  • Final checks performed on the current main base.

Copy link
Copy Markdown
Collaborator Author

@codex review

@morluto
morluto merged commit bb91abd into morluto:main Oct 5, 2026
19 checks passed
@morluto morluto added bug Something isn't working area: build Build, CI, packaging, and publishing labels Oct 14, 2026
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.

2 participants