@openrewrite/recipes-nodejs 0.36.0-20251209-170730 → 0.36.0-20251210-140320
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.
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ExecutionContext, Recipe, TreeVisitor } from "@openrewrite/rewrite";
|
|
2
|
+
export declare class ReplaceTimersEnroll extends Recipe {
|
|
3
|
+
readonly name = "org.openrewrite.node.migrate.timers.replace-timers-enroll";
|
|
4
|
+
readonly displayName: string;
|
|
5
|
+
readonly description: string;
|
|
6
|
+
readonly tags: string[];
|
|
7
|
+
editor(): Promise<TreeVisitor<any, ExecutionContext>>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=timers-enroll.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timers-enroll.d.ts","sourceRoot":"","sources":["../../src/migrate/timers-enroll.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAE,MAAM,EAAE,WAAW,EAAC,MAAM,sBAAsB,CAAC;AAI3E,qBAAa,mBAAoB,SAAQ,MAAM;IAC3C,QAAQ,CAAC,IAAI,+DAA8D;IAC3E,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAkE;IAC9F,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAiK;IAC7L,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,CAA0B;IAE3C,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;CA4G9D"}
|
|
@@ -0,0 +1,132 @@
|
|
|
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.ReplaceTimersEnroll = 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 ReplaceTimersEnroll extends rewrite_1.Recipe {
|
|
17
|
+
constructor() {
|
|
18
|
+
super(...arguments);
|
|
19
|
+
this.name = "org.openrewrite.node.migrate.timers.replace-timers-enroll";
|
|
20
|
+
this.displayName = "Replace deprecated `timers.enroll()` and `timers.unenroll()`";
|
|
21
|
+
this.description = "Replace deprecated `timers.enroll(item, msecs)` with `setTimeout(item._onTimeout.bind(item), msecs)` and `timers.unenroll(item)` with `clearTimeout(item)`.";
|
|
22
|
+
this.tags = ["DEP0095", "DEP0096"];
|
|
23
|
+
}
|
|
24
|
+
editor() {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
return new class extends javascript_1.JavaScriptVisitor {
|
|
27
|
+
constructor() {
|
|
28
|
+
super(...arguments);
|
|
29
|
+
this.timersNamespaceAlias = null;
|
|
30
|
+
this.hasEnrollImport = false;
|
|
31
|
+
this.hasUnenrollImport = false;
|
|
32
|
+
}
|
|
33
|
+
visitImportDeclaration(jsImport, p) {
|
|
34
|
+
const _super = Object.create(null, {
|
|
35
|
+
visitImportDeclaration: { get: () => super.visitImportDeclaration }
|
|
36
|
+
});
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
const imp = yield _super.visitImportDeclaration.call(this, jsImport, p);
|
|
39
|
+
if (!imp.moduleSpecifier) {
|
|
40
|
+
return imp;
|
|
41
|
+
}
|
|
42
|
+
const moduleSpec = imp.moduleSpecifier.element;
|
|
43
|
+
if (moduleSpec.kind === java_1.J.Kind.Literal) {
|
|
44
|
+
const moduleName = moduleSpec.value;
|
|
45
|
+
if (moduleName === "timers" || moduleName === "node:timers") {
|
|
46
|
+
const importClause = imp.importClause;
|
|
47
|
+
if (importClause) {
|
|
48
|
+
const namedBindings = importClause.namedBindings;
|
|
49
|
+
if ((namedBindings === null || namedBindings === void 0 ? void 0 : namedBindings.kind) === javascript_1.JS.Kind.Alias) {
|
|
50
|
+
const alias = namedBindings;
|
|
51
|
+
if (alias.alias.kind === java_1.J.Kind.Identifier) {
|
|
52
|
+
this.timersNamespaceAlias = alias.alias.simpleName;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if ((namedBindings === null || namedBindings === void 0 ? void 0 : namedBindings.kind) === javascript_1.JS.Kind.NamedImports) {
|
|
56
|
+
const namedImports = namedBindings;
|
|
57
|
+
for (const binding of namedImports.elements.elements) {
|
|
58
|
+
const specifier = binding.element;
|
|
59
|
+
if (specifier.specifier.kind === java_1.J.Kind.Identifier) {
|
|
60
|
+
const name = specifier.specifier.simpleName;
|
|
61
|
+
if (name === "enroll") {
|
|
62
|
+
this.hasEnrollImport = true;
|
|
63
|
+
}
|
|
64
|
+
if (name === "unenroll") {
|
|
65
|
+
this.hasUnenrollImport = true;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return imp;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
visitMethodInvocation(m, p) {
|
|
77
|
+
const _super = Object.create(null, {
|
|
78
|
+
visitMethodInvocation: { get: () => super.visitMethodInvocation }
|
|
79
|
+
});
|
|
80
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
const method = yield _super.visitMethodInvocation.call(this, m, p);
|
|
82
|
+
const methodName = method.name.simpleName;
|
|
83
|
+
const args = method.arguments.elements;
|
|
84
|
+
const isEnroll = methodName === "enroll" && args.length === 2;
|
|
85
|
+
const isUnenroll = methodName === "unenroll" && args.length === 1;
|
|
86
|
+
if (!isEnroll && !isUnenroll) {
|
|
87
|
+
return method;
|
|
88
|
+
}
|
|
89
|
+
let isTimersMethod = false;
|
|
90
|
+
if (method.select && this.timersNamespaceAlias) {
|
|
91
|
+
const select = method.select.element;
|
|
92
|
+
if (select.kind === java_1.J.Kind.Identifier) {
|
|
93
|
+
const selectName = select.simpleName;
|
|
94
|
+
if (selectName === this.timersNamespaceAlias) {
|
|
95
|
+
isTimersMethod = true;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (!method.select) {
|
|
100
|
+
if (isEnroll && this.hasEnrollImport) {
|
|
101
|
+
isTimersMethod = true;
|
|
102
|
+
}
|
|
103
|
+
if (isUnenroll && this.hasUnenrollImport) {
|
|
104
|
+
isTimersMethod = true;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (isTimersMethod) {
|
|
108
|
+
(0, javascript_1.maybeRemoveImport)(this, "timers");
|
|
109
|
+
(0, javascript_1.maybeRemoveImport)(this, "node:timers");
|
|
110
|
+
(0, javascript_1.maybeRemoveImport)(this, "timers", "enroll");
|
|
111
|
+
(0, javascript_1.maybeRemoveImport)(this, "node:timers", "enroll");
|
|
112
|
+
(0, javascript_1.maybeRemoveImport)(this, "timers", "unenroll");
|
|
113
|
+
(0, javascript_1.maybeRemoveImport)(this, "node:timers", "unenroll");
|
|
114
|
+
if (isEnroll) {
|
|
115
|
+
const item = args[0].element;
|
|
116
|
+
const msecs = args[1].element;
|
|
117
|
+
return yield (0, javascript_1.template) `setTimeout(${item}._onTimeout.bind(${item}), ${msecs})`.apply(method, this.cursor);
|
|
118
|
+
}
|
|
119
|
+
if (isUnenroll) {
|
|
120
|
+
const item = args[0].element;
|
|
121
|
+
return yield (0, javascript_1.template) `clearTimeout(${item})`.apply(method, this.cursor);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return method;
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
exports.ReplaceTimersEnroll = ReplaceTimersEnroll;
|
|
132
|
+
//# sourceMappingURL=timers-enroll.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timers-enroll.js","sourceRoot":"","sources":["../../src/migrate/timers-enroll.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAA2E;AAC3E,gEAAmG;AACnG,oDAA4C;AAE5C,MAAa,mBAAoB,SAAQ,gBAAM;IAA/C;;QACa,SAAI,GAAG,2DAA2D,CAAA;QAClE,gBAAW,GAAW,8DAA8D,CAAC;QACrF,gBAAW,GAAW,6JAA6J,CAAC;QACpL,SAAI,GAAa,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IA8GrD,CAAC;IA5GS,MAAM;;YACR,OAAO,IAAI,KAAM,SAAQ,8BAAmC;gBAAjD;;oBACC,yBAAoB,GAAkB,IAAI,CAAC;oBAC3C,oBAAe,GAAG,KAAK,CAAC;oBACxB,sBAAiB,GAAG,KAAK,CAAC;gBAsGtC,CAAC;gBApGmB,sBAAsB,CAAC,QAAmB,EAAE,CAAmB;;;;;wBAC3E,MAAM,GAAG,GAAG,MAAM,OAAM,sBAAsB,YAAC,QAAQ,EAAE,CAAC,CAAc,CAAC;wBAEzE,IAAI,CAAC,GAAG,CAAC,eAAe,EAAE,CAAC;4BACvB,OAAO,GAAG,CAAC;wBACf,CAAC;wBAED,MAAM,UAAU,GAAG,GAAG,CAAC,eAAe,CAAC,OAAO,CAAC;wBAC/C,IAAI,UAAU,CAAC,IAAI,KAAK,QAAC,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;4BACrC,MAAM,UAAU,GAAI,UAAwB,CAAC,KAAe,CAAC;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nodejs",
|
|
3
|
-
"version": "0.36.0-
|
|
3
|
+
"version": "0.36.0-20251210-140320",
|
|
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",
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import {ExecutionContext, Recipe, TreeVisitor} from "@openrewrite/rewrite";
|
|
2
|
+
import {JavaScriptVisitor, JS, maybeRemoveImport, template} from "@openrewrite/rewrite/javascript";
|
|
3
|
+
import {J} from "@openrewrite/rewrite/java";
|
|
4
|
+
|
|
5
|
+
export class ReplaceTimersEnroll extends Recipe {
|
|
6
|
+
readonly name = "org.openrewrite.node.migrate.timers.replace-timers-enroll"
|
|
7
|
+
readonly displayName: string = "Replace deprecated `timers.enroll()` and `timers.unenroll()`";
|
|
8
|
+
readonly description: string = "Replace deprecated `timers.enroll(item, msecs)` with `setTimeout(item._onTimeout.bind(item), msecs)` and `timers.unenroll(item)` with `clearTimeout(item)`.";
|
|
9
|
+
readonly tags: string[] = ["DEP0095", "DEP0096"];
|
|
10
|
+
|
|
11
|
+
async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
12
|
+
return new class extends JavaScriptVisitor<ExecutionContext> {
|
|
13
|
+
private timersNamespaceAlias: string | null = null;
|
|
14
|
+
private hasEnrollImport = false;
|
|
15
|
+
private hasUnenrollImport = false;
|
|
16
|
+
|
|
17
|
+
protected async visitImportDeclaration(jsImport: JS.Import, p: ExecutionContext): Promise<J | undefined> {
|
|
18
|
+
const imp = await super.visitImportDeclaration(jsImport, p) as JS.Import;
|
|
19
|
+
|
|
20
|
+
if (!imp.moduleSpecifier) {
|
|
21
|
+
return imp;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const moduleSpec = imp.moduleSpecifier.element;
|
|
25
|
+
if (moduleSpec.kind === J.Kind.Literal) {
|
|
26
|
+
const moduleName = (moduleSpec as J.Literal).value as string;
|
|
27
|
+
if (moduleName === "timers" || moduleName === "node:timers") {
|
|
28
|
+
const importClause = imp.importClause;
|
|
29
|
+
if (importClause) {
|
|
30
|
+
const namedBindings = importClause.namedBindings;
|
|
31
|
+
|
|
32
|
+
if (namedBindings?.kind === JS.Kind.Alias) {
|
|
33
|
+
const alias = namedBindings as JS.Alias;
|
|
34
|
+
if (alias.alias.kind === J.Kind.Identifier) {
|
|
35
|
+
this.timersNamespaceAlias = (alias.alias as J.Identifier).simpleName;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (namedBindings?.kind === JS.Kind.NamedImports) {
|
|
40
|
+
const namedImports = namedBindings as JS.NamedImports;
|
|
41
|
+
for (const binding of namedImports.elements.elements) {
|
|
42
|
+
const specifier = binding.element;
|
|
43
|
+
if (specifier.specifier.kind === J.Kind.Identifier) {
|
|
44
|
+
const name = (specifier.specifier as J.Identifier).simpleName;
|
|
45
|
+
if (name === "enroll") {
|
|
46
|
+
this.hasEnrollImport = true;
|
|
47
|
+
}
|
|
48
|
+
if (name === "unenroll") {
|
|
49
|
+
this.hasUnenrollImport = true;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return imp;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
protected async visitMethodInvocation(m: J.MethodInvocation, p: ExecutionContext): Promise<J | undefined> {
|
|
62
|
+
const method = await super.visitMethodInvocation(m, p) as J.MethodInvocation;
|
|
63
|
+
|
|
64
|
+
const methodName = method.name.simpleName;
|
|
65
|
+
const args = method.arguments.elements;
|
|
66
|
+
|
|
67
|
+
const isEnroll = methodName === "enroll" && args.length === 2;
|
|
68
|
+
const isUnenroll = methodName === "unenroll" && args.length === 1;
|
|
69
|
+
|
|
70
|
+
if (!isEnroll && !isUnenroll) {
|
|
71
|
+
return method;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
let isTimersMethod = false;
|
|
75
|
+
|
|
76
|
+
if (method.select && this.timersNamespaceAlias) {
|
|
77
|
+
const select = method.select.element;
|
|
78
|
+
if (select.kind === J.Kind.Identifier) {
|
|
79
|
+
const selectName = (select as J.Identifier).simpleName;
|
|
80
|
+
if (selectName === this.timersNamespaceAlias) {
|
|
81
|
+
isTimersMethod = true;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (!method.select) {
|
|
87
|
+
if (isEnroll && this.hasEnrollImport) {
|
|
88
|
+
isTimersMethod = true;
|
|
89
|
+
}
|
|
90
|
+
if (isUnenroll && this.hasUnenrollImport) {
|
|
91
|
+
isTimersMethod = true;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (isTimersMethod) {
|
|
96
|
+
maybeRemoveImport(this, "timers");
|
|
97
|
+
maybeRemoveImport(this, "node:timers");
|
|
98
|
+
maybeRemoveImport(this, "timers", "enroll");
|
|
99
|
+
maybeRemoveImport(this, "node:timers", "enroll");
|
|
100
|
+
maybeRemoveImport(this, "timers", "unenroll");
|
|
101
|
+
maybeRemoveImport(this, "node:timers", "unenroll");
|
|
102
|
+
|
|
103
|
+
if (isEnroll) {
|
|
104
|
+
const item = args[0].element;
|
|
105
|
+
const msecs = args[1].element;
|
|
106
|
+
return await template`setTimeout(${item}._onTimeout.bind(${item}), ${msecs})`.apply(method, this.cursor);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (isUnenroll) {
|
|
110
|
+
const item = args[0].element;
|
|
111
|
+
return await template`clearTimeout(${item})`.apply(method, this.cursor);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return method;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|