refactor: normalizeMessage 抽取为共享模块#3
Open
alloevil wants to merge 1 commit into
Open
Conversation
- New module: lib/normalize-message.js (single source of truth) - auto-archive-simple.js: remove inline Node.js-side duplicate, use shared module - Browser-side USER_SCRIPT copy retained (can't require() in browser context) - Zero behavior change, pure extraction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
auto-archive-simple.js中有两个 normalizeMessage 函数:逻辑几乎相同但有细微差异(如
p.large?.url只在 Node 端有),修改一处忘改另一处就会出 bug。修复
lib/normalize-message.js,作为 Node.js 端唯一入口auto-archive-simple.js删除内联副本,改为require为什么浏览器端不一起改
USER_SCRIPT 是注入到 Puppeteer 页面的字符串,无法
require()CJS 模块。如果未来要完全统一,需要用 bundler 打包或把模块源码内联为字符串——复杂度不值得当前收益。