@openrewrite/recipes-nodejs 0.37.0-20251219-122858 → 0.37.0-20251219-170437
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/stream-internal-modules.d.ts +9 -0
- package/dist/migrate/stream-internal-modules.d.ts.map +1 -0
- package/dist/migrate/stream-internal-modules.js +110 -0
- package/dist/migrate/stream-internal-modules.js.map +1 -0
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/migrate/stream-internal-modules.ts +94 -0
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,sBAAsB,CAAC;AA0BpD,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,cAAc,QAwBhD"}
|
package/dist/index.js
CHANGED
|
@@ -19,6 +19,7 @@ const zlib_bytes_read_1 = require("./migrate/zlib-bytes-read");
|
|
|
19
19
|
const fs_truncate_1 = require("./migrate/fs-truncate");
|
|
20
20
|
const outgoing_message_headers_1 = require("./migrate/outgoing-message-headers");
|
|
21
21
|
const tls_internal_modules_1 = require("./migrate/tls-internal-modules");
|
|
22
|
+
const stream_internal_modules_1 = require("./migrate/stream-internal-modules");
|
|
22
23
|
const net_set_simultaneous_accepts_1 = require("./migrate/net-set-simultaneous-accepts");
|
|
23
24
|
const upgrade_node_22_1 = require("./migrate/upgrade-node-22");
|
|
24
25
|
const upgrade_node_24_1 = require("./migrate/upgrade-node-24");
|
|
@@ -42,6 +43,7 @@ function activate(registry) {
|
|
|
42
43
|
registry.register(fs_truncate_1.ReplaceFsTruncateWithFd);
|
|
43
44
|
registry.register(outgoing_message_headers_1.ReplaceOutgoingMessageHeaders);
|
|
44
45
|
registry.register(tls_internal_modules_1.ReplaceTlsInternalModules);
|
|
46
|
+
registry.register(stream_internal_modules_1.ReplaceStreamInternalModules);
|
|
45
47
|
registry.register(net_set_simultaneous_accepts_1.RemoveNetSetSimultaneousAccepts);
|
|
46
48
|
registry.register(upgrade_node_22_1.UpgradeNode22);
|
|
47
49
|
registry.register(upgrade_node_24_1.UpgradeNode24);
|
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":";;AA0BA,4BAwBC;AAjDD,qEAA0E;AAC1E,yDAAoE;AACpE,yEAAwF;AACxF,uEAAwE;AACxE,iDAAkD;AAClD,uDAAwD;AACxD,yEAAyE;AACzE,uDAAwD;AACxD,uDAAwD;AACxD,uEAAuE;AACvE,yEAAwE;AACxE,mEAA4E;AAC5E,uDAAwD;AACxD,+DAA6E;AAC7E,+DAA+D;AAC/D,uDAA8D;AAC9D,iFAAiF;AACjF,yEAAyE;AACzE,+EAA+E;AAC/E,yFAAuF;AACvF,+DAAwD;AACxD,+DAAwD;AACxD,yCAAwD;AAGxD,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,gDAAyB,CAAC,CAAC;IAC7C,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;IAC5C,QAAQ,CAAC,QAAQ,CAAC,mDAA+B,CAAC,CAAC;IACnD,QAAQ,CAAC,QAAQ,CAAC,+BAAiB,CAAC,CAAC;IACrC,QAAQ,CAAC,QAAQ,CAAC,oDAAkC,CAAC,CAAC;IACtD,QAAQ,CAAC,QAAQ,CAAC,sCAAoB,CAAC,CAAC;IACxC,QAAQ,CAAC,QAAQ,CAAC,qCAAuB,CAAC,CAAC;IAC3C,QAAQ,CAAC,QAAQ,CAAC,wDAA6B,CAAC,CAAC;IACjD,QAAQ,CAAC,QAAQ,CAAC,gDAAyB,CAAC,CAAC;IAC7C,QAAQ,CAAC,QAAQ,CAAC,sDAA4B,CAAC,CAAC;IAChD,QAAQ,CAAC,QAAQ,CAAC,8DAA+B,CAAC,CAAC;IACnD,QAAQ,CAAC,QAAQ,CAAC,+BAAa,CAAC,CAAC;IACjC,QAAQ,CAAC,QAAQ,CAAC,+BAAa,CAAC,CAAC;IACjC,QAAQ,CAAC,QAAQ,CAAC,uCAA4B,CAAC,CAAC;AACpD,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ExecutionContext, Recipe, TreeVisitor } from "@openrewrite/rewrite";
|
|
2
|
+
export declare class ReplaceStreamInternalModules extends Recipe {
|
|
3
|
+
readonly name = "org.openrewrite.node.migrate.stream.replace-internal-modules";
|
|
4
|
+
readonly displayName: string;
|
|
5
|
+
readonly description: string;
|
|
6
|
+
readonly tags: string[];
|
|
7
|
+
editor(): Promise<TreeVisitor<any, ExecutionContext>>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=stream-internal-modules.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-internal-modules.d.ts","sourceRoot":"","sources":["../../src/migrate/stream-internal-modules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAgB,MAAM,EAAE,WAAW,EAAC,MAAM,sBAAsB,CAAC;AAKzF,qBAAa,4BAA6B,SAAQ,MAAM;IACpD,QAAQ,CAAC,IAAI,kEAAiE;IAC9E,QAAQ,CAAC,WAAW,EAAE,MAAM,CAA4D;IACxF,QAAQ,CAAC,WAAW,EAAE,MAAM,CACgB;IAC5C,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,CAAe;IAEhC,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;CAiF9D"}
|
|
@@ -0,0 +1,110 @@
|
|
|
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.ReplaceStreamInternalModules = 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 ReplaceStreamInternalModules extends rewrite_1.Recipe {
|
|
17
|
+
constructor() {
|
|
18
|
+
super(...arguments);
|
|
19
|
+
this.name = "org.openrewrite.node.migrate.stream.replace-internal-modules";
|
|
20
|
+
this.displayName = "Replace deprecated `node:_stream_*` with `node:stream`";
|
|
21
|
+
this.description = "Replace deprecated internal stream module imports like `require('node:_stream_readable')` " +
|
|
22
|
+
"with the public `node:stream` module.";
|
|
23
|
+
this.tags = ["DEP0193"];
|
|
24
|
+
}
|
|
25
|
+
editor() {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
return new class extends javascript_1.JavaScriptVisitor {
|
|
28
|
+
constructor() {
|
|
29
|
+
super(...arguments);
|
|
30
|
+
this.deprecatedModules = new Set([
|
|
31
|
+
"node:_stream_duplex",
|
|
32
|
+
"node:_stream_passthrough",
|
|
33
|
+
"node:_stream_readable",
|
|
34
|
+
"node:_stream_transform",
|
|
35
|
+
"node:_stream_wrap",
|
|
36
|
+
"node:_stream_writable",
|
|
37
|
+
"_stream_duplex",
|
|
38
|
+
"_stream_passthrough",
|
|
39
|
+
"_stream_readable",
|
|
40
|
+
"_stream_transform",
|
|
41
|
+
"_stream_wrap",
|
|
42
|
+
"_stream_writable"
|
|
43
|
+
]);
|
|
44
|
+
}
|
|
45
|
+
getReplacement(moduleName) {
|
|
46
|
+
if (moduleName.startsWith("node:")) {
|
|
47
|
+
return "node:stream";
|
|
48
|
+
}
|
|
49
|
+
return "stream";
|
|
50
|
+
}
|
|
51
|
+
visitImportDeclaration(jsImport, p) {
|
|
52
|
+
const _super = Object.create(null, {
|
|
53
|
+
visitImportDeclaration: { get: () => super.visitImportDeclaration }
|
|
54
|
+
});
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
const imp = yield _super.visitImportDeclaration.call(this, jsImport, p);
|
|
57
|
+
if (!imp.moduleSpecifier) {
|
|
58
|
+
return imp;
|
|
59
|
+
}
|
|
60
|
+
const moduleSpec = imp.moduleSpecifier.element;
|
|
61
|
+
if (moduleSpec.kind === java_1.J.Kind.Literal) {
|
|
62
|
+
const literal = moduleSpec;
|
|
63
|
+
const moduleName = literal.value;
|
|
64
|
+
if (this.deprecatedModules.has(moduleName)) {
|
|
65
|
+
const replacement = this.getReplacement(moduleName);
|
|
66
|
+
return (0, rewrite_1.produceAsync)(imp, (draft) => __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
const litDraft = draft.moduleSpecifier.element;
|
|
68
|
+
litDraft.value = replacement;
|
|
69
|
+
litDraft.valueSource = `'${replacement}'`;
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return imp;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
visitMethodInvocation(method, p) {
|
|
77
|
+
const _super = Object.create(null, {
|
|
78
|
+
visitMethodInvocation: { get: () => super.visitMethodInvocation }
|
|
79
|
+
});
|
|
80
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
const m = yield _super.visitMethodInvocation.call(this, method, p);
|
|
82
|
+
if (m.name.simpleName !== "require") {
|
|
83
|
+
return m;
|
|
84
|
+
}
|
|
85
|
+
const args = m.arguments.elements;
|
|
86
|
+
if (args.length !== 1) {
|
|
87
|
+
return m;
|
|
88
|
+
}
|
|
89
|
+
const arg = args[0].element;
|
|
90
|
+
if (arg.kind === java_1.J.Kind.Literal) {
|
|
91
|
+
const literal = arg;
|
|
92
|
+
const moduleName = literal.value;
|
|
93
|
+
if (this.deprecatedModules.has(moduleName)) {
|
|
94
|
+
const replacement = this.getReplacement(moduleName);
|
|
95
|
+
return (0, rewrite_1.produceAsync)(m, (draft) => __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
const litDraft = draft.arguments.elements[0].element;
|
|
97
|
+
litDraft.value = replacement;
|
|
98
|
+
litDraft.valueSource = `'${replacement}'`;
|
|
99
|
+
}));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return m;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.ReplaceStreamInternalModules = ReplaceStreamInternalModules;
|
|
110
|
+
//# sourceMappingURL=stream-internal-modules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-internal-modules.js","sourceRoot":"","sources":["../../src/migrate/stream-internal-modules.ts"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openrewrite/recipes-nodejs",
|
|
3
|
-
"version": "0.37.0-20251219-
|
|
3
|
+
"version": "0.37.0-20251219-170437",
|
|
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
|
@@ -17,6 +17,7 @@ import {ReplaceZlibBytesRead} from "./migrate/zlib-bytes-read";
|
|
|
17
17
|
import {ReplaceFsTruncateWithFd} from "./migrate/fs-truncate";
|
|
18
18
|
import {ReplaceOutgoingMessageHeaders} from "./migrate/outgoing-message-headers";
|
|
19
19
|
import {ReplaceTlsInternalModules} from "./migrate/tls-internal-modules";
|
|
20
|
+
import {ReplaceStreamInternalModules} from "./migrate/stream-internal-modules";
|
|
20
21
|
import {RemoveNetSetSimultaneousAccepts} from "./migrate/net-set-simultaneous-accepts";
|
|
21
22
|
import {UpgradeNode22} from "./migrate/upgrade-node-22";
|
|
22
23
|
import {UpgradeNode24} from "./migrate/upgrade-node-24";
|
|
@@ -42,6 +43,7 @@ export function activate(registry: RecipeRegistry) {
|
|
|
42
43
|
registry.register(ReplaceFsTruncateWithFd);
|
|
43
44
|
registry.register(ReplaceOutgoingMessageHeaders);
|
|
44
45
|
registry.register(ReplaceTlsInternalModules);
|
|
46
|
+
registry.register(ReplaceStreamInternalModules);
|
|
45
47
|
registry.register(RemoveNetSetSimultaneousAccepts);
|
|
46
48
|
registry.register(UpgradeNode22);
|
|
47
49
|
registry.register(UpgradeNode24);
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import {ExecutionContext, produceAsync, Recipe, TreeVisitor} from "@openrewrite/rewrite";
|
|
2
|
+
import {JavaScriptVisitor, JS} from "@openrewrite/rewrite/javascript";
|
|
3
|
+
import {J} from "@openrewrite/rewrite/java";
|
|
4
|
+
import {Draft} from "immer";
|
|
5
|
+
|
|
6
|
+
export class ReplaceStreamInternalModules extends Recipe {
|
|
7
|
+
readonly name = "org.openrewrite.node.migrate.stream.replace-internal-modules"
|
|
8
|
+
readonly displayName: string = "Replace deprecated `node:_stream_*` with `node:stream`";
|
|
9
|
+
readonly description: string = "Replace deprecated internal stream module imports like `require('node:_stream_readable')` " +
|
|
10
|
+
"with the public `node:stream` module.";
|
|
11
|
+
readonly tags: string[] = ["DEP0193"];
|
|
12
|
+
|
|
13
|
+
async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
14
|
+
return new class extends JavaScriptVisitor<ExecutionContext> {
|
|
15
|
+
|
|
16
|
+
private readonly deprecatedModules = new Set([
|
|
17
|
+
"node:_stream_duplex",
|
|
18
|
+
"node:_stream_passthrough",
|
|
19
|
+
"node:_stream_readable",
|
|
20
|
+
"node:_stream_transform",
|
|
21
|
+
"node:_stream_wrap",
|
|
22
|
+
"node:_stream_writable",
|
|
23
|
+
"_stream_duplex",
|
|
24
|
+
"_stream_passthrough",
|
|
25
|
+
"_stream_readable",
|
|
26
|
+
"_stream_transform",
|
|
27
|
+
"_stream_wrap",
|
|
28
|
+
"_stream_writable"
|
|
29
|
+
]);
|
|
30
|
+
|
|
31
|
+
private getReplacement(moduleName: string): string {
|
|
32
|
+
if (moduleName.startsWith("node:")) {
|
|
33
|
+
return "node:stream";
|
|
34
|
+
}
|
|
35
|
+
return "stream";
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
protected async visitImportDeclaration(jsImport: JS.Import, p: ExecutionContext): Promise<J | undefined> {
|
|
39
|
+
const imp = await super.visitImportDeclaration(jsImport, p) as JS.Import;
|
|
40
|
+
|
|
41
|
+
if (!imp.moduleSpecifier) {
|
|
42
|
+
return imp;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const moduleSpec = imp.moduleSpecifier.element;
|
|
46
|
+
if (moduleSpec.kind === J.Kind.Literal) {
|
|
47
|
+
const literal = moduleSpec as J.Literal;
|
|
48
|
+
const moduleName = literal.value as string;
|
|
49
|
+
|
|
50
|
+
if (this.deprecatedModules.has(moduleName)) {
|
|
51
|
+
const replacement = this.getReplacement(moduleName);
|
|
52
|
+
return produceAsync(imp, async draft => {
|
|
53
|
+
const litDraft = (draft as Draft<JS.Import>).moduleSpecifier!.element as Draft<J.Literal>;
|
|
54
|
+
litDraft.value = replacement;
|
|
55
|
+
litDraft.valueSource = `'${replacement}'`;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return imp;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
protected async visitMethodInvocation(method: J.MethodInvocation, p: ExecutionContext): Promise<J | undefined> {
|
|
64
|
+
const m = await super.visitMethodInvocation(method, p) as J.MethodInvocation;
|
|
65
|
+
|
|
66
|
+
if (m.name.simpleName !== "require") {
|
|
67
|
+
return m;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const args = m.arguments.elements;
|
|
71
|
+
if (args.length !== 1) {
|
|
72
|
+
return m;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const arg = args[0].element;
|
|
76
|
+
if (arg.kind === J.Kind.Literal) {
|
|
77
|
+
const literal = arg as J.Literal;
|
|
78
|
+
const moduleName = literal.value as string;
|
|
79
|
+
|
|
80
|
+
if (this.deprecatedModules.has(moduleName)) {
|
|
81
|
+
const replacement = this.getReplacement(moduleName);
|
|
82
|
+
return produceAsync(m, async draft => {
|
|
83
|
+
const litDraft = (draft as Draft<J.MethodInvocation>).arguments.elements[0].element as Draft<J.Literal>;
|
|
84
|
+
litDraft.value = replacement;
|
|
85
|
+
litDraft.valueSource = `'${replacement}'`;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return m;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|