@openrewrite/recipes-nodejs 0.34.0-20251117-110757 → 0.34.0-20251117-134541

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,cAAc,EAAC,MAAM,sBAAsB,CAAC;AAIpD,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,cAAc,QAIhD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,cAAc,EAAC,MAAM,sBAAsB,CAAC;AAKpD,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,cAAc,QAKhD"}
package/dist/index.js CHANGED
@@ -4,9 +4,11 @@ exports.activate = activate;
4
4
  const util_type_checking_1 = require("./migrate/util-type-checking");
5
5
  const buffer_slice_1 = require("./migrate/buffer-slice");
6
6
  const process_features_tls_1 = require("./migrate/process-features-tls");
7
+ const crypto_hash_1 = require("./migrate/crypto-hash");
7
8
  function activate(registry) {
8
9
  registry.register(util_type_checking_1.UseNativeTypeCheckingMethods);
9
10
  registry.register(buffer_slice_1.ReplaceDeprecatedBufferSlice);
10
11
  registry.register(process_features_tls_1.RemoveUsageOfProcessFeaturesTlsConstants);
12
+ registry.register(crypto_hash_1.ReplaceCryptoHashConstructor);
11
13
  }
12
14
  //# 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":";;AAMA,4BAIC;AAVD,qEAA0E;AAC1E,yDAAoE;AAEpE,yEAAwF;AAGxF,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;AAChE,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAOA,4BAKC;AAZD,qEAA0E;AAC1E,yDAAoE;AAEpE,yEAAwF;AACxF,uDAAmE;AAGnE,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,0CAA4B,CAAC,CAAC;AACpD,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { ExecutionContext, Recipe, TreeVisitor } from "@openrewrite/rewrite";
