@openrewrite/rewrite 8.63.0 → 8.63.2

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 (134) hide show
  1. package/dist/java/index.d.ts +1 -0
  2. package/dist/java/index.d.ts.map +1 -1
  3. package/dist/java/index.js +1 -0
  4. package/dist/java/index.js.map +1 -1
  5. package/dist/java/rpc.d.ts +2 -0
  6. package/dist/java/rpc.d.ts.map +1 -1
  7. package/dist/java/rpc.js +749 -410
  8. package/dist/java/rpc.js.map +1 -1
  9. package/dist/java/tree.d.ts +1 -1
  10. package/dist/java/tree.d.ts.map +1 -1
  11. package/dist/java/type-visitor.d.ts +48 -0
  12. package/dist/java/type-visitor.d.ts.map +1 -0
  13. package/dist/java/type-visitor.js +260 -0
  14. package/dist/java/type-visitor.js.map +1 -0
  15. package/dist/java/type.d.ts +2 -0
  16. package/dist/java/type.d.ts.map +1 -1
  17. package/dist/java/type.js +0 -317
  18. package/dist/java/type.js.map +1 -1
  19. package/dist/java/visitor.d.ts.map +1 -1
  20. package/dist/java/visitor.js +579 -363
  21. package/dist/java/visitor.js.map +1 -1
  22. package/dist/javascript/preconditions.d.ts +1 -1
  23. package/dist/javascript/preconditions.d.ts.map +1 -1
  24. package/dist/javascript/preconditions.js +7 -6
  25. package/dist/javascript/preconditions.js.map +1 -1
  26. package/dist/javascript/rpc.js +430 -350
  27. package/dist/javascript/rpc.js.map +1 -1
  28. package/dist/javascript/tree.d.ts +1 -1
  29. package/dist/javascript/tree.d.ts.map +1 -1
  30. package/dist/javascript/type-mapping.d.ts.map +1 -1
  31. package/dist/javascript/type-mapping.js +7 -0
  32. package/dist/javascript/type-mapping.js.map +1 -1
  33. package/dist/javascript/visitor.d.ts.map +1 -1
  34. package/dist/javascript/visitor.js +504 -309
  35. package/dist/javascript/visitor.js.map +1 -1
  36. package/dist/json/visitor.d.ts.map +1 -1
  37. package/dist/json/visitor.js +46 -21
  38. package/dist/json/visitor.js.map +1 -1
  39. package/dist/rpc/queue.d.ts +7 -4
  40. package/dist/rpc/queue.d.ts.map +1 -1
  41. package/dist/rpc/queue.js +22 -32
  42. package/dist/rpc/queue.js.map +1 -1
  43. package/dist/rpc/request/generate.d.ts.map +1 -1
  44. package/dist/rpc/request/generate.js +2 -3
  45. package/dist/rpc/request/generate.js.map +1 -1
  46. package/dist/rpc/request/get-languages.d.ts.map +1 -1
  47. package/dist/rpc/request/get-languages.js +4 -3
  48. package/dist/rpc/request/get-languages.js.map +1 -1
  49. package/dist/rpc/request/get-object.d.ts +1 -1
  50. package/dist/rpc/request/get-object.d.ts.map +1 -1
  51. package/dist/rpc/request/get-object.js +8 -7
  52. package/dist/rpc/request/get-object.js.map +1 -1
  53. package/dist/rpc/request/get-recipes.d.ts.map +1 -1
  54. package/dist/rpc/request/get-recipes.js +2 -2
  55. package/dist/rpc/request/get-recipes.js.map +1 -1
  56. package/dist/rpc/request/index.d.ts +1 -0
  57. package/dist/rpc/request/index.d.ts.map +1 -1
  58. package/dist/rpc/request/index.js +1 -0
  59. package/dist/rpc/request/index.js.map +1 -1
  60. package/dist/rpc/request/install-recipes.d.ts.map +1 -1
  61. package/dist/rpc/request/install-recipes.js +30 -21
  62. package/dist/rpc/request/install-recipes.js.map +1 -1
  63. package/dist/rpc/request/metrics.d.ts +10 -10
  64. package/dist/rpc/request/metrics.d.ts.map +1 -1
  65. package/dist/rpc/request/metrics.js +38 -31
  66. package/dist/rpc/request/metrics.js.map +1 -1
  67. package/dist/rpc/request/parse.d.ts.map +1 -1
  68. package/dist/rpc/request/parse.js +10 -12
  69. package/dist/rpc/request/parse.js.map +1 -1
  70. package/dist/rpc/request/prepare-recipe.d.ts.map +1 -1
  71. package/dist/rpc/request/prepare-recipe.js +4 -4
  72. package/dist/rpc/request/prepare-recipe.js.map +1 -1
  73. package/dist/rpc/request/print.d.ts +1 -1
  74. package/dist/rpc/request/print.d.ts.map +1 -1
  75. package/dist/rpc/request/print.js +10 -6
  76. package/dist/rpc/request/print.js.map +1 -1
  77. package/dist/rpc/request/trace-get-object.d.ts +5 -0
  78. package/dist/rpc/request/trace-get-object.d.ts.map +1 -0
  79. package/dist/rpc/request/trace-get-object.js +3 -0
  80. package/dist/rpc/request/trace-get-object.js.map +1 -0
  81. package/dist/rpc/request/visit.d.ts.map +1 -1
  82. package/dist/rpc/request/visit.js +2 -3
  83. package/dist/rpc/request/visit.js.map +1 -1
  84. package/dist/rpc/rewrite-rpc.d.ts +2 -3
  85. package/dist/rpc/rewrite-rpc.d.ts.map +1 -1
  86. package/dist/rpc/rewrite-rpc.js +14 -5
  87. package/dist/rpc/rewrite-rpc.js.map +1 -1
  88. package/dist/rpc/server.d.ts.map +1 -1
  89. package/dist/rpc/server.js +15 -44
  90. package/dist/rpc/server.js.map +1 -1
  91. package/dist/rpc/trace.d.ts +1 -1
  92. package/dist/rpc/trace.d.ts.map +1 -1
  93. package/dist/rpc/trace.js +3 -3
  94. package/dist/rpc/trace.js.map +1 -1
  95. package/dist/util.d.ts +6 -0
  96. package/dist/util.d.ts.map +1 -1
  97. package/dist/util.js +14 -0
  98. package/dist/util.js.map +1 -1
  99. package/dist/version.txt +1 -1
  100. package/package.json +1 -1
  101. package/src/java/index.ts +1 -0
  102. package/src/java/rpc.ts +726 -537
  103. package/src/java/tree.ts +1 -1
  104. package/src/java/type-visitor.ts +241 -0
  105. package/src/java/type.ts +13 -277
  106. package/src/java/visitor.ts +581 -378
  107. package/src/javascript/preconditions.ts +7 -6
  108. package/src/javascript/rpc.ts +431 -360
  109. package/src/javascript/tree.ts +1 -1
  110. package/src/javascript/type-mapping.ts +7 -0
  111. package/src/javascript/visitor.ts +505 -310
  112. package/src/json/visitor.ts +47 -22
  113. package/src/rpc/queue.ts +20 -17
  114. package/src/rpc/request/generate.ts +31 -25
  115. package/src/rpc/request/get-languages.ts +18 -10
  116. package/src/rpc/request/get-object.ts +42 -34
  117. package/src/rpc/request/get-recipes.ts +15 -8
  118. package/src/rpc/request/index.ts +1 -0
  119. package/src/rpc/request/install-recipes.ts +96 -79
  120. package/src/rpc/request/metrics.ts +54 -48
  121. package/src/rpc/request/parse.ts +31 -25
  122. package/src/rpc/request/prepare-recipe.ts +31 -23
  123. package/src/rpc/request/print.ts +28 -14
  124. package/src/rpc/request/trace-get-object.ts +4 -0
  125. package/src/rpc/request/visit.ts +22 -16
  126. package/src/rpc/rewrite-rpc.ts +23 -10
  127. package/src/rpc/server.ts +17 -52
  128. package/src/rpc/trace.ts +3 -3
  129. package/src/util.ts +14 -0
  130. package/dist/rpc/chrome-profiler.d.ts +0 -25
  131. package/dist/rpc/chrome-profiler.d.ts.map +0 -1
  132. package/dist/rpc/chrome-profiler.js +0 -405
  133. package/dist/rpc/chrome-profiler.js.map +0 -1
  134. package/src/rpc/chrome-profiler.ts +0 -373
