@openrewrite/rewrite 8.103.0 → 8.104.0

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 (59) hide show
  1. package/dist/java/tree.d.ts +3 -0
  2. package/dist/java/tree.d.ts.map +1 -1
  3. package/dist/java/tree.js +3 -1
  4. package/dist/java/tree.js.map +1 -1
  5. package/dist/javascript/add-import.d.ts +28 -0
  6. package/dist/javascript/add-import.d.ts.map +1 -1
  7. package/dist/javascript/add-import.js +48 -25
  8. package/dist/javascript/add-import.js.map +1 -1
  9. package/dist/javascript/assertions.d.ts.map +1 -1
  10. package/dist/javascript/assertions.js +60 -67
  11. package/dist/javascript/assertions.js.map +1 -1
  12. package/dist/javascript/binding.d.ts +5 -2
  13. package/dist/javascript/binding.d.ts.map +1 -1
  14. package/dist/javascript/binding.js +58 -14
  15. package/dist/javascript/binding.js.map +1 -1
  16. package/dist/javascript/format/prettier-config-loader.d.ts +1 -0
  17. package/dist/javascript/format/prettier-config-loader.d.ts.map +1 -1
  18. package/dist/javascript/format/prettier-config-loader.js +23 -4
  19. package/dist/javascript/format/prettier-config-loader.js.map +1 -1
  20. package/dist/javascript/member-spellings.d.ts +88 -0
  21. package/dist/javascript/member-spellings.d.ts.map +1 -0
  22. package/dist/javascript/member-spellings.js +357 -0
  23. package/dist/javascript/member-spellings.js.map +1 -0
  24. package/dist/javascript/package-manager.d.ts +3 -0
  25. package/dist/javascript/package-manager.d.ts.map +1 -1
  26. package/dist/javascript/package-manager.js +49 -0
  27. package/dist/javascript/package-manager.js.map +1 -1
  28. package/dist/javascript/project-parser.d.ts.map +1 -1
  29. package/dist/javascript/project-parser.js +70 -109
  30. package/dist/javascript/project-parser.js.map +1 -1
  31. package/dist/javascript/scope.d.ts +2 -0
  32. package/dist/javascript/scope.d.ts.map +1 -1
  33. package/dist/javascript/scope.js +2 -1
  34. package/dist/javascript/scope.js.map +1 -1
  35. package/dist/json/index.d.ts +1 -0
  36. package/dist/json/index.d.ts.map +1 -1
  37. package/dist/json/index.js +1 -0
  38. package/dist/json/index.js.map +1 -1
  39. package/dist/json/path-matcher.d.ts +29 -0
  40. package/dist/json/path-matcher.d.ts.map +1 -0
  41. package/dist/json/path-matcher.js +974 -0
  42. package/dist/json/path-matcher.js.map +1 -0
  43. package/dist/rewrite-javascript-version.txt +1 -1
  44. package/dist/rpc/request/parse-project.d.ts.map +1 -1
  45. package/dist/rpc/request/parse-project.js +20 -23
  46. package/dist/rpc/request/parse-project.js.map +1 -1
  47. package/package.json +1 -1
  48. package/src/java/tree.ts +2 -0
  49. package/src/javascript/add-import.ts +58 -30
  50. package/src/javascript/assertions.ts +43 -57
  51. package/src/javascript/binding.ts +72 -17
  52. package/src/javascript/format/prettier-config-loader.ts +22 -3
  53. package/src/javascript/member-spellings.ts +374 -0
  54. package/src/javascript/package-manager.ts +51 -0
  55. package/src/javascript/project-parser.ts +17 -50
  56. package/src/javascript/scope.ts +2 -2
  57. package/src/json/index.ts +1 -0
  58. package/src/json/path-matcher.ts +1092 -0
  59. package/src/rpc/request/parse-project.ts +22 -32
@@ -339,57 +339,24 @@ export class ProjectParser {
339
339
  relativeTo: this.relativeTo
340
340
  });
341
341
 
