Skip to main content
Version: 11.x

pnx

别名:pnpm dlxpnpx

🌐 Aliases: pnpm dlx, pnpx

从注册表中获取包,而不将其安装为依赖,热加载它,并运行它公开的任何默认命令二进制文件。

🌐 Fetches a package from the registry without installing it as a dependency, hotloads it, and runs whatever default command binary it exposes.

例如,要在任何地方使用 create-vue 来引导一个 Vue 项目,而无需在其他项目下安装它,你可以运行:

🌐 For example, to use create-vue anywhere to bootstrap a Vue project without needing to install it under another project, you can run:

pnx create-vue my-app

这将从注册表中获取 create-vue 并使用给定的参数运行它。

🌐 This will fetch create-vue from the registry and run it with the given arguments.

你还可以指定你想要使用的软件包的确切版本:

🌐 You may also specify which exact version of the package you'd like to use:

pnx create-vue@next my-app

catalog: 协议也受支持,允许你使用工作区目录中定义的版本:

🌐 The catalog: protocol is also supported, allowing you to use versions defined in your workspace catalogs:

pnx shx@catalog:

选项

🌐 Options

--package <name>

运行命令之前要安装的包。

🌐 The package to install before running the command.

示例:

🌐 Example:

pnx --package=@pnpm/meta-updater meta-updater --help
pnx --package=@pnpm/meta-updater@0 meta-updater --help

可以提供多个包进行安装:

🌐 Multiple packages can be provided for installation:

pnx --package=yo --package=generator-webapp yo webapp --skip-install

--allow-build

新增于:v10.2.0

🌐 Added in: v10.2.0

允许在安装期间运行安装后脚本的软件包名称列表。

🌐 A list of package names that are allowed to run postinstall scripts during installation.

示例:

🌐 Example:

pnx --allow-build=esbuild my-bundler bundle

dlx 实际执行的包默认允许运行 postinstall 脚本。所以如果在上面的例子中 my-bundler 必须在执行前构建,它将会被构建。

🌐 The actual packages executed by dlx are allowed to run postinstall scripts by default. So if in the above example my-bundler has to be built before execution, it will be built.

--shell-mode, -c

在 shell 中运行命令。在 UNIX 上使用 /bin/sh,在 Windows 上使用 \cmd.exe

🌐 Runs the command inside of a shell. Uses /bin/sh on UNIX and \cmd.exe on Windows.

示例:

🌐 Example:

pnx --package cowsay --package lolcatjs -c 'echo "hi pnpm" | cowsay | lolcatjs'

--silent, -s

仅打印执行命令的输出。

🌐 Only the output of the executed command is printed.

安全与信任政策

🌐 Security and trust policies

自 v11.0.0 起,pnx(及其 pnpm dlx / pnpx 别名)在解析和获取请求的包时,会遵守项目级别的安全和信任策略设置:

🌐 Since v11.0.0, pnx (and its pnpm dlx / pnpx aliases) honors the project-level security and trust policy settings when resolving and fetching the requested package:

这意味着 pnx 将像普通的 pnpm install 一样,拒绝执行新发布或不够受信任的软件包。

🌐 This means pnx will refuse to execute freshly published or insufficiently trusted packages the same way a regular pnpm install would.