@amaster.ai/cli 1.1.54 → 1.1.55
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/README.md +4 -0
- package/dist/cli.cjs +455 -19
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +455 -19
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1167,6 +1167,10 @@ function toImportSpecifier(targetPath) {
|
|
|
1167
1167
|
function toAssetImportSpecifier(targetPath) {
|
|
1168
1168
|
return targetPath.replace(/\\/g, "/").replace(/^src\//, "@/");
|
|
1169
1169
|
}
|
|
1170
|
+
function resolveComponentImportSpecifier(member) {
|
|
1171
|
+
const entryPath = member.targetPaths.find((targetPath) => /\/index\.[cm]?[jt]sx?$/.test(targetPath));
|
|
1172
|
+
return entryPath ? toImportSpecifier(entryPath) : member.targetPaths[0] ? toImportSpecifier(member.targetPaths[0]) : "";
|
|
1173
|
+
}
|
|
1170
1174
|
function resolveInstalledAddonDisplay(meta) {
|
|
1171
1175
|
const legacyMeta = meta;
|
|
1172
1176
|
return {
|
|
@@ -1194,7 +1198,7 @@ function buildAddonLlmGuidance(input) {
|
|
|
1194
1198
|
}));
|
|
1195
1199
|
const components = componentMembers.map((member) => ({
|
|
1196
1200
|
name: member.name,
|
|
1197
|
-
importFrom:
|
|
1201
|
+
importFrom: resolveComponentImportSpecifier(member)
|
|
1198
1202
|
}));
|
|
1199
1203
|
const functions = functionMembers.map((member) => ({
|
|
1200
1204
|
name: member.name,
|
|
@@ -1556,7 +1560,7 @@ async function buildInstallPlan(options) {
|
|
|
1556
1560
|
memberName: "install-requirements",
|
|
1557
1561
|
memberType: "settings",
|
|
1558
1562
|
patch: requirementsSettingsPatch,
|
|
1559
|
-
paths: flattenSettingsPatch(requirementsSettingsPatch)
|
|
1563
|
+
paths: flattenSettingsPatch(requirementsSettingsPatch, [], { sharedRequirement: true })
|
|
1560
1564
|
});
|
|
1561
1565
|
members.push({
|
|
1562
1566
|
name: "install-requirements",
|
|
@@ -1651,18 +1655,21 @@ async function readYamlObject(filePath) {
|
|
|
1651
1655
|
}
|
|
1652
1656
|
return parsed;
|
|
1653
1657
|
}
|
|
1654
|
-
function flattenSettingsPatch(value, prefix = []) {
|
|
1658
|
+
function flattenSettingsPatch(value, prefix = [], options = {}) {
|
|
1655
1659
|
const paths = [];
|
|
1656
1660
|
for (const [key, child] of Object.entries(value)) {
|
|
1657
1661
|
const segments = prefix.concat(key);
|
|
1658
1662
|
if (isPlainObject(child)) {
|
|
1659
|
-
paths.push(...flattenSettingsPatch(child, segments));
|
|
1663
|
+
paths.push(...flattenSettingsPatch(child, segments, options));
|
|
1660
1664
|
continue;
|
|
1661
1665
|
}
|
|
1666
|
+
const path = segments.join(".");
|
|
1667
|
+
const merge = options.sharedRequirement ? { mergeStrategy: "shared-requirement" } : path === "rbac.permissions" && Array.isArray(child) ? { mergeStrategy: "append-unique" } : path === "rbac.roles" && Array.isArray(child) ? { mergeStrategy: "merge-by-key", mergeKey: "code" } : {};
|
|
1662
1668
|
paths.push({
|
|
1663
|
-
path
|
|
1669
|
+
path,
|
|
1664
1670
|
segments,
|
|
1665
|
-
value: child
|
|
1671
|
+
value: child,
|
|
1672
|
+
...merge
|
|
1666
1673
|
});
|
|
1667
1674
|
}
|
|
1668
1675
|
return paths;
|
|
@@ -1679,6 +1686,9 @@ function buildSettingsOwnershipMap(metas, excludeAddonName) {
|
|
|
1679
1686
|
}
|
|
1680
1687
|
for (const member of meta.members) {
|
|
1681
1688
|
for (const item of member.settings?.paths ?? []) {
|
|
1689
|
+
if (item.mergeStrategy) {
|
|
1690
|
+
continue;
|
|
1691
|
+
}
|
|
1682
1692
|
ownership.set(`${item.targetPath}#${item.path}`, meta.name);
|
|
1683
1693
|
}
|
|
1684
1694
|
}
|
|
@@ -1693,7 +1703,9 @@ function listPlannedSettingPaths(settings) {
|
|
|
1693
1703
|
targetPath: item.targetPath,
|
|
1694
1704
|
path: settingPath.path,
|
|
1695
1705
|
segments: settingPath.segments,
|
|
1696
|
-
value: settingPath.value
|
|
1706
|
+
value: settingPath.value,
|
|
1707
|
+
mergeStrategy: settingPath.mergeStrategy,
|
|
1708
|
+
mergeKey: settingPath.mergeKey
|
|
1697
1709
|
}))
|
|
1698
1710
|
);
|
|
1699
1711
|
}
|
|
@@ -1704,6 +1716,226 @@ function getPlainYamlValue(document, segments) {
|
|
|
1704
1716
|
}
|
|
1705
1717
|
return value;
|
|
1706
1718
|
}
|
|
1719
|
+
function cloneSettingsValue(value) {
|
|
1720
|
+
if (Array.isArray(value)) {
|
|
1721
|
+
return value.map((item) => cloneSettingsValue(item));
|
|
1722
|
+
}
|
|
1723
|
+
if (isPlainObject(value)) {
|
|
1724
|
+
return Object.fromEntries(Object.entries(value).map(([key, child]) => [key, cloneSettingsValue(child)]));
|
|
1725
|
+
}
|
|
1726
|
+
return value;
|
|
1727
|
+
}
|
|
1728
|
+
function settingsValuesEqual(left, right) {
|
|
1729
|
+
return stableJsonStringify(left) === stableJsonStringify(right);
|
|
1730
|
+
}
|
|
1731
|
+
function isComposableSettingsPath(path) {
|
|
1732
|
+
return path === "rbac.permissions" || path === "rbac.roles" || path.startsWith("envMetadata.");
|
|
1733
|
+
}
|
|
1734
|
+
function mergeNestedSettingsObject(existing, incoming) {
|
|
1735
|
+
const merged = cloneSettingsValue(existing);
|
|
1736
|
+
for (const [key, value] of Object.entries(incoming)) {
|
|
1737
|
+
const current = merged[key];
|
|
1738
|
+
merged[key] = isPlainObject(current) && isPlainObject(value) ? mergeNestedSettingsObject(current, value) : cloneSettingsValue(value);
|
|
1739
|
+
}
|
|
1740
|
+
return merged;
|
|
1741
|
+
}
|
|
1742
|
+
function mergeArrayByKey(current, incoming, mergeKey) {
|
|
1743
|
+
if (!Array.isArray(incoming)) {
|
|
1744
|
+
throw new Error(`merge-by-key setting requires an array value`);
|
|
1745
|
+
}
|
|
1746
|
+
const merged = Array.isArray(current) ? current.map((item) => cloneSettingsValue(item)) : [];
|
|
1747
|
+
const indexes = /* @__PURE__ */ new Map();
|
|
1748
|
+
for (const [index, item] of merged.entries()) {
|
|
1749
|
+
if (isPlainObject(item) && item[mergeKey] !== void 0) {
|
|
1750
|
+
indexes.set(item[mergeKey], index);
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
for (const item of incoming) {
|
|
1754
|
+
if (!isPlainObject(item) || item[mergeKey] === void 0) {
|
|
1755
|
+
throw new Error(`merge-by-key setting item must contain ${mergeKey}`);
|
|
1756
|
+
}
|
|
1757
|
+
const index = indexes.get(item[mergeKey]);
|
|
1758
|
+
if (index === void 0) {
|
|
1759
|
+
indexes.set(item[mergeKey], merged.length);
|
|
1760
|
+
merged.push(cloneSettingsValue(item));
|
|
1761
|
+
continue;
|
|
1762
|
+
}
|
|
1763
|
+
const existing = merged[index];
|
|
1764
|
+
if (!isPlainObject(existing)) {
|
|
1765
|
+
throw new Error(`merge-by-key setting contains a non-object item for ${String(item[mergeKey])}`);
|
|
1766
|
+
}
|
|
1767
|
+
const next = cloneSettingsValue(existing);
|
|
1768
|
+
for (const [field, value] of Object.entries(item)) {
|
|
1769
|
+
if (field === mergeKey) {
|
|
1770
|
+
continue;
|
|
1771
|
+
}
|
|
1772
|
+
const currentValue = next[field];
|
|
1773
|
+
if (isPlainObject(currentValue) && isPlainObject(value)) {
|
|
1774
|
+
next[field] = mergeNestedSettingsObject(currentValue, value);
|
|
1775
|
+
} else if (currentValue === void 0) {
|
|
1776
|
+
next[field] = cloneSettingsValue(value);
|
|
1777
|
+
}
|
|
1778
|
+
}
|
|
1779
|
+
merged[index] = next;
|
|
1780
|
+
}
|
|
1781
|
+
return merged;
|
|
1782
|
+
}
|
|
1783
|
+
function mergePlannedSettingValue(current, settingPath) {
|
|
1784
|
+
switch (settingPath.mergeStrategy) {
|
|
1785
|
+
case "append-unique": {
|
|
1786
|
+
if (!Array.isArray(settingPath.value)) {
|
|
1787
|
+
throw new Error(`append-unique setting requires an array value`);
|
|
1788
|
+
}
|
|
1789
|
+
const merged = Array.isArray(current) ? current.map((item) => cloneSettingsValue(item)) : [];
|
|
1790
|
+
for (const item of settingPath.value) {
|
|
1791
|
+
if (!merged.some((existing) => settingsValuesEqual(existing, item))) {
|
|
1792
|
+
merged.push(cloneSettingsValue(item));
|
|
1793
|
+
}
|
|
1794
|
+
}
|
|
1795
|
+
return merged;
|
|
1796
|
+
}
|
|
1797
|
+
case "merge-by-key":
|
|
1798
|
+
return mergeArrayByKey(current, settingPath.value, settingPath.mergeKey ?? "code");
|
|
1799
|
+
case "shared-requirement": {
|
|
1800
|
+
if (current === void 0) {
|
|
1801
|
+
return cloneSettingsValue(settingPath.value);
|
|
1802
|
+
}
|
|
1803
|
+
if (settingPath.segments.at(-1) === "required") {
|
|
1804
|
+
return Boolean(current) || Boolean(settingPath.value);
|
|
1805
|
+
}
|
|
1806
|
+
return current;
|
|
1807
|
+
}
|
|
1808
|
+
default:
|
|
1809
|
+
return cloneSettingsValue(settingPath.value);
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
function settingsValueContains(current, expected) {
|
|
1813
|
+
if (Array.isArray(expected)) {
|
|
1814
|
+
return Array.isArray(current) && expected.every(
|
|
1815
|
+
(item) => current.some((candidate) => settingsValueContains(candidate, item))
|
|
1816
|
+
);
|
|
1817
|
+
}
|
|
1818
|
+
if (isPlainObject(expected)) {
|
|
1819
|
+
return isPlainObject(current) && Object.entries(expected).every(
|
|
1820
|
+
([key, value]) => key in current && settingsValueContains(current[key], value)
|
|
1821
|
+
);
|
|
1822
|
+
}
|
|
1823
|
+
return settingsValuesEqual(current, expected);
|
|
1824
|
+
}
|
|
1825
|
+
function keyedArrayContributionPresent(current, contribution, previousValue, mergeKey) {
|
|
1826
|
+
if (!Array.isArray(current) || !Array.isArray(contribution)) {
|
|
1827
|
+
return false;
|
|
1828
|
+
}
|
|
1829
|
+
const previous = Array.isArray(previousValue) ? previousValue : [];
|
|
1830
|
+
for (const contributedItem of contribution) {
|
|
1831
|
+
if (!isPlainObject(contributedItem) || contributedItem[mergeKey] === void 0) {
|
|
1832
|
+
return false;
|
|
1833
|
+
}
|
|
1834
|
+
const currentItem = current.find(
|
|
1835
|
+
(item) => isPlainObject(item) && settingsValuesEqual(item[mergeKey], contributedItem[mergeKey])
|
|
1836
|
+
);
|
|
1837
|
+
if (!isPlainObject(currentItem)) {
|
|
1838
|
+
return false;
|
|
1839
|
+
}
|
|
1840
|
+
const previousItem = previous.find(
|
|
1841
|
+
(item) => isPlainObject(item) && settingsValuesEqual(item[mergeKey], contributedItem[mergeKey])
|
|
1842
|
+
);
|
|
1843
|
+
if (!isPlainObject(previousItem)) {
|
|
1844
|
+
if (!settingsValueContains(currentItem, contributedItem)) {
|
|
1845
|
+
return false;
|
|
1846
|
+
}
|
|
1847
|
+
continue;
|
|
1848
|
+
}
|
|
1849
|
+
for (const [field, value] of Object.entries(contributedItem)) {
|
|
1850
|
+
if (field === mergeKey) {
|
|
1851
|
+
continue;
|
|
1852
|
+
}
|
|
1853
|
+
if (isPlainObject(value)) {
|
|
1854
|
+
if (!settingsValueContains(currentItem[field], value)) {
|
|
1855
|
+
return false;
|
|
1856
|
+
}
|
|
1857
|
+
} else if (!(field in previousItem) && !settingsValuesEqual(currentItem[field], value)) {
|
|
1858
|
+
return false;
|
|
1859
|
+
}
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
return true;
|
|
1863
|
+
}
|
|
1864
|
+
function managedSettingContributionPresent(current, settingPath) {
|
|
1865
|
+
switch (settingPath.mergeStrategy) {
|
|
1866
|
+
case "append-unique":
|
|
1867
|
+
return settingsValueContains(current, settingPath.managedValue);
|
|
1868
|
+
case "merge-by-key":
|
|
1869
|
+
return keyedArrayContributionPresent(
|
|
1870
|
+
current,
|
|
1871
|
+
settingPath.managedValue,
|
|
1872
|
+
settingPath.previousValue,
|
|
1873
|
+
settingPath.mergeKey ?? "code"
|
|
1874
|
+
);
|
|
1875
|
+
case "shared-requirement":
|
|
1876
|
+
return true;
|
|
1877
|
+
default:
|
|
1878
|
+
return sha256Value(current) === settingPath.sha256;
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
function plannedSettingContributionPresent(current, settingPath, previousValue) {
|
|
1882
|
+
switch (settingPath.mergeStrategy) {
|
|
1883
|
+
case "append-unique":
|
|
1884
|
+
return settingsValueContains(current, settingPath.value);
|
|
1885
|
+
case "merge-by-key":
|
|
1886
|
+
return keyedArrayContributionPresent(
|
|
1887
|
+
current,
|
|
1888
|
+
settingPath.value,
|
|
1889
|
+
previousValue,
|
|
1890
|
+
settingPath.mergeKey ?? "code"
|
|
1891
|
+
);
|
|
1892
|
+
case "shared-requirement":
|
|
1893
|
+
return sharedRequirementValuesCompatible(settingPath.path, current, settingPath.value);
|
|
1894
|
+
default:
|
|
1895
|
+
return settingsValuesEqual(current, settingPath.value);
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
function sharedRequirementValuesCompatible(path, current, incoming) {
|
|
1899
|
+
const field = path.split(".").at(-1);
|
|
1900
|
+
if (current === void 0 || field === "required") {
|
|
1901
|
+
return true;
|
|
1902
|
+
}
|
|
1903
|
+
if (field === "category" || field === "label" || field === "description") {
|
|
1904
|
+
return true;
|
|
1905
|
+
}
|
|
1906
|
+
return settingsValuesEqual(current, incoming);
|
|
1907
|
+
}
|
|
1908
|
+
function findMergeByKeyConflict(current, incoming, mergeKey) {
|
|
1909
|
+
if (!Array.isArray(current) || !Array.isArray(incoming)) {
|
|
1910
|
+
return null;
|
|
1911
|
+
}
|
|
1912
|
+
for (const incomingItem of incoming) {
|
|
1913
|
+
if (!isPlainObject(incomingItem) || incomingItem[mergeKey] === void 0) {
|
|
1914
|
+
continue;
|
|
1915
|
+
}
|
|
1916
|
+
const currentItem = current.find(
|
|
1917
|
+
(item) => isPlainObject(item) && settingsValuesEqual(item[mergeKey], incomingItem[mergeKey])
|
|
1918
|
+
);
|
|
1919
|
+
if (!isPlainObject(currentItem)) {
|
|
1920
|
+
continue;
|
|
1921
|
+
}
|
|
1922
|
+
for (const [field, value] of Object.entries(incomingItem)) {
|
|
1923
|
+
if (field === mergeKey || !isPlainObject(value)) {
|
|
1924
|
+
continue;
|
|
1925
|
+
}
|
|
1926
|
+
const existing = currentItem[field];
|
|
1927
|
+
if (!isPlainObject(existing)) {
|
|
1928
|
+
continue;
|
|
1929
|
+
}
|
|
1930
|
+
for (const [nestedKey, nestedValue] of Object.entries(value)) {
|
|
1931
|
+
if (nestedKey in existing && !settingsValuesEqual(existing[nestedKey], nestedValue)) {
|
|
1932
|
+
return { currentValue: existing[nestedKey], nextValue: nestedValue };
|
|
1933
|
+
}
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
return null;
|
|
1938
|
+
}
|
|
1707
1939
|
function attachAppliedSettings(members, appliedSettings) {
|
|
1708
1940
|
return members.map((member) => {
|
|
1709
1941
|
const applied = appliedSettings.find((item) => item.memberName === member.name);
|
|
@@ -1729,13 +1961,17 @@ async function applyPlannedSettings(targetDir, settings) {
|
|
|
1729
1961
|
for (const settingPath of item.paths) {
|
|
1730
1962
|
const previousValueExists = document.hasIn(settingPath.segments);
|
|
1731
1963
|
const previousValue = previousValueExists ? getPlainYamlValue(document, settingPath.segments) : void 0;
|
|
1732
|
-
|
|
1964
|
+
const nextValue = mergePlannedSettingValue(previousValue, settingPath);
|
|
1965
|
+
document.setIn(settingPath.segments, nextValue);
|
|
1733
1966
|
pathMetas.push({
|
|
1734
1967
|
targetPath: item.targetPath,
|
|
1735
1968
|
path: settingPath.path,
|
|
1736
|
-
sha256: sha256Value(settingPath.value),
|
|
1969
|
+
sha256: sha256Value(settingPath.mergeStrategy ? settingPath.value : nextValue),
|
|
1737
1970
|
previousValueExists,
|
|
1738
|
-
previousValue
|
|
1971
|
+
previousValue,
|
|
1972
|
+
mergeStrategy: settingPath.mergeStrategy,
|
|
1973
|
+
mergeKey: settingPath.mergeKey,
|
|
1974
|
+
managedValue: settingPath.mergeStrategy ? cloneSettingsValue(settingPath.value) : void 0
|
|
1739
1975
|
});
|
|
1740
1976
|
}
|
|
1741
1977
|
await ensureParentDirectory(targetPath);
|
|
@@ -1752,7 +1988,124 @@ async function applyPlannedSettings(targetDir, settings) {
|
|
|
1752
1988
|
appliedSettings
|
|
1753
1989
|
};
|
|
1754
1990
|
}
|
|
1755
|
-
|
|
1991
|
+
function listOtherManagedSettingValues(metas, excludeAddonName, targetPath, path, mergeStrategy) {
|
|
1992
|
+
const values = [];
|
|
1993
|
+
for (const meta of metas) {
|
|
1994
|
+
if (meta.name === excludeAddonName) {
|
|
1995
|
+
continue;
|
|
1996
|
+
}
|
|
1997
|
+
for (const member of meta.members) {
|
|
1998
|
+
for (const settingPath of member.settings?.paths ?? []) {
|
|
1999
|
+
if (settingPath.targetPath === targetPath && settingPath.path === path && settingPath.mergeStrategy === mergeStrategy && settingPath.managedValue !== void 0) {
|
|
2000
|
+
values.push(settingPath.managedValue);
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
2004
|
+
}
|
|
2005
|
+
return values;
|
|
2006
|
+
}
|
|
2007
|
+
function removeNestedSettingsContribution(current, contribution, previous, others) {
|
|
2008
|
+
const next = cloneSettingsValue(current);
|
|
2009
|
+
for (const [key, contributedValue] of Object.entries(contribution)) {
|
|
2010
|
+
const currentValue = next[key];
|
|
2011
|
+
const previousHasKey = previous ? key in previous : false;
|
|
2012
|
+
const otherValues = others.filter((item) => key in item).map((item) => item[key]);
|
|
2013
|
+
if (isPlainObject(contributedValue) && isPlainObject(currentValue)) {
|
|
2014
|
+
const previousObject = previousHasKey && isPlainObject(previous?.[key]) ? previous[key] : void 0;
|
|
2015
|
+
const otherObjects = otherValues.filter(isPlainObject);
|
|
2016
|
+
const nested = removeNestedSettingsContribution(
|
|
2017
|
+
currentValue,
|
|
2018
|
+
contributedValue,
|
|
2019
|
+
previousObject,
|
|
2020
|
+
otherObjects
|
|
2021
|
+
);
|
|
2022
|
+
if (!Object.keys(nested).length && !previousHasKey && !otherObjects.length) {
|
|
2023
|
+
delete next[key];
|
|
2024
|
+
} else {
|
|
2025
|
+
next[key] = nested;
|
|
2026
|
+
}
|
|
2027
|
+
continue;
|
|
2028
|
+
}
|
|
2029
|
+
if (otherValues.some((value) => settingsValuesEqual(value, contributedValue))) {
|
|
2030
|
+
continue;
|
|
2031
|
+
}
|
|
2032
|
+
if (previousHasKey) {
|
|
2033
|
+
next[key] = cloneSettingsValue(previous?.[key]);
|
|
2034
|
+
} else if (settingsValuesEqual(currentValue, contributedValue)) {
|
|
2035
|
+
delete next[key];
|
|
2036
|
+
}
|
|
2037
|
+
}
|
|
2038
|
+
return next;
|
|
2039
|
+
}
|
|
2040
|
+
function removeManagedSettingContribution(current, settingPath, otherManagedValues) {
|
|
2041
|
+
if (settingPath.mergeStrategy === "shared-requirement") {
|
|
2042
|
+
return current;
|
|
2043
|
+
}
|
|
2044
|
+
if (settingPath.mergeStrategy === "append-unique") {
|
|
2045
|
+
if (!Array.isArray(current) || !Array.isArray(settingPath.managedValue)) {
|
|
2046
|
+
return current;
|
|
2047
|
+
}
|
|
2048
|
+
const previous = Array.isArray(settingPath.previousValue) ? settingPath.previousValue : [];
|
|
2049
|
+
const otherItems = otherManagedValues.flatMap((value) => Array.isArray(value) ? value : []);
|
|
2050
|
+
return current.filter((item) => {
|
|
2051
|
+
const contributed = settingPath.managedValue;
|
|
2052
|
+
if (!contributed.some((value) => settingsValuesEqual(value, item))) {
|
|
2053
|
+
return true;
|
|
2054
|
+
}
|
|
2055
|
+
return previous.some((value) => settingsValuesEqual(value, item)) || otherItems.some((value) => settingsValuesEqual(value, item));
|
|
2056
|
+
});
|
|
2057
|
+
}
|
|
2058
|
+
if (settingPath.mergeStrategy === "merge-by-key") {
|
|
2059
|
+
if (!Array.isArray(current) || !Array.isArray(settingPath.managedValue)) {
|
|
2060
|
+
return current;
|
|
2061
|
+
}
|
|
2062
|
+
const mergeKey = settingPath.mergeKey ?? "code";
|
|
2063
|
+
const previous = Array.isArray(settingPath.previousValue) ? settingPath.previousValue : [];
|
|
2064
|
+
const otherItems = otherManagedValues.flatMap((value) => Array.isArray(value) ? value : []);
|
|
2065
|
+
const next = current.map((item) => cloneSettingsValue(item));
|
|
2066
|
+
for (const contributedItem of settingPath.managedValue) {
|
|
2067
|
+
if (!isPlainObject(contributedItem) || contributedItem[mergeKey] === void 0) {
|
|
2068
|
+
continue;
|
|
2069
|
+
}
|
|
2070
|
+
const index = next.findIndex(
|
|
2071
|
+
(item) => isPlainObject(item) && settingsValuesEqual(item[mergeKey], contributedItem[mergeKey])
|
|
2072
|
+
);
|
|
2073
|
+
if (index < 0 || !isPlainObject(next[index])) {
|
|
2074
|
+
continue;
|
|
2075
|
+
}
|
|
2076
|
+
const currentItem = next[index];
|
|
2077
|
+
const previousItem = previous.find(
|
|
2078
|
+
(item) => isPlainObject(item) && settingsValuesEqual(item[mergeKey], contributedItem[mergeKey])
|
|
2079
|
+
);
|
|
2080
|
+
const matchingOtherItems = otherItems.filter(
|
|
2081
|
+
(item) => isPlainObject(item) && settingsValuesEqual(item[mergeKey], contributedItem[mergeKey])
|
|
2082
|
+
);
|
|
2083
|
+
if (!previousItem && !matchingOtherItems.length && settingsValuesEqual(currentItem, contributedItem)) {
|
|
2084
|
+
next.splice(index, 1);
|
|
2085
|
+
continue;
|
|
2086
|
+
}
|
|
2087
|
+
const updated = cloneSettingsValue(currentItem);
|
|
2088
|
+
for (const [field, contributedValue] of Object.entries(contributedItem)) {
|
|
2089
|
+
if (field === mergeKey || !isPlainObject(contributedValue) || !isPlainObject(updated[field])) {
|
|
2090
|
+
continue;
|
|
2091
|
+
}
|
|
2092
|
+
const previousObject = isPlainObject(previousItem) && isPlainObject(previousItem[field]) ? previousItem[field] : void 0;
|
|
2093
|
+
const otherObjects = matchingOtherItems.map((item) => item[field]).filter(isPlainObject);
|
|
2094
|
+
const nested = removeNestedSettingsContribution(
|
|
2095
|
+
updated[field],
|
|
2096
|
+
contributedValue,
|
|
2097
|
+
previousObject,
|
|
2098
|
+
otherObjects
|
|
2099
|
+
);
|
|
2100
|
+
updated[field] = nested;
|
|
2101
|
+
}
|
|
2102
|
+
next[index] = updated;
|
|
2103
|
+
}
|
|
2104
|
+
return next;
|
|
2105
|
+
}
|
|
2106
|
+
return settingPath.previousValueExists ? cloneSettingsValue(settingPath.previousValue) : void 0;
|
|
2107
|
+
}
|
|
2108
|
+
async function restoreObsoleteSettings(targetDir, previousMeta, nextSettings, existingMetas) {
|
|
1756
2109
|
if (!previousMeta) {
|
|
1757
2110
|
return [];
|
|
1758
2111
|
}
|
|
@@ -1772,12 +2125,30 @@ async function restoreObsoleteSettings(targetDir, previousMeta, nextSettings) {
|
|
|
1772
2125
|
};
|
|
1773
2126
|
for (const member of previousMeta.members) {
|
|
1774
2127
|
for (const settingPath of member.settings?.paths ?? []) {
|
|
1775
|
-
if (nextSettingKeys.has(`${settingPath.targetPath}#${settingPath.path}`)) {
|
|
2128
|
+
if (!settingPath.mergeStrategy && nextSettingKeys.has(`${settingPath.targetPath}#${settingPath.path}`)) {
|
|
2129
|
+
continue;
|
|
2130
|
+
}
|
|
2131
|
+
if (!settingPath.mergeStrategy && isComposableSettingsPath(settingPath.path)) {
|
|
1776
2132
|
continue;
|
|
1777
2133
|
}
|
|
1778
2134
|
const document = await getDocument(settingPath.targetPath);
|
|
1779
2135
|
const segments = settingPath.path.split(".");
|
|
1780
|
-
if (settingPath.
|
|
2136
|
+
if (settingPath.mergeStrategy) {
|
|
2137
|
+
const current = document.hasIn(segments) ? getPlainYamlValue(document, segments) : void 0;
|
|
2138
|
+
const otherManagedValues = listOtherManagedSettingValues(
|
|
2139
|
+
existingMetas,
|
|
2140
|
+
previousMeta.name,
|
|
2141
|
+
settingPath.targetPath,
|
|
2142
|
+
settingPath.path,
|
|
2143
|
+
settingPath.mergeStrategy
|
|
2144
|
+
);
|
|
2145
|
+
const restored = removeManagedSettingContribution(current, settingPath, otherManagedValues);
|
|
2146
|
+
if (restored === void 0) {
|
|
2147
|
+
document.deleteIn(segments);
|
|
2148
|
+
} else {
|
|
2149
|
+
document.setIn(segments, restored);
|
|
2150
|
+
}
|
|
2151
|
+
} else if (settingPath.previousValueExists) {
|
|
1781
2152
|
document.setIn(segments, settingPath.previousValue);
|
|
1782
2153
|
} else {
|
|
1783
2154
|
document.deleteIn(segments);
|
|
@@ -1869,6 +2240,16 @@ async function validateInstallConflicts(targetDir, plan, existingMetas) {
|
|
|
1869
2240
|
const settingsOwnership = buildSettingsOwnershipMap(existingMetas);
|
|
1870
2241
|
const conflicts = [];
|
|
1871
2242
|
const packageJson = await readPackageJson(targetDir);
|
|
2243
|
+
const settingsDocuments = /* @__PURE__ */ new Map();
|
|
2244
|
+
const getSettingsDocument = async (targetPath) => {
|
|
2245
|
+
const cached = settingsDocuments.get(targetPath);
|
|
2246
|
+
if (cached) {
|
|
2247
|
+
return cached;
|
|
2248
|
+
}
|
|
2249
|
+
const document = await readYamlDocument(ensurePathInsideTarget(targetDir, targetPath));
|
|
2250
|
+
settingsDocuments.set(targetPath, document);
|
|
2251
|
+
return document;
|
|
2252
|
+
};
|
|
1872
2253
|
for (const dependency of listNpmDependencies(resolveInstallNpm(plan.manifest))) {
|
|
1873
2254
|
const existing = findPackageDependency(packageJson, dependency.packageName);
|
|
1874
2255
|
if (existing && !isExistingNpmDependencyCompatible(existing, dependency.version)) {
|
|
@@ -1909,8 +2290,41 @@ async function validateInstallConflicts(targetDir, plan, existingMetas) {
|
|
|
1909
2290
|
}
|
|
1910
2291
|
}
|
|
1911
2292
|
for (const item of listPlannedSettingPaths(plan.settings)) {
|
|
2293
|
+
const document = await getSettingsDocument(item.targetPath);
|
|
2294
|
+
const currentValue = document.hasIn(item.segments) ? getPlainYamlValue(document, item.segments) : void 0;
|
|
2295
|
+
if (item.mergeStrategy === "shared-requirement" && !sharedRequirementValuesCompatible(item.path, currentValue, item.value)) {
|
|
2296
|
+
conflicts.push({
|
|
2297
|
+
kind: "setting_value_conflict",
|
|
2298
|
+
path: `${item.targetPath}#${item.path}`,
|
|
2299
|
+
sourcePath: item.sourceRelativePath,
|
|
2300
|
+
memberName: item.memberName,
|
|
2301
|
+
memberType: "settings",
|
|
2302
|
+
settingPath: item.path,
|
|
2303
|
+
currentValue,
|
|
2304
|
+
nextValue: item.value,
|
|
2305
|
+
message: `${item.targetPath}#${item.path} has an incompatible shared requirement value`
|
|
2306
|
+
});
|
|
2307
|
+
continue;
|
|
2308
|
+
}
|
|
2309
|
+
if (item.mergeStrategy === "merge-by-key") {
|
|
2310
|
+
const conflict = findMergeByKeyConflict(currentValue, item.value, item.mergeKey ?? "code");
|
|
2311
|
+
if (conflict) {
|
|
2312
|
+
conflicts.push({
|
|
2313
|
+
kind: "setting_value_conflict",
|
|
2314
|
+
path: `${item.targetPath}#${item.path}`,
|
|
2315
|
+
sourcePath: item.sourceRelativePath,
|
|
2316
|
+
memberName: item.memberName,
|
|
2317
|
+
memberType: "settings",
|
|
2318
|
+
settingPath: item.path,
|
|
2319
|
+
currentValue: conflict.currentValue,
|
|
2320
|
+
nextValue: conflict.nextValue,
|
|
2321
|
+
message: `${item.targetPath}#${item.path} contains an incompatible keyed setting value`
|
|
2322
|
+
});
|
|
2323
|
+
continue;
|
|
2324
|
+
}
|
|
2325
|
+
}
|
|
1912
2326
|
const owner = settingsOwnership.get(`${item.targetPath}#${item.path}`);
|
|
1913
|
-
if (owner && owner !== plan.manifest.name) {
|
|
2327
|
+
if (!item.mergeStrategy && owner && owner !== plan.manifest.name) {
|
|
1914
2328
|
conflicts.push({
|
|
1915
2329
|
kind: "owned_by_other_addon",
|
|
1916
2330
|
path: `${item.targetPath}#${item.path}`,
|
|
@@ -2044,12 +2458,13 @@ async function validateUpgradeConflicts(targetDir, plan, existingMetas, previous
|
|
|
2044
2458
|
const segments = settingPath.path.split(".");
|
|
2045
2459
|
const currentValue = document.hasIn(segments) ? getPlainYamlValue(document, segments) : void 0;
|
|
2046
2460
|
const actualSha256 = sha256Value(currentValue);
|
|
2047
|
-
if (actualSha256 === settingPath.sha256) {
|
|
2048
|
-
continue;
|
|
2049
|
-
}
|
|
2050
2461
|
const settingKey = `${settingPath.targetPath}#${settingPath.path}`;
|
|
2051
2462
|
const isStillManaged = nextSettingKeys.has(settingKey);
|
|
2052
2463
|
const nextSetting = plannedSettingsByKey.get(settingKey);
|
|
2464
|
+
const contributionPresent = settingPath.mergeStrategy ? managedSettingContributionPresent(currentValue, settingPath) : nextSetting?.mergeStrategy ? plannedSettingContributionPresent(currentValue, nextSetting, settingPath.previousValue) : actualSha256 === settingPath.sha256;
|
|
2465
|
+
if (contributionPresent) {
|
|
2466
|
+
continue;
|
|
2467
|
+
}
|
|
2053
2468
|
conflicts.push({
|
|
2054
2469
|
kind: isStillManaged ? "managed_file_modified" : "obsolete_file_modified",
|
|
2055
2470
|
path: settingKey,
|
|
@@ -2067,8 +2482,24 @@ async function validateUpgradeConflicts(targetDir, plan, existingMetas, previous
|
|
|
2067
2482
|
}
|
|
2068
2483
|
}
|
|
2069
2484
|
for (const item of plannedSettings) {
|
|
2485
|
+
const document = await getSettingsDocument(item.targetPath);
|
|
2486
|
+
const currentValue = document.hasIn(item.segments) ? getPlainYamlValue(document, item.segments) : void 0;
|
|
2487
|
+
if (item.mergeStrategy === "shared-requirement" && !sharedRequirementValuesCompatible(item.path, currentValue, item.value)) {
|
|
2488
|
+
conflicts.push({
|
|
2489
|
+
kind: "setting_value_conflict",
|
|
2490
|
+
path: `${item.targetPath}#${item.path}`,
|
|
2491
|
+
sourcePath: item.sourceRelativePath,
|
|
2492
|
+
memberName: item.memberName,
|
|
2493
|
+
memberType: "settings",
|
|
2494
|
+
settingPath: item.path,
|
|
2495
|
+
currentValue,
|
|
2496
|
+
nextValue: item.value,
|
|
2497
|
+
message: `${item.targetPath}#${item.path} has an incompatible shared requirement value`
|
|
2498
|
+
});
|
|
2499
|
+
continue;
|
|
2500
|
+
}
|
|
2070
2501
|
const owner = settingsOwnership.get(`${item.targetPath}#${item.path}`);
|
|
2071
|
-
if (owner) {
|
|
2502
|
+
if (!item.mergeStrategy && owner) {
|
|
2072
2503
|
conflicts.push({
|
|
2073
2504
|
kind: "owned_by_other_addon",
|
|
2074
2505
|
path: `${item.targetPath}#${item.path}`,
|
|
@@ -2136,7 +2567,12 @@ async function materializeAddon(options) {
|
|
|
2136
2567
|
await validateUpgradeConflicts(targetDir, plan, existingMetas, previousMeta);
|
|
2137
2568
|
}
|
|
2138
2569
|
const removedFiles = previousMeta ? await removeObsoleteFiles(targetDir, previousMeta, new Set(plan.files.map((file) => file.targetPath))) : [];
|
|
2139
|
-
const restoredSettingsFiles = await restoreObsoleteSettings(
|
|
2570
|
+
const restoredSettingsFiles = await restoreObsoleteSettings(
|
|
2571
|
+
targetDir,
|
|
2572
|
+
previousMeta,
|
|
2573
|
+
plan.settings,
|
|
2574
|
+
existingMetas
|
|
2575
|
+
);
|
|
2140
2576
|
const npm = resolveInstallNpm(plan.manifest);
|
|
2141
2577
|
const packageJsonFiles = await applyNpmDependencies(targetDir, npm);
|
|
2142
2578
|
await writePlannedFiles(targetDir, plan.files);
|