-
-
Notifications
You must be signed in to change notification settings - Fork 28
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
newkeyword 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
Metadata
Metadata
Assignees
Labels
Type
Projects
Status