@openrewrite/rewrite 8.110.1 → 8.112.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/javascript/add-import.d.ts +7 -2
- package/dist/javascript/add-import.d.ts.map +1 -1
- package/dist/javascript/add-import.js +47 -4
- package/dist/javascript/add-import.js.map +1 -1
- package/dist/javascript/binding.d.ts.map +1 -1
- package/dist/javascript/binding.js +15 -9
- package/dist/javascript/binding.js.map +1 -1
- package/dist/javascript/member-spellings.d.ts +1 -4
- package/dist/javascript/member-spellings.d.ts.map +1 -1
- package/dist/javascript/member-spellings.js +16 -26
- package/dist/javascript/member-spellings.js.map +1 -1
- package/dist/javascript/type-mapping.d.ts +1 -1
- package/dist/javascript/type-mapping.d.ts.map +1 -1
- package/dist/javascript/type-mapping.js +18 -34
- package/dist/javascript/type-mapping.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 +2 -0
- package/dist/rpc/index.js.map +1 -1
- package/dist/rpc/msbuild-project.d.ts +96 -0
- package/dist/rpc/msbuild-project.d.ts.map +1 -0
- package/dist/rpc/msbuild-project.js +219 -0
- package/dist/rpc/msbuild-project.js.map +1 -0
- package/package.json +2 -2
- package/src/javascript/add-import.ts +46 -4
- package/src/javascript/binding.ts +20 -10
- package/src/javascript/member-spellings.ts +7 -15
- package/src/javascript/type-mapping.ts +18 -35
- package/src/rpc/index.ts +2 -0
- package/src/rpc/msbuild-project.ts +329 -0
|
@@ -0,0 +1,329 @@
|
|
|
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
|
+
import {castDraft} from "mutative";
|
|
17
|
+
import {Marker} from "../markers";
|
|
18
|
+
import {asRef} from "../reference";
|
|
19
|
+
import {updateIfChanged} from "../util";
|
|
20
|
+
import {UUID} from "../uuid";
|
|
21
|
+
import {RpcCodecs, RpcReceiveQueue, RpcSendQueue} from "./queue";
|
|
22
|
+
|
|
23
|
+
/*
|
|
24
|
+
* The Java `org.openrewrite.csharp.marker.MSBuildProject` marker, which the Java host attaches to
|
|
25
|
+
* the Xml document of each .csproj file. A JavaScript recipe run over a repository that also holds
|
|
26
|
+
* .NET projects receives it on those files, and the Java codec streams it property by property, so
|
|
27
|
+
* this side needs a codec for it and every nested type to read exactly the messages Java sends. The
|
|
28
|
+
* field order in each codec is the wire contract and mirrors `rpcSend`/`rpcReceive` in the Java class.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
export const MSBuildProjectKind = "org.openrewrite.csharp.marker.MSBuildProject" as const;
|
|
32
|
+
export const MSBuildTargetFrameworkKind = "org.openrewrite.csharp.marker.MSBuildProject$TargetFramework" as const;
|
|
33
|
+
export const MSBuildPackageReferenceKind = "org.openrewrite.csharp.marker.MSBuildProject$PackageReference" as const;
|
|
34
|
+
export const MSBuildResolvedPackageKind = "org.openrewrite.csharp.marker.MSBuildProject$ResolvedPackage" as const;
|
|
35
|
+
export const MSBuildProjectReferenceKind = "org.openrewrite.csharp.marker.MSBuildProject$ProjectReference" as const;
|
|
36
|
+
export const MSBuildPropertyValueKind = "org.openrewrite.csharp.marker.MSBuildProject$PropertyValue" as const;
|
|
37
|
+
export const MSBuildPackageSourceKind = "org.openrewrite.csharp.marker.MSBuildProject$PackageSource" as const;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* An MSBuild property value, with the file that defines it.
|
|
41
|
+
*/
|
|
42
|
+
export interface MSBuildPropertyValue {
|
|
43
|
+
readonly kind: typeof MSBuildPropertyValueKind;
|
|
44
|
+
readonly value: string;
|
|
45
|
+
/**
|
|
46
|
+
* The Java `Path`, sent as its string form.
|
|
47
|
+
*/
|
|
48
|
+
readonly definedIn?: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* A NuGet package source from nuget.config.
|
|
53
|
+
*/
|
|
54
|
+
export interface MSBuildPackageSource {
|
|
55
|
+
readonly kind: typeof MSBuildPackageSourceKind;
|
|
56
|
+
readonly key: string;
|
|
57
|
+
readonly url: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* A NuGet package reference declared in the .csproj or Directory.Packages.props.
|
|
62
|
+
*/
|
|
63
|
+
export interface MSBuildPackageReference {
|
|
64
|
+
readonly kind: typeof MSBuildPackageReferenceKind;
|
|
65
|
+
readonly include: string;
|
|
66
|
+
readonly requestedVersion?: string;
|
|
67
|
+
readonly resolvedVersion?: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* A NuGet package resolved by restore. The `dependencies` of each entry point at other entries of
|
|
72
|
+
* the same graph, which may contain cycles.
|
|
73
|
+
*/
|
|
74
|
+
export interface MSBuildResolvedPackage {
|
|
75
|
+
readonly kind: typeof MSBuildResolvedPackageKind;
|
|
76
|
+
readonly name: string;
|
|
77
|
+
readonly resolvedVersion: string;
|
|
78
|
+
readonly dependencies: MSBuildResolvedPackage[];
|
|
79
|
+
readonly depth: number;
|
|
80
|
+
readonly type: string;
|
|
81
|
+
readonly compileAssemblies: string[];
|
|
82
|
+
readonly runtimeAssemblies: string[];
|
|
83
|
+
readonly frameworkAssemblies: string[];
|
|
84
|
+
readonly buildFiles: string[];
|
|
85
|
+
readonly buildMultiTargetingFiles: string[];
|
|
86
|
+
readonly contentFiles: string[];
|
|
87
|
+
readonly runtimeTargets: string[];
|
|
88
|
+
readonly resourceAssemblies: string[];
|
|
89
|
+
readonly analyzerAssemblies: string[];
|
|
90
|
+
readonly hasInstallScripts: boolean;
|
|
91
|
+
readonly hasXdtTransforms: boolean;
|
|
92
|
+
readonly hasLegacyContentFolder: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Declared dependency version range per child package id.
|
|
95
|
+
*/
|
|
96
|
+
readonly dependencyRanges: Readonly<Record<string, string>>;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* A project-to-project reference from the restore graph. Its `resolvedPackages` are the same
|
|
101
|
+
* instances the owning target framework's `resolvedPackages` holds.
|
|
102
|
+
*/
|
|
103
|
+
export interface MSBuildProjectReference {
|
|
104
|
+
readonly kind: typeof MSBuildProjectReferenceKind;
|
|
105
|
+
readonly include: string;
|
|
106
|
+
readonly name?: string;
|
|
107
|
+
readonly depth: number;
|
|
108
|
+
readonly projectReferences: MSBuildProjectReference[];
|
|
109
|
+
readonly resolvedPackages: MSBuildResolvedPackage[];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* What MSBuild evaluated for one target framework of the project.
|
|
114
|
+
*/
|
|
115
|
+
export interface MSBuildTargetFramework {
|
|
116
|
+
readonly kind: typeof MSBuildTargetFrameworkKind;
|
|
117
|
+
readonly targetFramework: string;
|
|
118
|
+
readonly packageReferences: MSBuildPackageReference[];
|
|
119
|
+
readonly resolvedPackages: MSBuildResolvedPackage[];
|
|
120
|
+
readonly projectReferences: MSBuildProjectReference[];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export interface MSBuildProject extends Marker {
|
|
124
|
+
readonly kind: typeof MSBuildProjectKind;
|
|
125
|
+
readonly id: UUID;
|
|
126
|
+
readonly sdk?: string;
|
|
127
|
+
readonly properties: Readonly<Record<string, MSBuildPropertyValue>>;
|
|
128
|
+
readonly packageSources: MSBuildPackageSource[];
|
|
129
|
+
readonly targetFrameworks: MSBuildTargetFramework[];
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const resolvedId = (rp: MSBuildResolvedPackage) => `${rp.name}@${rp.resolvedVersion}`;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Java sends a map as two parallel lists, its keys and then its values. This zips them back, keeping
|
|
136
|
+
* the map it had before when neither list changed.
|
|
137
|
+
*/
|
|
138
|
+
function zip<V>(keys: string[] | undefined, values: V[] | undefined,
|
|
139
|
+
before: Readonly<Record<string, V>> | undefined): Readonly<Record<string, V>> {
|
|
140
|
+
const entries: [string, V][] = [];
|
|
141
|
+
if (keys && values) {
|
|
142
|
+
for (let i = 0; i < keys.length && i < values.length; i++) {
|
|
143
|
+
entries.push([keys[i], values[i]]);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (before) {
|
|
147
|
+
const beforeEntries = Object.entries(before);
|
|
148
|
+
if (beforeEntries.length === entries.length &&
|
|
149
|
+
beforeEntries.every(([k, v], i) => entries[i][0] === k && entries[i][1] === v)) {
|
|
150
|
+
return before;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
// fromEntries defines own properties, so a key like `__proto__` stays an entry
|
|
154
|
+
return Object.fromEntries(entries);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function receiveStringList(q: RpcReceiveQueue, before: string[] | undefined): string[] {
|
|
158
|
+
return q.receiveListDefined(before, s => q.receive(s));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function sendStringList<T>(q: RpcSendQueue, after: T, values: (parent: T) => string[] | undefined): void {
|
|
162
|
+
q.getAndSendList(after, values, s => s, s => q.getAndSend(s, x => x));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
RpcCodecs.registerCodec(MSBuildPropertyValueKind, {
|
|
166
|
+
rpcReceive(before: MSBuildPropertyValue, q: RpcReceiveQueue): MSBuildPropertyValue {
|
|
167
|
+
return updateIfChanged(before, {
|
|
168
|
+
value: q.receive(before.value),
|
|
169
|
+
definedIn: q.receive(before.definedIn),
|
|
170
|
+
});
|
|
171
|
+
},
|
|
172
|
+
|
|
173
|
+
rpcSend(after: MSBuildPropertyValue, q: RpcSendQueue): void {
|
|
174
|
+
q.getAndSend(after, a => a.value);
|
|
175
|
+
q.getAndSend(after, a => a.definedIn);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
RpcCodecs.registerCodec(MSBuildPackageSourceKind, {
|
|
180
|
+
rpcReceive(before: MSBuildPackageSource, q: RpcReceiveQueue): MSBuildPackageSource {
|
|
181
|
+
return updateIfChanged(before, {
|
|
182
|
+
key: q.receive(before.key),
|
|
183
|
+
url: q.receive(before.url),
|
|
184
|
+
});
|
|
185
|
+
},
|
|
186
|
+
|
|
187
|
+
rpcSend(after: MSBuildPackageSource, q: RpcSendQueue): void {
|
|
188
|
+
q.getAndSend(after, a => a.key);
|
|
189
|
+
q.getAndSend(after, a => a.url);
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
RpcCodecs.registerCodec(MSBuildPackageReferenceKind, {
|
|
194
|
+
rpcReceive(before: MSBuildPackageReference, q: RpcReceiveQueue): MSBuildPackageReference {
|
|
195
|
+
return updateIfChanged(before, {
|
|
196
|
+
include: q.receive(before.include),
|
|
197
|
+
requestedVersion: q.receive(before.requestedVersion),
|
|
198
|
+
resolvedVersion: q.receive(before.resolvedVersion),
|
|
199
|
+
});
|
|
200
|
+
},
|
|
201
|
+
|
|
202
|
+
rpcSend(after: MSBuildPackageReference, q: RpcSendQueue): void {
|
|
203
|
+
q.getAndSend(after, a => a.include);
|
|
204
|
+
q.getAndSend(after, a => a.requestedVersion);
|
|
205
|
+
q.getAndSend(after, a => a.resolvedVersion);
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
RpcCodecs.registerCodec(MSBuildResolvedPackageKind, {
|
|
210
|
+
rpcReceive(before: MSBuildResolvedPackage, q: RpcReceiveQueue): MSBuildResolvedPackage {
|
|
211
|
+
// Populated in place: Java sends resolved packages only by ref, so the receive queue
|
|
212
|
+
// registered this instance for its ref before calling the codec, and a back-reference
|
|
213
|
+
// in the dependency graph resolves to the finished object.
|
|
214
|
+
const rp = castDraft(before);
|
|
215
|
+
rp.name = q.receive(before.name);
|
|
216
|
+
rp.resolvedVersion = q.receive(before.resolvedVersion);
|
|
217
|
+
rp.dependencies = castDraft(q.receiveListDefined(before.dependencies));
|
|
218
|
+
rp.depth = q.receive(before.depth);
|
|
219
|
+
rp.type = q.receive(before.type);
|
|
220
|
+
rp.compileAssemblies = receiveStringList(q, before.compileAssemblies);
|
|
221
|
+
rp.runtimeAssemblies = receiveStringList(q, before.runtimeAssemblies);
|
|
222
|
+
rp.frameworkAssemblies = receiveStringList(q, before.frameworkAssemblies);
|
|
223
|
+
rp.buildFiles = receiveStringList(q, before.buildFiles);
|
|
224
|
+
rp.buildMultiTargetingFiles = receiveStringList(q, before.buildMultiTargetingFiles);
|
|
225
|
+
rp.contentFiles = receiveStringList(q, before.contentFiles);
|
|
226
|
+
rp.runtimeTargets = receiveStringList(q, before.runtimeTargets);
|
|
227
|
+
rp.resourceAssemblies = receiveStringList(q, before.resourceAssemblies);
|
|
228
|
+
rp.analyzerAssemblies = receiveStringList(q, before.analyzerAssemblies);
|
|
229
|
+
rp.hasInstallScripts = q.receive(before.hasInstallScripts);
|
|
230
|
+
rp.hasXdtTransforms = q.receive(before.hasXdtTransforms);
|
|
231
|
+
rp.hasLegacyContentFolder = q.receive(before.hasLegacyContentFolder);
|
|
232
|
+
const beforeRanges = before.dependencyRanges ?? {};
|
|
233
|
+
const rangeKeys = receiveStringList(q, Object.keys(beforeRanges));
|
|
234
|
+
const rangeValues = receiveStringList(q, Object.values(beforeRanges));
|
|
235
|
+
rp.dependencyRanges = zip(rangeKeys, rangeValues, before.dependencyRanges);
|
|
236
|
+
return before;
|
|
237
|
+
},
|
|
238
|
+
|
|
239
|
+
rpcSend(after: MSBuildResolvedPackage, q: RpcSendQueue): void {
|
|
240
|
+
q.getAndSend(after, a => a.name);
|
|
241
|
+
q.getAndSend(after, a => a.resolvedVersion);
|
|
242
|
+
q.getAndSendList(after, a => a.dependencies?.map(d => asRef(d)), resolvedId);
|
|
243
|
+
q.getAndSend(after, a => a.depth);
|
|
244
|
+
q.getAndSend(after, a => a.type);
|
|
245
|
+
sendStringList(q, after, a => a.compileAssemblies);
|
|
246
|
+
sendStringList(q, after, a => a.runtimeAssemblies);
|
|
247
|
+
sendStringList(q, after, a => a.frameworkAssemblies);
|
|
248
|
+
sendStringList(q, after, a => a.buildFiles);
|
|
249
|
+
sendStringList(q, after, a => a.buildMultiTargetingFiles);
|
|
250
|
+
sendStringList(q, after, a => a.contentFiles);
|
|
251
|
+
sendStringList(q, after, a => a.runtimeTargets);
|
|
252
|
+
sendStringList(q, after, a => a.resourceAssemblies);
|
|
253
|
+
sendStringList(q, after, a => a.analyzerAssemblies);
|
|
254
|
+
q.getAndSend(after, a => a.hasInstallScripts);
|
|
255
|
+
q.getAndSend(after, a => a.hasXdtTransforms);
|
|
256
|
+
q.getAndSend(after, a => a.hasLegacyContentFolder);
|
|
257
|
+
// Java sends an absent map as two empty lists
|
|
258
|
+
sendStringList(q, after, a => Object.keys(a.dependencyRanges ?? {}));
|
|
259
|
+
sendStringList(q, after, a => Object.values(a.dependencyRanges ?? {}));
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
RpcCodecs.registerCodec(MSBuildProjectReferenceKind, {
|
|
264
|
+
rpcReceive(before: MSBuildProjectReference, q: RpcReceiveQueue): MSBuildProjectReference {
|
|
265
|
+
// Populated in place for the same reason as a resolved package: Java sends project
|
|
266
|
+
// references only by ref, and the project graph may close back onto this instance.
|
|
267
|
+
const pr = castDraft(before);
|
|
268
|
+
pr.include = q.receive(before.include);
|
|
269
|
+
pr.name = q.receive(before.name);
|
|
270
|
+
pr.depth = q.receive(before.depth);
|
|
271
|
+
pr.projectReferences = castDraft(q.receiveListDefined(before.projectReferences));
|
|
272
|
+
pr.resolvedPackages = castDraft(q.receiveListDefined(before.resolvedPackages));
|
|
273
|
+
return before;
|
|
274
|
+
},
|
|
275
|
+
|
|
276
|
+
rpcSend(after: MSBuildProjectReference, q: RpcSendQueue): void {
|
|
277
|
+
q.getAndSend(after, a => a.include);
|
|
278
|
+
q.getAndSend(after, a => a.name);
|
|
279
|
+
q.getAndSend(after, a => a.depth);
|
|
280
|
+
q.getAndSendList(after, a => a.projectReferences?.map(p => asRef(p)), p => p.include);
|
|
281
|
+
q.getAndSendList(after, a => a.resolvedPackages?.map(r => asRef(r)), resolvedId);
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
RpcCodecs.registerCodec(MSBuildTargetFrameworkKind, {
|
|
286
|
+
rpcReceive(before: MSBuildTargetFramework, q: RpcReceiveQueue): MSBuildTargetFramework {
|
|
287
|
+
return updateIfChanged(before, {
|
|
288
|
+
targetFramework: q.receive(before.targetFramework),
|
|
289
|
+
packageReferences: q.receiveListDefined(before.packageReferences),
|
|
290
|
+
resolvedPackages: q.receiveListDefined(before.resolvedPackages),
|
|
291
|
+
projectReferences: q.receiveListDefined(before.projectReferences),
|
|
292
|
+
});
|
|
293
|
+
},
|
|
294
|
+
|
|
295
|
+
rpcSend(after: MSBuildTargetFramework, q: RpcSendQueue): void {
|
|
296
|
+
q.getAndSend(after, a => a.targetFramework);
|
|
297
|
+
q.getAndSendList(after, a => a.packageReferences, pr => pr.include);
|
|
298
|
+
// Java's getAndSendListAsRef: each element travels once, later occurrences as its ref
|
|
299
|
+
q.getAndSendList(after, a => a.resolvedPackages?.map(r => asRef(r)), resolvedId);
|
|
300
|
+
q.getAndSendList(after, a => a.projectReferences?.map(p => asRef(p)), p => p.include);
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
RpcCodecs.registerCodec(MSBuildProjectKind, {
|
|
305
|
+
rpcReceive(before: MSBuildProject, q: RpcReceiveQueue): MSBuildProject {
|
|
306
|
+
const id = q.receive(before.id);
|
|
307
|
+
const sdk = q.receive(before.sdk);
|
|
308
|
+
const beforeProperties = before.properties ?? {};
|
|
309
|
+
const keys = q.receiveList(Object.keys(beforeProperties), k => q.receive(k));
|
|
310
|
+
const values = q.receiveList(Object.values(beforeProperties));
|
|
311
|
+
return updateIfChanged(before, {
|
|
312
|
+
id,
|
|
313
|
+
sdk,
|
|
314
|
+
properties: zip(keys, values, before.properties),
|
|
315
|
+
packageSources: q.receiveListDefined(before.packageSources),
|
|
316
|
+
targetFrameworks: q.receiveListDefined(before.targetFrameworks),
|
|
317
|
+
});
|
|
318
|
+
},
|
|
319
|
+
|
|
320
|
+
rpcSend(after: MSBuildProject, q: RpcSendQueue): void {
|
|
321
|
+
q.getAndSend(after, a => a.id);
|
|
322
|
+
q.getAndSend(after, a => a.sdk);
|
|
323
|
+
// The properties map travels as parallel lists: keys, then values through their codec
|
|
324
|
+
q.getAndSendList(after, a => Object.keys(a.properties ?? {}), k => k, k => q.getAndSend(k, x => x));
|
|
325
|
+
q.getAndSendList(after, a => Object.values(a.properties ?? {}), v => v.value);
|
|
326
|
+
q.getAndSendList(after, a => a.packageSources, ps => ps.key);
|
|
327
|
+
q.getAndSendList(after, a => a.targetFrameworks, tf => tf.targetFramework);
|
|
328
|
+
}
|
|
329
|
+
});
|