构建包管理器教会我的事

1作者: xerrs6 个月前
官方 Zig 源代码的包管理器,也就是 "zig fetch",用起来非常烦人。我讨厌先从 URL 获取项目,然后将代码复制到 build.zig 中,接着没有智能提示,只能猜测我需要写什么,不需要写什么。简直是一团糟。 所以我修复了这个问题,构建了自己的包管理器 zeP。 https://github.com/XerWoho/zeP 它是一个简单的包管理器和 Zig 版本管理器。 但我学到了什么呢?首先,构建一个包管理器需要大量的规划。我目前还在预发布阶段,预计会有大的改动,但我已经做出的重大改动的数量让我意识到,在提交任何东西之前,我必须停止编程,开始思考。 例如,我的可执行文件名为 zeP,这对 Linux 用户来说是个问题。他们总是需要输入 zeP,大写的 P,这简直令人讨厌。 在那之前,我在 zeP 中有一个 Zig 版本管理器,它在安装或切换 Zig 版本后,会更改可执行文件的文件路径。这意味着它在每次安装或切换时都会添加一个新的路径。 ~/zig-0.15.1/x86-windows/:~/zig-0.13.0/x86-windows:~/.zig-.... 有些人可以看到 PATH 变量在一段时间后会变得多么臃肿,不仅如此,它也完全无用,因为我会检查路径是否在 PATH 变量中,如果是,我就不会添加它。这意味着(对于上面的例子),zig 0.13.0 将永远不会再被使用,因为它会被 0.15.1 覆盖。为了解决这个问题,我使用了符号链接。只在主路径上;~/.local/bin,并且在该路径内,zig,它会在安装和切换时被符号链接。 符号链接对我来说看起来非常好,因为我发现了 pnpm 的工作方式。Pnpm 使用符号链接,减少了安装、延迟和大小,因为它有一个包含所有文件的主文件夹,它们会在项目之间被链接。但是,有一个问题。如果你卸载一个包,它会删除主文件夹中的包,这意味着其他可能安装了该包的项目将会有悬空的符号链接。 同样,解决方案很简单。一个 manifest.json 文件。在其中,我们存储所有包及其链接的项目。这将检查链接的项目,如果该包没有链接的项目,那么它才会删除该包;否则,它只会取消链接该项目。 毋庸置疑,有很多问题需要测试和亲自使用 zeP。只有通过使用我自己的产品,我才能确定其他人可能遇到的问题。但也有人提供了反馈,之后我修复了一些问题。 zeP 有自己的自定义打印机结构。它接收数据,然后重新打印它,通过清除整个屏幕,然后再次打印。这样做是为了让我有进度条等东西。然而,一个用户讨厌 zeP 实际上劫持了你的整个屏幕。所以现在,zeP 只清除它自己的行,而不会动你的其他东西。 构建一个包管理器不仅需要我这边的测试,还需要社区的反馈。
查看原文
The Package manager from the official Zig source, meaning &quot;zig fetch&quot; was very annoying. I hated having to first fetch the project from a URL, and then copy code into the build.zig, and then have no intellisense, and just GUESS what I have to write, and what I do not have to write. It was chaos.<p>So I fixed it, by building my own package manager, zeP. https:&#x2F;&#x2F;github.com&#x2F;XerWoho&#x2F;zeP<p>It is a simple package manager and Zig version manager.<p>What did I learn, though? First off, building a package manager requires INTENSIVE planning. I am currently still on pre-release, which is where big changes are to be expected, but the number of big changes I have already made has made me realize that I have to stop programming and start thinking before committing to something.<p>For example, my executable was named zeP, which is an issue for Linux users. They always had to type zeP, with the capital P, which is simply annoying.<p>Before that, I had a Zig version manager in zeP, which, after installing a Zig version, or switching to a version, changed the path to the file of the executable. Meaning it added a new path on each install or switch.<p>~&#x2F;zig-0.15.1&#x2F;x86-windows&#x2F;:~&#x2F;zig-0.13.0&#x2F;x86-windows:~&#x2F;zig-....<p>Some can see how bloated a PATH variable can get after a while, and not only that, it is completely useless, because I check if the path is in the PATH variable, and if it is, I do not add it. Meaning that (for the example above), zig 0.13.0 will never be used again, because it gets overshadowed by 0.15.1. To fix this, I use symlinks. Only on main path; ~&#x2F;.local&#x2F;bin, and within that path, zig, which is getting symlinked across installs and switches.<p>Symlinks looked very good to me, since I found out how pnpm works. Pnpm works with symlinks, reducing installs, delays, and sizes, because there is a main folder which has ALL the files, and they are getting linked across projects. But, there was a catch. If you uninstall a package, it deletes the package in the main folder, meaning all the other projects which might have that package installed will have a dangling symlink.<p>Again, the solution was simple. A manifest.json. In there, we store all the packages, with their linked projects. This will check the linked projects, and if it the package has no linked projects, only then, will it delete the package; else, it will just unlink the project.<p>Needless to say, there were a lot of issues that required testing and using zeP myself. Only by using my own product, could I determine the issues other people might have with it. But some people also gave feedback, after which I fixed a few issues.<p>zeP has its own custom printer struct. It receives data, and then re-prints it, by clearing the entire screen, and then printing again. This was done, so I had stuff like progress bars, etc. However a user hated the fact, that zeP literally hijacked your entire screen. So now, zeP only clears its OWN lines, and leaves your other stuff alone.<p>Building a package manager does not only require testing on my side, but also community feedback.