@openrewrite/rewrite 8.70.0-20251219-160440 → 8.70.0-20251219-215811

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/dist/cli/cli-utils.d.ts +6 -6
  2. package/dist/cli/cli-utils.d.ts.map +1 -1
  3. package/dist/cli/cli-utils.js +50 -228
  4. package/dist/cli/cli-utils.js.map +1 -1
  5. package/dist/javascript/assertions.d.ts.map +1 -1
  6. package/dist/javascript/assertions.js +87 -12
  7. package/dist/javascript/assertions.js.map +1 -1
  8. package/dist/javascript/autodetect.d.ts +11 -11
  9. package/dist/javascript/autodetect.d.ts.map +1 -1
  10. package/dist/javascript/autodetect.js +18 -21
  11. package/dist/javascript/autodetect.js.map +1 -1
  12. package/dist/javascript/format/prettier-config-loader.d.ts.map +1 -1
  13. package/dist/javascript/format/prettier-config-loader.js +1 -1
  14. package/dist/javascript/format/prettier-config-loader.js.map +1 -1
  15. package/dist/javascript/index.d.ts +1 -0
  16. package/dist/javascript/index.d.ts.map +1 -1
  17. package/dist/javascript/index.js +1 -0
  18. package/dist/javascript/index.js.map +1 -1
  19. package/dist/javascript/markers.d.ts.map +1 -1
  20. package/dist/javascript/markers.js +135 -6
  21. package/dist/javascript/markers.js.map +1 -1
  22. package/dist/javascript/node-resolution-result.d.ts +4 -1
  23. package/dist/javascript/node-resolution-result.d.ts.map +1 -1
  24. package/dist/javascript/node-resolution-result.js +22 -1
  25. package/dist/javascript/node-resolution-result.js.map +1 -1
  26. package/dist/javascript/package-json-parser.d.ts +7 -0
  27. package/dist/javascript/package-json-parser.d.ts.map +1 -1
  28. package/dist/javascript/package-json-parser.js +19 -1
  29. package/dist/javascript/package-json-parser.js.map +1 -1
  30. package/dist/javascript/parser.d.ts.map +1 -1
  31. package/dist/javascript/parser.js +1 -13
  32. package/dist/javascript/parser.js.map +1 -1
  33. package/dist/javascript/preconditions.js +4 -4
  34. package/dist/javascript/preconditions.js.map +1 -1
  35. package/dist/javascript/project-parser.d.ts +137 -0
  36. package/dist/javascript/project-parser.d.ts.map +1 -0
  37. package/dist/javascript/project-parser.js +726 -0
  38. package/dist/javascript/project-parser.js.map +1 -0
  39. package/dist/javascript/style.d.ts +9 -26
  40. package/dist/javascript/style.d.ts.map +1 -1
  41. package/dist/javascript/style.js +18 -42
  42. package/dist/javascript/style.js.map +1 -1
  43. package/dist/json/parser.d.ts.map +1 -1
  44. package/dist/json/parser.js +1 -0
  45. package/dist/json/parser.js.map +1 -1
  46. package/dist/markers.d.ts +1 -1
  47. package/dist/markers.js +1 -1
  48. package/dist/markers.js.map +1 -1
  49. package/dist/parser.d.ts +1 -1
  50. package/dist/parser.d.ts.map +1 -1
  51. package/dist/rpc/index.d.ts +0 -1
  52. package/dist/rpc/index.d.ts.map +1 -1
  53. package/dist/rpc/index.js +4 -2
  54. package/dist/rpc/index.js.map +1 -1
  55. package/dist/rpc/request/index.d.ts +1 -0
  56. package/dist/rpc/request/index.d.ts.map +1 -1
  57. package/dist/rpc/request/index.js +1 -0
  58. package/dist/rpc/request/index.js.map +1 -1
  59. package/dist/rpc/request/parse-project.d.ts +25 -0
  60. package/dist/rpc/request/parse-project.d.ts.map +1 -0
  61. package/dist/rpc/request/parse-project.js +304 -0
  62. package/dist/rpc/request/parse-project.js.map +1 -0
  63. package/dist/rpc/rewrite-rpc.d.ts.map +1 -1
  64. package/dist/rpc/rewrite-rpc.js +1 -0
  65. package/dist/rpc/rewrite-rpc.js.map +1 -1
  66. package/dist/text/parser.d.ts.map +1 -1
  67. package/dist/text/parser.js +1 -0
  68. package/dist/text/parser.js.map +1 -1
  69. package/dist/version.txt +1 -1
  70. package/dist/yaml/parser.d.ts.map +1 -1
  71. package/dist/yaml/parser.js +52 -4
  72. package/dist/yaml/parser.js.map +1 -1
  73. package/package.json +1 -1
  74. package/src/cli/cli-utils.ts +46 -237
  75. package/src/javascript/assertions.ts +74 -10
  76. package/src/javascript/autodetect.ts +22 -15
  77. package/src/javascript/format/prettier-config-loader.ts +2 -2
  78. package/src/javascript/index.ts +1 -0
  79. package/src/javascript/markers.ts +157 -7
  80. package/src/javascript/node-resolution-result.ts +23 -2
  81. package/src/javascript/package-json-parser.ts +19 -1
  82. package/src/javascript/parser.ts +1 -16
  83. package/src/javascript/preconditions.ts +1 -1
  84. package/src/javascript/project-parser.ts +657 -0
  85. package/src/javascript/style.ts +43 -28
  86. package/src/json/parser.ts +3 -1
  87. package/src/markers.ts +1 -1
  88. package/src/parser.ts +1 -1
  89. package/src/rpc/index.ts +7 -5
  90. package/src/rpc/request/index.ts +1 -0
  91. package/src/rpc/request/parse-project.ts +283 -0
  92. package/src/rpc/rewrite-rpc.ts +2 -0
  93. package/src/text/parser.ts +3 -1
  94. package/src/yaml/parser.ts +53 -5
