UNPKG

semantic-release-yarn

Version:

semantic-release plugin to publish a npm package with yarn

35 lines (34 loc) 1.3 kB
import { cosmiconfig } from "cosmiconfig"; import _ from "lodash"; import { dirname, resolve } from "node:path"; import { YARNRC_FILENAME } from "./definitions/constants.js"; export async function getYarnConfig({ cwd, logger, }) { const result = await cosmiconfigSearchRecursive(cosmiconfig("yarn", { searchPlaces: [YARNRC_FILENAME], }), cwd); if (!result) { return {}; } logger.log('Reading yarn config from "%s"', result.files.join(", ")); return result.config; } // https://github.com/chrisblossom/cosmiconfig-all-example/blob/master/src/cosmiconfig-all-example.js async function cosmiconfigSearchRecursive(explorer, searchFrom) { let config = {}; const files = []; async function getNext(currentPath) { const currentResult = await explorer.search(currentPath); // If no result found, end search if (!currentResult) { return; } // Merge current results files.push(currentResult.filepath); config = _.merge({}, currentResult.config, config); // Get the next parent directory const nextPath = resolve(dirname(currentResult.filepath), "../"); return getNext(nextPath); } await getNext(searchFrom); return files.length ? { config, files } : null; }