@openrewrite/recipes-nodejs 0.64.0 → 0.66.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 (78) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +12 -1
  4. package/dist/index.js.map +1 -1
  5. package/dist/migrate/aws-sdk-v3/add-aws-sdk-v3-dependencies.d.ts +16 -0
  6. package/dist/migrate/aws-sdk-v3/add-aws-sdk-v3-dependencies.d.ts.map +1 -0
  7. package/dist/migrate/aws-sdk-v3/add-aws-sdk-v3-dependencies.js +89 -0
  8. package/dist/migrate/aws-sdk-v3/add-aws-sdk-v3-dependencies.js.map +1 -0
  9. package/dist/migrate/aws-sdk-v3/aws-sdk-v3-node-support.d.ts +33 -0
  10. package/dist/migrate/aws-sdk-v3/aws-sdk-v3-node-support.d.ts.map +1 -0
  11. package/dist/migrate/aws-sdk-v3/aws-sdk-v3-node-support.js +190 -0
  12. package/dist/migrate/aws-sdk-v3/aws-sdk-v3-node-support.js.map +1 -0
  13. package/dist/migrate/aws-sdk-v3/aws-sdk-v3-plan.d.ts +70 -0
  14. package/dist/migrate/aws-sdk-v3/aws-sdk-v3-plan.d.ts.map +1 -0
  15. package/dist/migrate/aws-sdk-v3/aws-sdk-v3-plan.js +315 -0
  16. package/dist/migrate/aws-sdk-v3/aws-sdk-v3-plan.js.map +1 -0
  17. package/dist/migrate/aws-sdk-v3/aws-sdk-v3-support.d.ts +181 -0
  18. package/dist/migrate/aws-sdk-v3/aws-sdk-v3-support.d.ts.map +1 -0
  19. package/dist/migrate/aws-sdk-v3/aws-sdk-v3-support.js +1504 -0
  20. package/dist/migrate/aws-sdk-v3/aws-sdk-v3-support.js.map +1 -0
  21. package/dist/migrate/aws-sdk-v3/aws-sdk-v3-tables.d.ts +3 -0
  22. package/dist/migrate/aws-sdk-v3/aws-sdk-v3-tables.d.ts.map +1 -0
  23. package/dist/migrate/aws-sdk-v3/aws-sdk-v3-tables.js +421 -0
  24. package/dist/migrate/aws-sdk-v3/aws-sdk-v3-tables.js.map +1 -0
  25. package/dist/migrate/aws-sdk-v3/find-aws-sdk-v2-manual-migrations.d.ts +20 -0
  26. package/dist/migrate/aws-sdk-v3/find-aws-sdk-v2-manual-migrations.d.ts.map +1 -0
  27. package/dist/migrate/aws-sdk-v3/find-aws-sdk-v2-manual-migrations.js +146 -0
  28. package/dist/migrate/aws-sdk-v3/find-aws-sdk-v2-manual-migrations.js.map +1 -0
  29. package/dist/migrate/aws-sdk-v3/migrate-aws-sdk-v2-to-v3.d.ts +13 -0
  30. package/dist/migrate/aws-sdk-v3/migrate-aws-sdk-v2-to-v3.d.ts.map +1 -0
  31. package/dist/migrate/aws-sdk-v3/migrate-aws-sdk-v2-to-v3.js +69 -0
  32. package/dist/migrate/aws-sdk-v3/migrate-aws-sdk-v2-to-v3.js.map +1 -0
  33. package/dist/migrate/aws-sdk-v3/remove-unused-aws-sdk-v2-dependency.d.ts +35 -0
  34. package/dist/migrate/aws-sdk-v3/remove-unused-aws-sdk-v2-dependency.d.ts.map +1 -0
  35. package/dist/migrate/aws-sdk-v3/remove-unused-aws-sdk-v2-dependency.js +132 -0
  36. package/dist/migrate/aws-sdk-v3/remove-unused-aws-sdk-v2-dependency.js.map +1 -0
  37. package/dist/migrate/aws-sdk-v3/replace-aws-sdk-v2-clients.d.ts +18 -0
  38. package/dist/migrate/aws-sdk-v3/replace-aws-sdk-v2-clients.d.ts.map +1 -0
  39. package/dist/migrate/aws-sdk-v3/replace-aws-sdk-v2-clients.js +562 -0
  40. package/dist/migrate/aws-sdk-v3/replace-aws-sdk-v2-clients.js.map +1 -0
  41. package/dist/migrate/builtin-binding-visitor.d.ts +1 -6
  42. package/dist/migrate/builtin-binding-visitor.d.ts.map +1 -1
  43. package/dist/migrate/builtin-binding-visitor.js +6 -69
  44. package/dist/migrate/builtin-binding-visitor.js.map +1 -1
  45. package/dist/migrate/express-request-id/replace-express-request-id.d.ts.map +1 -1
  46. package/dist/migrate/express-request-id/replace-express-request-id.js +1 -2
  47. package/dist/migrate/express-request-id/replace-express-request-id.js.map +1 -1
  48. package/dist/migrate/fs-extra/fs-extra-support.d.ts +0 -1
  49. package/dist/migrate/fs-extra/fs-extra-support.d.ts.map +1 -1
  50. package/dist/migrate/fs-extra/fs-extra-support.js +1 -2
  51. package/dist/migrate/fs-extra/fs-extra-support.js.map +1 -1
  52. package/dist/migrate/increase-node-engine-version.d.ts +1 -0
  53. package/dist/migrate/increase-node-engine-version.d.ts.map +1 -1
  54. package/dist/migrate/increase-node-engine-version.js +12 -7
  55. package/dist/migrate/increase-node-engine-version.js.map +1 -1
  56. package/dist/migrate/source-map-support/replace-source-map-support-api.js +1 -1
  57. package/dist/migrate/source-map-support/replace-source-map-support-api.js.map +1 -1
  58. package/dist/migrate/source-map-support/source-map-support-support.d.ts +0 -1
  59. package/dist/migrate/source-map-support/source-map-support-support.d.ts.map +1 -1
  60. package/dist/migrate/source-map-support/source-map-support-support.js +0 -1
  61. package/dist/migrate/source-map-support/source-map-support-support.js.map +1 -1
  62. package/package.json +2 -2
  63. package/src/index.ts +11 -0
  64. package/src/migrate/aws-sdk-v3/add-aws-sdk-v3-dependencies.ts +71 -0
  65. package/src/migrate/aws-sdk-v3/aws-sdk-v3-node-support.ts +172 -0
  66. package/src/migrate/aws-sdk-v3/aws-sdk-v3-plan.ts +399 -0
  67. package/src/migrate/aws-sdk-v3/aws-sdk-v3-support.ts +1480 -0
  68. package/src/migrate/aws-sdk-v3/aws-sdk-v3-tables.ts +432 -0
  69. package/src/migrate/aws-sdk-v3/find-aws-sdk-v2-manual-migrations.ts +126 -0
  70. package/src/migrate/aws-sdk-v3/migrate-aws-sdk-v2-to-v3.ts +56 -0
  71. package/src/migrate/aws-sdk-v3/remove-unused-aws-sdk-v2-dependency.ts +119 -0
  72. package/src/migrate/aws-sdk-v3/replace-aws-sdk-v2-clients.ts +523 -0
  73. package/src/migrate/builtin-binding-visitor.ts +9 -94
  74. package/src/migrate/express-request-id/replace-express-request-id.ts +1 -2
  75. package/src/migrate/fs-extra/fs-extra-support.ts +1 -2
  76. package/src/migrate/increase-node-engine-version.ts +11 -7
  77. package/src/migrate/source-map-support/replace-source-map-support-api.ts +1 -1
  78. package/src/migrate/source-map-support/source-map-support-support.ts +0 -1
