@openrewrite/recipes-nodejs 0.59.0 → 0.61.0

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.
Files changed (132) hide show
  1. package/dist/migrate/angular-animations/remove-angular-animations-providers.d.ts.map +1 -1
  2. package/dist/migrate/angular-animations/remove-angular-animations-providers.js +6 -26
  3. package/dist/migrate/angular-animations/remove-angular-animations-providers.js.map +1 -1
  4. package/dist/migrate/builtin-binding-visitor.d.ts.map +1 -1
  5. package/dist/migrate/builtin-binding-visitor.js +6 -22
  6. package/dist/migrate/builtin-binding-visitor.js.map +1 -1
  7. package/dist/migrate/crypto-rsa-pss-key-pair-options.js +1 -4
  8. package/dist/migrate/crypto-rsa-pss-key-pair-options.js.map +1 -1
  9. package/dist/migrate/exports-folder-mappings.d.ts.map +1 -1
  10. package/dist/migrate/exports-folder-mappings.js +6 -19
  11. package/dist/migrate/exports-folder-mappings.js.map +1 -1
  12. package/dist/migrate/express-request-id/replace-express-request-id.d.ts.map +1 -1
  13. package/dist/migrate/express-request-id/replace-express-request-id.js +2 -5
  14. package/dist/migrate/express-request-id/replace-express-request-id.js.map +1 -1
  15. package/dist/migrate/find-aead-decipheriv-without-auth-tag-length.d.ts.map +1 -1
  16. package/dist/migrate/find-aead-decipheriv-without-auth-tag-length.js +2 -3
  17. package/dist/migrate/find-aead-decipheriv-without-auth-tag-length.js.map +1 -1
  18. package/dist/migrate/find-dns-lookup-options-coercion.js +2 -2
  19. package/dist/migrate/find-dns-lookup-options-coercion.js.map +1 -1
  20. package/dist/migrate/find-duplex-to-web-type.d.ts.map +1 -1
  21. package/dist/migrate/find-duplex-to-web-type.js +2 -3
  22. package/dist/migrate/find-duplex-to-web-type.js.map +1 -1
  23. package/dist/migrate/find-stream-thenable-implementations.js +4 -5
  24. package/dist/migrate/find-stream-thenable-implementations.js.map +1 -1
  25. package/dist/migrate/fs-extra/find-fs-extra-manual-migrations.d.ts +1 -0
  26. package/dist/migrate/fs-extra/find-fs-extra-manual-migrations.d.ts.map +1 -1
  27. package/dist/migrate/fs-extra/find-fs-extra-manual-migrations.js +10 -2
  28. package/dist/migrate/fs-extra/find-fs-extra-manual-migrations.js.map +1 -1
  29. package/dist/migrate/fs-extra/fs-extra-support.d.ts +0 -1
  30. package/dist/migrate/fs-extra/fs-extra-support.d.ts.map +1 -1
  31. package/dist/migrate/fs-extra/fs-extra-support.js +0 -4
  32. package/dist/migrate/fs-extra/fs-extra-support.js.map +1 -1
  33. package/dist/migrate/fs-extra/migrate-fs-extra-to-node-fs.d.ts.map +1 -1
  34. package/dist/migrate/fs-extra/migrate-fs-extra-to-node-fs.js +3 -2
  35. package/dist/migrate/fs-extra/migrate-fs-extra-to-node-fs.js.map +1 -1
  36. package/dist/migrate/fs-extra/replace-fs-extra-move.js +2 -2
  37. package/dist/migrate/fs-extra/replace-fs-extra-move.js.map +1 -1
  38. package/dist/migrate/fs-extra/replace-fs-extra-native-methods.d.ts +2 -0
  39. package/dist/migrate/fs-extra/replace-fs-extra-native-methods.d.ts.map +1 -1
  40. package/dist/migrate/fs-extra/replace-fs-extra-native-methods.js +58 -6
  41. package/dist/migrate/fs-extra/replace-fs-extra-native-methods.js.map +1 -1
  42. package/dist/migrate/fs-extra/replace-fs-extra-read-json.js +1 -1
  43. package/dist/migrate/fs-extra/replace-fs-extra-read-json.js.map +1 -1
  44. package/dist/migrate/fs-stats-constructor.d.ts.map +1 -1
  45. package/dist/migrate/fs-stats-constructor.js +1 -12
  46. package/dist/migrate/fs-stats-constructor.js.map +1 -1
  47. package/dist/migrate/hpagent/hpagent-support.d.ts +0 -1
  48. package/dist/migrate/hpagent/hpagent-support.d.ts.map +1 -1
  49. package/dist/migrate/hpagent/hpagent-support.js +3 -7
  50. package/dist/migrate/hpagent/hpagent-support.js.map +1 -1
  51. package/dist/migrate/hpagent/replace-hpagent.d.ts.map +1 -1
  52. package/dist/migrate/hpagent/replace-hpagent.js +8 -12
  53. package/dist/migrate/hpagent/replace-hpagent.js.map +1 -1
  54. package/dist/migrate/increase-node-engine-version.d.ts.map +1 -1
  55. package/dist/migrate/increase-node-engine-version.js +7 -26
  56. package/dist/migrate/increase-node-engine-version.js.map +1 -1
  57. package/dist/migrate/json-edits.d.ts +4 -9
  58. package/dist/migrate/json-edits.d.ts.map +1 -1
  59. package/dist/migrate/json-edits.js +46 -60
  60. package/dist/migrate/json-edits.js.map +1 -1
  61. package/dist/migrate/options-literal.d.ts.map +1 -1
  62. package/dist/migrate/options-literal.js +1 -2
  63. package/dist/migrate/options-literal.js.map +1 -1
  64. package/dist/migrate/package-json-support.d.ts +2 -1
  65. package/dist/migrate/package-json-support.d.ts.map +1 -1
  66. package/dist/migrate/package-json-support.js +14 -12
  67. package/dist/migrate/package-json-support.js.map +1 -1
  68. package/dist/migrate/path/remove-path-dependency.d.ts.map +1 -1
  69. package/dist/migrate/path/remove-path-dependency.js +4 -25
  70. package/dist/migrate/path/remove-path-dependency.js.map +1 -1
  71. package/dist/migrate/promisify-on-promise.js +3 -3
  72. package/dist/migrate/promisify-on-promise.js.map +1 -1
  73. package/dist/migrate/prop-types/remove-prop-types.d.ts.map +1 -1
  74. package/dist/migrate/prop-types/remove-prop-types.js +7 -25
  75. package/dist/migrate/prop-types/remove-prop-types.js.map +1 -1
  76. package/dist/migrate/source-map-support/enable-source-maps-at-launch.d.ts.map +1 -1
  77. package/dist/migrate/source-map-support/enable-source-maps-at-launch.js +14 -64
  78. package/dist/migrate/source-map-support/enable-source-maps-at-launch.js.map +1 -1
  79. package/dist/migrate/source-map-support/find-source-map-support-manual-migrations.d.ts.map +1 -1
  80. package/dist/migrate/source-map-support/find-source-map-support-manual-migrations.js +9 -38
  81. package/dist/migrate/source-map-support/find-source-map-support-manual-migrations.js.map +1 -1
  82. package/dist/migrate/source-map-support/replace-source-map-support-api.d.ts.map +1 -1
  83. package/dist/migrate/source-map-support/replace-source-map-support-api.js +1 -1
  84. package/dist/migrate/source-map-support/replace-source-map-support-api.js.map +1 -1
  85. package/dist/migrate/source-map-support/replace-source-map-support-register-in-mocha-config.js +1 -1
  86. package/dist/migrate/source-map-support/replace-source-map-support-register-in-mocha-config.js.map +1 -1
  87. package/dist/migrate/source-map-support/replace-source-map-support-register-in-package-json.d.ts.map +1 -1
  88. package/dist/migrate/source-map-support/replace-source-map-support-register-in-package-json.js +37 -88
  89. package/dist/migrate/source-map-support/replace-source-map-support-register-in-package-json.js.map +1 -1
  90. package/dist/migrate/source-map-support/source-map-support-support.d.ts.map +1 -1
  91. package/dist/migrate/source-map-support/source-map-support-support.js +3 -16
  92. package/dist/migrate/source-map-support/source-map-support-support.js.map +1 -1
  93. package/dist/migrate/stream-internal-modules.d.ts.map +1 -1
  94. package/dist/migrate/stream-internal-modules.js +2 -10
  95. package/dist/migrate/stream-internal-modules.js.map +1 -1
  96. package/dist/migrate/tls-internal-modules.d.ts.map +1 -1
  97. package/dist/migrate/tls-internal-modules.js +2 -10
  98. package/dist/migrate/tls-internal-modules.js.map +1 -1
  99. package/package.json +2 -2
  100. package/src/migrate/angular-animations/remove-angular-animations-providers.ts +7 -23
  101. package/src/migrate/builtin-binding-visitor.ts +10 -28
  102. package/src/migrate/crypto-rsa-pss-key-pair-options.ts +2 -11
  103. package/src/migrate/exports-folder-mappings.ts +18 -19
  104. package/src/migrate/express-request-id/replace-express-request-id.ts +3 -7
  105. package/src/migrate/find-aead-decipheriv-without-auth-tag-length.ts +3 -4
  106. package/src/migrate/find-dns-lookup-options-coercion.ts +3 -3
  107. package/src/migrate/find-duplex-to-web-type.ts +3 -4
  108. package/src/migrate/find-stream-thenable-implementations.ts +5 -7
  109. package/src/migrate/fs-extra/find-fs-extra-manual-migrations.ts +12 -4
  110. package/src/migrate/fs-extra/fs-extra-support.ts +0 -5
  111. package/src/migrate/fs-extra/migrate-fs-extra-to-node-fs.ts +3 -2
  112. package/src/migrate/fs-extra/replace-fs-extra-move.ts +3 -3
  113. package/src/migrate/fs-extra/replace-fs-extra-native-methods.ts +75 -8
  114. package/src/migrate/fs-extra/replace-fs-extra-read-json.ts +3 -3
  115. package/src/migrate/fs-stats-constructor.ts +2 -13
  116. package/src/migrate/hpagent/hpagent-support.ts +2 -7
  117. package/src/migrate/hpagent/replace-hpagent.ts +7 -8
  118. package/src/migrate/increase-node-engine-version.ts +10 -36
  119. package/src/migrate/json-edits.ts +48 -64
  120. package/src/migrate/options-literal.ts +2 -3
  121. package/src/migrate/package-json-support.ts +15 -12
  122. package/src/migrate/path/remove-path-dependency.ts +6 -23
  123. package/src/migrate/promisify-on-promise.ts +4 -4
  124. package/src/migrate/prop-types/remove-prop-types.ts +9 -25
  125. package/src/migrate/source-map-support/enable-source-maps-at-launch.ts +14 -52
  126. package/src/migrate/source-map-support/find-source-map-support-manual-migrations.ts +11 -34
  127. package/src/migrate/source-map-support/replace-source-map-support-api.ts +2 -1
  128. package/src/migrate/source-map-support/replace-source-map-support-register-in-mocha-config.ts +2 -2
  129. package/src/migrate/source-map-support/replace-source-map-support-register-in-package-json.ts +53 -98
  130. package/src/migrate/source-map-support/source-map-support-support.ts +6 -19
  131. package/src/migrate/stream-internal-modules.ts +4 -13
  132. package/src/migrate/tls-internal-modules.ts +4 -13
