@openrewrite/recipes-nodejs 0.55.0 → 0.56.1
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.
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -1
- package/dist/migrate/casts.d.ts +4 -0
- package/dist/migrate/casts.d.ts.map +1 -0
- package/dist/migrate/casts.js +53 -0
- package/dist/migrate/casts.js.map +1 -0
- package/dist/migrate/child-process-channel.d.ts +9 -0
- package/dist/migrate/child-process-channel.d.ts.map +1 -0
- package/dist/migrate/child-process-channel.js +65 -0
- package/dist/migrate/child-process-channel.js.map +1 -0
- package/dist/migrate/exports-folder-mappings.d.ts +9 -0
- package/dist/migrate/exports-folder-mappings.d.ts.map +1 -0
- package/dist/migrate/exports-folder-mappings.js +118 -0
- package/dist/migrate/exports-folder-mappings.js.map +1 -0
- package/dist/migrate/find-dns-lookup-options-coercion.d.ts +9 -0
- package/dist/migrate/find-dns-lookup-options-coercion.d.ts.map +1 -0
- package/dist/migrate/find-dns-lookup-options-coercion.js +270 -0
- package/dist/migrate/find-dns-lookup-options-coercion.js.map +1 -0
- package/dist/migrate/find-err-invalid-callback.d.ts +9 -0
- package/dist/migrate/find-err-invalid-callback.d.ts.map +1 -0
- package/dist/migrate/find-err-invalid-callback.js +61 -0
- package/dist/migrate/find-err-invalid-callback.js.map +1 -0
- package/dist/migrate/find-process-multiple-resolves.d.ts +9 -0
- package/dist/migrate/find-process-multiple-resolves.d.ts.map +1 -0
- package/dist/migrate/find-process-multiple-resolves.js +58 -0
- package/dist/migrate/find-process-multiple-resolves.js.map +1 -0
- package/dist/migrate/find-stream-thenable-implementations.d.ts +9 -0
- package/dist/migrate/find-stream-thenable-implementations.d.ts.map +1 -0
- package/dist/migrate/find-stream-thenable-implementations.js +123 -0
- package/dist/migrate/find-stream-thenable-implementations.js.map +1 -0
- package/dist/migrate/find-tls-parse-cert-string.d.ts +9 -0
- package/dist/migrate/find-tls-parse-cert-string.d.ts.map +1 -0
- package/dist/migrate/find-tls-parse-cert-string.js +206 -0
- package/dist/migrate/find-tls-parse-cert-string.js.map +1 -0
- package/dist/migrate/hpagent/hpagent-support.d.ts.map +1 -1
- package/dist/migrate/hpagent/hpagent-support.js +6 -2
- package/dist/migrate/hpagent/hpagent-support.js.map +1 -1
- package/dist/migrate/module-bindings.d.ts.map +1 -1
- package/dist/migrate/module-bindings.js +1 -1
- package/dist/migrate/module-bindings.js.map +1 -1
- package/dist/migrate/process-exit-code.d.ts.map +1 -1
- package/dist/migrate/process-exit-code.js +16 -11
- package/dist/migrate/process-exit-code.js.map +1 -1
- package/dist/migrate/process-multiple-resolves.d.ts +9 -0
- package/dist/migrate/process-multiple-resolves.d.ts.map +1 -0
- package/dist/migrate/process-multiple-resolves.js +72 -0
- package/dist/migrate/process-multiple-resolves.js.map +1 -0
- package/dist/migrate/prop-types/remove-prop-types.d.ts +8 -4
- package/dist/migrate/prop-types/remove-prop-types.d.ts.map +1 -1
- package/dist/migrate/prop-types/remove-prop-types.js +62 -40
- package/dist/migrate/prop-types/remove-prop-types.js.map +1 -1
- package/dist/migrate/repl-classes-with-new.d.ts +9 -0
- package/dist/migrate/repl-classes-with-new.d.ts.map +1 -0
- package/dist/migrate/repl-classes-with-new.js +74 -0
- package/dist/migrate/repl-classes-with-new.js.map +1 -0
- package/dist/migrate/source-map-support/replace-source-map-support-api.d.ts.map +1 -1
- package/dist/migrate/source-map-support/replace-source-map-support-api.js +1 -1
- package/dist/migrate/source-map-support/replace-source-map-support-api.js.map +1 -1
- package/dist/migrate/upgrade-node-18.d.ts +8 -0
- package/dist/migrate/upgrade-node-18.d.ts.map +1 -0
- package/dist/migrate/upgrade-node-18.js +58 -0
- package/dist/migrate/upgrade-node-18.js.map +1 -0
- package/dist/migrate/upgrade-node-20.d.ts +1 -1
- package/dist/migrate/upgrade-node-20.d.ts.map +1 -1
- package/dist/migrate/upgrade-node-20.js +3 -6
- package/dist/migrate/upgrade-node-20.js.map +1 -1
- package/dist/migrate/upgrade-node-22.d.ts.map +1 -1
- package/dist/migrate/upgrade-node-22.js +2 -0
- package/dist/migrate/upgrade-node-22.js.map +1 -1
- package/dist/migrate/upgrade-node-24.d.ts.map +1 -1
- package/dist/migrate/upgrade-node-24.js +8 -0
- package/dist/migrate/upgrade-node-24.js.map +1 -1
- package/dist/migrate/upgrade-node-26.d.ts.map +1 -1
- package/dist/migrate/upgrade-node-26.js +4 -0
- package/dist/migrate/upgrade-node-26.js.map +1 -1
- package/dist/migrate/util-type-checking.d.ts.map +1 -1
- package/dist/migrate/util-type-checking.js +24 -2
- package/dist/migrate/util-type-checking.js.map +1 -1
- package/dist/resources/advisories-npm.csv +207 -27
- package/package.json +2 -2
- package/src/index.ts +22 -0
- package/src/migrate/casts.ts +57 -0
- package/src/migrate/child-process-channel.ts +61 -0
- package/src/migrate/exports-folder-mappings.ts +113 -0
- package/src/migrate/find-dns-lookup-options-coercion.ts +292 -0
- package/src/migrate/find-err-invalid-callback.ts +43 -0
- package/src/migrate/find-process-multiple-resolves.ts +42 -0
- package/src/migrate/find-stream-thenable-implementations.ts +116 -0
- package/src/migrate/find-tls-parse-cert-string.ts +179 -0
- package/src/migrate/hpagent/hpagent-support.ts +8 -4
- package/src/migrate/module-bindings.ts +2 -2
- package/src/migrate/process-exit-code.ts +19 -14
- package/src/migrate/process-multiple-resolves.ts +72 -0
- package/src/migrate/prop-types/remove-prop-types.ts +77 -45
- package/src/migrate/repl-classes-with-new.ts +66 -0
- package/src/migrate/source-map-support/replace-source-map-support-api.ts +2 -1
- package/src/migrate/upgrade-node-18.ts +52 -0
- package/src/migrate/upgrade-node-20.ts +3 -8
- package/src/migrate/upgrade-node-22.ts +2 -0
- package/src/migrate/upgrade-node-24.ts +8 -0
- package/src/migrate/upgrade-node-26.ts +4 -0
- package/src/migrate/util-type-checking.ts +32 -6
|
@@ -53,21 +53,27 @@ interface PackageFacts {
|
|
|
53
53
|
docgen: boolean;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
|
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
|
-
|
|
68
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
275
|
-
if (module
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
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
|
|
290
|
-
return
|
|
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
|
|
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(
|
|
304
|
-
const removed = source.declarations.filter(d =>
|
|
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: [],
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
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
|
|
376
|
-
return
|
|
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(
|
|
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
|
+
}
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
JavaScriptVisitor,
|
|
15
15
|
JS,
|
|
16
16
|
maybeUnbind,
|
|
17
|
+
moduleExportName,
|
|
17
18
|
namesDeclaredIn,
|
|
18
19
|
namesReferencedWithin,
|
|
19
20
|
referencesOf,
|
|
@@ -61,7 +62,7 @@ function typeBindingsOf(cu: JS.CompilationUnit): Map<string, string> {
|
|
|
61
62
|
bindings.set(spec.specifier.simpleName, spec.specifier.simpleName);
|
|
62
63
|
} else if (spec.specifier.kind === JS.Kind.Alias && isIdentifier((spec.specifier as JS.Alias).alias)) {
|
|
63
64
|
const alias = spec.specifier as JS.Alias;
|
|
64
|
-
bindings.set((alias.alias as J.Identifier).simpleName, alias.propertyName.element
|
|
65
|
+
bindings.set((alias.alias as J.Identifier).simpleName, moduleExportName(alias.propertyName.element));
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
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 {Recipe} from "@openrewrite/rewrite";
|
|
7
|
+
import {prepareJavaRecipe} from "@openrewrite/rewrite/rpc";
|
|
8
|
+
import {FindTlsParseCertString} from "./find-tls-parse-cert-string";
|
|
9
|
+
import {FindDnsLookupOptionsCoercion} from "./find-dns-lookup-options-coercion";
|
|
10
|
+
import {FindErrInvalidCallback} from "./find-err-invalid-callback";
|
|
11
|
+
import {FindStreamThenableImplementations} from "./find-stream-thenable-implementations";
|
|
12
|
+
import {FindProcessMultipleResolves} from "./find-process-multiple-resolves";
|
|
13
|
+
import {ReplaceExportsFolderMappings} from "./exports-folder-mappings";
|
|
14
|
+
import {ReplaceDeprecatedBufferConstructor} from "./buffer-constructor";
|
|
15
|
+
import {IncreaseNodeEngineVersion} from "./increase-node-engine-version";
|
|
16
|
+
import {IncreaseNodeEngineVersionInGithubActions} from "./increase-node-engine-version-in-github-actions";
|
|
17
|
+
|
|
18
|
+
// Node 18 End-of-Life deprecations (includes v17 EOL)
|
|
19
|
+
const node18EolDeprecations: Recipe[] = [
|
|
20
|
+
new ReplaceExportsFolderMappings(), // DEP0148: "exports" folder mappings (v17 EOL)
|
|
21
|
+
new FindTlsParseCertString(), // DEP0076: tls.parseCertString() (v18 EOL)
|
|
22
|
+
new FindDnsLookupOptionsCoercion(), // DEP0153: dns.lookup options type coercion (v18 EOL)
|
|
23
|
+
new FindStreamThenableImplementations(), // DEP0157: thenables in stream implementations (v18 EOL)
|
|
24
|
+
new FindErrInvalidCallback(), // DEP0159: ERR_INVALID_CALLBACK (v18 EOL)
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
// Node 18 Runtime deprecations
|
|
28
|
+
const node18RuntimeDeprecations: Recipe[] = [
|
|
29
|
+
new FindProcessMultipleResolves(), // DEP0160: process.on('multipleResolves') (v18 runtime)
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
// Runtime deprecations from earlier versions, bundled with the oldest upgrade we have
|
|
33
|
+
const earlierRuntimeDeprecations: Recipe[] = [
|
|
34
|
+
new ReplaceDeprecatedBufferConstructor(), // DEP0005: Buffer() constructor (runtime since v10)
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
export class UpgradeNode18 extends Recipe {
|
|
38
|
+
readonly name = "org.openrewrite.node.migrate.upgrade-node-18";
|
|
39
|
+
readonly displayName = "Upgrade to Node.js 18";
|
|
40
|
+
readonly description = "Migrate deprecated APIs for Node.js 18 compatibility. Addresses deprecations that are end-of-life in Node 17 and 18, Node 18 runtime deprecations, and runtime deprecations from earlier versions.";
|
|
41
|
+
|
|
42
|
+
async recipeList(): Promise<Recipe[]> {
|
|
43
|
+
return [
|
|
44
|
+
new IncreaseNodeEngineVersion({version: "18"}),
|
|
45
|
+
new IncreaseNodeEngineVersionInGithubActions({version: "18"}),
|
|
46
|
+
await prepareJavaRecipe("org.openrewrite.nodejs.migrate.UpgradeNodeVersion", {version: "18"}),
|
|
47
|
+
...node18EolDeprecations,
|
|
48
|
+
...node18RuntimeDeprecations,
|
|
49
|
+
...earlierRuntimeDeprecations,
|
|
50
|
+
];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -7,7 +7,7 @@ import {Recipe} from "@openrewrite/rewrite";
|
|
|
7
7
|
import {prepareJavaRecipe} from "@openrewrite/rewrite/rpc";
|
|
8
8
|
import {AvoidImplicitCoercionOfExitCode} from "./process-exit-code";
|
|
9
9
|
import {FindCryptoDefaultEncoding} from "./find-crypto-default-encoding";
|
|
10
|
-
import {
|
|
10
|
+
import {UpgradeNode18} from "./upgrade-node-18";
|
|
11
11
|
import {IncreaseNodeEngineVersion} from "./increase-node-engine-version";
|
|
12
12
|
import {IncreaseNodeEngineVersionInGithubActions} from "./increase-node-engine-version-in-github-actions";
|
|
13
13
|
|
|
@@ -17,23 +17,18 @@ const node20EolDeprecations: Recipe[] = [
|
|
|
17
17
|
new FindCryptoDefaultEncoding(), // DEP0091: crypto.DEFAULT_ENCODING (v20 EOL)
|
|
18
18
|
];
|
|
19
19
|
|
|
20
|
-
// Runtime deprecations from earlier versions, bundled with the oldest upgrade we have
|
|
21
|
-
const earlierRuntimeDeprecations: Recipe[] = [
|
|
22
|
-
new ReplaceDeprecatedBufferConstructor(), // DEP0005: Buffer() constructor (runtime since v10)
|
|
23
|
-
];
|
|
24
|
-
|
|
25
20
|
export class UpgradeNode20 extends Recipe {
|
|
26
21
|
readonly name = "org.openrewrite.node.migrate.upgrade-node-20";
|
|
27
22
|
readonly displayName = "Upgrade to Node.js 20";
|
|
28
|
-
readonly description = "Migrate deprecated APIs for Node.js 20 compatibility.
|
|
23
|
+
readonly description = "Migrate deprecated APIs for Node.js 20 compatibility. Includes all migrations from Node.js 18, plus Node 20 deprecations.";
|
|
29
24
|
|
|
30
25
|
async recipeList(): Promise<Recipe[]> {
|
|
31
26
|
return [
|
|
32
27
|
new IncreaseNodeEngineVersion({version: "20"}),
|
|
33
28
|
new IncreaseNodeEngineVersionInGithubActions({version: "20"}),
|
|
34
29
|
await prepareJavaRecipe("org.openrewrite.nodejs.migrate.UpgradeNodeVersion", {version: "20"}),
|
|
30
|
+
new UpgradeNode18(),
|
|
35
31
|
...node20EolDeprecations,
|
|
36
|
-
...earlierRuntimeDeprecations,
|
|
37
32
|
];
|
|
38
33
|
}
|
|
39
34
|
}
|
|
@@ -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;
|