Skip to content

feat(DEP0199): migrate internal HTTP imports to node:http - #576

Open
vishalrajofficial wants to merge 4 commits into
nodejs:mainfrom
vishalrajofficial:feat-dep0199-http-internal-modules
Open

vishalrajofficial wants to merge 4 commits into
nodejs:mainfrom
vishalrajofficial:feat-dep0199-http-internal-modules

Conversation

@vishalrajofficial

Copy link
Copy Markdown

This PR implements a codemod for DEP0199 to migrate legacy imports of internal Node.js HTTP modules (_http_*) to the public node:http module.

Features

  • Migrates supported public exports for _http_agent, _http_client, _http_incoming, _http_outgoing, and _http_server to node:http.
  • Supports both bare and node: prefixed specifiers (e.g. _http_agent and node:_http_agent).
  • Supports ESM named imports, CommonJS destructuring, direct property access, dynamic imports, and re-exports.
  • Preserves local aliases and handles TypeScript type imports.
  • Consolidates multiple compatible imports targeting node:http.
  • Skips internal-only exports (including _http_common), escaped namespace objects, and unknown properties, emitting warnings for manual review.
  • Includes 12 test fixtures covering supported, mixed, alias, dynamic import, TypeScript, and unresolved scenarios.

Fixes #556

Signed-off-by: Vishal Raj <9031842908.vk@gmail.com>
@AugustinMauroy

Copy link
Copy Markdown
Member

and rest it's seem good

Signed-off-by: Vishal Raj <9031842908.vk@gmail.com>
Use ast-grep string_fragment query instead of regex for unquoting string nodes. Simplify import and require handling by leveraging @nodejs/codemod-utils directly, replace kind() === checks with .is(), handle newlines dynamically, and update test fixtures.

Signed-off-by: Vishal Raj <9031842908.vk@gmail.com>
@vishalrajofficial

Copy link
Copy Markdown
Author

Thanks for the feedback! Updated:

  1. Replaced the getUnquotedText regex with ast-grep string_fragment query, which extracts the unquoted string content directly. Also updated the _http_common check to query string_fragment directly.
  2. Removed the ad-hoc type import queries and relied directly on getNodeImportStatements.
  3. Inferred existingHttpImports type to keep it clean and lightweight.
  4. Integrated member require expressions directly into the getNodeRequireCalls loop, removing custom AST queries.
  5. Replaced .kind() === with ast-grep .is().
  6. Handled newlines dynamically to ensure compatibility with Windows CRLF checkouts.

All 12 recipe tests, type checks, and linting pass cleanly.

…query and remove helper function

Signed-off-by: Vishal Raj <9031842908.vk@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(DEP0199): migrate internal HTTP imports to node:http

2 participants