UNPKG

zephyr-xpack-internal

Version:

Xpack internals for Zephyr

44 lines (43 loc) • 2.4 kB
import "node:module"; function mergeWithoutDupe(source) { return source.reduce((acc, item)=>{ if ('object' == typeof item) { const isDupe = acc.find((existing)=>Object.entries(existing).every(([key, value])=>item[key] === value)); if (!isDupe) acc.push(item); } else acc.push(item); return acc; }, []); } function mergeGraphs(graph1, graph2) { graph1.devDependencies = mergeWithoutDupe([ ...graph2.devDependencies ?? [], ...graph1.devDependencies ?? [] ]); graph1.dependencies = mergeWithoutDupe([ ...graph2.dependencies ?? [], ...graph1.dependencies ?? [] ]); graph2.modules.forEach((hostModules)=>{ const existing = graph1.modules.find((sidecarModules)=>hostModules.id === sidecarModules.id && hostModules.name === sidecarModules.name && hostModules.file === sidecarModules.file && hostModules.applicationID === sidecarModules.applicationID); if (existing) existing.requires = Array.from(new Set([ ...existing.requires, ...hostModules.requires ])); else graph1.modules.push(hostModules); }); graph2.overrides.forEach((hostOverrides)=>{ const existing = graph1.overrides.find((sidecarOverrides)=>sidecarOverrides.id === hostOverrides.id && sidecarOverrides.name === hostOverrides.name && sidecarOverrides.version === hostOverrides.version && sidecarOverrides.location === hostOverrides.location && sidecarOverrides.applicationID === hostOverrides.applicationID); if (!existing) graph1.overrides.push(hostOverrides); }); graph2.consumes.forEach((hostConsumedModule)=>{ const existing = graph1.consumes.find((sidecarConsumedModule)=>sidecarConsumedModule.consumingApplicationID === hostConsumedModule.consumingApplicationID && sidecarConsumedModule.applicationID === hostConsumedModule.applicationID && sidecarConsumedModule.name === hostConsumedModule.name); if (existing) hostConsumedModule.usedIn.forEach((consumedModule)=>{ const alreadyExists = existing.usedIn.find(({ file, url })=>consumedModule.file === file && consumedModule.url === url); if (!alreadyExists) existing.usedIn.push(consumedModule); }); else graph1.consumes.push(hostConsumedModule); }); return graph1; } export { mergeGraphs }; //# sourceMappingURL=merge-graphs.mjs.map