Skip to content

fix(48431): skip node_modules probes for URI-like module names - #65723

Open
Sumit G (smg99) wants to merge 2 commits into
microsoft:mainfrom
smg99:fix/48431-skip-node-colon-fs-probes
Open

Sumit G (smg99) wants to merge 2 commits into
microsoft:mainfrom
smg99:fix/48431-skip-node-colon-fs-probes

Conversation

@smg99

@smg99 Sumit G (smg99) commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #48431

Problem

Resolving names like node:fs historically probed the filesystem for paths such as node_modules/node:fs, node_modules/node:fs.d.ts, and @types/node:fs. resolveNodeLikeWorker already treated names containing : as absolute URIs and skipped node_modules, but other entry points still searched disk:

  • typings-location ATA (tryResolveFromTypingsLocation)
  • ResolvePackageDirectory
  • type-reference directive primary/secondary lookup

This PR only closes those accidental holes. It does not change the existing by-design absolute-URI skip inside resolveNodeLikeWorker.

Fix

  • Extract moduleNameLooksLikeAbsoluteURI (same : check as today)
  • Apply it at the remaining entry points, and once at the top of the node_modules ancestor walk / immediate loader for defense in depth
  • Keep Windows drive-letter paths on the relative-name path via the existing IsExternalModuleNameRelative checks

Before / after (FS URI-like probes)

Local fixture with /project/node_modules/node:fs and a typings location. Counts are filesystem lookups whose path contains node: (or http:).

Entry point Before After
ResolveModuleName("node:fs") 0 (already skipped by resolveNodeLikeWorker) 0
Typings ATA (TypingsLocation set) 6 (/typings/node_modules/node:fs*, @types/node:fs*) 0
ResolvePackageDirectory("node:fs") 1 + wrongly resolved to /project/node_modules/node:fs 0, unresolved
ResolveTypeReferenceDirective("node:fs") 6 + wrongly resolved to …/node:fs/index.d.ts 0, unresolved
Control: bare "fs" probes node_modules/fs / @types/fs (no URI-like paths) unchanged

Tests

TestNodeColonModuleSkipsNodeModulesProbes covers the rows above and asserts the absolute-URI skip trace where tracing is enabled.

Notes

Linux can host files named with :. Matching the existing resolveNodeLikeWorker policy, those names are not loaded from node_modules. Ambient @types/node declarations for node:fs are unchanged.

Linked issue #48431 currently has no milestone (Domain: Performance only). Per CONTRIBUTING, issues without an assigned milestone are not accepting PRs; this PR is labeled For Uncommitted Bug until triage places the issue in Backlog (or equivalent).

Checklist

  • There is an associated issue in the Backlog milestone (required) — blocked on triage of Don't search the file system for node: modules #48431
  • Code is up-to-date with the main branch
  • You've successfully run npx hereby test (focused Go module-resolution tests)
  • You've successfully run npx hereby lint
  • You've successfully run npx hereby check:format
  • There are new or updated tests validating the change

Copilot AI balanced review requested due to automatic review settings November 29, 2026 09:58
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Nov 29, 2026
@typescript-automation typescript-automation Bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Nov 29, 2026
Extend the existing absolute-URI skip beyond resolveNodeLikeWorker so
typings ATA, package-directory lookup, and type-reference resolution
also avoid probing paths like node_modules/node:fs.
@smg99
Sumit G (smg99) force-pushed the fix/48431-skip-node-colon-fs-probes branch from f12b404 to 0cdda3b Compare November 29, 2026 10:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The unconditional colon check rejects valid disk-path type references, causing existing declaration files to resolve as unresolved.

1 open issue
What changed in this PR

Addresses #48431 by extending the resolver’s existing URI-like module handling to avoid unnecessary filesystem probes for names such as node:fs.

Changes:

  • Extracts the existing colon check into a shared helper.
  • Adds early exits for typings-location, package-directory, type-reference, and node_modules lookups.
  • Adds probe-counting tests for URI-like names and a bare "fs" control.
File Description
tsc/​internal/​module/​util.go Adds the shared URI-like module-name helper.
tsc/​internal/​module/​resolver.go Applies URI guards to additional resolution paths.
tsc/​internal/​module/​node_colon_probe_test.go Tests skipped filesystem probes and URI-skip traces.

Review effort: Balanced

Comment thread tsc/internal/module/resolver.go Resolved
Exclude IsExternalModuleNameRelative names from the URI early-exit in
resolveTypeReferenceDirective so disk paths like ./foo:bar still resolve.

This branch has not been deployed

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

Labels

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

Don't search the file system for node: modules

2 participants