From 96e812066784eddcd4960ec039aa9bbc11dcd80f Mon Sep 17 00:00:00 2001 From: Georgii Dolzhykov Date: Sun, 3 Dec 2023 10:02:39 +0200 Subject: [PATCH] `prettier.__internal.inferParser` for new CLI (#15745) * prettier.__internal.inferParser for new CLI * Don't resolve plugins if parser found in options --- src/index.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/index.js b/src/index.js index d64500e69..31f1eac17 100644 --- a/src/index.js +++ b/src/index.js @@ -6,6 +6,7 @@ import { getSupportInfo as getSupportInfoWithoutPlugins, normalizeOptionSettings, } from "./main/support.js"; +import inferParserWithoutPlugins from "./utils/infer-parser.js"; import getFileInfoWithoutPlugins from "./common/get-file-info.js"; import { loadBuiltinPlugins, @@ -80,6 +81,10 @@ const getFileInfo = withPlugins(getFileInfoWithoutPlugins); /** @type {typeof getSupportInfoWithoutPlugins} */ const getSupportInfo = withPlugins(getSupportInfoWithoutPlugins, 0); +const inferParser = withPlugins((file, options) => + inferParserWithoutPlugins(options, { physicalFile: file }), +); + // Internal shared with cli const sharedWithCli = { errors, @@ -89,6 +94,8 @@ const sharedWithCli = { normalizeOptions, getSupportInfoWithoutPlugins, normalizeOptionSettings, + inferParser: (file, options) => + Promise.resolve(options?.parser ?? inferParser(file, options)), vnopts: { ChoiceSchema: vnopts.ChoiceSchema, apiDescriptor: vnopts.apiDescriptor,