Skip to content

Conversation

Copy link

Copilot AI commented Oct 19, 2025

  • Create repl-classes-with-new recipe directory structure
  • Create workflow.ts with transformation logic for REPLServer and Recoverable classes
  • Add support for dynamic imports (await import())
  • Create package.json for the recipe with correct author
  • Create README.md with consolidated examples
  • Create codemod.yaml configuration with correct author
  • Create workflow.yaml configuration
  • Create tsconfig.json for TypeScript compilation
  • Create test input files covering various scenarios (CommonJS, ESM, dynamic imports)
  • Create test expected files with correct transformations
  • Run tests to validate the codemod - all 4 tests pass
  • Run lint and type-check to ensure code quality - both pass
  • Verify the codemod works correctly on real examples - tested with all cases
  • Run CodeQL security check - no issues found
  • Update author attribution to "GitHub Copilot" for accurate representation

Implementation Summary

Successfully implemented a codemod for DEP0185 with all requested features:

✅ Handles both REPLServer and Recoverable classes
✅ Supports CommonJS imports (require("node:repl"))
✅ Supports ESM imports (import { REPLServer } from "node:repl")
✅ Supports dynamic imports (await import("node:repl"))
✅ Destructured imports work correctly
✅ Namespace imports work correctly
✅ Preserves constructor arguments
✅ Correctly skips cases that already have new
✅ Early return optimization when no imports present
✅ Updated README with consolidated example
✅ Author correctly attributed as "GitHub Copilot"

All tests pass and code quality checks pass.

Original prompt

This section details on the original issue you should resolve

<issue_title>feat: handle DEP0187 Instantiating node:repl classes without new</issue_title>
<issue_description># Instantiating node:repl classes without new

Description

Since instantiating node:repl classes without new is deprecated (DEP0185) and has reached Runtime status, we should provide a codemod to replace it.

  • The codemod should add new keyword when instantiating REPL classes without it.
  • The codemod should handle REPL-related classes that require proper instantiation.
  • The codemod should handle both CommonJS and ESM imports.
  • The codemod should preserve any constructor arguments and assignments.

Additional Information

Note that instantiating node:repl classes without the new qualifier was deprecated and reached Runtime status in Node.js v24.0.0. The deprecation was introduced because calling class constructors without new can lead to unexpected behavior and is not consistent with standard JavaScript class instantiation patterns. Instead of calling constructors directly, developers should use the new keyword when instantiating REPL classes.

The REPL classes were designed to be instantiated as proper class instances, and calling them as functions bypasses important initialization logic.

Examples

Example 1: Basic REPL server instantiation

Before:

const repl = require("node:repl");
const server = repl.REPLServer();

After:

const repl = require("node:repl");
const server = new repl.REPLServer();

Example 2: REPL server with options

Before:

const repl = require("node:repl");
const server = repl.REPLServer({
  prompt: "custom> ",
  input: process.stdin,
  output: process.stdout
});

After:

const repl = require("node:repl");
const server = new repl.REPLServer({
  prompt: "custom> ",
  input: process.stdin,
  output: process.stdout
});

Example 3: Destructured import

Before:

const { REPLServer } = require("node:repl");
const server = REPLServer({ prompt: ">>> " });

After:

const { REPLServer } = require("node:repl");
const server = new REPLServer({ prompt: ">>> " });

Example 4: ESM import usage

Before:

import { REPLServer } from "node:repl";
const server = REPLServer();

After:

import { REPLServer } from "node:repl";
const server = new REPLServer();

Example 5: Function parameter usage

Before:

const repl = require("node:repl");
function createREPL(options) {
  return repl.REPLServer(options);
}

After:

const repl = require("node:repl");
function createREPL(options) {
  return new repl.REPLServer(options);
}

Example 6: Variable assignment with configuration

Before:

const repl = require("node:repl");
const customREPL = repl.REPLServer({
  prompt: "node> ",
  useColors: true,
  useGlobal: false
});

After:

const repl = require("node:repl");
const customREPL = new repl.REPLServer({
  prompt: "node> ",
  useColors: true,
  useGlobal: false
});

Refs

<agent_instructions>take example of recipes/http-classes-with-new</agent_instructions>

Comments on the Issue (you are @copilot in this section)

Fixes #240


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Add codemod to handle instantiation of node:repl classes feat: Add codemod for DEP0185 - Instantiating node:repl classes without new Oct 19, 2025
Copilot finished work on behalf of AugustinMauroy October 19, 2025 20:36
Copilot AI requested a review from AugustinMauroy October 19, 2025 20:36
Copy link
Member

@AugustinMauroy AugustinMauroy left a comment

Choose a reason for hiding this comment

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

@copilot could you allow the codemod to support dynamic import

…ove README and update author

Co-authored-by: AugustinMauroy <[email protected]>
Copy link
Author

Copilot AI commented Oct 19, 2025

@copilot could you allow the codemod to support dynamic import

Added support for dynamic imports using getNodeImportCalls() from the codemod-utils. The codemod now handles await import("node:repl") patterns. Test file added: file-4.mjs. Commit: ccf3d35

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • us.i.posthog.com
    • Triggering command: codemod jssg run --language typescript --target test-all-cases.js --allow-dirty /home/REDACTED/work/userland-migrations/userland-migrations/recipes/repl-classes-with-new/src/workflow.ts (dns block)
    • Triggering command: codemod jssg run --language typescript --target test-dynamic.mjs --allow-dirty /home/REDACTED/work/userland-migrations/userland-migrations/recipes/repl-classes-with-new/src/workflow.ts (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from AugustinMauroy October 19, 2025 20:50
Copilot finished work on behalf of AugustinMauroy October 19, 2025 20:50
@AugustinMauroy AugustinMauroy marked this pull request as ready for review October 19, 2025 20:51
Copy link
Member

@AugustinMauroy AugustinMauroy left a comment

Choose a reason for hiding this comment

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

WOW that suprisingliy cool
LGMT

@AugustinMauroy AugustinMauroy added awaiting reviewer Author has responded and needs action from the reviewer dep:v24 Migration handles deprecation introduced in node v24 dep:EoL Migration handles deprecation introduced in an EoL version of node labels Oct 19, 2025
Copy link
Member

@avivkeller avivkeller left a comment

Choose a reason for hiding this comment

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

ai is crazy

@AugustinMauroy
Copy link
Member

ai is crazy

I just prompt "take example of recipes/http-classes-with-new"

Copy link
Member

@JakobJingleheimer JakobJingleheimer left a comment

Choose a reason for hiding this comment

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

Wow 😳 Aside from authorship, this looks fine

Copilot AI requested a review from AugustinMauroy October 23, 2025 10:46
Copilot finished work on behalf of AugustinMauroy October 23, 2025 10:46
@AugustinMauroy AugustinMauroy removed the awaiting reviewer Author has responded and needs action from the reviewer label Oct 23, 2025
@AugustinMauroy
Copy link
Member

need a fresh approval then we can merge and publish

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

Labels

dep:EoL Migration handles deprecation introduced in an EoL version of node dep:v24 Migration handles deprecation introduced in node v24

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: handle DEP0187 Instantiating node:repl classes without new

5 participants