{"version":3,"file":"detectFormatCommand.mjs","names":[],"sources":["../../src/detectFormatCommand.ts"],"sourcesContent":["import { getProjectRequire } from '@intlayer/config/utils';\nimport type { IntlayerConfig } from '@intlayer/types/config';\n\nlet cachedFormatCommand: string | undefined | null = null;\n\nexport const detectFormatCommand = (\n  configuration: IntlayerConfig,\n  projectRequireProp?: NodeJS.Require\n) => {\n  const { baseDir } = configuration.system;\n  const { formatCommand } = configuration.content;\n  const projectRequire = projectRequireProp ?? getProjectRequire(baseDir);\n\n  // Priority: Explicit configuration\n  // We do not cache this because the user might change their config file active-session.\n  if (formatCommand) {\n    return formatCommand;\n  }\n\n  // Priority: Cached detection\n  // If not null, we have already performed the expensive checks.\n  if (cachedFormatCommand !== null) {\n    return cachedFormatCommand;\n  }\n\n  // Perform Detection\n\n  // Try Prettier\n  try {\n    projectRequire.resolve('prettier');\n    cachedFormatCommand = 'prettier --write \"{{file}}\" --log-level silent';\n    return cachedFormatCommand;\n  } catch (_error) {\n    // Prettier not found, continue\n  }\n\n  // Try Biome\n  try {\n    projectRequire.resolve('biome');\n    cachedFormatCommand = 'biome format \"{{file}}\" --write --log-level none';\n    return cachedFormatCommand;\n  } catch (_error) {\n    // Biome not found, continue\n  }\n\n  // Try ESLint\n  try {\n    projectRequire.resolve('eslint');\n    cachedFormatCommand =\n      'eslint --fix \"{{file}}\" --quiet || node -e \"process.exit(0)\"';\n    return cachedFormatCommand;\n  } catch (_error) {\n    // ESLint not found\n  }\n\n  // No formatter found\n  // Set to undefined (not null) so we know we checked and found nothing.\n  cachedFormatCommand = undefined;\n  return undefined;\n};\n"],"mappings":";;;AAGA,IAAI,sBAAiD;AAErD,MAAa,uBACX,eACA,uBACG;CACH,MAAM,EAAE,YAAY,cAAc;CAClC,MAAM,EAAE,kBAAkB,cAAc;CACxC,MAAM,iBAAiB,sBAAsB,kBAAkB,QAAQ;AAIvE,KAAI,cACF,QAAO;AAKT,KAAI,wBAAwB,KAC1B,QAAO;AAMT,KAAI;AACF,iBAAe,QAAQ,WAAW;AAClC,wBAAsB;AACtB,SAAO;UACA,QAAQ;AAKjB,KAAI;AACF,iBAAe,QAAQ,QAAQ;AAC/B,wBAAsB;AACtB,SAAO;UACA,QAAQ;AAKjB,KAAI;AACF,iBAAe,QAAQ,SAAS;AAChC,wBACE;AACF,SAAO;UACA,QAAQ;AAMjB,uBAAsB"}