@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.
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -1
- package/dist/index.js.map +1 -1
- package/dist/migrate/aws-sdk-v3/add-aws-sdk-v3-dependencies.d.ts +16 -0
- package/dist/migrate/aws-sdk-v3/add-aws-sdk-v3-dependencies.d.ts.map +1 -0
- package/dist/migrate/aws-sdk-v3/add-aws-sdk-v3-dependencies.js +89 -0
- package/dist/migrate/aws-sdk-v3/add-aws-sdk-v3-dependencies.js.map +1 -0
- package/dist/migrate/aws-sdk-v3/aws-sdk-v3-node-support.d.ts +33 -0
- package/dist/migrate/aws-sdk-v3/aws-sdk-v3-node-support.d.ts.map +1 -0
- package/dist/migrate/aws-sdk-v3/aws-sdk-v3-node-support.js +190 -0
- package/dist/migrate/aws-sdk-v3/aws-sdk-v3-node-support.js.map +1 -0
- package/dist/migrate/aws-sdk-v3/aws-sdk-v3-plan.d.ts +70 -0
- package/dist/migrate/aws-sdk-v3/aws-sdk-v3-plan.d.ts.map +1 -0
- package/dist/migrate/aws-sdk-v3/aws-sdk-v3-plan.js +315 -0
- package/dist/migrate/aws-sdk-v3/aws-sdk-v3-plan.js.map +1 -0
- package/dist/migrate/aws-sdk-v3/aws-sdk-v3-support.d.ts +181 -0
- package/dist/migrate/aws-sdk-v3/aws-sdk-v3-support.d.ts.map +1 -0
- package/dist/migrate/aws-sdk-v3/aws-sdk-v3-support.js +1504 -0
- package/dist/migrate/aws-sdk-v3/aws-sdk-v3-support.js.map +1 -0
- package/dist/migrate/aws-sdk-v3/aws-sdk-v3-tables.d.ts +3 -0
- package/dist/migrate/aws-sdk-v3/aws-sdk-v3-tables.d.ts.map +1 -0
- package/dist/migrate/aws-sdk-v3/aws-sdk-v3-tables.js +421 -0
- package/dist/migrate/aws-sdk-v3/aws-sdk-v3-tables.js.map +1 -0
- package/dist/migrate/aws-sdk-v3/find-aws-sdk-v2-manual-migrations.d.ts +20 -0
- package/dist/migrate/aws-sdk-v3/find-aws-sdk-v2-manual-migrations.d.ts.map +1 -0
- package/dist/migrate/aws-sdk-v3/find-aws-sdk-v2-manual-migrations.js +146 -0
- package/dist/migrate/aws-sdk-v3/find-aws-sdk-v2-manual-migrations.js.map +1 -0
- package/dist/migrate/aws-sdk-v3/migrate-aws-sdk-v2-to-v3.d.ts +13 -0
- package/dist/migrate/aws-sdk-v3/migrate-aws-sdk-v2-to-v3.d.ts.map +1 -0
- package/dist/migrate/aws-sdk-v3/migrate-aws-sdk-v2-to-v3.js +69 -0
- package/dist/migrate/aws-sdk-v3/migrate-aws-sdk-v2-to-v3.js.map +1 -0
- package/dist/migrate/aws-sdk-v3/remove-unused-aws-sdk-v2-dependency.d.ts +35 -0
- package/dist/migrate/aws-sdk-v3/remove-unused-aws-sdk-v2-dependency.d.ts.map +1 -0
- package/dist/migrate/aws-sdk-v3/remove-unused-aws-sdk-v2-dependency.js +132 -0
- package/dist/migrate/aws-sdk-v3/remove-unused-aws-sdk-v2-dependency.js.map +1 -0
- package/dist/migrate/aws-sdk-v3/replace-aws-sdk-v2-clients.d.ts +18 -0
- package/dist/migrate/aws-sdk-v3/replace-aws-sdk-v2-clients.d.ts.map +1 -0
- package/dist/migrate/aws-sdk-v3/replace-aws-sdk-v2-clients.js +562 -0
- package/dist/migrate/aws-sdk-v3/replace-aws-sdk-v2-clients.js.map +1 -0
- package/dist/migrate/builtin-binding-visitor.d.ts +1 -6
- package/dist/migrate/builtin-binding-visitor.d.ts.map +1 -1
- package/dist/migrate/builtin-binding-visitor.js +6 -69
- package/dist/migrate/builtin-binding-visitor.js.map +1 -1
- package/dist/migrate/express-request-id/replace-express-request-id.d.ts.map +1 -1
- package/dist/migrate/express-request-id/replace-express-request-id.js +1 -2
- package/dist/migrate/express-request-id/replace-express-request-id.js.map +1 -1
- package/dist/migrate/fs-extra/fs-extra-support.d.ts +0 -1
- package/dist/migrate/fs-extra/fs-extra-support.d.ts.map +1 -1
- package/dist/migrate/fs-extra/fs-extra-support.js +1 -2
- package/dist/migrate/fs-extra/fs-extra-support.js.map +1 -1
- package/dist/migrate/increase-node-engine-version.d.ts +1 -0
- package/dist/migrate/increase-node-engine-version.d.ts.map +1 -1
- package/dist/migrate/increase-node-engine-version.js +12 -7
- package/dist/migrate/increase-node-engine-version.js.map +1 -1
- package/dist/migrate/source-map-support/replace-source-map-support-api.js +1 -1
- package/dist/migrate/source-map-support/replace-source-map-support-api.js.map +1 -1
- package/dist/migrate/source-map-support/source-map-support-support.d.ts +0 -1
- package/dist/migrate/source-map-support/source-map-support-support.d.ts.map +1 -1
- package/dist/migrate/source-map-support/source-map-support-support.js +0 -1
- package/dist/migrate/source-map-support/source-map-support-support.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +11 -0
- package/src/migrate/aws-sdk-v3/add-aws-sdk-v3-dependencies.ts +71 -0
- package/src/migrate/aws-sdk-v3/aws-sdk-v3-node-support.ts +172 -0
- package/src/migrate/aws-sdk-v3/aws-sdk-v3-plan.ts +399 -0
- package/src/migrate/aws-sdk-v3/aws-sdk-v3-support.ts +1480 -0
- package/src/migrate/aws-sdk-v3/aws-sdk-v3-tables.ts +432 -0
- package/src/migrate/aws-sdk-v3/find-aws-sdk-v2-manual-migrations.ts +126 -0
- package/src/migrate/aws-sdk-v3/migrate-aws-sdk-v2-to-v3.ts +56 -0
- package/src/migrate/aws-sdk-v3/remove-unused-aws-sdk-v2-dependency.ts +119 -0
- package/src/migrate/aws-sdk-v3/replace-aws-sdk-v2-clients.ts +523 -0
- package/src/migrate/builtin-binding-visitor.ts +9 -94
- package/src/migrate/express-request-id/replace-express-request-id.ts +1 -2
- package/src/migrate/fs-extra/fs-extra-support.ts +1 -2
- package/src/migrate/increase-node-engine-version.ts +11 -7
- package/src/migrate/source-map-support/replace-source-map-support-api.ts +1 -1
- package/src/migrate/source-map-support/source-map-support-support.ts +0 -1
|
@@ -0,0 +1,71 @@
|
|
|
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, ScanningRecipe, Tree, TreeVisitor} from "@openrewrite/rewrite";
|
|
8
|
+
import {Json, jsonLiteral, setAt} from "@openrewrite/rewrite/json";
|
|
9
|
+
import {dirOf, isPackageJson, packageData} from "../package-json-support";
|
|
10
|
+
import {AWS_SDK, SECTIONS} from "./aws-sdk-v3-support";
|
|
11
|
+
import {AwsSdkPlan, AwsSdkScan, awsSdkScanner, newAwsSdkScan, normalizePath} from "./aws-sdk-v3-plan";
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
export class AddAwsSdkV3Dependencies extends ScanningRecipe<AwsSdkScan> {
|
|
15
|
+
readonly name = "org.openrewrite.node.migrate.aws-sdk-v3.add-aws-sdk-v3-dependencies";
|
|
16
|
+
readonly displayName = "Add the AWS SDK v3 packages a project imports";
|
|
17
|
+
readonly description = "In each `package.json` that declares `aws-sdk`, adds the `@aws-sdk/*` packages its " +
|
|
18
|
+
"sources import once `ReplaceAwsSdkV2Clients` has migrated them, in the section that declares `aws-sdk`, and " +
|
|
19
|
+
"`@smithy/smithy-client` where a source names the generic `ServiceException`. Each is declared at `3.x` " +
|
|
20
|
+
"(`4.x` for `@smithy/smithy-client`) where the lock group's oldest declared Node.js (`engines.node`, `.nvmrc`, " +
|
|
21
|
+
"`.node-version`, a Lambda runtime) runs the newest release or declares none, at the bounded range of the " +
|
|
22
|
+
"last releases that support it (`>=3.723.0 <3.968.0` for Node.js 18), and not at all where no release does. " +
|
|
23
|
+
"Like it, it leaves alone every `package.json` of a lock group where a source stays on v2. " +
|
|
24
|
+
"The lock file is not regenerated by this recipe: `RemoveUnusedAwsSdkV2Dependency` regenerates it where " +
|
|
25
|
+
"it removes `aws-sdk`, and elsewhere the package manager's install has to.";
|
|
26
|
+
readonly tags = ["aws-sdk", "aws"];
|
|
27
|
+
|
|
28
|
+
@Option({
|
|
29
|
+
displayName: "Version",
|
|
30
|
+
description: "The version range to declare for each added `@aws-sdk/*` package. A lock group whose oldest " +
|
|
31
|
+
"declared Node.js can't run the newest release it admits is left on v2.",
|
|
32
|
+
example: ">=3.723.0 <3.968.0",
|
|
33
|
+
required: false
|
|
34
|
+
})
|
|
35
|
+
version?: string;
|
|
36
|
+
|
|
37
|
+
constructor(options?: {version?: string}) {
|
|
38
|
+
super(options);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
initialValue(_ctx: ExecutionContext): AwsSdkScan {
|
|
42
|
+
return newAwsSdkScan();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async scanner(scan: AwsSdkScan): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
46
|
+
return awsSdkScanner(scan);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async editorWithData(scan: AwsSdkScan): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
50
|
+
const plan = new AwsSdkPlan(scan, this.version);
|
|
51
|
+
return new class extends TreeVisitor<Tree, ExecutionContext> {
|
|
52
|
+
async visit<R extends Tree>(tree: Tree, _p: ExecutionContext): Promise<R | undefined> {
|
|
53
|
+
const sourcePath: string | undefined = (tree as any).sourcePath;
|
|
54
|
+
if (tree.kind !== Json.Kind.Document || !sourcePath || !isPackageJson(sourcePath)) return tree as R;
|
|
55
|
+
const dir = dirOf(normalizePath(sourcePath));
|
|
56
|
+
const packages = plan.packagesOf(dir);
|
|
57
|
+
const versions = plan.versionsOf(dir);
|
|
58
|
+
if (packages.size === 0 || !versions) return tree as R;
|
|
59
|
+
const pkg = packageData(tree as Json.Document);
|
|
60
|
+
const section = SECTIONS.find(s => pkg?.[s]?.[AWS_SDK] !== undefined);
|
|
61
|
+
if (!pkg || !section) return tree as R;
|
|
62
|
+
let result = tree as Json.Document;
|
|
63
|
+
for (const name of [...packages].sort()) {
|
|
64
|
+
if (SECTIONS.some(s => pkg[s]?.[name] !== undefined)) continue;
|
|
65
|
+
result = setAt(result, [section, name], jsonLiteral(name.startsWith('@smithy/') ? versions.smithy! : versions.awsSdk), {position: 'sorted'});
|
|
66
|
+
}
|
|
67
|
+
return result as unknown as R;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
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 {Column, DataTable, ExecutionContext} from "@openrewrite/rewrite";
|
|
8
|
+
import {J} from "@openrewrite/rewrite/java";
|
|
9
|
+
import {JavaScriptVisitor, JS} from "@openrewrite/rewrite/javascript";
|
|
10
|
+
import * as semver from "semver";
|
|
11
|
+
import {lowestNodeMajor} from "../increase-node-engine-version";
|
|
12
|
+
|
|
13
|
+
interface NodeFloor {
|
|
14
|
+
/** The first release whose `engines.node` asks for `node`. */
|
|
15
|
+
from: string;
|
|
16
|
+
node: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// From npm by scripts/aws-sdk-v3-node-floors.js on 2026-11-11, newest first; ADR 003 cites them.
|
|
20
|
+
const AWS_SDK_NODE_FLOORS: NodeFloor[] = [{"from":"3.968.0","node":20},{"from":"3.723.0","node":18},{"from":"3.567.0","node":16},{"from":"3.201.0","node":14},{"from":"3.46.0","node":12},{"from":"3.0.0","node":10}];
|
|
21
|
+
const SMITHY_NODE_FLOORS: NodeFloor[] = [{"from":"4.0.0","node":18},{"from":"3.0.0","node":16},{"from":"1.0.0","node":14}];
|
|
22
|
+
/** One minor above the newest @smithy/smithy-client the script saw. */
|
|
23
|
+
const SMITHY_BOUND = '4.16.0';
|
|
24
|
+
|
|
25
|
+
/** Below it, Node.js's own npm resolves no v3 release to a tree that declares support for it (ADR 003). */
|
|
26
|
+
export const OLDEST_NODE = 18;
|
|
27
|
+
|
|
28
|
+
/** The Node.js the newest v3 release asks for, which `3.x` installs. */
|
|
29
|
+
export const CURRENT_NODE = AWS_SDK_NODE_FLOORS[0].node;
|
|
30
|
+
|
|
31
|
+
/** What a lock group of the given oldest Node.js declares, or undefined where no v3 release installs on it. */
|
|
32
|
+
export interface V3Versions {
|
|
33
|
+
awsSdk: string;
|
|
34
|
+
/** Undefined where no `@smithy/smithy-client` release supports the Node.js. */
|
|
35
|
+
smithy?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function band(floors: NodeFloor[], i: number): string {
|
|
39
|
+
return i === 0 ? `>=${floors[0].from}` : `>=${floors[i].from} <${floors[i - 1].from}`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The releases of `floors` that the given Node.js runs, newest first. */
|
|
43
|
+
function boundedFor(floors: NodeFloor[], node: number, newestBound: string): string | undefined {
|
|
44
|
+
const i = floors.findIndex(f => f.node <= node);
|
|
45
|
+
if (i < 0) return undefined;
|
|
46
|
+
return i === 0 ? `>=${floors[0].from} <${newestBound}` : band(floors, i);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function smithyFor(node: number): string | undefined {
|
|
50
|
+
return node >= CURRENT_NODE ? `${semver.major(SMITHY_NODE_FLOORS[0].from)}.x` : boundedFor(SMITHY_NODE_FLOORS, node, SMITHY_BOUND);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The Node.js the newest release `range` admits asks for, which is the one npm installs. */
|
|
54
|
+
export function nodeNeededBy(range: string): number {
|
|
55
|
+
for (let i = 0; i < AWS_SDK_NODE_FLOORS.length; i++) {
|
|
56
|
+
try {
|
|
57
|
+
if (semver.intersects(range, band(AWS_SDK_NODE_FLOORS, i))) return AWS_SDK_NODE_FLOORS[i].node;
|
|
58
|
+
} catch {
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// A dist-tag or a range of no v3 release: judged as the newest.
|
|
63
|
+
return CURRENT_NODE;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** What a lock group whose oldest Node.js is `node` declares, given the `version` option if set. */
|
|
67
|
+
export function v3VersionsFor(node: number | undefined, version: string | undefined): V3Versions | undefined {
|
|
68
|
+
const target = node ?? CURRENT_NODE;
|
|
69
|
+
if (version !== undefined) {
|
|
70
|
+
return nodeNeededBy(version) <= target ? {awsSdk: version, smithy: smithyFor(target)} : undefined;
|
|
71
|
+
}
|
|
72
|
+
if (target >= CURRENT_NODE) return {awsSdk: '3.x', smithy: smithyFor(target)};
|
|
73
|
+
if (target < OLDEST_NODE) return undefined;
|
|
74
|
+
return {awsSdk: band(AWS_SDK_NODE_FLOORS, AWS_SDK_NODE_FLOORS.findIndex(f => f.node <= target)), smithy: smithyFor(target)};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Where a project says which Node.js it runs on. */
|
|
78
|
+
export interface NodeSignal {
|
|
79
|
+
path: string;
|
|
80
|
+
/** As the file writes it, e.g. `engines.node >=18`, `.nvmrc 16`, `runtime: nodejs18.x`. */
|
|
81
|
+
declared: string;
|
|
82
|
+
node: number;
|
|
83
|
+
/** `engines.node` speaks for its own `package.json`; a file elsewhere also for the projects beneath it. */
|
|
84
|
+
engines: boolean;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** `engines.node` and Volta's pin, where they name a lowest version; `*` and `>=0.10` say nothing. */
|
|
88
|
+
export function packageJsonSignals(path: string, pkg: Record<string, any> | undefined): NodeSignal[] {
|
|
89
|
+
const signals: NodeSignal[] = [];
|
|
90
|
+
for (const [key, range] of [['engines.node', pkg?.engines?.node], ['volta.node', pkg?.volta?.node]]) {
|
|
91
|
+
const node = typeof range === 'string' ? lowestNodeMajor(range) : undefined;
|
|
92
|
+
if (node) signals.push({path, declared: `${key} ${range}`, node, engines: true});
|
|
93
|
+
}
|
|
94
|
+
return signals;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const LTS_CODENAMES: Record<string, number> = {
|
|
98
|
+
argon: 4, boron: 6, carbon: 8, dubnium: 10, erbium: 12, fermium: 14, gallium: 16, hydrogen: 18, iron: 20, jod: 22,
|
|
99
|
+
krypton: 24
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export const NODE_VERSION_FILE = /(^|\/)\.(nvmrc|node-version)$/;
|
|
103
|
+
|
|
104
|
+
/** `.nvmrc` or `.node-version`: `18`, `v18.17.0` or `lts/hydrogen`. `lts/*`, `node` and `stable` follow the newest. */
|
|
105
|
+
export function versionFileSignal(path: string, text: string): NodeSignal | undefined {
|
|
106
|
+
const value = text.split('\n').map(line => line.replace(/#.*/, '').trim()).find(line => line.length > 0);
|
|
107
|
+
if (!value) return undefined;
|
|
108
|
+
const lts = /^lts\/([a-z]+)$/i.exec(value);
|
|
109
|
+
const node = lts ? LTS_CODENAMES[lts[1].toLowerCase()] : lowestNodeMajor(value.replace(/^v/i, ''));
|
|
110
|
+
return node ? {path, declared: `${path.substring(path.lastIndexOf('/') + 1)} ${value}`, node, engines: false} : undefined;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const YAML_RUNTIME = /^[ \t-]*runtime[ \t]*:[ \t]*['"]?nodejs(\d+)\.x\b/gim;
|
|
114
|
+
|
|
115
|
+
/** The Lambda runtimes of a Serverless, SAM or CloudFormation template (`runtime: nodejs18.x`, `Runtime: nodejs18.x`). */
|
|
116
|
+
export function yamlSignals(path: string, text: string): NodeSignal[] {
|
|
117
|
+
return [...text.matchAll(YAML_RUNTIME)].map(m => ({path, declared: m[0].replace(/^[ \t-]*/, ''), node: parseInt(m[1], 10), engines: false}));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const RUNTIME_LITERAL = /^nodejs(\d+)\.x$/;
|
|
121
|
+
const CDK_RUNTIME = /^NODEJS_(\d+)_X$/;
|
|
122
|
+
|
|
123
|
+
/** The Lambda runtimes a source names: CDK's `Runtime.NODEJS_18_X`, or `'nodejs18.x'` as SST and `serverless.ts` write it. */
|
|
124
|
+
export async function sourceRuntimes(cu: JS.CompilationUnit): Promise<{declared: string; node: number}[]> {
|
|
125
|
+
const found: {declared: string; node: number}[] = [];
|
|
126
|
+
await new class extends JavaScriptVisitor<ExecutionContext> {
|
|
127
|
+
protected override async visitLiteral(literal: J.Literal, p: ExecutionContext): Promise<J | undefined> {
|
|
128
|
+
const m = typeof literal.value === 'string' ? RUNTIME_LITERAL.exec(literal.value) : null;
|
|
129
|
+
if (m) found.push({declared: `'${literal.value}'`, node: parseInt(m[1], 10)});
|
|
130
|
+
return super.visitLiteral(literal, p);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
protected override async visitFieldAccess(fieldAccess: J.FieldAccess, p: ExecutionContext): Promise<J | undefined> {
|
|
134
|
+
const name = fieldAccess.name.element.simpleName;
|
|
135
|
+
const m = CDK_RUNTIME.exec(name);
|
|
136
|
+
const target = fieldAccess.target;
|
|
137
|
+
const onRuntime = (target.kind === J.Kind.Identifier && (target as J.Identifier).simpleName === 'Runtime') ||
|
|
138
|
+
(target.kind === J.Kind.FieldAccess && (target as J.FieldAccess).name.element.simpleName === 'Runtime');
|
|
139
|
+
if (m && onRuntime) found.push({declared: `Runtime.${name}`, node: parseInt(m[1], 10)});
|
|
140
|
+
return super.visitFieldAccess(fieldAccess, p);
|
|
141
|
+
}
|
|
142
|
+
}().visit(cu, new ExecutionContext());
|
|
143
|
+
return found;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export class AwsSdkLockGroupNodeVersion {
|
|
147
|
+
@Column({displayName: "Lock group", description: "The `package.json` whose lock the group shares: a workspace root's, or a standalone project's."})
|
|
148
|
+
lockGroup!: string;
|
|
149
|
+
|
|
150
|
+
@Column({displayName: "Node.js version", description: "The oldest Node.js major the group declares, or empty where it declares none."})
|
|
151
|
+
nodeVersion!: string;
|
|
152
|
+
|
|
153
|
+
@Column({displayName: "Declared in", description: "The file that declares that version, and how (`engines.node`, `.nvmrc`, `.node-version`, a Lambda runtime)."})
|
|
154
|
+
declaredIn!: string;
|
|
155
|
+
|
|
156
|
+
@Column({displayName: "AWS SDK v3 version", description: "The range declared for each added `@aws-sdk/*` package, or empty where the group is left on v2."})
|
|
157
|
+
awsSdkVersion!: string;
|
|
158
|
+
|
|
159
|
+
@Column({displayName: "Note", description: "Why the group got that range, was left on v2, or should be checked by hand."})
|
|
160
|
+
note!: string;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export function awsSdkLockGroupNodeVersions(): DataTable<AwsSdkLockGroupNodeVersion> {
|
|
164
|
+
return new DataTable<AwsSdkLockGroupNodeVersion>(
|
|
165
|
+
"org.openrewrite.node.table.AwsSdkLockGroupNodeVersions",
|
|
166
|
+
"AWS SDK v3 lock groups by Node.js version",
|
|
167
|
+
"Each lock group whose sources migrate to v3, with the oldest Node.js it declares and the `@aws-sdk/*` range " +
|
|
168
|
+
"that Node.js runs. A group whose Node.js no v3 release supports is left on v2, and one that declares no " +
|
|
169
|
+
"Node.js migrates at the newest v3 and should be checked against the Node.js it runs on.",
|
|
170
|
+
AwsSdkLockGroupNodeVersion,
|
|
171
|
+
);
|
|
172
|
+
}
|
|
@@ -0,0 +1,399 @@
|
|
|
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 {builtinModules} from "module";
|
|
8
|
+
import {Column, DataTable, ExecutionContext, Tree, TreePrinters, TreeVisitor} from "@openrewrite/rewrite";
|
|
9
|
+
import {Json} from "@openrewrite/rewrite/json";
|
|
10
|
+
import {findNodeResolutionResult, JS} from "@openrewrite/rewrite/javascript";
|
|
11
|
+
import {PlainText} from "@openrewrite/rewrite/text";
|
|
12
|
+
import {Yaml} from "@openrewrite/rewrite/yaml";
|
|
13
|
+
import {dirOf, isPackageJson, packageData} from "../package-json-support";
|
|
14
|
+
import {analyzeAwsSdk, Analysis, declaresAwsSdk, ownerOf, REASONS, SECTIONS, SMITHY_CLIENT} from "./aws-sdk-v3-support";
|
|
15
|
+
import {
|
|
16
|
+
AwsSdkLockGroupNodeVersion,
|
|
17
|
+
CURRENT_NODE,
|
|
18
|
+
NODE_VERSION_FILE,
|
|
19
|
+
nodeNeededBy,
|
|
20
|
+
NodeSignal,
|
|
21
|
+
packageJsonSignals,
|
|
22
|
+
OLDEST_NODE,
|
|
23
|
+
sourceRuntimes,
|
|
24
|
+
V3Versions,
|
|
25
|
+
v3VersionsFor,
|
|
26
|
+
versionFileSignal,
|
|
27
|
+
yamlSignals
|
|
28
|
+
} from "./aws-sdk-v3-node-support";
|
|
29
|
+
// A cycle, used only at run time: the plan dry-runs that recipe's editor on each source.
|
|
30
|
+
import {migrates} from "./replace-aws-sdk-v2-clients";
|
|
31
|
+
|
|
32
|
+
const PARSE_ERROR = "org.openrewrite.tree.ParseError";
|
|
33
|
+
const SOURCE_FILE = /\.([cm]?[jt]sx?|vue|svelte|astro)$/;
|
|
34
|
+
const REFERENCE = /['"`]aws-sdk(\/[^'"`]*)?['"`]/;
|
|
35
|
+
|
|
36
|
+
/** What keeps a source on v2, as the `AwsSdkManualMigrationSteps` table names it. */
|
|
37
|
+
export interface Blocker {
|
|
38
|
+
construct: string;
|
|
39
|
+
reason: string;
|
|
40
|
+
/** A v2 call on a value from another file, which only counts in a lock group that declares `aws-sdk`. */
|
|
41
|
+
orphan?: boolean;
|
|
42
|
+
/** The package the call's receiver comes from, which voids the blocker where the source's project declares it. */
|
|
43
|
+
package?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** What one source needs, judged alone. */
|
|
47
|
+
interface SourceScan {
|
|
48
|
+
/** It binds the SDK at the top level. */
|
|
49
|
+
bound: boolean;
|
|
50
|
+
/** What keeps it on v2 taken alone. */
|
|
51
|
+
blockers: Blocker[];
|
|
52
|
+
/** The v3 packages it imports once migrated. */
|
|
53
|
+
packages: string[];
|
|
54
|
+
/** It exports a client another file may call as v2. */
|
|
55
|
+
exports: boolean;
|
|
56
|
+
/** It calls a v2-only API on a value from another file. */
|
|
57
|
+
foreign: boolean;
|
|
58
|
+
/** The Lambda runtimes it names. */
|
|
59
|
+
runtimes: {declared: string; node: number}[];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
interface ManifestScan {
|
|
63
|
+
declaresAwsSdk: boolean;
|
|
64
|
+
/** The packages it declares in any dependency section. */
|
|
65
|
+
dependencies: string[];
|
|
66
|
+
/** The `workspaces` globs of a workspace root, for an LST without the resolution marker. */
|
|
67
|
+
workspaces: string[];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** What the steps of the migration scan, which decides what each of them edits. */
|
|
71
|
+
export interface AwsSdkScan {
|
|
72
|
+
sources: Map<string, SourceScan>;
|
|
73
|
+
/** By the directory of each `package.json`. */
|
|
74
|
+
manifests: Map<string, ManifestScan>;
|
|
75
|
+
/** Each workspace member's directory, to its workspace root's, from the resolution markers. */
|
|
76
|
+
workspaceRoots: Map<string, string>;
|
|
77
|
+
nodeSignals: NodeSignal[];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function newAwsSdkScan(): AwsSdkScan {
|
|
81
|
+
return {sources: new Map(), manifests: new Map(), workspaceRoots: new Map(), nodeSignals: []};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Each step scans the same trees, so a source is analyzed and dry-run once per cycle rather than once per step.
|
|
85
|
+
const scans = new WeakMap<object, Promise<SourceScan>>();
|
|
86
|
+
|
|
87
|
+
async function scanSource(cu: JS.CompilationUnit, ctx: ExecutionContext): Promise<SourceScan> {
|
|
88
|
+
let scan = scans.get(cu);
|
|
89
|
+
if (!scan) {
|
|
90
|
+
scan = (async () => {
|
|
91
|
+
const analysis: Analysis = await analyzeAwsSdk(cu);
|
|
92
|
+
const bound = analysis.bindings.statements.size > 0;
|
|
93
|
+
const blockers: Blocker[] = analysis.problems.map(p => ({construct: p.construct, reason: p.reason, orphan: p.orphan, package: p.package}));
|
|
94
|
+
if (bound && blockers.length === 0 && !await migrates(cu, ctx)) {
|
|
95
|
+
blockers.push({construct: 'aws-sdk import', reason: REASONS.unmovable});
|
|
96
|
+
}
|
|
97
|
+
const runtimes = await sourceRuntimes(cu);
|
|
98
|
+
return {bound, blockers, packages: [...analysis.packages], exports: analysis.exports.length > 0, foreign: analysis.foreign, runtimes};
|
|
99
|
+
})();
|
|
100
|
+
scans.set(cu, scan);
|
|
101
|
+
}
|
|
102
|
+
return scan;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function normalizePath(path: string): string {
|
|
106
|
+
return path.replace(/\\/g, '/').replace(/^\.\//, '');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function workspaceGlobs(pkg: Record<string, any> | undefined): string[] {
|
|
110
|
+
const workspaces = pkg?.workspaces;
|
|
111
|
+
const globs = Array.isArray(workspaces) ? workspaces : Array.isArray(workspaces?.packages) ? workspaces.packages : [];
|
|
112
|
+
return globs.filter((g: unknown): g is string => typeof g === 'string');
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** `packages/*`, `apps/**`, `!packages/skip` as a test on a directory relative to the workspace root. */
|
|
116
|
+
function globMatcher(globs: string[]): (dir: string) => boolean {
|
|
117
|
+
const toRegex = (glob: string) => new RegExp('^' + normalizePath(glob).replace(/\/+$/, '').split('/').map(segment =>
|
|
118
|
+
segment === '**' ? '.*' : segment.replace(/[.+^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '[^/]*').replace(/\?/g, '[^/]')
|
|
119
|
+
).join('/').replace(/\/\.\*$/, '(/.*)?') + '$');
|
|
120
|
+
const include = globs.filter(g => !g.startsWith('!')).map(toRegex);
|
|
121
|
+
const exclude = globs.filter(g => g.startsWith('!')).map(g => toRegex(g.slice(1)));
|
|
122
|
+
return dir => include.some(r => r.test(dir)) && !exclude.some(r => r.test(dir));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function awsSdkScanner(scan: AwsSdkScan): TreeVisitor<any, ExecutionContext> {
|
|
126
|
+
return new class extends TreeVisitor<Tree, ExecutionContext> {
|
|
127
|
+
async visit<R extends Tree>(tree: Tree, ctx: ExecutionContext): Promise<R | undefined> {
|
|
128
|
+
const raw: string | undefined = (tree as any).sourcePath;
|
|
129
|
+
if (!raw || raw.includes('node_modules/')) return tree as R;
|
|
130
|
+
const sourcePath = normalizePath(raw);
|
|
131
|
+
if (tree.kind === JS.Kind.CompilationUnit) {
|
|
132
|
+
const source = await scanSource(tree as JS.CompilationUnit, ctx);
|
|
133
|
+
if (source.bound || source.blockers.length > 0 || source.foreign) scan.sources.set(sourcePath, source);
|
|
134
|
+
scan.nodeSignals.push(...source.runtimes.map(r => ({path: sourcePath, ...r, engines: false})));
|
|
135
|
+
} else if (tree.kind === Json.Kind.Document && isPackageJson(sourcePath)) {
|
|
136
|
+
const pkg = packageData(tree as Json.Document);
|
|
137
|
+
const dir = dirOf(sourcePath);
|
|
138
|
+
scan.manifests.set(dir, {declaresAwsSdk: declaresAwsSdk(pkg), dependencies: declaredPackages(pkg), workspaces: workspaceGlobs(pkg)});
|
|
139
|
+
for (const member of findNodeResolutionResult(tree as Json.Document)?.workspacePackagePaths ?? []) {
|
|
140
|
+
scan.workspaceRoots.set(dirOf(normalizePath(member)), dir);
|
|
141
|
+
}
|
|
142
|
+
scan.nodeSignals.push(...packageJsonSignals(sourcePath, pkg));
|
|
143
|
+
} else if (tree.kind === PlainText.Kind.PlainText && NODE_VERSION_FILE.test(sourcePath)) {
|
|
144
|
+
const signal = versionFileSignal(sourcePath, (tree as PlainText).text);
|
|
145
|
+
if (signal) scan.nodeSignals.push(signal);
|
|
146
|
+
} else if (tree.kind === Yaml.Kind.Documents) {
|
|
147
|
+
scan.nodeSignals.push(...yamlSignals(sourcePath, await TreePrinters.print(tree as any)));
|
|
148
|
+
} else if ((tree.kind === PARSE_ERROR || tree.kind === PlainText.Kind.PlainText) && SOURCE_FILE.test(sourcePath) &&
|
|
149
|
+
REFERENCE.test(await TreePrinters.print(tree as any))) {
|
|
150
|
+
scan.sources.set(sourcePath, {
|
|
151
|
+
bound: true, packages: [], exports: false, foreign: false, runtimes: [],
|
|
152
|
+
blockers: [{construct: 'unparsed source', reason: REASONS.unparsed}]
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
return tree as R;
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** A lock group the migration leaves unchanged, and the sources that keep it on v2. */
|
|
161
|
+
export interface SkippedGroup {
|
|
162
|
+
/** The `package.json` whose lock the group shares: its workspace root's, or its own. */
|
|
163
|
+
manifest: string;
|
|
164
|
+
blocked: Map<string, Blocker[]>;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** How a lock group whose sources migrate is judged by the oldest Node.js it declares. */
|
|
168
|
+
interface NodeVerdict {
|
|
169
|
+
manifest: string;
|
|
170
|
+
signal?: NodeSignal;
|
|
171
|
+
/** Undefined where the group is left on v2 for its Node.js. */
|
|
172
|
+
versions?: V3Versions;
|
|
173
|
+
note: string;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Which sources and manifests the migration changes. The unit is a lock group, the directory whose lock file is
|
|
178
|
+
* regenerated: a workspace root with its members, or a standalone `package.json`. A group migrates only when every
|
|
179
|
+
* source in it that uses the SDK migrates; otherwise none of its sources, manifests or lock change. A source with no
|
|
180
|
+
* `package.json` above it has no lock and is judged alone.
|
|
181
|
+
*/
|
|
182
|
+
export class AwsSdkPlan {
|
|
183
|
+
private readonly manifestDirs: string[];
|
|
184
|
+
private readonly sdkDirs: string[];
|
|
185
|
+
private readonly rootOf = new Map<string, string>();
|
|
186
|
+
/** By lock group, the sources that keep it on v2. */
|
|
187
|
+
readonly skipped = new Map<string, SkippedGroup>();
|
|
188
|
+
/** By source, what keeps it on v2. */
|
|
189
|
+
private readonly blockers = new Map<string, Blocker[]>();
|
|
190
|
+
/** By lock group whose sources migrate, what its Node.js lets it declare. */
|
|
191
|
+
private readonly nodes = new Map<string, NodeVerdict>();
|
|
192
|
+
|
|
193
|
+
/** `version` is the range the user asks to declare for each `@aws-sdk/*` package, which a group's Node.js may rule out. */
|
|
194
|
+
constructor(private readonly scan: AwsSdkScan, version?: string) {
|
|
195
|
+
this.manifestDirs = [...scan.manifests.keys()].sort((a, b) => b.length - a.length);
|
|
196
|
+
this.sdkDirs = [...scan.manifests].filter(([, m]) => m.declaresAwsSdk).map(([dir]) => dir);
|
|
197
|
+
for (const [member, root] of scan.workspaceRoots) this.rootOf.set(member, root);
|
|
198
|
+
for (const [root, manifest] of scan.manifests) {
|
|
199
|
+
if (manifest.workspaces.length === 0) continue;
|
|
200
|
+
const matches = globMatcher(manifest.workspaces);
|
|
201
|
+
for (const dir of this.manifestDirs) {
|
|
202
|
+
if (dir === root || this.rootOf.has(dir)) continue;
|
|
203
|
+
const relative = root === '' ? dir : dir.startsWith(root + '/') ? dir.substring(root.length + 1) : undefined;
|
|
204
|
+
if (relative !== undefined && matches(relative)) this.rootOf.set(dir, root);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const declaring = new Set<string>();
|
|
209
|
+
for (const dir of this.sdkDirs) declaring.add(this.groupOfDir(dir));
|
|
210
|
+
// Sources with no `package.json` above them share no lock, but may still hand each other a client.
|
|
211
|
+
const NO_GROUP = '\u0000';
|
|
212
|
+
const foreignByGroup = new Map<string, string[]>();
|
|
213
|
+
const standing = new Map<string, Blocker[]>();
|
|
214
|
+
for (const [path, source] of scan.sources) {
|
|
215
|
+
const group = this.sourceGroupOf(path) ?? NO_GROUP;
|
|
216
|
+
const kept = source.blockers.filter(b => b.package === undefined || !this.resolves(path, b.package));
|
|
217
|
+
standing.set(path, kept);
|
|
218
|
+
if (source.foreign || kept.some(b => b.package !== undefined)) foreignByGroup.set(group, [...foreignByGroup.get(group) ?? [], path]);
|
|
219
|
+
}
|
|
220
|
+
for (const [path, source] of scan.sources) {
|
|
221
|
+
const group = this.sourceGroupOf(path);
|
|
222
|
+
const blockers = standing.get(path)!.filter(b => !b.orphan || (group !== undefined && declaring.has(group)));
|
|
223
|
+
if (blockers.length === 0 && source.exports && (foreignByGroup.get(group ?? NO_GROUP) ?? []).some(f => f !== path)) {
|
|
224
|
+
blockers.push({construct: 'exported client', reason: REASONS.exportedClient});
|
|
225
|
+
}
|
|
226
|
+
if (blockers.length === 0) continue;
|
|
227
|
+
this.blockers.set(path, blockers);
|
|
228
|
+
if (group === undefined) continue;
|
|
229
|
+
this.skip(group, path, blockers);
|
|
230
|
+
}
|
|
231
|
+
this.judgeNode(version);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
private skip(group: string, path: string, blockers: Blocker[]) {
|
|
235
|
+
const skipped = this.skipped.get(group) ?? {manifest: manifestOf(group), blocked: new Map()};
|
|
236
|
+
skipped.blocked.set(path, blockers);
|
|
237
|
+
this.skipped.set(group, skipped);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** Leaves on v2 each group whose oldest Node.js no v3 release (or the `version` asked for) supports. */
|
|
241
|
+
private judgeNode(version: string | undefined) {
|
|
242
|
+
const smithy = new Set<string>();
|
|
243
|
+
const migrating = new Set<string>();
|
|
244
|
+
for (const [path, source] of this.scan.sources) {
|
|
245
|
+
const group = this.sourceGroupOf(path);
|
|
246
|
+
if (!source.bound || this.blockers.has(path) || group === undefined || this.skipped.has(group)) continue;
|
|
247
|
+
migrating.add(group);
|
|
248
|
+
if (source.packages.includes(SMITHY_CLIENT)) smithy.add(group);
|
|
249
|
+
}
|
|
250
|
+
for (const group of migrating) {
|
|
251
|
+
const signal = this.scan.nodeSignals
|
|
252
|
+
.filter(s => this.speaksFor(s, group))
|
|
253
|
+
.sort((a, b) => a.node - b.node || a.path.localeCompare(b.path))[0];
|
|
254
|
+
const found = v3VersionsFor(signal?.node, version);
|
|
255
|
+
const versions = found && (found.smithy || !smithy.has(group)) ? found : undefined;
|
|
256
|
+
const needs = version !== undefined ? nodeNeededBy(version) : found ? CURRENT_NODE : OLDEST_NODE;
|
|
257
|
+
let note = '';
|
|
258
|
+
if (!signal) {
|
|
259
|
+
note = `Node.js version undeclared; v3 needs >= ${needs}`;
|
|
260
|
+
} else if (!versions) {
|
|
261
|
+
note = found ? `Node.js ${signal.node} (${signal.declared}); no @smithy/smithy-client release supports it` :
|
|
262
|
+
`Node.js ${signal.node} (${signal.declared}); ${version !== undefined ? `version ${version}` : 'AWS SDK v3'} needs >= ${needs}`;
|
|
263
|
+
this.skip(group, signal.path, [{construct: note, reason: note}]);
|
|
264
|
+
} else if (version === undefined && signal.node < CURRENT_NODE) {
|
|
265
|
+
note = `Node.js ${signal.node} (${signal.declared}); newer v3 releases need >= ${CURRENT_NODE}, and a lock regenerated on a newer Node.js may pin @aws-sdk/util-locate-window >= 20 (npm update it on Node.js ${signal.node})`;
|
|
266
|
+
}
|
|
267
|
+
this.nodes.set(group, {manifest: manifestOf(group), signal, versions, note});
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** `engines.node` speaks for its lock group; any other file for its own group and every group beneath it. */
|
|
272
|
+
private speaksFor(signal: NodeSignal, group: string): boolean {
|
|
273
|
+
if (this.groupOf(signal.path) === group) return true;
|
|
274
|
+
if (signal.engines) return false;
|
|
275
|
+
const base = dirOf(signal.path);
|
|
276
|
+
return this.manifestDirs.some(dir => this.groupOfDir(dir) === group && (base === '' || dir === base || dir.startsWith(base + '/')));
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/** Whether `pkg` is a Node.js built-in or declared by a `package.json` the source at `path` resolves packages from. */
|
|
280
|
+
private resolves(path: string, pkg: string): boolean {
|
|
281
|
+
if (pkg.startsWith('node:') || builtinModules.includes(pkg)) return true;
|
|
282
|
+
const p = normalizePath(path);
|
|
283
|
+
return [...this.scan.manifests].some(([dir, m]) => (dir === '' || p.startsWith(dir + '/')) && m.dependencies.includes(pkg));
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
private groupOfDir(dir: string): string {
|
|
287
|
+
return this.rootOf.get(dir) ?? dir;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* The lock group of a source: that of the nearest `package.json` above it declaring `aws-sdk`, which is what it
|
|
292
|
+
* resolves the SDK from and what loses it, else that of its nearest `package.json`. A nested `package.json` that
|
|
293
|
+
* doesn't declare the SDK (`{"type": "module"}` in a test folder, an example app) doesn't split its sources off.
|
|
294
|
+
*/
|
|
295
|
+
sourceGroupOf(path: string): string | undefined {
|
|
296
|
+
const owner = ownerOf(normalizePath(path), this.sdkDirs);
|
|
297
|
+
return owner === undefined ? this.groupOf(path) : this.groupOfDir(owner);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/** The directory of the lock `path` belongs to, or undefined where no `package.json` is above it. */
|
|
301
|
+
groupOf(path: string): string | undefined {
|
|
302
|
+
const p = normalizePath(path);
|
|
303
|
+
const dir = this.manifestDirs.find(d => d === '' || p.startsWith(d + '/'));
|
|
304
|
+
return dir === undefined ? undefined : this.groupOfDir(dir);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/** Whether the source at `path` is migrated: it uses the SDK, and nothing in it or its lock group stays on v2. */
|
|
308
|
+
migrates(path: string): boolean {
|
|
309
|
+
const p = normalizePath(path);
|
|
310
|
+
const source = this.scan.sources.get(p);
|
|
311
|
+
if (!source?.bound || this.blockers.has(p)) return false;
|
|
312
|
+
const group = this.sourceGroupOf(p);
|
|
313
|
+
return group === undefined || !this.skipped.has(group);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/** What keeps the source at `path` itself on v2, which `FindAwsSdkV2ManualMigrations` marks. */
|
|
317
|
+
blockersOf(path: string): Blocker[] {
|
|
318
|
+
return this.blockers.get(normalizePath(path)) ?? [];
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/** The lock group the `package.json` at `path` belongs to, if the migration leaves it unchanged. */
|
|
322
|
+
skippedGroupOf(path: string): SkippedGroup | undefined {
|
|
323
|
+
const group = this.groupOf(path);
|
|
324
|
+
return group === undefined ? undefined : this.skipped.get(group);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/** The v3 packages the migrated sources of the `package.json` in `dir` import, which declares `aws-sdk`. */
|
|
328
|
+
packagesOf(dir: string): Set<string> {
|
|
329
|
+
const packages = new Set<string>();
|
|
330
|
+
if (!this.sdkDirs.includes(dir)) return packages;
|
|
331
|
+
for (const [path, source] of this.scan.sources) {
|
|
332
|
+
if (ownerOf(path, this.sdkDirs) === dir && this.migrates(path)) source.packages.forEach(p => packages.add(p));
|
|
333
|
+
}
|
|
334
|
+
return packages;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/** The ranges the `package.json` in `dir` declares for the v3 packages it gains. */
|
|
338
|
+
versionsOf(dir: string): V3Versions | undefined {
|
|
339
|
+
return this.nodes.get(this.groupOfDir(dir))?.versions;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/** Each lock group whose sources migrate, by its Node.js, for the `AwsSdkLockGroupNodeVersions` table. */
|
|
343
|
+
nodeRow(manifest: string): AwsSdkLockGroupNodeVersion | undefined {
|
|
344
|
+
const verdict = [...this.nodes.values()].find(v => v.manifest === manifest);
|
|
345
|
+
return verdict && {
|
|
346
|
+
lockGroup: verdict.manifest,
|
|
347
|
+
nodeVersion: verdict.signal ? String(verdict.signal.node) : '',
|
|
348
|
+
declaredIn: verdict.signal ? `${verdict.signal.path}: ${verdict.signal.declared}` : '',
|
|
349
|
+
awsSdkVersion: verdict.versions?.awsSdk ?? '',
|
|
350
|
+
note: verdict.note
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/** Whether the `package.json` in `dir` loses `aws-sdk`: its sources move to v3, or its group's lock is regenerated, which can't be with `aws-sdk` set aside. */
|
|
355
|
+
dropsAwsSdk(dir: string): boolean {
|
|
356
|
+
if (this.packagesOf(dir).size > 0) return true;
|
|
357
|
+
const group = this.groupOfDir(dir);
|
|
358
|
+
return this.sdkDirs.includes(dir) && this.sdkDirs.some(other => this.groupOfDir(other) === group && this.packagesOf(other).size > 0);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
function declaredPackages(pkg: Record<string, any> | undefined): string[] {
|
|
363
|
+
return SECTIONS.flatMap(section => pkg?.[section] && typeof pkg[section] === 'object' ? Object.keys(pkg[section]) : []);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
function manifestOf(group: string): string {
|
|
367
|
+
return group === '' ? 'package.json' : `${group}/package.json`;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
export class AwsSdkSkippedLockGroup {
|
|
371
|
+
@Column({displayName: "Lock group", description: "The `package.json` whose lock the group shares: a workspace root's, or a standalone project's."})
|
|
372
|
+
lockGroup!: string;
|
|
373
|
+
|
|
374
|
+
@Column({displayName: "Source path", description: "A source in the group that stays on AWS SDK v2, which keeps the whole group on v2, or the file declaring a Node.js no v3 release supports."})
|
|
375
|
+
sourcePath!: string;
|
|
376
|
+
|
|
377
|
+
@Column({displayName: "Constructs", description: "What keeps the source on v2, each listed with its reason in `AwsSdkManualMigrationSteps`, or the Node.js version and what v3 needs."})
|
|
378
|
+
constructs!: string;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
export function awsSdkSkippedLockGroups(): DataTable<AwsSdkSkippedLockGroup> {
|
|
382
|
+
return new DataTable<AwsSdkSkippedLockGroup>(
|
|
383
|
+
"org.openrewrite.node.table.AwsSdkSkippedLockGroups",
|
|
384
|
+
"AWS SDK v2 lock groups left unchanged",
|
|
385
|
+
"Lock groups (a workspace root with its members, or a standalone `package.json`) the migration to v3 left " +
|
|
386
|
+
"wholly unchanged, one row for each source that keeps the group on v2. Migrate those by hand, then run the " +
|
|
387
|
+
"migration again.",
|
|
388
|
+
AwsSdkSkippedLockGroup,
|
|
389
|
+
);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/** One row per source that keeps the lock group on v2, each construct named once. */
|
|
393
|
+
export function skippedRows(group: SkippedGroup): AwsSdkSkippedLockGroup[] {
|
|
394
|
+
return [...group.blocked].sort(([a], [b]) => a.localeCompare(b)).map(([sourcePath, blockers]) => ({
|
|
395
|
+
lockGroup: group.manifest,
|
|
396
|
+
sourcePath,
|
|
397
|
+
constructs: [...new Set(blockers.map(b => b.construct))].join(', ')
|
|
398
|
+
}));
|
|
399
|
+
}
|