@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
@@ -0,0 +1,281 @@
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 {Markers} from "../markers";
17
+ import {SourceFile, Tree} from "../tree";
18
+
19
+ export interface Yaml extends Tree {
20
+ readonly prefix: string
21
+ }
22
+
23
+ export namespace Yaml {
24
+ export const Kind = {
25
+ Documents: "org.openrewrite.yaml.tree.Yaml$Documents",
26
+ Document: "org.openrewrite.yaml.tree.Yaml$Document",
27
+ DocumentEnd: "org.openrewrite.yaml.tree.Yaml$Document$End",
28
+ Mapping: "org.openrewrite.yaml.tree.Yaml$Mapping",
29
+ MappingEntry: "org.openrewrite.yaml.tree.Yaml$Mapping$Entry",
30
+ Scalar: "org.openrewrite.yaml.tree.Yaml$Scalar",
31
+ Sequence: "org.openrewrite.yaml.tree.Yaml$Sequence",
32
+ SequenceEntry: "org.openrewrite.yaml.tree.Yaml$Sequence$Entry",
33
+ Alias: "org.openrewrite.yaml.tree.Yaml$Alias",
34
+ Anchor: "org.openrewrite.yaml.tree.Yaml$Anchor",
35
+ Tag: "org.openrewrite.yaml.tree.Yaml$Tag"
36
+ } as const;
37
+
38
+ export enum ScalarStyle {
39
+ DOUBLE_QUOTED = "DOUBLE_QUOTED",
40
+ SINGLE_QUOTED = "SINGLE_QUOTED",
41
+ LITERAL = "LITERAL",
42
+ FOLDED = "FOLDED",
43
+ PLAIN = "PLAIN"
44
+ }
45
+
46
+ export enum TagKind {
47
+ LOCAL = "LOCAL",
48
+ IMPLICIT_GLOBAL = "IMPLICIT_GLOBAL",
49
+ EXPLICIT_GLOBAL = "EXPLICIT_GLOBAL"
50
+ }
51
+
52
+ /**
53
+ * Either a Scalar or an Alias can be a key in a mapping
54
+ */
55
+ export type YamlKey = Scalar | Alias;
56
+
57
+ /**
58
+ * Block types are Scalar, Mapping, Sequence, or Alias
59
+ */
60
+ export type Block = Scalar | Mapping | Sequence | Alias;
61
+
62
+ /**
63
+ * A YAML file containing multiple documents
64
+ */
65
+ export interface Documents extends SourceFile, Yaml {
66
+ readonly kind: typeof Kind.Documents;
67
+ readonly documents: Document[];
68
+ readonly suffix: string | undefined;
69
+ }
70
+
71
+ /**
72
+ * A single YAML document within a Documents container
73
+ */
74
+ export interface Document extends Yaml {
75
+ readonly kind: typeof Kind.Document;
76
+ /**
77
+ * True if the document explicitly starts with "---"
78
+ */
79
+ readonly explicit: boolean;
80
+ readonly block: Block;
81
+ readonly end: DocumentEnd;
82
+ }
83
+
84
+ /**
85
+ * Document end marker. May or may not be explicit ("...")
86
+ */
87
+ export interface DocumentEnd extends Yaml {
88
+ readonly kind: typeof Kind.DocumentEnd;
89
+ /**
90
+ * True if the document end is explicitly marked with "..."
91
+ */
92
+ readonly explicit: boolean;
93
+ }
94
+
95
+ /**
96
+ * A scalar value in YAML (string, number, boolean, etc.)
97
+ */
98
+ export interface Scalar extends Yaml {
99
+ readonly kind: typeof Kind.Scalar;
100
+ readonly style: ScalarStyle;
101
+ readonly anchor: Anchor | undefined;
102
+ readonly tag: Tag | undefined;
103
+ readonly value: string;
104
+ }
105
+
106
+ /**
107
+ * A YAML mapping (object/dictionary)
108
+ */
109
+ export interface Mapping extends Yaml {
110
+ readonly kind: typeof Kind.Mapping;
111
+ /**
112
+ * When non-null, indicates this is an inline mapping and contains the whitespace before '{'
113
+ */
114
+ readonly openingBracePrefix: string | undefined;
115
+ readonly entries: MappingEntry[];
116
+ /**
117
+ * When non-null, indicates this is an inline mapping and contains the whitespace before '}'
118
+ */
119
+ readonly closingBracePrefix: string | undefined;
120
+ readonly anchor: Anchor | undefined;
121
+ readonly tag: Tag | undefined;
122
+ }
123
+
124
+ /**
125
+ * A single key-value pair in a mapping
126
+ */
127
+ export interface MappingEntry extends Yaml {
128
+ readonly kind: typeof Kind.MappingEntry;
129
+ readonly key: YamlKey;
130
+ /**
131
+ * Whitespace before the mapping value indicator ':'
132
+ */
133
+ readonly beforeMappingValueIndicator: string;
134
+ readonly value: Block;
135
+ }
136
+
137
+ /**
138
+ * A YAML sequence (array/list)
139
+ */
140
+ export interface Sequence extends Yaml {
141
+ readonly kind: typeof Kind.Sequence;
142
+ /**
143
+ * When non-null, indicates this is an inline sequence and contains the whitespace before '['
144
+ */
145
+ readonly openingBracketPrefix: string | undefined;
146
+ readonly entries: SequenceEntry[];
147
+ /**
148
+ * When non-null, indicates this is an inline sequence and contains the whitespace before ']'
149
+ */
150
+ readonly closingBracketPrefix: string | undefined;
151
+ readonly anchor: Anchor | undefined;
152
+ readonly tag: Tag | undefined;
153
+ }
154
+
155
+ /**
156
+ * A single entry in a sequence
157
+ */
158
+ export interface SequenceEntry extends Yaml {
159
+ readonly kind: typeof Kind.SequenceEntry;
160
+ readonly block: Block;
161
+ /**
162
+ * True when this entry is part of a block sequence (uses '-')
163
+ * False when this entry is part of an inline sequence (uses '[' and ']')
164
+ */
165
+ readonly dash: boolean;
166
+ /**
167
+ * When non-null, contains the whitespace before the trailing comma in inline sequences
168
+ */
169
+ readonly trailingCommaPrefix: string | undefined;
170
+ }
171
+
172
+ /**
173
+ * An alias reference to an anchor (*anchorName)
174
+ */
175
+ export interface Alias extends Yaml {
176
+ readonly kind: typeof Kind.Alias;
177
+ readonly anchor: Anchor;
178
+ }
179
+
180
+ /**
181
+ * An anchor definition (&anchorName)
182
+ */
183
+ export interface Anchor extends Yaml {
184
+ readonly kind: typeof Kind.Anchor;
185
+ readonly postfix: string;
186
+ readonly key: string;
187
+ }
188
+
189
+ /**
190
+ * A YAML tag (!tag, !!tag, or !<tag>)
191
+ */
192
+ export interface Tag extends Yaml {
193
+ readonly kind: typeof Kind.Tag;
194
+ readonly name: string;
195
+ readonly suffix: string;
196
+ readonly tagKind: TagKind;
197
+ }
198
+ }
199
+
200
+ const yamlKindValues = new Set(Object.values(Yaml.Kind));
201
+
202
+ export function isYaml(tree: any): tree is Yaml {
203
+ return yamlKindValues.has(tree?.kind);
204
+ }
205
+
206
+ export function isDocuments(yaml: Yaml): yaml is Yaml.Documents {
207
+ return yaml.kind === Yaml.Kind.Documents;
208
+ }
209
+
210
+ export function isDocument(yaml: Yaml): yaml is Yaml.Document {
211
+ return yaml.kind === Yaml.Kind.Document;
212
+ }
213
+
214
+ export function isDocumentEnd(yaml: Yaml): yaml is Yaml.DocumentEnd {
215
+ return yaml.kind === Yaml.Kind.DocumentEnd;
216
+ }
217
+
218
+ export function isScalar(yaml: Yaml): yaml is Yaml.Scalar {
219
+ return yaml.kind === Yaml.Kind.Scalar;
220
+ }
221
+
222
+ export function isMapping(yaml: Yaml): yaml is Yaml.Mapping {
223
+ return yaml.kind === Yaml.Kind.Mapping;
224
+ }
225
+
226
+ export function isMappingEntry(yaml: Yaml): yaml is Yaml.MappingEntry {
227
+ return yaml.kind === Yaml.Kind.MappingEntry;
228
+ }
229
+
230
+ export function isSequence(yaml: Yaml): yaml is Yaml.Sequence {
231
+ return yaml.kind === Yaml.Kind.Sequence;
232
+ }
233
+
234
+ export function isSequenceEntry(yaml: Yaml): yaml is Yaml.SequenceEntry {
235
+ return yaml.kind === Yaml.Kind.SequenceEntry;
236
+ }
237
+
238
+ export function isAlias(yaml: Yaml): yaml is Yaml.Alias {
239
+ return yaml.kind === Yaml.Kind.Alias;
240
+ }
241
+
242
+ export function isAnchor(yaml: Yaml): yaml is Yaml.Anchor {
243
+ return yaml.kind === Yaml.Kind.Anchor;
244
+ }
245
+
246
+ export function isTag(yaml: Yaml): yaml is Yaml.Tag {
247
+ return yaml.kind === Yaml.Kind.Tag;
248
+ }
249
+
250
+ export function isBlock(yaml: Yaml): yaml is Yaml.Block {
251
+ return isScalar(yaml) || isMapping(yaml) || isSequence(yaml) || isAlias(yaml);
252
+ }
253
+
254
+ export function isYamlKey(yaml: Yaml): yaml is Yaml.YamlKey {
255
+ return isScalar(yaml) || isAlias(yaml);
256
+ }
257
+
258
+ /**
259
+ * Gets the value from a YamlKey (either a Scalar or an Alias)
260
+ */
261
+ export function getYamlKeyValue(key: Yaml.YamlKey): string {
262
+ if (isScalar(key)) {
263
+ return key.value;
264
+ } else {
265
+ return key.anchor.key;
266
+ }
267
+ }
268
+
269
+ /**
270
+ * Prints a tag according to its kind
271
+ */
272
+ export function printTag(tag: Yaml.Tag): string {
273
+ switch (tag.tagKind) {
274
+ case Yaml.TagKind.LOCAL:
275
+ return `!${tag.name}`;
276
+ case Yaml.TagKind.IMPLICIT_GLOBAL:
277
+ return `!!${tag.name}`;
278
+ case Yaml.TagKind.EXPLICIT_GLOBAL:
279
+ return `!<${tag.name}>`;
280
+ }
281
+ }
@@ -0,0 +1,146 @@
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 {mapAsync, updateIfChanged} from "../util";
17
+ import {TreeVisitor} from "../visitor";
18
+ import {SourceFile} from "../tree";
19
+ import {isYaml, Yaml} from "./tree";
20
+
21
+ export class YamlVisitor<P> extends TreeVisitor<Yaml, P> {
22
+ async isAcceptable(sourceFile: SourceFile): Promise<boolean> {
23
+ return isYaml(sourceFile);
24
+ }
25
+
26
+ protected async visitDocuments(documents: Yaml.Documents, p: P): Promise<Yaml | undefined> {
27
+ const updates: any = {
28
+ markers: await this.visitMarkers(documents.markers, p),
29
+ documents: await mapAsync(documents.documents, doc => this.visitDefined(doc, p) as Promise<Yaml.Document>)
30
+ };
31
+ return updateIfChanged(documents, updates);
32
+ }
33
+
34
+ protected async visitDocument(document: Yaml.Document, p: P): Promise<Yaml | undefined> {
35
+ const updates: any = {
36
+ markers: await this.visitMarkers(document.markers, p),
37
+ block: await this.visitDefined(document.block, p),
38
+ end: await this.visitDefined(document.end, p)
39
+ };
40
+ return updateIfChanged(document, updates);
41
+ }
42
+
43
+ protected async visitDocumentEnd(end: Yaml.DocumentEnd, p: P): Promise<Yaml | undefined> {
44
+ const updates: any = {
45
+ markers: await this.visitMarkers(end.markers, p)
46
+ };
47
+ return updateIfChanged(end, updates);
48
+ }
49
+
50
+ protected async visitMapping(mapping: Yaml.Mapping, p: P): Promise<Yaml | undefined> {
51
+ const updates: any = {
52
+ markers: await this.visitMarkers(mapping.markers, p),
53
+ tag: mapping.tag ? await this.visit(mapping.tag, p) : undefined,
54
+ anchor: mapping.anchor ? await this.visit(mapping.anchor, p) : undefined,
55
+ entries: await mapAsync(mapping.entries, entry => this.visitDefined(entry, p) as Promise<Yaml.MappingEntry>)
56
+ };
57
+ return updateIfChanged(mapping, updates);
58
+ }
59
+
60
+ protected async visitMappingEntry(entry: Yaml.MappingEntry, p: P): Promise<Yaml | undefined> {
61
+ const updates: any = {
62
+ markers: await this.visitMarkers(entry.markers, p),
63
+ key: await this.visitDefined(entry.key, p),
64
+ value: await this.visitDefined(entry.value, p)
65
+ };
66
+ return updateIfChanged(entry, updates);
67
+ }
68
+
69
+ protected async visitScalar(scalar: Yaml.Scalar, p: P): Promise<Yaml | undefined> {
70
+ const updates: any = {
71
+ markers: await this.visitMarkers(scalar.markers, p),
72
+ anchor: scalar.anchor ? await this.visit(scalar.anchor, p) : undefined,
73
+ tag: scalar.tag ? await this.visit(scalar.tag, p) : undefined
74
+ };
75
+ return updateIfChanged(scalar, updates);
76
+ }
77
+
78
+ protected async visitSequence(sequence: Yaml.Sequence, p: P): Promise<Yaml | undefined> {
79
+ const updates: any = {
80
+ markers: await this.visitMarkers(sequence.markers, p),
81
+ tag: sequence.tag ? await this.visit(sequence.tag, p) : undefined,
82
+ anchor: sequence.anchor ? await this.visit(sequence.anchor, p) : undefined,
83
+ entries: await mapAsync(sequence.entries, entry => this.visitDefined(entry, p) as Promise<Yaml.SequenceEntry>)
84
+ };
85
+ return updateIfChanged(sequence, updates);
86
+ }
87
+
88
+ protected async visitSequenceEntry(entry: Yaml.SequenceEntry, p: P): Promise<Yaml | undefined> {
89
+ const updates: any = {
90
+ markers: await this.visitMarkers(entry.markers, p),
91
+ block: await this.visitDefined(entry.block, p)
92
+ };
93
+ return updateIfChanged(entry, updates);
94
+ }
95
+
96
+ protected async visitAnchor(anchor: Yaml.Anchor, p: P): Promise<Yaml | undefined> {
97
+ const updates: any = {
98
+ markers: await this.visitMarkers(anchor.markers, p)
99
+ };
100
+ return updateIfChanged(anchor, updates);
101
+ }
102
+
103
+ protected async visitAlias(alias: Yaml.Alias, p: P): Promise<Yaml | undefined> {
104
+ const updates: any = {
105
+ markers: await this.visitMarkers(alias.markers, p),
106
+ anchor: await this.visitDefined(alias.anchor, p)
107
+ };
108
+ return updateIfChanged(alias, updates);
109
+ }
110
+
111
+ protected async visitTag(tag: Yaml.Tag, p: P): Promise<Yaml | undefined> {
112
+ const updates: any = {
113
+ markers: await this.visitMarkers(tag.markers, p)
114
+ };
115
+ return updateIfChanged(tag, updates);
116
+ }
117
+
118
+ protected accept(t: Yaml, p: P): Promise<Yaml | undefined> {
119
+ switch (t.kind) {
120
+ case Yaml.Kind.Documents:
121
+ return this.visitDocuments(t as Yaml.Documents, p);
122
+ case Yaml.Kind.Document:
123
+ return this.visitDocument(t as Yaml.Document, p);
124
+ case Yaml.Kind.DocumentEnd:
125
+ return this.visitDocumentEnd(t as Yaml.DocumentEnd, p);
126
+ case Yaml.Kind.Mapping:
127
+ return this.visitMapping(t as Yaml.Mapping, p);
128
+ case Yaml.Kind.MappingEntry:
129
+ return this.visitMappingEntry(t as Yaml.MappingEntry, p);
130
+ case Yaml.Kind.Scalar:
131
+ return this.visitScalar(t as Yaml.Scalar, p);
132
+ case Yaml.Kind.Sequence:
133
+ return this.visitSequence(t as Yaml.Sequence, p);
134
+ case Yaml.Kind.SequenceEntry:
135
+ return this.visitSequenceEntry(t as Yaml.SequenceEntry, p);
136
+ case Yaml.Kind.Anchor:
137
+ return this.visitAnchor(t as Yaml.Anchor, p);
138
+ case Yaml.Kind.Alias:
139
+ return this.visitAlias(t as Yaml.Alias, p);
140
+ case Yaml.Kind.Tag:
141
+ return this.visitTag(t as Yaml.Tag, p);
142
+ default:
143
+ throw new Error(`Unexpected YAML kind ${(t as any).kind}`);
144
+ }
145
+ }
146
+ }