pnpm store
管理包存储。
命令#
status#
检查当前项目锁文件中列出的包在项目或全局虚拟存储中是否被修改。
如果包的内容与拆包时相同,返回退出代码 0。 Otherwise it fails with ERR_PNPM_MODIFIED_DEPENDENCY and
lists the modified packages.
If an installed global-store package cannot be located or its project link points
to a different slot, the command fails with
ERR_PNPM_STORE_STATUS_UNVERIFIABLE. Run pnpm install before checking again.
add#
功能上等同于 pnpm add,不同之处在于它只把包加入存储中,但没有修改存储外的任何项目或文件。
pnpm store add express@4
It also takes package tarballs or directories of tarballs that were downloaded
some other way, searching directories recursively for .tgz, .tar.gz, and
.tar archives. 这会为无需网络访问的安装准备好存储,例如提前下载其源码的沙箱构建:
pnpm store add ./tarballs
pnpm install --offline --frozen-lockfile
当锁文件条目固定了该 tarball 时,安装会从这样的 tarball 中获取包。 The entry's integrity can be the tarball's sha512 or sha1, or the
hash of the uncompressed tar inside it, which
lockfile.integrityTarget: tar
records.
Run pnpm store add in the project it prepares the store for. 然后它会读取项目的锁文件,并为每个固定该 tarball 的条目准备对应的 tarball。 This
covers a dependency on a tarball URL, a package from a
named registry, and a dependency on a
git host such as GitHub when its entry records an integrity. Outside a project,
a tarball only serves registry entries that name the package and version in its
package.json.
prune#
从存储中删除 未引用的包。
未引用的包是系统上的任何项目中都未使用的包。在大多数安装操作之后,包有可能会变为未引用状态,例如当依赖项变得多余时。
例如,在 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 从存储中删除 。
运行 pnpm store prune 是无害的,对你的项目没有副作用。如果以后的安装需要已经被删除的包,pnpm 将重新下载他们。
最好的做法是运行 pnpm store prune 来清理存储,但不要太频繁。有时,未引用的包会再次被需要。这可能在切换分支和安装旧的依赖项时发生,在这种情况下,pnpm 需要重新下载所有删除的包,会暂时减慢安装过程。
Before pruning the store, pnpm deletes the expired entries of the pnx cache
(see dlxCacheMaxAge), because
they hold hard links into the store.
pnpm store prune also removes the package metadata cache: the metadata*
directories in the cache directory and in its versioned subdirectories, such as
v12/metadata. 缓存目录中的其他缓存会保留。下一次安装会重新下载元数据。
修剪后,pnpm 会显示已删除文件的总大小。
如果 pnpm 无法解码某个包索引条目,它会保留该条目,并在摘要中报告无法解码的条目数量。其他条目会继续被清理。保留索引条目并不会保留其未被引用的文件。如果后续安装无法复用已存储的文件,则会再次下载该包。
pnpm store prune keeps the wheels and source distributions that the
pylock.toml of each registered Python project pins, so a later
pnpm install --offline can recreate its environment. Unless frozenStore
is enabled, an install tries to register each Python project that has an
environment, even one whose store is inside it. A failed registration does
not fail the install. A project installed by an earlier pnpm version is not
registered until it is installed again. Pruning stops if a registered
project's pylock.toml cannot be parsed.
pnpm store prune fails with ERR_PNPM_FROZEN_STORE_WRITE when
frozenStore is enabled.
Since v12.7.0, pnpm store prune also removes private copies of pnpm or a
runtime that a killed pnpm process left behind. 当项目固定某个版本,而另一个 pnpm 进程当时正在安装该版本时,pnpm 会创建这样的副本。
pnpm install registers the project in the projects directory of the store, "$(pnpm store path)/projects", with or without the global virtual store. Each entry is a symlink to the project directory, so ls -l "$(pnpm store path)/projects" lists the projects that use a store.
Without the global virtual store, an install with --frozen-store or enableModulesDir: false does not write the registry. Neither do --lockfile-only and --dry-run installs.
pnpm store prune removes the directory-clone cache used by local installs on macOS. 已安装的包仍然可用,后续安装会按需重新创建缓存。缓存要求存储和项目位于同一卷上。冻结存储在其缓存缺失时使用逐文件导入。
When the global virtual store is enabled, pnpm store prune also performs mark-and-sweep garbage collection on its links/ directory. 它会遍历已注册的项目,找出仍在使用的包,并移除其余部分。 If no registered project links into links/, prune leaves it unchanged.
如果无法读取某个依赖链接,修剪会停止。
path#
返回激活的存储目录的路径。