UNPKG

sf-package-combiner

Version:

Combine multiple Salesforce manifest files (package.xml) into 1 file for deployments.

61 lines 2.45 kB
import { ComponentSet } from '@salesforce/source-deploy-retrieve'; import { mapLimit } from 'async'; import { getConcurrencyThreshold } from '../utils/getConcurrencyThreshold.js'; import { sfXmlns } from '../utils/constants.js'; import { determineApiVersion } from './determineApiVersion.js'; import { writePackage } from './writePackage.js'; export async function mergePackageXmlFiles(files, combinedPackage, userApiVersion, noApiVersion) { const warnings = []; const apiVersions = []; const concurrencyLimit = getConcurrencyThreshold(); const combinedSet = new ComponentSet(); if (files) { await mapLimit(files, concurrencyLimit, async (filePath) => { try { const componentSet = await ComponentSet.fromManifest({ manifestPath: filePath }); if (componentSet.size === 0) { warnings.push(`Invalid or empty package.xml: ${filePath}`); return; } for (const component of componentSet.toArray()) { combinedSet.add(component); } const version = componentSet.sourceApiVersion; if (version && !apiVersions.includes(version)) { apiVersions.push(version); } } catch { warnings.push(`Invalid or empty package.xml: ${filePath}`); } }); } const metadataTypes = groupComponentsByType(combinedSet.toArray()); const version = determineApiVersion(apiVersions, userApiVersion, noApiVersion); const packageContents = { Package: { '@_xmlns': sfXmlns, types: Array.from(metadataTypes.entries()) .map(([name, members]) => ({ members: Array.from(new Set(members)).sort((a, b) => a.localeCompare(b)), name, })) .sort((a, b) => a.name.localeCompare(b.name)), version, }, }; await writePackage(packageContents, combinedPackage); return warnings; } function groupComponentsByType(components) { const map = new Map(); for (const component of components) { const typeName = component.type.name; if (!map.has(typeName)) { map.set(typeName, []); } map.get(typeName).push(component.fullName); } return map; } //# sourceMappingURL=mergePackageXmlFiles.js.map