@openrewrite/rewrite 8.69.0-20251211-160325 → 8.69.0-20251212-112414

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 (80) hide show
  1. package/dist/cli/cli-utils.d.ts.map +1 -1
  2. package/dist/cli/cli-utils.js +110 -71
  3. package/dist/cli/cli-utils.js.map +1 -1
  4. package/dist/javascript/package-json-parser.d.ts +0 -5
  5. package/dist/javascript/package-json-parser.d.ts.map +1 -1
  6. package/dist/javascript/package-json-parser.js +2 -12
  7. package/dist/javascript/package-json-parser.js.map +1 -1
  8. package/dist/javascript/package-manager.d.ts +72 -1
  9. package/dist/javascript/package-manager.d.ts.map +1 -1
  10. package/dist/javascript/package-manager.js +173 -2
  11. package/dist/javascript/package-manager.js.map +1 -1
  12. package/dist/javascript/recipes/add-dependency.d.ts.map +1 -1
  13. package/dist/javascript/recipes/add-dependency.js +11 -8
  14. package/dist/javascript/recipes/add-dependency.js.map +1 -1
  15. package/dist/javascript/recipes/upgrade-dependency-version.d.ts.map +1 -1
  16. package/dist/javascript/recipes/upgrade-dependency-version.js +11 -8
  17. package/dist/javascript/recipes/upgrade-dependency-version.js.map +1 -1
  18. package/dist/javascript/recipes/upgrade-transitive-dependency-version.d.ts.map +1 -1
  19. package/dist/javascript/recipes/upgrade-transitive-dependency-version.js +11 -8
  20. package/dist/javascript/recipes/upgrade-transitive-dependency-version.js.map +1 -1
  21. package/dist/json/parser.d.ts.map +1 -1
  22. package/dist/json/parser.js +355 -123
  23. package/dist/json/parser.js.map +1 -1
  24. package/dist/json/tree.d.ts +5 -1
  25. package/dist/json/tree.d.ts.map +1 -1
  26. package/dist/json/tree.js +157 -7
  27. package/dist/json/tree.js.map +1 -1
  28. package/dist/print.d.ts.map +1 -1
  29. package/dist/print.js +5 -1
  30. package/dist/print.js.map +1 -1
  31. package/dist/rpc/request/get-languages.d.ts.map +1 -1
  32. package/dist/rpc/request/get-languages.js +1 -0
  33. package/dist/rpc/request/get-languages.js.map +1 -1
  34. package/dist/rpc/server.d.ts +1 -0
  35. package/dist/rpc/server.d.ts.map +1 -1
  36. package/dist/rpc/server.js +1 -0
  37. package/dist/rpc/server.js.map +1 -1
  38. package/dist/version.txt +1 -1
  39. package/dist/yaml/index.d.ts +6 -0
  40. package/dist/yaml/index.d.ts.map +1 -0
  41. package/dist/yaml/index.js +37 -0
  42. package/dist/yaml/index.js.map +1 -0
  43. package/dist/yaml/parser.d.ts +6 -0
  44. package/dist/yaml/parser.d.ts.map +1 -0
  45. package/dist/yaml/parser.js +803 -0
  46. package/dist/yaml/parser.js.map +1 -0
  47. package/dist/yaml/print.d.ts +2 -0
  48. package/dist/yaml/print.d.ts.map +1 -0
  49. package/dist/yaml/print.js +234 -0
  50. package/dist/yaml/print.js.map +1 -0
  51. package/dist/yaml/rpc.d.ts +2 -0
  52. package/dist/yaml/rpc.d.ts.map +1 -0
  53. package/dist/yaml/rpc.js +264 -0
  54. package/dist/yaml/rpc.js.map +1 -0
  55. package/dist/yaml/tree.d.ts +188 -0
  56. package/dist/yaml/tree.d.ts.map +1 -0
  57. package/dist/yaml/tree.js +117 -0
  58. package/dist/yaml/tree.js.map +1 -0
  59. package/dist/yaml/visitor.d.ts +19 -0
  60. package/dist/yaml/visitor.d.ts.map +1 -0
  61. package/dist/yaml/visitor.js +170 -0
  62. package/dist/yaml/visitor.js.map +1 -0
  63. package/package.json +6 -1
  64. package/src/cli/cli-utils.ts +112 -35
  65. package/src/javascript/package-json-parser.ts +2 -12
  66. package/src/javascript/package-manager.ts +179 -3
  67. package/src/javascript/recipes/add-dependency.ts +16 -10
  68. package/src/javascript/recipes/upgrade-dependency-version.ts +16 -10
  69. package/src/javascript/recipes/upgrade-transitive-dependency-version.ts +15 -9
  70. package/src/json/parser.ts +443 -146
  71. package/src/json/tree.ts +159 -7
  72. package/src/print.ts +6 -2
  73. package/src/rpc/request/get-languages.ts +1 -0
  74. package/src/rpc/server.ts +1 -0
  75. package/src/yaml/index.ts +21 -0
  76. package/src/yaml/parser.ts +850 -0
  77. package/src/yaml/print.ts +212 -0
  78. package/src/yaml/rpc.ts +248 -0
  79. package/src/yaml/tree.ts +281 -0
  80. package/src/yaml/visitor.ts +146 -0
