@openrewrite/rewrite 8.69.0-20251207-220615 → 8.69.0-20251208-071356

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 (37) hide show
  1. package/dist/javascript/autodetect.d.ts +45 -0
  2. package/dist/javascript/autodetect.d.ts.map +1 -0
  3. package/dist/javascript/autodetect.js +303 -0
  4. package/dist/javascript/autodetect.js.map +1 -0
  5. package/dist/javascript/format.d.ts +13 -2
  6. package/dist/javascript/format.d.ts.map +1 -1
  7. package/dist/javascript/format.js +100 -21
  8. package/dist/javascript/format.js.map +1 -1
  9. package/dist/javascript/index.d.ts +1 -0
  10. package/dist/javascript/index.d.ts.map +1 -1
  11. package/dist/javascript/index.js +1 -0
  12. package/dist/javascript/index.js.map +1 -1
  13. package/dist/javascript/recipes/auto-format.d.ts +25 -13
  14. package/dist/javascript/recipes/auto-format.d.ts.map +1 -1
  15. package/dist/javascript/recipes/auto-format.js +38 -13
  16. package/dist/javascript/recipes/auto-format.js.map +1 -1
  17. package/dist/javascript/style.d.ts +9 -0
  18. package/dist/javascript/style.d.ts.map +1 -1
  19. package/dist/javascript/style.js +30 -0
  20. package/dist/javascript/style.js.map +1 -1
  21. package/dist/run.d.ts +6 -5
  22. package/dist/run.d.ts.map +1 -1
  23. package/dist/run.js +36 -37
  24. package/dist/run.js.map +1 -1
  25. package/dist/test/rewrite-test.d.ts +17 -0
  26. package/dist/test/rewrite-test.d.ts.map +1 -1
  27. package/dist/test/rewrite-test.js +1 -0
  28. package/dist/test/rewrite-test.js.map +1 -1
  29. package/dist/version.txt +1 -1
  30. package/package.json +1 -1
  31. package/src/javascript/autodetect.ts +302 -0
  32. package/src/javascript/format.ts +97 -28
  33. package/src/javascript/index.ts +1 -0
  34. package/src/javascript/recipes/auto-format.ts +49 -14
  35. package/src/javascript/style.ts +32 -0
  36. package/src/run.ts +20 -20
  37. package/src/test/rewrite-test.ts +1 -1
package/src/run.ts CHANGED
@@ -78,13 +78,14 @@ export type ProgressCallback = (phase: 'parsing' | 'scanning' | 'processing', cu
78
78
  * Streaming version of scheduleRun that yields results as soon as each file is processed.
79
79
  * This allows callers to print diffs immediately and free memory earlier.
80
80
  *
81
- * Accepts either an array or an async iterable of source files. When the recipe is not
82
- * a scanning recipe, files are processed immediately as they're yielded from the iterable,
83
- * avoiding the need to collect all files into memory first.
81
+ * Accepts either an array or an async iterable of source files. Files are processed
82
+ * immediately as they're yielded from the iterable, avoiding the need to collect all
83
+ * files into memory before starting work.
84
84
  *
85
- * For scanning recipes, the scan phase completes on all files before yielding any results.
85
+ * For scanning recipes, each file is scanned immediately as it's pulled from the generator,
86
+ * then stored for the edit phase. The scan phase completes before any results are yielded.
86
87
  *
87
- * @param onProgress Optional callback for progress updates during parsing, scanning, and processing phases.
88
+ * @param onProgress Optional callback for progress updates during scanning and processing phases.
88
89
  */
89
90
  export async function* scheduleRunStreaming(
90
91
  recipe: Recipe,
@@ -96,23 +97,20 @@ export async function* scheduleRunStreaming(
96
97
  const isScanning = await hasScanningRecipe(recipe);
97
98
 
98
99
  if (isScanning) {
99
- // For scanning recipes, we need to collect all files first for the scan phase
100
- const files: SourceFile[] = Array.isArray(before) ? [...before] : [];
101
- if (!Array.isArray(before)) {
102
- let parseCount = 0;
103
- for await (const sf of before) {
104
- files.push(sf);
105
- parseCount++;
106
- onProgress?.('parsing', parseCount, -1, sf.sourcePath); // -1 = unknown total
107
- }
108
- }
100
+ // For scanning recipes, pull files from the generator and scan them immediately.
101
+ // Files are stored for the later edit phase.
102
+ const files: SourceFile[] = [];
103
+ const iterable = Array.isArray(before) ? before : before;
104
+ const knownTotal = Array.isArray(before) ? before.length : -1; // -1 = unknown total
109
105
 
110
- const totalFiles = files.length;
106
+ // Phase 1: Pull files from generator and scan each immediately
107
+ let scanCount = 0;
108
+ for await (const b of iterable) {
109
+ files.push(b);
110
+ scanCount++;
111
+ onProgress?.('scanning', scanCount, knownTotal, b.sourcePath);
111
112
 
112
- // Phase 1: Run scanners on all files
113
- for (let i = 0; i < files.length; i++) {
114
- const b = files[i];
115
- onProgress?.('scanning', i + 1, totalFiles, b.sourcePath);
113
+ // Scan this file immediately
116
114
  await recurseRecipeList(recipe, b, async (recipe, b2) => {
117
115
  if (recipe instanceof ScanningRecipe) {
118
116
  return (await recipe.scanner(recipe.accumulator(cursor, ctx))).visit(b2, ctx, cursor)
@@ -120,6 +118,8 @@ export async function* scheduleRunStreaming(
120
118
  });
121
119
  }
122
120
 
121
+ const totalFiles = files.length;
122
+
123
123
  // Phase 2: Collect generated files
124
124
  const generated = (await recurseRecipeList(recipe, [] as SourceFile[], async (recipe, generated) => {
125
125
  if (recipe instanceof ScanningRecipe) {
@@ -257,7 +257,7 @@ export type AfterRecipeText = string | ((actual: string) => string | undefined)
257
257
  * - ` code\n` → `code` (trailing newline removed)
258
258
  * - ` code\n\n` → `code\n` (first trailing newline removed, second preserved)
259
259
  */
260
- function dedent(s: string): string {
260
+ export function dedent(s: string): string {
261
261
  if (!s) return s;
262
262
 
263
263
  // Remove single leading newline for ergonomics