@@ -1,373 +0,0 @@
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 * as fs from 'fs';
17
- import * as path from 'path';
18
- import * as v8 from 'v8';
19
- import * as inspector from 'inspector';
20
-
21
- export class ChromeProfiler {
22
- private traceEvents: any[] = [];
23
- private memoryInterval?: NodeJS.Timeout;
24
- private saveInterval?: NodeJS.Timeout;
25
- private session?: inspector.Session;
26
- private readonly pid = process.pid;
27
- private readonly tid = 1; // Main thread
28
- private readonly tracePath: string;
29
- private exitHandlersRegistered = false;
30
- private startTime: number = 0;
31
- private ttsCounter: number = 0;
32
- private lastProfileTime: number = 0;
33
- private profileNodes = new Map();
34
-
35
- constructor(outputPath?: string) {
36
- this.tracePath = outputPath || path.join(process.cwd(), 'chrome-trace.json');
37
- }
38
-
39
- async start() {
40
- this.startTime = Date.now() * 1000; // Convert to microseconds
41
- this.lastProfileTime = this.startTime;
42
-
43
- // Add initial metadata events
44
- this.addMetadataEvents();
45
-
46
- // Start V8 Inspector session for CPU profiling
47
- this.session = new inspector.Session();
48
- this.session.connect();
49
-
50
- // Enable and start CPU profiling
51
- await this.enableCpuProfiling();
52
-
53
- // Start collecting memory data
54
- this.startMemoryTracking();
55
-
56
- // Save trace periodically and collect CPU profile samples
57
- this.saveInterval = setInterval(async () => {
58
- await this.collectCpuProfile();
59
- this.saveTrace();
60
- }, 10000); // Save every 10 seconds
61
-
62
- // Register exit handlers
63
- if (!this.exitHandlersRegistered) {
64
- this.registerExitHandlers();
65
- this.exitHandlersRegistered = true;
66
- }
67
- }
68
-
69
- private async enableCpuProfiling() {
70
- if (!this.session) return;
71
-
72
- // Enable profiler
73
- await new Promise<void>((resolve, reject) => {
74
- this.session!.post('Profiler.enable', (err) => {
75
- if (err) reject(err);
76
- else resolve();
77
- });
78
- });
79
-
80
- // Start sampling
81
- await new Promise<void>((resolve, reject) => {
82
- this.session!.post('Profiler.start', {
83
- // Sample at high frequency for detailed profiling
84
- samplingInterval: 100
85
- }, (err) => {
86
- if (err) reject(err);
87
- else resolve();
88
- });
89
- });
90
-
91
- // Subscribe to console profile events
92
- this.session.on('Profiler.consoleProfileStarted', (params: any) => {
93
- this.traceEvents.push({
94
- cat: 'disabled-by-default-devtools.timeline',
95
- name: 'Profile',
96
- ph: 'P',
97
- id: params.id || '1',
98
- pid: this.pid,
99
- tid: this.tid,
100
- ts: Date.now() * 1000
101
- });
102
- });
103
- }
104
-
105
- private addMetadataEvents() {
106
- // Thread name metadata
107
- this.traceEvents.push({
108
- args: { name: 'CrRendererMain' },
109
- cat: '__metadata',
110
- name: 'thread_name',
111
- ph: 'M',
112
- pid: this.pid,
113
- tid: this.tid,
114
- ts: 0
115
- });
116
-
117
- // Process name metadata
118
- this.traceEvents.push({
119
- args: { name: 'Node.js' },
120
- cat: '__metadata',
121
- name: 'process_name',
122
- ph: 'M',
123
- pid: this.pid,
124
- tid: 0,
125
- ts: 0
126
- });
127
-
128
- // TracingStartedInBrowser event - required for Chrome DevTools
129
- this.traceEvents.push({
130
- args: {
131
- data: {
132
- frameTreeNodeId: 1,
133
- frames: [{
134
- frame: '0x1',
135
- name: '',
136
- processId: this.pid,
137
- url: 'node://process'
138
- }],
139
- persistentIds: true
140
- }
141
- },
142
- cat: 'disabled-by-default-devtools.timeline',
143
- name: 'TracingStartedInBrowser',
144
- ph: 'I',
145
- pid: this.pid,
146
- s: 't',
147
- tid: this.tid,
148
- ts: this.startTime,
149
- tts: this.ttsCounter++
150
- });
151
- }
152
-
153
- private startMemoryTracking() {
154
- // Collect memory data every 50ms (matching Chrome's frequency)
155
- this.memoryInterval = setInterval(() => {
156
- const memStats = v8.getHeapStatistics();
157
- const timestamp = Date.now() * 1000;
158
-
159
- // UpdateCounters event with correct format
160
- this.traceEvents.push({
161
- args: {
162
- data: {
163
- jsHeapSizeUsed: memStats.used_heap_size,
164
- jsEventListeners: 0,
165
- documents: 1,
166
- nodes: 0
167
- }
168
- },
169
- cat: 'disabled-by-default-devtools.timeline',
170
- name: 'UpdateCounters',
171
- ph: 'I', // Instant event, not Counter
172
- pid: this.pid,
173
- s: 't', // Required for instant events
174
- tid: this.tid,
175
- ts: timestamp,
176
- tts: this.ttsCounter++
177
- });
178
- }, 50); // Every 50ms
179
- }
180
-
181
- private saveTrace() {
182
- const trace = {
183
- metadata: {
184
- 'command-line': process.argv.join(' '),
185
- 'cpu-brand': 'Node.js V8',
186
- 'dataOrigin': 'TraceEvents',
187
- 'highres-ticks': true,
188
- 'hostname': 'localhost',
189
- 'num-cpus': require('os').cpus().length,
190
- 'physical-memory': require('os').totalmem(),
191
- 'platform': process.platform,
192
- 'process-uptime': process.uptime(),
193
- 'product-version': `Node.js ${process.version}`,
194
- 'protocol-version': '1.0',
195
- 'source': 'NodeProfiler',
196
- 'startTime': new Date(this.startTime / 1000).toISOString(),
197
- 'trace-config': '',
198
- 'user-agent': `Node.js/${process.version}`,
199
- 'v8-version': process.versions.v8
200
- },
201
- traceEvents: this.traceEvents
202
- };
203
-
204
- try {
205
- fs.writeFileSync(this.tracePath, JSON.stringify(trace, null, 2));
206
- } catch (e) {
207
- // Ignore write errors
208
- }
209
- }
210
-
211
- private async collectCpuProfile() {
212
- if (!this.session) return;
213
-
214
- try {
215
- // Stop current profiling to get samples
216
- const profile = await new Promise<any>((resolve, reject) => {
217
- this.session!.post('Profiler.stop', (err, params) => {
218
- if (err) reject(err);
219
- else resolve(params.profile);
220
- });
221
- });
222
-
223
- // Convert CPU profile samples to trace events
224
- if (profile && profile.samples) {
225
- this.addCpuProfileSamples(profile);
226
- }
227
-
228
- // Restart profiling for the next interval
229
- await new Promise<void>((resolve, reject) => {
230
- this.session!.post('Profiler.start', {
231
- samplingInterval: 100
232
- }, (err) => {
233
- if (err) reject(err);
234
- else resolve();
235
- });
236
- });
237
- } catch (e) {
238
- // Ignore errors and try to restart
239
- try {
240
- await new Promise<void>((resolve, reject) => {
241
- this.session!.post('Profiler.start', {
242
- samplingInterval: 100
243
- }, (err) => {
244
- if (err) reject(err);
245
- else resolve();
246
- });
247
- });
248
- } catch (e2) {
249
- // Ignore restart errors
250
- }
251
- }
252
- }
253
-
254
- async stop() {
255
- // Clear intervals
256
- if (this.memoryInterval) {
257
- clearInterval(this.memoryInterval);
258
- this.memoryInterval = undefined;
259
- }
260
- if (this.saveInterval) {
261
- clearInterval(this.saveInterval);
262
- this.saveInterval = undefined;
263
- }
264
-
265
- // Collect final CPU profile
266
- await this.collectCpuProfile();
267
-
268
- // Disconnect session
269
- if (this.session) {
270
- this.session.disconnect();
271
- this.session = undefined;
272
- }
273
-
274
- // Save final trace
275
- this.saveTrace();
276
- }
277
-
278
- private addCpuProfileSamples(profile: any) {
279
- if (!profile.samples || !profile.timeDeltas || !profile.nodes) return;
280
-
281
- // Use the last profile time as starting point to maintain continuity
282
- let currentTime = this.lastProfileTime;
283
-
284
- // Update nodes map with new nodes
285
- profile.nodes.forEach((node: any) => {
286
- this.profileNodes.set(node.id, node);
287
- });
288
-
289
- // Convert samples to trace events with actual function names
290
- profile.samples.forEach((nodeId: number, index: number) => {
291
- const node = this.profileNodes.get(nodeId);
292
- if (!node) return;
293
-
294
- currentTime += (profile.timeDeltas[index] || 0);
295
-
296
- const callFrame = node.callFrame;
297
- if (callFrame) {
298
- // Clean up function name for display
299
- let functionName = callFrame.functionName || '(anonymous)';
300
- if (functionName === '' || functionName === '(root)') {
301
- functionName = '(program)';
302
- }
303
-
304
- // Extract filename from URL or use a meaningful default
305
- let url = callFrame.url || '';
306
- let fileName: string;
307
-
308
- if (url) {
309
- // Clean up the URL for display
310
- if (url.startsWith('file://')) {
311
- url = url.substring(7);
312
- }
313
- const parts = url.split('/');
314
- fileName = parts[parts.length - 1] || url;
315
-
316
- // Special handling for node internals
317
- if (url.startsWith('node:')) {
318
- fileName = url;
319
- }
320
- } else {
321
- // No URL - try to provide context from function name
322
- if (functionName === '(garbage collector)') {
323
- fileName = 'v8::gc';
324
- } else if (functionName === '(idle)') {
325
- fileName = 'v8::idle';
326
- } else if (functionName === '(program)') {
327
- fileName = 'main';
328
- } else if (functionName.includes('::')) {
329
- // C++ internal function
330
- fileName = 'native';
331
- } else {
332
- // JavaScript code without source mapping
333
- fileName = 'javascript';
334
- }
335
- }
336
-
337
- this.traceEvents.push({
338
- args: {
339
- data: {
340
- columnNumber: callFrame.columnNumber || 0,
341
- frame: `0x${nodeId.toString(16)}`,
342
- functionName: functionName,
343
- lineNumber: callFrame.lineNumber || 0,
344
- scriptId: String(callFrame.scriptId || 0),
345
- url: url || fileName // Use fileName as URL if no real URL
346
- }
347
- },
348
- cat: 'devtools.timeline',
349
- dur: Math.max(profile.timeDeltas[index] || 1, 1),
350
- name: 'FunctionCall',
351
- ph: 'X',
352
- pid: this.pid,
353
- tid: this.tid,
354
- ts: Math.floor(currentTime),
355
- tts: this.ttsCounter++
356
- });
357
- }
358
- });
359
-
360
- // Update lastProfileTime to maintain continuity for the next batch
361
- this.lastProfileTime = currentTime;
362
- }
363
-
364
- private registerExitHandlers() {
365
- const cleanup = async () => {
366
- await this.stop();
367
- };
368
-
369
- process.once('beforeExit', cleanup);
370
- process.once('SIGINT', cleanup);
371
- process.once('SIGTERM', cleanup);
372
- }
373
- }