diff --git a/lib/core.js b/lib/core.js index 6928bdc..338e953 100644 --- a/lib/core.js +++ b/lib/core.js @@ -3817,7 +3817,7 @@ const NEW_TOOL_PATCHES = [ "\t\tthis.ensureLegacyDocument();\n" + "\t\tconst stored = this.legacyDocument[ns];\n" + "\t\tconst user = isPlainObject(stored) ? stored : void 0;\n" + - "\t\tconst resolved = plainConfig(schema(mergeLayers(options?.base, user))); // [dsh-purge] #86 plainConfig before validate\n" + + "\t\tconst resolved = plainConfig(schema(mergeLayers(options?.base ?? {}, user ?? {}))); // [dsh-purge] #86 plainConfig before validate + #89 ?? {} 兜 over=undefined 丢 base\n" + "\t\toptions?.validate?.(resolved);\n" + "\t\tconst registration = {\n" + "\t\t\tns,\n" + @@ -3891,7 +3891,7 @@ const NEW_TOOL_PATCHES = [ "\t\tif (registration === void 0) throw new Error(`settings namespace \"${ns}\" is not registered`);\n" + "\t\tif (expectedRevision !== void 0 && registration.revision !== expectedRevision) throw new SettingsConflictError(ns, expectedRevision, registration.revision);\n" + "\t\tconst user = change(registration.user);\n" + - "\t\tconst next = plainConfig(registration.schema(mergeLayers(registration.base, user))); // [dsh-purge] #86 plainConfig before validate\n" + + "\t\tconst next = plainConfig(registration.schema(mergeLayers(registration.base ?? {}, user ?? {}))); // [dsh-purge] #86 plainConfig before validate + #89 ?? {} 兜 over=undefined 丢 base\n" + "\t\tregistration.validate?.(next);\n" + "\t\tconst prev = registration.resolved;\n" + "\t\tregistration.user = user;\n" + @@ -3960,25 +3960,46 @@ const NEW_TOOL_PATCHES = [ }, { // #86 升级:老用户早期产物没过 plainConfig,volatile 字段漏进 validate。 + // #89 升级:同一行要补 `?? {}` 兜底 — mergeLayers(over=undefined) 原语会返回 undefined, + // 导致 schema(undefined) 填默认值,options.base 整段静默丢弃。两 fix 互补。 pattern: "\t\tconst resolved = schema(mergeLayers(options?.base, user));\n" + "\t\toptions?.validate?.(resolved);", replace: - "\t\tconst resolved = plainConfig(schema(mergeLayers(options?.base, user))); // [dsh-purge] #86 plainConfig before validate\n" + + "\t\tconst resolved = plainConfig(schema(mergeLayers(options?.base ?? {}, user ?? {}))); // [dsh-purge] #86 plainConfig before validate + #89 ?? {} 兜 over=undefined 丢 base\n" + "\t\toptions?.validate?.(resolved);", }, { // #86 升级:commitLegacy 同根问题。 + // #89 升级:commitLegacy 同样补 `?? {}` — change(user) 可能返回 undefined,registration.base 建仓时也可能是 undefined。 pattern: "\t\tconst next = registration.schema(mergeLayers(registration.base, user));\n" + "\t\tregistration.validate?.(next);", replace: + "\t\tconst next = plainConfig(registration.schema(mergeLayers(registration.base ?? {}, user ?? {}))); // [dsh-purge] #86 plainConfig before validate + #89 ?? {} 兜 over=undefined 丢 base\n" + + "\t\tregistration.validate?.(next);", + }, + { + // #89 旧 fallback:老用户早已 patch 到 #86 的 plainConfig 但没 `?? {}`,这里把 2 行都升到带兜底版本。 + // match 原子不含注释尾巴,只对**第一次 #86 升级产物**升级一次,带 #89 兜底的产物不会二次匹配。 + pattern: + "\t\tconst resolved = plainConfig(schema(mergeLayers(options?.base, user))); // [dsh-purge] #86 plainConfig before validate\n" + + "\t\toptions?.validate?.(resolved);", + replace: + "\t\tconst resolved = plainConfig(schema(mergeLayers(options?.base ?? {}, user ?? {}))); // [dsh-purge] #86 plainConfig before validate + #89 ?? {} 兜 over=undefined 丢 base\n" + + "\t\toptions?.validate?.(resolved);", + }, + { + pattern: "\t\tconst next = plainConfig(registration.schema(mergeLayers(registration.base, user))); // [dsh-purge] #86 plainConfig before validate\n" + "\t\tregistration.validate?.(next);", + replace: + "\t\tconst next = plainConfig(registration.schema(mergeLayers(registration.base ?? {}, user ?? {}))); // [dsh-purge] #86 plainConfig before validate + #89 ?? {} 兜 over=undefined 丢 base\n" + + "\t\tregistration.validate?.(next);", }, ], - // #86 换 marker:老用户已带 "legacy settings api",但缺 plainConfig —— 必须进 replacements 走升级。 - markers: ["[dsh-purge] #86 plainConfig before validate"], + // #89 换 marker:老用户已带 "#86 plainConfig" 单独 marker,但缺 `?? {}` 兜底 —— 必须进 replacements 走升级。 + markers: ["#89 ?? {} 兜 over=undefined 丢 base"], }, { id: 45, name: "OFFICIAL_DESKTOP_UPDATE_HANDOFF", layer: "代码", layer_en: "Code",