命令行接口
与 npm 的差异
¥Differences vs npm
与 npm 不同,pnpm 验证所有选项。例如,pnpm install --target_arch x64
将失败,因为 --target_arch
不是 pnpm install
的有效选项。
¥Unlike npm, pnpm validates all options. For example, pnpm install --target_arch x64
will
fail as --target_arch
is not a valid option for pnpm install
.
但是,某些依赖可能会使用 npm_config_
环境变量,该变量是从 CLI 选项填充的。在这种情况下,你有以下选择:
¥However, some dependencies may use the npm_config_
environment variable, which
is populated from the CLI options. In this case, you have the following options:
-
显式设置环境变量:
npm_config_target_arch=x64 pnpm install
¥explicitly set the env variable:
npm_config_target_arch=x64 pnpm install
-
使用
--config.
强制执行未知选项:pnpm install --config.target_arch=x64
¥force the unknown option with
--config.
:pnpm install --config.target_arch=x64
选项
¥Options
-C <path>, --dir <path>
运行时就好像 pnpm 是在 <path>
中启动的,而不是在当前工作目录中启动。
¥Run as if pnpm was started in <path>
instead of the current working directory.
-w, --workspace-root
运行时就好像 pnpm 是在 workspace 的根目录而不是当前工作目录中启动的。
¥Run as if pnpm was started in the root of the workspace instead of the current working directory.
命令
¥Commands
有关更多信息,请参阅各个 CLI 命令的文档。以下是方便你入门的 npm 等效项列表:
¥For more information, see the documentation for individual CLI commands. Here is a list of handy npm equivalents to get you started:
npm 命令 | 等值 pnpm |
---|---|
npm install | [pnpm install ] |
npm i <pkg> | [pnpm add <pkg> ] |
npm run <cmd> | [pnpm <cmd> ] |
当使用未知命令时,pnpm 将搜索具有给定名称的脚本,因此 pnpm run lint
与 pnpm lint
相同。如果 没有指定名称的脚本,则 pnpm 将作为 shell 脚本执行该命令,因此你可以执行类似 pnpm eslint
的操作(请参阅 pnpm exec)。
¥When an unknown command is used, pnpm will search for a script with the given name,
so pnpm run lint
is the same as pnpm lint
. If there is no script with the specified name,
then pnpm will execute the command as a shell script, so you can do things like pnpm eslint
(see pnpm exec).
环境变量
¥Environment variables
一些与 pnpm 无关的环境变量可能会改变 pnpm 的行为:
¥Some environment variables that are not pnpm related might change the behaviour of pnpm:
这些环境变量可能会影响 pnpm 将使用哪些目录来存储全局信息:
¥These environment variables may influence what directories pnpm will use for storing global information:
-
XDG_CACHE_HOME
-
XDG_CONFIG_HOME
-
XDG_DATA_HOME
-
XDG_STATE_HOME
你可以搜索文档以查找利用这些环境变量的设置。
¥You can search the docs to find the settings that leverage these environment variables.