Skip to main content
Version: 10.x

pnpm store

管理包存储。

🌐 Managing the package store.

命令

🌐 Commands

status

检查存储中是否有修改过的软件包。

🌐 Checks for modified packages in the store.

如果包的内容与解包时相同,则返回退出代码 0。

🌐 Returns exit code 0 if the content of the package is the same as it was at the time of unpacking.

add

在功能上与 pnpm add 相同,唯一不同的是它会直接向存储添加新软件包,而不会修改存储之外的任何项目或文件。

🌐 Functionally equivalent to pnpm add, except this adds new packages to the store directly without modifying any projects or files outside of the store.

prune

从存储中移除_未引用的包_。

🌐 Removes unreferenced packages from the store.

未被引用的软件包是指系统上没有任何项目使用的软件包。在大多数安装操作之后,软件包可能会变为未被引用,例如当某些依赖变得多余时。

🌐 Unreferenced packages are packages that are not used by any projects on the system. Packages can become unreferenced after most installation operations, for instance when dependencies are made redundant.

例如,在 pnpm install 期间,包 foo@1.0.0 会被更新到 foo@1.0.1。pnpm 会将 foo@1.0.0 保留在存储中,因为它不会自动移除包。如果系统上没有其他项目使用包 foo@1.0.0,它就会变为未引用状态。运行 pnpm store prune 会从存储中移除 foo@1.0.0

🌐 For example, during pnpm install, package foo@1.0.0 is updated to foo@1.0.1. pnpm will keep foo@1.0.0 in the store, as it does not automatically remove packages. If package foo@1.0.0 is not used by any other project on the system, it becomes unreferenced. Running pnpm store prune would remove foo@1.0.0 from the store.

运行 pnpm store prune 是安全的,不会对你的项目产生任何副作用。如果未来的安装需要被移除的包,pnpm 会再次下载它们。

🌐 Running pnpm store prune is not harmful and has no side effects on your projects. If future installations require removed packages, pnpm will download them again.

最佳做法是偶尔运行 pnpm store prune 来清理存储,但不要过于频繁。有时,未被引用的软件包可能会再次被需要。这可能发生在切换分支并安装较旧的依赖时,在这种情况下,pnpm 需要重新下载所有已删除的软件包,从而短暂地减慢安装过程。

🌐 It is best practice to run pnpm store prune occasionally to clean up the store, but not too frequently. Sometimes, unreferenced packages become required again. This could occur when switching branches and installing older dependencies, in which case pnpm would need to re-download all removed packages, briefly slowing down the installation process.

当启用 [全局虚拟存储] 时,pnpm store prune 也会对全局虚拟存储的 links/ 目录执行标记-清除垃圾回收。使用该存储的项目通过在 {storeDir}/v10/projects/ 中创建符号链接进行注册,从而允许 pnpm 跟踪活动使用情况,并安全地从全局虚拟存储中移除未使用的包。

🌐 When the global virtual store is enabled, pnpm store prune also performs mark-and-sweep garbage collection on the global virtual store's links/ directory. Projects using the store are registered via symlinks in {storeDir}/v10/projects/, allowing pnpm to track active usage and safely remove unused packages from the global virtual store.

请注意,当[存储服务器]正在运行时,此命令是禁止的。

🌐 Please note that this command is prohibited when a store server is running.

path

返回活动存储目录的路径。

🌐 Returns the path to the active store directory.