[PR #4219] [MERGED] fix(importer): reach package-main selection for trailing-slash directory references #6132

Closed
opened 2026-10-31 01:12:07 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/4219
Author: @hemv-857
Created: 10/15/2026
Status: ✅ Merged
Merged: 10/24/2026
Merged by: @baron

Base: main ← Head: fix-4189-trailing-slash-package-main


📝 Commits (4)

  • d15e319 fix(importer): reach package-main selection for trailing-slash directory references
  • a66f236 Merge origin/main into fix-4189-trailing-slash-package-main
  • 323010f fix(importer): derive trailing-slash directory identity with path semantics
  • a8abfed fix(importer): normalize package-main targets with path semantics

📊 Changes

2 files changed (+27 additions, -4 deletions)

View changed files

📝 src/application/ReferenceSourceImportEntries.ts (+10 -4)
📝 tests/boundary/cli/referenceSourceDirectoryImports.test.ts (+17 -0)

📄 Description

What

Fixes #4189. resolveInternalSpecifier skipped package-main selection for trailing-slash directory references.

Why

posix.normalize(posix.join(dirname, "./sub/")) preserves the trailing slash, so normalized is sub/ while posix.dirname(match) is sub. The resolvedThroughIndex equality fails, selectPackageMain never runs, and require("./sub/") resolves to the directory index even when sub/package.json declares a different main. The plain spelling require("./sub") normalizes without the slash and does reach the manifest, so the two spellings disagree on the same directory.

How

  • Derive the directory identity used by resolvedThroughIndex with path semantics (posix.join(normalized, ".")), so a trailing-slash reference takes the identical package-main path as the plain spelling, including behind line terminators.
  • Normalize the package-main target the same way inside selectPackageMain: joining "." collapses the trailing separator run regardless of the preceding character, so a manifest like main: "lib\n/" selects the declared file exactly as Node does. The lookbehind regex that missed line terminators is gone from both stages.
  • Boundary rows pair each trailing-slash request with the existing manifest fixtures (./pkg/ → pkg/actual.js, ./stale/ → stale/index.js) and are validated against Node's own resolver inside the same table; a new row pins the competing file/index case (main: "lib\n/" with both lib\n.js and lib\n/index.js present resolves to lib\n.js).

Tests

  • npm run test:focused -- tests/boundary/cli/referenceSourceDirectoryImports.test.ts — 1 passed (trailing-slash rows RED without the fix, GREEN with it)
  • Same suite after a8abfedc: manifest-newline row RED with the fixture alone (index selected), GREEN with the path-semantics normalization
  • 6 reference-source suites, 40 tests pass together; npm run check:fast — typecheck + lint pass

Author readiness

Human owner: @hemv-857

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Re-triggering the readiness check after GitHub's commit-association outage on 2026-10-19.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/4219 **Author:** [@hemv-857](https://github.com/hemv-857) **Created:** 10/15/2026 **Status:** ✅ Merged **Merged:** 10/24/2026 **Merged by:** [@baron](https://github.com/baron) **Base:** `main` ← **Head:** `fix-4189-trailing-slash-package-main` --- ### 📝 Commits (4) - [`d15e319`](https://github.com/morluto/rea/commit/d15e3190f6bd2759e0787e16509fe4f32a1cb607) fix(importer): reach package-main selection for trailing-slash directory references - [`a66f236`](https://github.com/morluto/rea/commit/a66f236157a127be1d226fb45cc81825fe955c08) Merge origin/main into fix-4189-trailing-slash-package-main - [`323010f`](https://github.com/morluto/rea/commit/323010fbd9b686e032063c5c48fe0049c4465f8f) fix(importer): derive trailing-slash directory identity with path semantics - [`a8abfed`](https://github.com/morluto/rea/commit/a8abfedcb81dc09b9ad63192a9b675b47c4b7377) fix(importer): normalize package-main targets with path semantics ### 📊 Changes **2 files changed** (+27 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `src/application/ReferenceSourceImportEntries.ts` (+10 -4) 📝 `tests/boundary/cli/referenceSourceDirectoryImports.test.ts` (+17 -0) </details> ### 📄 Description ## What Fixes #4189. `resolveInternalSpecifier` skipped package-main selection for trailing-slash directory references. ## Why `posix.normalize(posix.join(dirname, "./sub/"))` preserves the trailing slash, so `normalized` is `sub/` while `posix.dirname(match)` is `sub`. The `resolvedThroughIndex` equality fails, `selectPackageMain` never runs, and `require("./sub/")` resolves to the directory index even when `sub/package.json` declares a different `main`. The plain spelling `require("./sub")` normalizes without the slash and does reach the manifest, so the two spellings disagree on the same directory. ## How - Derive the directory identity used by `resolvedThroughIndex` with path semantics (`posix.join(normalized, ".")`), so a trailing-slash reference takes the identical package-main path as the plain spelling, including behind line terminators. - Normalize the package-main target the same way inside `selectPackageMain`: joining `"."` collapses the trailing separator run regardless of the preceding character, so a manifest like `main: "lib\n/"` selects the declared file exactly as Node does. The lookbehind regex that missed line terminators is gone from both stages. - Boundary rows pair each trailing-slash request with the existing manifest fixtures (`./pkg/` → `pkg/actual.js`, `./stale/` → `stale/index.js`) and are validated against Node's own resolver inside the same table; a new row pins the competing file/index case (`main: "lib\n/"` with both `lib\n.js` and `lib\n/index.js` present resolves to `lib\n.js`). ## Tests - `npm run test:focused -- tests/boundary/cli/referenceSourceDirectoryImports.test.ts` — 1 passed (trailing-slash rows RED without the fix, GREEN with it) - Same suite after a8abfedc: manifest-newline row RED with the fixture alone (index selected), GREEN with the path-semantics normalization - 6 reference-source suites, 40 tests pass together; `npm run check:fast` — typecheck + lint pass ## Author readiness Human owner: @hemv-857 - [x] I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work. - [x] I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps. - [x] I declare this PR ready for initial maintainer review. --- Re-triggering the readiness check after GitHub's commit-association outage on 2026-10-19. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 01:12:07 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#6132
No description provided.