@openrewrite/recipes-nodejs 0.56.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 +14 -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/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 +1 -1
- 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/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/resources/advisories-npm.csv +57 -14
- package/package.json +2 -2
- package/src/index.ts +14 -0
- package/src/migrate/casts.ts +57 -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 +2 -2
- package/src/migrate/module-bindings.ts +2 -2
- 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
|
@@ -0,0 +1,179 @@
|
|
|
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, foundSearchResult, or, Recipe, TreeVisitor} from "@openrewrite/rewrite";
|
|
7
|
+
import {declarationsOf, JavaScriptVisitor, JS, MethodMatcher, usesMethod, usesType} from "@openrewrite/rewrite/javascript";
|
|
8
|
+
import {isIdentifier, J, Type} from "@openrewrite/rewrite/java";
|
|
9
|
+
import {unwrapCasts} from "./casts";
|
|
10
|
+
import {bindingsOf, isModuleScoped, requiredModule, stringLiteral} from "./module-bindings";
|
|
11
|
+
|
|
12
|
+
const TLS_MODULES = new Set(["tls", "node:tls"]);
|
|
13
|
+
const NAME = "parseCertString";
|
|
14
|
+
const ADVICE = "Use the subject/issuer objects from getPeerCertificate() instead.";
|
|
15
|
+
const CALL_MESSAGE = `tls.parseCertString() was removed in Node.js 18 (DEP0076). ${ADVICE}`;
|
|
16
|
+
const REFERENCE_MESSAGE = `tls.parseCertString was removed in Node.js 18 (DEP0076), so this is undefined. ${ADVICE}`;
|
|
17
|
+
|
|
18
|
+
export class FindTlsParseCertString extends Recipe {
|
|
19
|
+
readonly name = "org.openrewrite.node.migrate.tls.find-tls-parse-cert-string"
|
|
20
|
+
readonly displayName: string = "Find deprecated `tls.parseCertString()` usage";
|
|
21
|
+
readonly description: string = "`tls.parseCertString()` was runtime-deprecated in Node.js 9 (DEP0076) and removed " +
|
|
22
|
+
"in Node.js 18. It never parsed multi-value Relative Distinguished Names correctly, and `querystring.parse()` " +
|
|
23
|
+
"is not a safe replacement either. Read the parsed `subject` and `issuer` objects from " +
|
|
24
|
+
"`tlsSocket.getPeerCertificate()` instead. Finds calls, and references that are not calls, such as " +
|
|
25
|
+
"`tls.parseCertString` passed as a callback or checked for feature detection, and calls through names it was imported, required or destructured as.";
|
|
26
|
+
readonly tags: string[] = ["DEP0076"];
|
|
27
|
+
|
|
28
|
+
async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
29
|
+
const patterns = [...TLS_MODULES].map(module => `${module} ${NAME}(..)`);
|
|
30
|
+
return check(or(bindsTls(), ...[...TLS_MODULES].map(module => usesType(module)), ...patterns.map(pattern => usesMethod(pattern))), new class extends JavaScriptVisitor<ExecutionContext> {
|
|
31
|
+
matchers = patterns.map(pattern => new MethodMatcher(pattern));
|
|
32
|
+
/** Module-scoped names bound to the tls module itself. */
|
|
33
|
+
modules = new Set<string>();
|
|
34
|
+
/** Module-scoped names bound to parseCertString. */
|
|
35
|
+
functions = new Set<string>();
|
|
36
|
+
|
|
37
|
+
protected async visitJsCompilationUnit(cu: JS.CompilationUnit, p: ExecutionContext): Promise<J | undefined> {
|
|
38
|
+
const bindings = bindingsOf(cu, TLS_MODULES);
|
|
39
|
+
this.modules = new Set([...bindings].filter(([, member]) => member === undefined).map(([local]) => local));
|
|
40
|
+
this.functions = new Set([...bindings].filter(([, member]) => member === NAME).map(([local]) => local));
|
|
41
|
+
for (const [local, member] of destructuredFromModule(cu, this.modules)) {
|
|
42
|
+
if (member === NAME) {
|
|
43
|
+
this.functions.add(local);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return super.visitJsCompilationUnit(cu, p);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
protected async visitMethodInvocation(m: J.MethodInvocation, p: ExecutionContext): Promise<J | undefined> {
|
|
50
|
+
const method = await super.visitMethodInvocation(m, p) as J.MethodInvocation;
|
|
51
|
+
if (this.matchers.some(matcher => matcher.matches(method.methodType)) ||
|
|
52
|
+
(method.name.simpleName === NAME && this.isTls(method.select?.element)) ||
|
|
53
|
+
(!method.select && this.functions.has(method.name.simpleName) && isModuleScoped(this.cursor, method.name.simpleName))) {
|
|
54
|
+
return foundSearchResult(method, CALL_MESSAGE);
|
|
55
|
+
}
|
|
56
|
+
return method;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
protected async visitFieldAccess(fieldAccess: J.FieldAccess, p: ExecutionContext): Promise<J | undefined> {
|
|
60
|
+
const f = await super.visitFieldAccess(fieldAccess, p) as J.FieldAccess;
|
|
61
|
+
return f.name.element.simpleName === NAME && this.isTls(f.target)
|
|
62
|
+
? foundSearchResult(f, REFERENCE_MESSAGE)
|
|
63
|
+
: f;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
protected async visitArrayAccess(arrayAccess: J.ArrayAccess, p: ExecutionContext): Promise<J | undefined> {
|
|
67
|
+
const a = await super.visitArrayAccess(arrayAccess, p) as J.ArrayAccess;
|
|
68
|
+
// Called right away, as in `tls['parseCertString'](s)`, the call is marked instead.
|
|
69
|
+
const parent = this.cursor.parentTree()?.value as J | undefined;
|
|
70
|
+
const called = parent?.kind === JS.Kind.FunctionCall &&
|
|
71
|
+
(parent as JS.FunctionCall).function?.element === arrayAccess;
|
|
72
|
+
return !called && this.isTlsBracketAccess(a) ? foundSearchResult(a, REFERENCE_MESSAGE) : a;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
protected async visitFunctionCall(functionCall: JS.FunctionCall, p: ExecutionContext): Promise<J | undefined> {
|
|
76
|
+
const f = await super.visitFunctionCall(functionCall, p) as JS.FunctionCall;
|
|
77
|
+
const callee = f.function?.element;
|
|
78
|
+
return callee?.kind === J.Kind.ArrayAccess && this.isTlsBracketAccess(callee as J.ArrayAccess)
|
|
79
|
+
? foundSearchResult(f, CALL_MESSAGE)
|
|
80
|
+
: f;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
protected async visitIdentifier(ident: J.Identifier, p: ExecutionContext): Promise<J | undefined> {
|
|
84
|
+
const id = await super.visitIdentifier(ident, p) as J.Identifier;
|
|
85
|
+
return this.functions.has(id.simpleName) && !declaresOrNames(this.cursor.parentTree()?.value, ident) &&
|
|
86
|
+
isModuleScoped(this.cursor, id.simpleName)
|
|
87
|
+
? foundSearchResult(id, REFERENCE_MESSAGE)
|
|
88
|
+
: id;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
private isTlsBracketAccess(a: J.ArrayAccess): boolean {
|
|
92
|
+
return stringLiteral(unwrapCasts(a.dimension.index.element)) === NAME && this.isTls(a.indexed);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Whether `e` is the tls module: typed as it, a name bound to it, or a `require` of it. */
|
|
96
|
+
private isTls(e: J | undefined): boolean {
|
|
97
|
+
const target = unwrapCasts(e);
|
|
98
|
+
if (target?.kind === J.Kind.Identifier) {
|
|
99
|
+
const id = target as J.Identifier;
|
|
100
|
+
const type = id.type;
|
|
101
|
+
return (type?.kind === Type.Kind.Class && TLS_MODULES.has((type as Type.Class).fullyQualifiedName)) ||
|
|
102
|
+
(this.modules.has(id.simpleName) && isModuleScoped(this.cursor, id.simpleName));
|
|
103
|
+
}
|
|
104
|
+
return TLS_MODULES.has(requiredModule(target) ?? "");
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Finds files that import or require tls, which can refer to parseCertString through a local name without
|
|
112
|
+
* anything typed as the tls module, as `import {parseCertString as parse} from 'tls'; [].map(parse)` does.
|
|
113
|
+
*/
|
|
114
|
+
function bindsTls(): TreeVisitor<any, ExecutionContext> {
|
|
115
|
+
return new class extends JavaScriptVisitor<ExecutionContext> {
|
|
116
|
+
protected async visitJsCompilationUnit(cu: JS.CompilationUnit): Promise<J | undefined> {
|
|
117
|
+
return bindingsOf(cu, TLS_MODULES).size > 0 ? foundSearchResult(cu) : cu;
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Whether `ident` under `parent` is not a use of the name it holds: the name a call, property access, property or
|
|
124
|
+
* declaration spells out, such as `p` in `p(s)`, `x.p`, `{p: 1}`, `const {p} = tls` or `import {p} from 'tls'`.
|
|
125
|
+
* Calls are marked as calls, and the rest are not references to parseCertString.
|
|
126
|
+
*/
|
|
127
|
+
function declaresOrNames(parent: any, ident: J.Identifier): boolean {
|
|
128
|
+
switch (parent?.kind) {
|
|
129
|
+
case J.Kind.MethodInvocation:
|
|
130
|
+
return (parent as J.MethodInvocation).name === ident;
|
|
131
|
+
case J.Kind.FieldAccess:
|
|
132
|
+
return (parent as J.FieldAccess).name.element === ident;
|
|
133
|
+
case JS.Kind.PropertyAssignment:
|
|
134
|
+
// The shorthand `{p}` has no initializer and uses `p` as its value.
|
|
135
|
+
return (parent as JS.PropertyAssignment).name.element === ident && !!(parent as JS.PropertyAssignment).initializer;
|
|
136
|
+
case J.Kind.NamedVariable:
|
|
137
|
+
return (parent as J.VariableDeclarations.NamedVariable).name === ident;
|
|
138
|
+
case J.Kind.MethodDeclaration:
|
|
139
|
+
return (parent as J.MethodDeclaration).name === ident;
|
|
140
|
+
case JS.Kind.ObjectBindingPattern:
|
|
141
|
+
case JS.Kind.BindingElement:
|
|
142
|
+
case JS.Kind.ImportSpecifier:
|
|
143
|
+
case JS.Kind.Alias:
|
|
144
|
+
case JS.Kind.ImportClause:
|
|
145
|
+
return true;
|
|
146
|
+
default:
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** The local and property names of top-level `const {a: b} = tls` destructurings of the module names in `modules`. */
|
|
152
|
+
function destructuredFromModule(cu: JS.CompilationUnit, modules: ReadonlySet<string>): [string, string][] {
|
|
153
|
+
const found: [string, string][] = [];
|
|
154
|
+
for (const padded of cu.statements) {
|
|
155
|
+
for (const declaration of declarationsOf(padded.element)) {
|
|
156
|
+
for (const v of declaration.variables) {
|
|
157
|
+
const initializer = unwrapCasts(v.element.initializer?.element);
|
|
158
|
+
const pattern = v.element.name as J;
|
|
159
|
+
if (!isIdentifier(initializer) || !modules.has(initializer.simpleName) ||
|
|
160
|
+
pattern.kind !== JS.Kind.ObjectBindingPattern) {
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
for (const el of (pattern as JS.ObjectBindingPattern).bindings.elements) {
|
|
164
|
+
const b = el.element;
|
|
165
|
+
if (isIdentifier(b)) {
|
|
166
|
+
found.push([b.simpleName, b.simpleName]);
|
|
167
|
+
} else if (b.kind === JS.Kind.BindingElement) {
|
|
168
|
+
const be = b as JS.BindingElement;
|
|
169
|
+
const property = be.propertyName?.element ?? be.name;
|
|
170
|
+
if (isIdentifier(be.name as J) && isIdentifier(property as J)) {
|
|
171
|
+
found.push([(be.name as J.Identifier).simpleName, (property as J.Identifier).simpleName]);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return found;
|
|
179
|
+
}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import {Column, Cursor, DataTable, emptyMarkers, randomId} from "@openrewrite/rewrite";
|
|
8
8
|
import {emptySpace, isIdentifier, J, rightPadded, space, Type} from "@openrewrite/rewrite/java";
|
|
9
|
-
import {bindingNames, declarationsOf, JS, scopeOf, walk} from "@openrewrite/rewrite/javascript";
|
|
9
|
+
import {bindingNames, declarationsOf, JS, moduleExportName, 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";
|
|
12
12
|
|
|
@@ -92,7 +92,7 @@ export function hpagentBindings(cu: JS.CompilationUnit): HpagentBindings {
|
|
|
92
92
|
typeOnly.add(spec.specifier.simpleName);
|
|
93
93
|
} else if (spec.specifier.kind === JS.Kind.Alias && isIdentifier((spec.specifier as JS.Alias).alias)) {
|
|
94
94
|
const alias = spec.specifier as JS.Alias;
|
|
95
|
-
bindings.set((alias.alias as J.Identifier).simpleName, alias.propertyName.element
|
|
95
|
+
bindings.set((alias.alias as J.Identifier).simpleName, moduleExportName(alias.propertyName.element));
|
|
96
96
|
typeOnly.add((alias.alias as J.Identifier).simpleName);
|
|
97
97
|
}
|
|
98
98
|
}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import {Cursor} from "@openrewrite/rewrite";
|
|
8
8
|
import {isIdentifier, J} from "@openrewrite/rewrite/java";
|
|
9
|
-
import {declarationsOf, JS, scopeOf} from "@openrewrite/rewrite/javascript";
|
|
9
|
+
import {declarationsOf, JS, moduleExportName, scopeOf} from "@openrewrite/rewrite/javascript";
|
|
10
10
|
|
|
11
11
|
// Resolution is syntactic rather than by type attribution: JavaScript without type declarations for
|
|
12
12
|
// a library (express-request-id 1.x, fs-extra without @types) attributes its calls to `<unknown>`.
|
|
@@ -58,7 +58,7 @@ export function bindingsOf(cu: JS.CompilationUnit, modules: ReadonlySet<string>)
|
|
|
58
58
|
} else if (spec.specifier.kind === JS.Kind.Alias) {
|
|
59
59
|
const alias = spec.specifier as JS.Alias;
|
|
60
60
|
if (isIdentifier(alias.alias)) {
|
|
61
|
-
bindings.set(alias.alias.simpleName, alias.propertyName.element
|
|
61
|
+
bindings.set(alias.alias.simpleName, moduleExportName(alias.propertyName.element));
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
}
|
|
@@ -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
|
}
|