UNPKG

pncat

Version:

Enhanced pnpm catalogs management with advanced workspace dependency control.

46 lines (42 loc) 1.55 kB
import { D as DEFAULT_CATALOG_RULES, t as toArray } from './shared/pncat.DZVqskSj.mjs'; export { P as PnpmCatalogManager, i as inferCatalogName } from './shared/pncat.DZVqskSj.mjs'; import deepmerge from 'deepmerge'; import 'node:process'; import 'pathe'; import 'pkg-types'; import 'node:fs'; import 'find-up'; import 'tinyglobby'; import 'semver'; import 'node:fs/promises'; import 'pnpm-workspace-yaml'; function mergeCatalogRules(...args) { const hasOptions = typeof args[0] === "object" && !Array.isArray(args[0]); const options = hasOptions ? args[0] : { mergeDefaults: true }; const rules = hasOptions ? args.slice(1) : args; const { mergeDefaults = true, arrayMerge = mergeByName } = options; const sources = mergeDefaults ? [structuredClone(DEFAULT_CATALOG_RULES), ...rules] : [...rules]; return sources.length === 0 ? [] : sortCatalogRules(deepmerge.all(sources, { arrayMerge })); } function mergeByName(target, source) { return source.reduce((result, item) => { const existing = result.find((x) => x.name === item.name); if (existing) { existing.match = toArray(existing.match); item.match = toArray(item.match); Object.assign(existing, deepmerge(existing, item)); } else { result.push(item); } return result; }, [...target]); } function sortCatalogRules(rules) { return rules.sort( (a, b) => (a.priority ?? Infinity) - (b.priority ?? Infinity) ); } function defineConfig(config) { return config; } export { DEFAULT_CATALOG_RULES, defineConfig, mergeCatalogRules };