Skip to content

fix(javascript): preserve bare package specifier suffixes - #1888

Closed
xu91102 wants to merge 1 commit into
morluto:mainfrom
xu91102:fix/esm-package-specifier-punctuation
Closed

xu91102 wants to merge 1 commit into
morluto:mainfrom
xu91102:fix/esm-package-specifier-punctuation

Conversation

@xu91102

@xu91102 xu91102 commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Bare ESM package specifiers lost their query/fragment spelling before exports lookup, inventing dependencies that Node rejects and missing explicitly exported punctuated keys. Preserve the full bare package request and apply URL normalization only to URL-like paths. Fixes #1883.

Problem and expected behavior

Given a package exporting only ./feature, Node rejects import "fixture/feature?cache=1" with ERR_PACKAGE_PATH_NOT_EXPORTED. REA previously reported node_modules/fixture/feature.cjs as resolved by silently looking up ./feature. The import now remains external/unresolved. An explicitly exported ./literal?cache=1 still resolves by that exact key.

Change and scope

Keep module-specifier text intact until bare package requests are distinguished from relative/file URLs. Strip query/fragment text in the relative ESM URL branch, retaining existing HTML, source-map URL, file URL, and CommonJS behavior. Package export selection itself is unchanged.

Contract and boundary impact

  • Semantic owner and earliest changed stage: application-layer module-specifier normalization before package resolution.
  • CLI and MCP/tool-catalog contract: unchanged schemas; both surfaces now report the correct target or unresolved status for the original request.
  • Provider, bridge, target-format, or platform compatibility: static JavaScript package analysis; no engine or bridge changes.
  • Evidence, artifact, provenance, or reconstruction contract: preserve the full caller specifier and avoid deriving a target from a different export key.
  • Process execution, authorization, cleanup, or containment impact: none in production; resolution still uses the existing artifact inventory.
  • Generated metadata, package, or installation impact: none.

Evidence and regression coverage

  • New compiled CLI and stdio MCP acceptance coverage checks unexported query and fragment requests plus an explicitly exported query-bearing subpath.

  • Separate real Node subprocesses resolve each request against the same on-disk package: the unexported requests return ERR_PACKAGE_PATH_NOT_EXPORTED, and the explicit full key loads its intended module.

  • On base fb94d9dde0ccda83ae520ac6fb22b1d283562cf3, both new surface tests failed because REA invented the ./feature target. Both pass after the fix.

  • A separate actual CLI reproduction produced the wrong resolved target twice while direct Node execution rejected the request.

  • Existing relative ESM, file URL, CommonJS, conditional exports, and package-subpath tests pass.

  • Review: self-review of the fixed base, complete patch, and new acceptance test; no actionable findings.

  • Remaining proof gaps: full deterministic coverage is left to upstream CI; real native engines and browser runtime are outside this static resolution change.

  • 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

All local checks used Node 24.18.0 / npm 11.16.0 on macOS 27.0.1 arm64.

  • npm run test:focused -- tests/acceptance/applications/packageSpecifierSuffixCli.test.ts before the production fix — 2 expected regression failures.
  • npm run test:focused -- tests/acceptance/applications/packageSpecifierSuffixCli.test.ts tests/acceptance/applications/packageSubpathsCli.test.ts tests/boundary/javascript/packageConditionalExports.test.ts src/application/javascript/JavaScriptModuleSpecifierPaths.test.ts src/application/javascript/JavaScriptArtifactPathResolution.test.ts — 181 tests passed across 5 files, including freshly built CLI/MCP workflows.
  • npm run check — passed typecheck, lint, formatting, knip, metadata, module boundaries, and architecture guards; 758 lint warnings, zero errors.
  • npm run verify:test-discovery — all 843 test files discovered exactly once.
  • git diff --check — passed.
  • Upstream CI — awaiting maintainer approval for this fork contribution (action_required); no CI jobs have executed. This is not counted as a passing check.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: actual Node resolver and REA CLI/MCP on macOS; no native-provider or browser-runtime claim.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: artifact-root and container checks remain unchanged; no new process authority or external fetches.

Review checklist

  • This PR addresses a concrete reproduced problem and has one focused outcome.
  • The title follows Conventional Commits and the related issue is linked.
  • Tests cover observable behavior, runtime refusal, and exact export keys.
  • No owning docs, schemas, or generated metadata require changes.
  • Representative CLI/MCP output and actual validation are recorded above.
  • The final diff contains no secrets, unrelated cleanup, or unsupported provider claims.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-11T15:57:03.272581Z f11cc3d PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f11cc3dc05

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@@ -154,7 +152,7 @@ const contextualCandidate = (
if (!declared.startsWith(".") && !declared.startsWith("/"))
return bareModuleCandidate(input, declared);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Normalize suffixes before legacy package-path lookup

When an ES-module bare subpath has a query or fragment and the package has no exports (for example, import "fixture/feature.js?cache=1"), Node 24 still loads feature.js; only exports key selection treats the suffix as literal. Passing the full request into bareModuleCandidate also feeds it to the legacy branch at lines 294-298, which looks for an inventoried file literally named feature.js?cache=1 and reports not-found (or can select that wrong literal file). Keep the full subpath through selectPackageExport, but strip its suffix before the no-exports filesystem lookup.

AGENTS.md reference: AGENTS.md:L21-L21

Useful? React with 👍 / 👎.

@morluto

morluto commented Oct 11, 2026

Copy link
Copy Markdown
Owner

Superseded by #1939, which retains your implementation commit, integrates the self-reference fix, and covers exact query-suffixed self exports plus unexported query/fragment keys through real Node and REA CLI/MCP workflows. #1883 remains linked for closure when the integration merges.

@morluto morluto closed this Oct 11, 2026
@morluto morluto added bug Something isn't working area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Oct 14, 2026
@morluto

morluto commented Oct 15, 2026

Copy link
Copy Markdown
Owner

@xu91102, thanks for showing how normalizing a bare package request could invent an export match that Node would reject. Package lookup now preserves the original suffix spelling and tests both unresolved and explicitly exported punctuated keys (main).

@morluto morluto added the area: build Build, CI, packaging, and publishing label Nov 23, 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 area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Bare ESM package specifiers lose query and fragment identity during exports lookup

2 participants