@openrewrite/rewrite 8.83.3 → 8.83.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -5
- package/dist/index.js.map +1 -1
- package/dist/java/rpc.d.ts.map +1 -1
- package/dist/java/rpc.js +2 -0
- package/dist/java/rpc.js.map +1 -1
- package/dist/java/tree.d.ts +1 -0
- package/dist/java/tree.d.ts.map +1 -1
- package/dist/java/tree.js.map +1 -1
- package/dist/java/visitor.d.ts.map +1 -1
- package/dist/java/visitor.js +1 -0
- package/dist/java/visitor.js.map +1 -1
- package/dist/javascript/parser.d.ts.map +1 -1
- package/dist/javascript/parser.js +8 -0
- package/dist/javascript/parser.js.map +1 -1
- package/dist/javascript/recipes/dependencies.d.ts +63 -0
- package/dist/javascript/recipes/dependencies.d.ts.map +1 -0
- package/dist/javascript/recipes/dependencies.js +49 -0
- package/dist/javascript/recipes/dependencies.js.map +1 -0
- package/dist/javascript/recipes/index.d.ts +1 -4
- package/dist/javascript/recipes/index.d.ts.map +1 -1
- package/dist/javascript/recipes/index.js +1 -4
- package/dist/javascript/recipes/index.js.map +1 -1
- package/dist/rewrite-javascript-version.txt +1 -1
- package/dist/rpc/index.d.ts +1 -0
- package/dist/rpc/index.d.ts.map +1 -1
- package/dist/rpc/index.js +3 -1
- package/dist/rpc/index.js.map +1 -1
- package/dist/rpc/java-recipe.d.ts +33 -0
- package/dist/rpc/java-recipe.d.ts.map +1 -0
- package/dist/rpc/java-recipe.js +61 -0
- package/dist/rpc/java-recipe.js.map +1 -0
- package/dist/rpc/java-rpc-client.d.ts +65 -0
- package/dist/rpc/java-rpc-client.d.ts.map +1 -0
- package/dist/rpc/java-rpc-client.js +221 -0
- package/dist/rpc/java-rpc-client.js.map +1 -0
- package/dist/rpc/rewrite-rpc.d.ts +9 -0
- package/dist/rpc/rewrite-rpc.d.ts.map +1 -1
- package/dist/rpc/rewrite-rpc.js +23 -1
- package/dist/rpc/rewrite-rpc.js.map +1 -1
- package/dist/test/java-rpc.d.ts +46 -0
- package/dist/test/java-rpc.d.ts.map +1 -0
- package/dist/test/java-rpc.js +79 -0
- package/dist/test/java-rpc.js.map +1 -0
- package/package.json +5 -1
- package/src/index.ts +0 -8
- package/src/java/rpc.ts +2 -0
- package/src/java/tree.ts +1 -0
- package/src/java/visitor.ts +1 -0
- package/src/javascript/parser.ts +8 -0
- package/src/javascript/recipes/dependencies.ts +108 -0
- package/src/javascript/recipes/index.ts +1 -4
- package/src/rpc/index.ts +1 -0
- package/src/rpc/java-recipe.ts +64 -0
- package/src/rpc/java-rpc-client.ts +220 -0
- package/src/rpc/rewrite-rpc.ts +34 -6
- package/src/test/java-rpc.ts +93 -0
- package/dist/javascript/recipes/add-dependency.d.ts +0 -61
- package/dist/javascript/recipes/add-dependency.d.ts.map +0 -1
- package/dist/javascript/recipes/add-dependency.js +0 -430
- package/dist/javascript/recipes/add-dependency.js.map +0 -1
- package/dist/javascript/recipes/remove-dependency.d.ts +0 -29
- package/dist/javascript/recipes/remove-dependency.d.ts.map +0 -1
- package/dist/javascript/recipes/remove-dependency.js +0 -261
- package/dist/javascript/recipes/remove-dependency.js.map +0 -1
- package/dist/javascript/recipes/upgrade-dependency-version.d.ts +0 -74
- package/dist/javascript/recipes/upgrade-dependency-version.d.ts.map +0 -1
- package/dist/javascript/recipes/upgrade-dependency-version.js +0 -387
- package/dist/javascript/recipes/upgrade-dependency-version.js.map +0 -1
- package/dist/javascript/recipes/upgrade-transitive-dependency-version.d.ts +0 -68
- package/dist/javascript/recipes/upgrade-transitive-dependency-version.d.ts.map +0 -1
- package/dist/javascript/recipes/upgrade-transitive-dependency-version.js +0 -307
- package/dist/javascript/recipes/upgrade-transitive-dependency-version.js.map +0 -1
- package/src/javascript/recipes/add-dependency.ts +0 -549
- package/src/javascript/recipes/remove-dependency.ts +0 -345
- package/src/javascript/recipes/upgrade-dependency-version.ts +0 -486
- package/src/javascript/recipes/upgrade-transitive-dependency-version.ts +0 -403
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 the original author or authors.
|
|
3
|
+
* <p>
|
|
4
|
+
* Licensed under the Moderne Source Available License (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
* <p>
|
|
8
|
+
* https://docs.moderne.io/licensing/moderne-source-available-license
|
|
9
|
+
* <p>
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import * as fs from "node:fs";
|
|
17
|
+
import * as path from "node:path";
|
|
18
|
+
import * as readline from "node:readline";
|
|
19
|
+
import {ChildProcessWithoutNullStreams, spawn} from "node:child_process";
|
|
20
|
+
import * as rpc from "vscode-jsonrpc/node";
|
|
21
|
+
import {RewriteRpc} from "./rewrite-rpc";
|
|
22
|
+
import {RecipeMarketplace} from "../marketplace";
|
|
23
|
+
|
|
24
|
+
export interface JavaRpcOptions {
|
|
25
|
+
/** Explicit classpath override. Falls back to env var, then test-classpath.txt. */
|
|
26
|
+
classpath?: string;
|
|
27
|
+
/** JAVA_HOME to use. Falls back to process.env.JAVA_HOME, then `java` on PATH. */
|
|
28
|
+
javaHome?: string;
|
|
29
|
+
/** Optional logger forwarded to the underlying RewriteRpc instance. */
|
|
30
|
+
logger?: rpc.Logger;
|
|
31
|
+
/** Optional path to a marketplace CSV — passed via `--marketplace=` to the Java process. */
|
|
32
|
+
marketplaceCsv?: string;
|
|
33
|
+
/** Enable RPC tracing on the Java side (passed as `--trace`). */
|
|
34
|
+
trace?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Pre-built {@link RecipeMarketplace} for the TS-side {@link RewriteRpc} instance
|
|
37
|
+
* only. Does NOT configure the Java side — for that, use {@link marketplaceCsv}.
|
|
38
|
+
*/
|
|
39
|
+
marketplace?: RecipeMarketplace;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Test-only wrapper around a spawned `org.openrewrite.maven.rpc.JavaRewriteRpc` process,
|
|
44
|
+
* exposing a {@link RewriteRpc} client wired to its stdio over JSON-RPC.
|
|
45
|
+
*
|
|
46
|
+
* Typical use:
|
|
47
|
+
* ```
|
|
48
|
+
* const server = await JavaRpcTestServer.start();
|
|
49
|
+
* try {
|
|
50
|
+
* const recipe = await server.rpc.prepareRecipe("org.openrewrite.text.FindAndReplace", {...});
|
|
51
|
+
* const result = await server.rpc.visit(parsed, recipe.editVisitor, ctx);
|
|
52
|
+
* } finally {
|
|
53
|
+
* await server.dispose();
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export class JavaRpcTestServer {
|
|
58
|
+
private constructor(
|
|
59
|
+
private readonly child: ChildProcessWithoutNullStreams,
|
|
60
|
+
readonly rpc: RewriteRpc,
|
|
61
|
+
) {
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Spawn the Java RPC server and connect a {@link RewriteRpc} client to its stdio. */
|
|
65
|
+
static async start(opts: JavaRpcOptions = {}): Promise<JavaRpcTestServer> {
|
|
66
|
+
const classpath = opts.classpath ?? findTestClasspath();
|
|
67
|
+
if (!classpath) {
|
|
68
|
+
throw new Error(
|
|
69
|
+
"Java RPC test classpath not configured. " +
|
|
70
|
+
"Run `./gradlew :rewrite-javascript:generateTestClasspath`, " +
|
|
71
|
+
"or set REWRITE_JAVASCRIPT_CLASSPATH."
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const javaCmd = resolveJavaCommand(opts.javaHome);
|
|
76
|
+
const args = ["-cp", classpath, "org.openrewrite.maven.rpc.JavaRewriteRpc"];
|
|
77
|
+
if (opts.marketplaceCsv) args.push(`--marketplace=${opts.marketplaceCsv}`);
|
|
78
|
+
if (opts.trace) args.push("--trace");
|
|
79
|
+
|
|
80
|
+
const child = spawn(javaCmd, args);
|
|
81
|
+
|
|
82
|
+
// Forward Java stderr line-by-line so stack traces surface in the test output.
|
|
83
|
+
// `readline` handles partial-line buffering and flushes a non-newline-terminated
|
|
84
|
+
// final line on `close` (a hand-rolled split would silently drop it).
|
|
85
|
+
readline.createInterface({input: child.stderr, crlfDelay: Infinity})
|
|
86
|
+
.on("line", line => {
|
|
87
|
+
if (line.length > 0) process.stderr.write(`[Java RPC] ${line}\n`);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// If the JVM dies before we can talk to it, surface that immediately rather
|
|
91
|
+
// than letting the first RPC request hang waiting for a response. Capture the
|
|
92
|
+
// listener so we can detach it after the race resolves — otherwise the normal
|
|
93
|
+
// exit during dispose() fires it, rejecting a Promise nobody is observing
|
|
94
|
+
// (UnhandledPromiseRejection under Node 15+).
|
|
95
|
+
let onEarlyExit!: (code: number | null, signal: NodeJS.Signals | null) => void;
|
|
96
|
+
const earlyExit = new Promise<never>((_, reject) => {
|
|
97
|
+
onEarlyExit = (code, signal) => {
|
|
98
|
+
reject(new Error(
|
|
99
|
+
`Java RPC server exited before any request was sent ` +
|
|
100
|
+
`(code=${code}, signal=${signal}). Check the [Java RPC] stderr above.`
|
|
101
|
+
));
|
|
102
|
+
};
|
|
103
|
+
child.once("exit", onEarlyExit);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const connection = rpc.createMessageConnection(
|
|
107
|
+
new rpc.StreamMessageReader(child.stdout),
|
|
108
|
+
new rpc.StreamMessageWriter(child.stdin),
|
|
109
|
+
opts.logger,
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
// RewriteRpc's constructor calls connection.listen() — no need to call it ourselves.
|
|
113
|
+
const rewriteRpc = new RewriteRpc(connection, {
|
|
114
|
+
marketplace: opts.marketplace,
|
|
115
|
+
logger: opts.logger,
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// Hand back control once we know either (a) the JVM is up and the connection is
|
|
119
|
+
// listening, or (b) the JVM died early. A trivial round-trip (GetLanguages) does both.
|
|
120
|
+
try {
|
|
121
|
+
await Promise.race([
|
|
122
|
+
rewriteRpc.languages(),
|
|
123
|
+
earlyExit,
|
|
124
|
+
]);
|
|
125
|
+
} catch (e) {
|
|
126
|
+
child.kill("SIGKILL");
|
|
127
|
+
throw e;
|
|
128
|
+
} finally {
|
|
129
|
+
child.removeListener("exit", onEarlyExit);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return new JavaRpcTestServer(child, rewriteRpc);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Reset accumulated state on both the Java side and the TS-side
|
|
137
|
+
* {@link RewriteRpc} caches so the next test starts clean.
|
|
138
|
+
*/
|
|
139
|
+
async reset(): Promise<void> {
|
|
140
|
+
await this.rpc.reset();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* End the JSON-RPC connection and wait for the Java process to exit. Falls back
|
|
145
|
+
* to SIGKILL after a short grace period to ensure no orphan JVMs are left behind.
|
|
146
|
+
*/
|
|
147
|
+
async dispose(): Promise<void> {
|
|
148
|
+
// Attach the exit listener BEFORE signalling shutdown so we never miss the
|
|
149
|
+
// event in a TOCTOU race between checking exitCode and registering the
|
|
150
|
+
// listener. The Promise also resolves immediately if the process is
|
|
151
|
+
// already gone — see the exitCode shortcut below.
|
|
152
|
+
const exited = new Promise<void>((resolve) => {
|
|
153
|
+
this.child.once("exit", resolve);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
if (this.child.exitCode !== null) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// End the connection before killing the process: this triggers an EOF on the
|
|
161
|
+
// Java side's stdin reader, which lets it shut down cleanly. Killing first
|
|
162
|
+
// can race with in-flight requests and leak the connection-close handler.
|
|
163
|
+
try {
|
|
164
|
+
this.rpc.end();
|
|
165
|
+
} catch { /* ignore — already closed */ }
|
|
166
|
+
|
|
167
|
+
const grace = setTimeout(() => {
|
|
168
|
+
this.child.kill("SIGKILL");
|
|
169
|
+
}, 5_000);
|
|
170
|
+
try {
|
|
171
|
+
await exited;
|
|
172
|
+
} finally {
|
|
173
|
+
clearTimeout(grace);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Find the classpath for spawning the Java RPC server.
|
|
180
|
+
*
|
|
181
|
+
* Resolution order:
|
|
182
|
+
* 1. `REWRITE_JAVASCRIPT_CLASSPATH` environment variable.
|
|
183
|
+
* 2. `test-classpath.txt` written by the `:rewrite-javascript:generateTestClasspath`
|
|
184
|
+
* Gradle task. Walks up from this source file (works both when running directly
|
|
185
|
+
* via vitest and when running from `dist/`).
|
|
186
|
+
*
|
|
187
|
+
* @returns the classpath string, or `undefined` if no source is configured.
|
|
188
|
+
*/
|
|
189
|
+
export function findTestClasspath(): string | undefined {
|
|
190
|
+
const env = process.env.REWRITE_JAVASCRIPT_CLASSPATH;
|
|
191
|
+
if (env && env.length > 0) {
|
|
192
|
+
return env;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// From src/rpc/ (vitest source mode) or dist/rpc/ (compiled), the classpath
|
|
196
|
+
// sits two levels up at the package root. The cwd fallback handles
|
|
197
|
+
// consumer projects where this module is in node_modules but the file
|
|
198
|
+
// lives next to the consumer's package root.
|
|
199
|
+
const candidates = [
|
|
200
|
+
path.resolve(__dirname, "..", "..", "test-classpath.txt"),
|
|
201
|
+
path.resolve(process.cwd(), "test-classpath.txt"),
|
|
202
|
+
];
|
|
203
|
+
for (const candidate of candidates) {
|
|
204
|
+
if (fs.existsSync(candidate)) {
|
|
205
|
+
return fs.readFileSync(candidate, "utf8").trim();
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return undefined;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function resolveJavaCommand(javaHome?: string): string {
|
|
212
|
+
const home = javaHome ?? process.env.JAVA_HOME;
|
|
213
|
+
if (home) {
|
|
214
|
+
const candidate = path.join(home, "bin", process.platform === "win32" ? "java.exe" : "java");
|
|
215
|
+
if (fs.existsSync(candidate)) {
|
|
216
|
+
return candidate;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return "java";
|
|
220
|
+
}
|
package/src/rpc/rewrite-rpc.ts
CHANGED
|
@@ -108,15 +108,27 @@ export class RewriteRpc {
|
|
|
108
108
|
}
|
|
109
109
|
)
|
|
110
110
|
|
|
111
|
+
// Clears local caches. Captured here so it can close over the
|
|
112
|
+
// constructor-local `preparedRecipes` while still being callable
|
|
113
|
+
// from the public `reset()` method on the class.
|
|
114
|
+
const clearLocalState = () => {
|
|
115
|
+
this.localObjects.clear();
|
|
116
|
+
this.localObjectIds.clear();
|
|
117
|
+
this.remoteObjects.clear();
|
|
118
|
+
this.remoteRefs.clear();
|
|
119
|
+
this.localRefs.clear();
|
|
120
|
+
preparedRecipes.clear();
|
|
121
|
+
this.remoteLanguages = undefined;
|
|
122
|
+
};
|
|
123
|
+
this.clearLocalState = clearLocalState;
|
|
124
|
+
|
|
111
125
|
this.connection.onRequest(
|
|
112
126
|
new rpc.RequestType0<boolean, Error>("Reset"),
|
|
113
127
|
async () => {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
this.localRefs.clear();
|
|
119
|
-
preparedRecipes.clear();
|
|
128
|
+
// Inbound Reset only clears local state — never sends a Reset
|
|
129
|
+
// back to the originator. Mirrors the Java handler in
|
|
130
|
+
// RewriteRpc.java around line 222.
|
|
131
|
+
clearLocalState();
|
|
120
132
|
return true;
|
|
121
133
|
}
|
|
122
134
|
)
|
|
@@ -125,6 +137,22 @@ export class RewriteRpc {
|
|
|
125
137
|
this.connection.listen();
|
|
126
138
|
}
|
|
127
139
|
|
|
140
|
+
private readonly clearLocalState!: () => void;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Reset both the remote and local RPC caches. Sends a `Reset` request to the
|
|
144
|
+
* remote — which clears the remote's state without sending one back — and
|
|
145
|
+
* then clears local caches. Use this between independent operations (e.g.
|
|
146
|
+
* between tests) so accumulated objects and prepared recipes don't leak
|
|
147
|
+
* across boundaries.
|
|
148
|
+
*/
|
|
149
|
+
async reset(): Promise<void> {
|
|
150
|
+
await this.connection.sendRequest(
|
|
151
|
+
new rpc.RequestType0<boolean, Error>("Reset"),
|
|
152
|
+
);
|
|
153
|
+
this.clearLocalState();
|
|
154
|
+
}
|
|
155
|
+
|
|
128
156
|
static set(value: RewriteRpc) {
|
|
129
157
|
this._global = value;
|
|
130
158
|
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 the original author or authors.
|
|
3
|
+
* <p>
|
|
4
|
+
* Licensed under the Moderne Source Available License (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
* <p>
|
|
8
|
+
* https://docs.moderne.io/licensing/moderne-source-available-license
|
|
9
|
+
* <p>
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Vitest fixture for tests that need to drive Java recipes via a spawned
|
|
18
|
+
* `org.openrewrite.maven.rpc.JavaRewriteRpc` process. Provides a worker-scoped
|
|
19
|
+
* JVM (one process per vitest worker) wrapped in a test-scoped fixture that
|
|
20
|
+
* resets accumulated state before each test.
|
|
21
|
+
*
|
|
22
|
+
* Typical use:
|
|
23
|
+
* ```
|
|
24
|
+
* import {testJavaRpc, describeJavaRpc} from "@openrewrite/rewrite/test/java-rpc";
|
|
25
|
+
*
|
|
26
|
+
* describeJavaRpc("AddDependency", () => {
|
|
27
|
+
* testJavaRpc("adds a dep to package.json", async ({javaRpc}) => {
|
|
28
|
+
* const spec = new RecipeSpec();
|
|
29
|
+
* spec.recipe = await javaRpc.rpc.prepareRecipe(
|
|
30
|
+
* "org.openrewrite.javascript.AddDependency", {name: "lodash", version: "^4.17.21"},
|
|
31
|
+
* );
|
|
32
|
+
* await spec.rewriteRun(packageJson(before, after));
|
|
33
|
+
* });
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* The classpath is resolved via {@link findTestClasspath}; the suite is skipped
|
|
38
|
+
* (via {@link describeJavaRpc}) when no classpath has been configured.
|
|
39
|
+
*/
|
|
40
|
+
import {describe, type SuiteAPI, test as base} from "vitest";
|
|
41
|
+
import {findTestClasspath, JavaRpcTestServer} from "../rpc/java-rpc-client";
|
|
42
|
+
|
|
43
|
+
export {findTestClasspath, JavaRpcTestServer} from "../rpc/java-rpc-client";
|
|
44
|
+
export type {JavaRpcOptions} from "../rpc/java-rpc-client";
|
|
45
|
+
|
|
46
|
+
interface JavaRpcFixtures {
|
|
47
|
+
/**
|
|
48
|
+
* Internal worker-scoped fixture holding the spawned JVM. Test code should
|
|
49
|
+
* use {@link javaRpc} instead — it depends on this fixture but adds a
|
|
50
|
+
* per-test reset.
|
|
51
|
+
*/
|
|
52
|
+
_javaRpcServer: JavaRpcTestServer;
|
|
53
|
+
/**
|
|
54
|
+
* The {@link JavaRpcTestServer} for this test. State on both the Java
|
|
55
|
+
* side and the TS-side {@link RewriteRpc} is reset before the test runs,
|
|
56
|
+
* so each test gets a clean slate even though the JVM persists across
|
|
57
|
+
* tests within the same vitest worker.
|
|
58
|
+
*/
|
|
59
|
+
javaRpc: JavaRpcTestServer;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Vitest test API extended with a {@link JavaRpcTestServer} fixture. The JVM
|
|
64
|
+
* is spawned once per worker; state is reset before every test.
|
|
65
|
+
*/
|
|
66
|
+
export const testJavaRpc = base.extend<JavaRpcFixtures>({
|
|
67
|
+
_javaRpcServer: [
|
|
68
|
+
async ({}, use) => {
|
|
69
|
+
const server = await JavaRpcTestServer.start();
|
|
70
|
+
try {
|
|
71
|
+
await use(server);
|
|
72
|
+
} finally {
|
|
73
|
+
await server.dispose();
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
{scope: "worker"},
|
|
77
|
+
],
|
|
78
|
+
javaRpc: async ({_javaRpcServer}, use) => {
|
|
79
|
+
await _javaRpcServer.reset();
|
|
80
|
+
await use(_javaRpcServer);
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* `describe` wrapper that skips the suite when the Java RPC test classpath has
|
|
86
|
+
* not been configured (env var or generated file). Use in place of `describe`
|
|
87
|
+
* for any suite that uses {@link testJavaRpc}.
|
|
88
|
+
*
|
|
89
|
+
* Run `./gradlew :rewrite-javascript:generateTestClasspath` to enable, or set
|
|
90
|
+
* the `REWRITE_JAVASCRIPT_CLASSPATH` environment variable.
|
|
91
|
+
*/
|
|
92
|
+
export const describeJavaRpc: SuiteAPI =
|
|
93
|
+
findTestClasspath() ? describe : (describe.skip as unknown as SuiteAPI);
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { ScanningRecipe } from "../../recipe";
|
|
2
|
-
import { ExecutionContext } from "../../execution";
|
|
3
|
-
import { TreeVisitor } from "../../visitor";
|
|
4
|
-
import { DependencyScope, PackageManager } from "../node-resolution-result";
|
|
5
|
-
import { DependencyRecipeAccumulator } from "../package-manager";
|
|
6
|
-
/**
|
|
7
|
-
* Information about a project that needs updating
|
|
8
|
-
*/
|
|
9
|
-
interface ProjectUpdateInfo {
|
|
10
|
-
/** Relative path to package.json (from source root) */
|
|
11
|
-
packageJsonPath: string;
|
|
12
|
-
/** Original package.json content */
|
|
13
|
-
originalPackageJson: string;
|
|
14
|
-
/** The scope where the dependency should be added */
|
|
15
|
-
dependencyScope: DependencyScope;
|
|
16
|
-
/** Version constraint to apply */
|
|
17
|
-
newVersion: string;
|
|
18
|
-
/** The package manager used by this project */
|
|
19
|
-
packageManager: PackageManager;
|
|
20
|
-
/** Config file contents extracted from the project (e.g., .npmrc) */
|
|
21
|
-
configFiles?: Record<string, string>;
|
|
22
|
-
}
|
|
23
|
-
interface Accumulator extends DependencyRecipeAccumulator<ProjectUpdateInfo> {
|
|
24
|
-
/** Original lock file content, keyed by lock file path */
|
|
25
|
-
originalLockFiles: Map<string, string>;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Adds a new dependency to package.json and updates the lock file.
|
|
29
|
-
*
|
|
30
|
-
* This recipe:
|
|
31
|
-
* 1. Finds package.json files that don't already have the specified dependency
|
|
32
|
-
* 2. Adds the dependency to the specified scope (defaults to 'dependencies')
|
|
33
|
-
* 3. Runs the package manager to update the lock file
|
|
34
|
-
* 4. Updates the NodeResolutionResult marker with new dependency info
|
|
35
|
-
*
|
|
36
|
-
* If the dependency already exists in any scope, no changes are made.
|
|
37
|
-
* This matches the behavior of org.openrewrite.maven.AddDependency.
|
|
38
|
-
*/
|
|
39
|
-
export declare class AddDependency extends ScanningRecipe<Accumulator> {
|
|
40
|
-
readonly name = "org.openrewrite.javascript.dependencies.add-dependency";
|
|
41
|
-
readonly displayName = "Add npm dependency";
|
|
42
|
-
readonly description = "Adds a new dependency to `package.json` and updates the lock file by running the package manager.";
|
|
43
|
-
packageName: string;
|
|
44
|
-
version: string;
|
|
45
|
-
scope?: DependencyScope;
|
|
46
|
-
initialValue(_ctx: ExecutionContext): Accumulator;
|
|
47
|
-
private getTargetScope;
|
|
48
|
-
scanner(acc: Accumulator): Promise<TreeVisitor<any, ExecutionContext>>;
|
|
49
|
-
editorWithData(acc: Accumulator): Promise<TreeVisitor<any, ExecutionContext>>;
|
|
50
|
-
/**
|
|
51
|
-
* Runs the package manager in a temporary directory to update the lock file.
|
|
52
|
-
* All file contents are provided from in-memory sources (SourceFiles), not read from disk.
|
|
53
|
-
*/
|
|
54
|
-
private runPackageManagerInstall;
|
|
55
|
-
/**
|
|
56
|
-
* Creates a modified package.json with the new dependency added.
|
|
57
|
-
*/
|
|
58
|
-
private createModifiedPackageJson;
|
|
59
|
-
}
|
|
60
|
-
export {};
|
|
61
|
-
//# sourceMappingURL=add-dependency.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"add-dependency.d.ts","sourceRoot":"","sources":["../../../src/javascript/recipes/add-dependency.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAS,cAAc,EAAC,MAAM,cAAc,CAAC;AACpD,OAAO,EAAC,gBAAgB,EAAC,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAK1C,OAAO,EAEH,eAAe,EAEf,cAAc,EAEjB,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EAGH,2BAA2B,EAQ9B,MAAM,oBAAoB,CAAC;AAI5B;;GAEG;AACH,UAAU,iBAAiB;IACvB,uDAAuD;IACvD,eAAe,EAAE,MAAM,CAAC;IACxB,oCAAoC;IACpC,mBAAmB,EAAE,MAAM,CAAC;IAC5B,qDAAqD;IACrD,eAAe,EAAE,eAAe,CAAC;IACjC,kCAAkC;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,+CAA+C;IAC/C,cAAc,EAAE,cAAc,CAAC;IAC/B,qEAAqE;IACrE,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACxC;AAED,UAAU,WAAY,SAAQ,2BAA2B,CAAC,iBAAiB,CAAC;IACxE,0DAA0D;IAC1D,iBAAiB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC1C;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,aAAc,SAAQ,cAAc,CAAC,WAAW,CAAC;IAC1D,QAAQ,CAAC,IAAI,4DAA4D;IACzE,QAAQ,CAAC,WAAW,wBAAwB;IAC5C,QAAQ,CAAC,WAAW,uGAAuG;IAO3H,WAAW,EAAG,MAAM,CAAC;IAOrB,OAAO,EAAG,MAAM,CAAC;IAQjB,KAAK,CAAC,EAAE,eAAe,CAAC;IAExB,YAAY,CAAC,IAAI,EAAE,gBAAgB,GAAG,WAAW;IAOjD,OAAO,CAAC,cAAc;IAIhB,OAAO,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;IA2FtE,cAAc,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;IA8DnF;;;OAGG;YACW,wBAAwB;IAiCtC;;OAEG;IACH,OAAO,CAAC,yBAAyB;CAcpC"}
|