342
- // Check if Prettier is available
343
- const detection = await prettierLoader.detectPrettier();
344
-
345
- if (detection.available) {
346
- // Prettier is available: add per-file PrettierStyle markers
347
- for await (const sf of parser.parse(...discovered.jsFiles)) {
348
- current++;
349
- this.onProgress?.("parsing", current, totalFiles, sf.sourcePath);
350
-
351
- const prettierMarker = await prettierLoader.getConfigMarker(
352
- path.join(this.relativeTo, sf.sourcePath)
353
- );
354
- if (prettierMarker) {
355
- yield produce(sf, draft => {
356
- draft.markers = replaceMarkerByKind(draft.markers, prettierMarker);
357
- });
358
- } else {
359
- yield sf;
360
- }
361
- }
362
- } else {
363
- // Prettier is NOT available: auto-detect styles from parsed files
364
- this.log("Prettier not found, auto-detecting styles...");
365
-
366
- // Dynamic import to break circular dependency at module load time
367
- // (see buildAutodetectMarker for explanation)
368
- const {Autodetect} = await import("./autodetect.js");
369
- const {JS} = await import("./tree.js");
370
-
371
- const parsedFiles: SourceFile[] = [];
372
-
373
- // Parse all JS files and collect them for sampling
374
- for await (const sf of parser.parse(...discovered.jsFiles)) {
375
- current++;
376
- this.onProgress?.("parsing", current, totalFiles, sf.sourcePath);
377
- if (sf.kind === JS.Kind.CompilationUnit) {
378
- parsedFiles.push(sf);
379
- }
380
- }
381
-
382
- // Sample all parsed files and build Autodetect marker
383
- const detector = Autodetect.detector();
384
- for (const sf of parsedFiles) {
385
- await detector.sample(sf);
342
+ const fallbackFiles: SourceFile[] = [];
343
+ for await (const sf of parser.parse(...discovered.jsFiles)) {
344
+ current++;
345
+ this.onProgress?.("parsing", current, totalFiles, sf.sourcePath);
346
+ const prettierMarker = await prettierLoader.getConfigMarker(
347
+ path.join(this.relativeTo, sf.sourcePath)
348
+ );
349
+ if (prettierMarker) {
350
+ yield produce(sf, draft => {
351
+ draft.markers = replaceMarkerByKind(draft.markers, prettierMarker);
352
+ });
353
+ } else {
354
+ fallbackFiles.push(sf);
386
355
  }
387
- const autodetectMarker = detector.build();
388
- this.log(`Auto-detected styles: indent=${detector.getTabsAndIndentsStyle().indentSize}, ` +
389
- `useTabs=${detector.getTabsAndIndentsStyle().useTabCharacter}`);
390
-
391
- // Yield all files with the Autodetect marker
392
- for (const sf of parsedFiles) {
356
+ }
357
+ if (fallbackFiles.length > 0) {
358
+ const autodetectMarker = await this.buildAutodetectMarker(fallbackFiles);
359
+ for (const sf of fallbackFiles) {
393
360
  yield produce(sf, draft => {
394
361
  draft.markers = replaceMarkerByKind(draft.markers, autodetectMarker);
395
362
  });
@@ -786,8 +786,8 @@ function enumMemberNames(body: J.Block): Bound[] {
786
786
  });
787
787
  }
788
788
 
789
- /** The identifier a dotted name `A.B.C` declares, which is `A`: the rest are members of it. */
790
- function rootName(name: J | undefined): J | undefined {
789
+ /** The root of a dotted name: `A` in `A.B.C`. */
790
+ export function rootName(name: J | undefined): J | undefined {
791
791
  return name?.kind === J.Kind.FieldAccess ? rootName((name as J.FieldAccess).target) : name;
792
792
  }
793
793
 
package/src/json/index.ts CHANGED
@@ -18,6 +18,7 @@ export * from "./edit";
18
18
  export * from "./visitor";
19
19
  export * from "./assertions";
20
20
  export * from "./parser";
21
+ export * from "./path-matcher";
21
22
 
22
23
  import "./print";
23
24
  import "./rpc";