Skip to content

feat(DEP0192): migrate internal TLS imports to node:tls - #577

Open
vishalrajofficial wants to merge 2 commits into
nodejs:mainfrom
vishalrajofficial:feat-dep0192-tls-internal-modules
Open

vishalrajofficial wants to merge 2 commits into
nodejs:mainfrom
vishalrajofficial:feat-dep0192-tls-internal-modules

Conversation

@vishalrajofficial

Copy link
Copy Markdown

This PR implements a codemod for DEP0192 to migrate imports of internal Node.js TLS modules (_tls_common, _tls_wrap) to the public node:tls module.

Features

  • Migrates supported public exports for _tls_common (SecureContext, createSecureContext) and _tls_wrap (TLSSocket, Server, createServer, connect) to node:tls.
  • Supports both bare and node: prefixed specifiers (e.g. _tls_common and node:_tls_wrap).
  • 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:tls.
  • Skips internal-only exports (e.g. translatePeerCertificate), 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 #554

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

@AugustinMauroy AugustinMauroy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

seem good but huge point:

  1. the type part should be skipped or improved. to improve I invite you to create/add new utility to the utility part
  2. the logic same complicated maybe try to use more utility that has been already create
  3. there are serval kind() === which should be replaced by is()

Simplify workflow.ts by leveraging @nodejs/codemod-utils directly for import statements and require calls. Replace kind() === checks with .is(), remove verbose type annotations, handle CRLF and LF newlines dynamically, and update test fixtures.

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

Copy link
Copy Markdown
Author

Thanks for the thorough review! Updated:

  1. Replaced the custom require queries with getNodeRequireCalls from @nodejs/codemod-utils, handling member expressions and object patterns within the same loop.
  2. Removed the ad-hoc type import queries and relied directly on getNodeImportStatements.
  3. Inferred existingTlsImports type to keep it clean and lightweight.
  4. Replaced .kind() === with ast-grep .is().
  5. Handled newlines dynamically to ensure compatibility with Windows CRLF checkouts.

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

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(DEP0192): migrate internal TLS imports to node:tls

2 participants