@openrewrite/recipes-nodejs 0.55.0 → 0.56.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/index.d.ts.map +1 -1
  2. package/dist/index.js +8 -0
  3. package/dist/index.js.map +1 -1
  4. package/dist/migrate/child-process-channel.d.ts +9 -0
  5. package/dist/migrate/child-process-channel.d.ts.map +1 -0
  6. package/dist/migrate/child-process-channel.js +65 -0
  7. package/dist/migrate/child-process-channel.js.map +1 -0
  8. package/dist/migrate/hpagent/hpagent-support.d.ts.map +1 -1
  9. package/dist/migrate/hpagent/hpagent-support.js +5 -1
  10. package/dist/migrate/hpagent/hpagent-support.js.map +1 -1
  11. package/dist/migrate/process-exit-code.d.ts.map +1 -1
  12. package/dist/migrate/process-exit-code.js +16 -11
  13. package/dist/migrate/process-exit-code.js.map +1 -1
  14. package/dist/migrate/process-multiple-resolves.d.ts +9 -0
  15. package/dist/migrate/process-multiple-resolves.d.ts.map +1 -0
  16. package/dist/migrate/process-multiple-resolves.js +72 -0
  17. package/dist/migrate/process-multiple-resolves.js.map +1 -0
  18. package/dist/migrate/prop-types/remove-prop-types.d.ts +8 -4
  19. package/dist/migrate/prop-types/remove-prop-types.d.ts.map +1 -1
  20. package/dist/migrate/prop-types/remove-prop-types.js +62 -40
  21. package/dist/migrate/prop-types/remove-prop-types.js.map +1 -1
  22. package/dist/migrate/repl-classes-with-new.d.ts +9 -0
  23. package/dist/migrate/repl-classes-with-new.d.ts.map +1 -0
  24. package/dist/migrate/repl-classes-with-new.js +74 -0
  25. package/dist/migrate/repl-classes-with-new.js.map +1 -0
  26. package/dist/migrate/upgrade-node-22.d.ts.map +1 -1
  27. package/dist/migrate/upgrade-node-22.js +2 -0
  28. package/dist/migrate/upgrade-node-22.js.map +1 -1
  29. package/dist/migrate/upgrade-node-24.d.ts.map +1 -1
  30. package/dist/migrate/upgrade-node-24.js +8 -0
  31. package/dist/migrate/upgrade-node-24.js.map +1 -1
  32. package/dist/migrate/upgrade-node-26.d.ts.map +1 -1
  33. package/dist/migrate/upgrade-node-26.js +4 -0
  34. package/dist/migrate/upgrade-node-26.js.map +1 -1
  35. package/dist/migrate/util-type-checking.d.ts.map +1 -1
  36. package/dist/migrate/util-type-checking.js +24 -2
  37. package/dist/migrate/util-type-checking.js.map +1 -1
  38. package/dist/resources/advisories-npm.csv +151 -14
  39. package/package.json +2 -2
  40. package/src/index.ts +8 -0
  41. package/src/migrate/child-process-channel.ts +61 -0
  42. package/src/migrate/hpagent/hpagent-support.ts +6 -2
  43. package/src/migrate/process-exit-code.ts +19 -14
  44. package/src/migrate/process-multiple-resolves.ts +72 -0
  45. package/src/migrate/prop-types/remove-prop-types.ts +77 -45
  46. package/src/migrate/repl-classes-with-new.ts +66 -0
  47. package/src/migrate/upgrade-node-22.ts +2 -0
  48. package/src/migrate/upgrade-node-24.ts +8 -0
  49. package/src/migrate/upgrade-node-26.ts +4 -0
  50. package/src/migrate/util-type-checking.ts +32 -6
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  import {Column, Cursor, DataTable, emptyMarkers, randomId} from "@openrewrite/rewrite";
8
- import {emptySpace, isIdentifier, J, rightPadded, space} from "@openrewrite/rewrite/java";
8
+ import {emptySpace, isIdentifier, J, rightPadded, space, Type} from "@openrewrite/rewrite/java";
9
9
  import {bindingNames, declarationsOf, JS, scopeOf, walk} from "@openrewrite/rewrite/javascript";
10
10
  import {CodeStyle, DEFAULT_CODE_STYLE, indented} from "../code-style";
11
11
  import {bindingsOf, importModule, ModuleBindings, requiredModule, stringLiteral} from "../module-bindings";
@@ -495,7 +495,11 @@ export function builtinAgentType(local: string | undefined, specifier: string, p
495
495
  }
496
496
  const module = {
497
497
  kind: JS.Kind.LiteralType, id: randomId(), prefix: emptySpace, markers: emptyMarkers,
498
- literal: {kind: J.Kind.Literal, id: randomId(), prefix: emptySpace, markers: emptyMarkers, value: specifier, valueSource: `'${specifier}'`}
498
+ literal: {
499
+ kind: J.Kind.Literal, id: randomId(), prefix: emptySpace, markers: emptyMarkers, value: specifier,
500
+ valueSource: `'${specifier}'`, type: Type.Primitive.String
501
+ },
502
+ type: Type.Primitive.String
499
503
  };
