From c1f09d48fa27db4bf83399260919e7bc5c896fdd Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Fri, 14 Mar 2025 02:27:58 +0100 Subject: [PATCH] fix: dlx with --allow-build flag (#9281) close #9263 --- .changeset/great-groups-fry.md | 7 +++++++ exec/plugin-commands-script-runners/src/dlx.ts | 3 ++- .../test/utils/index.ts | 1 - pkg-manager/plugin-commands-installation/src/add.ts | 12 +++++++----- 4 files changed, 16 insertions(+), 7 deletions(-) create mode 100644 .changeset/great-groups-fry.md diff --git a/.changeset/great-groups-fry.md b/.changeset/great-groups-fry.md new file mode 100644 index 0000000000..2081e41bb8 --- /dev/null +++ b/.changeset/great-groups-fry.md @@ -0,0 +1,7 @@ +--- +"@pnpm/plugin-commands-installation": patch +"@pnpm/plugin-commands-script-runners": patch +"pnpm": patch +--- + +Fix `pnpm dlx` with `--allow-build` flag [#9263](https://github.com/pnpm/pnpm/issues/9263). diff --git a/exec/plugin-commands-script-runners/src/dlx.ts b/exec/plugin-commands-script-runners/src/dlx.ts index 57851acfef..7b5ca8f061 100644 --- a/exec/plugin-commands-script-runners/src/dlx.ts +++ b/exec/plugin-commands-script-runners/src/dlx.ts @@ -75,7 +75,7 @@ export type DlxCommandOptions = { package?: string[] shellMode?: boolean allowBuild?: string[] -} & Pick & add.AddCommandOptions & PnpmSettings +} & Pick & Omit & PnpmSettings export async function handler ( opts: DlxCommandOptions, @@ -113,6 +113,7 @@ export async function handler ( dir: cachedDir, lockfileDir: cachedDir, onlyBuiltDependencies: [...resolvedPkgAliases, ...(opts.allowBuild ?? [])], + rootProjectManifestDir: cachedDir, saveProd: true, // dlx will be looking for the package in the "dependencies" field! saveDev: false, saveOptional: false, diff --git a/exec/plugin-commands-script-runners/test/utils/index.ts b/exec/plugin-commands-script-runners/test/utils/index.ts index f54d9a59de..49e244e711 100644 --- a/exec/plugin-commands-script-runners/test/utils/index.ts +++ b/exec/plugin-commands-script-runners/test/utils/index.ts @@ -88,7 +88,6 @@ export const DLX_DEFAULT_OPTS = { registries: { default: REGISTRY_URL, }, - rootProjectManifestDir: '', sort: true, storeDir: path.join(tmp, 'store'), symlink: true, diff --git a/pkg-manager/plugin-commands-installation/src/add.ts b/pkg-manager/plugin-commands-installation/src/add.ts index 1b0efc553e..346aff440e 100644 --- a/pkg-manager/plugin-commands-installation/src/add.ts +++ b/pkg-manager/plugin-commands-installation/src/add.ts @@ -231,11 +231,13 @@ export async function handler ( ...(opts.onlyBuiltDependencies ?? []), ...opts.allowBuild, ])).sort((a, b) => a.localeCompare(b)) - opts.rootProjectManifest = opts.rootProjectManifest ?? {} - opts.rootProjectManifest.pnpm = opts.rootProjectManifest.pnpm ?? {} - opts.rootProjectManifest.pnpm.onlyBuiltDependencies = opts.onlyBuiltDependencies - const writeProjectManifest = await createProjectManifestWriter(opts.rootProjectManifestDir) - await writeProjectManifest(opts.rootProjectManifest) + if (opts.rootProjectManifestDir) { + opts.rootProjectManifest = opts.rootProjectManifest ?? {} + opts.rootProjectManifest.pnpm = opts.rootProjectManifest.pnpm ?? {} + opts.rootProjectManifest.pnpm.onlyBuiltDependencies = opts.onlyBuiltDependencies + const writeProjectManifest = await createProjectManifestWriter(opts.rootProjectManifestDir) + await writeProjectManifest(opts.rootProjectManifest) + } } return installDeps({ ...opts,