package/src/json/tree.ts CHANGED
@@ -98,18 +98,170 @@ export namespace Json {
98
98
  }
99
99
  }
100
100
 
101
- export function space(whitespace: string): Json.Space {
102
- return {
103
- kind: Json.Kind.Space,
104
- comments: [],
105
- whitespace: whitespace
106
- }
107
- }
101
+ // Cache for Space objects - reuse for common whitespace patterns (flyweight pattern)
102
+ const spaceCache = new Map<string, Json.Space>();
103
+ const SPACE_CACHE_MAX_LENGTH = 100;
108
104
 
109
105
  export const emptySpace: Json.Space = {
110
106
  kind: Json.Kind.Space,
111
107
  comments: [],
112
108
  whitespace: ""
109
+ };
110
+
111
+ const singleSpace: Json.Space = {
112
+ kind: Json.Kind.Space,
113
+ comments: [],
114
+ whitespace: " "
115
+ };
116
+
117
+ /**
118
+ * Parse a formatting string into a Space object, extracting comments.
119
+ * Mirrors the Java Space.format() method.
120
+ */
121
+ export function space(formatting: string): Json.Space {
122
+ if (formatting.length === 0) {
123
+ return emptySpace;
124
+ }
125
+ if (formatting === " ") {
126
+ return singleSpace;
127
+ }
128
+
129
+ // Check cache first for short strings
130
+ const cacheable = formatting.length <= SPACE_CACHE_MAX_LENGTH;
131
+ if (cacheable) {
132
+ const cached = spaceCache.get(formatting);
133
+ if (cached !== undefined) {
134
+ return cached;
135
+ }
136
+ }
137
+
138
+ // No comment markers means simple whitespace-only Space
139
+ if (!formatting.includes('/')) {
140
+ const result: Json.Space = {
141
+ kind: Json.Kind.Space,
142
+ comments: [],
143
+ whitespace: formatting
144
+ };
145
+ if (cacheable) {
146
+ spaceCache.set(formatting, result);
147
+ }
148
+ return result;
149
+ }
150
+
151
+ // Parse comments out of the formatting string
152
+ let prefix = '';
153
+ let comment = '';
154
+ const comments: Json.Comment[] = [];
155
+
156
+ let inSingleLineComment = false;
157
+ let inMultiLineComment = false;
158
+ let last = '';
159
+
160
+ for (let i = 0; i < formatting.length; i++) {
161
+ const c = formatting[i];
162
+
163
+ if (c === '/') {
164
+ if (inSingleLineComment) {
165
+ comment += c;
166
+ } else if (last === '/' && !inMultiLineComment) {
167
+ // Start of single-line comment
168
+ inSingleLineComment = true;
169
+ comment = '';
170
+ prefix = prefix.slice(0, -1); // Remove the first '/'
171
+ } else if (last === '*' && inMultiLineComment && comment.length > 0) {
172
+ // End of multi-line comment
173
+ inMultiLineComment = false;
174
+ comment = comment.slice(0, -1); // Trim the last '*'
175
+ comments.push({
176
+ kind: Json.Kind.Comment,
177
+ multiline: true,
178
+ text: comment,
179
+ suffix: prefix.slice(0, -1),
180
+ markers: emptyMarkers
181
+ });
182
+ prefix = '';
183
+ comment = '';
184
+ continue;
185
+ } else if (inMultiLineComment) {
186
+ comment += c;
187
+ } else {
188
+ prefix += c;
189
+ }
190
+ } else if (c === '\r' || c === '\n') {
191
+ if (inSingleLineComment) {
192
+ // End of single-line comment
193
+ inSingleLineComment = false;
194
+ comments.push({
195
+ kind: Json.Kind.Comment,
196
+ multiline: false,
197
+ text: comment,
198
+ suffix: prefix,
199
+ markers: emptyMarkers
200
+ });
201
+ prefix = c;
202
+ comment = '';
203
+ } else if (!inMultiLineComment) {
204
+ prefix += c;
205
+ } else {
206
+ comment += c;
207
+ }
208
+ } else if (c === '*') {
209
+ if (inSingleLineComment) {
210
+ comment += c;
211
+ } else if (last === '/' && !inMultiLineComment) {
212
+ // Start of multi-line comment
213
+ inMultiLineComment = true;
214
+ comment = '';
215
+ } else {
216
+ comment += c;
217
+ }
218
+ } else {
219
+ if (inSingleLineComment || inMultiLineComment) {
220
+ comment += c;
221
+ } else {
222
+ prefix += c;
223
+ }
224
+ }
225
+ last = c;
226
+ }
227
+
228
+ // If a file ends with a single-line comment there may be no terminating newline
229
+ if (comment.length > 0 || inSingleLineComment) {
230
+ comments.push({
231
+ kind: Json.Kind.Comment,
232
+ multiline: false,
233
+ text: comment,
234
+ suffix: prefix,
235
+ markers: emptyMarkers
236
+ });
237
+ prefix = '';
238
+ }
239
+
240
+ // Shift the whitespace on each comment forward to be a suffix of the comment before it,
241
+ // and the whitespace on the first comment to be the whitespace of the tree element.
242
+ // The remaining prefix is the suffix of the last comment.
243
+ let whitespace = prefix;
244
+ if (comments.length > 0) {
245
+ for (let i = comments.length - 1; i >= 0; i--) {
246
+ const c = comments[i];
247
+ const next = c.suffix;
248
+ comments[i] = {
249
+ ...c,
250
+ suffix: whitespace
251
+ };
252
+ whitespace = next;
253
+ }
254
+ }
255
+
256
+ const result: Json.Space = {
257
+ kind: Json.Kind.Space,
258
+ comments,
259
+ whitespace
260
+ };
261
+ if (cacheable) {
262
+ spaceCache.set(formatting, result);
263
+ }
264
+ return result;
113
265
  }
