@openrewrite/recipes-nodejs 0.53.0-20261025-170921 → 0.53.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 +4 -0
- package/dist/index.js.map +1 -1
- package/dist/migrate/crypto-rsa-pss-key-pair-options.d.ts +9 -0
- package/dist/migrate/crypto-rsa-pss-key-pair-options.d.ts.map +1 -0
- package/dist/migrate/crypto-rsa-pss-key-pair-options.js +107 -0
- package/dist/migrate/crypto-rsa-pss-key-pair-options.js.map +1 -0
- package/dist/migrate/find-fs-rmdir-recursive.d.ts +9 -0
- package/dist/migrate/find-fs-rmdir-recursive.d.ts.map +1 -0
- package/dist/migrate/find-fs-rmdir-recursive.js +89 -0
- package/dist/migrate/find-fs-rmdir-recursive.js.map +1 -0
- package/dist/migrate/options-literal.d.ts +5 -0
- package/dist/migrate/options-literal.d.ts.map +1 -0
- package/dist/migrate/options-literal.js +55 -0
- package/dist/migrate/options-literal.js.map +1 -0
- 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/resources/advisories-npm.csv +258 -5
- package/package.json +2 -2
- package/src/index.ts +4 -0
- package/src/migrate/crypto-rsa-pss-key-pair-options.ts +119 -0
- package/src/migrate/find-fs-rmdir-recursive.ts +87 -0
- package/src/migrate/options-literal.ts +66 -0
- package/src/migrate/upgrade-node-26.ts +5 -1
|
@@ -0,0 +1,119 @@
|
|
|
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, randomId, Recipe, TreeVisitor} from "@openrewrite/rewrite";
|
|
7
|
+
import {JavaScriptVisitor, JS, MethodMatcher, usesMethod} from "@openrewrite/rewrite/javascript";
|
|
8
|
+
import {isIdentifier, J, space} from "@openrewrite/rewrite/java";
|
|
9
|
+
import {propertyNameOf} from "./fs-extra/fs-extra-support";
|
|
10
|
+
import {stringLiteral} from "./module-bindings";
|
|
11
|
+
import {optionsLiteral, withOptionsLiteral, withoutCasts} from "./options-literal";
|
|
12
|
+
|
|
13
|
+
const KEY_PAIR_GENERATORS = [
|
|
14
|
+
"crypto generateKeyPair(..)",
|
|
15
|
+
"crypto generateKeyPairSync(..)",
|
|
16
|
+
// `util.promisify(crypto.generateKeyPair)`, which @types/node types as `generateKeyPair.__promisify__`.
|
|
17
|
+
"generateKeyPair __promisify__(..)",
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
/** The name Node.js 16.10 gave each option it later removed. */
|
|
21
|
+
const RENAMED = new Map([
|
|
22
|
+
["hash", "hashAlgorithm"],
|
|
23
|
+
["mgf1Hash", "mgf1HashAlgorithm"],
|
|
24
|
+
]);
|
|
25
|
+
|
|
26
|
+
export class ReplaceRsaPssKeyPairOptions extends Recipe {
|
|
27
|
+
readonly name = "org.openrewrite.node.migrate.crypto.replace-rsa-pss-key-pair-options"
|
|
28
|
+
readonly displayName: string = "Replace removed RSA-PSS `hash` and `mgf1Hash` key pair options";
|
|
29
|
+
readonly description: string = "Rename the `hash` and `mgf1Hash` options of `crypto.generateKeyPair('rsa-pss', ...)` " +
|
|
30
|
+
"and `crypto.generateKeyPairSync('rsa-pss', ...)` to `hashAlgorithm` and `mgf1HashAlgorithm`, the names " +
|
|
31
|
+
"Node.js 16.10 added. Node.js 25 removed the old names (DEP0154) and throws `ERR_INVALID_ARG_VALUE` for them, " +
|
|
32
|
+
"where earlier versions read each the same as its new name. Options are renamed where they are written as an " +
|
|
33
|
+
"object literal, unless it already gives the new name or has keys that can't be read, such as a spread.";
|
|
34
|
+
readonly tags: string[] = ["DEP0154"];
|
|
35
|
+
|
|
36
|
+
async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
37
|
+
return check(or(...KEY_PAIR_GENERATORS.map(pattern => usesMethod(pattern))), new class extends JavaScriptVisitor<ExecutionContext> {
|
|
38
|
+
generators = KEY_PAIR_GENERATORS.map(pattern => new MethodMatcher(pattern));
|
|
39
|
+
|
|
40
|
+
protected async visitMethodInvocation(m: J.MethodInvocation, p: ExecutionContext): Promise<J | undefined> {
|
|
41
|
+
const method = await super.visitMethodInvocation(m, p) as J.MethodInvocation;
|
|
42
|
+
if (!this.generators.some(generator => generator.matches(method.methodType))) {
|
|
43
|
+
return method;
|
|
44
|
+
}
|
|
45
|
+
const [type, options] = method.arguments.elements;
|
|
46
|
+
// Only `rsa-pss` reads these options; every other key type ignores them, as it always did.
|
|
47
|
+
if (stringLiteral(withoutCasts(type?.element)) !== "rsa-pss" || !options) {
|
|
48
|
+
return method;
|
|
49
|
+
}
|
|
50
|
+
const literal = optionsLiteral(options.element);
|
|
51
|
+
const renamed = literal && renameOptions(literal);
|
|
52
|
+
if (!renamed || renamed === literal) {
|
|
53
|
+
return method;
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
...method,
|
|
57
|
+
arguments: {
|
|
58
|
+
...method.arguments,
|
|
59
|
+
elements: method.arguments.elements.map(arg =>
|
|
60
|
+
arg === options ? {...arg, element: withOptionsLiteral(arg.element, renamed)} : arg)
|
|
61
|
+
}
|
|
62
|
+
} as J.MethodInvocation;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The literal with each removed option under its new name. An option is left alone where the
|
|
70
|
+
* literal already gives its new name, since Node.js before 25 then read both and failed when they
|
|
71
|
+
* differed, and so is every option of a literal with a key that can't be read, such as a spread,
|
|
72
|
+
* a computed key or a method, which could give either name.
|
|
73
|
+
*/
|
|
74
|
+
function renameOptions(options: J.NewClass): J.NewClass {
|
|
75
|
+
const members = options.body?.statements ?? [];
|
|
76
|
+
const names = members.map(member => member.element.kind === JS.Kind.PropertyAssignment
|
|
77
|
+
? propertyNameOf(member.element as JS.PropertyAssignment)
|
|
78
|
+
: undefined);
|
|
79
|
+
if (names.some(name => name === undefined)) {
|
|
80
|
+
return options;
|
|
81
|
+
}
|
|
82
|
+
let renamed = false;
|
|
83
|
+
const statements = members.map((member, i) => {
|
|
84
|
+
const to = RENAMED.get(names[i]!);
|
|
85
|
+
if (!to || names.includes(to)) {
|
|
86
|
+
return member;
|
|
87
|
+
}
|
|
88
|
+
renamed = true;
|
|
89
|
+
return {...member, element: renameProperty(member.element as JS.PropertyAssignment, to)};
|
|
90
|
+
});
|
|
91
|
+
return renamed ? {...options, body: {...options.body!, statements}} : options;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function renameProperty(property: JS.PropertyAssignment, to: string): JS.PropertyAssignment {
|
|
95
|
+
const key = property.name.element;
|
|
96
|
+
if (isIdentifier(key)) {
|
|
97
|
+
const renamedKey = {...key, simpleName: to, fieldType: undefined};
|
|
98
|
+
if (property.initializer) {
|
|
99
|
+
return {...property, name: {...property.name, element: renamedKey}};
|
|
100
|
+
}
|
|
101
|
+
// `{hash}` becomes `{hashAlgorithm: hash}`, which still reads the variable.
|
|
102
|
+
return {
|
|
103
|
+
...property,
|
|
104
|
+
name: {...property.name, element: {...renamedKey, id: randomId()}},
|
|
105
|
+
assigmentToken: JS.PropertyAssignment.Token.Colon,
|
|
106
|
+
initializer: {...key, prefix: space(' ')}
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
// A quoted key keeps its quotes.
|
|
110
|
+
const literal = key as J.Literal;
|
|
111
|
+
const quote = literal.valueSource?.charAt(0) ?? "'";
|
|
112
|
+
return {
|
|
113
|
+
...property,
|
|
114
|
+
name: {
|
|
115
|
+
...property.name,
|
|
116
|
+
element: {...literal, value: to, valueSource: `${quote}${to}${quote}`, unicodeEscapes: undefined} as J.Literal
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
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 {JavaScriptVisitor, JS, MethodMatcher, usesMethod} from "@openrewrite/rewrite/javascript";
|
|
8
|
+
import {isIdentifier, J} from "@openrewrite/rewrite/java";
|
|
9
|
+
import {propertyNameOf} from "./fs-extra/fs-extra-support";
|
|
10
|
+
import {optionsLiteral} from "./options-literal";
|
|
11
|
+
|
|
12
|
+
interface RmdirForm {
|
|
13
|
+
pattern: string;
|
|
14
|
+
api: string;
|
|
15
|
+
/** How the call reports the option since Node.js 25. */
|
|
16
|
+
fails: string;
|
|
17
|
+
/** How the call reported a path that is not a directory before. */
|
|
18
|
+
failed: string;
|
|
19
|
+
/** The `fs.rm()` call that removes a directory tree the same way. */
|
|
20
|
+
rm: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const RMDIR_FORMS: RmdirForm[] = [
|
|
24
|
+
{
|
|
25
|
+
pattern: "fs rmdir(..)", api: "fs.rmdir()", fails: "throws", failed: "failed with",
|
|
26
|
+
rm: "fs.rm(path, { recursive: true }, callback)"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
pattern: "fs rmdirSync(..)", api: "fs.rmdirSync()", fails: "throws", failed: "threw",
|
|
30
|
+
rm: "fs.rmSync(path, { recursive: true })"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
pattern: "fs/promises rmdir(..)", api: "fs.promises.rmdir()", fails: "rejects with", failed: "rejected with",
|
|
34
|
+
rm: "fs.promises.rm(path, { recursive: true })"
|
|
35
|
+
},
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
export class FindFsRmdirRecursive extends Recipe {
|
|
39
|
+
readonly name = "org.openrewrite.node.migrate.fs.find-rmdir-recursive"
|
|
40
|
+
readonly displayName: string = "Find `fs.rmdir()` calls with the removed `recursive` option";
|
|
41
|
+
readonly description: string = "Node.js 25 removed the `recursive` option of `fs.rmdir()`, `fs.rmdirSync()` and " +
|
|
42
|
+
"`fs.promises.rmdir()` (DEP0147), which now fail with `ERR_INVALID_ARG_VALUE` whenever it is passed, even as " +
|
|
43
|
+
"`false`. `fs.rm()` with `recursive: true` removes a directory tree the same way, but it is not an " +
|
|
44
|
+
"exact replacement: it deletes a file where `fs.rmdir()` failed with `ENOTDIR`, and with `force: true`, as Node.js " +
|
|
45
|
+
"suggests, it also ignores a missing path. So the calls are marked to be changed by hand. Only options written " +
|
|
46
|
+
"as an object literal are found.";
|
|
47
|
+
readonly tags: string[] = ["DEP0147"];
|
|
48
|
+
|
|
49
|
+
async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
50
|
+
return check(or(...RMDIR_FORMS.map(form => usesMethod(form.pattern))), new class extends JavaScriptVisitor<ExecutionContext> {
|
|
51
|
+
forms = RMDIR_FORMS.map(form => ({form, matcher: new MethodMatcher(form.pattern)}));
|
|
52
|
+
|
|
53
|
+
protected async visitMethodInvocation(m: J.MethodInvocation, p: ExecutionContext): Promise<J | undefined> {
|
|
54
|
+
const method = await super.visitMethodInvocation(m, p) as J.MethodInvocation;
|
|
55
|
+
const form = this.forms.find(f => f.matcher.matches(method.methodType))?.form;
|
|
56
|
+
const options = form && optionsLiteral(method.arguments.elements[1]?.element);
|
|
57
|
+
const recursive = options && recursiveOption(options);
|
|
58
|
+
return form && recursive ? foundSearchResult(method, message(form, recursive)) : method;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The value an options literal gives `recursive`, the last one where it gives several, or undefined
|
|
66
|
+
* where it gives none. `{recursive}` passes the variable of that name.
|
|
67
|
+
*/
|
|
68
|
+
function recursiveOption(options: J.NewClass): J | undefined {
|
|
69
|
+
let value: J | undefined;
|
|
70
|
+
for (const member of options.body?.statements ?? []) {
|
|
71
|
+
const property = member.element as JS.PropertyAssignment;
|
|
72
|
+
if (property.kind === JS.Kind.PropertyAssignment && propertyNameOf(property) === "recursive") {
|
|
73
|
+
value = property.initializer ?? property.name.element;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// Node.js 25 only throws for a value other than undefined.
|
|
77
|
+
return value && !(isIdentifier(value) && value.simpleName === "undefined") ? value : undefined;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function message(form: RmdirForm, recursive: J): string {
|
|
81
|
+
const removed = `${form.api} ${form.fails} ERR_INVALID_ARG_VALUE for the recursive option since Node.js 25`;
|
|
82
|
+
if (recursive.kind === J.Kind.Literal && (recursive as J.Literal).value === false) {
|
|
83
|
+
return `${removed}, even when it is false (DEP0147). Remove the option.`;
|
|
84
|
+
}
|
|
85
|
+
return `${removed} (DEP0147). ${form.rm} removes the directory tree as before, but deletes a file where ` +
|
|
86
|
+
`${form.api} ${form.failed} ENOTDIR, and force: true also ignores a missing path.`;
|
|
87
|
+
}
|
|
@@ -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 {Expression, J} from "@openrewrite/rewrite/java";
|
|
7
|
+
import {JS} from "@openrewrite/rewrite/javascript";
|
|
8
|
+
import {isObjectLiteral} from "./fs-extra/fs-extra-support";
|
|
9
|
+
|
|
10
|
+
/** The expression under any parentheses and TypeScript casts (`as`, `<T>`, `satisfies`). */
|
|
11
|
+
export function withoutCasts(e: J | undefined): J | undefined {
|
|
12
|
+
for (;;) {
|
|
13
|
+
switch (e?.kind) {
|
|
14
|
+
case J.Kind.Parentheses:
|
|
15
|
+
e = (e as J.Parentheses<J>).tree.element;
|
|
16
|
+
break;
|
|
17
|
+
case JS.Kind.As:
|
|
18
|
+
e = (e as JS.As).left.element;
|
|
19
|
+
break;
|
|
20
|
+
case J.Kind.TypeCast:
|
|
21
|
+
e = (e as J.TypeCast).expression;
|
|
22
|
+
break;
|
|
23
|
+
case JS.Kind.SatisfiesExpression:
|
|
24
|
+
e = (e as JS.SatisfiesExpression).expression;
|
|
25
|
+
break;
|
|
26
|
+
default:
|
|
27
|
+
return e;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The object literal an options argument is written as, under any parentheses and casts, or
|
|
34
|
+
* undefined when the argument is anything else, such as a variable.
|
|
35
|
+
*/
|
|
36
|
+
export function optionsLiteral(arg: J | undefined): J.NewClass | undefined {
|
|
37
|
+
const e = withoutCasts(arg);
|
|
38
|
+
return isObjectLiteral(e) ? e : undefined;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** `arg` with the object literal {@link optionsLiteral} finds in it replaced by `literal`, its parentheses and casts kept. */
|
|
42
|
+
export function withOptionsLiteral(arg: J, literal: J.NewClass): J {
|
|
43
|
+
switch (arg.kind) {
|
|
44
|
+
case J.Kind.Parentheses: {
|
|
45
|
+
const parentheses = arg as J.Parentheses<J>;
|
|
46
|
+
return {
|
|
47
|
+
...parentheses,
|
|
48
|
+
tree: {...parentheses.tree, element: withOptionsLiteral(parentheses.tree.element, literal)}
|
|
49
|
+
} as J.Parentheses<J>;
|
|
50
|
+
}
|
|
51
|
+
case JS.Kind.As: {
|
|
52
|
+
const as = arg as JS.As;
|
|
53
|
+
return {...as, left: {...as.left, element: withOptionsLiteral(as.left.element, literal) as Expression}} as JS.As;
|
|
54
|
+
}
|
|
55
|
+
case J.Kind.TypeCast: {
|
|
56
|
+
const cast = arg as J.TypeCast;
|
|
57
|
+
return {...cast, expression: withOptionsLiteral(cast.expression, literal) as Expression} as J.TypeCast;
|
|
58
|
+
}
|
|
59
|
+
case JS.Kind.SatisfiesExpression: {
|
|
60
|
+
const satisfies = arg as JS.SatisfiesExpression;
|
|
61
|
+
return {...satisfies, expression: withOptionsLiteral(satisfies.expression, literal)} as JS.SatisfiesExpression;
|
|
62
|
+
}
|
|
63
|
+
default:
|
|
64
|
+
return literal;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -13,9 +13,13 @@ import {ReplaceServerResponseWriteHeader} from "./server-response-write-header";
|
|
|
13
13
|
import {FindAeadDecipherivWithoutAuthTagLength} from "./find-aead-decipheriv-without-auth-tag-length";
|
|
14
14
|
import {FindDuplexToWebType} from "./find-duplex-to-web-type";
|
|
15
15
|
import {FindModuleRegister} from "./find-module-register";
|
|
16
|
+
import {FindFsRmdirRecursive} from "./find-fs-rmdir-recursive";
|
|
17
|
+
import {ReplaceRsaPssKeyPairOptions} from "./crypto-rsa-pss-key-pair-options";
|
|
16
18
|
|
|
17
|
-
// Node 26 End-of-Life deprecations (
|
|
19
|
+
// Node 26 End-of-Life deprecations (includes v25 EOL)
|
|
18
20
|
const node26EolDeprecations: Recipe[] = [
|
|
21
|
+
new FindFsRmdirRecursive(), // DEP0147: fs.rmdir(path, { recursive: true }) (v25 EOL)
|
|
22
|
+
new ReplaceRsaPssKeyPairOptions(), // DEP0154: RSA-PSS hash and mgf1Hash options (v25 EOL)
|
|
19
23
|
new ReplaceServerResponseWriteHeader(), // DEP0063: ServerResponse.writeHeader() (v26 EOL)
|
|
20
24
|
new ReplaceStreamInternalModules(), // DEP0125: legacy _stream_* modules (v26 EOL)
|
|
21
25
|
new FindAeadDecipherivWithoutAuthTagLength(), // DEP0182: short GCM auth tags (v26 EOL)
|