mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-17 16:31:36 +00:00
* feat(ui): add plugin catalog management * feat(gateway): add plugins.uninstall and richer plugin catalog metadata Adds a plugins.uninstall gateway method (operator.admin, control-plane write) backed by a lock-guarded uninstallManagedPlugin that mirrors the CLI flow: config cleanup, install-record removal, managed file deletion, and registry refresh. Bundled plugins stay disable-only. Catalog entries now carry a manifest-derived category and a removable flag; ClawHub search results expose download counts and verification tiers. * feat(ui): redesign plugins page with inventory, store shelves, and cover art Rebuilds /settings/plugins around three tabs: Installed (category-grouped inventory with overview stats, state filters, uninstall for external plugins, and inline MCP server management through the shared config seam), Discover (featured/official shelves plus one-click MCP connectors and curated ClawHub searches), and ClawHub (search with download counts and verification badges). Every catalog entry renders bundled cover art or a deterministic gradient monogram tile - no more empty boxes. Artwork generated with Codex CLI, shipped as 512px WebP under ui/public/plugin-art. * chore(ui): regenerate locale bundles for plugins manager strings * docs: describe plugins manager tabs, uninstall, and MCP connectors * fix(plugins): human catalog labels and un-pinned hosted fallback ids listManagedPlugins now prefers manifest names over registry package-name backfill, falls back to channel catalog labels and blurbs, and stops pinning expectedPluginId when a hosted feed entry only exposes its package name (which rejected every legitimate install of that package). Found via live gateway testing against ClawHub. * fix(ui): send minimal RFC 7396 merge patches for MCP server edits config.patch merges rather than replaces, so key removal needs an explicit null; sending the full config back made MCP server removal a no-op. Found via live gateway testing. * fix(ui): write explicit MCP transports for URL servers The MCP runtime defaults URL-only servers to SSE, so streamable HTTP endpoints saved by the add form or connector templates would fail at connect time. Connector templates now declare their transport and the add form infers streamable-http unless the URL follows the /sse convention. Flagged by autoreview against the transport resolver. * test(ui): wait for deferred plugin requests before resolving in e2e * feat(ui): plugins detail view, action menus, and unified ClawHub search Reworks the plugins page from PR #103176 feedback: merges the ClawHub tab into Discover (typing searches ClawHub inline and appends a quiet From ClawHub section, with Browse ClawHub demoted to a header text link), makes every row and store card open a plugin detail overlay (hero art, primary enable/install action, metadata table), and replaces enable/disable switches with a state chip plus an overflow menu (Enable/Disable, Remove for external plugins, View details) matching the ChatGPT-store install+menu pattern. MCP rows use the same menu; refresh is now icon-only. * chore(ui): regenerate locale bundles for plugins UI iteration * feat(ui): vetted, grouped connector catalog for the plugins store Expands Connect your world to 28 connectors organized into use-case shelves (Work & productivity, Coding & infrastructure, Home & media, Everyday life). Every entry passed a three-stage subagent review: official-docs verification plus live endpoint probes for MCP servers, ClawHub result-quality and malware/typosquat screening for curated searches, and an adversarial pass that dynamically registered OAuth clients to prove one-click viability. That review removed Figma (registration allowlisted, 403) and Atlassian (OAuth issuer-mismatch bug upstream), downgraded GitHub to PAT-based setup (no dynamic client registration upstream), fixed Linear (/sse retired) and Home Assistant (/api/mcp, streamable HTTP) endpoints, retargeted poisoned or dead searches (youtube, finance, hue dropped; calendar -> google calendar; stocks replaces finance), and added Todoist, Airtable, Canva, Stripe, Context7, DeepWiki, Hugging Face one-click MCP servers plus Jira, PDF, transcription, Kubernetes, Reddit, maps, translation, and notes searches. Keyless servers get a ready-to-use success message; new cover art included. * chore(ui): regenerate locale bundles for connector groups * fix(plugins): suppress hosted catalog rows once their package is installed Hosted feed entries without a declared runtime id fall back to their package name as catalog id, which never matches the installed runtime id, so the Discover shelf kept offering an already-installed package. Installed package names now also suppress official rows. Flagged by autoreview. * fix(plugins): pin declared runtime ids and surface connector errors in place The runtime-id pin now keys off explicitly declared catalog ids (plugin, channel, or provider) instead of string-comparing against the package name, so declared ids that equal their package name stay enforced while entry-id fallbacks stay unpinned. Connector add failures on Discover now render on the triggering card instead of the Installed tab's MCP section. Both flagged by autoreview; regression tests included. * feat(ui): full inventory artwork, pulse header, and two-column plugin list Every bundled plugin now ships distinctive cover art (113 new Codex CLI illustrations; 172 total, ~2.1MB WebP), so inventory rows and detail views never fall back to monogram tiles. The four stat cards give way to a compact inventory pulse: a segmented enabled/disabled/issues meter whose legend and counts live inside the filter chips. Inventory, MCP, and search rows flow into two columns when the panel is wide enough. * chore(ui): regenerate locale bundles for pulse header * fix(ui): omit stdio args from the MCP server row target Stdio MCP args routinely carry tokens, and the inventory is visible to read-only operators; mirror the config page and show only the command. Flagged by autoreview; regression test included. * fix(merge): point crestodian setup at relocated plugin commit/refresh modules * fix(merge): add bootstrapToken to plugins page test gateway harness * fix(plugins): name catalog install-action branches so Swift emits the union * fix(ui): satisfy strict lint on plugins page form parsing and mocks * chore(build): regen docs map, raise plugin-sdk declaration budget for new protocol surface * fix(ui): type the plugins page patch mock with its real call signature
471 lines
16 KiB
TypeScript
471 lines
16 KiB
TypeScript
// Commit helpers that move transient plugin install records into the persisted install index.
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { isDeepStrictEqual } from "node:util";
|
|
import {
|
|
replaceConfigFile,
|
|
resolveConfigWriteAfterWrite,
|
|
transformConfigFileWithRetry,
|
|
type ConfigMutationCommit,
|
|
type ConfigReplaceResult,
|
|
type ConfigMutationResult,
|
|
type TransformConfigFileWithRetryParams,
|
|
} from "../config/config.js";
|
|
import type { ConfigWriteOptions } from "../config/io.js";
|
|
import { extractShippedPluginInstallConfigRecords } from "../config/plugin-install-config-migration.js";
|
|
import type { OpenClawConfig } from "../config/types.openclaw.js";
|
|
import type { PluginInstallRecord } from "../config/types.plugins.js";
|
|
import { isPathInside } from "../infra/path-guards.js";
|
|
import {
|
|
loadInstalledPluginIndexInstallRecords,
|
|
PLUGIN_INSTALLS_CONFIG_PATH,
|
|
withoutPluginInstallRecords,
|
|
writePersistedInstalledPluginIndexInstallRecords,
|
|
} from "./installed-plugin-index-records.js";
|
|
import {
|
|
clearRetainedManagedNpmInstallMarker,
|
|
markRetainedManagedNpmInstall,
|
|
resolveRetainedManagedNpmInstallPackageInfo,
|
|
resolveRetainedManagedNpmInstallMarkerPath,
|
|
} from "./managed-npm-retention.js";
|
|
import { planPluginUninstall } from "./uninstall.js";
|
|
|
|
function mergeUnsetPaths(
|
|
left?: ConfigWriteOptions["unsetPaths"],
|
|
right?: ConfigWriteOptions["unsetPaths"],
|
|
): ConfigWriteOptions["unsetPaths"] | undefined {
|
|
const merged = [...(left ?? []), ...(right ?? [])];
|
|
return merged.length > 0 ? merged : undefined;
|
|
}
|
|
|
|
/** Return whether config still contains legacy/transient plugin install records. */
|
|
export function hasPendingPluginInstallRecords(config: OpenClawConfig): boolean {
|
|
return Object.keys(config.plugins?.installs ?? {}).length > 0;
|
|
}
|
|
|
|
/** Find pending install records that match the base config and can be stripped as unchanged. */
|
|
export function unchangedPendingPluginInstallRecordIds(
|
|
config: OpenClawConfig,
|
|
baseConfig: OpenClawConfig,
|
|
): string[] {
|
|
const pendingInstalls = config.plugins?.installs ?? {};
|
|
return Object.entries(baseConfig.plugins?.installs ?? {})
|
|
.filter(([pluginId, baseInstall]) => isDeepStrictEqual(pendingInstalls[pluginId], baseInstall))
|
|
.map(([pluginId]) => pluginId);
|
|
}
|
|
|
|
/** Remove pending plugin install records from config, optionally only for selected ids. */
|
|
export function stripPendingPluginInstallRecords(
|
|
config: OpenClawConfig,
|
|
pluginIds?: Iterable<string>,
|
|
): OpenClawConfig {
|
|
if (!pluginIds) {
|
|
return withoutPluginInstallRecords(config);
|
|
}
|
|
const removeIds = new Set(pluginIds);
|
|
if (removeIds.size === 0 || !config.plugins?.installs) {
|
|
return config;
|
|
}
|
|
const remainingInstalls = Object.fromEntries(
|
|
Object.entries(config.plugins.installs).filter(([pluginId]) => !removeIds.has(pluginId)),
|
|
);
|
|
if (Object.keys(remainingInstalls).length === 0) {
|
|
return withoutPluginInstallRecords(config);
|
|
}
|
|
return {
|
|
...config,
|
|
plugins: {
|
|
...config.plugins,
|
|
installs: remainingInstalls,
|
|
},
|
|
};
|
|
}
|
|
|
|
type ConfigCommit = (
|
|
config: OpenClawConfig,
|
|
writeOptions?: ConfigWriteOptions,
|
|
) => Promise<ConfigReplaceResult | void>;
|
|
const PLUGIN_SOURCE_CHANGED_RESTART_REASON = "plugin source changed";
|
|
|
|
function mergeAfterWrite(
|
|
writeOptions: ConfigWriteOptions | undefined,
|
|
afterWrite: ConfigWriteOptions["afterWrite"],
|
|
): ConfigWriteOptions | undefined {
|
|
if (afterWrite === undefined) {
|
|
return writeOptions;
|
|
}
|
|
return {
|
|
...writeOptions,
|
|
afterWrite,
|
|
};
|
|
}
|
|
|
|
function installPathsOverlap(left: string, right: string): boolean {
|
|
const resolvedLeft = path.resolve(left);
|
|
const resolvedRight = path.resolve(right);
|
|
return (
|
|
resolvedLeft === resolvedRight ||
|
|
isPathInside(resolvedLeft, resolvedRight) ||
|
|
isPathInside(resolvedRight, resolvedLeft)
|
|
);
|
|
}
|
|
|
|
function resolveRetainedManagedNpmInstallMarkerTarget(params: {
|
|
pluginId: string;
|
|
previousRecord?: PluginInstallRecord;
|
|
nextRecord?: PluginInstallRecord;
|
|
}): string | null {
|
|
if (params.previousRecord?.source !== "npm" || params.nextRecord?.source !== "npm") {
|
|
return null;
|
|
}
|
|
const previousInstallPath = params.previousRecord.installPath?.trim();
|
|
const nextInstallPath = params.nextRecord.installPath?.trim();
|
|
if (!previousInstallPath || !nextInstallPath) {
|
|
return null;
|
|
}
|
|
if (installPathsOverlap(previousInstallPath, nextInstallPath)) {
|
|
return null;
|
|
}
|
|
|
|
const plan = planPluginUninstall({
|
|
config: {
|
|
plugins: {
|
|
installs: {
|
|
[params.pluginId]: params.previousRecord,
|
|
},
|
|
},
|
|
} as OpenClawConfig,
|
|
pluginId: params.pluginId,
|
|
deleteFiles: true,
|
|
});
|
|
if (
|
|
!plan.ok ||
|
|
!plan.directoryRemoval ||
|
|
plan.directoryRemoval.cleanup?.kind !== "npm" ||
|
|
path.resolve(plan.directoryRemoval.target) !== path.resolve(previousInstallPath)
|
|
) {
|
|
return null;
|
|
}
|
|
if (installPathsOverlap(plan.directoryRemoval.target, nextInstallPath)) {
|
|
return null;
|
|
}
|
|
return plan.directoryRemoval.target;
|
|
}
|
|
|
|
function resolveNpmInstallRecordPackageName(record: PluginInstallRecord): string | null {
|
|
if (record.source !== "npm" || !record.installPath?.trim()) {
|
|
return null;
|
|
}
|
|
return resolveRetainedManagedNpmInstallPackageInfo(record.installPath)?.packageName ?? null;
|
|
}
|
|
|
|
function findReplacementNpmRecordForRemovedRecord(params: {
|
|
previousRecord: PluginInstallRecord;
|
|
nextInstallRecords: Record<string, PluginInstallRecord>;
|
|
}): PluginInstallRecord | null {
|
|
const previousPackageName = resolveNpmInstallRecordPackageName(params.previousRecord);
|
|
if (!previousPackageName) {
|
|
return null;
|
|
}
|
|
for (const nextRecord of Object.values(params.nextInstallRecords)) {
|
|
if (resolveNpmInstallRecordPackageName(nextRecord) === previousPackageName) {
|
|
return nextRecord;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
async function markRetainedReplacedManagedNpmInstallRecords(params: {
|
|
previousInstallRecords: Record<string, PluginInstallRecord>;
|
|
nextInstallRecords: Record<string, PluginInstallRecord>;
|
|
createdMarkerPaths: string[];
|
|
}): Promise<void> {
|
|
const markedPreviousPluginIds = new Set<string>();
|
|
const markReplacement = async (
|
|
pluginId: string,
|
|
previousRecord: PluginInstallRecord | undefined,
|
|
nextRecord: PluginInstallRecord | undefined,
|
|
) => {
|
|
const packageDir = resolveRetainedManagedNpmInstallMarkerTarget({
|
|
pluginId,
|
|
previousRecord,
|
|
nextRecord,
|
|
});
|
|
if (!packageDir) {
|
|
return;
|
|
}
|
|
const markerPath = resolveRetainedManagedNpmInstallMarkerPath(packageDir);
|
|
const markerAlreadyExisted = fs.existsSync(markerPath);
|
|
const marked = await markRetainedManagedNpmInstall({
|
|
packageDir,
|
|
pluginId,
|
|
reason: "replaced-by-managed-npm-generation-update",
|
|
});
|
|
if (marked && !markerAlreadyExisted) {
|
|
// Record each marker immediately so a later filesystem failure can roll it back.
|
|
params.createdMarkerPaths.push(markerPath);
|
|
}
|
|
markedPreviousPluginIds.add(pluginId);
|
|
};
|
|
|
|
for (const [pluginId, nextRecord] of Object.entries(params.nextInstallRecords)) {
|
|
await markReplacement(pluginId, params.previousInstallRecords[pluginId], nextRecord);
|
|
}
|
|
for (const [pluginId, previousRecord] of Object.entries(params.previousInstallRecords)) {
|
|
if (markedPreviousPluginIds.has(pluginId) || params.nextInstallRecords[pluginId]) {
|
|
continue;
|
|
}
|
|
await markReplacement(
|
|
pluginId,
|
|
previousRecord,
|
|
findReplacementNpmRecordForRemovedRecord({
|
|
previousRecord,
|
|
nextInstallRecords: params.nextInstallRecords,
|
|
}) ?? undefined,
|
|
);
|
|
}
|
|
}
|
|
|
|
async function removeCreatedRetainedManagedNpmInstallMarkers(markerPaths: string[]): Promise<void> {
|
|
for (const markerPath of markerPaths) {
|
|
await fs.promises.rm(markerPath, { force: true });
|
|
}
|
|
}
|
|
|
|
async function clearActiveRetainedManagedNpmInstallMarkers(
|
|
nextInstallRecords: Record<string, PluginInstallRecord>,
|
|
): Promise<Array<{ markerPath: string; contents: string }>> {
|
|
const clearedMarkers: Array<{ markerPath: string; contents: string }> = [];
|
|
for (const record of Object.values(nextInstallRecords)) {
|
|
if (record.source !== "npm" || !record.installPath?.trim()) {
|
|
continue;
|
|
}
|
|
let markerPath: string;
|
|
try {
|
|
markerPath = resolveRetainedManagedNpmInstallMarkerPath(record.installPath);
|
|
} catch {
|
|
continue;
|
|
}
|
|
let contents: string;
|
|
try {
|
|
contents = await fs.promises.readFile(markerPath, "utf8");
|
|
} catch (error) {
|
|
if ((error as NodeJS.ErrnoException).code === "ENOENT") {
|
|
continue;
|
|
}
|
|
throw error;
|
|
}
|
|
const cleared = await clearRetainedManagedNpmInstallMarker(record.installPath);
|
|
if (cleared) {
|
|
clearedMarkers.push({ markerPath, contents });
|
|
}
|
|
}
|
|
return clearedMarkers;
|
|
}
|
|
|
|
async function restoreClearedRetainedManagedNpmInstallMarkers(
|
|
markerSnapshots: Array<{ markerPath: string; contents: string }>,
|
|
): Promise<void> {
|
|
for (const snapshot of markerSnapshots) {
|
|
await fs.promises.mkdir(path.dirname(snapshot.markerPath), { recursive: true });
|
|
await fs.promises.writeFile(snapshot.markerPath, snapshot.contents, "utf8");
|
|
}
|
|
}
|
|
|
|
async function commitPluginInstallRecordsWithWriter(params: {
|
|
previousInstallRecords?: Record<string, PluginInstallRecord>;
|
|
nextInstallRecords: Record<string, PluginInstallRecord>;
|
|
nextConfig: OpenClawConfig;
|
|
writeOptions?: ConfigWriteOptions;
|
|
commit: ConfigCommit;
|
|
}): Promise<ConfigReplaceResult | void> {
|
|
const previousInstallRecords =
|
|
params.previousInstallRecords ?? (await loadInstalledPluginIndexInstallRecords());
|
|
const retainedMarkerPaths: string[] = [];
|
|
const clearedMarkerSnapshots: Array<{ markerPath: string; contents: string }> = [];
|
|
try {
|
|
await writePersistedInstalledPluginIndexInstallRecords(params.nextInstallRecords);
|
|
try {
|
|
await markRetainedReplacedManagedNpmInstallRecords({
|
|
previousInstallRecords,
|
|
nextInstallRecords: params.nextInstallRecords,
|
|
// Keep partial progress visible to the outer rollback path.
|
|
createdMarkerPaths: retainedMarkerPaths,
|
|
});
|
|
clearedMarkerSnapshots.push(
|
|
...(await clearActiveRetainedManagedNpmInstallMarkers(params.nextInstallRecords)),
|
|
);
|
|
const installRecordsChanged = !isDeepStrictEqual(
|
|
previousInstallRecords,
|
|
params.nextInstallRecords,
|
|
);
|
|
return await params.commit(params.nextConfig, {
|
|
...params.writeOptions,
|
|
...(installRecordsChanged && params.writeOptions?.afterWrite === undefined
|
|
? { afterWrite: { mode: "restart", reason: PLUGIN_SOURCE_CHANGED_RESTART_REASON } }
|
|
: {}),
|
|
unsetPaths: mergeUnsetPaths(params.writeOptions?.unsetPaths, [
|
|
Array.from(PLUGIN_INSTALLS_CONFIG_PATH),
|
|
]),
|
|
});
|
|
} catch (error) {
|
|
try {
|
|
// Keep config and install index atomic from the caller's perspective.
|
|
await writePersistedInstalledPluginIndexInstallRecords(previousInstallRecords);
|
|
} catch (rollbackError) {
|
|
throw new Error(
|
|
"Failed to commit plugin install records and could not restore the previous plugin index",
|
|
{ cause: rollbackError },
|
|
);
|
|
}
|
|
throw error;
|
|
}
|
|
} catch (error) {
|
|
await restoreClearedRetainedManagedNpmInstallMarkers(clearedMarkerSnapshots);
|
|
await removeCreatedRetainedManagedNpmInstallMarkers(retainedMarkerPaths);
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
/** Persist plugin install records and commit the matching config update to disk. */
|
|
export async function commitPluginInstallRecordsWithConfig(params: {
|
|
previousInstallRecords?: Record<string, PluginInstallRecord>;
|
|
nextInstallRecords: Record<string, PluginInstallRecord>;
|
|
nextConfig: OpenClawConfig;
|
|
baseHash?: string;
|
|
writeOptions?: ConfigWriteOptions;
|
|
}): Promise<void> {
|
|
await commitPluginInstallRecordsWithWriter({
|
|
...params,
|
|
commit: async (nextConfig, writeOptions) => {
|
|
return await replaceConfigFile({
|
|
nextConfig,
|
|
...(params.baseHash !== undefined ? { baseHash: params.baseHash } : {}),
|
|
...(writeOptions ? { writeOptions } : {}),
|
|
});
|
|
},
|
|
});
|
|
}
|
|
|
|
/** Commit config while migrating any pending install records into the install index. */
|
|
export async function commitConfigWriteWithPendingPluginInstalls(params: {
|
|
nextConfig: OpenClawConfig;
|
|
/** Source snapshot whose transient records migrate below the canonical index. */
|
|
sourceConfig?: OpenClawConfig;
|
|
writeOptions?: ConfigWriteOptions;
|
|
commit: ConfigCommit;
|
|
}): Promise<{
|
|
config: OpenClawConfig;
|
|
installRecords: Record<string, PluginInstallRecord>;
|
|
movedInstallRecords: boolean;
|
|
persistedHash: string | null;
|
|
}> {
|
|
const sourceInstallRecords = extractShippedPluginInstallConfigRecords(params.sourceConfig);
|
|
const nextPendingConfig = params.sourceConfig
|
|
? stripPendingPluginInstallRecords(
|
|
params.nextConfig,
|
|
unchangedPendingPluginInstallRecordIds(params.nextConfig, {
|
|
plugins: { installs: sourceInstallRecords },
|
|
}),
|
|
)
|
|
: params.nextConfig;
|
|
if (
|
|
Object.keys(sourceInstallRecords).length === 0 &&
|
|
!hasPendingPluginInstallRecords(nextPendingConfig)
|
|
) {
|
|
const committed = params.writeOptions
|
|
? await params.commit(params.nextConfig, params.writeOptions)
|
|
: await params.commit(params.nextConfig);
|
|
return {
|
|
config: params.nextConfig,
|
|
installRecords: {},
|
|
movedInstallRecords: false,
|
|
persistedHash: committed?.persistedHash ?? null,
|
|
};
|
|
}
|
|
|
|
const pendingInstallRecords = nextPendingConfig.plugins?.installs ?? {};
|
|
const previousInstallRecords = await loadInstalledPluginIndexInstallRecords();
|
|
const nextInstallRecords = {
|
|
...sourceInstallRecords,
|
|
...previousInstallRecords,
|
|
...pendingInstallRecords,
|
|
};
|
|
const strippedConfig = withoutPluginInstallRecords(params.nextConfig);
|
|
const committed = await commitPluginInstallRecordsWithWriter({
|
|
previousInstallRecords,
|
|
nextInstallRecords,
|
|
nextConfig: strippedConfig,
|
|
...(params.writeOptions ? { writeOptions: params.writeOptions } : {}),
|
|
commit: params.commit,
|
|
});
|
|
return {
|
|
config: strippedConfig,
|
|
installRecords: nextInstallRecords,
|
|
movedInstallRecords: true,
|
|
persistedHash: committed?.persistedHash ?? null,
|
|
};
|
|
}
|
|
|
|
/** Replace the config file after moving pending plugin install records into the install index. */
|
|
export async function commitConfigWithPendingPluginInstalls(params: {
|
|
nextConfig: OpenClawConfig;
|
|
baseHash?: string;
|
|
writeOptions?: ConfigWriteOptions;
|
|
}): Promise<{
|
|
config: OpenClawConfig;
|
|
installRecords: Record<string, PluginInstallRecord>;
|
|
movedInstallRecords: boolean;
|
|
persistedHash: string | null;
|
|
}> {
|
|
return await commitConfigWriteWithPendingPluginInstalls({
|
|
nextConfig: params.nextConfig,
|
|
...(params.writeOptions ? { writeOptions: params.writeOptions } : {}),
|
|
commit: async (nextConfig, writeOptions) => {
|
|
return await replaceConfigFile({
|
|
nextConfig,
|
|
...(params.baseHash !== undefined ? { baseHash: params.baseHash } : {}),
|
|
...(writeOptions ? { writeOptions } : {}),
|
|
});
|
|
},
|
|
});
|
|
}
|
|
|
|
/** Transform config with retry support while preserving plugin install index consistency. */
|
|
export async function transformConfigWithPendingPluginInstalls<T = void>(
|
|
params: Omit<TransformConfigFileWithRetryParams<T>, "commit">,
|
|
): Promise<ConfigMutationResult<T>> {
|
|
const commit: ConfigMutationCommit = async ({ nextConfig, snapshot, baseHash, writeOptions }) => {
|
|
const requestedAfterWrite = params.afterWrite ?? params.writeOptions?.afterWrite;
|
|
const committed = await commitConfigWriteWithPendingPluginInstalls({
|
|
nextConfig,
|
|
sourceConfig: snapshot.sourceConfig,
|
|
...(writeOptions ? { writeOptions: mergeAfterWrite(writeOptions, params.afterWrite) } : {}),
|
|
commit: async (config, commitWriteOptions) => {
|
|
return await replaceConfigFile({
|
|
nextConfig: config,
|
|
snapshot,
|
|
writeOptions: commitWriteOptions ?? {},
|
|
...(baseHash !== undefined ? { baseHash } : {}),
|
|
});
|
|
},
|
|
});
|
|
const afterWrite = resolveConfigWriteAfterWrite(
|
|
requestedAfterWrite ??
|
|
(committed.movedInstallRecords
|
|
? { mode: "restart", reason: PLUGIN_SOURCE_CHANGED_RESTART_REASON }
|
|
: undefined),
|
|
);
|
|
return {
|
|
config: committed.config,
|
|
persistedHash: committed.persistedHash,
|
|
afterWrite,
|
|
};
|
|
};
|
|
|
|
return await transformConfigFileWithRetry<T>({
|
|
...params,
|
|
commit,
|
|
});
|
|
}
|