2
+ export declare class ReplaceCryptoHashConstructor extends Recipe {
3
+ readonly name = "org.openrewrite.node.migrate.crypto.replace-hash-constructor";
4
+ readonly displayName: string;
5
+ readonly description: string;
6
+ readonly tags: string[];
7
+ editor(): Promise<TreeVisitor<any, ExecutionContext>>;
8
+ }
9
+ //# sourceMappingURL=crypto-hash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto-hash.d.ts","sourceRoot":"","sources":["../../src/migrate/crypto-hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,gBAAgB,EAAE,MAAM,EAAE,WAAW,EAAC,MAAM,sBAAsB,CAAC;AAgBlF,qBAAa,4BAA6B,SAAQ,MAAM;IACpD,QAAQ,CAAC,IAAI,kEAAiE;IAC9E,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAuE;IACnG,QAAQ,CAAC,WAAW,EAAE,MAAM,CAA2H;IACvJ,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,CAAe;IAEhC,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;CAyC9D"}
@@ -0,0 +1,67 @@
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.ReplaceCryptoHashConstructor = 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 ReplaceCryptoHashConstructor extends rewrite_1.Recipe {
17
+ constructor() {
18
+ super(...arguments);
19
+ this.name = "org.openrewrite.node.migrate.crypto.replace-hash-constructor";
20
+ this.displayName = "Replace deprecated `new crypto.Hash()` with `crypto.createHash()`";
21
+ this.description = "Replace deprecated `new crypto.Hash(algorithm)` constructor calls with `crypto.createHash(algorithm)` factory method.";
22
+ this.tags = ["DEP0179"];
23
+ }
24
+ editor() {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ return new class extends javascript_1.JavaScriptVisitor {
27
+ visitNewClass(newClass, p) {
28
+ const _super = Object.create(null, {
29
+ visitNewClass: { get: () => super.visitNewClass }
30
+ });
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ var _a, _b;
33
+ const clazz = newClass.class;
34
+ const args = (_a = newClass.arguments) === null || _a === void 0 ? void 0 : _a.elements;
35
+ if (!args || args.length !== 1) {
36
+ return _super.visitNewClass.call(this, newClass, p);
37
+ }
38
+ const algorithm = args[0].element;
39
+ if (clazz && clazz.kind === java_1.J.Kind.FieldAccess) {
40
+ const fieldAccess = clazz;
41
+ const target = fieldAccess.target;
42
+ if (target.kind === java_1.J.Kind.Identifier
43
+ && ((_b = clazz.type) === null || _b === void 0 ? void 0 : _b.kind) == java_1.Type.Kind.Class
44
+ && clazz.type.fullyQualifiedName == "crypto.Hash") {
45
+ const cryptoIdentifier = target;
46
+ return yield (0, javascript_1.template) `${cryptoIdentifier}.createHash(${algorithm})`.apply(this.cursor, newClass);
47
+ }
48
+ }
49
+ if (clazz && clazz.kind === java_1.J.Kind.Identifier) {
50
+ const constructorType = newClass.constructorType;
51
+ if ((constructorType === null || constructorType === void 0 ? void 0 : constructorType.declaringType.kind) == java_1.Type.Kind.Class
52
+ && constructorType.declaringType.fullyQualifiedName == "crypto"
53
+ && constructorType.name == "Hash") {
54
+ (0, javascript_1.maybeAddImport)(this, { target: "crypto", member: "createHash", onlyIfReferenced: false });
55
+ (0, javascript_1.maybeRemoveImport)(this, "crypto", "Hash");
56
+ return yield (0, javascript_1.template) `createHash(${algorithm})`.apply(this.cursor, newClass);
57
+ }
58
+ }
59
+ return _super.visitNewClass.call(this, newClass, p);
60
+ });
61
+ }
62
+ };
63
+ });
64
+ }
65
+ }
66
+ exports.ReplaceCryptoHashConstructor = ReplaceCryptoHashConstructor;
67
+ //# sourceMappingURL=crypto-hash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto-hash.js","sourceRoot":"","sources":["../../src/migrate/crypto-hash.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAAkF;AAClF,gEAMyC;AACzC,oDAA8D;AAQ9D,MAAa,4BAA6B,SAAQ,gBAAM;IAAxD;;QACa,SAAI,GAAG,8DAA8D,CAAA;QACrE,gBAAW,GAAW,mEAAmE,CAAC;QAC1F,gBAAW,GAAW,uHAAuH,CAAC;QAC9I,SAAI,GAAa,CAAC,SAAS,CAAC,CAAC;IA2C1C,CAAC;IAzCS,MAAM;;YACR,OAAO,IAAI,KAAM,SAAQ,8BAAmC;gBACxC,aAAa,CAAC,QAAoB,EAAE,CAAmB;;;;;;wBACnE,MA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QAAQ;mCAC5E,eAAe,CAAC,IAAI,IAAI,MAAM,EAAE,CAAC;gCACpC,IAAA,2BAAc,EAAC,IAAI,EAAE,EAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,gBAAgB,EAAE,KAAK,EAAC,CAAC,CAAC;gCACxF,IAAA,8BAAiB,EAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;gCAC1C,OAAO,MAAM,IAAA,qBAAQ,EAAA,cAAc,SAAS,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;4BACjF,CAAC;wBACL,CAAC;wBAED,OAAO,OAAM,aAAa,YAAC,QAAQ,EAAE,CAAC,EAAE;oBAC5C,CAAC;iBAAA;aACJ,CAAC;QACN,CAAC;KAAA;CACJ;AA/CD,oEA+CC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openrewrite/recipes-nodejs",
3
- "version": "0.34.0-20251117-110757",
3
+ "version": "0.34.0-20251117-134541",
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
@@ -2,10 +2,12 @@ import {UseNativeTypeCheckingMethods} from "./migrate/util-type-checking";
2
2
  import {ReplaceDeprecatedBufferSlice} from "./migrate/buffer-slice";
3
3
  import {RecipeRegistry} from "@openrewrite/rewrite";
4
4
  import {RemoveUsageOfProcessFeaturesTlsConstants} from "./migrate/process-features-tls";
