[{"data":1,"prerenderedAt":14322},["Reactive",2],{"all-articles":3},[4,381,2683,9299,10292,12922,13507],{"_path":5,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":9,"description":8,"published":10,"categories":11,"tags":13,"slug":16,"body":17,"_type":376,"_id":377,"_source":378,"_file":379,"_extension":380},"/articles/20260305","articles",false,"","浅谈 AI 编程助手的发展与实践","2026/03/05",[12],"技术",[14,15],"AI","编程","浅谈-AI-编程助手的发展与实践",{"type":18,"children":19,"toc":358},"root",[20,28,34,40,47,52,58,63,69,74,130,136,138,243,248,253,258,263,268,273,279,284,289,294,338,343,348,353],{"type":21,"tag":22,"props":23,"children":25},"element","h2",{"id":24},"前言",[26],{"type":27,"value":24},"text",{"type":21,"tag":29,"props":30,"children":31},"p",{},[32],{"type":27,"value":33},"最近几年，AI 技术的发展可以说是日新月异，特别是在编程领域，各种 AI 编程助手层出不穷。从最早的代码补全工具，到如今能够理解整个项目上下文的高级助手，AI 正在深刻地改变着我们的开发方式。",{"type":21,"tag":22,"props":35,"children":37},{"id":36},"ai-编程助手的发展历程",[38],{"type":27,"value":39},"AI 编程助手的发展历程",{"type":21,"tag":41,"props":42,"children":44},"h3",{"id":43},"_1-萌芽期",[45],{"type":27,"value":46},"1. 萌芽期",{"type":21,"tag":29,"props":48,"children":49},{},[50],{"type":27,"value":51},"早期的 AI 编程辅助主要体现在简单的代码补全上，比如 IDE 自带的智能补全功能。这一阶段的工具主要基于规则和统计模型，效果有限。",{"type":21,"tag":41,"props":53,"children":55},{"id":54},"_2-快速发展期",[56],{"type":27,"value":57},"2. 快速发展期",{"type":21,"tag":29,"props":59,"children":60},{},[61],{"type":27,"value":62},"随着大语言模型的出现，AI 编程助手迎来了爆发式增长。以 GitHub Copilot 为代表的工具能够根据上下文自动生成代码片段，大大提升了开发效率。",{"type":21,"tag":41,"props":64,"children":66},{"id":65},"_3-智能化期",[67],{"type":27,"value":68},"3. 智能化期",{"type":21,"tag":29,"props":70,"children":71},{},[72],{"type":27,"value":73},"如今，AI 编程助手已经具备了以下能力：",{"type":21,"tag":75,"props":76,"children":77},"ul",{},[78,90,100,110,120],{"type":21,"tag":79,"props":80,"children":81},"li",{},[82,88],{"type":21,"tag":83,"props":84,"children":85},"strong",{},[86],{"type":27,"value":87},"代码理解",{"type":27,"value":89},"：能够理解整个项目的架构和逻辑",{"type":21,"tag":79,"props":91,"children":92},{},[93,98],{"type":21,"tag":83,"props":94,"children":95},{},[96],{"type":27,"value":97},"智能调试",{"type":27,"value":99},"：帮助定位和修复 bug",{"type":21,"tag":79,"props":101,"children":102},{},[103,108],{"type":21,"tag":83,"props":104,"children":105},{},[106],{"type":27,"value":107},"代码重构",{"type":27,"value":109},"：提供优化建议和改进方案",{"type":21,"tag":79,"props":111,"children":112},{},[113,118],{"type":21,"tag":83,"props":114,"children":115},{},[116],{"type":27,"value":117},"文档生成",{"type":27,"value":119},"：自动生成注释和文档",{"type":21,"tag":79,"props":121,"children":122},{},[123,128],{"type":21,"tag":83,"props":124,"children":125},{},[126],{"type":27,"value":127},"跨语言翻译",{"type":27,"value":129},"：在不同编程语言之间转换代码",{"type":21,"tag":22,"props":131,"children":133},{"id":132},"主流-ai-编程助手对比",[134],{"type":27,"value":135},"主流 AI 编程助手对比",{"type":27,"value":137},"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n",{"type":21,"tag":139,"props":140,"children":141},"table",{},[142,166],{"type":21,"tag":143,"props":144,"children":145},"thead",{},[146],{"type":21,"tag":147,"props":148,"children":149},"tr",{},[150,156,161],{"type":21,"tag":151,"props":152,"children":153},"th",{},[154],{"type":27,"value":155},"工具",{"type":21,"tag":151,"props":157,"children":158},{},[159],{"type":27,"value":160},"特点",{"type":21,"tag":151,"props":162,"children":163},{},[164],{"type":27,"value":165},"适用场景",{"type":21,"tag":167,"props":168,"children":169},"tbody",{},[170,189,207,225],{"type":21,"tag":147,"props":171,"children":172},{},[173,179,184],{"type":21,"tag":174,"props":175,"children":176},"td",{},[177],{"type":27,"value":178},"GitHub Copilot",{"type":21,"tag":174,"props":180,"children":181},{},[182],{"type":27,"value":183},"集成度高，与 VS Code 无缝配合",{"type":21,"tag":174,"props":185,"children":186},{},[187],{"type":27,"value":188},"日常开发",{"type":21,"tag":147,"props":190,"children":191},{},[192,197,202],{"type":21,"tag":174,"props":193,"children":194},{},[195],{"type":27,"value":196},"Cursor",{"type":21,"tag":174,"props":198,"children":199},{},[200],{"type":27,"value":201},"专注于 AI 辅助编程，体验流畅",{"type":21,"tag":174,"props":203,"children":204},{},[205],{"type":27,"value":206},"快速迭代",{"type":21,"tag":147,"props":208,"children":209},{},[210,215,220],{"type":21,"tag":174,"props":211,"children":212},{},[213],{"type":27,"value":214},"Claude Code",{"type":21,"tag":174,"props":216,"children":217},{},[218],{"type":27,"value":219},"推理能力强，适合复杂任务",{"type":21,"tag":174,"props":221,"children":222},{},[223],{"type":27,"value":224},"架构设计",{"type":21,"tag":147,"props":226,"children":227},{},[228,233,238],{"type":21,"tag":174,"props":229,"children":230},{},[231],{"type":27,"value":232},"Gemini CLI",{"type":21,"tag":174,"props":234,"children":235},{},[236],{"type":27,"value":237},"Google 出品，多模态能力",{"type":21,"tag":174,"props":239,"children":240},{},[241],{"type":27,"value":242},"前端开发",{"type":21,"tag":22,"props":244,"children":246},{"id":245},"实际使用体验",[247],{"type":27,"value":245},{"type":21,"tag":29,"props":249,"children":250},{},[251],{"type":27,"value":252},"作为一个经常写代码的人，我也尝试了市面上主流的 AI 编程助手。分享一下我的使用感受：",{"type":21,"tag":41,"props":254,"children":256},{"id":255},"代码补全",[257],{"type":27,"value":255},{"type":21,"tag":29,"props":259,"children":260},{},[261],{"type":27,"value":262},"Copilot 的代码补全功能确实很强大，特别是在写一些重复性的代码时，能够显著减少键盘敲击次数。",{"type":21,"tag":41,"props":264,"children":266},{"id":265},"代码生成",[267],{"type":27,"value":265},{"type":21,"tag":29,"props":269,"children":270},{},[271],{"type":27,"value":272},"有时候只需要描述需求，AI 就能生成完整的代码块。比如我想实现一个登录功能，只需要说出需求，它就能生成包含前端表单和后端接口的完整代码。",{"type":21,"tag":41,"props":274,"children":276},{"id":275},"bug-修复",[277],{"type":27,"value":278},"bug 修复",{"type":21,"tag":29,"props":280,"children":281},{},[282],{"type":27,"value":283},"这可能是 AI 编程助手最实用的功能之一。当遇到报错时，把错误信息贴给 AI，它往往能够快速定位问题并给出解决方案。",{"type":21,"tag":22,"props":285,"children":287},{"id":286},"未来展望",[288],{"type":27,"value":286},{"type":21,"tag":29,"props":290,"children":291},{},[292],{"type":27,"value":293},"我认为 AI 编程助手未来会朝着以下方向发展：",{"type":21,"tag":295,"props":296,"children":297},"ol",{},[298,308,318,328],{"type":21,"tag":79,"props":299,"children":300},{},[301,306],{"type":21,"tag":83,"props":302,"children":303},{},[304],{"type":27,"value":305},"更强的上下文理解能力",{"type":27,"value":307},"：不仅理解当前文件，还能理解整个项目甚至整个代码库",{"type":21,"tag":79,"props":309,"children":310},{},[311,316],{"type":21,"tag":83,"props":312,"children":313},{},[314],{"type":27,"value":315},"多模态交互",{"type":27,"value":317},"：除了文字，还能通过语音、图片等方式与开发者交互",{"type":21,"tag":79,"props":319,"children":320},{},[321,326],{"type":21,"tag":83,"props":322,"children":323},{},[324],{"type":27,"value":325},"个性化定制",{"type":27,"value":327},"：根据开发者的习惯和偏好进行深度定制",{"type":21,"tag":79,"props":329,"children":330},{},[331,336],{"type":21,"tag":83,"props":332,"children":333},{},[334],{"type":27,"value":335},"端到端服务",{"type":27,"value":337},"：从需求分析到代码实现，再到测试部署，全流程覆盖",{"type":21,"tag":22,"props":339,"children":341},{"id":340},"结语",[342],{"type":27,"value":340},{"type":21,"tag":29,"props":344,"children":345},{},[346],{"type":27,"value":347},"AI 编程助手不是要取代程序员，而是要成为程序员的得力助手。它们可以帮助我们从繁琐的重复工作中解放出来，让我们有更多时间去做创造性的工作。",{"type":21,"tag":29,"props":349,"children":350},{},[351],{"type":27,"value":352},"面对 AI 的发展，我们需要保持学习的态度，不断提升自己的技能，同时也要学会如何更好地与 AI 协作。毕竟，未来的编程可能不再是写代码，而是「指挥」AI 写代码。",{"type":21,"tag":29,"props":354,"children":355},{},[356],{"type":27,"value":357},"让我们拥抱变化，迎接 AI 时代的到来！",{"title":8,"searchDepth":359,"depth":359,"links":360},2,[361,362,368,369,374,375],{"id":24,"depth":359,"text":24},{"id":36,"depth":359,"text":39,"children":363},[364,366,367],{"id":43,"depth":365,"text":46},3,{"id":54,"depth":365,"text":57},{"id":65,"depth":365,"text":68},{"id":132,"depth":359,"text":135},{"id":245,"depth":359,"text":245,"children":370},[371,372,373],{"id":255,"depth":365,"text":255},{"id":265,"depth":365,"text":265},{"id":275,"depth":365,"text":278},{"id":286,"depth":359,"text":286},{"id":340,"depth":359,"text":340},"markdown","content:articles:20260305.md","content","articles/20260305.md","md",{"_path":382,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":383,"description":8,"published":384,"categories":385,"tags":387,"slug":383,"body":389,"_type":376,"_id":2681,"_source":378,"_file":2682,"_extension":380},"/articles/20250122","强大的自动化工作流工具，你值得拥有","2025/01/22",[386],"前端",[388],"自动化",{"type":18,"children":390,"toc":2676},[391,396,401,419,424,429,434,439,455,463,468,475,480,485,490,495,500,529,534,541,546,551,569,574,581,586,591,598,603,608,615,620,627,632,695,700,707,712,717,722,727,732,737,744,749,756,761,778,783,790,795,1086,1098,1103,1151,1156,1189,1194,1333,1338,1345,1350,1355,2558,2563,2570,2575,2580,2585,2592,2597,2604,2617,2622,2627,2632,2637,2642,2655,2660,2665,2670],{"type":21,"tag":22,"props":392,"children":394},{"id":393},"背景",[395],{"type":27,"value":393},{"type":21,"tag":29,"props":397,"children":398},{},[399],{"type":27,"value":400},"最近在家忙着开发telegram机器人项目，每次部署到nas上时，都会有一个比较重复的步骤：",{"type":21,"tag":295,"props":402,"children":403},{},[404,409,414],{"type":21,"tag":79,"props":405,"children":406},{},[407],{"type":27,"value":408},"推送到远程触发ci构建docker镜像，等待镜像构建完成",{"type":21,"tag":79,"props":410,"children":411},{},[412],{"type":27,"value":413},"打开终端ssh进入nas，然后cd到机器人项目的目录",{"type":21,"tag":79,"props":415,"children":416},{},[417],{"type":27,"value":418},"运行docker-compose下拉命令和重新构建命令",{"type":21,"tag":29,"props":420,"children":421},{},[422],{"type":27,"value":423},"重复次数多了之后，我就想能不能找个工具代替（没办法我实在是懒），而且我在外面的时候就没办法进入nas所在的局域网重启了。",{"type":21,"tag":29,"props":425,"children":426},{},[427],{"type":27,"value":428},"我需要一个按钮，按下去，程序就帮我执行完后面的2步。",{"type":21,"tag":29,"props":430,"children":431},{},[432],{"type":27,"value":433},"其实这最后2步也可以挪到ci中完成，但我就是想找一个独立的工具，不去依赖ci。",{"type":21,"tag":29,"props":435,"children":436},{},[437],{"type":27,"value":438},"于是我就想，应该已经有这样的工具了，配置好任务的触发器，触发之后就自动执行写好的脚本。",{"type":21,"tag":29,"props":440,"children":441},{},[442,444,453],{"type":27,"value":443},"带着这个想法，我就立马去搜索关键词，最终搜到了",{"type":21,"tag":445,"props":446,"children":450},"a",{"href":447,"rel":448},"https://docs.n8n.io/",[449],"nofollow",[451],{"type":27,"value":452},"n8n",{"type":27,"value":454},"，基于node写的工作流自动化工具。",{"type":21,"tag":29,"props":456,"children":457},{},[458],{"type":21,"tag":459,"props":460,"children":462},"img",{"alt":8,"src":461},"https://johnhom-img.oss-cn-guangzhou.aliyuncs.com/obsidian/Pasted%20image%2020250122171737.png",[],{"type":21,"tag":29,"props":464,"children":465},{},[466],{"type":27,"value":467},"刚好第二天无意中看到群里有人转了奇舞精选的一篇【2024年最受欢迎的前段项目】n8n赫然在列。",{"type":21,"tag":29,"props":469,"children":470},{},[471],{"type":21,"tag":459,"props":472,"children":474},{"alt":8,"src":473},"https://johnhom-img.oss-cn-guangzhou.aliyuncs.com/obsidian/Pasted%20image%2020250122172417.png",[],{"type":21,"tag":29,"props":476,"children":477},{},[478],{"type":27,"value":479},"好家伙，那我不得高低学一下。",{"type":21,"tag":22,"props":481,"children":483},{"id":482},"搭建自动化工作流",[484],{"type":27,"value":482},{"type":21,"tag":29,"props":486,"children":487},{},[488],{"type":27,"value":489},"n8n有两种方式使用，一种是直接使用官方网站，一种是在自己服务器上搭建n8n，我毫不犹疑就选了后者。毕竟这样可控制的程度更高一些",{"type":21,"tag":29,"props":491,"children":492},{},[493],{"type":27,"value":494},"我们可以直接使用npm启动n8n，",{"type":21,"tag":29,"props":496,"children":497},{},[498],{"type":27,"value":499},"只需要运行：",{"type":21,"tag":501,"props":502,"children":506},"pre",{"className":503,"code":504,"language":505,"meta":8,"style":8},"language-bash shiki shiki-themes github-dark","npx n8n\n","bash",[507],{"type":21,"tag":508,"props":509,"children":510},"code",{"__ignoreMap":8},[511],{"type":21,"tag":512,"props":513,"children":516},"span",{"class":514,"line":515},"line",1,[517,523],{"type":21,"tag":512,"props":518,"children":520},{"style":519},"--shiki-default:#B392F0",[521],{"type":27,"value":522},"npx",{"type":21,"tag":512,"props":524,"children":526},{"style":525},"--shiki-default:#9ECBFF",[527],{"type":27,"value":528}," n8n\n",{"type":21,"tag":29,"props":530,"children":531},{},[532],{"type":27,"value":533},"然后注册一个账号，进入主页就是这样子：",{"type":21,"tag":29,"props":535,"children":536},{},[537],{"type":21,"tag":459,"props":538,"children":540},{"alt":8,"src":539},"https://johnhom-img.oss-cn-guangzhou.aliyuncs.com/obsidian/Pasted%20image%2020250122173325.png",[],{"type":21,"tag":29,"props":542,"children":543},{},[544],{"type":27,"value":545},"为了方便搭建和运行，我决定部署到在nas上，用docker容器运行n8n。",{"type":21,"tag":29,"props":547,"children":548},{},[549],{"type":27,"value":550},"接下来整理一波n8n需要实现的工作流：",{"type":21,"tag":295,"props":552,"children":553},{},[554,559,564],{"type":21,"tag":79,"props":555,"children":556},{},[557],{"type":27,"value":558},"外部某个事件触发",{"type":21,"tag":79,"props":560,"children":561},{},[562],{"type":27,"value":563},"进入到某个文件夹，执行重启脚本",{"type":21,"tag":79,"props":565,"children":566},{},[567],{"type":27,"value":568},"发送邮件提示已经执行完成",{"type":21,"tag":29,"props":570,"children":571},{},[572],{"type":27,"value":573},"开整，我们先点击右上角的【Create Workflow】新建一个工作流，然后点击中间的添加第一步，右侧会弹出可选的触发器：",{"type":21,"tag":29,"props":575,"children":576},{},[577],{"type":21,"tag":459,"props":578,"children":580},{"alt":8,"src":579},"https://johnhom-img.oss-cn-guangzhou.aliyuncs.com/obsidian/Pasted%20image%2020250122173804.png",[],{"type":21,"tag":29,"props":582,"children":583},{},[584],{"type":27,"value":585},"app event的列表我看了一遍，全是国外的应用，看来国外开源项目的唯一缺点就是在国内水土不服。",{"type":21,"tag":29,"props":587,"children":588},{},[589],{"type":27,"value":590},"那就只能用webhook call了，用它来新建一个触发节点，然后我们可以看到：",{"type":21,"tag":29,"props":592,"children":593},{},[594],{"type":21,"tag":459,"props":595,"children":597},{"alt":8,"src":596},"https://johnhom-img.oss-cn-guangzhou.aliyuncs.com/obsidian/Pasted%20image%2020250122174148.png",[],{"type":21,"tag":29,"props":599,"children":600},{},[601],{"type":27,"value":602},"不得不说界面真的挺简洁明了。大概的用法就是，只要请求提供的webhook url，n8n就会从这个webhook节点开始执行任务。",{"type":21,"tag":29,"props":604,"children":605},{},[606],{"type":27,"value":607},"接下来就是执行脚本，继续添加下一步，选择【Execute Command】",{"type":21,"tag":29,"props":609,"children":610},{},[611],{"type":21,"tag":459,"props":612,"children":614},{"alt":8,"src":613},"https://johnhom-img.oss-cn-guangzhou.aliyuncs.com/obsidian/Pasted%20image%2020250123174457.png",[],{"type":21,"tag":29,"props":616,"children":617},{},[618],{"type":27,"value":619},"然后cd到某个目录，执行restart.sh脚本",{"type":21,"tag":29,"props":621,"children":622},{},[623],{"type":21,"tag":459,"props":624,"children":626},{"alt":8,"src":625},"https://johnhom-img.oss-cn-guangzhou.aliyuncs.com/obsidian/Pasted%20image%2020250123174554.png",[],{"type":21,"tag":29,"props":628,"children":629},{},[630],{"type":27,"value":631},"restart.sh脚本内容如下：",{"type":21,"tag":501,"props":633,"children":637},{"className":634,"code":635,"language":636,"meta":8,"style":8},"language-shell shiki shiki-themes github-dark","# 拉取最新的镜像\ndocker-compose pull\n# 重新创建并启动\ndocker-compose up -d --force-recreate\n","shell",[638],{"type":21,"tag":508,"props":639,"children":640},{"__ignoreMap":8},[641,650,663,671],{"type":21,"tag":512,"props":642,"children":643},{"class":514,"line":515},[644],{"type":21,"tag":512,"props":645,"children":647},{"style":646},"--shiki-default:#6A737D",[648],{"type":27,"value":649},"# 拉取最新的镜像\n",{"type":21,"tag":512,"props":651,"children":652},{"class":514,"line":359},[653,658],{"type":21,"tag":512,"props":654,"children":655},{"style":519},[656],{"type":27,"value":657},"docker-compose",{"type":21,"tag":512,"props":659,"children":660},{"style":525},[661],{"type":27,"value":662}," pull\n",{"type":21,"tag":512,"props":664,"children":665},{"class":514,"line":365},[666],{"type":21,"tag":512,"props":667,"children":668},{"style":646},[669],{"type":27,"value":670},"# 重新创建并启动\n",{"type":21,"tag":512,"props":672,"children":674},{"class":514,"line":673},4,[675,679,684,690],{"type":21,"tag":512,"props":676,"children":677},{"style":519},[678],{"type":27,"value":657},{"type":21,"tag":512,"props":680,"children":681},{"style":525},[682],{"type":27,"value":683}," up",{"type":21,"tag":512,"props":685,"children":687},{"style":686},"--shiki-default:#79B8FF",[688],{"type":27,"value":689}," -d",{"type":21,"tag":512,"props":691,"children":692},{"style":686},[693],{"type":27,"value":694}," --force-recreate\n",{"type":21,"tag":29,"props":696,"children":697},{},[698],{"type":27,"value":699},"到这里我突然想到一个问题，就是我搭建的n8n是在nas里基于容器运行的，在容器内会存在命令空间隔离问题，执行docker命令肯定会提示command not found。",{"type":21,"tag":29,"props":701,"children":702},{},[703],{"type":21,"tag":459,"props":704,"children":706},{"alt":8,"src":705},"https://johnhom-img.oss-cn-guangzhou.aliyuncs.com/obsidian/Pasted%20image%2020250123175119.png",[],{"type":21,"tag":29,"props":708,"children":709},{},[710],{"type":27,"value":711},"于是就想着如何在容器内，也能够控制宿主的docker去拉取某个镜像和重启，但是困难重重：",{"type":21,"tag":29,"props":713,"children":714},{},[715],{"type":27,"value":716},"首先挂载宿主机的docker.sock文件，然后通过Node.js的dockerode库调用docker api去重启容器",{"type":21,"tag":29,"props":718,"children":719},{},[720],{"type":27,"value":721},"由于我是用docker-compose.yml去管理容器，所以换成dockerode-compose去操作，本来以为这样就没问题了，然而打脸来的太快，不知道为啥报错了，过程折腾了好久，最终还是放弃了调用docker api的方案。",{"type":21,"tag":29,"props":723,"children":724},{},[725],{"type":27,"value":726},"然后我回顾一下，如果容器直接通过ssh登录到宿主机上，也可以直接执行脚本了。",{"type":21,"tag":29,"props":728,"children":729},{},[730],{"type":27,"value":731},"只能先这样了，如果大家有什么更好的方法，也可以在评论区发出来我学习一波。",{"type":21,"tag":29,"props":733,"children":734},{},[735],{"type":27,"value":736},"首先问一下ai，在容器里如何获取宿主机的ip：",{"type":21,"tag":29,"props":738,"children":739},{},[740],{"type":21,"tag":459,"props":741,"children":743},{"alt":8,"src":742},"https://johnhom-img.oss-cn-guangzhou.aliyuncs.com/obsidian/Pasted%20image%2020250123180955.png",[],{"type":21,"tag":29,"props":745,"children":746},{},[747],{"type":27,"value":748},"然后在容器内测试一下这个命令，确实可行！",{"type":21,"tag":29,"props":750,"children":751},{},[752],{"type":21,"tag":459,"props":753,"children":755},{"alt":8,"src":754},"https://johnhom-img.oss-cn-guangzhou.aliyuncs.com/obsidian/Pasted%20image%2020250123181208.png",[],{"type":21,"tag":29,"props":757,"children":758},{},[759],{"type":27,"value":760},"再整理一下最新的工作流方案：",{"type":21,"tag":295,"props":762,"children":763},{},[764,768,773],{"type":21,"tag":79,"props":765,"children":766},{},[767],{"type":27,"value":558},{"type":21,"tag":79,"props":769,"children":770},{},[771],{"type":27,"value":772},"执行js代码，通过child_process执行命令获取宿主机的ip地址",{"type":21,"tag":79,"props":774,"children":775},{},[776],{"type":27,"value":777},"通过ssh2进入宿主机，运行命令重启容器。",{"type":21,"tag":29,"props":779,"children":780},{},[781],{"type":27,"value":782},"好的，接下来创建一个Code节点：",{"type":21,"tag":29,"props":784,"children":785},{},[786],{"type":21,"tag":459,"props":787,"children":789},{"alt":8,"src":788},"https://johnhom-img.oss-cn-guangzhou.aliyuncs.com/obsidian/Pasted%20image%2020250123194745.png",[],{"type":21,"tag":29,"props":791,"children":792},{},[793],{"type":27,"value":794},"获取宿主机ip的代码如下：",{"type":21,"tag":501,"props":796,"children":800},{"className":797,"code":798,"language":799,"meta":8,"style":8},"language-javascript shiki shiki-themes github-dark","const { execSync } = require('child_process');\n\n// 获取宿主机ip的命令\nconst findIpCommand = \"ip route | awk '/default/ { print $3 }'\";\n\nconst ip = execSync(findIpCommand, { encoding: 'utf8' }).trim();\nconsole.log('ip', ip);\n\nif (!ip) {\n  throw new Error('宿主ip为空');\n}\nreturn {\n  ip,\n};\n","javascript",[801],{"type":21,"tag":508,"props":802,"children":803},{"__ignoreMap":8},[804,854,863,871,898,906,953,981,989,1013,1045,1054,1068,1077],{"type":21,"tag":512,"props":805,"children":806},{"class":514,"line":515},[807,813,819,824,829,834,839,844,849],{"type":21,"tag":512,"props":808,"children":810},{"style":809},"--shiki-default:#F97583",[811],{"type":27,"value":812},"const",{"type":21,"tag":512,"props":814,"children":816},{"style":815},"--shiki-default:#E1E4E8",[817],{"type":27,"value":818}," { ",{"type":21,"tag":512,"props":820,"children":821},{"style":686},[822],{"type":27,"value":823},"execSync",{"type":21,"tag":512,"props":825,"children":826},{"style":815},[827],{"type":27,"value":828}," } ",{"type":21,"tag":512,"props":830,"children":831},{"style":809},[832],{"type":27,"value":833},"=",{"type":21,"tag":512,"props":835,"children":836},{"style":519},[837],{"type":27,"value":838}," require",{"type":21,"tag":512,"props":840,"children":841},{"style":815},[842],{"type":27,"value":843},"(",{"type":21,"tag":512,"props":845,"children":846},{"style":525},[847],{"type":27,"value":848},"'child_process'",{"type":21,"tag":512,"props":850,"children":851},{"style":815},[852],{"type":27,"value":853},");\n",{"type":21,"tag":512,"props":855,"children":856},{"class":514,"line":359},[857],{"type":21,"tag":512,"props":858,"children":860},{"emptyLinePlaceholder":859},true,[861],{"type":27,"value":862},"\n",{"type":21,"tag":512,"props":864,"children":865},{"class":514,"line":365},[866],{"type":21,"tag":512,"props":867,"children":868},{"style":646},[869],{"type":27,"value":870},"// 获取宿主机ip的命令\n",{"type":21,"tag":512,"props":872,"children":873},{"class":514,"line":673},[874,878,883,888,893],{"type":21,"tag":512,"props":875,"children":876},{"style":809},[877],{"type":27,"value":812},{"type":21,"tag":512,"props":879,"children":880},{"style":686},[881],{"type":27,"value":882}," findIpCommand",{"type":21,"tag":512,"props":884,"children":885},{"style":809},[886],{"type":27,"value":887}," =",{"type":21,"tag":512,"props":889,"children":890},{"style":525},[891],{"type":27,"value":892}," \"ip route | awk '/default/ { print $3 }'\"",{"type":21,"tag":512,"props":894,"children":895},{"style":815},[896],{"type":27,"value":897},";\n",{"type":21,"tag":512,"props":899,"children":901},{"class":514,"line":900},5,[902],{"type":21,"tag":512,"props":903,"children":904},{"emptyLinePlaceholder":859},[905],{"type":27,"value":862},{"type":21,"tag":512,"props":907,"children":909},{"class":514,"line":908},6,[910,914,919,923,928,933,938,943,948],{"type":21,"tag":512,"props":911,"children":912},{"style":809},[913],{"type":27,"value":812},{"type":21,"tag":512,"props":915,"children":916},{"style":686},[917],{"type":27,"value":918}," ip",{"type":21,"tag":512,"props":920,"children":921},{"style":809},[922],{"type":27,"value":887},{"type":21,"tag":512,"props":924,"children":925},{"style":519},[926],{"type":27,"value":927}," execSync",{"type":21,"tag":512,"props":929,"children":930},{"style":815},[931],{"type":27,"value":932},"(findIpCommand, { encoding: ",{"type":21,"tag":512,"props":934,"children":935},{"style":525},[936],{"type":27,"value":937},"'utf8'",{"type":21,"tag":512,"props":939,"children":940},{"style":815},[941],{"type":27,"value":942}," }).",{"type":21,"tag":512,"props":944,"children":945},{"style":519},[946],{"type":27,"value":947},"trim",{"type":21,"tag":512,"props":949,"children":950},{"style":815},[951],{"type":27,"value":952},"();\n",{"type":21,"tag":512,"props":954,"children":956},{"class":514,"line":955},7,[957,962,967,971,976],{"type":21,"tag":512,"props":958,"children":959},{"style":815},[960],{"type":27,"value":961},"console.",{"type":21,"tag":512,"props":963,"children":964},{"style":519},[965],{"type":27,"value":966},"log",{"type":21,"tag":512,"props":968,"children":969},{"style":815},[970],{"type":27,"value":843},{"type":21,"tag":512,"props":972,"children":973},{"style":525},[974],{"type":27,"value":975},"'ip'",{"type":21,"tag":512,"props":977,"children":978},{"style":815},[979],{"type":27,"value":980},", ip);\n",{"type":21,"tag":512,"props":982,"children":984},{"class":514,"line":983},8,[985],{"type":21,"tag":512,"props":986,"children":987},{"emptyLinePlaceholder":859},[988],{"type":27,"value":862},{"type":21,"tag":512,"props":990,"children":992},{"class":514,"line":991},9,[993,998,1003,1008],{"type":21,"tag":512,"props":994,"children":995},{"style":809},[996],{"type":27,"value":997},"if",{"type":21,"tag":512,"props":999,"children":1000},{"style":815},[1001],{"type":27,"value":1002}," (",{"type":21,"tag":512,"props":1004,"children":1005},{"style":809},[1006],{"type":27,"value":1007},"!",{"type":21,"tag":512,"props":1009,"children":1010},{"style":815},[1011],{"type":27,"value":1012},"ip) {\n",{"type":21,"tag":512,"props":1014,"children":1016},{"class":514,"line":1015},10,[1017,1022,1027,1032,1036,1041],{"type":21,"tag":512,"props":1018,"children":1019},{"style":809},[1020],{"type":27,"value":1021},"  throw",{"type":21,"tag":512,"props":1023,"children":1024},{"style":809},[1025],{"type":27,"value":1026}," new",{"type":21,"tag":512,"props":1028,"children":1029},{"style":519},[1030],{"type":27,"value":1031}," Error",{"type":21,"tag":512,"props":1033,"children":1034},{"style":815},[1035],{"type":27,"value":843},{"type":21,"tag":512,"props":1037,"children":1038},{"style":525},[1039],{"type":27,"value":1040},"'宿主ip为空'",{"type":21,"tag":512,"props":1042,"children":1043},{"style":815},[1044],{"type":27,"value":853},{"type":21,"tag":512,"props":1046,"children":1048},{"class":514,"line":1047},11,[1049],{"type":21,"tag":512,"props":1050,"children":1051},{"style":815},[1052],{"type":27,"value":1053},"}\n",{"type":21,"tag":512,"props":1055,"children":1057},{"class":514,"line":1056},12,[1058,1063],{"type":21,"tag":512,"props":1059,"children":1060},{"style":809},[1061],{"type":27,"value":1062},"return",{"type":21,"tag":512,"props":1064,"children":1065},{"style":815},[1066],{"type":27,"value":1067}," {\n",{"type":21,"tag":512,"props":1069,"children":1071},{"class":514,"line":1070},13,[1072],{"type":21,"tag":512,"props":1073,"children":1074},{"style":815},[1075],{"type":27,"value":1076},"  ip,\n",{"type":21,"tag":512,"props":1078,"children":1080},{"class":514,"line":1079},14,[1081],{"type":21,"tag":512,"props":1082,"children":1083},{"style":815},[1084],{"type":27,"value":1085},"};\n",{"type":21,"tag":29,"props":1087,"children":1088},{},[1089,1091],{"type":27,"value":1090},"运行前，需要配置n8n支持使用内部和外部的模块，具体可以看这里：",{"type":21,"tag":445,"props":1092,"children":1095},{"href":1093,"rel":1094},"https://docs.n8n.io/hosting/configuration/configuration-examples/modules-in-code-node/",[449],[1096],{"type":27,"value":1097},"modules-in-code-node",{"type":21,"tag":29,"props":1099,"children":1100},{},[1101],{"type":27,"value":1102},"由于n8n我是用docker-compose去部署的，所以需要在evnironment字段加上以下的值：",{"type":21,"tag":501,"props":1104,"children":1108},{"className":1105,"code":1106,"language":1107,"meta":8,"style":8},"language-yml shiki shiki-themes github-dark","environment:\n    - NODE_FUNCTION_ALLOW_EXTERNAL=*\n    - NODE_FUNCTION_ALLOW_BUILTIN=*\n","yml",[1109],{"type":21,"tag":508,"props":1110,"children":1111},{"__ignoreMap":8},[1112,1126,1139],{"type":21,"tag":512,"props":1113,"children":1114},{"class":514,"line":515},[1115,1121],{"type":21,"tag":512,"props":1116,"children":1118},{"style":1117},"--shiki-default:#85E89D",[1119],{"type":27,"value":1120},"environment",{"type":21,"tag":512,"props":1122,"children":1123},{"style":815},[1124],{"type":27,"value":1125},":\n",{"type":21,"tag":512,"props":1127,"children":1128},{"class":514,"line":359},[1129,1134],{"type":21,"tag":512,"props":1130,"children":1131},{"style":815},[1132],{"type":27,"value":1133},"    - ",{"type":21,"tag":512,"props":1135,"children":1136},{"style":525},[1137],{"type":27,"value":1138},"NODE_FUNCTION_ALLOW_EXTERNAL=*\n",{"type":21,"tag":512,"props":1140,"children":1141},{"class":514,"line":365},[1142,1146],{"type":21,"tag":512,"props":1143,"children":1144},{"style":815},[1145],{"type":27,"value":1133},{"type":21,"tag":512,"props":1147,"children":1148},{"style":525},[1149],{"type":27,"value":1150},"NODE_FUNCTION_ALLOW_BUILTIN=*\n",{"type":21,"tag":29,"props":1152,"children":1153},{},[1154],{"type":27,"value":1155},"如果引入了外部的模块，比如后面会用到的ssh2，需要先用npm安装好，因为我是用的Docker，所以我这边是选择新建一个Dockerfile，引入n8n的镜像，然后运行安装依赖的代码：",{"type":21,"tag":501,"props":1157,"children":1161},{"className":1158,"code":1159,"language":1160,"meta":8,"style":8},"language-Dockerfile shiki shiki-themes github-dark","FROM docker.n8n.io/n8nio/n8n:latest\nRUN npm config set registry https://registry.npmmirror.com\nRUN npm install -g ssh2\n","Dockerfile",[1162],{"type":21,"tag":508,"props":1163,"children":1164},{"__ignoreMap":8},[1165,1173,1181],{"type":21,"tag":512,"props":1166,"children":1167},{"class":514,"line":515},[1168],{"type":21,"tag":512,"props":1169,"children":1170},{},[1171],{"type":27,"value":1172},"FROM docker.n8n.io/n8nio/n8n:latest\n",{"type":21,"tag":512,"props":1174,"children":1175},{"class":514,"line":359},[1176],{"type":21,"tag":512,"props":1177,"children":1178},{},[1179],{"type":27,"value":1180},"RUN npm config set registry https://registry.npmmirror.com\n",{"type":21,"tag":512,"props":1182,"children":1183},{"class":514,"line":365},[1184],{"type":21,"tag":512,"props":1185,"children":1186},{},[1187],{"type":27,"value":1188},"RUN npm install -g ssh2\n",{"type":21,"tag":29,"props":1190,"children":1191},{},[1192],{"type":27,"value":1193},"所以我目前的docker-compose.yml内容如下：",{"type":21,"tag":501,"props":1195,"children":1199},{"className":1196,"code":1197,"language":1198,"meta":8,"style":8},"language-docker-compose.yml shiki shiki-themes github-dark","version: '3.8'\nservices:\n  n8n:\n    container_name: n8n\n    build: .\n    restart: 'unless-stopped'\n    ports:\n      - '5678:5678'\n    volumes:\n      - ./data:/root/.n8n\n    environment:\n      # 允许http的方式登录\n      - N8N_SECURE_COOKIE=false\n      # 支持所有内部和外部的包\n      - NODE_FUNCTION_ALLOW_EXTERNAL=*\n      - NODE_FUNCTION_ALLOW_BUILTIN=*\n","docker-compose.yml",[1200],{"type":21,"tag":508,"props":1201,"children":1202},{"__ignoreMap":8},[1203,1211,1219,1227,1235,1243,1251,1259,1267,1275,1283,1291,1299,1307,1315,1324],{"type":21,"tag":512,"props":1204,"children":1205},{"class":514,"line":515},[1206],{"type":21,"tag":512,"props":1207,"children":1208},{},[1209],{"type":27,"value":1210},"version: '3.8'\n",{"type":21,"tag":512,"props":1212,"children":1213},{"class":514,"line":359},[1214],{"type":21,"tag":512,"props":1215,"children":1216},{},[1217],{"type":27,"value":1218},"services:\n",{"type":21,"tag":512,"props":1220,"children":1221},{"class":514,"line":365},[1222],{"type":21,"tag":512,"props":1223,"children":1224},{},[1225],{"type":27,"value":1226},"  n8n:\n",{"type":21,"tag":512,"props":1228,"children":1229},{"class":514,"line":673},[1230],{"type":21,"tag":512,"props":1231,"children":1232},{},[1233],{"type":27,"value":1234},"    container_name: n8n\n",{"type":21,"tag":512,"props":1236,"children":1237},{"class":514,"line":900},[1238],{"type":21,"tag":512,"props":1239,"children":1240},{},[1241],{"type":27,"value":1242},"    build: .\n",{"type":21,"tag":512,"props":1244,"children":1245},{"class":514,"line":908},[1246],{"type":21,"tag":512,"props":1247,"children":1248},{},[1249],{"type":27,"value":1250},"    restart: 'unless-stopped'\n",{"type":21,"tag":512,"props":1252,"children":1253},{"class":514,"line":955},[1254],{"type":21,"tag":512,"props":1255,"children":1256},{},[1257],{"type":27,"value":1258},"    ports:\n",{"type":21,"tag":512,"props":1260,"children":1261},{"class":514,"line":983},[1262],{"type":21,"tag":512,"props":1263,"children":1264},{},[1265],{"type":27,"value":1266},"      - '5678:5678'\n",{"type":21,"tag":512,"props":1268,"children":1269},{"class":514,"line":991},[1270],{"type":21,"tag":512,"props":1271,"children":1272},{},[1273],{"type":27,"value":1274},"    volumes:\n",{"type":21,"tag":512,"props":1276,"children":1277},{"class":514,"line":1015},[1278],{"type":21,"tag":512,"props":1279,"children":1280},{},[1281],{"type":27,"value":1282},"      - ./data:/root/.n8n\n",{"type":21,"tag":512,"props":1284,"children":1285},{"class":514,"line":1047},[1286],{"type":21,"tag":512,"props":1287,"children":1288},{},[1289],{"type":27,"value":1290},"    environment:\n",{"type":21,"tag":512,"props":1292,"children":1293},{"class":514,"line":1056},[1294],{"type":21,"tag":512,"props":1295,"children":1296},{},[1297],{"type":27,"value":1298},"      # 允许http的方式登录\n",{"type":21,"tag":512,"props":1300,"children":1301},{"class":514,"line":1070},[1302],{"type":21,"tag":512,"props":1303,"children":1304},{},[1305],{"type":27,"value":1306},"      - N8N_SECURE_COOKIE=false\n",{"type":21,"tag":512,"props":1308,"children":1309},{"class":514,"line":1079},[1310],{"type":21,"tag":512,"props":1311,"children":1312},{},[1313],{"type":27,"value":1314},"      # 支持所有内部和外部的包\n",{"type":21,"tag":512,"props":1316,"children":1318},{"class":514,"line":1317},15,[1319],{"type":21,"tag":512,"props":1320,"children":1321},{},[1322],{"type":27,"value":1323},"      - NODE_FUNCTION_ALLOW_EXTERNAL=*\n",{"type":21,"tag":512,"props":1325,"children":1327},{"class":514,"line":1326},16,[1328],{"type":21,"tag":512,"props":1329,"children":1330},{},[1331],{"type":27,"value":1332},"      - NODE_FUNCTION_ALLOW_BUILTIN=*\n",{"type":21,"tag":29,"props":1334,"children":1335},{},[1336],{"type":27,"value":1337},"重启n8n之后，测试运行以下这个节点，输出也没问题：",{"type":21,"tag":29,"props":1339,"children":1340},{},[1341],{"type":21,"tag":459,"props":1342,"children":1344},{"alt":8,"src":1343},"https://johnhom-img.oss-cn-guangzhou.aliyuncs.com/obsidian/Pasted%20image%2020250123194522.png",[],{"type":21,"tag":29,"props":1346,"children":1347},{},[1348],{"type":27,"value":1349},"这个节点会自动把return的数据传给下一个节点，接下来就是拿到传入的ip然后通过ssh2来连接宿主机。",{"type":21,"tag":29,"props":1351,"children":1352},{},[1353],{"type":27,"value":1354},"我们继续创建新的Core节点，代码如下：",{"type":21,"tag":501,"props":1356,"children":1358},{"className":797,"code":1357,"language":799,"meta":8,"style":8},"const { Client } = require('ssh2');\n\nconst conn = new Client();\n// n8n内部提供获取传入节点数据的方式，具体可以看\n// https://docs.n8n.io/code/builtin/current-node-input/\n// 这里拿到上一个节点写入的ip属性\nconst host = $json.ip;\nconst port = 22;\nconst username = 'root';\nconst password = 'xxxx';\n// docker镜像源的用户名\nconst dockerUser = 'xxxxx';\n// docker镜像源的密码\nconst dockerPassword = 'xxxx';\n\nconst loginCommand = `docker login -u ${dockerUser} -p ${dockerPassword} xxxx`;\nconst cdCommand = 'cd /volume1/docker/xxx';\nconst pullCommand = 'docker-compose pull';\nconst recreateCommand = 'docker-compose up -d --force-recreate';\nconst allCommand = `${loginCommand} && ${cdCommand} && ${pullCommand} && ${recreateCommand}`;\n\nreturn new Promise((resolve) => {\n  conn\n  .on('ready', () => {\n    console.log('Client :: ready');\n    conn.shell((err, stream) => {\n      stream\n        .on('close', (code, signal) => {\n          console.log('执行完成');\n          conn.end();\n        })\n        .on('data', (data) => {\n          console.log(data.toString());\n        })\n        .stderr.on('data', (data) => {\n          console.log('STDERR: ' + data);\n        });\n\n      //执行命令 \n      stream.write(allCommand + '\\n');\n      // 退出\n      stream.write('exit\\n');\n    });\n  }).on('close', () => {\n    resolve([\n      {\n        msg: 'success',\n        code: 0,\n      }\n    ]);\n  })\n  .connect({\n    host,\n    port,\n    username,\n    password,\n  });\n})\n\n",[1359],{"type":21,"tag":508,"props":1360,"children":1361},{"__ignoreMap":8},[1362,1403,1410,1439,1447,1455,1463,1484,1509,1534,1559,1567,1592,1600,1624,1631,1676,1702,1728,1754,1818,1826,1868,1877,1913,1939,1983,1992,2044,2070,2088,2097,2139,2166,2174,2215,2246,2255,2263,2272,2315,2324,2357,2366,2399,2413,2422,2441,2459,2468,2477,2486,2504,2513,2522,2531,2540,2549],{"type":21,"tag":512,"props":1363,"children":1364},{"class":514,"line":515},[1365,1369,1373,1378,1382,1386,1390,1394,1399],{"type":21,"tag":512,"props":1366,"children":1367},{"style":809},[1368],{"type":27,"value":812},{"type":21,"tag":512,"props":1370,"children":1371},{"style":815},[1372],{"type":27,"value":818},{"type":21,"tag":512,"props":1374,"children":1375},{"style":686},[1376],{"type":27,"value":1377},"Client",{"type":21,"tag":512,"props":1379,"children":1380},{"style":815},[1381],{"type":27,"value":828},{"type":21,"tag":512,"props":1383,"children":1384},{"style":809},[1385],{"type":27,"value":833},{"type":21,"tag":512,"props":1387,"children":1388},{"style":519},[1389],{"type":27,"value":838},{"type":21,"tag":512,"props":1391,"children":1392},{"style":815},[1393],{"type":27,"value":843},{"type":21,"tag":512,"props":1395,"children":1396},{"style":525},[1397],{"type":27,"value":1398},"'ssh2'",{"type":21,"tag":512,"props":1400,"children":1401},{"style":815},[1402],{"type":27,"value":853},{"type":21,"tag":512,"props":1404,"children":1405},{"class":514,"line":359},[1406],{"type":21,"tag":512,"props":1407,"children":1408},{"emptyLinePlaceholder":859},[1409],{"type":27,"value":862},{"type":21,"tag":512,"props":1411,"children":1412},{"class":514,"line":365},[1413,1417,1422,1426,1430,1435],{"type":21,"tag":512,"props":1414,"children":1415},{"style":809},[1416],{"type":27,"value":812},{"type":21,"tag":512,"props":1418,"children":1419},{"style":686},[1420],{"type":27,"value":1421}," conn",{"type":21,"tag":512,"props":1423,"children":1424},{"style":809},[1425],{"type":27,"value":887},{"type":21,"tag":512,"props":1427,"children":1428},{"style":809},[1429],{"type":27,"value":1026},{"type":21,"tag":512,"props":1431,"children":1432},{"style":519},[1433],{"type":27,"value":1434}," Client",{"type":21,"tag":512,"props":1436,"children":1437},{"style":815},[1438],{"type":27,"value":952},{"type":21,"tag":512,"props":1440,"children":1441},{"class":514,"line":673},[1442],{"type":21,"tag":512,"props":1443,"children":1444},{"style":646},[1445],{"type":27,"value":1446},"// n8n内部提供获取传入节点数据的方式，具体可以看\n",{"type":21,"tag":512,"props":1448,"children":1449},{"class":514,"line":900},[1450],{"type":21,"tag":512,"props":1451,"children":1452},{"style":646},[1453],{"type":27,"value":1454},"// https://docs.n8n.io/code/builtin/current-node-input/\n",{"type":21,"tag":512,"props":1456,"children":1457},{"class":514,"line":908},[1458],{"type":21,"tag":512,"props":1459,"children":1460},{"style":646},[1461],{"type":27,"value":1462},"// 这里拿到上一个节点写入的ip属性\n",{"type":21,"tag":512,"props":1464,"children":1465},{"class":514,"line":955},[1466,1470,1475,1479],{"type":21,"tag":512,"props":1467,"children":1468},{"style":809},[1469],{"type":27,"value":812},{"type":21,"tag":512,"props":1471,"children":1472},{"style":686},[1473],{"type":27,"value":1474}," host",{"type":21,"tag":512,"props":1476,"children":1477},{"style":809},[1478],{"type":27,"value":887},{"type":21,"tag":512,"props":1480,"children":1481},{"style":815},[1482],{"type":27,"value":1483}," $json.ip;\n",{"type":21,"tag":512,"props":1485,"children":1486},{"class":514,"line":983},[1487,1491,1496,1500,1505],{"type":21,"tag":512,"props":1488,"children":1489},{"style":809},[1490],{"type":27,"value":812},{"type":21,"tag":512,"props":1492,"children":1493},{"style":686},[1494],{"type":27,"value":1495}," port",{"type":21,"tag":512,"props":1497,"children":1498},{"style":809},[1499],{"type":27,"value":887},{"type":21,"tag":512,"props":1501,"children":1502},{"style":686},[1503],{"type":27,"value":1504}," 22",{"type":21,"tag":512,"props":1506,"children":1507},{"style":815},[1508],{"type":27,"value":897},{"type":21,"tag":512,"props":1510,"children":1511},{"class":514,"line":991},[1512,1516,1521,1525,1530],{"type":21,"tag":512,"props":1513,"children":1514},{"style":809},[1515],{"type":27,"value":812},{"type":21,"tag":512,"props":1517,"children":1518},{"style":686},[1519],{"type":27,"value":1520}," username",{"type":21,"tag":512,"props":1522,"children":1523},{"style":809},[1524],{"type":27,"value":887},{"type":21,"tag":512,"props":1526,"children":1527},{"style":525},[1528],{"type":27,"value":1529}," 'root'",{"type":21,"tag":512,"props":1531,"children":1532},{"style":815},[1533],{"type":27,"value":897},{"type":21,"tag":512,"props":1535,"children":1536},{"class":514,"line":1015},[1537,1541,1546,1550,1555],{"type":21,"tag":512,"props":1538,"children":1539},{"style":809},[1540],{"type":27,"value":812},{"type":21,"tag":512,"props":1542,"children":1543},{"style":686},[1544],{"type":27,"value":1545}," password",{"type":21,"tag":512,"props":1547,"children":1548},{"style":809},[1549],{"type":27,"value":887},{"type":21,"tag":512,"props":1551,"children":1552},{"style":525},[1553],{"type":27,"value":1554}," 'xxxx'",{"type":21,"tag":512,"props":1556,"children":1557},{"style":815},[1558],{"type":27,"value":897},{"type":21,"tag":512,"props":1560,"children":1561},{"class":514,"line":1047},[1562],{"type":21,"tag":512,"props":1563,"children":1564},{"style":646},[1565],{"type":27,"value":1566},"// docker镜像源的用户名\n",{"type":21,"tag":512,"props":1568,"children":1569},{"class":514,"line":1056},[1570,1574,1579,1583,1588],{"type":21,"tag":512,"props":1571,"children":1572},{"style":809},[1573],{"type":27,"value":812},{"type":21,"tag":512,"props":1575,"children":1576},{"style":686},[1577],{"type":27,"value":1578}," dockerUser",{"type":21,"tag":512,"props":1580,"children":1581},{"style":809},[1582],{"type":27,"value":887},{"type":21,"tag":512,"props":1584,"children":1585},{"style":525},[1586],{"type":27,"value":1587}," 'xxxxx'",{"type":21,"tag":512,"props":1589,"children":1590},{"style":815},[1591],{"type":27,"value":897},{"type":21,"tag":512,"props":1593,"children":1594},{"class":514,"line":1070},[1595],{"type":21,"tag":512,"props":1596,"children":1597},{"style":646},[1598],{"type":27,"value":1599},"// docker镜像源的密码\n",{"type":21,"tag":512,"props":1601,"children":1602},{"class":514,"line":1079},[1603,1607,1612,1616,1620],{"type":21,"tag":512,"props":1604,"children":1605},{"style":809},[1606],{"type":27,"value":812},{"type":21,"tag":512,"props":1608,"children":1609},{"style":686},[1610],{"type":27,"value":1611}," dockerPassword",{"type":21,"tag":512,"props":1613,"children":1614},{"style":809},[1615],{"type":27,"value":887},{"type":21,"tag":512,"props":1617,"children":1618},{"style":525},[1619],{"type":27,"value":1554},{"type":21,"tag":512,"props":1621,"children":1622},{"style":815},[1623],{"type":27,"value":897},{"type":21,"tag":512,"props":1625,"children":1626},{"class":514,"line":1317},[1627],{"type":21,"tag":512,"props":1628,"children":1629},{"emptyLinePlaceholder":859},[1630],{"type":27,"value":862},{"type":21,"tag":512,"props":1632,"children":1633},{"class":514,"line":1326},[1634,1638,1643,1647,1652,1657,1662,1667,1672],{"type":21,"tag":512,"props":1635,"children":1636},{"style":809},[1637],{"type":27,"value":812},{"type":21,"tag":512,"props":1639,"children":1640},{"style":686},[1641],{"type":27,"value":1642}," loginCommand",{"type":21,"tag":512,"props":1644,"children":1645},{"style":809},[1646],{"type":27,"value":887},{"type":21,"tag":512,"props":1648,"children":1649},{"style":525},[1650],{"type":27,"value":1651}," `docker login -u ${",{"type":21,"tag":512,"props":1653,"children":1654},{"style":815},[1655],{"type":27,"value":1656},"dockerUser",{"type":21,"tag":512,"props":1658,"children":1659},{"style":525},[1660],{"type":27,"value":1661},"} -p ${",{"type":21,"tag":512,"props":1663,"children":1664},{"style":815},[1665],{"type":27,"value":1666},"dockerPassword",{"type":21,"tag":512,"props":1668,"children":1669},{"style":525},[1670],{"type":27,"value":1671},"} xxxx`",{"type":21,"tag":512,"props":1673,"children":1674},{"style":815},[1675],{"type":27,"value":897},{"type":21,"tag":512,"props":1677,"children":1679},{"class":514,"line":1678},17,[1680,1684,1689,1693,1698],{"type":21,"tag":512,"props":1681,"children":1682},{"style":809},[1683],{"type":27,"value":812},{"type":21,"tag":512,"props":1685,"children":1686},{"style":686},[1687],{"type":27,"value":1688}," cdCommand",{"type":21,"tag":512,"props":1690,"children":1691},{"style":809},[1692],{"type":27,"value":887},{"type":21,"tag":512,"props":1694,"children":1695},{"style":525},[1696],{"type":27,"value":1697}," 'cd /volume1/docker/xxx'",{"type":21,"tag":512,"props":1699,"children":1700},{"style":815},[1701],{"type":27,"value":897},{"type":21,"tag":512,"props":1703,"children":1705},{"class":514,"line":1704},18,[1706,1710,1715,1719,1724],{"type":21,"tag":512,"props":1707,"children":1708},{"style":809},[1709],{"type":27,"value":812},{"type":21,"tag":512,"props":1711,"children":1712},{"style":686},[1713],{"type":27,"value":1714}," pullCommand",{"type":21,"tag":512,"props":1716,"children":1717},{"style":809},[1718],{"type":27,"value":887},{"type":21,"tag":512,"props":1720,"children":1721},{"style":525},[1722],{"type":27,"value":1723}," 'docker-compose pull'",{"type":21,"tag":512,"props":1725,"children":1726},{"style":815},[1727],{"type":27,"value":897},{"type":21,"tag":512,"props":1729,"children":1731},{"class":514,"line":1730},19,[1732,1736,1741,1745,1750],{"type":21,"tag":512,"props":1733,"children":1734},{"style":809},[1735],{"type":27,"value":812},{"type":21,"tag":512,"props":1737,"children":1738},{"style":686},[1739],{"type":27,"value":1740}," recreateCommand",{"type":21,"tag":512,"props":1742,"children":1743},{"style":809},[1744],{"type":27,"value":887},{"type":21,"tag":512,"props":1746,"children":1747},{"style":525},[1748],{"type":27,"value":1749}," 'docker-compose up -d --force-recreate'",{"type":21,"tag":512,"props":1751,"children":1752},{"style":815},[1753],{"type":27,"value":897},{"type":21,"tag":512,"props":1755,"children":1757},{"class":514,"line":1756},20,[1758,1762,1767,1771,1776,1781,1786,1791,1795,1800,1804,1809,1814],{"type":21,"tag":512,"props":1759,"children":1760},{"style":809},[1761],{"type":27,"value":812},{"type":21,"tag":512,"props":1763,"children":1764},{"style":686},[1765],{"type":27,"value":1766}," allCommand",{"type":21,"tag":512,"props":1768,"children":1769},{"style":809},[1770],{"type":27,"value":887},{"type":21,"tag":512,"props":1772,"children":1773},{"style":525},[1774],{"type":27,"value":1775}," `${",{"type":21,"tag":512,"props":1777,"children":1778},{"style":815},[1779],{"type":27,"value":1780},"loginCommand",{"type":21,"tag":512,"props":1782,"children":1783},{"style":525},[1784],{"type":27,"value":1785},"} && ${",{"type":21,"tag":512,"props":1787,"children":1788},{"style":815},[1789],{"type":27,"value":1790},"cdCommand",{"type":21,"tag":512,"props":1792,"children":1793},{"style":525},[1794],{"type":27,"value":1785},{"type":21,"tag":512,"props":1796,"children":1797},{"style":815},[1798],{"type":27,"value":1799},"pullCommand",{"type":21,"tag":512,"props":1801,"children":1802},{"style":525},[1803],{"type":27,"value":1785},{"type":21,"tag":512,"props":1805,"children":1806},{"style":815},[1807],{"type":27,"value":1808},"recreateCommand",{"type":21,"tag":512,"props":1810,"children":1811},{"style":525},[1812],{"type":27,"value":1813},"}`",{"type":21,"tag":512,"props":1815,"children":1816},{"style":815},[1817],{"type":27,"value":897},{"type":21,"tag":512,"props":1819,"children":1821},{"class":514,"line":1820},21,[1822],{"type":21,"tag":512,"props":1823,"children":1824},{"emptyLinePlaceholder":859},[1825],{"type":27,"value":862},{"type":21,"tag":512,"props":1827,"children":1829},{"class":514,"line":1828},22,[1830,1834,1838,1843,1848,1854,1859,1864],{"type":21,"tag":512,"props":1831,"children":1832},{"style":809},[1833],{"type":27,"value":1062},{"type":21,"tag":512,"props":1835,"children":1836},{"style":809},[1837],{"type":27,"value":1026},{"type":21,"tag":512,"props":1839,"children":1840},{"style":686},[1841],{"type":27,"value":1842}," Promise",{"type":21,"tag":512,"props":1844,"children":1845},{"style":815},[1846],{"type":27,"value":1847},"((",{"type":21,"tag":512,"props":1849,"children":1851},{"style":1850},"--shiki-default:#FFAB70",[1852],{"type":27,"value":1853},"resolve",{"type":21,"tag":512,"props":1855,"children":1856},{"style":815},[1857],{"type":27,"value":1858},") ",{"type":21,"tag":512,"props":1860,"children":1861},{"style":809},[1862],{"type":27,"value":1863},"=>",{"type":21,"tag":512,"props":1865,"children":1866},{"style":815},[1867],{"type":27,"value":1067},{"type":21,"tag":512,"props":1869,"children":1871},{"class":514,"line":1870},23,[1872],{"type":21,"tag":512,"props":1873,"children":1874},{"style":815},[1875],{"type":27,"value":1876},"  conn\n",{"type":21,"tag":512,"props":1878,"children":1880},{"class":514,"line":1879},24,[1881,1886,1891,1895,1900,1905,1909],{"type":21,"tag":512,"props":1882,"children":1883},{"style":815},[1884],{"type":27,"value":1885},"  .",{"type":21,"tag":512,"props":1887,"children":1888},{"style":519},[1889],{"type":27,"value":1890},"on",{"type":21,"tag":512,"props":1892,"children":1893},{"style":815},[1894],{"type":27,"value":843},{"type":21,"tag":512,"props":1896,"children":1897},{"style":525},[1898],{"type":27,"value":1899},"'ready'",{"type":21,"tag":512,"props":1901,"children":1902},{"style":815},[1903],{"type":27,"value":1904},", () ",{"type":21,"tag":512,"props":1906,"children":1907},{"style":809},[1908],{"type":27,"value":1863},{"type":21,"tag":512,"props":1910,"children":1911},{"style":815},[1912],{"type":27,"value":1067},{"type":21,"tag":512,"props":1914,"children":1916},{"class":514,"line":1915},25,[1917,1922,1926,1930,1935],{"type":21,"tag":512,"props":1918,"children":1919},{"style":815},[1920],{"type":27,"value":1921},"    console.",{"type":21,"tag":512,"props":1923,"children":1924},{"style":519},[1925],{"type":27,"value":966},{"type":21,"tag":512,"props":1927,"children":1928},{"style":815},[1929],{"type":27,"value":843},{"type":21,"tag":512,"props":1931,"children":1932},{"style":525},[1933],{"type":27,"value":1934},"'Client :: ready'",{"type":21,"tag":512,"props":1936,"children":1937},{"style":815},[1938],{"type":27,"value":853},{"type":21,"tag":512,"props":1940,"children":1942},{"class":514,"line":1941},26,[1943,1948,1952,1956,1961,1966,1971,1975,1979],{"type":21,"tag":512,"props":1944,"children":1945},{"style":815},[1946],{"type":27,"value":1947},"    conn.",{"type":21,"tag":512,"props":1949,"children":1950},{"style":519},[1951],{"type":27,"value":636},{"type":21,"tag":512,"props":1953,"children":1954},{"style":815},[1955],{"type":27,"value":1847},{"type":21,"tag":512,"props":1957,"children":1958},{"style":1850},[1959],{"type":27,"value":1960},"err",{"type":21,"tag":512,"props":1962,"children":1963},{"style":815},[1964],{"type":27,"value":1965},", ",{"type":21,"tag":512,"props":1967,"children":1968},{"style":1850},[1969],{"type":27,"value":1970},"stream",{"type":21,"tag":512,"props":1972,"children":1973},{"style":815},[1974],{"type":27,"value":1858},{"type":21,"tag":512,"props":1976,"children":1977},{"style":809},[1978],{"type":27,"value":1863},{"type":21,"tag":512,"props":1980,"children":1981},{"style":815},[1982],{"type":27,"value":1067},{"type":21,"tag":512,"props":1984,"children":1986},{"class":514,"line":1985},27,[1987],{"type":21,"tag":512,"props":1988,"children":1989},{"style":815},[1990],{"type":27,"value":1991},"      stream\n",{"type":21,"tag":512,"props":1993,"children":1995},{"class":514,"line":1994},28,[1996,2001,2005,2009,2014,2019,2023,2027,2032,2036,2040],{"type":21,"tag":512,"props":1997,"children":1998},{"style":815},[1999],{"type":27,"value":2000},"        .",{"type":21,"tag":512,"props":2002,"children":2003},{"style":519},[2004],{"type":27,"value":1890},{"type":21,"tag":512,"props":2006,"children":2007},{"style":815},[2008],{"type":27,"value":843},{"type":21,"tag":512,"props":2010,"children":2011},{"style":525},[2012],{"type":27,"value":2013},"'close'",{"type":21,"tag":512,"props":2015,"children":2016},{"style":815},[2017],{"type":27,"value":2018},", (",{"type":21,"tag":512,"props":2020,"children":2021},{"style":1850},[2022],{"type":27,"value":508},{"type":21,"tag":512,"props":2024,"children":2025},{"style":815},[2026],{"type":27,"value":1965},{"type":21,"tag":512,"props":2028,"children":2029},{"style":1850},[2030],{"type":27,"value":2031},"signal",{"type":21,"tag":512,"props":2033,"children":2034},{"style":815},[2035],{"type":27,"value":1858},{"type":21,"tag":512,"props":2037,"children":2038},{"style":809},[2039],{"type":27,"value":1863},{"type":21,"tag":512,"props":2041,"children":2042},{"style":815},[2043],{"type":27,"value":1067},{"type":21,"tag":512,"props":2045,"children":2047},{"class":514,"line":2046},29,[2048,2053,2057,2061,2066],{"type":21,"tag":512,"props":2049,"children":2050},{"style":815},[2051],{"type":27,"value":2052},"          console.",{"type":21,"tag":512,"props":2054,"children":2055},{"style":519},[2056],{"type":27,"value":966},{"type":21,"tag":512,"props":2058,"children":2059},{"style":815},[2060],{"type":27,"value":843},{"type":21,"tag":512,"props":2062,"children":2063},{"style":525},[2064],{"type":27,"value":2065},"'执行完成'",{"type":21,"tag":512,"props":2067,"children":2068},{"style":815},[2069],{"type":27,"value":853},{"type":21,"tag":512,"props":2071,"children":2073},{"class":514,"line":2072},30,[2074,2079,2084],{"type":21,"tag":512,"props":2075,"children":2076},{"style":815},[2077],{"type":27,"value":2078},"          conn.",{"type":21,"tag":512,"props":2080,"children":2081},{"style":519},[2082],{"type":27,"value":2083},"end",{"type":21,"tag":512,"props":2085,"children":2086},{"style":815},[2087],{"type":27,"value":952},{"type":21,"tag":512,"props":2089,"children":2091},{"class":514,"line":2090},31,[2092],{"type":21,"tag":512,"props":2093,"children":2094},{"style":815},[2095],{"type":27,"value":2096},"        })\n",{"type":21,"tag":512,"props":2098,"children":2100},{"class":514,"line":2099},32,[2101,2105,2109,2113,2118,2122,2127,2131,2135],{"type":21,"tag":512,"props":2102,"children":2103},{"style":815},[2104],{"type":27,"value":2000},{"type":21,"tag":512,"props":2106,"children":2107},{"style":519},[2108],{"type":27,"value":1890},{"type":21,"tag":512,"props":2110,"children":2111},{"style":815},[2112],{"type":27,"value":843},{"type":21,"tag":512,"props":2114,"children":2115},{"style":525},[2116],{"type":27,"value":2117},"'data'",{"type":21,"tag":512,"props":2119,"children":2120},{"style":815},[2121],{"type":27,"value":2018},{"type":21,"tag":512,"props":2123,"children":2124},{"style":1850},[2125],{"type":27,"value":2126},"data",{"type":21,"tag":512,"props":2128,"children":2129},{"style":815},[2130],{"type":27,"value":1858},{"type":21,"tag":512,"props":2132,"children":2133},{"style":809},[2134],{"type":27,"value":1863},{"type":21,"tag":512,"props":2136,"children":2137},{"style":815},[2138],{"type":27,"value":1067},{"type":21,"tag":512,"props":2140,"children":2142},{"class":514,"line":2141},33,[2143,2147,2151,2156,2161],{"type":21,"tag":512,"props":2144,"children":2145},{"style":815},[2146],{"type":27,"value":2052},{"type":21,"tag":512,"props":2148,"children":2149},{"style":519},[2150],{"type":27,"value":966},{"type":21,"tag":512,"props":2152,"children":2153},{"style":815},[2154],{"type":27,"value":2155},"(data.",{"type":21,"tag":512,"props":2157,"children":2158},{"style":519},[2159],{"type":27,"value":2160},"toString",{"type":21,"tag":512,"props":2162,"children":2163},{"style":815},[2164],{"type":27,"value":2165},"());\n",{"type":21,"tag":512,"props":2167,"children":2169},{"class":514,"line":2168},34,[2170],{"type":21,"tag":512,"props":2171,"children":2172},{"style":815},[2173],{"type":27,"value":2096},{"type":21,"tag":512,"props":2175,"children":2177},{"class":514,"line":2176},35,[2178,2183,2187,2191,2195,2199,2203,2207,2211],{"type":21,"tag":512,"props":2179,"children":2180},{"style":815},[2181],{"type":27,"value":2182},"        .stderr.",{"type":21,"tag":512,"props":2184,"children":2185},{"style":519},[2186],{"type":27,"value":1890},{"type":21,"tag":512,"props":2188,"children":2189},{"style":815},[2190],{"type":27,"value":843},{"type":21,"tag":512,"props":2192,"children":2193},{"style":525},[2194],{"type":27,"value":2117},{"type":21,"tag":512,"props":2196,"children":2197},{"style":815},[2198],{"type":27,"value":2018},{"type":21,"tag":512,"props":2200,"children":2201},{"style":1850},[2202],{"type":27,"value":2126},{"type":21,"tag":512,"props":2204,"children":2205},{"style":815},[2206],{"type":27,"value":1858},{"type":21,"tag":512,"props":2208,"children":2209},{"style":809},[2210],{"type":27,"value":1863},{"type":21,"tag":512,"props":2212,"children":2213},{"style":815},[2214],{"type":27,"value":1067},{"type":21,"tag":512,"props":2216,"children":2218},{"class":514,"line":2217},36,[2219,2223,2227,2231,2236,2241],{"type":21,"tag":512,"props":2220,"children":2221},{"style":815},[2222],{"type":27,"value":2052},{"type":21,"tag":512,"props":2224,"children":2225},{"style":519},[2226],{"type":27,"value":966},{"type":21,"tag":512,"props":2228,"children":2229},{"style":815},[2230],{"type":27,"value":843},{"type":21,"tag":512,"props":2232,"children":2233},{"style":525},[2234],{"type":27,"value":2235},"'STDERR: '",{"type":21,"tag":512,"props":2237,"children":2238},{"style":809},[2239],{"type":27,"value":2240}," +",{"type":21,"tag":512,"props":2242,"children":2243},{"style":815},[2244],{"type":27,"value":2245}," data);\n",{"type":21,"tag":512,"props":2247,"children":2249},{"class":514,"line":2248},37,[2250],{"type":21,"tag":512,"props":2251,"children":2252},{"style":815},[2253],{"type":27,"value":2254},"        });\n",{"type":21,"tag":512,"props":2256,"children":2258},{"class":514,"line":2257},38,[2259],{"type":21,"tag":512,"props":2260,"children":2261},{"emptyLinePlaceholder":859},[2262],{"type":27,"value":862},{"type":21,"tag":512,"props":2264,"children":2266},{"class":514,"line":2265},39,[2267],{"type":21,"tag":512,"props":2268,"children":2269},{"style":646},[2270],{"type":27,"value":2271},"      //执行命令 \n",{"type":21,"tag":512,"props":2273,"children":2275},{"class":514,"line":2274},40,[2276,2281,2286,2291,2296,2301,2306,2311],{"type":21,"tag":512,"props":2277,"children":2278},{"style":815},[2279],{"type":27,"value":2280},"      stream.",{"type":21,"tag":512,"props":2282,"children":2283},{"style":519},[2284],{"type":27,"value":2285},"write",{"type":21,"tag":512,"props":2287,"children":2288},{"style":815},[2289],{"type":27,"value":2290},"(allCommand ",{"type":21,"tag":512,"props":2292,"children":2293},{"style":809},[2294],{"type":27,"value":2295},"+",{"type":21,"tag":512,"props":2297,"children":2298},{"style":525},[2299],{"type":27,"value":2300}," '",{"type":21,"tag":512,"props":2302,"children":2303},{"style":686},[2304],{"type":27,"value":2305},"\\n",{"type":21,"tag":512,"props":2307,"children":2308},{"style":525},[2309],{"type":27,"value":2310},"'",{"type":21,"tag":512,"props":2312,"children":2313},{"style":815},[2314],{"type":27,"value":853},{"type":21,"tag":512,"props":2316,"children":2318},{"class":514,"line":2317},41,[2319],{"type":21,"tag":512,"props":2320,"children":2321},{"style":646},[2322],{"type":27,"value":2323},"      // 退出\n",{"type":21,"tag":512,"props":2325,"children":2327},{"class":514,"line":2326},42,[2328,2332,2336,2340,2345,2349,2353],{"type":21,"tag":512,"props":2329,"children":2330},{"style":815},[2331],{"type":27,"value":2280},{"type":21,"tag":512,"props":2333,"children":2334},{"style":519},[2335],{"type":27,"value":2285},{"type":21,"tag":512,"props":2337,"children":2338},{"style":815},[2339],{"type":27,"value":843},{"type":21,"tag":512,"props":2341,"children":2342},{"style":525},[2343],{"type":27,"value":2344},"'exit",{"type":21,"tag":512,"props":2346,"children":2347},{"style":686},[2348],{"type":27,"value":2305},{"type":21,"tag":512,"props":2350,"children":2351},{"style":525},[2352],{"type":27,"value":2310},{"type":21,"tag":512,"props":2354,"children":2355},{"style":815},[2356],{"type":27,"value":853},{"type":21,"tag":512,"props":2358,"children":2360},{"class":514,"line":2359},43,[2361],{"type":21,"tag":512,"props":2362,"children":2363},{"style":815},[2364],{"type":27,"value":2365},"    });\n",{"type":21,"tag":512,"props":2367,"children":2369},{"class":514,"line":2368},44,[2370,2375,2379,2383,2387,2391,2395],{"type":21,"tag":512,"props":2371,"children":2372},{"style":815},[2373],{"type":27,"value":2374},"  }).",{"type":21,"tag":512,"props":2376,"children":2377},{"style":519},[2378],{"type":27,"value":1890},{"type":21,"tag":512,"props":2380,"children":2381},{"style":815},[2382],{"type":27,"value":843},{"type":21,"tag":512,"props":2384,"children":2385},{"style":525},[2386],{"type":27,"value":2013},{"type":21,"tag":512,"props":2388,"children":2389},{"style":815},[2390],{"type":27,"value":1904},{"type":21,"tag":512,"props":2392,"children":2393},{"style":809},[2394],{"type":27,"value":1863},{"type":21,"tag":512,"props":2396,"children":2397},{"style":815},[2398],{"type":27,"value":1067},{"type":21,"tag":512,"props":2400,"children":2402},{"class":514,"line":2401},45,[2403,2408],{"type":21,"tag":512,"props":2404,"children":2405},{"style":519},[2406],{"type":27,"value":2407},"    resolve",{"type":21,"tag":512,"props":2409,"children":2410},{"style":815},[2411],{"type":27,"value":2412},"([\n",{"type":21,"tag":512,"props":2414,"children":2416},{"class":514,"line":2415},46,[2417],{"type":21,"tag":512,"props":2418,"children":2419},{"style":815},[2420],{"type":27,"value":2421},"      {\n",{"type":21,"tag":512,"props":2423,"children":2425},{"class":514,"line":2424},47,[2426,2431,2436],{"type":21,"tag":512,"props":2427,"children":2428},{"style":815},[2429],{"type":27,"value":2430},"        msg: ",{"type":21,"tag":512,"props":2432,"children":2433},{"style":525},[2434],{"type":27,"value":2435},"'success'",{"type":21,"tag":512,"props":2437,"children":2438},{"style":815},[2439],{"type":27,"value":2440},",\n",{"type":21,"tag":512,"props":2442,"children":2444},{"class":514,"line":2443},48,[2445,2450,2455],{"type":21,"tag":512,"props":2446,"children":2447},{"style":815},[2448],{"type":27,"value":2449},"        code: ",{"type":21,"tag":512,"props":2451,"children":2452},{"style":686},[2453],{"type":27,"value":2454},"0",{"type":21,"tag":512,"props":2456,"children":2457},{"style":815},[2458],{"type":27,"value":2440},{"type":21,"tag":512,"props":2460,"children":2462},{"class":514,"line":2461},49,[2463],{"type":21,"tag":512,"props":2464,"children":2465},{"style":815},[2466],{"type":27,"value":2467},"      }\n",{"type":21,"tag":512,"props":2469,"children":2471},{"class":514,"line":2470},50,[2472],{"type":21,"tag":512,"props":2473,"children":2474},{"style":815},[2475],{"type":27,"value":2476},"    ]);\n",{"type":21,"tag":512,"props":2478,"children":2480},{"class":514,"line":2479},51,[2481],{"type":21,"tag":512,"props":2482,"children":2483},{"style":815},[2484],{"type":27,"value":2485},"  })\n",{"type":21,"tag":512,"props":2487,"children":2489},{"class":514,"line":2488},52,[2490,2494,2499],{"type":21,"tag":512,"props":2491,"children":2492},{"style":815},[2493],{"type":27,"value":1885},{"type":21,"tag":512,"props":2495,"children":2496},{"style":519},[2497],{"type":27,"value":2498},"connect",{"type":21,"tag":512,"props":2500,"children":2501},{"style":815},[2502],{"type":27,"value":2503},"({\n",{"type":21,"tag":512,"props":2505,"children":2507},{"class":514,"line":2506},53,[2508],{"type":21,"tag":512,"props":2509,"children":2510},{"style":815},[2511],{"type":27,"value":2512},"    host,\n",{"type":21,"tag":512,"props":2514,"children":2516},{"class":514,"line":2515},54,[2517],{"type":21,"tag":512,"props":2518,"children":2519},{"style":815},[2520],{"type":27,"value":2521},"    port,\n",{"type":21,"tag":512,"props":2523,"children":2525},{"class":514,"line":2524},55,[2526],{"type":21,"tag":512,"props":2527,"children":2528},{"style":815},[2529],{"type":27,"value":2530},"    username,\n",{"type":21,"tag":512,"props":2532,"children":2534},{"class":514,"line":2533},56,[2535],{"type":21,"tag":512,"props":2536,"children":2537},{"style":815},[2538],{"type":27,"value":2539},"    password,\n",{"type":21,"tag":512,"props":2541,"children":2543},{"class":514,"line":2542},57,[2544],{"type":21,"tag":512,"props":2545,"children":2546},{"style":815},[2547],{"type":27,"value":2548},"  });\n",{"type":21,"tag":512,"props":2550,"children":2552},{"class":514,"line":2551},58,[2553],{"type":21,"tag":512,"props":2554,"children":2555},{"style":815},[2556],{"type":27,"value":2557},"})\n",{"type":21,"tag":29,"props":2559,"children":2560},{},[2561],{"type":27,"value":2562},"测试一下试试：",{"type":21,"tag":29,"props":2564,"children":2565},{},[2566],{"type":21,"tag":459,"props":2567,"children":2569},{"alt":8,"src":2568},"https://johnhom-img.oss-cn-guangzhou.aliyuncs.com/obsidian/Pasted%20image%2020250123195725.png",[],{"type":21,"tag":29,"props":2571,"children":2572},{},[2573],{"type":27,"value":2574},"也是顺利执行完成，在nas管理页面也看到镜像拉取到最新的版本，并且自动重新启动了。",{"type":21,"tag":29,"props":2576,"children":2577},{},[2578],{"type":27,"value":2579},"最后我加上发送邮件的节点，运行到这个节点就给我的邮箱发送邮件通知，这个节点搭建也比较简单，我这边就不展示了。",{"type":21,"tag":29,"props":2581,"children":2582},{},[2583],{"type":27,"value":2584},"目前我的重启容器工作流如下：",{"type":21,"tag":29,"props":2586,"children":2587},{},[2588],{"type":21,"tag":459,"props":2589,"children":2591},{"alt":8,"src":2590},"https://johnhom-img.oss-cn-guangzhou.aliyuncs.com/obsidian/Pasted%20image%2020250123200211.png",[],{"type":21,"tag":29,"props":2593,"children":2594},{},[2595],{"type":27,"value":2596},"触发的方式就是直接请求从Webhook节点里拿到的生产环境url：",{"type":21,"tag":29,"props":2598,"children":2599},{},[2600],{"type":21,"tag":459,"props":2601,"children":2603},{"alt":8,"src":2602},"https://johnhom-img.oss-cn-guangzhou.aliyuncs.com/obsidian/Pasted%20image%2020250123200336.png",[],{"type":21,"tag":29,"props":2605,"children":2606},{},[2607,2609,2615],{"type":27,"value":2608},"当ci的docker镜像构建完之后，就可以通过",{"type":21,"tag":508,"props":2610,"children":2612},{"className":2611},[],[2613],{"type":27,"value":2614},"curl \u003Cwebhook_url>",{"type":27,"value":2616},"的方式触发nas拉取镜像并重启容器。",{"type":21,"tag":29,"props":2618,"children":2619},{},[2620],{"type":27,"value":2621},"其实还需要实现一个步骤就是内网穿透，需要把这个webhook_url暴露给外网环境，否则只能在内网里触发webhook。目前碍于篇幅的原因，我就不在这篇文章里展开啦。",{"type":21,"tag":22,"props":2623,"children":2625},{"id":2624},"总结",[2626],{"type":27,"value":2624},{"type":21,"tag":29,"props":2628,"children":2629},{},[2630],{"type":27,"value":2631},"经过以上的步骤，已经大致摸清了n8n这个自动化工具的使用流程。它的用户界面让我印象特别深刻，特别的简洁明了，让人一目了然整个工作流的执行顺序和操作流程，让一个没使用过的人都能轻易上手创建工作流。",{"type":21,"tag":29,"props":2633,"children":2634},{},[2635],{"type":27,"value":2636},"不仅如此，这个工具内置了许多的触发器和节点类型，功能已经相当完善，可以满足大多数人的使用需求。在官方的示例中，甚至可以跟AI结合，接收excel表格并按要求处理后导出，还有更多强大的功能等待着我们去发现和发掘。",{"type":21,"tag":29,"props":2638,"children":2639},{},[2640],{"type":27,"value":2641},"在使用过程中，我也发现了一些问题：",{"type":21,"tag":295,"props":2643,"children":2644},{},[2645,2650],{"type":21,"tag":79,"props":2646,"children":2647},{},[2648],{"type":27,"value":2649},"代码节点运行js时，只能运行cjs规范的代码，目前暂不支持esm规范。",{"type":21,"tag":79,"props":2651,"children":2652},{},[2653],{"type":27,"value":2654},"能作为触发器的app基本都是海外，国内的还未适配。",{"type":21,"tag":29,"props":2656,"children":2657},{},[2658],{"type":27,"value":2659},"但是这并不影响我对这款工具的喜爱。",{"type":21,"tag":29,"props":2661,"children":2662},{},[2663],{"type":27,"value":2664},"希望后面能够引入AI助手，我们只需要动动嘴，AI就会帮我们创建好工作流。",{"type":21,"tag":29,"props":2666,"children":2667},{},[2668],{"type":27,"value":2669},"这样不就更加接近漫威世界里钢铁侠的贾维斯了？",{"type":21,"tag":2671,"props":2672,"children":2673},"style",{},[2674],{"type":27,"value":2675},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}",{"title":8,"searchDepth":359,"depth":359,"links":2677},[2678,2679,2680],{"id":393,"depth":359,"text":393},{"id":482,"depth":359,"text":482},{"id":2624,"depth":359,"text":2624},"content:articles:20250122.md","articles/20250122.md",{"_path":2684,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":2685,"description":2686,"published":2687,"categories":2688,"slug":2685,"body":2689,"_type":376,"_id":9297,"_source":378,"_file":9298,"_extension":380},"/articles/20240516","责任链模式最强工具res-chain","责任链的好处，以及如何封装一个自己的责任链","2024/05/16",[242],{"type":18,"children":2690,"toc":9288},[2691,2699,2704,2716,2728,2748,2760,3147,3182,3187,3192,3375,3380,3385,3390,3395,3400,3423,3428,3446,3451,3456,4092,4097,4102,4940,4945,4958,4971,5450,5463,5469,5488,5502,6169,6181,6985,7003,7015,7020,7600,7609,7621,7665,7670,7675,8327,8332,8687,8714,8719,8733,8781,8786,9189,9194,9199,9204,9209,9235,9239,9244,9249,9254,9259,9270,9275,9284],{"type":21,"tag":29,"props":2692,"children":2693},{},[2694],{"type":21,"tag":459,"props":2695,"children":2698},{"alt":2696,"src":2697},"Pasted image 20240515003946","https://johnhom-img.oss-cn-guangzhou.aliyuncs.com/images/Pasted%20image%2020240515003946.png",[],{"type":21,"tag":22,"props":2700,"children":2702},{"id":2701},"责任链模式介绍",[2703],{"type":27,"value":2701},{"type":21,"tag":29,"props":2705,"children":2706},{},[2707,2709,2714],{"type":27,"value":2708},"责任链模式（Chain of Responsibility Pattern）是一种行为型设计模式，",{"type":21,"tag":83,"props":2710,"children":2711},{},[2712],{"type":27,"value":2713},"它通过把请求的发送者和接收者解耦，将多个对象连接成一个链，并沿着这条链传递请求，直到有一个对象能够处理它为止，从而避免了请求的发送者和接收者之间的直接耦合",{"type":27,"value":2715},"。",{"type":21,"tag":29,"props":2717,"children":2718},{},[2719,2721,2726],{"type":27,"value":2720},"在责任链模式中，",{"type":21,"tag":83,"props":2722,"children":2723},{},[2724],{"type":27,"value":2725},"每个处理者都持有对下一个处理者的引用",{"type":27,"value":2727},"，即构成一个链表结构。当请求从链头开始流经链上的每个处理者时，如果某个处理者能够处理该请求，就直接处理，否则将请求发送给下一个处理者，直到有一个处理者能够处理为止。这种方式可以灵活地动态添加或修改请求的处理流程，同时也避免了由于请求类型过多而导致类的爆炸性增长的问题。",{"type":21,"tag":29,"props":2729,"children":2730},{},[2731,2733,2739,2741,2746],{"type":27,"value":2732},"看完以上责任链的描述，有没有发现跟Node.js的某些库特别的像，没错，就是",{"type":21,"tag":508,"props":2734,"children":2736},{"className":2735},[],[2737],{"type":27,"value":2738},"koa",{"type":27,"value":2740},"。什么？没用过",{"type":21,"tag":508,"props":2742,"children":2744},{"className":2743},[],[2745],{"type":27,"value":2738},{"type":27,"value":2747},"？那我建议你立马学起来，因为它用起来特别的简单。",{"type":21,"tag":29,"props":2749,"children":2750},{},[2751,2753,2758],{"type":27,"value":2752},"下面来一个简单使用",{"type":21,"tag":508,"props":2754,"children":2756},{"className":2755},[],[2757],{"type":27,"value":2738},{"type":27,"value":2759},"的例子：",{"type":21,"tag":501,"props":2761,"children":2765},{"className":2762,"code":2763,"language":2764,"meta":8,"style":8},"language-js shiki shiki-themes github-dark","const Koa = require('koa');\nconst app = new Koa();\n\napp.use(async (ctx, next) => {\n  if (ctx.request.url === '/') {\n    ctx.body = 'home';\n    return;\n  }\n  \n  next(); // 执行下面的回调函数\n});\n\napp.use(async (ctx, next) => {\n  if (ctx.request.url === '/hello') {\n    ctx.body = 'hello world';\n    return;\n  }\n});\n\napp.listen(3000);\n","js",[2766],{"type":21,"tag":508,"props":2767,"children":2768},{"__ignoreMap":8},[2769,2802,2830,2837,2889,2917,2938,2950,2958,2966,2984,2992,2999,3046,3070,3090,3101,3108,3115,3122],{"type":21,"tag":512,"props":2770,"children":2771},{"class":514,"line":515},[2772,2776,2781,2785,2789,2793,2798],{"type":21,"tag":512,"props":2773,"children":2774},{"style":809},[2775],{"type":27,"value":812},{"type":21,"tag":512,"props":2777,"children":2778},{"style":686},[2779],{"type":27,"value":2780}," Koa",{"type":21,"tag":512,"props":2782,"children":2783},{"style":809},[2784],{"type":27,"value":887},{"type":21,"tag":512,"props":2786,"children":2787},{"style":519},[2788],{"type":27,"value":838},{"type":21,"tag":512,"props":2790,"children":2791},{"style":815},[2792],{"type":27,"value":843},{"type":21,"tag":512,"props":2794,"children":2795},{"style":525},[2796],{"type":27,"value":2797},"'koa'",{"type":21,"tag":512,"props":2799,"children":2800},{"style":815},[2801],{"type":27,"value":853},{"type":21,"tag":512,"props":2803,"children":2804},{"class":514,"line":359},[2805,2809,2814,2818,2822,2826],{"type":21,"tag":512,"props":2806,"children":2807},{"style":809},[2808],{"type":27,"value":812},{"type":21,"tag":512,"props":2810,"children":2811},{"style":686},[2812],{"type":27,"value":2813}," app",{"type":21,"tag":512,"props":2815,"children":2816},{"style":809},[2817],{"type":27,"value":887},{"type":21,"tag":512,"props":2819,"children":2820},{"style":809},[2821],{"type":27,"value":1026},{"type":21,"tag":512,"props":2823,"children":2824},{"style":519},[2825],{"type":27,"value":2780},{"type":21,"tag":512,"props":2827,"children":2828},{"style":815},[2829],{"type":27,"value":952},{"type":21,"tag":512,"props":2831,"children":2832},{"class":514,"line":365},[2833],{"type":21,"tag":512,"props":2834,"children":2835},{"emptyLinePlaceholder":859},[2836],{"type":27,"value":862},{"type":21,"tag":512,"props":2838,"children":2839},{"class":514,"line":673},[2840,2845,2850,2854,2859,2863,2868,2872,2877,2881,2885],{"type":21,"tag":512,"props":2841,"children":2842},{"style":815},[2843],{"type":27,"value":2844},"app.",{"type":21,"tag":512,"props":2846,"children":2847},{"style":519},[2848],{"type":27,"value":2849},"use",{"type":21,"tag":512,"props":2851,"children":2852},{"style":815},[2853],{"type":27,"value":843},{"type":21,"tag":512,"props":2855,"children":2856},{"style":809},[2857],{"type":27,"value":2858},"async",{"type":21,"tag":512,"props":2860,"children":2861},{"style":815},[2862],{"type":27,"value":1002},{"type":21,"tag":512,"props":2864,"children":2865},{"style":1850},[2866],{"type":27,"value":2867},"ctx",{"type":21,"tag":512,"props":2869,"children":2870},{"style":815},[2871],{"type":27,"value":1965},{"type":21,"tag":512,"props":2873,"children":2874},{"style":1850},[2875],{"type":27,"value":2876},"next",{"type":21,"tag":512,"props":2878,"children":2879},{"style":815},[2880],{"type":27,"value":1858},{"type":21,"tag":512,"props":2882,"children":2883},{"style":809},[2884],{"type":27,"value":1863},{"type":21,"tag":512,"props":2886,"children":2887},{"style":815},[2888],{"type":27,"value":1067},{"type":21,"tag":512,"props":2890,"children":2891},{"class":514,"line":900},[2892,2897,2902,2907,2912],{"type":21,"tag":512,"props":2893,"children":2894},{"style":809},[2895],{"type":27,"value":2896},"  if",{"type":21,"tag":512,"props":2898,"children":2899},{"style":815},[2900],{"type":27,"value":2901}," (ctx.request.url ",{"type":21,"tag":512,"props":2903,"children":2904},{"style":809},[2905],{"type":27,"value":2906},"===",{"type":21,"tag":512,"props":2908,"children":2909},{"style":525},[2910],{"type":27,"value":2911}," '/'",{"type":21,"tag":512,"props":2913,"children":2914},{"style":815},[2915],{"type":27,"value":2916},") {\n",{"type":21,"tag":512,"props":2918,"children":2919},{"class":514,"line":908},[2920,2925,2929,2934],{"type":21,"tag":512,"props":2921,"children":2922},{"style":815},[2923],{"type":27,"value":2924},"    ctx.body ",{"type":21,"tag":512,"props":2926,"children":2927},{"style":809},[2928],{"type":27,"value":833},{"type":21,"tag":512,"props":2930,"children":2931},{"style":525},[2932],{"type":27,"value":2933}," 'home'",{"type":21,"tag":512,"props":2935,"children":2936},{"style":815},[2937],{"type":27,"value":897},{"type":21,"tag":512,"props":2939,"children":2940},{"class":514,"line":955},[2941,2946],{"type":21,"tag":512,"props":2942,"children":2943},{"style":809},[2944],{"type":27,"value":2945},"    return",{"type":21,"tag":512,"props":2947,"children":2948},{"style":815},[2949],{"type":27,"value":897},{"type":21,"tag":512,"props":2951,"children":2952},{"class":514,"line":983},[2953],{"type":21,"tag":512,"props":2954,"children":2955},{"style":815},[2956],{"type":27,"value":2957},"  }\n",{"type":21,"tag":512,"props":2959,"children":2960},{"class":514,"line":991},[2961],{"type":21,"tag":512,"props":2962,"children":2963},{"style":815},[2964],{"type":27,"value":2965},"  \n",{"type":21,"tag":512,"props":2967,"children":2968},{"class":514,"line":1015},[2969,2974,2979],{"type":21,"tag":512,"props":2970,"children":2971},{"style":519},[2972],{"type":27,"value":2973},"  next",{"type":21,"tag":512,"props":2975,"children":2976},{"style":815},[2977],{"type":27,"value":2978},"(); ",{"type":21,"tag":512,"props":2980,"children":2981},{"style":646},[2982],{"type":27,"value":2983},"// 执行下面的回调函数\n",{"type":21,"tag":512,"props":2985,"children":2986},{"class":514,"line":1047},[2987],{"type":21,"tag":512,"props":2988,"children":2989},{"style":815},[2990],{"type":27,"value":2991},"});\n",{"type":21,"tag":512,"props":2993,"children":2994},{"class":514,"line":1056},[2995],{"type":21,"tag":512,"props":2996,"children":2997},{"emptyLinePlaceholder":859},[2998],{"type":27,"value":862},{"type":21,"tag":512,"props":3000,"children":3001},{"class":514,"line":1070},[3002,3006,3010,3014,3018,3022,3026,3030,3034,3038,3042],{"type":21,"tag":512,"props":3003,"children":3004},{"style":815},[3005],{"type":27,"value":2844},{"type":21,"tag":512,"props":3007,"children":3008},{"style":519},[3009],{"type":27,"value":2849},{"type":21,"tag":512,"props":3011,"children":3012},{"style":815},[3013],{"type":27,"value":843},{"type":21,"tag":512,"props":3015,"children":3016},{"style":809},[3017],{"type":27,"value":2858},{"type":21,"tag":512,"props":3019,"children":3020},{"style":815},[3021],{"type":27,"value":1002},{"type":21,"tag":512,"props":3023,"children":3024},{"style":1850},[3025],{"type":27,"value":2867},{"type":21,"tag":512,"props":3027,"children":3028},{"style":815},[3029],{"type":27,"value":1965},{"type":21,"tag":512,"props":3031,"children":3032},{"style":1850},[3033],{"type":27,"value":2876},{"type":21,"tag":512,"props":3035,"children":3036},{"style":815},[3037],{"type":27,"value":1858},{"type":21,"tag":512,"props":3039,"children":3040},{"style":809},[3041],{"type":27,"value":1863},{"type":21,"tag":512,"props":3043,"children":3044},{"style":815},[3045],{"type":27,"value":1067},{"type":21,"tag":512,"props":3047,"children":3048},{"class":514,"line":1079},[3049,3053,3057,3061,3066],{"type":21,"tag":512,"props":3050,"children":3051},{"style":809},[3052],{"type":27,"value":2896},{"type":21,"tag":512,"props":3054,"children":3055},{"style":815},[3056],{"type":27,"value":2901},{"type":21,"tag":512,"props":3058,"children":3059},{"style":809},[3060],{"type":27,"value":2906},{"type":21,"tag":512,"props":3062,"children":3063},{"style":525},[3064],{"type":27,"value":3065}," '/hello'",{"type":21,"tag":512,"props":3067,"children":3068},{"style":815},[3069],{"type":27,"value":2916},{"type":21,"tag":512,"props":3071,"children":3072},{"class":514,"line":1317},[3073,3077,3081,3086],{"type":21,"tag":512,"props":3074,"children":3075},{"style":815},[3076],{"type":27,"value":2924},{"type":21,"tag":512,"props":3078,"children":3079},{"style":809},[3080],{"type":27,"value":833},{"type":21,"tag":512,"props":3082,"children":3083},{"style":525},[3084],{"type":27,"value":3085}," 'hello world'",{"type":21,"tag":512,"props":3087,"children":3088},{"style":815},[3089],{"type":27,"value":897},{"type":21,"tag":512,"props":3091,"children":3092},{"class":514,"line":1326},[3093,3097],{"type":21,"tag":512,"props":3094,"children":3095},{"style":809},[3096],{"type":27,"value":2945},{"type":21,"tag":512,"props":3098,"children":3099},{"style":815},[3100],{"type":27,"value":897},{"type":21,"tag":512,"props":3102,"children":3103},{"class":514,"line":1678},[3104],{"type":21,"tag":512,"props":3105,"children":3106},{"style":815},[3107],{"type":27,"value":2957},{"type":21,"tag":512,"props":3109,"children":3110},{"class":514,"line":1704},[3111],{"type":21,"tag":512,"props":3112,"children":3113},{"style":815},[3114],{"type":27,"value":2991},{"type":21,"tag":512,"props":3116,"children":3117},{"class":514,"line":1730},[3118],{"type":21,"tag":512,"props":3119,"children":3120},{"emptyLinePlaceholder":859},[3121],{"type":27,"value":862},{"type":21,"tag":512,"props":3123,"children":3124},{"class":514,"line":1756},[3125,3129,3134,3138,3143],{"type":21,"tag":512,"props":3126,"children":3127},{"style":815},[3128],{"type":27,"value":2844},{"type":21,"tag":512,"props":3130,"children":3131},{"style":519},[3132],{"type":27,"value":3133},"listen",{"type":21,"tag":512,"props":3135,"children":3136},{"style":815},[3137],{"type":27,"value":843},{"type":21,"tag":512,"props":3139,"children":3140},{"style":686},[3141],{"type":27,"value":3142},"3000",{"type":21,"tag":512,"props":3144,"children":3145},{"style":815},[3146],{"type":27,"value":853},{"type":21,"tag":29,"props":3148,"children":3149},{},[3150,3152,3158,3160,3166,3168,3174,3175,3181],{"type":27,"value":3151},"通过node运行上面的代码，在浏览器请求",{"type":21,"tag":508,"props":3153,"children":3155},{"className":3154},[],[3156],{"type":27,"value":3157},"localhost:3000",{"type":27,"value":3159},"，接口就会返回",{"type":21,"tag":508,"props":3161,"children":3163},{"className":3162},[],[3164],{"type":27,"value":3165},"home",{"type":27,"value":3167},"，当我们请求",{"type":21,"tag":508,"props":3169,"children":3171},{"className":3170},[],[3172],{"type":27,"value":3173},"localhost:3000/hello",{"type":27,"value":3159},{"type":21,"tag":508,"props":3176,"children":3178},{"className":3177},[],[3179],{"type":27,"value":3180},"hello world",{"type":27,"value":2715},{"type":21,"tag":29,"props":3183,"children":3184},{},[3185],{"type":27,"value":3186},"上面对请求的处理过程就很符合职责链模式的思想，我们可以清楚的知道每个链做的工作，并且清晰链条的顺序流程。",{"type":21,"tag":29,"props":3188,"children":3189},{},[3190],{"type":27,"value":3191},"有人就会问，只在一个回调里面也能处理呀，比如下面的代码：",{"type":21,"tag":501,"props":3193,"children":3195},{"className":2762,"code":3194,"language":2764,"meta":8,"style":8},"app.use(async (ctx, next) => {\n  if (ctx.request.url === '/') {\n    ctx.body = 'home';\n    return;\n  } else if (ctx.request.url === '/home') {\n    ctx.body = 'hello world';\n    return\n  }\n});\n",[3196],{"type":21,"tag":508,"props":3197,"children":3198},{"__ignoreMap":8},[3199,3246,3269,3288,3299,3334,3353,3361,3368],{"type":21,"tag":512,"props":3200,"children":3201},{"class":514,"line":515},[3202,3206,3210,3214,3218,3222,3226,3230,3234,3238,3242],{"type":21,"tag":512,"props":3203,"children":3204},{"style":815},[3205],{"type":27,"value":2844},{"type":21,"tag":512,"props":3207,"children":3208},{"style":519},[3209],{"type":27,"value":2849},{"type":21,"tag":512,"props":3211,"children":3212},{"style":815},[3213],{"type":27,"value":843},{"type":21,"tag":512,"props":3215,"children":3216},{"style":809},[3217],{"type":27,"value":2858},{"type":21,"tag":512,"props":3219,"children":3220},{"style":815},[3221],{"type":27,"value":1002},{"type":21,"tag":512,"props":3223,"children":3224},{"style":1850},[3225],{"type":27,"value":2867},{"type":21,"tag":512,"props":3227,"children":3228},{"style":815},[3229],{"type":27,"value":1965},{"type":21,"tag":512,"props":3231,"children":3232},{"style":1850},[3233],{"type":27,"value":2876},{"type":21,"tag":512,"props":3235,"children":3236},{"style":815},[3237],{"type":27,"value":1858},{"type":21,"tag":512,"props":3239,"children":3240},{"style":809},[3241],{"type":27,"value":1863},{"type":21,"tag":512,"props":3243,"children":3244},{"style":815},[3245],{"type":27,"value":1067},{"type":21,"tag":512,"props":3247,"children":3248},{"class":514,"line":359},[3249,3253,3257,3261,3265],{"type":21,"tag":512,"props":3250,"children":3251},{"style":809},[3252],{"type":27,"value":2896},{"type":21,"tag":512,"props":3254,"children":3255},{"style":815},[3256],{"type":27,"value":2901},{"type":21,"tag":512,"props":3258,"children":3259},{"style":809},[3260],{"type":27,"value":2906},{"type":21,"tag":512,"props":3262,"children":3263},{"style":525},[3264],{"type":27,"value":2911},{"type":21,"tag":512,"props":3266,"children":3267},{"style":815},[3268],{"type":27,"value":2916},{"type":21,"tag":512,"props":3270,"children":3271},{"class":514,"line":365},[3272,3276,3280,3284],{"type":21,"tag":512,"props":3273,"children":3274},{"style":815},[3275],{"type":27,"value":2924},{"type":21,"tag":512,"props":3277,"children":3278},{"style":809},[3279],{"type":27,"value":833},{"type":21,"tag":512,"props":3281,"children":3282},{"style":525},[3283],{"type":27,"value":2933},{"type":21,"tag":512,"props":3285,"children":3286},{"style":815},[3287],{"type":27,"value":897},{"type":21,"tag":512,"props":3289,"children":3290},{"class":514,"line":673},[3291,3295],{"type":21,"tag":512,"props":3292,"children":3293},{"style":809},[3294],{"type":27,"value":2945},{"type":21,"tag":512,"props":3296,"children":3297},{"style":815},[3298],{"type":27,"value":897},{"type":21,"tag":512,"props":3300,"children":3301},{"class":514,"line":900},[3302,3307,3312,3317,3321,3325,3330],{"type":21,"tag":512,"props":3303,"children":3304},{"style":815},[3305],{"type":27,"value":3306},"  } ",{"type":21,"tag":512,"props":3308,"children":3309},{"style":809},[3310],{"type":27,"value":3311},"else",{"type":21,"tag":512,"props":3313,"children":3314},{"style":809},[3315],{"type":27,"value":3316}," if",{"type":21,"tag":512,"props":3318,"children":3319},{"style":815},[3320],{"type":27,"value":2901},{"type":21,"tag":512,"props":3322,"children":3323},{"style":809},[3324],{"type":27,"value":2906},{"type":21,"tag":512,"props":3326,"children":3327},{"style":525},[3328],{"type":27,"value":3329}," '/home'",{"type":21,"tag":512,"props":3331,"children":3332},{"style":815},[3333],{"type":27,"value":2916},{"type":21,"tag":512,"props":3335,"children":3336},{"class":514,"line":908},[3337,3341,3345,3349],{"type":21,"tag":512,"props":3338,"children":3339},{"style":815},[3340],{"type":27,"value":2924},{"type":21,"tag":512,"props":3342,"children":3343},{"style":809},[3344],{"type":27,"value":833},{"type":21,"tag":512,"props":3346,"children":3347},{"style":525},[3348],{"type":27,"value":3085},{"type":21,"tag":512,"props":3350,"children":3351},{"style":815},[3352],{"type":27,"value":897},{"type":21,"tag":512,"props":3354,"children":3355},{"class":514,"line":955},[3356],{"type":21,"tag":512,"props":3357,"children":3358},{"style":809},[3359],{"type":27,"value":3360},"    return\n",{"type":21,"tag":512,"props":3362,"children":3363},{"class":514,"line":983},[3364],{"type":21,"tag":512,"props":3365,"children":3366},{"style":815},[3367],{"type":27,"value":2957},{"type":21,"tag":512,"props":3369,"children":3370},{"class":514,"line":991},[3371],{"type":21,"tag":512,"props":3372,"children":3373},{"style":815},[3374],{"type":27,"value":2991},{"type":21,"tag":29,"props":3376,"children":3377},{},[3378],{"type":27,"value":3379},"是的，上面的代码确实可以实现，但是这就要回到我们使用责任链模式的初衷了：为了逻辑解耦。",{"type":21,"tag":22,"props":3381,"children":3383},{"id":3382},"责任链解决的问题",[3384],{"type":27,"value":3382},{"type":21,"tag":29,"props":3386,"children":3387},{},[3388],{"type":27,"value":3389},"我们继续接着聊上一节的问题，使用if确实可以实现相同效果，但是某些场景用if不如使用职责链的方式实现。",{"type":21,"tag":29,"props":3391,"children":3392},{},[3393],{"type":27,"value":3394},"我们来一个应用案例来举个例子：",{"type":21,"tag":29,"props":3396,"children":3397},{},[3398],{"type":27,"value":3399},"假设我们负责一个售卖手机的网站，需求的定义是：经过分别缴纳500元定金和200元定金的两轮预订，现在到了正式购买阶段。公司对于交了定金的用户有一定的优惠政策，规则如下：",{"type":21,"tag":75,"props":3401,"children":3402},{},[3403,3408,3413,3418],{"type":21,"tag":79,"props":3404,"children":3405},{},[3406],{"type":27,"value":3407},"缴纳500元定金的用户可以收到100元优惠券；",{"type":21,"tag":79,"props":3409,"children":3410},{},[3411],{"type":27,"value":3412},"缴纳200元定金的用户可以收到50元优惠券；",{"type":21,"tag":79,"props":3414,"children":3415},{},[3416],{"type":27,"value":3417},"没有缴纳定金的用户进入普通购买模式，没有优惠券。",{"type":21,"tag":79,"props":3419,"children":3420},{},[3421],{"type":27,"value":3422},"而且在库存不足的情况下，不一定能保证买得到。",{"type":21,"tag":29,"props":3424,"children":3425},{},[3426],{"type":27,"value":3427},"下面开始设计几个字段，解释它们的含义：",{"type":21,"tag":75,"props":3429,"children":3430},{},[3431,3436,3441],{"type":21,"tag":79,"props":3432,"children":3433},{},[3434],{"type":27,"value":3435},"orderType：表示订单类型，值为1表示500元定金用户，值为2表示200元定金用户，值为3表示普通用户。",{"type":21,"tag":79,"props":3437,"children":3438},{},[3439],{"type":27,"value":3440},"pay：表示用户是否支付定金，值为布尔值true和false，就算用户下了500元定金的订单，但是如果没有支付定金，那也会降级为普通用户购买模式。",{"type":21,"tag":79,"props":3442,"children":3443},{},[3444],{"type":27,"value":3445},"stock：表示当前用户普通购买的手机库存数量，已经支付过定金的用户不受限制。",{"type":21,"tag":29,"props":3447,"children":3448},{},[3449],{"type":27,"value":3450},"下面我们分别用if和职责链模式来实现：",{"type":21,"tag":29,"props":3452,"children":3453},{},[3454],{"type":27,"value":3455},"使用if：",{"type":21,"tag":501,"props":3457,"children":3459},{"className":2762,"code":3458,"language":2764,"meta":8,"style":8},"const order = function (orderType, pay, stock) {\n  if (orderType === 1) {\n    if (pay === true) {\n      console.log('500元定金预购，得到100元优惠券')\n    } else {\n      if (stock > 0) {\n        console.log('普通用户购买，无优惠券')\n      } else {\n        console.log('手机库存不足')\n      }\n    } else if (orderType === 2) {\n      if (pay === true) {\n        console.log('200元定金预购，得到50元优惠券')\n      } else {\n        if (stock > 0) {\n          console.log('普通用户购买，无优惠券')\n        } else {\n          console.log('手机库存不足')\n        }\n      }\n    } else if (orderType === 3) {\n      if (stock > 0) {\n          console.log('普通用户购买，无优惠券')\n        } else {\n          console.log('手机库存不足')\n      } \n  }\n}\n\norder(1, true, 500)  // 输出：500元定金预购，得到100元优惠券'\n",[3460],{"type":21,"tag":508,"props":3461,"children":3462},{"__ignoreMap":8},[3463,3515,3540,3566,3592,3608,3635,3660,3676,3700,3707,3739,3762,3786,3801,3825,3848,3864,3887,3895,3902,3934,3957,3980,3995,4018,4026,4033,4040,4047],{"type":21,"tag":512,"props":3464,"children":3465},{"class":514,"line":515},[3466,3470,3475,3479,3484,3488,3493,3497,3502,3506,3511],{"type":21,"tag":512,"props":3467,"children":3468},{"style":809},[3469],{"type":27,"value":812},{"type":21,"tag":512,"props":3471,"children":3472},{"style":519},[3473],{"type":27,"value":3474}," order",{"type":21,"tag":512,"props":3476,"children":3477},{"style":809},[3478],{"type":27,"value":887},{"type":21,"tag":512,"props":3480,"children":3481},{"style":809},[3482],{"type":27,"value":3483}," function",{"type":21,"tag":512,"props":3485,"children":3486},{"style":815},[3487],{"type":27,"value":1002},{"type":21,"tag":512,"props":3489,"children":3490},{"style":1850},[3491],{"type":27,"value":3492},"orderType",{"type":21,"tag":512,"props":3494,"children":3495},{"style":815},[3496],{"type":27,"value":1965},{"type":21,"tag":512,"props":3498,"children":3499},{"style":1850},[3500],{"type":27,"value":3501},"pay",{"type":21,"tag":512,"props":3503,"children":3504},{"style":815},[3505],{"type":27,"value":1965},{"type":21,"tag":512,"props":3507,"children":3508},{"style":1850},[3509],{"type":27,"value":3510},"stock",{"type":21,"tag":512,"props":3512,"children":3513},{"style":815},[3514],{"type":27,"value":2916},{"type":21,"tag":512,"props":3516,"children":3517},{"class":514,"line":359},[3518,3522,3527,3531,3536],{"type":21,"tag":512,"props":3519,"children":3520},{"style":809},[3521],{"type":27,"value":2896},{"type":21,"tag":512,"props":3523,"children":3524},{"style":815},[3525],{"type":27,"value":3526}," (orderType ",{"type":21,"tag":512,"props":3528,"children":3529},{"style":809},[3530],{"type":27,"value":2906},{"type":21,"tag":512,"props":3532,"children":3533},{"style":686},[3534],{"type":27,"value":3535}," 1",{"type":21,"tag":512,"props":3537,"children":3538},{"style":815},[3539],{"type":27,"value":2916},{"type":21,"tag":512,"props":3541,"children":3542},{"class":514,"line":365},[3543,3548,3553,3557,3562],{"type":21,"tag":512,"props":3544,"children":3545},{"style":809},[3546],{"type":27,"value":3547},"    if",{"type":21,"tag":512,"props":3549,"children":3550},{"style":815},[3551],{"type":27,"value":3552}," (pay ",{"type":21,"tag":512,"props":3554,"children":3555},{"style":809},[3556],{"type":27,"value":2906},{"type":21,"tag":512,"props":3558,"children":3559},{"style":686},[3560],{"type":27,"value":3561}," true",{"type":21,"tag":512,"props":3563,"children":3564},{"style":815},[3565],{"type":27,"value":2916},{"type":21,"tag":512,"props":3567,"children":3568},{"class":514,"line":673},[3569,3574,3578,3582,3587],{"type":21,"tag":512,"props":3570,"children":3571},{"style":815},[3572],{"type":27,"value":3573},"      console.",{"type":21,"tag":512,"props":3575,"children":3576},{"style":519},[3577],{"type":27,"value":966},{"type":21,"tag":512,"props":3579,"children":3580},{"style":815},[3581],{"type":27,"value":843},{"type":21,"tag":512,"props":3583,"children":3584},{"style":525},[3585],{"type":27,"value":3586},"'500元定金预购，得到100元优惠券'",{"type":21,"tag":512,"props":3588,"children":3589},{"style":815},[3590],{"type":27,"value":3591},")\n",{"type":21,"tag":512,"props":3593,"children":3594},{"class":514,"line":900},[3595,3600,3604],{"type":21,"tag":512,"props":3596,"children":3597},{"style":815},[3598],{"type":27,"value":3599},"    } ",{"type":21,"tag":512,"props":3601,"children":3602},{"style":809},[3603],{"type":27,"value":3311},{"type":21,"tag":512,"props":3605,"children":3606},{"style":815},[3607],{"type":27,"value":1067},{"type":21,"tag":512,"props":3609,"children":3610},{"class":514,"line":908},[3611,3616,3621,3626,3631],{"type":21,"tag":512,"props":3612,"children":3613},{"style":809},[3614],{"type":27,"value":3615},"      if",{"type":21,"tag":512,"props":3617,"children":3618},{"style":815},[3619],{"type":27,"value":3620}," (stock ",{"type":21,"tag":512,"props":3622,"children":3623},{"style":809},[3624],{"type":27,"value":3625},">",{"type":21,"tag":512,"props":3627,"children":3628},{"style":686},[3629],{"type":27,"value":3630}," 0",{"type":21,"tag":512,"props":3632,"children":3633},{"style":815},[3634],{"type":27,"value":2916},{"type":21,"tag":512,"props":3636,"children":3637},{"class":514,"line":955},[3638,3643,3647,3651,3656],{"type":21,"tag":512,"props":3639,"children":3640},{"style":815},[3641],{"type":27,"value":3642},"        console.",{"type":21,"tag":512,"props":3644,"children":3645},{"style":519},[3646],{"type":27,"value":966},{"type":21,"tag":512,"props":3648,"children":3649},{"style":815},[3650],{"type":27,"value":843},{"type":21,"tag":512,"props":3652,"children":3653},{"style":525},[3654],{"type":27,"value":3655},"'普通用户购买，无优惠券'",{"type":21,"tag":512,"props":3657,"children":3658},{"style":815},[3659],{"type":27,"value":3591},{"type":21,"tag":512,"props":3661,"children":3662},{"class":514,"line":983},[3663,3668,3672],{"type":21,"tag":512,"props":3664,"children":3665},{"style":815},[3666],{"type":27,"value":3667},"      } ",{"type":21,"tag":512,"props":3669,"children":3670},{"style":809},[3671],{"type":27,"value":3311},{"type":21,"tag":512,"props":3673,"children":3674},{"style":815},[3675],{"type":27,"value":1067},{"type":21,"tag":512,"props":3677,"children":3678},{"class":514,"line":991},[3679,3683,3687,3691,3696],{"type":21,"tag":512,"props":3680,"children":3681},{"style":815},[3682],{"type":27,"value":3642},{"type":21,"tag":512,"props":3684,"children":3685},{"style":519},[3686],{"type":27,"value":966},{"type":21,"tag":512,"props":3688,"children":3689},{"style":815},[3690],{"type":27,"value":843},{"type":21,"tag":512,"props":3692,"children":3693},{"style":525},[3694],{"type":27,"value":3695},"'手机库存不足'",{"type":21,"tag":512,"props":3697,"children":3698},{"style":815},[3699],{"type":27,"value":3591},{"type":21,"tag":512,"props":3701,"children":3702},{"class":514,"line":1015},[3703],{"type":21,"tag":512,"props":3704,"children":3705},{"style":815},[3706],{"type":27,"value":2467},{"type":21,"tag":512,"props":3708,"children":3709},{"class":514,"line":1047},[3710,3714,3718,3722,3726,3730,3735],{"type":21,"tag":512,"props":3711,"children":3712},{"style":815},[3713],{"type":27,"value":3599},{"type":21,"tag":512,"props":3715,"children":3716},{"style":809},[3717],{"type":27,"value":3311},{"type":21,"tag":512,"props":3719,"children":3720},{"style":809},[3721],{"type":27,"value":3316},{"type":21,"tag":512,"props":3723,"children":3724},{"style":815},[3725],{"type":27,"value":3526},{"type":21,"tag":512,"props":3727,"children":3728},{"style":809},[3729],{"type":27,"value":2906},{"type":21,"tag":512,"props":3731,"children":3732},{"style":686},[3733],{"type":27,"value":3734}," 2",{"type":21,"tag":512,"props":3736,"children":3737},{"style":815},[3738],{"type":27,"value":2916},{"type":21,"tag":512,"props":3740,"children":3741},{"class":514,"line":1056},[3742,3746,3750,3754,3758],{"type":21,"tag":512,"props":3743,"children":3744},{"style":809},[3745],{"type":27,"value":3615},{"type":21,"tag":512,"props":3747,"children":3748},{"style":815},[3749],{"type":27,"value":3552},{"type":21,"tag":512,"props":3751,"children":3752},{"style":809},[3753],{"type":27,"value":2906},{"type":21,"tag":512,"props":3755,"children":3756},{"style":686},[3757],{"type":27,"value":3561},{"type":21,"tag":512,"props":3759,"children":3760},{"style":815},[3761],{"type":27,"value":2916},{"type":21,"tag":512,"props":3763,"children":3764},{"class":514,"line":1070},[3765,3769,3773,3777,3782],{"type":21,"tag":512,"props":3766,"children":3767},{"style":815},[3768],{"type":27,"value":3642},{"type":21,"tag":512,"props":3770,"children":3771},{"style":519},[3772],{"type":27,"value":966},{"type":21,"tag":512,"props":3774,"children":3775},{"style":815},[3776],{"type":27,"value":843},{"type":21,"tag":512,"props":3778,"children":3779},{"style":525},[3780],{"type":27,"value":3781},"'200元定金预购，得到50元优惠券'",{"type":21,"tag":512,"props":3783,"children":3784},{"style":815},[3785],{"type":27,"value":3591},{"type":21,"tag":512,"props":3787,"children":3788},{"class":514,"line":1079},[3789,3793,3797],{"type":21,"tag":512,"props":3790,"children":3791},{"style":815},[3792],{"type":27,"value":3667},{"type":21,"tag":512,"props":3794,"children":3795},{"style":809},[3796],{"type":27,"value":3311},{"type":21,"tag":512,"props":3798,"children":3799},{"style":815},[3800],{"type":27,"value":1067},{"type":21,"tag":512,"props":3802,"children":3803},{"class":514,"line":1317},[3804,3809,3813,3817,3821],{"type":21,"tag":512,"props":3805,"children":3806},{"style":809},[3807],{"type":27,"value":3808},"        if",{"type":21,"tag":512,"props":3810,"children":3811},{"style":815},[3812],{"type":27,"value":3620},{"type":21,"tag":512,"props":3814,"children":3815},{"style":809},[3816],{"type":27,"value":3625},{"type":21,"tag":512,"props":3818,"children":3819},{"style":686},[3820],{"type":27,"value":3630},{"type":21,"tag":512,"props":3822,"children":3823},{"style":815},[3824],{"type":27,"value":2916},{"type":21,"tag":512,"props":3826,"children":3827},{"class":514,"line":1326},[3828,3832,3836,3840,3844],{"type":21,"tag":512,"props":3829,"children":3830},{"style":815},[3831],{"type":27,"value":2052},{"type":21,"tag":512,"props":3833,"children":3834},{"style":519},[3835],{"type":27,"value":966},{"type":21,"tag":512,"props":3837,"children":3838},{"style":815},[3839],{"type":27,"value":843},{"type":21,"tag":512,"props":3841,"children":3842},{"style":525},[3843],{"type":27,"value":3655},{"type":21,"tag":512,"props":3845,"children":3846},{"style":815},[3847],{"type":27,"value":3591},{"type":21,"tag":512,"props":3849,"children":3850},{"class":514,"line":1678},[3851,3856,3860],{"type":21,"tag":512,"props":3852,"children":3853},{"style":815},[3854],{"type":27,"value":3855},"        } ",{"type":21,"tag":512,"props":3857,"children":3858},{"style":809},[3859],{"type":27,"value":3311},{"type":21,"tag":512,"props":3861,"children":3862},{"style":815},[3863],{"type":27,"value":1067},{"type":21,"tag":512,"props":3865,"children":3866},{"class":514,"line":1704},[3867,3871,3875,3879,3883],{"type":21,"tag":512,"props":3868,"children":3869},{"style":815},[3870],{"type":27,"value":2052},{"type":21,"tag":512,"props":3872,"children":3873},{"style":519},[3874],{"type":27,"value":966},{"type":21,"tag":512,"props":3876,"children":3877},{"style":815},[3878],{"type":27,"value":843},{"type":21,"tag":512,"props":3880,"children":3881},{"style":525},[3882],{"type":27,"value":3695},{"type":21,"tag":512,"props":3884,"children":3885},{"style":815},[3886],{"type":27,"value":3591},{"type":21,"tag":512,"props":3888,"children":3889},{"class":514,"line":1730},[3890],{"type":21,"tag":512,"props":3891,"children":3892},{"style":815},[3893],{"type":27,"value":3894},"        }\n",{"type":21,"tag":512,"props":3896,"children":3897},{"class":514,"line":1756},[3898],{"type":21,"tag":512,"props":3899,"children":3900},{"style":815},[3901],{"type":27,"value":2467},{"type":21,"tag":512,"props":3903,"children":3904},{"class":514,"line":1820},[3905,3909,3913,3917,3921,3925,3930],{"type":21,"tag":512,"props":3906,"children":3907},{"style":815},[3908],{"type":27,"value":3599},{"type":21,"tag":512,"props":3910,"children":3911},{"style":809},[3912],{"type":27,"value":3311},{"type":21,"tag":512,"props":3914,"children":3915},{"style":809},[3916],{"type":27,"value":3316},{"type":21,"tag":512,"props":3918,"children":3919},{"style":815},[3920],{"type":27,"value":3526},{"type":21,"tag":512,"props":3922,"children":3923},{"style":809},[3924],{"type":27,"value":2906},{"type":21,"tag":512,"props":3926,"children":3927},{"style":686},[3928],{"type":27,"value":3929}," 3",{"type":21,"tag":512,"props":3931,"children":3932},{"style":815},[3933],{"type":27,"value":2916},{"type":21,"tag":512,"props":3935,"children":3936},{"class":514,"line":1828},[3937,3941,3945,3949,3953],{"type":21,"tag":512,"props":3938,"children":3939},{"style":809},[3940],{"type":27,"value":3615},{"type":21,"tag":512,"props":3942,"children":3943},{"style":815},[3944],{"type":27,"value":3620},{"type":21,"tag":512,"props":3946,"children":3947},{"style":809},[3948],{"type":27,"value":3625},{"type":21,"tag":512,"props":3950,"children":3951},{"style":686},[3952],{"type":27,"value":3630},{"type":21,"tag":512,"props":3954,"children":3955},{"style":815},[3956],{"type":27,"value":2916},{"type":21,"tag":512,"props":3958,"children":3959},{"class":514,"line":1870},[3960,3964,3968,3972,3976],{"type":21,"tag":512,"props":3961,"children":3962},{"style":815},[3963],{"type":27,"value":2052},{"type":21,"tag":512,"props":3965,"children":3966},{"style":519},[3967],{"type":27,"value":966},{"type":21,"tag":512,"props":3969,"children":3970},{"style":815},[3971],{"type":27,"value":843},{"type":21,"tag":512,"props":3973,"children":3974},{"style":525},[3975],{"type":27,"value":3655},{"type":21,"tag":512,"props":3977,"children":3978},{"style":815},[3979],{"type":27,"value":3591},{"type":21,"tag":512,"props":3981,"children":3982},{"class":514,"line":1879},[3983,3987,3991],{"type":21,"tag":512,"props":3984,"children":3985},{"style":815},[3986],{"type":27,"value":3855},{"type":21,"tag":512,"props":3988,"children":3989},{"style":809},[3990],{"type":27,"value":3311},{"type":21,"tag":512,"props":3992,"children":3993},{"style":815},[3994],{"type":27,"value":1067},{"type":21,"tag":512,"props":3996,"children":3997},{"class":514,"line":1915},[3998,4002,4006,4010,4014],{"type":21,"tag":512,"props":3999,"children":4000},{"style":815},[4001],{"type":27,"value":2052},{"type":21,"tag":512,"props":4003,"children":4004},{"style":519},[4005],{"type":27,"value":966},{"type":21,"tag":512,"props":4007,"children":4008},{"style":815},[4009],{"type":27,"value":843},{"type":21,"tag":512,"props":4011,"children":4012},{"style":525},[4013],{"type":27,"value":3695},{"type":21,"tag":512,"props":4015,"children":4016},{"style":815},[4017],{"type":27,"value":3591},{"type":21,"tag":512,"props":4019,"children":4020},{"class":514,"line":1941},[4021],{"type":21,"tag":512,"props":4022,"children":4023},{"style":815},[4024],{"type":27,"value":4025},"      } \n",{"type":21,"tag":512,"props":4027,"children":4028},{"class":514,"line":1985},[4029],{"type":21,"tag":512,"props":4030,"children":4031},{"style":815},[4032],{"type":27,"value":2957},{"type":21,"tag":512,"props":4034,"children":4035},{"class":514,"line":1994},[4036],{"type":21,"tag":512,"props":4037,"children":4038},{"style":815},[4039],{"type":27,"value":1053},{"type":21,"tag":512,"props":4041,"children":4042},{"class":514,"line":2046},[4043],{"type":21,"tag":512,"props":4044,"children":4045},{"emptyLinePlaceholder":859},[4046],{"type":27,"value":862},{"type":21,"tag":512,"props":4048,"children":4049},{"class":514,"line":2072},[4050,4055,4059,4064,4068,4073,4077,4082,4087],{"type":21,"tag":512,"props":4051,"children":4052},{"style":519},[4053],{"type":27,"value":4054},"order",{"type":21,"tag":512,"props":4056,"children":4057},{"style":815},[4058],{"type":27,"value":843},{"type":21,"tag":512,"props":4060,"children":4061},{"style":686},[4062],{"type":27,"value":4063},"1",{"type":21,"tag":512,"props":4065,"children":4066},{"style":815},[4067],{"type":27,"value":1965},{"type":21,"tag":512,"props":4069,"children":4070},{"style":686},[4071],{"type":27,"value":4072},"true",{"type":21,"tag":512,"props":4074,"children":4075},{"style":815},[4076],{"type":27,"value":1965},{"type":21,"tag":512,"props":4078,"children":4079},{"style":686},[4080],{"type":27,"value":4081},"500",{"type":21,"tag":512,"props":4083,"children":4084},{"style":815},[4085],{"type":27,"value":4086},")  ",{"type":21,"tag":512,"props":4088,"children":4089},{"style":646},[4090],{"type":27,"value":4091},"// 输出：500元定金预购，得到100元优惠券'\n",{"type":21,"tag":29,"props":4093,"children":4094},{},[4095],{"type":27,"value":4096},"虽然上面的代码也可以实现需求，但是代码实在是难以阅读，维护起来更是困难，如果继续在这个代码上开发，未来肯定会成为一座很大的屎山。",{"type":21,"tag":29,"props":4098,"children":4099},{},[4100],{"type":27,"value":4101},"下面我们使用责任链模式来实现：",{"type":21,"tag":501,"props":4103,"children":4105},{"className":2762,"code":4104,"language":2764,"meta":8,"style":8},"\nfunction printResult(orderType, pay, stock) {\n    // 这里ResChain类是模拟koa的写法，后面会讲如何实现ResChain\n    // 请先耐心看完它是如何处理的\n    const resChain = new ResChain()\n    \n    resChain.add('order500', (_, next) => {\n        if (orderType === 1 && pay === true) {\n            console.log('500元定金预购，拿到100元优惠券');\n            return;\n        }\n        next(); // 这里将会调用order200对应的回调函数\n    })\n\n    resChain.add('order200', (_, next) => {\n        if (orderType === 2 && pay === true) {\n            console.log('200元定金预购，拿到50元优惠券');\n            return;\n        }\n        next(); // 这里会调用noOrder对应回调函数\n    })\n\n    resChain.add('noOrder', (_, next) => {\n        if (stock > 0) {\n            console.log('普通用户购买，无优惠券');\n        } else {\n            console.log('手机库存不足');\n        }\n    })\n\n    resChain.run() // 开始执行order500对应的回调函数\n}\n\n// 测试 \nprintResult(1, true, 500)  // 500元定金预购，得到100元优惠券\nprintResult(1, false, 500) // 普通用户购买，无优惠券\nprintResult(2, true, 500)  // 200元定金预购，得到50元优惠券\nprintResult(3, false, 500) // 普通用户购买，无优惠券\nprintResult(3, false, 0)   // 手机库存不足\n",[4106],{"type":21,"tag":508,"props":4107,"children":4108},{"__ignoreMap":8},[4109,4116,4157,4165,4173,4204,4212,4263,4304,4329,4341,4348,4365,4373,4380,4428,4467,4491,4502,4509,4525,4532,4539,4587,4610,4633,4648,4671,4678,4685,4692,4714,4721,4728,4736,4777,4818,4859,4899],{"type":21,"tag":512,"props":4110,"children":4111},{"class":514,"line":515},[4112],{"type":21,"tag":512,"props":4113,"children":4114},{"emptyLinePlaceholder":859},[4115],{"type":27,"value":862},{"type":21,"tag":512,"props":4117,"children":4118},{"class":514,"line":359},[4119,4124,4129,4133,4137,4141,4145,4149,4153],{"type":21,"tag":512,"props":4120,"children":4121},{"style":809},[4122],{"type":27,"value":4123},"function",{"type":21,"tag":512,"props":4125,"children":4126},{"style":519},[4127],{"type":27,"value":4128}," printResult",{"type":21,"tag":512,"props":4130,"children":4131},{"style":815},[4132],{"type":27,"value":843},{"type":21,"tag":512,"props":4134,"children":4135},{"style":1850},[4136],{"type":27,"value":3492},{"type":21,"tag":512,"props":4138,"children":4139},{"style":815},[4140],{"type":27,"value":1965},{"type":21,"tag":512,"props":4142,"children":4143},{"style":1850},[4144],{"type":27,"value":3501},{"type":21,"tag":512,"props":4146,"children":4147},{"style":815},[4148],{"type":27,"value":1965},{"type":21,"tag":512,"props":4150,"children":4151},{"style":1850},[4152],{"type":27,"value":3510},{"type":21,"tag":512,"props":4154,"children":4155},{"style":815},[4156],{"type":27,"value":2916},{"type":21,"tag":512,"props":4158,"children":4159},{"class":514,"line":365},[4160],{"type":21,"tag":512,"props":4161,"children":4162},{"style":646},[4163],{"type":27,"value":4164},"    // 这里ResChain类是模拟koa的写法，后面会讲如何实现ResChain\n",{"type":21,"tag":512,"props":4166,"children":4167},{"class":514,"line":673},[4168],{"type":21,"tag":512,"props":4169,"children":4170},{"style":646},[4171],{"type":27,"value":4172},"    // 请先耐心看完它是如何处理的\n",{"type":21,"tag":512,"props":4174,"children":4175},{"class":514,"line":900},[4176,4181,4186,4190,4194,4199],{"type":21,"tag":512,"props":4177,"children":4178},{"style":809},[4179],{"type":27,"value":4180},"    const",{"type":21,"tag":512,"props":4182,"children":4183},{"style":686},[4184],{"type":27,"value":4185}," resChain",{"type":21,"tag":512,"props":4187,"children":4188},{"style":809},[4189],{"type":27,"value":887},{"type":21,"tag":512,"props":4191,"children":4192},{"style":809},[4193],{"type":27,"value":1026},{"type":21,"tag":512,"props":4195,"children":4196},{"style":519},[4197],{"type":27,"value":4198}," ResChain",{"type":21,"tag":512,"props":4200,"children":4201},{"style":815},[4202],{"type":27,"value":4203},"()\n",{"type":21,"tag":512,"props":4205,"children":4206},{"class":514,"line":908},[4207],{"type":21,"tag":512,"props":4208,"children":4209},{"style":815},[4210],{"type":27,"value":4211},"    \n",{"type":21,"tag":512,"props":4213,"children":4214},{"class":514,"line":955},[4215,4220,4225,4229,4234,4238,4243,4247,4251,4255,4259],{"type":21,"tag":512,"props":4216,"children":4217},{"style":815},[4218],{"type":27,"value":4219},"    resChain.",{"type":21,"tag":512,"props":4221,"children":4222},{"style":519},[4223],{"type":27,"value":4224},"add",{"type":21,"tag":512,"props":4226,"children":4227},{"style":815},[4228],{"type":27,"value":843},{"type":21,"tag":512,"props":4230,"children":4231},{"style":525},[4232],{"type":27,"value":4233},"'order500'",{"type":21,"tag":512,"props":4235,"children":4236},{"style":815},[4237],{"type":27,"value":2018},{"type":21,"tag":512,"props":4239,"children":4240},{"style":1850},[4241],{"type":27,"value":4242},"_",{"type":21,"tag":512,"props":4244,"children":4245},{"style":815},[4246],{"type":27,"value":1965},{"type":21,"tag":512,"props":4248,"children":4249},{"style":1850},[4250],{"type":27,"value":2876},{"type":21,"tag":512,"props":4252,"children":4253},{"style":815},[4254],{"type":27,"value":1858},{"type":21,"tag":512,"props":4256,"children":4257},{"style":809},[4258],{"type":27,"value":1863},{"type":21,"tag":512,"props":4260,"children":4261},{"style":815},[4262],{"type":27,"value":1067},{"type":21,"tag":512,"props":4264,"children":4265},{"class":514,"line":983},[4266,4270,4274,4278,4282,4287,4292,4296,4300],{"type":21,"tag":512,"props":4267,"children":4268},{"style":809},[4269],{"type":27,"value":3808},{"type":21,"tag":512,"props":4271,"children":4272},{"style":815},[4273],{"type":27,"value":3526},{"type":21,"tag":512,"props":4275,"children":4276},{"style":809},[4277],{"type":27,"value":2906},{"type":21,"tag":512,"props":4279,"children":4280},{"style":686},[4281],{"type":27,"value":3535},{"type":21,"tag":512,"props":4283,"children":4284},{"style":809},[4285],{"type":27,"value":4286}," &&",{"type":21,"tag":512,"props":4288,"children":4289},{"style":815},[4290],{"type":27,"value":4291}," pay ",{"type":21,"tag":512,"props":4293,"children":4294},{"style":809},[4295],{"type":27,"value":2906},{"type":21,"tag":512,"props":4297,"children":4298},{"style":686},[4299],{"type":27,"value":3561},{"type":21,"tag":512,"props":4301,"children":4302},{"style":815},[4303],{"type":27,"value":2916},{"type":21,"tag":512,"props":4305,"children":4306},{"class":514,"line":991},[4307,4312,4316,4320,4325],{"type":21,"tag":512,"props":4308,"children":4309},{"style":815},[4310],{"type":27,"value":4311},"            console.",{"type":21,"tag":512,"props":4313,"children":4314},{"style":519},[4315],{"type":27,"value":966},{"type":21,"tag":512,"props":4317,"children":4318},{"style":815},[4319],{"type":27,"value":843},{"type":21,"tag":512,"props":4321,"children":4322},{"style":525},[4323],{"type":27,"value":4324},"'500元定金预购，拿到100元优惠券'",{"type":21,"tag":512,"props":4326,"children":4327},{"style":815},[4328],{"type":27,"value":853},{"type":21,"tag":512,"props":4330,"children":4331},{"class":514,"line":1015},[4332,4337],{"type":21,"tag":512,"props":4333,"children":4334},{"style":809},[4335],{"type":27,"value":4336},"            return",{"type":21,"tag":512,"props":4338,"children":4339},{"style":815},[4340],{"type":27,"value":897},{"type":21,"tag":512,"props":4342,"children":4343},{"class":514,"line":1047},[4344],{"type":21,"tag":512,"props":4345,"children":4346},{"style":815},[4347],{"type":27,"value":3894},{"type":21,"tag":512,"props":4349,"children":4350},{"class":514,"line":1056},[4351,4356,4360],{"type":21,"tag":512,"props":4352,"children":4353},{"style":519},[4354],{"type":27,"value":4355},"        next",{"type":21,"tag":512,"props":4357,"children":4358},{"style":815},[4359],{"type":27,"value":2978},{"type":21,"tag":512,"props":4361,"children":4362},{"style":646},[4363],{"type":27,"value":4364},"// 这里将会调用order200对应的回调函数\n",{"type":21,"tag":512,"props":4366,"children":4367},{"class":514,"line":1070},[4368],{"type":21,"tag":512,"props":4369,"children":4370},{"style":815},[4371],{"type":27,"value":4372},"    })\n",{"type":21,"tag":512,"props":4374,"children":4375},{"class":514,"line":1079},[4376],{"type":21,"tag":512,"props":4377,"children":4378},{"emptyLinePlaceholder":859},[4379],{"type":27,"value":862},{"type":21,"tag":512,"props":4381,"children":4382},{"class":514,"line":1317},[4383,4387,4391,4395,4400,4404,4408,4412,4416,4420,4424],{"type":21,"tag":512,"props":4384,"children":4385},{"style":815},[4386],{"type":27,"value":4219},{"type":21,"tag":512,"props":4388,"children":4389},{"style":519},[4390],{"type":27,"value":4224},{"type":21,"tag":512,"props":4392,"children":4393},{"style":815},[4394],{"type":27,"value":843},{"type":21,"tag":512,"props":4396,"children":4397},{"style":525},[4398],{"type":27,"value":4399},"'order200'",{"type":21,"tag":512,"props":4401,"children":4402},{"style":815},[4403],{"type":27,"value":2018},{"type":21,"tag":512,"props":4405,"children":4406},{"style":1850},[4407],{"type":27,"value":4242},{"type":21,"tag":512,"props":4409,"children":4410},{"style":815},[4411],{"type":27,"value":1965},{"type":21,"tag":512,"props":4413,"children":4414},{"style":1850},[4415],{"type":27,"value":2876},{"type":21,"tag":512,"props":4417,"children":4418},{"style":815},[4419],{"type":27,"value":1858},{"type":21,"tag":512,"props":4421,"children":4422},{"style":809},[4423],{"type":27,"value":1863},{"type":21,"tag":512,"props":4425,"children":4426},{"style":815},[4427],{"type":27,"value":1067},{"type":21,"tag":512,"props":4429,"children":4430},{"class":514,"line":1326},[4431,4435,4439,4443,4447,4451,4455,4459,4463],{"type":21,"tag":512,"props":4432,"children":4433},{"style":809},[4434],{"type":27,"value":3808},{"type":21,"tag":512,"props":4436,"children":4437},{"style":815},[4438],{"type":27,"value":3526},{"type":21,"tag":512,"props":4440,"children":4441},{"style":809},[4442],{"type":27,"value":2906},{"type":21,"tag":512,"props":4444,"children":4445},{"style":686},[4446],{"type":27,"value":3734},{"type":21,"tag":512,"props":4448,"children":4449},{"style":809},[4450],{"type":27,"value":4286},{"type":21,"tag":512,"props":4452,"children":4453},{"style":815},[4454],{"type":27,"value":4291},{"type":21,"tag":512,"props":4456,"children":4457},{"style":809},[4458],{"type":27,"value":2906},{"type":21,"tag":512,"props":4460,"children":4461},{"style":686},[4462],{"type":27,"value":3561},{"type":21,"tag":512,"props":4464,"children":4465},{"style":815},[4466],{"type":27,"value":2916},{"type":21,"tag":512,"props":4468,"children":4469},{"class":514,"line":1678},[4470,4474,4478,4482,4487],{"type":21,"tag":512,"props":4471,"children":4472},{"style":815},[4473],{"type":27,"value":4311},{"type":21,"tag":512,"props":4475,"children":4476},{"style":519},[4477],{"type":27,"value":966},{"type":21,"tag":512,"props":4479,"children":4480},{"style":815},[4481],{"type":27,"value":843},{"type":21,"tag":512,"props":4483,"children":4484},{"style":525},[4485],{"type":27,"value":4486},"'200元定金预购，拿到50元优惠券'",{"type":21,"tag":512,"props":4488,"children":4489},{"style":815},[4490],{"type":27,"value":853},{"type":21,"tag":512,"props":4492,"children":4493},{"class":514,"line":1704},[4494,4498],{"type":21,"tag":512,"props":4495,"children":4496},{"style":809},[4497],{"type":27,"value":4336},{"type":21,"tag":512,"props":4499,"children":4500},{"style":815},[4501],{"type":27,"value":897},{"type":21,"tag":512,"props":4503,"children":4504},{"class":514,"line":1730},[4505],{"type":21,"tag":512,"props":4506,"children":4507},{"style":815},[4508],{"type":27,"value":3894},{"type":21,"tag":512,"props":4510,"children":4511},{"class":514,"line":1756},[4512,4516,4520],{"type":21,"tag":512,"props":4513,"children":4514},{"style":519},[4515],{"type":27,"value":4355},{"type":21,"tag":512,"props":4517,"children":4518},{"style":815},[4519],{"type":27,"value":2978},{"type":21,"tag":512,"props":4521,"children":4522},{"style":646},[4523],{"type":27,"value":4524},"// 这里会调用noOrder对应回调函数\n",{"type":21,"tag":512,"props":4526,"children":4527},{"class":514,"line":1820},[4528],{"type":21,"tag":512,"props":4529,"children":4530},{"style":815},[4531],{"type":27,"value":4372},{"type":21,"tag":512,"props":4533,"children":4534},{"class":514,"line":1828},[4535],{"type":21,"tag":512,"props":4536,"children":4537},{"emptyLinePlaceholder":859},[4538],{"type":27,"value":862},{"type":21,"tag":512,"props":4540,"children":4541},{"class":514,"line":1870},[4542,4546,4550,4554,4559,4563,4567,4571,4575,4579,4583],{"type":21,"tag":512,"props":4543,"children":4544},{"style":815},[4545],{"type":27,"value":4219},{"type":21,"tag":512,"props":4547,"children":4548},{"style":519},[4549],{"type":27,"value":4224},{"type":21,"tag":512,"props":4551,"children":4552},{"style":815},[4553],{"type":27,"value":843},{"type":21,"tag":512,"props":4555,"children":4556},{"style":525},[4557],{"type":27,"value":4558},"'noOrder'",{"type":21,"tag":512,"props":4560,"children":4561},{"style":815},[4562],{"type":27,"value":2018},{"type":21,"tag":512,"props":4564,"children":4565},{"style":1850},[4566],{"type":27,"value":4242},{"type":21,"tag":512,"props":4568,"children":4569},{"style":815},[4570],{"type":27,"value":1965},{"type":21,"tag":512,"props":4572,"children":4573},{"style":1850},[4574],{"type":27,"value":2876},{"type":21,"tag":512,"props":4576,"children":4577},{"style":815},[4578],{"type":27,"value":1858},{"type":21,"tag":512,"props":4580,"children":4581},{"style":809},[4582],{"type":27,"value":1863},{"type":21,"tag":512,"props":4584,"children":4585},{"style":815},[4586],{"type":27,"value":1067},{"type":21,"tag":512,"props":4588,"children":4589},{"class":514,"line":1879},[4590,4594,4598,4602,4606],{"type":21,"tag":512,"props":4591,"children":4592},{"style":809},[4593],{"type":27,"value":3808},{"type":21,"tag":512,"props":4595,"children":4596},{"style":815},[4597],{"type":27,"value":3620},{"type":21,"tag":512,"props":4599,"children":4600},{"style":809},[4601],{"type":27,"value":3625},{"type":21,"tag":512,"props":4603,"children":4604},{"style":686},[4605],{"type":27,"value":3630},{"type":21,"tag":512,"props":4607,"children":4608},{"style":815},[4609],{"type":27,"value":2916},{"type":21,"tag":512,"props":4611,"children":4612},{"class":514,"line":1915},[4613,4617,4621,4625,4629],{"type":21,"tag":512,"props":4614,"children":4615},{"style":815},[4616],{"type":27,"value":4311},{"type":21,"tag":512,"props":4618,"children":4619},{"style":519},[4620],{"type":27,"value":966},{"type":21,"tag":512,"props":4622,"children":4623},{"style":815},[4624],{"type":27,"value":843},{"type":21,"tag":512,"props":4626,"children":4627},{"style":525},[4628],{"type":27,"value":3655},{"type":21,"tag":512,"props":4630,"children":4631},{"style":815},[4632],{"type":27,"value":853},{"type":21,"tag":512,"props":4634,"children":4635},{"class":514,"line":1941},[4636,4640,4644],{"type":21,"tag":512,"props":4637,"children":4638},{"style":815},[4639],{"type":27,"value":3855},{"type":21,"tag":512,"props":4641,"children":4642},{"style":809},[4643],{"type":27,"value":3311},{"type":21,"tag":512,"props":4645,"children":4646},{"style":815},[4647],{"type":27,"value":1067},{"type":21,"tag":512,"props":4649,"children":4650},{"class":514,"line":1985},[4651,4655,4659,4663,4667],{"type":21,"tag":512,"props":4652,"children":4653},{"style":815},[4654],{"type":27,"value":4311},{"type":21,"tag":512,"props":4656,"children":4657},{"style":519},[4658],{"type":27,"value":966},{"type":21,"tag":512,"props":4660,"children":4661},{"style":815},[4662],{"type":27,"value":843},{"type":21,"tag":512,"props":4664,"children":4665},{"style":525},[4666],{"type":27,"value":3695},{"type":21,"tag":512,"props":4668,"children":4669},{"style":815},[4670],{"type":27,"value":853},{"type":21,"tag":512,"props":4672,"children":4673},{"class":514,"line":1994},[4674],{"type":21,"tag":512,"props":4675,"children":4676},{"style":815},[4677],{"type":27,"value":3894},{"type":21,"tag":512,"props":4679,"children":4680},{"class":514,"line":2046},[4681],{"type":21,"tag":512,"props":4682,"children":4683},{"style":815},[4684],{"type":27,"value":4372},{"type":21,"tag":512,"props":4686,"children":4687},{"class":514,"line":2072},[4688],{"type":21,"tag":512,"props":4689,"children":4690},{"emptyLinePlaceholder":859},[4691],{"type":27,"value":862},{"type":21,"tag":512,"props":4693,"children":4694},{"class":514,"line":2090},[4695,4699,4704,4709],{"type":21,"tag":512,"props":4696,"children":4697},{"style":815},[4698],{"type":27,"value":4219},{"type":21,"tag":512,"props":4700,"children":4701},{"style":519},[4702],{"type":27,"value":4703},"run",{"type":21,"tag":512,"props":4705,"children":4706},{"style":815},[4707],{"type":27,"value":4708},"() ",{"type":21,"tag":512,"props":4710,"children":4711},{"style":646},[4712],{"type":27,"value":4713},"// 开始执行order500对应的回调函数\n",{"type":21,"tag":512,"props":4715,"children":4716},{"class":514,"line":2099},[4717],{"type":21,"tag":512,"props":4718,"children":4719},{"style":815},[4720],{"type":27,"value":1053},{"type":21,"tag":512,"props":4722,"children":4723},{"class":514,"line":2141},[4724],{"type":21,"tag":512,"props":4725,"children":4726},{"emptyLinePlaceholder":859},[4727],{"type":27,"value":862},{"type":21,"tag":512,"props":4729,"children":4730},{"class":514,"line":2168},[4731],{"type":21,"tag":512,"props":4732,"children":4733},{"style":646},[4734],{"type":27,"value":4735},"// 测试 \n",{"type":21,"tag":512,"props":4737,"children":4738},{"class":514,"line":2176},[4739,4744,4748,4752,4756,4760,4764,4768,4772],{"type":21,"tag":512,"props":4740,"children":4741},{"style":519},[4742],{"type":27,"value":4743},"printResult",{"type":21,"tag":512,"props":4745,"children":4746},{"style":815},[4747],{"type":27,"value":843},{"type":21,"tag":512,"props":4749,"children":4750},{"style":686},[4751],{"type":27,"value":4063},{"type":21,"tag":512,"props":4753,"children":4754},{"style":815},[4755],{"type":27,"value":1965},{"type":21,"tag":512,"props":4757,"children":4758},{"style":686},[4759],{"type":27,"value":4072},{"type":21,"tag":512,"props":4761,"children":4762},{"style":815},[4763],{"type":27,"value":1965},{"type":21,"tag":512,"props":4765,"children":4766},{"style":686},[4767],{"type":27,"value":4081},{"type":21,"tag":512,"props":4769,"children":4770},{"style":815},[4771],{"type":27,"value":4086},{"type":21,"tag":512,"props":4773,"children":4774},{"style":646},[4775],{"type":27,"value":4776},"// 500元定金预购，得到100元优惠券\n",{"type":21,"tag":512,"props":4778,"children":4779},{"class":514,"line":2217},[4780,4784,4788,4792,4796,4801,4805,4809,4813],{"type":21,"tag":512,"props":4781,"children":4782},{"style":519},[4783],{"type":27,"value":4743},{"type":21,"tag":512,"props":4785,"children":4786},{"style":815},[4787],{"type":27,"value":843},{"type":21,"tag":512,"props":4789,"children":4790},{"style":686},[4791],{"type":27,"value":4063},{"type":21,"tag":512,"props":4793,"children":4794},{"style":815},[4795],{"type":27,"value":1965},{"type":21,"tag":512,"props":4797,"children":4798},{"style":686},[4799],{"type":27,"value":4800},"false",{"type":21,"tag":512,"props":4802,"children":4803},{"style":815},[4804],{"type":27,"value":1965},{"type":21,"tag":512,"props":4806,"children":4807},{"style":686},[4808],{"type":27,"value":4081},{"type":21,"tag":512,"props":4810,"children":4811},{"style":815},[4812],{"type":27,"value":1858},{"type":21,"tag":512,"props":4814,"children":4815},{"style":646},[4816],{"type":27,"value":4817},"// 普通用户购买，无优惠券\n",{"type":21,"tag":512,"props":4819,"children":4820},{"class":514,"line":2248},[4821,4825,4829,4834,4838,4842,4846,4850,4854],{"type":21,"tag":512,"props":4822,"children":4823},{"style":519},[4824],{"type":27,"value":4743},{"type":21,"tag":512,"props":4826,"children":4827},{"style":815},[4828],{"type":27,"value":843},{"type":21,"tag":512,"props":4830,"children":4831},{"style":686},[4832],{"type":27,"value":4833},"2",{"type":21,"tag":512,"props":4835,"children":4836},{"style":815},[4837],{"type":27,"value":1965},{"type":21,"tag":512,"props":4839,"children":4840},{"style":686},[4841],{"type":27,"value":4072},{"type":21,"tag":512,"props":4843,"children":4844},{"style":815},[4845],{"type":27,"value":1965},{"type":21,"tag":512,"props":4847,"children":4848},{"style":686},[4849],{"type":27,"value":4081},{"type":21,"tag":512,"props":4851,"children":4852},{"style":815},[4853],{"type":27,"value":4086},{"type":21,"tag":512,"props":4855,"children":4856},{"style":646},[4857],{"type":27,"value":4858},"// 200元定金预购，得到50元优惠券\n",{"type":21,"tag":512,"props":4860,"children":4861},{"class":514,"line":2257},[4862,4866,4870,4875,4879,4883,4887,4891,4895],{"type":21,"tag":512,"props":4863,"children":4864},{"style":519},[4865],{"type":27,"value":4743},{"type":21,"tag":512,"props":4867,"children":4868},{"style":815},[4869],{"type":27,"value":843},{"type":21,"tag":512,"props":4871,"children":4872},{"style":686},[4873],{"type":27,"value":4874},"3",{"type":21,"tag":512,"props":4876,"children":4877},{"style":815},[4878],{"type":27,"value":1965},{"type":21,"tag":512,"props":4880,"children":4881},{"style":686},[4882],{"type":27,"value":4800},{"type":21,"tag":512,"props":4884,"children":4885},{"style":815},[4886],{"type":27,"value":1965},{"type":21,"tag":512,"props":4888,"children":4889},{"style":686},[4890],{"type":27,"value":4081},{"type":21,"tag":512,"props":4892,"children":4893},{"style":815},[4894],{"type":27,"value":1858},{"type":21,"tag":512,"props":4896,"children":4897},{"style":646},[4898],{"type":27,"value":4817},{"type":21,"tag":512,"props":4900,"children":4901},{"class":514,"line":2265},[4902,4906,4910,4914,4918,4922,4926,4930,4935],{"type":21,"tag":512,"props":4903,"children":4904},{"style":519},[4905],{"type":27,"value":4743},{"type":21,"tag":512,"props":4907,"children":4908},{"style":815},[4909],{"type":27,"value":843},{"type":21,"tag":512,"props":4911,"children":4912},{"style":686},[4913],{"type":27,"value":4874},{"type":21,"tag":512,"props":4915,"children":4916},{"style":815},[4917],{"type":27,"value":1965},{"type":21,"tag":512,"props":4919,"children":4920},{"style":686},[4921],{"type":27,"value":4800},{"type":21,"tag":512,"props":4923,"children":4924},{"style":815},[4925],{"type":27,"value":1965},{"type":21,"tag":512,"props":4927,"children":4928},{"style":686},[4929],{"type":27,"value":2454},{"type":21,"tag":512,"props":4931,"children":4932},{"style":815},[4933],{"type":27,"value":4934},")   ",{"type":21,"tag":512,"props":4936,"children":4937},{"style":646},[4938],{"type":27,"value":4939},"// 手机库存不足\n",{"type":21,"tag":29,"props":4941,"children":4942},{},[4943],{"type":27,"value":4944},"以上的代码经过责任链处理之后特别的清晰，并且减少了大量的if-else嵌套，每个链的职责分，我们可以看出责任链模式存在的优点：",{"type":21,"tag":295,"props":4946,"children":4947},{},[4948,4953],{"type":21,"tag":79,"props":4949,"children":4950},{},[4951],{"type":27,"value":4952},"降低了代码之间的耦合，很好的对每个处理逻辑进行封装。在每个链条内，只需要关注自身的逻辑实现。",{"type":21,"tag":79,"props":4954,"children":4955},{},[4956],{"type":27,"value":4957},"增强了代码的可维护性。我们可以很轻易在原有链条内的任何位置添加新的节点，或者对链条内的节点进行替换或者删除。",{"type":21,"tag":29,"props":4959,"children":4960},{},[4961,4963,4969],{"type":27,"value":4962},"责任链特别的灵活，如果说后面pm找我们加需求了，多了一个预付定金400，返回80元优惠券，处理起来也是易如反掌，只需要在",{"type":21,"tag":508,"props":4964,"children":4966},{"className":4965},[],[4967],{"type":27,"value":4968},"order500",{"type":27,"value":4970},"下面加多一个节点处理即可：",{"type":21,"tag":501,"props":4972,"children":4974},{"className":2762,"code":4973,"language":2764,"meta":8,"style":8},"    ... \n    resChain.add('order500', (_, next) => {\n        if (orderType === 1 && pay === true) {\n            console.log('500元定金预购，拿到100元优惠券');\n            return;\n        }\n        next();\n    })\n    \n    resChain.add('order400', (_, next) => {\n        if (orderType === 3 && pay === true) {\n            console.log('400元定金预购，拿80元优惠券');\n            return;\n        }\n        next();\n    })\n    \n    resChain.add('order200', (_, next) => {\n        if (orderType === 2 && pay === true) {\n            console.log('200元定金预购，拿到50元优惠券');\n            return;\n        }\n        next();\n    })\n    ...\n",[4975],{"type":21,"tag":508,"props":4976,"children":4977},{"__ignoreMap":8},[4978,4991,5038,5077,5100,5111,5118,5129,5136,5143,5191,5230,5254,5265,5272,5283,5290,5297,5344,5383,5406,5417,5424,5435,5442],{"type":21,"tag":512,"props":4979,"children":4980},{"class":514,"line":515},[4981,4986],{"type":21,"tag":512,"props":4982,"children":4983},{"style":809},[4984],{"type":27,"value":4985},"    ...",{"type":21,"tag":512,"props":4987,"children":4988},{"style":815},[4989],{"type":27,"value":4990}," \n",{"type":21,"tag":512,"props":4992,"children":4993},{"class":514,"line":359},[4994,4998,5002,5006,5010,5014,5018,5022,5026,5030,5034],{"type":21,"tag":512,"props":4995,"children":4996},{"style":815},[4997],{"type":27,"value":4219},{"type":21,"tag":512,"props":4999,"children":5000},{"style":519},[5001],{"type":27,"value":4224},{"type":21,"tag":512,"props":5003,"children":5004},{"style":815},[5005],{"type":27,"value":843},{"type":21,"tag":512,"props":5007,"children":5008},{"style":525},[5009],{"type":27,"value":4233},{"type":21,"tag":512,"props":5011,"children":5012},{"style":815},[5013],{"type":27,"value":2018},{"type":21,"tag":512,"props":5015,"children":5016},{"style":1850},[5017],{"type":27,"value":4242},{"type":21,"tag":512,"props":5019,"children":5020},{"style":815},[5021],{"type":27,"value":1965},{"type":21,"tag":512,"props":5023,"children":5024},{"style":1850},[5025],{"type":27,"value":2876},{"type":21,"tag":512,"props":5027,"children":5028},{"style":815},[5029],{"type":27,"value":1858},{"type":21,"tag":512,"props":5031,"children":5032},{"style":809},[5033],{"type":27,"value":1863},{"type":21,"tag":512,"props":5035,"children":5036},{"style":815},[5037],{"type":27,"value":1067},{"type":21,"tag":512,"props":5039,"children":5040},{"class":514,"line":365},[5041,5045,5049,5053,5057,5061,5065,5069,5073],{"type":21,"tag":512,"props":5042,"children":5043},{"style":809},[5044],{"type":27,"value":3808},{"type":21,"tag":512,"props":5046,"children":5047},{"style":815},[5048],{"type":27,"value":3526},{"type":21,"tag":512,"props":5050,"children":5051},{"style":809},[5052],{"type":27,"value":2906},{"type":21,"tag":512,"props":5054,"children":5055},{"style":686},[5056],{"type":27,"value":3535},{"type":21,"tag":512,"props":5058,"children":5059},{"style":809},[5060],{"type":27,"value":4286},{"type":21,"tag":512,"props":5062,"children":5063},{"style":815},[5064],{"type":27,"value":4291},{"type":21,"tag":512,"props":5066,"children":5067},{"style":809},[5068],{"type":27,"value":2906},{"type":21,"tag":512,"props":5070,"children":5071},{"style":686},[5072],{"type":27,"value":3561},{"type":21,"tag":512,"props":5074,"children":5075},{"style":815},[5076],{"type":27,"value":2916},{"type":21,"tag":512,"props":5078,"children":5079},{"class":514,"line":673},[5080,5084,5088,5092,5096],{"type":21,"tag":512,"props":5081,"children":5082},{"style":815},[5083],{"type":27,"value":4311},{"type":21,"tag":512,"props":5085,"children":5086},{"style":519},[5087],{"type":27,"value":966},{"type":21,"tag":512,"props":5089,"children":5090},{"style":815},[5091],{"type":27,"value":843},{"type":21,"tag":512,"props":5093,"children":5094},{"style":525},[5095],{"type":27,"value":4324},{"type":21,"tag":512,"props":5097,"children":5098},{"style":815},[5099],{"type":27,"value":853},{"type":21,"tag":512,"props":5101,"children":5102},{"class":514,"line":900},[5103,5107],{"type":21,"tag":512,"props":5104,"children":5105},{"style":809},[5106],{"type":27,"value":4336},{"type":21,"tag":512,"props":5108,"children":5109},{"style":815},[5110],{"type":27,"value":897},{"type":21,"tag":512,"props":5112,"children":5113},{"class":514,"line":908},[5114],{"type":21,"tag":512,"props":5115,"children":5116},{"style":815},[5117],{"type":27,"value":3894},{"type":21,"tag":512,"props":5119,"children":5120},{"class":514,"line":955},[5121,5125],{"type":21,"tag":512,"props":5122,"children":5123},{"style":519},[5124],{"type":27,"value":4355},{"type":21,"tag":512,"props":5126,"children":5127},{"style":815},[5128],{"type":27,"value":952},{"type":21,"tag":512,"props":5130,"children":5131},{"class":514,"line":983},[5132],{"type":21,"tag":512,"props":5133,"children":5134},{"style":815},[5135],{"type":27,"value":4372},{"type":21,"tag":512,"props":5137,"children":5138},{"class":514,"line":991},[5139],{"type":21,"tag":512,"props":5140,"children":5141},{"style":815},[5142],{"type":27,"value":4211},{"type":21,"tag":512,"props":5144,"children":5145},{"class":514,"line":1015},[5146,5150,5154,5158,5163,5167,5171,5175,5179,5183,5187],{"type":21,"tag":512,"props":5147,"children":5148},{"style":815},[5149],{"type":27,"value":4219},{"type":21,"tag":512,"props":5151,"children":5152},{"style":519},[5153],{"type":27,"value":4224},{"type":21,"tag":512,"props":5155,"children":5156},{"style":815},[5157],{"type":27,"value":843},{"type":21,"tag":512,"props":5159,"children":5160},{"style":525},[5161],{"type":27,"value":5162},"'order400'",{"type":21,"tag":512,"props":5164,"children":5165},{"style":815},[5166],{"type":27,"value":2018},{"type":21,"tag":512,"props":5168,"children":5169},{"style":1850},[5170],{"type":27,"value":4242},{"type":21,"tag":512,"props":5172,"children":5173},{"style":815},[5174],{"type":27,"value":1965},{"type":21,"tag":512,"props":5176,"children":5177},{"style":1850},[5178],{"type":27,"value":2876},{"type":21,"tag":512,"props":5180,"children":5181},{"style":815},[5182],{"type":27,"value":1858},{"type":21,"tag":512,"props":5184,"children":5185},{"style":809},[5186],{"type":27,"value":1863},{"type":21,"tag":512,"props":5188,"children":5189},{"style":815},[5190],{"type":27,"value":1067},{"type":21,"tag":512,"props":5192,"children":5193},{"class":514,"line":1047},[5194,5198,5202,5206,5210,5214,5218,5222,5226],{"type":21,"tag":512,"props":5195,"children":5196},{"style":809},[5197],{"type":27,"value":3808},{"type":21,"tag":512,"props":5199,"children":5200},{"style":815},[5201],{"type":27,"value":3526},{"type":21,"tag":512,"props":5203,"children":5204},{"style":809},[5205],{"type":27,"value":2906},{"type":21,"tag":512,"props":5207,"children":5208},{"style":686},[5209],{"type":27,"value":3929},{"type":21,"tag":512,"props":5211,"children":5212},{"style":809},[5213],{"type":27,"value":4286},{"type":21,"tag":512,"props":5215,"children":5216},{"style":815},[5217],{"type":27,"value":4291},{"type":21,"tag":512,"props":5219,"children":5220},{"style":809},[5221],{"type":27,"value":2906},{"type":21,"tag":512,"props":5223,"children":5224},{"style":686},[5225],{"type":27,"value":3561},{"type":21,"tag":512,"props":5227,"children":5228},{"style":815},[5229],{"type":27,"value":2916},{"type":21,"tag":512,"props":5231,"children":5232},{"class":514,"line":1056},[5233,5237,5241,5245,5250],{"type":21,"tag":512,"props":5234,"children":5235},{"style":815},[5236],{"type":27,"value":4311},{"type":21,"tag":512,"props":5238,"children":5239},{"style":519},[5240],{"type":27,"value":966},{"type":21,"tag":512,"props":5242,"children":5243},{"style":815},[5244],{"type":27,"value":843},{"type":21,"tag":512,"props":5246,"children":5247},{"style":525},[5248],{"type":27,"value":5249},"'400元定金预购，拿80元优惠券'",{"type":21,"tag":512,"props":5251,"children":5252},{"style":815},[5253],{"type":27,"value":853},{"type":21,"tag":512,"props":5255,"children":5256},{"class":514,"line":1070},[5257,5261],{"type":21,"tag":512,"props":5258,"children":5259},{"style":809},[5260],{"type":27,"value":4336},{"type":21,"tag":512,"props":5262,"children":5263},{"style":815},[5264],{"type":27,"value":897},{"type":21,"tag":512,"props":5266,"children":5267},{"class":514,"line":1079},[5268],{"type":21,"tag":512,"props":5269,"children":5270},{"style":815},[5271],{"type":27,"value":3894},{"type":21,"tag":512,"props":5273,"children":5274},{"class":514,"line":1317},[5275,5279],{"type":21,"tag":512,"props":5276,"children":5277},{"style":519},[5278],{"type":27,"value":4355},{"type":21,"tag":512,"props":5280,"children":5281},{"style":815},[5282],{"type":27,"value":952},{"type":21,"tag":512,"props":5284,"children":5285},{"class":514,"line":1326},[5286],{"type":21,"tag":512,"props":5287,"children":5288},{"style":815},[5289],{"type":27,"value":4372},{"type":21,"tag":512,"props":5291,"children":5292},{"class":514,"line":1678},[5293],{"type":21,"tag":512,"props":5294,"children":5295},{"style":815},[5296],{"type":27,"value":4211},{"type":21,"tag":512,"props":5298,"children":5299},{"class":514,"line":1704},[5300,5304,5308,5312,5316,5320,5324,5328,5332,5336,5340],{"type":21,"tag":512,"props":5301,"children":5302},{"style":815},[5303],{"type":27,"value":4219},{"type":21,"tag":512,"props":5305,"children":5306},{"style":519},[5307],{"type":27,"value":4224},{"type":21,"tag":512,"props":5309,"children":5310},{"style":815},[5311],{"type":27,"value":843},{"type":21,"tag":512,"props":5313,"children":5314},{"style":525},[5315],{"type":27,"value":4399},{"type":21,"tag":512,"props":5317,"children":5318},{"style":815},[5319],{"type":27,"value":2018},{"type":21,"tag":512,"props":5321,"children":5322},{"style":1850},[5323],{"type":27,"value":4242},{"type":21,"tag":512,"props":5325,"children":5326},{"style":815},[5327],{"type":27,"value":1965},{"type":21,"tag":512,"props":5329,"children":5330},{"style":1850},[5331],{"type":27,"value":2876},{"type":21,"tag":512,"props":5333,"children":5334},{"style":815},[5335],{"type":27,"value":1858},{"type":21,"tag":512,"props":5337,"children":5338},{"style":809},[5339],{"type":27,"value":1863},{"type":21,"tag":512,"props":5341,"children":5342},{"style":815},[5343],{"type":27,"value":1067},{"type":21,"tag":512,"props":5345,"children":5346},{"class":514,"line":1730},[5347,5351,5355,5359,5363,5367,5371,5375,5379],{"type":21,"tag":512,"props":5348,"children":5349},{"style":809},[5350],{"type":27,"value":3808},{"type":21,"tag":512,"props":5352,"children":5353},{"style":815},[5354],{"type":27,"value":3526},{"type":21,"tag":512,"props":5356,"children":5357},{"style":809},[5358],{"type":27,"value":2906},{"type":21,"tag":512,"props":5360,"children":5361},{"style":686},[5362],{"type":27,"value":3734},{"type":21,"tag":512,"props":5364,"children":5365},{"style":809},[5366],{"type":27,"value":4286},{"type":21,"tag":512,"props":5368,"children":5369},{"style":815},[5370],{"type":27,"value":4291},{"type":21,"tag":512,"props":5372,"children":5373},{"style":809},[5374],{"type":27,"value":2906},{"type":21,"tag":512,"props":5376,"children":5377},{"style":686},[5378],{"type":27,"value":3561},{"type":21,"tag":512,"props":5380,"children":5381},{"style":815},[5382],{"type":27,"value":2916},{"type":21,"tag":512,"props":5384,"children":5385},{"class":514,"line":1756},[5386,5390,5394,5398,5402],{"type":21,"tag":512,"props":5387,"children":5388},{"style":815},[5389],{"type":27,"value":4311},{"type":21,"tag":512,"props":5391,"children":5392},{"style":519},[5393],{"type":27,"value":966},{"type":21,"tag":512,"props":5395,"children":5396},{"style":815},[5397],{"type":27,"value":843},{"type":21,"tag":512,"props":5399,"children":5400},{"style":525},[5401],{"type":27,"value":4486},{"type":21,"tag":512,"props":5403,"children":5404},{"style":815},[5405],{"type":27,"value":853},{"type":21,"tag":512,"props":5407,"children":5408},{"class":514,"line":1820},[5409,5413],{"type":21,"tag":512,"props":5410,"children":5411},{"style":809},[5412],{"type":27,"value":4336},{"type":21,"tag":512,"props":5414,"children":5415},{"style":815},[5416],{"type":27,"value":897},{"type":21,"tag":512,"props":5418,"children":5419},{"class":514,"line":1828},[5420],{"type":21,"tag":512,"props":5421,"children":5422},{"style":815},[5423],{"type":27,"value":3894},{"type":21,"tag":512,"props":5425,"children":5426},{"class":514,"line":1870},[5427,5431],{"type":21,"tag":512,"props":5428,"children":5429},{"style":519},[5430],{"type":27,"value":4355},{"type":21,"tag":512,"props":5432,"children":5433},{"style":815},[5434],{"type":27,"value":952},{"type":21,"tag":512,"props":5436,"children":5437},{"class":514,"line":1879},[5438],{"type":21,"tag":512,"props":5439,"children":5440},{"style":815},[5441],{"type":27,"value":4372},{"type":21,"tag":512,"props":5443,"children":5444},{"class":514,"line":1915},[5445],{"type":21,"tag":512,"props":5446,"children":5447},{"style":809},[5448],{"type":27,"value":5449},"    ...\n",{"type":21,"tag":29,"props":5451,"children":5452},{},[5453,5455,5461],{"type":27,"value":5454},"就是这么简单。那这个",{"type":21,"tag":508,"props":5456,"children":5458},{"className":5457},[],[5459],{"type":27,"value":5460},"ResChain",{"type":27,"value":5462},"是如何实现的呢？",{"type":21,"tag":22,"props":5464,"children":5466},{"id":5465},"封装reschain",[5467],{"type":27,"value":5468},"封装ResChain",{"type":21,"tag":29,"props":5470,"children":5471},{},[5472,5474,5479,5481,5486],{"type":27,"value":5473},"先别急，首先我们来了解一下",{"type":21,"tag":508,"props":5475,"children":5477},{"className":5476},[],[5478],{"type":27,"value":2738},{"type":27,"value":5480},"是如何实现：在链节点的回调函数内",{"type":21,"tag":508,"props":5482,"children":5484},{"className":5483},[],[5485],{"type":27,"value":2876},{"type":27,"value":5487},"就可以跳到下一个节点的呢？",{"type":21,"tag":29,"props":5489,"children":5490},{},[5491,5493,5500],{"type":27,"value":5492},"话不多说，直接看源码，参考的库是",{"type":21,"tag":445,"props":5494,"children":5497},{"href":5495,"rel":5496},"https://github.com/koajs/compose",[449],[5498],{"type":27,"value":5499},"koa-compose",{"type":27,"value":5501},"，代码也是特别的简洁：",{"type":21,"tag":501,"props":5503,"children":5505},{"className":2762,"code":5504,"language":2764,"meta":8,"style":8},"function compose (middleware) {\n    // 这里传入的middleware是函数数组，类似的结构为： [fn1, fn2, fn3, fn4, ...]\n  if (!Array.isArray(middleware)) throw new TypeError('Middleware stack must be an array!')\n  for (const fn of middleware) {\n    if (typeof fn !== 'function') throw new TypeError('Middleware must be composed of functions!')\n  }\n\n  return function (context, next) {\n    // last called middleware #\n    let index = -1\n    return dispatch(0)\n    function dispatch (i) {\n      // 这里是防止重复调用next\n      if (i \u003C= index) return Promise.reject(new Error('next() called multiple times'))\n      index = i\n      let fn = middleware[i]\n      if (i === middleware.length) fn = next\n      if (!fn) return Promise.resolve()\n      try {\n        // next函数其实就是middleware的下一个函数，执行next就是执行下一个函数\n        return Promise.resolve(fn(context, dispatch.bind(null, i + 1)))\n      } catch (err) {\n        return Promise.reject(err)\n      }\n    }\n  }\n}\n",[5506],{"type":21,"tag":508,"props":5507,"children":5508},{"__ignoreMap":8},[5509,5534,5542,5599,5630,5690,5697,5704,5737,5745,5772,5796,5821,5829,5896,5913,5934,5973,6013,6025,6033,6099,6116,6140,6147,6155,6162],{"type":21,"tag":512,"props":5510,"children":5511},{"class":514,"line":515},[5512,5516,5521,5525,5530],{"type":21,"tag":512,"props":5513,"children":5514},{"style":809},[5515],{"type":27,"value":4123},{"type":21,"tag":512,"props":5517,"children":5518},{"style":519},[5519],{"type":27,"value":5520}," compose",{"type":21,"tag":512,"props":5522,"children":5523},{"style":815},[5524],{"type":27,"value":1002},{"type":21,"tag":512,"props":5526,"children":5527},{"style":1850},[5528],{"type":27,"value":5529},"middleware",{"type":21,"tag":512,"props":5531,"children":5532},{"style":815},[5533],{"type":27,"value":2916},{"type":21,"tag":512,"props":5535,"children":5536},{"class":514,"line":359},[5537],{"type":21,"tag":512,"props":5538,"children":5539},{"style":646},[5540],{"type":27,"value":5541},"    // 这里传入的middleware是函数数组，类似的结构为： [fn1, fn2, fn3, fn4, ...]\n",{"type":21,"tag":512,"props":5543,"children":5544},{"class":514,"line":365},[5545,5549,5553,5557,5562,5567,5572,5577,5581,5586,5590,5595],{"type":21,"tag":512,"props":5546,"children":5547},{"style":809},[5548],{"type":27,"value":2896},{"type":21,"tag":512,"props":5550,"children":5551},{"style":815},[5552],{"type":27,"value":1002},{"type":21,"tag":512,"props":5554,"children":5555},{"style":809},[5556],{"type":27,"value":1007},{"type":21,"tag":512,"props":5558,"children":5559},{"style":815},[5560],{"type":27,"value":5561},"Array.",{"type":21,"tag":512,"props":5563,"children":5564},{"style":519},[5565],{"type":27,"value":5566},"isArray",{"type":21,"tag":512,"props":5568,"children":5569},{"style":815},[5570],{"type":27,"value":5571},"(middleware)) ",{"type":21,"tag":512,"props":5573,"children":5574},{"style":809},[5575],{"type":27,"value":5576},"throw",{"type":21,"tag":512,"props":5578,"children":5579},{"style":809},[5580],{"type":27,"value":1026},{"type":21,"tag":512,"props":5582,"children":5583},{"style":519},[5584],{"type":27,"value":5585}," TypeError",{"type":21,"tag":512,"props":5587,"children":5588},{"style":815},[5589],{"type":27,"value":843},{"type":21,"tag":512,"props":5591,"children":5592},{"style":525},[5593],{"type":27,"value":5594},"'Middleware stack must be an array!'",{"type":21,"tag":512,"props":5596,"children":5597},{"style":815},[5598],{"type":27,"value":3591},{"type":21,"tag":512,"props":5600,"children":5601},{"class":514,"line":673},[5602,5607,5611,5615,5620,5625],{"type":21,"tag":512,"props":5603,"children":5604},{"style":809},[5605],{"type":27,"value":5606},"  for",{"type":21,"tag":512,"props":5608,"children":5609},{"style":815},[5610],{"type":27,"value":1002},{"type":21,"tag":512,"props":5612,"children":5613},{"style":809},[5614],{"type":27,"value":812},{"type":21,"tag":512,"props":5616,"children":5617},{"style":686},[5618],{"type":27,"value":5619}," fn",{"type":21,"tag":512,"props":5621,"children":5622},{"style":809},[5623],{"type":27,"value":5624}," of",{"type":21,"tag":512,"props":5626,"children":5627},{"style":815},[5628],{"type":27,"value":5629}," middleware) {\n",{"type":21,"tag":512,"props":5631,"children":5632},{"class":514,"line":900},[5633,5637,5641,5646,5651,5656,5661,5665,5669,5673,5677,5681,5686],{"type":21,"tag":512,"props":5634,"children":5635},{"style":809},[5636],{"type":27,"value":3547},{"type":21,"tag":512,"props":5638,"children":5639},{"style":815},[5640],{"type":27,"value":1002},{"type":21,"tag":512,"props":5642,"children":5643},{"style":809},[5644],{"type":27,"value":5645},"typeof",{"type":21,"tag":512,"props":5647,"children":5648},{"style":815},[5649],{"type":27,"value":5650}," fn ",{"type":21,"tag":512,"props":5652,"children":5653},{"style":809},[5654],{"type":27,"value":5655},"!==",{"type":21,"tag":512,"props":5657,"children":5658},{"style":525},[5659],{"type":27,"value":5660}," 'function'",{"type":21,"tag":512,"props":5662,"children":5663},{"style":815},[5664],{"type":27,"value":1858},{"type":21,"tag":512,"props":5666,"children":5667},{"style":809},[5668],{"type":27,"value":5576},{"type":21,"tag":512,"props":5670,"children":5671},{"style":809},[5672],{"type":27,"value":1026},{"type":21,"tag":512,"props":5674,"children":5675},{"style":519},[5676],{"type":27,"value":5585},{"type":21,"tag":512,"props":5678,"children":5679},{"style":815},[5680],{"type":27,"value":843},{"type":21,"tag":512,"props":5682,"children":5683},{"style":525},[5684],{"type":27,"value":5685},"'Middleware must be composed of functions!'",{"type":21,"tag":512,"props":5687,"children":5688},{"style":815},[5689],{"type":27,"value":3591},{"type":21,"tag":512,"props":5691,"children":5692},{"class":514,"line":908},[5693],{"type":21,"tag":512,"props":5694,"children":5695},{"style":815},[5696],{"type":27,"value":2957},{"type":21,"tag":512,"props":5698,"children":5699},{"class":514,"line":955},[5700],{"type":21,"tag":512,"props":5701,"children":5702},{"emptyLinePlaceholder":859},[5703],{"type":27,"value":862},{"type":21,"tag":512,"props":5705,"children":5706},{"class":514,"line":983},[5707,5712,5716,5720,5725,5729,5733],{"type":21,"tag":512,"props":5708,"children":5709},{"style":809},[5710],{"type":27,"value":5711},"  return",{"type":21,"tag":512,"props":5713,"children":5714},{"style":809},[5715],{"type":27,"value":3483},{"type":21,"tag":512,"props":5717,"children":5718},{"style":815},[5719],{"type":27,"value":1002},{"type":21,"tag":512,"props":5721,"children":5722},{"style":1850},[5723],{"type":27,"value":5724},"context",{"type":21,"tag":512,"props":5726,"children":5727},{"style":815},[5728],{"type":27,"value":1965},{"type":21,"tag":512,"props":5730,"children":5731},{"style":1850},[5732],{"type":27,"value":2876},{"type":21,"tag":512,"props":5734,"children":5735},{"style":815},[5736],{"type":27,"value":2916},{"type":21,"tag":512,"props":5738,"children":5739},{"class":514,"line":991},[5740],{"type":21,"tag":512,"props":5741,"children":5742},{"style":646},[5743],{"type":27,"value":5744},"    // last called middleware #\n",{"type":21,"tag":512,"props":5746,"children":5747},{"class":514,"line":1015},[5748,5753,5758,5762,5767],{"type":21,"tag":512,"props":5749,"children":5750},{"style":809},[5751],{"type":27,"value":5752},"    let",{"type":21,"tag":512,"props":5754,"children":5755},{"style":815},[5756],{"type":27,"value":5757}," index ",{"type":21,"tag":512,"props":5759,"children":5760},{"style":809},[5761],{"type":27,"value":833},{"type":21,"tag":512,"props":5763,"children":5764},{"style":809},[5765],{"type":27,"value":5766}," -",{"type":21,"tag":512,"props":5768,"children":5769},{"style":686},[5770],{"type":27,"value":5771},"1\n",{"type":21,"tag":512,"props":5773,"children":5774},{"class":514,"line":1047},[5775,5779,5784,5788,5792],{"type":21,"tag":512,"props":5776,"children":5777},{"style":809},[5778],{"type":27,"value":2945},{"type":21,"tag":512,"props":5780,"children":5781},{"style":519},[5782],{"type":27,"value":5783}," dispatch",{"type":21,"tag":512,"props":5785,"children":5786},{"style":815},[5787],{"type":27,"value":843},{"type":21,"tag":512,"props":5789,"children":5790},{"style":686},[5791],{"type":27,"value":2454},{"type":21,"tag":512,"props":5793,"children":5794},{"style":815},[5795],{"type":27,"value":3591},{"type":21,"tag":512,"props":5797,"children":5798},{"class":514,"line":1056},[5799,5804,5808,5812,5817],{"type":21,"tag":512,"props":5800,"children":5801},{"style":809},[5802],{"type":27,"value":5803},"    function",{"type":21,"tag":512,"props":5805,"children":5806},{"style":519},[5807],{"type":27,"value":5783},{"type":21,"tag":512,"props":5809,"children":5810},{"style":815},[5811],{"type":27,"value":1002},{"type":21,"tag":512,"props":5813,"children":5814},{"style":1850},[5815],{"type":27,"value":5816},"i",{"type":21,"tag":512,"props":5818,"children":5819},{"style":815},[5820],{"type":27,"value":2916},{"type":21,"tag":512,"props":5822,"children":5823},{"class":514,"line":1070},[5824],{"type":21,"tag":512,"props":5825,"children":5826},{"style":646},[5827],{"type":27,"value":5828},"      // 这里是防止重复调用next\n",{"type":21,"tag":512,"props":5830,"children":5831},{"class":514,"line":1079},[5832,5836,5841,5846,5851,5855,5859,5864,5869,5873,5878,5882,5886,5891],{"type":21,"tag":512,"props":5833,"children":5834},{"style":809},[5835],{"type":27,"value":3615},{"type":21,"tag":512,"props":5837,"children":5838},{"style":815},[5839],{"type":27,"value":5840}," (i ",{"type":21,"tag":512,"props":5842,"children":5843},{"style":809},[5844],{"type":27,"value":5845},"\u003C=",{"type":21,"tag":512,"props":5847,"children":5848},{"style":815},[5849],{"type":27,"value":5850}," index) ",{"type":21,"tag":512,"props":5852,"children":5853},{"style":809},[5854],{"type":27,"value":1062},{"type":21,"tag":512,"props":5856,"children":5857},{"style":686},[5858],{"type":27,"value":1842},{"type":21,"tag":512,"props":5860,"children":5861},{"style":815},[5862],{"type":27,"value":5863},".",{"type":21,"tag":512,"props":5865,"children":5866},{"style":519},[5867],{"type":27,"value":5868},"reject",{"type":21,"tag":512,"props":5870,"children":5871},{"style":815},[5872],{"type":27,"value":843},{"type":21,"tag":512,"props":5874,"children":5875},{"style":809},[5876],{"type":27,"value":5877},"new",{"type":21,"tag":512,"props":5879,"children":5880},{"style":519},[5881],{"type":27,"value":1031},{"type":21,"tag":512,"props":5883,"children":5884},{"style":815},[5885],{"type":27,"value":843},{"type":21,"tag":512,"props":5887,"children":5888},{"style":525},[5889],{"type":27,"value":5890},"'next() called multiple times'",{"type":21,"tag":512,"props":5892,"children":5893},{"style":815},[5894],{"type":27,"value":5895},"))\n",{"type":21,"tag":512,"props":5897,"children":5898},{"class":514,"line":1317},[5899,5904,5908],{"type":21,"tag":512,"props":5900,"children":5901},{"style":815},[5902],{"type":27,"value":5903},"      index ",{"type":21,"tag":512,"props":5905,"children":5906},{"style":809},[5907],{"type":27,"value":833},{"type":21,"tag":512,"props":5909,"children":5910},{"style":815},[5911],{"type":27,"value":5912}," i\n",{"type":21,"tag":512,"props":5914,"children":5915},{"class":514,"line":1326},[5916,5921,5925,5929],{"type":21,"tag":512,"props":5917,"children":5918},{"style":809},[5919],{"type":27,"value":5920},"      let",{"type":21,"tag":512,"props":5922,"children":5923},{"style":815},[5924],{"type":27,"value":5650},{"type":21,"tag":512,"props":5926,"children":5927},{"style":809},[5928],{"type":27,"value":833},{"type":21,"tag":512,"props":5930,"children":5931},{"style":815},[5932],{"type":27,"value":5933}," middleware[i]\n",{"type":21,"tag":512,"props":5935,"children":5936},{"class":514,"line":1678},[5937,5941,5945,5949,5954,5959,5964,5968],{"type":21,"tag":512,"props":5938,"children":5939},{"style":809},[5940],{"type":27,"value":3615},{"type":21,"tag":512,"props":5942,"children":5943},{"style":815},[5944],{"type":27,"value":5840},{"type":21,"tag":512,"props":5946,"children":5947},{"style":809},[5948],{"type":27,"value":2906},{"type":21,"tag":512,"props":5950,"children":5951},{"style":815},[5952],{"type":27,"value":5953}," middleware.",{"type":21,"tag":512,"props":5955,"children":5956},{"style":686},[5957],{"type":27,"value":5958},"length",{"type":21,"tag":512,"props":5960,"children":5961},{"style":815},[5962],{"type":27,"value":5963},") fn ",{"type":21,"tag":512,"props":5965,"children":5966},{"style":809},[5967],{"type":27,"value":833},{"type":21,"tag":512,"props":5969,"children":5970},{"style":815},[5971],{"type":27,"value":5972}," next\n",{"type":21,"tag":512,"props":5974,"children":5975},{"class":514,"line":1704},[5976,5980,5984,5988,5993,5997,6001,6005,6009],{"type":21,"tag":512,"props":5977,"children":5978},{"style":809},[5979],{"type":27,"value":3615},{"type":21,"tag":512,"props":5981,"children":5982},{"style":815},[5983],{"type":27,"value":1002},{"type":21,"tag":512,"props":5985,"children":5986},{"style":809},[5987],{"type":27,"value":1007},{"type":21,"tag":512,"props":5989,"children":5990},{"style":815},[5991],{"type":27,"value":5992},"fn) ",{"type":21,"tag":512,"props":5994,"children":5995},{"style":809},[5996],{"type":27,"value":1062},{"type":21,"tag":512,"props":5998,"children":5999},{"style":686},[6000],{"type":27,"value":1842},{"type":21,"tag":512,"props":6002,"children":6003},{"style":815},[6004],{"type":27,"value":5863},{"type":21,"tag":512,"props":6006,"children":6007},{"style":519},[6008],{"type":27,"value":1853},{"type":21,"tag":512,"props":6010,"children":6011},{"style":815},[6012],{"type":27,"value":4203},{"type":21,"tag":512,"props":6014,"children":6015},{"class":514,"line":1730},[6016,6021],{"type":21,"tag":512,"props":6017,"children":6018},{"style":809},[6019],{"type":27,"value":6020},"      try",{"type":21,"tag":512,"props":6022,"children":6023},{"style":815},[6024],{"type":27,"value":1067},{"type":21,"tag":512,"props":6026,"children":6027},{"class":514,"line":1756},[6028],{"type":21,"tag":512,"props":6029,"children":6030},{"style":646},[6031],{"type":27,"value":6032},"        // next函数其实就是middleware的下一个函数，执行next就是执行下一个函数\n",{"type":21,"tag":512,"props":6034,"children":6035},{"class":514,"line":1820},[6036,6041,6045,6049,6053,6057,6062,6067,6072,6076,6081,6086,6090,6094],{"type":21,"tag":512,"props":6037,"children":6038},{"style":809},[6039],{"type":27,"value":6040},"        return",{"type":21,"tag":512,"props":6042,"children":6043},{"style":686},[6044],{"type":27,"value":1842},{"type":21,"tag":512,"props":6046,"children":6047},{"style":815},[6048],{"type":27,"value":5863},{"type":21,"tag":512,"props":6050,"children":6051},{"style":519},[6052],{"type":27,"value":1853},{"type":21,"tag":512,"props":6054,"children":6055},{"style":815},[6056],{"type":27,"value":843},{"type":21,"tag":512,"props":6058,"children":6059},{"style":519},[6060],{"type":27,"value":6061},"fn",{"type":21,"tag":512,"props":6063,"children":6064},{"style":815},[6065],{"type":27,"value":6066},"(context, dispatch.",{"type":21,"tag":512,"props":6068,"children":6069},{"style":519},[6070],{"type":27,"value":6071},"bind",{"type":21,"tag":512,"props":6073,"children":6074},{"style":815},[6075],{"type":27,"value":843},{"type":21,"tag":512,"props":6077,"children":6078},{"style":686},[6079],{"type":27,"value":6080},"null",{"type":21,"tag":512,"props":6082,"children":6083},{"style":815},[6084],{"type":27,"value":6085},", i ",{"type":21,"tag":512,"props":6087,"children":6088},{"style":809},[6089],{"type":27,"value":2295},{"type":21,"tag":512,"props":6091,"children":6092},{"style":686},[6093],{"type":27,"value":3535},{"type":21,"tag":512,"props":6095,"children":6096},{"style":815},[6097],{"type":27,"value":6098},")))\n",{"type":21,"tag":512,"props":6100,"children":6101},{"class":514,"line":1828},[6102,6106,6111],{"type":21,"tag":512,"props":6103,"children":6104},{"style":815},[6105],{"type":27,"value":3667},{"type":21,"tag":512,"props":6107,"children":6108},{"style":809},[6109],{"type":27,"value":6110},"catch",{"type":21,"tag":512,"props":6112,"children":6113},{"style":815},[6114],{"type":27,"value":6115}," (err) {\n",{"type":21,"tag":512,"props":6117,"children":6118},{"class":514,"line":1870},[6119,6123,6127,6131,6135],{"type":21,"tag":512,"props":6120,"children":6121},{"style":809},[6122],{"type":27,"value":6040},{"type":21,"tag":512,"props":6124,"children":6125},{"style":686},[6126],{"type":27,"value":1842},{"type":21,"tag":512,"props":6128,"children":6129},{"style":815},[6130],{"type":27,"value":5863},{"type":21,"tag":512,"props":6132,"children":6133},{"style":519},[6134],{"type":27,"value":5868},{"type":21,"tag":512,"props":6136,"children":6137},{"style":815},[6138],{"type":27,"value":6139},"(err)\n",{"type":21,"tag":512,"props":6141,"children":6142},{"class":514,"line":1879},[6143],{"type":21,"tag":512,"props":6144,"children":6145},{"style":815},[6146],{"type":27,"value":2467},{"type":21,"tag":512,"props":6148,"children":6149},{"class":514,"line":1915},[6150],{"type":21,"tag":512,"props":6151,"children":6152},{"style":815},[6153],{"type":27,"value":6154},"    }\n",{"type":21,"tag":512,"props":6156,"children":6157},{"class":514,"line":1941},[6158],{"type":21,"tag":512,"props":6159,"children":6160},{"style":815},[6161],{"type":27,"value":2957},{"type":21,"tag":512,"props":6163,"children":6164},{"class":514,"line":1985},[6165],{"type":21,"tag":512,"props":6166,"children":6167},{"style":815},[6168],{"type":27,"value":1053},{"type":21,"tag":29,"props":6170,"children":6171},{},[6172,6174,6179],{"type":27,"value":6173},"原理很简单吧，接下来我们来实现",{"type":21,"tag":508,"props":6175,"children":6177},{"className":6176},[],[6178],{"type":27,"value":5460},{"type":27,"value":6180},":",{"type":21,"tag":501,"props":6182,"children":6184},{"className":2762,"code":6183,"language":2764,"meta":8,"style":8},"export class ResChain {\n  \n  /**\n   * 按顺序存放链的key\n   */\n  keyOrder = [];\n  /**\n   * key对应的函数\n   */\n  key2FnMap = new Map();\n  /**\n   * 每个节点都可以拿到的对象\n   */\n  ctx = {}\n  constructor(ctx) {\n    this.ctx = ctx;\n  }\n\n  add(key: string, callback) {\n    if (this.key2FnMap.has(key)) {\n      throw new Error(`Chain ${key} already exists`);\n    }\n\n    this.keyOrder.push(key);\n    this.key2FnMap.set(key, callback);\n    return this;\n  }\n\n  async run() {\n    let index = -1;\n    const dispatch = (i) => {\n      if (i \u003C= index) {\n        return Promise.reject(new Error('next() called multiple times'));\n      }\n\n      index = i;\n      const fn = this.key2FnMap.get(this.keyOrder[i]);\n      if (!fn) {\n        return Promise.resolve(void 0);\n      }\n\n      return fn(this.ctx, dispatch.bind(null, i + 1));\n    };\n\n    return dispatch(0);\n  }\n}\n",[6185],{"type":21,"tag":508,"props":6186,"children":6187},{"__ignoreMap":8},[6188,6209,6216,6224,6232,6240,6257,6264,6272,6279,6304,6311,6319,6326,6343,6363,6385,6392,6399,6438,6469,6507,6514,6521,6543,6564,6580,6587,6594,6612,6639,6674,6694,6738,6745,6752,6768,6810,6830,6866,6873,6880,6933,6941,6948,6971,6978],{"type":21,"tag":512,"props":6189,"children":6190},{"class":514,"line":515},[6191,6196,6201,6205],{"type":21,"tag":512,"props":6192,"children":6193},{"style":809},[6194],{"type":27,"value":6195},"export",{"type":21,"tag":512,"props":6197,"children":6198},{"style":809},[6199],{"type":27,"value":6200}," class",{"type":21,"tag":512,"props":6202,"children":6203},{"style":519},[6204],{"type":27,"value":4198},{"type":21,"tag":512,"props":6206,"children":6207},{"style":815},[6208],{"type":27,"value":1067},{"type":21,"tag":512,"props":6210,"children":6211},{"class":514,"line":359},[6212],{"type":21,"tag":512,"props":6213,"children":6214},{"style":815},[6215],{"type":27,"value":2965},{"type":21,"tag":512,"props":6217,"children":6218},{"class":514,"line":365},[6219],{"type":21,"tag":512,"props":6220,"children":6221},{"style":646},[6222],{"type":27,"value":6223},"  /**\n",{"type":21,"tag":512,"props":6225,"children":6226},{"class":514,"line":673},[6227],{"type":21,"tag":512,"props":6228,"children":6229},{"style":646},[6230],{"type":27,"value":6231},"   * 按顺序存放链的key\n",{"type":21,"tag":512,"props":6233,"children":6234},{"class":514,"line":900},[6235],{"type":21,"tag":512,"props":6236,"children":6237},{"style":646},[6238],{"type":27,"value":6239},"   */\n",{"type":21,"tag":512,"props":6241,"children":6242},{"class":514,"line":908},[6243,6248,6252],{"type":21,"tag":512,"props":6244,"children":6245},{"style":1850},[6246],{"type":27,"value":6247},"  keyOrder",{"type":21,"tag":512,"props":6249,"children":6250},{"style":809},[6251],{"type":27,"value":887},{"type":21,"tag":512,"props":6253,"children":6254},{"style":815},[6255],{"type":27,"value":6256}," [];\n",{"type":21,"tag":512,"props":6258,"children":6259},{"class":514,"line":955},[6260],{"type":21,"tag":512,"props":6261,"children":6262},{"style":646},[6263],{"type":27,"value":6223},{"type":21,"tag":512,"props":6265,"children":6266},{"class":514,"line":983},[6267],{"type":21,"tag":512,"props":6268,"children":6269},{"style":646},[6270],{"type":27,"value":6271},"   * key对应的函数\n",{"type":21,"tag":512,"props":6273,"children":6274},{"class":514,"line":991},[6275],{"type":21,"tag":512,"props":6276,"children":6277},{"style":646},[6278],{"type":27,"value":6239},{"type":21,"tag":512,"props":6280,"children":6281},{"class":514,"line":1015},[6282,6287,6291,6295,6300],{"type":21,"tag":512,"props":6283,"children":6284},{"style":1850},[6285],{"type":27,"value":6286},"  key2FnMap",{"type":21,"tag":512,"props":6288,"children":6289},{"style":809},[6290],{"type":27,"value":887},{"type":21,"tag":512,"props":6292,"children":6293},{"style":809},[6294],{"type":27,"value":1026},{"type":21,"tag":512,"props":6296,"children":6297},{"style":519},[6298],{"type":27,"value":6299}," Map",{"type":21,"tag":512,"props":6301,"children":6302},{"style":815},[6303],{"type":27,"value":952},{"type":21,"tag":512,"props":6305,"children":6306},{"class":514,"line":1047},[6307],{"type":21,"tag":512,"props":6308,"children":6309},{"style":646},[6310],{"type":27,"value":6223},{"type":21,"tag":512,"props":6312,"children":6313},{"class":514,"line":1056},[6314],{"type":21,"tag":512,"props":6315,"children":6316},{"style":646},[6317],{"type":27,"value":6318},"   * 每个节点都可以拿到的对象\n",{"type":21,"tag":512,"props":6320,"children":6321},{"class":514,"line":1070},[6322],{"type":21,"tag":512,"props":6323,"children":6324},{"style":646},[6325],{"type":27,"value":6239},{"type":21,"tag":512,"props":6327,"children":6328},{"class":514,"line":1079},[6329,6334,6338],{"type":21,"tag":512,"props":6330,"children":6331},{"style":1850},[6332],{"type":27,"value":6333},"  ctx",{"type":21,"tag":512,"props":6335,"children":6336},{"style":809},[6337],{"type":27,"value":887},{"type":21,"tag":512,"props":6339,"children":6340},{"style":815},[6341],{"type":27,"value":6342}," {}\n",{"type":21,"tag":512,"props":6344,"children":6345},{"class":514,"line":1317},[6346,6351,6355,6359],{"type":21,"tag":512,"props":6347,"children":6348},{"style":809},[6349],{"type":27,"value":6350},"  constructor",{"type":21,"tag":512,"props":6352,"children":6353},{"style":815},[6354],{"type":27,"value":843},{"type":21,"tag":512,"props":6356,"children":6357},{"style":1850},[6358],{"type":27,"value":2867},{"type":21,"tag":512,"props":6360,"children":6361},{"style":815},[6362],{"type":27,"value":2916},{"type":21,"tag":512,"props":6364,"children":6365},{"class":514,"line":1326},[6366,6371,6376,6380],{"type":21,"tag":512,"props":6367,"children":6368},{"style":686},[6369],{"type":27,"value":6370},"    this",{"type":21,"tag":512,"props":6372,"children":6373},{"style":815},[6374],{"type":27,"value":6375},".ctx ",{"type":21,"tag":512,"props":6377,"children":6378},{"style":809},[6379],{"type":27,"value":833},{"type":21,"tag":512,"props":6381,"children":6382},{"style":815},[6383],{"type":27,"value":6384}," ctx;\n",{"type":21,"tag":512,"props":6386,"children":6387},{"class":514,"line":1678},[6388],{"type":21,"tag":512,"props":6389,"children":6390},{"style":815},[6391],{"type":27,"value":2957},{"type":21,"tag":512,"props":6393,"children":6394},{"class":514,"line":1704},[6395],{"type":21,"tag":512,"props":6396,"children":6397},{"emptyLinePlaceholder":859},[6398],{"type":27,"value":862},{"type":21,"tag":512,"props":6400,"children":6401},{"class":514,"line":1730},[6402,6407,6411,6416,6420,6425,6429,6434],{"type":21,"tag":512,"props":6403,"children":6404},{"style":519},[6405],{"type":27,"value":6406},"  add",{"type":21,"tag":512,"props":6408,"children":6409},{"style":815},[6410],{"type":27,"value":843},{"type":21,"tag":512,"props":6412,"children":6413},{"style":1850},[6414],{"type":27,"value":6415},"key",{"type":21,"tag":512,"props":6417,"children":6418},{"style":809},[6419],{"type":27,"value":6180},{"type":21,"tag":512,"props":6421,"children":6422},{"style":686},[6423],{"type":27,"value":6424}," string",{"type":21,"tag":512,"props":6426,"children":6427},{"style":815},[6428],{"type":27,"value":1965},{"type":21,"tag":512,"props":6430,"children":6431},{"style":1850},[6432],{"type":27,"value":6433},"callback",{"type":21,"tag":512,"props":6435,"children":6436},{"style":815},[6437],{"type":27,"value":2916},{"type":21,"tag":512,"props":6439,"children":6440},{"class":514,"line":1756},[6441,6445,6449,6454,6459,6464],{"type":21,"tag":512,"props":6442,"children":6443},{"style":809},[6444],{"type":27,"value":3547},{"type":21,"tag":512,"props":6446,"children":6447},{"style":815},[6448],{"type":27,"value":1002},{"type":21,"tag":512,"props":6450,"children":6451},{"style":686},[6452],{"type":27,"value":6453},"this",{"type":21,"tag":512,"props":6455,"children":6456},{"style":815},[6457],{"type":27,"value":6458},".key2FnMap.",{"type":21,"tag":512,"props":6460,"children":6461},{"style":519},[6462],{"type":27,"value":6463},"has",{"type":21,"tag":512,"props":6465,"children":6466},{"style":815},[6467],{"type":27,"value":6468},"(key)) {\n",{"type":21,"tag":512,"props":6470,"children":6471},{"class":514,"line":1820},[6472,6477,6481,6485,6489,6494,6498,6503],{"type":21,"tag":512,"props":6473,"children":6474},{"style":809},[6475],{"type":27,"value":6476},"      throw",{"type":21,"tag":512,"props":6478,"children":6479},{"style":809},[6480],{"type":27,"value":1026},{"type":21,"tag":512,"props":6482,"children":6483},{"style":519},[6484],{"type":27,"value":1031},{"type":21,"tag":512,"props":6486,"children":6487},{"style":815},[6488],{"type":27,"value":843},{"type":21,"tag":512,"props":6490,"children":6491},{"style":525},[6492],{"type":27,"value":6493},"`Chain ${",{"type":21,"tag":512,"props":6495,"children":6496},{"style":815},[6497],{"type":27,"value":6415},{"type":21,"tag":512,"props":6499,"children":6500},{"style":525},[6501],{"type":27,"value":6502},"} already exists`",{"type":21,"tag":512,"props":6504,"children":6505},{"style":815},[6506],{"type":27,"value":853},{"type":21,"tag":512,"props":6508,"children":6509},{"class":514,"line":1828},[6510],{"type":21,"tag":512,"props":6511,"children":6512},{"style":815},[6513],{"type":27,"value":6154},{"type":21,"tag":512,"props":6515,"children":6516},{"class":514,"line":1870},[6517],{"type":21,"tag":512,"props":6518,"children":6519},{"emptyLinePlaceholder":859},[6520],{"type":27,"value":862},{"type":21,"tag":512,"props":6522,"children":6523},{"class":514,"line":1879},[6524,6528,6533,6538],{"type":21,"tag":512,"props":6525,"children":6526},{"style":686},[6527],{"type":27,"value":6370},{"type":21,"tag":512,"props":6529,"children":6530},{"style":815},[6531],{"type":27,"value":6532},".keyOrder.",{"type":21,"tag":512,"props":6534,"children":6535},{"style":519},[6536],{"type":27,"value":6537},"push",{"type":21,"tag":512,"props":6539,"children":6540},{"style":815},[6541],{"type":27,"value":6542},"(key);\n",{"type":21,"tag":512,"props":6544,"children":6545},{"class":514,"line":1915},[6546,6550,6554,6559],{"type":21,"tag":512,"props":6547,"children":6548},{"style":686},[6549],{"type":27,"value":6370},{"type":21,"tag":512,"props":6551,"children":6552},{"style":815},[6553],{"type":27,"value":6458},{"type":21,"tag":512,"props":6555,"children":6556},{"style":519},[6557],{"type":27,"value":6558},"set",{"type":21,"tag":512,"props":6560,"children":6561},{"style":815},[6562],{"type":27,"value":6563},"(key, callback);\n",{"type":21,"tag":512,"props":6565,"children":6566},{"class":514,"line":1941},[6567,6571,6576],{"type":21,"tag":512,"props":6568,"children":6569},{"style":809},[6570],{"type":27,"value":2945},{"type":21,"tag":512,"props":6572,"children":6573},{"style":686},[6574],{"type":27,"value":6575}," this",{"type":21,"tag":512,"props":6577,"children":6578},{"style":815},[6579],{"type":27,"value":897},{"type":21,"tag":512,"props":6581,"children":6582},{"class":514,"line":1985},[6583],{"type":21,"tag":512,"props":6584,"children":6585},{"style":815},[6586],{"type":27,"value":2957},{"type":21,"tag":512,"props":6588,"children":6589},{"class":514,"line":1994},[6590],{"type":21,"tag":512,"props":6591,"children":6592},{"emptyLinePlaceholder":859},[6593],{"type":27,"value":862},{"type":21,"tag":512,"props":6595,"children":6596},{"class":514,"line":2046},[6597,6602,6607],{"type":21,"tag":512,"props":6598,"children":6599},{"style":809},[6600],{"type":27,"value":6601},"  async",{"type":21,"tag":512,"props":6603,"children":6604},{"style":519},[6605],{"type":27,"value":6606}," run",{"type":21,"tag":512,"props":6608,"children":6609},{"style":815},[6610],{"type":27,"value":6611},"() {\n",{"type":21,"tag":512,"props":6613,"children":6614},{"class":514,"line":2072},[6615,6619,6623,6627,6631,6635],{"type":21,"tag":512,"props":6616,"children":6617},{"style":809},[6618],{"type":27,"value":5752},{"type":21,"tag":512,"props":6620,"children":6621},{"style":815},[6622],{"type":27,"value":5757},{"type":21,"tag":512,"props":6624,"children":6625},{"style":809},[6626],{"type":27,"value":833},{"type":21,"tag":512,"props":6628,"children":6629},{"style":809},[6630],{"type":27,"value":5766},{"type":21,"tag":512,"props":6632,"children":6633},{"style":686},[6634],{"type":27,"value":4063},{"type":21,"tag":512,"props":6636,"children":6637},{"style":815},[6638],{"type":27,"value":897},{"type":21,"tag":512,"props":6640,"children":6641},{"class":514,"line":2090},[6642,6646,6650,6654,6658,6662,6666,6670],{"type":21,"tag":512,"props":6643,"children":6644},{"style":809},[6645],{"type":27,"value":4180},{"type":21,"tag":512,"props":6647,"children":6648},{"style":519},[6649],{"type":27,"value":5783},{"type":21,"tag":512,"props":6651,"children":6652},{"style":809},[6653],{"type":27,"value":887},{"type":21,"tag":512,"props":6655,"children":6656},{"style":815},[6657],{"type":27,"value":1002},{"type":21,"tag":512,"props":6659,"children":6660},{"style":1850},[6661],{"type":27,"value":5816},{"type":21,"tag":512,"props":6663,"children":6664},{"style":815},[6665],{"type":27,"value":1858},{"type":21,"tag":512,"props":6667,"children":6668},{"style":809},[6669],{"type":27,"value":1863},{"type":21,"tag":512,"props":6671,"children":6672},{"style":815},[6673],{"type":27,"value":1067},{"type":21,"tag":512,"props":6675,"children":6676},{"class":514,"line":2099},[6677,6681,6685,6689],{"type":21,"tag":512,"props":6678,"children":6679},{"style":809},[6680],{"type":27,"value":3615},{"type":21,"tag":512,"props":6682,"children":6683},{"style":815},[6684],{"type":27,"value":5840},{"type":21,"tag":512,"props":6686,"children":6687},{"style":809},[6688],{"type":27,"value":5845},{"type":21,"tag":512,"props":6690,"children":6691},{"style":815},[6692],{"type":27,"value":6693}," index) {\n",{"type":21,"tag":512,"props":6695,"children":6696},{"class":514,"line":2141},[6697,6701,6705,6709,6713,6717,6721,6725,6729,6733],{"type":21,"tag":512,"props":6698,"children":6699},{"style":809},[6700],{"type":27,"value":6040},{"type":21,"tag":512,"props":6702,"children":6703},{"style":686},[6704],{"type":27,"value":1842},{"type":21,"tag":512,"props":6706,"children":6707},{"style":815},[6708],{"type":27,"value":5863},{"type":21,"tag":512,"props":6710,"children":6711},{"style":519},[6712],{"type":27,"value":5868},{"type":21,"tag":512,"props":6714,"children":6715},{"style":815},[6716],{"type":27,"value":843},{"type":21,"tag":512,"props":6718,"children":6719},{"style":809},[6720],{"type":27,"value":5877},{"type":21,"tag":512,"props":6722,"children":6723},{"style":519},[6724],{"type":27,"value":1031},{"type":21,"tag":512,"props":6726,"children":6727},{"style":815},[6728],{"type":27,"value":843},{"type":21,"tag":512,"props":6730,"children":6731},{"style":525},[6732],{"type":27,"value":5890},{"type":21,"tag":512,"props":6734,"children":6735},{"style":815},[6736],{"type":27,"value":6737},"));\n",{"type":21,"tag":512,"props":6739,"children":6740},{"class":514,"line":2168},[6741],{"type":21,"tag":512,"props":6742,"children":6743},{"style":815},[6744],{"type":27,"value":2467},{"type":21,"tag":512,"props":6746,"children":6747},{"class":514,"line":2176},[6748],{"type":21,"tag":512,"props":6749,"children":6750},{"emptyLinePlaceholder":859},[6751],{"type":27,"value":862},{"type":21,"tag":512,"props":6753,"children":6754},{"class":514,"line":2217},[6755,6759,6763],{"type":21,"tag":512,"props":6756,"children":6757},{"style":815},[6758],{"type":27,"value":5903},{"type":21,"tag":512,"props":6760,"children":6761},{"style":809},[6762],{"type":27,"value":833},{"type":21,"tag":512,"props":6764,"children":6765},{"style":815},[6766],{"type":27,"value":6767}," i;\n",{"type":21,"tag":512,"props":6769,"children":6770},{"class":514,"line":2248},[6771,6776,6780,6784,6788,6792,6797,6801,6805],{"type":21,"tag":512,"props":6772,"children":6773},{"style":809},[6774],{"type":27,"value":6775},"      const",{"type":21,"tag":512,"props":6777,"children":6778},{"style":686},[6779],{"type":27,"value":5619},{"type":21,"tag":512,"props":6781,"children":6782},{"style":809},[6783],{"type":27,"value":887},{"type":21,"tag":512,"props":6785,"children":6786},{"style":686},[6787],{"type":27,"value":6575},{"type":21,"tag":512,"props":6789,"children":6790},{"style":815},[6791],{"type":27,"value":6458},{"type":21,"tag":512,"props":6793,"children":6794},{"style":519},[6795],{"type":27,"value":6796},"get",{"type":21,"tag":512,"props":6798,"children":6799},{"style":815},[6800],{"type":27,"value":843},{"type":21,"tag":512,"props":6802,"children":6803},{"style":686},[6804],{"type":27,"value":6453},{"type":21,"tag":512,"props":6806,"children":6807},{"style":815},[6808],{"type":27,"value":6809},".keyOrder[i]);\n",{"type":21,"tag":512,"props":6811,"children":6812},{"class":514,"line":2257},[6813,6817,6821,6825],{"type":21,"tag":512,"props":6814,"children":6815},{"style":809},[6816],{"type":27,"value":3615},{"type":21,"tag":512,"props":6818,"children":6819},{"style":815},[6820],{"type":27,"value":1002},{"type":21,"tag":512,"props":6822,"children":6823},{"style":809},[6824],{"type":27,"value":1007},{"type":21,"tag":512,"props":6826,"children":6827},{"style":815},[6828],{"type":27,"value":6829},"fn) {\n",{"type":21,"tag":512,"props":6831,"children":6832},{"class":514,"line":2265},[6833,6837,6841,6845,6849,6853,6858,6862],{"type":21,"tag":512,"props":6834,"children":6835},{"style":809},[6836],{"type":27,"value":6040},{"type":21,"tag":512,"props":6838,"children":6839},{"style":686},[6840],{"type":27,"value":1842},{"type":21,"tag":512,"props":6842,"children":6843},{"style":815},[6844],{"type":27,"value":5863},{"type":21,"tag":512,"props":6846,"children":6847},{"style":519},[6848],{"type":27,"value":1853},{"type":21,"tag":512,"props":6850,"children":6851},{"style":815},[6852],{"type":27,"value":843},{"type":21,"tag":512,"props":6854,"children":6855},{"style":809},[6856],{"type":27,"value":6857},"void",{"type":21,"tag":512,"props":6859,"children":6860},{"style":686},[6861],{"type":27,"value":3630},{"type":21,"tag":512,"props":6863,"children":6864},{"style":815},[6865],{"type":27,"value":853},{"type":21,"tag":512,"props":6867,"children":6868},{"class":514,"line":2274},[6869],{"type":21,"tag":512,"props":6870,"children":6871},{"style":815},[6872],{"type":27,"value":2467},{"type":21,"tag":512,"props":6874,"children":6875},{"class":514,"line":2317},[6876],{"type":21,"tag":512,"props":6877,"children":6878},{"emptyLinePlaceholder":859},[6879],{"type":27,"value":862},{"type":21,"tag":512,"props":6881,"children":6882},{"class":514,"line":2326},[6883,6888,6892,6896,6900,6905,6909,6913,6917,6921,6925,6929],{"type":21,"tag":512,"props":6884,"children":6885},{"style":809},[6886],{"type":27,"value":6887},"      return",{"type":21,"tag":512,"props":6889,"children":6890},{"style":519},[6891],{"type":27,"value":5619},{"type":21,"tag":512,"props":6893,"children":6894},{"style":815},[6895],{"type":27,"value":843},{"type":21,"tag":512,"props":6897,"children":6898},{"style":686},[6899],{"type":27,"value":6453},{"type":21,"tag":512,"props":6901,"children":6902},{"style":815},[6903],{"type":27,"value":6904},".ctx, dispatch.",{"type":21,"tag":512,"props":6906,"children":6907},{"style":519},[6908],{"type":27,"value":6071},{"type":21,"tag":512,"props":6910,"children":6911},{"style":815},[6912],{"type":27,"value":843},{"type":21,"tag":512,"props":6914,"children":6915},{"style":686},[6916],{"type":27,"value":6080},{"type":21,"tag":512,"props":6918,"children":6919},{"style":815},[6920],{"type":27,"value":6085},{"type":21,"tag":512,"props":6922,"children":6923},{"style":809},[6924],{"type":27,"value":2295},{"type":21,"tag":512,"props":6926,"children":6927},{"style":686},[6928],{"type":27,"value":3535},{"type":21,"tag":512,"props":6930,"children":6931},{"style":815},[6932],{"type":27,"value":6737},{"type":21,"tag":512,"props":6934,"children":6935},{"class":514,"line":2359},[6936],{"type":21,"tag":512,"props":6937,"children":6938},{"style":815},[6939],{"type":27,"value":6940},"    };\n",{"type":21,"tag":512,"props":6942,"children":6943},{"class":514,"line":2368},[6944],{"type":21,"tag":512,"props":6945,"children":6946},{"emptyLinePlaceholder":859},[6947],{"type":27,"value":862},{"type":21,"tag":512,"props":6949,"children":6950},{"class":514,"line":2401},[6951,6955,6959,6963,6967],{"type":21,"tag":512,"props":6952,"children":6953},{"style":809},[6954],{"type":27,"value":2945},{"type":21,"tag":512,"props":6956,"children":6957},{"style":519},[6958],{"type":27,"value":5783},{"type":21,"tag":512,"props":6960,"children":6961},{"style":815},[6962],{"type":27,"value":843},{"type":21,"tag":512,"props":6964,"children":6965},{"style":686},[6966],{"type":27,"value":2454},{"type":21,"tag":512,"props":6968,"children":6969},{"style":815},[6970],{"type":27,"value":853},{"type":21,"tag":512,"props":6972,"children":6973},{"class":514,"line":2415},[6974],{"type":21,"tag":512,"props":6975,"children":6976},{"style":815},[6977],{"type":27,"value":2957},{"type":21,"tag":512,"props":6979,"children":6980},{"class":514,"line":2424},[6981],{"type":21,"tag":512,"props":6982,"children":6983},{"style":815},[6984],{"type":27,"value":1053},{"type":21,"tag":29,"props":6986,"children":6987},{},[6988,6990,6995,6997,7002],{"type":27,"value":6989},"以上就是我参考",{"type":21,"tag":508,"props":6991,"children":6993},{"className":6992},[],[6994],{"type":27,"value":2738},{"type":27,"value":6996},"实现的责任链工具函数：",{"type":21,"tag":508,"props":6998,"children":7000},{"className":6999},[],[7001],{"type":27,"value":5460},{"type":27,"value":2715},{"type":21,"tag":29,"props":7004,"children":7005},{},[7006,7008,7013],{"type":27,"value":7007},"有些人会说，",{"type":21,"tag":508,"props":7009,"children":7011},{"className":7010},[],[7012],{"type":27,"value":2738},{"type":27,"value":7014},"的中间件是异步函数的，你这个行不行？",{"type":21,"tag":29,"props":7016,"children":7017},{},[7018],{"type":27,"value":7019},"当然可以，接下来看个异步的例子：",{"type":21,"tag":501,"props":7021,"children":7023},{"className":2762,"code":7022,"language":2764,"meta":8,"style":8},"const resChain = new ResChain();\n\nresChain.add('async1', async (_, next) => {\n  console.log('async1');\n  await next();\n});\n\n\nresChain.add('async2', async (_, next) => {\n  console.log('async2')\n  // 这里可以执行一些异步处理函数\n  await new Promise((resolve, reject) => {\n    setTimeOut(() => {\n      resolve();\n    }, 1000)\n  });\n\n  await next();\n});\n\n\nresChain.add('key3', async (_, next) => {\n  console.log('key3');\n  await next();\n});\n\n\n// 执行责任链\nawait resChain.run();\n\nconsole.log('finished');\n\n// 先输出 async1 async2 然后停顿了1秒钟之后，才输出async3 finished\n",[7024],{"type":21,"tag":508,"props":7025,"children":7026},{"__ignoreMap":8},[7027,7054,7061,7118,7142,7159,7166,7173,7180,7236,7259,7267,7310,7331,7343,7360,7367,7374,7389,7396,7403,7410,7466,7489,7504,7511,7518,7525,7533,7554,7561,7585,7592],{"type":21,"tag":512,"props":7028,"children":7029},{"class":514,"line":515},[7030,7034,7038,7042,7046,7050],{"type":21,"tag":512,"props":7031,"children":7032},{"style":809},[7033],{"type":27,"value":812},{"type":21,"tag":512,"props":7035,"children":7036},{"style":686},[7037],{"type":27,"value":4185},{"type":21,"tag":512,"props":7039,"children":7040},{"style":809},[7041],{"type":27,"value":887},{"type":21,"tag":512,"props":7043,"children":7044},{"style":809},[7045],{"type":27,"value":1026},{"type":21,"tag":512,"props":7047,"children":7048},{"style":519},[7049],{"type":27,"value":4198},{"type":21,"tag":512,"props":7051,"children":7052},{"style":815},[7053],{"type":27,"value":952},{"type":21,"tag":512,"props":7055,"children":7056},{"class":514,"line":359},[7057],{"type":21,"tag":512,"props":7058,"children":7059},{"emptyLinePlaceholder":859},[7060],{"type":27,"value":862},{"type":21,"tag":512,"props":7062,"children":7063},{"class":514,"line":365},[7064,7069,7073,7077,7082,7086,7090,7094,7098,7102,7106,7110,7114],{"type":21,"tag":512,"props":7065,"children":7066},{"style":815},[7067],{"type":27,"value":7068},"resChain.",{"type":21,"tag":512,"props":7070,"children":7071},{"style":519},[7072],{"type":27,"value":4224},{"type":21,"tag":512,"props":7074,"children":7075},{"style":815},[7076],{"type":27,"value":843},{"type":21,"tag":512,"props":7078,"children":7079},{"style":525},[7080],{"type":27,"value":7081},"'async1'",{"type":21,"tag":512,"props":7083,"children":7084},{"style":815},[7085],{"type":27,"value":1965},{"type":21,"tag":512,"props":7087,"children":7088},{"style":809},[7089],{"type":27,"value":2858},{"type":21,"tag":512,"props":7091,"children":7092},{"style":815},[7093],{"type":27,"value":1002},{"type":21,"tag":512,"props":7095,"children":7096},{"style":1850},[7097],{"type":27,"value":4242},{"type":21,"tag":512,"props":7099,"children":7100},{"style":815},[7101],{"type":27,"value":1965},{"type":21,"tag":512,"props":7103,"children":7104},{"style":1850},[7105],{"type":27,"value":2876},{"type":21,"tag":512,"props":7107,"children":7108},{"style":815},[7109],{"type":27,"value":1858},{"type":21,"tag":512,"props":7111,"children":7112},{"style":809},[7113],{"type":27,"value":1863},{"type":21,"tag":512,"props":7115,"children":7116},{"style":815},[7117],{"type":27,"value":1067},{"type":21,"tag":512,"props":7119,"children":7120},{"class":514,"line":673},[7121,7126,7130,7134,7138],{"type":21,"tag":512,"props":7122,"children":7123},{"style":815},[7124],{"type":27,"value":7125},"  console.",{"type":21,"tag":512,"props":7127,"children":7128},{"style":519},[7129],{"type":27,"value":966},{"type":21,"tag":512,"props":7131,"children":7132},{"style":815},[7133],{"type":27,"value":843},{"type":21,"tag":512,"props":7135,"children":7136},{"style":525},[7137],{"type":27,"value":7081},{"type":21,"tag":512,"props":7139,"children":7140},{"style":815},[7141],{"type":27,"value":853},{"type":21,"tag":512,"props":7143,"children":7144},{"class":514,"line":900},[7145,7150,7155],{"type":21,"tag":512,"props":7146,"children":7147},{"style":809},[7148],{"type":27,"value":7149},"  await",{"type":21,"tag":512,"props":7151,"children":7152},{"style":519},[7153],{"type":27,"value":7154}," next",{"type":21,"tag":512,"props":7156,"children":7157},{"style":815},[7158],{"type":27,"value":952},{"type":21,"tag":512,"props":7160,"children":7161},{"class":514,"line":908},[7162],{"type":21,"tag":512,"props":7163,"children":7164},{"style":815},[7165],{"type":27,"value":2991},{"type":21,"tag":512,"props":7167,"children":7168},{"class":514,"line":955},[7169],{"type":21,"tag":512,"props":7170,"children":7171},{"emptyLinePlaceholder":859},[7172],{"type":27,"value":862},{"type":21,"tag":512,"props":7174,"children":7175},{"class":514,"line":983},[7176],{"type":21,"tag":512,"props":7177,"children":7178},{"emptyLinePlaceholder":859},[7179],{"type":27,"value":862},{"type":21,"tag":512,"props":7181,"children":7182},{"class":514,"line":991},[7183,7187,7191,7195,7200,7204,7208,7212,7216,7220,7224,7228,7232],{"type":21,"tag":512,"props":7184,"children":7185},{"style":815},[7186],{"type":27,"value":7068},{"type":21,"tag":512,"props":7188,"children":7189},{"style":519},[7190],{"type":27,"value":4224},{"type":21,"tag":512,"props":7192,"children":7193},{"style":815},[7194],{"type":27,"value":843},{"type":21,"tag":512,"props":7196,"children":7197},{"style":525},[7198],{"type":27,"value":7199},"'async2'",{"type":21,"tag":512,"props":7201,"children":7202},{"style":815},[7203],{"type":27,"value":1965},{"type":21,"tag":512,"props":7205,"children":7206},{"style":809},[7207],{"type":27,"value":2858},{"type":21,"tag":512,"props":7209,"children":7210},{"style":815},[7211],{"type":27,"value":1002},{"type":21,"tag":512,"props":7213,"children":7214},{"style":1850},[7215],{"type":27,"value":4242},{"type":21,"tag":512,"props":7217,"children":7218},{"style":815},[7219],{"type":27,"value":1965},{"type":21,"tag":512,"props":7221,"children":7222},{"style":1850},[7223],{"type":27,"value":2876},{"type":21,"tag":512,"props":7225,"children":7226},{"style":815},[7227],{"type":27,"value":1858},{"type":21,"tag":512,"props":7229,"children":7230},{"style":809},[7231],{"type":27,"value":1863},{"type":21,"tag":512,"props":7233,"children":7234},{"style":815},[7235],{"type":27,"value":1067},{"type":21,"tag":512,"props":7237,"children":7238},{"class":514,"line":1015},[7239,7243,7247,7251,7255],{"type":21,"tag":512,"props":7240,"children":7241},{"style":815},[7242],{"type":27,"value":7125},{"type":21,"tag":512,"props":7244,"children":7245},{"style":519},[7246],{"type":27,"value":966},{"type":21,"tag":512,"props":7248,"children":7249},{"style":815},[7250],{"type":27,"value":843},{"type":21,"tag":512,"props":7252,"children":7253},{"style":525},[7254],{"type":27,"value":7199},{"type":21,"tag":512,"props":7256,"children":7257},{"style":815},[7258],{"type":27,"value":3591},{"type":21,"tag":512,"props":7260,"children":7261},{"class":514,"line":1047},[7262],{"type":21,"tag":512,"props":7263,"children":7264},{"style":646},[7265],{"type":27,"value":7266},"  // 这里可以执行一些异步处理函数\n",{"type":21,"tag":512,"props":7268,"children":7269},{"class":514,"line":1056},[7270,7274,7278,7282,7286,7290,7294,7298,7302,7306],{"type":21,"tag":512,"props":7271,"children":7272},{"style":809},[7273],{"type":27,"value":7149},{"type":21,"tag":512,"props":7275,"children":7276},{"style":809},[7277],{"type":27,"value":1026},{"type":21,"tag":512,"props":7279,"children":7280},{"style":686},[7281],{"type":27,"value":1842},{"type":21,"tag":512,"props":7283,"children":7284},{"style":815},[7285],{"type":27,"value":1847},{"type":21,"tag":512,"props":7287,"children":7288},{"style":1850},[7289],{"type":27,"value":1853},{"type":21,"tag":512,"props":7291,"children":7292},{"style":815},[7293],{"type":27,"value":1965},{"type":21,"tag":512,"props":7295,"children":7296},{"style":1850},[7297],{"type":27,"value":5868},{"type":21,"tag":512,"props":7299,"children":7300},{"style":815},[7301],{"type":27,"value":1858},{"type":21,"tag":512,"props":7303,"children":7304},{"style":809},[7305],{"type":27,"value":1863},{"type":21,"tag":512,"props":7307,"children":7308},{"style":815},[7309],{"type":27,"value":1067},{"type":21,"tag":512,"props":7311,"children":7312},{"class":514,"line":1070},[7313,7318,7323,7327],{"type":21,"tag":512,"props":7314,"children":7315},{"style":519},[7316],{"type":27,"value":7317},"    setTimeOut",{"type":21,"tag":512,"props":7319,"children":7320},{"style":815},[7321],{"type":27,"value":7322},"(() ",{"type":21,"tag":512,"props":7324,"children":7325},{"style":809},[7326],{"type":27,"value":1863},{"type":21,"tag":512,"props":7328,"children":7329},{"style":815},[7330],{"type":27,"value":1067},{"type":21,"tag":512,"props":7332,"children":7333},{"class":514,"line":1079},[7334,7339],{"type":21,"tag":512,"props":7335,"children":7336},{"style":519},[7337],{"type":27,"value":7338},"      resolve",{"type":21,"tag":512,"props":7340,"children":7341},{"style":815},[7342],{"type":27,"value":952},{"type":21,"tag":512,"props":7344,"children":7345},{"class":514,"line":1317},[7346,7351,7356],{"type":21,"tag":512,"props":7347,"children":7348},{"style":815},[7349],{"type":27,"value":7350},"    }, ",{"type":21,"tag":512,"props":7352,"children":7353},{"style":686},[7354],{"type":27,"value":7355},"1000",{"type":21,"tag":512,"props":7357,"children":7358},{"style":815},[7359],{"type":27,"value":3591},{"type":21,"tag":512,"props":7361,"children":7362},{"class":514,"line":1326},[7363],{"type":21,"tag":512,"props":7364,"children":7365},{"style":815},[7366],{"type":27,"value":2548},{"type":21,"tag":512,"props":7368,"children":7369},{"class":514,"line":1678},[7370],{"type":21,"tag":512,"props":7371,"children":7372},{"emptyLinePlaceholder":859},[7373],{"type":27,"value":862},{"type":21,"tag":512,"props":7375,"children":7376},{"class":514,"line":1704},[7377,7381,7385],{"type":21,"tag":512,"props":7378,"children":7379},{"style":809},[7380],{"type":27,"value":7149},{"type":21,"tag":512,"props":7382,"children":7383},{"style":519},[7384],{"type":27,"value":7154},{"type":21,"tag":512,"props":7386,"children":7387},{"style":815},[7388],{"type":27,"value":952},{"type":21,"tag":512,"props":7390,"children":7391},{"class":514,"line":1730},[7392],{"type":21,"tag":512,"props":7393,"children":7394},{"style":815},[7395],{"type":27,"value":2991},{"type":21,"tag":512,"props":7397,"children":7398},{"class":514,"line":1756},[7399],{"type":21,"tag":512,"props":7400,"children":7401},{"emptyLinePlaceholder":859},[7402],{"type":27,"value":862},{"type":21,"tag":512,"props":7404,"children":7405},{"class":514,"line":1820},[7406],{"type":21,"tag":512,"props":7407,"children":7408},{"emptyLinePlaceholder":859},[7409],{"type":27,"value":862},{"type":21,"tag":512,"props":7411,"children":7412},{"class":514,"line":1828},[7413,7417,7421,7425,7430,7434,7438,7442,7446,7450,7454,7458,7462],{"type":21,"tag":512,"props":7414,"children":7415},{"style":815},[7416],{"type":27,"value":7068},{"type":21,"tag":512,"props":7418,"children":7419},{"style":519},[7420],{"type":27,"value":4224},{"type":21,"tag":512,"props":7422,"children":7423},{"style":815},[7424],{"type":27,"value":843},{"type":21,"tag":512,"props":7426,"children":7427},{"style":525},[7428],{"type":27,"value":7429},"'key3'",{"type":21,"tag":512,"props":7431,"children":7432},{"style":815},[7433],{"type":27,"value":1965},{"type":21,"tag":512,"props":7435,"children":7436},{"style":809},[7437],{"type":27,"value":2858},{"type":21,"tag":512,"props":7439,"children":7440},{"style":815},[7441],{"type":27,"value":1002},{"type":21,"tag":512,"props":7443,"children":7444},{"style":1850},[7445],{"type":27,"value":4242},{"type":21,"tag":512,"props":7447,"children":7448},{"style":815},[7449],{"type":27,"value":1965},{"type":21,"tag":512,"props":7451,"children":7452},{"style":1850},[7453],{"type":27,"value":2876},{"type":21,"tag":512,"props":7455,"children":7456},{"style":815},[7457],{"type":27,"value":1858},{"type":21,"tag":512,"props":7459,"children":7460},{"style":809},[7461],{"type":27,"value":1863},{"type":21,"tag":512,"props":7463,"children":7464},{"style":815},[7465],{"type":27,"value":1067},{"type":21,"tag":512,"props":7467,"children":7468},{"class":514,"line":1870},[7469,7473,7477,7481,7485],{"type":21,"tag":512,"props":7470,"children":7471},{"style":815},[7472],{"type":27,"value":7125},{"type":21,"tag":512,"props":7474,"children":7475},{"style":519},[7476],{"type":27,"value":966},{"type":21,"tag":512,"props":7478,"children":7479},{"style":815},[7480],{"type":27,"value":843},{"type":21,"tag":512,"props":7482,"children":7483},{"style":525},[7484],{"type":27,"value":7429},{"type":21,"tag":512,"props":7486,"children":7487},{"style":815},[7488],{"type":27,"value":853},{"type":21,"tag":512,"props":7490,"children":7491},{"class":514,"line":1879},[7492,7496,7500],{"type":21,"tag":512,"props":7493,"children":7494},{"style":809},[7495],{"type":27,"value":7149},{"type":21,"tag":512,"props":7497,"children":7498},{"style":519},[7499],{"type":27,"value":7154},{"type":21,"tag":512,"props":7501,"children":7502},{"style":815},[7503],{"type":27,"value":952},{"type":21,"tag":512,"props":7505,"children":7506},{"class":514,"line":1915},[7507],{"type":21,"tag":512,"props":7508,"children":7509},{"style":815},[7510],{"type":27,"value":2991},{"type":21,"tag":512,"props":7512,"children":7513},{"class":514,"line":1941},[7514],{"type":21,"tag":512,"props":7515,"children":7516},{"emptyLinePlaceholder":859},[7517],{"type":27,"value":862},{"type":21,"tag":512,"props":7519,"children":7520},{"class":514,"line":1985},[7521],{"type":21,"tag":512,"props":7522,"children":7523},{"emptyLinePlaceholder":859},[7524],{"type":27,"value":862},{"type":21,"tag":512,"props":7526,"children":7527},{"class":514,"line":1994},[7528],{"type":21,"tag":512,"props":7529,"children":7530},{"style":646},[7531],{"type":27,"value":7532},"// 执行责任链\n",{"type":21,"tag":512,"props":7534,"children":7535},{"class":514,"line":2046},[7536,7541,7546,7550],{"type":21,"tag":512,"props":7537,"children":7538},{"style":809},[7539],{"type":27,"value":7540},"await",{"type":21,"tag":512,"props":7542,"children":7543},{"style":815},[7544],{"type":27,"value":7545}," resChain.",{"type":21,"tag":512,"props":7547,"children":7548},{"style":519},[7549],{"type":27,"value":4703},{"type":21,"tag":512,"props":7551,"children":7552},{"style":815},[7553],{"type":27,"value":952},{"type":21,"tag":512,"props":7555,"children":7556},{"class":514,"line":2072},[7557],{"type":21,"tag":512,"props":7558,"children":7559},{"emptyLinePlaceholder":859},[7560],{"type":27,"value":862},{"type":21,"tag":512,"props":7562,"children":7563},{"class":514,"line":2090},[7564,7568,7572,7576,7581],{"type":21,"tag":512,"props":7565,"children":7566},{"style":815},[7567],{"type":27,"value":961},{"type":21,"tag":512,"props":7569,"children":7570},{"style":519},[7571],{"type":27,"value":966},{"type":21,"tag":512,"props":7573,"children":7574},{"style":815},[7575],{"type":27,"value":843},{"type":21,"tag":512,"props":7577,"children":7578},{"style":525},[7579],{"type":27,"value":7580},"'finished'",{"type":21,"tag":512,"props":7582,"children":7583},{"style":815},[7584],{"type":27,"value":853},{"type":21,"tag":512,"props":7586,"children":7587},{"class":514,"line":2099},[7588],{"type":21,"tag":512,"props":7589,"children":7590},{"emptyLinePlaceholder":859},[7591],{"type":27,"value":862},{"type":21,"tag":512,"props":7593,"children":7594},{"class":514,"line":2141},[7595],{"type":21,"tag":512,"props":7596,"children":7597},{"style":646},[7598],{"type":27,"value":7599},"// 先输出 async1 async2 然后停顿了1秒钟之后，才输出async3 finished\n",{"type":21,"tag":7601,"props":7602,"children":7603},"blockquote",{},[7604],{"type":21,"tag":29,"props":7605,"children":7606},{},[7607],{"type":27,"value":7608},"🚧 需要注意：如果是异步模式，则链上的每个回调函数必须要 await next()，因为next函数代表下一个环的异步函数。",{"type":21,"tag":29,"props":7610,"children":7611},{},[7612,7614,7619],{"type":27,"value":7613},"有人可能还注意到了，",{"type":21,"tag":508,"props":7615,"children":7617},{"className":7616},[],[7618],{"type":27,"value":5460},{"type":27,"value":7620},"实例化的时候可以传入对象，比如下面的代码：",{"type":21,"tag":501,"props":7622,"children":7624},{"className":2762,"code":7623,"language":2764,"meta":8,"style":8},"const resChain = new ResChain({ interrupt: false });\n",[7625],{"type":21,"tag":508,"props":7626,"children":7627},{"__ignoreMap":8},[7628],{"type":21,"tag":512,"props":7629,"children":7630},{"class":514,"line":515},[7631,7635,7639,7643,7647,7651,7656,7660],{"type":21,"tag":512,"props":7632,"children":7633},{"style":809},[7634],{"type":27,"value":812},{"type":21,"tag":512,"props":7636,"children":7637},{"style":686},[7638],{"type":27,"value":4185},{"type":21,"tag":512,"props":7640,"children":7641},{"style":809},[7642],{"type":27,"value":887},{"type":21,"tag":512,"props":7644,"children":7645},{"style":809},[7646],{"type":27,"value":1026},{"type":21,"tag":512,"props":7648,"children":7649},{"style":519},[7650],{"type":27,"value":4198},{"type":21,"tag":512,"props":7652,"children":7653},{"style":815},[7654],{"type":27,"value":7655},"({ interrupt: ",{"type":21,"tag":512,"props":7657,"children":7658},{"style":686},[7659],{"type":27,"value":4800},{"type":21,"tag":512,"props":7661,"children":7662},{"style":815},[7663],{"type":27,"value":7664}," });\n",{"type":21,"tag":29,"props":7666,"children":7667},{},[7668],{"type":27,"value":7669},"传入对象具体有什么用法呢？可以用来获取一些在链中处理好的数据，来实现发送者和处理者的解耦。可能比较抽象，我们来举个例子。",{"type":21,"tag":29,"props":7671,"children":7672},{},[7673],{"type":27,"value":7674},"比如需要进行数据校验的场景，如果不通过，则中断提交：",{"type":21,"tag":501,"props":7676,"children":7678},{"className":2762,"code":7677,"language":2764,"meta":8,"style":8},"const ctx = {\n  // 表单项\n  model: {\n    name: '',\n    phone: '',\n  },\n  // 错误提示\n  error: '',\n  // 是否中断\n  interrupt: false,\n}\nconst resChain = new ResChain(ctx);\n\nresChain.add('校验name', (ctx, next) => {\n  const { name = '' } = ctx;\n  if (name === '') {\n    ctx.error = '请填写name';\n    ctx.interrupt = true;\n    return;\n  }\n\n  next();\n})\n\nresChain.add('校验phone', (ctx, next) => {\n  const { phone = '' } = ctx;\n  if (phone === '') {\n    ctx.error = '请填写手机号';\n    ctx.interrupt = true;\n    return;\n  }\n\n  next();\n})\n\n// 执行责任链\nresChain.run();\n\n// 如果需要中断，则提示\nif (resChain.ctx.interrupt) {\n  alert(resChain.ctx.error);\n  return;\n}\n",[7679],{"type":21,"tag":508,"props":7680,"children":7681},{"__ignoreMap":8},[7682,7702,7710,7718,7735,7751,7759,7767,7783,7791,7807,7814,7842,7849,7897,7935,7959,7980,8000,8011,8018,8025,8036,8043,8050,8098,8134,8158,8178,8197,8208,8215,8222,8233,8240,8247,8254,8269,8276,8284,8296,8309,8320],{"type":21,"tag":512,"props":7683,"children":7684},{"class":514,"line":515},[7685,7689,7694,7698],{"type":21,"tag":512,"props":7686,"children":7687},{"style":809},[7688],{"type":27,"value":812},{"type":21,"tag":512,"props":7690,"children":7691},{"style":686},[7692],{"type":27,"value":7693}," ctx",{"type":21,"tag":512,"props":7695,"children":7696},{"style":809},[7697],{"type":27,"value":887},{"type":21,"tag":512,"props":7699,"children":7700},{"style":815},[7701],{"type":27,"value":1067},{"type":21,"tag":512,"props":7703,"children":7704},{"class":514,"line":359},[7705],{"type":21,"tag":512,"props":7706,"children":7707},{"style":646},[7708],{"type":27,"value":7709},"  // 表单项\n",{"type":21,"tag":512,"props":7711,"children":7712},{"class":514,"line":365},[7713],{"type":21,"tag":512,"props":7714,"children":7715},{"style":815},[7716],{"type":27,"value":7717},"  model: {\n",{"type":21,"tag":512,"props":7719,"children":7720},{"class":514,"line":673},[7721,7726,7731],{"type":21,"tag":512,"props":7722,"children":7723},{"style":815},[7724],{"type":27,"value":7725},"    name: ",{"type":21,"tag":512,"props":7727,"children":7728},{"style":525},[7729],{"type":27,"value":7730},"''",{"type":21,"tag":512,"props":7732,"children":7733},{"style":815},[7734],{"type":27,"value":2440},{"type":21,"tag":512,"props":7736,"children":7737},{"class":514,"line":900},[7738,7743,7747],{"type":21,"tag":512,"props":7739,"children":7740},{"style":815},[7741],{"type":27,"value":7742},"    phone: ",{"type":21,"tag":512,"props":7744,"children":7745},{"style":525},[7746],{"type":27,"value":7730},{"type":21,"tag":512,"props":7748,"children":7749},{"style":815},[7750],{"type":27,"value":2440},{"type":21,"tag":512,"props":7752,"children":7753},{"class":514,"line":908},[7754],{"type":21,"tag":512,"props":7755,"children":7756},{"style":815},[7757],{"type":27,"value":7758},"  },\n",{"type":21,"tag":512,"props":7760,"children":7761},{"class":514,"line":955},[7762],{"type":21,"tag":512,"props":7763,"children":7764},{"style":646},[7765],{"type":27,"value":7766},"  // 错误提示\n",{"type":21,"tag":512,"props":7768,"children":7769},{"class":514,"line":983},[7770,7775,7779],{"type":21,"tag":512,"props":7771,"children":7772},{"style":815},[7773],{"type":27,"value":7774},"  error: ",{"type":21,"tag":512,"props":7776,"children":7777},{"style":525},[7778],{"type":27,"value":7730},{"type":21,"tag":512,"props":7780,"children":7781},{"style":815},[7782],{"type":27,"value":2440},{"type":21,"tag":512,"props":7784,"children":7785},{"class":514,"line":991},[7786],{"type":21,"tag":512,"props":7787,"children":7788},{"style":646},[7789],{"type":27,"value":7790},"  // 是否中断\n",{"type":21,"tag":512,"props":7792,"children":7793},{"class":514,"line":1015},[7794,7799,7803],{"type":21,"tag":512,"props":7795,"children":7796},{"style":815},[7797],{"type":27,"value":7798},"  interrupt: ",{"type":21,"tag":512,"props":7800,"children":7801},{"style":686},[7802],{"type":27,"value":4800},{"type":21,"tag":512,"props":7804,"children":7805},{"style":815},[7806],{"type":27,"value":2440},{"type":21,"tag":512,"props":7808,"children":7809},{"class":514,"line":1047},[7810],{"type":21,"tag":512,"props":7811,"children":7812},{"style":815},[7813],{"type":27,"value":1053},{"type":21,"tag":512,"props":7815,"children":7816},{"class":514,"line":1056},[7817,7821,7825,7829,7833,7837],{"type":21,"tag":512,"props":7818,"children":7819},{"style":809},[7820],{"type":27,"value":812},{"type":21,"tag":512,"props":7822,"children":7823},{"style":686},[7824],{"type":27,"value":4185},{"type":21,"tag":512,"props":7826,"children":7827},{"style":809},[7828],{"type":27,"value":887},{"type":21,"tag":512,"props":7830,"children":7831},{"style":809},[7832],{"type":27,"value":1026},{"type":21,"tag":512,"props":7834,"children":7835},{"style":519},[7836],{"type":27,"value":4198},{"type":21,"tag":512,"props":7838,"children":7839},{"style":815},[7840],{"type":27,"value":7841},"(ctx);\n",{"type":21,"tag":512,"props":7843,"children":7844},{"class":514,"line":1070},[7845],{"type":21,"tag":512,"props":7846,"children":7847},{"emptyLinePlaceholder":859},[7848],{"type":27,"value":862},{"type":21,"tag":512,"props":7850,"children":7851},{"class":514,"line":1079},[7852,7856,7860,7864,7869,7873,7877,7881,7885,7889,7893],{"type":21,"tag":512,"props":7853,"children":7854},{"style":815},[7855],{"type":27,"value":7068},{"type":21,"tag":512,"props":7857,"children":7858},{"style":519},[7859],{"type":27,"value":4224},{"type":21,"tag":512,"props":7861,"children":7862},{"style":815},[7863],{"type":27,"value":843},{"type":21,"tag":512,"props":7865,"children":7866},{"style":525},[7867],{"type":27,"value":7868},"'校验name'",{"type":21,"tag":512,"props":7870,"children":7871},{"style":815},[7872],{"type":27,"value":2018},{"type":21,"tag":512,"props":7874,"children":7875},{"style":1850},[7876],{"type":27,"value":2867},{"type":21,"tag":512,"props":7878,"children":7879},{"style":815},[7880],{"type":27,"value":1965},{"type":21,"tag":512,"props":7882,"children":7883},{"style":1850},[7884],{"type":27,"value":2876},{"type":21,"tag":512,"props":7886,"children":7887},{"style":815},[7888],{"type":27,"value":1858},{"type":21,"tag":512,"props":7890,"children":7891},{"style":809},[7892],{"type":27,"value":1863},{"type":21,"tag":512,"props":7894,"children":7895},{"style":815},[7896],{"type":27,"value":1067},{"type":21,"tag":512,"props":7898,"children":7899},{"class":514,"line":1317},[7900,7905,7909,7914,7918,7923,7927,7931],{"type":21,"tag":512,"props":7901,"children":7902},{"style":809},[7903],{"type":27,"value":7904},"  const",{"type":21,"tag":512,"props":7906,"children":7907},{"style":815},[7908],{"type":27,"value":818},{"type":21,"tag":512,"props":7910,"children":7911},{"style":686},[7912],{"type":27,"value":7913},"name",{"type":21,"tag":512,"props":7915,"children":7916},{"style":809},[7917],{"type":27,"value":887},{"type":21,"tag":512,"props":7919,"children":7920},{"style":525},[7921],{"type":27,"value":7922}," ''",{"type":21,"tag":512,"props":7924,"children":7925},{"style":815},[7926],{"type":27,"value":828},{"type":21,"tag":512,"props":7928,"children":7929},{"style":809},[7930],{"type":27,"value":833},{"type":21,"tag":512,"props":7932,"children":7933},{"style":815},[7934],{"type":27,"value":6384},{"type":21,"tag":512,"props":7936,"children":7937},{"class":514,"line":1326},[7938,7942,7947,7951,7955],{"type":21,"tag":512,"props":7939,"children":7940},{"style":809},[7941],{"type":27,"value":2896},{"type":21,"tag":512,"props":7943,"children":7944},{"style":815},[7945],{"type":27,"value":7946}," (name ",{"type":21,"tag":512,"props":7948,"children":7949},{"style":809},[7950],{"type":27,"value":2906},{"type":21,"tag":512,"props":7952,"children":7953},{"style":525},[7954],{"type":27,"value":7922},{"type":21,"tag":512,"props":7956,"children":7957},{"style":815},[7958],{"type":27,"value":2916},{"type":21,"tag":512,"props":7960,"children":7961},{"class":514,"line":1678},[7962,7967,7971,7976],{"type":21,"tag":512,"props":7963,"children":7964},{"style":815},[7965],{"type":27,"value":7966},"    ctx.error ",{"type":21,"tag":512,"props":7968,"children":7969},{"style":809},[7970],{"type":27,"value":833},{"type":21,"tag":512,"props":7972,"children":7973},{"style":525},[7974],{"type":27,"value":7975}," '请填写name'",{"type":21,"tag":512,"props":7977,"children":7978},{"style":815},[7979],{"type":27,"value":897},{"type":21,"tag":512,"props":7981,"children":7982},{"class":514,"line":1704},[7983,7988,7992,7996],{"type":21,"tag":512,"props":7984,"children":7985},{"style":815},[7986],{"type":27,"value":7987},"    ctx.interrupt ",{"type":21,"tag":512,"props":7989,"children":7990},{"style":809},[7991],{"type":27,"value":833},{"type":21,"tag":512,"props":7993,"children":7994},{"style":686},[7995],{"type":27,"value":3561},{"type":21,"tag":512,"props":7997,"children":7998},{"style":815},[7999],{"type":27,"value":897},{"type":21,"tag":512,"props":8001,"children":8002},{"class":514,"line":1730},[8003,8007],{"type":21,"tag":512,"props":8004,"children":8005},{"style":809},[8006],{"type":27,"value":2945},{"type":21,"tag":512,"props":8008,"children":8009},{"style":815},[8010],{"type":27,"value":897},{"type":21,"tag":512,"props":8012,"children":8013},{"class":514,"line":1756},[8014],{"type":21,"tag":512,"props":8015,"children":8016},{"style":815},[8017],{"type":27,"value":2957},{"type":21,"tag":512,"props":8019,"children":8020},{"class":514,"line":1820},[8021],{"type":21,"tag":512,"props":8022,"children":8023},{"emptyLinePlaceholder":859},[8024],{"type":27,"value":862},{"type":21,"tag":512,"props":8026,"children":8027},{"class":514,"line":1828},[8028,8032],{"type":21,"tag":512,"props":8029,"children":8030},{"style":519},[8031],{"type":27,"value":2973},{"type":21,"tag":512,"props":8033,"children":8034},{"style":815},[8035],{"type":27,"value":952},{"type":21,"tag":512,"props":8037,"children":8038},{"class":514,"line":1870},[8039],{"type":21,"tag":512,"props":8040,"children":8041},{"style":815},[8042],{"type":27,"value":2557},{"type":21,"tag":512,"props":8044,"children":8045},{"class":514,"line":1879},[8046],{"type":21,"tag":512,"props":8047,"children":8048},{"emptyLinePlaceholder":859},[8049],{"type":27,"value":862},{"type":21,"tag":512,"props":8051,"children":8052},{"class":514,"line":1915},[8053,8057,8061,8065,8070,8074,8078,8082,8086,8090,8094],{"type":21,"tag":512,"props":8054,"children":8055},{"style":815},[8056],{"type":27,"value":7068},{"type":21,"tag":512,"props":8058,"children":8059},{"style":519},[8060],{"type":27,"value":4224},{"type":21,"tag":512,"props":8062,"children":8063},{"style":815},[8064],{"type":27,"value":843},{"type":21,"tag":512,"props":8066,"children":8067},{"style":525},[8068],{"type":27,"value":8069},"'校验phone'",{"type":21,"tag":512,"props":8071,"children":8072},{"style":815},[8073],{"type":27,"value":2018},{"type":21,"tag":512,"props":8075,"children":8076},{"style":1850},[8077],{"type":27,"value":2867},{"type":21,"tag":512,"props":8079,"children":8080},{"style":815},[8081],{"type":27,"value":1965},{"type":21,"tag":512,"props":8083,"children":8084},{"style":1850},[8085],{"type":27,"value":2876},{"type":21,"tag":512,"props":8087,"children":8088},{"style":815},[8089],{"type":27,"value":1858},{"type":21,"tag":512,"props":8091,"children":8092},{"style":809},[8093],{"type":27,"value":1863},{"type":21,"tag":512,"props":8095,"children":8096},{"style":815},[8097],{"type":27,"value":1067},{"type":21,"tag":512,"props":8099,"children":8100},{"class":514,"line":1941},[8101,8105,8109,8114,8118,8122,8126,8130],{"type":21,"tag":512,"props":8102,"children":8103},{"style":809},[8104],{"type":27,"value":7904},{"type":21,"tag":512,"props":8106,"children":8107},{"style":815},[8108],{"type":27,"value":818},{"type":21,"tag":512,"props":8110,"children":8111},{"style":686},[8112],{"type":27,"value":8113},"phone",{"type":21,"tag":512,"props":8115,"children":8116},{"style":809},[8117],{"type":27,"value":887},{"type":21,"tag":512,"props":8119,"children":8120},{"style":525},[8121],{"type":27,"value":7922},{"type":21,"tag":512,"props":8123,"children":8124},{"style":815},[8125],{"type":27,"value":828},{"type":21,"tag":512,"props":8127,"children":8128},{"style":809},[8129],{"type":27,"value":833},{"type":21,"tag":512,"props":8131,"children":8132},{"style":815},[8133],{"type":27,"value":6384},{"type":21,"tag":512,"props":8135,"children":8136},{"class":514,"line":1985},[8137,8141,8146,8150,8154],{"type":21,"tag":512,"props":8138,"children":8139},{"style":809},[8140],{"type":27,"value":2896},{"type":21,"tag":512,"props":8142,"children":8143},{"style":815},[8144],{"type":27,"value":8145}," (phone ",{"type":21,"tag":512,"props":8147,"children":8148},{"style":809},[8149],{"type":27,"value":2906},{"type":21,"tag":512,"props":8151,"children":8152},{"style":525},[8153],{"type":27,"value":7922},{"type":21,"tag":512,"props":8155,"children":8156},{"style":815},[8157],{"type":27,"value":2916},{"type":21,"tag":512,"props":8159,"children":8160},{"class":514,"line":1994},[8161,8165,8169,8174],{"type":21,"tag":512,"props":8162,"children":8163},{"style":815},[8164],{"type":27,"value":7966},{"type":21,"tag":512,"props":8166,"children":8167},{"style":809},[8168],{"type":27,"value":833},{"type":21,"tag":512,"props":8170,"children":8171},{"style":525},[8172],{"type":27,"value":8173}," '请填写手机号'",{"type":21,"tag":512,"props":8175,"children":8176},{"style":815},[8177],{"type":27,"value":897},{"type":21,"tag":512,"props":8179,"children":8180},{"class":514,"line":2046},[8181,8185,8189,8193],{"type":21,"tag":512,"props":8182,"children":8183},{"style":815},[8184],{"type":27,"value":7987},{"type":21,"tag":512,"props":8186,"children":8187},{"style":809},[8188],{"type":27,"value":833},{"type":21,"tag":512,"props":8190,"children":8191},{"style":686},[8192],{"type":27,"value":3561},{"type":21,"tag":512,"props":8194,"children":8195},{"style":815},[8196],{"type":27,"value":897},{"type":21,"tag":512,"props":8198,"children":8199},{"class":514,"line":2072},[8200,8204],{"type":21,"tag":512,"props":8201,"children":8202},{"style":809},[8203],{"type":27,"value":2945},{"type":21,"tag":512,"props":8205,"children":8206},{"style":815},[8207],{"type":27,"value":897},{"type":21,"tag":512,"props":8209,"children":8210},{"class":514,"line":2090},[8211],{"type":21,"tag":512,"props":8212,"children":8213},{"style":815},[8214],{"type":27,"value":2957},{"type":21,"tag":512,"props":8216,"children":8217},{"class":514,"line":2099},[8218],{"type":21,"tag":512,"props":8219,"children":8220},{"emptyLinePlaceholder":859},[8221],{"type":27,"value":862},{"type":21,"tag":512,"props":8223,"children":8224},{"class":514,"line":2141},[8225,8229],{"type":21,"tag":512,"props":8226,"children":8227},{"style":519},[8228],{"type":27,"value":2973},{"type":21,"tag":512,"props":8230,"children":8231},{"style":815},[8232],{"type":27,"value":952},{"type":21,"tag":512,"props":8234,"children":8235},{"class":514,"line":2168},[8236],{"type":21,"tag":512,"props":8237,"children":8238},{"style":815},[8239],{"type":27,"value":2557},{"type":21,"tag":512,"props":8241,"children":8242},{"class":514,"line":2176},[8243],{"type":21,"tag":512,"props":8244,"children":8245},{"emptyLinePlaceholder":859},[8246],{"type":27,"value":862},{"type":21,"tag":512,"props":8248,"children":8249},{"class":514,"line":2217},[8250],{"type":21,"tag":512,"props":8251,"children":8252},{"style":646},[8253],{"type":27,"value":7532},{"type":21,"tag":512,"props":8255,"children":8256},{"class":514,"line":2248},[8257,8261,8265],{"type":21,"tag":512,"props":8258,"children":8259},{"style":815},[8260],{"type":27,"value":7068},{"type":21,"tag":512,"props":8262,"children":8263},{"style":519},[8264],{"type":27,"value":4703},{"type":21,"tag":512,"props":8266,"children":8267},{"style":815},[8268],{"type":27,"value":952},{"type":21,"tag":512,"props":8270,"children":8271},{"class":514,"line":2257},[8272],{"type":21,"tag":512,"props":8273,"children":8274},{"emptyLinePlaceholder":859},[8275],{"type":27,"value":862},{"type":21,"tag":512,"props":8277,"children":8278},{"class":514,"line":2265},[8279],{"type":21,"tag":512,"props":8280,"children":8281},{"style":646},[8282],{"type":27,"value":8283},"// 如果需要中断，则提示\n",{"type":21,"tag":512,"props":8285,"children":8286},{"class":514,"line":2274},[8287,8291],{"type":21,"tag":512,"props":8288,"children":8289},{"style":809},[8290],{"type":27,"value":997},{"type":21,"tag":512,"props":8292,"children":8293},{"style":815},[8294],{"type":27,"value":8295}," (resChain.ctx.interrupt) {\n",{"type":21,"tag":512,"props":8297,"children":8298},{"class":514,"line":2317},[8299,8304],{"type":21,"tag":512,"props":8300,"children":8301},{"style":519},[8302],{"type":27,"value":8303},"  alert",{"type":21,"tag":512,"props":8305,"children":8306},{"style":815},[8307],{"type":27,"value":8308},"(resChain.ctx.error);\n",{"type":21,"tag":512,"props":8310,"children":8311},{"class":514,"line":2326},[8312,8316],{"type":21,"tag":512,"props":8313,"children":8314},{"style":809},[8315],{"type":27,"value":5711},{"type":21,"tag":512,"props":8317,"children":8318},{"style":815},[8319],{"type":27,"value":897},{"type":21,"tag":512,"props":8321,"children":8322},{"class":514,"line":2359},[8323],{"type":21,"tag":512,"props":8324,"children":8325},{"style":815},[8326],{"type":27,"value":1053},{"type":21,"tag":29,"props":8328,"children":8329},{},[8330],{"type":27,"value":8331},"如果是使用if来实现：",{"type":21,"tag":501,"props":8333,"children":8335},{"className":2762,"code":8334,"language":2764,"meta":8,"style":8},"const ctx = {\n  // 表单项\n  model: {\n    name: '',\n    phone: '',\n  },\n  // 错误提示\n  error: '',\n  // 是否中断\n  interrupt: false,\n}\n\nif(ctx.model.name === '') {\n  ctx.error = '请填写用户名';\n  ctx.interrupt = true;\n}\n\nif (!ctx.interrupt && ctx.model.phone === '') {\n  ctx.error = '请填写手机号';\n  ctx.interrupt = true;\n}\n\n// 如果需要中断，则提示\nif (resChain.ctx.interrupt) {\n  alert(resChain.ctx.error);\n  return;\n}\n",[8336],{"type":21,"tag":508,"props":8337,"children":8338},{"__ignoreMap":8},[8339,8358,8365,8372,8387,8402,8409,8416,8431,8438,8453,8460,8467,8491,8512,8532,8539,8546,8588,8607,8626,8633,8640,8647,8658,8669,8680],{"type":21,"tag":512,"props":8340,"children":8341},{"class":514,"line":515},[8342,8346,8350,8354],{"type":21,"tag":512,"props":8343,"children":8344},{"style":809},[8345],{"type":27,"value":812},{"type":21,"tag":512,"props":8347,"children":8348},{"style":686},[8349],{"type":27,"value":7693},{"type":21,"tag":512,"props":8351,"children":8352},{"style":809},[8353],{"type":27,"value":887},{"type":21,"tag":512,"props":8355,"children":8356},{"style":815},[8357],{"type":27,"value":1067},{"type":21,"tag":512,"props":8359,"children":8360},{"class":514,"line":359},[8361],{"type":21,"tag":512,"props":8362,"children":8363},{"style":646},[8364],{"type":27,"value":7709},{"type":21,"tag":512,"props":8366,"children":8367},{"class":514,"line":365},[8368],{"type":21,"tag":512,"props":8369,"children":8370},{"style":815},[8371],{"type":27,"value":7717},{"type":21,"tag":512,"props":8373,"children":8374},{"class":514,"line":673},[8375,8379,8383],{"type":21,"tag":512,"props":8376,"children":8377},{"style":815},[8378],{"type":27,"value":7725},{"type":21,"tag":512,"props":8380,"children":8381},{"style":525},[8382],{"type":27,"value":7730},{"type":21,"tag":512,"props":8384,"children":8385},{"style":815},[8386],{"type":27,"value":2440},{"type":21,"tag":512,"props":8388,"children":8389},{"class":514,"line":900},[8390,8394,8398],{"type":21,"tag":512,"props":8391,"children":8392},{"style":815},[8393],{"type":27,"value":7742},{"type":21,"tag":512,"props":8395,"children":8396},{"style":525},[8397],{"type":27,"value":7730},{"type":21,"tag":512,"props":8399,"children":8400},{"style":815},[8401],{"type":27,"value":2440},{"type":21,"tag":512,"props":8403,"children":8404},{"class":514,"line":908},[8405],{"type":21,"tag":512,"props":8406,"children":8407},{"style":815},[8408],{"type":27,"value":7758},{"type":21,"tag":512,"props":8410,"children":8411},{"class":514,"line":955},[8412],{"type":21,"tag":512,"props":8413,"children":8414},{"style":646},[8415],{"type":27,"value":7766},{"type":21,"tag":512,"props":8417,"children":8418},{"class":514,"line":983},[8419,8423,8427],{"type":21,"tag":512,"props":8420,"children":8421},{"style":815},[8422],{"type":27,"value":7774},{"type":21,"tag":512,"props":8424,"children":8425},{"style":525},[8426],{"type":27,"value":7730},{"type":21,"tag":512,"props":8428,"children":8429},{"style":815},[8430],{"type":27,"value":2440},{"type":21,"tag":512,"props":8432,"children":8433},{"class":514,"line":991},[8434],{"type":21,"tag":512,"props":8435,"children":8436},{"style":646},[8437],{"type":27,"value":7790},{"type":21,"tag":512,"props":8439,"children":8440},{"class":514,"line":1015},[8441,8445,8449],{"type":21,"tag":512,"props":8442,"children":8443},{"style":815},[8444],{"type":27,"value":7798},{"type":21,"tag":512,"props":8446,"children":8447},{"style":686},[8448],{"type":27,"value":4800},{"type":21,"tag":512,"props":8450,"children":8451},{"style":815},[8452],{"type":27,"value":2440},{"type":21,"tag":512,"props":8454,"children":8455},{"class":514,"line":1047},[8456],{"type":21,"tag":512,"props":8457,"children":8458},{"style":815},[8459],{"type":27,"value":1053},{"type":21,"tag":512,"props":8461,"children":8462},{"class":514,"line":1056},[8463],{"type":21,"tag":512,"props":8464,"children":8465},{"emptyLinePlaceholder":859},[8466],{"type":27,"value":862},{"type":21,"tag":512,"props":8468,"children":8469},{"class":514,"line":1070},[8470,8474,8479,8483,8487],{"type":21,"tag":512,"props":8471,"children":8472},{"style":809},[8473],{"type":27,"value":997},{"type":21,"tag":512,"props":8475,"children":8476},{"style":815},[8477],{"type":27,"value":8478},"(ctx.model.name ",{"type":21,"tag":512,"props":8480,"children":8481},{"style":809},[8482],{"type":27,"value":2906},{"type":21,"tag":512,"props":8484,"children":8485},{"style":525},[8486],{"type":27,"value":7922},{"type":21,"tag":512,"props":8488,"children":8489},{"style":815},[8490],{"type":27,"value":2916},{"type":21,"tag":512,"props":8492,"children":8493},{"class":514,"line":1079},[8494,8499,8503,8508],{"type":21,"tag":512,"props":8495,"children":8496},{"style":815},[8497],{"type":27,"value":8498},"  ctx.error ",{"type":21,"tag":512,"props":8500,"children":8501},{"style":809},[8502],{"type":27,"value":833},{"type":21,"tag":512,"props":8504,"children":8505},{"style":525},[8506],{"type":27,"value":8507}," '请填写用户名'",{"type":21,"tag":512,"props":8509,"children":8510},{"style":815},[8511],{"type":27,"value":897},{"type":21,"tag":512,"props":8513,"children":8514},{"class":514,"line":1317},[8515,8520,8524,8528],{"type":21,"tag":512,"props":8516,"children":8517},{"style":815},[8518],{"type":27,"value":8519},"  ctx.interrupt ",{"type":21,"tag":512,"props":8521,"children":8522},{"style":809},[8523],{"type":27,"value":833},{"type":21,"tag":512,"props":8525,"children":8526},{"style":686},[8527],{"type":27,"value":3561},{"type":21,"tag":512,"props":8529,"children":8530},{"style":815},[8531],{"type":27,"value":897},{"type":21,"tag":512,"props":8533,"children":8534},{"class":514,"line":1326},[8535],{"type":21,"tag":512,"props":8536,"children":8537},{"style":815},[8538],{"type":27,"value":1053},{"type":21,"tag":512,"props":8540,"children":8541},{"class":514,"line":1678},[8542],{"type":21,"tag":512,"props":8543,"children":8544},{"emptyLinePlaceholder":859},[8545],{"type":27,"value":862},{"type":21,"tag":512,"props":8547,"children":8548},{"class":514,"line":1704},[8549,8553,8557,8561,8566,8571,8576,8580,8584],{"type":21,"tag":512,"props":8550,"children":8551},{"style":809},[8552],{"type":27,"value":997},{"type":21,"tag":512,"props":8554,"children":8555},{"style":815},[8556],{"type":27,"value":1002},{"type":21,"tag":512,"props":8558,"children":8559},{"style":809},[8560],{"type":27,"value":1007},{"type":21,"tag":512,"props":8562,"children":8563},{"style":815},[8564],{"type":27,"value":8565},"ctx.interrupt ",{"type":21,"tag":512,"props":8567,"children":8568},{"style":809},[8569],{"type":27,"value":8570},"&&",{"type":21,"tag":512,"props":8572,"children":8573},{"style":815},[8574],{"type":27,"value":8575}," ctx.model.phone ",{"type":21,"tag":512,"props":8577,"children":8578},{"style":809},[8579],{"type":27,"value":2906},{"type":21,"tag":512,"props":8581,"children":8582},{"style":525},[8583],{"type":27,"value":7922},{"type":21,"tag":512,"props":8585,"children":8586},{"style":815},[8587],{"type":27,"value":2916},{"type":21,"tag":512,"props":8589,"children":8590},{"class":514,"line":1730},[8591,8595,8599,8603],{"type":21,"tag":512,"props":8592,"children":8593},{"style":815},[8594],{"type":27,"value":8498},{"type":21,"tag":512,"props":8596,"children":8597},{"style":809},[8598],{"type":27,"value":833},{"type":21,"tag":512,"props":8600,"children":8601},{"style":525},[8602],{"type":27,"value":8173},{"type":21,"tag":512,"props":8604,"children":8605},{"style":815},[8606],{"type":27,"value":897},{"type":21,"tag":512,"props":8608,"children":8609},{"class":514,"line":1756},[8610,8614,8618,8622],{"type":21,"tag":512,"props":8611,"children":8612},{"style":815},[8613],{"type":27,"value":8519},{"type":21,"tag":512,"props":8615,"children":8616},{"style":809},[8617],{"type":27,"value":833},{"type":21,"tag":512,"props":8619,"children":8620},{"style":686},[8621],{"type":27,"value":3561},{"type":21,"tag":512,"props":8623,"children":8624},{"style":815},[8625],{"type":27,"value":897},{"type":21,"tag":512,"props":8627,"children":8628},{"class":514,"line":1820},[8629],{"type":21,"tag":512,"props":8630,"children":8631},{"style":815},[8632],{"type":27,"value":1053},{"type":21,"tag":512,"props":8634,"children":8635},{"class":514,"line":1828},[8636],{"type":21,"tag":512,"props":8637,"children":8638},{"emptyLinePlaceholder":859},[8639],{"type":27,"value":862},{"type":21,"tag":512,"props":8641,"children":8642},{"class":514,"line":1870},[8643],{"type":21,"tag":512,"props":8644,"children":8645},{"style":646},[8646],{"type":27,"value":8283},{"type":21,"tag":512,"props":8648,"children":8649},{"class":514,"line":1879},[8650,8654],{"type":21,"tag":512,"props":8651,"children":8652},{"style":809},[8653],{"type":27,"value":997},{"type":21,"tag":512,"props":8655,"children":8656},{"style":815},[8657],{"type":27,"value":8295},{"type":21,"tag":512,"props":8659,"children":8660},{"class":514,"line":1915},[8661,8665],{"type":21,"tag":512,"props":8662,"children":8663},{"style":519},[8664],{"type":27,"value":8303},{"type":21,"tag":512,"props":8666,"children":8667},{"style":815},[8668],{"type":27,"value":8308},{"type":21,"tag":512,"props":8670,"children":8671},{"class":514,"line":1941},[8672,8676],{"type":21,"tag":512,"props":8673,"children":8674},{"style":809},[8675],{"type":27,"value":5711},{"type":21,"tag":512,"props":8677,"children":8678},{"style":815},[8679],{"type":27,"value":897},{"type":21,"tag":512,"props":8681,"children":8682},{"class":514,"line":1985},[8683],{"type":21,"tag":512,"props":8684,"children":8685},{"style":815},[8686],{"type":27,"value":1053},{"type":21,"tag":29,"props":8688,"children":8689},{},[8690,8692,8697,8699,8705,8707,8712],{"type":27,"value":8691},"可以发现，对",{"type":21,"tag":508,"props":8693,"children":8695},{"className":8694},[],[8696],{"type":27,"value":8113},{"type":27,"value":8698},"的判断逻辑，就要先判断",{"type":21,"tag":508,"props":8700,"children":8702},{"className":8701},[],[8703],{"type":27,"value":8704},"interrupt",{"type":27,"value":8706},"是否为",{"type":21,"tag":508,"props":8708,"children":8710},{"className":8709},[],[8711],{"type":27,"value":4800},{"type":27,"value":8713},"才能继续，而且如果下面还有其他的字段校验，那必须都走一遍if。",{"type":21,"tag":29,"props":8715,"children":8716},{},[8717],{"type":27,"value":8718},"这也是责任链的一个优势，可以在某个环节按自己的想法停止，不用继续走后面的节点。",{"type":21,"tag":29,"props":8720,"children":8721},{},[8722,8724,8731],{"type":27,"value":8723},"目前我已经把这个工具上传到npm了，如果想要在自己的项目中使用，直接安装",{"type":21,"tag":445,"props":8725,"children":8728},{"href":8726,"rel":8727},"https://github.com/johnhom1024/res-chain",[449],[8729],{"type":27,"value":8730},"res-chain",{"type":27,"value":8732},"：",{"type":21,"tag":501,"props":8734,"children":8736},{"className":503,"code":8735,"language":505,"meta":8,"style":8},"npm install res-chain\n\n# 或者\n# yarn add res-chain\n",[8737],{"type":21,"tag":508,"props":8738,"children":8739},{"__ignoreMap":8},[8740,8758,8765,8773],{"type":21,"tag":512,"props":8741,"children":8742},{"class":514,"line":515},[8743,8748,8753],{"type":21,"tag":512,"props":8744,"children":8745},{"style":519},[8746],{"type":27,"value":8747},"npm",{"type":21,"tag":512,"props":8749,"children":8750},{"style":525},[8751],{"type":27,"value":8752}," install",{"type":21,"tag":512,"props":8754,"children":8755},{"style":525},[8756],{"type":27,"value":8757}," res-chain\n",{"type":21,"tag":512,"props":8759,"children":8760},{"class":514,"line":359},[8761],{"type":21,"tag":512,"props":8762,"children":8763},{"emptyLinePlaceholder":859},[8764],{"type":27,"value":862},{"type":21,"tag":512,"props":8766,"children":8767},{"class":514,"line":365},[8768],{"type":21,"tag":512,"props":8769,"children":8770},{"style":646},[8771],{"type":27,"value":8772},"# 或者\n",{"type":21,"tag":512,"props":8774,"children":8775},{"class":514,"line":673},[8776],{"type":21,"tag":512,"props":8777,"children":8778},{"style":646},[8779],{"type":27,"value":8780},"# yarn add res-chain\n",{"type":21,"tag":29,"props":8782,"children":8783},{},[8784],{"type":27,"value":8785},"引入：",{"type":21,"tag":501,"props":8787,"children":8789},{"className":2762,"code":8788,"language":2764,"meta":8,"style":8},"import { ResChain } from 'res-chain';\n// CommonJS方式的引入也是支持的\n// const { ResChain } = 'res-chain';\n\nconst resChain = new ResChain();\n\nresChain.add('key1', (_, next) => {\n  console.log('key1');\n  next();\n});\n\nresChain.add('key2', (_, next) => {\n  console.log('key2');\n  // 这里没有调用next，则不会执行key3\n});\n\nresChain.add('key3', (_, next) => {\n  console.log('key3');\n  next();\n});\n\n// 执行职责链\nresChain.run(); // => 将会按顺序输出 key1 key2\n",[8790],{"type":21,"tag":508,"props":8791,"children":8792},{"__ignoreMap":8},[8793,8820,8828,8836,8843,8870,8877,8925,8948,8959,8966,8973,9021,9044,9052,9059,9066,9113,9136,9147,9154,9161,9169],{"type":21,"tag":512,"props":8794,"children":8795},{"class":514,"line":515},[8796,8801,8806,8811,8816],{"type":21,"tag":512,"props":8797,"children":8798},{"style":809},[8799],{"type":27,"value":8800},"import",{"type":21,"tag":512,"props":8802,"children":8803},{"style":815},[8804],{"type":27,"value":8805}," { ResChain } ",{"type":21,"tag":512,"props":8807,"children":8808},{"style":809},[8809],{"type":27,"value":8810},"from",{"type":21,"tag":512,"props":8812,"children":8813},{"style":525},[8814],{"type":27,"value":8815}," 'res-chain'",{"type":21,"tag":512,"props":8817,"children":8818},{"style":815},[8819],{"type":27,"value":897},{"type":21,"tag":512,"props":8821,"children":8822},{"class":514,"line":359},[8823],{"type":21,"tag":512,"props":8824,"children":8825},{"style":646},[8826],{"type":27,"value":8827},"// CommonJS方式的引入也是支持的\n",{"type":21,"tag":512,"props":8829,"children":8830},{"class":514,"line":365},[8831],{"type":21,"tag":512,"props":8832,"children":8833},{"style":646},[8834],{"type":27,"value":8835},"// const { ResChain } = 'res-chain';\n",{"type":21,"tag":512,"props":8837,"children":8838},{"class":514,"line":673},[8839],{"type":21,"tag":512,"props":8840,"children":8841},{"emptyLinePlaceholder":859},[8842],{"type":27,"value":862},{"type":21,"tag":512,"props":8844,"children":8845},{"class":514,"line":900},[8846,8850,8854,8858,8862,8866],{"type":21,"tag":512,"props":8847,"children":8848},{"style":809},[8849],{"type":27,"value":812},{"type":21,"tag":512,"props":8851,"children":8852},{"style":686},[8853],{"type":27,"value":4185},{"type":21,"tag":512,"props":8855,"children":8856},{"style":809},[8857],{"type":27,"value":887},{"type":21,"tag":512,"props":8859,"children":8860},{"style":809},[8861],{"type":27,"value":1026},{"type":21,"tag":512,"props":8863,"children":8864},{"style":519},[8865],{"type":27,"value":4198},{"type":21,"tag":512,"props":8867,"children":8868},{"style":815},[8869],{"type":27,"value":952},{"type":21,"tag":512,"props":8871,"children":8872},{"class":514,"line":908},[8873],{"type":21,"tag":512,"props":8874,"children":8875},{"emptyLinePlaceholder":859},[8876],{"type":27,"value":862},{"type":21,"tag":512,"props":8878,"children":8879},{"class":514,"line":955},[8880,8884,8888,8892,8897,8901,8905,8909,8913,8917,8921],{"type":21,"tag":512,"props":8881,"children":8882},{"style":815},[8883],{"type":27,"value":7068},{"type":21,"tag":512,"props":8885,"children":8886},{"style":519},[8887],{"type":27,"value":4224},{"type":21,"tag":512,"props":8889,"children":8890},{"style":815},[8891],{"type":27,"value":843},{"type":21,"tag":512,"props":8893,"children":8894},{"style":525},[8895],{"type":27,"value":8896},"'key1'",{"type":21,"tag":512,"props":8898,"children":8899},{"style":815},[8900],{"type":27,"value":2018},{"type":21,"tag":512,"props":8902,"children":8903},{"style":1850},[8904],{"type":27,"value":4242},{"type":21,"tag":512,"props":8906,"children":8907},{"style":815},[8908],{"type":27,"value":1965},{"type":21,"tag":512,"props":8910,"children":8911},{"style":1850},[8912],{"type":27,"value":2876},{"type":21,"tag":512,"props":8914,"children":8915},{"style":815},[8916],{"type":27,"value":1858},{"type":21,"tag":512,"props":8918,"children":8919},{"style":809},[8920],{"type":27,"value":1863},{"type":21,"tag":512,"props":8922,"children":8923},{"style":815},[8924],{"type":27,"value":1067},{"type":21,"tag":512,"props":8926,"children":8927},{"class":514,"line":983},[8928,8932,8936,8940,8944],{"type":21,"tag":512,"props":8929,"children":8930},{"style":815},[8931],{"type":27,"value":7125},{"type":21,"tag":512,"props":8933,"children":8934},{"style":519},[8935],{"type":27,"value":966},{"type":21,"tag":512,"props":8937,"children":8938},{"style":815},[8939],{"type":27,"value":843},{"type":21,"tag":512,"props":8941,"children":8942},{"style":525},[8943],{"type":27,"value":8896},{"type":21,"tag":512,"props":8945,"children":8946},{"style":815},[8947],{"type":27,"value":853},{"type":21,"tag":512,"props":8949,"children":8950},{"class":514,"line":991},[8951,8955],{"type":21,"tag":512,"props":8952,"children":8953},{"style":519},[8954],{"type":27,"value":2973},{"type":21,"tag":512,"props":8956,"children":8957},{"style":815},[8958],{"type":27,"value":952},{"type":21,"tag":512,"props":8960,"children":8961},{"class":514,"line":1015},[8962],{"type":21,"tag":512,"props":8963,"children":8964},{"style":815},[8965],{"type":27,"value":2991},{"type":21,"tag":512,"props":8967,"children":8968},{"class":514,"line":1047},[8969],{"type":21,"tag":512,"props":8970,"children":8971},{"emptyLinePlaceholder":859},[8972],{"type":27,"value":862},{"type":21,"tag":512,"props":8974,"children":8975},{"class":514,"line":1056},[8976,8980,8984,8988,8993,8997,9001,9005,9009,9013,9017],{"type":21,"tag":512,"props":8977,"children":8978},{"style":815},[8979],{"type":27,"value":7068},{"type":21,"tag":512,"props":8981,"children":8982},{"style":519},[8983],{"type":27,"value":4224},{"type":21,"tag":512,"props":8985,"children":8986},{"style":815},[8987],{"type":27,"value":843},{"type":21,"tag":512,"props":8989,"children":8990},{"style":525},[8991],{"type":27,"value":8992},"'key2'",{"type":21,"tag":512,"props":8994,"children":8995},{"style":815},[8996],{"type":27,"value":2018},{"type":21,"tag":512,"props":8998,"children":8999},{"style":1850},[9000],{"type":27,"value":4242},{"type":21,"tag":512,"props":9002,"children":9003},{"style":815},[9004],{"type":27,"value":1965},{"type":21,"tag":512,"props":9006,"children":9007},{"style":1850},[9008],{"type":27,"value":2876},{"type":21,"tag":512,"props":9010,"children":9011},{"style":815},[9012],{"type":27,"value":1858},{"type":21,"tag":512,"props":9014,"children":9015},{"style":809},[9016],{"type":27,"value":1863},{"type":21,"tag":512,"props":9018,"children":9019},{"style":815},[9020],{"type":27,"value":1067},{"type":21,"tag":512,"props":9022,"children":9023},{"class":514,"line":1070},[9024,9028,9032,9036,9040],{"type":21,"tag":512,"props":9025,"children":9026},{"style":815},[9027],{"type":27,"value":7125},{"type":21,"tag":512,"props":9029,"children":9030},{"style":519},[9031],{"type":27,"value":966},{"type":21,"tag":512,"props":9033,"children":9034},{"style":815},[9035],{"type":27,"value":843},{"type":21,"tag":512,"props":9037,"children":9038},{"style":525},[9039],{"type":27,"value":8992},{"type":21,"tag":512,"props":9041,"children":9042},{"style":815},[9043],{"type":27,"value":853},{"type":21,"tag":512,"props":9045,"children":9046},{"class":514,"line":1079},[9047],{"type":21,"tag":512,"props":9048,"children":9049},{"style":646},[9050],{"type":27,"value":9051},"  // 这里没有调用next，则不会执行key3\n",{"type":21,"tag":512,"props":9053,"children":9054},{"class":514,"line":1317},[9055],{"type":21,"tag":512,"props":9056,"children":9057},{"style":815},[9058],{"type":27,"value":2991},{"type":21,"tag":512,"props":9060,"children":9061},{"class":514,"line":1326},[9062],{"type":21,"tag":512,"props":9063,"children":9064},{"emptyLinePlaceholder":859},[9065],{"type":27,"value":862},{"type":21,"tag":512,"props":9067,"children":9068},{"class":514,"line":1678},[9069,9073,9077,9081,9085,9089,9093,9097,9101,9105,9109],{"type":21,"tag":512,"props":9070,"children":9071},{"style":815},[9072],{"type":27,"value":7068},{"type":21,"tag":512,"props":9074,"children":9075},{"style":519},[9076],{"type":27,"value":4224},{"type":21,"tag":512,"props":9078,"children":9079},{"style":815},[9080],{"type":27,"value":843},{"type":21,"tag":512,"props":9082,"children":9083},{"style":525},[9084],{"type":27,"value":7429},{"type":21,"tag":512,"props":9086,"children":9087},{"style":815},[9088],{"type":27,"value":2018},{"type":21,"tag":512,"props":9090,"children":9091},{"style":1850},[9092],{"type":27,"value":4242},{"type":21,"tag":512,"props":9094,"children":9095},{"style":815},[9096],{"type":27,"value":1965},{"type":21,"tag":512,"props":9098,"children":9099},{"style":1850},[9100],{"type":27,"value":2876},{"type":21,"tag":512,"props":9102,"children":9103},{"style":815},[9104],{"type":27,"value":1858},{"type":21,"tag":512,"props":9106,"children":9107},{"style":809},[9108],{"type":27,"value":1863},{"type":21,"tag":512,"props":9110,"children":9111},{"style":815},[9112],{"type":27,"value":1067},{"type":21,"tag":512,"props":9114,"children":9115},{"class":514,"line":1704},[9116,9120,9124,9128,9132],{"type":21,"tag":512,"props":9117,"children":9118},{"style":815},[9119],{"type":27,"value":7125},{"type":21,"tag":512,"props":9121,"children":9122},{"style":519},[9123],{"type":27,"value":966},{"type":21,"tag":512,"props":9125,"children":9126},{"style":815},[9127],{"type":27,"value":843},{"type":21,"tag":512,"props":9129,"children":9130},{"style":525},[9131],{"type":27,"value":7429},{"type":21,"tag":512,"props":9133,"children":9134},{"style":815},[9135],{"type":27,"value":853},{"type":21,"tag":512,"props":9137,"children":9138},{"class":514,"line":1730},[9139,9143],{"type":21,"tag":512,"props":9140,"children":9141},{"style":519},[9142],{"type":27,"value":2973},{"type":21,"tag":512,"props":9144,"children":9145},{"style":815},[9146],{"type":27,"value":952},{"type":21,"tag":512,"props":9148,"children":9149},{"class":514,"line":1756},[9150],{"type":21,"tag":512,"props":9151,"children":9152},{"style":815},[9153],{"type":27,"value":2991},{"type":21,"tag":512,"props":9155,"children":9156},{"class":514,"line":1820},[9157],{"type":21,"tag":512,"props":9158,"children":9159},{"emptyLinePlaceholder":859},[9160],{"type":27,"value":862},{"type":21,"tag":512,"props":9162,"children":9163},{"class":514,"line":1828},[9164],{"type":21,"tag":512,"props":9165,"children":9166},{"style":646},[9167],{"type":27,"value":9168},"// 执行职责链\n",{"type":21,"tag":512,"props":9170,"children":9171},{"class":514,"line":1870},[9172,9176,9180,9184],{"type":21,"tag":512,"props":9173,"children":9174},{"style":815},[9175],{"type":27,"value":7068},{"type":21,"tag":512,"props":9177,"children":9178},{"style":519},[9179],{"type":27,"value":4703},{"type":21,"tag":512,"props":9181,"children":9182},{"style":815},[9183],{"type":27,"value":2978},{"type":21,"tag":512,"props":9185,"children":9186},{"style":646},[9187],{"type":27,"value":9188},"// => 将会按顺序输出 key1 key2\n",{"type":21,"tag":29,"props":9190,"children":9191},{},[9192],{"type":27,"value":9193},"芜湖起飞。",{"type":21,"tag":29,"props":9195,"children":9196},{},[9197],{"type":27,"value":9198},"有了这个工具函数，我们就可以视场景去优化项目中的一大坨if-else嵌套，或者直接使用它来实现一些业务中比较复杂的逻辑。",{"type":21,"tag":22,"props":9200,"children":9202},{"id":9201},"起源",[9203],{"type":27,"value":9201},{"type":21,"tag":29,"props":9205,"children":9206},{},[9207],{"type":27,"value":9208},"这个工具诞生的过程还挺巧合的，某一天周六我在公司加班赶需求，发现需要在一堆旧逻辑if-else中添加新的逻辑，强迫症的我实在是无法忍受在屎山上继续堆屎。。。",{"type":21,"tag":29,"props":9210,"children":9211},{},[9212,9214,9219,9221,9226,9228,9233],{"type":27,"value":9213},"我陷入沉思，用什么方式去优化呢？看了网上责任链模式的实现，感觉还是不够优雅。无意中翻到了之前用",{"type":21,"tag":508,"props":9215,"children":9217},{"className":9216},[],[9218],{"type":27,"value":2738},{"type":27,"value":9220},"写的项目，突然灵光咋现💡，",{"type":21,"tag":508,"props":9222,"children":9224},{"className":9223},[],[9225],{"type":27,"value":2738},{"type":27,"value":9227},"的中间件不就是一个很棒的实践。调用",{"type":21,"tag":508,"props":9229,"children":9231},{"className":9230},[],[9232],{"type":27,"value":2876},{"type":27,"value":9234},"就能够往下一个节点走，不调用的话就可以终止。",{"type":21,"tag":22,"props":9236,"children":9237},{"id":2624},[9238],{"type":27,"value":2624},{"type":21,"tag":29,"props":9240,"children":9241},{},[9242],{"type":27,"value":9243},"过去无意学到的某个知识，或者某个概念，在未来也许会发挥作用，你需要做的就是等待。",{"type":21,"tag":29,"props":9245,"children":9246},{},[9247],{"type":27,"value":9248},"如果你也喜欢这个工具，欢迎去github里给个🌟，感谢。",{"type":21,"tag":29,"props":9250,"children":9251},{},[9252],{"type":27,"value":9253},"如果有什么更好的建议，在底下留言，一起探讨。",{"type":21,"tag":22,"props":9255,"children":9257},{"id":9256},"工具链接",[9258],{"type":27,"value":9256},{"type":21,"tag":75,"props":9260,"children":9261},{},[9262],{"type":21,"tag":79,"props":9263,"children":9264},{},[9265],{"type":21,"tag":445,"props":9266,"children":9268},{"href":8726,"rel":9267},[449],[9269],{"type":27,"value":8730},{"type":21,"tag":22,"props":9271,"children":9273},{"id":9272},"参考",[9274],{"type":27,"value":9272},{"type":21,"tag":29,"props":9276,"children":9277},{},[9278],{"type":21,"tag":445,"props":9279,"children":9282},{"href":9280,"rel":9281},"https://juejin.cn/post/6844903855348514829",[449],[9283],{"type":27,"value":9280},{"type":21,"tag":2671,"props":9285,"children":9286},{},[9287],{"type":27,"value":2675},{"title":8,"searchDepth":359,"depth":359,"links":9289},[9290,9291,9292,9293,9294,9295,9296],{"id":2701,"depth":359,"text":2701},{"id":3382,"depth":359,"text":3382},{"id":5465,"depth":359,"text":5468},{"id":9201,"depth":359,"text":9201},{"id":2624,"depth":359,"text":2624},{"id":9256,"depth":359,"text":9256},{"id":9272,"depth":359,"text":9272},"content:articles:20240516.md","articles/20240516.md",{"_path":9300,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":9301,"description":8,"published":9302,"categories":9303,"tags":9304,"slug":9301,"body":9307,"_type":376,"_id":10290,"_source":378,"_file":10291,"_extension":380},"/articles/20230903","使用这个git工具，让你的工作效率大幅上升","2023/9/3 21:46:00",[242],[9305,9306,636],"git","node.js",{"type":18,"children":9308,"toc":10283},[9309,9317,9321,9326,9331,9377,9382,9387,9395,9400,9405,9410,9415,9427,9477,9490,9495,9516,9535,9540,9589,9594,9600,9605,9610,9886,9891,9904,9912,9925,9933,9938,9958,9963,10179,10184,10192,10219,10240,10244,10249,10254,10259,10279],{"type":21,"tag":29,"props":9310,"children":9311},{},[9312],{"type":21,"tag":459,"props":9313,"children":9316},{"alt":9314,"src":9315},"Sep-03-2023 18-40-17","https://johnhom-img.oss-cn-guangzhou.aliyuncs.com/images/Sep-03-2023%2018-40-17.gif",[],{"type":21,"tag":22,"props":9318,"children":9319},{"id":393},[9320],{"type":27,"value":393},{"type":21,"tag":29,"props":9322,"children":9323},{},[9324],{"type":27,"value":9325},"在公司项目使用git管理代码记录的背景下，每当我的需求进入了提测阶段，测试总能从我的代码中找出一堆bug（什么，你写的代码从来没有bug？那我先叫你声大佬）。一般我们要做的就是在需求分支中修复bug，然后切到测试分支，合并我们的功能分支，最后推送测试分支到远程触发自动构建和部署。如果过一会测试又发现了新的bug，那么就得继续重复上述的步骤。",{"type":21,"tag":29,"props":9327,"children":9328},{},[9329],{"type":27,"value":9330},"你发现了没有，每当我们修复了bug，合并到测试分支时，存在着极其重复而又繁琐的分支操作环节：",{"type":21,"tag":295,"props":9332,"children":9333},{},[9334,9345,9356,9367],{"type":21,"tag":79,"props":9335,"children":9336},{},[9337,9343],{"type":21,"tag":508,"props":9338,"children":9340},{"className":9339},[],[9341],{"type":27,"value":9342},"git checkout",{"type":27,"value":9344}," 切到测试分支。",{"type":21,"tag":79,"props":9346,"children":9347},{},[9348,9354],{"type":21,"tag":508,"props":9349,"children":9351},{"className":9350},[],[9352],{"type":27,"value":9353},"git merge",{"type":27,"value":9355}," 合并我们刚刚修复的功能分支。",{"type":21,"tag":79,"props":9357,"children":9358},{},[9359,9365],{"type":21,"tag":508,"props":9360,"children":9362},{"className":9361},[],[9363],{"type":27,"value":9364},"git push",{"type":27,"value":9366}," 推送到远程。",{"type":21,"tag":79,"props":9368,"children":9369},{},[9370,9375],{"type":21,"tag":508,"props":9371,"children":9373},{"className":9372},[],[9374],{"type":27,"value":9342},{"type":27,"value":9376}," 切回功能分支。",{"type":21,"tag":29,"props":9378,"children":9379},{},[9380],{"type":27,"value":9381},"这4个步骤贯穿着我们修复bug生涯的最后一环。而且当功能分支很长又难记时，你是不是得偷偷看看分支名，或者复制粘贴一下到命令行，简直是令人抓狂。",{"type":21,"tag":29,"props":9383,"children":9384},{},[9385],{"type":27,"value":9386},"不习惯敲命令的一些同学，会使用图形界面对分支进行操作，不过这样的话手就不得不离开键盘，用鼠标去点点点。",{"type":21,"tag":7601,"props":9388,"children":9389},{},[9390],{"type":21,"tag":29,"props":9391,"children":9392},{},[9393],{"type":27,"value":9394},"俗话说得好：浪费时间，就是浪费生命。",{"type":21,"tag":29,"props":9396,"children":9397},{},[9398],{"type":27,"value":9399},"有一天我突发奇想，如果能有一个CLI工具，帮我自动操作分支的合并，让我从这个重复又繁琐的操作中解放出来，那我岂不是能做很多其他的事情了（摸鱼）。虽然一次的自动操作可以节省几秒钟，但是千万不要小看了这几秒钟，日积月累之下难以想象它能给你带来多少收益，正所谓水滴能把石穿透。",{"type":21,"tag":29,"props":9401,"children":9402},{},[9403],{"type":27,"value":9404},"想到这里我就马不停蹄地投入到这个CLI工具的研发之中。。。",{"type":21,"tag":29,"props":9406,"children":9407},{},[9408],{"type":27,"value":9409},"下面我们介绍一下这个工具的使用，看他是如何解放你的双手的。",{"type":21,"tag":22,"props":9411,"children":9413},{"id":9412},"工具使用介绍",[9414],{"type":27,"value":9412},{"type":21,"tag":29,"props":9416,"children":9417},{},[9418,9420,9426],{"type":27,"value":9419},"全局安装",{"type":21,"tag":508,"props":9421,"children":9423},{"className":9422},[],[9424],{"type":27,"value":9425},"@johnhom/mg-cli",{"type":27,"value":8732},{"type":21,"tag":501,"props":9428,"children":9430},{"className":634,"code":9429,"language":636,"meta":8,"style":8},"npm install -g @johnhom/mg-cli\n\n# 或者\n# yarn global add @johnhom/mg-cli\n",[9431],{"type":21,"tag":508,"props":9432,"children":9433},{"__ignoreMap":8},[9434,9455,9462,9469],{"type":21,"tag":512,"props":9435,"children":9436},{"class":514,"line":515},[9437,9441,9445,9450],{"type":21,"tag":512,"props":9438,"children":9439},{"style":519},[9440],{"type":27,"value":8747},{"type":21,"tag":512,"props":9442,"children":9443},{"style":525},[9444],{"type":27,"value":8752},{"type":21,"tag":512,"props":9446,"children":9447},{"style":686},[9448],{"type":27,"value":9449}," -g",{"type":21,"tag":512,"props":9451,"children":9452},{"style":525},[9453],{"type":27,"value":9454}," @johnhom/mg-cli\n",{"type":21,"tag":512,"props":9456,"children":9457},{"class":514,"line":359},[9458],{"type":21,"tag":512,"props":9459,"children":9460},{"emptyLinePlaceholder":859},[9461],{"type":27,"value":862},{"type":21,"tag":512,"props":9463,"children":9464},{"class":514,"line":365},[9465],{"type":21,"tag":512,"props":9466,"children":9467},{"style":646},[9468],{"type":27,"value":8772},{"type":21,"tag":512,"props":9470,"children":9471},{"class":514,"line":673},[9472],{"type":21,"tag":512,"props":9473,"children":9474},{"style":646},[9475],{"type":27,"value":9476},"# yarn global add @johnhom/mg-cli\n",{"type":21,"tag":29,"props":9478,"children":9479},{},[9480,9482,9488],{"type":27,"value":9481},"全局安装完成之后，我们就可以在终端命令行里运行",{"type":21,"tag":508,"props":9483,"children":9485},{"className":9484},[],[9486],{"type":27,"value":9487},"amg",{"type":27,"value":9489},"这个命令。",{"type":21,"tag":29,"props":9491,"children":9492},{},[9493],{"type":27,"value":9494},"使用方法：",{"type":21,"tag":29,"props":9496,"children":9497},{},[9498,9500,9506,9508,9514],{"type":27,"value":9499},"假设你当前项目所在的分支为：",{"type":21,"tag":508,"props":9501,"children":9503},{"className":9502},[],[9504],{"type":27,"value":9505},"feature/a",{"type":27,"value":9507},"，你想要把这个分支合并到",{"type":21,"tag":508,"props":9509,"children":9511},{"className":9510},[],[9512],{"type":27,"value":9513},"dev",{"type":27,"value":9515},"，你只需要执行以下命令：",{"type":21,"tag":501,"props":9517,"children":9519},{"className":634,"code":9518,"language":636,"meta":8,"style":8},"amg dev\n",[9520],{"type":21,"tag":508,"props":9521,"children":9522},{"__ignoreMap":8},[9523],{"type":21,"tag":512,"props":9524,"children":9525},{"class":514,"line":515},[9526,9530],{"type":21,"tag":512,"props":9527,"children":9528},{"style":519},[9529],{"type":27,"value":9487},{"type":21,"tag":512,"props":9531,"children":9532},{"style":525},[9533],{"type":27,"value":9534}," dev\n",{"type":21,"tag":29,"props":9536,"children":9537},{},[9538],{"type":27,"value":9539},"上述命令执行后，终端会自动按进行如下操作：",{"type":21,"tag":295,"props":9541,"children":9542},{},[9543,9554,9559,9564,9574,9579,9584],{"type":21,"tag":79,"props":9544,"children":9545},{},[9546,9548],{"type":27,"value":9547},"在当前分支执行",{"type":21,"tag":508,"props":9549,"children":9551},{"className":9550},[],[9552],{"type":27,"value":9553},"git pull",{"type":21,"tag":79,"props":9555,"children":9556},{},[9557],{"type":27,"value":9558},"获取当前分支的名称",{"type":21,"tag":79,"props":9560,"children":9561},{},[9562],{"type":27,"value":9563},"切换到目标分支dev",{"type":21,"tag":79,"props":9565,"children":9566},{},[9567,9569],{"type":27,"value":9568},"执行",{"type":21,"tag":508,"props":9570,"children":9572},{"className":9571},[],[9573],{"type":27,"value":9553},{"type":21,"tag":79,"props":9575,"children":9576},{},[9577],{"type":27,"value":9578},"合并分支",{"type":21,"tag":79,"props":9580,"children":9581},{},[9582],{"type":27,"value":9583},"询问是否要推到远程",{"type":21,"tag":79,"props":9585,"children":9586},{},[9587],{"type":27,"value":9588},"询问是否要切回源分支",{"type":21,"tag":29,"props":9590,"children":9591},{},[9592],{"type":27,"value":9593},"我们来看看运行的gif图：",{"type":21,"tag":29,"props":9595,"children":9596},{},[9597],{"type":21,"tag":459,"props":9598,"children":9599},{"alt":9314,"src":9315},[],{"type":21,"tag":29,"props":9601,"children":9602},{},[9603],{"type":27,"value":9604},"nice！",{"type":21,"tag":29,"props":9606,"children":9607},{},[9608],{"type":27,"value":9609},"下面展示具体的用法：",{"type":21,"tag":501,"props":9611,"children":9613},{"className":634,"code":9612,"language":636,"meta":8,"style":8},"Usage:\n  $ amg [target_branch]\n\nCommands:\n  [target_branch]  merge current branch into target_branch\n\nFor more info, run any command with the `--help` flag:\n  $ amg --help\n\nOptions:\n  -h, --help     Display this message \n  -v, --version  Display version number \n\nExamples:\namg master    把当前分支自动合并到master\n",[9614],{"type":21,"tag":508,"props":9615,"children":9616},{"__ignoreMap":8},[9617,9625,9643,9650,9658,9691,9698,9760,9776,9783,9791,9822,9854,9861,9869],{"type":21,"tag":512,"props":9618,"children":9619},{"class":514,"line":515},[9620],{"type":21,"tag":512,"props":9621,"children":9622},{"style":519},[9623],{"type":27,"value":9624},"Usage:\n",{"type":21,"tag":512,"props":9626,"children":9627},{"class":514,"line":359},[9628,9633,9638],{"type":21,"tag":512,"props":9629,"children":9630},{"style":519},[9631],{"type":27,"value":9632},"  $",{"type":21,"tag":512,"props":9634,"children":9635},{"style":525},[9636],{"type":27,"value":9637}," amg",{"type":21,"tag":512,"props":9639,"children":9640},{"style":815},[9641],{"type":27,"value":9642}," [target_branch]\n",{"type":21,"tag":512,"props":9644,"children":9645},{"class":514,"line":365},[9646],{"type":21,"tag":512,"props":9647,"children":9648},{"emptyLinePlaceholder":859},[9649],{"type":27,"value":862},{"type":21,"tag":512,"props":9651,"children":9652},{"class":514,"line":673},[9653],{"type":21,"tag":512,"props":9654,"children":9655},{"style":519},[9656],{"type":27,"value":9657},"Commands:\n",{"type":21,"tag":512,"props":9659,"children":9660},{"class":514,"line":900},[9661,9666,9671,9676,9681,9686],{"type":21,"tag":512,"props":9662,"children":9663},{"style":815},[9664],{"type":27,"value":9665},"  [target_branch]  ",{"type":21,"tag":512,"props":9667,"children":9668},{"style":519},[9669],{"type":27,"value":9670},"merge",{"type":21,"tag":512,"props":9672,"children":9673},{"style":525},[9674],{"type":27,"value":9675}," current",{"type":21,"tag":512,"props":9677,"children":9678},{"style":525},[9679],{"type":27,"value":9680}," branch",{"type":21,"tag":512,"props":9682,"children":9683},{"style":525},[9684],{"type":27,"value":9685}," into",{"type":21,"tag":512,"props":9687,"children":9688},{"style":525},[9689],{"type":27,"value":9690}," target_branch\n",{"type":21,"tag":512,"props":9692,"children":9693},{"class":514,"line":908},[9694],{"type":21,"tag":512,"props":9695,"children":9696},{"emptyLinePlaceholder":859},[9697],{"type":27,"value":862},{"type":21,"tag":512,"props":9699,"children":9700},{"class":514,"line":955},[9701,9706,9711,9716,9720,9725,9730,9735,9740,9745,9750,9755],{"type":21,"tag":512,"props":9702,"children":9703},{"style":519},[9704],{"type":27,"value":9705},"For",{"type":21,"tag":512,"props":9707,"children":9708},{"style":525},[9709],{"type":27,"value":9710}," more",{"type":21,"tag":512,"props":9712,"children":9713},{"style":525},[9714],{"type":27,"value":9715}," info,",{"type":21,"tag":512,"props":9717,"children":9718},{"style":525},[9719],{"type":27,"value":6606},{"type":21,"tag":512,"props":9721,"children":9722},{"style":525},[9723],{"type":27,"value":9724}," any",{"type":21,"tag":512,"props":9726,"children":9727},{"style":525},[9728],{"type":27,"value":9729}," command",{"type":21,"tag":512,"props":9731,"children":9732},{"style":525},[9733],{"type":27,"value":9734}," with",{"type":21,"tag":512,"props":9736,"children":9737},{"style":525},[9738],{"type":27,"value":9739}," the",{"type":21,"tag":512,"props":9741,"children":9742},{"style":525},[9743],{"type":27,"value":9744}," `",{"type":21,"tag":512,"props":9746,"children":9747},{"style":519},[9748],{"type":27,"value":9749},"--help",{"type":21,"tag":512,"props":9751,"children":9752},{"style":525},[9753],{"type":27,"value":9754},"`",{"type":21,"tag":512,"props":9756,"children":9757},{"style":519},[9758],{"type":27,"value":9759}," flag:\n",{"type":21,"tag":512,"props":9761,"children":9762},{"class":514,"line":983},[9763,9767,9771],{"type":21,"tag":512,"props":9764,"children":9765},{"style":519},[9766],{"type":27,"value":9632},{"type":21,"tag":512,"props":9768,"children":9769},{"style":525},[9770],{"type":27,"value":9637},{"type":21,"tag":512,"props":9772,"children":9773},{"style":686},[9774],{"type":27,"value":9775}," --help\n",{"type":21,"tag":512,"props":9777,"children":9778},{"class":514,"line":991},[9779],{"type":21,"tag":512,"props":9780,"children":9781},{"emptyLinePlaceholder":859},[9782],{"type":27,"value":862},{"type":21,"tag":512,"props":9784,"children":9785},{"class":514,"line":1015},[9786],{"type":21,"tag":512,"props":9787,"children":9788},{"style":519},[9789],{"type":27,"value":9790},"Options:\n",{"type":21,"tag":512,"props":9792,"children":9793},{"class":514,"line":1047},[9794,9799,9804,9809,9813,9818],{"type":21,"tag":512,"props":9795,"children":9796},{"style":519},[9797],{"type":27,"value":9798},"  -h,",{"type":21,"tag":512,"props":9800,"children":9801},{"style":686},[9802],{"type":27,"value":9803}," --help",{"type":21,"tag":512,"props":9805,"children":9806},{"style":525},[9807],{"type":27,"value":9808},"     Display",{"type":21,"tag":512,"props":9810,"children":9811},{"style":525},[9812],{"type":27,"value":6575},{"type":21,"tag":512,"props":9814,"children":9815},{"style":525},[9816],{"type":27,"value":9817}," message",{"type":21,"tag":512,"props":9819,"children":9820},{"style":815},[9821],{"type":27,"value":4990},{"type":21,"tag":512,"props":9823,"children":9824},{"class":514,"line":1056},[9825,9830,9835,9840,9845,9850],{"type":21,"tag":512,"props":9826,"children":9827},{"style":519},[9828],{"type":27,"value":9829},"  -v,",{"type":21,"tag":512,"props":9831,"children":9832},{"style":686},[9833],{"type":27,"value":9834}," --version",{"type":21,"tag":512,"props":9836,"children":9837},{"style":525},[9838],{"type":27,"value":9839},"  Display",{"type":21,"tag":512,"props":9841,"children":9842},{"style":525},[9843],{"type":27,"value":9844}," version",{"type":21,"tag":512,"props":9846,"children":9847},{"style":525},[9848],{"type":27,"value":9849}," number",{"type":21,"tag":512,"props":9851,"children":9852},{"style":815},[9853],{"type":27,"value":4990},{"type":21,"tag":512,"props":9855,"children":9856},{"class":514,"line":1070},[9857],{"type":21,"tag":512,"props":9858,"children":9859},{"emptyLinePlaceholder":859},[9860],{"type":27,"value":862},{"type":21,"tag":512,"props":9862,"children":9863},{"class":514,"line":1079},[9864],{"type":21,"tag":512,"props":9865,"children":9866},{"style":519},[9867],{"type":27,"value":9868},"Examples:\n",{"type":21,"tag":512,"props":9870,"children":9871},{"class":514,"line":1317},[9872,9876,9881],{"type":21,"tag":512,"props":9873,"children":9874},{"style":519},[9875],{"type":27,"value":9487},{"type":21,"tag":512,"props":9877,"children":9878},{"style":525},[9879],{"type":27,"value":9880}," master",{"type":21,"tag":512,"props":9882,"children":9883},{"style":525},[9884],{"type":27,"value":9885},"    把当前分支自动合并到master\n",{"type":21,"tag":29,"props":9887,"children":9888},{},[9889],{"type":27,"value":9890},"假设你当前项目所在的分支为：feature/a，你想要把这个分支合并到dev，并自动上传到远程仓库，你只需要执行以下命令：",{"type":21,"tag":501,"props":9892,"children":9893},{"className":2762,"code":9518,"language":2764,"meta":8,"style":8},[9894],{"type":21,"tag":508,"props":9895,"children":9896},{"__ignoreMap":8},[9897],{"type":21,"tag":512,"props":9898,"children":9899},{"class":514,"line":515},[9900],{"type":21,"tag":512,"props":9901,"children":9902},{"style":815},[9903],{"type":27,"value":9518},{"type":21,"tag":29,"props":9905,"children":9906},{},[9907],{"type":21,"tag":83,"props":9908,"children":9909},{},[9910],{"type":27,"value":9911},"自动合并过程中如果遇到了冲突",{"type":21,"tag":29,"props":9913,"children":9914},{},[9915,9917,9923],{"type":27,"value":9916},"假设在合并分支的过程中遇到了冲突，",{"type":21,"tag":508,"props":9918,"children":9920},{"className":9919},[],[9921],{"type":27,"value":9922},"mg-cli",{"type":27,"value":9924},"会识别到冲突，并且中断后续的操作，最后提示你需要处理，如下图所示：",{"type":21,"tag":29,"props":9926,"children":9927},{},[9928],{"type":21,"tag":459,"props":9929,"children":9932},{"alt":9930,"src":9931},"Pasted image 20230903213552","https://johnhom-img.oss-cn-guangzhou.aliyuncs.com/images/Pasted%20image%2020230903213552.png",[],{"type":21,"tag":22,"props":9934,"children":9936},{"id":9935},"实现原理",[9937],{"type":27,"value":9935},{"type":21,"tag":29,"props":9939,"children":9940},{},[9941,9943,9949,9951,9956],{"type":27,"value":9942},"原理其实也特别的简单，其实就是使用Node.js自带的",{"type":21,"tag":508,"props":9944,"children":9946},{"className":9945},[],[9947],{"type":27,"value":9948},"child_process",{"type":27,"value":9950},"模块创建子进程来执行一些",{"type":21,"tag":508,"props":9952,"children":9954},{"className":9953},[],[9955],{"type":27,"value":636},{"type":27,"value":9957},"的命令。",{"type":21,"tag":29,"props":9959,"children":9960},{},[9961],{"type":27,"value":9962},"下面我们看一个简单的使用例子：",{"type":21,"tag":501,"props":9964,"children":9966},{"className":2762,"code":9965,"language":2764,"meta":8,"style":8},"const childProcess = require('child_process');\n\n// 在子进程中执行git branch\nchildProcess.exec('git branch', (error, stdout, stderr) => {\n  if (error) {\n    console.error(error);\n    return;\n  }\n\n  // 输出子进程运行之后的输出内容\n  console.log('----------johnhomLogDebug stdout\\n', stdout);\n});\n",[9967],{"type":21,"tag":508,"props":9968,"children":9969},{"__ignoreMap":8},[9970,10002,10009,10017,10078,10090,10106,10117,10124,10131,10139,10172],{"type":21,"tag":512,"props":9971,"children":9972},{"class":514,"line":515},[9973,9977,9982,9986,9990,9994,9998],{"type":21,"tag":512,"props":9974,"children":9975},{"style":809},[9976],{"type":27,"value":812},{"type":21,"tag":512,"props":9978,"children":9979},{"style":686},[9980],{"type":27,"value":9981}," childProcess",{"type":21,"tag":512,"props":9983,"children":9984},{"style":809},[9985],{"type":27,"value":887},{"type":21,"tag":512,"props":9987,"children":9988},{"style":519},[9989],{"type":27,"value":838},{"type":21,"tag":512,"props":9991,"children":9992},{"style":815},[9993],{"type":27,"value":843},{"type":21,"tag":512,"props":9995,"children":9996},{"style":525},[9997],{"type":27,"value":848},{"type":21,"tag":512,"props":9999,"children":10000},{"style":815},[10001],{"type":27,"value":853},{"type":21,"tag":512,"props":10003,"children":10004},{"class":514,"line":359},[10005],{"type":21,"tag":512,"props":10006,"children":10007},{"emptyLinePlaceholder":859},[10008],{"type":27,"value":862},{"type":21,"tag":512,"props":10010,"children":10011},{"class":514,"line":365},[10012],{"type":21,"tag":512,"props":10013,"children":10014},{"style":646},[10015],{"type":27,"value":10016},"// 在子进程中执行git branch\n",{"type":21,"tag":512,"props":10018,"children":10019},{"class":514,"line":673},[10020,10025,10030,10034,10039,10043,10048,10052,10057,10061,10066,10070,10074],{"type":21,"tag":512,"props":10021,"children":10022},{"style":815},[10023],{"type":27,"value":10024},"childProcess.",{"type":21,"tag":512,"props":10026,"children":10027},{"style":519},[10028],{"type":27,"value":10029},"exec",{"type":21,"tag":512,"props":10031,"children":10032},{"style":815},[10033],{"type":27,"value":843},{"type":21,"tag":512,"props":10035,"children":10036},{"style":525},[10037],{"type":27,"value":10038},"'git branch'",{"type":21,"tag":512,"props":10040,"children":10041},{"style":815},[10042],{"type":27,"value":2018},{"type":21,"tag":512,"props":10044,"children":10045},{"style":1850},[10046],{"type":27,"value":10047},"error",{"type":21,"tag":512,"props":10049,"children":10050},{"style":815},[10051],{"type":27,"value":1965},{"type":21,"tag":512,"props":10053,"children":10054},{"style":1850},[10055],{"type":27,"value":10056},"stdout",{"type":21,"tag":512,"props":10058,"children":10059},{"style":815},[10060],{"type":27,"value":1965},{"type":21,"tag":512,"props":10062,"children":10063},{"style":1850},[10064],{"type":27,"value":10065},"stderr",{"type":21,"tag":512,"props":10067,"children":10068},{"style":815},[10069],{"type":27,"value":1858},{"type":21,"tag":512,"props":10071,"children":10072},{"style":809},[10073],{"type":27,"value":1863},{"type":21,"tag":512,"props":10075,"children":10076},{"style":815},[10077],{"type":27,"value":1067},{"type":21,"tag":512,"props":10079,"children":10080},{"class":514,"line":900},[10081,10085],{"type":21,"tag":512,"props":10082,"children":10083},{"style":809},[10084],{"type":27,"value":2896},{"type":21,"tag":512,"props":10086,"children":10087},{"style":815},[10088],{"type":27,"value":10089}," (error) {\n",{"type":21,"tag":512,"props":10091,"children":10092},{"class":514,"line":908},[10093,10097,10101],{"type":21,"tag":512,"props":10094,"children":10095},{"style":815},[10096],{"type":27,"value":1921},{"type":21,"tag":512,"props":10098,"children":10099},{"style":519},[10100],{"type":27,"value":10047},{"type":21,"tag":512,"props":10102,"children":10103},{"style":815},[10104],{"type":27,"value":10105},"(error);\n",{"type":21,"tag":512,"props":10107,"children":10108},{"class":514,"line":955},[10109,10113],{"type":21,"tag":512,"props":10110,"children":10111},{"style":809},[10112],{"type":27,"value":2945},{"type":21,"tag":512,"props":10114,"children":10115},{"style":815},[10116],{"type":27,"value":897},{"type":21,"tag":512,"props":10118,"children":10119},{"class":514,"line":983},[10120],{"type":21,"tag":512,"props":10121,"children":10122},{"style":815},[10123],{"type":27,"value":2957},{"type":21,"tag":512,"props":10125,"children":10126},{"class":514,"line":991},[10127],{"type":21,"tag":512,"props":10128,"children":10129},{"emptyLinePlaceholder":859},[10130],{"type":27,"value":862},{"type":21,"tag":512,"props":10132,"children":10133},{"class":514,"line":1015},[10134],{"type":21,"tag":512,"props":10135,"children":10136},{"style":646},[10137],{"type":27,"value":10138},"  // 输出子进程运行之后的输出内容\n",{"type":21,"tag":512,"props":10140,"children":10141},{"class":514,"line":1047},[10142,10146,10150,10154,10159,10163,10167],{"type":21,"tag":512,"props":10143,"children":10144},{"style":815},[10145],{"type":27,"value":7125},{"type":21,"tag":512,"props":10147,"children":10148},{"style":519},[10149],{"type":27,"value":966},{"type":21,"tag":512,"props":10151,"children":10152},{"style":815},[10153],{"type":27,"value":843},{"type":21,"tag":512,"props":10155,"children":10156},{"style":525},[10157],{"type":27,"value":10158},"'----------johnhomLogDebug stdout",{"type":21,"tag":512,"props":10160,"children":10161},{"style":686},[10162],{"type":27,"value":2305},{"type":21,"tag":512,"props":10164,"children":10165},{"style":525},[10166],{"type":27,"value":2310},{"type":21,"tag":512,"props":10168,"children":10169},{"style":815},[10170],{"type":27,"value":10171},", stdout);\n",{"type":21,"tag":512,"props":10173,"children":10174},{"class":514,"line":1056},[10175],{"type":21,"tag":512,"props":10176,"children":10177},{"style":815},[10178],{"type":27,"value":2991},{"type":21,"tag":29,"props":10180,"children":10181},{},[10182],{"type":27,"value":10183},"运行以上代码之后：",{"type":21,"tag":29,"props":10185,"children":10186},{},[10187],{"type":21,"tag":459,"props":10188,"children":10191},{"alt":10189,"src":10190},"Pasted image 20230903190856","https://johnhom-img.oss-cn-guangzhou.aliyuncs.com/images/Pasted%20image%2020230903190856.png",[],{"type":21,"tag":29,"props":10193,"children":10194},{},[10195,10197,10202,10204,10210,10212,10217],{"type":27,"value":10196},"以上就是一个简单的例子，通过",{"type":21,"tag":508,"props":10198,"children":10200},{"className":10199},[],[10201],{"type":27,"value":9948},{"type":27,"value":10203},"模块衍生一个shell进程，然后在该进程中执行了",{"type":21,"tag":508,"props":10205,"children":10207},{"className":10206},[],[10208],{"type":27,"value":10209},"git branch",{"type":27,"value":10211},"命令，完成之后把命令输出的内容作为",{"type":21,"tag":508,"props":10213,"children":10215},{"className":10214},[],[10216],{"type":27,"value":10056},{"type":27,"value":10218},"放入回调函数中。",{"type":21,"tag":29,"props":10220,"children":10221},{},[10222,10224,10231,10233,10238],{"type":27,"value":10223},"一般我们都会使用第三方库",{"type":21,"tag":445,"props":10225,"children":10228},{"href":10226,"rel":10227},"https://github.com/shelljs/shelljs",[449],[10229],{"type":27,"value":10230},"shelljs",{"type":27,"value":10232},"来代替",{"type":21,"tag":508,"props":10234,"children":10236},{"className":10235},[],[10237],{"type":27,"value":9948},{"type":27,"value":10239},"，它提供了更高级的API和更简洁的语法，适用于执行简单的Shell命令和一些常见的文件和目录操作。",{"type":21,"tag":22,"props":10241,"children":10242},{"id":2624},[10243],{"type":27,"value":2624},{"type":21,"tag":29,"props":10245,"children":10246},{},[10247],{"type":27,"value":10248},"通过这次git工具的开发呢，让我发现在编程生涯中，其实很多重复的事情，其实都可以通过写一个Node.js的程序去处理和解决，以此解放我们的双手，极大地提升工作的效率。只要你敢想，然后动手造出来。",{"type":21,"tag":29,"props":10250,"children":10251},{},[10252],{"type":27,"value":10253},"其实工具并不缺乏，缺乏的只是你的想象力还有珍贵的行动力。",{"type":21,"tag":22,"props":10255,"children":10257},{"id":10256},"相关的工具链接",[10258],{"type":27,"value":10256},{"type":21,"tag":75,"props":10260,"children":10261},{},[10262,10271],{"type":21,"tag":79,"props":10263,"children":10264},{},[10265],{"type":21,"tag":445,"props":10266,"children":10269},{"href":10267,"rel":10268},"https://github.com/johnhom1024/tool-cli/tree/main/packages/mg-cli",[449],[10270],{"type":27,"value":9425},{"type":21,"tag":79,"props":10272,"children":10273},{},[10274],{"type":21,"tag":445,"props":10275,"children":10277},{"href":10226,"rel":10276},[449],[10278],{"type":27,"value":10230},{"type":21,"tag":2671,"props":10280,"children":10281},{},[10282],{"type":27,"value":2675},{"title":8,"searchDepth":359,"depth":359,"links":10284},[10285,10286,10287,10288,10289],{"id":393,"depth":359,"text":393},{"id":9412,"depth":359,"text":9412},{"id":9935,"depth":359,"text":9935},{"id":2624,"depth":359,"text":2624},{"id":10256,"depth":359,"text":10256},"content:articles:20230903.md","articles/20230903.md",{"_path":10293,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":10294,"description":8,"published":10295,"categories":10296,"slug":10294,"body":10297,"_type":376,"_id":12920,"_source":378,"_file":12921,"_extension":380},"/articles/20240323","ESModule与CommonJS互相引用的问题","2023/06/03",[242],{"type":18,"children":10298,"toc":12911},[10299,10303,10332,10370,10376,10381,10410,10422,10442,10488,10494,10499,10541,10554,10560,10583,10698,10720,10855,10870,10927,10968,10976,11004,11012,11038,11043,11048,11078,11208,11224,11398,11443,11630,11638,11668,11681,11699,11707,11734,11784,11803,12001,12014,12041,12060,12129,12135,12171,12176,12184,12207,12272,12291,12306,12342,12361,12626,12641,12668,12685,12704,12786,12790,12816,12828,12869,12902,12907],{"type":21,"tag":22,"props":10300,"children":10301},{"id":24},[10302],{"type":27,"value":24},{"type":21,"tag":29,"props":10304,"children":10305},{},[10306,10308,10314,10316,10322,10324,10330],{"type":27,"value":10307},"最近使用",{"type":21,"tag":508,"props":10309,"children":10311},{"className":10310},[],[10312],{"type":27,"value":10313},"Rollup",{"type":27,"value":10315},"打包输出",{"type":21,"tag":508,"props":10317,"children":10319},{"className":10318},[],[10320],{"type":27,"value":10321},"CJS",{"type":27,"value":10323},"模块的代码，时不时会提示导入的模块是",{"type":21,"tag":508,"props":10325,"children":10327},{"className":10326},[],[10328],{"type":27,"value":10329},"ESM",{"type":27,"value":10331},"规范，需要使用动态导入的方式引入这个模块，这个问题引起了我的注意，所以决定深入研究一下。",{"type":21,"tag":75,"props":10333,"children":10334},{},[10335,10354],{"type":21,"tag":79,"props":10336,"children":10337},{},[10338,10340,10345,10347,10352],{"type":27,"value":10339},"简单介绍",{"type":21,"tag":508,"props":10341,"children":10343},{"className":10342},[],[10344],{"type":27,"value":10329},{"type":27,"value":10346},"和",{"type":21,"tag":508,"props":10348,"children":10350},{"className":10349},[],[10351],{"type":27,"value":10321},{"type":27,"value":10353},"的原理",{"type":21,"tag":79,"props":10355,"children":10356},{},[10357,10362,10363,10368],{"type":21,"tag":508,"props":10358,"children":10360},{"className":10359},[],[10361],{"type":27,"value":10329},{"type":27,"value":10346},{"type":21,"tag":508,"props":10364,"children":10366},{"className":10365},[],[10367],{"type":27,"value":10321},{"type":27,"value":10369},"的互相引用问题",{"type":21,"tag":22,"props":10371,"children":10373},{"id":10372},"cjs和esm的历史演变",[10374],{"type":27,"value":10375},"CJS和ESM的历史演变",{"type":21,"tag":29,"props":10377,"children":10378},{},[10379],{"type":27,"value":10380},"JavaScript一开始诞生是在浏览器上作为脚本语言使用的，当时在浏览器上并不存在模块的概念。它就像日本动漫里的男主角，刚转生到异世界时没有任何的武器和装备（不是龙傲天），所以说一开始的JavaScript也是不完善的，需要时间的历练，打怪升级学技能。",{"type":21,"tag":29,"props":10382,"children":10383},{},[10384,10386,10392,10394,10400,10402,10408],{"type":27,"value":10385},"直到Node.JS的诞生，让JavaScript能在服务端运行，同时Node.js社区的发展给JavaScript带来了模块化的概念，使用",{"type":21,"tag":508,"props":10387,"children":10389},{"className":10388},[],[10390],{"type":27,"value":10391},"module.exports",{"type":27,"value":10393},"导出和",{"type":21,"tag":508,"props":10395,"children":10397},{"className":10396},[],[10398],{"type":27,"value":10399},"require",{"type":27,"value":10401},"引入模块，这个规范叫做",{"type":21,"tag":508,"props":10403,"children":10405},{"className":10404},[],[10406],{"type":27,"value":10407},"CommonJS",{"type":27,"value":10409},"。它的出现使得服务端的JavaScript应用程序的开发更加规范化和标准化。",{"type":21,"tag":29,"props":10411,"children":10412},{},[10413,10415,10420],{"type":27,"value":10414},"由于",{"type":21,"tag":508,"props":10416,"children":10418},{"className":10417},[],[10419],{"type":27,"value":10407},{"type":27,"value":10421},"的引入模块原理是同步加载的方式，要是在浏览器端使用这个规范，则需要等待所有的模块加载完才能执行后面的代码。由于浏览器中的JavaScript引擎是单线程的，如果加载JavaScript模块的过程中，代码执行的时间过长，就会导致其他代码无法执行，从而影响整个页面的渲染和交互，最终影响了用户体验。因此，浏览器需要一种异步加载模块方式。",{"type":21,"tag":29,"props":10423,"children":10424},{},[10425,10427,10433,10435,10440],{"type":27,"value":10426},"在2015年的6月，",{"type":21,"tag":508,"props":10428,"children":10430},{"className":10429},[],[10431],{"type":27,"value":10432},"ES6",{"type":27,"value":10434},"标准正式推出，在这个标准里带来了JavaScript异步加载模块的",{"type":21,"tag":508,"props":10436,"children":10438},{"className":10437},[],[10439],{"type":27,"value":10329},{"type":27,"value":10441},"规范。",{"type":21,"tag":29,"props":10443,"children":10444},{},[10445,10450,10452,10458,10460,10466,10468,10473,10475,10480,10481,10486],{"type":21,"tag":508,"props":10446,"children":10448},{"className":10447},[],[10449],{"type":27,"value":10329},{"type":27,"value":10451},"，也叫做 ",{"type":21,"tag":508,"props":10453,"children":10455},{"className":10454},[],[10456],{"type":27,"value":10457},"ECMAScript modules",{"type":27,"value":10459},"或者",{"type":21,"tag":508,"props":10461,"children":10463},{"className":10462},[],[10464],{"type":27,"value":10465},"ES modules",{"type":27,"value":10467},"，是来自",{"type":21,"tag":508,"props":10469,"children":10471},{"className":10470},[],[10472],{"type":27,"value":10432},{"type":27,"value":10474},"规范里的模块化概念，使用",{"type":21,"tag":508,"props":10476,"children":10478},{"className":10477},[],[10479],{"type":27,"value":8800},{"type":27,"value":10346},{"type":21,"tag":508,"props":10482,"children":10484},{"className":10483},[],[10485],{"type":27,"value":6195},{"type":27,"value":10487},"关键字，来实现js的模块化导入和导出。",{"type":21,"tag":22,"props":10489,"children":10491},{"id":10490},"esmodule和commonjs互相引用",[10492],{"type":27,"value":10493},"ESModule和CommonJS互相引用",{"type":21,"tag":29,"props":10495,"children":10496},{},[10497],{"type":27,"value":10498},"完全不同的两个规范，互相导入的话会导致什么情况呢？",{"type":21,"tag":29,"props":10500,"children":10501},{},[10502,10504,10509,10511,10517,10519,10524,10526,10532,10534,10539],{"type":27,"value":10503},"在继续之前，我们需要了解Node.js支持运行",{"type":21,"tag":508,"props":10505,"children":10507},{"className":10506},[],[10508],{"type":27,"value":10329},{"type":27,"value":10510},"规范的最低版本是：",{"type":21,"tag":508,"props":10512,"children":10514},{"className":10513},[],[10515],{"type":27,"value":10516},"v13.2.0",{"type":27,"value":10518},"，在之前的版本中，想要在node中使用",{"type":21,"tag":508,"props":10520,"children":10522},{"className":10521},[],[10523],{"type":27,"value":10329},{"type":27,"value":10525},"，需要添加",{"type":21,"tag":508,"props":10527,"children":10529},{"className":10528},[],[10530],{"type":27,"value":10531},"--experimental-module",{"type":27,"value":10533},"参数，在",{"type":21,"tag":508,"props":10535,"children":10537},{"className":10536},[],[10538],{"type":27,"value":10516},{"type":27,"value":10540},"版本之后可以直接使用。",{"type":21,"tag":29,"props":10542,"children":10543},{},[10544,10546,10552],{"type":27,"value":10545},"我将会使用Node.js",{"type":21,"tag":508,"props":10547,"children":10549},{"className":10548},[],[10550],{"type":27,"value":10551},"v16.18.0",{"type":27,"value":10553},"版本进行下面的测试，话不多说，立马进入。",{"type":21,"tag":41,"props":10555,"children":10557},{"id":10556},"cjs导入esm模块",[10558],{"type":27,"value":10559},"CJS导入ESM模块",{"type":21,"tag":295,"props":10561,"children":10562},{},[10563],{"type":21,"tag":79,"props":10564,"children":10565},{},[10566,10568,10573,10575,10581],{"type":27,"value":10567},"先新建一个",{"type":21,"tag":508,"props":10569,"children":10571},{"className":10570},[],[10572],{"type":27,"value":10329},{"type":27,"value":10574},"模块，文件名为： ",{"type":21,"tag":508,"props":10576,"children":10578},{"className":10577},[],[10579],{"type":27,"value":10580},"esm.js",{"type":27,"value":10582},"，代码如下：",{"type":21,"tag":501,"props":10584,"children":10586},{"className":2762,"code":10585,"language":2764,"meta":8,"style":8},"// esm.js\nexport const a = 1;\nexport const b = 2;\nexport function foo () {\n  return 3;\n}\n",[10587],{"type":21,"tag":508,"props":10588,"children":10589},{"__ignoreMap":8},[10590,10598,10627,10655,10676,10691],{"type":21,"tag":512,"props":10591,"children":10592},{"class":514,"line":515},[10593],{"type":21,"tag":512,"props":10594,"children":10595},{"style":646},[10596],{"type":27,"value":10597},"// esm.js\n",{"type":21,"tag":512,"props":10599,"children":10600},{"class":514,"line":359},[10601,10605,10610,10615,10619,10623],{"type":21,"tag":512,"props":10602,"children":10603},{"style":809},[10604],{"type":27,"value":6195},{"type":21,"tag":512,"props":10606,"children":10607},{"style":809},[10608],{"type":27,"value":10609}," const",{"type":21,"tag":512,"props":10611,"children":10612},{"style":686},[10613],{"type":27,"value":10614}," a",{"type":21,"tag":512,"props":10616,"children":10617},{"style":809},[10618],{"type":27,"value":887},{"type":21,"tag":512,"props":10620,"children":10621},{"style":686},[10622],{"type":27,"value":3535},{"type":21,"tag":512,"props":10624,"children":10625},{"style":815},[10626],{"type":27,"value":897},{"type":21,"tag":512,"props":10628,"children":10629},{"class":514,"line":365},[10630,10634,10638,10643,10647,10651],{"type":21,"tag":512,"props":10631,"children":10632},{"style":809},[10633],{"type":27,"value":6195},{"type":21,"tag":512,"props":10635,"children":10636},{"style":809},[10637],{"type":27,"value":10609},{"type":21,"tag":512,"props":10639,"children":10640},{"style":686},[10641],{"type":27,"value":10642}," b",{"type":21,"tag":512,"props":10644,"children":10645},{"style":809},[10646],{"type":27,"value":887},{"type":21,"tag":512,"props":10648,"children":10649},{"style":686},[10650],{"type":27,"value":3734},{"type":21,"tag":512,"props":10652,"children":10653},{"style":815},[10654],{"type":27,"value":897},{"type":21,"tag":512,"props":10656,"children":10657},{"class":514,"line":673},[10658,10662,10666,10671],{"type":21,"tag":512,"props":10659,"children":10660},{"style":809},[10661],{"type":27,"value":6195},{"type":21,"tag":512,"props":10663,"children":10664},{"style":809},[10665],{"type":27,"value":3483},{"type":21,"tag":512,"props":10667,"children":10668},{"style":519},[10669],{"type":27,"value":10670}," foo",{"type":21,"tag":512,"props":10672,"children":10673},{"style":815},[10674],{"type":27,"value":10675}," () {\n",{"type":21,"tag":512,"props":10677,"children":10678},{"class":514,"line":900},[10679,10683,10687],{"type":21,"tag":512,"props":10680,"children":10681},{"style":809},[10682],{"type":27,"value":5711},{"type":21,"tag":512,"props":10684,"children":10685},{"style":686},[10686],{"type":27,"value":3929},{"type":21,"tag":512,"props":10688,"children":10689},{"style":815},[10690],{"type":27,"value":897},{"type":21,"tag":512,"props":10692,"children":10693},{"class":514,"line":908},[10694],{"type":21,"tag":512,"props":10695,"children":10696},{"style":815},[10697],{"type":27,"value":1053},{"type":21,"tag":295,"props":10699,"children":10700},{"start":359},[10701],{"type":21,"tag":79,"props":10702,"children":10703},{},[10704,10706,10711,10713,10719],{"type":27,"value":10705},"另外新建一个",{"type":21,"tag":508,"props":10707,"children":10709},{"className":10708},[],[10710],{"type":27,"value":10321},{"type":27,"value":10712},"模块，文件名为：",{"type":21,"tag":508,"props":10714,"children":10716},{"className":10715},[],[10717],{"type":27,"value":10718},"cjs.js",{"type":27,"value":10582},{"type":21,"tag":501,"props":10721,"children":10723},{"className":2762,"code":10722,"language":2764,"meta":8,"style":8},"// cjs.js\nconst { a, b, foo } = require('./esm.js')\n\nconsole.log(a);\nconsole.log(b);\nconsole.log(foo());\n",[10724],{"type":21,"tag":508,"props":10725,"children":10726},{"__ignoreMap":8},[10727,10735,10793,10800,10816,10832],{"type":21,"tag":512,"props":10728,"children":10729},{"class":514,"line":515},[10730],{"type":21,"tag":512,"props":10731,"children":10732},{"style":646},[10733],{"type":27,"value":10734},"// cjs.js\n",{"type":21,"tag":512,"props":10736,"children":10737},{"class":514,"line":359},[10738,10742,10746,10750,10754,10759,10763,10768,10772,10776,10780,10784,10789],{"type":21,"tag":512,"props":10739,"children":10740},{"style":809},[10741],{"type":27,"value":812},{"type":21,"tag":512,"props":10743,"children":10744},{"style":815},[10745],{"type":27,"value":818},{"type":21,"tag":512,"props":10747,"children":10748},{"style":686},[10749],{"type":27,"value":445},{"type":21,"tag":512,"props":10751,"children":10752},{"style":815},[10753],{"type":27,"value":1965},{"type":21,"tag":512,"props":10755,"children":10756},{"style":686},[10757],{"type":27,"value":10758},"b",{"type":21,"tag":512,"props":10760,"children":10761},{"style":815},[10762],{"type":27,"value":1965},{"type":21,"tag":512,"props":10764,"children":10765},{"style":686},[10766],{"type":27,"value":10767},"foo",{"type":21,"tag":512,"props":10769,"children":10770},{"style":815},[10771],{"type":27,"value":828},{"type":21,"tag":512,"props":10773,"children":10774},{"style":809},[10775],{"type":27,"value":833},{"type":21,"tag":512,"props":10777,"children":10778},{"style":519},[10779],{"type":27,"value":838},{"type":21,"tag":512,"props":10781,"children":10782},{"style":815},[10783],{"type":27,"value":843},{"type":21,"tag":512,"props":10785,"children":10786},{"style":525},[10787],{"type":27,"value":10788},"'./esm.js'",{"type":21,"tag":512,"props":10790,"children":10791},{"style":815},[10792],{"type":27,"value":3591},{"type":21,"tag":512,"props":10794,"children":10795},{"class":514,"line":365},[10796],{"type":21,"tag":512,"props":10797,"children":10798},{"emptyLinePlaceholder":859},[10799],{"type":27,"value":862},{"type":21,"tag":512,"props":10801,"children":10802},{"class":514,"line":673},[10803,10807,10811],{"type":21,"tag":512,"props":10804,"children":10805},{"style":815},[10806],{"type":27,"value":961},{"type":21,"tag":512,"props":10808,"children":10809},{"style":519},[10810],{"type":27,"value":966},{"type":21,"tag":512,"props":10812,"children":10813},{"style":815},[10814],{"type":27,"value":10815},"(a);\n",{"type":21,"tag":512,"props":10817,"children":10818},{"class":514,"line":900},[10819,10823,10827],{"type":21,"tag":512,"props":10820,"children":10821},{"style":815},[10822],{"type":27,"value":961},{"type":21,"tag":512,"props":10824,"children":10825},{"style":519},[10826],{"type":27,"value":966},{"type":21,"tag":512,"props":10828,"children":10829},{"style":815},[10830],{"type":27,"value":10831},"(b);\n",{"type":21,"tag":512,"props":10833,"children":10834},{"class":514,"line":908},[10835,10839,10843,10847,10851],{"type":21,"tag":512,"props":10836,"children":10837},{"style":815},[10838],{"type":27,"value":961},{"type":21,"tag":512,"props":10840,"children":10841},{"style":519},[10842],{"type":27,"value":966},{"type":21,"tag":512,"props":10844,"children":10845},{"style":815},[10846],{"type":27,"value":843},{"type":21,"tag":512,"props":10848,"children":10849},{"style":519},[10850],{"type":27,"value":10767},{"type":21,"tag":512,"props":10852,"children":10853},{"style":815},[10854],{"type":27,"value":2165},{"type":21,"tag":295,"props":10856,"children":10857},{"start":365},[10858],{"type":21,"tag":79,"props":10859,"children":10860},{},[10861,10863,10868],{"type":27,"value":10862},"运行",{"type":21,"tag":508,"props":10864,"children":10866},{"className":10865},[],[10867],{"type":27,"value":10718},{"type":27,"value":10869},"文件，结果提示以下的错误信息：",{"type":21,"tag":501,"props":10871,"children":10873},{"className":634,"code":10872,"language":636,"meta":8,"style":8},"export const a = 1;\n^^^^^^\n\nSyntaxError: Unexpected token 'export'\n",[10874],{"type":21,"tag":508,"props":10875,"children":10876},{"__ignoreMap":8},[10877,10889,10897,10904],{"type":21,"tag":512,"props":10878,"children":10879},{"class":514,"line":515},[10880,10884],{"type":21,"tag":512,"props":10881,"children":10882},{"style":809},[10883],{"type":27,"value":6195},{"type":21,"tag":512,"props":10885,"children":10886},{"style":815},[10887],{"type":27,"value":10888}," const a = 1;\n",{"type":21,"tag":512,"props":10890,"children":10891},{"class":514,"line":359},[10892],{"type":21,"tag":512,"props":10893,"children":10894},{"style":519},[10895],{"type":27,"value":10896},"^^^^^^\n",{"type":21,"tag":512,"props":10898,"children":10899},{"class":514,"line":365},[10900],{"type":21,"tag":512,"props":10901,"children":10902},{"emptyLinePlaceholder":859},[10903],{"type":27,"value":862},{"type":21,"tag":512,"props":10905,"children":10906},{"class":514,"line":673},[10907,10912,10917,10922],{"type":21,"tag":512,"props":10908,"children":10909},{"style":519},[10910],{"type":27,"value":10911},"SyntaxError:",{"type":21,"tag":512,"props":10913,"children":10914},{"style":525},[10915],{"type":27,"value":10916}," Unexpected",{"type":21,"tag":512,"props":10918,"children":10919},{"style":525},[10920],{"type":27,"value":10921}," token",{"type":21,"tag":512,"props":10923,"children":10924},{"style":525},[10925],{"type":27,"value":10926}," 'export'\n",{"type":21,"tag":29,"props":10928,"children":10929},{},[10930,10932,10937,10939,10945,10947,10952,10954,10959,10961,10966],{"type":27,"value":10931},"通过来说，如果在",{"type":21,"tag":508,"props":10933,"children":10935},{"className":10934},[],[10936],{"type":27,"value":10321},{"type":27,"value":10938},"上通过相对路径方式引入",{"type":21,"tag":508,"props":10940,"children":10942},{"className":10941},[],[10943],{"type":27,"value":10944},".js",{"type":27,"value":10946},"结尾的",{"type":21,"tag":508,"props":10948,"children":10950},{"className":10949},[],[10951],{"type":27,"value":10329},{"type":27,"value":10953},"模块，就会遇到上面的问题。根本原因Node.js底层在加载这个",{"type":21,"tag":508,"props":10955,"children":10957},{"className":10956},[],[10958],{"type":27,"value":10580},{"type":27,"value":10960},"文件时，把它识别成了",{"type":21,"tag":508,"props":10962,"children":10964},{"className":10963},[],[10965],{"type":27,"value":10321},{"type":27,"value":10967},"规范，最后使用cjs的loader进行处理时抛出的异常：",{"type":21,"tag":29,"props":10969,"children":10970},{},[10971],{"type":21,"tag":459,"props":10972,"children":10975},{"alt":10973,"src":10974},"Pasted image 20230605165120","https://johnhom-img.oss-cn-guangzhou.aliyuncs.com/images/Pasted%20image%2020230605165120.png",[],{"type":21,"tag":29,"props":10977,"children":10978},{},[10979,10981,10986,10988,10993,10995,11002],{"type":27,"value":10980},"那么问题来了，Node.js是如何识别引入的文件是",{"type":21,"tag":508,"props":10982,"children":10984},{"className":10983},[],[10985],{"type":27,"value":10329},{"type":27,"value":10987},"还是",{"type":21,"tag":508,"props":10989,"children":10991},{"className":10990},[],[10992],{"type":27,"value":10321},{"type":27,"value":10994},"规范的？其实Node.js有一个判断的机制叫做：",{"type":21,"tag":445,"props":10996,"children":10999},{"href":10997,"rel":10998},"https://nodejs.org/docs/latest-v14.x/api/packages.html#packages_determining_module_system",[449],[11000],{"type":27,"value":11001},"Determining module system",{"type":27,"value":11003},"。用图例简单解析这个机制的判断逻辑:",{"type":21,"tag":29,"props":11005,"children":11006},{},[11007],{"type":21,"tag":459,"props":11008,"children":11011},{"alt":11009,"src":11010},"Drawing 2023-06-05 17.08.24.excalidraw","https://johnhom-img.oss-cn-guangzhou.aliyuncs.com/images/Drawing%202023-06-05%2017.08.24.excalidraw.png",[],{"type":21,"tag":29,"props":11013,"children":11014},{},[11015,11017,11022,11024,11029,11031,11036],{"type":27,"value":11016},"为了",{"type":21,"tag":508,"props":11018,"children":11020},{"className":11019},[],[11021],{"type":27,"value":11001},{"type":27,"value":11023},"能够把",{"type":21,"tag":508,"props":11025,"children":11027},{"className":11026},[],[11028],{"type":27,"value":10580},{"type":27,"value":11030},"正确识别成",{"type":21,"tag":508,"props":11032,"children":11034},{"className":11033},[],[11035],{"type":27,"value":10329},{"type":27,"value":11037},"模块，我们有2种方案：",{"type":21,"tag":29,"props":11039,"children":11040},{},[11041],{"type":27,"value":11042},"第一种：修改文件名后缀的方式。",{"type":21,"tag":29,"props":11044,"children":11045},{},[11046],{"type":27,"value":11047},"步骤如下：",{"type":21,"tag":295,"props":11049,"children":11050},{},[11051],{"type":21,"tag":79,"props":11052,"children":11053},{},[11054,11056,11061,11063,11069,11071,11076],{"type":27,"value":11055},"我们修改一下",{"type":21,"tag":508,"props":11057,"children":11059},{"className":11058},[],[11060],{"type":27,"value":10580},{"type":27,"value":11062},"文件为",{"type":21,"tag":508,"props":11064,"children":11066},{"className":11065},[],[11067],{"type":27,"value":11068},"esm.mjs",{"type":27,"value":11070},"，然后调整一下",{"type":21,"tag":508,"props":11072,"children":11074},{"className":11073},[],[11075],{"type":27,"value":10718},{"type":27,"value":11077},"文件的内容如下：",{"type":21,"tag":501,"props":11079,"children":11081},{"className":2762,"code":11080,"language":2764,"meta":8,"style":8},"// cjs.js\nconst { a, b, foo } = require('./esm.mjs');\n\nconsole.log(a);\nconsole.log(b);\nconsole.log(foo());\n",[11082],{"type":21,"tag":508,"props":11083,"children":11084},{"__ignoreMap":8},[11085,11092,11148,11155,11170,11185],{"type":21,"tag":512,"props":11086,"children":11087},{"class":514,"line":515},[11088],{"type":21,"tag":512,"props":11089,"children":11090},{"style":646},[11091],{"type":27,"value":10734},{"type":21,"tag":512,"props":11093,"children":11094},{"class":514,"line":359},[11095,11099,11103,11107,11111,11115,11119,11123,11127,11131,11135,11139,11144],{"type":21,"tag":512,"props":11096,"children":11097},{"style":809},[11098],{"type":27,"value":812},{"type":21,"tag":512,"props":11100,"children":11101},{"style":815},[11102],{"type":27,"value":818},{"type":21,"tag":512,"props":11104,"children":11105},{"style":686},[11106],{"type":27,"value":445},{"type":21,"tag":512,"props":11108,"children":11109},{"style":815},[11110],{"type":27,"value":1965},{"type":21,"tag":512,"props":11112,"children":11113},{"style":686},[11114],{"type":27,"value":10758},{"type":21,"tag":512,"props":11116,"children":11117},{"style":815},[11118],{"type":27,"value":1965},{"type":21,"tag":512,"props":11120,"children":11121},{"style":686},[11122],{"type":27,"value":10767},{"type":21,"tag":512,"props":11124,"children":11125},{"style":815},[11126],{"type":27,"value":828},{"type":21,"tag":512,"props":11128,"children":11129},{"style":809},[11130],{"type":27,"value":833},{"type":21,"tag":512,"props":11132,"children":11133},{"style":519},[11134],{"type":27,"value":838},{"type":21,"tag":512,"props":11136,"children":11137},{"style":815},[11138],{"type":27,"value":843},{"type":21,"tag":512,"props":11140,"children":11141},{"style":525},[11142],{"type":27,"value":11143},"'./esm.mjs'",{"type":21,"tag":512,"props":11145,"children":11146},{"style":815},[11147],{"type":27,"value":853},{"type":21,"tag":512,"props":11149,"children":11150},{"class":514,"line":365},[11151],{"type":21,"tag":512,"props":11152,"children":11153},{"emptyLinePlaceholder":859},[11154],{"type":27,"value":862},{"type":21,"tag":512,"props":11156,"children":11157},{"class":514,"line":673},[11158,11162,11166],{"type":21,"tag":512,"props":11159,"children":11160},{"style":815},[11161],{"type":27,"value":961},{"type":21,"tag":512,"props":11163,"children":11164},{"style":519},[11165],{"type":27,"value":966},{"type":21,"tag":512,"props":11167,"children":11168},{"style":815},[11169],{"type":27,"value":10815},{"type":21,"tag":512,"props":11171,"children":11172},{"class":514,"line":900},[11173,11177,11181],{"type":21,"tag":512,"props":11174,"children":11175},{"style":815},[11176],{"type":27,"value":961},{"type":21,"tag":512,"props":11178,"children":11179},{"style":519},[11180],{"type":27,"value":966},{"type":21,"tag":512,"props":11182,"children":11183},{"style":815},[11184],{"type":27,"value":10831},{"type":21,"tag":512,"props":11186,"children":11187},{"class":514,"line":908},[11188,11192,11196,11200,11204],{"type":21,"tag":512,"props":11189,"children":11190},{"style":815},[11191],{"type":27,"value":961},{"type":21,"tag":512,"props":11193,"children":11194},{"style":519},[11195],{"type":27,"value":966},{"type":21,"tag":512,"props":11197,"children":11198},{"style":815},[11199],{"type":27,"value":843},{"type":21,"tag":512,"props":11201,"children":11202},{"style":519},[11203],{"type":27,"value":10767},{"type":21,"tag":512,"props":11205,"children":11206},{"style":815},[11207],{"type":27,"value":2165},{"type":21,"tag":295,"props":11209,"children":11210},{"start":359},[11211],{"type":21,"tag":79,"props":11212,"children":11213},{},[11214,11216,11222],{"type":27,"value":11215},"执行命令",{"type":21,"tag":508,"props":11217,"children":11219},{"className":11218},[],[11220],{"type":27,"value":11221},"node cjs.js",{"type":27,"value":11223},"，又抛出异常了，不过这次的报错稍微不太一样：",{"type":21,"tag":501,"props":11225,"children":11227},{"className":634,"code":11226,"language":636,"meta":8,"style":8},"node:internal/modules/cjs/loader:1031\n    throw new ERR_REQUIRE_ESM(filename, true);\n    ^\n\nError [ERR_REQUIRE_ESM]: require() of ES Module esm.mjs not supported.\nInstead change the require of esm.mjs to a dynamic import() which is available in all CommonJS modules.\n",[11228],{"type":21,"tag":508,"props":11229,"children":11230},{"__ignoreMap":8},[11231,11239,11273,11281,11288,11310],{"type":21,"tag":512,"props":11232,"children":11233},{"class":514,"line":515},[11234],{"type":21,"tag":512,"props":11235,"children":11236},{"style":519},[11237],{"type":27,"value":11238},"node:internal/modules/cjs/loader:1031\n",{"type":21,"tag":512,"props":11240,"children":11241},{"class":514,"line":359},[11242,11247,11251,11256,11260,11265,11269],{"type":21,"tag":512,"props":11243,"children":11244},{"style":519},[11245],{"type":27,"value":11246},"    throw",{"type":21,"tag":512,"props":11248,"children":11249},{"style":525},[11250],{"type":27,"value":1026},{"type":21,"tag":512,"props":11252,"children":11253},{"style":525},[11254],{"type":27,"value":11255}," ERR_REQUIRE_ESM",{"type":21,"tag":512,"props":11257,"children":11258},{"style":815},[11259],{"type":27,"value":843},{"type":21,"tag":512,"props":11261,"children":11262},{"style":519},[11263],{"type":27,"value":11264},"filename,",{"type":21,"tag":512,"props":11266,"children":11267},{"style":686},[11268],{"type":27,"value":3561},{"type":21,"tag":512,"props":11270,"children":11271},{"style":815},[11272],{"type":27,"value":853},{"type":21,"tag":512,"props":11274,"children":11275},{"class":514,"line":365},[11276],{"type":21,"tag":512,"props":11277,"children":11278},{"style":519},[11279],{"type":27,"value":11280},"    ^\n",{"type":21,"tag":512,"props":11282,"children":11283},{"class":514,"line":673},[11284],{"type":21,"tag":512,"props":11285,"children":11286},{"emptyLinePlaceholder":859},[11287],{"type":27,"value":862},{"type":21,"tag":512,"props":11289,"children":11290},{"class":514,"line":900},[11291,11296,11301,11305],{"type":21,"tag":512,"props":11292,"children":11293},{"style":519},[11294],{"type":27,"value":11295},"Error",{"type":21,"tag":512,"props":11297,"children":11298},{"style":815},[11299],{"type":27,"value":11300}," [ERR_REQUIRE_ESM]: ",{"type":21,"tag":512,"props":11302,"children":11303},{"style":519},[11304],{"type":27,"value":10399},{"type":21,"tag":512,"props":11306,"children":11307},{"style":815},[11308],{"type":27,"value":11309},"() of ES Module esm.mjs not supported.\n",{"type":21,"tag":512,"props":11311,"children":11312},{"class":514,"line":908},[11313,11318,11323,11327,11331,11335,11340,11345,11349,11354,11359,11363,11368,11373,11378,11383,11388,11393],{"type":21,"tag":512,"props":11314,"children":11315},{"style":519},[11316],{"type":27,"value":11317},"Instead",{"type":21,"tag":512,"props":11319,"children":11320},{"style":525},[11321],{"type":27,"value":11322}," change",{"type":21,"tag":512,"props":11324,"children":11325},{"style":525},[11326],{"type":27,"value":9739},{"type":21,"tag":512,"props":11328,"children":11329},{"style":525},[11330],{"type":27,"value":838},{"type":21,"tag":512,"props":11332,"children":11333},{"style":525},[11334],{"type":27,"value":5624},{"type":21,"tag":512,"props":11336,"children":11337},{"style":525},[11338],{"type":27,"value":11339}," esm.mjs",{"type":21,"tag":512,"props":11341,"children":11342},{"style":525},[11343],{"type":27,"value":11344}," to",{"type":21,"tag":512,"props":11346,"children":11347},{"style":525},[11348],{"type":27,"value":10614},{"type":21,"tag":512,"props":11350,"children":11351},{"style":525},[11352],{"type":27,"value":11353}," dynamic",{"type":21,"tag":512,"props":11355,"children":11356},{"style":525},[11357],{"type":27,"value":11358}," import",{"type":21,"tag":512,"props":11360,"children":11361},{"style":815},[11362],{"type":27,"value":4708},{"type":21,"tag":512,"props":11364,"children":11365},{"style":525},[11366],{"type":27,"value":11367},"which",{"type":21,"tag":512,"props":11369,"children":11370},{"style":525},[11371],{"type":27,"value":11372}," is",{"type":21,"tag":512,"props":11374,"children":11375},{"style":525},[11376],{"type":27,"value":11377}," available",{"type":21,"tag":512,"props":11379,"children":11380},{"style":525},[11381],{"type":27,"value":11382}," in",{"type":21,"tag":512,"props":11384,"children":11385},{"style":525},[11386],{"type":27,"value":11387}," all",{"type":21,"tag":512,"props":11389,"children":11390},{"style":525},[11391],{"type":27,"value":11392}," CommonJS",{"type":21,"tag":512,"props":11394,"children":11395},{"style":525},[11396],{"type":27,"value":11397}," modules.\n",{"type":21,"tag":295,"props":11399,"children":11400},{"start":365},[11401],{"type":21,"tag":79,"props":11402,"children":11403},{},[11404,11406,11411,11413,11419,11421,11427,11429,11434,11436,11441],{"type":27,"value":11405},"大致的意思是",{"type":21,"tag":508,"props":11407,"children":11409},{"className":11408},[],[11410],{"type":27,"value":10329},{"type":27,"value":11412},"模块不支持通过",{"type":21,"tag":508,"props":11414,"children":11416},{"className":11415},[],[11417],{"type":27,"value":11418},"require()",{"type":27,"value":11420},"函数引入，需要替换成通过",{"type":21,"tag":508,"props":11422,"children":11424},{"className":11423},[],[11425],{"type":27,"value":11426},"import()",{"type":27,"value":11428},"函数动态引入",{"type":21,"tag":508,"props":11430,"children":11432},{"className":11431},[],[11433],{"type":27,"value":10329},{"type":27,"value":11435},"模块，那我们就改一下",{"type":21,"tag":508,"props":11437,"children":11439},{"className":11438},[],[11440],{"type":27,"value":10718},{"type":27,"value":11442},"文件中代码，通过动态import的方式引入:",{"type":21,"tag":501,"props":11444,"children":11446},{"className":2762,"code":11445,"language":2764,"meta":8,"style":8},"async function main() {\n  const mod = await import('./esm.mjs');\n  const { a, b, foo } = mod;\n  console.log(a);\n  console.log(b);\n  console.log(foo());\n}\n\nmain();\n",[11447],{"type":21,"tag":508,"props":11448,"children":11449},{"__ignoreMap":8},[11450,11470,11507,11551,11566,11581,11604,11611,11618],{"type":21,"tag":512,"props":11451,"children":11452},{"class":514,"line":515},[11453,11457,11461,11466],{"type":21,"tag":512,"props":11454,"children":11455},{"style":809},[11456],{"type":27,"value":2858},{"type":21,"tag":512,"props":11458,"children":11459},{"style":809},[11460],{"type":27,"value":3483},{"type":21,"tag":512,"props":11462,"children":11463},{"style":519},[11464],{"type":27,"value":11465}," main",{"type":21,"tag":512,"props":11467,"children":11468},{"style":815},[11469],{"type":27,"value":6611},{"type":21,"tag":512,"props":11471,"children":11472},{"class":514,"line":359},[11473,11477,11482,11486,11491,11495,11499,11503],{"type":21,"tag":512,"props":11474,"children":11475},{"style":809},[11476],{"type":27,"value":7904},{"type":21,"tag":512,"props":11478,"children":11479},{"style":686},[11480],{"type":27,"value":11481}," mod",{"type":21,"tag":512,"props":11483,"children":11484},{"style":809},[11485],{"type":27,"value":887},{"type":21,"tag":512,"props":11487,"children":11488},{"style":809},[11489],{"type":27,"value":11490}," await",{"type":21,"tag":512,"props":11492,"children":11493},{"style":809},[11494],{"type":27,"value":11358},{"type":21,"tag":512,"props":11496,"children":11497},{"style":815},[11498],{"type":27,"value":843},{"type":21,"tag":512,"props":11500,"children":11501},{"style":525},[11502],{"type":27,"value":11143},{"type":21,"tag":512,"props":11504,"children":11505},{"style":815},[11506],{"type":27,"value":853},{"type":21,"tag":512,"props":11508,"children":11509},{"class":514,"line":365},[11510,11514,11518,11522,11526,11530,11534,11538,11542,11546],{"type":21,"tag":512,"props":11511,"children":11512},{"style":809},[11513],{"type":27,"value":7904},{"type":21,"tag":512,"props":11515,"children":11516},{"style":815},[11517],{"type":27,"value":818},{"type":21,"tag":512,"props":11519,"children":11520},{"style":686},[11521],{"type":27,"value":445},{"type":21,"tag":512,"props":11523,"children":11524},{"style":815},[11525],{"type":27,"value":1965},{"type":21,"tag":512,"props":11527,"children":11528},{"style":686},[11529],{"type":27,"value":10758},{"type":21,"tag":512,"props":11531,"children":11532},{"style":815},[11533],{"type":27,"value":1965},{"type":21,"tag":512,"props":11535,"children":11536},{"style":686},[11537],{"type":27,"value":10767},{"type":21,"tag":512,"props":11539,"children":11540},{"style":815},[11541],{"type":27,"value":828},{"type":21,"tag":512,"props":11543,"children":11544},{"style":809},[11545],{"type":27,"value":833},{"type":21,"tag":512,"props":11547,"children":11548},{"style":815},[11549],{"type":27,"value":11550}," mod;\n",{"type":21,"tag":512,"props":11552,"children":11553},{"class":514,"line":673},[11554,11558,11562],{"type":21,"tag":512,"props":11555,"children":11556},{"style":815},[11557],{"type":27,"value":7125},{"type":21,"tag":512,"props":11559,"children":11560},{"style":519},[11561],{"type":27,"value":966},{"type":21,"tag":512,"props":11563,"children":11564},{"style":815},[11565],{"type":27,"value":10815},{"type":21,"tag":512,"props":11567,"children":11568},{"class":514,"line":900},[11569,11573,11577],{"type":21,"tag":512,"props":11570,"children":11571},{"style":815},[11572],{"type":27,"value":7125},{"type":21,"tag":512,"props":11574,"children":11575},{"style":519},[11576],{"type":27,"value":966},{"type":21,"tag":512,"props":11578,"children":11579},{"style":815},[11580],{"type":27,"value":10831},{"type":21,"tag":512,"props":11582,"children":11583},{"class":514,"line":908},[11584,11588,11592,11596,11600],{"type":21,"tag":512,"props":11585,"children":11586},{"style":815},[11587],{"type":27,"value":7125},{"type":21,"tag":512,"props":11589,"children":11590},{"style":519},[11591],{"type":27,"value":966},{"type":21,"tag":512,"props":11593,"children":11594},{"style":815},[11595],{"type":27,"value":843},{"type":21,"tag":512,"props":11597,"children":11598},{"style":519},[11599],{"type":27,"value":10767},{"type":21,"tag":512,"props":11601,"children":11602},{"style":815},[11603],{"type":27,"value":2165},{"type":21,"tag":512,"props":11605,"children":11606},{"class":514,"line":955},[11607],{"type":21,"tag":512,"props":11608,"children":11609},{"style":815},[11610],{"type":27,"value":1053},{"type":21,"tag":512,"props":11612,"children":11613},{"class":514,"line":983},[11614],{"type":21,"tag":512,"props":11615,"children":11616},{"emptyLinePlaceholder":859},[11617],{"type":27,"value":862},{"type":21,"tag":512,"props":11619,"children":11620},{"class":514,"line":991},[11621,11626],{"type":21,"tag":512,"props":11622,"children":11623},{"style":519},[11624],{"type":27,"value":11625},"main",{"type":21,"tag":512,"props":11627,"children":11628},{"style":815},[11629],{"type":27,"value":952},{"type":21,"tag":295,"props":11631,"children":11632},{"start":673},[11633],{"type":21,"tag":79,"props":11634,"children":11635},{},[11636],{"type":27,"value":11637},"成功输出：",{"type":21,"tag":501,"props":11639,"children":11641},{"className":634,"code":11640,"language":636,"meta":8,"style":8},"1\n2\n3\n",[11642],{"type":21,"tag":508,"props":11643,"children":11644},{"__ignoreMap":8},[11645,11652,11660],{"type":21,"tag":512,"props":11646,"children":11647},{"class":514,"line":515},[11648],{"type":21,"tag":512,"props":11649,"children":11650},{"style":519},[11651],{"type":27,"value":5771},{"type":21,"tag":512,"props":11653,"children":11654},{"class":514,"line":359},[11655],{"type":21,"tag":512,"props":11656,"children":11657},{"style":519},[11658],{"type":27,"value":11659},"2\n",{"type":21,"tag":512,"props":11661,"children":11662},{"class":514,"line":365},[11663],{"type":21,"tag":512,"props":11664,"children":11665},{"style":519},[11666],{"type":27,"value":11667},"3\n",{"type":21,"tag":29,"props":11669,"children":11670},{},[11671,11673,11679],{"type":27,"value":11672},"第二种：在文件同级或者父级目录加一个",{"type":21,"tag":508,"props":11674,"children":11676},{"className":11675},[],[11677],{"type":27,"value":11678},"package.json",{"type":27,"value":11680},"文件，并且加上\"type\"字段，值为\"module\"。",{"type":21,"tag":29,"props":11682,"children":11683},{},[11684,11686,11691,11692,11697],{"type":27,"value":11685},"为了让",{"type":21,"tag":508,"props":11687,"children":11689},{"className":11688},[],[11690],{"type":27,"value":10718},{"type":27,"value":10346},{"type":21,"tag":508,"props":11693,"children":11695},{"className":11694},[],[11696],{"type":27,"value":10580},{"type":27,"value":11698},"分别识别成正确的规范。我们改造成下图的结构：",{"type":21,"tag":29,"props":11700,"children":11701},{},[11702],{"type":21,"tag":459,"props":11703,"children":11706},{"alt":11704,"src":11705},"Pasted image 20230605180856","https://johnhom-img.oss-cn-guangzhou.aliyuncs.com/images/Pasted%20image%2020230605180856.png",[],{"type":21,"tag":29,"props":11708,"children":11709},{},[11710,11712,11718,11720,11725,11727,11732],{"type":27,"value":11711},"其中",{"type":21,"tag":508,"props":11713,"children":11715},{"className":11714},[],[11716],{"type":27,"value":11717},"lib/package.json",{"type":27,"value":11719},"的文件内容如下，这样",{"type":21,"tag":508,"props":11721,"children":11723},{"className":11722},[],[11724],{"type":27,"value":10580},{"type":27,"value":11726},"就会被识别成",{"type":21,"tag":508,"props":11728,"children":11730},{"className":11729},[],[11731],{"type":27,"value":10329},{"type":27,"value":11733},"模块。",{"type":21,"tag":501,"props":11735,"children":11739},{"className":11736,"code":11737,"language":11738,"meta":8,"style":8},"language-json shiki shiki-themes github-dark","// lib/package.json\n{\n  \"type\": \"module\"\n}\n","json",[11740],{"type":21,"tag":508,"props":11741,"children":11742},{"__ignoreMap":8},[11743,11751,11759,11777],{"type":21,"tag":512,"props":11744,"children":11745},{"class":514,"line":515},[11746],{"type":21,"tag":512,"props":11747,"children":11748},{"style":646},[11749],{"type":27,"value":11750},"// lib/package.json\n",{"type":21,"tag":512,"props":11752,"children":11753},{"class":514,"line":359},[11754],{"type":21,"tag":512,"props":11755,"children":11756},{"style":815},[11757],{"type":27,"value":11758},"{\n",{"type":21,"tag":512,"props":11760,"children":11761},{"class":514,"line":365},[11762,11767,11772],{"type":21,"tag":512,"props":11763,"children":11764},{"style":686},[11765],{"type":27,"value":11766},"  \"type\"",{"type":21,"tag":512,"props":11768,"children":11769},{"style":815},[11770],{"type":27,"value":11771},": ",{"type":21,"tag":512,"props":11773,"children":11774},{"style":525},[11775],{"type":27,"value":11776},"\"module\"\n",{"type":21,"tag":512,"props":11778,"children":11779},{"class":514,"line":673},[11780],{"type":21,"tag":512,"props":11781,"children":11782},{"style":815},[11783],{"type":27,"value":1053},{"type":21,"tag":29,"props":11785,"children":11786},{},[11787,11789,11794,11796,11801],{"type":27,"value":11788},"然后",{"type":21,"tag":508,"props":11790,"children":11792},{"className":11791},[],[11793],{"type":27,"value":10718},{"type":27,"value":11795},"文件导入",{"type":21,"tag":508,"props":11797,"children":11799},{"className":11798},[],[11800],{"type":27,"value":10580},{"type":27,"value":11802},"我们可以改写成：",{"type":21,"tag":501,"props":11804,"children":11806},{"className":2762,"code":11805,"language":2764,"meta":8,"style":8},"// cjs.js\nasync function main() {\n  // 这里改成导入./lib/esm.js 注意看后缀是 .js\n  const mod = await import('./lib/esm.js');\n  const { a, b, foo } = mod;\n  console.log(a);\n  console.log(b);\n  console.log(foo());\n}\n\nmain();\n",[11807],{"type":21,"tag":508,"props":11808,"children":11809},{"__ignoreMap":8},[11810,11817,11836,11844,11880,11923,11938,11953,11976,11983,11990],{"type":21,"tag":512,"props":11811,"children":11812},{"class":514,"line":515},[11813],{"type":21,"tag":512,"props":11814,"children":11815},{"style":646},[11816],{"type":27,"value":10734},{"type":21,"tag":512,"props":11818,"children":11819},{"class":514,"line":359},[11820,11824,11828,11832],{"type":21,"tag":512,"props":11821,"children":11822},{"style":809},[11823],{"type":27,"value":2858},{"type":21,"tag":512,"props":11825,"children":11826},{"style":809},[11827],{"type":27,"value":3483},{"type":21,"tag":512,"props":11829,"children":11830},{"style":519},[11831],{"type":27,"value":11465},{"type":21,"tag":512,"props":11833,"children":11834},{"style":815},[11835],{"type":27,"value":6611},{"type":21,"tag":512,"props":11837,"children":11838},{"class":514,"line":365},[11839],{"type":21,"tag":512,"props":11840,"children":11841},{"style":646},[11842],{"type":27,"value":11843},"  // 这里改成导入./lib/esm.js 注意看后缀是 .js\n",{"type":21,"tag":512,"props":11845,"children":11846},{"class":514,"line":673},[11847,11851,11855,11859,11863,11867,11871,11876],{"type":21,"tag":512,"props":11848,"children":11849},{"style":809},[11850],{"type":27,"value":7904},{"type":21,"tag":512,"props":11852,"children":11853},{"style":686},[11854],{"type":27,"value":11481},{"type":21,"tag":512,"props":11856,"children":11857},{"style":809},[11858],{"type":27,"value":887},{"type":21,"tag":512,"props":11860,"children":11861},{"style":809},[11862],{"type":27,"value":11490},{"type":21,"tag":512,"props":11864,"children":11865},{"style":809},[11866],{"type":27,"value":11358},{"type":21,"tag":512,"props":11868,"children":11869},{"style":815},[11870],{"type":27,"value":843},{"type":21,"tag":512,"props":11872,"children":11873},{"style":525},[11874],{"type":27,"value":11875},"'./lib/esm.js'",{"type":21,"tag":512,"props":11877,"children":11878},{"style":815},[11879],{"type":27,"value":853},{"type":21,"tag":512,"props":11881,"children":11882},{"class":514,"line":900},[11883,11887,11891,11895,11899,11903,11907,11911,11915,11919],{"type":21,"tag":512,"props":11884,"children":11885},{"style":809},[11886],{"type":27,"value":7904},{"type":21,"tag":512,"props":11888,"children":11889},{"style":815},[11890],{"type":27,"value":818},{"type":21,"tag":512,"props":11892,"children":11893},{"style":686},[11894],{"type":27,"value":445},{"type":21,"tag":512,"props":11896,"children":11897},{"style":815},[11898],{"type":27,"value":1965},{"type":21,"tag":512,"props":11900,"children":11901},{"style":686},[11902],{"type":27,"value":10758},{"type":21,"tag":512,"props":11904,"children":11905},{"style":815},[11906],{"type":27,"value":1965},{"type":21,"tag":512,"props":11908,"children":11909},{"style":686},[11910],{"type":27,"value":10767},{"type":21,"tag":512,"props":11912,"children":11913},{"style":815},[11914],{"type":27,"value":828},{"type":21,"tag":512,"props":11916,"children":11917},{"style":809},[11918],{"type":27,"value":833},{"type":21,"tag":512,"props":11920,"children":11921},{"style":815},[11922],{"type":27,"value":11550},{"type":21,"tag":512,"props":11924,"children":11925},{"class":514,"line":908},[11926,11930,11934],{"type":21,"tag":512,"props":11927,"children":11928},{"style":815},[11929],{"type":27,"value":7125},{"type":21,"tag":512,"props":11931,"children":11932},{"style":519},[11933],{"type":27,"value":966},{"type":21,"tag":512,"props":11935,"children":11936},{"style":815},[11937],{"type":27,"value":10815},{"type":21,"tag":512,"props":11939,"children":11940},{"class":514,"line":955},[11941,11945,11949],{"type":21,"tag":512,"props":11942,"children":11943},{"style":815},[11944],{"type":27,"value":7125},{"type":21,"tag":512,"props":11946,"children":11947},{"style":519},[11948],{"type":27,"value":966},{"type":21,"tag":512,"props":11950,"children":11951},{"style":815},[11952],{"type":27,"value":10831},{"type":21,"tag":512,"props":11954,"children":11955},{"class":514,"line":983},[11956,11960,11964,11968,11972],{"type":21,"tag":512,"props":11957,"children":11958},{"style":815},[11959],{"type":27,"value":7125},{"type":21,"tag":512,"props":11961,"children":11962},{"style":519},[11963],{"type":27,"value":966},{"type":21,"tag":512,"props":11965,"children":11966},{"style":815},[11967],{"type":27,"value":843},{"type":21,"tag":512,"props":11969,"children":11970},{"style":519},[11971],{"type":27,"value":10767},{"type":21,"tag":512,"props":11973,"children":11974},{"style":815},[11975],{"type":27,"value":2165},{"type":21,"tag":512,"props":11977,"children":11978},{"class":514,"line":991},[11979],{"type":21,"tag":512,"props":11980,"children":11981},{"style":815},[11982],{"type":27,"value":1053},{"type":21,"tag":512,"props":11984,"children":11985},{"class":514,"line":1015},[11986],{"type":21,"tag":512,"props":11987,"children":11988},{"emptyLinePlaceholder":859},[11989],{"type":27,"value":862},{"type":21,"tag":512,"props":11991,"children":11992},{"class":514,"line":1047},[11993,11997],{"type":21,"tag":512,"props":11994,"children":11995},{"style":519},[11996],{"type":27,"value":11625},{"type":21,"tag":512,"props":11998,"children":11999},{"style":815},[12000],{"type":27,"value":952},{"type":21,"tag":29,"props":12002,"children":12003},{},[12004,12006,12012],{"type":27,"value":12005},"最后运行命令：",{"type":21,"tag":508,"props":12007,"children":12009},{"className":12008},[],[12010],{"type":27,"value":12011},"node ./cjs.js",{"type":27,"value":12013},"，成功！！！",{"type":21,"tag":501,"props":12015,"children":12016},{"className":634,"code":11640,"language":636,"meta":8,"style":8},[12017],{"type":21,"tag":508,"props":12018,"children":12019},{"__ignoreMap":8},[12020,12027,12034],{"type":21,"tag":512,"props":12021,"children":12022},{"class":514,"line":515},[12023],{"type":21,"tag":512,"props":12024,"children":12025},{"style":519},[12026],{"type":27,"value":5771},{"type":21,"tag":512,"props":12028,"children":12029},{"class":514,"line":359},[12030],{"type":21,"tag":512,"props":12031,"children":12032},{"style":519},[12033],{"type":27,"value":11659},{"type":21,"tag":512,"props":12035,"children":12036},{"class":514,"line":365},[12037],{"type":21,"tag":512,"props":12038,"children":12039},{"style":519},[12040],{"type":27,"value":11667},{"type":21,"tag":29,"props":12042,"children":12043},{},[12044,12046,12051,12053,12058],{"type":27,"value":12045},"经过以上的实验，我们了解到Node.js的底层机制已经支持",{"type":21,"tag":508,"props":12047,"children":12049},{"className":12048},[],[12050],{"type":27,"value":10321},{"type":27,"value":12052},"模块导入",{"type":21,"tag":508,"props":12054,"children":12056},{"className":12055},[],[12057],{"type":27,"value":10329},{"type":27,"value":12059},"模块，不过需要注意以下的几个点：",{"type":21,"tag":75,"props":12061,"children":12062},{},[12063,12106],{"type":21,"tag":79,"props":12064,"children":12065},{},[12066,12068,12074,12076,12081,12083,12089,12091,12096,12098,12104],{"type":27,"value":12067},"根据",{"type":21,"tag":508,"props":12069,"children":12071},{"className":12070},[],[12072],{"type":27,"value":12073},"Determining Module System",{"type":27,"value":12075},"机制,需要修改",{"type":21,"tag":508,"props":12077,"children":12079},{"className":12078},[],[12080],{"type":27,"value":10329},{"type":27,"value":12082},"模块的文件后缀名为",{"type":21,"tag":508,"props":12084,"children":12086},{"className":12085},[],[12087],{"type":27,"value":12088},".mjs",{"type":27,"value":12090},"或者通过",{"type":21,"tag":508,"props":12092,"children":12094},{"className":12093},[],[12095],{"type":27,"value":11678},{"type":27,"value":12097},"加上",{"type":21,"tag":508,"props":12099,"children":12101},{"className":12100},[],[12102],{"type":27,"value":12103},"\"type\": \"module\"",{"type":27,"value":12105},"字段。",{"type":21,"tag":79,"props":12107,"children":12108},{},[12109,12114,12116,12121,12123,12128],{"type":21,"tag":508,"props":12110,"children":12112},{"className":12111},[],[12113],{"type":27,"value":10321},{"type":27,"value":12115},"只能通过",{"type":21,"tag":508,"props":12117,"children":12119},{"className":12118},[],[12120],{"type":27,"value":11426},{"type":27,"value":12122},"函数的方式导入",{"type":21,"tag":508,"props":12124,"children":12126},{"className":12125},[],[12127],{"type":27,"value":10329},{"type":27,"value":11733},{"type":21,"tag":41,"props":12130,"children":12132},{"id":12131},"esm导入cjs模块",[12133],{"type":27,"value":12134},"ESM导入CJS模块",{"type":21,"tag":29,"props":12136,"children":12137},{},[12138,12139,12144,12145,12150,12152,12157,12158,12163,12165,12170],{"type":27,"value":10503},{"type":21,"tag":508,"props":12140,"children":12142},{"className":12141},[],[12143],{"type":27,"value":10329},{"type":27,"value":10510},{"type":21,"tag":508,"props":12146,"children":12148},{"className":12147},[],[12149],{"type":27,"value":10516},{"type":27,"value":12151},"，在此之前，想要在node中使用",{"type":21,"tag":508,"props":12153,"children":12155},{"className":12154},[],[12156],{"type":27,"value":10329},{"type":27,"value":10525},{"type":21,"tag":508,"props":12159,"children":12161},{"className":12160},[],[12162],{"type":27,"value":10531},{"type":27,"value":12164},"参数。在",{"type":21,"tag":508,"props":12166,"children":12168},{"className":12167},[],[12169],{"type":27,"value":10516},{"type":27,"value":10540},{"type":21,"tag":29,"props":12172,"children":12173},{},[12174],{"type":27,"value":12175},"首先新建一个文件夹，结构如下：",{"type":21,"tag":29,"props":12177,"children":12178},{},[12179],{"type":21,"tag":459,"props":12180,"children":12183},{"alt":12181,"src":12182},"Pasted image 20230605182410","https://johnhom-img.oss-cn-guangzhou.aliyuncs.com/images/Pasted%20image%2020230605182410.png",[],{"type":21,"tag":295,"props":12185,"children":12186},{},[12187],{"type":21,"tag":79,"props":12188,"children":12189},{},[12190,12192,12197,12199,12205],{"type":27,"value":12191},"编辑根目录下的",{"type":21,"tag":508,"props":12193,"children":12195},{"className":12194},[],[12196],{"type":27,"value":11678},{"type":27,"value":12198},"文件，加上",{"type":21,"tag":508,"props":12200,"children":12202},{"className":12201},[],[12203],{"type":27,"value":12204},"type",{"type":27,"value":12206},"字段，值为\"module\"，如下所示：",{"type":21,"tag":501,"props":12208,"children":12210},{"className":11736,"code":12209,"language":11738,"meta":8,"style":8},"// package.json\n{\n  ...,\n  \"type\": \"module\",\n  ...,\n}\n",[12211],{"type":21,"tag":508,"props":12212,"children":12213},{"__ignoreMap":8},[12214,12222,12229,12238,12258,12265],{"type":21,"tag":512,"props":12215,"children":12216},{"class":514,"line":515},[12217],{"type":21,"tag":512,"props":12218,"children":12219},{"style":646},[12220],{"type":27,"value":12221},"// package.json\n",{"type":21,"tag":512,"props":12223,"children":12224},{"class":514,"line":359},[12225],{"type":21,"tag":512,"props":12226,"children":12227},{"style":815},[12228],{"type":27,"value":11758},{"type":21,"tag":512,"props":12230,"children":12231},{"class":514,"line":365},[12232],{"type":21,"tag":512,"props":12233,"children":12235},{"style":12234},"--shiki-default:#FDAEB7;--shiki-default-font-style:italic",[12236],{"type":27,"value":12237},"  ...,\n",{"type":21,"tag":512,"props":12239,"children":12240},{"class":514,"line":673},[12241,12245,12249,12254],{"type":21,"tag":512,"props":12242,"children":12243},{"style":686},[12244],{"type":27,"value":11766},{"type":21,"tag":512,"props":12246,"children":12247},{"style":815},[12248],{"type":27,"value":11771},{"type":21,"tag":512,"props":12250,"children":12251},{"style":525},[12252],{"type":27,"value":12253},"\"module\"",{"type":21,"tag":512,"props":12255,"children":12256},{"style":815},[12257],{"type":27,"value":2440},{"type":21,"tag":512,"props":12259,"children":12260},{"class":514,"line":900},[12261],{"type":21,"tag":512,"props":12262,"children":12263},{"style":12234},[12264],{"type":27,"value":12237},{"type":21,"tag":512,"props":12266,"children":12267},{"class":514,"line":908},[12268],{"type":21,"tag":512,"props":12269,"children":12270},{"style":815},[12271],{"type":27,"value":1053},{"type":21,"tag":29,"props":12273,"children":12274},{},[12275,12277,12282,12284,12289],{"type":27,"value":12276},"这样",{"type":21,"tag":508,"props":12278,"children":12280},{"className":12279},[],[12281],{"type":27,"value":10580},{"type":27,"value":12283},"就会被当做",{"type":21,"tag":508,"props":12285,"children":12287},{"className":12286},[],[12288],{"type":27,"value":10329},{"type":27,"value":12290},"模块处理。",{"type":21,"tag":295,"props":12292,"children":12293},{"start":359},[12294],{"type":21,"tag":79,"props":12295,"children":12296},{},[12297,12299,12304],{"type":27,"value":12298},"编辑",{"type":21,"tag":508,"props":12300,"children":12302},{"className":12301},[],[12303],{"type":27,"value":11717},{"type":27,"value":12305},"，内容如下：",{"type":21,"tag":501,"props":12307,"children":12309},{"className":11736,"code":12308,"language":11738,"meta":8,"style":8},"// lib/package.json\n{\n    // 或者可以加上\"type\": \"commonjs\"\n}\n",[12310],{"type":21,"tag":508,"props":12311,"children":12312},{"__ignoreMap":8},[12313,12320,12327,12335],{"type":21,"tag":512,"props":12314,"children":12315},{"class":514,"line":515},[12316],{"type":21,"tag":512,"props":12317,"children":12318},{"style":646},[12319],{"type":27,"value":11750},{"type":21,"tag":512,"props":12321,"children":12322},{"class":514,"line":359},[12323],{"type":21,"tag":512,"props":12324,"children":12325},{"style":815},[12326],{"type":27,"value":11758},{"type":21,"tag":512,"props":12328,"children":12329},{"class":514,"line":365},[12330],{"type":21,"tag":512,"props":12331,"children":12332},{"style":646},[12333],{"type":27,"value":12334},"    // 或者可以加上\"type\": \"commonjs\"\n",{"type":21,"tag":512,"props":12336,"children":12337},{"class":514,"line":673},[12338],{"type":21,"tag":512,"props":12339,"children":12340},{"style":815},[12341],{"type":27,"value":1053},{"type":21,"tag":295,"props":12343,"children":12344},{"start":365},[12345],{"type":21,"tag":79,"props":12346,"children":12347},{},[12348,12353,12354,12359],{"type":21,"tag":508,"props":12349,"children":12351},{"className":12350},[],[12352],{"type":27,"value":10580},{"type":27,"value":10346},{"type":21,"tag":508,"props":12355,"children":12357},{"className":12356},[],[12358],{"type":27,"value":10718},{"type":27,"value":12360},"文件内容分别为：",{"type":21,"tag":501,"props":12362,"children":12364},{"className":2762,"code":12363,"language":2764,"meta":8,"style":8},"// ./lib/cjs.js\nmodule.exports = {\n  a: 1,\n  b: 2,\n  foo: function () {\n    return 3\n  }\n}\n\n// esm.js\nimport pkg from './lib/cjs.js'\n\nconst { a, b, foo} = pkg;\n\nconsole.log(a);\nconsole.log(b);\nconsole.log(foo());\n\n",[12365],{"type":21,"tag":508,"props":12366,"children":12367},{"__ignoreMap":8},[12368,12376,12401,12417,12433,12453,12465,12472,12479,12486,12493,12514,12521,12566,12573,12588,12603],{"type":21,"tag":512,"props":12369,"children":12370},{"class":514,"line":515},[12371],{"type":21,"tag":512,"props":12372,"children":12373},{"style":646},[12374],{"type":27,"value":12375},"// ./lib/cjs.js\n",{"type":21,"tag":512,"props":12377,"children":12378},{"class":514,"line":359},[12379,12384,12388,12393,12397],{"type":21,"tag":512,"props":12380,"children":12381},{"style":686},[12382],{"type":27,"value":12383},"module",{"type":21,"tag":512,"props":12385,"children":12386},{"style":815},[12387],{"type":27,"value":5863},{"type":21,"tag":512,"props":12389,"children":12390},{"style":686},[12391],{"type":27,"value":12392},"exports",{"type":21,"tag":512,"props":12394,"children":12395},{"style":809},[12396],{"type":27,"value":887},{"type":21,"tag":512,"props":12398,"children":12399},{"style":815},[12400],{"type":27,"value":1067},{"type":21,"tag":512,"props":12402,"children":12403},{"class":514,"line":365},[12404,12409,12413],{"type":21,"tag":512,"props":12405,"children":12406},{"style":815},[12407],{"type":27,"value":12408},"  a: ",{"type":21,"tag":512,"props":12410,"children":12411},{"style":686},[12412],{"type":27,"value":4063},{"type":21,"tag":512,"props":12414,"children":12415},{"style":815},[12416],{"type":27,"value":2440},{"type":21,"tag":512,"props":12418,"children":12419},{"class":514,"line":673},[12420,12425,12429],{"type":21,"tag":512,"props":12421,"children":12422},{"style":815},[12423],{"type":27,"value":12424},"  b: ",{"type":21,"tag":512,"props":12426,"children":12427},{"style":686},[12428],{"type":27,"value":4833},{"type":21,"tag":512,"props":12430,"children":12431},{"style":815},[12432],{"type":27,"value":2440},{"type":21,"tag":512,"props":12434,"children":12435},{"class":514,"line":900},[12436,12441,12445,12449],{"type":21,"tag":512,"props":12437,"children":12438},{"style":519},[12439],{"type":27,"value":12440},"  foo",{"type":21,"tag":512,"props":12442,"children":12443},{"style":815},[12444],{"type":27,"value":11771},{"type":21,"tag":512,"props":12446,"children":12447},{"style":809},[12448],{"type":27,"value":4123},{"type":21,"tag":512,"props":12450,"children":12451},{"style":815},[12452],{"type":27,"value":10675},{"type":21,"tag":512,"props":12454,"children":12455},{"class":514,"line":908},[12456,12460],{"type":21,"tag":512,"props":12457,"children":12458},{"style":809},[12459],{"type":27,"value":2945},{"type":21,"tag":512,"props":12461,"children":12462},{"style":686},[12463],{"type":27,"value":12464}," 3\n",{"type":21,"tag":512,"props":12466,"children":12467},{"class":514,"line":955},[12468],{"type":21,"tag":512,"props":12469,"children":12470},{"style":815},[12471],{"type":27,"value":2957},{"type":21,"tag":512,"props":12473,"children":12474},{"class":514,"line":983},[12475],{"type":21,"tag":512,"props":12476,"children":12477},{"style":815},[12478],{"type":27,"value":1053},{"type":21,"tag":512,"props":12480,"children":12481},{"class":514,"line":991},[12482],{"type":21,"tag":512,"props":12483,"children":12484},{"emptyLinePlaceholder":859},[12485],{"type":27,"value":862},{"type":21,"tag":512,"props":12487,"children":12488},{"class":514,"line":1015},[12489],{"type":21,"tag":512,"props":12490,"children":12491},{"style":646},[12492],{"type":27,"value":10597},{"type":21,"tag":512,"props":12494,"children":12495},{"class":514,"line":1047},[12496,12500,12505,12509],{"type":21,"tag":512,"props":12497,"children":12498},{"style":809},[12499],{"type":27,"value":8800},{"type":21,"tag":512,"props":12501,"children":12502},{"style":815},[12503],{"type":27,"value":12504}," pkg ",{"type":21,"tag":512,"props":12506,"children":12507},{"style":809},[12508],{"type":27,"value":8810},{"type":21,"tag":512,"props":12510,"children":12511},{"style":525},[12512],{"type":27,"value":12513}," './lib/cjs.js'\n",{"type":21,"tag":512,"props":12515,"children":12516},{"class":514,"line":1056},[12517],{"type":21,"tag":512,"props":12518,"children":12519},{"emptyLinePlaceholder":859},[12520],{"type":27,"value":862},{"type":21,"tag":512,"props":12522,"children":12523},{"class":514,"line":1070},[12524,12528,12532,12536,12540,12544,12548,12552,12557,12561],{"type":21,"tag":512,"props":12525,"children":12526},{"style":809},[12527],{"type":27,"value":812},{"type":21,"tag":512,"props":12529,"children":12530},{"style":815},[12531],{"type":27,"value":818},{"type":21,"tag":512,"props":12533,"children":12534},{"style":686},[12535],{"type":27,"value":445},{"type":21,"tag":512,"props":12537,"children":12538},{"style":815},[12539],{"type":27,"value":1965},{"type":21,"tag":512,"props":12541,"children":12542},{"style":686},[12543],{"type":27,"value":10758},{"type":21,"tag":512,"props":12545,"children":12546},{"style":815},[12547],{"type":27,"value":1965},{"type":21,"tag":512,"props":12549,"children":12550},{"style":686},[12551],{"type":27,"value":10767},{"type":21,"tag":512,"props":12553,"children":12554},{"style":815},[12555],{"type":27,"value":12556},"} ",{"type":21,"tag":512,"props":12558,"children":12559},{"style":809},[12560],{"type":27,"value":833},{"type":21,"tag":512,"props":12562,"children":12563},{"style":815},[12564],{"type":27,"value":12565}," pkg;\n",{"type":21,"tag":512,"props":12567,"children":12568},{"class":514,"line":1079},[12569],{"type":21,"tag":512,"props":12570,"children":12571},{"emptyLinePlaceholder":859},[12572],{"type":27,"value":862},{"type":21,"tag":512,"props":12574,"children":12575},{"class":514,"line":1317},[12576,12580,12584],{"type":21,"tag":512,"props":12577,"children":12578},{"style":815},[12579],{"type":27,"value":961},{"type":21,"tag":512,"props":12581,"children":12582},{"style":519},[12583],{"type":27,"value":966},{"type":21,"tag":512,"props":12585,"children":12586},{"style":815},[12587],{"type":27,"value":10815},{"type":21,"tag":512,"props":12589,"children":12590},{"class":514,"line":1326},[12591,12595,12599],{"type":21,"tag":512,"props":12592,"children":12593},{"style":815},[12594],{"type":27,"value":961},{"type":21,"tag":512,"props":12596,"children":12597},{"style":519},[12598],{"type":27,"value":966},{"type":21,"tag":512,"props":12600,"children":12601},{"style":815},[12602],{"type":27,"value":10831},{"type":21,"tag":512,"props":12604,"children":12605},{"class":514,"line":1678},[12606,12610,12614,12618,12622],{"type":21,"tag":512,"props":12607,"children":12608},{"style":815},[12609],{"type":27,"value":961},{"type":21,"tag":512,"props":12611,"children":12612},{"style":519},[12613],{"type":27,"value":966},{"type":21,"tag":512,"props":12615,"children":12616},{"style":815},[12617],{"type":27,"value":843},{"type":21,"tag":512,"props":12619,"children":12620},{"style":519},[12621],{"type":27,"value":10767},{"type":21,"tag":512,"props":12623,"children":12624},{"style":815},[12625],{"type":27,"value":2165},{"type":21,"tag":295,"props":12627,"children":12628},{"start":673},[12629],{"type":21,"tag":79,"props":12630,"children":12631},{},[12632,12633,12639],{"type":27,"value":10862},{"type":21,"tag":508,"props":12634,"children":12636},{"className":12635},[],[12637],{"type":27,"value":12638},"node esm.js",{"type":27,"value":12640},"，输出了以下信息：",{"type":21,"tag":501,"props":12642,"children":12643},{"className":634,"code":11640,"language":636,"meta":8,"style":8},[12644],{"type":21,"tag":508,"props":12645,"children":12646},{"__ignoreMap":8},[12647,12654,12661],{"type":21,"tag":512,"props":12648,"children":12649},{"class":514,"line":515},[12650],{"type":21,"tag":512,"props":12651,"children":12652},{"style":519},[12653],{"type":27,"value":5771},{"type":21,"tag":512,"props":12655,"children":12656},{"class":514,"line":359},[12657],{"type":21,"tag":512,"props":12658,"children":12659},{"style":519},[12660],{"type":27,"value":11659},{"type":21,"tag":512,"props":12662,"children":12663},{"class":514,"line":365},[12664],{"type":21,"tag":512,"props":12665,"children":12666},{"style":519},[12667],{"type":27,"value":11667},{"type":21,"tag":29,"props":12669,"children":12670},{},[12671,12676,12678,12683],{"type":21,"tag":508,"props":12672,"children":12674},{"className":12673},[],[12675],{"type":27,"value":10329},{"type":27,"value":12677},"成功引入",{"type":21,"tag":508,"props":12679,"children":12681},{"className":12680},[],[12682],{"type":27,"value":10321},{"type":27,"value":12684},"模块!!!",{"type":21,"tag":29,"props":12686,"children":12687},{},[12688,12690,12695,12697,12702],{"type":27,"value":12689},"在Node.js中",{"type":21,"tag":508,"props":12691,"children":12693},{"className":12692},[],[12694],{"type":27,"value":10329},{"type":27,"value":12696},"模块是支持引入",{"type":21,"tag":508,"props":12698,"children":12700},{"className":12699},[],[12701],{"type":27,"value":10321},{"type":27,"value":12703},"模块的，但是注意以下几点：",{"type":21,"tag":75,"props":12705,"children":12706},{},[12707,12753],{"type":21,"tag":79,"props":12708,"children":12709},{},[12710,12712,12717,12719,12724,12726,12731,12732,12738,12740,12745,12746,12752],{"type":27,"value":12711},"为了让Node.js正确识别这是一个",{"type":21,"tag":508,"props":12713,"children":12715},{"className":12714},[],[12716],{"type":27,"value":10321},{"type":27,"value":12718},"模块，根据",{"type":21,"tag":508,"props":12720,"children":12722},{"className":12721},[],[12723],{"type":27,"value":12073},{"type":27,"value":12725},"机制，需要修改",{"type":21,"tag":508,"props":12727,"children":12729},{"className":12728},[],[12730],{"type":27,"value":10329},{"type":27,"value":12082},{"type":21,"tag":508,"props":12733,"children":12735},{"className":12734},[],[12736],{"type":27,"value":12737},".cjs",{"type":27,"value":12739},"，或者通过同级或者最近父级文件夹下的",{"type":21,"tag":508,"props":12741,"children":12743},{"className":12742},[],[12744],{"type":27,"value":11678},{"type":27,"value":12097},{"type":21,"tag":508,"props":12747,"children":12749},{"className":12748},[],[12750],{"type":27,"value":12751},"\"type\": \"commonjs\"",{"type":27,"value":12105},{"type":21,"tag":79,"props":12754,"children":12755},{},[12756,12758,12763,12765,12770,12772,12777,12778,12784],{"type":27,"value":12757},"转换时，",{"type":21,"tag":508,"props":12759,"children":12761},{"className":12760},[],[12762],{"type":27,"value":10321},{"type":27,"value":12764},"模块的",{"type":21,"tag":508,"props":12766,"children":12768},{"className":12767},[],[12769],{"type":27,"value":10391},{"type":27,"value":12771}," 与 ",{"type":21,"tag":508,"props":12773,"children":12775},{"className":12774},[],[12776],{"type":27,"value":10329},{"type":27,"value":12764},{"type":21,"tag":508,"props":12779,"children":12781},{"className":12780},[],[12782],{"type":27,"value":12783},"export default",{"type":27,"value":12785},"对应。",{"type":21,"tag":22,"props":12787,"children":12788},{"id":2624},[12789],{"type":27,"value":2624},{"type":21,"tag":29,"props":12791,"children":12792},{},[12793,12795,12800,12801,12806,12808,12814],{"type":27,"value":12794},"经过以上的章节，我们了解到",{"type":21,"tag":508,"props":12796,"children":12798},{"className":12797},[],[12799],{"type":27,"value":10321},{"type":27,"value":10346},{"type":21,"tag":508,"props":12802,"children":12804},{"className":12803},[],[12805],{"type":27,"value":10329},{"type":27,"value":12807},"模块各自的特点，也知道了Node.js的",{"type":21,"tag":445,"props":12809,"children":12812},{"href":12810,"rel":12811,"title":10997},"https://link.juejin.cn/?target=https%3A%2F%2Fnodejs.org%2Fdocs%2Flatest-v14.x%2Fapi%2Fpackages.html%23packages_determining_module_system",[449],[12813],{"type":27,"value":11001},{"type":27,"value":12815},"机制时是如何识别代码属于哪种模块，再通过不同的loader去转换代码。",{"type":21,"tag":29,"props":12817,"children":12818},{},[12819,12821,12826],{"type":27,"value":12820},"当你需要封装一些类库，引入不同规范依赖的时候也能够游刃有余地处理，也可以配合一些打包工具例如",{"type":21,"tag":508,"props":12822,"children":12824},{"className":12823},[],[12825],{"type":27,"value":10313},{"type":27,"value":12827},"的使用。",{"type":21,"tag":29,"props":12829,"children":12830},{},[12831,12833,12838,12840,12846,12848,12854,12856,12861,12863,12868],{"type":27,"value":12832},"原本两种模块规范是分别用在不同的端，但是由于",{"type":21,"tag":508,"props":12834,"children":12836},{"className":12835},[],[12837],{"type":27,"value":10329},{"type":27,"value":12839},"规范的异步加载优势，天生支持",{"type":21,"tag":508,"props":12841,"children":12843},{"className":12842},[],[12844],{"type":27,"value":12845},"Tree Shaking",{"type":27,"value":12847},"，以及各种JavaScript打包工具的流行，例如",{"type":21,"tag":508,"props":12849,"children":12851},{"className":12850},[],[12852],{"type":27,"value":12853},"Webpack",{"type":27,"value":12855},"，",{"type":21,"tag":508,"props":12857,"children":12859},{"className":12858},[],[12860],{"type":27,"value":10313},{"type":27,"value":12862},"等等，越来越多的开发者在封装各类工具库时使用",{"type":21,"tag":508,"props":12864,"children":12866},{"className":12865},[],[12867],{"type":27,"value":10329},{"type":27,"value":10441},{"type":21,"tag":29,"props":12870,"children":12871},{},[12872,12874,12879,12881,12886,12888,12893,12895,12900],{"type":27,"value":12873},"后面我将会写一篇文章讲解使用",{"type":21,"tag":508,"props":12875,"children":12877},{"className":12876},[],[12878],{"type":27,"value":10313},{"type":27,"value":12880},"工具的简单使用，来解决打包成",{"type":21,"tag":508,"props":12882,"children":12884},{"className":12883},[],[12885],{"type":27,"value":10321},{"type":27,"value":12887},"规范时处理",{"type":21,"tag":508,"props":12889,"children":12891},{"className":12890},[],[12892],{"type":27,"value":10329},{"type":27,"value":12894},"。不过也许在不远的将来，Node.js默认使用",{"type":21,"tag":508,"props":12896,"children":12898},{"className":12897},[],[12899],{"type":27,"value":10329},{"type":27,"value":12901},"规范执行js代码也说不定。",{"type":21,"tag":29,"props":12903,"children":12904},{},[12905],{"type":27,"value":12906},"感谢你阅读到这里，如有发现文章中存在错误的地方也请指正。",{"type":21,"tag":2671,"props":12908,"children":12909},{},[12910],{"type":27,"value":2675},{"title":8,"searchDepth":359,"depth":359,"links":12912},[12913,12914,12915,12919],{"id":24,"depth":359,"text":24},{"id":10372,"depth":359,"text":10375},{"id":10490,"depth":359,"text":10493,"children":12916},[12917,12918],{"id":10556,"depth":365,"text":10559},{"id":12131,"depth":365,"text":12134},{"id":2624,"depth":359,"text":2624},"content:articles:20240323.md","articles/20240323.md",{"_path":12923,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":12924,"description":8,"published":12925,"tags":12926,"slug":12924,"body":12929,"_type":376,"_id":13505,"_source":378,"_file":13506,"_extension":380},"/articles/20230506","docker内的容器走clash代理","2023/05/06",[12927,12928],"docker","proxy",{"type":18,"children":12930,"toc":13500},[12931,12936,12956,13136,13141,13149,13154,13159,13164,13169,13465,13470,13475,13483,13488,13496],{"type":21,"tag":22,"props":12932,"children":12934},{"id":12933},"容器内搭建clash",[12935],{"type":27,"value":12933},{"type":21,"tag":29,"props":12937,"children":12938},{},[12939,12941,12946,12948,12954],{"type":27,"value":12940},"首先使用",{"type":21,"tag":508,"props":12942,"children":12944},{"className":12943},[],[12945],{"type":27,"value":1198},{"type":27,"value":12947},"在docker内搭建一个",{"type":21,"tag":508,"props":12949,"children":12951},{"className":12950},[],[12952],{"type":27,"value":12953},"clash",{"type":27,"value":12955},"容器：",{"type":21,"tag":501,"props":12957,"children":12959},{"code":12958,"language":1107,"meta":8,"className":1105,"style":8},"version: '3.9'\nservices:\n  clash:\n    image: dreamacro/clash\n    container_name: clash\n    restart: always\n    ports:\n      - 7890:7890\n      - 7891:7891\n      - 9090:9090\n    volumes:\n      # 将配置文件挂载到容器中\n      - ./clash:/root/.config/clash\n",[12960],{"type":21,"tag":508,"props":12961,"children":12962},{"__ignoreMap":8},[12963,12980,12992,13004,13021,13038,13055,13067,13080,13092,13104,13116,13124],{"type":21,"tag":512,"props":12964,"children":12965},{"class":514,"line":515},[12966,12971,12975],{"type":21,"tag":512,"props":12967,"children":12968},{"style":1117},[12969],{"type":27,"value":12970},"version",{"type":21,"tag":512,"props":12972,"children":12973},{"style":815},[12974],{"type":27,"value":11771},{"type":21,"tag":512,"props":12976,"children":12977},{"style":525},[12978],{"type":27,"value":12979},"'3.9'\n",{"type":21,"tag":512,"props":12981,"children":12982},{"class":514,"line":359},[12983,12988],{"type":21,"tag":512,"props":12984,"children":12985},{"style":1117},[12986],{"type":27,"value":12987},"services",{"type":21,"tag":512,"props":12989,"children":12990},{"style":815},[12991],{"type":27,"value":1125},{"type":21,"tag":512,"props":12993,"children":12994},{"class":514,"line":365},[12995,13000],{"type":21,"tag":512,"props":12996,"children":12997},{"style":1117},[12998],{"type":27,"value":12999},"  clash",{"type":21,"tag":512,"props":13001,"children":13002},{"style":815},[13003],{"type":27,"value":1125},{"type":21,"tag":512,"props":13005,"children":13006},{"class":514,"line":673},[13007,13012,13016],{"type":21,"tag":512,"props":13008,"children":13009},{"style":1117},[13010],{"type":27,"value":13011},"    image",{"type":21,"tag":512,"props":13013,"children":13014},{"style":815},[13015],{"type":27,"value":11771},{"type":21,"tag":512,"props":13017,"children":13018},{"style":525},[13019],{"type":27,"value":13020},"dreamacro/clash\n",{"type":21,"tag":512,"props":13022,"children":13023},{"class":514,"line":900},[13024,13029,13033],{"type":21,"tag":512,"props":13025,"children":13026},{"style":1117},[13027],{"type":27,"value":13028},"    container_name",{"type":21,"tag":512,"props":13030,"children":13031},{"style":815},[13032],{"type":27,"value":11771},{"type":21,"tag":512,"props":13034,"children":13035},{"style":525},[13036],{"type":27,"value":13037},"clash\n",{"type":21,"tag":512,"props":13039,"children":13040},{"class":514,"line":908},[13041,13046,13050],{"type":21,"tag":512,"props":13042,"children":13043},{"style":1117},[13044],{"type":27,"value":13045},"    restart",{"type":21,"tag":512,"props":13047,"children":13048},{"style":815},[13049],{"type":27,"value":11771},{"type":21,"tag":512,"props":13051,"children":13052},{"style":525},[13053],{"type":27,"value":13054},"always\n",{"type":21,"tag":512,"props":13056,"children":13057},{"class":514,"line":955},[13058,13063],{"type":21,"tag":512,"props":13059,"children":13060},{"style":1117},[13061],{"type":27,"value":13062},"    ports",{"type":21,"tag":512,"props":13064,"children":13065},{"style":815},[13066],{"type":27,"value":1125},{"type":21,"tag":512,"props":13068,"children":13069},{"class":514,"line":983},[13070,13075],{"type":21,"tag":512,"props":13071,"children":13072},{"style":815},[13073],{"type":27,"value":13074},"      - ",{"type":21,"tag":512,"props":13076,"children":13077},{"style":525},[13078],{"type":27,"value":13079},"7890:7890\n",{"type":21,"tag":512,"props":13081,"children":13082},{"class":514,"line":991},[13083,13087],{"type":21,"tag":512,"props":13084,"children":13085},{"style":815},[13086],{"type":27,"value":13074},{"type":21,"tag":512,"props":13088,"children":13089},{"style":525},[13090],{"type":27,"value":13091},"7891:7891\n",{"type":21,"tag":512,"props":13093,"children":13094},{"class":514,"line":1015},[13095,13099],{"type":21,"tag":512,"props":13096,"children":13097},{"style":815},[13098],{"type":27,"value":13074},{"type":21,"tag":512,"props":13100,"children":13101},{"style":525},[13102],{"type":27,"value":13103},"9090:9090\n",{"type":21,"tag":512,"props":13105,"children":13106},{"class":514,"line":1047},[13107,13112],{"type":21,"tag":512,"props":13108,"children":13109},{"style":1117},[13110],{"type":27,"value":13111},"    volumes",{"type":21,"tag":512,"props":13113,"children":13114},{"style":815},[13115],{"type":27,"value":1125},{"type":21,"tag":512,"props":13117,"children":13118},{"class":514,"line":1056},[13119],{"type":21,"tag":512,"props":13120,"children":13121},{"style":646},[13122],{"type":27,"value":13123},"      # 将配置文件挂载到容器中\n",{"type":21,"tag":512,"props":13125,"children":13126},{"class":514,"line":1070},[13127,13131],{"type":21,"tag":512,"props":13128,"children":13129},{"style":815},[13130],{"type":27,"value":13074},{"type":21,"tag":512,"props":13132,"children":13133},{"style":525},[13134],{"type":27,"value":13135},"./clash:/root/.config/clash\n",{"type":21,"tag":29,"props":13137,"children":13138},{},[13139],{"type":27,"value":13140},"然后在docker-compose.yml文件所在的目录下，执行命令：",{"type":21,"tag":501,"props":13142,"children":13144},{"code":13143},"docker-compose up -d\n",[13145],{"type":21,"tag":508,"props":13146,"children":13147},{"__ignoreMap":8},[13148],{"type":27,"value":13143},{"type":21,"tag":29,"props":13150,"children":13151},{},[13152],{"type":27,"value":13153},"这样就简单搭建起来了一个代理服务器，clash的配置文件从./clash文件夹中读取，clash相关的教程这里就不提供啦。",{"type":21,"tag":22,"props":13155,"children":13157},{"id":13156},"搭建一个测试联通的容器",[13158],{"type":27,"value":13156},{"type":21,"tag":29,"props":13160,"children":13161},{},[13162],{"type":27,"value":13163},"确认clash可以代理本机的http请求之后呢，我们在docker中另外开一个容器，随便开一个，然后我们设置这个容器的http流量代理到clash容器中",{"type":21,"tag":29,"props":13165,"children":13166},{},[13167],{"type":27,"value":13168},"改写docker-compose.yml文件，改为以下的内容：",{"type":21,"tag":501,"props":13170,"children":13172},{"code":13171,"language":1107,"meta":8,"className":1105,"style":8},"version: '3.9'\nservices:\n  clash:\n    image: dreamacro/clash\n    container_name: clash\n    restart: always\n    ports:\n      - 7890:7890\n      - 7891:7891\n      - 9090:9090\n    volumes:\n      # 将配置文件挂载到容器中\n      - ./clash:/root/.config/clash\n  yacd:\n    image: ghcr.io/haishanh/yacd:master\n    container_name: yacd\n    restart: always\n    depends_on:\n      # 依赖于上面的clash服务，在clash启动后，web才启动\n      - clash\n    environment:\n      # 注意这里，这里会代理终端的http流量到clash容器的7890端口\n      - http_proxy=http://clash:7890\n      - https_proxy=http://clash:7890\n",[13173],{"type":21,"tag":508,"props":13174,"children":13175},{"__ignoreMap":8},[13176,13191,13202,13213,13228,13243,13258,13269,13280,13291,13302,13313,13320,13331,13343,13359,13375,13390,13402,13410,13421,13433,13441,13453],{"type":21,"tag":512,"props":13177,"children":13178},{"class":514,"line":515},[13179,13183,13187],{"type":21,"tag":512,"props":13180,"children":13181},{"style":1117},[13182],{"type":27,"value":12970},{"type":21,"tag":512,"props":13184,"children":13185},{"style":815},[13186],{"type":27,"value":11771},{"type":21,"tag":512,"props":13188,"children":13189},{"style":525},[13190],{"type":27,"value":12979},{"type":21,"tag":512,"props":13192,"children":13193},{"class":514,"line":359},[13194,13198],{"type":21,"tag":512,"props":13195,"children":13196},{"style":1117},[13197],{"type":27,"value":12987},{"type":21,"tag":512,"props":13199,"children":13200},{"style":815},[13201],{"type":27,"value":1125},{"type":21,"tag":512,"props":13203,"children":13204},{"class":514,"line":365},[13205,13209],{"type":21,"tag":512,"props":13206,"children":13207},{"style":1117},[13208],{"type":27,"value":12999},{"type":21,"tag":512,"props":13210,"children":13211},{"style":815},[13212],{"type":27,"value":1125},{"type":21,"tag":512,"props":13214,"children":13215},{"class":514,"line":673},[13216,13220,13224],{"type":21,"tag":512,"props":13217,"children":13218},{"style":1117},[13219],{"type":27,"value":13011},{"type":21,"tag":512,"props":13221,"children":13222},{"style":815},[13223],{"type":27,"value":11771},{"type":21,"tag":512,"props":13225,"children":13226},{"style":525},[13227],{"type":27,"value":13020},{"type":21,"tag":512,"props":13229,"children":13230},{"class":514,"line":900},[13231,13235,13239],{"type":21,"tag":512,"props":13232,"children":13233},{"style":1117},[13234],{"type":27,"value":13028},{"type":21,"tag":512,"props":13236,"children":13237},{"style":815},[13238],{"type":27,"value":11771},{"type":21,"tag":512,"props":13240,"children":13241},{"style":525},[13242],{"type":27,"value":13037},{"type":21,"tag":512,"props":13244,"children":13245},{"class":514,"line":908},[13246,13250,13254],{"type":21,"tag":512,"props":13247,"children":13248},{"style":1117},[13249],{"type":27,"value":13045},{"type":21,"tag":512,"props":13251,"children":13252},{"style":815},[13253],{"type":27,"value":11771},{"type":21,"tag":512,"props":13255,"children":13256},{"style":525},[13257],{"type":27,"value":13054},{"type":21,"tag":512,"props":13259,"children":13260},{"class":514,"line":955},[13261,13265],{"type":21,"tag":512,"props":13262,"children":13263},{"style":1117},[13264],{"type":27,"value":13062},{"type":21,"tag":512,"props":13266,"children":13267},{"style":815},[13268],{"type":27,"value":1125},{"type":21,"tag":512,"props":13270,"children":13271},{"class":514,"line":983},[13272,13276],{"type":21,"tag":512,"props":13273,"children":13274},{"style":815},[13275],{"type":27,"value":13074},{"type":21,"tag":512,"props":13277,"children":13278},{"style":525},[13279],{"type":27,"value":13079},{"type":21,"tag":512,"props":13281,"children":13282},{"class":514,"line":991},[13283,13287],{"type":21,"tag":512,"props":13284,"children":13285},{"style":815},[13286],{"type":27,"value":13074},{"type":21,"tag":512,"props":13288,"children":13289},{"style":525},[13290],{"type":27,"value":13091},{"type":21,"tag":512,"props":13292,"children":13293},{"class":514,"line":1015},[13294,13298],{"type":21,"tag":512,"props":13295,"children":13296},{"style":815},[13297],{"type":27,"value":13074},{"type":21,"tag":512,"props":13299,"children":13300},{"style":525},[13301],{"type":27,"value":13103},{"type":21,"tag":512,"props":13303,"children":13304},{"class":514,"line":1047},[13305,13309],{"type":21,"tag":512,"props":13306,"children":13307},{"style":1117},[13308],{"type":27,"value":13111},{"type":21,"tag":512,"props":13310,"children":13311},{"style":815},[13312],{"type":27,"value":1125},{"type":21,"tag":512,"props":13314,"children":13315},{"class":514,"line":1056},[13316],{"type":21,"tag":512,"props":13317,"children":13318},{"style":646},[13319],{"type":27,"value":13123},{"type":21,"tag":512,"props":13321,"children":13322},{"class":514,"line":1070},[13323,13327],{"type":21,"tag":512,"props":13324,"children":13325},{"style":815},[13326],{"type":27,"value":13074},{"type":21,"tag":512,"props":13328,"children":13329},{"style":525},[13330],{"type":27,"value":13135},{"type":21,"tag":512,"props":13332,"children":13333},{"class":514,"line":1079},[13334,13339],{"type":21,"tag":512,"props":13335,"children":13336},{"style":1117},[13337],{"type":27,"value":13338},"  yacd",{"type":21,"tag":512,"props":13340,"children":13341},{"style":815},[13342],{"type":27,"value":1125},{"type":21,"tag":512,"props":13344,"children":13345},{"class":514,"line":1317},[13346,13350,13354],{"type":21,"tag":512,"props":13347,"children":13348},{"style":1117},[13349],{"type":27,"value":13011},{"type":21,"tag":512,"props":13351,"children":13352},{"style":815},[13353],{"type":27,"value":11771},{"type":21,"tag":512,"props":13355,"children":13356},{"style":525},[13357],{"type":27,"value":13358},"ghcr.io/haishanh/yacd:master\n",{"type":21,"tag":512,"props":13360,"children":13361},{"class":514,"line":1326},[13362,13366,13370],{"type":21,"tag":512,"props":13363,"children":13364},{"style":1117},[13365],{"type":27,"value":13028},{"type":21,"tag":512,"props":13367,"children":13368},{"style":815},[13369],{"type":27,"value":11771},{"type":21,"tag":512,"props":13371,"children":13372},{"style":525},[13373],{"type":27,"value":13374},"yacd\n",{"type":21,"tag":512,"props":13376,"children":13377},{"class":514,"line":1678},[13378,13382,13386],{"type":21,"tag":512,"props":13379,"children":13380},{"style":1117},[13381],{"type":27,"value":13045},{"type":21,"tag":512,"props":13383,"children":13384},{"style":815},[13385],{"type":27,"value":11771},{"type":21,"tag":512,"props":13387,"children":13388},{"style":525},[13389],{"type":27,"value":13054},{"type":21,"tag":512,"props":13391,"children":13392},{"class":514,"line":1704},[13393,13398],{"type":21,"tag":512,"props":13394,"children":13395},{"style":1117},[13396],{"type":27,"value":13397},"    depends_on",{"type":21,"tag":512,"props":13399,"children":13400},{"style":815},[13401],{"type":27,"value":1125},{"type":21,"tag":512,"props":13403,"children":13404},{"class":514,"line":1730},[13405],{"type":21,"tag":512,"props":13406,"children":13407},{"style":646},[13408],{"type":27,"value":13409},"      # 依赖于上面的clash服务，在clash启动后，web才启动\n",{"type":21,"tag":512,"props":13411,"children":13412},{"class":514,"line":1756},[13413,13417],{"type":21,"tag":512,"props":13414,"children":13415},{"style":815},[13416],{"type":27,"value":13074},{"type":21,"tag":512,"props":13418,"children":13419},{"style":525},[13420],{"type":27,"value":13037},{"type":21,"tag":512,"props":13422,"children":13423},{"class":514,"line":1820},[13424,13429],{"type":21,"tag":512,"props":13425,"children":13426},{"style":1117},[13427],{"type":27,"value":13428},"    environment",{"type":21,"tag":512,"props":13430,"children":13431},{"style":815},[13432],{"type":27,"value":1125},{"type":21,"tag":512,"props":13434,"children":13435},{"class":514,"line":1828},[13436],{"type":21,"tag":512,"props":13437,"children":13438},{"style":646},[13439],{"type":27,"value":13440},"      # 注意这里，这里会代理终端的http流量到clash容器的7890端口\n",{"type":21,"tag":512,"props":13442,"children":13443},{"class":514,"line":1870},[13444,13448],{"type":21,"tag":512,"props":13445,"children":13446},{"style":815},[13447],{"type":27,"value":13074},{"type":21,"tag":512,"props":13449,"children":13450},{"style":525},[13451],{"type":27,"value":13452},"http_proxy=http://clash:7890\n",{"type":21,"tag":512,"props":13454,"children":13455},{"class":514,"line":1879},[13456,13460],{"type":21,"tag":512,"props":13457,"children":13458},{"style":815},[13459],{"type":27,"value":13074},{"type":21,"tag":512,"props":13461,"children":13462},{"style":525},[13463],{"type":27,"value":13464},"https_proxy=http://clash:7890\n",{"type":21,"tag":22,"props":13466,"children":13468},{"id":13467},"测试",[13469],{"type":27,"value":13467},{"type":21,"tag":29,"props":13471,"children":13472},{},[13473],{"type":27,"value":13474},"之后我们只需要进入yacd容器中，在shell下使用命令测试能否访问google：",{"type":21,"tag":501,"props":13476,"children":13478},{"code":13477},"curl -Iv www.google.com\n",[13479],{"type":21,"tag":508,"props":13480,"children":13481},{"__ignoreMap":8},[13482],{"type":27,"value":13477},{"type":21,"tag":29,"props":13484,"children":13485},{},[13486],{"type":27,"value":13487},"如果显示一下的信息，则说明终端的代理设置成功：",{"type":21,"tag":29,"props":13489,"children":13490},{},[13491],{"type":21,"tag":459,"props":13492,"children":13495},{"alt":13493,"src":13494},"image","https://johnhom-img.oss-cn-guangzhou.aliyuncs.com/images/curl_google.jpg",[],{"type":21,"tag":2671,"props":13497,"children":13498},{},[13499],{"type":27,"value":2675},{"title":8,"searchDepth":359,"depth":359,"links":13501},[13502,13503,13504],{"id":12933,"depth":359,"text":12933},{"id":13156,"depth":359,"text":13156},{"id":13467,"depth":359,"text":13467},"content:articles:20230506.md","articles/20230506.md",{"_path":13508,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":13509,"description":8,"published":13510,"categories":13511,"tags":13513,"slug":13514,"body":13515,"_type":376,"_id":14320,"_source":378,"_file":14321,"_extension":380},"/articles/20211218","macOS下terminal的配置","2021/12/18",[13512],"系统",[636],"terminal相关设置",{"type":18,"children":13516,"toc":14307},[13517,13523,13534,13540,13545,13557,13563,13568,13576,13581,13589,13595,13600,13608,13614,13619,13624,13629,13634,13642,13647,13665,13677,13682,13690,13726,13731,13736,13741,13746,13766,13976,13995,14188,14193,14228,14233,14241,14252,14260,14265,14270,14303],{"type":21,"tag":22,"props":13518,"children":13520},{"id":13519},"oh-my-zsh",[13521],{"type":27,"value":13522},"Oh My Zsh",{"type":21,"tag":29,"props":13524,"children":13525},{},[13526,13528],{"type":27,"value":13527},"官网网址：",{"type":21,"tag":445,"props":13529,"children":13532},{"href":13530,"rel":13531},"https://ohmyz.sh/",[449],[13533],{"type":27,"value":13530},{"type":21,"tag":22,"props":13535,"children":13537},{"id":13536},"iterm2的配置使用",[13538],{"type":27,"value":13539},"iTerm2的配置使用",{"type":21,"tag":29,"props":13541,"children":13542},{},[13543],{"type":27,"value":13544},"用于代替macOS的终端软件",{"type":21,"tag":29,"props":13546,"children":13547},{},[13548,13550],{"type":27,"value":13549},"安装网址：",{"type":21,"tag":445,"props":13551,"children":13554},{"href":13552,"rel":13553},"https://iterm2.com/",[449],[13555],{"type":27,"value":13556},"iTerm2",{"type":21,"tag":41,"props":13558,"children":13560},{"id":13559},"status-bar",[13561],{"type":27,"value":13562},"status bar",{"type":21,"tag":29,"props":13564,"children":13565},{},[13566],{"type":27,"value":13567},"status bar就是一下图示的红色区域：",{"type":21,"tag":29,"props":13569,"children":13570},{},[13571],{"type":21,"tag":459,"props":13572,"children":13575},{"alt":13573,"src":13574},"Pasted image 20260303203031","https://johnhom-img.oss-cn-guangzhou.aliyuncs.com/obsidian/Pasted%20image%2020260303203031.png",[],{"type":21,"tag":29,"props":13577,"children":13578},{},[13579],{"type":27,"value":13580},"如果需要使用呢，请按照以下的图示开启status bar：",{"type":21,"tag":29,"props":13582,"children":13583},{},[13584],{"type":21,"tag":459,"props":13585,"children":13588},{"alt":13586,"src":13587},"Pasted image 20260303203043","https://johnhom-img.oss-cn-guangzhou.aliyuncs.com/obsidian/Pasted%20image%2020260303203043.png",[],{"type":21,"tag":22,"props":13590,"children":13592},{"id":13591},"使用命令打开vscode",[13593],{"type":27,"value":13594},"使用命令打开VSCode",{"type":21,"tag":29,"props":13596,"children":13597},{},[13598],{"type":27,"value":13599},"首先打开VSCode，然后使用快捷键Shift+Command+P，调起命令窗口，输入shell Command，下方出现Install 'code' command in PATH选项，点击以安装。",{"type":21,"tag":29,"props":13601,"children":13602},{},[13603],{"type":21,"tag":459,"props":13604,"children":13607},{"alt":13605,"src":13606},"Pasted image 20260303203100","https://johnhom-img.oss-cn-guangzhou.aliyuncs.com/obsidian/Pasted%20image%2020260303203100.png",[],{"type":21,"tag":41,"props":13609,"children":13611},{"id":13610},"使用步骤",[13612],{"type":27,"value":13613},"使用步骤：",{"type":21,"tag":29,"props":13615,"children":13616},{},[13617],{"type":27,"value":13618},"打开命令行，进入工作目录，然后如果要用vscode打开某个文件夹，直接输入vscode + . 即可。",{"type":21,"tag":22,"props":13620,"children":13622},{"id":13621},"link",[13623],{"type":27,"value":13621},{"type":21,"tag":29,"props":13625,"children":13626},{},[13627],{"type":27,"value":13628},"软链接的作用就是生成一个目标文件或者目录，这个文件或者目录指向源文件或者目录。",{"type":21,"tag":29,"props":13630,"children":13631},{},[13632],{"type":27,"value":13633},"语法",{"type":21,"tag":501,"props":13635,"children":13637},{"code":13636},"ln -s [源文件或目录] [目标文件或目录]\n",[13638],{"type":21,"tag":508,"props":13639,"children":13640},{"__ignoreMap":8},[13641],{"type":27,"value":13636},{"type":21,"tag":29,"props":13643,"children":13644},{},[13645],{"type":27,"value":13646},"在某个场景下，我想通过终端，用VSCode打开某个文件夹，步骤是如下：",{"type":21,"tag":295,"props":13648,"children":13649},{},[13650,13655,13660],{"type":21,"tag":79,"props":13651,"children":13652},{},[13653],{"type":27,"value":13654},"打开终端",{"type":21,"tag":79,"props":13656,"children":13657},{},[13658],{"type":27,"value":13659},"一层一层进入到对应的文件夹内。",{"type":21,"tag":79,"props":13661,"children":13662},{},[13663],{"type":27,"value":13664},"输入code + .命令，之后就会启动VSCode打开文件夹。",{"type":21,"tag":29,"props":13666,"children":13667},{},[13668,13670,13675],{"type":27,"value":13669},"如果文件夹所在的层次较多，又无法移动，我们可以使用",{"type":21,"tag":508,"props":13671,"children":13673},{"className":13672},[],[13674],{"type":27,"value":13621},{"type":27,"value":13676},"命令，通过软链接的方式，将该文件夹软链接到用户的根目录下。",{"type":21,"tag":29,"props":13678,"children":13679},{},[13680],{"type":27,"value":13681},"执行的软连接的命令如下：",{"type":21,"tag":501,"props":13683,"children":13685},{"code":13684},"ln -s /Volumes/Backup/fk ~/\n",[13686],{"type":21,"tag":508,"props":13687,"children":13688},{"__ignoreMap":8},[13689],{"type":27,"value":13684},{"type":21,"tag":29,"props":13691,"children":13692},{},[13693,13695,13701,13703,13709,13711,13717,13719,13724],{"type":27,"value":13694},"这样就会在当前的用户目录下创建一个",{"type":21,"tag":508,"props":13696,"children":13698},{"className":13697},[],[13699],{"type":27,"value":13700},"fk",{"type":27,"value":13702},"的文件夹，这个文件夹会指向",{"type":21,"tag":508,"props":13704,"children":13706},{"className":13705},[],[13707],{"type":27,"value":13708},"/Volumes/Backup/fk",{"type":27,"value":13710},"，之后我只需要在终端直接",{"type":21,"tag":508,"props":13712,"children":13714},{"className":13713},[],[13715],{"type":27,"value":13716},"cd ~/fk",{"type":27,"value":13718},"，即可执行",{"type":21,"tag":508,"props":13720,"children":13722},{"className":13721},[],[13723],{"type":27,"value":508},{"type":27,"value":13725},"命令打开文件夹。",{"type":21,"tag":22,"props":13727,"children":13729},{"id":13728},"终端设置代理翻墙",[13730],{"type":27,"value":13728},{"type":21,"tag":29,"props":13732,"children":13733},{},[13734],{"type":27,"value":13735},"想要在命令行安装oh-my-zsh，最后发现终端访问github失败，但是浏览器缺可以访问，这可能是因为终端并没有走代理。",{"type":21,"tag":29,"props":13737,"children":13738},{},[13739],{"type":27,"value":13740},"下面我们来配置终端走代理。",{"type":21,"tag":41,"props":13742,"children":13744},{"id":13743},"改写shell配置文件",[13745],{"type":27,"value":13743},{"type":21,"tag":29,"props":13747,"children":13748},{},[13749,13751,13757,13758,13764],{"type":27,"value":13750},"把代理服务器地址写入 shell 配置文件",{"type":21,"tag":508,"props":13752,"children":13754},{"className":13753},[],[13755],{"type":27,"value":13756},".bashrc",{"type":27,"value":10459},{"type":21,"tag":508,"props":13759,"children":13761},{"className":13760},[],[13762],{"type":27,"value":13763},".zshrc",{"type":27,"value":13765},"，在shell配置文件添加下面内容：",{"type":21,"tag":501,"props":13767,"children":13769},{"code":13768,"language":636,"meta":8,"className":634,"style":8},"# 配置终端走代理模式\nfunction proxy_on() {\n  export https_proxy=http://127.0.0.1:port\n  export http_proxy=http://127.0.0.1:port\n  export all_proxy=socks5://127.0.0.1:port\n}\n# 关闭代理\nfunction proxy_off() {\n  unset https_proxy\n  unset http_proxy\n  unset all_proxy\n  echo -e \"已关闭代理\"\n}\n\n# 执行proxy_on\nproxy_on\n",[13770],{"type":21,"tag":508,"props":13771,"children":13772},{"__ignoreMap":8},[13773,13781,13797,13819,13839,13860,13867,13875,13891,13904,13916,13928,13946,13953,13960,13968],{"type":21,"tag":512,"props":13774,"children":13775},{"class":514,"line":515},[13776],{"type":21,"tag":512,"props":13777,"children":13778},{"style":646},[13779],{"type":27,"value":13780},"# 配置终端走代理模式\n",{"type":21,"tag":512,"props":13782,"children":13783},{"class":514,"line":359},[13784,13788,13793],{"type":21,"tag":512,"props":13785,"children":13786},{"style":809},[13787],{"type":27,"value":4123},{"type":21,"tag":512,"props":13789,"children":13790},{"style":519},[13791],{"type":27,"value":13792}," proxy_on",{"type":21,"tag":512,"props":13794,"children":13795},{"style":815},[13796],{"type":27,"value":6611},{"type":21,"tag":512,"props":13798,"children":13799},{"class":514,"line":365},[13800,13805,13810,13814],{"type":21,"tag":512,"props":13801,"children":13802},{"style":809},[13803],{"type":27,"value":13804},"  export",{"type":21,"tag":512,"props":13806,"children":13807},{"style":815},[13808],{"type":27,"value":13809}," https_proxy",{"type":21,"tag":512,"props":13811,"children":13812},{"style":809},[13813],{"type":27,"value":833},{"type":21,"tag":512,"props":13815,"children":13816},{"style":815},[13817],{"type":27,"value":13818},"http://127.0.0.1:port\n",{"type":21,"tag":512,"props":13820,"children":13821},{"class":514,"line":673},[13822,13826,13831,13835],{"type":21,"tag":512,"props":13823,"children":13824},{"style":809},[13825],{"type":27,"value":13804},{"type":21,"tag":512,"props":13827,"children":13828},{"style":815},[13829],{"type":27,"value":13830}," http_proxy",{"type":21,"tag":512,"props":13832,"children":13833},{"style":809},[13834],{"type":27,"value":833},{"type":21,"tag":512,"props":13836,"children":13837},{"style":815},[13838],{"type":27,"value":13818},{"type":21,"tag":512,"props":13840,"children":13841},{"class":514,"line":900},[13842,13846,13851,13855],{"type":21,"tag":512,"props":13843,"children":13844},{"style":809},[13845],{"type":27,"value":13804},{"type":21,"tag":512,"props":13847,"children":13848},{"style":815},[13849],{"type":27,"value":13850}," all_proxy",{"type":21,"tag":512,"props":13852,"children":13853},{"style":809},[13854],{"type":27,"value":833},{"type":21,"tag":512,"props":13856,"children":13857},{"style":815},[13858],{"type":27,"value":13859},"socks5://127.0.0.1:port\n",{"type":21,"tag":512,"props":13861,"children":13862},{"class":514,"line":908},[13863],{"type":21,"tag":512,"props":13864,"children":13865},{"style":815},[13866],{"type":27,"value":1053},{"type":21,"tag":512,"props":13868,"children":13869},{"class":514,"line":955},[13870],{"type":21,"tag":512,"props":13871,"children":13872},{"style":646},[13873],{"type":27,"value":13874},"# 关闭代理\n",{"type":21,"tag":512,"props":13876,"children":13877},{"class":514,"line":983},[13878,13882,13887],{"type":21,"tag":512,"props":13879,"children":13880},{"style":809},[13881],{"type":27,"value":4123},{"type":21,"tag":512,"props":13883,"children":13884},{"style":519},[13885],{"type":27,"value":13886}," proxy_off",{"type":21,"tag":512,"props":13888,"children":13889},{"style":815},[13890],{"type":27,"value":6611},{"type":21,"tag":512,"props":13892,"children":13893},{"class":514,"line":991},[13894,13899],{"type":21,"tag":512,"props":13895,"children":13896},{"style":686},[13897],{"type":27,"value":13898},"  unset",{"type":21,"tag":512,"props":13900,"children":13901},{"style":525},[13902],{"type":27,"value":13903}," https_proxy\n",{"type":21,"tag":512,"props":13905,"children":13906},{"class":514,"line":1015},[13907,13911],{"type":21,"tag":512,"props":13908,"children":13909},{"style":686},[13910],{"type":27,"value":13898},{"type":21,"tag":512,"props":13912,"children":13913},{"style":525},[13914],{"type":27,"value":13915}," http_proxy\n",{"type":21,"tag":512,"props":13917,"children":13918},{"class":514,"line":1047},[13919,13923],{"type":21,"tag":512,"props":13920,"children":13921},{"style":686},[13922],{"type":27,"value":13898},{"type":21,"tag":512,"props":13924,"children":13925},{"style":525},[13926],{"type":27,"value":13927}," all_proxy\n",{"type":21,"tag":512,"props":13929,"children":13930},{"class":514,"line":1056},[13931,13936,13941],{"type":21,"tag":512,"props":13932,"children":13933},{"style":686},[13934],{"type":27,"value":13935},"  echo",{"type":21,"tag":512,"props":13937,"children":13938},{"style":686},[13939],{"type":27,"value":13940}," -e",{"type":21,"tag":512,"props":13942,"children":13943},{"style":525},[13944],{"type":27,"value":13945}," \"已关闭代理\"\n",{"type":21,"tag":512,"props":13947,"children":13948},{"class":514,"line":1070},[13949],{"type":21,"tag":512,"props":13950,"children":13951},{"style":815},[13952],{"type":27,"value":1053},{"type":21,"tag":512,"props":13954,"children":13955},{"class":514,"line":1079},[13956],{"type":21,"tag":512,"props":13957,"children":13958},{"emptyLinePlaceholder":859},[13959],{"type":27,"value":862},{"type":21,"tag":512,"props":13961,"children":13962},{"class":514,"line":1317},[13963],{"type":21,"tag":512,"props":13964,"children":13965},{"style":646},[13966],{"type":27,"value":13967},"# 执行proxy_on\n",{"type":21,"tag":512,"props":13969,"children":13970},{"class":514,"line":1326},[13971],{"type":21,"tag":512,"props":13972,"children":13973},{"style":519},[13974],{"type":27,"value":13975},"proxy_on\n",{"type":21,"tag":29,"props":13977,"children":13978},{},[13979,13981,13986,13988,13993],{"type":27,"value":13980},"首先我们要知道代理本地端口号，以ClashX为例，http和https的代理端口为",{"type":21,"tag":83,"props":13982,"children":13983},{},[13984],{"type":27,"value":13985},"7890",{"type":27,"value":13987},"，socks的代理端口为",{"type":21,"tag":83,"props":13989,"children":13990},{},[13991],{"type":27,"value":13992},"7891",{"type":27,"value":13994},"，那么我们应该对shell的配置文件（.bashrc或者.zshrc）的末尾行添加以下内容：",{"type":21,"tag":501,"props":13996,"children":13998},{"code":13997,"language":636,"meta":8,"className":634,"style":8},"# 配置终端走代理模式\nfunction proxy_on() {\n  export https_proxy=http://127.0.0.1:7890\n  export http_proxy=http://127.0.0.1:7890\n  export all_proxy=socks5://127.0.0.1:7891\n}\n# 关闭代理\nfunction proxy_off() {\n  unset https_proxy\n  unset http_proxy\n  unset all_proxy\n  echo -e \"已关闭代理\"\n}\n\n# 执行proxy_on\nproxy_on\n",[13999],{"type":21,"tag":508,"props":14000,"children":14001},{"__ignoreMap":8},[14002,14009,14024,14044,14063,14083,14090,14097,14112,14123,14134,14145,14160,14167,14174,14181],{"type":21,"tag":512,"props":14003,"children":14004},{"class":514,"line":515},[14005],{"type":21,"tag":512,"props":14006,"children":14007},{"style":646},[14008],{"type":27,"value":13780},{"type":21,"tag":512,"props":14010,"children":14011},{"class":514,"line":359},[14012,14016,14020],{"type":21,"tag":512,"props":14013,"children":14014},{"style":809},[14015],{"type":27,"value":4123},{"type":21,"tag":512,"props":14017,"children":14018},{"style":519},[14019],{"type":27,"value":13792},{"type":21,"tag":512,"props":14021,"children":14022},{"style":815},[14023],{"type":27,"value":6611},{"type":21,"tag":512,"props":14025,"children":14026},{"class":514,"line":365},[14027,14031,14035,14039],{"type":21,"tag":512,"props":14028,"children":14029},{"style":809},[14030],{"type":27,"value":13804},{"type":21,"tag":512,"props":14032,"children":14033},{"style":815},[14034],{"type":27,"value":13809},{"type":21,"tag":512,"props":14036,"children":14037},{"style":809},[14038],{"type":27,"value":833},{"type":21,"tag":512,"props":14040,"children":14041},{"style":815},[14042],{"type":27,"value":14043},"http://127.0.0.1:7890\n",{"type":21,"tag":512,"props":14045,"children":14046},{"class":514,"line":673},[14047,14051,14055,14059],{"type":21,"tag":512,"props":14048,"children":14049},{"style":809},[14050],{"type":27,"value":13804},{"type":21,"tag":512,"props":14052,"children":14053},{"style":815},[14054],{"type":27,"value":13830},{"type":21,"tag":512,"props":14056,"children":14057},{"style":809},[14058],{"type":27,"value":833},{"type":21,"tag":512,"props":14060,"children":14061},{"style":815},[14062],{"type":27,"value":14043},{"type":21,"tag":512,"props":14064,"children":14065},{"class":514,"line":900},[14066,14070,14074,14078],{"type":21,"tag":512,"props":14067,"children":14068},{"style":809},[14069],{"type":27,"value":13804},{"type":21,"tag":512,"props":14071,"children":14072},{"style":815},[14073],{"type":27,"value":13850},{"type":21,"tag":512,"props":14075,"children":14076},{"style":809},[14077],{"type":27,"value":833},{"type":21,"tag":512,"props":14079,"children":14080},{"style":815},[14081],{"type":27,"value":14082},"socks5://127.0.0.1:7891\n",{"type":21,"tag":512,"props":14084,"children":14085},{"class":514,"line":908},[14086],{"type":21,"tag":512,"props":14087,"children":14088},{"style":815},[14089],{"type":27,"value":1053},{"type":21,"tag":512,"props":14091,"children":14092},{"class":514,"line":955},[14093],{"type":21,"tag":512,"props":14094,"children":14095},{"style":646},[14096],{"type":27,"value":13874},{"type":21,"tag":512,"props":14098,"children":14099},{"class":514,"line":983},[14100,14104,14108],{"type":21,"tag":512,"props":14101,"children":14102},{"style":809},[14103],{"type":27,"value":4123},{"type":21,"tag":512,"props":14105,"children":14106},{"style":519},[14107],{"type":27,"value":13886},{"type":21,"tag":512,"props":14109,"children":14110},{"style":815},[14111],{"type":27,"value":6611},{"type":21,"tag":512,"props":14113,"children":14114},{"class":514,"line":991},[14115,14119],{"type":21,"tag":512,"props":14116,"children":14117},{"style":686},[14118],{"type":27,"value":13898},{"type":21,"tag":512,"props":14120,"children":14121},{"style":525},[14122],{"type":27,"value":13903},{"type":21,"tag":512,"props":14124,"children":14125},{"class":514,"line":1015},[14126,14130],{"type":21,"tag":512,"props":14127,"children":14128},{"style":686},[14129],{"type":27,"value":13898},{"type":21,"tag":512,"props":14131,"children":14132},{"style":525},[14133],{"type":27,"value":13915},{"type":21,"tag":512,"props":14135,"children":14136},{"class":514,"line":1047},[14137,14141],{"type":21,"tag":512,"props":14138,"children":14139},{"style":686},[14140],{"type":27,"value":13898},{"type":21,"tag":512,"props":14142,"children":14143},{"style":525},[14144],{"type":27,"value":13927},{"type":21,"tag":512,"props":14146,"children":14147},{"class":514,"line":1056},[14148,14152,14156],{"type":21,"tag":512,"props":14149,"children":14150},{"style":686},[14151],{"type":27,"value":13935},{"type":21,"tag":512,"props":14153,"children":14154},{"style":686},[14155],{"type":27,"value":13940},{"type":21,"tag":512,"props":14157,"children":14158},{"style":525},[14159],{"type":27,"value":13945},{"type":21,"tag":512,"props":14161,"children":14162},{"class":514,"line":1070},[14163],{"type":21,"tag":512,"props":14164,"children":14165},{"style":815},[14166],{"type":27,"value":1053},{"type":21,"tag":512,"props":14168,"children":14169},{"class":514,"line":1079},[14170],{"type":21,"tag":512,"props":14171,"children":14172},{"emptyLinePlaceholder":859},[14173],{"type":27,"value":862},{"type":21,"tag":512,"props":14175,"children":14176},{"class":514,"line":1317},[14177],{"type":21,"tag":512,"props":14178,"children":14179},{"style":646},[14180],{"type":27,"value":13967},{"type":21,"tag":512,"props":14182,"children":14183},{"class":514,"line":1326},[14184],{"type":21,"tag":512,"props":14185,"children":14186},{"style":519},[14187],{"type":27,"value":13975},{"type":21,"tag":29,"props":14189,"children":14190},{},[14191],{"type":27,"value":14192},"然后我们重启终端即可生效。如果不想重启终端，而是想在当前的终端生效，我们只需要执行命令：",{"type":21,"tag":501,"props":14194,"children":14196},{"code":14195,"language":636,"meta":8,"className":634,"style":8},"source ~/.zshrc\n\n## .zshrc可以替换成上一步中修改的配置文件比如.bashrc\n",[14197],{"type":21,"tag":508,"props":14198,"children":14199},{"__ignoreMap":8},[14200,14213,14220],{"type":21,"tag":512,"props":14201,"children":14202},{"class":514,"line":515},[14203,14208],{"type":21,"tag":512,"props":14204,"children":14205},{"style":686},[14206],{"type":27,"value":14207},"source",{"type":21,"tag":512,"props":14209,"children":14210},{"style":525},[14211],{"type":27,"value":14212}," ~/.zshrc\n",{"type":21,"tag":512,"props":14214,"children":14215},{"class":514,"line":359},[14216],{"type":21,"tag":512,"props":14217,"children":14218},{"emptyLinePlaceholder":859},[14219],{"type":27,"value":862},{"type":21,"tag":512,"props":14221,"children":14222},{"class":514,"line":365},[14223],{"type":21,"tag":512,"props":14224,"children":14225},{"style":646},[14226],{"type":27,"value":14227},"## .zshrc可以替换成上一步中修改的配置文件比如.bashrc\n",{"type":21,"tag":29,"props":14229,"children":14230},{},[14231],{"type":27,"value":14232},"最后测试是否翻墙成功，我们使用curl命令请求一下google网址：",{"type":21,"tag":501,"props":14234,"children":14236},{"code":14235},"curl -I https://www.google.com\n",[14237],{"type":21,"tag":508,"props":14238,"children":14239},{"__ignoreMap":8},[14240],{"type":27,"value":14235},{"type":21,"tag":29,"props":14242,"children":14243},{},[14244,14250],{"type":21,"tag":508,"props":14245,"children":14247},{"className":14246},[],[14248],{"type":27,"value":14249},"-I",{"type":27,"value":14251},"参数代表向服务器发出 HEAD 请求，然会将服务器返回的 HTTP 标头打印出来。",{"type":21,"tag":501,"props":14253,"children":14255},{"code":14254},"➜  ~ curl -I https://www.google.com\n\nHTTP/1.1 200 Connection established\n\nHTTP/2 200 \ncontent-type: text/html; charset=ISO-8859-1\np3p: CP=\"This is not a P3P policy! See g.co/p3phelp for more info.\"\ndate: Sat, 18 Dec 2021 07:07:43 GMT\nserver: gws\nx-xss-protection: 0\nx-frame-options: SAMEORIGIN\nexpires: Sat, 18 Dec 2021 07:07:43 GMT\ncache-control: private\nset-cookie: 1P_JAR=2021-12-18-07; expires=Mon, 17-Jan-2022 07:07:43 GMT; path=/; domain=.google.com; Secure\nset-cookie: NID=511=ne5-MBMfwxq2a6ZyCdRAZ_zU-YjjksqtQ0OTNyRVPTWq1vnDpKTA0a2oDCeDLrbbDixP--aQ6H-ufrL-Zoj8HDkJpAOjkriQysg5OmPfViBCc7aknFCw_NBIlXffS8y0KwnAX3FBnqdUu1IiuQrT_t7gVOqOTqLmGKqxt6MZohU; expires=Sun, 19-Jun-2022 07:07:43 GMT; path=/; domain=.google.com; HttpOnly\nalt-svc: h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\"\n",[14256],{"type":21,"tag":508,"props":14257,"children":14258},{"__ignoreMap":8},[14259],{"type":27,"value":14254},{"type":21,"tag":29,"props":14261,"children":14262},{},[14263],{"type":27,"value":14264},"看到如下的输出，说明终端已经阔以访问外网啦。",{"type":21,"tag":29,"props":14266,"children":14267},{},[14268],{"type":27,"value":14269},"如果想要终端不使用代理，那么我们直接在终端输入以下命令即可：",{"type":21,"tag":501,"props":14271,"children":14273},{"code":14272,"language":636,"meta":8,"className":634,"style":8},"➜  ~ proxy_off\n已关闭代理\n",[14274],{"type":21,"tag":508,"props":14275,"children":14276},{"__ignoreMap":8},[14277,14295],{"type":21,"tag":512,"props":14278,"children":14279},{"class":514,"line":515},[14280,14285,14290],{"type":21,"tag":512,"props":14281,"children":14282},{"style":519},[14283],{"type":27,"value":14284},"➜",{"type":21,"tag":512,"props":14286,"children":14287},{"style":525},[14288],{"type":27,"value":14289},"  ~",{"type":21,"tag":512,"props":14291,"children":14292},{"style":525},[14293],{"type":27,"value":14294}," proxy_off\n",{"type":21,"tag":512,"props":14296,"children":14297},{"class":514,"line":359},[14298],{"type":21,"tag":512,"props":14299,"children":14300},{"style":519},[14301],{"type":27,"value":14302},"已关闭代理\n",{"type":21,"tag":2671,"props":14304,"children":14305},{},[14306],{"type":27,"value":2675},{"title":8,"searchDepth":359,"depth":359,"links":14308},[14309,14310,14313,14316,14317],{"id":13519,"depth":359,"text":13522},{"id":13536,"depth":359,"text":13539,"children":14311},[14312],{"id":13559,"depth":365,"text":13562},{"id":13591,"depth":359,"text":13594,"children":14314},[14315],{"id":13610,"depth":365,"text":13613},{"id":13621,"depth":359,"text":13621},{"id":13728,"depth":359,"text":13728,"children":14318},[14319],{"id":13743,"depth":365,"text":13743},"content:articles:20211218.md","articles/20211218.md",1772793490481]