@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
|
@@ -1,345 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2026 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
|
-
import {Option, ScanningRecipe} from "../../recipe";
|
|
18
|
-
import {ExecutionContext} from "../../execution";
|
|
19
|
-
import {TreeVisitor} from "../../visitor";
|
|
20
|
-
import {Tree} from "../../tree";
|
|
21
|
-
import {getMemberKeyName, isJson, isObject, Json, JsonVisitor} from "../../json";
|
|
22
|
-
import {isDocuments, isYaml, Yaml} from "../../yaml";
|
|
23
|
-
import {isPlainText, PlainText} from "../../text";
|
|
24
|
-
import {
|
|
25
|
-
allDependencyScopes,
|
|
26
|
-
DependencyScope,
|
|
27
|
-
findNodeResolutionResult,
|
|
28
|
-
PackageManager,
|
|
29
|
-
serializeNpmrcConfigs
|
|
30
|
-
} from "../node-resolution-result";
|
|
31
|
-
import {markupWarn} from "../../markers";
|
|
32
|
-
import {TreePrinters} from "../../print";
|
|
33
|
-
import {
|
|
34
|
-
createDependencyRecipeAccumulator,
|
|
35
|
-
createLockFileEditor,
|
|
36
|
-
DependencyRecipeAccumulator,
|
|
37
|
-
getAllLockFileNames,
|
|
38
|
-
getLockFileName,
|
|
39
|
-
parseLockFileContent,
|
|
40
|
-
runInstallIfNeeded,
|
|
41
|
-
runInstallInTempDir,
|
|
42
|
-
storeInstallResult,
|
|
43
|
-
updateNodeResolutionMarker
|
|
44
|
-
} from "../package-manager";
|
|
45
|
-
import * as path from "path";
|
|
46
|
-
|
|
47
|
-
interface ProjectUpdateInfo {
|
|
48
|
-
packageJsonPath: string;
|
|
49
|
-
originalPackageJson: string;
|
|
50
|
-
dependencyScopes: DependencyScope[];
|
|
51
|
-
packageManager: PackageManager;
|
|
52
|
-
configFiles?: Record<string, string>;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
interface Accumulator extends DependencyRecipeAccumulator<ProjectUpdateInfo> {
|
|
56
|
-
originalLockFiles: Map<string, string>;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export class RemoveDependency extends ScanningRecipe<Accumulator> {
|
|
60
|
-
readonly name = "org.openrewrite.javascript.dependencies.remove-dependency";
|
|
61
|
-
readonly displayName = "Remove npm dependency";
|
|
62
|
-
readonly description = "Removes a dependency from `package.json` and updates the lock file by running the package manager.";
|
|
63
|
-
|
|
64
|
-
@Option({
|
|
65
|
-
displayName: "Package name",
|
|
66
|
-
description: "The name of the npm package to remove (e.g., `lodash`, `@types/node`)",
|
|
67
|
-
example: "lodash"
|
|
68
|
-
})
|
|
69
|
-
packageName!: string;
|
|
70
|
-
|
|
71
|
-
@Option({
|
|
72
|
-
displayName: "Scope",
|
|
73
|
-
description: "The dependency scope to remove from. If not specified, the dependency is removed from all scopes where it is found.",
|
|
74
|
-
example: "dependencies",
|
|
75
|
-
required: false
|
|
76
|
-
})
|
|
77
|
-
scope?: DependencyScope;
|
|
78
|
-
|
|
79
|
-
initialValue(_ctx: ExecutionContext): Accumulator {
|
|
80
|
-
return {
|
|
81
|
-
...createDependencyRecipeAccumulator<ProjectUpdateInfo>(),
|
|
82
|
-
originalLockFiles: new Map()
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
async scanner(acc: Accumulator): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
87
|
-
const recipe = this;
|
|
88
|
-
const LOCK_FILE_NAMES = getAllLockFileNames();
|
|
89
|
-
|
|
90
|
-
return new class extends TreeVisitor<Tree, ExecutionContext> {
|
|
91
|
-
protected async accept(tree: Tree, ctx: ExecutionContext): Promise<Tree | undefined> {
|
|
92
|
-
if (isJson(tree) && tree.kind === Json.Kind.Document) {
|
|
93
|
-
return this.handleJsonDocument(tree as Json.Document, ctx);
|
|
94
|
-
}
|
|
95
|
-
if (isYaml(tree) && isDocuments(tree)) {
|
|
96
|
-
return this.handleYamlDocument(tree, ctx);
|
|
97
|
-
}
|
|
98
|
-
if (isPlainText(tree)) {
|
|
99
|
-
return this.handlePlainTextDocument(tree as PlainText, ctx);
|
|
100
|
-
}
|
|
101
|
-
return tree;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
private async handleJsonDocument(doc: Json.Document, _ctx: ExecutionContext): Promise<Json | undefined> {
|
|
105
|
-
const basename = path.basename(doc.sourcePath);
|
|
106
|
-
|
|
107
|
-
if (LOCK_FILE_NAMES.includes(basename)) {
|
|
108
|
-
acc.originalLockFiles.set(doc.sourcePath, await TreePrinters.print(doc));
|
|
109
|
-
return doc;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (!doc.sourcePath.endsWith('package.json')) {
|
|
113
|
-
return doc;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const marker = findNodeResolutionResult(doc);
|
|
117
|
-
if (!marker) {
|
|
118
|
-
return doc;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const scopesToCheck = recipe.scope ? [recipe.scope] : allDependencyScopes;
|
|
122
|
-
const foundScopes: DependencyScope[] = [];
|
|
123
|
-
|
|
124
|
-
for (const scope of scopesToCheck) {
|
|
125
|
-
const deps = marker[scope];
|
|
126
|
-
if (deps?.some(d => d.name === recipe.packageName)) {
|
|
127
|
-
foundScopes.push(scope);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (foundScopes.length === 0) {
|
|
132
|
-
return doc;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const pm = marker.packageManager ?? PackageManager.Npm;
|
|
136
|
-
|
|
137
|
-
const configFiles: Record<string, string> = {};
|
|
138
|
-
const npmrcContent = serializeNpmrcConfigs(marker.npmrcConfigs);
|
|
139
|
-
if (npmrcContent) {
|
|
140
|
-
configFiles['.npmrc'] = npmrcContent;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
acc.projectsToUpdate.set(doc.sourcePath, {
|
|
144
|
-
packageJsonPath: doc.sourcePath,
|
|
145
|
-
originalPackageJson: await TreePrinters.print(doc),
|
|
146
|
-
dependencyScopes: foundScopes,
|
|
147
|
-
packageManager: pm,
|
|
148
|
-
configFiles: Object.keys(configFiles).length > 0 ? configFiles : undefined
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
return doc;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
private async handleYamlDocument(docs: Yaml.Documents, _ctx: ExecutionContext): Promise<Yaml.Documents | undefined> {
|
|
155
|
-
const basename = path.basename(docs.sourcePath);
|
|
156
|
-
if (LOCK_FILE_NAMES.includes(basename)) {
|
|
157
|
-
acc.originalLockFiles.set(docs.sourcePath, await TreePrinters.print(docs));
|
|
158
|
-
}
|
|
159
|
-
return docs;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
private async handlePlainTextDocument(text: PlainText, _ctx: ExecutionContext): Promise<PlainText | undefined> {
|
|
163
|
-
const basename = path.basename(text.sourcePath);
|
|
164
|
-
if (LOCK_FILE_NAMES.includes(basename)) {
|
|
165
|
-
acc.originalLockFiles.set(text.sourcePath, await TreePrinters.print(text));
|
|
166
|
-
}
|
|
167
|
-
return text;
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
async editorWithData(acc: Accumulator): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
173
|
-
const recipe = this;
|
|
174
|
-
|
|
175
|
-
const jsonEditor = new class extends JsonVisitor<ExecutionContext> {
|
|
176
|
-
protected async visitDocument(doc: Json.Document, ctx: ExecutionContext): Promise<Json | undefined> {
|
|
177
|
-
const sourcePath = doc.sourcePath;
|
|
178
|
-
|
|
179
|
-
if (sourcePath.endsWith('package.json')) {
|
|
180
|
-
const updateInfo = acc.projectsToUpdate.get(sourcePath);
|
|
181
|
-
if (!updateInfo) {
|
|
182
|
-
return doc;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
const failureMessage = await runInstallIfNeeded(sourcePath, acc, () =>
|
|
186
|
-
recipe.runPackageManagerInstall(acc, updateInfo, ctx)
|
|
187
|
-
);
|
|
188
|
-
if (failureMessage) {
|
|
189
|
-
return markupWarn(
|
|
190
|
-
doc,
|
|
191
|
-
`Failed to remove ${recipe.packageName}`,
|
|
192
|
-
failureMessage
|
|
193
|
-
);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
const modifiedDoc = removeDependencyFromJson(
|
|
197
|
-
doc,
|
|
198
|
-
recipe.packageName,
|
|
199
|
-
updateInfo.dependencyScopes
|
|
200
|
-
);
|
|
201
|
-
|
|
202
|
-
return updateNodeResolutionMarker(modifiedDoc, updateInfo, acc);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
const lockFileName = path.basename(sourcePath);
|
|
206
|
-
if (getAllLockFileNames().includes(lockFileName)) {
|
|
207
|
-
const updatedLockContent = acc.updatedLockFiles.get(sourcePath);
|
|
208
|
-
if (updatedLockContent) {
|
|
209
|
-
const parsed = await parseLockFileContent(updatedLockContent, sourcePath, lockFileName) as Json.Document;
|
|
210
|
-
return {
|
|
211
|
-
...doc,
|
|
212
|
-
value: parsed.value,
|
|
213
|
-
eof: parsed.eof
|
|
214
|
-
} as Json.Document;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
return doc;
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
return createLockFileEditor(jsonEditor, acc);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
private async runPackageManagerInstall(
|
|
226
|
-
acc: Accumulator,
|
|
227
|
-
updateInfo: ProjectUpdateInfo,
|
|
228
|
-
_ctx: ExecutionContext
|
|
229
|
-
): Promise<void> {
|
|
230
|
-
const modifiedPackageJson = this.createModifiedPackageJson(
|
|
231
|
-
updateInfo.originalPackageJson,
|
|
232
|
-
updateInfo.dependencyScopes
|
|
233
|
-
);
|
|
234
|
-
|
|
235
|
-
const lockFileName = getLockFileName(updateInfo.packageManager);
|
|
236
|
-
const packageJsonDir = path.dirname(updateInfo.packageJsonPath);
|
|
237
|
-
const lockFilePath = packageJsonDir === '.'
|
|
238
|
-
? lockFileName
|
|
239
|
-
: path.join(packageJsonDir, lockFileName);
|
|
240
|
-
|
|
241
|
-
const originalLockFileContent = acc.originalLockFiles.get(lockFilePath);
|
|
242
|
-
|
|
243
|
-
const result = await runInstallInTempDir(
|
|
244
|
-
updateInfo.packageManager,
|
|
245
|
-
modifiedPackageJson,
|
|
246
|
-
{
|
|
247
|
-
originalLockFileContent,
|
|
248
|
-
configFiles: updateInfo.configFiles
|
|
249
|
-
}
|
|
250
|
-
);
|
|
251
|
-
|
|
252
|
-
storeInstallResult(result, acc, updateInfo, modifiedPackageJson);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
private createModifiedPackageJson(
|
|
256
|
-
originalContent: string,
|
|
257
|
-
scopes: DependencyScope[]
|
|
258
|
-
): string {
|
|
259
|
-
const packageJson = JSON.parse(originalContent);
|
|
260
|
-
|
|
261
|
-
for (const scope of scopes) {
|
|
262
|
-
if (packageJson[scope] && packageJson[scope][this.packageName]) {
|
|
263
|
-
delete packageJson[scope][this.packageName];
|
|
264
|
-
|
|
265
|
-
if (Object.keys(packageJson[scope]).length === 0) {
|
|
266
|
-
delete packageJson[scope];
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
return JSON.stringify(packageJson, null, 2);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
function removeDependencyFromJson(
|
|
276
|
-
doc: Json.Document,
|
|
277
|
-
packageName: string,
|
|
278
|
-
scopes: DependencyScope[]
|
|
279
|
-
): Json.Document {
|
|
280
|
-
if (!isObject(doc.value)) {
|
|
281
|
-
return doc;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
const targetScopes = new Set<string>(scopes);
|
|
285
|
-
const rootObj = doc.value;
|
|
286
|
-
let changed = false;
|
|
287
|
-
const result: Json.RightPadded<Json>[] = [];
|
|
288
|
-
|
|
289
|
-
for (const rp of rootObj.members) {
|
|
290
|
-
const member = rp.element as Json.Member;
|
|
291
|
-
const keyName = getMemberKeyName(member);
|
|
292
|
-
|
|
293
|
-
if (!keyName || !targetScopes.has(keyName) || !isObject(member.value)) {
|
|
294
|
-
result.push(rp);
|
|
295
|
-
continue;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
const scopeObj = member.value;
|
|
299
|
-
const filtered = scopeObj.members.filter(depRp =>
|
|
300
|
-
getMemberKeyName(depRp.element as Json.Member) !== packageName
|
|
301
|
-
);
|
|
302
|
-
|
|
303
|
-
if (filtered.length === scopeObj.members.length) {
|
|
304
|
-
result.push(rp);
|
|
305
|
-
continue;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
changed = true;
|
|
309
|
-
|
|
310
|
-
if (filtered.length === 0) {
|
|
311
|
-
continue;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
const lastOriginalAfter = scopeObj.members[scopeObj.members.length - 1].after;
|
|
315
|
-
filtered[filtered.length - 1] = {
|
|
316
|
-
...filtered[filtered.length - 1],
|
|
317
|
-
after: lastOriginalAfter
|
|
318
|
-
};
|
|
319
|
-
|
|
320
|
-
result.push({
|
|
321
|
-
...rp,
|
|
322
|
-
element: {
|
|
323
|
-
...member,
|
|
324
|
-
value: {...scopeObj, members: filtered} as Json.Object
|
|
325
|
-
}
|
|
326
|
-
} as Json.RightPadded<Json>);
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
if (!changed) {
|
|
330
|
-
return doc;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
if (result.length > 0 && result.length < rootObj.members.length) {
|
|
334
|
-
const originalLastAfter = rootObj.members[rootObj.members.length - 1].after;
|
|
335
|
-
result[result.length - 1] = {
|
|
336
|
-
...result[result.length - 1],
|
|
337
|
-
after: originalLastAfter
|
|
338
|
-
};
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
return {
|
|
342
|
-
...doc,
|
|
343
|
-
value: {...rootObj, members: result} as Json.Object
|
|
344
|
-
};
|
|
345
|
-
}
|