114
266
 
115
267
  const jsonKindValues = new Set(Object.values(Json.Kind));
package/src/print.ts CHANGED
@@ -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 {Marker, MarkersKind, SearchResult} from "./markers";
16
+ import {Marker, MarkersKind, Markup, SearchResult} from "./markers";
17
17
  import {Cursor, isSourceFile, SourceFile, Tree} from "./tree";
18
18
  import {TreeVisitor} from "./visitor";
19
19
  import {trimIndent} from "./util";
@@ -35,7 +35,11 @@ export namespace MarkerPrinter {
35
35
  let searchResult = marker as SearchResult;
36
36
  return commentWrapper(searchResult.description == null ? "" : "(" + searchResult.description + ")");
37
37
  } else if (marker.kind.startsWith("org.openrewrite.marker.Markup$")) {
38
- return commentWrapper("(" + (marker as any).message + ")");
38
+ const markup = marker as Markup;
39
+ const content = markup.detail
40
+ ? `(${markup.message}: ${markup.detail})`
41
+ : `(${markup.message})`;
42
+ return commentWrapper(content);
39
43
  }
40
44
  return "";
41
45
  },
@@ -13,6 +13,7 @@ export class GetLanguages {
13
13
  const languages = [
14
14
  "org.openrewrite.text.PlainText",
15
15
  "org.openrewrite.json.tree.Json$Document",
16
+ "org.openrewrite.yaml.tree.Yaml$Documents",
16
17
  // TODO Support for Javadoc comments is not yet implemented
17
18
  // "org.openrewrite.java.tree.J$CompilationUnit",
18
19
  "org.openrewrite.javascript.tree.JS$CompilationUnit",
package/src/rpc/server.ts CHANGED
@@ -24,6 +24,7 @@ import {DependencyWorkspace} from "../javascript/dependency-workspace";
24
24
  // Include all languages you want this server to support.
25
25
  import "../text";
26
26
  import "../json";
27
+ import "../yaml";
27
28
  import "../java";
28
29
  import "../javascript";
29
30
 
@@ -0,0 +1,21 @@
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
+ export * from "./tree";
17
+ export * from "./visitor";
18
+ export * from "./parser";
19
+
20
+ import "./print";
21
+ import "./rpc";