





















@@ -470,52 +470,54 @@ function assertNonDestructiveReplacement(params: {
470470}
471471}
472472473-function unsetAtPath(root: Record<string, unknown>, path: PathSegment[]): boolean {
473+type UnsetAtPathResult = { removed: true; leafContainer: "array" | "object" } | { removed: false };
474+475+function unsetAtPath(root: Record<string, unknown>, path: PathSegment[]): UnsetAtPathResult {
474476let current: unknown = root;
475477for (let i = 0; i < path.length - 1; i += 1) {
476478const segment = path[i];
477479if (!current || typeof current !== "object") {
478-return false;
480+return { removed: false };
479481}
480482if (Array.isArray(current)) {
481483if (!isIndexSegment(segment)) {
482-return false;
484+return { removed: false };
483485}
484486const index = Number.parseInt(segment, 10);
485487if (!Number.isFinite(index) || index < 0 || index >= current.length) {
486-return false;
488+return { removed: false };
487489}
488490current = current[index];
489491continue;
490492}
491493const record = current as Record<string, unknown>;
492494if (!hasOwnPathKey(record, segment)) {
493-return false;
495+return { removed: false };
494496}
495497current = record[segment];
496498}
497499498500const last = path[path.length - 1];
499501if (Array.isArray(current)) {
500502if (!isIndexSegment(last)) {
501-return false;
503+return { removed: false };
502504}
503505const index = Number.parseInt(last, 10);
504506if (!Number.isFinite(index) || index < 0 || index >= current.length) {
505-return false;
507+return { removed: false };
506508}
507509current.splice(index, 1);
508-return true;
510+return { removed: true, leafContainer: "array" };
509511}
510512if (!current || typeof current !== "object") {
511-return false;
513+return { removed: false };
512514}
513515const record = current as Record<string, unknown>;
514516if (!hasOwnPathKey(record, last)) {
515-return false;
517+return { removed: false };
516518}
517519delete record[last];
518-return true;
520+return { removed: true, leafContainer: "object" };
519521}
520522521523async function loadValidConfig(runtime: RuntimeEnv = defaultRuntime) {
@@ -1692,16 +1694,18 @@ export async function runConfigUnset(opts: { path: string; runtime?: RuntimeEnv
16921694// instead of snapshot.config (runtime-merged with defaults).
16931695// This prevents runtime defaults from leaking into the written config file (issue #6070)
16941696const next = structuredClone(snapshot.resolved) as Record<string, unknown>;
1695-const removed = unsetAtPath(next, parsedPath);
1696-if (!removed) {
1697+const unsetResult = unsetAtPath(next, parsedPath);
1698+if (!unsetResult.removed) {
16971699runtime.error(danger(`Config path not found: ${opts.path}`));
16981700runtime.exit(1);
16991701return;
17001702}
17011703await replaceConfigFile({
17021704nextConfig: next,
17031705 ...(snapshot.hash !== undefined ? { baseHash: snapshot.hash } : {}),
1704-writeOptions: { unsetPaths: [parsedPath] },
1706+ ...(unsetResult.leafContainer === "array"
1707+ ? {}
1708+ : { writeOptions: { unsetPaths: [parsedPath] } }),
17051709});
17061710runtime.log(info(`Removed ${opts.path}. Restart the gateway to apply.`));
17071711} catch (err) {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。