5
+ import {ReplaceCryptoHashConstructor} from "./migrate/crypto-hash";
5
6
 
6
7
 
7
8
  export function activate(registry: RecipeRegistry) {
8
9
  registry.register(UseNativeTypeCheckingMethods);
9
10
  registry.register(ReplaceDeprecatedBufferSlice);
10
11
  registry.register(RemoveUsageOfProcessFeaturesTlsConstants);
12
+ registry.register(ReplaceCryptoHashConstructor);
11
13
  }
@@ -0,0 +1,64 @@
1
+ import {check, ExecutionContext, Recipe, TreeVisitor} from "@openrewrite/rewrite";
2
+ import {
3
+ JavaScriptVisitor,
4
+ maybeAddImport,
5
+ maybeRemoveImport,
6
+ template,
7
+ usesType
8
+ } from "@openrewrite/rewrite/javascript";
9
+ import {Expression, J, Type} from "@openrewrite/rewrite/java";
10
+
11
+ /**
12
+ * Replace deprecated new crypto.Hash() constructor with crypto.createHash()
13
+ *
14
+ * DEP0179: new crypto.Hash() was deprecated because the crypto.Hash class
15
+ * should not be instantiated directly. Use the crypto.createHash() factory method instead.
16
+ */
17
+ export class ReplaceCryptoHashConstructor extends Recipe {
18
+ readonly name = "org.openrewrite.node.migrate.crypto.replace-hash-constructor"
19
+ readonly displayName: string = "Replace deprecated `new crypto.Hash()` with `crypto.createHash()`";
20
+ readonly description: string = "Replace deprecated `new crypto.Hash(algorithm)` constructor calls with `crypto.createHash(algorithm)` factory method.";
21
+ readonly tags: string[] = ["DEP0179"];
22
+
23
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
24
+ return new class extends JavaScriptVisitor<ExecutionContext> {
25
+ protected async visitNewClass(newClass: J.NewClass, p: ExecutionContext): Promise<J | undefined> {
26
+ const clazz = newClass.class;
27
+ const args = newClass.arguments?.elements;
28
+
29
+ if (!args || args.length !== 1) {
30
+ return super.visitNewClass(newClass, p);
31
+ }
32
+
33
+ const algorithm = args[0].element;
34
+
35
+ // Case 1: new crypto.Hash(...) or new identifier.Hash(...)
36
+ if (clazz && clazz.kind === J.Kind.FieldAccess) {
37
+ const fieldAccess = clazz as J.FieldAccess;
38
+ const target = fieldAccess.target;
39
+
40
+ if (target.kind === J.Kind.Identifier
41
+ && (clazz as J.FieldAccess).type?.kind == Type.Kind.Class
42
+ && ((clazz as J.FieldAccess).type as Type.Class).fullyQualifiedName == "crypto.Hash") {
43
+ const cryptoIdentifier = target as J.Identifier;
44
+ return await template`${cryptoIdentifier}.createHash(${algorithm})`.apply(this.cursor, newClass);
45
+ }
46
+ }
47
+
48
+ // Case 2: new Hash(...) or new CryptoHash(...) - direct import
49
+ if (clazz && clazz.kind === J.Kind.Identifier) {
50
+ const constructorType = newClass.constructorType;
51
+ if (constructorType?.declaringType.kind == Type.Kind.Class
52
+ && (constructorType.declaringType as Type.Class).fullyQualifiedName == "crypto"
53
+ && constructorType.name == "Hash") {
54
+ maybeAddImport(this, {target: "crypto", member: "createHash", onlyIfReferenced: false});
55
+ maybeRemoveImport(this, "crypto", "Hash");
56
+ return await template`createHash(${algorithm})`.apply(this.cursor, newClass);
57
+ }
58
+ }
59
+
60
+ return super.visitNewClass(newClass, p);
61
+ }
62
+ };
63
+ }
64
+ }