500
504
  return {
501
505
  kind: JS.Kind.ImportType, id: randomId(), prefix, markers: emptyMarkers,
@@ -4,7 +4,7 @@
4
4
  * Moderne Proprietary. Only for use by Moderne customers under the terms of a commercial contract.
5
5
  */
6
6
  import {check, emptyMarkers, ExecutionContext, produceAsync, Recipe, TreeVisitor} from "@openrewrite/rewrite";
7
- import {JavaScriptVisitor, MethodMatcher, template, usesType} from "@openrewrite/rewrite/javascript";
7
+ import {JavaScriptVisitor, MethodMatcher, raw, template, usesType} from "@openrewrite/rewrite/javascript";
8
8
  import {Expression, J, TextComment, Type} from "@openrewrite/rewrite/java";
9
9
 
10
10
 
@@ -40,15 +40,23 @@ export class AvoidImplicitCoercionOfExitCode extends Recipe {
40
40
  return false;
41
41
  }
42
42
 
43
- private needsCoercion(expr: Expression): boolean {
44
- // For literals, check the valueSource to see if it's already a whole number
43
+ private isIntegerLiteral(expr: Expression): boolean {
44
+ if (expr.kind === J.Kind.Unary) {
45
+ const unary = expr as J.Unary;
46
+ const operator = unary.operator.element;
47
+ return (operator === J.Unary.Type.Negative || operator === J.Unary.Type.Positive) &&
48
+ this.isIntegerLiteral(unary.expression);
49
+ }
45
50
  if (expr.kind === J.Kind.Literal) {
46
- const literal = expr as J.Literal;
47
- const valueSource = literal.valueSource;
48
- // Integer literals (e.g., "1", "-3", "42") don't need coercion
49
- if (valueSource && /^-?\d+$/.test(valueSource)) {
50
- return false;
51
- }
51
+ const value = (expr as J.Literal).value;
52
+ return typeof value === 'number' && Number.isInteger(value);
53
+ }
54
+ return false;
55
+ }
56
+
57
+ private needsCoercion(expr: Expression): boolean {
58
+ if (this.isIntegerLiteral(expr)) {
59
+ return false;
52
60
  }
53
61
 
54
62
  const exprType = expr.type;
@@ -74,11 +82,8 @@ export class AvoidImplicitCoercionOfExitCode extends Recipe {
74
82
  if (expr.kind === J.Kind.Literal) {
75
83
  const literal = expr as J.Literal;
76
84
  if (literal && Number.isInteger(Number(literal.value))) {
77
- const numberValue = Number(literal.value);
78
- return (await produceAsync(literal, async draft => {
79
- draft.value = numberValue;
80
- draft.valueSource = (numberValue).toString();
81
- }))!;
85
+ // A template makes the number as the parser does: a number literal, under a unary minus when negative
86
+ return (await template`${raw(Number(literal.value).toString())}`.apply(expr, this.cursor))! as Expression;
82
87
  } else {
83
88
  const justZero = await template`0`.apply(expr, this.cursor) as J.MethodInvocation;
84
89
  return (await produceAsync(justZero, async draft => {
@@ -0,0 +1,72 @@
1
+ /*
2
+ * Copyright 2026 the original author or authors.
3
+ *
4
+ * Moderne Proprietary. Only for use by Moderne customers under the terms of a commercial contract.
5
+ */
6
+ import {check, ExecutionContext, Recipe, TreeVisitor} from "@openrewrite/rewrite";
7
+ import {JavaScriptVisitor, JS, usesType} from "@openrewrite/rewrite/javascript";
8
+ import {J, Type} from "@openrewrite/rewrite/java";
9
+
10
+ /** The `EventEmitter` methods that take an event name as their first argument. */
11
+ const LISTENER_METHODS = [
12
+ "on", "once", "addListener", "prependListener", "prependOnceListener",
13
+ "off", "removeListener", "removeAllListeners",
14
+ ];
15
+
16
+ const PROCESS_TYPE = "NodeJS.Process";
17
+
18
+ export class RemoveProcessMultipleResolves extends Recipe {
19
+ readonly name = "org.openrewrite.node.migrate.process.remove-multiple-resolves"
20
+ readonly displayName: string = "Remove `process.on('multipleResolves')` listeners";
21
+ readonly description: string = "The `'multipleResolves'` process event was removed in Node.js 25 (DEP0160) because it " +
22
+ "did not work with the V8 promise combinators, which left it of little use. Node.js offers no replacement and " +
23
+ "never emits the event, so registering a listener for it is dead code and the registration is removed. The " +
24
+ "handler itself is left in place, since it may be referenced elsewhere. Only a registration written as its own " +
25
+ "statement is removed; one whose result is used, such as a chained or assigned call, is left alone.";
26
+ readonly tags: string[] = ["DEP0160"];
27
+
28
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
29
+ return check(usesType(PROCESS_TYPE), new class extends JavaScriptVisitor<ExecutionContext> {
30
+
31
+ /**
32
+ * Whether the call registers (or removes) a listener on `process`. The receiver's type
33
+ * is what is checked, not the method's declaring type: `process` overrides `on()` and
34
+ * `once()` but inherits `off()`, `removeListener()` and `removeAllListeners()` from
35
+ * `EventEmitter`, which every other emitter declares too.
36
+ */
37
+ private isProcessListenerCall(m: J.MethodInvocation): boolean {
38
+ if (!LISTENER_METHODS.includes(m.name.simpleName)) {
39
+ return false;
40
+ }
41
+ const receiver = m.select?.element.type;
42
+ return receiver?.kind === Type.Kind.Class
43
+ && (receiver as Type.Class).fullyQualifiedName === PROCESS_TYPE;
44
+ }
45
+
46
+ /** Whether the first argument is the string `'multipleResolves'`. */
47
+ private isMultipleResolves(m: J.MethodInvocation): boolean {
48
+ const first = m.arguments.elements[0]?.element;
49
+ return first?.kind === J.Kind.Literal && (first as J.Literal).value === "multipleResolves";
50
+ }
51
+
52
+ /**
53
+ * Whether the call stands alone as a statement, so dropping it cannot strand an
54
+ * expression. A chained `process.on(..).on(..)` or an assigned result does not.
55
+ */
56
+ private isOwnStatement(): boolean {
57
+ const parent = this.cursor.parentTree()?.value as J | undefined;
58
+ return parent?.kind === J.Kind.Block || parent?.kind === JS.Kind.CompilationUnit;
59
+ }
60
+
61
+ protected async visitMethodInvocation(method: J.MethodInvocation, p: ExecutionContext): Promise<J | undefined> {
62
+ const m = await super.visitMethodInvocation(method, p) as J.MethodInvocation;
63
+
64
+ if (this.isProcessListenerCall(m) && this.isMultipleResolves(m) && this.isOwnStatement()) {
65
+ return undefined;
66
+ }
67
+
68
+ return m;
69
+ }
70
+ });
71
+ }
72
+ }
@@ -53,21 +53,27 @@ interface PackageFacts {
53
53
  docgen: boolean;
54
54
  }
55
55
 
56
- interface Accumulator {
57
- sources: SourceFacts[];
58
- packages: PackageFacts[];
59
- /** Components whose `propTypes` something reads, which removing them would break. */
60
- readComponents: Set<string>;
61
- /** Whether something reads `propTypes` off an expression that names no component, like an HOC's argument. */
62
- dynamicReads: boolean;
56
+ /** A read of some component's `propTypes`, which removing them would break. */
57
+ interface PropTypesRead {
58
+ /** The component read, or none when the expression names no component, like an HOC's argument. */
59
+ component?: string;
63
60
  /**
64
- * Where components read through an import are declared: resolved paths without extension for relative
61
+ * Where a component read through an import is declared: resolved paths without extension for relative
65
62
  * imports, and the module's last path segment for aliased or package imports, which can't be resolved here.
66
63
  */
67
- readFiles: Set<string>;
68
- readSegments: Set<string>;
64
+ files: string[];
65
+ segments: string[];
66
+ /** The `propTypes` declaration the read sits in, which stops counting once that declaration is removed. */
67
+ within?: PropTypesDeclaration;
68
+ }
69
+
70
+ interface Accumulator {
71
+ sources: SourceFacts[];
72
+ packages: PackageFacts[];
73
+ reads: PropTypesRead[];
69
74
  /** Unparsed sources and configuration that mention prop-types, which keep the dependency. */
70
75
  otherReferences: string[];
76
+ removable?: Set<PropTypesDeclaration>;
71
77
  }
72
78
 
73
79
  /** Visits every tree node beneath `node`, which upstream's `walk` does when told to keep descending. */
@@ -161,10 +167,17 @@ function hasTypedProps(cu: JS.CompilationUnit, name: string, seen = new Set<stri
161
167
  return typed;
162
168
  }
163
169
 
164
- function sourceFacts(cu: JS.CompilationUnit): SourceFacts {
170
+ function sourceFacts(cu: JS.CompilationUnit, enclosing: Map<J, PropTypesDeclaration>): SourceFacts {
165
171
  const names = new Set(bindingsOf(cu, new Set([MODULE])).keys());
166
172
  const typeScript = TYPESCRIPT_FILE.test(cu.sourcePath);
167
173
  const declarations: PropTypesDeclaration[] = [];
174
+ const declare = (component: string, node: J) => {
175
+ const decl = {component, typedProps: typeScript && hasTypedProps(cu, component), references: countReferences(node, names)};
176
+ declarations.push(decl);
177
+ walk(node, n => {
178
+ if (isPropTypesTarget(n)) enclosing.set(n, decl);
179
+ });
180
+ };
168
181
  let otherUse = false;
169
182
  let references = 0;
170
183
  for (const s of cu.statements) {
@@ -180,16 +193,13 @@ function sourceFacts(cu: JS.CompilationUnit): SourceFacts {
180
193
  }
181
194
  const component = assignedComponent(stmt);
182
195
  if (component) {
183
- declarations.push({component, typedProps: typeScript && hasTypedProps(cu, component),
184
- references: countReferences((stmt.kind === JS.Kind.ExpressionStatement ? (stmt as JS.ExpressionStatement).expression : stmt as J.Assignment), names)});
196
+ declare(component, stmt.kind === JS.Kind.ExpressionStatement ? (stmt as JS.ExpressionStatement).expression : stmt);
185
197
  }
186
198
  walk(stmt, n => {
187
199
  if (n.kind === J.Kind.ClassDeclaration) {
188
200
  for (const member of (n as J.ClassDeclaration).body.statements) {
189
201
  if (isStaticPropTypes(member.element)) {
190
- const component = (n as J.ClassDeclaration).name.simpleName;
191
- declarations.push({component, typedProps: typeScript && hasTypedProps(cu, component),
192
- references: countReferences(member.element, names)});
202
+ declare((n as J.ClassDeclaration).name.simpleName, member.element);
193
203
  }
194
204
  }
195
205
  } else if (n.kind === JS.Kind.ExportDeclaration && REFERENCE.test(JSON.stringify(n.moduleSpecifier ?? ''))) {
@@ -271,37 +281,57 @@ function lastSegment(path: string): string {
271
281
  return (segments[segments.length - 1] === 'index' ? segments[segments.length - 2] : segments[segments.length - 1]) ?? '';
272
282
  }
273
283
 
274
- function noteReadModule(acc: Accumulator, fromPath: string, module: string): void {
275
- if (module.startsWith('.')) {
276
- const parts = [...dirOf(fromPath).split('/').filter(Boolean)];
277
- for (const segment of withoutExtension(module).split('/')) {
278
- if (segment === '..') parts.pop();
279
- else if (segment !== '.' && segment) parts.push(segment);
280
- }
281
- const resolved = parts.join('/');
282
- acc.readFiles.add(resolved);
283
- acc.readFiles.add(resolved + '/index');
284
- } else {
285
- acc.readSegments.add(lastSegment(module));
284
+ function readModule(fromPath: string, module: string | undefined): Pick<PropTypesRead, 'files' | 'segments'> {
285
+ if (!module) return {files: [], segments: []};
286
+ if (!module.startsWith('.')) return {files: [], segments: [lastSegment(module)]};
287
+ const parts = [...dirOf(fromPath).split('/').filter(Boolean)];
288
+ for (const segment of withoutExtension(module).split('/')) {
289
+ if (segment === '..') parts.pop();
290
+ else if (segment !== '.' && segment) parts.push(segment);
286
291
  }
292
+ const resolved = parts.join('/');
293
+ return {files: [resolved, resolved + '/index'], segments: []};
287
294
  }
288
295
 
289
- function isRead(acc: Accumulator, source: SourceFacts, decl: PropTypesDeclaration): boolean {
290
- return acc.readComponents.has(decl.component) || acc.readFiles.has(withoutExtension(source.path)) ||
291
- acc.readSegments.has(lastSegment(source.path));
296
+ function readsDeclaration(read: PropTypesRead, file: string, segment: string, decl: PropTypesDeclaration): boolean {
297
+ return read.component === undefined || read.component === decl.component || read.files.includes(file) || read.segments.includes(segment);
292
298
  }
293
299
 
294
- function isRemovable(acc: Accumulator, source: SourceFacts, decl: PropTypesDeclaration): boolean {
295
- if (acc.dynamicReads || isRead(acc, source, decl)) return false;
300
+ function isRedundant(acc: Accumulator, source: SourceFacts, decl: PropTypesDeclaration): boolean {
296
301
  const pkg = packageOf(acc, source.path);
297
302
  if (pkg.supportsOldReact) return false;
298
303
  if (source.typeScript) return decl.typedProps;
299
304
  return !!pkg.react && pkg.react.major >= 19 && !pkg.docgen;
300
305
  }
301
306
 
307
+ /**
308
+ * The redundant declarations no remaining code reads. A read inside a declaration that goes too, like
309
+ * `Card.propTypes = {...DocsLink.propTypes}`, stops counting.
310
+ */
311
+ function removableDeclarations(acc: Accumulator): Set<PropTypesDeclaration> {
312
+ const candidates = acc.sources.flatMap(source => {
313
+ const file = withoutExtension(source.path);
314
+ const segment = lastSegment(source.path);
315
+ return source.declarations
316
+ .filter(decl => isRedundant(acc, source, decl))
317
+ .map(decl => ({decl, readers: acc.reads.filter(r => readsDeclaration(r, file, segment, decl))}));
318
+ });
319
+ const removable = new Set<PropTypesDeclaration>();
320
+ for (let grew = true; grew;) {
321
+ grew = false;
322
+ for (const {decl, readers} of candidates) {
323
+ if (!removable.has(decl) && readers.every(r => r.within && removable.has(r.within))) {
324
+ removable.add(decl);
325
+ grew = true;
326
+ }
327
+ }
328
+ }
329
+ return removable;
330
+ }
331
+
302
332
  /** Whether `source` still uses prop-types once its removable declarations are gone. */
303
- function stillUsesPropTypes(acc: Accumulator, source: SourceFacts): boolean {
304
- const removed = source.declarations.filter(d => isRemovable(acc, source, d)).reduce((sum, d) => sum + d.references, 0);
333
+ function stillUsesPropTypes(removable: ReadonlySet<PropTypesDeclaration>, source: SourceFacts): boolean {
334
+ const removed = source.declarations.filter(d => removable.has(d)).reduce((sum, d) => sum + d.references, 0);
305
335
  return source.otherUse || source.references - removed > 0;
306
336
  }
307
337
 
@@ -320,7 +350,7 @@ export class RemovePropTypes extends ScanningRecipe<Accumulator> {
320
350
  readonly tags = ["prop-types", "react"];
321
351
 
322
352
  initialValue(_ctx: ExecutionContext): Accumulator {
323
- return {sources: [], packages: [], readComponents: new Set(), dynamicReads: false, readFiles: new Set(), readSegments: new Set(), otherReferences: []};
353
+ return {sources: [], packages: [], reads: [], otherReferences: []};
324
354
  }
325
355
 
326
356
  async scanner(acc: Accumulator): Promise<TreeVisitor<any, ExecutionContext>> {
@@ -330,7 +360,8 @@ export class RemovePropTypes extends ScanningRecipe<Accumulator> {
330
360
  if (!sourcePath || sourcePath.includes('node_modules/') || LOCK_FILE.test(sourcePath)) return tree;
331
361
  if (tree.kind === JS.Kind.CompilationUnit) {
332
362
  const cu = tree as JS.CompilationUnit;
333
- acc.sources.push(sourceFacts(cu));
363
+ const enclosing = new Map<J, PropTypesDeclaration>();
364
+ acc.sources.push(sourceFacts(cu, enclosing));
334
365
  // An assignment's target declares `propTypes`; every other `X.propTypes` reads them.
335
366
  const declared = new Set<J>();
336
367
  walk(cu.statements, n => {
@@ -339,14 +370,14 @@ export class RemovePropTypes extends ScanningRecipe<Accumulator> {
339
370
  walk(cu.statements, n => {
340
371
  if (!isPropTypesTarget(n) || declared.has(n)) return;
341
372
  const target = (n as J.FieldAccess).target;
373
+ const within = enclosing.get(n);
342
374
  if (!isIdentifier(target)) {
343
- acc.dynamicReads = true;
375
+ acc.reads.push({files: [], segments: [], within});
344
376
  return;
345
377
  }
346
- acc.readComponents.add(target.simpleName);
347
378
  // An imported component may be declared under another name, so its declaring file is recorded too.
348
379
  const module = [...importedModules(cu)].find(m => bindingsOf(cu, new Set([m])).has(target.simpleName));
349
- if (module) noteReadModule(acc, cu.sourcePath, module);
380
+ acc.reads.push({component: target.simpleName, ...readModule(cu.sourcePath, module), within});
350
381
  });
351
382
  } else if (tree.kind === PARSE_ERROR && SOURCE_FILE.test(sourcePath)) {
352
383
  acc.otherReferences.push(sourcePath);
@@ -367,16 +398,17 @@ export class RemovePropTypes extends ScanningRecipe<Accumulator> {
367
398
 
368
399
  async editorWithData(acc: Accumulator): Promise<TreeVisitor<any, ExecutionContext>> {
369
400
  const sources = new Map(acc.sources.map(s => [s.path, s]));
401
+ const removable = acc.removable ??= removableDeclarations(acc);
370
402
  return new class extends TreeVisitor<Tree, ExecutionContext> {
371
403
  protected async accept(tree: Tree, p: ExecutionContext): Promise<Tree | undefined> {
372
404
  const sourcePath: string = (tree as any).sourcePath ?? '';
373
405
  if (tree.kind === JS.Kind.CompilationUnit) {
374
406
  const source = sources.get(sourcePath);
375
- const removable = new Set(source?.declarations.filter(d => isRemovable(acc, source, d)).map(d => d.component));
376
- return removable.size === 0 ? tree : new RemovePropTypesVisitor(removable).visit(tree, p);
407
+ const components = new Set(source?.declarations.filter(d => removable.has(d)).map(d => d.component));
408
+ return components.size === 0 ? tree : new RemovePropTypesVisitor(components).visit(tree, p);
377
409
  }
378
410
  if (tree.kind === Json.Kind.Document && isPackageJson(sourcePath)) {
379
- return removeDependency(acc, tree as Json.Document);
411
+ return removeDependency(acc, removable, tree as Json.Document);
380
412
  }
381
413
  return tree;
382
414
  }
@@ -384,10 +416,10 @@ export class RemovePropTypes extends ScanningRecipe<Accumulator> {
384
416
  }
385
417
  }
386
418
 
387
- function removeDependency(acc: Accumulator, doc: Json.Document): Json.Document {
419
+ function removeDependency(acc: Accumulator, removable: ReadonlySet<PropTypesDeclaration>, doc: Json.Document): Json.Document {
388
420
  const dir = dirOf(doc.sourcePath);
389
421
  const beneath = acc.sources.filter(s => dir === '' || s.path.startsWith(dir + '/'));
390
- if (beneath.length === 0 || anyBeneath(dir, acc.otherReferences) || beneath.some(s => stillUsesPropTypes(acc, s)) ||
422
+ if (beneath.length === 0 || anyBeneath(dir, acc.otherReferences) || beneath.some(s => stillUsesPropTypes(removable, s)) ||
391
423
  !isObject(doc.value)) {
392
424
  return doc;
393
425
  }
@@ -0,0 +1,66 @@
1
+ /*
2
+ * Copyright 2026 the original author or authors.
3
+ *
4
+ * Moderne Proprietary. Only for use by Moderne customers under the terms of a commercial contract.
5
+ */
6
+ import {check, ExecutionContext, or, Recipe, TreeVisitor} from "@openrewrite/rewrite";
7
+ import {JavaScriptVisitor, template, usesMethod, usesType} from "@openrewrite/rewrite/javascript";
8
+ import {J, Type} from "@openrewrite/rewrite/java";
9
+
10
+ /** The `node:repl` classes that must be called with `new`. */
11
+ const REPL_CLASSES = ["REPLServer", "Recoverable"];
12
+
13
+ const REPL_MODULES = ["repl", "node:repl"];
14
+
15
+ export class AddNewToReplClasses extends Recipe {
16
+ readonly name = "org.openrewrite.node.migrate.repl.add-new-to-repl-classes"
17
+ readonly displayName: string = "Add `new` when instantiating `node:repl` classes";
18
+ readonly description: string = "Calling the `node:repl` classes `REPLServer` and `Recoverable` as plain functions was " +
19
+ "runtime-deprecated in Node.js 24 and removed in Node.js 25 (DEP0185), where it now throws. The `new` qualifier " +
20
+ "must be used instead. Adding `new` is the whole fix: these classes returned a new instance either way, so the " +
21
+ "call keeps its arguments and its result.";
22
+ readonly tags: string[] = ["DEP0185"];
23
+
24
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
25
+ // A namespace import gives a `repl` type reference; a destructured import gives only
26
+ // the call, so both have to be looked for.
27
+ const preconditions = [
28
+ ...REPL_MODULES.map(module => usesType(module)),
29
+ ...REPL_MODULES.flatMap(module => REPL_CLASSES.map(cls => usesMethod(`${module} ${cls}(..)`))),
30
+ ];
31
+ return check(or(...preconditions), new class extends JavaScriptVisitor<ExecutionContext> {
32
+
33
+ /** Whether the call resolves to a class exported by `node:repl`. */
34
+ private isReplClassCall(m: J.MethodInvocation): boolean {
35
+ if (!REPL_CLASSES.includes(m.name.simpleName)) {
36
+ return false;
37
+ }
38
+ const declaring = m.methodType?.declaringType;
39
+ if (declaring?.kind !== Type.Kind.Class) {
40
+ return false;
41
+ }
42
+ return REPL_MODULES.includes((declaring as Type.Class).fullyQualifiedName);
43
+ }
44
+
45
+ protected async visitMethodInvocation(method: J.MethodInvocation, p: ExecutionContext): Promise<J | undefined> {
46
+ const m = await super.visitMethodInvocation(method, p) as J.MethodInvocation;
47
+ if (!this.isReplClassCall(m)) {
48
+ return m;
49
+ }
50
+
51
+ const args = m.arguments.elements;
52
+ const target = m.select?.element;
53
+
54
+ // `repl.REPLServer(..)` keeps its qualifier; a destructured `REPLServer(..)` has none.
55
+ if (target) {
56
+ return m.name.simpleName === "REPLServer"
57
+ ? await template`new ${target}.REPLServer(${args})`.apply(m, this.cursor)
58
+ : await template`new ${target}.Recoverable(${args})`.apply(m, this.cursor);
59
+ }
60
+ return m.name.simpleName === "REPLServer"
61
+ ? await template`new REPLServer(${args})`.apply(m, this.cursor)
62
+ : await template`new Recoverable(${args})`.apply(m, this.cursor);
63
+ }
64
+ });
65
+ }
66
+ }
@@ -17,6 +17,7 @@ import {IncreaseNodeEngineVersion} from "./increase-node-engine-version";
17
17
  import {IncreaseNodeEngineVersionInGithubActions} from "./increase-node-engine-version-in-github-actions";
18
18
  import {FindPunycodeUsage} from "./find-punycode-usage";
19
19
  import {FindCryptoCreateCipher} from "./find-crypto-create-cipher";
20
+ import {ReplaceFsStatsConstructor} from "./fs-stats-constructor";
20
21
 
21
22
  // Node 22 End-of-Life deprecations
22
23
  const node22EolDeprecations: Recipe[] = [
@@ -30,6 +31,7 @@ const node22RuntimeDeprecations: Recipe[] = [
30
31
  new UseNativeTypeCheckingMethods(), // DEP0044: util.isArray (runtime in v22)
31
32
  new ReplaceUtilExtend(), // DEP0060: util._extend (runtime in v22)
32
33
  new ReplaceCryptoConstructors(), // DEP0179, DEP0181: Hash/Hmac constructors
34
+ new ReplaceFsStatsConstructor(), // DEP0180: fs.Stats constructor (runtime in v22)
33
35
  ];
34
36
 
35
37
  // Doc-only deprecations (no fixed EOL version) bundled with the v22 upgrade
@@ -17,6 +17,10 @@ import {IncreaseNodeEngineVersionInGithubActions} from "./increase-node-engine-v
17
17
  import {FindProcessAssert} from "./find-process-assert";
18
18
  import {FindTlsSecurePair} from "./find-tls-secure-pair";
19
19
  import {FindTimersActive} from "./find-timers-active";
20
+ import {ReplaceTlsServerSetOptions} from "./tls-server-set-options";
21
+ import {RemoveNetSetSimultaneousAccepts} from "./net-set-simultaneous-accepts";
22
+ import {ReplaceTlsInternalModules} from "./tls-internal-modules";
23
+ import {AddNewToReplClasses} from "./repl-classes-with-new";
20
24
 
21
25
  // Node 24 End-of-Life deprecations (includes v23 EOL)
22
26
  const node24EolDeprecations: Recipe[] = [
@@ -28,11 +32,15 @@ const node24EolDeprecations: Recipe[] = [
28
32
  new ReplaceDirentPath(), // DEP0178: dirent.path (v24 EOL)
29
33
  new FindTlsSecurePair(), // DEP0043, DEP0064: tls.SecurePair/createSecurePair (v24 EOL)
30
34
  new FindTimersActive(), // DEP0126, DEP0127: timers.active/_unrefActive (v24 EOL)
35
+ new ReplaceTlsServerSetOptions(), // DEP0122: tls Server.prototype.setOptions() (v24 EOL)
36
+ new RemoveNetSetSimultaneousAccepts(), // DEP0121: net._setSimultaneousAccepts() (v24 EOL)
31
37
  ];
32
38
 
33
39
  // Node 24 Runtime deprecations (includes v23 runtime)
34
40
  const node24RuntimeDeprecations: Recipe[] = [
35
41
  new ReplaceCryptoFips(), // DEP0093: crypto.fips (v23 runtime)
42
+ new ReplaceTlsInternalModules(), // DEP0192: node:_tls_common/_tls_wrap (v24 runtime)
43
+ new AddNewToReplClasses(), // DEP0185: node:repl classes without new (v24 runtime)
36
44
  ];
37
45
 
38
46
  export class UpgradeNode24 extends Recipe {
@@ -17,6 +17,8 @@ import {FindFsRmdirRecursive} from "./find-fs-rmdir-recursive";
17
17
  import {ReplaceRsaPssKeyPairOptions} from "./crypto-rsa-pss-key-pair-options";
18
18
  import {ReplaceSlowBuffer} from "./slow-buffer";
19
19
  import {ReplaceFsAccessConstants} from "./fs-access-constants";
20
+ import {ReplaceChildProcessChannel} from "./child-process-channel";
21
+ import {RemoveProcessMultipleResolves} from "./process-multiple-resolves";
20
22
 
21
23
  // Node 26 End-of-Life deprecations (includes v25 EOL)
22
24
  const node26EolDeprecations: Recipe[] = [
@@ -24,6 +26,8 @@ const node26EolDeprecations: Recipe[] = [
24
26
  new FindFsRmdirRecursive(), // DEP0147: fs.rmdir(path, { recursive: true }) (v25 EOL)
25
27
  new ReplaceRsaPssKeyPairOptions(), // DEP0154: RSA-PSS hash and mgf1Hash options (v25 EOL)
26
28
  new ReplaceFsAccessConstants(), // DEP0176: fs.F_OK, fs.R_OK, fs.W_OK, fs.X_OK (v25 EOL)
29
+ new ReplaceChildProcessChannel(), // DEP0129: ChildProcess._channel (v25 EOL)
30
+ new RemoveProcessMultipleResolves(), // DEP0160: process.on('multipleResolves') (v25 EOL)
27
31
  new ReplaceServerResponseWriteHeader(), // DEP0063: ServerResponse.writeHeader() (v26 EOL)
28
32
  new ReplaceStreamInternalModules(), // DEP0125: legacy _stream_* modules (v26 EOL)
29
33
  new FindAeadDecipherivWithoutAuthTagLength(), // DEP0182: short GCM auth tags (v26 EOL)
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Moderne Proprietary. Only for use by Moderne customers under the terms of a commercial contract.
5
5
  */
6
- import {check, ExecutionContext, Recipe, TreeVisitor} from "@openrewrite/rewrite";
6
+ import {check, emptyMarkers, ExecutionContext, randomId, Recipe, TreeVisitor} from "@openrewrite/rewrite";
7
7
  import {
8
8
  JavaScriptVisitor,
9
9
  JS,
@@ -12,7 +12,13 @@ import {
12
12
  template,
13
13
  usesMethod
14
14
  } from "@openrewrite/rewrite/javascript";
15
- import {Expression, J} from "@openrewrite/rewrite/java";
15
+ import {emptySpace, Expression, J} from "@openrewrite/rewrite/java";
16
+
17
+ /** Trees whose `!` children stand as statements, since any condition they have sits in a tree of its own. */
18
+ const STATEMENT_HOLDERS = new Set<string>([
19
+ J.Kind.Block, JS.Kind.CompilationUnit, J.Kind.If, J.Kind.IfElse, J.Kind.WhileLoop, J.Kind.DoWhileLoop,
20
+ J.Kind.ForLoop, J.Kind.ForEachLoop, JS.Kind.ForInLoop, JS.Kind.WithStatement, J.Kind.Label,
21
+ ]);
16
22
 
17
23
  export class UseNativeTypeCheckingMethods extends Recipe {
18
24
  readonly name = "org.openrewrite.node.migrate.util.use-native-type-checking-methods"
@@ -55,27 +61,27 @@ export class UseNativeTypeCheckingMethods extends Recipe {
55
61
  if (replaced.kind === JS.Kind.Binary) {
56
62
  const binary = replaced as JS.Binary;
57
63
  if (binary.operator.element === JS.Binary.Type.IdentityEquals) {
58
- return {
64
+ return this.asStatementWhereOneWas({
59
65
  ...binary,
60
66
  prefix: unaryAfter.prefix,
61
67
  operator: {
62
68
  ...binary.operator,
63
69
  element: JS.Binary.Type.IdentityNotEquals
64
70
  }
65
- } as JS.Binary;
71
+ } as JS.Binary);
66
72
  }
67
73
  } else if (replaced.kind === J.Kind.Binary) {
68
74
  // used for `!util.isNullOrUndefined(x)`
69
75
  const binary = replaced as J.Binary;
70
76
  if (binary.operator.element === J.Binary.Type.Equal) {
71
- return {
77
+ return this.asStatementWhereOneWas({
72
78
  ...binary,
73
79
  prefix: unaryAfter.prefix,
74
80
  operator: {
75
81
  ...binary.operator,
76
82
  element: J.Binary.Type.NotEqual
77
83
  }
78
- } as J.Binary;
84
+ } as J.Binary);
79
85
  }
80
86
  }
81
87
 
@@ -83,6 +89,26 @@ export class UseNativeTypeCheckingMethods extends Recipe {
83
89
  return unaryAfter;
84
90
  }
85
91
 
92
+ /** Wraps the comparison in an ExpressionStatement where the `!` stood as a statement, as the parser does. */
93
+ private asStatementWhereOneWas(comparison: Expression): J {
94
+ const parent = this.cursor.parentTree()?.value as J | undefined;
95
+ const id = (this.cursor.value as J).id;
96
+ // A case holds its labels directly too, and they are expressions
97
+ const statement = parent?.kind === J.Kind.Case ?
98
+ (parent as J.Case).statements.elements.some(s => s.element.id === id) :
99
+ parent !== undefined && STATEMENT_HOLDERS.has(parent.kind);
100
+ if (!statement) {
101
+ return comparison;
102
+ }
103
+ return {
104
+ kind: JS.Kind.ExpressionStatement,
105
+ id: randomId(),
106
+ prefix: comparison.prefix,
107
+ markers: emptyMarkers,
108
+ expression: {...comparison, prefix: emptySpace}
109
+ } as JS.ExpressionStatement;
110
+ }
111
+
86
112
  protected async visitMethodInvocation(method: J.MethodInvocation, p: ExecutionContext): Promise<J | undefined> {
87
113
  if (this.isUtil.matches(method.methodType)) {
88
114
  const arg = method.arguments.elements[0].element;