diff --git a/changelog_unreleased/api/18375.md b/changelog_unreleased/api/18375.md new file mode 100644 index 000000000..0361c1b64 --- /dev/null +++ b/changelog_unreleased/api/18375.md @@ -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. diff --git a/src/cli/file-info.js b/src/cli/file-info.js index 95b387c4c..1b21bdfbc 100644 --- a/src/cli/file-info.js +++ b/src/cli/file-info.js @@ -16,7 +16,7 @@ async function logFileInfoOrDie(context) { const fileInfo = await getFileInfo(path.resolve(file), { ignorePath, withNodeModules, - plugins, + plugins: plugins.length > 0 ? plugins : undefined, resolveConfig: config !== false, }); diff --git a/src/common/get-file-info.js b/src/common/get-file-info.js index 92ae4f9e8..ce86cdb0a 100644 --- a/src/common/get-file-info.js +++ b/src/common/get-file-info.js @@ -1,5 +1,5 @@ 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 inferParser from "../utils/infer-parser.js"; @@ -54,10 +54,14 @@ async function getParser(file, options) { return config.parser; } - const plugins = [ - ...options.plugins, - ...(await loadPlugins(config?.plugins ?? [])), - ]; + let plugins = options.plugins ?? 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 }); } diff --git a/src/index.js b/src/index.js index 31c67a0da..8a8a7050b 100644 --- a/src/index.js +++ b/src/index.js @@ -11,7 +11,6 @@ import { closestMatch as closetLevenshteinMatch } from "leven"; import picocolors from "picocolors"; import * as vnopts from "vnopts"; import * as errors from "./common/errors.js"; -import getFileInfoWithoutPlugins from "./common/get-file-info.js"; import { mockable } from "./common/mockable.js"; import { clearCache as clearConfigCache, @@ -91,8 +90,6 @@ const inferParser = withPlugins((file, options) => inferParserWithoutPlugins(options, { physicalFile: file }), ); -const getFileInfo = withPlugins(getFileInfoWithoutPlugins); - // Internal shared with cli const sharedWithCli = { errors, @@ -135,11 +132,11 @@ export { clearCache as clearConfigCache, format, formatWithCursor, - getFileInfo, getSupportInfo, resolveConfig, resolveConfigFile, }; +export { default as getFileInfo } from "./common/get-file-info.js"; export * as doc from "./document/public.js"; export { default as version } from "./main/version.evaluate.js"; export * as util from "./utils/public.js";