fix: dlx with --allow-build flag (#9281)

close #9263
This commit is contained in:
Zoltan Kochan
2025-03-14 02:27:58 +01:00
parent 942de71d5d
commit e5b7bf4694
4 changed files with 16 additions and 7 deletions

View File

@@ -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).

View File

@@ -75,7 +75,7 @@ export type DlxCommandOptions = {
package?: string[]
shellMode?: boolean
allowBuild?: string[]
} & Pick<Config, 'extraBinPaths' | 'registries' | 'reporter' | 'userAgent' | 'cacheDir' | 'dlxCacheMaxAge' | 'useNodeVersion' | 'symlink'> & add.AddCommandOptions & PnpmSettings
} & Pick<Config, 'extraBinPaths' | 'registries' | 'reporter' | 'userAgent' | 'cacheDir' | 'dlxCacheMaxAge' | 'useNodeVersion' | 'symlink'> & Omit<add.AddCommandOptions, 'rootProjectManifestDir'> & 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,

View File

@@ -88,7 +88,6 @@ export const DLX_DEFAULT_OPTS = {
registries: {
default: REGISTRY_URL,
},
rootProjectManifestDir: '',
sort: true,
storeDir: path.join(tmp, 'store'),
symlink: true,

View File

@@ -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,