UNPKG

xo

Version:

JavaScript/TypeScript linter (ESLint wrapper) with great defaults

50 lines 2.11 kB
import path from 'node:path'; import process from 'node:process'; import { cosmiconfig, defaultLoaders } from 'cosmiconfig'; import arrify from 'arrify'; import { moduleName } from './constants.js'; /** Finds the XO config file. */ export async function resolveXoConfig(options) { try { options.cwd ||= process.cwd(); if (!path.isAbsolute(options.cwd)) { options.cwd = path.resolve(process.cwd(), options.cwd); } const stopDirectory = path.dirname(options.cwd); const flatConfigExplorer = cosmiconfig(moduleName, { searchPlaces: [ 'package.json', `${moduleName}.config.js`, `${moduleName}.config.mjs`, `${moduleName}.config.ts`, `${moduleName}.config.mts`, ], loaders: { '.mts': defaultLoaders['.ts'], // eslint-disable-line @typescript-eslint/naming-convention }, stopDir: stopDirectory, cache: true, }); options.filePath &&= path.resolve(options.cwd, options.filePath); const searchPath = options.filePath ?? options.cwd; let { config: flatOptions = [], filepath: flatConfigPath = '', // eslint-disable-line @typescript-eslint/no-useless-default-assignment } = await (options.configPath // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion ? flatConfigExplorer.load(path.resolve(options.cwd, options.configPath)) // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion : flatConfigExplorer.search(searchPath)) ?? {}; flatOptions = arrify(flatOptions); return { flatOptions, flatConfigPath, }; } catch (error) { // eslint-disable-next-line preserve-caught-error throw new AggregateError([error], 'Error resolving XO config, there is likely an issue with your config file. Please check the file for mistakes.'); } } export default resolveXoConfig; //# sourceMappingURL=resolve-config.js.map