@@ -18,7 +18,17 @@ import {J} from "../java";
18
18
  import {JS} from "./tree";
19
19
  import {RpcCodecs, RpcReceiveQueue, RpcSendQueue} from "../rpc";
20
20
  import {createDraft, finishDraft} from "immer";
21
- import {PrettierStyle, StyleKind} from "./style";
21
+ import {
22
+ prettierStyle,
23
+ PrettierStyle,
24
+ SpacesStyle,
25
+ SpacesStyleDetailKind,
26
+ StyleKind,
27
+ TabsAndIndentsStyle,
28
+ WrappingAndBracesStyle,
29
+ WrappingAndBracesStyleDetailKind
30
+ } from "./style";
31
+ import {Autodetect, autodetect} from "./autodetect";
22
32
 
23
33
  declare module "./tree" {
24
34
  namespace JS {
@@ -107,19 +117,159 @@ registerPrefixedMarkerCodec<Spread>(JS.Markers.Spread);
107
117
  registerPrefixedMarkerCodec<FunctionDeclaration>(JS.Markers.FunctionDeclaration);
108
118
 
109
119
  // Register codec for PrettierStyle (a NamedStyles that contains Prettier configuration)
110
- // Only serialize the variable fields; constant fields are defined in the class
120
+ // Only serialize the variable fields; constant fields are defined in the interface
111
121
  RpcCodecs.registerCodec(StyleKind.PrettierStyle, {
112
122
  async rpcReceive(before: PrettierStyle, q: RpcReceiveQueue): Promise<PrettierStyle> {
113
- const draft = createDraft(before);
114
- (draft as any).id = await q.receive(before.id);
115
- (draft as any).config = await q.receive(before.config);
116
- (draft as any).prettierVersion = await q.receive(before.prettierVersion);
117
- return finishDraft(draft) as PrettierStyle;
123
+ const id = await q.receive(before.id);
124
+ const config = await q.receive(before.config);
125
+ const version = await q.receive(before.prettierVersion);
126
+ const ignored = await q.receive(before.ignored);
127
+ return prettierStyle(id, config, version, ignored);
118
128
  },
119
129
 
120
130
  async rpcSend(after: PrettierStyle, q: RpcSendQueue): Promise<void> {
121
131
  await q.getAndSend(after, a => a.id);
122
132
  await q.getAndSend(after, a => a.config);
123
133
  await q.getAndSend(after, a => a.prettierVersion);
134
+ await q.getAndSend(after, a => a.ignored);
135
+ }
136
+ });
137
+
138
+ // Register codec for Autodetect (auto-detected styles for JavaScript/TypeScript)
139
+ // Only serialize the variable fields (id, styles); constant fields are defined in the interface
140
+ RpcCodecs.registerCodec(StyleKind.Autodetect, {
141
+ async rpcReceive(before: Autodetect, q: RpcReceiveQueue): Promise<Autodetect> {
142
+ const id = await q.receive(before.id);
143
+ const styles = (await q.receiveList(before.styles))!;
144
+ return autodetect(id, styles);
145
+ },
146
+
147
+ async rpcSend(after: Autodetect, q: RpcSendQueue): Promise<void> {
148
+ await q.getAndSend(after, a => a.id);
149
+ await q.getAndSendList(after, a => a.styles, s => s.kind);
150
+ }
151
+ });
152
+
153
+ // ============================================================================
154
+ // Style RPC Codecs
155
+ // ============================================================================
156
+
157
+ // Helper to create a simple codec for objects where all fields are primitives
158
+ function registerSimpleCodec<T extends { kind: string }>(
159
+ kind: T["kind"],
160
+ fields: (keyof T)[]
161
+ ) {
162
+ RpcCodecs.registerCodec(kind, {
163
+ async rpcReceive(before: T, q: RpcReceiveQueue): Promise<T> {
164
+ const draft = createDraft(before);
165
+ for (const field of fields) {
166
+ (draft as any)[field] = await q.receive((before as any)[field]);
167
+ }
168
+ return finishDraft(draft) as T;
169
+ },
170
+
171
+ async rpcSend(after: T, q: RpcSendQueue): Promise<void> {
172
+ for (const field of fields) {
173
+ await q.getAndSend(after, a => (a as any)[field]);
174
+ }
175
+ }
176
+ });
177
+ }
178
+
179
+ // TabsAndIndentsStyle - simple style with primitive fields
180
+ registerSimpleCodec<TabsAndIndentsStyle>(StyleKind.TabsAndIndentsStyle, [
181
+ 'useTabCharacter', 'tabSize', 'indentSize', 'continuationIndent',
182
+ 'keepIndentsOnEmptyLines', 'indentChainedMethods', 'indentAllChainedCallsInAGroup'
183
+ ]);
184
+
185
+ // SpacesStyle and its nested types
186
+ registerSimpleCodec<SpacesStyle.BeforeParentheses>(SpacesStyleDetailKind.SpacesStyleBeforeParentheses, [
187
+ 'functionDeclarationParentheses', 'functionCallParentheses', 'ifParentheses',
188
+ 'forParentheses', 'whileParentheses', 'switchParentheses', 'catchParentheses',
189
+ 'inFunctionCallExpression', 'inAsyncArrowFunction'
190
+ ]);
191
+
192
+ registerSimpleCodec<SpacesStyle.AroundOperators>(SpacesStyleDetailKind.SpacesStyleAroundOperators, [
193
+ 'assignment', 'logical', 'equality', 'relational', 'bitwise', 'additive',
194
+ 'multiplicative', 'shift', 'unary', 'arrowFunction',
195
+ 'beforeUnaryNotAndNotNull', 'afterUnaryNotAndNotNull'
196
+ ]);
197
+
198
+ registerSimpleCodec<SpacesStyle.BeforeLeftBrace>(SpacesStyleDetailKind.SpacesStyleBeforeLeftBrace, [
199
+ 'functionLeftBrace', 'ifLeftBrace', 'elseLeftBrace', 'forLeftBrace',
200
+ 'whileLeftBrace', 'doLeftBrace', 'switchLeftBrace', 'tryLeftBrace',
201
+ 'catchLeftBrace', 'finallyLeftBrace', 'classInterfaceModuleLeftBrace'
202
+ ]);
203
+
204
+ registerSimpleCodec<SpacesStyle.BeforeKeywords>(SpacesStyleDetailKind.SpacesStyleBeforeKeywords, [
205
+ 'elseKeyword', 'whileKeyword', 'catchKeyword', 'finallyKeyword'
206
+ ]);
207
+
208
+ registerSimpleCodec<SpacesStyle.Within>(SpacesStyleDetailKind.SpacesStyleWithin, [
209
+ 'indexAccessBrackets', 'groupingParentheses', 'functionDeclarationParentheses',
210
+ 'functionCallParentheses', 'ifParentheses', 'forParentheses', 'whileParentheses',
211
+ 'switchParentheses', 'catchParentheses', 'objectLiteralBraces', 'es6ImportExportBraces',
212
+ 'arrayBrackets', 'interpolationExpressions', 'objectLiteralTypeBraces',
213
+ 'unionAndIntersectionTypes', 'typeAssertions'
214
+ ]);
215
+
216
+ registerSimpleCodec<SpacesStyle.TernaryOperator>(SpacesStyleDetailKind.SpacesStyleTernaryOperator, [
217
+ 'beforeQuestionMark', 'afterQuestionMark', 'beforeColon', 'afterColon'
218
+ ]);
219
+
220
+ registerSimpleCodec<SpacesStyle.Other>(SpacesStyleDetailKind.SpacesStyleOther, [
221
+ 'beforeComma', 'afterComma', 'beforeForSemicolon',
222
+ 'beforePropertyNameValueSeparator', 'afterPropertyNameValueSeparator',
223
+ 'afterVarArgInRestOrSpread', 'beforeAsteriskInGenerator', 'afterAsteriskInGenerator',
224
+ 'beforeTypeReferenceColon', 'afterTypeReferenceColon'
225
+ ]);
226
+
227
+ // SpacesStyle - has nested objects
228
+ RpcCodecs.registerCodec(StyleKind.SpacesStyle, {
229
+ async rpcReceive(before: SpacesStyle, q: RpcReceiveQueue): Promise<SpacesStyle> {
230
+ const draft = createDraft(before);
231
+ draft.beforeParentheses = await q.receive(before.beforeParentheses);
232
+ draft.aroundOperators = await q.receive(before.aroundOperators);
233
+ draft.beforeLeftBrace = await q.receive(before.beforeLeftBrace);
234
+ draft.beforeKeywords = await q.receive(before.beforeKeywords);
235
+ draft.within = await q.receive(before.within);
236
+ draft.ternaryOperator = await q.receive(before.ternaryOperator);
237
+ draft.other = await q.receive(before.other);
238
+ return finishDraft(draft) as SpacesStyle;
239
+ },
240
+
241
+ async rpcSend(after: SpacesStyle, q: RpcSendQueue): Promise<void> {
242
+ await q.getAndSend(after, a => a.beforeParentheses);
243
+ await q.getAndSend(after, a => a.aroundOperators);
244
+ await q.getAndSend(after, a => a.beforeLeftBrace);
245
+ await q.getAndSend(after, a => a.beforeKeywords);
246
+ await q.getAndSend(after, a => a.within);
247
+ await q.getAndSend(after, a => a.ternaryOperator);
248
+ await q.getAndSend(after, a => a.other);
249
+ }
250
+ });
251
+
252
+ // WrappingAndBracesStyle and its nested types
253
+ registerSimpleCodec<WrappingAndBracesStyle.IfStatement>(
254
+ WrappingAndBracesStyleDetailKind.WrappingAndBracesStyleIfStatement,
255
+ ['elseOnNewLine']
256
+ );
257
+
258
+ registerSimpleCodec<WrappingAndBracesStyle.KeepWhenReformatting>(
259
+ WrappingAndBracesStyleDetailKind.WrappingAndBracesStyleKeepWhenReformatting,
260
+ ['simpleBlocksInOneLine', 'simpleMethodsInOneLine']
261
+ );
262
+
263
+ RpcCodecs.registerCodec(StyleKind.WrappingAndBracesStyle, {
264
+ async rpcReceive(before: WrappingAndBracesStyle, q: RpcReceiveQueue): Promise<WrappingAndBracesStyle> {
265
+ const draft = createDraft(before);
266
+ draft.ifStatement = await q.receive(before.ifStatement);
267
+ draft.keepWhenReformatting = await q.receive(before.keepWhenReformatting);
268
+ return finishDraft(draft) as WrappingAndBracesStyle;
269
+ },
270
+
271
+ async rpcSend(after: WrappingAndBracesStyle, q: RpcSendQueue): Promise<void> {
272
+ await q.getAndSend(after, a => a.ifStatement);
273
+ await q.getAndSend(after, a => a.keepWhenReformatting);
124
274
  }
125
275
  });
@@ -50,7 +50,7 @@ export interface PackageLockEntry {
50
50
  readonly version?: string;
51
51
  readonly resolved?: string;
52
52
  readonly integrity?: string;
53
- readonly license?: string;
53
+ readonly license?: string | string[] | { type?: string; url?: string }; // Can be legacy formats
54
54
  readonly dependencies?: Record<string, string>;
55
55
  readonly devDependencies?: Record<string, string>;
56
56
  readonly peerDependencies?: Record<string, string>;
@@ -264,6 +264,27 @@ export function createNodeResolutionResultMarker(
264
264
  return engines;
265
265
  }
266
266
 
267
+ /**
268
+ * Normalizes the license field from package-lock.json.
269
+ * Older packages may have license in legacy formats:
270
+ * - Array: ["MIT", "Apache2"] -> "(MIT OR Apache2)"
271
+ * - Object: { type: "MIT", url: "..." } -> "MIT"
272
+ */
273
+ function normalizeLicense(license?: string | string[] | { type?: string; url?: string }): string | undefined {
274
+ if (!license) return undefined;
275
+ if (Array.isArray(license)) {
276
+ // Convert array format to SPDX OR expression
277
+ // e.g., ["MIT", "Apache2"] -> "(MIT OR Apache2)"
278
+ return license.length > 0 ? `(${license.join(' OR ')})` : undefined;
279
+ }
280
+ if (typeof license === 'object') {
281
+ // Extract type from object format
282
+ // e.g., { type: "MIT", url: "..." } -> "MIT"
283
+ return license.type || undefined;
284
+ }
285
+ return license;
286
+ }
287
+
267
288
  /**
268
289
  * Extracts package name and optionally version from a package-lock.json path.
269
290
  * e.g., "node_modules/@babel/core" -> { name: "@babel/core" }
@@ -324,7 +345,7 @@ export function createNodeResolutionResultMarker(
324
345
  peerDependencies: undefined,
325
346
  optionalDependencies: undefined,
326
347
  engines: normalizeEngines(pkgEntry?.engines),
327
- license: pkgEntry?.license,
348
+ license: normalizeLicense(pkgEntry?.license),
328
349
  });
329
350
  resolvedDependencyCache.set(key, resolved);
330
351
 
@@ -107,12 +107,30 @@ export class PackageJsonParser extends Parser {
107
107
  entry.engines = pkgJson.engines;
108
108
  }
109
109
  if (pkgJson.license) {
110
- entry.license = pkgJson.license;
110
+ // Normalize legacy license formats to string
111
+ entry.license = PackageJsonParser.normalizeLicense(pkgJson.license);
111
112
  }
112
113
 
113
114
  return entry;
114
115
  }
115
116
 
117
+ /**
118
+ * Normalizes the license field from package.json.
119
+ * Older packages may have license in legacy formats:
120
+ * - Array: ["MIT", "Apache2"] -> "(MIT OR Apache2)"
121
+ * - Object: { type: "MIT", url: "..." } -> "MIT"
122
+ */
123
+ private static normalizeLicense(license: any): string | undefined {
124
+ if (!license) return undefined;
125
+ if (Array.isArray(license)) {
126
+ return license.length > 0 ? `(${license.join(' OR ')})` : undefined;
127
+ }
128
+ if (typeof license === 'object' && license.type) {
129
+ return license.type;
130
+ }
131
+ return typeof license === 'string' ? license : undefined;
132
+ }
133
+
116
134
  /**
117
135
  * Accepts package.json files.
118
136
  */
@@ -48,12 +48,9 @@ import {
48
48
  } from "./parser-utils";
49
49
  import {JavaScriptTypeMapping} from "./type-mapping";
50
50
  import {produce} from "immer";
51
- import {PrettierConfigLoader} from "./format/prettier-config-loader";
52
- import Kind = JS.Kind;
53
51
  import ComputedPropertyName = JS.ComputedPropertyName;
54
52
  import Attribute = JSX.Attribute;
55
53
  import SpreadAttribute = JSX.SpreadAttribute;
56
-
57
54
  export interface JavaScriptParserOptions extends ParserOptions {
58
55
  styles?: NamedStyles[],
59
56
  sourceFileCache?: Map<string, ts.SourceFile>,
@@ -330,12 +327,6 @@ export class JavaScriptParser extends Parser {
330
327
  // Update the oldProgram reference
331
328
  this.oldProgram = program;
332
329
 
333
- // Detect Prettier config for the project
334
- const prettierLoader = this.relativeTo ? new PrettierConfigLoader(this.relativeTo) : undefined;
335
- if (prettierLoader) {
336
- await prettierLoader.detectPrettier();
337
- }
338
-
339
330
  // Create a single JavaScriptTypeMapping instance to be shared across all files in this parse batch.
340
331
  // This ensures that TypeScript types with the same type.id map to the same Type instance,
341
332
  // preventing duplicate Type.Class, Type.Parameterized, etc. instances.
@@ -363,9 +354,6 @@ export class JavaScriptParser extends Parser {
363
354
  }
364
355
 
365
356
  try {
366
- // Get Prettier config marker for this file (if Prettier is available)
367
- const prettierConfigMarker = await prettierLoader?.getConfigMarker(filePath);
368
-
369
357
  yield produce(
370
358
  new JavaScriptParserVisitor(sourceFile, this.relativePath(input), typeMapping)
371
359
  .visit(sourceFile) as SourceFile,
@@ -373,9 +361,6 @@ export class JavaScriptParser extends Parser {
373
361
  if (this.styles) {
374
362
  draft.markers.markers = draft.markers.markers.concat(this.styles);
375
363
  }
376
- if (prettierConfigMarker) {
377
- draft.markers.markers = draft.markers.markers.concat([prettierConfigMarker]);
378
- }
379
364
  });
380
365
  } catch (error) {
381
366
  yield this.error(input, error instanceof Error ? error : new Error('Parser threw unknown error: ' + error));
@@ -1766,7 +1751,7 @@ export class JavaScriptParserVisitor {
1766
1751
  markers: emptyMarkers,
1767
1752
  typeParameter: this.rightPadded(
1768
1753
  {
1769
- kind: Kind.MappedTypeParameter,
1754
+ kind: JS.Kind.MappedTypeParameter,
1770
1755
  id: randomId(),
1771
1756
  prefix: this.prefix(node.typeParameter),
1772
1757
  markers: emptyMarkers,
@@ -13,7 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import {RewriteRpc} from "../rpc";
16
+ import {RewriteRpc} from "../rpc/rewrite-rpc";
17
17
  import {UsesMethod, UsesType} from "./search";
18
18
  import {ExecutionContext} from "../execution";
19
19
  import {TreeVisitor} from "../visitor";