@openrewrite/rewrite 8.103.1 → 8.105.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.
- package/dist/java/tree.d.ts +3 -0
- package/dist/java/tree.d.ts.map +1 -1
- package/dist/java/tree.js +3 -1
- package/dist/java/tree.js.map +1 -1
- package/dist/javascript/add-import.d.ts +28 -0
- package/dist/javascript/add-import.d.ts.map +1 -1
- package/dist/javascript/add-import.js +48 -25
- package/dist/javascript/add-import.js.map +1 -1
- package/dist/javascript/assertions.d.ts.map +1 -1
- package/dist/javascript/assertions.js +60 -67
- package/dist/javascript/assertions.js.map +1 -1
- package/dist/javascript/binding.d.ts +5 -2
- package/dist/javascript/binding.d.ts.map +1 -1
- package/dist/javascript/binding.js +58 -14
- package/dist/javascript/binding.js.map +1 -1
- package/dist/javascript/format/prettier-config-loader.d.ts +1 -0
- package/dist/javascript/format/prettier-config-loader.d.ts.map +1 -1
- package/dist/javascript/format/prettier-config-loader.js +23 -4
- package/dist/javascript/format/prettier-config-loader.js.map +1 -1
- package/dist/javascript/member-spellings.d.ts +88 -0
- package/dist/javascript/member-spellings.d.ts.map +1 -0
- package/dist/javascript/member-spellings.js +357 -0
- package/dist/javascript/member-spellings.js.map +1 -0
- package/dist/javascript/package-manager.d.ts +3 -0
- package/dist/javascript/package-manager.d.ts.map +1 -1
- package/dist/javascript/package-manager.js +49 -0
- package/dist/javascript/package-manager.js.map +1 -1
- package/dist/javascript/project-parser.d.ts.map +1 -1
- package/dist/javascript/project-parser.js +70 -109
- package/dist/javascript/project-parser.js.map +1 -1
- package/dist/javascript/scope.d.ts +2 -0
- package/dist/javascript/scope.d.ts.map +1 -1
- package/dist/javascript/scope.js +2 -1
- package/dist/javascript/scope.js.map +1 -1
- package/dist/rewrite-javascript-version.txt +1 -1
- package/dist/rpc/request/parse-project.d.ts.map +1 -1
- package/dist/rpc/request/parse-project.js +20 -23
- package/dist/rpc/request/parse-project.js.map +1 -1
- package/package.json +1 -1
- package/src/java/tree.ts +2 -0
- package/src/javascript/add-import.ts +58 -30
- package/src/javascript/assertions.ts +43 -57
- package/src/javascript/binding.ts +72 -17
- package/src/javascript/format/prettier-config-loader.ts +22 -3
- package/src/javascript/member-spellings.ts +374 -0
- package/src/javascript/package-manager.ts +51 -0
- package/src/javascript/project-parser.ts +17 -50
- package/src/javascript/scope.ts +2 -2
- 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
|
-
|
|
343
|
-
const
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
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
|
-
|
|
388
|
-
|
|
389
|
-
|
|
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
|
});
|
package/src/javascript/scope.ts
CHANGED
|
@@ -786,8 +786,8 @@ function enumMemberNames(body: J.Block): Bound[] {
|
|
|
786
786
|
});
|
|
787
787
|
}
|
|
788
788
|
|
|
789
|
-
/** The
|
|
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
|
|
|
@@ -20,7 +20,7 @@ import {randomId, UUID} from "../../uuid";
|
|
|
20
20
|
import {SourceFile} from "../../tree";
|
|
21
21
|
import {Parsers} from "../../parser";
|
|
22
22
|
import {withMetrics} from "./metrics";
|
|
23
|
-
import {replaceMarkerByKind} from "../../markers";
|
|
23
|
+
import {Marker, replaceMarkerByKind} from "../../markers";
|
|
24
24
|
import {setLastParsedProject} from "./last-parsed-project";
|
|
25
25
|
|
|
26
26
|
/**
|
|
@@ -177,60 +177,50 @@ export class ParseProject {
|
|
|
177
177
|
relativeTo
|
|
178
178
|
});
|
|
179
179
|
|
|
180
|
-
|
|
181
|
-
const
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
180
|
+
const prettierMarkers = new Map<string, Marker>();
|
|
181
|
+
for (const filePath of discovered.jsFiles) {
|
|
182
|
+
const marker = await prettierLoader.getConfigMarker(filePath);
|
|
183
|
+
if (marker) {
|
|
184
|
+
prettierMarkers.set(filePath, marker);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
const generator = parser.parse(...discovered.jsFiles);
|
|
188
|
+
if (prettierMarkers.size === discovered.jsFiles.length) {
|
|
187
189
|
for (const filePath of discovered.jsFiles) {
|
|
190
|
+
const marker = prettierMarkers.get(filePath)!;
|
|
188
191
|
const id = randomId();
|
|
189
192
|
localObjects.set(id, async (id: string) => {
|
|
190
193
|
const sourceFile: SourceFile = (await generator.next()).value;
|
|
191
|
-
// Add PrettierStyle marker if Prettier is available
|
|
192
|
-
const prettierMarker = await prettierLoader.getConfigMarker(filePath);
|
|
193
194
|
return {
|
|
194
195
|
...sourceFile,
|
|
195
196
|
id,
|
|
196
|
-
markers:
|
|
197
|
-
? replaceMarkerByKind(sourceFile.markers, prettierMarker)
|
|
198
|
-
: sourceFile.markers
|
|
197
|
+
markers: replaceMarkerByKind(sourceFile.markers, marker)
|
|
199
198
|
};
|
|
200
199
|
});
|
|
201
200
|
resultItems.push({
|
|
202
201
|
id,
|
|
203
|
-
sourceFileType: "org.openrewrite.javascript.tree.JS$CompilationUnit",
|
|
202
|
+
sourceFileType: "org.openrewrite.javascript.tree.JS$CompilationUnit",
|
|
204
203
|
sourcePath: path.relative(relativeTo, filePath)
|
|
205
204
|
});
|
|
206
205
|
}
|
|
207
206
|
} else {
|
|
208
|
-
// Prettier is NOT available: auto-detect styles from parsed files
|
|
209
|
-
// Parse all files first to sample them
|
|
210
207
|
const parsedFiles: {id: string, sourceFile: SourceFile, filePath: string}[] = [];
|
|
211
208
|
let fileIndex = 0;
|
|
212
|
-
for await (const sourceFile of
|
|
213
|
-
|
|
214
|
-
parsedFiles.push({id, sourceFile, filePath: discovered.jsFiles[fileIndex++]});
|
|
209
|
+
for await (const sourceFile of generator) {
|
|
210
|
+
parsedFiles.push({id: randomId(), sourceFile, filePath: discovered.jsFiles[fileIndex++]});
|
|
215
211
|
}
|
|
216
|
-
|
|
217
|
-
// Sample all parsed files and build Autodetect marker using ProjectParser helper
|
|
218
212
|
const autodetectMarker = await projectParser.buildAutodetectMarker(
|
|
219
|
-
parsedFiles.map(p => p.sourceFile)
|
|
213
|
+
parsedFiles.filter(p => !prettierMarkers.has(p.filePath)).map(p => p.sourceFile)
|
|
220
214
|
);
|
|
221
|
-
|
|
222
|
-
// Store thunks that add the Autodetect marker
|
|
223
215
|
for (const {id, sourceFile, filePath} of parsedFiles) {
|
|
224
|
-
localObjects.set(id, async (newId: string) => {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
};
|
|
230
|
-
});
|
|
216
|
+
localObjects.set(id, async (newId: string) => ({
|
|
217
|
+
...sourceFile,
|
|
218
|
+
id: newId,
|
|
219
|
+
markers: replaceMarkerByKind(sourceFile.markers, prettierMarkers.get(filePath) ?? autodetectMarker)
|
|
220
|
+
}));
|
|
231
221
|
resultItems.push({
|
|
232
222
|
id,
|
|
233
|
-
sourceFileType: "org.openrewrite.javascript.tree.JS$CompilationUnit",
|
|
223
|
+
sourceFileType: "org.openrewrite.javascript.tree.JS$CompilationUnit",
|
|
234
224
|
sourcePath: path.relative(relativeTo, filePath)
|
|
235
225
|
});
|
|
236
226
|
}
|