@openrewrite/recipes-nodejs 0.33.0-20251027-170349 → 0.33.0-20251029-223605
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/buffer-slice.d.ts +9 -0
- package/dist/migrate/buffer-slice.d.ts.map +1 -0
- package/dist/migrate/buffer-slice.js +61 -0
- package/dist/migrate/buffer-slice.js.map +1 -0
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/migrate/buffer-slice.ts +43 -0
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,cAAc,EAAC,MAAM,sBAAsB,CAAC;AAGpD,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,cAAc,QAGhD"}
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.activate = activate;
|
|
4
4
|
const util_type_checking_1 = require("./migrate/util-type-checking");
|
|
5
|
+
const buffer_slice_1 = require("./migrate/buffer-slice");
|
|
5
6
|
function activate(registry) {
|
|
6
7
|
registry.register(util_type_checking_1.UseNativeTypeCheckingMethods);
|
|
8
|
+
registry.register(buffer_slice_1.ReplaceDeprecatedBufferSlice);
|
|
7
9
|
}
|
|
8
10
|
//# 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":";;AAKA,4BAGC;AARD,qEAA0E;AAC1E,yDAAoE;AAIpE,SAAgB,QAAQ,CAAC,QAAwB;IAC7C,QAAQ,CAAC,QAAQ,CAAC,iDAA4B,CAAC,CAAC;IAChD,QAAQ,CAAC,QAAQ,CAAC,2CAA4B,CAAC,CAAC;AACpD,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ExecutionContext, Recipe, TreeVisitor } from "@openrewrite/rewrite";
|
|
2
|
+
export declare class ReplaceDeprecatedBufferSlice extends Recipe {
|
|
3
|
+
readonly name = "org.openrewrite.node.migrate.buffer.replace-deprecated-slice";
|
|
4
|
+
readonly displayName: string;
|
|
5
|
+
readonly description: string;
|
|
6
|
+
readonly tags: string[];
|
|
7
|
+
editor(): Promise<TreeVisitor<any, ExecutionContext>>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=buffer-slice.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buffer-slice.d.ts","sourceRoot":"","sources":["../../src/migrate/buffer-slice.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,gBAAgB,EAAE,MAAM,EAAE,WAAW,EAAC,MAAM,sBAAsB,CAAC;AAUlF,qBAAa,4BAA6B,SAAQ,MAAM;IACpD,QAAQ,CAAC,IAAI,kEAAiE;IAC9E,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAkE;IAC9F,QAAQ,CAAC,WAAW,EAAE,MAAM,CAA6H;IACzJ,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,CAAe;IAEhC,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;CA0B9D"}
|
|
@@ -0,0 +1,61 @@
|
|
|
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.ReplaceDeprecatedBufferSlice = void 0;
|
|
13
|
+
const rewrite_1 = require("@openrewrite/rewrite");
|
|
14
|
+
const javascript_1 = require("@openrewrite/rewrite/javascript");
|
|
15
|
+
class ReplaceDeprecatedBufferSlice extends rewrite_1.Recipe {
|
|
16
|
+
constructor() {
|
|
17
|
+
super(...arguments);
|
|
18
|
+
this.name = "org.openrewrite.node.migrate.buffer.replace-deprecated-slice";
|
|
19
|
+
this.displayName = "Replace deprecated `Buffer.slice()` with `Buffer.subarray()`";
|
|
20
|
+
this.description = "Replace deprecated `buffer.slice()` calls with `buffer.subarray()` for compatibility with Uint8Array.prototype.slice().";
|
|
21
|
+
this.tags = ["DEP0158"];
|
|
22
|
+
}
|
|
23
|
+
editor() {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
return (0, rewrite_1.check)((0, javascript_1.usesMethod)("Buffer slice(..)"), new class extends javascript_1.JavaScriptVisitor {
|
|
26
|
+
constructor() {
|
|
27
|
+
super(...arguments);
|
|
28
|
+
this.sliceMatcher = new javascript_1.MethodMatcher("Buffer slice(..)");
|
|
29
|
+
}
|
|
30
|
+
visitMethodInvocation(method, p) {
|
|
31
|
+
const _super = Object.create(null, {
|
|
32
|
+
visitMethodInvocation: { get: () => super.visitMethodInvocation }
|
|
33
|
+
});
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
if (this.sliceMatcher.matches(method.methodType)) {
|
|
36
|
+
if (method.select) {
|
|
37
|
+
const selectExpr = method.select.element;
|
|
38
|
+
const args = method.arguments.elements;
|
|
39
|
+
if (args.length === 0) {
|
|
40
|
+
return yield (0, javascript_1.template) `${selectExpr}.subarray()`.apply(this.cursor, method);
|
|
41
|
+
}
|
|
42
|
+
else if (args.length === 1) {
|
|
43
|
+
const arg0 = args[0].element;
|
|
44
|
+
return yield (0, javascript_1.template) `${selectExpr}.subarray(${arg0})`.apply(this.cursor, method);
|
|
45
|
+
}
|
|
46
|
+
else if (args.length >= 2) {
|
|
47
|
+
const arg0 = args[0].element;
|
|
48
|
+
const arg1 = args[1].element;
|
|
49
|
+
return yield (0, javascript_1.template) `${selectExpr}.subarray(${arg0}, ${arg1})`.apply(this.cursor, method);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return _super.visitMethodInvocation.call(this, method, p);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.ReplaceDeprecatedBufferSlice = ReplaceDeprecatedBufferSlice;
|
|
61
|
+
//# sourceMappingURL=buffer-slice.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buffer-slice.js","sourceRoot":"","sources":["../../src/migrate/buffer-slice.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAAkF;AAClF,gEAAuG;AASvG,MAAa,4BAA6B,SAAQ,gBAAM;IAAxD;;QACa,SAAI,GAAG,8DAA8D,CAAA;QACrE,gBAAW,GAAW,8DAA8D,CAAC;QACrF,gBAAW,GAAW,yHAAyH,CAAC;QAChJ,SAAI,GAAa,CAAC,SAAS,CAAC,CAAC;IA4B1C,CAAC;IA1BS,MAAM;;YACR,OAAO,IAAA,eAAK,EAAC,IAAA,uBAAU,EAAC,kBAAkB,CAAC,EAAE,IAAI,KAAM,SAAQ,8BAAmC;gBAAjD;;oBAC7C,iBAAY,GAAG,IAAI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C,EAAE;oBAClD,CAAC;iBAAA;aACJ,CAAC,CAAC;QACP,CAAC;KAAA;CACJ;AAhCD,oEAgCC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openrewrite/recipes-nodejs",
|
|
3
|
-
"version": "0.33.0-
|
|
3
|
+
"version": "0.33.0-20251029-223605",
|
|
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
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import {UseNativeTypeCheckingMethods} from "./migrate/util-type-checking";
|
|
2
|
+
import {ReplaceDeprecatedBufferSlice} from "./migrate/buffer-slice";
|
|
2
3
|
import {RecipeRegistry} from "@openrewrite/rewrite";
|
|
3
4
|
|
|
4
5
|
|
|
5
6
|
export function activate(registry: RecipeRegistry) {
|
|
6
7
|
registry.register(UseNativeTypeCheckingMethods);
|
|
8
|
+
registry.register(ReplaceDeprecatedBufferSlice);
|
|
7
9
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {check, ExecutionContext, Recipe, TreeVisitor} from "@openrewrite/rewrite";
|
|
2
|
+
import {JavaScriptVisitor, MethodMatcher, template, usesMethod} from "@openrewrite/rewrite/javascript";
|
|
3
|
+
import {J, TypedTree} from "@openrewrite/rewrite/java";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Replace deprecated Buffer.slice() with Buffer.subarray()
|
|
7
|
+
*
|
|
8
|
+
* DEP0158: buffer.slice(start, end) was deprecated because it is not compatible
|
|
9
|
+
* with Uint8Array.prototype.slice(), which is a superclass of Buffer.
|
|
10
|
+
*/
|
|
11
|
+
export class ReplaceDeprecatedBufferSlice extends Recipe {
|
|
12
|
+
readonly name = "org.openrewrite.node.migrate.buffer.replace-deprecated-slice"
|
|
13
|
+
readonly displayName: string = "Replace deprecated `Buffer.slice()` with `Buffer.subarray()`";
|
|
14
|
+
readonly description: string = "Replace deprecated `buffer.slice()` calls with `buffer.subarray()` for compatibility with Uint8Array.prototype.slice().";
|
|
15
|
+
readonly tags: string[] = ["DEP0158"];
|
|
16
|
+
|
|
17
|
+
async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
18
|
+
return check(usesMethod("Buffer slice(..)"), new class extends JavaScriptVisitor<ExecutionContext> {
|
|
19
|
+
sliceMatcher = new MethodMatcher("Buffer slice(..)");
|
|
20
|
+
|
|
21
|
+
protected async visitMethodInvocation(method: J.MethodInvocation, p: ExecutionContext): Promise<J | undefined> {
|
|
22
|
+
if (this.sliceMatcher.matches(method.methodType)) {
|
|
23
|
+
if (method.select) {
|
|
24
|
+
const selectExpr = method.select.element;
|
|
25
|
+
const args = method.arguments.elements;
|
|
26
|
+
|
|
27
|
+
if (args.length === 0) {
|
|
28
|
+
return await template`${selectExpr}.subarray()`.apply(this.cursor, method);
|
|
29
|
+
} else if (args.length === 1) {
|
|
30
|
+
const arg0 = args[0].element;
|
|
31
|
+
return await template`${selectExpr}.subarray(${arg0})`.apply(this.cursor, method);
|
|
32
|
+
} else if (args.length >= 2) {
|
|
33
|
+
const arg0 = args[0].element;
|
|
34
|
+
const arg1 = args[1].element;
|
|
35
|
+
return await template`${selectExpr}.subarray(${arg0}, ${arg1})`.apply(this.cursor, method);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return super.visitMethodInvocation(method, p);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|