乐闻世界logo
搜索文章和话题

How to get pnpm store directory

5 个月前提问
3 个月前修改
浏览次数106

6个答案

1
2
3
4
5
6

首先,pnpm 是一个快速、高效的包管理工具,它通过硬链接和符号链接的方式来节省磁盘空间,并且保证了不同项目间的依赖隔离。要确定 pnpm 的全局依赖库文件目录,我们可以使用 pnpm 命令本身来查询。

可以通过以下命令获取 pnpm 的全局存储位置:

sh
pnpm config get store-dir

执行这个命令后,pnpm 将会打印出用来存储全局依赖的文件目录路径。

举个例子,如果我在我的开发环境中运行这个命令,可能会得到类似这样的输出:

plaintext
/home/username/.pnpm-store

这表明 pnpm 的全局依赖被存储在我的用户目录下的 .pnpm-store 文件夹中。

此外,了解 pnpm 的其他配置信息也是有用的。如果你想查看所有的 pnpm 配置,可以运行:

sh
pnpm config list

这将列出所有的 pnpm 配置项,包括全局存储目录、当前的注册表以及其他相关的配置。

在实际的工作流中,知道如何查找全局存储目录可以帮助我们进行一些高级的操作,比如手动清理缓存或者调整存储位置来适用于特定的项目结构或者团队的工作流。

2024年6月29日 12:07 回复

Nowadays you can do

shell
pnpm store path

which, according to pnpm's documentation:

Returns the path to the active store directory.

The default locations of the store are:

  • If the $XDG_DATA_HOME env variable is set, then $XDG_DATA_HOME/pnpm/store
  • On Windows: ~/AppData/Local/pnpm/store
  • On macOS: ~/Library/pnpm/store
  • On Linux: ~/.local/share/pnpm/store

Related docs: https://pnpm.io/npmrc#store-dir

2024年6月29日 12:07 回复

Seems like as of v3.0.1, you cannot get it. pnpm should probably update pnpm get store so that it returns the default location.

As of v3, the pnpm store is located at ~/.pnpm-store by default.

You could also open the file node_modules/.modules.yaml in your project. It will contain a field called "store" with the location of the store that was used to hardlink packages to your project.

Update 2022:

As of v7, refer to @renardesque's or @nouvist's answer's below.

2024年6月29日 12:07 回复

previously, pnpm store is located on user home folder.

shell
Linux : ~/.pnpm-store Windows : C:\Users\YOUR_NAME\.pnpm-store macOS : ~/.pnpm-store

but from now on (v7.0.0), pnpm store is located on different folder. it will located on $XDG_DATA_HOME on Linux, and %LOCALAPPDATA% on Windows. take a look to this issue.

shell
Linux : ~/.local/share/pnpm/store (default) Windows : C:\Users\YOUR_NAME\AppData\Local\pnpm\store macOS : ~/Library/pnpm/store

or, you can check where is located with pnpm store path command

2024年6月29日 12:07 回复

Possible locaiton:

  • ~/.pnpm-store
    If project is on the same partition as user home.
  • $partition_root/.pnpm-store
    If project is on different partition as user home.

Why not just use ~/.pnpm-store:

  • On linux/mac, pnpm use hard link to reuse file.
  • And hard link, can be created only on the same partition.
2024年6月29日 12:07 回复

Content-addressable store is at: C:\Users\username\AppData\Local\pnpm\store\v3

Virtual store is at: node_modules/.pnpm

2024年6月29日 12:07 回复

你的答案