@@ -6,7 +6,7 @@
6
6
 
7
7
  import {Column, Cursor, DataTable} from "@openrewrite/rewrite";
8
8
  import {isIdentifier, J} from "@openrewrite/rewrite/java";
9
- import {compilationUnitOf, JS, scopeOf, walk} from "@openrewrite/rewrite/javascript";
9
+ import {compilationUnitOf, isAssignmentTarget, isObjectLiteral, JS, scopeOf, walk} from "@openrewrite/rewrite/javascript";
10
10
  import {BuiltinBindingVisitor} from "../builtin-binding-visitor";
11
11
  import {bindingsOf, isModuleScoped, ModuleBindings, requiredModule, stringLiteral} from "../module-bindings";
12
12
  import {REGISTER_MODULES} from "./register-flag";
@@ -128,10 +128,10 @@ function memberMethodName(e: J): string | undefined {
128
128
  /** The first `install` option Node has no equivalent for, or undefined where every one is covered. */
129
129
  export function nonNativeOption(arg: J | undefined): {option: string; reason: string} | undefined {
130
130
  if (!arg || arg.kind === J.Kind.Empty) return undefined;
131
- if (arg.kind !== J.Kind.NewClass || (arg as J.NewClass).class) {
131
+ if (!isObjectLiteral(arg)) {
132
132
  return {option: 'options', reason: REASONS.nonNativeOption('options that cannot be read statically')};
133
133
  }
134
- for (const s of (arg as J.NewClass).body?.statements ?? []) {
134
+ for (const s of arg.body?.statements ?? []) {
135
135
  if (s.element.kind === J.Kind.Empty) continue;
136
136
  if (s.element.kind !== JS.Kind.PropertyAssignment) {
137
137
  // A shorthand method — `retrieveSourceMap(source) {...}` — names the option it sets.
@@ -161,27 +161,14 @@ export function hasOnlyNativeOptions(arg: J | undefined): boolean {
161
161
 
162
162
  /** Whether the tree at `cursor` is written to: assigned, incremented or deleted. */
163
163
  export function isWriteTarget(cursor: Cursor): boolean {
164
- const node = cursor.value as J;
165
164
  const parent = cursor.parentTree()?.value as J | undefined;
166
- switch (parent?.kind) {
167
- case J.Kind.Assignment:
168
- case J.Kind.AssignmentOperation:
169
- case JS.Kind.AssignmentOperation:
170
- return (parent as J.Assignment).variable === node;
171
- case JS.Kind.Delete:
172
- return (parent as JS.Delete).expression === node;
173
- case J.Kind.Unary:
174
- return [J.Unary.Type.PreIncrement, J.Unary.Type.PreDecrement, J.Unary.Type.PostIncrement,
175
- J.Unary.Type.PostDecrement].includes((parent as J.Unary).operator.element);
176
- default:
177
- return false;
178
- }
165
+ return isAssignmentTarget(cursor) || parent?.kind === JS.Kind.Delete && (parent as JS.Delete).expression === cursor.value;
179
166
  }
180
167
 
181
168
  /** Whether an `install()` options literal sets `environment: 'browser'`. */
182
169
  export function isBrowserInstall(arg: J | undefined): boolean {
183
- if (arg?.kind !== J.Kind.NewClass || (arg as J.NewClass).class) return false;
184
- return ((arg as J.NewClass).body?.statements ?? []).some(s => s.element.kind === JS.Kind.PropertyAssignment &&
170
+ if (!arg || !isObjectLiteral(arg)) return false;
171
+ return (arg.body?.statements ?? []).some(s => s.element.kind === JS.Kind.PropertyAssignment &&
185
172
  propertyName(s.element as JS.PropertyAssignment) === 'environment' &&
186
173
  stringLiteral((s.element as JS.PropertyAssignment).initializer) === 'browser');
187
174
  }
@@ -3,10 +3,9 @@
3
3
  *
4
4
  * Moderne Proprietary. Only for use by Moderne customers under the terms of a commercial contract.
5
5
  */
6
- import {ExecutionContext, produceAsync, Recipe, TreeVisitor} from "@openrewrite/rewrite";
7
- import {JavaScriptVisitor, JS} from "@openrewrite/rewrite/javascript";
6
+ import {ExecutionContext, Recipe, TreeVisitor} from "@openrewrite/rewrite";
7
+ import {JavaScriptVisitor, JS, withStringValue} from "@openrewrite/rewrite/javascript";
8
8
  import {J} from "@openrewrite/rewrite/java";
9
- import {Draft} from "mutative";
10
9
 
11
10
  export class ReplaceStreamInternalModules extends Recipe {
12
11
  readonly name = "org.openrewrite.node.migrate.stream.replace-internal-modules"
@@ -54,11 +53,7 @@ export class ReplaceStreamInternalModules extends Recipe {
54
53
 
55
54
  if (this.deprecatedModules.has(moduleName)) {
56
55
  const replacement = this.getReplacement(moduleName);
57
- return produceAsync(imp, async draft => {
58
- const litDraft = (draft as Draft<JS.Import>).moduleSpecifier!.element as Draft<J.Literal>;
59
- litDraft.value = replacement;
60
- litDraft.valueSource = `'${replacement}'`;
61
- });
56
+ return {...imp, moduleSpecifier: {...imp.moduleSpecifier, element: withStringValue(literal, replacement)}} as JS.Import;
62
57
  }
63
58
  }
64
59
 
@@ -84,11 +79,7 @@ export class ReplaceStreamInternalModules extends Recipe {
84
79
 
85
80
  if (this.deprecatedModules.has(moduleName)) {
86
81
  const replacement = this.getReplacement(moduleName);
87
- return produceAsync(m, async draft => {
88
- const litDraft = (draft as Draft<J.MethodInvocation>).arguments.elements[0].element as Draft<J.Literal>;
89
- litDraft.value = replacement;
90
- litDraft.valueSource = `'${replacement}'`;
91
- });
82
+ return {...m, arguments: {...m.arguments, elements: [{...args[0], element: withStringValue(literal, replacement)}]}} as J.MethodInvocation;
92
83
  }
93
84
  }
94
85
 
@@ -3,10 +3,9 @@
3
3
  *
4
4
  * Moderne Proprietary. Only for use by Moderne customers under the terms of a commercial contract.
5
5
  */
6
- import {ExecutionContext, produceAsync, Recipe, TreeVisitor} from "@openrewrite/rewrite";
7
- import {JavaScriptVisitor, JS} from "@openrewrite/rewrite/javascript";
6
+ import {ExecutionContext, Recipe, TreeVisitor} from "@openrewrite/rewrite";
7
+ import {JavaScriptVisitor, JS, withStringValue} from "@openrewrite/rewrite/javascript";
8
8
  import {J} from "@openrewrite/rewrite/java";
9
- import {Draft} from "mutative";
10
9
 
11
10
  export class ReplaceTlsInternalModules extends Recipe {
12
11
  readonly name = "org.openrewrite.node.migrate.tls.replace-internal-modules"
@@ -46,11 +45,7 @@ export class ReplaceTlsInternalModules extends Recipe {
46
45
 
47
46
  if (this.deprecatedModules.has(moduleName)) {
48
47
  const replacement = this.getReplacement(moduleName);
49
- return produceAsync(imp, async draft => {
50
- const litDraft = (draft as Draft<JS.Import>).moduleSpecifier!.element as Draft<J.Literal>;
51
- litDraft.value = replacement;
52
- litDraft.valueSource = `'${replacement}'`;
53
- });
48
+ return {...imp, moduleSpecifier: {...imp.moduleSpecifier, element: withStringValue(literal, replacement)}} as JS.Import;
54
49
  }
55
50
  }
56
51
 
@@ -76,11 +71,7 @@ export class ReplaceTlsInternalModules extends Recipe {
76
71
 
77
72
  if (this.deprecatedModules.has(moduleName)) {
78
73
  const replacement = this.getReplacement(moduleName);
79
- return produceAsync(m, async draft => {
80
- const litDraft = (draft as Draft<J.MethodInvocation>).arguments.elements[0].element as Draft<J.Literal>;
81
- litDraft.value = replacement;
82
- litDraft.valueSource = `'${replacement}'`;
83
- });
74
+ return {...m, arguments: {...m.arguments, elements: [{...args[0], element: withStringValue(literal, replacement)}]}} as J.MethodInvocation;
84
75
  }
85
76
  }
86
77