Skip to content

fix(javascript): resolve NodeNext emitted extensions in application analysis - #1820

Closed
BaaRai wants to merge 4 commits into
morluto:mainfrom
BaaRai:fix/analyze-nodenext-emitted-extensions
Closed

BaaRai wants to merge 4 commits into
morluto:mainfrom
BaaRai:fix/analyze-nodenext-emitted-extensions

Conversation

@BaaRai

@BaaRai BaaRai commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Summary

analyze-javascript-application reported ./dep.js as not-found whenever only dep.ts existed on disk, so TypeScript NodeNext source trees lost almost all internal import edges and feature traces stopped at the first import. The reference-source importer gained exactly this substitution through #755/#815; the application resolver (resolveCandidate) did not. This PR applies the same rule there, extracted into one shared helper used by both resolvers.

Problem and expected behavior

In a TypeScript ESM/NodeNext source tree, relative imports name the emitted file: import { dep } from "./dep.js" with only dep.ts present resolves under tsc --module NodeNext --moduleResolution NodeNext, as do ./x.mjs -> x.mts, ./x.cjs -> x.cts, ./B.js -> B.tsx, and the declaration counterparts (.d.ts, .d.mts, .d.cts). Application analysis reported every one as not-found with no unknowns entry, silently. This is #1811; the resolver gap was also flagged during the #1130 merge review.

Expected: these specifiers resolve to their TypeScript source counterparts, and every previously working shape keeps resolving.

