mirror of
https://github.com/pnpm/pnpm.git
synced 2026-03-09 10:47:48 -04:00
fix(dlx): set saveProd to true for getting pkgName from dependencies (#7540)
close #7424 --------- Co-authored-by: Zoltan Kochan <z@kochan.io>
This commit is contained in:
6
.changeset/nasty-apricots-taste.md
Normal file
6
.changeset/nasty-apricots-taste.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/plugin-commands-script-runners": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
Set saveProd to true for getting pkgName from dependencies [7424](https://github.com/pnpm/pnpm/issues/7424).
|
||||
@@ -95,6 +95,10 @@ export async function handler (
|
||||
dir: prefix,
|
||||
lockfileDir: prefix,
|
||||
rootProjectManifestDir: prefix, // This property won't be used as rootProjectManifest will be undefined
|
||||
saveProd: true, // dlx will be looking for the package in the "dependencies" field!
|
||||
saveDev: false,
|
||||
saveOptional: false,
|
||||
savePeer: false,
|
||||
}, pkgs)
|
||||
const binName = opts.package
|
||||
? command
|
||||
@@ -119,7 +123,11 @@ export async function handler (
|
||||
|
||||
async function getPkgName (pkgDir: string) {
|
||||
const manifest = await readPackageJsonFromDir(pkgDir)
|
||||
return Object.keys(manifest.dependencies ?? {})[0]
|
||||
const dependencyNames = Object.keys(manifest.dependencies ?? {})
|
||||
if (dependencyNames.length === 0) {
|
||||
throw new PnpmError('DLX_NO_DEP', 'dlx was unable to find the installed dependency in "dependencies"')
|
||||
}
|
||||
return dependencyNames[0]
|
||||
}
|
||||
|
||||
async function getBinName (modulesDir: string, pkgName: string): Promise<string> {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { promises as fs, mkdirSync } from 'fs'
|
||||
import path from 'path'
|
||||
import PATH_NAME from 'path-name'
|
||||
import { prepare, preparePackages } from '@pnpm/prepare'
|
||||
import { prepare, prepareEmpty, preparePackages } from '@pnpm/prepare'
|
||||
import isWindows from 'is-windows'
|
||||
import { execPnpm, execPnpmSync } from './utils'
|
||||
|
||||
@@ -259,3 +259,14 @@ test('--reporter-hide-prefix should hide workspace prefix', async () => {
|
||||
expect(output).toContain('2')
|
||||
expect(output).not.toContain('script2: 2')
|
||||
})
|
||||
|
||||
test('dlx should work with npm_config_save_dev env variable', async () => {
|
||||
prepareEmpty()
|
||||
const result = execPnpmSync(['dlx', '@foo/touch-file-one-bin@latest'], {
|
||||
env: {
|
||||
npm_config_save_dev: 'true',
|
||||
},
|
||||
stdio: 'inherit',
|
||||
})
|
||||
expect(result.status).toBe(0)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user