Skip to content

Commit 27d6c64

Browse files
authored
Revert previous change to getFileInfo (#18375)
1 parent f4a7afa commit 27d6c64

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

changelog_unreleased/api/18375.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#### Fix `prettier.getFileInfo()` change that breaks VSCode extension (#18375 by @fisker)
2+
3+
An internal refactor accidentally broke the VSCode extension plugin loading.

src/cli/file-info.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ async function logFileInfoOrDie(context) {
1616
const fileInfo = await getFileInfo(path.resolve(file), {
1717
ignorePath,
1818
withNodeModules,
19-
plugins,
19+
plugins: plugins.length > 0 ? plugins : undefined,
2020
resolveConfig: config !== false,
2121
});
2222

src/common/get-file-info.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { resolveConfig } from "../config/resolve-config.js";
2-
import { loadPlugins } from "../main/plugins/index.js";
2+
import { loadBuiltinPlugins, loadPlugins } from "../main/plugins/index.js";
33
import { isIgnored } from "../utils/ignore.js";
44
import inferParser from "../utils/infer-parser.js";
55

@@ -54,10 +54,14 @@ async function getParser(file, options) {
5454
return config.parser;
5555
}
5656

57-
const plugins = [
58-
...options.plugins,
59-
...(await loadPlugins(config?.plugins ?? [])),
60-
];
57+
let plugins = options.plugins ?? config?.plugins ?? [];
58+
59+
// We should wrap this funciton with `withPlugins` and use `options.plugins` directly instead of loading plugins here
60+
// See #18375 #18081
61+
// But somehow it breaks VSCode extension, see #18353
62+
plugins = (
63+
await Promise.all([loadBuiltinPlugins(), loadPlugins(plugins)])
64+
).flat();
6165

6266
return inferParser({ plugins }, { physicalFile: file });
6367
}

src/index.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { closestMatch as closetLevenshteinMatch } from "leven";
1111
import picocolors from "picocolors";
1212
import * as vnopts from "vnopts";
1313
import * as errors from "./common/errors.js";
14-
import getFileInfoWithoutPlugins from "./common/get-file-info.js";
1514
import { mockable } from "./common/mockable.js";
1615
import {
1716
clearCache as clearConfigCache,
@@ -91,8 +90,6 @@ const inferParser = withPlugins((file, options) =>
9190
inferParserWithoutPlugins(options, { physicalFile: file }),
9291
);
9392

94-
const getFileInfo = withPlugins(getFileInfoWithoutPlugins);
95-
9693
// Internal shared with cli
9794
const sharedWithCli = {
9895
errors,
@@ -135,11 +132,11 @@ export {
135132
clearCache as clearConfigCache,
136133
format,
137134
formatWithCursor,
138-
getFileInfo,
139135
getSupportInfo,
140136
resolveConfig,
141137
resolveConfigFile,
142138
};
139+
export { default as getFileInfo } from "./common/get-file-info.js";
143140
export * as doc from "./document/public.js";
144141
export { default as version } from "./main/version.evaluate.js";
145142
export * as util from "./utils/public.js";

0 commit comments

Comments
 (0)