@openrewrite/recipes-nodejs 0.35.0-20251120-170459 → 0.35.0-20251121-142457
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 +2 -0
- package/dist/index.js.map +1 -1
- package/dist/migrate/promisify-on-promise.d.ts +9 -0
- package/dist/migrate/promisify-on-promise.d.ts.map +1 -0
- package/dist/migrate/promisify-on-promise.js +107 -0
- package/dist/migrate/promisify-on-promise.js.map +1 -0
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/migrate/promisify-on-promise.ts +99 -0
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,cAAc,EAAC,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,cAAc,EAAC,MAAM,sBAAsB,CAAC;AAWpD,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,cAAc,QAWhD"}
|
package/dist/index.js
CHANGED
|
@@ -10,6 +10,7 @@ const util_extend_1 = require("./migrate/util-extend");
|
|
|
10
10
|
const crypto_fips_1 = require("./migrate/crypto-fips");
|
|
11
11
|
const slow_buffer_1 = require("./migrate/slow-buffer");
|
|
12
12
|
const fs_access_constants_1 = require("./migrate/fs-access-constants");
|
|
13
|
+
const promisify_on_promise_1 = require("./migrate/promisify-on-promise");
|
|
13
14
|
function activate(registry) {
|
|
14
15
|
registry.register(util_type_checking_1.UseNativeTypeCheckingMethods);
|
|
15
16
|
registry.register(buffer_slice_1.ReplaceDeprecatedBufferSlice);
|
|
@@ -20,5 +21,6 @@ function activate(registry) {
|
|
|
20
21
|
registry.register(crypto_fips_1.ReplaceCryptoFips);
|
|
21
22
|
registry.register(slow_buffer_1.ReplaceSlowBuffer);
|
|
22
23
|
registry.register(fs_access_constants_1.ReplaceFsAccessConstants);
|
|
24
|
+
registry.register(promisify_on_promise_1.RemovePromisifyOnPromise);
|
|
23
25
|
}
|
|
24
26
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAaA,4BAWC;AAxBD,qEAA0E;AAC1E,yDAAoE;AAEpE,yEAAwF;AACxF,uEAAwE;AACxE,iDAAkD;AAClD,uDAAwD;AACxD,uDAAwD;AACxD,uDAAwD;AACxD,uEAAuE;AACvE,yEAAwE;AAGxE,SAAgB,QAAQ,CAAC,QAAwB;IAC7C,QAAQ,CAAC,QAAQ,CAAC,iDAA4B,CAAC,CAAC;IAChD,QAAQ,CAAC,QAAQ,CAAC,2CAA4B,CAAC,CAAC;IAChD,QAAQ,CAAC,QAAQ,CAAC,+DAAwC,CAAC,CAAC;IAC5D,QAAQ,CAAC,QAAQ,CAAC,+CAAyB,CAAC,CAAC;IAC7C,QAAQ,CAAC,QAAQ,CAAC,yBAAc,CAAC,CAAC;IAClC,QAAQ,CAAC,QAAQ,CAAC,+BAAiB,CAAC,CAAC;IACrC,QAAQ,CAAC,QAAQ,CAAC,+BAAiB,CAAC,CAAC;IACrC,QAAQ,CAAC,QAAQ,CAAC,+BAAiB,CAAC,CAAC;IACrC,QAAQ,CAAC,QAAQ,CAAC,8CAAwB,CAAC,CAAC;IAC5C,QAAQ,CAAC,QAAQ,CAAC,+CAAwB,CAAC,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ExecutionContext, Recipe, TreeVisitor } from "@openrewrite/rewrite";
|
|
2
|
+
export declare class RemovePromisifyOnPromise extends Recipe {
|
|
3
|
+
readonly name = "org.openrewrite.node.migrate.util.remove-promisify-on-promise";
|
|
4
|
+
readonly displayName: string;
|
|
5
|
+
readonly description: string;
|
|
6
|
+
readonly tags: string[];
|
|
7
|
+
editor(): Promise<TreeVisitor<any, ExecutionContext>>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=promisify-on-promise.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promisify-on-promise.d.ts","sourceRoot":"","sources":["../../src/migrate/promisify-on-promise.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,gBAAgB,EAAE,MAAM,EAAE,WAAW,EAAC,MAAM,sBAAsB,CAAC;AAOlF,qBAAa,wBAAyB,SAAQ,MAAM;IAChD,QAAQ,CAAC,IAAI,mEAAkE;IAC/E,QAAQ,CAAC,WAAW,EAAE,MAAM,CAA0E;IACtG,QAAQ,CAAC,WAAW,EAAE,MAAM,CACuG;IACnI,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,CAAe;IAEhC,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;CAoF9D"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.RemovePromisifyOnPromise = void 0;
|
|
13
|
+
const rewrite_1 = require("@openrewrite/rewrite");
|
|
14
|
+
const javascript_1 = require("@openrewrite/rewrite/javascript");
|
|
15
|
+
const java_1 = require("@openrewrite/rewrite/java");
|
|
16
|
+
class RemovePromisifyOnPromise extends rewrite_1.Recipe {
|
|
17
|
+
constructor() {
|
|
18
|
+
super(...arguments);
|
|
19
|
+
this.name = "org.openrewrite.node.migrate.util.remove-promisify-on-promise";
|
|
20
|
+
this.displayName = "Remove unnecessary `util.promisify()` on Promise-returning functions";
|
|
21
|
+
this.description = "Removes `util.promisify()` calls on functions that already return a Promise. " +
|
|
22
|
+
"Since Node.js v17.0.0, calling promisify on a function that returns a Promise emits a runtime deprecation warning (DEP0174).";
|
|
23
|
+
this.tags = ["DEP0174"];
|
|
24
|
+
}
|
|
25
|
+
editor() {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
return (0, rewrite_1.check)((0, javascript_1.usesMethod)("util promisify(..)"), new class extends javascript_1.JavaScriptVisitor {
|
|
28
|
+
constructor() {
|
|
29
|
+
super(...arguments);
|
|
30
|
+
this.promisifyMatcher = new javascript_1.MethodMatcher("util promisify(..)");
|
|
31
|
+
}
|
|
32
|
+
visitMethodInvocation(m, p) {
|
|
33
|
+
const _super = Object.create(null, {
|
|
34
|
+
visitMethodInvocation: { get: () => super.visitMethodInvocation }
|
|
35
|
+
});
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
const method = yield _super.visitMethodInvocation.call(this, m, p);
|
|
38
|
+
if (this.promisifyMatcher.matches(method.methodType)) {
|
|
39
|
+
const args = method.arguments.elements;
|
|
40
|
+
if (args.length === 1) {
|
|
41
|
+
const arg = args[0].element;
|
|
42
|
+
if (this.isAsyncOrPromiseReturning(arg)) {
|
|
43
|
+
(0, javascript_1.maybeRemoveImport)(this, "util");
|
|
44
|
+
(0, javascript_1.maybeRemoveImport)(this, "util", "promisify");
|
|
45
|
+
return Object.assign(Object.assign({}, arg), { prefix: method.prefix });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return method;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
isAsyncOrPromiseReturning(expr) {
|
|
53
|
+
if (expr.kind === javascript_1.JS.Kind.ArrowFunction) {
|
|
54
|
+
const arrowFunc = expr;
|
|
55
|
+
if (this.hasAsyncModifier(arrowFunc.modifiers)) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
if (arrowFunc.returnTypeExpression && this.isPromiseTyped(arrowFunc.returnTypeExpression)) {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (expr.kind === javascript_1.JS.Kind.StatementExpression) {
|
|
63
|
+
const stmtExpr = expr;
|
|
64
|
+
return this.isAsyncOrPromiseReturning(stmtExpr.statement);
|
|
65
|
+
}
|
|
66
|
+
if (expr.kind === java_1.J.Kind.MethodDeclaration) {
|
|
67
|
+
const methodDecl = expr;
|
|
68
|
+
if (this.hasAsyncModifier(methodDecl.modifiers)) {
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if ('type' in expr && expr.type) {
|
|
73
|
+
const type = expr.type;
|
|
74
|
+
if (type.kind === java_1.Type.Kind.Method) {
|
|
75
|
+
const methodType = type;
|
|
76
|
+
if (this.isPromiseTyped(methodType.returnType)) {
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else if (type.kind === java_1.Type.Kind.Class) {
|
|
81
|
+
const clazz = type;
|
|
82
|
+
if (clazz.fullyQualifiedName == "𝑓" && clazz.methods.length == 1 && this.isPromiseTyped(clazz.methods[0].returnType)) {
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
hasAsyncModifier(modifiers) {
|
|
90
|
+
return modifiers.some(mod => mod.type === "Async" ||
|
|
91
|
+
(mod.type === "LanguageExtension" && mod.keyword === "async"));
|
|
92
|
+
}
|
|
93
|
+
isPromiseTyped(type) {
|
|
94
|
+
if (type && type.kind === java_1.Type.Kind.Parameterized) {
|
|
95
|
+
const paramType = type;
|
|
96
|
+
if (paramType.type.kind == java_1.Type.Kind.Class && paramType.type.fullyQualifiedName == "Promise") {
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
exports.RemovePromisifyOnPromise = RemovePromisifyOnPromise;
|
|
107
|
+
//# sourceMappingURL=promisify-on-promise.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promisify-on-promise.js","sourceRoot":"","sources":["../../src/migrate/promisify-on-promise.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAAkF;AAClF,gEAAoH;AACpH,oDAAkD;AAKlD,MAAa,wBAAyB,SAAQ,gBAAM;IAApD;;QACa,SAAI,GAAG,+DAA+D,CAAA;QACtE,gBAAW,GAAW,sEAAsE,CAAC;QAC7F,gBAAW,GAAW,+EAA+E;YAC1G,8HAA8H,CAAC;QAC1H,SAAI,GAAa,CAAC,SAAS,CAAC,CAAC;IAsF1C,CAAC;IApFS,MAAM;;YACR,OAAO,IAAA,eAAK,EAAC,IAAA,uBAAU,EAAC,oBAAoB,CAAC,EAAE,IAAI,KAAM,SAAQ,8BAAmC;gBAAjD;;oBAC/C,qBAAgB,GAAG,IAAI,0BAAa,CAAC,oBAAoB,CAAC,CAAC;gBAgF/D,CAAC;gBA9EmB,qBAAqB,CAAC,CAAqB,EAAE,CAAmB;;;;;wBAC5E,MAAM,MAAM,GAAG,MAAM,OAAM,qBAAqB,YAAC,CAAC,EAAE,CAAC,CAAuB,CAAC;wBAC7E,IAAI,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,MAAM,CAAC,UAA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IAAI,CAAC,IAAI,KAAK,WAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;wBAChD,MAAM,SAAS,GAAG,IAA0B,CAAC;wBAC7C,IAAI,SAAS,CAAC,IAAI,CAAC,IAAI,IAAI,WAAI,CAAC,IAAI,CAAC,KAAK,IAAK,SAAS,CAAC,IAAmB,CAAC,kBAAkB,IAAI,SAAS,EAAE,CAAC;4BAC3G,OAAO,IAAI,CAAC;wBAChB,CAAC;oBACL,CAAC;oBACD,OAAO,KAAK,CAAC;gBACjB,CAAC;aACJ,CAAC,CAAC;QACP,CAAC;KAAA;CACJ;AA3FD,4DA2FC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openrewrite/recipes-nodejs",
|
|
3
|
-
"version": "0.35.0-
|
|
3
|
+
"version": "0.35.0-20251121-142457",
|
|
4
4
|
"license": "Moderne Source Available License",
|
|
5
5
|
"description": "OpenRewrite recipes for Node.js library migrations.",
|
|
6
6
|
"homepage": "https://github.com/moderneinc/rewrite-node",
|
package/src/index.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {ReplaceUtilExtend} from "./migrate/util-extend";
|
|
|
8
8
|
import {ReplaceCryptoFips} from "./migrate/crypto-fips";
|
|
9
9
|
import {ReplaceSlowBuffer} from "./migrate/slow-buffer";
|
|
10
10
|
import {ReplaceFsAccessConstants} from "./migrate/fs-access-constants";
|
|
11
|
+
import {RemovePromisifyOnPromise} from "./migrate/promisify-on-promise";
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
export function activate(registry: RecipeRegistry) {
|
|
@@ -20,4 +21,5 @@ export function activate(registry: RecipeRegistry) {
|
|
|
20
21
|
registry.register(ReplaceCryptoFips);
|
|
21
22
|
registry.register(ReplaceSlowBuffer);
|
|
22
23
|
registry.register(ReplaceFsAccessConstants);
|
|
24
|
+
registry.register(RemovePromisifyOnPromise);
|
|
23
25
|
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import {check, ExecutionContext, Recipe, TreeVisitor} from "@openrewrite/rewrite";
|
|
2
|
+
import {JavaScriptVisitor, JS, maybeRemoveImport, MethodMatcher, usesMethod} from "@openrewrite/rewrite/javascript";
|
|
3
|
+
import {J, Type} from "@openrewrite/rewrite/java";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Removes unnecessary util.promisify() calls on functions that already return a Promise.
|
|
7
|
+
*/
|
|
8
|
+
export class RemovePromisifyOnPromise extends Recipe {
|
|
9
|
+
readonly name = "org.openrewrite.node.migrate.util.remove-promisify-on-promise"
|
|
10
|
+
readonly displayName: string = "Remove unnecessary `util.promisify()` on Promise-returning functions";
|
|
11
|
+
readonly description: string = "Removes `util.promisify()` calls on functions that already return a Promise. " +
|
|
12
|
+
"Since Node.js v17.0.0, calling promisify on a function that returns a Promise emits a runtime deprecation warning (DEP0174).";
|
|
13
|
+
readonly tags: string[] = ["DEP0174"];
|
|
14
|
+
|
|
15
|
+
async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
16
|
+
return check(usesMethod("util promisify(..)"), new class extends JavaScriptVisitor<ExecutionContext> {
|
|
17
|
+
promisifyMatcher = new MethodMatcher("util promisify(..)");
|
|
18
|
+
|
|
19
|
+
protected async visitMethodInvocation(m: J.MethodInvocation, p: ExecutionContext): Promise<J | undefined> {
|
|
20
|
+
const method = await super.visitMethodInvocation(m, p) as J.MethodInvocation;
|
|
21
|
+
if (this.promisifyMatcher.matches(method.methodType)) {
|
|
22
|
+
const args = method.arguments.elements;
|
|
23
|
+
if (args.length === 1) {
|
|
24
|
+
const arg = args[0].element;
|
|
25
|
+
if (this.isAsyncOrPromiseReturning(arg)) {
|
|
26
|
+
maybeRemoveImport(this, "util");
|
|
27
|
+
maybeRemoveImport(this, "util", "promisify");
|
|
28
|
+
return {
|
|
29
|
+
...arg,
|
|
30
|
+
prefix: method.prefix
|
|
31
|
+
} as J;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return method;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private isAsyncOrPromiseReturning(expr: J): boolean {
|
|
39
|
+
if (expr.kind === JS.Kind.ArrowFunction) {
|
|
40
|
+
const arrowFunc = expr as JS.ArrowFunction;
|
|
41
|
+
if (this.hasAsyncModifier(arrowFunc.modifiers)) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
if (arrowFunc.returnTypeExpression && this.isPromiseTyped(arrowFunc.returnTypeExpression)) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (expr.kind === JS.Kind.StatementExpression) {
|
|
50
|
+
const stmtExpr = expr as JS.StatementExpression;
|
|
51
|
+
return this.isAsyncOrPromiseReturning(stmtExpr.statement as J);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (expr.kind === J.Kind.MethodDeclaration) {
|
|
55
|
+
const methodDecl = expr as J.MethodDeclaration;
|
|
56
|
+
if (this.hasAsyncModifier(methodDecl.modifiers)) {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Looks pretty ugly to check the `type` property. We know upfront for what subclasses we define a `type` property,
|
|
62
|
+
// the problem is it's like ~50 of them.
|
|
63
|
+
if ('type' in expr && expr.type) {
|
|
64
|
+
const type = expr.type as Type;
|
|
65
|
+
if (type.kind === Type.Kind.Method) {
|
|
66
|
+
const methodType = type as Type.Method;
|
|
67
|
+
if (this.isPromiseTyped(methodType.returnType)) {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
} else if (type.kind === Type.Kind.Class) {
|
|
71
|
+
const clazz = type as Type.Class;
|
|
72
|
+
if (clazz.fullyQualifiedName == "𝑓" && clazz.methods.length == 1 && this.isPromiseTyped(clazz.methods[0].returnType)) {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private hasAsyncModifier(modifiers: J.Modifier[]): boolean {
|
|
82
|
+
return modifiers.some(mod =>
|
|
83
|
+
mod.type === J.ModifierType.Async ||
|
|
84
|
+
(mod.type === J.ModifierType.LanguageExtension && mod.keyword === "async")
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private isPromiseTyped(type: Type): boolean {
|
|
89
|
+
if (type && type.kind === Type.Kind.Parameterized) {
|
|
90
|
+
const paramType = type as Type.Parameterized;
|
|
91
|
+
if (paramType.type.kind == Type.Kind.Class && (paramType.type as Type.Class).fullyQualifiedName == "Promise") {
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|