@code-pushup/utils 0.47.0 → 0.48.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +111 -3
- package/package.json +2 -2
- package/src/index.d.ts +1 -0
- package/src/lib/merge-configs.d.ts +2 -0
package/index.js
CHANGED
|
@@ -1876,6 +1876,113 @@ function groupByStatus(results) {
|
|
|
1876
1876
|
);
|
|
1877
1877
|
}
|
|
1878
1878
|
|
|
1879
|
+
// packages/utils/src/lib/merge-configs.ts
|
|
1880
|
+
function mergeConfigs(config, ...configs) {
|
|
1881
|
+
return configs.reduce(
|
|
1882
|
+
(acc, obj) => ({
|
|
1883
|
+
...acc,
|
|
1884
|
+
...mergeCategories(acc.categories, obj.categories),
|
|
1885
|
+
...mergePlugins(acc.plugins, obj.plugins),
|
|
1886
|
+
...mergePersist(acc.persist, obj.persist),
|
|
1887
|
+
...mergeUpload(acc.upload, obj.upload)
|
|
1888
|
+
}),
|
|
1889
|
+
config
|
|
1890
|
+
);
|
|
1891
|
+
}
|
|
1892
|
+
function mergeCategories(a, b) {
|
|
1893
|
+
if (!a && !b) {
|
|
1894
|
+
return {};
|
|
1895
|
+
}
|
|
1896
|
+
const mergedMap = /* @__PURE__ */ new Map();
|
|
1897
|
+
const addToMap = (categories) => {
|
|
1898
|
+
categories.forEach((newObject) => {
|
|
1899
|
+
if (mergedMap.has(newObject.slug)) {
|
|
1900
|
+
const existingObject = mergedMap.get(
|
|
1901
|
+
newObject.slug
|
|
1902
|
+
);
|
|
1903
|
+
mergedMap.set(newObject.slug, {
|
|
1904
|
+
...existingObject,
|
|
1905
|
+
...newObject,
|
|
1906
|
+
refs: mergeByUniqueCategoryRefCombination(
|
|
1907
|
+
existingObject?.refs,
|
|
1908
|
+
newObject.refs
|
|
1909
|
+
)
|
|
1910
|
+
});
|
|
1911
|
+
} else {
|
|
1912
|
+
mergedMap.set(newObject.slug, newObject);
|
|
1913
|
+
}
|
|
1914
|
+
});
|
|
1915
|
+
};
|
|
1916
|
+
if (a) {
|
|
1917
|
+
addToMap(a);
|
|
1918
|
+
}
|
|
1919
|
+
if (b) {
|
|
1920
|
+
addToMap(b);
|
|
1921
|
+
}
|
|
1922
|
+
return { categories: [...mergedMap.values()] };
|
|
1923
|
+
}
|
|
1924
|
+
function mergePlugins(a, b) {
|
|
1925
|
+
if (!a && !b) {
|
|
1926
|
+
return { plugins: [] };
|
|
1927
|
+
}
|
|
1928
|
+
const mergedMap = /* @__PURE__ */ new Map();
|
|
1929
|
+
const addToMap = (plugins) => {
|
|
1930
|
+
plugins.forEach((newObject) => {
|
|
1931
|
+
mergedMap.set(newObject.slug, newObject);
|
|
1932
|
+
});
|
|
1933
|
+
};
|
|
1934
|
+
if (a) {
|
|
1935
|
+
addToMap(a);
|
|
1936
|
+
}
|
|
1937
|
+
if (b) {
|
|
1938
|
+
addToMap(b);
|
|
1939
|
+
}
|
|
1940
|
+
return { plugins: [...mergedMap.values()] };
|
|
1941
|
+
}
|
|
1942
|
+
function mergePersist(a, b) {
|
|
1943
|
+
if (!a && !b) {
|
|
1944
|
+
return {};
|
|
1945
|
+
}
|
|
1946
|
+
if (a) {
|
|
1947
|
+
return b ? { persist: { ...a, ...b } } : {};
|
|
1948
|
+
} else {
|
|
1949
|
+
return { persist: b };
|
|
1950
|
+
}
|
|
1951
|
+
}
|
|
1952
|
+
function mergeByUniqueCategoryRefCombination(a, b) {
|
|
1953
|
+
const map = /* @__PURE__ */ new Map();
|
|
1954
|
+
const addToMap = (refs) => {
|
|
1955
|
+
refs.forEach((ref) => {
|
|
1956
|
+
const uniqueIdentification = `${ref.type}:${ref.plugin}:${ref.slug}`;
|
|
1957
|
+
if (map.has(uniqueIdentification)) {
|
|
1958
|
+
map.set(uniqueIdentification, {
|
|
1959
|
+
...map.get(uniqueIdentification),
|
|
1960
|
+
...ref
|
|
1961
|
+
});
|
|
1962
|
+
} else {
|
|
1963
|
+
map.set(uniqueIdentification, ref);
|
|
1964
|
+
}
|
|
1965
|
+
});
|
|
1966
|
+
};
|
|
1967
|
+
if (a) {
|
|
1968
|
+
addToMap(a);
|
|
1969
|
+
}
|
|
1970
|
+
if (b) {
|
|
1971
|
+
addToMap(b);
|
|
1972
|
+
}
|
|
1973
|
+
return [...map.values()];
|
|
1974
|
+
}
|
|
1975
|
+
function mergeUpload(a, b) {
|
|
1976
|
+
if (!a && !b) {
|
|
1977
|
+
return {};
|
|
1978
|
+
}
|
|
1979
|
+
if (a) {
|
|
1980
|
+
return b ? { upload: { ...a, ...b } } : {};
|
|
1981
|
+
} else {
|
|
1982
|
+
return { upload: b };
|
|
1983
|
+
}
|
|
1984
|
+
}
|
|
1985
|
+
|
|
1879
1986
|
// packages/utils/src/lib/progress.ts
|
|
1880
1987
|
import chalk3 from "chalk";
|
|
1881
1988
|
import { MultiProgressBars } from "multi-progress-bars";
|
|
@@ -2281,8 +2388,8 @@ function formatDiffCategoriesSection(diff) {
|
|
|
2281
2388
|
}
|
|
2282
2389
|
const columns = [
|
|
2283
2390
|
{ key: "category", label: "\u{1F3F7}\uFE0F Category", align: "left" },
|
|
2284
|
-
{ key: "before", label: "\u2B50 Previous score" },
|
|
2285
|
-
{ key: "after", label:
|
|
2391
|
+
{ key: "before", label: hasChanges ? "\u2B50 Previous score" : "\u2B50 Score" },
|
|
2392
|
+
{ key: "after", label: "\u2B50 Current score" },
|
|
2286
2393
|
{ key: "change", label: "\u{1F504} Score change" }
|
|
2287
2394
|
];
|
|
2288
2395
|
return lines5(
|
|
@@ -2311,7 +2418,7 @@ function formatDiffCategoriesSection(diff) {
|
|
|
2311
2418
|
change: "\u2013"
|
|
2312
2419
|
}))
|
|
2313
2420
|
].map(
|
|
2314
|
-
(row) => hasChanges ? row : { category: row.category,
|
|
2421
|
+
(row) => hasChanges ? row : { category: row.category, before: row.before }
|
|
2315
2422
|
)
|
|
2316
2423
|
}),
|
|
2317
2424
|
added.length > 0 && section5(italicMd("(\\*) New category."))
|
|
@@ -2772,6 +2879,7 @@ export {
|
|
|
2772
2879
|
logStdoutSummary,
|
|
2773
2880
|
matchArrayItemsByKey,
|
|
2774
2881
|
md,
|
|
2882
|
+
mergeConfigs,
|
|
2775
2883
|
normalizeSemver,
|
|
2776
2884
|
objectFromEntries,
|
|
2777
2885
|
objectToCliArgs,
|
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export { groupByStatus } from './lib/group-by-status';
|
|
|
10
10
|
export { isPromiseFulfilledResult, isPromiseRejectedResult, } from './lib/guards';
|
|
11
11
|
export { logMultipleResults } from './lib/log-results';
|
|
12
12
|
export { CliUi, Column, link, ui } from './lib/logging';
|
|
13
|
+
export { mergeConfigs } from './lib/merge-configs';
|
|
13
14
|
export { ProgressBar, getProgressBar } from './lib/progress';
|
|
14
15
|
export { CODE_PUSHUP_DOMAIN, FOOTER_PREFIX, README_LINK, TERMINAL_WIDTH, } from './lib/reports/constants';
|
|
15
16
|
export { listAuditsFromAllPlugins, listGroupsFromAllPlugins, } from './lib/reports/flatten-plugins';
|