Change and scope

  • New src/application/TypeScriptEmittedSourceCandidates.ts: for TypeScript-family callers (.ts, .tsx, .mts, .cts, including declaration callers, matching the tsc-verified behavior retained in fix(reference): resolve emitted extensions to TypeScript source #755), a candidate ending in an emitted extension substitutes its source counterparts (.js -> .ts/.tsx/.d.ts, .mjs -> .mts/.d.mts, .cjs -> .cts/.d.cts, .jsx -> .tsx/.d.ts). Explicit filenames only: no directory or index resolution. JavaScript callers get no fallback.
  • resolveCandidate appends these after the existing runtime candidates, so a present runtime file always wins and every other candidate order is unchanged.
  • ReferenceSourceImportEntries.resolveInternalSpecifier now calls the same helper instead of its inline copy. The logic is token-identical to the merged fix: integrate 24 reviewed browser/native/semantics corrections #815 rule (same caller gate, same suffix lists, same stem computation); its eight behavior tests are unchanged and pass.
  • Bare specifiers, package exports/entrypoint resolution, and HTML/URL contexts are untouched: the fallback lives only in the relative-candidate file lookup.

Contract and boundary impact

not applicable: resolver candidate list extension only; no schema, contract, or provider change. Module edges that previously carried resolution_status: "not-found" now carry resolved paths, which is the issue's requested outcome.

Evidence and regression coverage

  • Red-first unit coverage in JavaScriptArtifactPathResolution.test.ts: five emitted-name cases (.js->.ts, ./ui/Button.js->.tsx, .mjs->.mts, .cjs->.cts, .js->.tsx), three declaration-counterpart cases, plus four controls that already passed and must keep passing (runtime file wins, JavaScript-caller negative, no index substitution, extensionless resolution). 78/78 pass.
  • The fix: integrate 24 reviewed browser/native/semantics corrections #815 regression suite (referenceSourceImport) is untouched by behavior: its failures on Windows are the known symlink-EPERM environment artifacts, identical count on a clean main worktree.
  • End-to-end with the exact [Bug] TypeScript NodeNext imports such as ./dep.js stay not-found in analyze-javascript-application #1811 reproduction tree (Linux, node 24.19, compiled CLI): all five module_link_kind: "import" edges resolve - ./dep.js -> src/dep.ts, ./ui/Button.js -> src/ui/Button.tsx, ./cfg.mjs -> src/cfg.mts, ./legacy.cjs -> src/legacy.cts, ./util -> src/util.ts - and the graph reports zero unknown nodes.
  • check:fast passes; jscpd stays under its budget (the shared helper replaces the inline copy rather than adding duplication).

…nalysis

analyze-javascript-application reported ./dep.js as not-found whenever
only dep.ts existed, so TypeScript NodeNext source trees lost almost all
internal import edges. The reference-source importer gained exactly this
substitution in morluto#815; the application resolver did not.

Extract the rule into a shared helper (TypeScript callers only, emitted
.js/.mjs/.cjs/.jsx names substitute .ts/.tsx/.d.ts, .mts/.d.mts,
.cts/.d.cts, .tsx/.d.ts, explicit filenames only, present runtime files
always win) and apply it to both resolvers.

Fixes morluto#1811.
@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-11T17:36:06.891030Z 59d3152 New commits
ℹ️ 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: 11a31e0ec7

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

? [".tsx", ".d.ts"]
: [];
if (suffixes.length === 0) return [];
const stem = candidate.slice(0, -posix.extname(candidate).length);

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 Retain directories when substituting emitted dotfiles

For a nested TypeScript module importing the valid emitted dotfile ./.js, the candidate is src/.js, but posix.extname("src/.js") is empty, so slice(0, -0) discards the entire candidate and generates root-level .ts/.tsx/.d.ts candidates instead of src/.ts and its peers. The new application lookup can therefore leave this NodeNext edge unresolved or, when an unrelated root .ts exists in the same container, record an edge to the wrong file; strip the already-detected emitted suffix directly so the directory is preserved.

AGENTS.md reference: AGENTS.md:L11-L11

Useful? React with 👍 / 👎.

…le names

A candidate that is itself a dotfile name, such as src/.js, made
posix.extname return an empty extension, so the stem computation sliced
the whole candidate away and generated root-level source candidates.
Match each emitted suffix and strip it by matched length from one table,
which keeps the substitution within the candidate's directory and gives
the emitted and source suffixes a single shared source of truth.

@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: e0bee7b632

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

resolveFileCandidates(input, fileCandidates(candidate)) ??
resolveFileCandidates(input, [
...fileCandidates(candidate),
...typescriptEmittedSourceCandidates(input.sourcePath, candidate),

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 Restrict emitted-source candidates to module lookups

When analyzing a .ts file that creates new Worker("./worker.js") while only worker.ts is inventoried, the url-reference path reaches resolveCandidate and this unconditional candidate makes the worker look resolved to TypeScript even though URL loading does not perform NodeNext extension substitution. That fabricates a loads edge rather than preserving the missing runtime URL, so gate this fallback to module-specifier resolution (the HTML branch is already kept exact).

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

Useful? React with 👍 / 👎.

…sclosure

With NodeNext emitted-extension resolution, import "./util.js" inside
util.ts resolves back to the importing module itself, so it is disclosed
through the same self-import omission instead of a not-found edge.

@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: d382550a31

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

resolveFileCandidates(input, fileCandidates(candidate)) ??
resolveFileCandidates(input, [
...fileCandidates(candidate),
...typescriptEmittedSourceCandidates(input.sourcePath, candidate),

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 Do not substitute TypeScript sources for file-URL imports

When a .ts module imports file:///assets/dep.js and only assets/dep.ts is inventoried, contextualCandidate first converts that URL to assets/dep.js, after which this unconditional helper call resolves it to the TypeScript file. NodeNext skips absolute-URI specifiers and Node executes the URL's exact .js resource, so the graph now fabricates a resolved internal import; preserve whether the candidate came from fileUrlPath and bypass emitted-name substitution in that case.

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

Useful? React with 👍 / 👎.

…ule specifiers

Address review: NodeNext emitted-name substitution models TypeScript
module resolution, but the helper ran for every resolveCandidate lookup.
A url-reference such as new Worker("./worker.js") and an absolute
file:// module import load the exact resource named; resolving either
to a TypeScript counterpart fabricated a loads or module edge that
NodeNext never performs. The substitution now applies only to
module-specifier lookups whose declaration carries no scheme and is not
a file URL.
@morluto

morluto commented Oct 11, 2026

Copy link
Copy Markdown
Owner

Superseded by 1dfb933e4 and f8513a42d, now on main. The shared emitted-source helper and self-import behavior are retained, with public CLI coverage for multiple distinct source counterparts, runtime-file precedence, and Electron resource-path boundaries. Package/URL targets remain exact. Issue #1811 is closed as fixed; #1818 remains open for its distinct proposal.

@morluto morluto closed this Oct 11, 2026
@morluto morluto added bug Something isn't working area: domain Domain logic, errors, and pure functions labels Oct 14, 2026
@morluto

morluto commented Oct 15, 2026

Copy link
Copy Markdown
Owner

@BaaRai, thanks for identifying the gap between NodeNext emitted import suffixes and the TypeScript sources analysts actually have. The resolver now maps those emitted forms through a dedicated candidate owner and tests the application workflow (main).

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

Labels

area: domain Domain logic, errors, and pure functions bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants