pnx
别名:pnpm dlx、pnpx
从注册源中获取软件包而不将其安装为依赖项,热加载它,并运行它暴露的任何默认命令二进制文件。
例如,若要在任何地方使用 create-vue 来初始化一个 Vue 项目,而不想在另一个项目下安装它,你可以运行:
pnx create-vue my-app
这将从注册源获取 create-vue 并使用给定的参数运行它。
你还可以指定想使用的软件包的确切版本:
pnx create-vue@next my-app
catalog: 协议也被支持, 允许你使用工作区目录中定义的版本:
pnx shx@catalog:
Running a package manager or a runtime
Added in: v12.0.0-rc.6 (pnpm v12 only)
Naming one of the package managers pnpm provisions (npm, yarn, bun), or a runtime (node, deno, bun), provisions the real thing instead of installing the npm package that shares its name:
pnx yarn@4 install
pnx npm@11 ci
pnx bun@1.3.0 install
pnx node@22 --version
Those npm packages are either a different line of the tool or a wrapper that downloads it, so this is what naming them was always meant to do: pnx yarn@4 used to fail with a missing version, since Yarn 4 is published as @yarnpkg/cli-dist, and pnx node@22 used to run a wrapper that downloads a Node.js build rather than that release itself.
A specifier that locates a package rather than asking for a released version installs what it names, unchanged:
pnx yarn@npm:yarn@1.22.22
pnx yarn@yarnpkg/berry
--package naming a package manager picks which of its commands to run:
pnx --package npm@11 npx create-something
配置项
--package <name>
在运行命令之前要安装的软件包。
示例:
pnx --package=@pnpm/meta-updater meta-updater --help
pnx --package=@pnpm/meta-updater@0 meta-updater --help
可以为安装提供多个软件包:
pnx --package=yo --package=generator-webapp yo webapp --skip-install
--allow-build
添加于:v10.2.0
允许在安装期间执行安装的包名列表。
示例:
pnx --allow-build=esbuild my-bundler bundle
dlx 执行的实际软件包默认允许运行 postinstall 脚本。 因此,如果在上面的例子中 my-bundler 必须在执行之前构建,那么它就会被构建。
--shell-mode, -c
在 shell 中运行该命令。 在 UNIX 上使用 /bin/sh,在 Windows 上使用 \cmd.exe。
示例:
pnx --package cowsay --package lolcatjs -c 'echo "hi pnpm" | cowsay | lolcatjs'
--silent, -s
只打印执行命令的输出。
安全和信任政策
自 v11.0.0 版本起,pnx(及其别名 pnpm dlx / pnpx)在解析和获取请求的软件包时,会遵循项目级别的安全和信任策略设置:
minimumReleaseAge,minimumReleaseAgeExclude,minimumReleaseAgeStricttrustPolicy,trustPolicyExclude,trustPolicyIgnoreAfter
这意味着 pnx 将拒绝执行新发布的或信任度不足的软件包,就像常规的 pnpm install 一样。