fix(listing): --json shows wrong private (#8541)

close #8519
This commit is contained in:
Khải
2024-09-22 07:37:50 +07:00
committed by GitHub
parent 9ff7724dd5
commit 44b8935997
4 changed files with 40 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
---
"@pnpm/plugin-commands-listing": patch
"@pnpm/list": patch
"pnpm": patch
---
Fix issue where `pnpm list --json pkg` shows `"private": false` for a private package [#8519](https://github.com/pnpm/pnpm/issues/8519).

View File

@@ -87,6 +87,7 @@ export async function searchForPackages (
return {
name: entryPkg.name,
version: entryPkg.version,
private: entryPkg.private,
path: projectPath,
...buildDependenciesHierarchy,

View File

@@ -133,6 +133,7 @@ export type ListCommandOptions = Pick<Config,
alwaysPrintRootPackage?: boolean
depth?: number
excludePeers?: boolean
json?: boolean
lockfileDir?: string
long?: boolean
parseable?: boolean

View File

@@ -0,0 +1,31 @@
import { list } from '@pnpm/plugin-commands-listing'
import { prepare } from '@pnpm/prepare'
import { DEFAULT_OPTS } from './utils'
// Covers https://github.com/pnpm/pnpm/issues/8519
describe('correctly report the value of the private field when arguments are provided', () => {
test.each([
[undefined, false],
[false, false],
[true, true],
])('%s -> %s', async (given, expected) => {
prepare({
name: 'root',
version: '0.0.0',
private: given,
})
const output = await list.handler({
...DEFAULT_OPTS,
dir: process.cwd(),
json: true,
}, ['root'])
expect(JSON.parse(output)).toStrictEqual([{
name: 'root',
version: '0.0.0',
private: expected,
path: expect.any(String),
}])
})
})