Revert previous change to getFileInfo (#18375)

This commit is contained in:
fisker Cheung authored and GitHub committed 2025-11-30 01:41:34 +08:00
1 parent f4a7afaebf
commit 27d6c645ca
4 files changed
+14 -10

No files matched your search

+3
View File
@@ -0,0 +1,3 @@
#### Fix `prettier.getFileInfo()` change that breaks VSCode extension (#18375 by @fisker)
An internal refactor accidentally broke the VSCode extension plugin loading.
+1 -1
View File
@@ -16,7 +16,7 @@ async function logFileInfoOrDie(context) {
const fileInfo = await getFileInfo(path.resolve(file), { const fileInfo = await getFileInfo(path.resolve(file), {
ignorePath, ignorePath,
withNodeModules, withNodeModules,
plugins, plugins: plugins.length > 0 ? plugins : undefined,
resolveConfig: config !== false, resolveConfig: config !== false,
}); });
+9 -5
View File
@@ -1,5 +1,5 @@
import { resolveConfig } from "../config/resolve-config.js"; import { resolveConfig } from "../config/resolve-config.js";
import { loadPlugins } from "../main/plugins/index.js"; import { loadBuiltinPlugins, loadPlugins } from "../main/plugins/index.js";
import { isIgnored } from "../utils/ignore.js"; import { isIgnored } from "../utils/ignore.js";
import inferParser from "../utils/infer-parser.js"; import inferParser from "../utils/infer-parser.js";
@@ -54,10 +54,14 @@ async function getParser(file, options) {
return config.parser; return config.parser;
} }
const plugins = [ let plugins = options.plugins ?? config?.plugins ?? [];
...options.plugins,
...(await loadPlugins(config?.plugins ?? [])), // We should wrap this funciton with `withPlugins` and use `options.plugins` directly instead of loading plugins here
]; // See #18375 #18081
// But somehow it breaks VSCode extension, see #18353
plugins = (
await Promise.all([loadBuiltinPlugins(), loadPlugins(plugins)])
).flat();
return inferParser({ plugins }, { physicalFile: file }); return inferParser({ plugins }, { physicalFile: file });
} }
+1 -4
View File
@@ -11,7 +11,6 @@ import { closestMatch as closetLevenshteinMatch } from "leven";
import picocolors from "picocolors"; import picocolors from "picocolors";
import * as vnopts from "vnopts"; import * as vnopts from "vnopts";
import * as errors from "./common/errors.js"; import * as errors from "./common/errors.js";
import getFileInfoWithoutPlugins from "./common/get-file-info.js";
import { mockable } from "./common/mockable.js"; import { mockable } from "./common/mockable.js";
import { import {
clearCache as clearConfigCache, clearCache as clearConfigCache,
@@ -91,8 +90,6 @@ const inferParser = withPlugins((file, options) =>
inferParserWithoutPlugins(options, { physicalFile: file }), inferParserWithoutPlugins(options, { physicalFile: file }),
); );
const getFileInfo = withPlugins(getFileInfoWithoutPlugins);
// Internal shared with cli // Internal shared with cli
const sharedWithCli = { const sharedWithCli = {
errors, errors,
@@ -135,11 +132,11 @@ export {
clearCache as clearConfigCache, clearCache as clearConfigCache,
format, format,
formatWithCursor, formatWithCursor,
getFileInfo,
getSupportInfo, getSupportInfo,
resolveConfig, resolveConfig,
resolveConfigFile, resolveConfigFile,
}; };
export { default as getFileInfo } from "./common/get-file-info.js";
export * as doc from "./document/public.js"; export * as doc from "./document/public.js";
export { default as version } from "./main/version.evaluate.js"; export { default as version } from "./main/version.evaluate.js";
export * as util from "./utils/public.js"; export * as util from "./utils/public.js";