@@ -0,0 +1,126 @@
1
+ /*
2
+ * Copyright 2026 the original author or authors.
3
+ *
4
+ * Moderne Proprietary. Only for use by Moderne customers under the terms of a commercial contract.
5
+ */
6
+
7
+ import {ExecutionContext, foundSearchResult, Option, ScanningRecipe, Tree, TreeVisitor} from "@openrewrite/rewrite";
8
+ import {J} from "@openrewrite/rewrite/java";
9
+ import {Json} from "@openrewrite/rewrite/json";
10
+ import {JavaScriptVisitor, JS} from "@openrewrite/rewrite/javascript";
11
+ import {isPackageJson} from "../package-json-support";
12
+ import {analyzeAwsSdk, awsSdkManualMigrationSteps, Problem, REASONS} from "./aws-sdk-v3-support";
13
+ import {awsSdkLockGroupNodeVersions} from "./aws-sdk-v3-node-support";
14
+ import {AwsSdkPlan, AwsSdkScan, awsSdkScanner, awsSdkSkippedLockGroups, newAwsSdkScan, normalizePath, skippedRows} from "./aws-sdk-v3-plan";
15
+
16
+ export class FindAwsSdkV2ManualMigrations extends ScanningRecipe<AwsSdkScan> {
17
+ readonly name = "org.openrewrite.node.migrate.aws-sdk-v3.find-aws-sdk-v2-manual-migrations";
18
+ readonly displayName = "Find AWS SDK v2 uses that need manual migration";
19
+ readonly description = "Marks what keeps a file from moving to the AWS SDK for JavaScript v3 mechanically, and " +
20
+ "records each in the `AwsSdkManualMigrationSteps` data table with what to do instead: global `AWS.config`, " +
21
+ "`AWS.Request` and its events (`on`, `send`, `createReadStream`, `eachPage`), `AWS.EventListeners`, credential " +
22
+ "and token classes, `AWS.Config`, `AWSError` used as a value, an AWS error's fields with no v3 counterpart " +
23
+ "(`region`, `time`, ...) or read other than as `err.field`, or read where a function of the file that calls " +
24
+ "a client failed, a response's `$response`, an S3 `getObject` `Body` read as a Buffer, waiters, S3 `upload`, " +
25
+ "`getSignedUrl` and `createPresignedPost` in forms without a v3 counterpart, client options with no v3 name, " +
26
+ "`.promise()` on a value not known to be a client, and the SDK loaded or mocked other than by a top-level " +
27
+ "import or require (`jest.mock('aws-sdk')`, `import()`). A `.promise()` whose receiver comes from another " +
28
+ "package (mysql2's `createPool(...).promise()`) is not a v2 call. In a project that " +
29
+ "declares `aws-sdk`, it also marks `.promise()` in files that don't import the SDK, since the client may come " +
30
+ "from a file the migration moves to v3, and marks a file that exports a client such a call may reach, which " +
31
+ "the migration leaves on v2. Each lock group such a file keeps on v2, which the migration leaves wholly unchanged, " +
32
+ "is listed in the `AwsSdkSkippedLockGroups` data table with the files that keep it there, and so is a group " +
33
+ "whose oldest declared Node.js no v3 release supports. Each group that migrates is listed in " +
34
+ "`AwsSdkLockGroupNodeVersions` with its Node.js and the v3 range it gets, flagged where it declares no Node.js.";
35
+ readonly tags = ["aws-sdk", "aws"];
36
+
37
+ readonly dataTables = [awsSdkManualMigrationSteps().descriptor, awsSdkSkippedLockGroups().descriptor, awsSdkLockGroupNodeVersions().descriptor];
38
+
39
+ private readonly steps = awsSdkManualMigrationSteps();
40
+ private readonly skippedGroups = awsSdkSkippedLockGroups();
41
+ private readonly nodeVersions = awsSdkLockGroupNodeVersions();
42
+
43
+ @Option({
44
+ displayName: "Version",
45
+ description: "The version range the migration declares for each added `@aws-sdk/*` package. A lock group whose " +
46
+ "oldest declared Node.js can't run the newest release it admits is left on v2.",
47
+ example: ">=3.723.0 <3.968.0",
48
+ required: false
49
+ })
50
+ version?: string;
51
+
52
+ constructor(options?: {version?: string}) {
53
+ super(options);
54
+ }
55
+
56
+ initialValue(_ctx: ExecutionContext): AwsSdkScan {
57
+ return newAwsSdkScan();
58
+ }
59
+
60
+ async scanner(scan: AwsSdkScan): Promise<TreeVisitor<any, ExecutionContext>> {
61
+ return awsSdkScanner(scan);
62
+ }
63
+
64
+ async editorWithData(scan: AwsSdkScan): Promise<TreeVisitor<any, ExecutionContext>> {
65
+ const plan = new AwsSdkPlan(scan, this.version);
66
+ const skippedGroups = this.skippedGroups;
67
+ const nodeVersions = this.nodeVersions;
68
+ const marker = new class extends JavaScriptVisitor<ExecutionContext> {
69
+ private problems = new Map<string, Problem>();
70
+ private reported = new Set<string>();
71
+ private sourcePath = '';
72
+
73
+ protected override async visitJsCompilationUnit(cu: JS.CompilationUnit, p: ExecutionContext): Promise<J | undefined> {
74
+ const blockers = plan.blockersOf(cu.sourcePath);
75
+ if (blockers.length === 0) return cu;
76
+ const analysis = await analyzeAwsSdk(cu);
77
+ const problems = analysis.problems.filter(problem => (!problem.orphan || blockers.some(b => b.orphan)) &&
78
+ (problem.package === undefined || blockers.some(b => b.package === problem.package)));
79
+ const first = cu.statements.find(s => analysis.bindings.statements.has(s.element.id))?.element;
80
+ if (first && blockers.some(b => b.reason === REASONS.unmovable)) {
81
+ problems.push({id: first.id, construct: 'aws-sdk import', reason: REASONS.unmovable});
82
+ }
83
+ if (blockers.some(b => b.reason === REASONS.exportedClient)) {
84
+ problems.push(...analysis.exports.map(id => ({id, construct: 'exported client', reason: REASONS.exportedClient})));
85
+ }
86
+ this.problems = new Map(problems.map(problem => [problem.id, problem]));
87
+ this.reported = new Set();
88
+ this.sourcePath = cu.sourcePath;
89
+ return this.problems.size === 0 ? cu : super.visitJsCompilationUnit(cu, p);
90
+ }
91
+
92
+ protected override async postVisit(tree: J, p: ExecutionContext): Promise<J | undefined> {
93
+ const problem = this.problems.get(tree.id);
94
+ if (!problem) return tree;
95
+ const marked = foundSearchResult(tree, problem.reason);
96
+ const key = `${problem.construct}\u0000${problem.reason}`;
97
+ if (marked !== tree && !this.reported.has(key)) {
98
+ // Every site is marked; the table reports each construct of a file once.
99
+ this.reported.add(key);
100
+ this.steps.insertRow(p, {sourcePath: this.sourcePath, construct: problem.construct, reason: problem.reason});
101
+ }
102
+ return marked;
103
+ }
104
+
105
+ constructor(private readonly steps: ReturnType<typeof awsSdkManualMigrationSteps>) {
106
+ super();
107
+ }
108
+ }(this.steps);
109
+ return new class extends TreeVisitor<Tree, ExecutionContext> {
110
+ async visit<R extends Tree>(tree: Tree, p: ExecutionContext): Promise<R | undefined> {
111
+ const sourcePath: string | undefined = (tree as any).sourcePath;
112
+ if (tree.kind === Json.Kind.Document && sourcePath && isPackageJson(sourcePath)) {
113
+ const group = plan.skippedGroupOf(sourcePath);
114
+ // Each skipped group is listed once, at the manifest whose lock it shares.
115
+ if (group && group.manifest === normalizePath(sourcePath)) {
116
+ for (const row of skippedRows(group)) skippedGroups.insertRow(p, row);
117
+ }
118
+ const nodeRow = plan.nodeRow(normalizePath(sourcePath));
119
+ if (nodeRow) nodeVersions.insertRow(p, nodeRow);
120
+ return tree as R;
121
+ }
122
+ return tree.kind === JS.Kind.CompilationUnit ? await marker.visit(tree, p) as unknown as R : tree as R;
123
+ }
124
+ };
125
+ }
126
+ }
@@ -0,0 +1,56 @@
1
+ /*
2
+ * Copyright 2026 the original author or authors.
3
+ *
4
+ * Moderne Proprietary. Only for use by Moderne customers under the terms of a commercial contract.
5
+ */
6
+
7
+ import {Option, Recipe} from "@openrewrite/rewrite";
8
+ import {AddAwsSdkV3Dependencies} from "./add-aws-sdk-v3-dependencies";
9
+ import {FindAwsSdkV2ManualMigrations} from "./find-aws-sdk-v2-manual-migrations";
10
+ import {RemoveUnusedAwsSdkV2Dependency} from "./remove-unused-aws-sdk-v2-dependency";
11
+ import {ReplaceAwsSdkV2Clients} from "./replace-aws-sdk-v2-clients";
12
+
13
+ export class MigrateAwsSdkV2ToV3 extends Recipe {
14
+ readonly name = "org.openrewrite.node.migrate.aws-sdk-v3.migrate-aws-sdk-v2-to-v3";
15
+ readonly displayName = "Migrate AWS SDK for JavaScript v2 to v3";
16
+ readonly description = "Moves code from `aws-sdk` (v2) to the modular `@aws-sdk/*` v3 packages the way AWS's " +
17
+ "aws-sdk-js-codemod does by default: each v2 client becomes the v3 client class of the same shape " +
18
+ "(`new S3(...)`, `await s3.getObject(...)`), so call sites change minimally (`ReplaceAwsSdkV2Clients`). " +
19
+ "A lock group (a workspace root with its members, or a standalone `package.json`) is migrated whole or left " +
20
+ "unchanged. What has no mechanical v3 equivalent (global `AWS.config`, `AWS.Request` and its events, credential " +
21
+ "classes, `$response`, an S3 `Body` read as a Buffer, waiters, an exported client another file still calls as v2, " +
22
+ "...) keeps its file on v2 and is listed in the `AwsSdkManualMigrationSteps` data table " +
23
+ "(`FindAwsSdkV2ManualMigrations`). Its lock group then keeps every source, `package.json` and lock as it was, " +
24
+ "and is listed in the `AwsSdkSkippedLockGroups` data table with the files that hold it back. In a group that " +
25
+ "migrates, each `package.json` declaring `aws-sdk` gets the `@aws-sdk/*` packages its sources import " +
26
+ "(`AddAwsSdkV3Dependencies`) and loses `aws-sdk`, with the lock file regenerated " +
27
+ "(`RemoveUnusedAwsSdkV2Dependency`). Migrate what the tables list by hand, then run the recipe again for " +
28
+ "the rest. Current v3 releases require Node.js 20 or later: a group whose oldest declared Node.js " +
29
+ "(`engines.node`, `.nvmrc`, `.node-version`, a Lambda runtime in `serverless.yml`, a SAM or CloudFormation " +
30
+ "template, CDK's `Runtime.NODEJS_18_X` or a `'nodejs18.x'` literal) is 18 or 19 gets the last releases that " +
31
+ "support it (`>=3.723.0 <3.968.0`), and an older one is left on v2 and listed in `AwsSdkSkippedLockGroups`. " +
32
+ "Each migrated group is listed in `AwsSdkLockGroupNodeVersions`, flagged where it declares no Node.js.";
33
+ readonly tags = ["aws-sdk", "aws"];
34
+
35
+ @Option({
36
+ displayName: "Version",
37
+ description: "The version range to declare for each added `@aws-sdk/*` package. A lock group whose oldest " +
38
+ "declared Node.js can't run the newest release it admits is left on v2.",
39
+ example: ">=3.723.0 <3.968.0",
40
+ required: false
41
+ })
42
+ version?: string;
43
+
44
+ constructor(options?: {version?: string}) {
45
+ super(options);
46
+ }
47
+
48
+ async recipeList(): Promise<Recipe[]> {
49
+ return [
50
+ new ReplaceAwsSdkV2Clients({version: this.version}),
51
+ new FindAwsSdkV2ManualMigrations({version: this.version}),
52
+ new AddAwsSdkV3Dependencies({version: this.version}),
53
+ new RemoveUnusedAwsSdkV2Dependency({version: this.version}),
54
+ ];
55
+ }
56
+ }
@@ -0,0 +1,119 @@
1
+ /*
2
+ * Copyright 2026 the original author or authors.
3
+ *
4
+ * Moderne Proprietary. Only for use by Moderne customers under the terms of a commercial contract.
5
+ */
6
+
7
+ import {ExecutionContext, Option, Recipe, ScanningRecipe, Tree, TreeVisitor} from "@openrewrite/rewrite";
8
+ import {findMember, isObject, Json, updateAt} from "@openrewrite/rewrite/json";
9
+ import {removeDependency} from "@openrewrite/rewrite/javascript";
10
+ import {dirOf, isPackageJson} from "../package-json-support";
11
+ import {replaceMember} from "../json-edits";
12
+ import {AWS_SDK, SECTIONS} from "./aws-sdk-v3-support";
13
+ import {AwsSdkPlan, AwsSdkScan, awsSdkScanner, newAwsSdkScan, normalizePath} from "./aws-sdk-v3-plan";
14
+
15
+ // Core's RemoveDependency runs in Java and can't be gated per lock group from a TypeScript composite: a recipe-list
16
+ // entry takes no precondition, and `check` gates a visitor, which would mean calling the prepared recipe's editor
17
+ // ourselves. It does skip a package.json that no longer declares the package, so the package.jsons that keep `aws-sdk`
18
+ // hold it under this key while it runs.
19
+ export const KEPT_KEY = 'aws-sdk (kept by migrate-aws-sdk-v2-to-v3)';
20
+
21
+ /** Renames `from` to `to` in every dependency section that declares it, keeping its place and value. */
22
+ function renameDependency(doc: Json.Document, from: string, to: string): Json.Document {
23
+ let result = doc;
24
+ for (const section of SECTIONS) {
25
+ result = updateAt(result, [section], obj => {
26
+ if (!isObject(obj)) return obj;
27
+ const member = findMember(obj, from);
28
+ return member ? replaceMember(obj, from, to, member.value) : obj;
29
+ });
30
+ }
31
+ return result;
32
+ }
33
+
34
+ function packageJsonEditor(edit: (doc: Json.Document) => Json.Document): TreeVisitor<any, ExecutionContext> {
35
+ return new class extends TreeVisitor<Tree, ExecutionContext> {
36
+ async visit<R extends Tree>(tree: Tree, _p: ExecutionContext): Promise<R | undefined> {
37
+ const sourcePath: string | undefined = (tree as any).sourcePath;
38
+ if (tree.kind !== Json.Kind.Document || !sourcePath || !isPackageJson(sourcePath)) return tree as R;
39
+ return edit(tree as Json.Document) as unknown as R;
40
+ }
41
+ };
42
+ }
43
+
44
+ export class KeepUsedAwsSdkV2Dependency extends ScanningRecipe<AwsSdkScan> {
45
+ readonly name = "org.openrewrite.node.migrate.aws-sdk-v3.keep-used-aws-sdk-v2-dependency";
46
+ readonly displayName = "Set aside `aws-sdk` where it is still used";
47
+ readonly description = "Renames `aws-sdk` in each `package.json` the migration doesn't take it from: those of a " +
48
+ "lock group where a source stays on v2, and those whose sources import nothing from it, so that the removal " +
49
+ "after it leaves them alone. `RestoreKeptAwsSdkV2Dependency` renames it back.";
50
+ readonly tags = ["aws-sdk", "aws"];
51
+
52
+ @Option({
53
+ displayName: "Version",
54
+ description: "The version range the migration declares for each added `@aws-sdk/*` package. A lock group whose " +
55
+ "oldest declared Node.js can't run the newest release it admits is left on v2.",
56
+ example: ">=3.723.0 <3.968.0",
57
+ required: false
58
+ })
59
+ version?: string;
60
+
61
+ constructor(options?: {version?: string}) {
62
+ super(options);
63
+ }
64
+
65
+ initialValue(_ctx: ExecutionContext): AwsSdkScan {
66
+ return newAwsSdkScan();
67
+ }
68
+
69
+ async scanner(scan: AwsSdkScan): Promise<TreeVisitor<any, ExecutionContext>> {
70
+ return awsSdkScanner(scan);
71
+ }
72
+
73
+ async editorWithData(scan: AwsSdkScan): Promise<TreeVisitor<any, ExecutionContext>> {
74
+ const plan = new AwsSdkPlan(scan, this.version);
75
+ return packageJsonEditor(doc => plan.dropsAwsSdk(dirOf(normalizePath(doc.sourcePath))) ? doc : renameDependency(doc, AWS_SDK, KEPT_KEY));
76
+ }
77
+ }
78
+
79
+ export class RestoreKeptAwsSdkV2Dependency extends Recipe {
80
+ readonly name = "org.openrewrite.node.migrate.aws-sdk-v3.restore-kept-aws-sdk-v2-dependency";
81
+ readonly displayName = "Restore the `aws-sdk` set aside where it is still used";
82
+ readonly description = "Renames the `aws-sdk` dependency `KeepUsedAwsSdkV2Dependency` set aside back to `aws-sdk`.";
83
+ readonly tags = ["aws-sdk", "aws"];
84
+
85
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
86
+ return packageJsonEditor(doc => renameDependency(doc, KEPT_KEY, AWS_SDK));
87
+ }
88
+ }
89
+
90
+ export class RemoveUnusedAwsSdkV2Dependency extends Recipe {
91
+ readonly name = "org.openrewrite.node.migrate.aws-sdk-v3.remove-unused-aws-sdk-v2-dependency";
92
+ readonly displayName = "Remove the `aws-sdk` dependency where nothing uses it";
93
+ readonly description = "Removes `aws-sdk` from each `package.json` whose lock group `ReplaceAwsSdkV2Clients` " +
94
+ "migrates and whose sources import a v3 package once migrated, and regenerates the lock file to match, the " +
95
+ "`@aws-sdk/*` packages `AddAwsSdkV3Dependencies` added included. Every `package.json` of a lock group where a " +
96
+ "source stays on v2, or whose Node.js no v3 release supports, keeps `aws-sdk`, and its lock is left as it was.";
97
+ readonly tags = ["aws-sdk", "aws"];
98
+
99
+ @Option({
100
+ displayName: "Version",
101
+ description: "The version range the migration declares for each added `@aws-sdk/*` package. A lock group whose " +
102
+ "oldest declared Node.js can't run the newest release it admits is left on v2.",
103
+ example: ">=3.723.0 <3.968.0",
104
+ required: false
105
+ })
106
+ version?: string;
107
+
108
+ constructor(options?: {version?: string}) {
109
+ super(options);
110
+ }
111
+
112
+ async recipeList(): Promise<Recipe[]> {
113
+ return [
114
+ new KeepUsedAwsSdkV2Dependency({version: this.version}),
115
+ await removeDependency({packageName: AWS_SDK}),
116
+ new RestoreKeptAwsSdkV2Dependency(),
117
+ ];
118
+ }
119
+ }