@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/README.md
CHANGED
|
@@ -147,6 +147,10 @@ Addon 可在 `addon.json` 中声明安装后的运行配置要求:
|
|
|
147
147
|
|
|
148
148
|
`install.requirements` 会写入 `meta.json`,并在安装/升级结果中返回 `requirements` 和 `missingRequirements`。`requirements.envs` 和 `requirements.secrets` 会合并到应用根目录 `app.settings.yml` 的 `envMetadata`;env 字段生成 `type: input` / `storage: env`,secret 字段生成 `type: password` / `storage: secret` / `sensitive: true`。`defaultValue` 仅支持 env,会写为 `default`;secret 不保存密钥值。
|
|
149
149
|
|
|
150
|
+
环境变量和 Secret requirement 是应用级共享依赖,不归某一个 Addon 独占。多个 Addon 声明同名且存储类型兼容的 requirement 时会复用同一份 `envMetadata`;展示名称和说明保留应用中已有值,`required` 按逻辑或合并。若同一个 key 被分别声明成 env 和 secret,或核心存储属性不一致,安装会以 `setting_value_conflict` 停止。
|
|
151
|
+
|
|
152
|
+
`settings` 成员中的 `rbac.permissions` 按权限字符串去重追加,`rbac.roles` 按 `role.code` 合并;同一角色的 `permissions` 会增量合并,应用已有的角色名称和说明不会被后安装的 Addon 覆盖。升级 Addon 时只移除该 Addon 已不再声明的权限贡献,不影响应用原有配置或其他 Addon 的贡献。其他数组仍按普通设置整体替换,避免把未知数组误判成可组合资源。
|
|
153
|
+
|
|
150
154
|
页面接入方式:
|
|
151
155
|
|
|
152
156
|
- CLI 只复制页面文件并写入 `src/addons/{addonName}/meta.json`
|
package/dist/cli.cjs
CHANGED
|
@@ -1194,6 +1194,10 @@ function toImportSpecifier(targetPath) {
|
|
|
1194
1194
|
function toAssetImportSpecifier(targetPath) {
|
|
1195
1195
|
return targetPath.replace(/\\/g, "/").replace(/^src\//, "@/");
|
|
1196
1196
|
}
|
|
1197
|
+
function resolveComponentImportSpecifier(member) {
|
|
1198
|
+
const entryPath = member.targetPaths.find((targetPath) => /\/index\.[cm]?[jt]sx?$/.test(targetPath));
|
|
1199
|
+
return entryPath ? toImportSpecifier(entryPath) : member.targetPaths[0] ? toImportSpecifier(member.targetPaths[0]) : "";
|
|
1200
|
+
}
|
|
1197
1201
|
function resolveInstalledAddonDisplay(meta) {
|
|
1198
1202
|
const legacyMeta = meta;
|
|
1199
1203
|
return {
|
|
@@ -1221,7 +1225,7 @@ function buildAddonLlmGuidance(input) {
|
|
|
1221
1225
|
}));
|
|
1222
1226
|
const components = componentMembers.map((member) => ({
|
|
1223
1227
|
name: member.name,
|
|
1224
|
-
importFrom:
|
|
1228
|
+
importFrom: resolveComponentImportSpecifier(member)
|
|
1225
1229
|
}));
|
|
1226
1230
|
const functions = functionMembers.map((member) => ({
|
|
1227
1231
|
name: member.name,
|
|
@@ -1583,7 +1587,7 @@ async function buildInstallPlan(options) {
|
|
|
1583
1587
|
memberName: "install-requirements",
|
|
1584
1588
|
memberType: "settings",
|
|
1585
1589
|
patch: requirementsSettingsPatch,
|
|
1586
|
-
paths: flattenSettingsPatch(requirementsSettingsPatch)
|
|
1590
|
+
paths: flattenSettingsPatch(requirementsSettingsPatch, [], { sharedRequirement: true })
|
|
1587
1591
|
});
|
|
1588
1592
|
members.push({
|
|
1589
1593
|
name: "install-requirements",
|
|
@@ -1678,18 +1682,21 @@ async function readYamlObject(filePath) {
|
|
|
1678
1682
|
}
|
|
1679
1683
|
return parsed;
|
|
1680
1684
|
}
|
|
1681
|
-
function flattenSettingsPatch(value, prefix = []) {
|
|
1685
|
+
function flattenSettingsPatch(value, prefix = [], options = {}) {
|
|
1682
1686
|
const paths = [];
|
|
1683
1687
|
for (const [key, child] of Object.entries(value)) {
|
|
1684
1688
|
const segments = prefix.concat(key);
|
|
1685
1689
|
if (isPlainObject(child)) {
|
|
1686
|
-
paths.push(...flattenSettingsPatch(child, segments));
|
|
1690
|
+
paths.push(...flattenSettingsPatch(child, segments, options));
|
|
1687
1691
|
continue;
|
|
1688
1692
|
}
|
|
1693
|
+
const path = segments.join(".");
|
|
1694
|
+
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" } : {};
|
|
1689
1695
|
paths.push({
|
|
1690
|
-
path
|
|
1696
|
+
path,
|
|
1691
1697
|
segments,
|
|
1692
|
-
value: child
|
|
1698
|
+
value: child,
|
|
1699
|
+
...merge
|
|
1693
1700
|
});
|
|
1694
1701
|
}
|
|
1695
1702
|
return paths;
|
|
@@ -1706,6 +1713,9 @@ function buildSettingsOwnershipMap(metas, excludeAddonName) {
|
|
|
1706
1713
|
}
|
|
1707
1714
|
for (const member of meta.members) {
|
|
1708
1715
|
for (const item of member.settings?.paths ?? []) {
|
|
1716
|
+
if (item.mergeStrategy) {
|
|
1717
|
+
continue;
|
|
1718
|
+
}
|
|
1709
1719
|
ownership.set(`${item.targetPath}#${item.path}`, meta.name);
|
|
1710
1720
|
}
|
|
1711
1721
|
}
|
|
@@ -1720,7 +1730,9 @@ function listPlannedSettingPaths(settings) {
|
|
|
1720
1730
|
targetPath: item.targetPath,
|
|
1721
1731
|
path: settingPath.path,
|
|
1722
1732
|
segments: settingPath.segments,
|
|
1723
|
-
value: settingPath.value
|
|
1733
|
+
value: settingPath.value,
|
|
1734
|
+
mergeStrategy: settingPath.mergeStrategy,
|
|
1735
|
+
mergeKey: settingPath.mergeKey
|
|
1724
1736
|
}))
|
|
1725
1737
|
);
|
|
1726
1738
|
}
|
|
@@ -1731,6 +1743,226 @@ function getPlainYamlValue(document, segments) {
|
|
|
1731
1743
|
}
|
|
1732
1744
|
return value;
|
|
1733
1745
|
}
|
|
1746
|
+
function cloneSettingsValue(value) {
|
|
1747
|
+
if (Array.isArray(value)) {
|
|
1748
|
+
return value.map((item) => cloneSettingsValue(item));
|
|
1749
|
+
}
|
|
1750
|
+
if (isPlainObject(value)) {
|
|
1751
|
+
return Object.fromEntries(Object.entries(value).map(([key, child]) => [key, cloneSettingsValue(child)]));
|
|
1752
|
+
}
|
|
1753
|
+
return value;
|
|
1754
|
+
}
|
|
1755
|
+
function settingsValuesEqual(left, right) {
|
|
1756
|
+
return stableJsonStringify(left) === stableJsonStringify(right);
|
|
1757
|
+
}
|
|
1758
|
+
function isComposableSettingsPath(path) {
|
|
1759
|
+
return path === "rbac.permissions" || path === "rbac.roles" || path.startsWith("envMetadata.");
|
|
1760
|
+
}
|
|
1761
|
+
function mergeNestedSettingsObject(existing, incoming) {
|
|
1762
|
+
const merged = cloneSettingsValue(existing);
|
|
1763
|
+
for (const [key, value] of Object.entries(incoming)) {
|
|
1764
|
+
const current = merged[key];
|
|
1765
|
+
merged[key] = isPlainObject(current) && isPlainObject(value) ? mergeNestedSettingsObject(current, value) : cloneSettingsValue(value);
|
|
1766
|
+
}
|
|
1767
|
+
return merged;
|
|
1768
|
+
}
|
|
1769
|
+
function mergeArrayByKey(current, incoming, mergeKey) {
|
|
1770
|
+
if (!Array.isArray(incoming)) {
|
|
1771
|
+
throw new Error(`merge-by-key setting requires an array value`);
|
|
1772
|
+
}
|
|
1773
|
+
const merged = Array.isArray(current) ? current.map((item) => cloneSettingsValue(item)) : [];
|
|
1774
|
+
const indexes = /* @__PURE__ */ new Map();
|
|
1775
|
+
for (const [index, item] of merged.entries()) {
|
|
1776
|
+
if (isPlainObject(item) && item[mergeKey] !== void 0) {
|
|
1777
|
+
indexes.set(item[mergeKey], index);
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
for (const item of incoming) {
|
|
1781
|
+
if (!isPlainObject(item) || item[mergeKey] === void 0) {
|
|
1782
|
+
throw new Error(`merge-by-key setting item must contain ${mergeKey}`);
|
|
1783
|
+
}
|
|
1784
|
+
const index = indexes.get(item[mergeKey]);
|
|
1785
|
+
if (index === void 0) {
|
|
1786
|
+
indexes.set(item[mergeKey], merged.length);
|
|
1787
|
+
merged.push(cloneSettingsValue(item));
|
|
1788
|
+
continue;
|
|
1789
|
+
}
|
|
1790
|
+
const existing = merged[index];
|
|
1791
|
+
if (!isPlainObject(existing)) {
|
|
1792
|
+
throw new Error(`merge-by-key setting contains a non-object item for ${String(item[mergeKey])}`);
|
|
1793
|
+
}
|
|
1794
|
+
const next = cloneSettingsValue(existing);
|
|
1795
|
+
for (const [field, value] of Object.entries(item)) {
|
|
1796
|
+
if (field === mergeKey) {
|
|
1797
|
+
continue;
|
|
1798
|
+
}
|
|
1799
|
+
const currentValue = next[field];
|
|
1800
|
+
if (isPlainObject(currentValue) && isPlainObject(value)) {
|
|
1801
|
+
next[field] = mergeNestedSettingsObject(currentValue, value);
|
|
1802
|
+
} else if (currentValue === void 0) {
|
|
1803
|
+
next[field] = cloneSettingsValue(value);
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
merged[index] = next;
|
|
1807
|
+
}
|
|
1808
|
+
return merged;
|
|
1809
|
+
}
|
|
1810
|
+
function mergePlannedSettingValue(current, settingPath) {
|
|
1811
|
+
switch (settingPath.mergeStrategy) {
|
|
1812
|
+
case "append-unique": {
|
|
1813
|
+
if (!Array.isArray(settingPath.value)) {
|
|
1814
|
+
throw new Error(`append-unique setting requires an array value`);
|
|
1815
|
+
}
|
|
1816
|
+
const merged = Array.isArray(current) ? current.map((item) => cloneSettingsValue(item)) : [];
|
|
1817
|
+
for (const item of settingPath.value) {
|
|
1818
|
+
if (!merged.some((existing) => settingsValuesEqual(existing, item))) {
|
|
1819
|
+
merged.push(cloneSettingsValue(item));
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
return merged;
|
|
1823
|
+
}
|
|
1824
|
+
case "merge-by-key":
|
|
1825
|
+
return mergeArrayByKey(current, settingPath.value, settingPath.mergeKey ?? "code");
|
|
1826
|
+
case "shared-requirement": {
|
|
1827
|
+
if (current === void 0) {
|
|
1828
|
+
return cloneSettingsValue(settingPath.value);
|
|
1829
|
+
}
|
|
1830
|
+
if (settingPath.segments.at(-1) === "required") {
|
|
1831
|
+
return Boolean(current) || Boolean(settingPath.value);
|
|
1832
|
+
}
|
|
1833
|
+
return current;
|
|
1834
|
+
}
|
|
1835
|
+
default:
|
|
1836
|
+
return cloneSettingsValue(settingPath.value);
|
|
1837
|
+
}
|
|
1838
|
+
}
|
|
1839
|
+
function settingsValueContains(current, expected) {
|
|
1840
|
+
if (Array.isArray(expected)) {
|
|
1841
|
+
return Array.isArray(current) && expected.every(
|
|
1842
|
+
(item) => current.some((candidate) => settingsValueContains(candidate, item))
|
|
1843
|
+
);
|
|
1844
|
+
}
|
|
1845
|
+
if (isPlainObject(expected)) {
|
|
1846
|
+
return isPlainObject(current) && Object.entries(expected).every(
|
|
1847
|
+
([key, value]) => key in current && settingsValueContains(current[key], value)
|
|
1848
|
+
);
|
|
1849
|
+
}
|
|
1850
|
+
return settingsValuesEqual(current, expected);
|
|
1851
|
+
}
|
|
1852
|
+
function keyedArrayContributionPresent(current, contribution, previousValue, mergeKey) {
|
|
1853
|
+
if (!Array.isArray(current) || !Array.isArray(contribution)) {
|
|
1854
|
+
return false;
|
|
1855
|
+
}
|
|
1856
|
+
const previous = Array.isArray(previousValue) ? previousValue : [];
|
|
1857
|
+
for (const contributedItem of contribution) {
|
|
1858
|
+
if (!isPlainObject(contributedItem) || contributedItem[mergeKey] === void 0) {
|
|
1859
|
+
return false;
|
|
1860
|
+
}
|
|
1861
|
+
const currentItem = current.find(
|
|
1862
|
+
(item) => isPlainObject(item) && settingsValuesEqual(item[mergeKey], contributedItem[mergeKey])
|
|
1863
|
+
);
|
|
1864
|
+
if (!isPlainObject(currentItem)) {
|
|
1865
|
+
return false;
|
|
1866
|
+
}
|
|
1867
|
+
const previousItem = previous.find(
|
|
1868
|
+
(item) => isPlainObject(item) && settingsValuesEqual(item[mergeKey], contributedItem[mergeKey])
|
|
1869
|
+
);
|
|
1870
|
+
if (!isPlainObject(previousItem)) {
|
|
1871
|
+
if (!settingsValueContains(currentItem, contributedItem)) {
|
|
1872
|
+
return false;
|
|
1873
|
+
}
|
|
1874
|
+
continue;
|
|
1875
|
+
}
|
|
1876
|
+
for (const [field, value] of Object.entries(contributedItem)) {
|
|
1877
|
+
if (field === mergeKey) {
|
|
1878
|
+
continue;
|
|
1879
|
+
}
|
|
1880
|
+
if (isPlainObject(value)) {
|
|
1881
|
+
if (!settingsValueContains(currentItem[field], value)) {
|
|
1882
|
+
return false;
|
|
1883
|
+
}
|
|
1884
|
+
} else if (!(field in previousItem) && !settingsValuesEqual(currentItem[field], value)) {
|
|
1885
|
+
return false;
|
|
1886
|
+
}
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
return true;
|
|
1890
|
+
}
|
|
1891
|
+
function managedSettingContributionPresent(current, settingPath) {
|
|
1892
|
+
switch (settingPath.mergeStrategy) {
|
|
1893
|
+
case "append-unique":
|
|
1894
|
+
return settingsValueContains(current, settingPath.managedValue);
|
|
1895
|
+
case "merge-by-key":
|
|
1896
|
+
return keyedArrayContributionPresent(
|
|
1897
|
+
current,
|
|
1898
|
+
settingPath.managedValue,
|
|
1899
|
+
settingPath.previousValue,
|
|
1900
|
+
settingPath.mergeKey ?? "code"
|
|
1901
|
+
);
|
|
1902
|
+
case "shared-requirement":
|
|
1903
|
+
return true;
|
|
1904
|
+
default:
|
|
1905
|
+
return sha256Value(current) === settingPath.sha256;
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
1908
|
+
function plannedSettingContributionPresent(current, settingPath, previousValue) {
|
|
1909
|
+
switch (settingPath.mergeStrategy) {
|
|
1910
|
+
case "append-unique":
|
|
1911
|
+
return settingsValueContains(current, settingPath.value);
|
|
1912
|
+
case "merge-by-key":
|
|
1913
|
+
return keyedArrayContributionPresent(
|
|
1914
|
+
current,
|
|
1915
|
+
settingPath.value,
|
|
1916
|
+
previousValue,
|
|
1917
|
+
settingPath.mergeKey ?? "code"
|
|
1918
|
+
);
|
|
1919
|
+
case "shared-requirement":
|
|
1920
|
+
return sharedRequirementValuesCompatible(settingPath.path, current, settingPath.value);
|
|
1921
|
+
default:
|
|
1922
|
+
return settingsValuesEqual(current, settingPath.value);
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
1925
|
+
function sharedRequirementValuesCompatible(path, current, incoming) {
|
|
1926
|
+
const field = path.split(".").at(-1);
|
|
1927
|
+
if (current === void 0 || field === "required") {
|
|
1928
|
+
return true;
|
|
1929
|
+
}
|
|
1930
|
+
if (field === "category" || field === "label" || field === "description") {
|
|
1931
|
+
return true;
|
|
1932
|
+
}
|
|
1933
|
+
return settingsValuesEqual(current, incoming);
|
|
1934
|
+
}
|
|
1935
|
+
function findMergeByKeyConflict(current, incoming, mergeKey) {
|
|
1936
|
+
if (!Array.isArray(current) || !Array.isArray(incoming)) {
|
|
1937
|
+
return null;
|
|
1938
|
+
}
|
|
1939
|
+
for (const incomingItem of incoming) {
|
|
1940
|
+
if (!isPlainObject(incomingItem) || incomingItem[mergeKey] === void 0) {
|
|
1941
|
+
continue;
|
|
1942
|
+
}
|
|
1943
|
+
const currentItem = current.find(
|
|
1944
|
+
(item) => isPlainObject(item) && settingsValuesEqual(item[mergeKey], incomingItem[mergeKey])
|
|
1945
|
+
);
|
|
1946
|
+
if (!isPlainObject(currentItem)) {
|
|
1947
|
+
continue;
|
|
1948
|
+
}
|
|
1949
|
+
for (const [field, value] of Object.entries(incomingItem)) {
|
|
1950
|
+
if (field === mergeKey || !isPlainObject(value)) {
|
|
1951
|
+
continue;
|
|
1952
|
+
}
|
|
1953
|
+
const existing = currentItem[field];
|
|
1954
|
+
if (!isPlainObject(existing)) {
|
|
1955
|
+
continue;
|
|
1956
|
+
}
|
|
1957
|
+
for (const [nestedKey, nestedValue] of Object.entries(value)) {
|
|
1958
|
+
if (nestedKey in existing && !settingsValuesEqual(existing[nestedKey], nestedValue)) {
|
|
1959
|
+
return { currentValue: existing[nestedKey], nextValue: nestedValue };
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1964
|
+
return null;
|
|
1965
|
+
}
|
|
1734
1966
|
function attachAppliedSettings(members, appliedSettings) {
|
|
1735
1967
|
return members.map((member) => {
|
|
1736
1968
|
const applied = appliedSettings.find((item) => item.memberName === member.name);
|
|
@@ -1756,13 +1988,17 @@ async function applyPlannedSettings(targetDir, settings) {
|
|
|
1756
1988
|
for (const settingPath of item.paths) {
|
|
1757
1989
|
const previousValueExists = document.hasIn(settingPath.segments);
|
|
1758
1990
|
const previousValue = previousValueExists ? getPlainYamlValue(document, settingPath.segments) : void 0;
|
|
1759
|
-
|
|
1991
|
+
const nextValue = mergePlannedSettingValue(previousValue, settingPath);
|
|
1992
|
+
document.setIn(settingPath.segments, nextValue);
|
|
1760
1993
|
pathMetas.push({
|
|
1761
1994
|
targetPath: item.targetPath,
|
|
1762
1995
|
path: settingPath.path,
|
|
1763
|
-
sha256: sha256Value(settingPath.value),
|
|
1996
|
+
sha256: sha256Value(settingPath.mergeStrategy ? settingPath.value : nextValue),
|
|
1764
1997
|
previousValueExists,
|
|
1765
|
-
previousValue
|
|
1998
|
+
previousValue,
|
|
1999
|
+
mergeStrategy: settingPath.mergeStrategy,
|
|
2000
|
+
mergeKey: settingPath.mergeKey,
|
|
2001
|
+
managedValue: settingPath.mergeStrategy ? cloneSettingsValue(settingPath.value) : void 0
|
|
1766
2002
|
});
|
|
1767
2003
|
}
|
|
1768
2004
|
await ensureParentDirectory(targetPath);
|
|
@@ -1779,7 +2015,124 @@ async function applyPlannedSettings(targetDir, settings) {
|
|
|
1779
2015
|
appliedSettings
|
|
1780
2016
|
};
|
|
1781
2017
|
}
|
|
1782
|
-
|
|
2018
|
+
function listOtherManagedSettingValues(metas, excludeAddonName, targetPath, path, mergeStrategy) {
|
|
2019
|
+
const values = [];
|
|
2020
|
+
for (const meta of metas) {
|
|
2021
|
+
if (meta.name === excludeAddonName) {
|
|
2022
|
+
continue;
|
|
2023
|
+
}
|
|
2024
|
+
for (const member of meta.members) {
|
|
2025
|
+
for (const settingPath of member.settings?.paths ?? []) {
|
|
2026
|
+
if (settingPath.targetPath === targetPath && settingPath.path === path && settingPath.mergeStrategy === mergeStrategy && settingPath.managedValue !== void 0) {
|
|
2027
|
+
values.push(settingPath.managedValue);
|
|
2028
|
+
}
|
|
2029
|
+
}
|
|
2030
|
+
}
|
|
2031
|
+
}
|
|
2032
|
+
return values;
|
|
2033
|
+
}
|
|
2034
|
+
function removeNestedSettingsContribution(current, contribution, previous, others) {
|
|
2035
|
+
const next = cloneSettingsValue(current);
|
|
2036
|
+
for (const [key, contributedValue] of Object.entries(contribution)) {
|
|
2037
|
+
const currentValue = next[key];
|
|
2038
|
+
const previousHasKey = previous ? key in previous : false;
|
|
2039
|
+
const otherValues = others.filter((item) => key in item).map((item) => item[key]);
|
|
2040
|
+
if (isPlainObject(contributedValue) && isPlainObject(currentValue)) {
|
|
2041
|
+
const previousObject = previousHasKey && isPlainObject(previous?.[key]) ? previous[key] : void 0;
|
|
2042
|
+
const otherObjects = otherValues.filter(isPlainObject);
|
|
2043
|
+
const nested = removeNestedSettingsContribution(
|
|
2044
|
+
currentValue,
|
|
2045
|
+
contributedValue,
|
|
2046
|
+
previousObject,
|
|
2047
|
+
otherObjects
|
|
2048
|
+
);
|
|
2049
|
+
if (!Object.keys(nested).length && !previousHasKey && !otherObjects.length) {
|
|
2050
|
+
delete next[key];
|
|
2051
|
+
} else {
|
|
2052
|
+
next[key] = nested;
|
|
2053
|
+
}
|
|
2054
|
+
continue;
|
|
2055
|
+
}
|
|
2056
|
+
if (otherValues.some((value) => settingsValuesEqual(value, contributedValue))) {
|
|
2057
|
+
continue;
|
|
2058
|
+
}
|
|
2059
|
+
if (previousHasKey) {
|
|
2060
|
+
next[key] = cloneSettingsValue(previous?.[key]);
|
|
2061
|
+
} else if (settingsValuesEqual(currentValue, contributedValue)) {
|
|
2062
|
+
delete next[key];
|
|
2063
|
+
}
|
|
2064
|
+
}
|
|
2065
|
+
return next;
|
|
2066
|
+
}
|
|
2067
|
+
function removeManagedSettingContribution(current, settingPath, otherManagedValues) {
|
|
2068
|
+
if (settingPath.mergeStrategy === "shared-requirement") {
|
|
2069
|
+
return current;
|
|
2070
|
+
}
|
|
2071
|
+
if (settingPath.mergeStrategy === "append-unique") {
|
|
2072
|
+
if (!Array.isArray(current) || !Array.isArray(settingPath.managedValue)) {
|
|
2073
|
+
return current;
|
|
2074
|
+
}
|
|
2075
|
+
const previous = Array.isArray(settingPath.previousValue) ? settingPath.previousValue : [];
|
|
2076
|
+
const otherItems = otherManagedValues.flatMap((value) => Array.isArray(value) ? value : []);
|
|
2077
|
+
return current.filter((item) => {
|
|
2078
|
+
const contributed = settingPath.managedValue;
|
|
2079
|
+
if (!contributed.some((value) => settingsValuesEqual(value, item))) {
|
|
2080
|
+
return true;
|
|
2081
|
+
}
|
|
2082
|
+
return previous.some((value) => settingsValuesEqual(value, item)) || otherItems.some((value) => settingsValuesEqual(value, item));
|
|
2083
|
+
});
|
|
2084
|
+
}
|
|
2085
|
+
if (settingPath.mergeStrategy === "merge-by-key") {
|
|
2086
|
+
if (!Array.isArray(current) || !Array.isArray(settingPath.managedValue)) {
|
|
2087
|
+
return current;
|
|
2088
|
+
}
|
|
2089
|
+
const mergeKey = settingPath.mergeKey ?? "code";
|
|
2090
|
+
const previous = Array.isArray(settingPath.previousValue) ? settingPath.previousValue : [];
|
|
2091
|
+
const otherItems = otherManagedValues.flatMap((value) => Array.isArray(value) ? value : []);
|
|
2092
|
+
const next = current.map((item) => cloneSettingsValue(item));
|
|
2093
|
+
for (const contributedItem of settingPath.managedValue) {
|
|
2094
|
+
if (!isPlainObject(contributedItem) || contributedItem[mergeKey] === void 0) {
|
|
2095
|
+
continue;
|
|
2096
|
+
}
|
|
2097
|
+
const index = next.findIndex(
|
|
2098
|
+
(item) => isPlainObject(item) && settingsValuesEqual(item[mergeKey], contributedItem[mergeKey])
|
|
2099
|
+
);
|
|
2100
|
+
if (index < 0 || !isPlainObject(next[index])) {
|
|
2101
|
+
continue;
|
|
2102
|
+
}
|
|
2103
|
+
const currentItem = next[index];
|
|
2104
|
+
const previousItem = previous.find(
|
|
2105
|
+
(item) => isPlainObject(item) && settingsValuesEqual(item[mergeKey], contributedItem[mergeKey])
|
|
2106
|
+
);
|
|
2107
|
+
const matchingOtherItems = otherItems.filter(
|
|
2108
|
+
(item) => isPlainObject(item) && settingsValuesEqual(item[mergeKey], contributedItem[mergeKey])
|
|
2109
|
+
);
|
|
2110
|
+
if (!previousItem && !matchingOtherItems.length && settingsValuesEqual(currentItem, contributedItem)) {
|
|
2111
|
+
next.splice(index, 1);
|
|
2112
|
+
continue;
|
|
2113
|
+
}
|
|
2114
|
+
const updated = cloneSettingsValue(currentItem);
|
|
2115
|
+
for (const [field, contributedValue] of Object.entries(contributedItem)) {
|
|
2116
|
+
if (field === mergeKey || !isPlainObject(contributedValue) || !isPlainObject(updated[field])) {
|
|
2117
|
+
continue;
|
|
2118
|
+
}
|
|
2119
|
+
const previousObject = isPlainObject(previousItem) && isPlainObject(previousItem[field]) ? previousItem[field] : void 0;
|
|
2120
|
+
const otherObjects = matchingOtherItems.map((item) => item[field]).filter(isPlainObject);
|
|
2121
|
+
const nested = removeNestedSettingsContribution(
|
|
2122
|
+
updated[field],
|
|
2123
|
+
contributedValue,
|
|
2124
|
+
previousObject,
|
|
2125
|
+
otherObjects
|
|
2126
|
+
);
|
|
2127
|
+
updated[field] = nested;
|
|
2128
|
+
}
|
|
2129
|
+
next[index] = updated;
|
|
2130
|
+
}
|
|
2131
|
+
return next;
|
|
2132
|
+
}
|
|
2133
|
+
return settingPath.previousValueExists ? cloneSettingsValue(settingPath.previousValue) : void 0;
|
|
2134
|
+
}
|
|
2135
|
+
async function restoreObsoleteSettings(targetDir, previousMeta, nextSettings, existingMetas) {
|
|
1783
2136
|
if (!previousMeta) {
|
|
1784
2137
|
return [];
|
|
1785
2138
|
}
|
|
@@ -1799,12 +2152,30 @@ async function restoreObsoleteSettings(targetDir, previousMeta, nextSettings) {
|
|
|
1799
2152
|
};
|
|
1800
2153
|
for (const member of previousMeta.members) {
|
|
1801
2154
|
for (const settingPath of member.settings?.paths ?? []) {
|
|
1802
|
-
if (nextSettingKeys.has(`${settingPath.targetPath}#${settingPath.path}`)) {
|
|
2155
|
+
if (!settingPath.mergeStrategy && nextSettingKeys.has(`${settingPath.targetPath}#${settingPath.path}`)) {
|
|
2156
|
+
continue;
|
|
2157
|
+
}
|
|
2158
|
+
if (!settingPath.mergeStrategy && isComposableSettingsPath(settingPath.path)) {
|
|
1803
2159
|
continue;
|
|
1804
2160
|
}
|
|
1805
2161
|
const document = await getDocument(settingPath.targetPath);
|
|
1806
2162
|
const segments = settingPath.path.split(".");
|
|
1807
|
-
if (settingPath.
|
|
2163
|
+
if (settingPath.mergeStrategy) {
|
|
2164
|
+
const current = document.hasIn(segments) ? getPlainYamlValue(document, segments) : void 0;
|
|
2165
|
+
const otherManagedValues = listOtherManagedSettingValues(
|
|
2166
|
+
existingMetas,
|
|
2167
|
+
previousMeta.name,
|
|
2168
|
+
settingPath.targetPath,
|
|
2169
|
+
settingPath.path,
|
|
2170
|
+
settingPath.mergeStrategy
|
|
2171
|
+
);
|
|
2172
|
+
const restored = removeManagedSettingContribution(current, settingPath, otherManagedValues);
|
|
2173
|
+
if (restored === void 0) {
|
|
2174
|
+
document.deleteIn(segments);
|
|
2175
|
+
} else {
|
|
2176
|
+
document.setIn(segments, restored);
|
|
2177
|
+
}
|
|
2178
|
+
} else if (settingPath.previousValueExists) {
|
|
1808
2179
|
document.setIn(segments, settingPath.previousValue);
|
|
1809
2180
|
} else {
|
|
1810
2181
|
document.deleteIn(segments);
|
|
@@ -1896,6 +2267,16 @@ async function validateInstallConflicts(targetDir, plan, existingMetas) {
|
|
|
1896
2267
|
const settingsOwnership = buildSettingsOwnershipMap(existingMetas);
|
|
1897
2268
|
const conflicts = [];
|
|
1898
2269
|
const packageJson = await readPackageJson(targetDir);
|
|
2270
|
+
const settingsDocuments = /* @__PURE__ */ new Map();
|
|
2271
|
+
const getSettingsDocument = async (targetPath) => {
|
|
2272
|
+
const cached = settingsDocuments.get(targetPath);
|
|
2273
|
+
if (cached) {
|
|
2274
|
+
return cached;
|
|
2275
|
+
}
|
|
2276
|
+
const document = await readYamlDocument(ensurePathInsideTarget(targetDir, targetPath));
|
|
2277
|
+
settingsDocuments.set(targetPath, document);
|
|
2278
|
+
return document;
|
|
2279
|
+
};
|
|
1899
2280
|
for (const dependency of listNpmDependencies(resolveInstallNpm(plan.manifest))) {
|
|
1900
2281
|
const existing = findPackageDependency(packageJson, dependency.packageName);
|
|
1901
2282
|
if (existing && !isExistingNpmDependencyCompatible(existing, dependency.version)) {
|
|
@@ -1936,8 +2317,41 @@ async function validateInstallConflicts(targetDir, plan, existingMetas) {
|
|
|
1936
2317
|
}
|
|
1937
2318
|
}
|
|
1938
2319
|
for (const item of listPlannedSettingPaths(plan.settings)) {
|
|
2320
|
+
const document = await getSettingsDocument(item.targetPath);
|
|
2321
|
+
const currentValue = document.hasIn(item.segments) ? getPlainYamlValue(document, item.segments) : void 0;
|
|
2322
|
+
if (item.mergeStrategy === "shared-requirement" && !sharedRequirementValuesCompatible(item.path, currentValue, item.value)) {
|
|
2323
|
+
conflicts.push({
|
|
2324
|
+
kind: "setting_value_conflict",
|
|
2325
|
+
path: `${item.targetPath}#${item.path}`,
|
|
2326
|
+
sourcePath: item.sourceRelativePath,
|
|
2327
|
+
memberName: item.memberName,
|
|
2328
|
+
memberType: "settings",
|
|
2329
|
+
settingPath: item.path,
|
|
2330
|
+
currentValue,
|
|
2331
|
+
nextValue: item.value,
|
|
2332
|
+
message: `${item.targetPath}#${item.path} has an incompatible shared requirement value`
|
|
2333
|
+
});
|
|
2334
|
+
continue;
|
|
2335
|
+
}
|
|
2336
|
+
if (item.mergeStrategy === "merge-by-key") {
|
|
2337
|
+
const conflict = findMergeByKeyConflict(currentValue, item.value, item.mergeKey ?? "code");
|
|
2338
|
+
if (conflict) {
|
|
2339
|
+
conflicts.push({
|
|
2340
|
+
kind: "setting_value_conflict",
|
|
2341
|
+
path: `${item.targetPath}#${item.path}`,
|
|
2342
|
+
sourcePath: item.sourceRelativePath,
|
|
2343
|
+
memberName: item.memberName,
|
|
2344
|
+
memberType: "settings",
|
|
2345
|
+
settingPath: item.path,
|
|
2346
|
+
currentValue: conflict.currentValue,
|
|
2347
|
+
nextValue: conflict.nextValue,
|
|
2348
|
+
message: `${item.targetPath}#${item.path} contains an incompatible keyed setting value`
|
|
2349
|
+
});
|
|
2350
|
+
continue;
|
|
2351
|
+
}
|
|
2352
|
+
}
|
|
1939
2353
|
const owner = settingsOwnership.get(`${item.targetPath}#${item.path}`);
|
|
1940
|
-
if (owner && owner !== plan.manifest.name) {
|
|
2354
|
+
if (!item.mergeStrategy && owner && owner !== plan.manifest.name) {
|
|
1941
2355
|
conflicts.push({
|
|
1942
2356
|
kind: "owned_by_other_addon",
|
|
1943
2357
|
path: `${item.targetPath}#${item.path}`,
|
|
@@ -2071,12 +2485,13 @@ async function validateUpgradeConflicts(targetDir, plan, existingMetas, previous
|
|
|
2071
2485
|
const segments = settingPath.path.split(".");
|
|
2072
2486
|
const currentValue = document.hasIn(segments) ? getPlainYamlValue(document, segments) : void 0;
|
|
2073
2487
|
const actualSha256 = sha256Value(currentValue);
|
|
2074
|
-
if (actualSha256 === settingPath.sha256) {
|
|
2075
|
-
continue;
|
|
2076
|
-
}
|
|
2077
2488
|
const settingKey = `${settingPath.targetPath}#${settingPath.path}`;
|
|
2078
2489
|
const isStillManaged = nextSettingKeys.has(settingKey);
|
|
2079
2490
|
const nextSetting = plannedSettingsByKey.get(settingKey);
|
|
2491
|
+
const contributionPresent = settingPath.mergeStrategy ? managedSettingContributionPresent(currentValue, settingPath) : nextSetting?.mergeStrategy ? plannedSettingContributionPresent(currentValue, nextSetting, settingPath.previousValue) : actualSha256 === settingPath.sha256;
|
|
2492
|
+
if (contributionPresent) {
|
|
2493
|
+
continue;
|
|
2494
|
+
}
|
|
2080
2495
|
conflicts.push({
|
|
2081
2496
|
kind: isStillManaged ? "managed_file_modified" : "obsolete_file_modified",
|
|
2082
2497
|
path: settingKey,
|
|
@@ -2094,8 +2509,24 @@ async function validateUpgradeConflicts(targetDir, plan, existingMetas, previous
|
|
|
2094
2509
|
}
|
|
2095
2510
|
}
|
|
2096
2511
|
for (const item of plannedSettings) {
|
|
2512
|
+
const document = await getSettingsDocument(item.targetPath);
|
|
2513
|
+
const currentValue = document.hasIn(item.segments) ? getPlainYamlValue(document, item.segments) : void 0;
|
|
2514
|
+
if (item.mergeStrategy === "shared-requirement" && !sharedRequirementValuesCompatible(item.path, currentValue, item.value)) {
|
|
2515
|
+
conflicts.push({
|
|
2516
|
+
kind: "setting_value_conflict",
|
|
2517
|
+
path: `${item.targetPath}#${item.path}`,
|
|
2518
|
+
sourcePath: item.sourceRelativePath,
|
|
2519
|
+
memberName: item.memberName,
|
|
2520
|
+
memberType: "settings",
|
|
2521
|
+
settingPath: item.path,
|
|
2522
|
+
currentValue,
|
|
2523
|
+
nextValue: item.value,
|
|
2524
|
+
message: `${item.targetPath}#${item.path} has an incompatible shared requirement value`
|
|
2525
|
+
});
|
|
2526
|
+
continue;
|
|
2527
|
+
}
|
|
2097
2528
|
const owner = settingsOwnership.get(`${item.targetPath}#${item.path}`);
|
|
2098
|
-
if (owner) {
|
|
2529
|
+
if (!item.mergeStrategy && owner) {
|
|
2099
2530
|
conflicts.push({
|
|
2100
2531
|
kind: "owned_by_other_addon",
|
|
2101
2532
|
path: `${item.targetPath}#${item.path}`,
|
|
@@ -2163,7 +2594,12 @@ async function materializeAddon(options) {
|
|
|
2163
2594
|
await validateUpgradeConflicts(targetDir, plan, existingMetas, previousMeta);
|
|
2164
2595
|
}
|
|
2165
2596
|
const removedFiles = previousMeta ? await removeObsoleteFiles(targetDir, previousMeta, new Set(plan.files.map((file) => file.targetPath))) : [];
|
|
2166
|
-
const restoredSettingsFiles = await restoreObsoleteSettings(
|
|
2597
|
+
const restoredSettingsFiles = await restoreObsoleteSettings(
|
|
2598
|
+
targetDir,
|
|
2599
|
+
previousMeta,
|
|
2600
|
+
plan.settings,
|
|
2601
|
+
existingMetas
|
|
2602
|
+
);
|
|
2167
2603
|
const npm = resolveInstallNpm(plan.manifest);
|
|
2168
2604
|
const packageJsonFiles = await applyNpmDependencies(targetDir, npm);
|
|
2169
2605
|
await writePlannedFiles(targetDir, plan.files);
|