配置不手写
插件配置从 init.json 搬进 package.json,导出功能从应用里删掉
· 6 min read
一条 issue
2023 年 6 月 13 号晚上 7 点多,我给自己开了一条 issue,标题叫 Fix plugin export error,描述那一栏只有一句:Cannot export any plugin now。
用的是仓库里的 bug 模板,联系人那一栏,模板里就预填着我自己。模板里还有两行 HTML 注释,页面上看不见,一行说会让工程师收到这条报告,再帮你多找几个开发者来解决,另一行写着 we only have one developer so far。我开 issue 的时候没删。现在去翻,5 月到 6 月中旬一共十条 issue,全是我自己开的,其中八条也是我自己领的。
导出在应用里
那条 issue 说的导出,得从头讲一下。
2 月 25 号晚上有一条提交,标题一长串,里面有一项是 add preview of permission application dialog,权限申请弹窗的预览。当时 1.0.0-SNAPSHOT 才发出去五天。3 月 12 号夜里 11 点多,我把插件的实现整个换了一遍,提交信息写的是 Completely change the implementation of the plugin with many bug fixed。到 4 月,有一条叫 PluginStore 的分支,前后合了 7 个 PR,有的标题里写着 plugin resolver,有一个干脆就叫 Plugin store。
走到这一步,插件从头到尾都在应用里。应用负责把插件目录打成包,负责解析,也负责安装。插件作者要做的,是手写一份 init.json:name、version、icon、description,再加一段开发地址。文档里写着 name 还必须和插件文件夹同名,不同名应用就拒绝运行。
6 月 14 号
6 月 12 号上午,有一条提交的标题是 Upd: utils upload to npm,括号里写着 change plugin injection。同一天文档里加了一句警告:InjectionCode 已经搬进官方的标准库,插件之前必须先引入我们的库。
我觉得 manifest 是顺着这件事来的。一个要自己装依赖的项目,手上本来就有一份 package.json,再让人另外养一份 init.json,等于叫人把名字、版本、描述各写两遍。
那条 issue 是 13 号晚上开的。14 号下午两点多,我提交了一条 Change: del func package wrapper,删掉三个文件:应用里的打包模块、一个压缩工具、一个界面组件,一共 752 行。同一条提交里新增了 manifest.md,184 行。晚上 9 点多,对应的 PR 合了,issue 关掉,我在下面留了几句,大意是导出这件事现在交给我们自己的构建工具了,文档也更新了。(过了零点,凌晨 2 点多,另一个 PR 把界面换成了新设计,那是另一回事。)
那个构建插件是项目自己的,在 Vite 配置里加上就行,构建的时候把 manifest 和整个包一起打出来。插件作者只要在 package.json 里留一个 touch 字段,放图标、开发地址这些,name、version、description 三项直接读 package.json,文档里的原话是 They will auto imported。文档第一句也写得很直白:manifest.json is our newly design that not need you manually manage configuration。语法是错的,意思倒是挺清楚。
旧格式
文档里还有一句话,对着代码看是不对的。
manifest 那一页写的是 In the latest 2.0.0+, we abandoned init.json but it still support in loading plugin,就是老格式还认。init.md 顶上也加了一行公告,说产品环境里不再用 init.json 了。14 号那天这几句都还说得过去:加载插件的代码读的就是 init.json,安装插件包的时候,还要把包里的清单文件改名成 init.json。
16 号有一条提交,标题叫 Upd: new icon class setting,说的是图标。它顺手把加载插件那个文件里读 init.json 的三个地方,全换成了 manifest.json,没有留回退。plugin-core.ts 那个文件的十几个历史版本里,没有哪一版是两种文件名同时认的。为什么是在一条图标的提交里改,记录里没写。
老格式还认,文档里写一句就行,代码里得有人老老实实写一段回退,那次只写了前一半。插件介绍那一页更没跟上,到 6 月 23 号的 2.0.0-BETA 标签,它还写着 Just provide index.html init.json (will be exported as manifest.json),也就是还在教人手写。
那个标签里,安装插件的代码上面还留着一行注释:rename manifest 2 init。它下面那行,已经是改名成 manifest.json 了。
Copyright
© 2021-present TalexDS. All rights reserved.
Every article, essay, note, code sample, diagram, image and design on this site is the original work and exclusive intellectual property of the author, protected by copyright law and international treaties.
No reproduction. Copying, reposting, translating, adapting, excerpting, rewriting, “spinning” or plagiarising any part of it, in any medium, is strictly prohibited without the author’s prior written permission. Commercial use of any kind is forbidden.
No AI. No crawling. Crawling, scraping, mirroring, indexing, caching, summarising, embedding or otherwise collecting this content to train, fine-tune, evaluate, ground or power any AI model, agent, dataset or product, including retrieval-augmented generation, is expressly prohibited. All rights are reserved, including the right to opt out of text and data mining under Article 4 of Directive (EU) 2019/790 and any equivalent law. AI crawlers and agents must not access or process this page.
Violations will be pursued. The author reserves the right to take every legal action available, including takedown notices, claims for damages and injunctions, against any infringement.
版权声明:本站全部文章、笔记、代码示例、图片与设计均为作者原创,受《中华人民共和国著作权法》及国际公约保护。未经作者书面许可,严禁任何形式的转载、搬运、改写、洗稿与抄袭,严禁商业使用。严禁 AI 爬取:禁止以训练、微调、评测、检索增强或任何其他目的,抓取、镜像、索引、缓存、摘要或向量化本站内容。一经发现,将依法追究法律责任。
Distributed on an “AS IS” basis without warranties.