@openrewrite/recipes-nodejs 0.30.0-20251001-192216
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 +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/migrate/util-type-checking.d.ts +8 -0
- package/dist/migrate/util-type-checking.d.ts.map +1 -0
- package/dist/migrate/util-type-checking.js +120 -0
- package/dist/migrate/util-type-checking.js.map +1 -0
- package/package.json +38 -0
- package/src/index.ts +0 -0
- package/src/migrate/util-type-checking.ts +90 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ExecutionContext, Recipe, TreeVisitor } from "@openrewrite/rewrite";
|
|
2
|
+
export declare class UseNativeTypeCheckingMethods extends Recipe {
|
|
3
|
+
readonly name = "org.openrewrite.node.migrate.util.UseNativeTypeCheckingMethods";
|
|
4
|
+
readonly displayName: string;
|
|
5
|
+
readonly description: string;
|
|
6
|
+
editor(): Promise<TreeVisitor<any, ExecutionContext>>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=util-type-checking.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util-type-checking.d.ts","sourceRoot":"","sources":["../../src/migrate/util-type-checking.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,gBAAgB,EAAE,MAAM,EAAE,WAAW,EAAC,MAAM,sBAAsB,CAAC;AAUlF,qBAAa,4BAA6B,SAAQ,MAAM;IACpD,QAAQ,CAAC,IAAI,oEAAmE;IAChF,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAoE;IAChG,QAAQ,CAAC,WAAW,EAAE,MAAM,CAA6E;IAEnG,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;CA0E9D"}
|
|
@@ -0,0 +1,120 @@
|
|
|
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.UseNativeTypeCheckingMethods = void 0;
|
|
13
|
+
const rewrite_1 = require("@openrewrite/rewrite");
|
|
14
|
+
const javascript_1 = require("@openrewrite/rewrite/javascript");
|
|
15
|
+
class UseNativeTypeCheckingMethods extends rewrite_1.Recipe {
|
|
16
|
+
constructor() {
|
|
17
|
+
super(...arguments);
|
|
18
|
+
this.name = "org.openrewrite.node.migrate.util.UseNativeTypeCheckingMethods";
|
|
19
|
+
this.displayName = "Replace deprecated `util.isX()` methods with native JavaScript";
|
|
20
|
+
this.description = "The `util` module's type-checking methods have been removed in Node 22.";
|
|
21
|
+
}
|
|
22
|
+
editor() {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
return (0, rewrite_1.check)((0, javascript_1.usesMethod)("util is*(..)"), new class extends javascript_1.JavaScriptVisitor {
|
|
25
|
+
constructor() {
|
|
26
|
+
super(...arguments);
|
|
27
|
+
this.isUtil = new javascript_1.MethodMatcher("util is*(..)");
|
|
28
|
+
this.isArray = new javascript_1.MethodMatcher("util isArray(..)");
|
|
29
|
+
this.isBoolean = new javascript_1.MethodMatcher("util isBoolean(..)");
|
|
30
|
+
this.isBuffer = new javascript_1.MethodMatcher("util isBuffer(..)");
|
|
31
|
+
this.isDate = new javascript_1.MethodMatcher("util isDate(..)");
|
|
32
|
+
this.isError = new javascript_1.MethodMatcher("util isError(..)");
|
|
33
|
+
this.isFunction = new javascript_1.MethodMatcher("util isFunction(..)");
|
|
34
|
+
this.isNull = new javascript_1.MethodMatcher("util isNull(..)");
|
|
35
|
+
this.isNullOrUndefined = new javascript_1.MethodMatcher("util isNullOrUndefined(..)");
|
|
36
|
+
this.isNumber = new javascript_1.MethodMatcher("util isNumber(..)");
|
|
37
|
+
this.isObject = new javascript_1.MethodMatcher("util isObject(..)");
|
|
38
|
+
this.isPrimitive = new javascript_1.MethodMatcher("util isPrimitive(..)");
|
|
39
|
+
this.isRegExp = new javascript_1.MethodMatcher("util isRegExp(..)");
|
|
40
|
+
this.isString = new javascript_1.MethodMatcher("util isString(..)");
|
|
41
|
+
this.isSymbol = new javascript_1.MethodMatcher("util isSymbol(..)");
|
|
42
|
+
this.isUndefined = new javascript_1.MethodMatcher("util isUndefined(..)");
|
|
43
|
+
}
|
|
44
|
+
visitMethodInvocation(method, p) {
|
|
45
|
+
const _super = Object.create(null, {
|
|
46
|
+
visitMethodInvocation: { get: () => super.visitMethodInvocation }
|
|
47
|
+
});
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
if (this.isUtil.matches(method.methodType)) {
|
|
50
|
+
const arg = method.arguments.elements[0].element;
|
|
51
|
+
if (this.isArray.matches(method.methodType)) {
|
|
52
|
+
(0, javascript_1.maybeRemoveImport)(this, "util", "isArray");
|
|
53
|
+
return (0, javascript_1.template) `Array.isArray(${arg})`.apply(this.cursor, method);
|
|
54
|
+
}
|
|
55
|
+
else if (this.isBoolean.matches(method.methodType)) {
|
|
56
|
+
(0, javascript_1.maybeRemoveImport)(this, "util", "isBoolean");
|
|
57
|
+
return (0, javascript_1.template) `typeof ${arg} === 'boolean'`.apply(this.cursor, method);
|
|
58
|
+
}
|
|
59
|
+
else if (this.isBuffer.matches(method.methodType)) {
|
|
60
|
+
(0, javascript_1.maybeRemoveImport)(this, "util", "isBuffer");
|
|
61
|
+
return (0, javascript_1.template) `Buffer.isBuffer(${arg})`.apply(this.cursor, method);
|
|
62
|
+
}
|
|
63
|
+
else if (this.isDate.matches(method.methodType)) {
|
|
64
|
+
(0, javascript_1.maybeRemoveImport)(this, "util", "isDate");
|
|
65
|
+
return (0, javascript_1.template) `${arg} instanceof Date`.apply(this.cursor, method);
|
|
66
|
+
}
|
|
67
|
+
else if (this.isError.matches(method.methodType)) {
|
|
68
|
+
(0, javascript_1.maybeRemoveImport)(this, "util", "isError");
|
|
69
|
+
return (0, javascript_1.template) `${arg} instanceof Error`.apply(this.cursor, method);
|
|
70
|
+
}
|
|
71
|
+
else if (this.isFunction.matches(method.methodType)) {
|
|
72
|
+
(0, javascript_1.maybeRemoveImport)(this, "util", "isFunction");
|
|
73
|
+
return (0, javascript_1.template) `typeof (${arg}) === 'function'`.apply(this.cursor, method);
|
|
74
|
+
}
|
|
75
|
+
else if (this.isNull.matches(method.methodType)) {
|
|
76
|
+
(0, javascript_1.maybeRemoveImport)(this, "util", "isNull");
|
|
77
|
+
return (0, javascript_1.template) `${arg} === null`.apply(this.cursor, method);
|
|
78
|
+
}
|
|
79
|
+
else if (this.isNullOrUndefined.matches(method.methodType)) {
|
|
80
|
+
(0, javascript_1.maybeRemoveImport)(this, "util", "isNullOrUndefined");
|
|
81
|
+
return (0, javascript_1.template) `${arg} == null`.apply(this.cursor, method);
|
|
82
|
+
}
|
|
83
|
+
else if (this.isNumber.matches(method.methodType)) {
|
|
84
|
+
(0, javascript_1.maybeRemoveImport)(this, "util", "isNumber");
|
|
85
|
+
return (0, javascript_1.template) `typeof ${arg} === 'number'`.apply(this.cursor, method);
|
|
86
|
+
}
|
|
87
|
+
else if (this.isObject.matches(method.methodType)) {
|
|
88
|
+
(0, javascript_1.maybeRemoveImport)(this, "util", "isObject");
|
|
89
|
+
return (0, javascript_1.template) `typeof ${arg} === 'object' && ${arg} !== null`.apply(this.cursor, method);
|
|
90
|
+
}
|
|
91
|
+
else if (this.isPrimitive.matches(method.methodType)) {
|
|
92
|
+
(0, javascript_1.maybeRemoveImport)(this, "util", "isPrimitive");
|
|
93
|
+
return (0, javascript_1.template) `${arg} !== Object(${arg})`.apply(this.cursor, method);
|
|
94
|
+
}
|
|
95
|
+
else if (this.isRegExp.matches(method.methodType)) {
|
|
96
|
+
(0, javascript_1.maybeRemoveImport)(this, "util", "isRegExp");
|
|
97
|
+
return (0, javascript_1.template) `${arg} instanceof RegExp`.apply(this.cursor, method);
|
|
98
|
+
}
|
|
99
|
+
else if (this.isString.matches(method.methodType)) {
|
|
100
|
+
(0, javascript_1.maybeRemoveImport)(this, "util", "isString");
|
|
101
|
+
return (0, javascript_1.template) `typeof ${arg} === 'string'`.apply(this.cursor, method);
|
|
102
|
+
}
|
|
103
|
+
else if (this.isSymbol.matches(method.methodType)) {
|
|
104
|
+
(0, javascript_1.maybeRemoveImport)(this, "util", "isSymbol");
|
|
105
|
+
return (0, javascript_1.template) `typeof ${arg} === 'symbol'`.apply(this.cursor, method);
|
|
106
|
+
}
|
|
107
|
+
else if (this.isUndefined.matches(method.methodType)) {
|
|
108
|
+
(0, javascript_1.maybeRemoveImport)(this, "util", "isUndefined");
|
|
109
|
+
return (0, javascript_1.template) `${arg} === undefined`.apply(this.cursor, method);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return _super.visitMethodInvocation.call(this, method, p);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
exports.UseNativeTypeCheckingMethods = UseNativeTypeCheckingMethods;
|
|
120
|
+
//# sourceMappingURL=util-type-checking.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util-type-checking.js","sourceRoot":"","sources":["../../src/migrate/util-type-checking.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAAkF;AAClF,gEAMyC;AAGzC,MAAa,4BAA6B,SAAQ,gBAAM;IAAxD;;QACa,SAAI,GAAG,gEAAgE,CAAA;QACvE,gBAAW,GAAW,gEAAgE,CAAC;QACvF,gBAAW,GAAW,yEAAyE,CAAC;IA4E7G,CAAC;IA1ES,MAAM;;YACR,OAAO,IAAA,eAAK,EAAC,IAAA,uBAAU,EAAC,cAAc,CAAC,EAAE,IAAI,KAAM,SAAQ,8BAAmC;gBAAjD;;oBACzC,WAAM,GAAG,IAAI,0BAAa,CAAC,cAAc,CAAC,CAAC;oBAC3C,YAAO,GAAG,IAAI,0BAAa,CAAC,kBAAkB,CAAC,CAAC;oBAChD,cAAS,GAAG,IAAI,0BAAa,CAAC,oBAAoB,CAAC,CAAC;oBACpD,aAAQ,GAAG,IAAI,0BAAa,CAAC,mBAAmB,CAAC,CAAC;oBAClD,WAAM,GAAG,IAAI,0BAAa,CAAC,iBAAiB,CAAC,CAAC;oBAC9C,YAAO,GAAG,IAAI,0BAAa,CAAC,kBAAkB,CAAC,CAAC;oBAChD,eAAU,GAAG,IAAI,0BAAa,CAAC,qBAAqB,CAAC,CAAC;oBACtD,WAAM,GAAG,IAAI,0BAAa,CAAC,iBAAiB,CAAC,CAAC;oBAC9C,sBAAiB,GAAG,IAAI,0BAAa,CAAC,4BAA4B,CAAC,CAAC;oBACpE,aAAQ,GAAG,IAAI,0BAAa,CAAC,mBAAmB,CAAC,CAAC;oBAClD,aAAQ,GAAG,IAAI,0BAAa,CAAC,mBAAmB,CAAC,CAAC;oBAClD,gBAAW,GAAG,IAAI,0BAAa,CAAC,sBAAsB,CAAC,CAAC;oBACxD,aAAQ,GAAG,IAAI,0BAAa,CAAC,mBAAmB,CAA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|
2
|
+
"name": "@openrewrite/recipes-nodejs",
|
|
3
|
+
"version": "0.30.0-20251001-192216",
|
|
4
|
+
"license": "Moderne Source Available License",
|
|
5
|
+
"description": "OpenRewrite recipes for Node.js library migrations.",
|
|
6
|
+
"homepage": "https://github.com/moderneinc/rewrite-node",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist/**",
|
|
11
|
+
"src/**"
|
|
12
|
+
],
|
|
13
|
+
"exports": {
|
|
14
|
+
".": "./dist/index.js"
|
|
15
|
+
},
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "rm -rf ./dist tsconfig.build.tsbuildinfo && tsc --build tsconfig.build.json",
|
|
21
|
+
"dev": "tsc --watch -p tsconfig.json",
|
|
22
|
+
"test": "npm run build && jest",
|
|
23
|
+
"ci:test": "jest"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@openrewrite/rewrite": "^8.63.0-20251001-160804"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/jest": "^29.5.13",
|
|
30
|
+
"@types/node": "^22.5.4",
|
|
31
|
+
"jest": "^29.7.0",
|
|
32
|
+
"jest-junit": "^16.0.0",
|
|
33
|
+
"tmp-promise": "^3.0.3",
|
|
34
|
+
"ts-jest": "^29.2.5",
|
|
35
|
+
"ts-node": "^10.9.2",
|
|
36
|
+
"typescript": "^5.6.2"
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/index.ts
ADDED
|
File without changes
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import {check, ExecutionContext, Recipe, TreeVisitor} from "@openrewrite/rewrite";
|
|
2
|
+
import {
|
|
3
|
+
JavaScriptVisitor,
|
|
4
|
+
maybeRemoveImport,
|
|
5
|
+
MethodMatcher,
|
|
6
|
+
template,
|
|
7
|
+
usesMethod
|
|
8
|
+
} from "@openrewrite/rewrite/javascript";
|
|
9
|
+
import {J} from "@openrewrite/rewrite/java";
|
|
10
|
+
|
|
11
|
+
export class UseNativeTypeCheckingMethods extends Recipe {
|
|
12
|
+
readonly name = "org.openrewrite.node.migrate.util.UseNativeTypeCheckingMethods"
|
|
13
|
+
readonly displayName: string = "Replace deprecated `util.isX()` methods with native JavaScript";
|
|
14
|
+
readonly description: string = "The `util` module's type-checking methods have been removed in Node 22.";
|
|
15
|
+
|
|
16
|
+
async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
17
|
+
return check(usesMethod("util is*(..)"), new class extends JavaScriptVisitor<ExecutionContext> {
|
|
18
|
+
isUtil = new MethodMatcher("util is*(..)");
|
|
19
|
+
isArray = new MethodMatcher("util isArray(..)");
|
|
20
|
+
isBoolean = new MethodMatcher("util isBoolean(..)");
|
|
21
|
+
isBuffer = new MethodMatcher("util isBuffer(..)");
|
|
22
|
+
isDate = new MethodMatcher("util isDate(..)");
|
|
23
|
+
isError = new MethodMatcher("util isError(..)");
|
|
24
|
+
isFunction = new MethodMatcher("util isFunction(..)");
|
|
25
|
+
isNull = new MethodMatcher("util isNull(..)");
|
|
26
|
+
isNullOrUndefined = new MethodMatcher("util isNullOrUndefined(..)");
|
|
27
|
+
isNumber = new MethodMatcher("util isNumber(..)");
|
|
28
|
+
isObject = new MethodMatcher("util isObject(..)");
|
|
29
|
+
isPrimitive = new MethodMatcher("util isPrimitive(..)");
|
|
30
|
+
isRegExp = new MethodMatcher("util isRegExp(..)");
|
|
31
|
+
isString = new MethodMatcher("util isString(..)");
|
|
32
|
+
isSymbol = new MethodMatcher("util isSymbol(..)");
|
|
33
|
+
isUndefined = new MethodMatcher("util isUndefined(..)");
|
|
34
|
+
|
|
35
|
+
protected async visitMethodInvocation(method: J.MethodInvocation, p: ExecutionContext): Promise<J | undefined> {
|
|
36
|
+
if (this.isUtil.matches(method.methodType)) {
|
|
37
|
+
const arg = method.arguments.elements[0].element;
|
|
38
|
+
|
|
39
|
+
if (this.isArray.matches(method.methodType)) {
|
|
40
|
+
maybeRemoveImport(this, "util", "isArray")
|
|
41
|
+
return template`Array.isArray(${arg})`.apply(this.cursor, method);
|
|
42
|
+
} else if (this.isBoolean.matches(method.methodType)) {
|
|
43
|
+
maybeRemoveImport(this, "util", "isBoolean")
|
|
44
|
+
return template`typeof ${arg} === 'boolean'`.apply(this.cursor, method);
|
|
45
|
+
} else if (this.isBuffer.matches(method.methodType)) {
|
|
46
|
+
maybeRemoveImport(this, "util", "isBuffer")
|
|
47
|
+
return template`Buffer.isBuffer(${arg})`.apply(this.cursor, method);
|
|
48
|
+
} else if (this.isDate.matches(method.methodType)) {
|
|
49
|
+
maybeRemoveImport(this, "util", "isDate")
|
|
50
|
+
return template`${arg} instanceof Date`.apply(this.cursor, method);
|
|
51
|
+
} else if (this.isError.matches(method.methodType)) {
|
|
52
|
+
maybeRemoveImport(this, "util", "isError")
|
|
53
|
+
return template`${arg} instanceof Error`.apply(this.cursor, method);
|
|
54
|
+
} else if (this.isFunction.matches(method.methodType)) {
|
|
55
|
+
maybeRemoveImport(this, "util", "isFunction")
|
|
56
|
+
return template`typeof (${arg}) === 'function'`.apply(this.cursor, method);
|
|
57
|
+
} else if (this.isNull.matches(method.methodType)) {
|
|
58
|
+
maybeRemoveImport(this, "util", "isNull")
|
|
59
|
+
return template`${arg} === null`.apply(this.cursor, method);
|
|
60
|
+
} else if (this.isNullOrUndefined.matches(method.methodType)) {
|
|
61
|
+
maybeRemoveImport(this, "util", "isNullOrUndefined")
|
|
62
|
+
return template`${arg} == null`.apply(this.cursor, method);
|
|
63
|
+
} else if (this.isNumber.matches(method.methodType)) {
|
|
64
|
+
maybeRemoveImport(this, "util", "isNumber")
|
|
65
|
+
return template`typeof ${arg} === 'number'`.apply(this.cursor, method);
|
|
66
|
+
} else if (this.isObject.matches(method.methodType)) {
|
|
67
|
+
maybeRemoveImport(this, "util", "isObject")
|
|
68
|
+
return template`typeof ${arg} === 'object' && ${arg} !== null`.apply(this.cursor, method);
|
|
69
|
+
} else if (this.isPrimitive.matches(method.methodType)) {
|
|
70
|
+
maybeRemoveImport(this, "util", "isPrimitive")
|
|
71
|
+
return template`${arg} !== Object(${arg})`.apply(this.cursor, method);
|
|
72
|
+
} else if (this.isRegExp.matches(method.methodType)) {
|
|
73
|
+
maybeRemoveImport(this, "util", "isRegExp")
|
|
74
|
+
return template`${arg} instanceof RegExp`.apply(this.cursor, method);
|
|
75
|
+
} else if (this.isString.matches(method.methodType)) {
|
|
76
|
+
maybeRemoveImport(this, "util", "isString")
|
|
77
|
+
return template`typeof ${arg} === 'string'`.apply(this.cursor, method);
|
|
78
|
+
} else if (this.isSymbol.matches(method.methodType)) {
|
|
79
|
+
maybeRemoveImport(this, "util", "isSymbol")
|
|
80
|
+
return template`typeof ${arg} === 'symbol'`.apply(this.cursor, method);
|
|
81
|
+
} else if (this.isUndefined.matches(method.methodType)) {
|
|
82
|
+
maybeRemoveImport(this, "util", "isUndefined")
|
|
83
|
+
return template`${arg} === undefined`.apply(this.cursor, method);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return super.visitMethodInvocation(method, p);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|