@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.
- 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/json/index.d.ts +1 -0
- package/dist/json/index.d.ts.map +1 -1
- package/dist/json/index.js +1 -0
- package/dist/json/index.js.map +1 -1
- package/dist/json/path-matcher.d.ts +29 -0
- package/dist/json/path-matcher.d.ts.map +1 -0
- package/dist/json/path-matcher.js +974 -0
- package/dist/json/path-matcher.js.map +1 -0
- 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/json/index.ts +1 -0
- package/src/json/path-matcher.ts +1092 -0
- package/src/rpc/request/parse-project.ts +22 -32
|
@@ -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
|
}
|