diff --git a/scripts/patch_admin_timeline_ui.py b/scripts/patch_admin_timeline_ui.py index 2ac4689..3bebff0 100644 --- a/scripts/patch_admin_timeline_ui.py +++ b/scripts/patch_admin_timeline_ui.py @@ -26,22 +26,12 @@ def patch_file_manage(path: Path) -> bool: def patch_clipboard(path: Path) -> bool: - text = path.read_text(encoding='utf-8') - old = text - pattern = re.compile( - r'const (?P[A-Za-z_$][\w$]*)=async\(a,e=\{\}\)=>\{.*?\},' - r'(?=[A-Za-z_$][\w$]*=async\(a,e=\{\}\)=>\{)', - re.S, - ) - match = pattern.search(text) - if not match: - return False - name = match.group('name') - replacement = f'''const {name}=async(a,e={{}})=>{{const{{successMsg:t="复制成功",errorMsg:n="复制失败,请手动复制",showMsg:s=!0,notify:c}}=e,l=(r,d)=>{{s&&c?.(r,d)}},q=()=>{{try{{window.prompt("复制下面内容",a)}}catch{{}}}};try{{if(navigator.clipboard&&window.isSecureContext)try{{await navigator.clipboard.writeText(a);return l(t,"success"),!0}}catch{{}}const r=document.createElement("textarea");r.value=a,r.setAttribute("readonly","");r.className="fcbx-copy-fallback";r.style.cssText="position:fixed;left:0;top:0;width:1px;height:1px;opacity:0;z-index:-1";document.body.appendChild(r);r.focus();r.select();r.setSelectionRange(0,r.value.length);let d=!1;try{{d=document.execCommand("copy")}}finally{{document.body.removeChild(r)}}if(d)return l(t,"success"),!0;q();l("已打开手动复制窗口","warning");return!1}}catch(r){{return console.error("复制失败:",r),q(),l(n,"error"),!1}}}},''' - text = text[:match.start()] + replacement + text[match.end():] - if text != old: - rewrite(path, text) - return True + """Never rewrite Vite's shared clipboard chunk after compilation. + + The source utility already implements Clipboard API, DOM and manual-copy + fallbacks. Rewriting a minified ESM module can invalidate every page that + imports it, including FileManageView. + """ return False diff --git a/tests/test_patch_admin_timeline_ui.py b/tests/test_patch_admin_timeline_ui.py index b1f9cfa..df2030c 100644 --- a/tests/test_patch_admin_timeline_ui.py +++ b/tests/test_patch_admin_timeline_ui.py @@ -1,8 +1,7 @@ -import tempfile -import unittest from pathlib import Path +import unittest -from scripts.patch_admin_timeline_ui import build_lifecycle_script, patch_clipboard +from scripts.patch_admin_timeline_ui import build_lifecycle_script, patch_clipboard, patch_file_manage class AdminTimelinePatchTests(unittest.TestCase): @@ -13,16 +12,10 @@ class AdminTimelinePatchTests(unittest.TestCase): self.assertIn("展开全部取件记录", script) self.assertIn("row.style.overflow = 'visible'", script) - def test_clipboard_rewrite_keeps_module_declaration_separator(self): - source = '''const m=async(a,e={})=>{try{return!0}catch(r){return!1}},R=async(a,e={})=>{return a};export{m};''' - with tempfile.TemporaryDirectory() as temp_dir: - path = Path(temp_dir) / "clipboard-test.js" - path.write_text(source, encoding="utf-8") - - self.assertTrue(patch_clipboard(path)) - patched = path.read_text(encoding="utf-8") - - self.assertIn("}},R=async", patched) + def test_shared_compiled_modules_are_not_rewritten(self): + placeholder = Path("unused.js") + self.assertFalse(patch_file_manage(placeholder)) + self.assertFalse(patch_clipboard(placeholder)) if __name__ == "__main__":